sync master with lastest vba changes
[ooovba.git] / starmath / inc / utility.hxx
blob04d659210926acda349ee3ad0737032b038fac6d
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.11 $
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 #include <sfx2/minarray.hxx>
34 #ifndef _FONT_HXX //autogen
35 #include <vcl/font.hxx>
36 #endif
37 #include <vcl/fixed.hxx>
38 #include <vcl/combobox.hxx>
39 #include <vcl/lstbox.hxx>
40 #include <tools/fract.hxx>
43 class SmRect;
44 class String;
46 #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar))
48 /////////////////////////////////////////////////////////////////
50 const ByteString ExportString( const String& rString );
51 const String ImportString( const ByteString& rByteString );
53 /////////////////////////////////////////////////////////////////
55 inline long SmPtsTo100th_mm(long nNumPts)
56 // returns the length (in 100th of mm) that corresponds to the length
57 // 'nNumPts' (in units points).
58 // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
59 // result is being rounded to the nearest integer.
61 DBG_ASSERT(nNumPts >= 0, "Sm : Ooops...");
62 // broken into multiple and fraction of 'nNumPts' to reduce chance
63 // of overflow
64 // (7227 / 2) is added in order to round to the nearest integer
65 return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
69 inline long SmPtsTo100th_mm(const Fraction &rNumPts)
70 // as above but with argument 'rNumPts' as 'Fraction'
72 Fraction aTmp (254000L, 7227L);
73 return aTmp *= rNumPts;
77 inline Fraction Sm100th_mmToPts(long nNum100th_mm)
78 // returns the length (in points) that corresponds to the length
79 // 'nNum100th_mm' (in 100th of mm).
81 DBG_ASSERT(nNum100th_mm >= 0, "Sm : Ooops...");
82 Fraction aTmp (7227L, 254000L);
83 return aTmp *= Fraction(nNum100th_mm);
87 inline long SmRoundFraction(const Fraction &rFrac)
89 DBG_ASSERT(rFrac > Fraction(), "Sm : Ooops...");
90 return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
94 class SmViewShell;
95 SmViewShell * SmGetActiveView();
98 ////////////////////////////////////////////////////////////
100 // SmFace
103 BOOL IsItalic( const Font &rFont );
104 BOOL IsBold( const Font &rFont );
106 class SmFace : public Font
108 long nBorderWidth;
110 void Impl_Init();
112 public:
113 SmFace() :
114 Font(), nBorderWidth(-1) { Impl_Init(); }
115 SmFace(const Font& rFont) :
116 Font(rFont), nBorderWidth(-1) { Impl_Init(); }
117 SmFace(const String& rName, const Size& rSize) :
118 Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
119 SmFace( FontFamily eFamily, const Size& rSize) :
120 Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
122 SmFace(const SmFace &rFace) :
123 Font(rFace), nBorderWidth(-1) { Impl_Init(); }
125 // overloaded version in order to supply a min value
126 // for font size (height). (Also used in ctor's to do so.)
127 void SetSize(const Size& rSize);
129 void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
130 long GetBorderWidth() const;
131 long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
132 void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
134 SmFace & operator = (const SmFace &rFace);
137 SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
140 #ifdef NEVER
141 ////////////////////////////////////////////////////////////
143 // SmInfoText
146 class SmInfoText : public FixedText
148 protected:
149 USHORT nMaxLen;
150 String aText;
152 public:
153 SmInfoText(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 128);
154 SmInfoText(Window* pParent, const ResId& rResId, USHORT nMax = 128);
156 void SetText(const String& rStr);
158 XubString GetText() const { return (aText); }
160 #endif
163 ////////////////////////////////////////////////////////////
165 // SmPickList
168 class SmPickList : public SfxPtrArr
170 protected:
171 USHORT nSize;
173 virtual void *CreateItem(const String& rString) = 0;
174 virtual void *CreateItem(const void *pItem) = 0;
175 virtual void DestroyItem(void *pItem) = 0;
177 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
179 virtual String GetStringItem(void *pItem) = 0;
181 void *GetPtr(USHORT nPos) const { return SfxPtrArr::GetObject(nPos); }
182 void *&GetPtr(USHORT nPos) { return SfxPtrArr::GetObject(nPos); }
183 void InsertPtr(USHORT nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
184 void RemovePtr(USHORT nPos, USHORT nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
186 public:
187 SmPickList(USHORT nInitSize = 0, USHORT nMaxSize = 5);
188 virtual ~SmPickList();
190 SmPickList& operator = (const SmPickList& rList);
192 void *Get(USHORT nPos = 0) const { return GetPtr(nPos); }
193 using SfxPtrArr::Insert;
194 void Insert(const void* pItem);
195 void Update(const void* pItem, const void *pNewItem);
196 using SfxPtrArr::Remove;
197 void Remove(const void* pItem);
199 using SfxPtrArr::operator [];
200 void *operator [] (USHORT nPos) const { return GetPtr(nPos); }
202 USHORT GetSize() const { return nSize; }
203 USHORT Count() const { return SfxPtrArr::Count(); }
205 void Clear();
209 ////////////////////////////////////////////////////////////
211 // SmStringPickList
213 #ifdef NEVER
214 class SmStringPickList : public SmPickList
216 protected:
217 virtual void *CreateItem(const String& rString);
218 virtual void *CreateItem(const void *pItem);
219 virtual void DestroyItem(void *pItem);
221 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
223 virtual String GetStringItem(void *pItem);
225 public:
226 SmStringPickList()
227 : SmPickList(0, 5) {}
228 SmStringPickList(USHORT nInitSize, USHORT nMaxSize)
229 : SmPickList(nInitSize, nMaxSize) {}
230 SmStringPickList(const SmPickList& rOrig )
231 : SmPickList(rOrig) {}
232 virtual ~SmStringPickList() { Clear(); }
234 virtual void Insert(const String &rString);
235 virtual void Update(const String &rString, const String &rNewString);
236 virtual void Remove(const String &rString);
238 inline BOOL Contains(const String &rString) const;
239 inline String Get(USHORT nPos = 0) const;
241 inline SmStringPickList& operator = (const SmStringPickList& rList);
242 inline String operator [] (USHORT nPos) const;
245 inline SmStringPickList& SmStringPickList::operator = (const SmStringPickList& rList)
247 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
250 inline String SmStringPickList::operator [] (USHORT nPos) const
252 return *((String *)SmPickList::operator[](nPos));
255 inline String SmStringPickList::Get(USHORT nPos) const
257 return nPos < Count() ? *((String *)SmPickList::Get(nPos)) : String();
260 inline BOOL SmStringPickList::Contains(const String &rString) const
262 return SmPickList::Contains((void *)&rString);
264 #endif
266 ////////////////////////////////////////////////////////////
268 // SmFontPickList
271 class SmFontDialog;
273 class SmFontPickList : public SmPickList
275 protected:
276 virtual void *CreateItem(const String& rString);
277 virtual void *CreateItem(const void *pItem);
278 virtual void DestroyItem(void *pItem);
280 virtual BOOL CompareItem(const void *pFirstItem, const void *pSecondItem) const;
282 virtual String GetStringItem(void *pItem);
284 public:
285 SmFontPickList()
286 : SmPickList(0, 5) {}
287 SmFontPickList(USHORT nInitSize, USHORT nMaxSize)
288 : SmPickList(nInitSize, nMaxSize) {}
289 SmFontPickList(const SmPickList& rOrig )
290 : SmPickList(rOrig) {}
291 virtual ~SmFontPickList() { Clear(); }
293 using SfxPtrArr::Insert;
294 virtual void Insert(const Font &rFont);
295 using SmPickList::Update;
296 virtual void Update(const Font &rFont, const Font &rNewFont);
297 using SfxPtrArr::Remove;
298 virtual void Remove(const Font &rFont);
300 using SmPickList::Contains;
301 inline BOOL Contains(const Font &rFont) const;
302 inline Font Get(USHORT nPos = 0) const;
304 inline SmFontPickList& operator = (const SmFontPickList& rList);
305 using SfxPtrArr::operator [];
306 inline Font operator [] (USHORT nPos) const;
308 void ReadFrom(const SmFontDialog& rDialog);
309 void WriteTo(SmFontDialog& rDialog) const;
312 inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
314 *(SmPickList *)this = *(SmPickList *)&rList; return *this;
317 inline Font SmFontPickList::operator [] (USHORT nPos) const
319 return *((Font *)SmPickList::operator[](nPos));
322 inline Font SmFontPickList::Get(USHORT nPos) const
324 return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
327 inline BOOL SmFontPickList::Contains(const Font &rFont) const
329 return SmPickList::Contains((void *)&rFont);
333 ////////////////////////////////////////////////////////////
335 // SmStringPickComboBox
337 #ifdef NEVER
338 class SmStringPickComboBox : public SmStringPickList, public ComboBox
340 protected:
341 virtual void LoseFocus();
343 DECL_LINK(SelectHdl, ComboBox *);
345 public:
346 SmStringPickComboBox(Window* pParent, WinBits nWinStyle = 0, USHORT nMax = 4);
347 SmStringPickComboBox(Window* pParent, const ResId& rResId, USHORT nMax = 4);
349 SmStringPickComboBox& operator = (const SmStringPickList& rList);
351 void SetText(const String& rStr);
353 virtual void Insert(const String &rString);
354 virtual void Update(const String &rString, const String &rNewString);
355 virtual void Remove(const String &rString);
357 #endif
359 ////////////////////////////////////////////////////////////
361 // SmFontPickListBox
364 class SmFontPickListBox : public SmFontPickList, public ListBox
366 protected:
367 DECL_LINK(SelectHdl, ListBox *);
369 public:
370 SmFontPickListBox(Window* pParent, const ResId& rResId, USHORT nMax = 4);
372 SmFontPickListBox& operator = (const SmFontPickList& rList);
374 using SfxPtrArr::Insert;
375 virtual void Insert(const Font &rFont);
376 using Window::Update;
377 virtual void Update(const Font &rFont, const Font &rNewFont);
378 using SfxPtrArr::Remove;
379 virtual void Remove(const Font &rFont);
382 #endif