From 3524e4f7352993517ebdd514435378f6de0ca713 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 25 Apr 2022 18:24:43 +0300 Subject: 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 --- starmath/Library_sm.mk | 2 + starmath/UIConfig_smath.mk | 1 + starmath/source/SmElementsPanel.cxx | 105 ++++++++++++++ starmath/source/SmElementsPanel.hxx | 59 ++++++++ starmath/source/SmPanelFactory.cxx | 131 ++++++++++++++++++ starmath/uiconfig/smath/ui/sidebarelements_math.ui | 154 +++++++++++++++++++++ starmath/util/sm.component | 4 + 7 files changed, 456 insertions(+) create mode 100644 starmath/source/SmElementsPanel.cxx create mode 100644 starmath/source/SmElementsPanel.hxx create mode 100644 starmath/source/SmPanelFactory.cxx create mode 100644 starmath/uiconfig/smath/ui/sidebarelements_math.ui (limited to 'starmath') 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 + +#include +#include + +#include "SmElementsPanel.hxx" +#include +#include +#include +#include + +namespace sm::sidebar +{ +// static +std::unique_ptr SmElementsPanel::Create(weld::Widget& rParent, + const SfxBindings& rBindings) +{ + return std::make_unique(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( + m_xBuilder->weld_scrolled_window("scrolledwindow", true))) + , mxElementsControlWin( + std::make_unique(*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 pInsertCommand + = std::make_unique(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(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 + +#include +#include +#include +#include +#include +#include + +#include + +#include + +namespace sm::sidebar +{ +class SmElementsPanel : public PanelLayout +{ +public: + static std::unique_ptr 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 mxCategoryList; + std::unique_ptr mxElementsControl; + std::unique_ptr 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 + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "SmElementsPanel.hxx" + +namespace +{ +typedef comphelper::WeakComponentImplHelper + PanelFactoryInterfaceBase; + +class SmPanelFactory final : public PanelFactoryInterfaceBase +{ +public: + SmPanelFactory() = default; + + SmPanelFactory(const SmPanelFactory&) = delete; + const SmPanelFactory& operator=(const SmPanelFactory&) = delete; + + // XUIElementFactory + css::uno::Reference SAL_CALL + createUIElement(const OUString& ResourceURL, + const css::uno::Sequence& Arguments) override; + + // XServiceInfo + OUString SAL_CALL getImplementationName() override; + sal_Bool SAL_CALL supportsService(OUString const& ServiceName) override; + css::uno::Sequence SAL_CALL getSupportedServiceNames() override; +}; + +css::uno::Reference SAL_CALL SmPanelFactory::createUIElement( + const OUString& ResourceURL, const css::uno::Sequence& Arguments) +{ + try + { + const comphelper::NamedValueCollection aArguments(Arguments); + auto xFrame(aArguments.getOrDefault("Frame", css::uno::Reference())); + auto xParentWindow( + aArguments.getOrDefault("ParentWindow", css::uno::Reference())); + const sal_uInt64 nBindingsValue(aArguments.getOrDefault("SfxBindings", sal_uInt64(0))); + SfxBindings* pBindings = reinterpret_cast(nBindingsValue); + + weld::Widget* pParent(nullptr); + if (auto pTunnel = dynamic_cast(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 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 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 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 @@ + + + + + + + + + + + + + True + False + True + True + 6 + + + + True + False + True + True + 3 + 6 + + + True + True + True + True + vertical + True + + + + True + False + True + True + + + True + True + True + True + in + + + True + True + True + True + liststore1 + False + 0 + False + + + + + + + + + 1 + + + + + + + + + 0 + 0 + + + + + False + True + + + + + + True + False + True + True + 6 + + + + True + False + True + True + + + True + True + True + True + in + + + True + False + + + True + True + 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 + True + True + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + True + True + + + + + 0 + 0 + + + + + 0 + 0 + + + + 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"> + + + -- cgit