00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef UTMISC_H
00021 #define UTMISC_H
00022
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026
00027
00028
00029
00030
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034
00035 #ifndef UTVECTOR_H
00036 #include "ut_vector.h"
00037 #endif
00038
00039 #include <string>
00040
00041 class UT_RGBColor;
00042 class UT_Rect;
00043 class UT_String;
00044 class UT_UTF8String;
00045
00046
00047 #define UT_RGBCOLOR_PROXIMITY 45
00048
00049 class ABI_EXPORT UT_RGBColor
00050 {
00051 public:
00052 UT_RGBColor();
00053 UT_RGBColor(unsigned char, unsigned char, unsigned char, bool bTransparent = false);
00054 UT_RGBColor(const UT_RGBColor&);
00055 bool operator != (const UT_RGBColor &op1)
00056 {
00057 return (op1.m_red != m_red || op1.m_grn != m_grn || op1.m_blu != m_blu);
00058 }
00059
00060 bool operator == (const UT_RGBColor &op1)
00061 {
00062 return (op1.m_red == m_red && op1.m_grn == m_grn && op1.m_blu == m_blu);
00063 }
00064
00065
00066 bool operator %= (const UT_RGBColor &op1)
00067 {
00068 UT_uint32 iDiff = abs(m_red - op1.m_red) + abs(m_grn - op1.m_grn) + abs(m_blu - op1.m_blu);
00069 return (iDiff < UT_RGBCOLOR_PROXIMITY);
00070 }
00071
00072 UT_RGBColor & operator ^= (const UT_RGBColor &op1)
00073 {
00074 m_red ^= op1.m_red;
00075 m_grn ^= op1.m_grn;
00076 m_blu ^= op1.m_blu;
00077 return *this;
00078 }
00079
00080 UT_RGBColor & operator += (const unsigned char inc)
00081 {
00082 m_red += inc;
00083 m_grn += inc;
00084 m_blu += inc;
00085 return *this;
00086 }
00087
00088 UT_RGBColor & operator += (const UT_RGBColor &inc)
00089 {
00090 m_red += inc.m_red;
00091 m_grn += inc.m_grn;
00092 m_blu += inc.m_blu;
00093 return *this;
00094 }
00095
00096 UT_RGBColor & operator -= (const UT_RGBColor &inc)
00097 {
00098 m_red -= inc.m_red;
00099 m_grn -= inc.m_grn;
00100 m_blu -= inc.m_blu;
00101 return *this;
00102 }
00103
00104 inline bool isTransparent() const {return m_bIsTransparent;}
00105 bool setColor(const char * pszColor);
00106
00107 unsigned char m_red;
00108 unsigned char m_grn;
00109 unsigned char m_blu;
00110 bool m_bIsTransparent;
00111
00112 };
00113
00114 void UT_setColor(UT_RGBColor & col, unsigned char r, unsigned char g, unsigned char b, bool bTransparent = false);
00115 ABI_EXPORT void UT_parseColor(const char*, UT_RGBColor&);
00116 ABI_EXPORT std::string UT_colorToHex(const char*, bool bPrefix = false);
00117
00118 class ABI_EXPORT UT_HashColor
00119 {
00120 private:
00121 char m_colorBuffer[8];
00122
00123 public:
00124 UT_HashColor ();
00125 ~UT_HashColor ();
00126
00127
00128
00129
00130 const char * setColor (unsigned char r, unsigned char g, unsigned char b);
00131 const char * setColor (const UT_RGBColor & color) { return setColor (color.m_red, color.m_grn, color.m_blu); }
00132 const char * setColor (const char * color);
00133 const char * lookupNamedColor (const char * color_name);
00134 const char * setHashIfValid (const char * color_hash);
00135
00136 const UT_RGBColor rgb ();
00137 };
00138
00139
00140 class ABI_EXPORT UT_Rect
00141 {
00142 public:
00143 UT_Rect();
00144 UT_Rect(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00145 UT_Rect(const UT_Rect &);
00146 UT_Rect(const UT_Rect * r);
00147
00148 bool containsPoint(UT_sint32 x, UT_sint32 y) const;
00149 void set(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00150 bool intersectsRect(const UT_Rect * pRect) const;
00151 void unionRect( const UT_Rect *pRect);
00152 UT_sint32 left;
00153 UT_sint32 top;
00154 UT_sint32 width;
00155 UT_sint32 height;
00156 };
00157
00158
00159 struct ABI_EXPORT UT_Point
00160 {
00161 UT_sint32 x;
00162 UT_sint32 y;
00163 };
00164
00165 #define UT_MAX(A,B) (((A) > (B)) ? (A) : (B))
00166 #define UT_MIN(A,B) (((A) < (B)) ? (A) : (B))
00167 #define UT_ABS(A) ( ((A) < 0) ? (-(A)) : (A) )
00168
00169 const char * UT_pathSuffix(const char * path);
00170 bool UT_isWordDelimiter(UT_UCSChar currentChar, UT_UCSChar followChar, UT_UCSChar prevChar);
00171 ABI_EXPORT const gchar* UT_getAttribute(const gchar* name,
00172 const gchar** atts);
00173
00174 ABI_EXPORT gchar ** UT_cloneAndDecodeAttributes (const gchar ** attrs);
00175
00176 UT_sint32 signedHiWord(UT_uint32 dw);
00177 UT_sint32 signedLoWord(UT_uint32 dw);
00178
00179 UT_GenericVector<UT_String*> * simpleSplit (const UT_String & str, char separator = ' ',
00180 size_t max = 0 );
00181
00182 void warpString(UT_String& str, size_t col_max = 75);
00183 UT_uint32 UT_HeadingDepth(const char * szHeadName);
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193 #define UT_UID_INVALID 0xffffffff
00194 class ABI_EXPORT UT_UniqueId
00195 {
00196 public:
00197 UT_UniqueId();
00198 ~UT_UniqueId(){};
00199
00200 enum idType
00201 {
00202 List = 0,
00203 Footnote,
00204 Endnote,
00205 Annotation,
00206 HeaderFtr,
00207 Image,
00208 Math,
00209 Embed,
00210
00211
00212 _Last
00213 };
00214
00215 UT_uint32 getUID(idType t);
00216 bool setMinId(idType t, UT_uint32 iMin);
00217 bool isIdUnique(idType t, UT_uint32 iId);
00218
00219 private:
00220 UT_uint32 m_iID[(UT_uint32)_Last];
00221 };
00222
00223 ABI_EXPORT bool UT_parseBool (const char * param, bool dfl);
00224
00225
00226 #if 0
00227
00228
00229
00230 #include <time.h>
00231
00232 typedef signed long suseconds_t;
00233
00234 struct timeval
00235 {
00236 time_t tv_sec;
00237 suseconds_t tv_usec;
00238 };
00239 #endif
00240
00246 void UT_gettimeofday(struct timeval *tv);
00247
00248 typedef unsigned char UT_EthernetAddress[6];
00252 bool UT_getEthernetAddress(UT_EthernetAddress &a);
00253
00254 class ABI_EXPORT UT_VersionInfo
00255 {
00256 public:
00257 UT_VersionInfo(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00258 : m_iMajor(maj), m_iMinor(min), m_iMicro(mic), m_iNano(nan) {};
00259
00260 UT_VersionInfo()
00261 : m_iMajor(0), m_iMinor(0), m_iMicro(0), m_iNano(0) {};
00262
00263 UT_uint32 getMajor() const {return m_iMajor;}
00264 UT_uint32 getMinor() const {return m_iMinor;}
00265 UT_uint32 getMicro() const {return m_iMicro;}
00266 UT_uint32 getNano() const {return m_iNano;}
00267
00268 void set(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00269 {m_iMajor = maj; m_iMinor = min; m_iMicro = mic; m_iNano = nan;}
00270
00271 bool operator > (const UT_VersionInfo &v) const
00272 {
00273 if(m_iMajor > v.m_iMajor)
00274 return true;
00275 if(m_iMajor < v.m_iMajor)
00276 return false;
00277
00278 if(m_iMinor > v.m_iMinor)
00279 return true;
00280 if(m_iMinor < v.m_iMinor)
00281 return false;
00282
00283 if(m_iMicro > v.m_iMicro)
00284 return true;
00285 if(m_iMicro < v.m_iMicro)
00286 return false;
00287
00288 if(m_iNano > v.m_iNano)
00289 return true;
00290 if(m_iNano < v.m_iNano)
00291 return false;
00292
00293 return false;
00294 }
00295
00296 const UT_UTF8String & getString() const;
00297
00298
00299 private:
00300 UT_uint32 m_iMajor;
00301 UT_uint32 m_iMinor;
00302 UT_uint32 m_iMicro;
00303 UT_uint32 m_iNano;
00304 };
00305
00306
00307
00308
00309
00310
00311
00312
00313 const gchar ** UT_setPropsToNothing(const gchar ** props);
00314
00315 const gchar ** UT_setPropsToValue(const gchar ** props, const gchar * value);
00316
00317 const gchar ** UT_splitPropsToArray(gchar * props);
00318
00319 UT_uint64 UT_hash64(const char * p, UT_uint32 bytelen = 0);
00320 UT_uint32 UT_hash32(const char * p, UT_uint32 bytelen = 0);
00321
00322
00323 #ifdef TOOLKIT_GTK
00324 #include "ut_unixMisc.h"
00325 #else
00326
00327 typedef void AbiNativeWidget;
00328 #endif
00329
00330 #endif