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 :
20 : #include <sfx2/app.hxx>
21 : #include <vcl/virdev.hxx>
22 : #include <vcl/builderfactory.hxx>
23 : #include <tools/tenccvt.hxx>
24 : #include <osl/thread.h>
25 :
26 : #include <tools/stream.hxx>
27 :
28 : #include "starmath.hrc"
29 :
30 : #include "utility.hxx"
31 : #include "dialog.hxx"
32 : #include "view.hxx"
33 : #include "smdll.hxx"
34 :
35 :
36 :
37 :
38 : // return pointer to active SmViewShell, if this is not possible
39 : // return 0 instead.
40 : //!! Since this method is based on the current focus it is somewhat
41 : //!! unreliable and may return unexpected 0 pointers!
42 1536 : SmViewShell * SmGetActiveView()
43 : {
44 1536 : SfxViewShell *pView = SfxViewShell::Current();
45 1536 : return PTR_CAST(SmViewShell, pView);
46 : }
47 :
48 :
49 :
50 :
51 :
52 : /**************************************************************************/
53 :
54 14 : void SmFontPickList::Clear()
55 : {
56 14 : aFontVec.clear();
57 14 : }
58 :
59 0 : SmFontPickList& SmFontPickList::operator = (const SmFontPickList& rList)
60 : {
61 0 : Clear();
62 0 : nMaxItems = rList.nMaxItems;
63 0 : for (size_t nPos = 0; nPos < rList.aFontVec.size(); nPos++)
64 0 : aFontVec.push_back( rList.aFontVec[nPos] );
65 :
66 0 : return *this;
67 : }
68 :
69 0 : vcl::Font SmFontPickList::operator [] (sal_uInt16 nPos) const
70 : {
71 0 : return aFontVec[nPos];
72 : }
73 :
74 0 : vcl::Font SmFontPickList::Get(sal_uInt16 nPos) const
75 : {
76 0 : return nPos < aFontVec.size() ? aFontVec[nPos] : vcl::Font();
77 : }
78 :
79 0 : bool SmFontPickList::CompareItem(const vcl::Font & rFirstFont, const vcl::Font & rSecondFont)
80 : {
81 0 : return rFirstFont.GetName() == rSecondFont.GetName() &&
82 0 : rFirstFont.GetFamily() == rSecondFont.GetFamily() &&
83 0 : rFirstFont.GetCharSet() == rSecondFont.GetCharSet() &&
84 0 : rFirstFont.GetWeight() == rSecondFont.GetWeight() &&
85 0 : rFirstFont.GetItalic() == rSecondFont.GetItalic();
86 : }
87 :
88 0 : OUString SmFontPickList::GetStringItem(const vcl::Font &rFont)
89 : {
90 0 : OUStringBuffer aString(rFont.GetName());
91 :
92 0 : if (IsItalic( rFont ))
93 : {
94 0 : aString.append(", ");
95 0 : aString.append(SM_RESSTR(RID_FONTITALIC));
96 : }
97 0 : if (IsBold( rFont ))
98 : {
99 0 : aString.append(", ");
100 0 : aString.append(SM_RESSTR(RID_FONTBOLD));
101 : }
102 :
103 0 : return aString.makeStringAndClear();
104 : }
105 :
106 0 : void SmFontPickList::Insert(const vcl::Font &rFont)
107 : {
108 0 : Remove(rFont);
109 0 : aFontVec.push_front( rFont );
110 :
111 0 : if (aFontVec.size() > nMaxItems)
112 : {
113 0 : aFontVec.pop_back();
114 : }
115 0 : }
116 :
117 0 : void SmFontPickList::Update(const vcl::Font &rFont, const vcl::Font &rNewFont)
118 : {
119 0 : for (size_t nPos = 0; nPos < aFontVec.size(); nPos++)
120 0 : if (CompareItem( aFontVec[nPos], rFont ))
121 : {
122 0 : aFontVec[nPos] = rNewFont;
123 0 : break;
124 : }
125 0 : }
126 :
127 0 : void SmFontPickList::Remove(const vcl::Font &rFont)
128 : {
129 0 : for (size_t nPos = 0; nPos < aFontVec.size(); nPos++)
130 0 : if (CompareItem( aFontVec[nPos], rFont))
131 : {
132 0 : aFontVec.erase( aFontVec.begin() + nPos );
133 0 : break;
134 : }
135 0 : }
136 :
137 :
138 0 : void SmFontPickList::ReadFrom(const SmFontDialog& rDialog)
139 : {
140 0 : Insert(rDialog.GetFont());
141 0 : }
142 :
143 0 : void SmFontPickList::WriteTo(SmFontDialog& rDialog) const
144 : {
145 0 : rDialog.SetFont(Get());
146 0 : }
147 :
148 :
149 : /**************************************************************************/
150 :
151 0 : VCL_BUILDER_FACTORY_ARGS(SmFontPickListBox, WB_DROPDOWN)
152 :
153 0 : SmFontPickListBox::SmFontPickListBox (vcl::Window* pParent, WinBits nBits) :
154 : SmFontPickList(4),
155 0 : ListBox(pParent, nBits)
156 : {
157 0 : SetSelectHdl(LINK(this, SmFontPickListBox, SelectHdl));
158 0 : }
159 :
160 0 : IMPL_LINK( SmFontPickListBox, SelectHdl, ListBox *, /*pListBox*/ )
161 : {
162 : sal_uInt16 nPos;
163 0 : OUString aString;
164 :
165 0 : nPos = GetSelectEntryPos();
166 :
167 0 : if (nPos != 0)
168 : {
169 0 : SmFontPickList::Insert(Get(nPos));
170 0 : aString = GetEntry(nPos);
171 0 : RemoveEntry(nPos);
172 0 : InsertEntry(aString, 0);
173 : }
174 :
175 0 : SelectEntryPos(0);
176 :
177 0 : return 0;
178 : }
179 :
180 0 : SmFontPickListBox& SmFontPickListBox::operator=(const SmFontPickList& rList)
181 : {
182 : sal_uInt16 nPos;
183 :
184 0 : *static_cast<SmFontPickList *>(this) = rList;
185 :
186 0 : for (nPos = 0; nPos < aFontVec.size(); nPos++)
187 0 : InsertEntry(GetStringItem(aFontVec[nPos]), nPos);
188 :
189 0 : if (aFontVec.size() > 0)
190 0 : SelectEntry(GetStringItem(aFontVec.front()));
191 :
192 0 : return *this;
193 : }
194 :
195 0 : void SmFontPickListBox::Insert(const vcl::Font &rFont)
196 : {
197 0 : SmFontPickList::Insert(rFont);
198 :
199 0 : RemoveEntry(GetStringItem(aFontVec.front()));
200 0 : InsertEntry(GetStringItem(aFontVec.front()), 0);
201 0 : SelectEntry(GetStringItem(aFontVec.front()));
202 :
203 0 : while (GetEntryCount() > nMaxItems)
204 0 : RemoveEntry(GetEntryCount() - 1);
205 :
206 0 : return;
207 : }
208 :
209 :
210 0 : void SmFontPickListBox::Update(const vcl::Font &rFont, const vcl::Font &rNewFont)
211 : {
212 0 : SmFontPickList::Update(rFont, rNewFont);
213 :
214 0 : return;
215 : }
216 :
217 :
218 0 : void SmFontPickListBox::Remove(const vcl::Font &rFont)
219 : {
220 0 : SmFontPickList::Remove(rFont);
221 :
222 0 : return;
223 : }
224 :
225 :
226 :
227 10986 : bool IsItalic( const vcl::Font &rFont )
228 : {
229 10986 : FontItalic eItalic = rFont.GetItalic();
230 : // the code below leaves only _NONE and _DONTKNOW as not italic
231 10986 : return eItalic == ITALIC_OBLIQUE || eItalic == ITALIC_NORMAL;
232 : }
233 :
234 :
235 8997 : bool IsBold( const vcl::Font &rFont )
236 : {
237 8997 : FontWeight eWeight = rFont.GetWeight();
238 8997 : return eWeight != WEIGHT_DONTKNOW && eWeight > WEIGHT_NORMAL;
239 : }
240 :
241 :
242 26176 : void SmFace::Impl_Init()
243 : {
244 26176 : SetSize( GetSize() );
245 26176 : SetTransparent( true );
246 26176 : SetAlign( ALIGN_BASELINE );
247 26176 : SetColor( COL_AUTO );
248 26176 : }
249 :
250 42880 : void SmFace::SetSize(const Size& rSize)
251 : {
252 42880 : Size aSize (rSize);
253 :
254 : // check the requested size against minimum value
255 42880 : static int const nMinVal = SmPtsTo100th_mm(2);
256 :
257 42880 : if (aSize.Height() < nMinVal)
258 23868 : aSize.Height() = nMinVal;
259 :
260 : //! we don't force a maximum value here because this may prevent eg the
261 : //! parentheses in "left ( ... right )" from matching up with large
262 : //! bodies (eg stack{...} with many entries).
263 : //! Of course this is holds only if characters are used and not polygons.
264 :
265 42880 : Font::SetSize(aSize);
266 42880 : }
267 :
268 :
269 10703 : long SmFace::GetBorderWidth() const
270 : {
271 10703 : if (nBorderWidth < 0)
272 7234 : return GetDefaultBorderWidth();
273 : else
274 3469 : return nBorderWidth;
275 : }
276 :
277 37934 : SmFace & SmFace::operator = (const SmFace &rFace)
278 : {
279 37934 : Font::operator = (rFace);
280 37934 : nBorderWidth = -1;
281 37934 : return *this;
282 : }
283 :
284 :
285 10519 : SmFace & operator *= (SmFace &rFace, const Fraction &rFrac)
286 : // scales the width and height of 'rFace' by 'rFrac' and returns a
287 : // reference to 'rFace'.
288 : // It's main use is to make scaling fonts look easier.
289 10519 : { const Size &rFaceSize = rFace.GetSize();
290 :
291 21038 : rFace.SetSize(Size(Fraction(rFaceSize.Width()) *= rFrac,
292 31557 : Fraction(rFaceSize.Height()) *= rFrac));
293 10519 : return rFace;
294 42 : }
295 :
296 :
297 :
298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|