Update ooo320-m1
[ooovba.git] / binfilter / inc / bf_starmath / utility.hxx
blob010838d6c1b4d689ff8de7d85c6a8e6dd87969c7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: utility.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #ifndef UTILITY_HXX
31 #define UTILITY_HXX
33 #ifndef _SFXVARARR_HXX //autogen
34 #include <bf_sfx2/minarray.hxx>
35 #endif
36 #ifndef _FONT_HXX //autogen
37 #include <vcl/font.hxx>
38 #endif
39 #ifndef _SV_FIXED_HXX //autogen
40 #include <vcl/fixed.hxx>
41 #endif
42 #ifndef _SV_COMBOBOX_HXX //autogen
43 #include <vcl/combobox.hxx>
44 #endif
45 #ifndef _SV_LSTBOX_HXX //autogen
46 #include <vcl/lstbox.hxx>
47 #endif
48 #ifndef _FRACT_HXX //autogen
49 #include <tools/fract.hxx>
50 #endif
51 class String;
52 namespace binfilter {
55 class SmRect;
58 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
60 /////////////////////////////////////////////////////////////////
62 const ByteString ExportString( const String& rString );
63 const String ImportString( const ByteString& rByteString );
65 /////////////////////////////////////////////////////////////////
67 inline long SmPtsTo100th_mm(long nNumPts)
68 // returns the length (in 100th of mm) that corresponds to the length
69 // 'nNumPts' (in units points).
70 // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
71 // result is being rounded to the nearest integer.
73 DBG_ASSERT(nNumPts >= 0, "Sm : Ooops...");
74 // broken into multiple and fraction of 'nNumPts' to reduce chance
75 // of overflow
76 // (7227 / 2) is added in order to round to the nearest integer
77 return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
81 inline long SmPtsTo100th_mm(const Fraction &rNumPts)
82 // as above but with argument 'rNumPts' as 'Fraction'
84 Fraction aTmp (254000L, 7227L);
85 return aTmp *= rNumPts;
89 inline Fraction Sm100th_mmToPts(long nNum100th_mm)
90 // returns the length (in points) that corresponds to the length
91 // 'nNum100th_mm' (in 100th of mm).
93 DBG_ASSERT(nNum100th_mm >= 0, "Sm : Ooops...");
94 Fraction aTmp (7227L, 254000L);
95 return aTmp *= Fraction(nNum100th_mm);
99 inline long SmRoundFraction(const Fraction &rFrac)
101 DBG_ASSERT(rFrac > Fraction(), "Sm : Ooops...");
102 return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
106 class SmViewShell;
107 SmViewShell * SmGetActiveView();
110 ////////////////////////////////////////////////////////////
112 class SmFace;
114 SvStream& operator << (SvStream& rStream, const SmFace& rFont);
115 SvStream& operator >> (SvStream& rStream, SmFace& rFont);
117 void ReadSM20Font(SvStream& rStream, Font& rFont);
120 ////////////////////////////////////////////////////////////
122 // SmRectCache
125 class SmRectCache
127 VirtualDevice *pVirDev;
129 SmRectCache(const SmRectCache &);
130 SmRectCache & operator = (const SmRectCache &);
132 public:
133 struct Key
134 { XubString aText,
135 aFontName;
136 Size aFontSize;
137 FontWeight eFontWeight;
138 FontItalic eFontItalic;
140 Key(const XubString &rText, const Font &rFont);
144 SmRectCache();
145 ~SmRectCache();
147 const SmRect * Search(const Key &rKey) const;
148 const SmRect * Add(const Key &rKey, const SmRect &rRect);
150 VirtualDevice * GetVirDev();
152 void Reset();
156 ////////////////////////////////////////////////////////////
158 // SmFace
162 class SmFace : public Font
164 long nBorderWidth;
166 void Impl_Init();
168 public:
169 SmFace() :
170 Font(), nBorderWidth(-1) { Impl_Init(); }
171 SmFace(const Font& rFont) :
172 Font(rFont), nBorderWidth(-1) { Impl_Init(); }
173 SmFace(const String& rName, const Size& rSize) :
174 Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
175 SmFace( FontFamily eFamily, const Size& rSize) :
176 Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
178 SmFace(const SmFace &rFace) :
179 Font(rFace), nBorderWidth(-1) { Impl_Init(); }
181 // overloaded version in order to supply a min value
182 // for font size (height). (Also used in ctor's to do so.)
183 void SetSize(const Size& rSize);
185 void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
186 long GetBorderWidth() const;
187 long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
188 void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
190 SmFace & operator = (const SmFace &rFace);
193 SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
196 #ifdef NEVER
197 ////////////////////////////////////////////////////////////
199 // SmInfoText
202 class SmInfoText : public FixedText
204 protected:
205 USHORT nMaxLen;
206 String aText;
208 public:
209 SmInfoText(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 128);
210 SmInfoText(Window* pParent, const ResId& rResId, USHORT nMax = 128);
212 void SetText(const String& rStr);
214 XubString GetText() const { return (aText); }
216 #endif
219 ////////////////////////////////////////////////////////////
221 // SmPickList
224 class SmPickList : public SfxPtrArr
226 protected:
227 USHORT nSize;
229 virtual void *CreateItem(const String& rString) = 0;
230 virtual void *CreateItem(const void *pItem) = 0;
231 virtual void DestroyItem(void *pItem) = 0;
233 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
235 virtual String GetStringItem(void *pItem) = 0;
237 virtual void LoadItem(SvStream& rStream, void *pItem) = 0;
238 virtual void SaveItem(SvStream& rStream, const void *pItem) const = 0;
240 void *GetPtr(USHORT nPos) const { return SfxPtrArr::GetObject(nPos); }
241 void *&GetPtr(USHORT nPos) { return SfxPtrArr::GetObject(nPos); }
242 void InsertPtr(USHORT nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
243 void RemovePtr(USHORT nPos, USHORT nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
245 public:
246 SmPickList(USHORT nInitSize = 0, USHORT nMaxSize = 5);
247 ~SmPickList();
250 void *Get(USHORT nPos = 0) const { return GetPtr(nPos); }
252 void *operator [] (USHORT nPos) const { return GetPtr(nPos); }
254 USHORT GetSize() const { return nSize; }
255 USHORT Count() const { return SfxPtrArr::Count(); }
257 void Clear();
262 ////////////////////////////////////////////////////////////
264 // SmStringPickList
266 #ifdef NEVER
267 class SmStringPickList : public SmPickList
269 protected:
270 virtual void *CreateItem(const String& rString);
271 virtual void *CreateItem(const void *pItem);
272 virtual void DestroyItem(void *pItem);
274 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
276 virtual String GetStringItem(void *pItem);
278 virtual void LoadItem(SvStream& rStream, void *pItem);
279 virtual void SaveItem(SvStream& rStream, const void *pItem) const;
281 public:
282 SmStringPickList()
283 : SmPickList(0, 5) {}
284 SmStringPickList(USHORT nInitSize, USHORT nMaxSize)
285 : SmPickList(nInitSize, nMaxSize) {}
286 SmStringPickList(const SmPickList& rOrig )
287 : SmPickList(rOrig) {}
288 ~SmStringPickList() { Clear(); }
290 virtual void Insert(const String &rString);
291 virtual void Update(const String &rString, const String &rNewString);
292 virtual void Remove(const String &rString);
294 inline BOOL Contains(const String &rString) const;
295 inline String Get(USHORT nPos = 0) const;
297 inline SmStringPickList& operator = (const SmStringPickList& rList);
298 inline String operator [] (USHORT nPos) const;
301 inline SmStringPickList& SmStringPickList::operator = (const SmStringPickList& rList)
303 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
306 inline String SmStringPickList::operator [] (USHORT nPos) const
308 return *((String *)SmPickList::operator[](nPos));
311 inline String SmStringPickList::Get(USHORT nPos) const
313 return nPos < Count() ? *((String *)SmPickList::Get(nPos)) : String();
316 inline BOOL SmStringPickList::Contains(const String &rString) const
318 return SmPickList::Contains((void *)&rString);
320 #endif
322 ////////////////////////////////////////////////////////////
324 // SmFontPickList
327 class SmFontDialog;
329 class SmFontPickList : public SmPickList
331 protected:
332 virtual void *CreateItem(const String& rString);
333 virtual void *CreateItem(const void *pItem);
334 virtual void DestroyItem(void *pItem);
336 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
338 virtual String GetStringItem(void *pItem);
340 virtual void LoadItem(SvStream& rStream, void *pItem);
341 virtual void SaveItem(SvStream& rStream, const void *pItem) const;
343 public:
344 SmFontPickList()
345 : SmPickList(0, 5) {}
346 SmFontPickList(USHORT nInitSize, USHORT nMaxSize)
347 : SmPickList(nInitSize, nMaxSize) {}
348 SmFontPickList(const SmPickList& rOrig )
349 : SmPickList(rOrig) {}
350 ~SmFontPickList() { Clear(); }
353 inline BOOL Contains(const Font &rFont) const;
354 inline Font Get(USHORT nPos = 0) const;
356 inline SmFontPickList& operator = (const SmFontPickList& rList);
357 inline Font operator [] (USHORT nPos) const;
361 inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
363 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
366 inline Font SmFontPickList::operator [] (USHORT nPos) const
368 return *((Font *)SmPickList::operator[](nPos));
371 inline Font SmFontPickList::Get(USHORT nPos) const
373 return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
376 ////////////////////////////////////////////////////////////
378 // SmStringPickComboBox
380 #ifdef NEVER
381 class SmStringPickComboBox : public SmStringPickList, public ComboBox
383 protected:
384 virtual void LoseFocus();
386 DECL_LINK(SelectHdl, ComboBox *);
388 public:
389 SmStringPickComboBox(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 4);
390 SmStringPickComboBox(Window* pParent, const ResId& rResId, USHORT nMax = 4);
392 SmStringPickComboBox& operator = (const SmStringPickList& rList);
394 void SetText(const String& rStr);
396 virtual void Insert(const String &rString);
397 virtual void Update(const String &rString, const String &rNewString);
398 virtual void Remove(const String &rString);
400 #endif
402 ////////////////////////////////////////////////////////////
404 // SmFontPickListBox
408 } //namespace binfilter
409 #endif