diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2022-04-25 18:24:43 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2022-04-26 17:01:56 +0200 |
commit | 3524e4f7352993517ebdd514435378f6de0ca713 (patch) | |
tree | 41967311fc1aef6cae8b6fd9ef33f1baa6bbc60c /starmath | |
parent | 9098d5a2e43b156648f187559790547d1b536896 (diff) |
tdf#125931: Add Elements deck and Elements panel to Math's sidebar
Change-Id: Ie04a5dc48de38f318f0ddb42efc42cea022dc62c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133393
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'starmath')
-rw-r--r-- | starmath/Library_sm.mk | 2 | ||||
-rw-r--r-- | starmath/UIConfig_smath.mk | 1 | ||||
-rw-r--r-- | starmath/source/SmElementsPanel.cxx | 105 | ||||
-rw-r--r-- | starmath/source/SmElementsPanel.hxx | 59 | ||||
-rw-r--r-- | starmath/source/SmPanelFactory.cxx | 131 | ||||
-rw-r--r-- | starmath/uiconfig/smath/ui/sidebarelements_math.ui | 154 | ||||
-rw-r--r-- | starmath/util/sm.component | 4 |
7 files changed, 456 insertions, 0 deletions
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk index 2a7aeffcfb40..ba4c59fdfd75 100644 --- a/starmath/Library_sm.mk +++ b/starmath/Library_sm.mk @@ -67,6 +67,8 @@ $(eval $(call gb_Library_add_exception_objects,sm,\ starmath/source/AccessibleSmElement \ starmath/source/AccessibleSmElementsControl \ starmath/source/ElementsDockingWindow \ + starmath/source/SmElementsPanel \ + starmath/source/SmPanelFactory \ starmath/source/accessibility \ starmath/source/action \ starmath/source/caret \ diff --git a/starmath/UIConfig_smath.mk b/starmath/UIConfig_smath.mk index 2a39af9e4a6d..45b12819731a 100644 --- a/starmath/UIConfig_smath.mk +++ b/starmath/UIConfig_smath.mk @@ -39,6 +39,7 @@ $(eval $(call gb_UIConfig_add_uifiles,modules/smath,\ starmath/uiconfig/smath/ui/mathwindow \ starmath/uiconfig/smath/ui/printeroptions \ starmath/uiconfig/smath/ui/savedefaultsdialog \ + starmath/uiconfig/smath/ui/sidebarelements_math \ starmath/uiconfig/smath/ui/smathsettings \ starmath/uiconfig/smath/ui/spacingdialog \ starmath/uiconfig/smath/ui/symdefinedialog \ diff --git a/starmath/source/SmElementsPanel.cxx b/starmath/source/SmElementsPanel.cxx new file mode 100644 index 000000000000..a4c8d7c6d883 --- /dev/null +++ b/starmath/source/SmElementsPanel.cxx @@ -0,0 +1,105 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <sfx2/dispatch.hxx> +#include <svl/stritem.hxx> + +#include "SmElementsPanel.hxx" +#include <starmath.hrc> +#include <smmod.hxx> +#include <strings.hrc> +#include <view.hxx> + +namespace sm::sidebar +{ +// static +std::unique_ptr<PanelLayout> SmElementsPanel::Create(weld::Widget& rParent, + const SfxBindings& rBindings) +{ + return std::make_unique<SmElementsPanel>(rParent, rBindings); +} + +SmElementsPanel::SmElementsPanel(weld::Widget& rParent, const SfxBindings& rBindings) + : PanelLayout(&rParent, "MathElementsPanel", "modules/smath/ui/sidebarelements_math.ui") + , mrBindings(rBindings) + , mxCategoryList(m_xBuilder->weld_tree_view("categorylist")) + , mxElementsControl(std::make_unique<SmElementsControl>( + m_xBuilder->weld_scrolled_window("scrolledwindow", true))) + , mxElementsControlWin( + std::make_unique<weld::CustomWeld>(*m_xBuilder, "element_selector", *mxElementsControl)) +{ + for (size_t i = 0; i < SmElementsControl::categoriesSize(); ++i) + mxCategoryList->append_text(SmResId(std::get<0>(SmElementsControl::categories()[i]))); + + mxCategoryList->set_size_request(-1, mxCategoryList->get_height_rows(6)); + + mxCategoryList->connect_changed(LINK(this, SmElementsPanel, CategorySelectedHandle)); + mxCategoryList->select_text(SmResId(RID_CATEGORY_UNARY_BINARY_OPERATORS)); + + mxElementsControl->setVerticalMode(false); // Sidebar currently can only dock to a side + mxElementsControl->setElementSetId(RID_CATEGORY_UNARY_BINARY_OPERATORS); + mxElementsControl->SetSelectHdl(LINK(this, SmElementsPanel, ElementClickHandler)); +} + +SmElementsPanel::~SmElementsPanel() +{ + mxElementsControlWin.reset(); + mxElementsControl.reset(); + mxCategoryList.reset(); +} + +IMPL_LINK(SmElementsPanel, CategorySelectedHandle, weld::TreeView&, rList, void) +{ + const OUString sSelected = rList.get_selected_text(); + for (size_t i = 0; i < SmElementsControl::categoriesSize(); ++i) + { + const TranslateId& rCategoryId = std::get<0>(SmElementsControl::categories()[i]); + OUString aCurrentCategoryString = SmResId(rCategoryId); + if (aCurrentCategoryString == sSelected) + { + mxElementsControl->setElementSetId(rCategoryId); + if (SmViewShell* pViewSh = GetView()) + mxElementsControl->setSmSyntaxVersion(pViewSh->GetDoc()->GetSmSyntaxVersion()); + return; + } + } +} + +IMPL_LINK(SmElementsPanel, ElementClickHandler, SmElement&, rElement, void) +{ + if (SmViewShell* pViewSh = GetView()) + { + std::unique_ptr<SfxStringItem> pInsertCommand + = std::make_unique<SfxStringItem>(SID_INSERTCOMMANDTEXT, rElement.getText()); + pViewSh->GetViewFrame()->GetDispatcher()->ExecuteList( + SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD, { pInsertCommand.get() }); + } +} + +SmViewShell* SmElementsPanel::GetView() const +{ + SfxViewShell* pView = mrBindings.GetDispatcher()->GetFrame()->GetViewShell(); + return dynamic_cast<SmViewShell*>(pView); +} + +} // end of namespace sm::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/starmath/source/SmElementsPanel.hxx b/starmath/source/SmElementsPanel.hxx new file mode 100644 index 000000000000..4629b33af409 --- /dev/null +++ b/starmath/source/SmElementsPanel.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <sal/config.h> + +#include <sfx2/bindings.hxx> +#include <sfx2/sidebar/IContextChangeReceiver.hxx> +#include <sfx2/sidebar/SidebarModelUpdate.hxx> +#include <sfx2/sidebar/PanelLayout.hxx> +#include <vcl/customweld.hxx> +#include <vcl/EnumContext.hxx> + +#include <ElementsDockingWindow.hxx> + +#include <memory> + +namespace sm::sidebar +{ +class SmElementsPanel : public PanelLayout +{ +public: + static std::unique_ptr<PanelLayout> Create(weld::Widget& rParent, const SfxBindings& rBindings); + SmElementsPanel(weld::Widget& rParent, const SfxBindings& rBindings); + ~SmElementsPanel(); + +private: + DECL_LINK(CategorySelectedHandle, weld::TreeView&, void); + DECL_LINK(ElementClickHandler, SmElement&, void); + + SmViewShell* GetView() const; + + const SfxBindings& mrBindings; + + std::unique_ptr<weld::TreeView> mxCategoryList; + std::unique_ptr<SmElementsControl> mxElementsControl; + std::unique_ptr<weld::CustomWeld> mxElementsControlWin; +}; + +} // end of namespace sm::sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/starmath/source/SmPanelFactory.cxx b/starmath/source/SmPanelFactory.cxx new file mode 100644 index 000000000000..593b2e4a14d6 --- /dev/null +++ b/starmath/source/SmPanelFactory.cxx @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp> +#include <com/sun/star/ui/XUIElementFactory.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +#include <cppuhelper/exc_hlp.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <comphelper/namedvaluecollection.hxx> +#include <sfx2/sidebar/SidebarPanelBase.hxx> +#include <vcl/weldutils.hxx> + +#include "SmElementsPanel.hxx" + +namespace +{ +typedef comphelper::WeakComponentImplHelper<css::ui::XUIElementFactory, css::lang::XServiceInfo> + PanelFactoryInterfaceBase; + +class SmPanelFactory final : public PanelFactoryInterfaceBase +{ +public: + SmPanelFactory() = default; + + SmPanelFactory(const SmPanelFactory&) = delete; + const SmPanelFactory& operator=(const SmPanelFactory&) = delete; + + // XUIElementFactory + css::uno::Reference<css::ui::XUIElement> SAL_CALL + createUIElement(const OUString& ResourceURL, + const css::uno::Sequence<css::beans::PropertyValue>& Arguments) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; +}; + +css::uno::Reference<css::ui::XUIElement> SAL_CALL SmPanelFactory::createUIElement( + const OUString& ResourceURL, const css::uno::Sequence<css::beans::PropertyValue>& Arguments) +{ + try + { + const comphelper::NamedValueCollection aArguments(Arguments); + auto xFrame(aArguments.getOrDefault("Frame", css::uno::Reference<css::frame::XFrame>())); + auto xParentWindow( + aArguments.getOrDefault("ParentWindow", css::uno::Reference<css::awt::XWindow>())); + const sal_uInt64 nBindingsValue(aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); + SfxBindings* pBindings = reinterpret_cast<SfxBindings*>(nBindingsValue); + + weld::Widget* pParent(nullptr); + if (auto pTunnel = dynamic_cast<weld::TransportAsXWindow*>(xParentWindow.get())) + pParent = pTunnel->getWidget(); + + if (!pParent) + throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no ParentWindow"); + if (!xFrame) + throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no Frame"); + if (!pBindings) + throw css::uno::RuntimeException("SmPanelFactory::createUIElement: no SfxBindings"); + + std::unique_ptr<PanelLayout> pPanel; + css::ui::LayoutSize aLayoutSize{ -1, -1, -1 }; + if (ResourceURL.endsWith("/MathElementsPanel")) + { + pPanel = sm::sidebar::SmElementsPanel::Create(*pParent, *pBindings); + aLayoutSize = { 300, -1, -1 }; + } + + if (pPanel) + return sfx2::sidebar::SidebarPanelBase::Create(ResourceURL, xFrame, std::move(pPanel), + aLayoutSize); + } + catch (const css::uno::RuntimeException&) + { + throw; + } + catch (const css::uno::Exception&) + { + css::uno::Any anyEx = cppu::getCaughtException(); + throw css::lang::WrappedTargetRuntimeException("SmPanelFactory::createUIElement exception", + nullptr, anyEx); + } + + return {}; +} + +OUString SmPanelFactory::getImplementationName() +{ + return "org.libreoffice.comp.Math.sidebar.SmPanelFactory"; +} + +sal_Bool SmPanelFactory::supportsService(OUString const& ServiceName) +{ + return cppu::supportsService(this, ServiceName); +} + +css::uno::Sequence<OUString> SmPanelFactory::getSupportedServiceNames() +{ + return { "com.sun.star.ui.UIElementFactory" }; +} + +} // end of unnamed namespace + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +org_libreoffice_comp_Math_sidebar_SmPanelFactory(css::uno::XComponentContext*, + css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new SmPanelFactory); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/starmath/uiconfig/smath/ui/sidebarelements_math.ui b/starmath/uiconfig/smath/ui/sidebarelements_math.ui new file mode 100644 index 000000000000..c645e7f8d349 --- /dev/null +++ b/starmath/uiconfig/smath/ui/sidebarelements_math.ui @@ -0,0 +1,154 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.38.1 --> +<interface domain="svx"> + <requires lib="gtk+" version="3.20"/> + <object class="GtkTreeStore" id="liststore1"> + <columns> + <!-- column-name text --> + <column type="gchararray"/> + </columns> + </object> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid" id="MathElementsPanel"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="border-width">6</property> + <child> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid" id="container"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="row-spacing">3</property> + <property name="column-spacing">6</property> + <child> + <object class="GtkPaned" id="splitter"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="orientation">vertical</property> + <property name="wide-handle">True</property> + <child> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <child> + <object class="GtkScrolledWindow"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow-type">in</property> + <child> + <object class="GtkTreeView" id="categorylist"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore1</property> + <property name="headers-visible">False</property> + <property name="search-column">0</property> + <property name="show-expanders">False</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="treeview-selection2"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn0"> + <child> + <object class="GtkCellRendererText" id="cellrenderertext1"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> + <packing> + <property name="resize">False</property> + <property name="shrink">True</property> + </packing> + </child> + <child> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="row-spacing">6</property> + <child> + <!-- n-columns=1 n-rows=1 --> + <object class="GtkGrid"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <child> + <object class="GtkScrolledWindow" id="scrolledwindow"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="shadow-type">in</property> + <child> + <object class="GtkViewport"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <child> + <object class="GtkDrawingArea" id="element_selector"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="events">GDK_BUTTON_MOTION_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_STRUCTURE_MASK | GDK_SCROLL_MASK | GDK_SMOOTH_SCROLL_MASK</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + </object> + </child> + </object> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> + <packing> + <property name="resize">True</property> + <property name="shrink">True</property> + </packing> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> + <packing> + <property name="left-attach">0</property> + <property name="top-attach">0</property> + </packing> + </child> + </object> +</interface> diff --git a/starmath/util/sm.component b/starmath/util/sm.component index 4f354df4acb0..2b84a17c429c 100644 --- a/starmath/util/sm.component +++ b/starmath/util/sm.component @@ -63,4 +63,8 @@ constructor="com_sun_star_comp_Math_MathTypeFilter_get_implementation"> <service name="com.sun.star.document.ImportFilter"/> </implementation> + <implementation name="org.libreoffice.comp.Math.sidebar.SmPanelFactory" + constructor="org_libreoffice_comp_Math_sidebar_SmPanelFactory"> + <service name="com.sun.star.ui.UIElementFactory"/> + </implementation> </component> |