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>
26 #include <svl/itemset.hxx>
28 #include "SmElementsPanel.hxx"
29 #include <starmath.hrc>
31 #include <strings.hrc>
37 std::unique_ptr
<PanelLayout
> SmElementsPanel::Create(weld::Widget
& rParent
,
38 const SfxBindings
& rBindings
)
40 return std::make_unique
<SmElementsPanel
>(rParent
, rBindings
);
43 SmElementsPanel::SmElementsPanel(weld::Widget
& rParent
, const SfxBindings
& rBindings
)
44 : PanelLayout(&rParent
, u
"MathElementsPanel"_ustr
,
45 u
"modules/smath/ui/sidebarelements_math.ui"_ustr
)
46 , mrBindings(rBindings
)
47 , mxCategoryList(m_xBuilder
->weld_combo_box(u
"categorylist"_ustr
))
49 std::make_unique
<SmElementsControl
>(m_xBuilder
->weld_icon_view(u
"elements"_ustr
)))
51 for (const auto& rCategoryId
: SmElementsControl::categories())
52 mxCategoryList
->append_text(SmResId(rCategoryId
));
54 mxCategoryList
->set_size_request(-1, -1);
56 mxCategoryList
->connect_changed(LINK(this, SmElementsPanel
, CategorySelectedHandle
));
57 mxCategoryList
->set_active(0);
59 mxElementsControl
->setElementSetIndex(0);
60 mxElementsControl
->SetSelectHdl(LINK(this, SmElementsPanel
, ElementClickHandler
));
63 SmElementsPanel::~SmElementsPanel()
65 mxElementsControl
.reset();
66 mxCategoryList
.reset();
69 IMPL_LINK(SmElementsPanel
, CategorySelectedHandle
, weld::ComboBox
&, rList
, void)
71 const int nActive
= rList
.get_active();
74 mxElementsControl
->setElementSetIndex(nActive
);
75 if (SmViewShell
* pViewSh
= GetView())
76 mxElementsControl
->setSmSyntaxVersion(pViewSh
->GetDoc()->GetSmSyntaxVersion());
79 IMPL_LINK(SmElementsPanel
, ElementClickHandler
, const OUString
&, ElementSource
, void)
81 if (SmViewShell
* pViewSh
= GetView())
83 SfxStringItem
aInsertCommand(SID_INSERTCOMMANDTEXT
, ElementSource
);
84 pViewSh
->GetViewFrame().GetDispatcher()->ExecuteList(
85 SID_INSERTCOMMANDTEXT
, SfxCallMode::RECORD
, { &aInsertCommand
});
89 SmViewShell
* SmElementsPanel::GetView() const
91 SfxViewShell
* pView
= mrBindings
.GetDispatcher()->GetFrame()->GetViewShell();
92 SmViewShell
* pSmViewShell
= dynamic_cast<SmViewShell
*>(pView
);
93 if (!pSmViewShell
&& comphelper::LibreOfficeKit::isActive())
95 auto* pWindow
= static_cast<SmGraphicWindow
*>(LokStarMathHelper(pView
).GetGraphicWindow());
97 pSmViewShell
= &pWindow
->GetGraphicWidget().GetView();
102 } // end of namespace sm::sidebar
104 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */