LibreOffice Module starmath (master) 1
SmPropertiesPanel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sal/config.h>
21
22#include <com/sun/star/beans/PropertyValue.hpp>
23#include <com/sun/star/frame/theUICommandDescription.hpp>
24#include <com/sun/star/uno/Sequence.hxx>
25
29
30#include "SmPropertiesPanel.hxx"
31
32namespace sm::sidebar
33{
34// static
35std::unique_ptr<PanelLayout>
37 const css::uno::Reference<css::frame::XFrame>& xFrame)
38{
39 return std::make_unique<SmPropertiesPanel>(rParent, xFrame);
40}
41
43 const css::uno::Reference<css::frame::XFrame>& xFrame)
44 : PanelLayout(&rParent, "MathPropertiesPanel", "modules/smath/ui/sidebarproperties_math.ui")
45 , mxFrame(xFrame)
46 , mpFormatFontsButton(m_xBuilder->weld_button("btnFormatFonts"))
47 , mpFormatFontSizeButton(m_xBuilder->weld_button("btnFormatFontSize"))
48 , mpFormatSpacingButton(m_xBuilder->weld_button("btnFormatSpacing"))
49 , mpFormatAlignmentButton(m_xBuilder->weld_button("btnFormatAlignment"))
50 , maButtonCommands{ { mpFormatFontsButton.get(), ".uno:ChangeFont" },
51 { mpFormatFontSizeButton.get(), ".uno:ChangeFontSize" },
52 { mpFormatSpacingButton.get(), ".uno:ChangeDistance" },
53 { mpFormatAlignmentButton.get(), ".uno:ChangeAlignment" } }
54{
55 // Set localized labels to the buttons
56 auto xConfs
57 = css::frame::theUICommandDescription::get(comphelper::getProcessComponentContext());
58 if (css::uno::Reference<css::container::XNameAccess> xConf{
59 xConfs->getByName("com.sun.star.formula.FormulaProperties"), css::uno::UNO_QUERY })
60 {
61 for (const auto & [ button, command ] : maButtonCommands)
62 {
63 comphelper::SequenceAsHashMap props(xConf->getByName(command));
64 button->set_label(props.getUnpackedValueOrDefault("Name", button->get_label()));
65 }
66 }
67
68 mpFormatFontsButton->connect_clicked(LINK(this, SmPropertiesPanel, ButtonClickHandler));
69 mpFormatFontSizeButton->connect_clicked(LINK(this, SmPropertiesPanel, ButtonClickHandler));
70 mpFormatSpacingButton->connect_clicked(LINK(this, SmPropertiesPanel, ButtonClickHandler));
71 mpFormatAlignmentButton->connect_clicked(LINK(this, SmPropertiesPanel, ButtonClickHandler));
72}
73
74SmPropertiesPanel::~SmPropertiesPanel()
75{
76 maButtonCommands.clear();
77
78 mpFormatFontsButton.reset();
79 mpFormatFontSizeButton.reset();
80 mpFormatSpacingButton.reset();
81 mpFormatAlignmentButton.reset();
82}
83
84IMPL_LINK(SmPropertiesPanel, ButtonClickHandler, weld::Button&, rButton, void)
85{
86 if (OUString command = maButtonCommands[&rButton]; !command.isEmpty())
87 comphelper::dispatchCommand(command, mxFrame, {});
88}
89
90} // end of namespace sm::sidebar
91
92/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
SmPropertiesPanel(weld::Widget &rParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
static std::unique_ptr< PanelLayout > Create(weld::Widget &rParent, const css::uno::Reference< css::frame::XFrame > &xFrame)
std::unique_ptr< weld::Button > mpFormatFontsButton
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
dictionary props
IMPL_LINK(SmPropertiesPanel, ButtonClickHandler, weld::Button &, rButton, void)
Reference< XFrame > xFrame