LibreOffice Module starmath (master) 1
SmElementsPanel.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 <comphelper/lok.hxx>
23#include <sfx2/dispatch.hxx>
25#include <svl/stritem.hxx>
26
27#include "SmElementsPanel.hxx"
28#include <starmath.hrc>
29#include <smmod.hxx>
30#include <strings.hrc>
31#include <view.hxx>
32
33namespace sm::sidebar
34{
35// static
36std::unique_ptr<PanelLayout> SmElementsPanel::Create(weld::Widget& rParent,
37 const SfxBindings& rBindings)
38{
39 return std::make_unique<SmElementsPanel>(rParent, rBindings);
40}
41
43 : PanelLayout(&rParent, "MathElementsPanel", "modules/smath/ui/sidebarelements_math.ui")
44 , mrBindings(rBindings)
45 , mxCategoryList(m_xBuilder->weld_combo_box("categorylist"))
46 , mxElementsControl(std::make_unique<SmElementsControl>(m_xBuilder->weld_icon_view("elements")))
47{
48 for (const auto& rCategoryId : SmElementsControl::categories())
49 mxCategoryList->append_text(SmResId(rCategoryId));
50
51 mxCategoryList->set_size_request(-1, -1);
52
53 mxCategoryList->connect_changed(LINK(this, SmElementsPanel, CategorySelectedHandle));
54 mxCategoryList->set_active(0);
55
56 mxElementsControl->setElementSetIndex(0);
57 mxElementsControl->SetSelectHdl(LINK(this, SmElementsPanel, ElementClickHandler));
58}
59
61{
62 mxElementsControl.reset();
63 mxCategoryList.reset();
64}
65
66IMPL_LINK(SmElementsPanel, CategorySelectedHandle, weld::ComboBox&, rList, void)
67{
68 const int nActive = rList.get_active();
69 if (nActive == -1)
70 return;
71 mxElementsControl->setElementSetIndex(nActive);
72 if (SmViewShell* pViewSh = GetView())
73 mxElementsControl->setSmSyntaxVersion(pViewSh->GetDoc()->GetSmSyntaxVersion());
74}
75
76IMPL_LINK(SmElementsPanel, ElementClickHandler, OUString, ElementSource, void)
77{
78 if (SmViewShell* pViewSh = GetView())
79 {
80 SfxStringItem aInsertCommand(SID_INSERTCOMMANDTEXT, ElementSource);
81 pViewSh->GetViewFrame().GetDispatcher()->ExecuteList(
82 SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD, { &aInsertCommand });
83 }
84}
85
87{
89 SmViewShell* pSmViewShell = dynamic_cast<SmViewShell*>(pView);
90 if (!pSmViewShell && comphelper::LibreOfficeKit::isActive())
91 {
92 auto* pWindow = static_cast<SmGraphicWindow*>(LokStarMathHelper(pView).GetGraphicWindow());
93 if (pWindow)
94 pSmViewShell = &pWindow->GetGraphicWidget().GetView();
95 }
96 return pSmViewShell;
97}
98
99} // end of namespace sm::sidebar
100
101/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
vcl::Window * GetGraphicWindow()
SfxDispatcher * GetDispatcher() const
SfxViewFrame * GetFrame() const
SfxViewShell * GetViewShell() const
static const std::vector< TranslateId > & categories()
SmViewShell & GetView()
Definition: view.hxx:115
SmGraphicWidget & GetGraphicWidget()
Definition: view.hxx:304
static std::unique_ptr< PanelLayout > Create(weld::Widget &rParent, const SfxBindings &rBindings)
SmElementsPanel(weld::Widget &rParent, const SfxBindings &rBindings)
SmViewShell * GetView() const
std::unique_ptr< weld::ComboBox > mxCategoryList
std::unique_ptr< SmElementsControl > mxElementsControl
const SfxBindings & mrBindings
IMPL_LINK(SmElementsPanel, CategorySelectedHandle, weld::ComboBox &, rList, void)
OUString SmResId(TranslateId aId)
Definition: smmod.cxx:42