Bump version to 21.06.18.1
[LibreOffice.git] / starmath / source / dialog.cxx
blob5902669c8df436aef327bcfc295129e68f1bc9d3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <cassert>
25 #include <comphelper/string.hxx>
26 #include <svl/eitem.hxx>
27 #include <svl/intitem.hxx>
28 #include <svl/stritem.hxx>
29 #include <vcl/event.hxx>
30 #include <vcl/svapp.hxx>
31 #include <vcl/virdev.hxx>
32 #include <vcl/weld.hxx>
33 #include <svtools/ctrltool.hxx>
34 #include <vcl/settings.hxx>
35 #include <vcl/wall.hxx>
36 #include <vcl/fontcharmap.hxx>
37 #include <sfx2/dispatch.hxx>
38 #include <svx/charmap.hxx>
39 #include <svx/ucsubset.hxx>
41 #include <dialog.hxx>
42 #include <starmath.hrc>
43 #include <strings.hrc>
44 #include <helpids.h>
45 #include "cfgitem.hxx"
46 #include <smmod.hxx>
47 #include <symbol.hxx>
48 #include <view.hxx>
50 #include <algorithm>
52 namespace
55 void lclGetSettingColors(Color& rBackgroundColor, Color& rTextColor)
57 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
58 if (rStyleSettings.GetHighContrastMode())
60 rBackgroundColor = rStyleSettings.GetFieldColor();
61 rTextColor = rStyleSettings.GetFieldTextColor();
63 else
65 rBackgroundColor = COL_WHITE;
66 rTextColor = COL_BLACK;
70 // Since it's better to set/query the FontStyle via its attributes rather
71 // than via the StyleName we create a way to translate
72 // Attribute <-> StyleName
74 class SmFontStyles
76 OUString aNormal;
77 OUString aBold;
78 OUString aItalic;
79 OUString aBoldItalic;
81 public:
82 SmFontStyles();
84 static sal_uInt16 GetCount() { return 4; }
85 const OUString& GetStyleName(const vcl::Font& rFont) const;
86 const OUString& GetStyleName(sal_uInt16 nIdx) const;
89 } // end anonymous namespace
91 SmFontStyles::SmFontStyles()
92 : aNormal(SmResId(RID_FONTREGULAR))
93 , aBold(SmResId(RID_FONTBOLD))
94 , aItalic(SmResId(RID_FONTITALIC))
96 aBoldItalic = aBold;
97 aBoldItalic += ", ";
98 aBoldItalic += aItalic;
101 const OUString& SmFontStyles::GetStyleName(const vcl::Font& rFont) const
103 //! compare also SmSpecialNode::Prepare
104 bool bBold = IsBold( rFont ),
105 bItalic = IsItalic( rFont );
107 if (bBold && bItalic)
108 return aBoldItalic;
109 else if (bItalic)
110 return aItalic;
111 else if (bBold)
112 return aBold;
113 return aNormal;
116 const OUString& SmFontStyles::GetStyleName( sal_uInt16 nIdx ) const
118 // 0 = "normal", 1 = "italic",
119 // 2 = "bold", 3 = "bold italic"
121 assert( nIdx < GetCount() );
122 switch (nIdx)
124 case 0 : return aNormal;
125 case 1 : return aItalic;
126 case 2 : return aBold;
127 default: /*case 3:*/ return aBoldItalic;
131 static const SmFontStyles & GetFontStyles()
133 static const SmFontStyles aImpl;
134 return aImpl;
137 void SetFontStyle(const OUString &rStyleName, vcl::Font &rFont)
139 // Find index related to StyleName. For an empty StyleName it's assumed to be
140 // 0 (neither bold nor italic).
141 sal_uInt16 nIndex = 0;
142 if (!rStyleName.isEmpty())
144 sal_uInt16 i;
145 const SmFontStyles &rStyles = GetFontStyles();
146 for (i = 0; i < SmFontStyles::GetCount(); ++i)
147 if (rStyleName == rStyles.GetStyleName(i))
148 break;
149 assert(i < SmFontStyles::GetCount() && "style-name unknown");
150 nIndex = i;
153 rFont.SetItalic((nIndex & 0x1) ? ITALIC_NORMAL : ITALIC_NONE);
154 rFont.SetWeight((nIndex & 0x2) ? WEIGHT_BOLD : WEIGHT_NORMAL);
157 IMPL_LINK_NOARG(SmPrintOptionsTabPage, SizeButtonClickHdl, weld::ToggleButton&, void)
159 m_xZoom->set_sensitive(m_xSizeZoomed->get_active());
162 SmPrintOptionsTabPage::SmPrintOptionsTabPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rOptions)
163 : SfxTabPage(pPage, pController, "modules/smath/ui/smathsettings.ui", "SmathSettings", &rOptions)
164 , m_xTitle(m_xBuilder->weld_check_button("title"))
165 , m_xText(m_xBuilder->weld_check_button("text"))
166 , m_xFrame(m_xBuilder->weld_check_button("frame"))
167 , m_xSizeNormal(m_xBuilder->weld_radio_button("sizenormal"))
168 , m_xSizeScaled(m_xBuilder->weld_radio_button("sizescaled"))
169 , m_xSizeZoomed(m_xBuilder->weld_radio_button("sizezoomed"))
170 , m_xZoom(m_xBuilder->weld_metric_spin_button("zoom", FieldUnit::PERCENT))
171 , m_xNoRightSpaces(m_xBuilder->weld_check_button("norightspaces"))
172 , m_xSaveOnlyUsedSymbols(m_xBuilder->weld_check_button("saveonlyusedsymbols"))
173 , m_xAutoCloseBrackets(m_xBuilder->weld_check_button("autoclosebrackets"))
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));
179 Reset(&rOptions);
182 SmPrintOptionsTabPage::~SmPrintOptionsTabPage()
186 bool SmPrintOptionsTabPage::FillItemSet(SfxItemSet* rSet)
188 sal_uInt16 nPrintSize;
189 if (m_xSizeNormal->get_active())
190 nPrintSize = PRINT_SIZE_NORMAL;
191 else if (m_xSizeScaled->get_active())
192 nPrintSize = PRINT_SIZE_SCALED;
193 else
194 nPrintSize = PRINT_SIZE_ZOOMED;
196 rSet->Put(SfxUInt16Item(GetWhich(SID_PRINTSIZE), nPrintSize));
197 rSet->Put(SfxUInt16Item(GetWhich(SID_PRINTZOOM), sal::static_int_cast<sal_uInt16>(m_xZoom->get_value(FieldUnit::PERCENT))));
198 rSet->Put(SfxBoolItem(GetWhich(SID_PRINTTITLE), m_xTitle->get_active()));
199 rSet->Put(SfxBoolItem(GetWhich(SID_PRINTTEXT), m_xText->get_active()));
200 rSet->Put(SfxBoolItem(GetWhich(SID_PRINTFRAME), m_xFrame->get_active()));
201 rSet->Put(SfxBoolItem(GetWhich(SID_NO_RIGHT_SPACES), m_xNoRightSpaces->get_active()));
202 rSet->Put(SfxBoolItem(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS), m_xSaveOnlyUsedSymbols->get_active()));
203 rSet->Put(SfxBoolItem(GetWhich(SID_AUTO_CLOSE_BRACKETS), m_xAutoCloseBrackets->get_active()));
205 return true;
208 void SmPrintOptionsTabPage::Reset(const SfxItemSet* rSet)
210 SmPrintSize ePrintSize = static_cast<SmPrintSize>(static_cast<const SfxUInt16Item &>(rSet->Get(GetWhich(SID_PRINTSIZE))).GetValue());
212 m_xSizeNormal->set_active(ePrintSize == PRINT_SIZE_NORMAL);
213 m_xSizeScaled->set_active(ePrintSize == PRINT_SIZE_SCALED);
214 m_xSizeZoomed->set_active(ePrintSize == PRINT_SIZE_ZOOMED);
216 m_xZoom->set_sensitive(m_xSizeZoomed->get_active());
218 m_xZoom->set_value(static_cast<const SfxUInt16Item &>(rSet->Get(GetWhich(SID_PRINTZOOM))).GetValue(), FieldUnit::PERCENT);
220 m_xTitle->set_active(static_cast<const SfxBoolItem &>(rSet->Get(GetWhich(SID_PRINTTITLE))).GetValue());
221 m_xNoRightSpaces->set_active(static_cast<const SfxBoolItem &>(rSet->Get(GetWhich(SID_NO_RIGHT_SPACES))).GetValue());
222 m_xSaveOnlyUsedSymbols->set_active(static_cast<const SfxBoolItem &>(rSet->Get(GetWhich(SID_SAVE_ONLY_USED_SYMBOLS))).GetValue());
223 m_xAutoCloseBrackets->set_active(static_cast<const SfxBoolItem &>(rSet->Get(GetWhich(SID_AUTO_CLOSE_BRACKETS))).GetValue());
226 std::unique_ptr<SfxTabPage> SmPrintOptionsTabPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet)
228 return std::make_unique<SmPrintOptionsTabPage>(pPage, pController, rSet);
231 void SmShowFont::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
233 Color aBackColor;
234 Color aTextColor;
235 lclGetSettingColors(aBackColor, aTextColor);
237 rRenderContext.SetBackground(Wallpaper(aBackColor));
239 vcl::Font aFont(maFont);
240 aFont.SetFontSize(Size(0, 24 * rRenderContext.GetDPIScaleFactor()));
241 aFont.SetAlignment(ALIGN_TOP);
242 rRenderContext.SetFont(aFont);
243 rRenderContext.SetTextColor(aTextColor);
245 OUString sText(rRenderContext.GetFont().GetFamilyName());
246 Size aTextSize(rRenderContext.GetTextWidth(sText), rRenderContext.GetTextHeight());
248 rRenderContext.DrawText(Point((rRenderContext.GetOutputSize().Width() - aTextSize.Width()) / 2,
249 (rRenderContext.GetOutputSize().Height() - aTextSize.Height()) / 2), sText);
252 void SmShowFont::SetDrawingArea(weld::DrawingArea* pDrawingArea)
254 CustomWidgetController::SetDrawingArea(pDrawingArea);
255 Size aSize(pDrawingArea->get_ref_device().LogicToPixel(Size(111 , 31), MapMode(MapUnit::MapAppFont)));
256 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
259 void SmShowFont::SetFont(const vcl::Font& rFont)
261 maFont = rFont;
262 Invalidate();
265 IMPL_LINK( SmFontDialog, FontSelectHdl, weld::ComboBox&, rComboBox, void )
267 maFont.SetFamilyName(rComboBox.get_active_text());
268 m_aShowFont.SetFont(maFont);
271 IMPL_LINK_NOARG(SmFontDialog, AttrChangeHdl, weld::ToggleButton&, void)
273 if (m_xBoldCheckBox->get_active())
274 maFont.SetWeight(WEIGHT_BOLD);
275 else
276 maFont.SetWeight(WEIGHT_NORMAL);
278 if (m_xItalicCheckBox->get_active())
279 maFont.SetItalic(ITALIC_NORMAL);
280 else
281 maFont.SetItalic(ITALIC_NONE);
283 m_aShowFont.SetFont(maFont);
286 void SmFontDialog::SetFont(const vcl::Font &rFont)
288 maFont = rFont;
290 m_xFontBox->set_active_text(maFont.GetFamilyName());
291 m_xBoldCheckBox->set_active(IsBold(maFont));
292 m_xItalicCheckBox->set_active(IsItalic(maFont));
293 m_aShowFont.SetFont(maFont);
296 SmFontDialog::SmFontDialog(weld::Window * pParent, OutputDevice *pFntListDevice, bool bHideCheckboxes)
297 : GenericDialogController(pParent, "modules/smath/ui/fontdialog.ui", "FontDialog")
298 , m_xFontBox(m_xBuilder->weld_entry_tree_view("fontgrid", "font", "fonts"))
299 , m_xAttrFrame(m_xBuilder->weld_widget("attrframe"))
300 , m_xBoldCheckBox(m_xBuilder->weld_check_button("bold"))
301 , m_xItalicCheckBox(m_xBuilder->weld_check_button("italic"))
302 , m_xShowFont(new weld::CustomWeld(*m_xBuilder, "preview", m_aShowFont))
304 m_xFontBox->set_height_request_by_rows(8);
307 weld::WaitObject aWait(pParent);
309 FontList aFontList( pFntListDevice );
311 sal_uInt16 nCount = aFontList.GetFontNameCount();
312 for (sal_uInt16 i = 0; i < nCount; ++i)
314 m_xFontBox->append_text(aFontList.GetFontName(i).GetFamilyName());
316 maFont.SetFontSize(Size(0, 24));
317 maFont.SetWeight(WEIGHT_NORMAL);
318 maFont.SetItalic(ITALIC_NONE);
319 maFont.SetFamily(FAMILY_DONTKNOW);
320 maFont.SetPitch(PITCH_DONTKNOW);
321 maFont.SetCharSet(RTL_TEXTENCODING_DONTKNOW);
322 maFont.SetTransparent(true);
325 m_xFontBox->connect_changed(LINK(this, SmFontDialog, FontSelectHdl));
326 m_xBoldCheckBox->connect_toggled(LINK(this, SmFontDialog, AttrChangeHdl));
327 m_xItalicCheckBox->connect_toggled(LINK(this, SmFontDialog, AttrChangeHdl));
329 if (bHideCheckboxes)
331 m_xBoldCheckBox->set_active(false);
332 m_xBoldCheckBox->set_sensitive(false);
333 m_xItalicCheckBox->set_active(false);
334 m_xItalicCheckBox->set_sensitive(false);
335 m_xAttrFrame->hide();
339 SmFontDialog::~SmFontDialog()
343 namespace {
345 class SaveDefaultsQuery : public weld::MessageDialogController
347 public:
348 explicit SaveDefaultsQuery(weld::Widget* pParent)
349 : MessageDialogController(pParent, "modules/smath/ui/savedefaultsdialog.ui",
350 "SaveDefaultsDialog")
357 IMPL_LINK_NOARG( SmFontSizeDialog, DefaultButtonClickHdl, weld::Button&, void )
359 SaveDefaultsQuery aQuery(m_xDialog.get());
360 if (aQuery.run() == RET_YES)
362 SmModule *pp = SM_MOD();
363 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
364 WriteTo( aFmt );
365 pp->GetConfig()->SetStandardFormat( aFmt );
369 SmFontSizeDialog::SmFontSizeDialog(weld::Window* pParent)
370 : GenericDialogController(pParent, "modules/smath/ui/fontsizedialog.ui", "FontSizeDialog")
371 , m_xBaseSize(m_xBuilder->weld_metric_spin_button("spinB_baseSize", FieldUnit::POINT))
372 , m_xTextSize(m_xBuilder->weld_metric_spin_button("spinB_text", FieldUnit::PERCENT))
373 , m_xIndexSize(m_xBuilder->weld_metric_spin_button("spinB_index", FieldUnit::PERCENT))
374 , m_xFunctionSize(m_xBuilder->weld_metric_spin_button("spinB_function", FieldUnit::PERCENT))
375 , m_xOperatorSize(m_xBuilder->weld_metric_spin_button("spinB_operator", FieldUnit::PERCENT))
376 , m_xBorderSize(m_xBuilder->weld_metric_spin_button("spinB_limit", FieldUnit::PERCENT))
377 , m_xDefaultButton(m_xBuilder->weld_button("default"))
379 m_xDefaultButton->connect_clicked(LINK(this, SmFontSizeDialog, DefaultButtonClickHdl));
382 SmFontSizeDialog::~SmFontSizeDialog()
386 void SmFontSizeDialog::ReadFrom(const SmFormat &rFormat)
388 //! watch out: round properly!
389 m_xBaseSize->set_value( SmRoundFraction(
390 Sm100th_mmToPts( rFormat.GetBaseSize().Height() ) ), FieldUnit::NONE );
392 m_xTextSize->set_value( rFormat.GetRelSize(SIZ_TEXT), FieldUnit::NONE );
393 m_xIndexSize->set_value( rFormat.GetRelSize(SIZ_INDEX), FieldUnit::NONE );
394 m_xFunctionSize->set_value( rFormat.GetRelSize(SIZ_FUNCTION), FieldUnit::NONE );
395 m_xOperatorSize->set_value( rFormat.GetRelSize(SIZ_OPERATOR), FieldUnit::NONE );
396 m_xBorderSize->set_value( rFormat.GetRelSize(SIZ_LIMITS), FieldUnit::NONE );
399 void SmFontSizeDialog::WriteTo(SmFormat &rFormat) const
401 rFormat.SetBaseSize( Size(0, SmPtsTo100th_mm( static_cast< tools::Long >(m_xBaseSize->get_value(FieldUnit::NONE)))) );
403 rFormat.SetRelSize(SIZ_TEXT, sal::static_int_cast<sal_uInt16>(m_xTextSize->get_value(FieldUnit::NONE)));
404 rFormat.SetRelSize(SIZ_INDEX, sal::static_int_cast<sal_uInt16>(m_xIndexSize->get_value(FieldUnit::NONE)));
405 rFormat.SetRelSize(SIZ_FUNCTION, sal::static_int_cast<sal_uInt16>(m_xFunctionSize->get_value(FieldUnit::NONE)));
406 rFormat.SetRelSize(SIZ_OPERATOR, sal::static_int_cast<sal_uInt16>(m_xOperatorSize->get_value(FieldUnit::NONE)));
407 rFormat.SetRelSize(SIZ_LIMITS, sal::static_int_cast<sal_uInt16>(m_xBorderSize->get_value(FieldUnit::NONE)));
409 const Size aTmp (rFormat.GetBaseSize());
410 for (sal_uInt16 i = FNT_BEGIN; i <= FNT_END; i++)
411 rFormat.SetFontSize(i, aTmp);
413 rFormat.RequestApplyChanges();
416 IMPL_LINK(SmFontTypeDialog, MenuSelectHdl, const OString&, rIdent, void)
418 SmFontPickListBox *pActiveListBox;
420 bool bHideCheckboxes = false;
421 if (rIdent == "variables")
422 pActiveListBox = m_xVariableFont.get();
423 else if (rIdent == "functions")
424 pActiveListBox = m_xFunctionFont.get();
425 else if (rIdent == "numbers")
426 pActiveListBox = m_xNumberFont.get();
427 else if (rIdent == "text")
428 pActiveListBox = m_xTextFont.get();
429 else if (rIdent == "serif")
431 pActiveListBox = m_xSerifFont.get();
432 bHideCheckboxes = true;
434 else if (rIdent == "sansserif")
436 pActiveListBox = m_xSansFont.get();
437 bHideCheckboxes = true;
439 else if (rIdent == "fixedwidth")
441 pActiveListBox = m_xFixedFont.get();
442 bHideCheckboxes = true;
444 else
445 pActiveListBox = nullptr;
447 if (pActiveListBox)
449 SmFontDialog aFontDialog(m_xDialog.get(), pFontListDev, bHideCheckboxes);
451 pActiveListBox->WriteTo(aFontDialog);
452 if (aFontDialog.run() == RET_OK)
453 pActiveListBox->ReadFrom(aFontDialog);
457 IMPL_LINK_NOARG(SmFontTypeDialog, DefaultButtonClickHdl, weld::Button&, void)
459 SaveDefaultsQuery aQuery(m_xDialog.get());
460 if (aQuery.run() == RET_YES)
462 SmModule *pp = SM_MOD();
463 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
464 WriteTo( aFmt );
465 pp->GetConfig()->SetStandardFormat( aFmt, true );
469 SmFontTypeDialog::SmFontTypeDialog(weld::Window* pParent, OutputDevice *pFntListDevice)
470 : GenericDialogController(pParent, "modules/smath/ui/fonttypedialog.ui", "FontsDialog")
471 , pFontListDev(pFntListDevice)
472 , m_xVariableFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("variableCB")))
473 , m_xFunctionFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("functionCB")))
474 , m_xNumberFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("numberCB")))
475 , m_xTextFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("textCB")))
476 , m_xSerifFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("serifCB")))
477 , m_xSansFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("sansCB")))
478 , m_xFixedFont(new SmFontPickListBox(m_xBuilder->weld_combo_box("fixedCB")))
479 , m_xMenuButton(m_xBuilder->weld_menu_button("modify"))
480 , m_xDefaultButton(m_xBuilder->weld_button("default"))
482 m_xDefaultButton->connect_clicked(LINK(this, SmFontTypeDialog, DefaultButtonClickHdl));
483 m_xMenuButton->connect_selected(LINK(this, SmFontTypeDialog, MenuSelectHdl));
486 SmFontTypeDialog::~SmFontTypeDialog()
490 void SmFontTypeDialog::ReadFrom(const SmFormat &rFormat)
492 SmModule *pp = SM_MOD();
494 *m_xVariableFont = pp->GetConfig()->GetFontPickList(FNT_VARIABLE);
495 *m_xFunctionFont = pp->GetConfig()->GetFontPickList(FNT_FUNCTION);
496 *m_xNumberFont = pp->GetConfig()->GetFontPickList(FNT_NUMBER);
497 *m_xTextFont = pp->GetConfig()->GetFontPickList(FNT_TEXT);
498 *m_xSerifFont = pp->GetConfig()->GetFontPickList(FNT_SERIF);
499 *m_xSansFont = pp->GetConfig()->GetFontPickList(FNT_SANS);
500 *m_xFixedFont = pp->GetConfig()->GetFontPickList(FNT_FIXED);
502 m_xVariableFont->Insert( rFormat.GetFont(FNT_VARIABLE) );
503 m_xFunctionFont->Insert( rFormat.GetFont(FNT_FUNCTION) );
504 m_xNumberFont->Insert( rFormat.GetFont(FNT_NUMBER) );
505 m_xTextFont->Insert( rFormat.GetFont(FNT_TEXT) );
506 m_xSerifFont->Insert( rFormat.GetFont(FNT_SERIF) );
507 m_xSansFont->Insert( rFormat.GetFont(FNT_SANS) );
508 m_xFixedFont->Insert( rFormat.GetFont(FNT_FIXED) );
512 void SmFontTypeDialog::WriteTo(SmFormat &rFormat) const
514 SmModule *pp = SM_MOD();
516 pp->GetConfig()->GetFontPickList(FNT_VARIABLE) = *m_xVariableFont;
517 pp->GetConfig()->GetFontPickList(FNT_FUNCTION) = *m_xFunctionFont;
518 pp->GetConfig()->GetFontPickList(FNT_NUMBER) = *m_xNumberFont;
519 pp->GetConfig()->GetFontPickList(FNT_TEXT) = *m_xTextFont;
520 pp->GetConfig()->GetFontPickList(FNT_SERIF) = *m_xSerifFont;
521 pp->GetConfig()->GetFontPickList(FNT_SANS) = *m_xSansFont;
522 pp->GetConfig()->GetFontPickList(FNT_FIXED) = *m_xFixedFont;
524 rFormat.SetFont( FNT_VARIABLE, m_xVariableFont->Get() );
525 rFormat.SetFont( FNT_FUNCTION, m_xFunctionFont->Get() );
526 rFormat.SetFont( FNT_NUMBER, m_xNumberFont->Get() );
527 rFormat.SetFont( FNT_TEXT, m_xTextFont->Get() );
528 rFormat.SetFont( FNT_SERIF, m_xSerifFont->Get() );
529 rFormat.SetFont( FNT_SANS, m_xSansFont->Get() );
530 rFormat.SetFont( FNT_FIXED, m_xFixedFont->Get() );
532 rFormat.RequestApplyChanges();
535 /**************************************************************************/
537 namespace {
539 struct FieldMinMax
541 sal_uInt16 nMin, nMax;
546 // Data for min and max values of the 4 metric fields
547 // for each of the 10 categories
548 const FieldMinMax pMinMaxData[10][4] =
550 // 0
551 {{ 0, 200 }, { 0, 200 }, { 0, 100 }, { 0, 0 }},
552 // 1
553 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
554 // 2
555 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
556 // 3
557 {{ 0, 100 }, { 1, 100 }, { 0, 0 }, { 0, 0 }},
558 // 4
559 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
560 // 5
561 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 100 }},
562 // 6
563 {{ 0, 300 }, { 0, 300 }, { 0, 0 }, { 0, 0 }},
564 // 7
565 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
566 // 8
567 {{ 0, 100 }, { 0, 100 }, { 0, 0 }, { 0, 0 }},
568 // 9
569 {{ 0, 10000 }, { 0, 10000 }, { 0, 10000 }, { 0, 10000 }}
572 SmCategoryDesc::SmCategoryDesc(weld::Builder& rBuilder, sal_uInt16 nCategoryIdx)
574 ++nCategoryIdx;
575 std::unique_ptr<weld::Label> xTitle(rBuilder.weld_label(OString::number(nCategoryIdx)+"title"));
576 if (xTitle)
578 Name = xTitle->get_label();
580 for (int i = 0; i < 4; ++i)
582 std::unique_ptr<weld::Label> xLabel(rBuilder.weld_label(OString::number(nCategoryIdx)+"label"+OString::number(i+1)));
584 if (xLabel)
586 Strings[i] = xLabel->get_label();
587 Graphics[i] = rBuilder.weld_widget(OString::number(nCategoryIdx)+"image"+OString::number(i+1));
589 else
591 Strings[i].clear();
592 Graphics[i].reset();
595 const FieldMinMax& rMinMax = pMinMaxData[ nCategoryIdx-1 ][i];
596 Value[i] = Minimum[i] = rMinMax.nMin;
597 Maximum[i] = rMinMax.nMax;
601 SmCategoryDesc::~SmCategoryDesc()
605 /**************************************************************************/
607 IMPL_LINK( SmDistanceDialog, GetFocusHdl, weld::Widget&, rControl, void )
609 if (!m_xCategories[nActiveCategory])
610 return;
612 sal_uInt16 i;
614 if (&rControl == &m_xMetricField1->get_widget())
615 i = 0;
616 else if (&rControl == &m_xMetricField2->get_widget())
617 i = 1;
618 else if (&rControl == &m_xMetricField3->get_widget())
619 i = 2;
620 else if (&rControl == &m_xMetricField4->get_widget())
621 i = 3;
622 else
623 return;
624 if (m_pCurrentImage)
625 m_pCurrentImage->hide();
626 m_pCurrentImage = m_xCategories[nActiveCategory]->GetGraphic(i);
627 m_pCurrentImage->show();
630 IMPL_LINK(SmDistanceDialog, MenuSelectHdl, const OString&, rId, void)
632 assert(rId.startsWith("menuitem"));
633 SetCategory(rId.replaceFirst("menuitem", "").toInt32() - 1);
636 IMPL_LINK_NOARG( SmDistanceDialog, DefaultButtonClickHdl, weld::Button&, void )
638 SaveDefaultsQuery aQuery(m_xDialog.get());
639 if (aQuery.run() == RET_YES)
641 SmModule *pp = SM_MOD();
642 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
643 WriteTo( aFmt );
644 pp->GetConfig()->SetStandardFormat( aFmt );
648 IMPL_LINK( SmDistanceDialog, CheckBoxClickHdl, weld::ToggleButton&, rCheckBox, void )
650 if (&rCheckBox == m_xCheckBox1.get())
652 bool bChecked = m_xCheckBox1->get_active();
653 m_xFixedText4->set_sensitive( bChecked );
654 m_xMetricField4->set_sensitive( bChecked );
658 void SmDistanceDialog::SetCategory(sal_uInt16 nCategory)
660 assert(nCategory < NOCATEGORIES && "Sm: wrong category number in SmDistanceDialog");
662 // array to convert category- and metricfield-number in help ids.
663 // 0 is used in case of unused combinations.
664 assert(NOCATEGORIES == 10 && "Sm : array doesn't fit into the number of categories");
665 static const char * aCatMf2Hid[10][4] =
667 { HID_SMA_DEFAULT_DIST, HID_SMA_LINE_DIST, HID_SMA_ROOT_DIST, nullptr },
668 { HID_SMA_SUP_DIST, HID_SMA_SUB_DIST , nullptr, nullptr },
669 { HID_SMA_NUMERATOR_DIST, HID_SMA_DENOMINATOR_DIST, nullptr, nullptr },
670 { HID_SMA_FRACLINE_EXCWIDTH, HID_SMA_FRACLINE_LINEWIDTH, nullptr, nullptr },
671 { HID_SMA_UPPERLIMIT_DIST, HID_SMA_LOWERLIMIT_DIST, nullptr, nullptr },
672 { HID_SMA_BRACKET_EXCHEIGHT, HID_SMA_BRACKET_DIST, nullptr, HID_SMA_BRACKET_EXCHEIGHT2 },
673 { HID_SMA_MATRIXROW_DIST, HID_SMA_MATRIXCOL_DIST, nullptr, nullptr },
674 { HID_SMA_ATTRIBUT_DIST, HID_SMA_INTERATTRIBUT_DIST, nullptr, nullptr },
675 { HID_SMA_OPERATOR_EXCHEIGHT, HID_SMA_OPERATOR_DIST, nullptr, nullptr },
676 { HID_SMA_LEFTBORDER_DIST, HID_SMA_RIGHTBORDER_DIST, HID_SMA_UPPERBORDER_DIST, HID_SMA_LOWERBORDER_DIST }
679 // array to help iterate over the controls
680 std::pair<weld::Label*, weld::MetricSpinButton*> const aWin[4] =
682 { m_xFixedText1.get(), m_xMetricField1.get() },
683 { m_xFixedText2.get(), m_xMetricField2.get() },
684 { m_xFixedText3.get(), m_xMetricField3.get() },
685 { m_xFixedText4.get(), m_xMetricField4.get() }
688 SmCategoryDesc *pCat;
690 // remember the (maybe new) settings of the active SmCategoryDesc
691 // before switching to the new one
692 if (nActiveCategory != CATEGORY_NONE)
694 pCat = m_xCategories[nActiveCategory].get();
695 pCat->SetValue(0, sal::static_int_cast<sal_uInt16>(m_xMetricField1->get_value(FieldUnit::NONE)));
696 pCat->SetValue(1, sal::static_int_cast<sal_uInt16>(m_xMetricField2->get_value(FieldUnit::NONE)));
697 pCat->SetValue(2, sal::static_int_cast<sal_uInt16>(m_xMetricField3->get_value(FieldUnit::NONE)));
698 pCat->SetValue(3, sal::static_int_cast<sal_uInt16>(m_xMetricField4->get_value(FieldUnit::NONE)));
700 if (nActiveCategory == 5)
701 bScaleAllBrackets = m_xCheckBox1->get_active();
703 m_xMenuButton->set_item_active("menuitem" + OString::number(nActiveCategory + 1), false);
706 // activation/deactivation of the associated controls depending on the chosen category
707 bool bActive;
708 for (sal_uInt16 i = 0; i < 4; i++)
710 weld::Label *pFT = aWin[i].first;
711 weld::MetricSpinButton *pMF = aWin[i].second;
713 // To determine which Controls should be active, the existence
714 // of an associated HelpID is checked
715 bActive = aCatMf2Hid[nCategory][i] != nullptr;
717 pFT->set_visible(bActive);
718 pFT->set_sensitive(bActive);
719 pMF->set_visible(bActive);
720 pMF->set_sensitive(bActive);
722 // set measurement unit and number of decimal places
723 FieldUnit eUnit;
724 sal_uInt16 nDigits;
725 if (nCategory < 9)
727 eUnit = FieldUnit::PERCENT;
728 nDigits = 0;
730 else
732 eUnit = FieldUnit::MM_100TH;
733 nDigits = 2;
735 pMF->set_unit(eUnit); // changes the value
736 pMF->set_digits(nDigits);
738 if (bActive)
740 pCat = m_xCategories[nCategory].get();
741 pFT->set_label(pCat->GetString(i));
743 pMF->set_range(pCat->GetMinimum(i), pCat->GetMaximum(i), FieldUnit::NONE);
744 pMF->set_value(pCat->GetValue(i), FieldUnit::NONE);
746 pMF->set_help_id(aCatMf2Hid[nCategory][i]);
749 // activate the CheckBox and the associated MetricField if we're dealing with the brackets menu
750 bActive = nCategory == 5;
751 m_xCheckBox1->set_visible(bActive);
752 m_xCheckBox1->set_sensitive(bActive);
753 if (bActive)
755 m_xCheckBox1->set_active(bScaleAllBrackets);
757 bool bChecked = m_xCheckBox1->get_active();
758 m_xFixedText4->set_sensitive( bChecked );
759 m_xMetricField4->set_sensitive( bChecked );
762 m_xMenuButton->set_item_active("menuitem" + OString::number(nCategory + 1), true);
763 m_xFrame->set_label(m_xCategories[nCategory]->GetName());
765 nActiveCategory = nCategory;
767 m_xMetricField1->grab_focus();
770 SmDistanceDialog::SmDistanceDialog(weld::Window *pParent)
771 : GenericDialogController(pParent, "modules/smath/ui/spacingdialog.ui", "SpacingDialog")
772 , m_xFrame(m_xBuilder->weld_frame("template"))
773 , m_xFixedText1(m_xBuilder->weld_label("label1"))
774 , m_xMetricField1(m_xBuilder->weld_metric_spin_button("spinbutton1", FieldUnit::CM))
775 , m_xFixedText2(m_xBuilder->weld_label("label2"))
776 , m_xMetricField2(m_xBuilder->weld_metric_spin_button("spinbutton2", FieldUnit::CM))
777 , m_xFixedText3(m_xBuilder->weld_label("label3"))
778 , m_xMetricField3(m_xBuilder->weld_metric_spin_button("spinbutton3", FieldUnit::CM))
779 , m_xCheckBox1(m_xBuilder->weld_check_button("checkbutton"))
780 , m_xFixedText4(m_xBuilder->weld_label("label4"))
781 , m_xMetricField4(m_xBuilder->weld_metric_spin_button("spinbutton4", FieldUnit::CM))
782 , m_xMenuButton(m_xBuilder->weld_menu_button("category"))
783 , m_xDefaultButton(m_xBuilder->weld_button("default"))
784 , m_xBitmap(m_xBuilder->weld_widget("image"))
785 , m_pCurrentImage(m_xBitmap.get())
787 for (sal_uInt16 i = 0; i < NOCATEGORIES; ++i)
788 m_xCategories[i].reset( new SmCategoryDesc(*m_xBuilder, i) );
789 nActiveCategory = CATEGORY_NONE;
790 bScaleAllBrackets = false;
792 m_xMetricField1->connect_focus_in(LINK(this, SmDistanceDialog, GetFocusHdl));
793 m_xMetricField2->connect_focus_in(LINK(this, SmDistanceDialog, GetFocusHdl));
794 m_xMetricField3->connect_focus_in(LINK(this, SmDistanceDialog, GetFocusHdl));
795 m_xMetricField4->connect_focus_in(LINK(this, SmDistanceDialog, GetFocusHdl));
796 m_xCheckBox1->connect_toggled(LINK(this, SmDistanceDialog, CheckBoxClickHdl));
797 m_xMenuButton->connect_selected(LINK(this, SmDistanceDialog, MenuSelectHdl));
798 m_xDefaultButton->connect_clicked(LINK(this, SmDistanceDialog, DefaultButtonClickHdl));
800 //set the initial size, with max visible widgets visible, as preferred size
801 m_xDialog->set_size_request(-1, m_xDialog->get_preferred_size().Height());
804 SmDistanceDialog::~SmDistanceDialog()
808 void SmDistanceDialog::ReadFrom(const SmFormat &rFormat)
810 m_xCategories[0]->SetValue(0, rFormat.GetDistance(DIS_HORIZONTAL));
811 m_xCategories[0]->SetValue(1, rFormat.GetDistance(DIS_VERTICAL));
812 m_xCategories[0]->SetValue(2, rFormat.GetDistance(DIS_ROOT));
813 m_xCategories[1]->SetValue(0, rFormat.GetDistance(DIS_SUPERSCRIPT));
814 m_xCategories[1]->SetValue(1, rFormat.GetDistance(DIS_SUBSCRIPT));
815 m_xCategories[2]->SetValue(0, rFormat.GetDistance(DIS_NUMERATOR));
816 m_xCategories[2]->SetValue(1, rFormat.GetDistance(DIS_DENOMINATOR));
817 m_xCategories[3]->SetValue(0, rFormat.GetDistance(DIS_FRACTION));
818 m_xCategories[3]->SetValue(1, rFormat.GetDistance(DIS_STROKEWIDTH));
819 m_xCategories[4]->SetValue(0, rFormat.GetDistance(DIS_UPPERLIMIT));
820 m_xCategories[4]->SetValue(1, rFormat.GetDistance(DIS_LOWERLIMIT));
821 m_xCategories[5]->SetValue(0, rFormat.GetDistance(DIS_BRACKETSIZE));
822 m_xCategories[5]->SetValue(1, rFormat.GetDistance(DIS_BRACKETSPACE));
823 m_xCategories[5]->SetValue(3, rFormat.GetDistance(DIS_NORMALBRACKETSIZE));
824 m_xCategories[6]->SetValue(0, rFormat.GetDistance(DIS_MATRIXROW));
825 m_xCategories[6]->SetValue(1, rFormat.GetDistance(DIS_MATRIXCOL));
826 m_xCategories[7]->SetValue(0, rFormat.GetDistance(DIS_ORNAMENTSIZE));
827 m_xCategories[7]->SetValue(1, rFormat.GetDistance(DIS_ORNAMENTSPACE));
828 m_xCategories[8]->SetValue(0, rFormat.GetDistance(DIS_OPERATORSIZE));
829 m_xCategories[8]->SetValue(1, rFormat.GetDistance(DIS_OPERATORSPACE));
830 m_xCategories[9]->SetValue(0, rFormat.GetDistance(DIS_LEFTSPACE));
831 m_xCategories[9]->SetValue(1, rFormat.GetDistance(DIS_RIGHTSPACE));
832 m_xCategories[9]->SetValue(2, rFormat.GetDistance(DIS_TOPSPACE));
833 m_xCategories[9]->SetValue(3, rFormat.GetDistance(DIS_BOTTOMSPACE));
835 bScaleAllBrackets = rFormat.IsScaleNormalBrackets();
837 // force update (even of category 0) by setting nActiveCategory to a
838 // non-existent category number
839 nActiveCategory = CATEGORY_NONE;
840 SetCategory(0);
844 void SmDistanceDialog::WriteTo(SmFormat &rFormat) /*const*/
846 // TODO can they actually be different?
847 // if that's not the case 'const' could be used above!
848 SetCategory(nActiveCategory);
850 rFormat.SetDistance( DIS_HORIZONTAL, m_xCategories[0]->GetValue(0) );
851 rFormat.SetDistance( DIS_VERTICAL, m_xCategories[0]->GetValue(1) );
852 rFormat.SetDistance( DIS_ROOT, m_xCategories[0]->GetValue(2) );
853 rFormat.SetDistance( DIS_SUPERSCRIPT, m_xCategories[1]->GetValue(0) );
854 rFormat.SetDistance( DIS_SUBSCRIPT, m_xCategories[1]->GetValue(1) );
855 rFormat.SetDistance( DIS_NUMERATOR, m_xCategories[2]->GetValue(0) );
856 rFormat.SetDistance( DIS_DENOMINATOR, m_xCategories[2]->GetValue(1) );
857 rFormat.SetDistance( DIS_FRACTION, m_xCategories[3]->GetValue(0) );
858 rFormat.SetDistance( DIS_STROKEWIDTH, m_xCategories[3]->GetValue(1) );
859 rFormat.SetDistance( DIS_UPPERLIMIT, m_xCategories[4]->GetValue(0) );
860 rFormat.SetDistance( DIS_LOWERLIMIT, m_xCategories[4]->GetValue(1) );
861 rFormat.SetDistance( DIS_BRACKETSIZE, m_xCategories[5]->GetValue(0) );
862 rFormat.SetDistance( DIS_BRACKETSPACE, m_xCategories[5]->GetValue(1) );
863 rFormat.SetDistance( DIS_MATRIXROW, m_xCategories[6]->GetValue(0) );
864 rFormat.SetDistance( DIS_MATRIXCOL, m_xCategories[6]->GetValue(1) );
865 rFormat.SetDistance( DIS_ORNAMENTSIZE, m_xCategories[7]->GetValue(0) );
866 rFormat.SetDistance( DIS_ORNAMENTSPACE, m_xCategories[7]->GetValue(1) );
867 rFormat.SetDistance( DIS_OPERATORSIZE, m_xCategories[8]->GetValue(0) );
868 rFormat.SetDistance( DIS_OPERATORSPACE, m_xCategories[8]->GetValue(1) );
869 rFormat.SetDistance( DIS_LEFTSPACE, m_xCategories[9]->GetValue(0) );
870 rFormat.SetDistance( DIS_RIGHTSPACE, m_xCategories[9]->GetValue(1) );
871 rFormat.SetDistance( DIS_TOPSPACE, m_xCategories[9]->GetValue(2) );
872 rFormat.SetDistance( DIS_BOTTOMSPACE, m_xCategories[9]->GetValue(3) );
873 rFormat.SetDistance( DIS_NORMALBRACKETSIZE, m_xCategories[5]->GetValue(3) );
875 rFormat.SetScaleNormalBrackets( bScaleAllBrackets );
877 rFormat.RequestApplyChanges();
880 IMPL_LINK_NOARG( SmAlignDialog, DefaultButtonClickHdl, weld::Button&, void )
882 SaveDefaultsQuery aQuery(m_xDialog.get());
883 if (aQuery.run() == RET_YES)
885 SmModule *pp = SM_MOD();
886 SmFormat aFmt( pp->GetConfig()->GetStandardFormat() );
887 WriteTo( aFmt );
888 pp->GetConfig()->SetStandardFormat( aFmt );
892 SmAlignDialog::SmAlignDialog(weld::Window* pParent)
893 : GenericDialogController(pParent, "modules/smath/ui/alignmentdialog.ui", "AlignmentDialog")
894 , m_xLeft(m_xBuilder->weld_radio_button("left"))
895 , m_xCenter(m_xBuilder->weld_radio_button("center"))
896 , m_xRight(m_xBuilder->weld_radio_button("right"))
897 , m_xDefaultButton(m_xBuilder->weld_button("default"))
899 m_xDefaultButton->connect_clicked(LINK(this, SmAlignDialog, DefaultButtonClickHdl));
902 SmAlignDialog::~SmAlignDialog()
906 void SmAlignDialog::ReadFrom(const SmFormat &rFormat)
908 switch (rFormat.GetHorAlign())
910 case SmHorAlign::Left:
911 m_xLeft->set_active(true);
912 break;
913 case SmHorAlign::Center:
914 m_xCenter->set_active(true);
915 break;
916 case SmHorAlign::Right:
917 m_xRight->set_active(true);
918 break;
922 void SmAlignDialog::WriteTo(SmFormat &rFormat) const
924 if (m_xLeft->get_active())
925 rFormat.SetHorAlign(SmHorAlign::Left);
926 else if (m_xRight->get_active())
927 rFormat.SetHorAlign(SmHorAlign::Right);
928 else
929 rFormat.SetHorAlign(SmHorAlign::Center);
931 rFormat.RequestApplyChanges();
934 SmShowSymbolSet::SmShowSymbolSet(std::unique_ptr<weld::ScrolledWindow> pScrolledWindow)
935 : nLen(0)
936 , nRows(0)
937 , nColumns(0)
938 , nXOffset(0)
939 , nYOffset(0)
940 , nSelectSymbol(SYMBOL_NONE)
941 , m_xScrolledWindow(std::move(pScrolledWindow))
943 m_xScrolledWindow->connect_vadjustment_changed(LINK(this, SmShowSymbolSet, ScrollHdl));
946 Point SmShowSymbolSet::OffsetPoint(const Point &rPoint) const
948 return Point(rPoint.X() + nXOffset, rPoint.Y() + nYOffset);
951 void SmShowSymbolSet::Resize()
953 CustomWidgetController::Resize();
954 Size aWinSize(GetOutputSizePixel());
955 if (aWinSize != m_aOldSize)
957 calccols(GetDrawingArea()->get_ref_device());
958 m_aOldSize = aWinSize;
962 void SmShowSymbolSet::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
964 Color aBackgroundColor;
965 Color aTextColor;
966 lclGetSettingColors(aBackgroundColor, aTextColor);
968 rRenderContext.SetBackground(Wallpaper(aBackgroundColor));
969 rRenderContext.SetTextColor(aTextColor);
971 rRenderContext.Push(PushFlags::MAPMODE);
973 // set MapUnit for which 'nLen' has been calculated
974 rRenderContext.SetMapMode(MapMode(MapUnit::MapPixel));
976 sal_uInt16 v = sal::static_int_cast< sal_uInt16 >(m_xScrolledWindow->vadjustment_get_value() * nColumns);
977 size_t nSymbols = aSymbolSet.size();
979 Color aTxtColor(rRenderContext.GetTextColor());
980 for (size_t i = v; i < nSymbols ; i++)
982 SmSym aSymbol(*aSymbolSet[i]);
983 vcl::Font aFont(aSymbol.GetFace());
984 aFont.SetAlignment(ALIGN_TOP);
986 // taking a FontSize which is a bit smaller (compared to nLen) in order to have a buffer
987 // (hopefully enough for left and right, too)
988 aFont.SetFontSize(Size(0, nLen - (nLen / 3)));
989 rRenderContext.SetFont(aFont);
990 // keep text color
991 rRenderContext.SetTextColor(aTxtColor);
993 int nIV = i - v;
994 sal_UCS4 cChar = aSymbol.GetCharacter();
995 OUString aText(&cChar, 1);
996 Size aSize(rRenderContext.GetTextWidth( aText ), rRenderContext.GetTextHeight());
998 Point aPoint((nIV % nColumns) * nLen + (nLen - aSize.Width()) / 2,
999 (nIV / nColumns) * nLen + (nLen - aSize.Height()) / 2);
1001 rRenderContext.DrawText(OffsetPoint(aPoint), aText);
1004 if (nSelectSymbol != SYMBOL_NONE)
1006 Point aPoint(((nSelectSymbol - v) % nColumns) * nLen,
1007 ((nSelectSymbol - v) / nColumns) * nLen);
1009 rRenderContext.Invert(tools::Rectangle(OffsetPoint(aPoint), Size(nLen, nLen)));
1013 rRenderContext.Pop();
1016 bool SmShowSymbolSet::MouseButtonDown(const MouseEvent& rMEvt)
1018 GrabFocus();
1020 Size aOutputSize(nColumns * nLen, nRows * nLen);
1021 aOutputSize.AdjustWidth(nXOffset );
1022 aOutputSize.AdjustHeight(nYOffset );
1023 Point aPoint(rMEvt.GetPosPixel());
1024 aPoint.AdjustX( -nXOffset );
1025 aPoint.AdjustY( -nYOffset );
1027 if (rMEvt.IsLeft() && tools::Rectangle(Point(0, 0), aOutputSize).IsInside(rMEvt.GetPosPixel()))
1029 tools::Long nPos = (aPoint.Y() / nLen) * nColumns + (aPoint.X() / nLen) +
1030 m_xScrolledWindow->vadjustment_get_value() * nColumns;
1031 SelectSymbol( sal::static_int_cast< sal_uInt16 >(nPos) );
1033 aSelectHdlLink.Call(*this);
1035 if (rMEvt.GetClicks() > 1)
1036 aDblClickHdlLink.Call(*this);
1039 return true;
1042 bool SmShowSymbolSet::KeyInput(const KeyEvent& rKEvt)
1044 sal_uInt16 n = nSelectSymbol;
1046 if (n != SYMBOL_NONE)
1048 switch (rKEvt.GetKeyCode().GetCode())
1050 case KEY_DOWN: n = n + nColumns; break;
1051 case KEY_UP: n = n - nColumns; break;
1052 case KEY_LEFT: n -= 1; break;
1053 case KEY_RIGHT: n += 1; break;
1054 case KEY_HOME: n = 0; break;
1055 case KEY_END: n = static_cast< sal_uInt16 >(aSymbolSet.size() - 1); break;
1056 case KEY_PAGEUP: n -= nColumns * nRows; break;
1057 case KEY_PAGEDOWN: n += nColumns * nRows; break;
1058 default:
1059 return false;
1062 else
1063 n = 0;
1065 if (n >= aSymbolSet.size())
1066 n = nSelectSymbol;
1068 // adjust scrollbar
1069 if ((n < sal::static_int_cast<sal_uInt16>(m_xScrolledWindow->vadjustment_get_value() * nColumns)) ||
1070 (n >= sal::static_int_cast<sal_uInt16>((m_xScrolledWindow->vadjustment_get_value() + nRows) * nColumns)))
1072 m_xScrolledWindow->vadjustment_set_value(n / nColumns);
1073 Invalidate();
1076 SelectSymbol(n);
1077 aSelectHdlLink.Call(*this);
1079 return true;
1082 void SmShowSymbolSet::calccols(const vcl::RenderContext& rRenderContext)
1084 // Height of 16pt in pixels (matching 'aOutputSize')
1085 nLen = rRenderContext.LogicToPixel(Size(0, 16), MapMode(MapUnit::MapPoint)).Height();
1087 Size aOutputSize(GetOutputSizePixel());
1089 nColumns = aOutputSize.Width() / nLen;
1090 nRows = aOutputSize.Height() / nLen;
1091 nColumns = std::max<tools::Long>(1, nColumns);
1092 nRows = std::max<tools::Long>(1, nRows);
1094 nXOffset = (aOutputSize.Width() - (nColumns * nLen)) / 2;
1095 nYOffset = (aOutputSize.Height() - (nRows * nLen)) / 2;
1097 SetScrollBarRange();
1100 void SmShowSymbolSet::SetSymbolSet(const SymbolPtrVec_t& rSymbolSet)
1102 aSymbolSet = rSymbolSet;
1103 SetScrollBarRange();
1104 Invalidate();
1107 void SmShowSymbolSet::SetScrollBarRange()
1109 const int nLastRow = (aSymbolSet.size() - 1 + nColumns) / nColumns;
1110 m_xScrolledWindow->vadjustment_configure(m_xScrolledWindow->vadjustment_get_value(), 0, nLastRow, 1, nRows - 1, nRows);
1111 Invalidate();
1114 void SmShowSymbolSet::SelectSymbol(sal_uInt16 nSymbol)
1116 int v = m_xScrolledWindow->vadjustment_get_value() * nColumns;
1118 if (nSelectSymbol != SYMBOL_NONE && nColumns)
1120 Point aPoint(OffsetPoint(Point(((nSelectSymbol - v) % nColumns) * nLen,
1121 ((nSelectSymbol - v) / nColumns) * nLen)));
1122 Invalidate(tools::Rectangle(aPoint, Size(nLen, nLen)));
1125 if (nSymbol < aSymbolSet.size())
1126 nSelectSymbol = nSymbol;
1128 if (aSymbolSet.empty())
1129 nSelectSymbol = SYMBOL_NONE;
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 (!nColumns)
1139 Invalidate();
1142 IMPL_LINK_NOARG(SmShowSymbolSet, ScrollHdl, weld::ScrolledWindow&, void)
1144 Invalidate();
1147 SmShowSymbol::SmShowSymbol()
1151 void SmShowSymbol::setFontSize(vcl::Font &rFont) const
1153 Size aSize(GetOutputSizePixel());
1154 rFont.SetFontSize(Size(0, aSize.Height() - aSize.Height() / 3));
1157 void SmShowSymbol::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1159 Color aBackgroundColor;
1160 Color aTextColor;
1161 lclGetSettingColors(aBackgroundColor, aTextColor);
1162 rRenderContext.SetBackground(Wallpaper(aBackgroundColor));
1163 rRenderContext.SetTextColor(aTextColor);
1164 rRenderContext.Erase();
1166 vcl::Font aFont(GetFont());
1167 setFontSize(aFont);
1168 rRenderContext.SetFont(aFont);
1170 const OUString &rText = GetText();
1171 Size aTextSize(rRenderContext.GetTextWidth(rText), rRenderContext.GetTextHeight());
1173 rRenderContext.DrawText(Point((rRenderContext.GetOutputSize().Width() - aTextSize.Width()) / 2,
1174 (rRenderContext.GetOutputSize().Height() * 7 / 10)), rText);
1177 bool SmShowSymbol::MouseButtonDown(const MouseEvent& rMEvt)
1179 if (rMEvt.GetClicks() > 1)
1180 aDblClickHdlLink.Call(*this);
1181 return true;
1184 void SmShowSymbol::SetSymbol(const SmSym *pSymbol)
1186 if (pSymbol)
1188 vcl::Font aFont(pSymbol->GetFace());
1189 aFont.SetAlignment(ALIGN_BASELINE);
1190 SetFont(aFont);
1192 sal_UCS4 cChar = pSymbol->GetCharacter();
1193 OUString aText(&cChar, 1);
1194 SetText( aText );
1197 Invalidate();
1200 void SmSymbolDialog::FillSymbolSets()
1201 // populate the entries of possible SymbolsSets in the dialog with
1202 // current values of the SymbolSet manager but selects none of those
1204 m_xSymbolSets->clear();
1205 m_xSymbolSets->set_active(-1);
1207 std::set< OUString > aSymbolSetNames( rSymbolMgr.GetSymbolSetNames() );
1208 for (const auto& rSymbolSetName : aSymbolSetNames)
1209 m_xSymbolSets->append_text(rSymbolSetName);
1212 IMPL_LINK_NOARG( SmSymbolDialog, SymbolSetChangeHdl, weld::ComboBox&, void )
1214 SelectSymbolSet(m_xSymbolSets->get_active_text());
1217 IMPL_LINK_NOARG( SmSymbolDialog, SymbolChangeHdl, SmShowSymbolSet&, void )
1219 SelectSymbol(m_xSymbolSetDisplay->GetSelectSymbol());
1222 IMPL_LINK_NOARG(SmSymbolDialog, EditClickHdl, weld::Button&, void)
1224 SmSymDefineDialog aDialog(m_xDialog.get(), pFontListDev, rSymbolMgr);
1226 // set current symbol and SymbolSet for the new dialog
1227 const OUString aSymSetName (m_xSymbolSets->get_active_text()),
1228 aSymName (m_xSymbolName->get_label());
1229 aDialog.SelectOldSymbolSet(aSymSetName);
1230 aDialog.SelectOldSymbol(aSymName);
1231 aDialog.SelectSymbolSet(aSymSetName);
1232 aDialog.SelectSymbol(aSymName);
1234 // remember old SymbolSet
1235 OUString aOldSymbolSet (m_xSymbolSets->get_active_text());
1237 sal_uInt16 nSymPos = m_xSymbolSetDisplay->GetSelectSymbol();
1239 // adapt dialog to data of the SymbolSet manager, which might have changed
1240 if (aDialog.run() == RET_OK && rSymbolMgr.IsModified())
1242 rSymbolMgr.Save();
1243 FillSymbolSets();
1246 // if the old SymbolSet doesn't exist anymore, go to the first one SymbolSet (if one exists)
1247 if (!SelectSymbolSet(aOldSymbolSet) && m_xSymbolSets->get_count() > 0)
1248 SelectSymbolSet(m_xSymbolSets->get_text(0));
1249 else
1251 // just update display of current symbol set
1252 assert(aSymSetName == aSymSetName); //unexpected change in symbol set name
1253 aSymbolSet = rSymbolMgr.GetSymbolSet( aSymbolSetName );
1254 m_xSymbolSetDisplay->SetSymbolSet( aSymbolSet );
1257 if (nSymPos >= aSymbolSet.size())
1258 nSymPos = static_cast< sal_uInt16 >(aSymbolSet.size()) - 1;
1259 SelectSymbol( nSymPos );
1262 IMPL_LINK_NOARG( SmSymbolDialog, SymbolDblClickHdl2, SmShowSymbolSet&, void )
1264 SymbolDblClickHdl();
1267 IMPL_LINK_NOARG( SmSymbolDialog, SymbolDblClickHdl, SmShowSymbol&, void )
1269 SymbolDblClickHdl();
1272 void SmSymbolDialog::SymbolDblClickHdl()
1274 GetClickHdl(*m_xGetBtn);
1275 m_xDialog->response(RET_OK);
1278 IMPL_LINK_NOARG(SmSymbolDialog, GetClickHdl, weld::Button&, void)
1280 const SmSym *pSym = GetSymbol();
1281 if (pSym)
1283 OUString aText = "%" + pSym->GetName() + " ";
1285 rViewSh.GetViewFrame()->GetDispatcher()->ExecuteList(
1286 SID_INSERTSPECIAL, SfxCallMode::RECORD,
1287 { new SfxStringItem(SID_INSERTSPECIAL, aText) });
1291 SmSymbolDialog::SmSymbolDialog(weld::Window *pParent, OutputDevice *pFntListDevice,
1292 SmSymbolManager &rMgr, SmViewShell &rViewShell)
1293 : GenericDialogController(pParent, "modules/smath/ui/catalogdialog.ui", "CatalogDialog")
1294 , rViewSh(rViewShell)
1295 , rSymbolMgr(rMgr)
1296 , pFontListDev(pFntListDevice)
1297 , m_xSymbolSets(m_xBuilder->weld_combo_box("symbolset"))
1298 , m_xSymbolSetDisplay(new SmShowSymbolSet(m_xBuilder->weld_scrolled_window("scrolledwindow", true)))
1299 , m_xSymbolSetDisplayArea(new weld::CustomWeld(*m_xBuilder, "symbolsetdisplay", *m_xSymbolSetDisplay))
1300 , m_xSymbolName(m_xBuilder->weld_label("symbolname"))
1301 , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder, "preview", m_aSymbolDisplay))
1302 , m_xGetBtn(m_xBuilder->weld_button("ok"))
1303 , m_xEditBtn(m_xBuilder->weld_button("edit"))
1305 m_xSymbolSets->make_sorted();
1307 aSymbolSetName.clear();
1308 aSymbolSet.clear();
1309 FillSymbolSets();
1310 if (m_xSymbolSets->get_count() > 0)
1311 SelectSymbolSet(m_xSymbolSets->get_text(0));
1313 m_xSymbolSets->connect_changed(LINK(this, SmSymbolDialog, SymbolSetChangeHdl));
1314 m_xSymbolSetDisplay->SetSelectHdl(LINK(this, SmSymbolDialog, SymbolChangeHdl));
1315 m_xSymbolSetDisplay->SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl2));
1316 m_aSymbolDisplay.SetDblClickHdl(LINK(this, SmSymbolDialog, SymbolDblClickHdl));
1317 m_xEditBtn->connect_clicked(LINK(this, SmSymbolDialog, EditClickHdl));
1318 m_xGetBtn->connect_clicked(LINK(this, SmSymbolDialog, GetClickHdl));
1321 SmSymbolDialog::~SmSymbolDialog()
1325 bool SmSymbolDialog::SelectSymbolSet(const OUString &rSymbolSetName)
1327 bool bRet = false;
1328 sal_Int32 nPos = m_xSymbolSets->find_text(rSymbolSetName);
1330 aSymbolSetName.clear();
1331 aSymbolSet.clear();
1332 if (nPos != -1)
1334 m_xSymbolSets->set_active(nPos);
1336 aSymbolSetName = rSymbolSetName;
1337 aSymbolSet = rSymbolMgr.GetSymbolSet( aSymbolSetName );
1339 // sort symbols by Unicode position (useful for displaying Greek characters alphabetically)
1340 std::sort( aSymbolSet.begin(), aSymbolSet.end(),
1341 [](const SmSym *pSym1, const SmSym *pSym2)
1343 return pSym1->GetCharacter() < pSym2->GetCharacter();
1344 } );
1346 m_xSymbolSetDisplay->SetSymbolSet( aSymbolSet );
1347 if (!aSymbolSet.empty())
1348 SelectSymbol(0);
1350 bRet = true;
1352 else
1353 m_xSymbolSets->set_active(-1);
1355 return bRet;
1358 void SmSymbolDialog::SelectSymbol(sal_uInt16 nSymbolNo)
1360 const SmSym *pSym = nullptr;
1361 if (!aSymbolSetName.isEmpty() && nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size()))
1362 pSym = aSymbolSet[ nSymbolNo ];
1364 m_xSymbolSetDisplay->SelectSymbol(nSymbolNo);
1365 m_aSymbolDisplay.SetSymbol(pSym);
1366 m_xSymbolName->set_label(pSym ? pSym->GetName() : OUString());
1369 const SmSym* SmSymbolDialog::GetSymbol() const
1371 sal_uInt16 nSymbolNo = m_xSymbolSetDisplay->GetSelectSymbol();
1372 bool bValid = !aSymbolSetName.isEmpty() && nSymbolNo < static_cast< sal_uInt16 >(aSymbolSet.size());
1373 return bValid ? aSymbolSet[ nSymbolNo ] : nullptr;
1376 void SmShowChar::Resize()
1378 const OUString &rText = GetText();
1379 if (rText.isEmpty())
1380 return;
1381 sal_Int32 nStrIndex = 0;
1382 sal_UCS4 cChar = rText.iterateCodePoints(&nStrIndex);
1383 SetSymbol(cChar, GetFont()); //force recalculation of size
1386 void SmShowChar::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
1388 Color aTextCol = rRenderContext.GetTextColor();
1389 Color aFillCol = rRenderContext.GetFillColor();
1391 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
1392 const Color aWindowTextColor(rStyleSettings.GetDialogTextColor());
1393 const Color aWindowColor(rStyleSettings.GetWindowColor());
1394 rRenderContext.SetTextColor(aWindowTextColor);
1395 rRenderContext.SetFillColor(aWindowColor);
1397 Size aSize(GetOutputSizePixel());
1398 rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), aSize));
1400 OUString aText(GetText());
1401 if (!aText.isEmpty())
1403 vcl::Font aFont(m_aFont);
1404 aFont.SetAlignment(ALIGN_TOP);
1405 rRenderContext.SetFont(aFont);
1407 Size aTextSize(rRenderContext.GetTextWidth(aText), rRenderContext.GetTextHeight());
1409 rRenderContext.DrawText(Point((aSize.Width() - aTextSize.Width()) / 2,
1410 (aSize.Height() - aTextSize.Height()) / 2), aText);
1413 rRenderContext.SetTextColor(aTextCol);
1414 rRenderContext.SetFillColor(aFillCol);
1417 void SmShowChar::SetSymbol( const SmSym *pSym )
1419 if (pSym)
1420 SetSymbol( pSym->GetCharacter(), pSym->GetFace() );
1424 void SmShowChar::SetSymbol( sal_UCS4 cChar, const vcl::Font &rFont )
1426 vcl::Font aFont( rFont );
1427 Size aSize(GetOutputSizePixel());
1428 aFont.SetFontSize(Size(0, aSize.Height() - aSize.Height() / 3));
1429 aFont.SetAlignment(ALIGN_BASELINE);
1430 SetFont(aFont);
1432 OUString aText(&cChar, 1);
1433 SetText( aText );
1435 Invalidate();
1438 void SmSymDefineDialog::FillSymbols(weld::ComboBox& rComboBox, bool bDeleteText)
1440 assert((&rComboBox == m_xOldSymbols.get() || &rComboBox == m_xSymbols.get()) && "Sm : wrong ComboBox");
1442 rComboBox.clear();
1443 if (bDeleteText)
1444 rComboBox.set_entry_text(OUString());
1446 weld::ComboBox& rBox = &rComboBox == m_xOldSymbols.get() ? *m_xOldSymbolSets : *m_xSymbolSets;
1447 SymbolPtrVec_t aSymSet(m_aSymbolMgrCopy.GetSymbolSet(rBox.get_active_text()));
1448 for (const SmSym* i : aSymSet)
1449 rComboBox.append_text(i->GetName());
1452 void SmSymDefineDialog::FillSymbolSets(weld::ComboBox& rComboBox, bool bDeleteText)
1454 assert((&rComboBox == m_xOldSymbolSets.get() || &rComboBox == m_xSymbolSets.get()) && "Sm : wrong ComboBox");
1456 rComboBox.clear();
1457 if (bDeleteText)
1458 rComboBox.set_entry_text(OUString());
1460 const std::set< OUString > aSymbolSetNames( m_aSymbolMgrCopy.GetSymbolSetNames() );
1461 for (const auto& rSymbolSetName : aSymbolSetNames)
1462 rComboBox.append_text(rSymbolSetName);
1465 void SmSymDefineDialog::FillFonts()
1467 m_xFonts->clear();
1468 m_xFonts->set_active(-1);
1470 // Include all fonts of FontList into the font list.
1471 // If there are duplicates, only include one entry of each font since the style will be
1472 // already selected using the FontStyleBox.
1473 if (m_xFontList)
1475 sal_uInt16 nCount = m_xFontList->GetFontNameCount();
1476 for (sal_uInt16 i = 0; i < nCount; ++i)
1477 m_xFonts->append_text(m_xFontList->GetFontName(i).GetFamilyName());
1481 void SmSymDefineDialog::FillStyles()
1483 m_xStyles->clear();
1484 // pStyles->SetText(OUString());
1486 OUString aText(m_xFonts->get_active_text());
1487 if (!aText.isEmpty())
1489 // use own StyleNames
1490 const SmFontStyles &rStyles = GetFontStyles();
1491 for (sal_uInt16 i = 0; i < SmFontStyles::GetCount(); ++i)
1492 m_xStyles->append_text(rStyles.GetStyleName(i));
1494 assert(m_xStyles->get_count() > 0 && "Sm : no styles available");
1495 m_xStyles->set_active(0);
1499 SmSym* SmSymDefineDialog::GetSymbol(const weld::ComboBox& rComboBox)
1501 assert((&rComboBox == m_xOldSymbols.get() || &rComboBox == m_xSymbols.get()) && "Sm : wrong combobox");
1502 return m_aSymbolMgrCopy.GetSymbolByName(rComboBox.get_active_text());
1505 IMPL_LINK(SmSymDefineDialog, OldSymbolChangeHdl, weld::ComboBox&, rComboBox, void)
1507 (void) rComboBox;
1508 assert(&rComboBox == m_xOldSymbols.get() && "Sm : wrong argument");
1509 SelectSymbol(*m_xOldSymbols, m_xOldSymbols->get_active_text(), false);
1512 IMPL_LINK( SmSymDefineDialog, OldSymbolSetChangeHdl, weld::ComboBox&, rComboBox, void )
1514 (void) rComboBox;
1515 assert(&rComboBox == m_xOldSymbolSets.get() && "Sm : wrong argument");
1516 SelectSymbolSet(*m_xOldSymbolSets, m_xOldSymbolSets->get_active_text(), false);
1519 IMPL_LINK(SmSymDefineDialog, ModifyHdl, weld::ComboBox&, rComboBox, void)
1521 // remember cursor position for later restoring of it
1522 int nStartPos, nEndPos;
1523 rComboBox.get_entry_selection_bounds(nStartPos, nEndPos);
1525 if (&rComboBox == m_xSymbols.get())
1526 SelectSymbol(*m_xSymbols, m_xSymbols->get_active_text(), false);
1527 else if (&rComboBox == m_xSymbolSets.get())
1528 SelectSymbolSet(*m_xSymbolSets, m_xSymbolSets->get_active_text(), false);
1529 else if (&rComboBox == m_xOldSymbols.get())
1530 // allow only names from the list
1531 SelectSymbol(*m_xOldSymbols, m_xOldSymbols->get_active_text(), true);
1532 else if (&rComboBox == m_xOldSymbolSets.get())
1533 // allow only names from the list
1534 SelectSymbolSet(*m_xOldSymbolSets, m_xOldSymbolSets->get_active_text(), true);
1535 else if (&rComboBox == m_xStyles.get())
1536 // allow only names from the list (that's the case here anyway)
1537 SelectStyle(m_xStyles->get_active_text(), true);
1538 else
1539 SAL_WARN("starmath", "wrong combobox argument");
1541 rComboBox.select_entry_region(nStartPos, nEndPos);
1543 UpdateButtons();
1546 IMPL_LINK(SmSymDefineDialog, FontChangeHdl, weld::ComboBox&, rListBox, void)
1548 (void) rListBox;
1549 assert(&rListBox == m_xFonts.get() && "Sm : wrong argument");
1551 SelectFont(m_xFonts->get_active_text());
1554 IMPL_LINK_NOARG(SmSymDefineDialog, SubsetChangeHdl, weld::ComboBox&, void)
1556 int nPos = m_xFontsSubsetLB->get_active();
1557 if (nPos != -1)
1559 const Subset* pSubset = reinterpret_cast<const Subset*>(m_xFontsSubsetLB->get_active_id().toUInt64());
1560 if (pSubset)
1562 m_xCharsetDisplay->SelectCharacter( pSubset->GetRangeMin() );
1567 IMPL_LINK( SmSymDefineDialog, StyleChangeHdl, weld::ComboBox&, rComboBox, void )
1569 (void) rComboBox;
1570 assert(&rComboBox == m_xStyles.get() && "Sm : wrong argument");
1572 SelectStyle(m_xStyles->get_active_text());
1575 IMPL_LINK_NOARG(SmSymDefineDialog, CharHighlightHdl, SvxShowCharSet*, void)
1577 sal_UCS4 cChar = m_xCharsetDisplay->GetSelectCharacter();
1579 if (m_xSubsetMap)
1581 const Subset* pSubset = m_xSubsetMap->GetSubsetByUnicode(cChar);
1582 if (pSubset)
1583 m_xFontsSubsetLB->set_active_text(pSubset->GetName());
1584 else
1585 m_xFontsSubsetLB->set_active(-1);
1588 m_aSymbolDisplay.SetSymbol(cChar, m_xCharsetDisplay->GetFont());
1590 UpdateButtons();
1592 // display Unicode position as symbol name while iterating over characters
1593 const OUString aHex(OUString::number(cChar, 16).toAsciiUpperCase());
1594 const OUString aPattern( (aHex.getLength() > 4) ? OUString("Ux000000") : OUString("Ux0000") );
1595 OUString aUnicodePos = aPattern.subView( 0, aPattern.getLength() - aHex.getLength() ) +
1596 aHex;
1597 m_xSymbols->set_entry_text(aUnicodePos);
1598 m_xSymbolName->set_label(aUnicodePos);
1601 IMPL_LINK( SmSymDefineDialog, AddClickHdl, weld::Button&, rButton, void )
1603 (void) rButton;
1604 assert(&rButton == m_xAddBtn.get() && "Sm : wrong argument");
1605 assert(rButton.get_sensitive() && "Sm : requirements met ??");
1607 // add symbol
1608 const SmSym aNewSymbol(m_xSymbols->get_active_text(), m_xCharsetDisplay->GetFont(),
1609 m_xCharsetDisplay->GetSelectCharacter(), m_xSymbolSets->get_active_text());
1610 //OSL_ENSURE( m_aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == NULL, "symbol already exists" );
1611 m_aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol );
1613 // update display of new symbol
1614 m_aSymbolDisplay.SetSymbol( &aNewSymbol );
1615 m_xSymbolName->set_label(aNewSymbol.GetName());
1616 m_xSymbolSetName->set_label(aNewSymbol.GetSymbolSetName());
1618 // update list box entries
1619 FillSymbolSets(*m_xOldSymbolSets, false);
1620 FillSymbolSets(*m_xSymbolSets, false);
1621 FillSymbols(*m_xOldSymbols, false);
1622 FillSymbols(*m_xSymbols, false);
1624 UpdateButtons();
1627 IMPL_LINK( SmSymDefineDialog, ChangeClickHdl, weld::Button&, rButton, void )
1629 (void) rButton;
1630 assert(&rButton == m_xChangeBtn.get() && "Sm : wrong argument");
1631 assert(m_xChangeBtn->get_sensitive() && "Sm : requirements met ??");
1633 // get new Symbol to use
1634 //! get font from symbol-disp lay since charset-display does not keep
1635 //! the bold attribute.
1636 const SmSym aNewSymbol(m_xSymbols->get_active_text(), m_xCharsetDisplay->GetFont(),
1637 m_xCharsetDisplay->GetSelectCharacter(), m_xSymbolSets->get_active_text());
1639 // remove old symbol if the name was changed then add new one
1640 const bool bNameChanged = m_xOldSymbols->get_active_text() != m_xSymbols->get_active_text();
1641 if (bNameChanged)
1642 m_aSymbolMgrCopy.RemoveSymbol(m_xOldSymbols->get_active_text());
1643 m_aSymbolMgrCopy.AddOrReplaceSymbol( aNewSymbol, true );
1645 // clear display for original symbol if necessary
1646 if (bNameChanged)
1647 SetOrigSymbol(nullptr, OUString());
1649 // update display of new symbol
1650 m_aSymbolDisplay.SetSymbol(&aNewSymbol);
1651 m_xSymbolName->set_label(aNewSymbol.GetName());
1652 m_xSymbolSetName->set_label(aNewSymbol.GetSymbolSetName());
1654 // update list box entries
1655 FillSymbolSets(*m_xOldSymbolSets, false);
1656 FillSymbolSets(*m_xSymbolSets, false);
1657 FillSymbols(*m_xOldSymbols, false);
1658 FillSymbols(*m_xSymbols, false);
1660 UpdateButtons();
1663 IMPL_LINK(SmSymDefineDialog, DeleteClickHdl, weld::Button&, rButton, void)
1665 (void) rButton;
1666 assert(&rButton == m_xDeleteBtn.get() && "Sm : wrong argument");
1667 assert(m_xDeleteBtn->get_sensitive() && "Sm : requirements met ??");
1669 if (m_xOrigSymbol)
1671 m_aSymbolMgrCopy.RemoveSymbol(m_xOrigSymbol->GetName());
1673 // clear display for original symbol
1674 SetOrigSymbol(nullptr, OUString());
1676 // update list box entries
1677 FillSymbolSets(*m_xOldSymbolSets, false);
1678 FillSymbolSets(*m_xSymbolSets, false);
1679 FillSymbols(*m_xOldSymbols ,false);
1680 FillSymbols(*m_xSymbols ,false);
1683 UpdateButtons();
1686 void SmSymDefineDialog::UpdateButtons()
1688 bool bAdd = false,
1689 bChange = false,
1690 bDelete = false;
1691 OUString aTmpSymbolName(m_xSymbols->get_active_text()),
1692 aTmpSymbolSetName(m_xSymbolSets->get_active_text());
1694 if (!aTmpSymbolName.isEmpty() && !aTmpSymbolSetName.isEmpty())
1696 // are all settings equal?
1697 //! (Font-, Style- and SymbolSet name comparison is not case sensitive)
1698 bool bEqual = m_xOrigSymbol
1699 && aTmpSymbolSetName.equalsIgnoreAsciiCase(m_xOldSymbolSetName->get_label())
1700 && aTmpSymbolName == m_xOrigSymbol->GetName()
1701 && m_xFonts->get_active_text().equalsIgnoreAsciiCase(
1702 m_xOrigSymbol->GetFace().GetFamilyName())
1703 && m_xStyles->get_active_text().equalsIgnoreAsciiCase(
1704 GetFontStyles().GetStyleName(m_xOrigSymbol->GetFace()))
1705 && m_xCharsetDisplay->GetSelectCharacter() == m_xOrigSymbol->GetCharacter();
1707 // only add it if there isn't already a symbol with the same name
1708 bAdd = m_aSymbolMgrCopy.GetSymbolByName(aTmpSymbolName) == nullptr;
1710 // only delete it if all settings are equal
1711 bDelete = bool(m_xOrigSymbol);
1713 // only change it if the old symbol exists and the new one is different
1714 bChange = m_xOrigSymbol && !bEqual;
1717 m_xAddBtn->set_sensitive(bAdd);
1718 m_xChangeBtn->set_sensitive(bChange);
1719 m_xDeleteBtn->set_sensitive(bDelete);
1722 SmSymDefineDialog::SmSymDefineDialog(weld::Window* pParent, OutputDevice *pFntListDevice, SmSymbolManager &rMgr)
1723 : GenericDialogController(pParent, "modules/smath/ui/symdefinedialog.ui", "EditSymbols")
1724 , m_xVirDev(VclPtr<VirtualDevice>::Create())
1725 , m_rSymbolMgr(rMgr)
1726 , m_xFontList(new FontList(pFntListDevice))
1727 , m_xOldSymbols(m_xBuilder->weld_combo_box("oldSymbols"))
1728 , m_xOldSymbolSets(m_xBuilder->weld_combo_box("oldSymbolSets"))
1729 , m_xSymbols(m_xBuilder->weld_combo_box("symbols"))
1730 , m_xSymbolSets(m_xBuilder->weld_combo_box("symbolSets"))
1731 , m_xFonts(m_xBuilder->weld_combo_box("fonts"))
1732 , m_xFontsSubsetLB(m_xBuilder->weld_combo_box("fontsSubsetLB"))
1733 , m_xStyles(m_xBuilder->weld_combo_box("styles"))
1734 , m_xOldSymbolName(m_xBuilder->weld_label("oldSymbolName"))
1735 , m_xOldSymbolSetName(m_xBuilder->weld_label("oldSymbolSetName"))
1736 , m_xSymbolName(m_xBuilder->weld_label("symbolName"))
1737 , m_xSymbolSetName(m_xBuilder->weld_label("symbolSetName"))
1738 , m_xAddBtn(m_xBuilder->weld_button("add"))
1739 , m_xChangeBtn(m_xBuilder->weld_button("modify"))
1740 , m_xDeleteBtn(m_xBuilder->weld_button("delete"))
1741 , m_xOldSymbolDisplay(new weld::CustomWeld(*m_xBuilder, "oldSymbolDisplay", m_aOldSymbolDisplay))
1742 , m_xSymbolDisplay(new weld::CustomWeld(*m_xBuilder, "symbolDisplay", m_aSymbolDisplay))
1743 , m_xCharsetDisplay(new SvxShowCharSet(m_xBuilder->weld_scrolled_window("showscroll", true), m_xVirDev))
1744 , m_xCharsetDisplayArea(new weld::CustomWeld(*m_xBuilder, "charsetDisplay", *m_xCharsetDisplay))
1746 // auto completion is troublesome since that symbols character also gets automatically selected in the
1747 // display and if the user previously selected a character to define/redefine that one this is bad
1748 m_xOldSymbols->set_entry_completion(false);
1749 m_xSymbols->set_entry_completion(false);
1751 FillFonts();
1752 if (m_xFonts->get_count() > 0)
1753 SelectFont(m_xFonts->get_text(0));
1755 SetSymbolSetManager(m_rSymbolMgr);
1757 m_xOldSymbols->connect_changed(LINK(this, SmSymDefineDialog, OldSymbolChangeHdl));
1758 m_xOldSymbolSets->connect_changed(LINK(this, SmSymDefineDialog, OldSymbolSetChangeHdl));
1759 m_xSymbolSets->connect_changed(LINK(this, SmSymDefineDialog, ModifyHdl));
1760 m_xOldSymbolSets->connect_changed(LINK(this, SmSymDefineDialog, ModifyHdl));
1761 m_xSymbols->connect_changed(LINK(this, SmSymDefineDialog, ModifyHdl));
1762 m_xOldSymbols->connect_changed(LINK(this, SmSymDefineDialog, ModifyHdl));
1763 m_xStyles->connect_changed(LINK(this, SmSymDefineDialog, ModifyHdl));
1764 m_xFonts->connect_changed(LINK(this, SmSymDefineDialog, FontChangeHdl));
1765 m_xFontsSubsetLB->connect_changed(LINK(this, SmSymDefineDialog, SubsetChangeHdl));
1766 m_xStyles->connect_changed(LINK(this, SmSymDefineDialog, StyleChangeHdl));
1767 m_xAddBtn->connect_clicked(LINK(this, SmSymDefineDialog, AddClickHdl));
1768 m_xChangeBtn->connect_clicked(LINK(this, SmSymDefineDialog, ChangeClickHdl));
1769 m_xDeleteBtn->connect_clicked(LINK(this, SmSymDefineDialog, DeleteClickHdl));
1770 m_xCharsetDisplay->SetHighlightHdl( LINK( this, SmSymDefineDialog, CharHighlightHdl ) );
1773 SmSymDefineDialog::~SmSymDefineDialog()
1777 short SmSymDefineDialog::run()
1779 short nResult = GenericDialogController::run();
1781 // apply changes if dialog was closed by clicking OK
1782 if (m_aSymbolMgrCopy.IsModified() && nResult == RET_OK)
1783 m_rSymbolMgr = m_aSymbolMgrCopy;
1785 return nResult;
1788 void SmSymDefineDialog::SetSymbolSetManager(const SmSymbolManager &rMgr)
1790 m_aSymbolMgrCopy = rMgr;
1792 // Set the modified flag of the copy to false so that
1793 // we can check later on if anything has been changed
1794 m_aSymbolMgrCopy.SetModified(false);
1796 FillSymbolSets(*m_xOldSymbolSets);
1797 if (m_xOldSymbolSets->get_count() > 0)
1798 SelectSymbolSet(m_xOldSymbolSets->get_text(0));
1799 FillSymbolSets(*m_xSymbolSets);
1800 if (m_xSymbolSets->get_count() > 0)
1801 SelectSymbolSet(m_xSymbolSets->get_text(0));
1802 FillSymbols(*m_xOldSymbols);
1803 if (m_xOldSymbols->get_count() > 0)
1804 SelectSymbol(m_xOldSymbols->get_text(0));
1805 FillSymbols(*m_xSymbols);
1806 if (m_xSymbols->get_count() > 0)
1807 SelectSymbol(m_xSymbols->get_text(0));
1809 UpdateButtons();
1812 bool SmSymDefineDialog::SelectSymbolSet(weld::ComboBox& rComboBox,
1813 const OUString &rSymbolSetName, bool bDeleteText)
1815 assert((&rComboBox == m_xOldSymbolSets.get() || &rComboBox == m_xSymbolSets.get()) && "Sm : wrong ComboBox");
1817 // trim SymbolName (no leading and trailing blanks)
1818 OUString aNormName = comphelper::string::stripStart(rSymbolSetName, ' ');
1819 aNormName = comphelper::string::stripEnd(aNormName, ' ');
1820 // and remove possible deviations within the input
1821 rComboBox.set_entry_text(aNormName);
1823 bool bRet = false;
1824 int nPos = rComboBox.find_text(aNormName);
1826 if (nPos != -1)
1828 rComboBox.set_active(nPos);
1829 bRet = true;
1831 else if (bDeleteText)
1832 rComboBox.set_entry_text(OUString());
1834 bool bIsOld = &rComboBox == m_xOldSymbolSets.get();
1836 // setting the SymbolSet name at the associated display
1837 weld::Label& rFT = bIsOld ? *m_xOldSymbolSetName : *m_xSymbolSetName;
1838 rFT.set_label(rComboBox.get_active_text());
1840 // set the symbol name which belongs to the SymbolSet at the associated combobox
1841 weld::ComboBox& rCB = bIsOld ? *m_xOldSymbols : *m_xSymbols;
1842 FillSymbols(rCB, false);
1844 // display a valid respectively no symbol when changing the SymbolSets
1845 if (bIsOld)
1847 OUString aTmpOldSymbolName;
1848 if (m_xOldSymbols->get_count() > 0)
1849 aTmpOldSymbolName = m_xOldSymbols->get_text(0);
1850 SelectSymbol(*m_xOldSymbols, aTmpOldSymbolName, true);
1853 UpdateButtons();
1855 return bRet;
1858 void SmSymDefineDialog::SetOrigSymbol(const SmSym *pSymbol,
1859 const OUString &rSymbolSetName)
1861 // clear old symbol
1862 m_xOrigSymbol.reset();
1864 OUString aSymName,
1865 aSymSetName;
1866 if (pSymbol)
1868 // set new symbol
1869 m_xOrigSymbol.reset(new SmSym(*pSymbol));
1871 aSymName = pSymbol->GetName();
1872 aSymSetName = rSymbolSetName;
1873 m_aOldSymbolDisplay.SetSymbol( pSymbol );
1875 else
1876 { // delete displayed symbols
1877 m_aOldSymbolDisplay.SetText(OUString());
1878 m_aOldSymbolDisplay.Invalidate();
1880 m_xOldSymbolName->set_label(aSymName);
1881 m_xOldSymbolSetName->set_label(aSymSetName);
1885 bool SmSymDefineDialog::SelectSymbol(weld::ComboBox& rComboBox,
1886 const OUString &rSymbolName, bool bDeleteText)
1888 assert((&rComboBox == m_xOldSymbols.get() || &rComboBox == m_xSymbols.get()) && "Sm : wrong ComboBox");
1890 // trim SymbolName (no blanks)
1891 OUString aNormName = rSymbolName.replaceAll(" ", "");
1892 // and remove possible deviations within the input
1893 rComboBox.set_entry_text(aNormName);
1895 bool bRet = false;
1896 int nPos = rComboBox.find_text(aNormName);
1898 bool bIsOld = &rComboBox == m_xOldSymbols.get();
1900 if (nPos != -1)
1902 rComboBox.set_active(nPos);
1904 if (!bIsOld)
1906 const SmSym *pSymbol = GetSymbol(*m_xSymbols);
1907 if (pSymbol)
1909 // choose font and style accordingly
1910 const vcl::Font &rFont = pSymbol->GetFace();
1911 SelectFont(rFont.GetFamilyName(), false);
1912 SelectStyle(GetFontStyles().GetStyleName(rFont), false);
1914 // Since setting the Font via the Style name of the SymbolFonts doesn't
1915 // work really well (e.g. it can be empty even though the font itself is
1916 // bold or italic) we're manually setting the Font with respect to the Symbol
1917 m_xCharsetDisplay->SetFont(rFont);
1918 m_aSymbolDisplay.SetFont(rFont);
1920 // select associated character
1921 SelectChar(pSymbol->GetCharacter());
1923 // since SelectChar will also set the unicode point as text in the
1924 // symbols box, we have to set the symbol name again to get that one displayed
1925 m_xSymbols->set_entry_text(pSymbol->GetName());
1929 bRet = true;
1931 else if (bDeleteText)
1932 rComboBox.set_entry_text(OUString());
1934 if (bIsOld)
1936 // if there's a change of the old symbol, show only the available ones, otherwise show none
1937 const SmSym *pOldSymbol = nullptr;
1938 OUString aTmpOldSymbolSetName;
1939 if (nPos != -1)
1941 pOldSymbol = m_aSymbolMgrCopy.GetSymbolByName(aNormName);
1942 aTmpOldSymbolSetName = m_xOldSymbolSets->get_active_text();
1944 SetOrigSymbol(pOldSymbol, aTmpOldSymbolSetName);
1946 else
1947 m_xSymbolName->set_label(rComboBox.get_active_text());
1949 UpdateButtons();
1951 return bRet;
1955 void SmSymDefineDialog::SetFont(const OUString &rFontName, const OUString &rStyleName)
1957 // get Font (FontInfo) matching name and style
1958 FontMetric aFontMetric;
1959 if (m_xFontList)
1960 aFontMetric = m_xFontList->Get(rFontName, WEIGHT_NORMAL, ITALIC_NONE);
1961 SetFontStyle(rStyleName, aFontMetric);
1963 m_xCharsetDisplay->SetFont(aFontMetric);
1964 m_aSymbolDisplay.SetFont(aFontMetric);
1966 // update subset listbox for new font's unicode subsets
1967 FontCharMapRef xFontCharMap = m_xCharsetDisplay->GetFontCharMap();
1968 m_xSubsetMap.reset(new SubsetMap( xFontCharMap ));
1970 m_xFontsSubsetLB->clear();
1971 bool bFirst = true;
1972 for (auto & subset : m_xSubsetMap->GetSubsetMap())
1974 m_xFontsSubsetLB->append(OUString::number(reinterpret_cast<sal_uInt64>(&subset)), subset.GetName());
1975 // subset must live at least as long as the selected font !!!
1976 if (bFirst)
1977 m_xFontsSubsetLB->set_active(0);
1978 bFirst = false;
1980 if (bFirst)
1981 m_xFontsSubsetLB->set_active(-1);
1982 m_xFontsSubsetLB->set_sensitive(!bFirst);
1985 bool SmSymDefineDialog::SelectFont(const OUString &rFontName, bool bApplyFont)
1987 bool bRet = false;
1988 int nPos = m_xFonts->find_text(rFontName);
1990 if (nPos != -1)
1992 m_xFonts->set_active(nPos);
1993 if (m_xStyles->get_count() > 0)
1994 SelectStyle(m_xStyles->get_text(0));
1995 if (bApplyFont)
1997 SetFont(m_xFonts->get_active_text(), m_xStyles->get_active_text());
1998 m_aSymbolDisplay.SetSymbol(m_xCharsetDisplay->GetSelectCharacter(), m_xCharsetDisplay->GetFont());
2000 bRet = true;
2002 else
2003 m_xFonts->set_active(-1);
2004 FillStyles();
2006 UpdateButtons();
2008 return bRet;
2012 bool SmSymDefineDialog::SelectStyle(const OUString &rStyleName, bool bApplyFont)
2014 bool bRet = false;
2015 int nPos = m_xStyles->find_text(rStyleName);
2017 // if the style is not available take the first available one (if existent)
2018 if (nPos == -1 && m_xStyles->get_count() > 0)
2019 nPos = 0;
2021 if (nPos != -1)
2023 m_xStyles->set_active(nPos);
2024 if (bApplyFont)
2026 SetFont(m_xFonts->get_active_text(), m_xStyles->get_active_text());
2027 m_aSymbolDisplay.SetSymbol(m_xCharsetDisplay->GetSelectCharacter(), m_xCharsetDisplay->GetFont());
2029 bRet = true;
2031 else
2032 m_xStyles->set_entry_text(OUString());
2034 UpdateButtons();
2036 return bRet;
2039 void SmSymDefineDialog::SelectChar(sal_Unicode cChar)
2041 m_xCharsetDisplay->SelectCharacter( cChar );
2042 m_aSymbolDisplay.SetSymbol(cChar, m_xCharsetDisplay->GetFont());
2044 UpdateButtons();
2047 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */