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 <sfx2/dispatch.hxx>
23 #include <svl/stritem.hxx>
25 #include "SmElementsPanel.hxx"
26 #include <starmath.hrc>
28 #include <strings.hrc>
34 std::unique_ptr
<PanelLayout
> SmElementsPanel::Create(weld::Widget
& rParent
,
35 const SfxBindings
& rBindings
)
37 return std::make_unique
<SmElementsPanel
>(rParent
, rBindings
);
40 SmElementsPanel::SmElementsPanel(weld::Widget
& rParent
, const SfxBindings
& rBindings
)
41 : PanelLayout(&rParent
, "MathElementsPanel", "modules/smath/ui/sidebarelements_math.ui")
42 , mrBindings(rBindings
)
43 , mxCategoryList(m_xBuilder
->weld_combo_box("categorylist"))
44 , mxElementsControl(std::make_unique
<SmElementsControl
>(m_xBuilder
->weld_icon_view("elements")))
46 for (const auto& rCategoryId
: SmElementsControl::categories())
47 mxCategoryList
->append_text(SmResId(rCategoryId
));
49 mxCategoryList
->set_size_request(-1, -1);
51 mxCategoryList
->connect_changed(LINK(this, SmElementsPanel
, CategorySelectedHandle
));
52 mxCategoryList
->set_active(0);
54 mxElementsControl
->setElementSetIndex(0);
55 mxElementsControl
->SetSelectHdl(LINK(this, SmElementsPanel
, ElementClickHandler
));
58 SmElementsPanel::~SmElementsPanel()
60 mxElementsControl
.reset();
61 mxCategoryList
.reset();
64 IMPL_LINK(SmElementsPanel
, CategorySelectedHandle
, weld::ComboBox
&, rList
, void)
66 const int nActive
= rList
.get_active();
69 mxElementsControl
->setElementSetIndex(nActive
);
70 if (SmViewShell
* pViewSh
= GetView())
71 mxElementsControl
->setSmSyntaxVersion(pViewSh
->GetDoc()->GetSmSyntaxVersion());
74 IMPL_LINK(SmElementsPanel
, ElementClickHandler
, OUString
, ElementSource
, void)
76 if (SmViewShell
* pViewSh
= GetView())
78 SfxStringItem
aInsertCommand(SID_INSERTCOMMANDTEXT
, ElementSource
);
79 pViewSh
->GetViewFrame().GetDispatcher()->ExecuteList(
80 SID_INSERTCOMMANDTEXT
, SfxCallMode::RECORD
, { &aInsertCommand
});
84 SmViewShell
* SmElementsPanel::GetView() const
86 SfxViewShell
* pView
= mrBindings
.GetDispatcher()->GetFrame()->GetViewShell();
87 return dynamic_cast<SmViewShell
*>(pView
);
90 } // end of namespace sm::sidebar
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */