summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2022-06-01 11:20:12 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2022-06-02 12:51:41 +0200
commitd79c527c2a599c7821d27cf03b95cb79e2abe685 (patch)
treef48c85d924086b7112b43137712de5e438556c38 /starmath
parentf6fbdb87a15f7de97e18676560eeba988fac1b67 (diff)
Use IconView in SmElementsControl
Allows to send individual images over the wire in lok case, instead of sending full canvas at every scroll operation. The control's horizontal and vertical modes (when it's docked to a vertical or a horizontal parent window side) are now identical. Some TODOs: * Re-implement a11y - that needs to be implemented on IconView level; * Make sure that sub-pixel positioning is not used when creating the elements icons (makes elements look a bit slim on Windows); * Maybe restore mouse hover indication; in non-GTK case, a call to m_xIconView->SetHoverSelection would suffice in SalInstanceIconView. Change-Id: Idbc35f4e38e2b49fd0848a96da557fa2c1a1f6e1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134761 Tested-by: Mike Kaganski <mike.kaganski@collabora.com> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/Library_sm.mk3
-rw-r--r--starmath/inc/AccessibleSmElement.hxx101
-rw-r--r--starmath/inc/AccessibleSmElementsControl.hxx106
-rw-r--r--starmath/inc/ElementsDockingWindow.hxx106
-rw-r--r--starmath/source/AccessibleSmElement.cxx281
-rw-r--r--starmath/source/AccessibleSmElementsControl.cxx369
-rw-r--r--starmath/source/ElementsDockingWindow.cxx841
-rw-r--r--starmath/source/SmElementsPanel.cxx14
-rw-r--r--starmath/source/SmElementsPanel.hxx3
-rw-r--r--starmath/source/uiobject.cxx106
-rw-r--r--starmath/source/uiobject.hxx57
-rw-r--r--starmath/uiconfig/smath/ui/dockingelements.ui40
-rw-r--r--starmath/uiconfig/smath/ui/sidebarelements_math.ui42
13 files changed, 165 insertions, 1904 deletions
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index e4eca13440d7..aa824cee5890 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -64,8 +64,6 @@ $(eval $(call gb_Library_use_libraries,sm,\
))
$(eval $(call gb_Library_add_exception_objects,sm,\
- starmath/source/AccessibleSmElement \
- starmath/source/AccessibleSmElementsControl \
starmath/source/ElementsDockingWindow \
starmath/source/SmElementsPanel \
starmath/source/SmPanelFactory \
@@ -94,7 +92,6 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
starmath/source/symbol \
starmath/source/tmpdevice \
starmath/source/typemap \
- starmath/source/uiobject \
starmath/source/unodoc \
starmath/source/unofilter \
starmath/source/unomodel \
diff --git a/starmath/inc/AccessibleSmElement.hxx b/starmath/inc/AccessibleSmElement.hxx
deleted file mode 100644
index c1e7e6526872..000000000000
--- a/starmath/inc/AccessibleSmElement.hxx
+++ /dev/null
@@ -1,101 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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 <com/sun/star/accessibility/XAccessible.hpp>
-#include <com/sun/star/accessibility/XAccessibleAction.hpp>
-#include <com/sun/star/accessibility/XAccessibleContext.hpp>
-#include <com/sun/star/accessibility/XAccessibleStateSet.hpp>
-#include <com/sun/star/awt/Rectangle.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <cppuhelper/implbase3.hxx>
-#include <comphelper/accessiblecomponenthelper.hxx>
-#include <sal/types.h>
-
-class SmElementsControl;
-
-typedef ::cppu::ImplHelper3<css::lang::XServiceInfo, css::accessibility::XAccessible,
- css::accessibility::XAccessibleAction>
- AccessibleSmElement_BASE;
-
-class AccessibleSmElement final : public comphelper::OAccessibleComponentHelper,
- public AccessibleSmElement_BASE
-{
- SmElementsControl* m_pSmElementsControl;
- const sal_Int32 m_nIndexInParent; ///< index in the parent XAccessible
- const sal_uInt16 m_nItemId; ///< index in the SmElementsControl
- bool m_bHasFocus;
- sal_Int16 m_nRole;
-
- ~AccessibleSmElement() override;
- void SAL_CALL disposing() override;
- css::awt::Rectangle implGetBounds() override;
-
- void testAction(sal_Int32) const;
-
-public:
- explicit AccessibleSmElement(SmElementsControl* pSmElementsControl, sal_uInt16 nItemId,
- sal_Int32 nIndexInParent);
-
- void SetFocus(bool _bFocus);
- sal_uInt16 itemId() const { return m_nItemId; }
-
- DECLARE_XINTERFACE()
- DECLARE_XTYPEPROVIDER()
-
- // XAccessible
- css::uno::Reference<css::accessibility::XAccessibleContext>
- SAL_CALL getAccessibleContext() override;
-
- // XServiceInfo
- OUString SAL_CALL getImplementationName() override;
- sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override;
- css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
-
- // XAccessibleContext
- sal_Int32 SAL_CALL getAccessibleChildCount() override;
- css::uno::Reference<css::accessibility::XAccessible>
- SAL_CALL getAccessibleChild(sal_Int32 i) override;
- css::uno::Reference<css::accessibility::XAccessible> SAL_CALL getAccessibleParent() override;
- sal_Int32 SAL_CALL getAccessibleIndexInParent() override;
- sal_Int16 SAL_CALL getAccessibleRole() override;
- OUString SAL_CALL getAccessibleDescription() override;
- OUString SAL_CALL getAccessibleName() override;
- css::uno::Reference<css::accessibility::XAccessibleRelationSet>
- SAL_CALL getAccessibleRelationSet() override;
- css::uno::Reference<css::accessibility::XAccessibleStateSet>
- SAL_CALL getAccessibleStateSet() override;
-
- // XAccessibleComponent
- css::uno::Reference<css::accessibility::XAccessible>
- SAL_CALL getAccessibleAtPoint(const css::awt::Point& aPoint) override;
- void SAL_CALL grabFocus() override;
- sal_Int32 SAL_CALL getForeground() override;
- sal_Int32 SAL_CALL getBackground() override;
-
- // XAccessibleAction
- sal_Int32 SAL_CALL getAccessibleActionCount() override;
- sal_Bool SAL_CALL doAccessibleAction(sal_Int32 nIndex) override;
- OUString SAL_CALL getAccessibleActionDescription(sal_Int32 nIndex) override;
- css::uno::Reference<css::accessibility::XAccessibleKeyBinding>
- SAL_CALL getAccessibleActionKeyBinding(sal_Int32 nIndex) override;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/AccessibleSmElementsControl.hxx b/starmath/inc/AccessibleSmElementsControl.hxx
deleted file mode 100644
index bdb5e25ea724..000000000000
--- a/starmath/inc/AccessibleSmElementsControl.hxx
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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 <comphelper/accessiblecomponenthelper.hxx>
-#include <com/sun/star/accessibility/XAccessibleSelection.hpp>
-#include <com/sun/star/lang/XServiceInfo.hpp>
-#include <cppuhelper/implbase3.hxx>
-#include <rtl/ref.hxx>
-
-#include <vector>
-
-class AccessibleSmElement;
-class SmElementsControl;
-
-typedef ::cppu::ImplHelper3<css::lang::XServiceInfo, css::accessibility::XAccessible,
- css::accessibility::XAccessibleSelection>
- AccessibleSmElementsControl_BASE;
-
-class AccessibleSmElementsControl final : public comphelper::OAccessibleComponentHelper,
- public AccessibleSmElementsControl_BASE
-{
- std::vector<rtl::Reference<AccessibleSmElement>> m_aAccessibleChildren;
- SmElementsControl* m_pControl;
-
- void UpdateFocus(sal_uInt16);
- inline void TestControl();
-
- ~AccessibleSmElementsControl() override;
- void SAL_CALL disposing() override;
- css::awt::Rectangle implGetBounds() override;
-
-public:
- AccessibleSmElementsControl(SmElementsControl& rControl);
-
- void ReleaseAllItems();
- void AddAllItems();
- inline void AcquireFocus();
- inline void ReleaseFocus(sal_uInt16);
-
- DECLARE_XINTERFACE()
- DECLARE_XTYPEPROVIDER()
-
- // XAccessible
- css::uno::Reference<css::accessibility::XAccessibleContext>
- SAL_CALL getAccessibleContext() override;
-
- // XServiceInfo
- OUString SAL_CALL getImplementationName() override;
- sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override;
- css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override;
-
- // XAccessibleComponent
- sal_Bool SAL_CALL containsPoint(const css::awt::Point& aPoint) override;
- css::uno::Reference<css::accessibility::XAccessible>
- SAL_CALL getAccessibleAtPoint(const css::awt::Point& aPoint) override;
- void SAL_CALL grabFocus() override;
- sal_Int32 SAL_CALL getForeground() override;
- sal_Int32 SAL_CALL getBackground() override;
-
- // XAccessibleContext
- sal_Int32 SAL_CALL getAccessibleChildCount() override;
- css::uno::Reference<css::accessibility::XAccessible>
- SAL_CALL getAccessibleChild(sal_Int32 i) override;
- css::uno::Reference<css::accessibility::XAccessible> SAL_CALL getAccessibleParent() override;
- sal_Int16 SAL_CALL getAccessibleRole() override;
- OUString SAL_CALL getAccessibleDescription() override;
- OUString SAL_CALL getAccessibleName() override;
- css::uno::Reference<css::accessibility::XAccessibleRelationSet>
- SAL_CALL getAccessibleRelationSet() override;
- css::uno::Reference<css::accessibility::XAccessibleStateSet>
- SAL_CALL getAccessibleStateSet() override;
-
- // XAccessibleSelection
- void SAL_CALL selectAccessibleChild(sal_Int32 nChildIndex) override;
- sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int32 nChildIndex) override;
- void SAL_CALL clearAccessibleSelection() override;
- void SAL_CALL selectAllAccessibleChildren() override;
- sal_Int32 SAL_CALL getSelectedAccessibleChildCount() override;
- css::uno::Reference<css::accessibility::XAccessible>
- SAL_CALL getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex) override;
- void SAL_CALL deselectAccessibleChild(sal_Int32 nChildIndex) override;
-};
-
-void AccessibleSmElementsControl::AcquireFocus() { UpdateFocus(SAL_MAX_UINT16); }
-
-void AccessibleSmElementsControl::ReleaseFocus(sal_uInt16 nPos) { UpdateFocus(nPos); }
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/ElementsDockingWindow.hxx b/starmath/inc/ElementsDockingWindow.hxx
index 28a564f7a1e7..859b7b73a826 100644
--- a/starmath/inc/ElementsDockingWindow.hxx
+++ b/starmath/inc/ElementsDockingWindow.hxx
@@ -26,90 +26,44 @@
#include "node.hxx"
#include "parsebase.hxx"
-#include "AccessibleSmElementsControl.hxx"
-class SmDocShell;
-
-class SmElement
-{
- std::unique_ptr<SmNode> mpNode;
- OUString maText;
- OUString maHelpText;
-
-public:
- Point mBoxLocation;
- Size mBoxSize;
-
- SmElement(std::unique_ptr<SmNode>&& pNode, const OUString& aText, const OUString& aHelpText);
- virtual ~SmElement();
-
- const std::unique_ptr<SmNode>& getNode() const;
- const OUString& getText() const { return maText; }
- const OUString& getHelpText() const { return maHelpText; }
+#include <memory>
+#include <vector>
- virtual bool isSeparator() const { return false; }
-};
-
-class SmElementSeparator final : public SmElement
-{
-public:
- SmElementSeparator();
-
- bool isSeparator() const override { return true; }
-};
+class SmDocShell;
+class SvTreeListBox;
+struct ElementData;
-class SmElementsControl : public weld::CustomWidgetController
+class SmElementsControl
{
- friend class ElementSelectorUIObject;
- friend class ElementUIObject;
-
std::unique_ptr<AbstractSmParser> maParser;
- virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
- virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
- virtual bool MouseMove(const MouseEvent& rMEvt) override;
- virtual OUString RequestHelp(tools::Rectangle& rRect) override;
- virtual void Resize() override;
- virtual void GetFocus() override;
- virtual void LoseFocus() override;
- virtual bool KeyInput(const KeyEvent& rKEvt) override;
- css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
-
SmDocShell* mpDocShell;
SmFormat maFormat;
TranslateId msCurrentSetId;
- sal_uInt16 m_nCurrentElement;
- sal_uInt16 m_nCurrentRolloverElement;
- sal_uInt16 m_nCurrentOffset;
sal_uInt16 m_nSmSyntaxVersion;
- Link<SmElement&,void> maSelectHdlLink;
- std::vector< std::unique_ptr<SmElement> > maElementList;
- Size maMaxElementDimensions;
bool mbVerticalMode;
- std::unique_ptr<weld::ScrolledWindow> mxScroll;
- bool m_bFirstPaintAfterLayout;
- rtl::Reference<AccessibleSmElementsControl> m_xAccessible;
+ std::vector<std::unique_ptr<ElementData>> maItemDatas;
+ std::unique_ptr<weld::IconView> mpIconView;
- void addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText);
- SmElement* current() const;
- void setCurrentElement(sal_uInt16);
- bool hasRollover() const { return m_nCurrentRolloverElement != SAL_MAX_UINT16; }
+ Link<OUString, void> maSelectHdlLink;
- void stepFocus(const bool bBackward);
- void pageFocus(const bool bBackward);
- // common code of page and step focus
- inline void scrollToElement(const bool, const SmElement*);
- inline sal_uInt16 nextElement(const bool, const sal_uInt16, const sal_uInt16);
+ void addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText);
+ void addElements(const TranslateId& rCategory);
void build();
- //if bDraw is true, then draw, otherwise just layout
- void LayoutOrPaintContents(vcl::RenderContext& rContext, bool bDraw);
+ DECL_LINK(QueryTooltipHandler, const weld::TreeIter&, OUString);
+ DECL_LINK(ElementActivatedHandler, weld::IconView&, bool);
+
+ static OUString GetElementSource(const OUString& itemId);
+ static OUString GetElementHelpText(const OUString& itemId);
public:
- explicit SmElementsControl(std::unique_ptr<weld::ScrolledWindow> xScrolledWindow);
- virtual ~SmElementsControl() override;
+
+ explicit SmElementsControl(std::unique_ptr<weld::IconView> pIconView);
+ ~SmElementsControl();
static const std::vector<TranslateId>& categories();
const TranslateId& elementSetId() const { return msCurrentSetId; }
@@ -117,41 +71,23 @@ public:
void setVerticalMode(bool bVertical);
- sal_uInt16 itemCount() const;
- sal_uInt16 itemHighlighted() const;
- sal_uInt16 itemAtPos(const Point& rPos) const;
- tools::Rectangle itemPosRect(sal_uInt16) const;
- bool itemIsSeparator(sal_uInt16) const;
- bool itemIsVisible(sal_uInt16) const;
- OUString itemName(sal_uInt16) const;
- bool itemTrigger(sal_uInt16);
- void setItemHighlighted(sal_uInt16);
void setSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion);
- sal_uInt16 itemOffset() const { return m_nCurrentOffset; }
- virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
+ void SetSelectHdl(const Link<OUString, void>& rLink) { maSelectHdlLink = rLink; }
- DECL_LINK( ScrollHdl, weld::ScrolledWindow&, void );
-
- void SetSelectHdl(const Link<SmElement&,void>& rLink) { maSelectHdlLink = rLink; }
-
- const rtl::Reference<AccessibleSmElementsControl> & GetAccessible() const { return m_xAccessible; }
static Color GetTextColor();
static Color GetControlBackground();
-
- virtual FactoryFunction GetUITestFactory() const override;
};
class SmElementsDockingWindow final : public SfxDockingWindow
{
std::unique_ptr<SmElementsControl> mxElementsControl;
- std::unique_ptr<weld::CustomWeld> mxElementsControlWin;
std::unique_ptr<weld::ComboBox> mxElementListBox;
virtual void Resize() override;
SmViewShell* GetView();
- DECL_LINK(SelectClickHandler, SmElement&, void);
+ DECL_LINK(SelectClickHandler, OUString, void);
DECL_LINK(ElementSelectedHandle, weld::ComboBox&, void);
public:
diff --git a/starmath/source/AccessibleSmElement.cxx b/starmath/source/AccessibleSmElement.cxx
deleted file mode 100644
index 30d19cc8afc3..000000000000
--- a/starmath/source/AccessibleSmElement.cxx
+++ /dev/null
@@ -1,281 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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 <AccessibleSmElement.hxx>
-#include <ElementsDockingWindow.hxx>
-
-#include <com/sun/star/accessibility/AccessibleEventId.hpp>
-#include <com/sun/star/accessibility/AccessibleRole.hpp>
-#include <com/sun/star/accessibility/AccessibleStateType.hpp>
-#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
-#include <cppuhelper/supportsservice.hxx>
-#include <toolkit/helper/convert.hxx>
-#include <unotools/accessiblerelationsethelper.hxx>
-#include <unotools/accessiblestatesethelper.hxx>
-
-using namespace ::com::sun::star::accessibility;
-using namespace ::com::sun::star;
-using OContextEntryGuard = ::comphelper::OContextEntryGuard;
-using OExternalLockGuard = ::comphelper::OExternalLockGuard;
-
-AccessibleSmElement::AccessibleSmElement(SmElementsControl* pSmElementsControl, sal_uInt16 nItemId,
- sal_Int32 nIndexInParent)
- : m_pSmElementsControl(pSmElementsControl)
- , m_nIndexInParent(nIndexInParent)
- , m_nItemId(nItemId)
- , m_bHasFocus(false)
-{
- assert(m_pSmElementsControl);
- m_nRole = m_pSmElementsControl->itemIsSeparator(m_nItemId) ? AccessibleRole::SEPARATOR
- : AccessibleRole::PUSH_BUTTON;
-}
-
-AccessibleSmElement::~AccessibleSmElement() {}
-
-void AccessibleSmElement::SetFocus(bool bFocus)
-{
- if (m_bHasFocus == bFocus)
- return;
-
- uno::Any aOldValue;
- uno::Any aNewValue;
- if (m_bHasFocus)
- aOldValue <<= AccessibleStateType::FOCUSED;
- else
- aNewValue <<= AccessibleStateType::FOCUSED;
- m_bHasFocus = bFocus;
- NotifyAccessibleEvent(AccessibleEventId::STATE_CHANGED, aOldValue, aNewValue);
-}
-
-awt::Rectangle AccessibleSmElement::implGetBounds()
-{
- awt::Rectangle aRect;
- if (m_pSmElementsControl)
- aRect = AWTRectangle(m_pSmElementsControl->itemPosRect(m_nItemId));
- return aRect;
-}
-
-// XInterface
-
-IMPLEMENT_FORWARD_REFCOUNT(AccessibleSmElement, comphelper::OAccessibleComponentHelper)
-
-uno::Any AccessibleSmElement::queryInterface(const uno::Type& _rType)
-{
- if (_rType == cppu::UnoType<XAccessibleAction>::get()
- && (!m_pSmElementsControl || m_pSmElementsControl->itemIsSeparator(m_nItemId)))
- return uno::Any();
-
- uno::Any aReturn = comphelper::OAccessibleComponentHelper::queryInterface(_rType);
- if (!aReturn.hasValue())
- aReturn = AccessibleSmElement_BASE::queryInterface(_rType);
- return aReturn;
-}
-
-// XTypeProvider
-
-IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleSmElement, comphelper::OAccessibleComponentHelper,
- AccessibleSmElement_BASE)
-
-// XComponent
-
-void AccessibleSmElement::disposing()
-{
- comphelper::OAccessibleComponentHelper::disposing();
- m_pSmElementsControl = nullptr;
-}
-
-// XServiceInfo
-
-OUString AccessibleSmElement::getImplementationName()
-{
- return "com.sun.star.comp.toolkit.AccessibleSmElement";
-}
-
-sal_Bool AccessibleSmElement::supportsService(const OUString& rServiceName)
-{
- return cppu::supportsService(this, rServiceName);
-}
-
-uno::Sequence<OUString> AccessibleSmElement::getSupportedServiceNames()
-{
- return { "com.sun.star.accessibility.AccessibleContext",
- "com.sun.star.accessibility.AccessibleComponent",
- "com.sun.star.accessibility.AccessibleSmElement" };
-}
-
-// XAccessible
-
-uno::Reference<XAccessibleContext> AccessibleSmElement::getAccessibleContext() { return this; }
-
-// XAccessibleContext
-
-sal_Int32 AccessibleSmElement::getAccessibleChildCount() { return 0; }
-
-uno::Reference<accessibility::XAccessible> AccessibleSmElement::getAccessibleChild(sal_Int32)
-{
- return uno::Reference<XAccessible>();
-}
-
-uno::Reference<XAccessible> AccessibleSmElement::getAccessibleParent()
-{
- OContextEntryGuard aGuard(this);
- uno::Reference<XAccessible> xParent;
- if (m_pSmElementsControl)
- xParent = m_pSmElementsControl->GetAccessible();
- return xParent;
-}
-
-sal_Int32 AccessibleSmElement::getAccessibleIndexInParent()
-{
- OContextEntryGuard aGuard(this);
- return m_nIndexInParent;
-}
-
-sal_Int16 AccessibleSmElement::getAccessibleRole()
-{
- OContextEntryGuard aGuard(this);
- return m_nRole;
-}
-
-OUString AccessibleSmElement::getAccessibleDescription() { return getAccessibleName(); }
-
-OUString AccessibleSmElement::getAccessibleName()
-{
- OExternalLockGuard aGuard(this);
- OUString aName;
- if (m_pSmElementsControl)
- aName = m_pSmElementsControl->itemName(m_nItemId);
- return aName;
-}
-
-uno::Reference<XAccessibleRelationSet> AccessibleSmElement::getAccessibleRelationSet()
-{
- OContextEntryGuard aGuard(this);
-
- return new utl::AccessibleRelationSetHelper;
-}
-
-uno::Reference<XAccessibleStateSet> AccessibleSmElement::getAccessibleStateSet()
-{
- OExternalLockGuard aGuard(this);
-
- rtl::Reference<utl::AccessibleStateSetHelper> pStateSetHelper
- = new utl::AccessibleStateSetHelper;
-
- if (m_pSmElementsControl && !rBHelper.bDisposed && !rBHelper.bInDispose)
- {
- if (m_pSmElementsControl->itemIsVisible(m_nItemId))
- pStateSetHelper->AddState(AccessibleStateType::VISIBLE);
- if (!m_pSmElementsControl->itemIsSeparator(m_nItemId))
- {
- if (m_pSmElementsControl->IsEnabled())
- {
- pStateSetHelper->AddState(AccessibleStateType::ENABLED);
- pStateSetHelper->AddState(AccessibleStateType::SENSITIVE);
- }
- pStateSetHelper->AddState(AccessibleStateType::FOCUSABLE);
- if (m_bHasFocus)
- pStateSetHelper->AddState(AccessibleStateType::FOCUSED);
- }
- }
- else
- pStateSetHelper->AddState(AccessibleStateType::DEFUNC);
-
- return pStateSetHelper;
-}
-
-// XAccessibleComponent
-
-uno::Reference<XAccessible> AccessibleSmElement::getAccessibleAtPoint(const awt::Point&)
-{
- return uno::Reference<XAccessible>();
-}
-
-void AccessibleSmElement::grabFocus()
-{
- uno::Reference<XAccessible> xParent(getAccessibleParent());
-
- if (xParent.is())
- {
- uno::Reference<XAccessibleSelection> rxAccessibleSelection(xParent->getAccessibleContext(),
- uno::UNO_QUERY);
- if (rxAccessibleSelection.is())
- rxAccessibleSelection->selectAccessibleChild(getAccessibleIndexInParent());
- }
-}
-
-sal_Int32 AccessibleSmElement::getForeground()
-{
- OExternalLockGuard aGuard(this);
-
- Color nColor = SmElementsControl::GetTextColor();
- return sal_Int32(nColor);
-}
-
-sal_Int32 AccessibleSmElement::getBackground()
-{
- OExternalLockGuard aGuard(this);
-
- Color nColor = SmElementsControl::GetControlBackground();
- return sal_Int32(nColor);
-}
-
-// XAccessibleAction
-
-sal_Int32 AccessibleSmElement::getAccessibleActionCount()
-{
- // only one action -> "Press"
- return m_pSmElementsControl->itemIsSeparator(m_nItemId) ? 0 : 1;
-}
-
-void AccessibleSmElement::testAction(sal_Int32 nIndex) const
-{
- if (!m_pSmElementsControl || m_pSmElementsControl->itemIsSeparator(m_nItemId) || (nIndex != 0))
- throw lang::IndexOutOfBoundsException();
-}
-
-sal_Bool AccessibleSmElement::doAccessibleAction(sal_Int32 nIndex)
-{
- OExternalLockGuard aGuard(this);
-
- testAction(nIndex);
-
- return m_pSmElementsControl->itemTrigger(m_nItemId);
-}
-
-OUString AccessibleSmElement::getAccessibleActionDescription(sal_Int32 nIndex)
-{
- OExternalLockGuard aGuard(this);
-
- testAction(nIndex);
-
- return "press";
-}
-
-uno::Reference<XAccessibleKeyBinding>
-AccessibleSmElement::getAccessibleActionKeyBinding(sal_Int32 nIndex)
-{
- OContextEntryGuard aGuard(this);
-
- testAction(nIndex);
-
- return uno::Reference<XAccessibleKeyBinding>();
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/AccessibleSmElementsControl.cxx b/starmath/source/AccessibleSmElementsControl.cxx
deleted file mode 100644
index 1017d8468686..000000000000
--- a/starmath/source/AccessibleSmElementsControl.cxx
+++ /dev/null
@@ -1,369 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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 <AccessibleSmElementsControl.hxx>
-#include <AccessibleSmElement.hxx>
-#include <ElementsDockingWindow.hxx>
-#include <smmod.hxx>
-
-#include <com/sun/star/accessibility/AccessibleEventId.hpp>
-#include <com/sun/star/accessibility/AccessibleRole.hpp>
-#include <com/sun/star/accessibility/AccessibleStateType.hpp>
-#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
-#include <cppuhelper/supportsservice.hxx>
-#include <o3tl/safeint.hxx>
-#include <toolkit/helper/convert.hxx>
-#include <unotools/accessiblerelationsethelper.hxx>
-#include <unotools/accessiblestatesethelper.hxx>
-#include <vcl/svapp.hxx>
-
-using namespace ::com::sun::star;
-using namespace ::com::sun::star::accessibility;
-using OContextEntryGuard = ::comphelper::OContextEntryGuard;
-using OExternalLockGuard = ::comphelper::OExternalLockGuard;
-
-// AccessibleSmElementsControl
-
-AccessibleSmElementsControl::AccessibleSmElementsControl(SmElementsControl& rControl)
- : m_pControl(&rControl)
-{
-}
-
-AccessibleSmElementsControl::~AccessibleSmElementsControl() {}
-
-void AccessibleSmElementsControl::UpdateFocus(sal_uInt16 nPos)
-{
- const bool bSetFocus = (nPos == SAL_MAX_UINT16);
-
- // submit events only if the widget has the focus to avoid sending events due to mouse move
- if (!m_pControl || (bSetFocus && !m_pControl->HasFocus()))
- return;
-
- if (bSetFocus)
- nPos = m_pControl->itemHighlighted() - m_pControl->itemOffset();
-
- if (nPos < m_aAccessibleChildren.size())
- {
- const auto& rxChild = m_aAccessibleChildren[nPos];
- if (rxChild.is())
- rxChild->SetFocus(bSetFocus);
- }
-}
-
-void AccessibleSmElementsControl::ReleaseAllItems()
-{
- if (m_aAccessibleChildren.empty())
- return;
-
- m_aAccessibleChildren.clear();
-
- // The original toolbox accessibility code uses individual NAME_CHANGED
- // events in a loop. We can't do this, because on each remove event the
- // list of known children is rebuild. But since we rely on the child
- // count of the SmElementsControl, we'll always have no or all items.
- // In the latter case this would automatically recreate all items!
- assert(m_pControl && m_pControl->itemCount() == 0);
- NotifyAccessibleEvent(AccessibleEventId::INVALIDATE_ALL_CHILDREN, uno::Any(), uno::Any());
-}
-
-void AccessibleSmElementsControl::AddAllItems()
-{
- assert(m_pControl);
- if (!m_pControl)
- return;
-
- uno::Any aNewName(getAccessibleName());
- NotifyAccessibleEvent(AccessibleEventId::NAME_CHANGED, uno::Any(), aNewName);
-
- // register the new items
- sal_uInt16 nCount = getAccessibleChildCount();
- for (sal_uInt16 i = 0; i < nCount; ++i)
- {
- uno::Any aNewValue;
- aNewValue <<= getAccessibleChild(static_cast<sal_Int32>(i));
- NotifyAccessibleEvent(AccessibleEventId::CHILD, uno::Any(), aNewValue);
- }
-}
-
-IMPLEMENT_FORWARD_XINTERFACE2(AccessibleSmElementsControl, comphelper::OAccessibleComponentHelper,
- AccessibleSmElementsControl_BASE)
-
-IMPLEMENT_FORWARD_XTYPEPROVIDER2(AccessibleSmElementsControl,
- comphelper::OAccessibleComponentHelper,
- AccessibleSmElementsControl_BASE)
-
-// XAccessible
-uno::Reference<XAccessibleContext> AccessibleSmElementsControl::getAccessibleContext()
-{
- return this;
-}
-
-// XComponent
-void AccessibleSmElementsControl::disposing()
-{
- comphelper::OAccessibleComponentHelper::disposing();
- m_aAccessibleChildren.clear();
-}
-
-void AccessibleSmElementsControl::grabFocus()
-{
- SolarMutexGuard aGuard;
- if (!m_pControl)
- throw uno::RuntimeException();
-
- m_pControl->GrabFocus();
-}
-
-sal_Int32 AccessibleSmElementsControl::getForeground()
-{
- SolarMutexGuard aGuard;
-
- return static_cast<sal_Int32>(SmElementsControl::GetTextColor());
-}
-
-sal_Int32 AccessibleSmElementsControl::getBackground()
-{
- SolarMutexGuard aGuard;
-
- Color nCol = SmElementsControl::GetControlBackground();
- return static_cast<sal_Int32>(nCol);
-}
-
-// XServiceInfo
-OUString AccessibleSmElementsControl::getImplementationName()
-{
- return "com.sun.star.comp.toolkit.AccessibleSmElementsControl";
-}
-
-sal_Bool AccessibleSmElementsControl::supportsService(const OUString& rServiceName)
-{
- return cppu::supportsService(this, rServiceName);
-}
-
-uno::Sequence<OUString> AccessibleSmElementsControl::getSupportedServiceNames()
-{
- return { "com.sun.star.accessibility.AccessibleContext",
- "com.sun.star.accessibility.AccessibleComponent",
- "com.sun.star.accessibility.AccessibleSelection",
- "com.sun.star.accessibility.AccessibleSmElementsControl" };
-}
-
-// XAccessibleContext
-sal_Int32 AccessibleSmElementsControl::getAccessibleChildCount()
-{
- comphelper::OExternalLockGuard aGuard(this);
- sal_Int32 nCount = 0;
- if (m_pControl)
- {
- nCount = m_pControl->itemCount();
- if (m_aAccessibleChildren.size() != sal_uInt16(nCount))
- m_aAccessibleChildren.resize(nCount);
- }
- return nCount;
-}
-
-uno::Reference<XAccessible> AccessibleSmElementsControl::getAccessibleChild(sal_Int32 c)
-{
- comphelper::OExternalLockGuard aGuard(this);
-
- if (c < 0 || c >= getAccessibleChildCount())
- throw lang::IndexOutOfBoundsException();
-
- rtl::Reference<AccessibleSmElement> xChild = m_aAccessibleChildren[c];
- const sal_uInt16 nItemId = m_pControl->itemOffset() + c;
- if (xChild.is() && xChild->itemId() != nItemId)
- xChild.clear();
- if (!xChild.is())
- {
- sal_uInt16 nHighlightItemId = m_pControl->itemHighlighted();
- rtl::Reference<AccessibleSmElement> pChild
- = new AccessibleSmElement(m_pControl, nItemId, c);
- if (pChild->itemId() == nHighlightItemId)
- pChild->SetFocus(true);
- m_aAccessibleChildren[c] = pChild;
- xChild = pChild;
- }
- return xChild;
-}
-
-uno::Reference<XAccessible> AccessibleSmElementsControl::getAccessibleParent()
-{
- SolarMutexGuard aGuard;
- if (!m_pControl)
- throw uno::RuntimeException();
-
- return m_pControl->GetDrawingArea()->get_accessible_parent();
-}
-
-uno::Reference<XAccessible>
-AccessibleSmElementsControl::getAccessibleAtPoint(const awt::Point& rPoint)
-{
- comphelper::OExternalLockGuard aGuard(this);
-
- uno::Reference<XAccessible> xAccessible;
- if (m_pControl)
- {
- sal_uInt16 nPos = m_pControl->itemAtPos(VCLPoint(rPoint));
- nPos -= m_pControl->itemOffset();
- if (nPos <= m_aAccessibleChildren.size())
- xAccessible = getAccessibleChild(nPos);
- }
- return xAccessible;
-}
-
-sal_Int16 AccessibleSmElementsControl::getAccessibleRole() { return AccessibleRole::SCROLL_PANE; }
-
-OUString AccessibleSmElementsControl::getAccessibleDescription() { return OUString(); }
-
-OUString AccessibleSmElementsControl::getAccessibleName()
-{
- SolarMutexGuard aGuard;
- OUString aName;
- if (m_pControl && m_pControl->elementSetId())
- aName = SmResId(m_pControl->elementSetId());
- return aName;
-}
-
-// XAccessibleSelection
-void AccessibleSmElementsControl::selectAccessibleChild(sal_Int32 nChildIndex)
-{
- OExternalLockGuard aGuard(this);
-
- if ((!m_pControl) || nChildIndex < 0
- || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size())
- throw lang::IndexOutOfBoundsException();
-
- m_pControl->setItemHighlighted(nChildIndex);
-}
-
-sal_Bool AccessibleSmElementsControl::isAccessibleChildSelected(sal_Int32 nChildIndex)
-{
- OExternalLockGuard aGuard(this);
- if ((!m_pControl) || nChildIndex < 0
- || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size())
- throw lang::IndexOutOfBoundsException();
-
- return (m_pControl->itemHighlighted() == nChildIndex);
-}
-
-void AccessibleSmElementsControl::clearAccessibleSelection()
-{
- OExternalLockGuard aGuard(this);
- if (m_pControl)
- m_pControl->setItemHighlighted(SAL_MAX_UINT16);
-}
-
-void AccessibleSmElementsControl::selectAllAccessibleChildren()
-{
- // intentionally empty
-}
-
-sal_Int32 AccessibleSmElementsControl::getSelectedAccessibleChildCount()
-{
- OExternalLockGuard aGuard(this);
-
- sal_Int32 nRet = 0;
- if (m_pControl
- && (m_pControl->itemHighlighted() - m_pControl->itemOffset()) < getAccessibleChildCount())
- nRet = 1;
- return nRet;
-}
-
-uno::Reference<XAccessible>
-AccessibleSmElementsControl::getSelectedAccessibleChild(sal_Int32 nSelectedChildIndex)
-{
- OExternalLockGuard aGuard(this);
- if (nSelectedChildIndex != 0 || !m_pControl)
- throw lang::IndexOutOfBoundsException();
- return getAccessibleChild(m_pControl->itemHighlighted() - m_pControl->itemOffset());
-}
-
-void AccessibleSmElementsControl::deselectAccessibleChild(sal_Int32 nChildIndex)
-{
- OExternalLockGuard aGuard(this);
- if (nChildIndex != 0 || nChildIndex >= getAccessibleChildCount())
- throw lang::IndexOutOfBoundsException();
- clearAccessibleSelection(); // there can be just one selected child
-}
-
-void AccessibleSmElementsControl::TestControl()
-{
- if (!m_pControl)
- throw uno::RuntimeException();
-}
-
-awt::Rectangle AccessibleSmElementsControl::implGetBounds()
-{
- SolarMutexGuard aGuard;
- TestControl();
-
- awt::Rectangle aRet;
-
- const Point aOutPos;
- Size aOutSize(m_pControl->GetOutputSizePixel());
-
- aRet.X = aOutPos.X();
- aRet.Y = aOutPos.Y();
- aRet.Width = aOutSize.Width();
- aRet.Height = aOutSize.Height();
-
- return aRet;
-}
-
-sal_Bool AccessibleSmElementsControl::containsPoint(const awt::Point& aPoint)
-{
- SolarMutexGuard aGuard;
- TestControl();
- Size aSz(m_pControl->GetOutputSizePixel());
- return aPoint.X >= 0 && aPoint.Y >= 0 && aPoint.X < aSz.Width() && aPoint.Y < aSz.Height();
-}
-
-uno::Reference<XAccessibleRelationSet> AccessibleSmElementsControl::getAccessibleRelationSet()
-{
- uno::Reference<XAccessibleRelationSet> xRelSet = new utl::AccessibleRelationSetHelper();
- return xRelSet; // empty relation set
-}
-
-uno::Reference<XAccessibleStateSet> AccessibleSmElementsControl::getAccessibleStateSet()
-{
- SolarMutexGuard aGuard;
- rtl::Reference<::utl::AccessibleStateSetHelper> pStateSet = new ::utl::AccessibleStateSetHelper;
-
- if (!m_pControl)
- pStateSet->AddState(AccessibleStateType::DEFUNC);
- else
- {
- pStateSet->AddState(AccessibleStateType::ENABLED);
- pStateSet->AddState(AccessibleStateType::FOCUSABLE);
- if (m_pControl->HasFocus())
- pStateSet->AddState(AccessibleStateType::FOCUSED);
- if (m_pControl->IsActive())
- pStateSet->AddState(AccessibleStateType::ACTIVE);
- if (m_pControl->IsVisible())
- pStateSet->AddState(AccessibleStateType::SHOWING);
- if (m_pControl->IsReallyVisible())
- pStateSet->AddState(AccessibleStateType::VISIBLE);
- if (COL_TRANSPARENT != SmElementsControl::GetControlBackground())
- pStateSet->AddState(AccessibleStateType::OPAQUE);
- }
-
- return pStateSet;
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ElementsDockingWindow.cxx b/starmath/source/ElementsDockingWindow.cxx
index f534a5345b8e..bdfdf9e6444d 100644
--- a/starmath/source/ElementsDockingWindow.cxx
+++ b/starmath/source/ElementsDockingWindow.cxx
@@ -27,7 +27,6 @@
#include <view.hxx>
#include <visitors.hxx>
#include <document.hxx>
-#include "uiobject.hxx"
#include <strings.hxx>
#include <sfx2/dispatch.hxx>
@@ -37,24 +36,11 @@
#include <vcl/settings.hxx>
#include <vcl/uitest/eventdescription.hxx>
#include <vcl/uitest/logger.hxx>
+#include <vcl/virdev.hxx>
+#include <unordered_map>
#include <utility>
-SmElement::SmElement(std::unique_ptr<SmNode>&& pNode, const OUString& aText, const OUString& aHelpText) :
- mpNode(std::move(pNode)),
- maText(aText),
- maHelpText(aHelpText)
-{}
-
-SmElement::~SmElement()
-{}
-
-const std::unique_ptr<SmNode>& SmElement::getNode() const { return mpNode; }
-
-SmElementSeparator::SmElementSeparator() :
- SmElement(std::unique_ptr<SmNode>(), OUString(), OUString())
-{}
-
namespace
{
// element, element help, element visual, element visual's translatable
@@ -440,25 +426,29 @@ const std::vector<TranslateId> s_a5Categories{
};
template <size_t N>
-constexpr std::tuple<TranslateId, const SmElementDescr*, size_t>
-asTuple(TranslateId id, const SmElementDescr (&category)[N])
+constexpr std::pair<const SmElementDescr*, size_t> asPair(const SmElementDescr (&category)[N])
{
- return { id, category, N };
+ return { category, N };
}
-const std::tuple<TranslateId, const SmElementDescr*, size_t> s_a5CategoryDescriptions[]{
- asTuple(RID_CATEGORY_UNARY_BINARY_OPERATORS, s_a5UnaryBinaryOperatorsList),
- asTuple(RID_CATEGORY_RELATIONS, s_a5RelationsList),
- asTuple(RID_CATEGORY_SET_OPERATIONS, s_a5SetOperationsList),
- asTuple(RID_CATEGORY_FUNCTIONS, s_a5FunctionsList),
- asTuple(RID_CATEGORY_OPERATORS, s_a5OperatorsList),
- asTuple(RID_CATEGORY_ATTRIBUTES, s_a5AttributesList),
- asTuple(RID_CATEGORY_BRACKETS, s_a5BracketsList),
- asTuple(RID_CATEGORY_FORMATS, s_a5FormatsList),
- asTuple(RID_CATEGORY_OTHERS, s_a5OthersList),
- asTuple(RID_CATEGORY_EXAMPLES, s_a5ExamplesList),
+struct TranslateId_hash
+{
+ size_t operator()(const TranslateId& val) const { return std::hash<std::string_view>()(val.mpId); }
};
-}
+
+const std::unordered_map<TranslateId, std::pair<const SmElementDescr*, size_t>, TranslateId_hash> s_a5CategoryDescriptions{
+ { RID_CATEGORY_UNARY_BINARY_OPERATORS, asPair(s_a5UnaryBinaryOperatorsList) },
+ { RID_CATEGORY_RELATIONS, asPair(s_a5RelationsList) },
+ { RID_CATEGORY_SET_OPERATIONS, asPair(s_a5SetOperationsList) },
+ { RID_CATEGORY_FUNCTIONS, asPair(s_a5FunctionsList) },
+ { RID_CATEGORY_OPERATORS, asPair(s_a5OperatorsList) },
+ { RID_CATEGORY_ATTRIBUTES, asPair(s_a5AttributesList) },
+ { RID_CATEGORY_BRACKETS, asPair(s_a5BracketsList) },
+ { RID_CATEGORY_FORMATS, asPair(s_a5FormatsList) },
+ { RID_CATEGORY_OTHERS, asPair(s_a5OthersList) },
+ { RID_CATEGORY_EXAMPLES, asPair(s_a5ExamplesList) },
+};
+} // namespace
// static
const std::vector<TranslateId>& SmElementsControl::categories()
@@ -466,20 +456,17 @@ const std::vector<TranslateId>& SmElementsControl::categories()
return s_a5Categories;
}
-SmElementsControl::SmElementsControl(std::unique_ptr<weld::ScrolledWindow> xScrolledWindow)
+SmElementsControl::SmElementsControl(std::unique_ptr<weld::IconView> pIconView)
: mpDocShell(new SmDocShell(SfxModelFlags::EMBEDDED_OBJECT))
- , m_nCurrentElement(SAL_MAX_UINT16)
- , m_nCurrentRolloverElement(SAL_MAX_UINT16)
- , m_nCurrentOffset(0)
, m_nSmSyntaxVersion(SM_MOD()->GetConfig()->GetDefaultSmSyntaxVersion())
, mbVerticalMode(true)
- , mxScroll(std::move(xScrolledWindow))
- , m_bFirstPaintAfterLayout(false)
+ , mpIconView(std::move(pIconView))
{
- mxScroll->connect_hadjustment_changed( LINK(this, SmElementsControl, ScrollHdl) );
- mxScroll->connect_vadjustment_changed( LINK(this, SmElementsControl, ScrollHdl) );
maParser.reset(starmathdatabase::GetVersionSmParser(m_nSmSyntaxVersion));
maParser->SetImportSymbolNames(true);
+
+ mpIconView->connect_query_tooltip(LINK(this, SmElementsControl, QueryTooltipHandler));
+ mpIconView->connect_item_activated(LINK(this, SmElementsControl, ElementActivatedHandler));
}
SmElementsControl::~SmElementsControl()
@@ -492,33 +479,7 @@ void SmElementsControl::setVerticalMode(bool bVerticalMode)
if (mbVerticalMode == bVerticalMode)
return;
mbVerticalMode = bVerticalMode;
- // turn off scrollbars, LayoutOrPaintContents will enable whichever one
- // might be needed
- mxScroll->set_vpolicy(VclPolicyType::NEVER);
- mxScroll->set_hpolicy(VclPolicyType::NEVER);
- LayoutOrPaintContents(GetDrawingArea()->get_ref_device(), false);
- Invalidate();
-}
-
-SmElement* SmElementsControl::current() const
-{
- sal_uInt16 nCur = (m_nCurrentRolloverElement != SAL_MAX_UINT16)
- ? m_nCurrentRolloverElement
- : (HasFocus() ? m_nCurrentElement : SAL_MAX_UINT16);
- return (nCur < maElementList.size()) ? maElementList[nCur].get() : nullptr;
-}
-
-void SmElementsControl::setCurrentElement(sal_uInt16 nPos)
-{
- if (m_nCurrentElement == nPos)
- return;
- if (nPos != SAL_MAX_UINT16 && nPos >= maElementList.size())
- return;
- if (m_xAccessible.is() && m_nCurrentElement != SAL_MAX_UINT16)
- m_xAccessible->ReleaseFocus(m_nCurrentElement);
- m_nCurrentElement = nPos;
- if (m_xAccessible.is() && m_nCurrentElement != SAL_MAX_UINT16)
- m_xAccessible->AcquireFocus();
+ build();
}
Color SmElementsControl::GetTextColor()
@@ -533,701 +494,106 @@ Color SmElementsControl::GetControlBackground()
return rStyleSettings.GetFieldColor();
}
-/**
- * !bDraw => layout only
- *
- * Layouting is always done without a scrollbar and will show or hide it.
- * The first paint (m_bFirstPaintAfterLayout) therefore needs to update a
- * visible scrollbar, because the layouting was wrong.
- **/
-void SmElementsControl::LayoutOrPaintContents(vcl::RenderContext& rContext, bool bDraw)
+struct ElementData
{
- rContext.Push();
-
- rContext.SetMapMode( MapMode(MapUnit::Map100thMM) );
- rContext.SetDrawMode( DrawModeFlags::Default );
- rContext.SetLayoutMode( vcl::text::ComplexTextLayoutFlags::Default );
- rContext.SetDigitLanguage( LANGUAGE_ENGLISH );
- if (bDraw)
- {
- rContext.SetBackground(GetControlBackground());
- rContext.SetTextColor(GetTextColor());
- rContext.Erase();
- }
-
- const sal_Int32 nControlHeight = GetOutputSizePixel().Height();
- const sal_Int32 nControlWidth = GetOutputSizePixel().Width();
-
- sal_Int32 boxX = maMaxElementDimensions.Width() + 10;
- sal_Int32 boxY = maMaxElementDimensions.Height() + 10;
-
- sal_Int32 x = mbVerticalMode ? -mxScroll->hadjustment_get_value() : 0;
- sal_Int32 y = !mbVerticalMode ? -mxScroll->vadjustment_get_value() : 0;
-
- sal_Int32 perLine = 0;
-
- if (mbVerticalMode)
- perLine = nControlHeight / boxY;
- else
- perLine = nControlWidth / boxX;
- if (perLine <= 0)
- perLine = 1;
-
- if (mbVerticalMode)
- boxY = nControlHeight / perLine;
- else
- boxX = nControlWidth / perLine;
-
- const SmElement* pCurrentElement = current();
- for (const std::unique_ptr<SmElement> & i : maElementList)
+ OUString maElementSource;
+ OUString maHelpText;
+ ElementData(const OUString& aElementSource, const OUString& aHelpText)
+ : maElementSource(aElementSource)
+ , maHelpText(aHelpText)
{
- SmElement* element = i.get();
- if (element->isSeparator())
- {
- if (mbVerticalMode)
- {
- x += boxX;
- y = 0;
-
- element->mBoxLocation = Point(x, y);
- element->mBoxSize = Size(10, nControlHeight);
-
- tools::Rectangle aSelectionRectangle(x + 5 - 1, y + 5,
- x + 5 + 1, nControlHeight - 5);
-
- if (bDraw)
- rContext.DrawRect(rContext.PixelToLogic(aSelectionRectangle));
- x += 10;
- }
- else
- {
- x = 0;
- y += boxY;
-
- element->mBoxLocation = Point(x, y);
- element->mBoxSize = Size(nControlWidth, 10);
-
- tools::Rectangle aSelectionRectangle(x + 5, y + 5 - 1,
- nControlWidth - 5, y + 5 + 1);
-
- if (bDraw)
- rContext.DrawRect(rContext.PixelToLogic(aSelectionRectangle));
- y += 10;
- }
- }
- else
- {
- if (mbVerticalMode)
- {
- if (y + boxY > nControlHeight)
- {
- x += boxX;
- y = 0;
- }
- }
- else
- {
- if ( x + boxX > nControlWidth)
- {
- x = 0;
- y += boxY;
- }
- }
-
- element->mBoxLocation = Point(x,y);
- element->mBoxSize = Size(boxX, boxY);
-
- if (bDraw)
- {
- if (pCurrentElement == element)
- {
- rContext.Push(vcl::PushFlags::FILLCOLOR | vcl::PushFlags::LINECOLOR);
- const StyleSettings& rStyleSettings = rContext.GetSettings().GetStyleSettings();
- rContext.SetLineColor(rStyleSettings.GetHighlightColor());
- rContext.SetFillColor(COL_TRANSPARENT);
- rContext.DrawRect(rContext.PixelToLogic(tools::Rectangle(x + 1, y + 1, x + boxX - 1, y + boxY - 1)));
- rContext.DrawRect(rContext.PixelToLogic(tools::Rectangle(x + 2, y + 2, x + boxX - 2, y + boxY - 2)));
- rContext.Pop();
- }
-
- Size aSizePixel = rContext.LogicToPixel(Size(element->getNode()->GetWidth(),
- element->getNode()->GetHeight()));
- Point location(x + ((boxX - aSizePixel.Width()) / 2),
- y + ((boxY - aSizePixel.Height()) / 2));
- SmDrawingVisitor(rContext, rContext.PixelToLogic(location), element->getNode().get());
- }
-
- if (mbVerticalMode)
- y += boxY;
- else
- x += boxX;
- }
}
+};
- if (bDraw)
- {
- if (!m_bFirstPaintAfterLayout)
- {
- rContext.Pop();
- return;
- }
- m_bFirstPaintAfterLayout = false;
- }
- else
- m_bFirstPaintAfterLayout = true;
-
- if (mbVerticalMode)
- {
- sal_Int32 nTotalControlWidth = x + boxX + mxScroll->hadjustment_get_value();
- if (nTotalControlWidth > GetOutputSizePixel().Width())
- {
- mxScroll->hadjustment_set_upper(nTotalControlWidth);
- mxScroll->hadjustment_set_page_size(nControlWidth);
- mxScroll->hadjustment_set_page_increment(nControlWidth);
- mxScroll->hadjustment_set_step_increment(boxX);
- mxScroll->set_hpolicy(VclPolicyType::ALWAYS);
- }
- else
- {
- mxScroll->hadjustment_set_value(0);
- mxScroll->set_hpolicy(VclPolicyType::NEVER);
- }
- }
- else
- {
- sal_Int32 nTotalControlHeight = y + boxY + mxScroll->vadjustment_get_value();
- if (nTotalControlHeight > GetOutputSizePixel().Height())
- {
- mxScroll->vadjustment_set_upper(nTotalControlHeight);
- mxScroll->vadjustment_set_page_size(nControlHeight);
- mxScroll->vadjustment_set_page_increment(nControlHeight);
- mxScroll->vadjustment_set_step_increment(boxY);
- mxScroll->set_vpolicy(VclPolicyType::ALWAYS);
- }
- else
- {
- mxScroll->vadjustment_set_value(0);
- mxScroll->set_vpolicy(VclPolicyType::NEVER);
- }
- }
- rContext.Pop();
-}
-
-void SmElementsControl::Resize()
-{
- CustomWidgetController::Resize();
- LayoutOrPaintContents(GetDrawingArea()->get_ref_device(), false);
-}
-
-void SmElementsControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
+void SmElementsControl::addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText)
{
- LayoutOrPaintContents(rRenderContext, true);
-}
+ std::unique_ptr<SmNode> pNode = maParser->ParseExpression(aElementVisual);
+ VclPtr<VirtualDevice> pDevice(mpIconView->create_virtual_device());
+ pDevice->SetTextRenderModeForResolutionIndependentLayout(true);
+ pDevice->SetMapMode(MapMode(MapUnit::Map100thMM));
+ pDevice->SetDrawMode(DrawModeFlags::Default);
+ pDevice->SetLayoutMode(vcl::text::ComplexTextLayoutFlags::Default);
+ pDevice->SetDigitLanguage(LANGUAGE_ENGLISH);
-OUString SmElementsControl::RequestHelp(tools::Rectangle& rRect)
-{
- if (!hasRollover())
- return OUString();
+ pDevice->SetBackground(GetControlBackground());
+ pDevice->SetTextColor(GetTextColor());
- const SmElement* pHelpElement = current();
- if (!pHelpElement)
- return OUString();
+ pNode->Prepare(maFormat, *mpDocShell, 0);
+ pNode->SetSize(Fraction(10,8));
+ pNode->Arrange(*pDevice, maFormat);
- rRect = tools::Rectangle(pHelpElement->mBoxLocation, pHelpElement->mBoxSize);
+ Size aSize = pDevice->LogicToPixel(Size(pNode->GetWidth(), pNode->GetHeight()));
+ aSize.extendBy(10, 0); // Add 5 pixels from both sides to accomodate extending parts of italics
+ pDevice->SetOutputSizePixel(aSize);
+ SmDrawingVisitor(*pDevice, pDevice->PixelToLogic(Point(5, 0)), pNode.get());
- // get text and display it
- return pHelpElement->getHelpText();
+ maItemDatas.push_back(std::make_unique<ElementData>(aElementSource, aHelpText));
+ const OUString aId(weld::toId(maItemDatas.back().get()));
+ mpIconView->insert(-1, nullptr, &aId, pDevice, nullptr);
+ if (mpIconView->get_item_width() < aSize.Width())
+ mpIconView->set_item_width(aSize.Width());
}
-bool SmElementsControl::MouseMove( const MouseEvent& rMouseEvent )
+OUString SmElementsControl::GetElementSource(const OUString& itemId)
{
- if (rMouseEvent.IsLeaveWindow())
- {
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
- Invalidate();
- return false;
- }
-
- if (tools::Rectangle(Point(0, 0), GetOutputSizePixel()).Contains(rMouseEvent.GetPosPixel()))
- {
- const SmElement* pPrevElement = current();
- if (pPrevElement)
- {
- const tools::Rectangle rect(pPrevElement->mBoxLocation, pPrevElement->mBoxSize);
- if (rect.Contains(rMouseEvent.GetPosPixel()))
- return true;
- }
-
- const sal_uInt16 nElementCount = maElementList.size();
- for (sal_uInt16 n = 0; n < nElementCount; n++)
- {
- const SmElement* element = maElementList[n].get();
- if (pPrevElement == element)
- continue;
-
- const tools::Rectangle rect(element->mBoxLocation, element->mBoxSize);
- if (rect.Contains(rMouseEvent.GetPosPixel()))
- {
- m_nCurrentRolloverElement = n;
- Invalidate();
- return true;
- }
- }
- if (pPrevElement && hasRollover())
- Invalidate();
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
- return true;
- }
-
- return false;
+ return weld::fromId<ElementData*>(itemId)->maElementSource;
}
-namespace {
-
-void collectUIInformation(const OUString& aID)
+OUString SmElementsControl::GetElementHelpText(const OUString& itemId)
{
- EventDescription aDescription;
- aDescription.aID = aID;
- aDescription.aParent = "element_selector";
- aDescription.aAction = "SELECT";
- aDescription.aKeyWord = "ElementUIObject";
- UITestLogger::getInstance().logEvent(aDescription);
-}
-
+ return weld::fromId<ElementData*>(itemId)->maHelpText;
}
-bool SmElementsControl::MouseButtonDown(const MouseEvent& rMouseEvent)
-{
- GrabFocus();
-
- if (rMouseEvent.IsLeft() && tools::Rectangle(Point(0, 0), GetOutputSizePixel()).Contains(rMouseEvent.GetPosPixel()) && maSelectHdlLink.IsSet())
- {
- const SmElement* pPrevElement = hasRollover() ? current() : nullptr;
- if (pPrevElement)
- {
- tools::Rectangle rect(pPrevElement->mBoxLocation, pPrevElement->mBoxSize);
- if (rect.Contains(rMouseEvent.GetPosPixel()))
- {
- setCurrentElement(m_nCurrentRolloverElement);
- maSelectHdlLink.Call(*const_cast<SmElement*>(pPrevElement));
- collectUIInformation(OUString::number(m_nCurrentRolloverElement));
- return true;
- }
- }
-
- const sal_uInt16 nElementCount = maElementList.size();
- for (sal_uInt16 n = 0; n < nElementCount; n++)
- {
- SmElement* element = maElementList[n].get();
- tools::Rectangle rect(element->mBoxLocation, element->mBoxSize);
- if (rect.Contains(rMouseEvent.GetPosPixel()))
- {
- setCurrentElement(n);
- maSelectHdlLink.Call(*element);
- collectUIInformation(OUString::number(n));
- return true;
- }
- }
-
- return true;
- }
- return false;
-}
-
-void SmElementsControl::GetFocus()
+void SmElementsControl::setElementSetId(TranslateId pSetId)
{
- CustomWidgetController::GetFocus();
- Invalidate();
- if (m_xAccessible.is() && m_nCurrentElement != SAL_MAX_UINT16)
- m_xAccessible->AcquireFocus();
+ if (msCurrentSetId == pSetId)
+ return;
+ msCurrentSetId = pSetId;
+ build();
}
-void SmElementsControl::LoseFocus()
+void SmElementsControl::addElements(const TranslateId& rCategory)
{
- if (m_xAccessible.is() && m_nCurrentElement != SAL_MAX_UINT16)
- m_xAccessible->ReleaseFocus(m_nCurrentElement);
- CustomWidgetController::LoseFocus();
- Invalidate();
-}
+ mpIconView->freeze();
+ mpIconView->clear();
+ mpIconView->set_item_width(0);
+ maItemDatas.clear();
-sal_uInt16 SmElementsControl::nextElement(const bool bBackward, const sal_uInt16 nStartPos, const sal_uInt16 nLastElement)
-{
- sal_uInt16 nPos = nStartPos;
+ const auto& [aElementsArray, aElementsArraySize] = s_a5CategoryDescriptions.at(rCategory);
- while (true)
+ for (size_t i = 0; i < aElementsArraySize; i++)
{
- if (bBackward)
+ const auto& [element, elementHelp, elementVisual, visualTranslatable] = aElementsArray[i];
+ if (element.empty())
{
- if (nPos == 0)
- break;
- nPos--;
+ mpIconView->append_separator({});
}
else
{
- if (nPos == nLastElement)
- break;
- nPos++;
+ OUString aElement(OUString::createFromAscii(element));
+ OUString aVisual(elementVisual.empty() ? aElement : OUString(elementVisual));
+ if (visualTranslatable)
+ aVisual = aVisual.replaceFirst("$1", SmResId(visualTranslatable));
+ OUString aHelp(elementHelp ? SmResId(elementHelp) : OUString());
+ addElement(aVisual, aElement, aHelp);
}
-
- if (nStartPos == nPos)
- break;
- if (!maElementList[nPos]->isSeparator())
- break;
}
- return nPos;
-}
-
-void SmElementsControl::scrollToElement(const bool bBackward, const SmElement *pCur)
-{
- if (mbVerticalMode)
- {
- auto nScrollPos = mxScroll->hadjustment_get_value();
- nScrollPos += pCur->mBoxLocation.X();
- if (!bBackward)
- nScrollPos += pCur->mBoxSize.Width() - GetOutputSizePixel().Width();
- mxScroll->hadjustment_set_value(nScrollPos);
- }
- else
- {
- auto nScrollPos = mxScroll->vadjustment_get_value();
- nScrollPos += pCur->mBoxLocation.Y();
- if (!bBackward)
- nScrollPos += pCur->mBoxSize.Height() - GetOutputSizePixel().Height();
- mxScroll->vadjustment_set_value(nScrollPos);
- }
-}
-
-void SmElementsControl::stepFocus(const bool bBackward)
-{
- const sal_uInt16 nStartPos = m_nCurrentElement;
- const sal_uInt16 nLastElement = (maElementList.size() ? maElementList.size() - 1 : 0);
- assert(nStartPos <= nLastElement);
-
- sal_uInt16 nPos = nextElement(bBackward, nStartPos, nLastElement);
- if (nStartPos != nPos)
- {
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
- setCurrentElement(nPos);
-
- const tools::Rectangle outputRect(Point(0,0), GetOutputSizePixel());
- const SmElement *pCur = maElementList[nPos].get();
- tools::Rectangle elementRect(pCur->mBoxLocation, pCur->mBoxSize);
- if (!outputRect.Contains(elementRect))
- scrollToElement(bBackward, pCur);
- Invalidate();
- }
-}
-
-void SmElementsControl::pageFocus(const bool bBackward)
-{
- const sal_uInt16 nStartPos = m_nCurrentElement;
- const sal_uInt16 nLastElement = (maElementList.size() ? maElementList.size() - 1 : 0);
- assert(nStartPos <= nLastElement);
- tools::Rectangle outputRect(Point(0,0), GetOutputSizePixel());
- sal_uInt16 nPrevPos = nStartPos;
- sal_uInt16 nPos = nPrevPos;
-
- bool bMoved = false;
- while (true)
- {
- nPrevPos = nPos;
- nPos = nextElement(bBackward, nPrevPos, nLastElement);
- if (nPrevPos == nPos)
- break;
-
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
-
- SmElement *pCur = maElementList[nPos].get();
- tools::Rectangle elementRect(pCur->mBoxLocation, pCur->mBoxSize);
- if (!outputRect.Contains(elementRect))
- {
- if (nPrevPos != nStartPos)
- {
- nPos = nPrevPos;
- break;
- }
- if (bMoved)
- break;
- pCur = maElementList[nPrevPos].get();
-
- elementRect = tools::Rectangle(pCur->mBoxLocation, pCur->mBoxSize);
- if (mbVerticalMode)
- outputRect.Move(bBackward ? -outputRect.GetWidth() + elementRect.Right() : elementRect.Left(), 0);
- else
- outputRect.Move(0, bBackward ? -outputRect.GetHeight() + elementRect.Bottom() : elementRect.Top());
- bMoved = true;
- }
- }
-
- if (nStartPos != nPos)
- {
- setCurrentElement(nPos);
- if (bMoved)
- scrollToElement(bBackward, maElementList[nPos].get());
- Invalidate();
- }
-}
-
-bool SmElementsControl::KeyInput(const KeyEvent& rKEvt)
-{
- vcl::KeyCode aKeyCode = rKEvt.GetKeyCode();
-
- if (aKeyCode.GetModifier())
- {
- return false;
- }
-
- switch(aKeyCode.GetCode())
- {
- case KEY_RETURN:
- [[fallthrough]];
- case KEY_SPACE:
- assert(m_nCurrentElement < maElementList.size());
- assert(maSelectHdlLink.IsSet());
- maSelectHdlLink.Call(*maElementList[m_nCurrentElement]);
- collectUIInformation(OUString::number(m_nCurrentElement));
- break;
-
- case KEY_DOWN:
- [[fallthrough]];
- case KEY_RIGHT:
- stepFocus(false);
- break;
-
- case KEY_LEFT:
- [[fallthrough]];
- case KEY_UP:
- stepFocus(true);
- break;
-
- case KEY_HOME:
- if (!maElementList.empty())
- {
- setCurrentElement(0);
- mxScroll->vadjustment_set_value(0);
- }
- break;
- case KEY_END:
- if (!maElementList.empty())
- {
- setCurrentElement(maElementList.size() - 1);
- mxScroll->vadjustment_set_value(mxScroll->vadjustment_get_upper());
- }
- break;
-
- case KEY_PAGEUP:
- pageFocus(true);
- break;
- case KEY_PAGEDOWN:
- pageFocus(false);
- break;
-
- default:
- return false;
- }
- return true;
-}
-
-IMPL_LINK_NOARG( SmElementsControl, ScrollHdl, weld::ScrolledWindow&, void )
-{
- Invalidate();
-}
-
-void SmElementsControl::addElement(const OUString& aElementVisual, const OUString& aElementSource, const OUString& aHelpText)
-{
- // SAL_MAX_UINT16 is invalid, zero is the scrollbar
- assert(maElementList.size() < SAL_MAX_UINT16 - 2);
- auto pNode = maParser->ParseExpression(aElementVisual);
-
- OutputDevice& rDevice = GetDrawingArea()->get_ref_device();
- rDevice.Push(vcl::PushFlags::MAPMODE);
- rDevice.SetMapMode( MapMode(MapUnit::Map100thMM) );
-
- pNode->Prepare(maFormat, *mpDocShell, 0);
- pNode->SetSize(Fraction(10,8));
- pNode->Arrange(rDevice, maFormat);
-
- Size aSizePixel = rDevice.LogicToPixel(Size(pNode->GetWidth(), pNode->GetHeight()), MapMode(MapUnit::Map100thMM));
- if (aSizePixel.Width() > maMaxElementDimensions.Width()) {
- maMaxElementDimensions.setWidth( aSizePixel.Width() );
- }
-
- if (aSizePixel.Height() > maMaxElementDimensions.Height()) {
- maMaxElementDimensions.setHeight( aSizePixel.Height() );
- }
-
- maElementList.push_back(std::make_unique<SmElement>(std::move(pNode), aElementSource, aHelpText));
-
- rDevice.Pop();
-}
-
-void SmElementsControl::setElementSetId(TranslateId pSetId)
-{
- if (msCurrentSetId == pSetId)
- return;
- msCurrentSetId = pSetId;
- maMaxElementDimensions = Size();
- build();
+ mpIconView->set_size_request(0, 0);
+ mpIconView->thaw();
}
void SmElementsControl::build()
{
- // The order is important!
- // 1. Ensure there are no items left
- // 2. Release all the current accessible items.
- // This will check for new items after releasing them!
- // 3. Set the cursor element
- maElementList.clear();
- mxScroll->hadjustment_set_value(0);
- mxScroll->vadjustment_set_value(0);
- mxScroll->set_hpolicy(VclPolicyType::NEVER);
- mxScroll->set_vpolicy(VclPolicyType::NEVER);
-
- if (m_xAccessible.is())
- m_xAccessible->ReleaseAllItems();
-
- setCurrentElement(SAL_MAX_UINT16);
-
- m_nCurrentOffset = 0;
-
switch(m_nSmSyntaxVersion)
{
case 5:
- {
- for (const auto& [rSetId, rElementsArray, rElementsArraySize] : s_a5CategoryDescriptions)
- {
- if (msCurrentSetId == rSetId)
- {
- for (size_t i = 0; i < rElementsArraySize; i++)
- {
- const auto& [element, elementHelp, elementVisual, visualTranslatable]
- = rElementsArray[i];
- if (element.empty())
- {
- maElementList.push_back(std::make_unique<SmElementSeparator>());
- }
- else
- {
- OUString aElement(OUString::createFromAscii(element));
- OUString aVisual(elementVisual.empty() ? aElement
- : OUString(elementVisual));
- if (visualTranslatable)
- aVisual = aVisual.replaceFirst("$1", SmResId(visualTranslatable));
- OUString aHelp(elementHelp ? SmResId(elementHelp) : OUString());
- addElement(aVisual, aElement, aHelp);
- }
- }
-
- break;
- }
- else
- m_nCurrentOffset += rElementsArraySize;
- }
+ addElements(msCurrentSetId);
break;
- }
case 6:
default:
throw std::range_error("parser version limit");
}
-
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
- LayoutOrPaintContents(GetDrawingArea()->get_ref_device(), false);
-
- if (m_xAccessible.is())
- m_xAccessible->AddAllItems();
-
- setCurrentElement(0);
- Invalidate();
-}
-
-void SmElementsControl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
-{
- CustomWidgetController::SetDrawingArea(pDrawingArea);
- OutputDevice& rDevice = pDrawingArea->get_ref_device();
- maFormat.SetBaseSize(rDevice.PixelToLogic(Size(0, SmPtsTo100th_mm(12))));
- Size aSize(rDevice.LogicToPixel(Size(10, 100), MapMode(MapUnit::MapAppFont)));
- // give it an arbitrary small width request so it can shrink in the sidebar
- pDrawingArea->set_size_request(42, aSize.Height());
- SetOutputSizePixel(aSize);
-}
-
-FactoryFunction SmElementsControl::GetUITestFactory() const
-{
- return ElementSelectorUIObject::create;
-}
-
-bool SmElementsControl::itemIsSeparator(sal_uInt16 nPos) const
-{
- if (nPos < m_nCurrentOffset)
- return true;
- nPos -= m_nCurrentOffset;
- if (nPos >= maElementList.size())
- return true;
- return maElementList[nPos]->isSeparator();
-}
-
-css::uno::Reference<css::accessibility::XAccessible> SmElementsControl::CreateAccessible()
-{
- if (!m_xAccessible.is())
- {
- m_xAccessible = new AccessibleSmElementsControl(*this);
- m_xAccessible->AddAllItems();
- }
- return m_xAccessible;
-}
-
-bool SmElementsControl::itemTrigger(sal_uInt16 nPos)
-{
- if (nPos < m_nCurrentOffset)
- return false;
- nPos -= m_nCurrentOffset;
- if (nPos >= maElementList.size())
- return false;
-
- maSelectHdlLink.Call(*maElementList[nPos]);
- collectUIInformation(OUString::number(nPos));
- return true;
-}
-
-tools::Rectangle SmElementsControl::itemPosRect(sal_uInt16 nPos) const
-{
- if (nPos < m_nCurrentOffset)
- return tools::Rectangle();
- nPos -= m_nCurrentOffset;
- if (nPos >= maElementList.size())
- return tools::Rectangle();
-
- SmElement* pItem = maElementList[nPos].get();
- return tools::Rectangle(pItem->mBoxLocation, pItem->mBoxSize);
-}
-
-bool SmElementsControl::itemIsVisible(sal_uInt16 nPos) const
-{
- tools::Rectangle elementRect = itemPosRect(nPos);
- if (elementRect.IsEmpty())
- return false;
-
- tools::Rectangle outputRect(Point(0, 0), GetOutputSizePixel());
- return outputRect.Contains(elementRect);
-}
-
-sal_uInt16 SmElementsControl::itemCount() const { return maElementList.size(); }
-
-sal_uInt16 SmElementsControl::itemHighlighted() const { return m_nCurrentElement; }
-
-void SmElementsControl::setItemHighlighted(sal_uInt16 nPos)
-{
- if (m_nCurrentRolloverElement == nPos)
- return;
- if (nPos != SAL_MAX_UINT16 && nPos >= maElementList.size())
- return;
-
- if (maElementList[nPos]->isSeparator())
- m_nCurrentRolloverElement = SAL_MAX_UINT16;
- else
- m_nCurrentRolloverElement = nPos;
- Invalidate();
}
void SmElementsControl::setSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion)
@@ -1242,35 +608,26 @@ void SmElementsControl::setSmSyntaxVersion(sal_uInt16 nSmSyntaxVersion)
}
}
-OUString SmElementsControl::itemName(sal_uInt16 nPos) const
+IMPL_LINK(SmElementsControl, QueryTooltipHandler, const weld::TreeIter&, iter, OUString)
{
- if (nPos < m_nCurrentOffset)
- return OUString();
- nPos -= m_nCurrentOffset;
- if (nPos >= maElementList.size())
- return OUString();
-
- return maElementList[nPos]->getHelpText();
+ if (const OUString id = mpIconView->get_id(iter); !id.isEmpty())
+ return GetElementHelpText(id);
+ return {};
}
-sal_uInt16 SmElementsControl::itemAtPos(const Point& rPoint) const
+IMPL_LINK_NOARG(SmElementsControl, ElementActivatedHandler, weld::IconView&, bool)
{
- sal_uInt16 nElementCount = maElementList.size();
- for (sal_uInt16 n = 0; n < nElementCount; n++)
- {
- const SmElement* pItem = maElementList[n].get();
- tools::Rectangle elementRect(pItem->mBoxLocation, pItem->mBoxSize);
- if (elementRect.Contains(rPoint))
- return n;
- }
- return SAL_MAX_UINT16;
+ if (const OUString id = mpIconView->get_selected_id(); !id.isEmpty())
+ maSelectHdlLink.Call(GetElementSource(id));
+
+ mpIconView->unselect_all();
+ return true;
}
SmElementsDockingWindow::SmElementsDockingWindow(SfxBindings* pInputBindings, SfxChildWindow* pChildWindow, vcl::Window* pParent)
: SfxDockingWindow(pInputBindings, pChildWindow, pParent, "DockingElements",
"modules/smath/ui/dockingelements.ui")
- , mxElementsControl(new SmElementsControl(m_xBuilder->weld_scrolled_window("scrolledwindow", true)))
- , mxElementsControlWin(new weld::CustomWeld(*m_xBuilder, "element_selector", *mxElementsControl))
+ , mxElementsControl(std::make_unique<SmElementsControl>(m_xBuilder->weld_icon_view("elements")))
, mxElementListBox(m_xBuilder->weld_combo_box("listbox"))
{
// give it an arbitrary small width request so it can shrink in the sidebar
@@ -1300,7 +657,6 @@ SmElementsDockingWindow::~SmElementsDockingWindow ()
void SmElementsDockingWindow::dispose()
{
- mxElementsControlWin.reset();
mxElementsControl.reset();
mxElementListBox.reset();
SfxDockingWindow::dispose();
@@ -1328,16 +684,15 @@ void SmElementsDockingWindow::EndDocking( const tools::Rectangle& rReactangle, b
mxElementsControl->setVerticalMode(bVertical);
}
-IMPL_LINK(SmElementsDockingWindow, SelectClickHandler, SmElement&, rElement, void)
+IMPL_LINK(SmElementsDockingWindow, SelectClickHandler, OUString, sElementSource, void)
{
SmViewShell* pViewSh = GetView();
if (pViewSh)
{
- std::unique_ptr<SfxStringItem> pInsertCommand = std::make_unique<SfxStringItem>(SID_INSERTCOMMANDTEXT, rElement.getText());
+ SfxStringItem aInsertCommand(SID_INSERTCOMMANDTEXT, sElementSource);
pViewSh->GetViewFrame()->GetDispatcher()->ExecuteList(
- SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD,
- { pInsertCommand.get() });
+ SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD, { &aInsertCommand });
}
}
diff --git a/starmath/source/SmElementsPanel.cxx b/starmath/source/SmElementsPanel.cxx
index fdf76daa6e1d..165e950ead5a 100644
--- a/starmath/source/SmElementsPanel.cxx
+++ b/starmath/source/SmElementsPanel.cxx
@@ -41,10 +41,7 @@ SmElementsPanel::SmElementsPanel(weld::Widget& rParent, const SfxBindings& rBind
: 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))
+ , mxElementsControl(std::make_unique<SmElementsControl>(m_xBuilder->weld_icon_view("elements")))
{
for (const auto& rCategoryId : SmElementsControl::categories())
mxCategoryList->append_text(SmResId(rCategoryId));
@@ -54,14 +51,12 @@ SmElementsPanel::SmElementsPanel(weld::Widget& rParent, const SfxBindings& rBind
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();
}
@@ -82,14 +77,13 @@ IMPL_LINK(SmElementsPanel, CategorySelectedHandle, weld::TreeView&, rList, void)
}
}
-IMPL_LINK(SmElementsPanel, ElementClickHandler, SmElement&, rElement, void)
+IMPL_LINK(SmElementsPanel, ElementClickHandler, OUString, ElementSource, void)
{
if (SmViewShell* pViewSh = GetView())
{
- std::unique_ptr<SfxStringItem> pInsertCommand
- = std::make_unique<SfxStringItem>(SID_INSERTCOMMANDTEXT, rElement.getText());
+ SfxStringItem aInsertCommand(SID_INSERTCOMMANDTEXT, ElementSource);
pViewSh->GetViewFrame()->GetDispatcher()->ExecuteList(
- SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD, { pInsertCommand.get() });
+ SID_INSERTCOMMANDTEXT, SfxCallMode::RECORD, { &aInsertCommand });
}
}
diff --git a/starmath/source/SmElementsPanel.hxx b/starmath/source/SmElementsPanel.hxx
index 72de4c227a87..d80d53e7211f 100644
--- a/starmath/source/SmElementsPanel.hxx
+++ b/starmath/source/SmElementsPanel.hxx
@@ -41,7 +41,7 @@ public:
private:
DECL_LINK(CategorySelectedHandle, weld::TreeView&, void);
- DECL_LINK(ElementClickHandler, SmElement&, void);
+ DECL_LINK(ElementClickHandler, OUString, void);
SmViewShell* GetView() const;
@@ -49,7 +49,6 @@ private:
std::unique_ptr<weld::TreeView> mxCategoryList;
std::unique_ptr<SmElementsControl> mxElementsControl;
- std::unique_ptr<weld::CustomWeld> mxElementsControlWin;
};
} // end of namespace sm::sidebar
diff --git a/starmath/source/uiobject.cxx b/starmath/source/uiobject.cxx
deleted file mode 100644
index e39de3cc6bbe..000000000000
--- a/starmath/source/uiobject.cxx
+++ /dev/null
@@ -1,106 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- */
-
-#include <memory>
-#include "uiobject.hxx"
-#include <ElementsDockingWindow.hxx>
-
-ElementUIObject::ElementUIObject(SmElementsControl* pElementSelector,
- const OUString& rID):
- mpElementsSelector(pElementSelector),
- maID(rID)
-{
-}
-
-SmElement* ElementUIObject::get_element()
-{
- sal_uInt32 nID = maID.toUInt32();
- size_t n = mpElementsSelector->maElementList.size();
- if (nID >= n)
- return nullptr;
-
- return mpElementsSelector->maElementList[nID].get();
-}
-
-StringMap ElementUIObject::get_state()
-{
- StringMap aMap;
- aMap["ID"] = maID;
-
- SmElement* pElement = get_element();
- if (pElement)
- aMap["Text"] = pElement->getText();
-
- return aMap;
-}
-
-void ElementUIObject::execute(const OUString& rAction,
- const StringMap& /*rParameters*/)
-{
- if (rAction == "SELECT")
- {
- SmElement* pElement = get_element();
- if (pElement)
- mpElementsSelector->maSelectHdlLink.Call(*pElement);
- }
-}
-
-ElementSelectorUIObject::ElementSelectorUIObject(vcl::Window* pElementSelectorWindow)
- : DrawingAreaUIObject(pElementSelectorWindow)
- , mpElementsSelector(static_cast<SmElementsControl*>(mpController))
-{
-}
-
-StringMap ElementSelectorUIObject::get_state()
-{
- StringMap aMap = DrawingAreaUIObject::get_state();
-
- SmElement* pElement = mpElementsSelector->current();
- if (pElement)
- aMap["CurrentEntry"] = pElement->getText();
-
- aMap["CurrentSelection"] = OUString::fromUtf8(mpElementsSelector->msCurrentSetId.mpId);
-
- return aMap;
-}
-
-std::unique_ptr<UIObject> ElementSelectorUIObject::get_child(const OUString& rID)
-{
- size_t nID = rID.toInt32();
- size_t n = mpElementsSelector->maElementList.size();
- if (nID >= n)
- throw css::uno::RuntimeException("invalid id");
-
- return std::unique_ptr<UIObject>(new ElementUIObject(mpElementsSelector, rID));
-}
-
-std::set<OUString> ElementSelectorUIObject::get_children() const
-{
- std::set<OUString> aChildren;
-
- size_t n = mpElementsSelector->maElementList.size();
- for (size_t i = 0; i < n; ++i)
- {
- aChildren.insert(OUString::number(i));
- }
-
- return aChildren;
-}
-
-std::unique_ptr<UIObject> ElementSelectorUIObject::create(vcl::Window* pWindow)
-{
- return std::unique_ptr<UIObject>(new ElementSelectorUIObject(pWindow));
-}
-
-OUString ElementSelectorUIObject::get_name() const
-{
- return "SmElementSelector";
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/uiobject.hxx b/starmath/source/uiobject.hxx
deleted file mode 100644
index 665572e5ad5e..000000000000
--- a/starmath/source/uiobject.hxx
+++ /dev/null
@@ -1,57 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * 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/.
- */
-
-#pragma once
-
-#include <vcl/uitest/uiobject.hxx>
-#include <ElementsDockingWindow.hxx>
-
-class ElementUIObject : public UIObject
-{
-private:
- SmElementsControl* mpElementsSelector;
- OUString maID;
-
-public:
-
- ElementUIObject(SmElementsControl* pElementSelector,
- const OUString& rID);
-
- virtual StringMap get_state() override;
-
- virtual void execute(const OUString& rAction,
- const StringMap& rParameters) override;
-
-private:
- SmElement* get_element();
-};
-
-class ElementSelectorUIObject : public DrawingAreaUIObject
-{
-private:
- SmElementsControl* mpElementsSelector;
-
-public:
-
- explicit ElementSelectorUIObject(vcl::Window* pElementSelectorWindow);
-
- virtual StringMap get_state() override;
-
- static std::unique_ptr<UIObject> create(vcl::Window* pWindow);
-
- virtual std::unique_ptr<UIObject> get_child(const OUString& rID) override;
-
- virtual std::set<OUString> get_children() const override;
-
-protected:
-
- virtual OUString get_name() const override;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/uiconfig/smath/ui/dockingelements.ui b/starmath/uiconfig/smath/ui/dockingelements.ui
index 18b7356afcbe..a7dfec85ebaf 100644
--- a/starmath/uiconfig/smath/ui/dockingelements.ui
+++ b/starmath/uiconfig/smath/ui/dockingelements.ui
@@ -2,9 +2,17 @@
<!-- Generated with glade 3.22.1 -->
<interface domain="sm">
<requires lib="gtk+" version="3.20"/>
+ <object class="GtkTreeStore" id="liststore1">
+ <columns>
+ <!-- column-name expander -->
+ <column type="GdkPixbuf"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkBox" id="DockingElements">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="orientation">vertical</property>
@@ -12,8 +20,8 @@
<child>
<object class="GtkComboBoxText" id="listbox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="tooltip_text" translatable="yes" context="dockingelements|ElementCategories|tooltip_text">Element categories</property>
+ <property name="can-focus">False</property>
+ <property name="tooltip-text" translatable="yes" context="dockingelements|ElementCategories|tooltip_text">Element categories</property>
</object>
<packing>
<property name="expand">False</property>
@@ -22,25 +30,23 @@
</packing>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow">
+ <object class="GtkScrolledWindow">
<property name="visible">True</property>
- <property name="can_focus">True</property>
+ <property name="can-focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
- <property name="shadow_type">in</property>
+ <property name="shadow-type">in</property>
<child>
- <object class="GtkViewport">
+ <object class="GtkIconView" id="elements">
<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>
+ <property name="can-focus">True</property>
+ <property name="margin">6</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="model">liststore1</property>
+ <property name="columns">2</property>
+ <property name="pixbuf-column">0</property>
+ <property name="activate-on-single-click">True</property>
</object>
</child>
</object>
diff --git a/starmath/uiconfig/smath/ui/sidebarelements_math.ui b/starmath/uiconfig/smath/ui/sidebarelements_math.ui
index b8ae84e7cfa9..e82e6032de22 100644
--- a/starmath/uiconfig/smath/ui/sidebarelements_math.ui
+++ b/starmath/uiconfig/smath/ui/sidebarelements_math.ui
@@ -10,6 +10,14 @@
<column type="gchararray"/>
</columns>
</object>
+ <object class="GtkTreeStore" id="liststore2">
+ <columns>
+ <!-- column-name expander -->
+ <column type="GdkPixbuf"/>
+ <!-- column-name id -->
+ <column type="gchararray"/>
+ </columns>
+ </object>
<object class="GtkPaned" id="MathElementsPanel">
<property name="visible">True</property>
<property name="can-focus">False</property>
@@ -53,37 +61,23 @@
</object>
</child>
<child>
- <object class="GtkScrolledWindow" id="scrolledwindow">
+ <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="GtkViewport">
+ <object class="GtkIconView" id="elements">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <child>
- <object class="GtkBox">
- <property name="visible">True</property>
- <property name="can-focus">False</property>
- <property name="orientation">vertical</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</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>
- <packing>
- <property name="position">0</property>
- </packing>
- </child>
- </object>
- </child>
+ <property name="can-focus">True</property>
+ <property name="margin">6</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="model">liststore2</property>
+ <property name="columns">2</property>
+ <property name="pixbuf-column">0</property>
+ <property name="activate-on-single-click">True</property>
</object>
</child>
</object>