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 <vcl/builderfactory.hxx>
22 #include "starmath.hrc"
24 #include "utility.hxx"
29 // return pointer to active SmViewShell, if this is not possible
31 //!! Since this method is based on the current focus it is somewhat
32 //!! unreliable and may return unexpected 0 pointers!
33 SmViewShell
* SmGetActiveView()
35 SfxViewShell
*pView
= SfxViewShell::Current();
36 return dynamic_cast<SmViewShell
*>( pView
);
40 /**************************************************************************/
42 void SmFontPickList::Clear()
47 SmFontPickList
& SmFontPickList::operator = (const SmFontPickList
& rList
)
50 nMaxItems
= rList
.nMaxItems
;
51 for (const auto & nPos
: rList
.aFontVec
)
52 aFontVec
.push_back( nPos
);
57 vcl::Font
SmFontPickList::Get(sal_uInt16 nPos
) const
59 return nPos
< aFontVec
.size() ? aFontVec
[nPos
] : vcl::Font();
62 bool SmFontPickList::CompareItem(const vcl::Font
& rFirstFont
, const vcl::Font
& rSecondFont
)
64 return rFirstFont
.GetFamilyName() == rSecondFont
.GetFamilyName() &&
65 rFirstFont
.GetFamilyType() == rSecondFont
.GetFamilyType() &&
66 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
67 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
68 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
71 OUString
SmFontPickList::GetStringItem(const vcl::Font
&rFont
)
73 OUStringBuffer
aString(rFont
.GetFamilyName());
75 if (IsItalic( rFont
))
78 aString
.append(SM_RESSTR(RID_FONTITALIC
));
83 aString
.append(SM_RESSTR(RID_FONTBOLD
));
86 return aString
.makeStringAndClear();
89 void SmFontPickList::Insert(const vcl::Font
&rFont
)
91 for (size_t nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
92 if (CompareItem( aFontVec
[nPos
], rFont
))
94 aFontVec
.erase( aFontVec
.begin() + nPos
);
98 aFontVec
.push_front( rFont
);
100 if (aFontVec
.size() > nMaxItems
)
106 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
108 Insert(rDialog
.GetFont());
111 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
113 rDialog
.SetFont(Get());
117 /**************************************************************************/
119 VCL_BUILDER_FACTORY_ARGS(SmFontPickListBox
, WB_DROPDOWN
)
121 SmFontPickListBox::SmFontPickListBox (vcl::Window
* pParent
, WinBits nBits
) :
123 ListBox(pParent
, nBits
)
125 SetSelectHdl(LINK(this, SmFontPickListBox
, SelectHdl
));
128 IMPL_LINK_NOARG( SmFontPickListBox
, SelectHdl
, ListBox
&, void )
132 const sal_Int32 nPos
= GetSelectEntryPos();
136 SmFontPickList::Insert(Get(nPos
));
137 aString
= GetEntry(nPos
);
139 InsertEntry(aString
, 0);
145 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
149 *static_cast<SmFontPickList
*>(this) = rList
;
151 for (nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
152 InsertEntry(GetStringItem(aFontVec
[nPos
]), nPos
);
154 if (aFontVec
.size() > 0)
155 SelectEntry(GetStringItem(aFontVec
.front()));
160 void SmFontPickListBox::Insert(const vcl::Font
&rFont
)
162 SmFontPickList::Insert(rFont
);
164 RemoveEntry(GetStringItem(aFontVec
.front()));
165 InsertEntry(GetStringItem(aFontVec
.front()), 0);
166 SelectEntry(GetStringItem(aFontVec
.front()));
168 while (GetEntryCount() > nMaxItems
)
169 RemoveEntry(GetEntryCount() - 1);
175 bool IsItalic( const vcl::Font
&rFont
)
177 FontItalic eItalic
= rFont
.GetItalic();
178 // the code below leaves only _NONE and _DONTKNOW as not italic
179 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
183 bool IsBold( const vcl::Font
&rFont
)
185 FontWeight eWeight
= rFont
.GetWeight();
186 return eWeight
!= WEIGHT_DONTKNOW
&& eWeight
> WEIGHT_NORMAL
;
190 void SmFace::Impl_Init()
192 SetSize( GetFontSize() );
193 SetTransparent( true );
194 SetAlignment( ALIGN_BASELINE
);
195 SetColor( COL_AUTO
);
198 void SmFace::SetSize(const Size
& rSize
)
202 // check the requested size against minimum value
203 static int const nMinVal
= SmPtsTo100th_mm(2);
205 if (aSize
.Height() < nMinVal
)
206 aSize
.Height() = nMinVal
;
208 //! we don't force a maximum value here because this may prevent eg the
209 //! parentheses in "left ( ... right )" from matching up with large
210 //! bodies (eg stack{...} with many entries).
211 //! Of course this is holds only if characters are used and not polygons.
213 Font::SetFontSize(aSize
);
217 long SmFace::GetBorderWidth() const
219 if (nBorderWidth
< 0)
220 return GetDefaultBorderWidth();
225 SmFace
& SmFace::operator = (const SmFace
&rFace
)
227 Font::operator = (rFace
);
233 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
234 // scales the width and height of 'rFace' by 'rFrac' and returns a
235 // reference to 'rFace'.
236 // It's main use is to make scaling fonts look easier.
237 { const Size
&rFaceSize
= rFace
.GetFontSize();
239 rFace
.SetSize(Size(Fraction(rFaceSize
.Width()) *= rFrac
,
240 Fraction(rFaceSize
.Height()) *= rFrac
));
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */