Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : : #ifndef UTILITY_HXX
20 : : #define UTILITY_HXX
21 : :
22 : : #include <sfx2/minarray.hxx>
23 : : #include <vcl/font.hxx>
24 : : #include <vcl/fixed.hxx>
25 : : #include <vcl/combobox.hxx>
26 : : #include <vcl/lstbox.hxx>
27 : : #include <tools/fract.hxx>
28 : :
29 : :
30 : : class String;
31 : :
32 : : /////////////////////////////////////////////////////////////////
33 : :
34 : 490 : inline long SmPtsTo100th_mm(long nNumPts)
35 : : // returns the length (in 100th of mm) that corresponds to the length
36 : : // 'nNumPts' (in units points).
37 : : // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
38 : : // result is being rounded to the nearest integer.
39 : : {
40 : : OSL_ENSURE(nNumPts >= 0, "Sm : Ooops...");
41 : : // broken into multiple and fraction of 'nNumPts' to reduce chance
42 : : // of overflow
43 : : // (7227 / 2) is added in order to round to the nearest integer
44 : 490 : return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
45 : : }
46 : :
47 : :
48 : : inline long SmPtsTo100th_mm(const Fraction &rNumPts)
49 : : // as above but with argument 'rNumPts' as 'Fraction'
50 : : {
51 : : Fraction aTmp (254000L, 7227L);
52 : : return aTmp *= rNumPts;
53 : : }
54 : :
55 : :
56 : 0 : inline Fraction Sm100th_mmToPts(long nNum100th_mm)
57 : : // returns the length (in points) that corresponds to the length
58 : : // 'nNum100th_mm' (in 100th of mm).
59 : : {
60 : : OSL_ENSURE(nNum100th_mm >= 0, "Sm : Ooops...");
61 [ # # ]: 0 : Fraction aTmp (7227L, 254000L);
62 [ # # ][ # # ]: 0 : return aTmp *= Fraction(nNum100th_mm);
[ # # ]
63 : : }
64 : :
65 : :
66 : 0 : inline long SmRoundFraction(const Fraction &rFrac)
67 : : {
68 : : OSL_ENSURE(rFrac > Fraction(), "Sm : Ooops...");
69 : 0 : return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
70 : : }
71 : :
72 : :
73 : : class SmViewShell;
74 : : SmViewShell * SmGetActiveView();
75 : :
76 : :
77 : : ////////////////////////////////////////////////////////////
78 : : //
79 : : // SmFace
80 : : //
81 : :
82 : : bool IsItalic( const Font &rFont );
83 : : bool IsBold( const Font &rFont );
84 : :
85 : 36391 : class SmFace : public Font
86 : : {
87 : : long nBorderWidth;
88 : :
89 : : void Impl_Init();
90 : :
91 : : public:
92 : 35954 : SmFace() :
93 [ + - ]: 35954 : Font(), nBorderWidth(-1) { Impl_Init(); }
94 : 818 : SmFace(const Font& rFont) :
95 [ + - ]: 818 : Font(rFont), nBorderWidth(-1) { Impl_Init(); }
96 : 1894 : SmFace(const rtl::OUString& rName, const Size& rSize) :
97 [ + - ][ + - ]: 1894 : Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
98 : : SmFace( FontFamily eFamily, const Size& rSize) :
99 : : Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
100 : :
101 : 14 : SmFace(const SmFace &rFace) :
102 [ + - ]: 14 : Font(rFace), nBorderWidth(-1) { Impl_Init(); }
103 : :
104 : : // overloaded version in order to supply a min value
105 : : // for font size (height). (Also used in ctor's to do so.)
106 : : void SetSize(const Size& rSize);
107 : :
108 : 14 : void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
109 : : long GetBorderWidth() const;
110 : 13430 : long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
111 : 2196 : void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
112 : :
113 : : SmFace & operator = (const SmFace &rFace);
114 : : };
115 : :
116 : : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
117 : :
118 : :
119 : : ////////////////////////////////////////////////////////////
120 : : //
121 : : // SmPickList
122 : : //
123 : :
124 : : class SmPickList : public SfxPtrArr
125 : : {
126 : : protected:
127 : : sal_uInt16 nSize;
128 : :
129 : : virtual void *CreateItem(const String& rString) = 0;
130 : : virtual void *CreateItem(const void *pItem) = 0;
131 : : virtual void DestroyItem(void *pItem) = 0;
132 : :
133 : : virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
134 : :
135 : : virtual String GetStringItem(void *pItem) = 0;
136 : :
137 : 0 : void *GetPtr(sal_uInt16 nPos) const { return SfxPtrArr::GetObject(nPos); }
138 : 0 : void *&GetPtr(sal_uInt16 nPos) { return SfxPtrArr::GetObject(nPos); }
139 : 0 : void InsertPtr(sal_uInt16 nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
140 : 56 : void RemovePtr(sal_uInt16 nPos, sal_uInt16 nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
141 : :
142 : : public:
143 : : SmPickList(sal_uInt16 nInitSize = 0, sal_uInt16 nMaxSize = 5);
144 : : virtual ~SmPickList();
145 : :
146 : : SmPickList& operator = (const SmPickList& rList);
147 : :
148 : 0 : void *Get(sal_uInt16 nPos = 0) const { return GetPtr(nPos); }
149 : : using SfxPtrArr::Insert;
150 : : void Insert(const void* pItem);
151 : : void Update(const void* pItem, const void *pNewItem);
152 : : using SfxPtrArr::Remove;
153 : : void Remove(const void* pItem);
154 : :
155 : : using SfxPtrArr::operator [];
156 : : void *operator [] (sal_uInt16 nPos) const { return GetPtr(nPos); }
157 : :
158 : : sal_uInt16 GetSize() const { return nSize; }
159 : 112 : sal_uInt16 Count() const { return SfxPtrArr::Count(); }
160 : :
161 : : void Clear();
162 : : };
163 : :
164 : :
165 : : ////////////////////////////////////////////////////////////
166 : : //
167 : : // SmFontPickList
168 : : //
169 : :
170 : : class SmFontDialog;
171 : :
172 : : class SmFontPickList : public SmPickList
173 : : {
174 : : protected:
175 : : virtual void *CreateItem(const String& rString);
176 : : virtual void *CreateItem(const void *pItem);
177 : : virtual void DestroyItem(void *pItem);
178 : :
179 : : virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const;
180 : :
181 : : virtual String GetStringItem(void *pItem);
182 : :
183 : : public:
184 : 70 : SmFontPickList()
185 : 70 : : SmPickList(0, 5) {}
186 : 0 : SmFontPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize)
187 : 0 : : SmPickList(nInitSize, nMaxSize) {}
188 : : SmFontPickList(const SmPickList& rOrig )
189 : : : SmPickList(rOrig) {}
190 [ + - ][ - + ]: 28 : virtual ~SmFontPickList() { Clear(); }
191 : :
192 : : using SfxPtrArr::Insert;
193 : : virtual void Insert(const Font &rFont);
194 : : using SmPickList::Update;
195 : : virtual void Update(const Font &rFont, const Font &rNewFont);
196 : : using SfxPtrArr::Remove;
197 : : virtual void Remove(const Font &rFont);
198 : :
199 : : using SmPickList::Contains;
200 : : inline bool Contains(const Font &rFont) const;
201 : : inline Font Get(sal_uInt16 nPos = 0) const;
202 : :
203 : : inline SmFontPickList& operator = (const SmFontPickList& rList);
204 : : using SfxPtrArr::operator [];
205 : : inline Font operator [] (sal_uInt16 nPos) const;
206 : :
207 : : void ReadFrom(const SmFontDialog& rDialog);
208 : : void WriteTo(SmFontDialog& rDialog) const;
209 : : };
210 : :
211 : 0 : inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
212 : : {
213 : 0 : *(SmPickList *)this = *(SmPickList *)&rList; return *this;
214 : : }
215 : :
216 : : inline Font SmFontPickList::operator [] (sal_uInt16 nPos) const
217 : : {
218 : : return *((Font *)SmPickList::operator[](nPos));
219 : : }
220 : :
221 : 0 : inline Font SmFontPickList::Get(sal_uInt16 nPos) const
222 : : {
223 [ # # ]: 0 : return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
224 : : }
225 : :
226 : : inline bool SmFontPickList::Contains(const Font &rFont) const
227 : : {
228 : : return SmPickList::Contains((void *)&rFont);
229 : : }
230 : :
231 : :
232 : : ////////////////////////////////////////////////////////////
233 : : //
234 : : // SmFontPickListBox
235 : : //
236 : :
237 [ # # ][ # # ]: 0 : class SmFontPickListBox : public SmFontPickList, public ListBox
238 : : {
239 : : protected:
240 : : DECL_LINK(SelectHdl, ListBox *);
241 : :
242 : : public:
243 : : SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 4);
244 : :
245 : : SmFontPickListBox& operator = (const SmFontPickList& rList);
246 : :
247 : : using SfxPtrArr::Insert;
248 : : virtual void Insert(const Font &rFont);
249 : : using Window::Update;
250 : : virtual void Update(const Font &rFont, const Font &rNewFont);
251 : : using SfxPtrArr::Remove;
252 : : virtual void Remove(const Font &rFont);
253 : : };
254 : :
255 : : #endif
256 : :
257 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|