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 <strings.hrc>
22 #include <utility.hxx>
26 // return pointer to active SmViewShell, if this is not possible
28 //!! Since this method is based on the current focus it is somewhat
29 //!! unreliable and may return unexpected 0 pointers!
30 SmViewShell
* SmGetActiveView()
32 SfxViewShell
*pView
= SfxViewShell::Current();
33 return dynamic_cast<SmViewShell
*>( pView
);
37 /**************************************************************************/
39 void SmFontPickList::Clear()
44 SmFontPickList
& SmFontPickList::operator = (const SmFontPickList
& rList
)
47 nMaxItems
= rList
.nMaxItems
;
48 for (const auto & nPos
: rList
.aFontVec
)
49 aFontVec
.push_back( nPos
);
54 vcl::Font
SmFontPickList::Get(sal_uInt16 nPos
) const
56 return nPos
< aFontVec
.size() ? aFontVec
[nPos
] : vcl::Font();
61 bool lcl_CompareItem(const vcl::Font
& rFirstFont
, const vcl::Font
& rSecondFont
)
63 return rFirstFont
.GetFamilyName() == rSecondFont
.GetFamilyName() &&
64 rFirstFont
.GetFamilyType() == rSecondFont
.GetFamilyType() &&
65 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
66 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
67 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
70 OUString
lcl_GetStringItem(const vcl::Font
&rFont
)
72 OUStringBuffer
aString(rFont
.GetFamilyName());
74 if (IsItalic( rFont
))
77 aString
.append(SmResId(RID_FONTITALIC
));
82 aString
.append(SmResId(RID_FONTBOLD
));
85 return aString
.makeStringAndClear();
90 void SmFontPickList::Insert(const vcl::Font
&rFont
)
92 for (size_t nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
93 if (lcl_CompareItem( aFontVec
[nPos
], rFont
))
95 aFontVec
.erase( aFontVec
.begin() + nPos
);
99 aFontVec
.push_front( rFont
);
101 if (aFontVec
.size() > nMaxItems
)
107 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
109 Insert(rDialog
.GetFont());
112 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
114 rDialog
.SetFont(Get());
118 /**************************************************************************/
120 SmFontPickListBox::SmFontPickListBox(std::unique_ptr
<weld::ComboBox
> pWidget
)
122 , m_xWidget(std::move(pWidget
))
124 m_xWidget
->connect_changed(LINK(this, SmFontPickListBox
, SelectHdl
));
127 IMPL_LINK_NOARG(SmFontPickListBox
, SelectHdl
, weld::ComboBox
&, void)
129 const int nPos
= m_xWidget
->get_active();
132 SmFontPickList::Insert(Get(nPos
));
133 OUString aString
= m_xWidget
->get_text(nPos
);
134 m_xWidget
->remove(nPos
);
135 m_xWidget
->insert_text(0, aString
);
138 m_xWidget
->set_active(0);
141 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
143 *static_cast<SmFontPickList
*>(this) = rList
;
145 for (decltype(aFontVec
)::size_type nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
146 m_xWidget
->insert_text(nPos
, lcl_GetStringItem(aFontVec
[nPos
]));
148 if (!aFontVec
.empty())
149 m_xWidget
->set_active_text(lcl_GetStringItem(aFontVec
.front()));
154 void SmFontPickListBox::Insert(const vcl::Font
&rFont
)
156 SmFontPickList::Insert(rFont
);
158 OUString
aEntry(lcl_GetStringItem(aFontVec
.front()));
159 int nPos
= m_xWidget
->find_text(aEntry
);
161 m_xWidget
->remove(nPos
);
162 m_xWidget
->insert_text(0, aEntry
);
163 m_xWidget
->set_active(0);
165 while (m_xWidget
->get_count() > nMaxItems
)
166 m_xWidget
->remove(m_xWidget
->get_count() - 1);
169 bool IsItalic( const vcl::Font
&rFont
)
171 FontItalic eItalic
= rFont
.GetItalic();
172 // the code below leaves only _NONE and _DONTKNOW as not italic
173 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
177 bool IsBold( const vcl::Font
&rFont
)
179 FontWeight eWeight
= rFont
.GetWeight();
180 return eWeight
> WEIGHT_NORMAL
;
184 void SmFace::Impl_Init()
186 SetSize( GetFontSize() );
187 SetTransparent( true );
188 SetAlignment( ALIGN_BASELINE
);
189 SetColor( COL_AUTO
);
192 void SmFace::SetSize(const Size
& rSize
)
196 // check the requested size against minimum value
197 static int const nMinVal
= SmPtsTo100th_mm(2);
199 if (aSize
.Height() < nMinVal
)
200 aSize
.setHeight( nMinVal
);
202 //! we don't force a maximum value here because this may prevent eg the
203 //! parentheses in "left ( ... right )" from matching up with large
204 //! bodies (eg stack{...} with many entries).
205 //! Of course this is holds only if characters are used and not polygons.
207 Font::SetFontSize(aSize
);
211 tools::Long
SmFace::GetBorderWidth() const
213 if (nBorderWidth
< 0)
214 return GetDefaultBorderWidth();
219 SmFace
& SmFace::operator = (const SmFace
&rFace
)
221 Font::operator = (rFace
);
227 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
228 // scales the width and height of 'rFace' by 'rFrac' and returns a
229 // reference to 'rFace'.
230 // It's main use is to make scaling fonts look easier.
231 { const Size
&rFaceSize
= rFace
.GetFontSize();
233 rFace
.SetSize(Size(tools::Long(rFaceSize
.Width() * rFrac
),
234 tools::Long(rFaceSize
.Height() * rFrac
)));
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */