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 #include <comphelper/lok.hxx>
27 #include <sfx2/lokcomponenthelpers.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 SmViewShell
* pSmView
= dynamic_cast<SmViewShell
*>(pView
);
37 if (!pSmView
&& comphelper::LibreOfficeKit::isActive())
39 auto* pWindow
= static_cast<SmGraphicWindow
*>(LokStarMathHelper(pView
).GetGraphicWindow());
41 pSmView
= &pWindow
->GetGraphicWidget().GetView();
47 /**************************************************************************/
49 void SmFontPickList::Clear()
54 SmFontPickList
& SmFontPickList::operator = (const SmFontPickList
& rList
)
57 nMaxItems
= rList
.nMaxItems
;
58 aFontVec
= rList
.aFontVec
;
63 vcl::Font
SmFontPickList::Get(sal_uInt16 nPos
) const
65 return nPos
< aFontVec
.size() ? aFontVec
[nPos
] : vcl::Font();
70 bool lcl_CompareItem(const vcl::Font
& rFirstFont
, const vcl::Font
& rSecondFont
)
72 return rFirstFont
.GetFamilyName() == rSecondFont
.GetFamilyName() &&
73 rFirstFont
.GetFamilyType() == rSecondFont
.GetFamilyType() &&
74 rFirstFont
.GetCharSet() == rSecondFont
.GetCharSet() &&
75 rFirstFont
.GetWeight() == rSecondFont
.GetWeight() &&
76 rFirstFont
.GetItalic() == rSecondFont
.GetItalic();
79 OUString
lcl_GetStringItem(const vcl::Font
&rFont
)
81 OUStringBuffer
aString(rFont
.GetFamilyName());
83 if (IsItalic( rFont
))
86 aString
.append(SmResId(RID_FONTITALIC
));
91 aString
.append(SmResId(RID_FONTBOLD
));
94 return aString
.makeStringAndClear();
99 void SmFontPickList::Insert(const vcl::Font
&rFont
)
101 for (size_t nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
102 if (lcl_CompareItem( aFontVec
[nPos
], rFont
))
104 aFontVec
.erase( aFontVec
.begin() + nPos
);
108 aFontVec
.push_front( rFont
);
110 if (aFontVec
.size() > nMaxItems
)
116 void SmFontPickList::ReadFrom(const SmFontDialog
& rDialog
)
118 Insert(rDialog
.GetFont());
121 void SmFontPickList::WriteTo(SmFontDialog
& rDialog
) const
123 rDialog
.SetFont(Get());
127 /**************************************************************************/
129 SmFontPickListBox::SmFontPickListBox(std::unique_ptr
<weld::ComboBox
> pWidget
)
131 , m_xWidget(std::move(pWidget
))
133 m_xWidget
->connect_changed(LINK(this, SmFontPickListBox
, SelectHdl
));
136 IMPL_LINK_NOARG(SmFontPickListBox
, SelectHdl
, weld::ComboBox
&, void)
138 const int nPos
= m_xWidget
->get_active();
141 SmFontPickList::Insert(Get(nPos
));
142 OUString aString
= m_xWidget
->get_text(nPos
);
143 m_xWidget
->remove(nPos
);
144 m_xWidget
->insert_text(0, aString
);
147 m_xWidget
->set_active(0);
150 SmFontPickListBox
& SmFontPickListBox::operator=(const SmFontPickList
& rList
)
152 *static_cast<SmFontPickList
*>(this) = rList
;
154 for (decltype(aFontVec
)::size_type nPos
= 0; nPos
< aFontVec
.size(); nPos
++)
155 m_xWidget
->insert_text(nPos
, lcl_GetStringItem(aFontVec
[nPos
]));
157 if (!aFontVec
.empty())
158 m_xWidget
->set_active_text(lcl_GetStringItem(aFontVec
.front()));
163 void SmFontPickListBox::Insert(const vcl::Font
&rFont
)
165 SmFontPickList::Insert(rFont
);
167 OUString
aEntry(lcl_GetStringItem(aFontVec
.front()));
168 int nPos
= m_xWidget
->find_text(aEntry
);
170 m_xWidget
->remove(nPos
);
171 m_xWidget
->insert_text(0, aEntry
);
172 m_xWidget
->set_active(0);
174 while (m_xWidget
->get_count() > nMaxItems
)
175 m_xWidget
->remove(m_xWidget
->get_count() - 1);
178 bool IsItalic( const vcl::Font
&rFont
)
180 FontItalic eItalic
= rFont
.GetItalic();
181 // the code below leaves only _NONE and _DONTKNOW as not italic
182 return eItalic
== ITALIC_OBLIQUE
|| eItalic
== ITALIC_NORMAL
;
186 bool IsBold( const vcl::Font
&rFont
)
188 FontWeight eWeight
= rFont
.GetWeight();
189 return eWeight
> WEIGHT_NORMAL
;
193 void SmFace::Impl_Init()
195 SetSize( GetFontSize() );
196 SetTransparent( true );
197 SetAlignment( ALIGN_BASELINE
);
198 SetColor( COL_AUTO
);
201 void SmFace::SetSize(const Size
& rSize
)
205 // check the requested size against minimum value
206 const int nMinVal
= o3tl::convert(2, o3tl::Length::pt
, SmO3tlLengthUnit());
208 if (aSize
.Height() < nMinVal
)
209 aSize
.setHeight( nMinVal
);
211 //! we don't force a maximum value here because this may prevent eg the
212 //! parentheses in "left ( ... right )" from matching up with large
213 //! bodies (eg stack{...} with many entries).
214 //! Of course this is holds only if characters are used and not polygons.
216 Font::SetFontSize(aSize
);
220 tools::Long
SmFace::GetBorderWidth() const
222 if (nBorderWidth
< 0)
223 return GetDefaultBorderWidth();
228 SmFace
& SmFace::operator = (const SmFace
&rFace
)
230 Font::operator = (rFace
);
236 SmFace
& operator *= (SmFace
&rFace
, const Fraction
&rFrac
)
237 // scales the width and height of 'rFace' by 'rFrac' and returns a
238 // reference to 'rFace'.
239 // It's main use is to make scaling fonts look easier.
240 { const Size
&rFaceSize
= rFace
.GetFontSize();
242 rFace
.SetSize(Size(tools::Long(rFaceSize
.Width() * rFrac
),
243 tools::Long(rFaceSize
.Height() * rFrac
)));
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */