1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/app.hxx>
21 #include <vcl/virdev.hxx>
22 #include <tools/tenccvt.hxx>
23 #include <osl/thread.h>
25 #include <tools/stream.hxx>
27 #include "starmath.hrc"
29 #include "utility.hxx"
35 ////////////////////////////////////////////////////////////
37 // return pointer to active SmViewShell, if this is not possible
39 //!! Since this method is based on the current focus it is somewhat
40 //!! unreliable and may return unexpected 0 pointers!
41 SmViewShell
* SmGetActiveView()
43 SfxViewShell
*pView
= SfxViewShell::Current();
44 return PTR_CAST(SmViewShell
, pView
);
48 ////////////////////////////////////////////////////////////
51 /**************************************************************************/
53 void SmFontPickList::Clear()
58 SmFontPickList
& SmFontPickList::operator = (const SmFontPickList
& rList
)
61 nMaxItems
= rList
.nMaxItems
;
62 for (sal_uInt16 nPos
= 0; nPos
< rList
.aFontVec
.size(); nPos
++)
63 aFontVec
.push_back( rList
.aFontVec
[nPos
] );
68 Font
SmFontPickList::operator [] (sal_uInt16 nPos
) const
70 return aFontVec
[nPos
];
73 Font
SmFontPickList::Get(sal_uInt16 nPos
) const
75 return nPos
< aFontVec
.size() ? aFontVec
[nPos
] : Font();
78 bool SmFontPickList::Contains(const Font
&rFont
) const
80 return std::find( aFontVec
.begin(), aFontVec
.end(), rFont
) != aFontVec
.end();
86 bool SmFontPickList::CompareItem(const Font
& rFirstFont
, const Font
& rSecondFont
) const
88 return rFirstFont
.GetName() == rSecondFont
.GetName() &&
89 rFirstFont
.GetFamily() == rSecondFont
.GetFamily() &&
90 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
91 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
92 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
95 OUString
SmFontPickList::GetStringItem(const Font
&rFont
)
97 OUStringBuffer
aString(rFont
.GetName());
99 if (IsItalic( rFont
))
101 aString
.append(", ");
102 aString
.append(SM_RESSTR(RID_FONTITALIC
));
106 aString
.append(", ");
107 aString
.append(SM_RESSTR(RID_FONTBOLD
));
110 return aString
.makeStringAndClear();
113 void SmFontPickList::Insert(const Font
&rFont
)
116 aFontVec
.push_front( rFont
);
118 if (aFontVec
.size() > nMaxItems
)
124 void SmFontPickList::Update(const Font
&rFont
, const Font
&rNewFont
)
126 for (sal_uInt16 nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
127 if (CompareItem( aFontVec
[nPos
], rFont
))
129 aFontVec
[nPos
] = rNewFont
;
134 void SmFontPickList::Remove(const Font
&rFont
)
136 for (sal_uInt16 nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
137 if (CompareItem( aFontVec
[nPos
], rFont
))
139 aFontVec
.erase( aFontVec
.begin() + nPos
);
145 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
147 Insert(rDialog
.GetFont());
150 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
152 rDialog
.SetFont(Get());
156 /**************************************************************************/
159 IMPL_LINK( SmFontPickListBox
, SelectHdl
, ListBox
*, /*pListBox*/ )
164 nPos
= GetSelectEntryPos();
168 SmFontPickList::Insert(Get(nPos
));
169 aString
= GetEntry(nPos
);
171 InsertEntry(aString
, 0);
180 SmFontPickListBox::SmFontPickListBox(Window
* pParent
, const ResId
& rResId
) :
182 ListBox(pParent
, rResId
)
184 SetSelectHdl(LINK(this, SmFontPickListBox
, SelectHdl
));
188 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
192 *(SmFontPickList
*)this = rList
;
194 for (nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
195 InsertEntry(GetStringItem(aFontVec
[nPos
]), nPos
);
197 if (aFontVec
.size() > 0)
198 SelectEntry(GetStringItem(aFontVec
.front()));
203 void SmFontPickListBox::Insert(const Font
&rFont
)
205 SmFontPickList::Insert(rFont
);
207 RemoveEntry(GetStringItem(aFontVec
.front()));
208 InsertEntry(GetStringItem(aFontVec
.front()), 0);
209 SelectEntry(GetStringItem(aFontVec
.front()));
211 while (GetEntryCount() > nMaxItems
)
212 RemoveEntry(GetEntryCount() - 1);
218 void SmFontPickListBox::Update(const Font
&rFont
, const Font
&rNewFont
)
220 SmFontPickList::Update(rFont
, rNewFont
);
226 void SmFontPickListBox::Remove(const Font
&rFont
)
228 SmFontPickList::Remove(rFont
);
233 ////////////////////////////////////////
235 bool IsItalic( const Font
&rFont
)
237 FontItalic eItalic
= rFont
.GetItalic();
238 // the code below leaves only _NONE and _DONTKNOW as not italic
239 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
243 bool IsBold( const Font
&rFont
)
245 FontWeight eWeight
= rFont
.GetWeight();
246 return eWeight
!= WEIGHT_DONTKNOW
&& eWeight
> WEIGHT_NORMAL
;
250 void SmFace::Impl_Init()
252 SetSize( GetSize() );
253 SetTransparent( true );
254 SetAlign( ALIGN_BASELINE
);
255 SetColor( COL_AUTO
);
258 void SmFace::SetSize(const Size
& rSize
)
262 // check the requested size against minimum value
263 static int const nMinVal
= SmPtsTo100th_mm(2);
265 if (aSize
.Height() < nMinVal
)
266 aSize
.Height() = nMinVal
;
268 //! we don't force a maximum value here because this may prevent eg the
269 //! parentheses in "left ( ... right )" from matching up with large
270 //! bodies (eg stack{...} with many entries).
271 //! Of course this is holds only if characters are used and not polygons.
273 Font::SetSize(aSize
);
277 long SmFace::GetBorderWidth() const
279 if (nBorderWidth
< 0)
280 return GetDefaultBorderWidth();
285 SmFace
& SmFace::operator = (const SmFace
&rFace
)
287 Font::operator = (rFace
);
293 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
294 // scales the width and height of 'rFace' by 'rFrac' and returns a
295 // reference to 'rFace'.
296 // It's main use is to make scaling fonts look easier.
297 { const Size
&rFaceSize
= rFace
.GetSize();
299 rFace
.SetSize(Size(Fraction(rFaceSize
.Width()) *= rFrac
,
300 Fraction(rFaceSize
.Height()) *= rFrac
));
306 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */