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 <vcl/builderfactory.hxx>
23 #include <tools/tenccvt.hxx>
24 #include <osl/thread.h>
26 #include <tools/stream.hxx>
28 #include "starmath.hrc"
30 #include "utility.hxx"
38 // return pointer to active SmViewShell, if this is not possible
40 //!! Since this method is based on the current focus it is somewhat
41 //!! unreliable and may return unexpected 0 pointers!
42 SmViewShell
* SmGetActiveView()
44 SfxViewShell
*pView
= SfxViewShell::Current();
45 return PTR_CAST(SmViewShell
, pView
);
52 /**************************************************************************/
54 void SmFontPickList::Clear()
59 SmFontPickList
& SmFontPickList::operator = (const SmFontPickList
& rList
)
62 nMaxItems
= rList
.nMaxItems
;
63 for (sal_uInt16 nPos
= 0; nPos
< rList
.aFontVec
.size(); nPos
++)
64 aFontVec
.push_back( rList
.aFontVec
[nPos
] );
69 vcl::Font
SmFontPickList::operator [] (sal_uInt16 nPos
) const
71 return aFontVec
[nPos
];
74 vcl::Font
SmFontPickList::Get(sal_uInt16 nPos
) const
76 return nPos
< aFontVec
.size() ? aFontVec
[nPos
] : vcl::Font();
79 bool SmFontPickList::CompareItem(const vcl::Font
& rFirstFont
, const vcl::Font
& rSecondFont
)
81 return rFirstFont
.GetName() == rSecondFont
.GetName() &&
82 rFirstFont
.GetFamily() == rSecondFont
.GetFamily() &&
83 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
84 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
85 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
88 OUString
SmFontPickList::GetStringItem(const vcl::Font
&rFont
)
90 OUStringBuffer
aString(rFont
.GetName());
92 if (IsItalic( rFont
))
95 aString
.append(SM_RESSTR(RID_FONTITALIC
));
100 aString
.append(SM_RESSTR(RID_FONTBOLD
));
103 return aString
.makeStringAndClear();
106 void SmFontPickList::Insert(const vcl::Font
&rFont
)
109 aFontVec
.push_front( rFont
);
111 if (aFontVec
.size() > nMaxItems
)
117 void SmFontPickList::Update(const vcl::Font
&rFont
, const vcl::Font
&rNewFont
)
119 for (sal_uInt16 nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
120 if (CompareItem( aFontVec
[nPos
], rFont
))
122 aFontVec
[nPos
] = rNewFont
;
127 void SmFontPickList::Remove(const vcl::Font
&rFont
)
129 for (sal_uInt16 nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
130 if (CompareItem( aFontVec
[nPos
], rFont
))
132 aFontVec
.erase( aFontVec
.begin() + nPos
);
138 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
140 Insert(rDialog
.GetFont());
143 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
145 rDialog
.SetFont(Get());
149 /**************************************************************************/
151 VCL_BUILDER_FACTORY_ARGS(SmFontPickListBox
, WB_DROPDOWN
)
153 SmFontPickListBox::SmFontPickListBox (vcl::Window
* pParent
, WinBits nBits
) :
155 ListBox(pParent
, nBits
)
157 SetSelectHdl(LINK(this, SmFontPickListBox
, SelectHdl
));
160 IMPL_LINK( SmFontPickListBox
, SelectHdl
, ListBox
*, /*pListBox*/ )
165 nPos
= GetSelectEntryPos();
169 SmFontPickList::Insert(Get(nPos
));
170 aString
= GetEntry(nPos
);
172 InsertEntry(aString
, 0);
180 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
184 *(SmFontPickList
*)this = rList
;
186 for (nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
187 InsertEntry(GetStringItem(aFontVec
[nPos
]), nPos
);
189 if (aFontVec
.size() > 0)
190 SelectEntry(GetStringItem(aFontVec
.front()));
195 void SmFontPickListBox::Insert(const vcl::Font
&rFont
)
197 SmFontPickList::Insert(rFont
);
199 RemoveEntry(GetStringItem(aFontVec
.front()));
200 InsertEntry(GetStringItem(aFontVec
.front()), 0);
201 SelectEntry(GetStringItem(aFontVec
.front()));
203 while (GetEntryCount() > nMaxItems
)
204 RemoveEntry(GetEntryCount() - 1);
210 void SmFontPickListBox::Update(const vcl::Font
&rFont
, const vcl::Font
&rNewFont
)
212 SmFontPickList::Update(rFont
, rNewFont
);
218 void SmFontPickListBox::Remove(const vcl::Font
&rFont
)
220 SmFontPickList::Remove(rFont
);
227 bool IsItalic( const vcl::Font
&rFont
)
229 FontItalic eItalic
= rFont
.GetItalic();
230 // the code below leaves only _NONE and _DONTKNOW as not italic
231 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
235 bool IsBold( const vcl::Font
&rFont
)
237 FontWeight eWeight
= rFont
.GetWeight();
238 return eWeight
!= WEIGHT_DONTKNOW
&& eWeight
> WEIGHT_NORMAL
;
242 void SmFace::Impl_Init()
244 SetSize( GetSize() );
245 SetTransparent( true );
246 SetAlign( ALIGN_BASELINE
);
247 SetColor( COL_AUTO
);
250 void SmFace::SetSize(const Size
& rSize
)
254 // check the requested size against minimum value
255 static int const nMinVal
= SmPtsTo100th_mm(2);
257 if (aSize
.Height() < nMinVal
)
258 aSize
.Height() = nMinVal
;
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.
265 Font::SetSize(aSize
);
269 long SmFace::GetBorderWidth() const
271 if (nBorderWidth
< 0)
272 return GetDefaultBorderWidth();
277 SmFace
& SmFace::operator = (const SmFace
&rFace
)
279 Font::operator = (rFace
);
285 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 { const Size
&rFaceSize
= rFace
.GetSize();
291 rFace
.SetSize(Size(Fraction(rFaceSize
.Width()) *= rFrac
,
292 Fraction(rFaceSize
.Height()) *= rFrac
));
298 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */