00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef UTILITY_HXX
00036 #define UTILITY_HXX
00037
00038 #ifndef _SFXVARARR_HXX //autogen
00039 #include <sfx2/minarray.hxx>
00040 #endif
00041 #ifndef _FONT_HXX //autogen
00042 #include <vcl/font.hxx>
00043 #endif
00044 #ifndef _SV_FIXED_HXX //autogen
00045 #include <vcl/fixed.hxx>
00046 #endif
00047 #ifndef _SV_COMBOBOX_HXX //autogen
00048 #include <vcl/combobox.hxx>
00049 #endif
00050 #ifndef _SV_LSTBOX_HXX //autogen
00051 #include <vcl/lstbox.hxx>
00052 #endif
00053 #ifndef _FRACT_HXX //autogen
00054 #include <tools/fract.hxx>
00055 #endif
00056
00057
00058 class SmRect;
00059 class String;
00060
00061 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
00062
00064
00065 const ByteString ExportString( const String& rString );
00066 const String ImportString( const ByteString& rByteString );
00067
00069
00070 inline long SmPtsTo100th_mm(long nNumPts)
00071
00072
00073
00074
00075 {
00076 DBG_ASSERT(nNumPts >= 0, "Sm : Ooops...");
00077
00078
00079
00080 return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
00081 }
00082
00083
00084 inline long SmPtsTo100th_mm(const Fraction &rNumPts)
00085
00086 {
00087 Fraction aTmp (254000L, 7227L);
00088 return aTmp *= rNumPts;
00089 }
00090
00091
00092 inline Fraction Sm100th_mmToPts(long nNum100th_mm)
00093
00094
00095 {
00096 DBG_ASSERT(nNum100th_mm >= 0, "Sm : Ooops...");
00097 Fraction aTmp (7227L, 254000L);
00098 return aTmp *= Fraction(nNum100th_mm);
00099 }
00100
00101
00102 inline long SmRoundFraction(const Fraction &rFrac)
00103 {
00104 DBG_ASSERT(rFrac > Fraction(), "Sm : Ooops...");
00105 return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
00106 }
00107
00108
00109 class SmViewShell;
00110 SmViewShell * SmGetActiveView();
00111
00112
00114
00115
00116
00117
00118 BOOL IsItalic( const Font &rFont );
00119 BOOL IsBold( const Font &rFont );
00120
00121 class SmFace : public Font
00122 {
00123 long nBorderWidth;
00124
00125 void Impl_Init();
00126
00127 public:
00128 SmFace() :
00129 Font(), nBorderWidth(-1) { Impl_Init(); }
00130 SmFace(const Font& rFont) :
00131 Font(rFont), nBorderWidth(-1) { Impl_Init(); }
00132 SmFace(const String& rName, const Size& rSize) :
00133 Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
00134 SmFace( FontFamily eFamily, const Size& rSize) :
00135 Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
00136
00137 SmFace(const SmFace &rFace) :
00138 Font(rFace), nBorderWidth(-1) { Impl_Init(); }
00139
00140
00141
00142 void SetSize(const Size& rSize);
00143
00144 void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
00145 long GetBorderWidth() const;
00146 long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
00147 void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
00148
00149 SmFace & operator = (const SmFace &rFace);
00150 };
00151
00152 SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
00153
00154
00155 #ifdef NEVER
00157 //
00158
00159
00160
00161 class SmInfoText : public FixedText
00162 {
00163 protected:
00164 USHORT nMaxLen;
00165 String aText;
00166
00167 public:
00168 SmInfoText(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 128);
00169 SmInfoText(Window* pParent, const ResId& rResId, USHORT nMax = 128);
00170
00171 void SetText(const String& rStr);
00172
00173 XubString GetText() const { return (aText); }
00174 };
00175 #endif
00176
00177
00179
00180
00181
00182
00183 class SmPickList : public SfxPtrArr
00184 {
00185 protected:
00186 USHORT nSize;
00187
00188 virtual void *CreateItem(const String& rString) = 0;
00189 virtual void *CreateItem(const void *pItem) = 0;
00190 virtual void DestroyItem(void *pItem) = 0;
00191
00192 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
00193
00194 virtual String GetStringItem(void *pItem) = 0;
00195
00196 void *GetPtr(USHORT nPos) const { return SfxPtrArr::GetObject(nPos); }
00197 void *&GetPtr(USHORT nPos) { return SfxPtrArr::GetObject(nPos); }
00198 void InsertPtr(USHORT nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
00199 void RemovePtr(USHORT nPos, USHORT nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
00200
00201 public:
00202 SmPickList(USHORT nInitSize = 0, USHORT nMaxSize = 5);
00203 virtual ~SmPickList();
00204
00205 SmPickList& operator = (const SmPickList& rList);
00206
00207 void *Get(USHORT nPos = 0) const { return GetPtr(nPos); }
00208 using SfxPtrArr::Insert;
00209 void Insert(const void* pItem);
00210 void Update(const void* pItem, const void *pNewItem);
00211 using SfxPtrArr::Remove;
00212 void Remove(const void* pItem);
00213
00214 using SfxPtrArr::operator [];
00215 void *operator [] (USHORT nPos) const { return GetPtr(nPos); }
00216
00217 void SetSize(USHORT nNewSize);
00218 USHORT GetSize() const { return nSize; }
00219 USHORT Count() const { return SfxPtrArr::Count(); }
00220
00221 BOOL Contains(const void *pItem) const;
00222 void Clear();
00223 };
00224
00225
00227
00228
00229
00230 #ifdef NEVER
00231 class SmStringPickList : public SmPickList
00232 {
00233 protected:
00234 virtual void *CreateItem(const String& rString);
00235 virtual void *CreateItem(const void *pItem);
00236 virtual void DestroyItem(void *pItem);
00237
00238 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
00239
00240 virtual String GetStringItem(void *pItem);
00241
00242 public:
00243 SmStringPickList()
00244 : SmPickList(0, 5) {}
00245 SmStringPickList(USHORT nInitSize, USHORT nMaxSize)
00246 : SmPickList(nInitSize, nMaxSize) {}
00247 SmStringPickList(const SmPickList& rOrig )
00248 : SmPickList(rOrig) {}
00249 virtual ~SmStringPickList() { Clear(); }
00250
00251 virtual void Insert(const String &rString);
00252 virtual void Update(const String &rString, const String &rNewString);
00253 virtual void Remove(const String &rString);
00254
00255 inline BOOL Contains(const String &rString) const;
00256 inline String Get(USHORT nPos = 0) const;
00257
00258 inline SmStringPickList& operator = (const SmStringPickList& rList);
00259 inline String operator [] (USHORT nPos) const;
00260 };
00261
00262 inline SmStringPickList& SmStringPickList::operator = (const SmStringPickList& rList)
00263 {
00264 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
00265 }
00266
00267 inline String SmStringPickList::operator [] (USHORT nPos) const
00268 {
00269 return *((String *)SmPickList::operator[](nPos));
00270 }
00271
00272 inline String SmStringPickList::Get(USHORT nPos) const
00273 {
00274 return nPos < Count() ? *((String *)SmPickList::Get(nPos)) : String();
00275 }
00276
00277 inline BOOL SmStringPickList::Contains(const String &rString) const
00278 {
00279 return SmPickList::Contains((void *)&rString);
00280 }
00281 #endif
00282
00284
00285
00286
00287
00288 class SmFontDialog;
00289
00290 class SmFontPickList : public SmPickList
00291 {
00292 protected:
00293 virtual void *CreateItem(const String& rString);
00294 virtual void *CreateItem(const void *pItem);
00295 virtual void DestroyItem(void *pItem);
00296
00297 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
00298
00299 virtual String GetStringItem(void *pItem);
00300
00301 public:
00302 SmFontPickList()
00303 : SmPickList(0, 5) {}
00304 SmFontPickList(USHORT nInitSize, USHORT nMaxSize)
00305 : SmPickList(nInitSize, nMaxSize) {}
00306 SmFontPickList(const SmPickList& rOrig )
00307 : SmPickList(rOrig) {}
00308 virtual ~SmFontPickList() { Clear(); }
00309
00310 using SfxPtrArr::Insert;
00311 virtual void Insert(const Font &rFont);
00312 using SmPickList::Update;
00313 virtual void Update(const Font &rFont, const Font &rNewFont);
00314 using SfxPtrArr::Remove;
00315 virtual void Remove(const Font &rFont);
00316
00317 using SmPickList::Contains;
00318 inline BOOL Contains(const Font &rFont) const;
00319 inline Font Get(USHORT nPos = 0) const;
00320
00321 inline SmFontPickList& operator = (const SmFontPickList& rList);
00322 using SfxPtrArr::operator [];
00323 inline Font operator [] (USHORT nPos) const;
00324
00325 void ReadFrom(const SmFontDialog& rDialog);
00326 void WriteTo(SmFontDialog& rDialog) const;
00327 };
00328
00329 inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
00330 {
00331 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
00332 }
00333
00334 inline Font SmFontPickList::operator [] (USHORT nPos) const
00335 {
00336 return *((Font *)SmPickList::operator[](nPos));
00337 }
00338
00339 inline Font SmFontPickList::Get(USHORT nPos) const
00340 {
00341 return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
00342 }
00343
00344 inline BOOL SmFontPickList::Contains(const Font &rFont) const
00345 {
00346 return SmPickList::Contains((void *)&rFont);
00347 }
00348
00349
00351
00352
00353
00354 #ifdef NEVER
00355 class SmStringPickComboBox : public SmStringPickList, public ComboBox
00356 {
00357 protected:
00358 virtual void LoseFocus();
00359
00360 DECL_LINK(SelectHdl, ComboBox *);
00361
00362 public:
00363 SmStringPickComboBox(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 4);
00364 SmStringPickComboBox(Window* pParent, const ResId& rResId, USHORT nMax = 4);
00365
00366 SmStringPickComboBox& operator = (const SmStringPickList& rList);
00367
00368 void SetText(const String& rStr);
00369
00370 virtual void Insert(const String &rString);
00371 virtual void Update(const String &rString, const String &rNewString);
00372 virtual void Remove(const String &rString);
00373 };
00374 #endif
00375
00377
00378
00379
00380
00381 class SmFontPickListBox : public SmFontPickList, public ListBox
00382 {
00383 protected:
00384 DECL_LINK(SelectHdl, ListBox *);
00385
00386 public:
00387 SmFontPickListBox(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 4);
00388 SmFontPickListBox(Window* pParent, const ResId& rResId, USHORT nMax = 4);
00389
00390 SmFontPickListBox& operator = (const SmFontPickList& rList);
00391
00392 using SfxPtrArr::Insert;
00393 virtual void Insert(const Font &rFont);
00394 using Window::Update;
00395 virtual void Update(const Font &rFont, const Font &rNewFont);
00396 using SfxPtrArr::Remove;
00397 virtual void Remove(const Font &rFont);
00398 };
00399
00400 #endif
00401