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 <strings.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();
64 bool lcl_CompareItem(const vcl::Font
& rFirstFont
, const vcl::Font
& rSecondFont
)
66 return rFirstFont
.GetFamilyName() == rSecondFont
.GetFamilyName() &&
67 rFirstFont
.GetFamilyType() == rSecondFont
.GetFamilyType() &&
68 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
69 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
70 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
73 OUString
lcl_GetStringItem(const vcl::Font
&rFont
)
75 OUStringBuffer
aString(rFont
.GetFamilyName());
77 if (IsItalic( rFont
))
80 aString
.append(SmResId(RID_FONTITALIC
));
85 aString
.append(SmResId(RID_FONTBOLD
));
88 return aString
.makeStringAndClear();
93 void SmFontPickList::Insert(const vcl::Font
&rFont
)
95 for (size_t nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
96 if (lcl_CompareItem( aFontVec
[nPos
], rFont
))
98 aFontVec
.erase( aFontVec
.begin() + nPos
);
102 aFontVec
.push_front( rFont
);
104 if (aFontVec
.size() > nMaxItems
)
110 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
112 Insert(rDialog
.GetFont());
115 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
117 rDialog
.SetFont(Get());
121 /**************************************************************************/
123 SmFontPickListBox::SmFontPickListBox(weld::ComboBoxText
* pWidget
)
127 m_xWidget
->connect_changed(LINK(this, SmFontPickListBox
, SelectHdl
));
130 IMPL_LINK_NOARG(SmFontPickListBox
, SelectHdl
, weld::ComboBoxText
&, void)
134 const int nPos
= m_xWidget
->get_active();
137 SmFontPickList::Insert(Get(nPos
));
138 aString
= m_xWidget
->get_text(nPos
);
139 m_xWidget
->remove(nPos
);
140 m_xWidget
->insert_text(0, aString
);
143 m_xWidget
->set_active(0);
146 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
148 *static_cast<SmFontPickList
*>(this) = rList
;
150 for (decltype(aFontVec
)::size_type nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
151 m_xWidget
->insert_text(nPos
, lcl_GetStringItem(aFontVec
[nPos
]));
153 if (!aFontVec
.empty())
154 m_xWidget
->set_active_text(lcl_GetStringItem(aFontVec
.front()));
159 void SmFontPickListBox::Insert(const vcl::Font
&rFont
)
161 SmFontPickList::Insert(rFont
);
163 OUString
aEntry(lcl_GetStringItem(aFontVec
.front()));
164 int nPos
= m_xWidget
->find_text(aEntry
);
166 m_xWidget
->remove(nPos
);
167 m_xWidget
->insert_text(0, aEntry
);
168 m_xWidget
->set_active(0);
170 while (m_xWidget
->get_count() > nMaxItems
)
171 m_xWidget
->remove(m_xWidget
->get_count() - 1);
174 bool IsItalic( const vcl::Font
&rFont
)
176 FontItalic eItalic
= rFont
.GetItalic();
177 // the code below leaves only _NONE and _DONTKNOW as not italic
178 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
182 bool IsBold( const vcl::Font
&rFont
)
184 FontWeight eWeight
= rFont
.GetWeight();
185 return eWeight
!= WEIGHT_DONTKNOW
&& eWeight
> WEIGHT_NORMAL
;
189 void SmFace::Impl_Init()
191 SetSize( GetFontSize() );
192 SetTransparent( true );
193 SetAlignment( ALIGN_BASELINE
);
194 SetColor( COL_AUTO
);
197 void SmFace::SetSize(const Size
& rSize
)
201 // check the requested size against minimum value
202 static int const nMinVal
= SmPtsTo100th_mm(2);
204 if (aSize
.Height() < nMinVal
)
205 aSize
.setHeight( nMinVal
);
207 //! we don't force a maximum value here because this may prevent eg the
208 //! parentheses in "left ( ... right )" from matching up with large
209 //! bodies (eg stack{...} with many entries).
210 //! Of course this is holds only if characters are used and not polygons.
212 Font::SetFontSize(aSize
);
216 long SmFace::GetBorderWidth() const
218 if (nBorderWidth
< 0)
219 return GetDefaultBorderWidth();
224 SmFace
& SmFace::operator = (const SmFace
&rFace
)
226 Font::operator = (rFace
);
232 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
233 // scales the width and height of 'rFace' by 'rFrac' and returns a
234 // reference to 'rFace'.
235 // It's main use is to make scaling fonts look easier.
236 { const Size
&rFaceSize
= rFace
.GetFontSize();
238 rFace
.SetSize(Size(long(rFaceSize
.Width() * rFrac
),
239 long(rFaceSize
.Height() * rFrac
)));
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */