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 <sal/config.h>
21 #include <sal/log.hxx>
23 #include <comphelper/string.hxx>
24 #include <o3tl/temporary.hxx>
25 #include <svl/eitem.hxx>
26 #include <svl/intitem.hxx>
27 #include <svl/stritem.hxx>
28 #include <vcl/event.hxx>
29 #include <vcl/svapp.hxx>
30 #include <vcl/virdev.hxx>
31 #include <vcl/weld.hxx>
32 #include <svtools/ctrltool.hxx>
33 #include <vcl/settings.hxx>
34 #include <vcl/wall.hxx>
35 #include <vcl/fontcharmap.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <svx/charmap.hxx>
38 #include <svx/ucsubset.hxx>
41 #include <starmath.hrc>
42 #include <strings.hrc>
44 #include <cfgitem.hxx>
54 void lclGetSettingColors(Color
& rBackgroundColor
, Color
& rTextColor
)
56 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
57 if (rStyleSettings
.GetHighContrastMode())
59 rBackgroundColor
= rStyleSettings
.GetFieldColor();
60 rTextColor
= rStyleSettings
.GetFieldTextColor();
64 rBackgroundColor
= rStyleSettings
.GetFaceColor();
65 rTextColor
= rStyleSettings
.GetLabelTextColor();
69 // Since it's better to set/query the FontStyle via its attributes rather
70 // than via the StyleName we create a way to translate
71 // Attribute <-> StyleName
83 static sal_uInt16
GetCount() { return 4; }
84 const OUString
& GetStyleName(const vcl::Font
& rFont
) const;
85 const OUString
& GetStyleName(sal_uInt16 nIdx
) const;
88 } // end anonymous namespace
90 SmFontStyles::SmFontStyles()
91 : aNormal(SmResId(RID_FONTREGULAR
))
92 , aBold(SmResId(RID_FONTBOLD
))
93 , aItalic(SmResId(RID_FONTITALIC
))
97 aBoldItalic
+= aItalic
;
100 const OUString
& SmFontStyles::GetStyleName(const vcl::Font
& rFont
) const
102 //! compare also SmSpecialNode::Prepare
103 bool bBold
= IsBold( rFont
),
104 bItalic
= IsItalic( rFont
);
106 if (bBold
&& bItalic
)
115 const OUString
& SmFontStyles::GetStyleName( sal_uInt16 nIdx
) const
117 // 0 = "normal", 1 = "italic",
118 // 2 = "bold", 3 = "bold italic"
120 assert( nIdx
< GetCount() );
123 case 0 : return aNormal
;
124 case 1 : return aItalic
;
125 case 2 : return aBold
;
126 default: /*case 3:*/ return aBoldItalic
;
130 static const SmFontStyles
& GetFontStyles()
132 static const SmFontStyles aImpl
;
136 void SetFontStyle(std::u16string_view rStyleName
, vcl::Font
&rFont
)
138 // Find index related to StyleName. For an empty StyleName it's assumed to be
139 // 0 (neither bold nor italic).
140 sal_uInt16 nIndex
= 0;
141 if (!rStyleName
.empty())
144 const SmFontStyles
&rStyles
= GetFontStyles();
145 for (i
= 0; i
< SmFontStyles::GetCount(); ++i
)
146 if (rStyleName
== rStyles
.GetStyleName(i
))
148 assert(i
< SmFontStyles::GetCount() && "style-name unknown");
152 rFont
.SetItalic((nIndex
& 0x1) ? ITALIC_NORMAL
: ITALIC_NONE
);
153 rFont
.SetWeight((nIndex
& 0x2) ? WEIGHT_BOLD
: WEIGHT_NORMAL
);
156 IMPL_LINK_NOARG(SmPrintOptionsTabPage
, SizeButtonClickHdl
, weld::Toggleable
&, void)
158 m_xZoom
->set_sensitive(m_xSizeZoomed
->get_active());
161 SmPrintOptionsTabPage::SmPrintOptionsTabPage(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rOptions
)
162 : SfxTabPage(pPage
, pController
, "modules/smath/ui/smathsettings.ui", "SmathSettings", &rOptions
)
163 , m_xTitle(m_xBuilder
->weld_check_button("title"))
164 , m_xText(m_xBuilder
->weld_check_button("text"))
165 , m_xFrame(m_xBuilder
->weld_check_button("frame"))
166 , m_xSizeNormal(m_xBuilder
->weld_radio_button("sizenormal"))
167 , m_xSizeScaled(m_xBuilder
->weld_radio_button("sizescaled"))
168 , m_xSizeZoomed(m_xBuilder
->weld_radio_button("sizezoomed"))
169 , m_xZoom(m_xBuilder
->weld_metric_spin_button("zoom", FieldUnit::PERCENT
))
170 , m_xNoRightSpaces(m_xBuilder
->weld_check_button("norightspaces"))
171 , m_xSaveOnlyUsedSymbols(m_xBuilder
->weld_check_button("saveonlyusedsymbols"))
172 , m_xAutoCloseBrackets(m_xBuilder
->weld_check_button("autoclosebrackets"))
173 , m_xSmZoom(m_xBuilder
->weld_metric_spin_button("smzoom", FieldUnit::PERCENT
))
175 m_xSizeNormal
->connect_toggled(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
176 m_xSizeScaled
->connect_toggled(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
177 m_xSizeZoomed
->connect_toggled(LINK(this, SmPrintOptionsTabPage
, SizeButtonClickHdl
));
182 SmPrintOptionsTabPage::~SmPrintOptionsTabPage()
184 if (SmViewShell
*pViewSh
= SmGetActiveView())
185 if (SmEditWindow
* pEdit
= pViewSh
->GetEditWindow())
186 pEdit
->UpdateStatus();
189 bool SmPrintOptionsTabPage::FillItemSet(SfxItemSet
* rSet
)
191 sal_uInt16 nPrintSize
;
192 if (m_xSizeNormal
->get_active())
193 nPrintSize
= PRINT_SIZE_NORMAL
;
194 else if (m_xSizeScaled
->get_active())
195 nPrintSize
= PRINT_SIZE_SCALED
;
197 nPrintSize
= PRINT_SIZE_ZOOMED
;
199 rSet
->Put(SfxUInt16Item(SID_PRINTSIZE
, nPrintSize
));
200 rSet
->Put(SfxUInt16Item(SID_PRINTZOOM
, sal::static_int_cast
<sal_uInt16
>(m_xZoom
->get_value(FieldUnit::PERCENT
))));
201 rSet
->Put(SfxBoolItem(SID_PRINTTITLE
, m_xTitle
->get_active()));
202 rSet
->Put(SfxBoolItem(SID_PRINTTEXT
, m_xText
->get_active()));
203 rSet
->Put(SfxBoolItem(SID_PRINTFRAME
, m_xFrame
->get_active()));
204 rSet
->Put(SfxBoolItem(SID_NO_RIGHT_SPACES
, m_xNoRightSpaces
->get_active()));
205 rSet
->Put(SfxBoolItem(SID_SAVE_ONLY_USED_SYMBOLS
, m_xSaveOnlyUsedSymbols
->get_active()));
206 rSet
->Put(SfxBoolItem(SID_AUTO_CLOSE_BRACKETS
, m_xAutoCloseBrackets
->get_active()));
207 rSet
->Put(SfxUInt16Item(SID_SMEDITWINDOWZOOM
, sal::static_int_cast
<sal_uInt16
>(m_xSmZoom
->get_value(FieldUnit::PERCENT
))));
209 if (SmViewShell
*pViewSh
= SmGetActiveView())
210 if (SmEditWindow
* pEdit
= pViewSh
->GetEditWindow())
211 pEdit
->UpdateStatus();
216 void SmPrintOptionsTabPage::Reset(const SfxItemSet
* rSet
)
218 SmPrintSize ePrintSize
= static_cast<SmPrintSize
>(rSet
->Get(SID_PRINTSIZE
).GetValue());
220 m_xSizeNormal
->set_active(ePrintSize
== PRINT_SIZE_NORMAL
);
221 m_xSizeScaled
->set_active(ePrintSize
== PRINT_SIZE_SCALED
);
222 m_xSizeZoomed
->set_active(ePrintSize
== PRINT_SIZE_ZOOMED
);
224 m_xZoom
->set_sensitive(m_xSizeZoomed
->get_active());
226 m_xZoom
->set_value(rSet
->Get(SID_PRINTZOOM
).GetValue(), FieldUnit::PERCENT
);
228 m_xSmZoom
->set_sensitive(true);
229 m_xSmZoom
->set_value(rSet
->Get(SID_SMEDITWINDOWZOOM
).GetValue(), FieldUnit::PERCENT
);
231 m_xTitle
->set_active(rSet
->Get(SID_PRINTTITLE
).GetValue());
232 m_xNoRightSpaces
->set_active(rSet
->Get(SID_NO_RIGHT_SPACES
).GetValue());
233 m_xSaveOnlyUsedSymbols
->set_active(rSet
->Get(SID_SAVE_ONLY_USED_SYMBOLS
).GetValue());
234 m_xAutoCloseBrackets
->set_active(rSet
->Get(SID_AUTO_CLOSE_BRACKETS
).GetValue());
237 std::unique_ptr
<SfxTabPage
> SmPrintOptionsTabPage::Create(weld::Container
* pPage
, weld::DialogController
* pController
, const SfxItemSet
& rSet
)
239 return std::make_unique
<SmPrintOptionsTabPage
>(pPage
, pController
, rSet
);
242 void SmShowFont::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& /*rRect*/)
246 lclGetSettingColors(aBackColor
, aTextColor
);
248 rRenderContext
.SetBackground(Wallpaper(aBackColor
));
250 vcl::Font
aFont(maFont
);
251 aFont
.SetFontSize(Size(0, 24 * rRenderContext
.GetDPIScaleFactor()));
252 aFont
.SetAlignment(ALIGN_TOP
);
253 rRenderContext
.SetFont(aFont
);
254 rRenderContext
.SetTextColor(aTextColor
);
256 OUString
sText(rRenderContext
.GetFont().GetFamilyName());
257 Size
aTextSize(rRenderContext
.GetTextWidth(sText
), rRenderContext
.GetTextHeight());
259 rRenderContext
.DrawText(Point((rRenderContext
.GetOutputSize().Width() - aTextSize
.Width()) / 2,
260 (rRenderContext
.GetOutputSize().Height() - aTextSize
.Height()) / 2), sText
);
263 void SmShowFont::SetDrawingArea(weld::DrawingArea
* pDrawingArea
)
265 CustomWidgetController::SetDrawingArea(pDrawingArea
);
266 Size
aSize(pDrawingArea
->get_ref_device().LogicToPixel(Size(111 , 31), MapMode(MapUnit::MapAppFont
)));
267 pDrawingArea
->set_size_request(aSize
.Width(), aSize
.Height());
270 void SmShowFont::SetFont(const vcl::Font
& rFont
)
276 IMPL_LINK( SmFontDialog
, FontSelectHdl
, weld::ComboBox
&, rComboBox
, void )
278 maFont
.SetFamilyName(rComboBox
.get_active_text());
279 m_aShowFont
.SetFont(maFont
);
282 IMPL_LINK_NOARG(SmFontDialog
, AttrChangeHdl
, weld::Toggleable
&, void)
284 if (m_xBoldCheckBox
->get_active())
285 maFont
.SetWeight(WEIGHT_BOLD
);
287 maFont
.SetWeight(WEIGHT_NORMAL
);
289 if (m_xItalicCheckBox
->get_active())
290 maFont
.SetItalic(ITALIC_NORMAL
);
292 maFont
.SetItalic(ITALIC_NONE
);
294 m_aShowFont
.SetFont(maFont
);
297 void SmFontDialog::SetFont(const vcl::Font
&rFont
)
301 m_xFontBox
->set_active_text(maFont
.GetFamilyName());
302 m_xBoldCheckBox
->set_active(IsBold(maFont
));
303 m_xItalicCheckBox
->set_active(IsItalic(maFont
));
304 m_aShowFont
.SetFont(maFont
);
307 SmFontDialog::SmFontDialog(weld::Window
* pParent
, OutputDevice
*pFntListDevice
, bool bHideCheckboxes
)
308 : GenericDialogController(pParent
, "modules/smath/ui/fontdialog.ui", "FontDialog")
309 , m_xFontBox(m_xBuilder
->weld_entry_tree_view("fontgrid", "font", "fonts"))
310 , m_xAttrFrame(m_xBuilder
->weld_widget("attrframe"))
311 , m_xBoldCheckBox(m_xBuilder
->weld_check_button("bold"))
312 , m_xItalicCheckBox(m_xBuilder
->weld_check_button("italic"))
313 , m_xShowFont(new weld::CustomWeld(*m_xBuilder
, "preview", m_aShowFont
))
315 m_xFontBox
->set_height_request_by_rows(8);
318 weld::WaitObject
aWait(pParent
);
320 FontList
aFontList( pFntListDevice
);
322 sal_uInt16 nCount
= aFontList
.GetFontNameCount();
323 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
325 m_xFontBox
->append_text(aFontList
.GetFontName(i
).GetFamilyName());
327 maFont
.SetFontSize(Size(0, 24));
328 maFont
.SetWeight(WEIGHT_NORMAL
);
329 maFont
.SetItalic(ITALIC_NONE
);
330 maFont
.SetFamily(FAMILY_DONTKNOW
);
331 maFont
.SetPitch(PITCH_DONTKNOW
);
332 maFont
.SetCharSet(RTL_TEXTENCODING_DONTKNOW
);
333 maFont
.SetTransparent(true);
336 m_xFontBox
->connect_changed(LINK(this, SmFontDialog
, FontSelectHdl
));
337 m_xBoldCheckBox
->connect_toggled(LINK(this, SmFontDialog
, AttrChangeHdl
));
338 m_xItalicCheckBox
->connect_toggled(LINK(this, SmFontDialog
, AttrChangeHdl
));
342 m_xBoldCheckBox
->set_active(false);
343 m_xBoldCheckBox
->set_sensitive(false);
344 m_xItalicCheckBox
->set_active(false);
345 m_xItalicCheckBox
->set_sensitive(false);
346 m_xAttrFrame
->hide();
350 SmFontDialog::~SmFontDialog()
356 class SaveDefaultsQuery
: public weld::MessageDialogController
359 explicit SaveDefaultsQuery(weld::Widget
* pParent
)
360 : MessageDialogController(pParent
, "modules/smath/ui/savedefaultsdialog.ui",
361 "SaveDefaultsDialog")
368 IMPL_LINK_NOARG( SmFontSizeDialog
, DefaultButtonClickHdl
, weld::Button
&, void )
370 SaveDefaultsQuery
aQuery(m_xDialog
.get());
371 if (aQuery
.run() == RET_YES
)
373 SmModule
*pp
= SM_MOD();
374 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
376 pp
->GetConfig()->SetStandardFormat( aFmt
);
380 SmFontSizeDialog::SmFontSizeDialog(weld::Window
* pParent
)
381 : GenericDialogController(pParent
, "modules/smath/ui/fontsizedialog.ui", "FontSizeDialog")
382 , m_xBaseSize(m_xBuilder
->weld_metric_spin_button("spinB_baseSize", FieldUnit::POINT
))
383 , m_xTextSize(m_xBuilder
->weld_metric_spin_button("spinB_text", FieldUnit::PERCENT
))
384 , m_xIndexSize(m_xBuilder
->weld_metric_spin_button("spinB_index", FieldUnit::PERCENT
))
385 , m_xFunctionSize(m_xBuilder
->weld_metric_spin_button("spinB_function", FieldUnit::PERCENT
))
386 , m_xOperatorSize(m_xBuilder
->weld_metric_spin_button("spinB_operator", FieldUnit::PERCENT
))
387 , m_xBorderSize(m_xBuilder
->weld_metric_spin_button("spinB_limit", FieldUnit::PERCENT
))
388 , m_xDefaultButton(m_xBuilder
->weld_button("default"))
390 m_xDefaultButton
->connect_clicked(LINK(this, SmFontSizeDialog
, DefaultButtonClickHdl
));
393 SmFontSizeDialog::~SmFontSizeDialog()
397 void SmFontSizeDialog::ReadFrom(const SmFormat
&rFormat
)
399 //! watch out: round properly!
400 m_xBaseSize
->set_value(
401 o3tl::convert(rFormat
.GetBaseSize().Height(), SmO3tlLengthUnit(), o3tl::Length::pt
),
404 m_xTextSize
->set_value( rFormat
.GetRelSize(SIZ_TEXT
), FieldUnit::NONE
);
405 m_xIndexSize
->set_value( rFormat
.GetRelSize(SIZ_INDEX
), FieldUnit::NONE
);
406 m_xFunctionSize
->set_value( rFormat
.GetRelSize(SIZ_FUNCTION
), FieldUnit::NONE
);
407 m_xOperatorSize
->set_value( rFormat
.GetRelSize(SIZ_OPERATOR
), FieldUnit::NONE
);
408 m_xBorderSize
->set_value( rFormat
.GetRelSize(SIZ_LIMITS
), FieldUnit::NONE
);
411 void SmFontSizeDialog::WriteTo(SmFormat
&rFormat
) const
413 rFormat
.SetBaseSize( Size(0, o3tl::convert(m_xBaseSize
->get_value(FieldUnit::NONE
), o3tl::Length::pt
, SmO3tlLengthUnit())) );
415 rFormat
.SetRelSize(SIZ_TEXT
, sal::static_int_cast
<sal_uInt16
>(m_xTextSize
->get_value(FieldUnit::NONE
)));
416 rFormat
.SetRelSize(SIZ_INDEX
, sal::static_int_cast
<sal_uInt16
>(m_xIndexSize
->get_value(FieldUnit::NONE
)));
417 rFormat
.SetRelSize(SIZ_FUNCTION
, sal::static_int_cast
<sal_uInt16
>(m_xFunctionSize
->get_value(FieldUnit::NONE
)));
418 rFormat
.SetRelSize(SIZ_OPERATOR
, sal::static_int_cast
<sal_uInt16
>(m_xOperatorSize
->get_value(FieldUnit::NONE
)));
419 rFormat
.SetRelSize(SIZ_LIMITS
, sal::static_int_cast
<sal_uInt16
>(m_xBorderSize
->get_value(FieldUnit::NONE
)));
421 const Size
aTmp (rFormat
.GetBaseSize());
422 for (sal_uInt16 i
= FNT_BEGIN
; i
<= FNT_END
; i
++)
423 rFormat
.SetFontSize(i
, aTmp
);
425 rFormat
.RequestApplyChanges();
428 IMPL_LINK(SmFontTypeDialog
, MenuSelectHdl
, const OUString
&, rIdent
, void)
430 SmFontPickListBox
*pActiveListBox
;
432 bool bHideCheckboxes
= false;
433 if (rIdent
== "variables")
434 pActiveListBox
= m_xVariableFont
.get();
435 else if (rIdent
== "functions")
436 pActiveListBox
= m_xFunctionFont
.get();
437 else if (rIdent
== "numbers")
438 pActiveListBox
= m_xNumberFont
.get();
439 else if (rIdent
== "text")
440 pActiveListBox
= m_xTextFont
.get();
441 else if (rIdent
== "serif")
443 pActiveListBox
= m_xSerifFont
.get();
444 bHideCheckboxes
= true;
446 else if (rIdent
== "sansserif")
448 pActiveListBox
= m_xSansFont
.get();
449 bHideCheckboxes
= true;
451 else if (rIdent
== "fixedwidth")
453 pActiveListBox
= m_xFixedFont
.get();
454 bHideCheckboxes
= true;
457 pActiveListBox
= nullptr;
461 SmFontDialog
aFontDialog(m_xDialog
.get(), pFontListDev
, bHideCheckboxes
);
463 pActiveListBox
->WriteTo(aFontDialog
);
464 if (aFontDialog
.run() == RET_OK
)
465 pActiveListBox
->ReadFrom(aFontDialog
);
469 IMPL_LINK_NOARG(SmFontTypeDialog
, DefaultButtonClickHdl
, weld::Button
&, void)
471 SaveDefaultsQuery
aQuery(m_xDialog
.get());
472 if (aQuery
.run() == RET_YES
)
474 SmModule
*pp
= SM_MOD();
475 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
477 pp
->GetConfig()->SetStandardFormat( aFmt
, true );
481 SmFontTypeDialog::SmFontTypeDialog(weld::Window
* pParent
, OutputDevice
*pFntListDevice
)
482 : GenericDialogController(pParent
, "modules/smath/ui/fonttypedialog.ui", "FontsDialog")
483 , pFontListDev(pFntListDevice
)
484 , m_xVariableFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("variableCB")))
485 , m_xFunctionFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("functionCB")))
486 , m_xNumberFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("numberCB")))
487 , m_xTextFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("textCB")))
488 , m_xSerifFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("serifCB")))
489 , m_xSansFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("sansCB")))
490 , m_xFixedFont(new SmFontPickListBox(m_xBuilder
->weld_combo_box("fixedCB")))
491 , m_xMenuButton(m_xBuilder
->weld_menu_button("modify"))
492 , m_xDefaultButton(m_xBuilder
->weld_button("default"))
494 m_xDefaultButton
->connect_clicked(LINK(this, SmFontTypeDialog
, DefaultButtonClickHdl
));
495 m_xMenuButton
->connect_selected(LINK(this, SmFontTypeDialog
, MenuSelectHdl
));
498 SmFontTypeDialog::~SmFontTypeDialog()
502 void SmFontTypeDialog::ReadFrom(const SmFormat
&rFormat
)
504 SmModule
*pp
= SM_MOD();
506 *m_xVariableFont
= pp
->GetConfig()->GetFontPickList(FNT_VARIABLE
);
507 *m_xFunctionFont
= pp
->GetConfig()->GetFontPickList(FNT_FUNCTION
);
508 *m_xNumberFont
= pp
->GetConfig()->GetFontPickList(FNT_NUMBER
);
509 *m_xTextFont
= pp
->GetConfig()->GetFontPickList(FNT_TEXT
);
510 *m_xSerifFont
= pp
->GetConfig()->GetFontPickList(FNT_SERIF
);
511 *m_xSansFont
= pp
->GetConfig()->GetFontPickList(FNT_SANS
);
512 *m_xFixedFont
= pp
->GetConfig()->GetFontPickList(FNT_FIXED
);
514 m_xVariableFont
->Insert( rFormat
.GetFont(FNT_VARIABLE
) );
515 m_xFunctionFont
->Insert( rFormat
.GetFont(FNT_FUNCTION
) );
516 m_xNumberFont
->Insert( rFormat
.GetFont(FNT_NUMBER
) );
517 m_xTextFont
->Insert( rFormat
.GetFont(FNT_TEXT
) );
518 m_xSerifFont
->Insert( rFormat
.GetFont(FNT_SERIF
) );
519 m_xSansFont
->Insert( rFormat
.GetFont(FNT_SANS
) );
520 m_xFixedFont
->Insert( rFormat
.GetFont(FNT_FIXED
) );
524 void SmFontTypeDialog::WriteTo(SmFormat
&rFormat
) const
526 SmModule
*pp
= SM_MOD();
528 pp
->GetConfig()->GetFontPickList(FNT_VARIABLE
) = *m_xVariableFont
;
529 pp
->GetConfig()->GetFontPickList(FNT_FUNCTION
) = *m_xFunctionFont
;
530 pp
->GetConfig()->GetFontPickList(FNT_NUMBER
) = *m_xNumberFont
;
531 pp
->GetConfig()->GetFontPickList(FNT_TEXT
) = *m_xTextFont
;
532 pp
->GetConfig()->GetFontPickList(FNT_SERIF
) = *m_xSerifFont
;
533 pp
->GetConfig()->GetFontPickList(FNT_SANS
) = *m_xSansFont
;
534 pp
->GetConfig()->GetFontPickList(FNT_FIXED
) = *m_xFixedFont
;
536 rFormat
.SetFont( FNT_VARIABLE
, m_xVariableFont
->Get() );
537 rFormat
.SetFont( FNT_FUNCTION
, m_xFunctionFont
->Get() );
538 rFormat
.SetFont( FNT_NUMBER
, m_xNumberFont
->Get() );
539 rFormat
.SetFont( FNT_TEXT
, m_xTextFont
->Get() );
540 rFormat
.SetFont( FNT_SERIF
, m_xSerifFont
->Get() );
541 rFormat
.SetFont( FNT_SANS
, m_xSansFont
->Get() );
542 rFormat
.SetFont( FNT_FIXED
, m_xFixedFont
->Get() );
544 rFormat
.RequestApplyChanges();
547 /**************************************************************************/
553 sal_uInt16 nMin
, nMax
;
558 // Data for min and max values of the 4 metric fields
559 // for each of the 10 categories
560 const FieldMinMax pMinMaxData
[10][4] =
563 {{ 0, 200 }, { 0, 200 }, { 0, 100 }, { 0, 0 }},
565 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
567 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
569 {{ 0, 100 }, { 1, 100 }, { 0, 0 }, { 0, 0 }},
571 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
573 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 100 }},
575 {{ 0, 300 }, { 0, 300 }, { 0, 0 }, { 0, 0 }},
577 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
579 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
581 {{ 0, 10000 }, { 0, 10000 }, { 0, 10000 }, { 0, 10000 }}
584 SmCategoryDesc::SmCategoryDesc(weld::Builder
& rBuilder
, sal_uInt16 nCategoryIdx
)
587 std::unique_ptr
<weld::Label
> xTitle(rBuilder
.weld_label(OUString::number(nCategoryIdx
)+"title"));
590 Name
= xTitle
->get_label();
592 for (int i
= 0; i
< 4; ++i
)
594 std::unique_ptr
<weld::Label
> xLabel(rBuilder
.weld_label(OUString::number(nCategoryIdx
)+"label"+OUString::number(i
+1)));
598 Strings
[i
] = xLabel
->get_label();
599 Graphics
[i
] = rBuilder
.weld_widget(OUString::number(nCategoryIdx
)+"image"+OUString::number(i
+1));
607 const FieldMinMax
& rMinMax
= pMinMaxData
[ nCategoryIdx
-1 ][i
];
608 Value
[i
] = Minimum
[i
] = rMinMax
.nMin
;
609 Maximum
[i
] = rMinMax
.nMax
;
613 SmCategoryDesc::~SmCategoryDesc()
617 /**************************************************************************/
619 IMPL_LINK( SmDistanceDialog
, GetFocusHdl
, weld::Widget
&, rControl
, void )
621 if (!m_xCategories
[nActiveCategory
])
626 if (&rControl
== &m_xMetricField1
->get_widget())
628 else if (&rControl
== &m_xMetricField2
->get_widget())
630 else if (&rControl
== &m_xMetricField3
->get_widget())
632 else if (&rControl
== &m_xMetricField4
->get_widget())
637 m_pCurrentImage
->hide();
638 m_pCurrentImage
= m_xCategories
[nActiveCategory
]->GetGraphic(i
);
639 m_pCurrentImage
->show();
642 IMPL_LINK(SmDistanceDialog
, MenuSelectHdl
, const OUString
&, rId
, void)
644 assert(rId
.startsWith("menuitem"));
645 SetCategory(rId
.replaceFirst("menuitem", "").toInt32() - 1);
648 IMPL_LINK_NOARG( SmDistanceDialog
, DefaultButtonClickHdl
, weld::Button
&, void )
650 SaveDefaultsQuery
aQuery(m_xDialog
.get());
651 if (aQuery
.run() == RET_YES
)
653 SmModule
*pp
= SM_MOD();
654 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
656 pp
->GetConfig()->SetStandardFormat( aFmt
);
660 IMPL_LINK( SmDistanceDialog
, CheckBoxClickHdl
, weld::Toggleable
&, rCheckBox
, void )
662 if (&rCheckBox
== m_xCheckBox1
.get())
664 bool bChecked
= m_xCheckBox1
->get_active();
665 m_xFixedText4
->set_sensitive( bChecked
);
666 m_xMetricField4
->set_sensitive( bChecked
);
670 void SmDistanceDialog::SetCategory(sal_uInt16 nCategory
)
672 assert(nCategory
< NOCATEGORIES
&& "Sm: wrong category number in SmDistanceDialog");
674 // array to convert category- and metricfield-number in help ids.
675 // 0 is used in case of unused combinations.
676 assert(NOCATEGORIES
== 10 && "Sm : array doesn't fit into the number of categories");
677 static constexpr OUStringLiteral
EMPTY(u
"");
678 static constexpr rtl::OUStringConstExpr aCatMf2Hid
[10][4] =
680 { HID_SMA_DEFAULT_DIST
, HID_SMA_LINE_DIST
, HID_SMA_ROOT_DIST
, EMPTY
},
681 { HID_SMA_SUP_DIST
, HID_SMA_SUB_DIST
, EMPTY
, EMPTY
},
682 { HID_SMA_NUMERATOR_DIST
, HID_SMA_DENOMINATOR_DIST
, EMPTY
, EMPTY
},
683 { HID_SMA_FRACLINE_EXCWIDTH
, HID_SMA_FRACLINE_LINEWIDTH
, EMPTY
, EMPTY
},
684 { HID_SMA_UPPERLIMIT_DIST
, HID_SMA_LOWERLIMIT_DIST
, EMPTY
, EMPTY
},
685 { HID_SMA_BRACKET_EXCHEIGHT
, HID_SMA_BRACKET_DIST
, EMPTY
, HID_SMA_BRACKET_EXCHEIGHT2
},
686 { HID_SMA_MATRIXROW_DIST
, HID_SMA_MATRIXCOL_DIST
, EMPTY
, EMPTY
},
687 { HID_SMA_ATTRIBUT_DIST
, HID_SMA_INTERATTRIBUT_DIST
, EMPTY
, EMPTY
},
688 { HID_SMA_OPERATOR_EXCHEIGHT
, HID_SMA_OPERATOR_DIST
, EMPTY
, EMPTY
},
689 { HID_SMA_LEFTBORDER_DIST
, HID_SMA_RIGHTBORDER_DIST
, HID_SMA_UPPERBORDER_DIST
, HID_SMA_LOWERBORDER_DIST
}
692 // array to help iterate over the controls
693 std::pair
<weld::Label
*, weld::MetricSpinButton
*> const aWin
[4] =
695 { m_xFixedText1
.get(), m_xMetricField1
.get() },
696 { m_xFixedText2
.get(), m_xMetricField2
.get() },
697 { m_xFixedText3
.get(), m_xMetricField3
.get() },
698 { m_xFixedText4
.get(), m_xMetricField4
.get() }
701 SmCategoryDesc
*pCat
;
703 // remember the (maybe new) settings of the active SmCategoryDesc
704 // before switching to the new one
705 if (nActiveCategory
!= CATEGORY_NONE
)
707 pCat
= m_xCategories
[nActiveCategory
].get();
708 pCat
->SetValue(0, sal::static_int_cast
<sal_uInt16
>(m_xMetricField1
->get_value(FieldUnit::NONE
)));
709 pCat
->SetValue(1, sal::static_int_cast
<sal_uInt16
>(m_xMetricField2
->get_value(FieldUnit::NONE
)));
710 pCat
->SetValue(2, sal::static_int_cast
<sal_uInt16
>(m_xMetricField3
->get_value(FieldUnit::NONE
)));
711 pCat
->SetValue(3, sal::static_int_cast
<sal_uInt16
>(m_xMetricField4
->get_value(FieldUnit::NONE
)));
713 if (nActiveCategory
== 5)
714 bScaleAllBrackets
= m_xCheckBox1
->get_active();
716 m_xMenuButton
->set_item_active("menuitem" + OUString::number(nActiveCategory
+ 1), false);
719 // activation/deactivation of the associated controls depending on the chosen category
721 for (sal_uInt16 i
= 0; i
< 4; i
++)
723 weld::Label
*pFT
= aWin
[i
].first
;
724 weld::MetricSpinButton
*pMF
= aWin
[i
].second
;
726 // To determine which Controls should be active, the existence
727 // of an associated HelpID is checked
728 bActive
= !aCatMf2Hid
[nCategory
][i
].asView().empty();
730 pFT
->set_visible(bActive
);
731 pFT
->set_sensitive(bActive
);
732 pMF
->set_visible(bActive
);
733 pMF
->set_sensitive(bActive
);
735 // set measurement unit and number of decimal places
740 eUnit
= FieldUnit::PERCENT
;
745 eUnit
= FieldUnit::MM_100TH
;
748 pMF
->set_unit(eUnit
); // changes the value
749 pMF
->set_digits(nDigits
);
753 pCat
= m_xCategories
[nCategory
].get();
754 pFT
->set_label(pCat
->GetString(i
));
756 pMF
->set_range(pCat
->GetMinimum(i
), pCat
->GetMaximum(i
), FieldUnit::NONE
);
757 pMF
->set_value(pCat
->GetValue(i
), FieldUnit::NONE
);
759 pMF
->set_help_id(aCatMf2Hid
[nCategory
][i
]);
762 // activate the CheckBox and the associated MetricField if we're dealing with the brackets menu
763 bActive
= nCategory
== 5;
764 m_xCheckBox1
->set_visible(bActive
);
765 m_xCheckBox1
->set_sensitive(bActive
);
768 m_xCheckBox1
->set_active(bScaleAllBrackets
);
770 bool bChecked
= m_xCheckBox1
->get_active();
771 m_xFixedText4
->set_sensitive( bChecked
);
772 m_xMetricField4
->set_sensitive( bChecked
);
775 m_xMenuButton
->set_item_active("menuitem" + OUString::number(nCategory
+ 1), true);
776 m_xFrame
->set_label(m_xCategories
[nCategory
]->GetName());
778 nActiveCategory
= nCategory
;
780 m_xMetricField1
->grab_focus();
783 SmDistanceDialog::SmDistanceDialog(weld::Window
*pParent
)
784 : GenericDialogController(pParent
, "modules/smath/ui/spacingdialog.ui", "SpacingDialog")
785 , m_xFrame(m_xBuilder
->weld_frame("template"))
786 , m_xFixedText1(m_xBuilder
->weld_label("label1"))
787 , m_xMetricField1(m_xBuilder
->weld_metric_spin_button("spinbutton1", FieldUnit::CM
))
788 , m_xFixedText2(m_xBuilder
->weld_label("label2"))
789 , m_xMetricField2(m_xBuilder
->weld_metric_spin_button("spinbutton2", FieldUnit::CM
))
790 , m_xFixedText3(m_xBuilder
->weld_label("label3"))
791 , m_xMetricField3(m_xBuilder
->weld_metric_spin_button("spinbutton3", FieldUnit::CM
))
792 , m_xCheckBox1(m_xBuilder
->weld_check_button("checkbutton"))
793 , m_xFixedText4(m_xBuilder
->weld_label("label4"))
794 , m_xMetricField4(m_xBuilder
->weld_metric_spin_button("spinbutton4", FieldUnit::CM
))
795 , m_xMenuButton(m_xBuilder
->weld_menu_button("category"))
796 , m_xDefaultButton(m_xBuilder
->weld_button("default"))
797 , m_xBitmap(m_xBuilder
->weld_widget("image"))
798 , m_pCurrentImage(m_xBitmap
.get())
800 for (sal_uInt16 i
= 0; i
< NOCATEGORIES
; ++i
)
801 m_xCategories
[i
].reset( new SmCategoryDesc(*m_xBuilder
, i
) );
802 nActiveCategory
= CATEGORY_NONE
;
803 bScaleAllBrackets
= false;
805 m_xMetricField1
->connect_focus_in(LINK(this, SmDistanceDialog
, GetFocusHdl
));
806 m_xMetricField2
->connect_focus_in(LINK(this, SmDistanceDialog
, GetFocusHdl
));
807 m_xMetricField3
->connect_focus_in(LINK(this, SmDistanceDialog
, GetFocusHdl
));
808 m_xMetricField4
->connect_focus_in(LINK(this, SmDistanceDialog
, GetFocusHdl
));
809 m_xCheckBox1
->connect_toggled(LINK(this, SmDistanceDialog
, CheckBoxClickHdl
));
810 m_xMenuButton
->connect_selected(LINK(this, SmDistanceDialog
, MenuSelectHdl
));
811 m_xDefaultButton
->connect_clicked(LINK(this, SmDistanceDialog
, DefaultButtonClickHdl
));
813 //set the initial size, with max visible widgets visible, as preferred size
814 m_xDialog
->set_size_request(-1, m_xDialog
->get_preferred_size().Height());
817 SmDistanceDialog::~SmDistanceDialog()
821 void SmDistanceDialog::ReadFrom(const SmFormat
&rFormat
)
823 m_xCategories
[0]->SetValue(0, rFormat
.GetDistance(DIS_HORIZONTAL
));
824 m_xCategories
[0]->SetValue(1, rFormat
.GetDistance(DIS_VERTICAL
));
825 m_xCategories
[0]->SetValue(2, rFormat
.GetDistance(DIS_ROOT
));
826 m_xCategories
[1]->SetValue(0, rFormat
.GetDistance(DIS_SUPERSCRIPT
));
827 m_xCategories
[1]->SetValue(1, rFormat
.GetDistance(DIS_SUBSCRIPT
));
828 m_xCategories
[2]->SetValue(0, rFormat
.GetDistance(DIS_NUMERATOR
));
829 m_xCategories
[2]->SetValue(1, rFormat
.GetDistance(DIS_DENOMINATOR
));
830 m_xCategories
[3]->SetValue(0, rFormat
.GetDistance(DIS_FRACTION
));
831 m_xCategories
[3]->SetValue(1, rFormat
.GetDistance(DIS_STROKEWIDTH
));
832 m_xCategories
[4]->SetValue(0, rFormat
.GetDistance(DIS_UPPERLIMIT
));
833 m_xCategories
[4]->SetValue(1, rFormat
.GetDistance(DIS_LOWERLIMIT
));
834 m_xCategories
[5]->SetValue(0, rFormat
.GetDistance(DIS_BRACKETSIZE
));
835 m_xCategories
[5]->SetValue(1, rFormat
.GetDistance(DIS_BRACKETSPACE
));
836 m_xCategories
[5]->SetValue(3, rFormat
.GetDistance(DIS_NORMALBRACKETSIZE
));
837 m_xCategories
[6]->SetValue(0, rFormat
.GetDistance(DIS_MATRIXROW
));
838 m_xCategories
[6]->SetValue(1, rFormat
.GetDistance(DIS_MATRIXCOL
));
839 m_xCategories
[7]->SetValue(0, rFormat
.GetDistance(DIS_ORNAMENTSIZE
));
840 m_xCategories
[7]->SetValue(1, rFormat
.GetDistance(DIS_ORNAMENTSPACE
));
841 m_xCategories
[8]->SetValue(0, rFormat
.GetDistance(DIS_OPERATORSIZE
));
842 m_xCategories
[8]->SetValue(1, rFormat
.GetDistance(DIS_OPERATORSPACE
));
843 m_xCategories
[9]->SetValue(0, rFormat
.GetDistance(DIS_LEFTSPACE
));
844 m_xCategories
[9]->SetValue(1, rFormat
.GetDistance(DIS_RIGHTSPACE
));
845 m_xCategories
[9]->SetValue(2, rFormat
.GetDistance(DIS_TOPSPACE
));
846 m_xCategories
[9]->SetValue(3, rFormat
.GetDistance(DIS_BOTTOMSPACE
));
848 bScaleAllBrackets
= rFormat
.IsScaleNormalBrackets();
850 // force update (even of category 0) by setting nActiveCategory to a
851 // non-existent category number
852 nActiveCategory
= CATEGORY_NONE
;
857 void SmDistanceDialog::WriteTo(SmFormat
&rFormat
) /*const*/
859 // TODO can they actually be different?
860 // if that's not the case 'const' could be used above!
861 SetCategory(nActiveCategory
);
863 rFormat
.SetDistance( DIS_HORIZONTAL
, m_xCategories
[0]->GetValue(0) );
864 rFormat
.SetDistance( DIS_VERTICAL
, m_xCategories
[0]->GetValue(1) );
865 rFormat
.SetDistance( DIS_ROOT
, m_xCategories
[0]->GetValue(2) );
866 rFormat
.SetDistance( DIS_SUPERSCRIPT
, m_xCategories
[1]->GetValue(0) );
867 rFormat
.SetDistance( DIS_SUBSCRIPT
, m_xCategories
[1]->GetValue(1) );
868 rFormat
.SetDistance( DIS_NUMERATOR
, m_xCategories
[2]->GetValue(0) );
869 rFormat
.SetDistance( DIS_DENOMINATOR
, m_xCategories
[2]->GetValue(1) );
870 rFormat
.SetDistance( DIS_FRACTION
, m_xCategories
[3]->GetValue(0) );
871 rFormat
.SetDistance( DIS_STROKEWIDTH
, m_xCategories
[3]->GetValue(1) );
872 rFormat
.SetDistance( DIS_UPPERLIMIT
, m_xCategories
[4]->GetValue(0) );
873 rFormat
.SetDistance( DIS_LOWERLIMIT
, m_xCategories
[4]->GetValue(1) );
874 rFormat
.SetDistance( DIS_BRACKETSIZE
, m_xCategories
[5]->GetValue(0) );
875 rFormat
.SetDistance( DIS_BRACKETSPACE
, m_xCategories
[5]->GetValue(1) );
876 rFormat
.SetDistance( DIS_MATRIXROW
, m_xCategories
[6]->GetValue(0) );
877 rFormat
.SetDistance( DIS_MATRIXCOL
, m_xCategories
[6]->GetValue(1) );
878 rFormat
.SetDistance( DIS_ORNAMENTSIZE
, m_xCategories
[7]->GetValue(0) );
879 rFormat
.SetDistance( DIS_ORNAMENTSPACE
, m_xCategories
[7]->GetValue(1) );
880 rFormat
.SetDistance( DIS_OPERATORSIZE
, m_xCategories
[8]->GetValue(0) );
881 rFormat
.SetDistance( DIS_OPERATORSPACE
, m_xCategories
[8]->GetValue(1) );
882 rFormat
.SetDistance( DIS_LEFTSPACE
, m_xCategories
[9]->GetValue(0) );
883 rFormat
.SetDistance( DIS_RIGHTSPACE
, m_xCategories
[9]->GetValue(1) );
884 rFormat
.SetDistance( DIS_TOPSPACE
, m_xCategories
[9]->GetValue(2) );
885 rFormat
.SetDistance( DIS_BOTTOMSPACE
, m_xCategories
[9]->GetValue(3) );
886 rFormat
.SetDistance( DIS_NORMALBRACKETSIZE
, m_xCategories
[5]->GetValue(3) );
888 rFormat
.SetScaleNormalBrackets( bScaleAllBrackets
);
890 rFormat
.RequestApplyChanges();
893 IMPL_LINK_NOARG( SmAlignDialog
, DefaultButtonClickHdl
, weld::Button
&, void )
895 SaveDefaultsQuery
aQuery(m_xDialog
.get());
896 if (aQuery
.run() == RET_YES
)
898 SmModule
*pp
= SM_MOD();
899 SmFormat
aFmt( pp
->GetConfig()->GetStandardFormat() );
901 pp
->GetConfig()->SetStandardFormat( aFmt
);
905 SmAlignDialog::SmAlignDialog(weld::Window
* pParent
)
906 : GenericDialogController(pParent
, "modules/smath/ui/alignmentdialog.ui", "AlignmentDialog")
907 , m_xLeft(m_xBuilder
->weld_radio_button("left"))
908 , m_xCenter(m_xBuilder
->weld_radio_button("center"))
909 , m_xRight(m_xBuilder
->weld_radio_button("right"))
910 , m_xDefaultButton(m_xBuilder
->weld_button("default"))
912 m_xDefaultButton
->connect_clicked(LINK(this, SmAlignDialog
, DefaultButtonClickHdl
));
915 SmAlignDialog::~SmAlignDialog()
919 void SmAlignDialog::ReadFrom(const SmFormat
&rFormat
)
921 switch (rFormat
.GetHorAlign())
923 case SmHorAlign::Left
:
924 m_xLeft
->set_active(true);
926 case SmHorAlign::Center
:
927 m_xCenter
->set_active(true);
929 case SmHorAlign::Right
:
930 m_xRight
->set_active(true);
935 void SmAlignDialog::WriteTo(SmFormat
&rFormat
) const
937 if (m_xLeft
->get_active())
938 rFormat
.SetHorAlign(SmHorAlign::Left
);
939 else if (m_xRight
->get_active())
940 rFormat
.SetHorAlign(SmHorAlign::Right
);
942 rFormat
.SetHorAlign(SmHorAlign::Center
);
944 rFormat
.RequestApplyChanges();
947 SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr
<weld::ScrolledWindow
> pScrolledWindow
)
953 , nSelectSymbol(SYMBOL_NONE
)
954 , m_xScrolledWindow(std::move(pScrolledWindow
))
956 m_xScrolledWindow
->connect_vadjustment_changed(LINK(this, SmShowSymbolSet
, ScrollHdl
));
959 Point
SmShowSymbolSet::OffsetPoint(const Point
&rPoint
) const
961 return Point(rPoint
.X() + nXOffset
, rPoint
.Y() + nYOffset
);
964 void SmShowSymbolSet::Resize()
966 CustomWidgetController::Resize();
967 Size
aWinSize(GetOutputSizePixel());
968 if (aWinSize
!= m_aOldSize
)
970 calccols(GetDrawingArea()->get_ref_device());
971 m_aOldSize
= aWinSize
;
975 void SmShowSymbolSet::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
977 Color aBackgroundColor
;
979 lclGetSettingColors(aBackgroundColor
, aTextColor
);
981 rRenderContext
.SetBackground(Wallpaper(aBackgroundColor
));
982 rRenderContext
.SetTextColor(aTextColor
);
984 rRenderContext
.Push(vcl::PushFlags::MAPMODE
);
986 // set MapUnit for which 'nLen' has been calculated
987 rRenderContext
.SetMapMode(MapMode(MapUnit::MapPixel
));
989 sal_uInt16 v
= sal::static_int_cast
< sal_uInt16
>(m_xScrolledWindow
->vadjustment_get_value() * nColumns
);
990 size_t nSymbols
= aSymbolSet
.size();
992 Color
aTxtColor(rRenderContext
.GetTextColor());
993 for (size_t i
= v
; i
< nSymbols
; i
++)
995 SmSym
aSymbol(*aSymbolSet
[i
]);
996 vcl::Font
aFont(aSymbol
.GetFace());
997 aFont
.SetAlignment(ALIGN_TOP
);
999 // taking a FontSize which is a bit smaller (compared to nLen) in order to have a buffer
1000 // (hopefully enough for left and right, too)
1001 aFont
.SetFontSize(Size(0, nLen
- (nLen
/ 3)));
1002 rRenderContext
.SetFont(aFont
);
1004 rRenderContext
.SetTextColor(aTxtColor
);
1007 sal_UCS4 cChar
= aSymbol
.GetCharacter();
1008 OUString
aText(&cChar
, 1);
1009 Size
aSize(rRenderContext
.GetTextWidth( aText
), rRenderContext
.GetTextHeight());
1011 Point
aPoint((nIV
% nColumns
) * nLen
+ (nLen
- aSize
.Width()) / 2,
1012 (nIV
/ nColumns
) * nLen
+ (nLen
- aSize
.Height()) / 2);
1014 rRenderContext
.DrawText(OffsetPoint(aPoint
), aText
);
1017 if (nSelectSymbol
!= SYMBOL_NONE
)
1019 Point
aPoint(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1020 ((nSelectSymbol
- v
) / nColumns
) * nLen
);
1022 rRenderContext
.Invert(tools::Rectangle(OffsetPoint(aPoint
), Size(nLen
, nLen
)));
1026 rRenderContext
.Pop();
1029 bool SmShowSymbolSet::MouseButtonDown(const MouseEvent
& rMEvt
)
1033 Size
aOutputSize(nColumns
* nLen
, nRows
* nLen
);
1034 aOutputSize
.AdjustWidth(nXOffset
);
1035 aOutputSize
.AdjustHeight(nYOffset
);
1036 Point
aPoint(rMEvt
.GetPosPixel());
1037 aPoint
.AdjustX( -nXOffset
);
1038 aPoint
.AdjustY( -nYOffset
);
1040 if (rMEvt
.IsLeft() && tools::Rectangle(Point(0, 0), aOutputSize
).Contains(rMEvt
.GetPosPixel()))
1042 tools::Long nPos
= (aPoint
.Y() / nLen
) * nColumns
+ (aPoint
.X() / nLen
) +
1043 m_xScrolledWindow
->vadjustment_get_value() * nColumns
;
1044 SelectSymbol( sal::static_int_cast
< sal_uInt16
>(nPos
) );
1046 aSelectHdlLink
.Call(*this);
1048 if (rMEvt
.GetClicks() > 1)
1049 aDblClickHdlLink
.Call(*this);
1055 bool SmShowSymbolSet::KeyInput(const KeyEvent
& rKEvt
)
1057 sal_uInt16 n
= nSelectSymbol
;
1059 if (n
!= SYMBOL_NONE
)
1061 switch (rKEvt
.GetKeyCode().GetCode())
1063 case KEY_DOWN
: n
= n
+ nColumns
; break;
1064 case KEY_UP
: n
= n
- nColumns
; break;
1065 case KEY_LEFT
: n
-= 1; break;
1066 case KEY_RIGHT
: n
+= 1; break;
1067 case KEY_HOME
: n
= 0; break;
1068 case KEY_END
: n
= static_cast< sal_uInt16
>(aSymbolSet
.size() - 1); break;
1069 case KEY_PAGEUP
: n
-= nColumns
* nRows
; break;
1070 case KEY_PAGEDOWN
: n
+= nColumns
* nRows
; break;
1078 if (n
>= aSymbolSet
.size())
1082 if ((n
< sal::static_int_cast
<sal_uInt16
>(m_xScrolledWindow
->vadjustment_get_value() * nColumns
)) ||
1083 (n
>= sal::static_int_cast
<sal_uInt16
>((m_xScrolledWindow
->vadjustment_get_value() + nRows
) * nColumns
)))
1085 m_xScrolledWindow
->vadjustment_set_value(n
/ nColumns
);
1090 aSelectHdlLink
.Call(*this);
1095 void SmShowSymbolSet::calccols(const vcl::RenderContext
& rRenderContext
)
1097 // Height of 16pt in pixels (matching 'aOutputSize')
1098 nLen
= rRenderContext
.LogicToPixel(Size(0, 16), MapMode(MapUnit::MapPoint
)).Height();
1100 Size
aOutputSize(GetOutputSizePixel());
1102 nColumns
= aOutputSize
.Width() / nLen
;
1103 nRows
= aOutputSize
.Height() / nLen
;
1104 nColumns
= std::max
<tools::Long
>(1, nColumns
);
1105 nRows
= std::max
<tools::Long
>(1, nRows
);
1107 nXOffset
= (aOutputSize
.Width() - (nColumns
* nLen
)) / 2;
1108 nYOffset
= (aOutputSize
.Height() - (nRows
* nLen
)) / 2;
1110 SetScrollBarRange();
1113 void SmShowSymbolSet::SetSymbolSet(const SymbolPtrVec_t
& rSymbolSet
)
1115 aSymbolSet
= rSymbolSet
;
1116 SetScrollBarRange();
1120 void SmShowSymbolSet::SetScrollBarRange()
1122 const int nLastRow
= (aSymbolSet
.size() - 1 + nColumns
) / nColumns
;
1123 m_xScrolledWindow
->vadjustment_configure(m_xScrolledWindow
->vadjustment_get_value(), 0, nLastRow
, 1, nRows
- 1, nRows
);
1127 void SmShowSymbolSet::SelectSymbol(sal_uInt16 nSymbol
)
1129 int v
= m_xScrolledWindow
->vadjustment_get_value() * nColumns
;
1131 if (nSelectSymbol
!= SYMBOL_NONE
&& nColumns
)
1133 Point
aPoint(OffsetPoint(Point(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1134 ((nSelectSymbol
- v
) / nColumns
) * nLen
)));
1135 Invalidate(tools::Rectangle(aPoint
, Size(nLen
, nLen
)));
1138 if (nSymbol
< aSymbolSet
.size())
1139 nSelectSymbol
= nSymbol
;
1141 if (aSymbolSet
.empty())
1142 nSelectSymbol
= SYMBOL_NONE
;
1144 if (nSelectSymbol
!= SYMBOL_NONE
&& nColumns
)
1146 Point
aPoint(OffsetPoint(Point(((nSelectSymbol
- v
) % nColumns
) * nLen
,
1147 ((nSelectSymbol
- v
) / nColumns
) * nLen
)));
1148 Invalidate(tools::Rectangle(aPoint
, Size(nLen
, nLen
)));
1155 IMPL_LINK_NOARG(SmShowSymbolSet
, ScrollHdl
, weld::ScrolledWindow
&, void)
1160 SmShowSymbol::SmShowSymbol()
1164 void SmShowSymbol::setFontSize(vcl::Font
&rFont
) const
1166 Size
aSize(GetOutputSizePixel());
1167 rFont
.SetFontSize(Size(0, aSize
.Height() - aSize
.Height() / 3));
1170 void SmShowSymbol::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
1172 Color aBackgroundColor
;
1174 lclGetSettingColors(aBackgroundColor
, aTextColor
);
1175 rRenderContext
.SetBackground(Wallpaper(aBackgroundColor
));
1176 rRenderContext
.SetTextColor(aTextColor
);
1177 rRenderContext
.Erase();
1179 vcl::Font
aFont(GetFont());
1181 rRenderContext
.SetFont(aFont
);
1183 const OUString
&rText
= GetText();
1184 Size
aTextSize(rRenderContext
.GetTextWidth(rText
), rRenderContext
.GetTextHeight());
1186 rRenderContext
.DrawText(Point((rRenderContext
.GetOutputSize().Width() - aTextSize
.Width()) / 2,
1187 (rRenderContext
.GetOutputSize().Height() * 7 / 10)), rText
);
1190 bool SmShowSymbol::MouseButtonDown(const MouseEvent
& rMEvt
)
1192 if (rMEvt
.GetClicks() > 1)
1193 aDblClickHdlLink
.Call(*this);
1197 void SmShowSymbol::SetSymbol(const SmSym
*pSymbol
)
1201 vcl::Font
aFont(pSymbol
->GetFace());
1202 aFont
.SetAlignment(ALIGN_BASELINE
);
1205 sal_UCS4 cChar
= pSymbol
->GetCharacter();
1206 OUString
aText(&cChar
, 1);
1213 void SmSymbolDialog::FillSymbolSets()
1214 // populate the entries of possible SymbolsSets in the dialog with
1215 // current values of the SymbolSet manager but selects none of those
1217 m_xSymbolSets
->clear();
1218 m_xSymbolSets
->set_active(-1);
1220 std::set
< OUString
> aSymbolSetNames( rSymbolMgr
.GetSymbolSetNames() );
1221 for (const auto& rSymbolSetName
: aSymbolSetNames
)
1222 m_xSymbolSets
->append_text(rSymbolSetName
);
1225 IMPL_LINK_NOARG( SmSymbolDialog
, SymbolSetChangeHdl
, weld::ComboBox
&, void )
1227 SelectSymbolSet(m_xSymbolSets
->get_active_text());
1230 IMPL_LINK_NOARG( SmSymbolDialog
, SymbolChangeHdl
, SmShowSymbolSet
&, void )
1232 SelectSymbol(m_xSymbolSetDisplay
->GetSelectSymbol());
1235 IMPL_LINK_NOARG(SmSymbolDialog
, EditClickHdl
, weld::Button
&, void)
1237 SmSymDefineDialog
aDialog(m_xDialog
.get(), pFontListDev
, rSymbolMgr
);
1239 // set current symbol and SymbolSet for the new dialog
1240 const OUString
aSymSetName (m_xSymbolSets
->get_active_text()),
1241 aSymName (m_xSymbolName
->get_label());
1242 aDialog
.SelectOldSymbolSet(aSymSetName
);
1243 aDialog
.SelectOldSymbol(aSymName
);
1244 aDialog
.SelectSymbolSet(aSymSetName
);
1245 aDialog
.SelectSymbol(aSymName
);
1247 // remember old SymbolSet
1248 OUString
aOldSymbolSet (m_xSymbolSets
->get_active_text());
1250 sal_uInt16 nSymPos
= m_xSymbolSetDisplay
->GetSelectSymbol();
1252 // adapt dialog to data of the SymbolSet manager, which might have changed
1253 if (aDialog
.run() == RET_OK
&& rSymbolMgr
.IsModified())
1259 // if the old SymbolSet doesn't exist anymore, go to the first one SymbolSet (if one exists)
1260 if (!SelectSymbolSet(aOldSymbolSet
) && m_xSymbolSets
->get_count() > 0)
1261 SelectSymbolSet(m_xSymbolSets
->get_text(0));
1264 // just update display of current symbol set
1265 assert(aSymSetName
== aSymSetName
); //unexpected change in symbol set name
1266 aSymbolSet
= rSymbolMgr
.GetSymbolSet( aSymbolSetName
);
1267 m_xSymbolSetDisplay
->SetSymbolSet( aSymbolSet
);
1270 if (nSymPos
>= aSymbolSet
.size())
1271 nSymPos
= static_cast< sal_uInt16
>(aSymbolSet
.size()) - 1;
1272 SelectSymbol( nSymPos
);
1275 IMPL_LINK_NOARG( SmSymbolDialog
, SymbolDblClickHdl2
, SmShowSymbolSet
&, void )
1277 SymbolDblClickHdl();
1280 IMPL_LINK_NOARG( SmSymbolDialog
, SymbolDblClickHdl
, SmShowSymbol
&, void )
1282 SymbolDblClickHdl();
1285 void SmSymbolDialog::SymbolDblClickHdl()
1287 GetClickHdl(*m_xGetBtn
);
1288 m_xDialog
->response(RET_OK
);
1291 IMPL_LINK_NOARG(SmSymbolDialog
, GetClickHdl
, weld::Button
&, void)
1293 const SmSym
*pSym
= GetSymbol();
1296 OUString aText
= "%" + pSym
->GetName() + " ";
1298 rViewSh
.GetViewFrame().GetDispatcher()->ExecuteList(
1299 SID_INSERTSPECIAL
, SfxCallMode::RECORD
,
1300 { new SfxStringItem(SID_INSERTSPECIAL
, aText
) });
1304 SmSymbolDialog::SmSymbolDialog(weld::Window
*pParent
, OutputDevice
*pFntListDevice
,
1305 SmSymbolManager
&rMgr
, SmViewShell
&rViewShell
)
1306 : GenericDialogController(pParent
, "modules/smath/ui/catalogdialog.ui", "CatalogDialog")
1307 , rViewSh(rViewShell
)
1309 , pFontListDev(pFntListDevice
)
1310 , m_xSymbolSets(m_xBuilder
->weld_combo_box("symbolset"))
1311 , m_xSymbolSetDisplay(new SmShowSymbolSet(m_xBuilder
->weld_scrolled_window("scrolledwindow", true)))
1312 , m_xSymbolSetDisplayArea(new weld::CustomWeld(*m_xBuilder
, "symbolsetdisplay", *m_xSymbolSetDisplay
))
1313 , m_xSymbolName(m_xBuilder
->weld_label("symbolname"))
1314 , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder
, "preview", m_aSymbolDisplay
))
1315 , m_xGetBtn(m_xBuilder
->weld_button("ok"))
1316 , m_xEditBtn(m_xBuilder
->weld_button("edit"))
1318 m_xSymbolSets
->make_sorted();
1320 aSymbolSetName
.clear();
1323 if (m_xSymbolSets
->get_count() > 0)
1324 SelectSymbolSet(m_xSymbolSets
->get_text(0));
1326 m_xSymbolSets
->connect_changed(LINK(this, SmSymbolDialog
, SymbolSetChangeHdl
));
1327 m_xSymbolSetDisplay
->SetSelectHdl(LINK(this, SmSymbolDialog
, SymbolChangeHdl
));
1328 m_xSymbolSetDisplay
->SetDblClickHdl(LINK(this, SmSymbolDialog
, SymbolDblClickHdl2
));
1329 m_aSymbolDisplay
.SetDblClickHdl(LINK(this, SmSymbolDialog
, SymbolDblClickHdl
));
1330 m_xEditBtn
->connect_clicked(LINK(this, SmSymbolDialog
, EditClickHdl
));
1331 m_xGetBtn
->connect_clicked(LINK(this, SmSymbolDialog
, GetClickHdl
));
1334 SmSymbolDialog::~SmSymbolDialog()
1338 bool SmSymbolDialog::SelectSymbolSet(const OUString
&rSymbolSetName
)
1341 sal_Int32 nPos
= m_xSymbolSets
->find_text(rSymbolSetName
);
1343 aSymbolSetName
.clear();
1347 m_xSymbolSets
->set_active(nPos
);
1349 aSymbolSetName
= rSymbolSetName
;
1350 aSymbolSet
= rSymbolMgr
.GetSymbolSet( aSymbolSetName
);
1352 // sort symbols by Unicode position (useful for displaying Greek characters alphabetically)
1353 std::sort( aSymbolSet
.begin(), aSymbolSet
.end(),
1354 [](const SmSym
*pSym1
, const SmSym
*pSym2
)
1356 return pSym1
->GetCharacter() < pSym2
->GetCharacter();
1359 const bool bEmptySymbolSet
= aSymbolSet
.empty();
1360 m_xSymbolSetDisplay
->SetSymbolSet( aSymbolSet
);
1361 if (!bEmptySymbolSet
)
1367 m_xSymbolSets
->set_active(-1);
1372 void SmSymbolDialog::SelectSymbol(sal_uInt16 nSymbolNo
)
1374 const SmSym
*pSym
= nullptr;
1375 if (!aSymbolSetName
.isEmpty() && nSymbolNo
< static_cast< sal_uInt16
>(aSymbolSet
.size()))
1376 pSym
= aSymbolSet
[ nSymbolNo
];
1378 m_xSymbolSetDisplay
->SelectSymbol(nSymbolNo
);
1379 m_aSymbolDisplay
.SetSymbol(pSym
);
1380 m_xSymbolName
->set_label(pSym
? pSym
->GetName() : OUString());
1383 const SmSym
* SmSymbolDialog::GetSymbol() const
1385 sal_uInt16 nSymbolNo
= m_xSymbolSetDisplay
->GetSelectSymbol();
1386 bool bValid
= !aSymbolSetName
.isEmpty() && nSymbolNo
< static_cast< sal_uInt16
>(aSymbolSet
.size());
1387 return bValid
? aSymbolSet
[ nSymbolNo
] : nullptr;
1390 void SmShowChar::Resize()
1392 const OUString
&rText
= GetText();
1393 if (rText
.isEmpty())
1395 sal_UCS4 cChar
= rText
.iterateCodePoints(&o3tl::temporary(sal_Int32(0)));
1396 SetSymbol(cChar
, GetFont()); //force recalculation of size
1399 void SmShowChar::Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&)
1401 Color aTextCol
= rRenderContext
.GetTextColor();
1402 Color aFillCol
= rRenderContext
.GetFillColor();
1404 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
1405 const Color
aWindowTextColor(rStyleSettings
.GetDialogTextColor());
1406 const Color
aWindowColor(rStyleSettings
.GetWindowColor());
1407 rRenderContext
.SetTextColor(aWindowTextColor
);
1408 rRenderContext
.SetFillColor(aWindowColor
);
1410 Size
aSize(GetOutputSizePixel());
1411 rRenderContext
.DrawRect(tools::Rectangle(Point(0, 0), aSize
));
1413 OUString
aText(GetText());
1414 if (!aText
.isEmpty())
1416 vcl::Font
aFont(m_aFont
);
1417 aFont
.SetAlignment(ALIGN_TOP
);
1418 rRenderContext
.SetFont(aFont
);
1420 Size
aTextSize(rRenderContext
.GetTextWidth(aText
), rRenderContext
.GetTextHeight());
1422 rRenderContext
.DrawText(Point((aSize
.Width() - aTextSize
.Width()) / 2,
1423 (aSize
.Height() - aTextSize
.Height()) / 2), aText
);
1426 rRenderContext
.SetTextColor(aTextCol
);
1427 rRenderContext
.SetFillColor(aFillCol
);
1430 void SmShowChar::SetSymbol( const SmSym
*pSym
)
1433 SetSymbol( pSym
->GetCharacter(), pSym
->GetFace() );
1437 void SmShowChar::SetSymbol( sal_UCS4 cChar
, const vcl::Font
&rFont
)
1439 vcl::Font
aFont( rFont
);
1440 Size
aSize(GetOutputSizePixel());
1441 aFont
.SetFontSize(Size(0, aSize
.Height() - aSize
.Height() / 3));
1442 aFont
.SetAlignment(ALIGN_BASELINE
);
1445 OUString
aText(&cChar
, 1);
1451 void SmSymDefineDialog::FillSymbols(weld::ComboBox
& rComboBox
, bool bDeleteText
)
1453 assert((&rComboBox
== m_xOldSymbols
.get() || &rComboBox
== m_xSymbols
.get()) && "Sm : wrong ComboBox");
1457 rComboBox
.set_entry_text(OUString());
1459 weld::ComboBox
& rBox
= &rComboBox
== m_xOldSymbols
.get() ? *m_xOldSymbolSets
: *m_xSymbolSets
;
1460 SymbolPtrVec_t
aSymSet(m_aSymbolMgrCopy
.GetSymbolSet(rBox
.get_active_text()));
1461 for (const SmSym
* i
: aSymSet
)
1462 rComboBox
.append_text(i
->GetName());
1465 void SmSymDefineDialog::FillSymbolSets(weld::ComboBox
& rComboBox
, bool bDeleteText
)
1467 assert((&rComboBox
== m_xOldSymbolSets
.get() || &rComboBox
== m_xSymbolSets
.get()) && "Sm : wrong ComboBox");
1471 rComboBox
.set_entry_text(OUString());
1473 const std::set
< OUString
> aSymbolSetNames( m_aSymbolMgrCopy
.GetSymbolSetNames() );
1474 for (const auto& rSymbolSetName
: aSymbolSetNames
)
1475 rComboBox
.append_text(rSymbolSetName
);
1478 void SmSymDefineDialog::FillFonts()
1481 m_xFonts
->set_active(-1);
1483 // Include all fonts of FontList into the font list.
1484 // If there are duplicates, only include one entry of each font since the style will be
1485 // already selected using the FontStyleBox.
1488 sal_uInt16 nCount
= m_xFontList
->GetFontNameCount();
1489 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
1490 m_xFonts
->append_text(m_xFontList
->GetFontName(i
).GetFamilyName());
1494 void SmSymDefineDialog::FillStyles()
1497 // pStyles->SetText(OUString());
1499 OUString
aText(m_xFonts
->get_active_text());
1500 if (!aText
.isEmpty())
1502 // use own StyleNames
1503 const SmFontStyles
&rStyles
= GetFontStyles();
1504 for (sal_uInt16 i
= 0; i
< SmFontStyles::GetCount(); ++i
)
1505 m_xStyles
->append_text(rStyles
.GetStyleName(i
));
1507 assert(m_xStyles
->get_count() > 0 && "Sm : no styles available");
1508 m_xStyles
->set_active(0);
1512 SmSym
* SmSymDefineDialog::GetSymbol(const weld::ComboBox
& rComboBox
)
1514 assert((&rComboBox
== m_xOldSymbols
.get() || &rComboBox
== m_xSymbols
.get()) && "Sm : wrong combobox");
1515 return m_aSymbolMgrCopy
.GetSymbolByName(rComboBox
.get_active_text());
1518 IMPL_LINK(SmSymDefineDialog
, OldSymbolChangeHdl
, weld::ComboBox
&, rComboBox
, void)
1521 assert(&rComboBox
== m_xOldSymbols
.get() && "Sm : wrong argument");
1522 SelectSymbol(*m_xOldSymbols
, m_xOldSymbols
->get_active_text(), false);
1525 IMPL_LINK( SmSymDefineDialog
, OldSymbolSetChangeHdl
, weld::ComboBox
&, rComboBox
, void )
1528 assert(&rComboBox
== m_xOldSymbolSets
.get() && "Sm : wrong argument");
1529 SelectSymbolSet(*m_xOldSymbolSets
, m_xOldSymbolSets
->get_active_text(), false);
1532 IMPL_LINK(SmSymDefineDialog
, ModifyHdl
, weld::ComboBox
&, rComboBox
, void)
1534 // remember cursor position for later restoring of it
1535 int nStartPos
, nEndPos
;
1536 rComboBox
.get_entry_selection_bounds(nStartPos
, nEndPos
);
1538 if (&rComboBox
== m_xSymbols
.get())
1539 SelectSymbol(*m_xSymbols
, m_xSymbols
->get_active_text(), false);
1540 else if (&rComboBox
== m_xSymbolSets
.get())
1541 SelectSymbolSet(*m_xSymbolSets
, m_xSymbolSets
->get_active_text(), false);
1542 else if (&rComboBox
== m_xOldSymbols
.get())
1543 // allow only names from the list
1544 SelectSymbol(*m_xOldSymbols
, m_xOldSymbols
->get_active_text(), true);
1545 else if (&rComboBox
== m_xOldSymbolSets
.get())
1546 // allow only names from the list
1547 SelectSymbolSet(*m_xOldSymbolSets
, m_xOldSymbolSets
->get_active_text(), true);
1548 else if (&rComboBox
== m_xStyles
.get())
1549 // allow only names from the list (that's the case here anyway)
1550 SelectStyle(m_xStyles
->get_active_text(), true);
1552 SAL_WARN("starmath", "wrong combobox argument");
1554 rComboBox
.select_entry_region(nStartPos
, nEndPos
);
1559 IMPL_LINK(SmSymDefineDialog
, FontChangeHdl
, weld::ComboBox
&, rListBox
, void)
1562 assert(&rListBox
== m_xFonts
.get() && "Sm : wrong argument");
1564 SelectFont(m_xFonts
->get_active_text());
1567 IMPL_LINK_NOARG(SmSymDefineDialog
, SubsetChangeHdl
, weld::ComboBox
&, void)
1569 int nPos
= m_xFontsSubsetLB
->get_active();
1572 const Subset
* pSubset
= weld::fromId
<const Subset
*>(m_xFontsSubsetLB
->get_active_id());
1575 m_xCharsetDisplay
->SelectCharacter( pSubset
->GetRangeMin() );
1580 IMPL_LINK( SmSymDefineDialog
, StyleChangeHdl
, weld::ComboBox
&, rComboBox
, void )
1583 assert(&rComboBox
== m_xStyles
.get() && "Sm : wrong argument");
1585 SelectStyle(m_xStyles
->get_active_text());
1588 IMPL_LINK_NOARG(SmSymDefineDialog
, CharHighlightHdl
, SvxShowCharSet
*, void)
1590 sal_UCS4 cChar
= m_xCharsetDisplay
->GetSelectCharacter();
1594 const Subset
* pSubset
= m_xSubsetMap
->GetSubsetByUnicode(cChar
);
1596 m_xFontsSubsetLB
->set_active_text(pSubset
->GetName());
1598 m_xFontsSubsetLB
->set_active(-1);
1601 m_aSymbolDisplay
.SetSymbol(cChar
, m_xCharsetDisplay
->GetFont());
1605 // display Unicode position as symbol name while iterating over characters
1606 const OUString
aHex(OUString::number(cChar
, 16).toAsciiUpperCase());
1607 const OUString
aPattern( (aHex
.getLength() > 4) ? OUString("Ux000000") : OUString("Ux0000") );
1608 OUString aUnicodePos
= aPattern
.subView( 0, aPattern
.getLength() - aHex
.getLength() ) +
1610 m_xSymbols
->set_entry_text(aUnicodePos
);
1611 m_xSymbolName
->set_label(aUnicodePos
);
1614 IMPL_LINK( SmSymDefineDialog
, AddClickHdl
, weld::Button
&, rButton
, void )
1617 assert(&rButton
== m_xAddBtn
.get() && "Sm : wrong argument");
1618 assert(rButton
.get_sensitive() && "Sm : requirements met ??");
1621 const SmSym
aNewSymbol(m_xSymbols
->get_active_text(), m_xCharsetDisplay
->GetFont(),
1622 m_xCharsetDisplay
->GetSelectCharacter(), m_xSymbolSets
->get_active_text());
1623 //OSL_ENSURE( m_aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL, "symbol already exists" );
1624 m_aSymbolMgrCopy
.AddOrReplaceSymbol( aNewSymbol
);
1626 // update display of new symbol
1627 m_aSymbolDisplay
.SetSymbol( &aNewSymbol
);
1628 m_xSymbolName
->set_label(aNewSymbol
.GetName());
1629 m_xSymbolSetName
->set_label(aNewSymbol
.GetSymbolSetName());
1631 // update list box entries
1632 FillSymbolSets(*m_xOldSymbolSets
, false);
1633 FillSymbolSets(*m_xSymbolSets
, false);
1634 FillSymbols(*m_xOldSymbols
, false);
1635 FillSymbols(*m_xSymbols
, false);
1640 IMPL_LINK( SmSymDefineDialog
, ChangeClickHdl
, weld::Button
&, rButton
, void )
1643 assert(&rButton
== m_xChangeBtn
.get() && "Sm : wrong argument");
1644 assert(m_xChangeBtn
->get_sensitive() && "Sm : requirements met ??");
1646 // get new Symbol to use
1647 //! get font from symbol-disp lay since charset-display does not keep
1648 //! the bold attribute.
1649 const SmSym
aNewSymbol(m_xSymbols
->get_active_text(), m_xCharsetDisplay
->GetFont(),
1650 m_xCharsetDisplay
->GetSelectCharacter(), m_xSymbolSets
->get_active_text());
1652 // remove old symbol if the name was changed then add new one
1653 const bool bNameChanged
= m_xOldSymbols
->get_active_text() != m_xSymbols
->get_active_text();
1655 m_aSymbolMgrCopy
.RemoveSymbol(m_xOldSymbols
->get_active_text());
1656 m_aSymbolMgrCopy
.AddOrReplaceSymbol( aNewSymbol
, true );
1658 // clear display for original symbol if necessary
1660 SetOrigSymbol(nullptr, OUString());
1662 // update display of new symbol
1663 m_aSymbolDisplay
.SetSymbol(&aNewSymbol
);
1664 m_xSymbolName
->set_label(aNewSymbol
.GetName());
1665 m_xSymbolSetName
->set_label(aNewSymbol
.GetSymbolSetName());
1667 // update list box entries
1668 FillSymbolSets(*m_xOldSymbolSets
, false);
1669 FillSymbolSets(*m_xSymbolSets
, false);
1670 FillSymbols(*m_xOldSymbols
, false);
1671 FillSymbols(*m_xSymbols
, false);
1676 IMPL_LINK(SmSymDefineDialog
, DeleteClickHdl
, weld::Button
&, rButton
, void)
1679 assert(&rButton
== m_xDeleteBtn
.get() && "Sm : wrong argument");
1680 assert(m_xDeleteBtn
->get_sensitive() && "Sm : requirements met ??");
1684 m_aSymbolMgrCopy
.RemoveSymbol(m_xOrigSymbol
->GetName());
1686 // clear display for original symbol
1687 SetOrigSymbol(nullptr, OUString());
1689 // update list box entries
1690 FillSymbolSets(*m_xOldSymbolSets
, false);
1691 FillSymbolSets(*m_xSymbolSets
, false);
1692 FillSymbols(*m_xOldSymbols
,false);
1693 FillSymbols(*m_xSymbols
,false);
1699 void SmSymDefineDialog::UpdateButtons()
1704 OUString
aTmpSymbolName(m_xSymbols
->get_active_text()),
1705 aTmpSymbolSetName(m_xSymbolSets
->get_active_text());
1707 if (!aTmpSymbolName
.isEmpty() && !aTmpSymbolSetName
.isEmpty())
1709 // are all settings equal?
1710 //! (Font-, Style- and SymbolSet name comparison is not case sensitive)
1711 bool bEqual
= m_xOrigSymbol
1712 && aTmpSymbolSetName
.equalsIgnoreAsciiCase(m_xOldSymbolSetName
->get_label())
1713 && aTmpSymbolName
== m_xOrigSymbol
->GetName()
1714 && m_xFonts
->get_active_text().equalsIgnoreAsciiCase(
1715 m_xOrigSymbol
->GetFace().GetFamilyName())
1716 && m_xStyles
->get_active_text().equalsIgnoreAsciiCase(
1717 GetFontStyles().GetStyleName(m_xOrigSymbol
->GetFace()))
1718 && m_xCharsetDisplay
->GetSelectCharacter() == m_xOrigSymbol
->GetCharacter();
1720 // only add it if there isn't already a symbol with the same name
1721 bAdd
= m_aSymbolMgrCopy
.GetSymbolByName(aTmpSymbolName
) == nullptr;
1723 // only delete it if all settings are equal
1724 bDelete
= bool(m_xOrigSymbol
);
1726 // only change it if the old symbol exists and the new one is different
1727 bChange
= m_xOrigSymbol
&& !bEqual
;
1730 m_xAddBtn
->set_sensitive(bAdd
);
1731 m_xChangeBtn
->set_sensitive(bChange
);
1732 m_xDeleteBtn
->set_sensitive(bDelete
);
1735 SmSymDefineDialog::SmSymDefineDialog(weld::Window
* pParent
, OutputDevice
*pFntListDevice
, SmSymbolManager
&rMgr
)
1736 : GenericDialogController(pParent
, "modules/smath/ui/symdefinedialog.ui", "EditSymbols")
1737 , m_xVirDev(VclPtr
<VirtualDevice
>::Create())
1738 , m_rSymbolMgr(rMgr
)
1739 , m_xFontList(new FontList(pFntListDevice
))
1740 , m_xOldSymbols(m_xBuilder
->weld_combo_box("oldSymbols"))
1741 , m_xOldSymbolSets(m_xBuilder
->weld_combo_box("oldSymbolSets"))
1742 , m_xSymbols(m_xBuilder
->weld_combo_box("symbols"))
1743 , m_xSymbolSets(m_xBuilder
->weld_combo_box("symbolSets"))
1744 , m_xFonts(m_xBuilder
->weld_combo_box("fonts"))
1745 , m_xFontsSubsetLB(m_xBuilder
->weld_combo_box("fontsSubsetLB"))
1746 , m_xStyles(m_xBuilder
->weld_combo_box("styles"))
1747 , m_xOldSymbolName(m_xBuilder
->weld_label("oldSymbolName"))
1748 , m_xOldSymbolSetName(m_xBuilder
->weld_label("oldSymbolSetName"))
1749 , m_xSymbolName(m_xBuilder
->weld_label("symbolName"))
1750 , m_xSymbolSetName(m_xBuilder
->weld_label("symbolSetName"))
1751 , m_xAddBtn(m_xBuilder
->weld_button("add"))
1752 , m_xChangeBtn(m_xBuilder
->weld_button("modify"))
1753 , m_xDeleteBtn(m_xBuilder
->weld_button("delete"))
1754 , m_xOldSymbolDisplay(new weld::CustomWeld(*m_xBuilder
, "oldSymbolDisplay", m_aOldSymbolDisplay
))
1755 , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder
, "symbolDisplay", m_aSymbolDisplay
))
1756 , m_xCharsetDisplay(new SvxShowCharSet(m_xBuilder
->weld_scrolled_window("showscroll", true), m_xVirDev
))
1757 , m_xCharsetDisplayArea(new weld::CustomWeld(*m_xBuilder
, "charsetDisplay", *m_xCharsetDisplay
))
1759 // auto completion is troublesome since that symbols character also gets automatically selected in the
1760 // display and if the user previously selected a character to define/redefine that one this is bad
1761 m_xOldSymbols
->set_entry_completion(false);
1762 m_xSymbols
->set_entry_completion(false);
1765 if (m_xFonts
->get_count() > 0)
1766 SelectFont(m_xFonts
->get_text(0));
1768 SetSymbolSetManager(m_rSymbolMgr
);
1770 m_xOldSymbols
->connect_changed(LINK(this, SmSymDefineDialog
, OldSymbolChangeHdl
));
1771 m_xOldSymbolSets
->connect_changed(LINK(this, SmSymDefineDialog
, OldSymbolSetChangeHdl
));
1772 m_xSymbolSets
->connect_changed(LINK(this, SmSymDefineDialog
, ModifyHdl
));
1773 m_xOldSymbolSets
->connect_changed(LINK(this, SmSymDefineDialog
, ModifyHdl
));
1774 m_xSymbols
->connect_changed(LINK(this, SmSymDefineDialog
, ModifyHdl
));
1775 m_xOldSymbols
->connect_changed(LINK(this, SmSymDefineDialog
, ModifyHdl
));
1776 m_xStyles
->connect_changed(LINK(this, SmSymDefineDialog
, ModifyHdl
));
1777 m_xFonts
->connect_changed(LINK(this, SmSymDefineDialog
, FontChangeHdl
));
1778 m_xFontsSubsetLB
->connect_changed(LINK(this, SmSymDefineDialog
, SubsetChangeHdl
));
1779 m_xStyles
->connect_changed(LINK(this, SmSymDefineDialog
, StyleChangeHdl
));
1780 m_xAddBtn
->connect_clicked(LINK(this, SmSymDefineDialog
, AddClickHdl
));
1781 m_xChangeBtn
->connect_clicked(LINK(this, SmSymDefineDialog
, ChangeClickHdl
));
1782 m_xDeleteBtn
->connect_clicked(LINK(this, SmSymDefineDialog
, DeleteClickHdl
));
1783 m_xCharsetDisplay
->SetHighlightHdl( LINK( this, SmSymDefineDialog
, CharHighlightHdl
) );
1786 SmSymDefineDialog::~SmSymDefineDialog()
1790 short SmSymDefineDialog::run()
1792 short nResult
= GenericDialogController::run();
1794 // apply changes if dialog was closed by clicking OK
1795 if (m_aSymbolMgrCopy
.IsModified() && nResult
== RET_OK
)
1796 m_rSymbolMgr
= m_aSymbolMgrCopy
;
1801 void SmSymDefineDialog::SetSymbolSetManager(const SmSymbolManager
&rMgr
)
1803 m_aSymbolMgrCopy
= rMgr
;
1805 // Set the modified flag of the copy to false so that
1806 // we can check later on if anything has been changed
1807 m_aSymbolMgrCopy
.SetModified(false);
1809 FillSymbolSets(*m_xOldSymbolSets
);
1810 if (m_xOldSymbolSets
->get_count() > 0)
1811 SelectSymbolSet(m_xOldSymbolSets
->get_text(0));
1812 FillSymbolSets(*m_xSymbolSets
);
1813 if (m_xSymbolSets
->get_count() > 0)
1814 SelectSymbolSet(m_xSymbolSets
->get_text(0));
1815 FillSymbols(*m_xOldSymbols
);
1816 if (m_xOldSymbols
->get_count() > 0)
1817 SelectSymbol(m_xOldSymbols
->get_text(0));
1818 FillSymbols(*m_xSymbols
);
1819 if (m_xSymbols
->get_count() > 0)
1820 SelectSymbol(m_xSymbols
->get_text(0));
1825 bool SmSymDefineDialog::SelectSymbolSet(weld::ComboBox
& rComboBox
,
1826 std::u16string_view rSymbolSetName
, bool bDeleteText
)
1828 assert((&rComboBox
== m_xOldSymbolSets
.get() || &rComboBox
== m_xSymbolSets
.get()) && "Sm : wrong ComboBox");
1830 // trim SymbolName (no leading and trailing blanks)
1831 OUString
aNormName( comphelper::string::strip(rSymbolSetName
, ' ') );
1832 // and remove possible deviations within the input
1833 rComboBox
.set_entry_text(aNormName
);
1836 int nPos
= rComboBox
.find_text(aNormName
);
1840 rComboBox
.set_active(nPos
);
1843 else if (bDeleteText
)
1844 rComboBox
.set_entry_text(OUString());
1846 bool bIsOld
= &rComboBox
== m_xOldSymbolSets
.get();
1848 // setting the SymbolSet name at the associated display
1849 weld::Label
& rFT
= bIsOld
? *m_xOldSymbolSetName
: *m_xSymbolSetName
;
1850 rFT
.set_label(rComboBox
.get_active_text());
1852 // set the symbol name which belongs to the SymbolSet at the associated combobox
1853 weld::ComboBox
& rCB
= bIsOld
? *m_xOldSymbols
: *m_xSymbols
;
1854 FillSymbols(rCB
, false);
1856 // display a valid respectively no symbol when changing the SymbolSets
1859 OUString aTmpOldSymbolName
;
1860 if (m_xOldSymbols
->get_count() > 0)
1861 aTmpOldSymbolName
= m_xOldSymbols
->get_text(0);
1862 SelectSymbol(*m_xOldSymbols
, aTmpOldSymbolName
, true);
1870 void SmSymDefineDialog::SetOrigSymbol(const SmSym
*pSymbol
,
1871 const OUString
&rSymbolSetName
)
1874 m_xOrigSymbol
.reset();
1881 m_xOrigSymbol
.reset(new SmSym(*pSymbol
));
1883 aSymName
= pSymbol
->GetName();
1884 aSymSetName
= rSymbolSetName
;
1885 m_aOldSymbolDisplay
.SetSymbol( pSymbol
);
1888 { // delete displayed symbols
1889 m_aOldSymbolDisplay
.SetText(OUString());
1890 m_aOldSymbolDisplay
.Invalidate();
1892 m_xOldSymbolName
->set_label(aSymName
);
1893 m_xOldSymbolSetName
->set_label(aSymSetName
);
1897 bool SmSymDefineDialog::SelectSymbol(weld::ComboBox
& rComboBox
,
1898 const OUString
&rSymbolName
, bool bDeleteText
)
1900 assert((&rComboBox
== m_xOldSymbols
.get() || &rComboBox
== m_xSymbols
.get()) && "Sm : wrong ComboBox");
1902 // trim SymbolName (no blanks)
1903 OUString aNormName
= rSymbolName
.replaceAll(" ", "");
1904 // and remove possible deviations within the input
1905 rComboBox
.set_entry_text(aNormName
);
1908 int nPos
= rComboBox
.find_text(aNormName
);
1910 bool bIsOld
= &rComboBox
== m_xOldSymbols
.get();
1914 rComboBox
.set_active(nPos
);
1918 const SmSym
*pSymbol
= GetSymbol(*m_xSymbols
);
1921 // choose font and style accordingly
1922 const vcl::Font
&rFont
= pSymbol
->GetFace();
1923 SelectFont(rFont
.GetFamilyName(), false);
1924 SelectStyle(GetFontStyles().GetStyleName(rFont
), false);
1926 // Since setting the Font via the Style name of the SymbolFonts doesn't
1927 // work really well (e.g. it can be empty even though the font itself is
1928 // bold or italic) we're manually setting the Font with respect to the Symbol
1929 m_xCharsetDisplay
->SetFont(rFont
);
1930 m_aSymbolDisplay
.SetFont(rFont
);
1932 // select associated character
1933 SelectChar(pSymbol
->GetCharacter());
1935 // since SelectChar will also set the unicode point as text in the
1936 // symbols box, we have to set the symbol name again to get that one displayed
1937 m_xSymbols
->set_entry_text(pSymbol
->GetName());
1943 else if (bDeleteText
)
1944 rComboBox
.set_entry_text(OUString());
1948 // if there's a change of the old symbol, show only the available ones, otherwise show none
1949 const SmSym
*pOldSymbol
= nullptr;
1950 OUString aTmpOldSymbolSetName
;
1953 pOldSymbol
= m_aSymbolMgrCopy
.GetSymbolByName(aNormName
);
1954 aTmpOldSymbolSetName
= m_xOldSymbolSets
->get_active_text();
1956 SetOrigSymbol(pOldSymbol
, aTmpOldSymbolSetName
);
1959 m_xSymbolName
->set_label(rComboBox
.get_active_text());
1967 void SmSymDefineDialog::SetFont(const OUString
&rFontName
, std::u16string_view rStyleName
)
1969 // get Font (FontInfo) matching name and style
1970 FontMetric aFontMetric
;
1972 aFontMetric
= m_xFontList
->Get(rFontName
, WEIGHT_NORMAL
, ITALIC_NONE
);
1973 SetFontStyle(rStyleName
, aFontMetric
);
1975 m_xCharsetDisplay
->SetFont(aFontMetric
);
1976 m_aSymbolDisplay
.SetFont(aFontMetric
);
1978 // update subset listbox for new font's unicode subsets
1979 FontCharMapRef xFontCharMap
= m_xCharsetDisplay
->GetFontCharMap();
1980 m_xSubsetMap
.reset(new SubsetMap( xFontCharMap
));
1982 m_xFontsSubsetLB
->clear();
1984 for (auto & subset
: m_xSubsetMap
->GetSubsetMap())
1986 m_xFontsSubsetLB
->append(weld::toId(&subset
), subset
.GetName());
1987 // subset must live at least as long as the selected font !!!
1989 m_xFontsSubsetLB
->set_active(0);
1993 m_xFontsSubsetLB
->set_active(-1);
1994 m_xFontsSubsetLB
->set_sensitive(!bFirst
);
1997 bool SmSymDefineDialog::SelectFont(const OUString
&rFontName
, bool bApplyFont
)
2000 int nPos
= m_xFonts
->find_text(rFontName
);
2004 m_xFonts
->set_active(nPos
);
2005 if (m_xStyles
->get_count() > 0)
2006 SelectStyle(m_xStyles
->get_text(0));
2009 SetFont(m_xFonts
->get_active_text(), m_xStyles
->get_active_text());
2010 m_aSymbolDisplay
.SetSymbol(m_xCharsetDisplay
->GetSelectCharacter(), m_xCharsetDisplay
->GetFont());
2015 m_xFonts
->set_active(-1);
2024 bool SmSymDefineDialog::SelectStyle(const OUString
&rStyleName
, bool bApplyFont
)
2027 int nPos
= m_xStyles
->find_text(rStyleName
);
2029 // if the style is not available take the first available one (if existent)
2030 if (nPos
== -1 && m_xStyles
->get_count() > 0)
2035 m_xStyles
->set_active(nPos
);
2038 SetFont(m_xFonts
->get_active_text(), m_xStyles
->get_active_text());
2039 m_aSymbolDisplay
.SetSymbol(m_xCharsetDisplay
->GetSelectCharacter(), m_xCharsetDisplay
->GetFont());
2044 m_xStyles
->set_entry_text(OUString());
2051 void SmSymDefineDialog::SelectChar(sal_Unicode cChar
)
2053 m_xCharsetDisplay
->SelectCharacter( cChar
);
2054 m_aSymbolDisplay
.SetSymbol(cChar
, m_xCharsetDisplay
->GetFont());
2059 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */