• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

ut_misc.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef UTMISC_H
00021 #define UTMISC_H
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include "config.h"
00025 #endif
00026 
00027 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00028  * so even if it's commented out in-file that's still a lot of work for
00029  * the preprocessor to do...
00030  */
00031 #ifndef UT_TYPES_H
00032 #include "ut_types.h"
00033 #endif
00034 
00035 #include <string>
00036 
00037 class UT_Rect;
00038 class PP_AttrProp;
00039 
00040 
00041 // ----------------------------------------------------------------
00042 class ABI_EXPORT UT_Rect
00043 {
00044 public:
00045     UT_Rect();
00046     UT_Rect(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00047     UT_Rect(const UT_Rect &);
00048 
00049     bool containsPoint(UT_sint32 x, UT_sint32 y) const;
00050     void set(UT_sint32 iLeft, UT_sint32 iTop, UT_sint32 iWidth, UT_sint32 iHeight);
00051     bool intersectsRect(const UT_Rect * pRect) const;
00052     void unionRect( const UT_Rect *pRect);
00053     UT_sint32   left;
00054     UT_sint32   top;
00055     UT_sint32   width;
00056     UT_sint32   height;
00057 };
00058 
00059 // ----------------------------------------------------------------
00060 struct ABI_EXPORT UT_Point
00061 {
00062     UT_sint32   x;
00063     UT_sint32   y;
00064 };
00065 
00066 #define UT_MAX(A,B) (((A) > (B)) ? (A) : (B))
00067 #define UT_MIN(A,B) (((A) < (B)) ? (A) : (B))
00068 #define UT_ABS(A)   ( ((A) < 0) ? (-(A)) : (A) )
00069 
00070 std::string UT_pathSuffix(std::string path);
00071 bool         UT_addOrReplacePathSuffix(std::string & sPath, const char* sSuffix);
00072 
00073 bool UT_isWordDelimiter(UT_UCSChar currentChar, UT_UCSChar followChar, UT_UCSChar prevChar);
00074 
00078 ABI_EXPORT const gchar* UT_getAttribute(const gchar* name,
00079                                         const gchar** atts);
00080 
00085 ABI_EXPORT bool isTrue( const char* s );
00086 
00087 
00088 UT_sint32 signedHiWord(UT_uint32 dw);
00089 UT_sint32 signedLoWord(UT_uint32 dw);
00090 
00091 UT_uint32 UT_HeadingDepth(const char * szHeadName);
00092 
00093 /*
00094    The purpose of this class is to generate document-unique
00095    numerical identifiers; uniqueness is type-specific, i.e., id's of
00096    the different types generated by the class can overlap. Most of the
00097    time you probably will not want to use this class directly, but use
00098    the methods provided in PD_Document class.
00099 */
00100 
00101 #define UT_UID_INVALID 0xffffffff
00102 class ABI_EXPORT UT_UniqueId
00103 {
00104   public:
00105     UT_UniqueId();
00106     ~UT_UniqueId(){};
00107 
00108     enum idType
00109     {
00110         List = 0,
00111         Footnote,
00112         Endnote,
00113         Annotation,
00114         HeaderFtr,
00115         Image,
00116         Math,
00117         Embed,
00118         ODTCTSplit,
00119 
00120         /* must be last; for internal use only !*/
00121         _Last
00122     };
00123 
00124     UT_uint32 getUID(idType t);
00125     bool      setMinId(idType t, UT_uint32 iMin);
00126     bool      isIdUnique(idType t, UT_uint32 iId) const;
00127 
00128   private:
00129     UT_uint32 m_iID[(UT_uint32)_Last];
00130 };
00131 
00132 ABI_EXPORT bool UT_parseBool (const char * param, bool dfl);
00133 
00134 
00135 #if 0
00136 /*
00137    if your platform does not define timeval, turn on the following definitions
00138 */
00139 #include <time.h>
00140 
00141 typedef signed long suseconds_t;
00142 
00143 struct timeval
00144 {
00145     time_t           tv_sec;
00146     suseconds_t      tv_usec;
00147 };
00148 #endif
00149 
00155 void UT_gettimeofday(struct timeval *tv);
00156 
00157 typedef unsigned char UT_EthernetAddress[6];
00161 bool UT_getEthernetAddress(UT_EthernetAddress &a);
00162 
00163 class ABI_EXPORT UT_VersionInfo
00164 {
00165   public:
00166     UT_VersionInfo(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00167         : m_iMajor(maj), m_iMinor(min), m_iMicro(mic), m_iNano(nan)
00168     {
00169         makeVersString();
00170     }
00171 
00172     UT_VersionInfo()
00173         : m_iMajor(0), m_iMinor(0), m_iMicro(0), m_iNano(0)
00174     {
00175         makeVersString();
00176         }
00177 
00178     UT_uint32 getMajor() const {return m_iMajor;}
00179     UT_uint32 getMinor() const {return m_iMinor;}
00180     UT_uint32 getMicro() const {return m_iMicro;}
00181     UT_uint32 getNano()  const {return m_iNano;}
00182 
00183     void set(UT_uint32 maj, UT_uint32 min, UT_uint32 mic, UT_uint32 nan)
00184     {
00185         m_iMajor = maj;
00186         m_iMinor = min;
00187         m_iMicro = mic;
00188         m_iNano = nan;
00189         makeVersString();
00190     }
00191 
00192     bool operator > (const UT_VersionInfo &v) const
00193         {
00194             if(m_iMajor > v.m_iMajor)
00195                 return true;
00196             if(m_iMajor < v.m_iMajor)
00197                 return false;
00198 
00199             if(m_iMinor > v.m_iMinor)
00200                 return true;
00201             if(m_iMinor < v.m_iMinor)
00202                 return false;
00203 
00204             if(m_iMicro > v.m_iMicro)
00205                 return true;
00206             if(m_iMicro < v.m_iMicro)
00207                 return false;
00208 
00209             if(m_iNano > v.m_iNano)
00210                 return true;
00211             if(m_iNano < v.m_iNano)
00212                 return false;
00213 
00214             return false;
00215         }
00216 
00217     const std::string & getString() const
00218     {
00219         return m_versString;
00220     }
00221 
00222 
00223   private:
00224         void makeVersString();
00225 
00226     UT_uint32 m_iMajor;
00227     UT_uint32 m_iMinor;
00228     UT_uint32 m_iMicro;
00229     UT_uint32 m_iNano;
00230     std::string m_versString;
00231 };
00232 
00233 ABI_EXPORT const gchar ** UT_splitPropsToArray(gchar * props);
00234 
00235 UT_uint64 UT_hash64(const char * p, UT_uint32 bytelen = 0);
00236 UT_uint32 UT_hash32(const char * p, UT_uint32 bytelen = 0);
00237 
00238 // Hack so we get AbiNativeWidget with an xp include
00239 #ifdef TOOLKIT_GTK_ALL
00240 #include "ut_compiler.h"
00241 ABI_W_NO_CONST_QUAL
00242 #include <gtk/gtk.h>
00243 ABI_W_POP
00244 typedef GtkWidget AbiNativeWidget;
00245 #else
00246 // TODO maintainers please fix their platform
00247 typedef void AbiNativeWidget;
00248 #endif
00249 
00250 #endif /* UTMISC_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1