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