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 <comphelper/lok.hxx>
23 #include <sfx2/dispatch.hxx>
24 #include <sfx2/lokcomponenthelpers.hxx>
25 #include <svl/stritem.hxx>
27 #include "SmElementsPanel.hxx"
28 #include <starmath.hrc>
30 #include <strings.hrc>
36 std::unique_ptr
<PanelLayout
> SmElementsPanel::Create(weld::Widget
& rParent
,
37 const SfxBindings
& rBindings
)
39 return std::make_unique
<SmElementsPanel
>(rParent
, rBindings
);
42 SmElementsPanel::SmElementsPanel(weld::Widget
& rParent
, const SfxBindings
& rBindings
)
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")))
48 for (const auto& rCategoryId
: SmElementsControl::categories())
49 mxCategoryList
->append_text(SmResId(rCategoryId
));
51 mxCategoryList
->set_size_request(-1, -1);
53 mxCategoryList
->connect_changed(LINK(this, SmElementsPanel
, CategorySelectedHandle
));
54 mxCategoryList
->set_active(0);
56 mxElementsControl
->setElementSetIndex(0);
57 mxElementsControl
->SetSelectHdl(LINK(this, SmElementsPanel
, ElementClickHandler
));
60 SmElementsPanel::~SmElementsPanel()
62 mxElementsControl
.reset();
63 mxCategoryList
.reset();
66 IMPL_LINK(SmElementsPanel
, CategorySelectedHandle
, weld::ComboBox
&, rList
, void)
68 const int nActive
= rList
.get_active();
71 mxElementsControl
->setElementSetIndex(nActive
);
72 if (SmViewShell
* pViewSh
= GetView())
73 mxElementsControl
->setSmSyntaxVersion(pViewSh
->GetDoc()->GetSmSyntaxVersion());
76 IMPL_LINK(SmElementsPanel
, ElementClickHandler
, OUString
, ElementSource
, void)
78 if (SmViewShell
* pViewSh
= GetView())
80 SfxStringItem
aInsertCommand(SID_INSERTCOMMANDTEXT
, ElementSource
);
81 pViewSh
->GetViewFrame()->GetDispatcher()->ExecuteList(
82 SID_INSERTCOMMANDTEXT
, SfxCallMode::RECORD
, { &aInsertCommand
});
86 SmViewShell
* SmElementsPanel::GetView() const
88 SfxViewShell
* pView
= mrBindings
.GetDispatcher()->GetFrame()->GetViewShell();
89 SmViewShell
* pSmViewShell
= dynamic_cast<SmViewShell
*>(pView
);
90 if (!pSmViewShell
&& comphelper::LibreOfficeKit::isActive())
92 auto* pWindow
= static_cast<SmGraphicWindow
*>(LokStarMathHelper(pView
).GetGraphicWindow());
94 pSmViewShell
= &pWindow
->GetGraphicWidget().GetView();
99 } // end of namespace sm::sidebar
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */