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 175 : inline long SmPtsTo100th_mm(long nNumPts)
31 : // returns the length (in 100th of mm) that corresponds to the length
32 : // 'nNumPts' (in units points).
33 : // 72.27 [pt] = 1 [inch] = 2,54 [cm] = 2540 [100th of mm].
34 : // result is being rounded to the nearest integer.
35 : {
36 : OSL_ENSURE(nNumPts >= 0, "Sm : Ooops...");
37 : // broken into multiple and fraction of 'nNumPts' to reduce chance
38 : // of overflow
39 : // (7227 / 2) is added in order to round to the nearest integer
40 175 : return 35 * nNumPts + (nNumPts * 1055L + (7227 / 2)) / 7227L;
41 : }
42 :
43 :
44 : inline long SmPtsTo100th_mm(const Fraction &rNumPts)
45 : // as above but with argument 'rNumPts' as 'Fraction'
46 : {
47 : Fraction aTmp (254000L, 7227L);
48 : return aTmp *= rNumPts;
49 : }
50 :
51 :
52 0 : inline Fraction Sm100th_mmToPts(long nNum100th_mm)
53 : // returns the length (in points) that corresponds to the length
54 : // 'nNum100th_mm' (in 100th of mm).
55 : {
56 : OSL_ENSURE(nNum100th_mm >= 0, "Sm : Ooops...");
57 0 : Fraction aTmp (7227L, 254000L);
58 0 : return aTmp *= Fraction(nNum100th_mm);
59 : }
60 :
61 :
62 0 : inline long SmRoundFraction(const Fraction &rFrac)
63 : {
64 : OSL_ENSURE(rFrac > Fraction(), "Sm : Ooops...");
65 0 : return (rFrac.GetNumerator() + rFrac.GetDenominator() / 2) / rFrac.GetDenominator();
66 : }
67 :
68 :
69 : class SmViewShell;
70 : SmViewShell * SmGetActiveView();
71 :
72 :
73 : ////////////////////////////////////////////////////////////
74 : //
75 : // SmFace
76 : //
77 :
78 : bool IsItalic( const Font &rFont );
79 : bool IsBold( const Font &rFont );
80 :
81 14945 : class SmFace : public Font
82 : {
83 : long nBorderWidth;
84 :
85 : void Impl_Init();
86 :
87 : public:
88 15433 : SmFace() :
89 15433 : Font(), nBorderWidth(-1) { Impl_Init(); }
90 638 : SmFace(const Font& rFont) :
91 638 : Font(rFont), nBorderWidth(-1) { Impl_Init(); }
92 668 : SmFace(const rtl::OUString& rName, const Size& rSize) :
93 668 : Font(rName, rSize), nBorderWidth(-1) { Impl_Init(); }
94 : SmFace( FontFamily eFamily, const Size& rSize) :
95 : Font(eFamily, rSize), nBorderWidth(-1) { Impl_Init(); }
96 :
97 0 : SmFace(const SmFace &rFace) :
98 0 : Font(rFace), nBorderWidth(-1) { Impl_Init(); }
99 :
100 : // overloaded version in order to supply a min value
101 : // for font size (height). (Also used in ctor's to do so.)
102 : void SetSize(const Size& rSize);
103 :
104 0 : void SetBorderWidth(long nWidth) { nBorderWidth = nWidth; }
105 : long GetBorderWidth() const;
106 4455 : long GetDefaultBorderWidth() const { return GetSize().Height() / 20 ; }
107 733 : void FreezeBorderWidth() { nBorderWidth = GetDefaultBorderWidth(); }
108 :
109 : SmFace & operator = (const SmFace &rFace);
110 : };
111 :
112 : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac);
113 :
114 :
115 : ////////////////////////////////////////////////////////////
116 : //
117 : // SmPickList
118 : //
119 :
120 : class SmPickList : public SfxPtrArr
121 : {
122 : protected:
123 : sal_uInt16 nSize;
124 :
125 : virtual void *CreateItem(const void *pItem) = 0;
126 : virtual void DestroyItem(void *pItem) = 0;
127 :
128 : virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const = 0;
129 :
130 : virtual OUString GetStringItem(void *pItem) = 0;
131 :
132 0 : void *GetPtr(sal_uInt16 nPos) const { return SfxPtrArr::GetObject(nPos); }
133 0 : void *&GetPtr(sal_uInt16 nPos) { return SfxPtrArr::GetObject(nPos); }
134 0 : void InsertPtr(sal_uInt16 nPos, void *pItem) { SfxPtrArr::Insert(nPos, pItem); }
135 0 : void RemovePtr(sal_uInt16 nPos, sal_uInt16 nCount = 1) { SfxPtrArr::Remove(nPos, nCount); }
136 :
137 : public:
138 : SmPickList(sal_uInt16 nInitSize = 0, sal_uInt16 nMaxSize = 5);
139 : virtual ~SmPickList();
140 :
141 : SmPickList& operator = (const SmPickList& rList);
142 :
143 0 : void *Get(sal_uInt16 nPos = 0) const { return GetPtr(nPos); }
144 : using SfxPtrArr::Insert;
145 : void Insert(const void* pItem);
146 : void Update(const void* pItem, const void *pNewItem);
147 : using SfxPtrArr::Remove;
148 : void Remove(const void* pItem);
149 :
150 : using SfxPtrArr::operator [];
151 : void *operator [] (sal_uInt16 nPos) const { return GetPtr(nPos); }
152 :
153 : sal_uInt16 GetSize() const { return nSize; }
154 0 : sal_uInt16 Count() const { return SfxPtrArr::Count(); }
155 :
156 : void Clear();
157 : };
158 :
159 :
160 : ////////////////////////////////////////////////////////////
161 : //
162 : // SmFontPickList
163 : //
164 :
165 : class SmFontDialog;
166 :
167 : class SmFontPickList : public SmPickList
168 : {
169 : protected:
170 : virtual void *CreateItem(const void *pItem);
171 : virtual void DestroyItem(void *pItem);
172 :
173 : virtual bool CompareItem(const void *pFirstItem, const void *pSecondItem) const;
174 :
175 : virtual OUString GetStringItem(void *pItem);
176 :
177 : public:
178 28 : SmFontPickList()
179 28 : : SmPickList(0, 5) {}
180 0 : SmFontPickList(sal_uInt16 nInitSize, sal_uInt16 nMaxSize)
181 0 : : SmPickList(nInitSize, nMaxSize) {}
182 : SmFontPickList(const SmPickList& rOrig )
183 : : SmPickList(rOrig) {}
184 0 : virtual ~SmFontPickList() { Clear(); }
185 :
186 : using SfxPtrArr::Insert;
187 : virtual void Insert(const Font &rFont);
188 : using SmPickList::Update;
189 : virtual void Update(const Font &rFont, const Font &rNewFont);
190 : using SfxPtrArr::Remove;
191 : virtual void Remove(const Font &rFont);
192 :
193 : using SmPickList::Contains;
194 : inline bool Contains(const Font &rFont) const;
195 : inline Font Get(sal_uInt16 nPos = 0) const;
196 :
197 : inline SmFontPickList& operator = (const SmFontPickList& rList);
198 : using SfxPtrArr::operator [];
199 : inline Font operator [] (sal_uInt16 nPos) const;
200 :
201 : void ReadFrom(const SmFontDialog& rDialog);
202 : void WriteTo(SmFontDialog& rDialog) const;
203 : };
204 :
205 0 : inline SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
206 : {
207 0 : *(SmPickList *)this = *(SmPickList *)&rList; return *this;
208 : }
209 :
210 : inline Font SmFontPickList::operator [] (sal_uInt16 nPos) const
211 : {
212 : return *((Font *)SmPickList::operator[](nPos));
213 : }
214 :
215 0 : inline Font SmFontPickList::Get(sal_uInt16 nPos) const
216 : {
217 0 : return nPos < Count() ? *((Font *)SmPickList::Get(nPos)) : Font();
218 : }
219 :
220 : inline bool SmFontPickList::Contains(const Font &rFont) const
221 : {
222 : return SmPickList::Contains((void *)&rFont);
223 : }
224 :
225 :
226 : ////////////////////////////////////////////////////////////
227 : //
228 : // SmFontPickListBox
229 : //
230 :
231 0 : class SmFontPickListBox : public SmFontPickList, public ListBox
232 : {
233 : protected:
234 : DECL_LINK(SelectHdl, ListBox *);
235 :
236 : public:
237 : SmFontPickListBox(Window* pParent, const ResId& rResId, sal_uInt16 nMax = 4);
238 :
239 : SmFontPickListBox& operator = (const SmFontPickList& rList);
240 :
241 : using SfxPtrArr::Insert;
242 : virtual void Insert(const Font &rFont);
243 : using Window::Update;
244 : virtual void Update(const Font &rFont, const Font &rNewFont);
245 : using SfxPtrArr::Remove;
246 : virtual void Remove(const Font &rFont);
247 : };
248 :
249 : #endif
250 :
251 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|