1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir #ifndef UTILITY_HXX 28*cdf0e10cSrcweir #define UTILITY_HXX 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <sfx2/minarray.hxx> 31*cdf0e10cSrcweir #ifndef _FONT_HXX //autogen 32*cdf0e10cSrcweir #include <vcl/font.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #include <vcl/fixed.hxx> 35*cdf0e10cSrcweir #include <vcl/combobox.hxx> 36*cdf0e10cSrcweir #include <vcl/lstbox.hxx> 37*cdf0e10cSrcweir #include <tools/fract.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir class SmRect; 41*cdf0e10cSrcweir class String; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define C2S(cChar) String::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM(cChar)) 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir ///////////////////////////////////////////////////////////////// 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir inline long SmPtsTo100th_mm(long nNumPts) 49*cdf0e10cSrcweir // returns the length (in 100th of mm) that corresponds to the length 50*cdf0e10cSrcweir // 'nNumPts' (in units points). 51*cdf0e10cSrcweir // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm]. 52*cdf0e10cSrcweir // result is being rounded to the nearest integer. 53*cdf0e10cSrcweir { 54*cdf0e10cSrcweir DBG_ASSERT(nNumPts >= 0, "Sm : Ooops..."); 55*cdf0e10cSrcweir // broken into multiple and fraction of 'nNumPts' to reduce chance 56*cdf0e10cSrcweir // of overflow 57*cdf0e10cSrcweir // (7227 / 2) is added in order to round to the nearest integer 58*cdf0e10cSrcweir return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L; 59*cdf0e10cSrcweir } 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir inline long SmPtsTo100th_mm(const Fraction &rNumPts) 63*cdf0e10cSrcweir // as above but with argument 'rNumPts' as 'Fraction' 64*cdf0e10cSrcweir { 65*cdf0e10cSrcweir Fraction aTmp (254000L, 7227L); 66*cdf0e10cSrcweir return aTmp *= rNumPts; 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir 70*cdf0e10cSrcweir inline Fraction Sm100th_mmToPts(long nNum100th_mm) 71*cdf0e10cSrcweir // returns the length (in points) that corresponds to the length 72*cdf0e10cSrcweir // 'nNum100th_mm' (in 100th of mm). 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir DBG_ASSERT(nNum100th_mm >= 0, "Sm : Ooops..."); 75*cdf0e10cSrcweir Fraction aTmp (7227L, 254000L); 76*cdf0e10cSrcweir return aTmp *= Fraction(nNum100th_mm); 77*cdf0e10cSrcweir } 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir inline long SmRoundFraction(const Fraction &rFrac) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir DBG_ASSERT(rFrac > Fraction(), "Sm : Ooops..."); 83*cdf0e10cSrcweir return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator(); 84*cdf0e10cSrcweir } 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir class SmViewShell; 88*cdf0e10cSrcweir SmViewShell * SmGetActiveView(); 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 92*cdf0e10cSrcweir // 93*cdf0e10cSrcweir // SmFace 94*cdf0e10cSrcweir // 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir sal_Bool IsItalic( const Font &rFont ); 97*cdf0e10cSrcweir sal_Bool IsBold( const Font &rFont ); 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir class SmFace : public Font 100*cdf0e10cSrcweir { 101*cdf0e10cSrcweir long nBorderWidth; 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void Impl_Init(); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir public: 106*cdf0e10cSrcweir SmFace() : 107*cdf0e10cSrcweir Font(), nBorderWidth(-1) { Impl_Init(); } 108*cdf0e10cSrcweir SmFace(const Font& rFont) : 109*cdf0e10cSrcweir Font(rFont), nBorderWidth(-1) { Impl_Init(); } 110*cdf0e10cSrcweir SmFace(const String& rName, const Size& rSize) : 111*cdf0e10cSrcweir Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); } 112*cdf0e10cSrcweir SmFace( FontFamily eFamily, const Size& rSize) : 113*cdf0e10cSrcweir Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir SmFace(const SmFace &rFace) : 116*cdf0e10cSrcweir Font(rFace), nBorderWidth(-1) { Impl_Init(); } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // overloaded version in order to supply a min value 119*cdf0e10cSrcweir // for font size (height). (Also used in ctor's to do so.) 120*cdf0e10cSrcweir void SetSize(const Size& rSize); 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; } 123*cdf0e10cSrcweir long GetBorderWidth() const; 124*cdf0e10cSrcweir long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; } 125*cdf0e10cSrcweir void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir SmFace & operator = (const SmFace &rFace); 128*cdf0e10cSrcweir }; 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir SmFace & operator *= (SmFace &rFace, const Fraction &rFrac); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir #ifdef NEVER 134*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 135*cdf0e10cSrcweir // 136*cdf0e10cSrcweir // SmInfoText 137*cdf0e10cSrcweir // 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir class SmInfoText : public FixedText 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir protected: 142*cdf0e10cSrcweir sal_uInt16 nMaxLen; 143*cdf0e10cSrcweir String aText; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir public: 146*cdf0e10cSrcweir SmInfoText(Window* pParent, WinBits nWinStyle = 0, sal_uInt16 nMax = 128); 147*cdf0e10cSrcweir SmInfoText(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 128); 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir void SetText(const String& rStr); 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir XubString GetText() const { return (aText); } 152*cdf0e10cSrcweir }; 153*cdf0e10cSrcweir #endif 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 157*cdf0e10cSrcweir // 158*cdf0e10cSrcweir // SmPickList 159*cdf0e10cSrcweir // 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir class SmPickList : public SfxPtrArr 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir protected: 164*cdf0e10cSrcweir sal_uInt16 nSize; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir virtual void *CreateItem(const String& rString) = 0; 167*cdf0e10cSrcweir virtual void *CreateItem(const void *pItem) = 0; 168*cdf0e10cSrcweir virtual void DestroyItem(void *pItem) = 0; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir virtual sal_Bool CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0; 171*cdf0e10cSrcweir 172*cdf0e10cSrcweir virtual String GetStringItem(void *pItem) = 0; 173*cdf0e10cSrcweir 174*cdf0e10cSrcweir void *GetPtr(sal_uInt16 nPos) const { return SfxPtrArr::GetObject(nPos); } 175*cdf0e10cSrcweir void *&GetPtr(sal_uInt16 nPos) { return SfxPtrArr::GetObject(nPos); } 176*cdf0e10cSrcweir void InsertPtr(sal_uInt16 nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); } 177*cdf0e10cSrcweir void RemovePtr(sal_uInt16 nPos, sal_uInt16 nCount = 1) { SfxPtrArr::Remove(nPos, nCount); } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir public: 180*cdf0e10cSrcweir SmPickList(sal_uInt16 nInitSize = 0, sal_uInt16 nMaxSize = 5); 181*cdf0e10cSrcweir virtual ~SmPickList(); 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir SmPickList& operator = (const SmPickList& rList); 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void *Get(sal_uInt16 nPos = 0) const { return GetPtr(nPos); } 186*cdf0e10cSrcweir using SfxPtrArr::Insert; 187*cdf0e10cSrcweir void Insert(const void* pItem); 188*cdf0e10cSrcweir void Update(const void* pItem, const void *pNewItem); 189*cdf0e10cSrcweir using SfxPtrArr::Remove; 190*cdf0e10cSrcweir void Remove(const void* pItem); 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir using SfxPtrArr::operator []; 193*cdf0e10cSrcweir void *operator [] (sal_uInt16 nPos) const { return GetPtr(nPos); } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_uInt16 GetSize() const { return nSize; } 196*cdf0e10cSrcweir sal_uInt16 Count() const { return SfxPtrArr::Count(); } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void Clear(); 199*cdf0e10cSrcweir }; 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 203*cdf0e10cSrcweir // 204*cdf0e10cSrcweir // SmStringPickList 205*cdf0e10cSrcweir // 206*cdf0e10cSrcweir #ifdef NEVER 207*cdf0e10cSrcweir class SmStringPickList : public SmPickList 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir protected: 210*cdf0e10cSrcweir virtual void *CreateItem(const String& rString); 211*cdf0e10cSrcweir virtual void *CreateItem(const void *pItem); 212*cdf0e10cSrcweir virtual void DestroyItem(void *pItem); 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir virtual sal_Bool CompareItem(const void *pFirstItem, const void *pSecondItem) const; 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir virtual String GetStringItem(void *pItem); 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir public: 219*cdf0e10cSrcweir SmStringPickList() 220*cdf0e10cSrcweir : SmPickList(0, 5) {} 221*cdf0e10cSrcweir SmStringPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize) 222*cdf0e10cSrcweir : SmPickList(nInitSize, nMaxSize) {} 223*cdf0e10cSrcweir SmStringPickList(const SmPickList& rOrig ) 224*cdf0e10cSrcweir : SmPickList(rOrig) {} 225*cdf0e10cSrcweir virtual ~SmStringPickList() { Clear(); } 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir virtual void Insert(const String &rString); 228*cdf0e10cSrcweir virtual void Update(const String &rString, const String &rNewString); 229*cdf0e10cSrcweir virtual void Remove(const String &rString); 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir inline sal_Bool Contains(const String &rString) const; 232*cdf0e10cSrcweir inline String Get(sal_uInt16 nPos = 0) const; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir inline SmStringPickList& operator = (const SmStringPickList& rList); 235*cdf0e10cSrcweir inline String operator [] (sal_uInt16 nPos) const; 236*cdf0e10cSrcweir }; 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir inline SmStringPickList& SmStringPickList::operator = (const SmStringPickList& rList) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir *(SmPickList *)this = *(SmPickList *)&rList; return *this; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir inline String SmStringPickList::operator [] (sal_uInt16 nPos) const 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir return *((String *)SmPickList::operator[](nPos)); 246*cdf0e10cSrcweir } 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir inline String SmStringPickList::Get(sal_uInt16 nPos) const 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir return nPos < Count() ? *((String *)SmPickList::Get(nPos)) : String(); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir inline sal_Bool SmStringPickList::Contains(const String &rString) const 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir return SmPickList::Contains((void *)&rString); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir #endif 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 260*cdf0e10cSrcweir // 261*cdf0e10cSrcweir // SmFontPickList 262*cdf0e10cSrcweir // 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir class SmFontDialog; 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir class SmFontPickList : public SmPickList 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir protected: 269*cdf0e10cSrcweir virtual void *CreateItem(const String& rString); 270*cdf0e10cSrcweir virtual void *CreateItem(const void *pItem); 271*cdf0e10cSrcweir virtual void DestroyItem(void *pItem); 272*cdf0e10cSrcweir 273*cdf0e10cSrcweir virtual sal_Bool CompareItem(const void *pFirstItem, const void *pSecondItem) const; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir virtual String GetStringItem(void *pItem); 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir public: 278*cdf0e10cSrcweir SmFontPickList() 279*cdf0e10cSrcweir : SmPickList(0, 5) {} 280*cdf0e10cSrcweir SmFontPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize) 281*cdf0e10cSrcweir : SmPickList(nInitSize, nMaxSize) {} 282*cdf0e10cSrcweir SmFontPickList(const SmPickList& rOrig ) 283*cdf0e10cSrcweir : SmPickList(rOrig) {} 284*cdf0e10cSrcweir virtual ~SmFontPickList() { Clear(); } 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir using SfxPtrArr::Insert; 287*cdf0e10cSrcweir virtual void Insert(const Font &rFont); 288*cdf0e10cSrcweir using SmPickList::Update; 289*cdf0e10cSrcweir virtual void Update(const Font &rFont, const Font &rNewFont); 290*cdf0e10cSrcweir using SfxPtrArr::Remove; 291*cdf0e10cSrcweir virtual void Remove(const Font &rFont); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir using SmPickList::Contains; 294*cdf0e10cSrcweir inline sal_Bool Contains(const Font &rFont) const; 295*cdf0e10cSrcweir inline Font Get(sal_uInt16 nPos = 0) const; 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir inline SmFontPickList& operator = (const SmFontPickList& rList); 298*cdf0e10cSrcweir using SfxPtrArr::operator []; 299*cdf0e10cSrcweir inline Font operator [] (sal_uInt16 nPos) const; 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir void ReadFrom(const SmFontDialog& rDialog); 302*cdf0e10cSrcweir void WriteTo(SmFontDialog& rDialog) const; 303*cdf0e10cSrcweir }; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir *(SmPickList *)this = *(SmPickList *)&rList; return *this; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir inline Font SmFontPickList::operator [] (sal_uInt16 nPos) const 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir return *((Font *)SmPickList::operator[](nPos)); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir inline Font SmFontPickList::Get(sal_uInt16 nPos) const 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font(); 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir inline sal_Bool SmFontPickList::Contains(const Font &rFont) const 321*cdf0e10cSrcweir { 322*cdf0e10cSrcweir return SmPickList::Contains((void *)&rFont); 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 327*cdf0e10cSrcweir // 328*cdf0e10cSrcweir // SmStringPickComboBox 329*cdf0e10cSrcweir // 330*cdf0e10cSrcweir #ifdef NEVER 331*cdf0e10cSrcweir class SmStringPickComboBox : public SmStringPickList, public ComboBox 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir protected: 334*cdf0e10cSrcweir virtual void LoseFocus(); 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir DECL_LINK(SelectHdl, ComboBox *); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir public: 339*cdf0e10cSrcweir SmStringPickComboBox(Window* pParent, WinBits nWinStyle = 0, sal_uInt16 nMax = 4); 340*cdf0e10cSrcweir SmStringPickComboBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 4); 341*cdf0e10cSrcweir 342*cdf0e10cSrcweir SmStringPickComboBox& operator = (const SmStringPickList& rList); 343*cdf0e10cSrcweir 344*cdf0e10cSrcweir void SetText(const String& rStr); 345*cdf0e10cSrcweir 346*cdf0e10cSrcweir virtual void Insert(const String &rString); 347*cdf0e10cSrcweir virtual void Update(const String &rString, const String &rNewString); 348*cdf0e10cSrcweir virtual void Remove(const String &rString); 349*cdf0e10cSrcweir }; 350*cdf0e10cSrcweir #endif 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir //////////////////////////////////////////////////////////// 353*cdf0e10cSrcweir // 354*cdf0e10cSrcweir // SmFontPickListBox 355*cdf0e10cSrcweir // 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir class SmFontPickListBox : public SmFontPickList, public ListBox 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir protected: 360*cdf0e10cSrcweir DECL_LINK(SelectHdl, ListBox *); 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir public: 363*cdf0e10cSrcweir SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 4); 364*cdf0e10cSrcweir 365*cdf0e10cSrcweir SmFontPickListBox& operator = (const SmFontPickList& rList); 366*cdf0e10cSrcweir 367*cdf0e10cSrcweir using SfxPtrArr::Insert; 368*cdf0e10cSrcweir virtual void Insert(const Font &rFont); 369*cdf0e10cSrcweir using Window::Update; 370*cdf0e10cSrcweir virtual void Update(const Font &rFont, const Font &rNewFont); 371*cdf0e10cSrcweir using SfxPtrArr::Remove; 372*cdf0e10cSrcweir virtual void Remove(const Font &rFont); 373*cdf0e10cSrcweir }; 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir #endif 376*cdf0e10cSrcweir 377