1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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>
22 #include <com/sun/star/beans/PropertyValue.hpp>
23 #include <com/sun/star/frame/theUICommandDescription.hpp>
24 #include <com/sun/star/uno/Sequence.hxx>
26 #include <comphelper/dispatchcommand.hxx>
27 #include <comphelper/processfactory.hxx>
28 #include <comphelper/sequenceashashmap.hxx>
30 #include "SmPropertiesPanel.hxx"
35 std::unique_ptr
<PanelLayout
>
36 SmPropertiesPanel::Create(weld::Widget
& rParent
,
37 const css::uno::Reference
<css::frame::XFrame
>& xFrame
)
39 return std::make_unique
<SmPropertiesPanel
>(rParent
, xFrame
);
42 SmPropertiesPanel::SmPropertiesPanel(weld::Widget
& rParent
,
43 const css::uno::Reference
<css::frame::XFrame
>& xFrame
)
44 : PanelLayout(&rParent
, u
"MathPropertiesPanel"_ustr
,
45 u
"modules/smath/ui/sidebarproperties_math.ui"_ustr
)
47 , mpFormatFontsButton(m_xBuilder
->weld_button(u
"btnFormatFonts"_ustr
))
48 , mpFormatFontSizeButton(m_xBuilder
->weld_button(u
"btnFormatFontSize"_ustr
))
49 , mpFormatSpacingButton(m_xBuilder
->weld_button(u
"btnFormatSpacing"_ustr
))
50 , mpFormatAlignmentButton(m_xBuilder
->weld_button(u
"btnFormatAlignment"_ustr
))
51 , maButtonCommands
{ { mpFormatFontsButton
.get(), ".uno:ChangeFont" },
52 { mpFormatFontSizeButton
.get(), ".uno:ChangeFontSize" },
53 { mpFormatSpacingButton
.get(), ".uno:ChangeDistance" },
54 { mpFormatAlignmentButton
.get(), ".uno:ChangeAlignment" } }
56 // Set localized labels to the buttons
58 = css::frame::theUICommandDescription::get(comphelper::getProcessComponentContext());
59 if (css::uno::Reference
<css::container::XNameAccess
> xConf
{
60 xConfs
->getByName(u
"com.sun.star.formula.FormulaProperties"_ustr
),
61 css::uno::UNO_QUERY
})
63 for (const auto & [ button
, command
] : maButtonCommands
)
65 comphelper::SequenceAsHashMap
props(xConf
->getByName(command
));
66 button
->set_label(props
.getUnpackedValueOrDefault(u
"Name"_ustr
, button
->get_label()));
70 mpFormatFontsButton
->connect_clicked(LINK(this, SmPropertiesPanel
, ButtonClickHandler
));
71 mpFormatFontSizeButton
->connect_clicked(LINK(this, SmPropertiesPanel
, ButtonClickHandler
));
72 mpFormatSpacingButton
->connect_clicked(LINK(this, SmPropertiesPanel
, ButtonClickHandler
));
73 mpFormatAlignmentButton
->connect_clicked(LINK(this, SmPropertiesPanel
, ButtonClickHandler
));
76 SmPropertiesPanel::~SmPropertiesPanel()
78 maButtonCommands
.clear();
80 mpFormatFontsButton
.reset();
81 mpFormatFontSizeButton
.reset();
82 mpFormatSpacingButton
.reset();
83 mpFormatAlignmentButton
.reset();
86 IMPL_LINK(SmPropertiesPanel
, ButtonClickHandler
, weld::Button
&, rButton
, void)
88 if (OUString command
= maButtonCommands
[&rButton
]; !command
.isEmpty())
89 comphelper::dispatchCommand(command
, mxFrame
, {});
92 } // end of namespace sm::sidebar
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */