extensions/source/bibliography/toolbar.hxx | 1 framework/source/uielement/edittoolbarcontroller.cxx | 1 include/sfx2/sidebar/ControllerFactory.hxx | 7 include/sfx2/weldutils.hxx | 54 + include/svtools/ctrlbox.hxx | 11 include/svtools/generictoolboxcontroller.hxx | 47 include/svx/labelitemwindow.hxx | 30 include/svx/relfld.hxx | 1 include/svx/sidebar/PanelLayout.hxx | 2 include/vcl/InterimItemWindow.hxx | 38 include/vcl/combobox.hxx | 3 include/vcl/customweld.hxx | 1 include/vcl/salvtables.hxx | 6 include/vcl/svapp.hxx | 4 include/vcl/syschild.hxx | 1 include/vcl/sysdata.hxx | 1 include/vcl/weld.hxx | 20 include/vcl/weldutils.hxx | 128 ++ officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu | 11 officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu | 8 sd/source/ui/dlg/diactrl.cxx | 1 sfx2/Library_sfx.mk | 1 sfx2/inc/pch/precompiled_sfx.hxx | 1 sfx2/source/dialog/recfloat.cxx | 3 sfx2/source/inc/recfloat.hxx | 6 sfx2/source/sidebar/ControllerFactory.cxx | 49 sfx2/source/toolbox/weldutils.cxx | 135 ++ solenv/bin/native-code.py | 1 svtools/source/control/ctrlbox.cxx | 11 svtools/source/uno/generictoolboxcontroller.cxx | 104 +- svx/Library_svxcore.mk | 2 svx/UIConfig_svx.mk | 2 svx/inc/pch/precompiled_svx.hxx | 3 svx/source/inc/InterimItemWindow.hxx | 35 svx/source/inc/StylesPreviewToolBoxControl.hxx | 72 + svx/source/inc/StylesPreviewWindow.hxx | 123 ++ svx/source/inc/findtextfield.hxx | 69 + svx/source/sidebar/PanelLayout.cxx | 15 svx/source/sidebar/paragraph/ParaSpacingControl.cxx | 10 svx/source/sidebar/paragraph/ParaSpacingWindow.cxx | 367 ++++--- svx/source/sidebar/paragraph/ParaSpacingWindow.hxx | 65 - svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx | 184 +++ svx/source/tbxctrls/StylesPreviewWindow.cxx | 505 ++++++++++ svx/source/tbxctrls/linemetricbox.hxx | 57 + svx/source/tbxctrls/tbunocontroller.cxx | 182 ++- svx/uiconfig/ui/fontsizebox.ui | 29 svx/uiconfig/ui/paralrspacing.ui | 43 svx/uiconfig/ui/paraulspacing.ui | 25 svx/uiconfig/ui/stylespreview.ui | 142 ++ svx/util/svxcore.component | 4 test/source/screenshot_test.cxx | 9 vcl/Library_vcl.mk | 1 vcl/inc/salinst.hxx | 2 vcl/inc/salobj.hxx | 3 vcl/inc/unx/gtk/gtkframe.hxx | 2 vcl/inc/unx/gtk/gtkinst.hxx | 1 vcl/inc/unx/gtk/gtkobject.hxx | 62 + vcl/source/app/salvtables.cxx | 63 + vcl/source/app/weldutils.cxx | 32 vcl/source/control/InterimItemWindow.cxx | 99 + vcl/source/control/combobox.cxx | 15 vcl/source/window/builder.cxx | 2 vcl/source/window/stacking.cxx | 17 vcl/source/window/syschild.cxx | 7 vcl/unx/gtk3/gtk3gtkinst.cxx | 143 ++ vcl/unx/gtk3/gtk3gtkobject.cxx | 296 +++++ 66 files changed, 2964 insertions(+), 411 deletions(-)
New commits: commit 2d4740cbd4511e1225b8447d7821630d71c5e3c9 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Wed May 27 16:25:10 2020 +0200 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:38 2020 +0200 Styles preview widget Change-Id: Ib9723c9793244069407ceaa4935a11da08db3795 diff --git a/include/vcl/customweld.hxx b/include/vcl/customweld.hxx index dc8fd57afd41..fbfd025af5a5 100644 --- a/include/vcl/customweld.hxx +++ b/include/vcl/customweld.hxx @@ -130,6 +130,7 @@ public: void set_grid_left_attach(int nAttach) { m_xDrawingArea->set_grid_left_attach(nAttach); } int get_grid_left_attach() const { return m_xDrawingArea->get_grid_left_attach(); } void set_help_id(const OString& rHelpId) { m_xDrawingArea->set_help_id(rHelpId); } + void set_tooltip_text(const OUString& rTip) { m_xDrawingArea->set_tooltip_text(rTip); } }; } #endif diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu index 722df647ce3b..458df8ee88e1 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu @@ -1426,6 +1426,17 @@ <value>com.sun.star.comp.svx.FontNameToolBoxControl</value> </prop> </node> + <node oor:name="StylesPreviewToolBox" oor:op="replace"> + <prop oor:name="Command"> + <value>.uno:StylesPreview</value> + </prop> + <prop oor:name="Module"> + <value/> + </prop> + <prop oor:name="Controller"> + <value>com.sun.star.comp.svx.StylesPreviewToolBoxControl</value> + </prop> + </node> <node oor:name="OpenToolbarController" oor:op="replace"> <prop oor:name="Command"> <value>.uno:Open</value> diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu index 08ff909b5db5..d3e6a8469d82 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu @@ -3025,6 +3025,14 @@ <value>1</value> </prop> </node> + <node oor:name=".uno:StylesPreview" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Styles Preview</value> + </prop> + <prop oor:name="Properties" oor:type="xs:int"> + <value>1</value> + </prop> + </node> <node oor:name=".uno:AddDateField" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> <value xml:lang="en-US">Date Field</value> diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py index abf3509cd911..b77a0a80d767 100755 --- a/solenv/bin/native-code.py +++ b/solenv/bin/native-code.py @@ -257,6 +257,7 @@ core_constructor_list = [ "com_sun_star_comp_svx_FontNameToolBoxControl_get_implementation", "com_sun_star_comp_Svx_GraphicExportHelper_get_implementation", "com_sun_star_comp_Svx_GraphicImportHelper_get_implementation", + "com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation" # toolkit/util/tk.component "stardiv_Toolkit_StdTabController_get_implementation", "stardiv_Toolkit_UnoButtonControl_get_implementation", diff --git a/svx/Library_svxcore.mk b/svx/Library_svxcore.mk index fe2a7469bfe5..271322c1073a 100644 --- a/svx/Library_svxcore.mk +++ b/svx/Library_svxcore.mk @@ -378,6 +378,8 @@ $(eval $(call gb_Library_add_exception_objects,svxcore,\ svx/source/tbxctrls/tbxcolorupdate \ svx/source/tbxctrls/SvxColorValueSet \ svx/source/tbxctrls/SvxPresetListBox \ + svx/source/tbxctrls/StylesPreviewToolBoxControl \ + svx/source/tbxctrls/StylesPreviewWindow \ svx/source/toolbars/extrusionbar \ svx/source/toolbars/fontworkbar \ svx/source/unodraw/gluepts \ diff --git a/svx/UIConfig_svx.mk b/svx/UIConfig_svx.mk index 853dc5ba397b..c2a7428ee582 100644 --- a/svx/UIConfig_svx.mk +++ b/svx/UIConfig_svx.mk @@ -95,6 +95,7 @@ $(eval $(call gb_UIConfig_add_uifiles,svx,\ svx/uiconfig/ui/sidebarstylespanel \ svx/uiconfig/ui/sidebartextpanel \ svx/uiconfig/ui/stylemenu \ + svx/uiconfig/ui/stylespreview \ svx/uiconfig/ui/textcharacterspacingcontrol \ svx/uiconfig/ui/textcontrolchardialog \ svx/uiconfig/ui/textcontrolparadialog \ diff --git a/svx/source/inc/StylesPreviewToolBoxControl.hxx b/svx/source/inc/StylesPreviewToolBoxControl.hxx new file mode 100644 index 000000000000..c42c5ba09fd2 --- /dev/null +++ b/svx/source/inc/StylesPreviewToolBoxControl.hxx @@ -0,0 +1,72 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_TOOLBOX_CONTROL_HXX +#define INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_TOOLBOX_CONTROL_HXX + +#include <svx/svxdllapi.h> +#include <sfx2/tbxctrl.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include "StylesPreviewWindow.hxx" +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XDispatchProvider.hpp> + +class SVX_DLLPUBLIC StylesPreviewToolBoxControl final + : public cppu::ImplInheritanceHelper<svt::ToolboxController, css::lang::XServiceInfo> +{ + VclPtr<StylesPreviewWindow_Impl> m_xVclBox; + std::unique_ptr<StylesPreviewWindow_Base> m_xWeldBox; + StylesPreviewWindow_Base* m_pBox; + + css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider; + + std::vector<OUString> m_aDefaultStyles; + +public: + StylesPreviewToolBoxControl(); + virtual ~StylesPreviewToolBoxControl() override; + + // XStatusListener + virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent& rEvent) override; + + // XToolbarController + virtual css::uno::Reference<css::awt::XWindow> + SAL_CALL createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) override; + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& aArguments) override; + + // XComponent + virtual void SAL_CALL dispose() override; + + // XUpdatable + virtual void SAL_CALL update() override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + +private: + void InitializeStyles(const css::uno::Reference<css::frame::XModel>& xModel); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file diff --git a/svx/source/inc/StylesPreviewWindow.hxx b/svx/source/inc/StylesPreviewWindow.hxx new file mode 100644 index 000000000000..5ae857210c6f --- /dev/null +++ b/svx/source/inc/StylesPreviewWindow.hxx @@ -0,0 +1,123 @@ +/* -*- 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 . + */ + +#ifndef INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_WINDOW_HXX +#define INCLUDED_SVX_SOURCE_INC_STYLES_PREVIEW_WINDOW_HXX + +#include <vcl/InterimItemWindow.hxx> +#include <vcl/customweld.hxx> +#include <svl/style.hxx> +#include <com/sun/star/frame/XDispatchProvider.hpp> +#include <sfx2/sfxstatuslistener.hxx> + +class StylesPreviewWindow_Base; + +class StyleStatusListener : public SfxStatusListener +{ + StylesPreviewWindow_Base* m_pPreviewControl; + +public: + StyleStatusListener(StylesPreviewWindow_Base* pPreviewControl, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); + + void StateChanged(SfxItemState eState, const SfxPoolItem* pState) override; +}; + +class StyleItemController : public weld::CustomWidgetController +{ + static constexpr unsigned LEFT_MARGIN = 8; + + SfxStyleFamily m_eStyleFamily; + OUString m_aStyleName; + bool m_bSelected; + css::uno::Reference<css::frame::XDispatchProvider> m_xDispatchProvider; + +public: + StyleItemController(const OUString& aStyleName, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); + + void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; + + bool MouseButtonDown(const MouseEvent&) override; + + void SetStyle(const OUString& sStyleName); + + void Select(bool bSelect); + +private: + void DrawEntry(vcl::RenderContext& rRenderContext); + void DrawText(vcl::RenderContext& rRenderContext); + void DrawHighlight(vcl::RenderContext& rRenderContext, Color aFontBack); + static void DrawSelection(vcl::RenderContext& rRenderContext); + static void DrawContentBackground(vcl::RenderContext& rRenderContext, + tools::Rectangle& aContentRect, Color& aColor); +}; + +class StylesPreviewWindow_Base +{ +protected: + static constexpr unsigned STYLES_COUNT = 4; + + std::unique_ptr<StyleItemController> m_xStyleControllers[STYLES_COUNT]; + std::unique_ptr<weld::CustomWeld> m_xStyleControllersWeld[STYLES_COUNT]; + + StyleStatusListener* m_pStatusListener; + css::uno::Reference<css::lang::XComponent> m_xStatusListener; + + std::unique_ptr<weld::Toolbar> m_xUp; + std::unique_ptr<weld::Toolbar> m_xDown; + + std::vector<OUString> m_aDefaultStyles; + std::vector<OUString> m_aAllStyles; + + unsigned m_nStyleIterator; + OUString m_sSelectedStyle; + + DECL_LINK(GoUp, const OString&, void); + DECL_LINK(GoDown, const OString&, void); + +public: + StylesPreviewWindow_Base(weld::Builder& xBuilder, std::vector<OUString>& aDefaultStyles, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); + ~StylesPreviewWindow_Base(); + + void Select(const OUString& rStyleName); + +private: + void Update(); + void UpdateStylesList(); + void MakeCurrentStyleVisible(); + OUString GetVisibleStyle(unsigned nPosition); +}; + +class StylesPreviewWindow_Impl : public InterimItemWindow, public StylesPreviewWindow_Base +{ +public: + StylesPreviewWindow_Impl(vcl::Window* pParent, std::vector<OUString>& aDefaultStyles, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider); + ~StylesPreviewWindow_Impl(); + + void dispose(); + + void SetOptimalSize(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file diff --git a/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx new file mode 100644 index 000000000000..0a95aa5397e5 --- /dev/null +++ b/svx/source/tbxctrls/StylesPreviewToolBoxControl.cxx @@ -0,0 +1,184 @@ +/* -*- 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 <StylesPreviewToolBoxControl.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <vcl/svapp.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <com/sun/star/uno/Reference.hxx> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> + +StylesPreviewToolBoxControl::StylesPreviewToolBoxControl() {} + +StylesPreviewToolBoxControl::~StylesPreviewToolBoxControl() {} + +void SAL_CALL +StylesPreviewToolBoxControl::initialize(const css::uno::Sequence<css::uno::Any>& rArguments) +{ + svt::ToolboxController::initialize(rArguments); + + if (m_xFrame.is()) + { + InitializeStyles(m_xFrame->getController()->getModel()); + + m_xDispatchProvider = css::uno::Reference<css::frame::XDispatchProvider>( + m_xFrame->getController(), css::uno::UNO_QUERY); + } +} + +void SAL_CALL StylesPreviewToolBoxControl::dispose() +{ + svt::ToolboxController::dispose(); + + SolarMutexGuard aSolarMutexGuard; + m_xVclBox.disposeAndClear(); + m_xWeldBox.reset(); + m_pBox = nullptr; +} + +void StylesPreviewToolBoxControl::InitializeStyles( + const css::uno::Reference<css::frame::XModel>& xModel) +{ + m_aDefaultStyles.clear(); + + //now convert the default style names to the localized names + try + { + css::uno::Reference<css::style::XStyleFamiliesSupplier> xStylesSupplier( + xModel, css::uno::UNO_QUERY_THROW); + css::uno::Reference<css::lang::XServiceInfo> xServices(xModel, css::uno::UNO_QUERY_THROW); + if (xServices->supportsService("com.sun.star.text.TextDocument")) + { + css::uno::Reference<css::container::XNameAccess> xParaStyles; + xStylesSupplier->getStyleFamilies()->getByName("ParagraphStyles") >>= xParaStyles; + static const std::vector<OUString> aWriterStyles + = { "Standard", "Text body", "Title", "Subtitle", + "Heading 1", "Heading 2", "Heading 3", "Quotations" }; + for (const OUString& aStyle : aWriterStyles) + { + try + { + css::uno::Reference<css::beans::XPropertySet> xStyle; + xParaStyles->getByName(aStyle) >>= xStyle; + OUString sName; + xStyle->getPropertyValue("DisplayName") >>= sName; + if (!sName.isEmpty()) + m_aDefaultStyles.push_back(sName); + } + catch (const css::uno::Exception&) + { + } + } + } + else if (xServices->supportsService("com.sun.star.sheet.SpreadsheetDocument")) + { + static const char* aCalcStyles[] = { "Default", "Heading1", "Result", "Result2" }; + css::uno::Reference<css::container::XNameAccess> xCellStyles; + xStylesSupplier->getStyleFamilies()->getByName("CellStyles") >>= xCellStyles; + for (const char* pCalcStyle : aCalcStyles) + { + try + { + const OUString sStyleName(OUString::createFromAscii(pCalcStyle)); + if (xCellStyles->hasByName(sStyleName)) + { + css::uno::Reference<css::beans::XPropertySet> xStyle( + xCellStyles->getByName(sStyleName), css::uno::UNO_QUERY_THROW); + OUString sName; + xStyle->getPropertyValue("DisplayName") >>= sName; + if (!sName.isEmpty()) + m_aDefaultStyles.push_back(sName); + } + } + catch (const css::uno::Exception&) + { + } + } + } + } + catch (const css::uno::Exception&) + { + OSL_FAIL("error while initializing style names"); + } +} + +void SAL_CALL StylesPreviewToolBoxControl::update() {} + +void StylesPreviewToolBoxControl::statusChanged(const css::frame::FeatureStateEvent& /*rEvent*/) {} + +css::uno::Reference<css::awt::XWindow> +StylesPreviewToolBoxControl::createItemWindow(const css::uno::Reference<css::awt::XWindow>& rParent) +{ + css::uno::Reference<css::awt::XWindow> xItemWindow; + + /* TODO + if (m_pBuilder) + { + SolarMutexGuard aSolarMutexGuard; + + std::unique_ptr<weld::Container> xWidget(*m_pBuilder); + + xItemWindow + = css::uno::Reference<css::awt::XWindow>(new weld::TransportAsXWindow(xWidget.get())); + + m_xWeldBox.reset(new StylesPreviewWindow_Base(std::move(xWidget))); + m_pBox = m_xWeldBox.get(); + } + else + */ + { + VclPtr<vcl::Window> pParent = VCLUnoHelper::GetWindow(rParent); + if (pParent) + { + SolarMutexGuard aSolarMutexGuard; + + m_xVclBox = VclPtr<StylesPreviewWindow_Impl>::Create(pParent, m_aDefaultStyles, + m_xDispatchProvider); + m_pBox = m_xVclBox.get(); + xItemWindow = VCLUnoHelper::GetInterface(m_xVclBox); + } + } + + return xItemWindow; +} + +OUString StylesPreviewToolBoxControl::getImplementationName() +{ + return "com.sun.star.comp.svx.StylesPreviewToolBoxControl"; +} + +sal_Bool StylesPreviewToolBoxControl::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +css::uno::Sequence<OUString> StylesPreviewToolBoxControl::getSupportedServiceNames() +{ + return { "com.sun.star.frame.ToolbarController" }; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation( + css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&) +{ + return cppu::acquire(new StylesPreviewToolBoxControl()); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file diff --git a/svx/source/tbxctrls/StylesPreviewWindow.cxx b/svx/source/tbxctrls/StylesPreviewWindow.cxx new file mode 100644 index 000000000000..48fd9ad6237f --- /dev/null +++ b/svx/source/tbxctrls/StylesPreviewWindow.cxx @@ -0,0 +1,505 @@ +/* -*- 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 <StylesPreviewWindow.hxx> + +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> +#include <sfx2/objsh.hxx> +#include <svl/itemset.hxx> +#include <sfx2/tbxctrl.hxx> +#include <sfx2/sfxsids.hrc> +#include <sfx2/tplpitem.hxx> + +#include <editeng/editids.hrc> +#include <editeng/fontitem.hxx> +#include <editeng/fhgtitem.hxx> +#include <editeng/svxfont.hxx> +#include <editeng/wghtitem.hxx> +#include <editeng/postitem.hxx> +#include <editeng/contouritem.hxx> +#include <editeng/shdditem.hxx> +#include <editeng/charreliefitem.hxx> +#include <editeng/udlnitem.hxx> +#include <editeng/crossedoutitem.hxx> +#include <editeng/colritem.hxx> +#include <editeng/cmapitem.hxx> +#include <editeng/emphasismarkitem.hxx> +#include <editeng/brushitem.hxx> + +#include <svx/xfillit0.hxx> +#include <svx/svddef.hxx> +#include <svx/xflclit.hxx> + +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/uno/Sequence.hxx> +#include <cppuhelper/weak.hxx> + +#include <sal/log.hxx> + +StyleStatusListener::StyleStatusListener( + StylesPreviewWindow_Base* pPreviewControl, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) + : SfxStatusListener(xDispatchProvider, SID_STYLE_FAMILY2, ".uno:ParaStyle") + , m_pPreviewControl(pPreviewControl) +{ + ReBind(); +} + +void StyleStatusListener::StateChanged(SfxItemState /*eState*/, const SfxPoolItem* pState) +{ + const SfxTemplateItem* pStateItem = dynamic_cast<const SfxTemplateItem*>(pState); + m_pPreviewControl->Select(pStateItem->GetStyleName()); +} + +StyleItemController::StyleItemController( + const OUString& aStyleName, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) + : m_eStyleFamily(SfxStyleFamily::Para) + , m_aStyleName(aStyleName) + , m_bSelected(false) + , m_xDispatchProvider(xDispatchProvider) +{ +} + +void StyleItemController::Paint(vcl::RenderContext& rRenderContext, + const tools::Rectangle& /*rRect*/) +{ + rRenderContext.Push(PushFlags::FILLCOLOR | PushFlags::FONT | PushFlags::TEXTCOLOR); + + DrawEntry(rRenderContext); + + rRenderContext.Pop(); +} + +void StyleItemController::SetStyle(const OUString& sStyleName) +{ + m_aStyleName = sStyleName; + Invalidate(); +} + +void StyleItemController::Select(bool bSelect) +{ + m_bSelected = bSelect; + Invalidate(); +} + +bool StyleItemController::MouseButtonDown(const MouseEvent&) +{ + css::uno::Sequence<css::beans::PropertyValue> aArgs(2); + aArgs[0].Value <<= m_aStyleName; + aArgs[1].Name = "Family"; + aArgs[1].Value <<= sal_Int16(m_eStyleFamily); + + aArgs[0].Name = "Template"; + SfxToolBoxControl::Dispatch(m_xDispatchProvider, ".uno:StyleApply", aArgs); + + return false; +} + +static Color GetTextColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet) +{ + const SfxPoolItem* pItem = pItemSet->GetItem(SID_ATTR_CHAR_COLOR); + if (pItem) + return static_cast<const SvxColorItem*>(pItem)->GetValue(); + + return COL_AUTO; +} + +static Color GetHighlightColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet) +{ + const SfxPoolItem* pItem = pItemSet->GetItem(SID_ATTR_BRUSH_CHAR); + if (pItem) + return static_cast<const SvxBrushItem*>(pItem)->GetColor(); + + return COL_AUTO; +} + +static Color GetBackgroundColorFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet) +{ + const SfxPoolItem* pItem = pItemSet->GetItem(XATTR_FILLCOLOR); + if (pItem) + return static_cast<const XFillColorItem*>(pItem)->GetColorValue(); + + return COL_AUTO; +} + +static css::drawing::FillStyle +GetFillStyleFromItemSet(std::unique_ptr<const SfxItemSet> const& pItemSet) +{ + const SfxPoolItem* pItem = pItemSet->GetItem(XATTR_FILLSTYLE); + if (pItem) + return static_cast<const XFillStyleItem*>(pItem)->GetValue(); + + return css::drawing::FillStyle_NONE; +} + +static SvxFont GetFontFromItems(const SvxFontItem* pFontItem, Size aPixelFontSize, + std::unique_ptr<const SfxItemSet> const& pItemSet) +{ + SvxFont aFont; + + aFont.SetFamilyName(pFontItem->GetFamilyName()); + aFont.SetStyleName(pFontItem->GetStyleName()); + aFont.SetFontSize(aPixelFontSize); + + const SfxPoolItem* pItem = pItemSet->GetItem(SID_ATTR_CHAR_WEIGHT); + if (pItem) + aFont.SetWeight(static_cast<const SvxWeightItem*>(pItem)->GetWeight()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_POSTURE); + if (pItem) + aFont.SetItalic(static_cast<const SvxPostureItem*>(pItem)->GetPosture()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_CONTOUR); + if (pItem) + aFont.SetOutline(static_cast<const SvxContourItem*>(pItem)->GetValue()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_SHADOWED); + if (pItem) + aFont.SetShadow(static_cast<const SvxShadowedItem*>(pItem)->GetValue()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_RELIEF); + if (pItem) + aFont.SetRelief(static_cast<const SvxCharReliefItem*>(pItem)->GetValue()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_UNDERLINE); + if (pItem) + aFont.SetUnderline(static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_OVERLINE); + if (pItem) + aFont.SetOverline(static_cast<const SvxOverlineItem*>(pItem)->GetValue()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_STRIKEOUT); + if (pItem) + aFont.SetStrikeout(static_cast<const SvxCrossedOutItem*>(pItem)->GetStrikeout()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_CASEMAP); + if (pItem) + aFont.SetCaseMap(static_cast<const SvxCaseMapItem*>(pItem)->GetCaseMap()); + + pItem = pItemSet->GetItem(SID_ATTR_CHAR_EMPHASISMARK); + if (pItem) + aFont.SetEmphasisMark(static_cast<const SvxEmphasisMarkItem*>(pItem)->GetEmphasisMark()); + + return aFont; +} + +void StyleItemController::DrawEntry(vcl::RenderContext& rRenderContext) +{ + SfxObjectShell* pShell = SfxObjectShell::Current(); + SfxStyleSheetBasePool* pPool = pShell->GetStyleSheetPool(); + SfxStyleSheetBase* pStyle = nullptr; + + if (pPool) + { + pPool->SetSearchMask(m_eStyleFamily); + pStyle = pPool->First(); + while (pStyle && pStyle->GetName() != m_aStyleName) + pStyle = pPool->Next(); + + if (!pStyle) + return; + + Size aSize(rRenderContext.GetOutputSizePixel()); + tools::Rectangle aFullRect(Point(0, 0), aSize); + aSize = Size(aSize.getWidth() - 6, aSize.getHeight() - 6); + tools::Rectangle aContentRect(aFullRect); + + Color aOriginalColor = rRenderContext.GetFillColor(); + Color aOriginalLineColor = rRenderContext.GetLineColor(); + vcl::Region aOriginalClipRegion(aFullRect); + + if (m_bSelected) + { + aContentRect = tools::Rectangle(Point(3, 3), aSize); + DrawSelection(rRenderContext); + } + + DrawContentBackground(rRenderContext, aContentRect, aOriginalColor); + + vcl::Region aClipRegion(aContentRect); + rRenderContext.SetClipRegion(aClipRegion); + + std::unique_ptr<const SfxItemSet> const pItemSet(pStyle->GetItemSetForPreview()); + if (!pItemSet) + return; + + Color aFontHighlight = COL_AUTO; + + const SvxFontItem* const pFontItem = pItemSet->GetItem<SvxFontItem>(SID_ATTR_CHAR_FONT); + const SvxFontHeightItem* const pFontHeightItem + = pItemSet->GetItem<SvxFontHeightItem>(SID_ATTR_CHAR_FONTHEIGHT); + + if (pFontItem && pFontHeightItem) + { + Size aFontSize(0, pFontHeightItem->GetHeight()); + Size aPixelSize(rRenderContext.LogicToPixel(aFontSize, MapMode(pShell->GetMapUnit()))); + + SvxFont aFont = GetFontFromItems(pFontItem, aPixelSize, pItemSet); + rRenderContext.SetFont(aFont); + + Color aFontCol = GetTextColorFromItemSet(pItemSet); + if (aFontCol != COL_AUTO) + rRenderContext.SetTextColor(aFontCol); + + aFontHighlight = GetHighlightColorFromItemSet(pItemSet); + + css::drawing::FillStyle style = GetFillStyleFromItemSet(pItemSet); + + switch (style) + { + case css::drawing::FillStyle_SOLID: + { + Color aBackCol = GetBackgroundColorFromItemSet(pItemSet); + if (aBackCol != COL_AUTO) + DrawContentBackground(rRenderContext, aContentRect, aBackCol); + } + break; + + default: + break; + //TODO Draw the other background styles: gradient, hatching and bitmap + } + } + + if (aFontHighlight != COL_AUTO) + DrawHighlight(rRenderContext, aFontHighlight); + + DrawText(rRenderContext); + + rRenderContext.SetFillColor(aOriginalColor); + rRenderContext.SetLineColor(aOriginalLineColor); + rRenderContext.SetClipRegion(aOriginalClipRegion); + } +} + +void StyleItemController::DrawContentBackground(vcl::RenderContext& rRenderContext, + tools::Rectangle& aContentRect, Color& aColor) +{ + rRenderContext.SetLineColor(aColor); + rRenderContext.SetFillColor(aColor); + rRenderContext.DrawRect(aContentRect); +} + +void StyleItemController::DrawSelection(vcl::RenderContext& rRenderContext) +{ + Size aSize(rRenderContext.GetOutputSizePixel()); + tools::Rectangle aFullRect(Point(0, 0), aSize); + + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + + rRenderContext.SetLineColor(rStyleSettings.GetActiveBorderColor()); + rRenderContext.SetFillColor(rStyleSettings.GetActiveBorderColor()); + + rRenderContext.DrawRect(aFullRect); +} + +void StyleItemController::DrawHighlight(vcl::RenderContext& rRenderContext, Color aFontBack) +{ + tools::Rectangle aTextRect; + rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName); + + Size aSize = aTextRect.GetSize(); + aSize.AdjustHeight(aSize.getHeight()); + aTextRect.SetSize(aSize); + + Point aPos(0, 0); + aPos.AdjustX(LEFT_MARGIN); + aPos.AdjustY((rRenderContext.GetOutputHeightPixel() - aTextRect.Bottom()) / 2); + aTextRect.SetPos(aPos); + + rRenderContext.SetLineColor(aFontBack); + rRenderContext.SetFillColor(aFontBack); + + rRenderContext.DrawRect(aTextRect); +} + +void StyleItemController::DrawText(vcl::RenderContext& rRenderContext) +{ + tools::Rectangle aTextRect; + rRenderContext.GetTextBoundRect(aTextRect, m_aStyleName); + + Point aPos(0, 0); + aPos.AdjustX(LEFT_MARGIN); + aPos.AdjustY((rRenderContext.GetOutputHeightPixel() - aTextRect.Bottom()) / 2); + + rRenderContext.DrawText(aPos, m_aStyleName); +} + +StylesPreviewWindow_Base::StylesPreviewWindow_Base( + weld::Builder& xBuilder, std::vector<OUString>& aDefaultStyles, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) + : m_xUp(xBuilder.weld_toolbar("uptoolbar")) + , m_xDown(xBuilder.weld_toolbar("downtoolbar")) + , m_aDefaultStyles(aDefaultStyles) + , m_nStyleIterator(0) +{ + for (unsigned int i = 0; i < STYLES_COUNT; i++) + { + m_xStyleControllers[i].reset(new StyleItemController(aDefaultStyles[i], xDispatchProvider)); + + OUString sIdOUString = "style" + OUString::number(i + 1); + OString sId = OUStringToOString(sIdOUString, RTL_TEXTENCODING_ASCII_US); + + m_xStyleControllersWeld[i].reset( + new weld::CustomWeld(xBuilder, sId, *m_xStyleControllers[i])); + m_xStyleControllersWeld[i]->set_size_request(100, 60); + } + + m_xUp->connect_clicked(LINK(this, StylesPreviewWindow_Base, GoUp)); + m_xDown->connect_clicked(LINK(this, StylesPreviewWindow_Base, GoDown)); + + m_pStatusListener = new StyleStatusListener(this, xDispatchProvider); + m_xStatusListener.set(static_cast<cppu::OWeakObject*>(m_pStatusListener), css::uno::UNO_QUERY); +} + +StylesPreviewWindow_Base::~StylesPreviewWindow_Base() +{ + m_pStatusListener->UnBind(); + + try + { + m_xStatusListener->dispose(); + } + catch (css::uno::Exception&) + { + } + + m_pStatusListener = nullptr; +} + +OUString StylesPreviewWindow_Base::GetVisibleStyle(unsigned nPosition) +{ + if (nPosition < 0 || nPosition >= STYLES_COUNT || !m_aAllStyles.size()) + return ""; + + return m_aAllStyles[(m_nStyleIterator + nPosition) % m_aAllStyles.size()]; +} + +void StylesPreviewWindow_Base::Select(const OUString& rStyleName) +{ + m_sSelectedStyle = rStyleName; + + UpdateStylesList(); + MakeCurrentStyleVisible(); + Update(); +} + +void StylesPreviewWindow_Base::MakeCurrentStyleVisible() +{ + if (m_aAllStyles.size()) + { + unsigned nNewIterator = m_nStyleIterator; + auto aFound = std::find(m_aAllStyles.begin(), m_aAllStyles.end(), m_sSelectedStyle); + if (aFound != m_aAllStyles.end()) + nNewIterator = aFound - m_aAllStyles.begin(); + + bool bIsAlreadyVisible + = nNewIterator >= m_nStyleIterator % m_aAllStyles.size() + && nNewIterator < m_nStyleIterator % m_aAllStyles.size() + STYLES_COUNT; + if (!bIsAlreadyVisible) + m_nStyleIterator = nNewIterator; + } +} + +void StylesPreviewWindow_Base::Update() +{ + UpdateStylesList(); + + for (unsigned int i = 0; i < STYLES_COUNT; i++) + { + OUString sStyleName = GetVisibleStyle(i); + m_xStyleControllers[i]->SetStyle(sStyleName); + m_xStyleControllersWeld[i]->set_tooltip_text(sStyleName); + + if (sStyleName == m_sSelectedStyle) + m_xStyleControllers[i]->Select(true); + else + m_xStyleControllers[i]->Select(false); + } +} + +void StylesPreviewWindow_Base::UpdateStylesList() +{ + m_aAllStyles = m_aDefaultStyles; + + SfxObjectShell* pDocShell = SfxObjectShell::Current(); + const SfxStyleFamily eFamily = SfxStyleFamily::Para; + SfxStyleSheetBasePool* pStyleSheetPool = nullptr; + + if (pDocShell) + pStyleSheetPool = pDocShell->GetStyleSheetPool(); + + if (pStyleSheetPool) + { + auto xIter = pStyleSheetPool->CreateIterator(eFamily, SfxStyleSearchBits::UserDefined); + + SfxStyleSheetBase* pStyle = xIter->First(); + + while (pStyle) + { + m_aAllStyles.push_back(pStyle->GetName()); + pStyle = xIter->Next(); + } + } +} + +IMPL_LINK(StylesPreviewWindow_Base, GoUp, const OString&, /*rItem*/, void) +{ + if (m_nStyleIterator == 0) + m_nStyleIterator = m_aAllStyles.size(); + else + m_nStyleIterator--; + + Update(); +} + +IMPL_LINK(StylesPreviewWindow_Base, GoDown, const OString&, /*rItem*/, void) +{ + m_nStyleIterator++; + Update(); +} + +StylesPreviewWindow_Impl::StylesPreviewWindow_Impl( + vcl::Window* pParent, std::vector<OUString>& aDefaultStyles, + css::uno::Reference<css::frame::XDispatchProvider>& xDispatchProvider) + : InterimItemWindow(pParent, "svx/ui/stylespreview.ui", "ApplyStyleBox") + , StylesPreviewWindow_Base(*m_xBuilder, aDefaultStyles, xDispatchProvider) +{ + SetOptimalSize(); +} + +StylesPreviewWindow_Impl::~StylesPreviewWindow_Impl() { disposeOnce(); } + +void StylesPreviewWindow_Impl::dispose() +{ + m_xUp.reset(); + m_xDown.reset(); + + for (unsigned int i = 0; i < STYLES_COUNT; i++) + m_xStyleControllersWeld[i].reset(); + + InterimItemWindow::dispose(); +} + +void StylesPreviewWindow_Impl::SetOptimalSize() { SetSizePixel(get_preferred_size()); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file diff --git a/svx/uiconfig/ui/stylespreview.ui b/svx/uiconfig/ui/stylespreview.ui new file mode 100644 index 000000000000..e714c31a3f37 --- /dev/null +++ b/svx/uiconfig/ui/stylespreview.ui @@ -0,0 +1,142 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.20.4 --> +<interface domain="svx"> + <requires lib="gtk+" version="3.18"/> + <object class="GtkBox" id="ApplyStyleBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="hexpand">True</property> + <property name="spacing">6</property> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">3</property> + <child> + <object class="GtkBox" id="stylescontainer"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="spacing">6</property> + <property name="homogeneous">True</property> + <child> + <object class="GtkDrawingArea" id="style1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkDrawingArea" id="style2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkDrawingArea" id="style3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkDrawingArea" id="style4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkBox"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkToolbar" id="uptoolbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="toolbar_style">icons</property> + <child> + <object class="GtkToolButton" id="up"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="stylespreview|up">Previous</property> + <property name="use_underline">True</property> + <property name="icon_name">cmd/lc_prevrecord.png</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkToolbar" id="downtoolbar"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="toolbar_style">icons</property> + <child> + <object class="GtkToolButton" id="down"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="stylespreview|down">Next</property> + <property name="use_underline">True</property> + <property name="icon_name">cmd/lc_nextrecord.png</property> + </object> + <packing> + <property name="expand">False</property> + <property name="homogeneous">True</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + </object> +</interface> diff --git a/svx/util/svxcore.component b/svx/util/svxcore.component index 50fedcc67feb..8e45cbe102ec 100644 --- a/svx/util/svxcore.component +++ b/svx/util/svxcore.component @@ -76,4 +76,8 @@ constructor="com_sun_star_comp_graphic_PrimitiveFactory2D_get_implementation"> <service name="com.sun.star.graphic.PrimitiveFactory2D"/> </implementation> + <implementation name="com.sun.star.comp.svx.StylesPreviewToolBoxControl" + constructor="com_sun_star_comp_svx_StylesPreviewToolBoxControl_get_implementation"> + <service name="com.sun.star.frame.ToolbarController"/> + </implementation> </component> commit 2c7cd737007311d81e3801f3ddb7f11362112f07 Author: Szymon Kłos <szymon.k...@collabora.com> AuthorDate: Thu May 28 11:01:34 2020 +0200 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:38 2020 +0200 gtk3: receive mouse events on drawing area Change-Id: Ibe447592995ac8359c8f8160fd9943b8784da213 diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index a2b60e1cb91b..ec47dd20ca6b 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -11046,6 +11046,8 @@ public: gtk_widget_set_has_tooltip(m_pWidget, true); g_object_set_data(G_OBJECT(m_pDrawingArea), "g-lo-GtkInstanceDrawingArea", this); m_xDevice->EnableRTL(get_direction()); + gtk_widget_add_events(m_pWidget, GDK_BUTTON_PRESS_MASK); + gtk_widget_add_events(m_pWidget, GDK_BUTTON_RELEASE_MASK); } AtkObject* GetAtkObject(AtkObject* pDefaultAccessible) commit 151911ffced654d49b3af1135111b00db4c680a6 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Dec 23 11:16:28 2019 +0000 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:38 2020 +0200 reorganize ToolbarUnoDispatcher to be useful for sidebar Change-Id: If129d4832f04758705e121bff88ea7d2e45bf96b Reviewed-on: https://gerrit.libreoffice.org/85755 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/sfx2/sidebar/ControllerFactory.hxx b/include/sfx2/sidebar/ControllerFactory.hxx index 4dfff756415d..09f28f92510e 100644 --- a/include/sfx2/sidebar/ControllerFactory.hxx +++ b/include/sfx2/sidebar/ControllerFactory.hxx @@ -29,6 +29,8 @@ namespace com::sun::star::frame { class XToolbarController; } class ToolBox; +namespace weld { class Toolbar; } + namespace sfx2 { namespace sidebar { /** Convenience class for the easy creation of toolbox controllers. @@ -45,6 +47,11 @@ public: const css::uno::Reference<css::awt::XWindow>& rxParentWindow, const sal_Int32 nItemWidth); + static css::uno::Reference<css::frame::XToolbarController> CreateToolBoxController( + weld::Toolbar& rToolbar, + const OUString& rsCommandName, + const css::uno::Reference<css::frame::XFrame>& rxFrame); + private: static css::uno::Reference<css::frame::XToolbarController> CreateToolBarController( ToolBox* pToolBox, diff --git a/include/sfx2/weldutils.hxx b/include/sfx2/weldutils.hxx new file mode 100644 index 000000000000..ccca8b393042 --- /dev/null +++ b/include/sfx2/weldutils.hxx @@ -0,0 +1,54 @@ +/* -*- 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/. + */ + +#ifndef INCLUDED_SFX2_WELDUTILS_HXX +#define INCLUDED_SFX2_WELDUTILS_HXX + +#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XToolbarController.hpp> + +#include <com/sun/star/uno/Reference.hxx> +#include <tools/link.hxx> +#include <sfx2/dllapi.h> + +#include <map> + +namespace weld +{ +class Toolbar; +} + +class SFX2_DLLPUBLIC ToolbarUnoDispatcher +{ +private: + css::uno::Reference<css::frame::XFrame> m_xFrame; + weld::Toolbar* m_pToolbar; + + DECL_LINK(SelectHdl, const OString&, void); + + void CreateController(const OUString& rCommand); + + typedef std::map<OUString, css::uno::Reference<css::frame::XToolbarController>> + ControllerContainer; + ControllerContainer maControllers; + + css::uno::Reference<css::frame::XToolbarController> + GetControllerForCommand(const OUString& rCommand) const; + +public: + // fill in the label and icons for actions and dispatch the action on item click + ToolbarUnoDispatcher(weld::Toolbar& rToolbar, + const css::uno::Reference<css::frame::XFrame>& rFrame); + void dispose(); + ~ToolbarUnoDispatcher(); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/svtools/generictoolboxcontroller.hxx b/include/svtools/generictoolboxcontroller.hxx index 6b9c11cc3924..ddf8dc06cee8 100644 --- a/include/svtools/generictoolboxcontroller.hxx +++ b/include/svtools/generictoolboxcontroller.hxx @@ -24,33 +24,46 @@ #include <svtools/toolboxcontroller.hxx> #include <vcl/toolbox.hxx> +namespace weld +{ + class Toolbar; +} + namespace svt { class SVT_DLLPUBLIC GenericToolboxController final : public svt::ToolboxController { - public: - GenericToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, - const css::uno::Reference< css::frame::XFrame >& rFrame, - ToolBox* pToolBox, - sal_uInt16 nID, - const OUString& aCommand ); - virtual ~GenericToolboxController() override; +public: + GenericToolboxController( const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XFrame >& rFrame, + ToolBox* pToolBox, + sal_uInt16 nID, + const OUString& aCommand ); + + GenericToolboxController(const css::uno::Reference< css::uno::XComponentContext >& rxContext, + const css::uno::Reference< css::frame::XFrame >& rFrame, + weld::Toolbar& rToolbar, + const OUString& rCommand); + + virtual ~GenericToolboxController() override; + + // XComponent + virtual void SAL_CALL dispose() override; - // XComponent - virtual void SAL_CALL dispose() override; + // XToolbarController + virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; - // XToolbarController - virtual void SAL_CALL execute( sal_Int16 KeyModifier ) override; + // XStatusListener + virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override; - // XStatusListener - virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override; + DECL_STATIC_LINK( GenericToolboxController, ExecuteHdl_Impl, void*, void ); - DECL_STATIC_LINK( GenericToolboxController, ExecuteHdl_Impl, void*, void ); +private: + VclPtr<ToolBox> m_xToolbox; + sal_uInt16 m_nID; - private: - VclPtr<ToolBox> m_pToolbox; - sal_uInt16 m_nID; + weld::Toolbar* m_pToolbox; }; } diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index 1d0499441345..a904269515ec 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -1933,12 +1933,18 @@ public: virtual bool get_item_active(const OString& rIdent) const = 0; virtual void set_item_menu(const OString& rIdent, weld::Menu* pMenu) = 0; virtual void set_item_popover(const OString& rIdent, weld::Widget* pPopover) = 0; + virtual void set_item_visible(const OString& rIdent, bool bVisible) = 0; + virtual bool get_item_visible(const OString& rIdent) const = 0; + virtual void set_item_label(const OString& rIdent, const OUString& rLabel) = 0; + virtual OUString get_item_label(const OString& rIdent) const = 0; + virtual void set_item_tooltip_text(const OString& rIdent, const OUString& rTip) = 0; virtual void insert_separator(int pos, const OUString& rId) = 0; void append_separator(const OUString& rId) { insert_separator(-1, rId); } virtual int get_n_items() const = 0; virtual OString get_item_ident(int nIndex) const = 0; + virtual void set_item_ident(int nIndex, const OString& rIdent) = 0; virtual void set_item_label(int nIndex, const OUString& rLabel) = 0; virtual void set_item_icon(int nIndex, const css::uno::Reference<css::graphic::XGraphic>& rIcon) = 0; diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index 4144803e8b3d..b145e060a9d5 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -10,24 +10,138 @@ #ifndef INCLUDED_VCL_WELDUTILS_HXX #define INCLUDED_VCL_WELDUTILS_HXX -#include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/awt/XWindow.hpp> #include <com/sun/star/uno/Reference.hxx> #include <tools/link.hxx> #include <vcl/dllapi.h> +#include <cppuhelper/compbase.hxx> +#include <comphelper/interfacecontainer2.hxx> namespace weld { -class Toolbar; +typedef cppu::WeakComponentImplHelper<css::awt::XWindow> TransportAsXWindow_Base; -class VCL_DLLPUBLIC ToolbarUnoDispatcher +class VCL_DLLPUBLIC TransportAsXWindow : public TransportAsXWindow_Base { private: - css::uno::Reference<css::frame::XFrame> m_xFrame; - DECL_LINK(SelectHdl, const OString&, void); + osl::Mutex m_aHelperMtx; + weld::Widget* m_pWeldWidget; + + comphelper::OInterfaceContainerHelper2 m_aWindowListeners; + comphelper::OInterfaceContainerHelper2 m_aKeyListeners; + comphelper::OInterfaceContainerHelper2 m_aFocusListeners; + comphelper::OInterfaceContainerHelper2 m_aMouseListeners; + comphelper::OInterfaceContainerHelper2 m_aMotionListeners; + comphelper::OInterfaceContainerHelper2 m_aPaintListeners; public: - // fill in the label and icons for actions and dispatch the action on item click - ToolbarUnoDispatcher(Toolbar& rToolbar, const css::uno::Reference<css::frame::XFrame>& rFrame); + TransportAsXWindow(weld::Widget* pWeldWidget) + : TransportAsXWindow_Base(m_aHelperMtx) + , m_pWeldWidget(pWeldWidget) + , m_aWindowListeners(m_aHelperMtx) + , m_aKeyListeners(m_aHelperMtx) + , m_aFocusListeners(m_aHelperMtx) + , m_aMouseListeners(m_aHelperMtx) + , m_aMotionListeners(m_aHelperMtx) + , m_aPaintListeners(m_aHelperMtx) + { + } + + weld::Widget* getWidget() const { return m_pWeldWidget; } + + virtual void clear() { m_pWeldWidget = nullptr; } + + // css::awt::XWindow + void SAL_CALL setPosSize(sal_Int32, sal_Int32, sal_Int32, sal_Int32, sal_Int16) override + { + throw css::uno::RuntimeException("not implemented"); + } + + css::awt::Rectangle SAL_CALL getPosSize() override + { + throw css::uno::RuntimeException("not implemented"); + } + + void SAL_CALL setVisible(sal_Bool bVisible) override { m_pWeldWidget->set_visible(bVisible); } + + void SAL_CALL setEnable(sal_Bool bSensitive) override + { + m_pWeldWidget->set_sensitive(bSensitive); + } + + void SAL_CALL setFocus() override { m_pWeldWidget->grab_focus(); } + + void SAL_CALL + addWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override + { + m_aWindowListeners.addInterface(rListener); + } + + void SAL_CALL + removeWindowListener(const css::uno::Reference<css::awt::XWindowListener>& rListener) override + { + m_aWindowListeners.removeInterface(rListener); + } + + void SAL_CALL + addFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override + { + m_aFocusListeners.addInterface(rListener); + } + + void SAL_CALL + removeFocusListener(const css::uno::Reference<css::awt::XFocusListener>& rListener) override + { + m_aFocusListeners.removeInterface(rListener); + } + + void SAL_CALL + addKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override + { + m_aKeyListeners.addInterface(rListener); + } + + void SAL_CALL + removeKeyListener(const css::uno::Reference<css::awt::XKeyListener>& rListener) override + { + m_aKeyListeners.removeInterface(rListener); + } + + void SAL_CALL + addMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override + { + m_aMouseListeners.addInterface(rListener); + } + + void SAL_CALL + removeMouseListener(const css::uno::Reference<css::awt::XMouseListener>& rListener) override + { + m_aMouseListeners.removeInterface(rListener); + } + + void SAL_CALL addMouseMotionListener( + const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override + { + m_aMotionListeners.addInterface(rListener); + } + + void SAL_CALL removeMouseMotionListener( + const css::uno::Reference<css::awt::XMouseMotionListener>& rListener) override + { + m_aMotionListeners.removeInterface(rListener); + } + + void SAL_CALL + addPaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override + { + m_aPaintListeners.addInterface(rListener); + } + + void SAL_CALL + removePaintListener(const css::uno::Reference<css::awt::XPaintListener>& rListener) override + { + m_aPaintListeners.removeInterface(rListener); + } }; } diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 8f386caaa283..cc2386fe5f82 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -291,6 +291,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/statbar/stbitem \ sfx2/source/styles/StyleManager \ sfx2/source/toolbox/tbxitem \ + sfx2/source/toolbox/weldutils \ sfx2/source/view/classificationcontroller \ sfx2/source/view/classificationhelper \ sfx2/source/view/frame \ diff --git a/sfx2/source/dialog/recfloat.cxx b/sfx2/source/dialog/recfloat.cxx index b431cc619298..471d611f745c 100644 --- a/sfx2/source/dialog/recfloat.cxx +++ b/sfx2/source/dialog/recfloat.cxx @@ -99,7 +99,7 @@ SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings* pBind, SfxChildWindo : SfxModelessDialogController(pBind, pChildWin, pParent, "sfx/ui/floatingrecord.ui", "FloatingRecord") , m_xToolbar(m_xBuilder->weld_toolbar("toolbar")) - , m_aDispatcher(*m_xToolbar, pBind->GetActiveFrame()) + , m_xDispatcher(new ToolbarUnoDispatcher(*m_xToolbar, pBind->GetActiveFrame())) { // start recording SfxBoolItem aItem( SID_RECORDMACRO, true ); @@ -109,6 +109,7 @@ SfxRecordingFloat_Impl::SfxRecordingFloat_Impl(SfxBindings* pBind, SfxChildWindo SfxRecordingFloat_Impl::~SfxRecordingFloat_Impl() { + m_xDispatcher->dispose(); } void SfxRecordingFloat_Impl::FillInfo( SfxChildWinInfo& rInfo ) const diff --git a/sfx2/source/inc/recfloat.hxx b/sfx2/source/inc/recfloat.hxx index e9d2dd7eb97e..b7aa71668491 100644 --- a/sfx2/source/inc/recfloat.hxx +++ b/sfx2/source/inc/recfloat.hxx @@ -20,9 +20,9 @@ #ifndef INCLUDED_SFX2_SOURCE_INC_RECFLOAT_HXX #define INCLUDED_SFX2_SOURCE_INC_RECFLOAT_HXX -#include <sfx2/childwin.hxx> #include <sfx2/basedlgs.hxx> -#include <vcl/weldutils.hxx> +#include <sfx2/childwin.hxx> +#include <sfx2/weldutils.hxx> class SfxRecordingFloatWrapper_Impl : public SfxChildWindow { @@ -41,7 +41,7 @@ public: class SfxRecordingFloat_Impl : public SfxModelessDialogController { std::unique_ptr<weld::Toolbar> m_xToolbar; - weld::ToolbarUnoDispatcher m_aDispatcher; + std::unique_ptr<ToolbarUnoDispatcher> m_xDispatcher; public: SfxRecordingFloat_Impl(SfxBindings* pBindings, SfxChildWindow* pChildWin, diff --git a/sfx2/source/sidebar/ControllerFactory.cxx b/sfx2/source/sidebar/ControllerFactory.cxx index 643d364bb266..edb29abd5280 100644 --- a/sfx2/source/sidebar/ControllerFactory.cxx +++ b/sfx2/source/sidebar/ControllerFactory.cxx @@ -137,6 +137,55 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( return xController; } +Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( + weld::Toolbar& rToolbar, + const OUString& rsCommandName, + const Reference<frame::XFrame>& rxFrame) +{ + Reference<frame::XToolbarController> xController; + + xController.set( + static_cast<XWeak*>(new svt::GenericToolboxController( + ::comphelper::getProcessComponentContext(), + rxFrame, + rToolbar, + rsCommandName)), + UNO_QUERY); + + // Initialize the controller with eg a service factory. + Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY); + if (/*!bFactoryHasController &&*/ xInitialization.is()) + { + beans::PropertyValue aPropValue; + std::vector<Any> aPropertyVector; + + aPropValue.Name = "Frame"; + aPropValue.Value <<= rxFrame; + aPropertyVector.push_back(makeAny(aPropValue)); + + aPropValue.Name = "ServiceManager"; + aPropValue.Value <<= ::comphelper::getProcessServiceFactory(); + aPropertyVector.push_back(makeAny(aPropValue)); + + aPropValue.Name = "CommandURL"; + aPropValue.Value <<= rsCommandName; + aPropertyVector.push_back(makeAny(aPropValue)); + + Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); + xInitialization->initialize(aArgs); + } + + if (xController.is()) + { + Reference<util::XUpdatable> xUpdatable(xController, UNO_QUERY); + if (xUpdatable.is()) + xUpdatable->update(); + } + + return xController; +} + + Reference<frame::XToolbarController> ControllerFactory::CreateToolBarController( ToolBox* pToolBox, const OUString& rsCommandName, diff --git a/sfx2/source/toolbox/weldutils.cxx b/sfx2/source/toolbox/weldutils.cxx new file mode 100644 index 000000000000..3f2d0970cc6e --- /dev/null +++ b/sfx2/source/toolbox/weldutils.cxx @@ -0,0 +1,135 @@ +/* -*- 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 <comphelper/dispatchcommand.hxx> +#include <sfx2/sidebar/ControllerFactory.hxx> +#include <sfx2/weldutils.hxx> +#include <vcl/commandinfoprovider.hxx> +#include <vcl/settings.hxx> +#include <vcl/weld.hxx> + +namespace +{ +bool lcl_RTLizeCommandURL(OUString& rCommandURL) +{ + if (rCommandURL == ".uno:ParaLeftToRight") + { + rCommandURL = ".uno:ParaRightToLeft"; + return true; + } + if (rCommandURL == ".uno:ParaRightToLeft") + { + rCommandURL = ".uno:ParaLeftToRight"; + return true; + } + if (rCommandURL == ".uno:LeftPara") + { + rCommandURL = ".uno:RightPara"; + return true; + } + if (rCommandURL == ".uno:RightPara") + { + rCommandURL = ".uno:LeftPara"; + return true; + } + if (rCommandURL == ".uno:AlignLeft") + { + rCommandURL = ".uno:AlignRight"; + return true; + } + if (rCommandURL == ".uno:AlignRight") + { + rCommandURL = ".uno:AlignLeft"; + return true; + } + return false; +} +} + +ToolbarUnoDispatcher::ToolbarUnoDispatcher(weld::Toolbar& rToolbar, + const css::uno::Reference<css::frame::XFrame>& rFrame) + : m_xFrame(rFrame) + , m_pToolbar(&rToolbar) +{ + OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame)); + vcl::ImageType eSize = rToolbar.get_icon_size(); + + bool bRTL = AllSettings::GetLayoutRTL(); + + for (int i = 0, nItems = rToolbar.get_n_items(); i < nItems; ++i) + { + OUString sCommand = OUString::fromUtf8(rToolbar.get_item_ident(i)); + if (bRTL && lcl_RTLizeCommandURL(sCommand)) + rToolbar.set_item_ident(i, sCommand.toUtf8()); + + auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sCommand, aModuleName); + OUString aLabel(vcl::CommandInfoProvider::GetLabelForCommand(aProperties)); + rToolbar.set_item_label(i, aLabel); + OUString aTooltip( + vcl::CommandInfoProvider::GetTooltipForCommand(sCommand, aProperties, rFrame)); + rToolbar.set_item_tooltip_text(i, aTooltip); + auto xImage(vcl::CommandInfoProvider::GetXGraphicForCommand(sCommand, rFrame, eSize)); + rToolbar.set_item_icon(i, xImage); + + CreateController(sCommand); + } + + rToolbar.connect_clicked(LINK(this, ToolbarUnoDispatcher, SelectHdl)); +} + +void ToolbarUnoDispatcher::CreateController(const OUString& rCommand) +{ + css::uno::Reference<css::frame::XToolbarController> xController( + sfx2::sidebar::ControllerFactory::CreateToolBoxController(*m_pToolbar, rCommand, m_xFrame)); + + if (xController.is()) + maControllers.insert(std::make_pair(rCommand, xController)); +} + +css::uno::Reference<css::frame::XToolbarController> +ToolbarUnoDispatcher::GetControllerForCommand(const OUString& rCommand) const +{ + ControllerContainer::const_iterator iController(maControllers.find(rCommand)); + if (iController != maControllers.end()) + return iController->second; + + return css::uno::Reference<css::frame::XToolbarController>(); +} + +IMPL_LINK(ToolbarUnoDispatcher, SelectHdl, const OString&, rCommand, void) +{ + css::uno::Reference<css::frame::XToolbarController> xController( + GetControllerForCommand(OUString::fromUtf8(rCommand))); + + if (xController.is()) + xController->execute(0); +} + +void ToolbarUnoDispatcher::dispose() +{ + if (!m_pToolbar) + return; + + ControllerContainer aControllers; + aControllers.swap(maControllers); + for (auto const& controller : aControllers) + { + css::uno::Reference<css::lang::XComponent> xComponent(controller.second, + css::uno::UNO_QUERY); + if (xComponent.is()) + xComponent->dispose(); + } + + m_pToolbar->connect_clicked(Link<const OString&, void>()); + m_pToolbar = nullptr; +} + +ToolbarUnoDispatcher::~ToolbarUnoDispatcher() { dispose(); } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svtools/source/uno/generictoolboxcontroller.cxx b/svtools/source/uno/generictoolboxcontroller.cxx index f5a8d470b7b1..545d683f1f0d 100644 --- a/svtools/source/uno/generictoolboxcontroller.cxx +++ b/svtools/source/uno/generictoolboxcontroller.cxx @@ -26,6 +26,7 @@ #include <com/sun/star/frame/XDispatch.hpp> #include <vcl/svapp.hxx> +#include <vcl/weld.hxx> using namespace css::awt; using namespace css::uno; @@ -49,10 +50,28 @@ GenericToolboxController::GenericToolboxController( const Reference< XComponentC const Reference< XFrame >& rFrame, ToolBox* pToolbox, sal_uInt16 nID, - const OUString& aCommand ) : - svt::ToolboxController( rxContext, rFrame, aCommand ) - , m_pToolbox( pToolbox ) - , m_nID( nID ) + const OUString& aCommand ) + : svt::ToolboxController( rxContext, rFrame, aCommand ) + , m_xToolbox( pToolbox ) + , m_nID( nID ) + , m_pToolbox(nullptr) +{ + // Initialization is done through ctor + m_bInitialized = true; + + // insert main command to our listener map + if ( !m_aCommandURL.isEmpty() ) + m_aListenerMap.emplace( aCommand, Reference< XDispatch >() ); +} + +GenericToolboxController::GenericToolboxController( const Reference< XComponentContext >& rxContext, + const Reference< XFrame >& rFrame, + weld::Toolbar& rToolbar, + const OUString& aCommand ) + : svt::ToolboxController( rxContext, rFrame, aCommand ) + , m_xToolbox( nullptr ) + , m_nID( 0 ) + , m_pToolbox(&rToolbar) { // Initialization is done through ctor m_bInitialized = true; @@ -69,8 +88,9 @@ GenericToolboxController::~GenericToolboxController() void SAL_CALL GenericToolboxController::dispose() { SolarMutexGuard aSolarMutexGuard; - m_pToolbox.clear(); + m_xToolbox.clear(); m_nID = 0; + m_pToolbox = nullptr; svt::ToolboxController::dispose(); } @@ -121,40 +141,60 @@ void GenericToolboxController::statusChanged( const FeatureStateEvent& Event ) if ( m_bDisposed ) return; - if ( !m_pToolbox ) - return; + if (m_xToolbox) + { + m_xToolbox->EnableItem( m_nID, Event.IsEnabled ); - m_pToolbox->EnableItem( m_nID, Event.IsEnabled ); + ToolBoxItemBits nItemBits = m_xToolbox->GetItemBits( m_nID ); + nItemBits &= ~ToolBoxItemBits::CHECKABLE; + TriState eTri = TRISTATE_FALSE; - ToolBoxItemBits nItemBits = m_pToolbox->GetItemBits( m_nID ); - nItemBits &= ~ToolBoxItemBits::CHECKABLE; - TriState eTri = TRISTATE_FALSE; + bool bValue; + OUString aStrValue; + ItemStatus aItemState; - bool bValue; - OUString aStrValue; - ItemStatus aItemState; + if ( Event.State >>= bValue ) + { + // Boolean, treat it as checked/unchecked + m_xToolbox->SetItemBits( m_nID, nItemBits ); + m_xToolbox->CheckItem( m_nID, bValue ); + if ( bValue ) + eTri = TRISTATE_TRUE; + nItemBits |= ToolBoxItemBits::CHECKABLE; + } + else if ( Event.State >>= aStrValue ) + { + m_xToolbox->SetItemText( m_nID, aStrValue ); + } + else if ( Event.State >>= aItemState ) + { + eTri = TRISTATE_INDET; + nItemBits |= ToolBoxItemBits::CHECKABLE; + } - if ( Event.State >>= bValue ) - { - // Boolean, treat it as checked/unchecked - m_pToolbox->SetItemBits( m_nID, nItemBits ); - m_pToolbox->CheckItem( m_nID, bValue ); - if ( bValue ) - eTri = TRISTATE_TRUE; - nItemBits |= ToolBoxItemBits::CHECKABLE; + m_xToolbox->SetItemState( m_nID, eTri ); + m_xToolbox->SetItemBits( m_nID, nItemBits ); } - else if ( Event.State >>= aStrValue ) - { - m_pToolbox->SetItemText( m_nID, aStrValue ); - } - else if ( Event.State >>= aItemState ) + + if (m_pToolbox) { - eTri = TRISTATE_INDET; - nItemBits |= ToolBoxItemBits::CHECKABLE; - } + OString sId = m_aCommandURL.toUtf8(); - m_pToolbox->SetItemState( m_nID, eTri ); - m_pToolbox->SetItemBits( m_nID, nItemBits ); + m_pToolbox->set_item_sensitive(sId, Event.IsEnabled); + + bool bValue; + OUString aStrValue; + + if ( Event.State >>= bValue ) + { + // Boolean, treat it as checked/unchecked + m_pToolbox->set_item_active( sId, bValue ); + } + else if ( Event.State >>= aStrValue ) + { + m_pToolbox->set_item_label( sId, aStrValue ); + } + } } IMPL_STATIC_LINK( GenericToolboxController, ExecuteHdl_Impl, void*, p, void ) diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 167f81d36aca..e2cad9d7592a 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -946,6 +946,16 @@ public: return m_xToolBox->IsItemEnabled(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent))); } + virtual void set_item_visible(const OString& rIdent, bool bVisible) override + { + m_xToolBox->ShowItem(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)), bVisible); + } + + virtual bool get_item_visible(const OString& rIdent) const override + { + return m_xToolBox->IsItemVisible(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent))); + } + virtual void set_item_active(const OString& rIdent, bool bActive) override { sal_uInt16 nItemId = m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)); @@ -1020,11 +1030,26 @@ public: return m_xToolBox->GetItemCommand(m_xToolBox->GetItemId(nIndex)).toUtf8(); } + virtual void set_item_ident(int nIndex, const OString& rIdent) override + { + return m_xToolBox->SetItemCommand(m_xToolBox->GetItemId(nIndex), OUString::fromUtf8(rIdent)); + } + virtual void set_item_label(int nIndex, const OUString& rLabel) override { m_xToolBox->SetItemText(m_xToolBox->GetItemId(nIndex), rLabel); } + virtual OUString get_item_label(const OString& rIdent) const override + { + return m_xToolBox->GetItemText(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent))); + } + + virtual void set_item_label(const OString& rIdent, const OUString& rLabel) override + { + m_xToolBox->SetItemText(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)), rLabel); + } + virtual void set_item_icon(int nIndex, const css::uno::Reference<css::graphic::XGraphic>& rIcon) override { m_xToolBox->SetItemImage(m_xToolBox->GetItemId(nIndex), Image(rIcon)); @@ -1035,6 +1060,11 @@ public: m_xToolBox->SetQuickHelpText(m_xToolBox->GetItemId(nIndex), rTip); } + virtual void set_item_tooltip_text(const OString& rIdent, const OUString& rTip) override + { + m_xToolBox->SetQuickHelpText(m_xToolBox->GetItemId(OUString::fromUtf8(rIdent)), rTip); + } + virtual vcl::ImageType get_icon_size() const override { return m_xToolBox->GetImageSize(); diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index 3d8f78392671..d1d013cb4568 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -7,9 +7,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#include <comphelper/dispatchcommand.hxx> #include <vcl/builderpage.hxx> #include <vcl/commandinfoprovider.hxx> +#include <vcl/settings.hxx> #include <vcl/svapp.hxx> #include <vcl/weldutils.hxx> @@ -105,36 +105,6 @@ void TriStateEnabled::ButtonToggled(weld::ToggleButton& rToggle) } eState = rToggle.get_state(); } - -ToolbarUnoDispatcher::ToolbarUnoDispatcher(Toolbar& rToolbar, - const css::uno::Reference<css::frame::XFrame>& rFrame) - : m_xFrame(rFrame) -{ - OUString aModuleName(vcl::CommandInfoProvider::GetModuleIdentifier(rFrame)); - vcl::ImageType eSize = rToolbar.get_icon_size(); - - for (int i = 0, nItems = rToolbar.get_n_items(); i < nItems; ++i) - { - OUString sCommand = OUString::fromUtf8(rToolbar.get_item_ident(i)); - - auto aProperties = vcl::CommandInfoProvider::GetCommandProperties(sCommand, aModuleName); - OUString aLabel(vcl::CommandInfoProvider::GetLabelForCommand(aProperties)); - rToolbar.set_item_label(i, aLabel); - OUString aTooltip( - vcl::CommandInfoProvider::GetTooltipForCommand(sCommand, aProperties, rFrame)); - rToolbar.set_item_tooltip_text(i, aTooltip); - auto xImage(vcl::CommandInfoProvider::GetXGraphicForCommand(sCommand, rFrame, eSize)); - rToolbar.set_item_icon(i, xImage); - } - - rToolbar.connect_clicked(LINK(this, ToolbarUnoDispatcher, SelectHdl)); -} - -IMPL_LINK(ToolbarUnoDispatcher, SelectHdl, const OString&, rCommand, void) -{ - comphelper::dispatchCommand(OUString::fromUtf8(rCommand), m_xFrame, - css::uno::Sequence<css::beans::PropertyValue>()); -} } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index d857c07cd950..a2b60e1cb91b 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -7082,6 +7082,18 @@ public: return gtk_widget_get_sensitive(GTK_WIDGET(m_aMap.find(rIdent)->second)); } + virtual void set_item_visible(const OString& rIdent, bool bVisible) override + { + disable_item_notify_events(); + gtk_widget_set_visible(GTK_WIDGET(m_aMap[rIdent]), bVisible); + enable_item_notify_events(); + } + + virtual bool get_item_visible(const OString& rIdent) const override + { + return gtk_widget_get_visible(GTK_WIDGET(m_aMap.find(rIdent)->second)); + } + virtual void set_item_active(const OString& rIdent, bool bActive) override { disable_item_notify_events(); @@ -7138,12 +7150,30 @@ public: return OString(pStr, pStr ? strlen(pStr) : 0); } + virtual void set_item_ident(int nIndex, const OString& rIdent) override + { + GtkToolItem* pItem = gtk_toolbar_get_nth_item(m_pToolbar, nIndex); + gtk_buildable_set_name(GTK_BUILDABLE(pItem), rIdent.getStr()); + } + virtual void set_item_label(int nIndex, const OUString& rLabel) override { GtkToolItem* pItem = gtk_toolbar_get_nth_item(m_pToolbar, nIndex); gtk_tool_button_set_label(GTK_TOOL_BUTTON(pItem), MapToGtkAccelerator(rLabel).getStr()); } + virtual void set_item_label(const OString& rIdent, const OUString& rLabel) override + { + GtkToolButton* pItem = m_aMap[rIdent]; + gtk_tool_button_set_label(GTK_TOOL_BUTTON(pItem), MapToGtkAccelerator(rLabel).getStr()); + } + + OUString get_item_label(const OString& rIdent) const override + { + const gchar* pText = gtk_tool_button_get_label(m_aMap.find(rIdent)->second); + return OUString(pText, pText ? strlen(pText) : 0, RTL_TEXTENCODING_UTF8); + } + virtual void set_item_icon(int nIndex, const css::uno::Reference<css::graphic::XGraphic>& rIcon) override { GtkToolItem* pItem = gtk_toolbar_get_nth_item(m_pToolbar, nIndex); @@ -7166,6 +7196,12 @@ public: gtk_widget_set_tooltip_text(GTK_WIDGET(pItem), OUStringToOString(rTip, RTL_TEXTENCODING_UTF8).getStr()); } + virtual void set_item_tooltip_text(const OString& rIdent, const OUString& rTip) override + { + GtkToolButton* pItem = m_aMap[rIdent]; + gtk_widget_set_tooltip_text(GTK_WIDGET(pItem), OUStringToOString(rTip, RTL_TEXTENCODING_UTF8).getStr()); + } + virtual vcl::ImageType get_icon_size() const override { return GtkToVcl(gtk_toolbar_get_icon_size(m_pToolbar)); commit d455add0c642d4426bf1593f9fe5203eca8f8c7c Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu May 21 16:43:40 2020 +0100 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:38 2020 +0200 move InterimItemWindow to vcl Change-Id: If0a4a14708810c44d087b51961f2ecb3fda4df23 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/94649 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/extensions/source/bibliography/toolbar.hxx b/extensions/source/bibliography/toolbar.hxx index 810445e85c7e..8ebec283431a 100644 --- a/extensions/source/bibliography/toolbar.hxx +++ b/extensions/source/bibliography/toolbar.hxx @@ -23,7 +23,6 @@ #include <com/sun/star/frame/XController.hpp> #include <com/sun/star/frame/XStatusListener.hpp> - #include <vcl/toolbox.hxx> #include <vcl/lstbox.hxx> #include <vcl/edit.hxx> diff --git a/framework/source/uielement/edittoolbarcontroller.cxx b/framework/source/uielement/edittoolbarcontroller.cxx index c095ef746010..78bbda07c00e 100644 --- a/framework/source/uielement/edittoolbarcontroller.cxx +++ b/framework/source/uielement/edittoolbarcontroller.cxx @@ -21,7 +21,6 @@ #include <com/sun/star/util/XURLTransformer.hpp> #include <com/sun/star/beans/PropertyValue.hpp> - #include <svtools/toolboxcontroller.hxx> #include <vcl/svapp.hxx> #include <vcl/mnemonic.hxx> diff --git a/include/svx/labelitemwindow.hxx b/include/svx/labelitemwindow.hxx new file mode 100644 index 000000000000..5271482b11ad --- /dev/null +++ b/include/svx/labelitemwindow.hxx @@ -0,0 +1,30 @@ +/* -*- 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/. + */ + +#pragma once + +#include <vcl/InterimItemWindow.hxx> +#include <svx/svxdllapi.h> + +class SVXCORE_DLLPUBLIC LabelItemWindow final : public InterimItemWindow +{ +private: + std::unique_ptr<weld::Label> m_xLabel; + +public: + LabelItemWindow(vcl::Window* pParent, const OUString& rLabel); + void set_label(const OUString& rLabel); + OUString get_label() const; + + void SetOptimalSize(); + virtual void dispose() override; + virtual ~LabelItemWindow() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/vcl/InterimItemWindow.hxx b/include/vcl/InterimItemWindow.hxx new file mode 100644 index 000000000000..3ba842a3eca1 --- /dev/null +++ b/include/vcl/InterimItemWindow.hxx @@ -0,0 +1,38 @@ +/* -*- 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/. + */ + +#pragma once + +#include <vcl/dllapi.h> +#include <vcl/ctrl.hxx> +#include <vcl/weld.hxx> + +class VCL_DLLPUBLIC InterimItemWindow : public Control +{ +public: + virtual ~InterimItemWindow() override; + virtual void dispose() override; + + virtual void Resize() override; + virtual Size GetOptimalSize() const override; + virtual void GetFocus() override; + +protected: + InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription, const OString& rID); + + // pass keystrokes from our child window through this to handle focus changes correctly + // returns true if keystroke is consumed + bool ChildKeyInput(const KeyEvent& rKEvt); + + std::unique_ptr<weld::Builder> m_xBuilder; + VclPtr<vcl::Window> m_xVclContentArea; + std::unique_ptr<weld::Container> m_xContainer; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sd/source/ui/dlg/diactrl.cxx b/sd/source/ui/dlg/diactrl.cxx index d05f4f1f16a0..3a4841458de0 100644 --- a/sd/source/ui/dlg/diactrl.cxx +++ b/sd/source/ui/dlg/diactrl.cxx @@ -19,6 +19,7 @@ #include <svl/intitem.hxx> #include <vcl/toolbox.hxx> +#include <svl/intitem.hxx> #include <strings.hrc> diff --git a/sfx2/inc/pch/precompiled_sfx.hxx b/sfx2/inc/pch/precompiled_sfx.hxx index b4e1587a5801..f06a39148a70 100644 --- a/sfx2/inc/pch/precompiled_sfx.hxx +++ b/sfx2/inc/pch/precompiled_sfx.hxx @@ -89,6 +89,7 @@ #include <sal/types.h> #include <vcl/EnumContext.hxx> #include <vcl/NotebookbarContextControl.hxx> +#include <vcl/InterimItemWindow.hxx> #include <vcl/Scanline.hxx> #include <vcl/alpha.hxx> #include <vcl/bitmapex.hxx> diff --git a/svx/inc/pch/precompiled_svx.hxx b/svx/inc/pch/precompiled_svx.hxx index 0de6708d0827..4d0c183208b9 100644 --- a/svx/inc/pch/precompiled_svx.hxx +++ b/svx/inc/pch/precompiled_svx.hxx @@ -80,6 +80,7 @@ #include <sal/typesizes.h> #include <vcl/BitmapFilter.hxx> #include <vcl/EnumContext.hxx> +#include <vcl/InterimItemWindow.hxx> #include <vcl/Scanline.hxx> #include <vcl/alpha.hxx> #include <vcl/bitmapex.hxx> @@ -316,6 +317,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/dllapi.h> #include <sfx2/dockwin.hxx> +#include <sfx2/lokhelper.hxx> #include <sfx2/module.hxx> #include <sfx2/objsh.hxx> #include <sfx2/request.hxx> @@ -361,6 +363,7 @@ #include <svtools/valueset.hxx> #include <toolkit/helper/convert.hxx> #include <toolkit/helper/vclunohelper.hxx> +#include <tools/UnitConversion.hxx> #include <tools/color.hxx> #include <tools/date.hxx> #include <tools/datetime.hxx> diff --git a/svx/source/inc/findtextfield.hxx b/svx/source/inc/findtextfield.hxx new file mode 100644 index 000000000000..1ac5519a2dcd --- /dev/null +++ b/svx/source/inc/findtextfield.hxx @@ -0,0 +1,69 @@ +/* -*- 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 <vcl/InterimItemWindow.hxx> + +namespace svt +{ +class AcceleratorExecute; +} + +class FindTextFieldControl final : public InterimItemWindow +{ +public: + FindTextFieldControl(vcl::Window* pParent, + css::uno::Reference<css::frame::XFrame> const& xFrame, + const css::uno::Reference<css::uno::XComponentContext>& xContext); + + virtual void dispose() override; + + virtual ~FindTextFieldControl() override; + + virtual void GetFocus() override; + + void Remember_Impl(const OUString& rStr); + void SetTextToSelected_Impl(); + + void connect_changed(const Link<weld::ComboBox&, void>& rLink); + + int get_count() const; + OUString get_text(int nIndex) const; + OUString get_active_text() const; + void append_text(const OUString& rText); + void set_entry_message_type(weld::EntryMessageType eType); + +private: + ImplSVEvent* m_nAsyncGetFocusId; + std::unique_ptr<weld::ComboBox> m_xWidget; + css::uno::Reference<css::frame::XFrame> m_xFrame; + css::uno::Reference<css::uno::XComponentContext> m_xContext; + std::unique_ptr<svt::AcceleratorExecute> m_pAcc; + Link<weld::ComboBox&, void> m_aChangeHdl; + + DECL_LINK(FocusInHdl, weld::Widget&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_LINK(ActivateHdl, weld::ComboBox&, bool); + DECL_LINK(OnAsyncGetFocus, void*, void); + + void ActivateFind(bool bShift); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/tbxctrls/linemetricbox.hxx b/svx/source/tbxctrls/linemetricbox.hxx new file mode 100644 index 000000000000..e58566a10d00 --- /dev/null +++ b/svx/source/tbxctrls/linemetricbox.hxx @@ -0,0 +1,57 @@ +/* -*- 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 <vcl/InterimItemWindow.hxx> +#include <svx/svxdllapi.h> + +class XLineWidthItem; + +class SvxMetricField final : public InterimItemWindow +{ +private: + std::unique_ptr<weld::MetricSpinButton> m_xWidget; + int nCurValue; + MapUnit eDestPoolUnit; + FieldUnit eDlgUnit; + css::uno::Reference<css::frame::XFrame> mxFrame; + + DECL_LINK(ModifyHdl, weld::MetricSpinButton&, void); + DECL_LINK(KeyInputHdl, const KeyEvent&, bool); + DECL_LINK(FocusInHdl, weld::Widget&, void); + + static void ReleaseFocus_Impl(); + + virtual void DataChanged(const DataChangedEvent& rDCEvt) override; + + virtual void GetFocus() override; + +public: + SvxMetricField(vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& rFrame); + virtual void dispose() override; + virtual ~SvxMetricField() override; + + void Update(const XLineWidthItem* pItem); + void SetDestCoreUnit(MapUnit eUnit); + void RefreshDlgUnit(); + + void set_sensitive(bool bSensitive); +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 73c74636c482..1a6fdce0d48b 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -191,6 +191,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/control/fixedhyper \ vcl/source/control/hyperlabel \ vcl/source/control/fmtfield \ + vcl/source/control/InterimItemWindow \ vcl/source/control/imgctrl \ vcl/source/control/imivctl1 \ vcl/source/control/imivctl2 \ diff --git a/vcl/source/control/InterimItemWindow.cxx b/vcl/source/control/InterimItemWindow.cxx new file mode 100644 index 000000000000..f9f54d757fd5 --- /dev/null +++ b/vcl/source/control/InterimItemWindow.cxx @@ -0,0 +1,99 @@ +/* -*- 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/. + */ + +#include <vcl/InterimItemWindow.hxx> +#include <vcl/layout.hxx> + +InterimItemWindow::InterimItemWindow(vcl::Window* pParent, const OUString& rUIXMLDescription, + const OString& rID) + : Control(pParent, WB_TABSTOP | WB_DIALOGCONTROL) +{ + m_xVclContentArea = VclPtr<VclVBox>::Create(this); + m_xVclContentArea->Show(); + m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription)); + m_xContainer = m_xBuilder->weld_container(rID); + + SetBackground(); + SetPaintTransparent(true); +} + +InterimItemWindow::~InterimItemWindow() { disposeOnce(); } + +void InterimItemWindow::dispose() +{ + m_xContainer.reset(); + m_xBuilder.reset(); + m_xVclContentArea.disposeAndClear(); + + Control::dispose(); +} + +void InterimItemWindow::Resize() +{ + vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); + assert(pChild); + VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel()); + Control::Resize(); +} + +Size InterimItemWindow::GetOptimalSize() const +{ + return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild)); +} + +void InterimItemWindow::GetFocus() +{ + /* let toolbox know this item window has focus so it updates its mnHighItemId to point + to this toolitem in case tab means to move to another toolitem within + the toolbox + */ + vcl::Window* pToolBox = GetParent(); + NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this); + pToolBox->EventNotify(aNEvt); +} + +bool InterimItemWindow::ChildKeyInput(const KeyEvent& rKEvt) +{ + sal_uInt16 nCode = rKEvt.GetKeyCode().GetCode(); + if (nCode != KEY_TAB) + return false; + + /* if the native widget has focus, then no vcl window has focus. + + We want to grab focus to this vcl widget so that pressing tab will traverse + to the next vcl widget. + + But just using GrabFocus will, because no vcl widget has focus, trigger + bringing the toplevel to front with the expectation that a suitable widget + will be picked for focus when that happen, which is no use to us here. + + SetFakeFocus avoids the problem, allowing GrabFocus to do the expected thing + then sending the Tab to our parent will do the right traversal + */ + SetFakeFocus(true); + GrabFocus(); + + /* now give focus to our toolbox parent */ + vcl::Window* pToolBox = GetParent(); + pToolBox->GrabFocus(); + + /* let toolbox know this item window has focus so it updates its mnHighItemId to point + to this toolitem in case tab means to move to another toolitem within + the toolbox + */ + NotifyEvent aNEvt(MouseNotifyEvent::GETFOCUS, this); + pToolBox->EventNotify(aNEvt); + + /* send parent the tab */ + pToolBox->KeyInput(rKEvt); + + return true; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ commit 27643882a5c1aaeea96e25aa5cbc061574eb84d2 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Wed Dec 18 16:46:42 2019 +0000 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:38 2020 +0200 these .ui no longer need special handling Change-Id: I1b112ea6780ff5da2b8aa86f8039b47e98219f08 Reviewed-on: https://gerrit.libreoffice.org/85407 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/test/source/screenshot_test.cxx b/test/source/screenshot_test.cxx index 6f4d49cc88bd..80c0b05abf15 100644 --- a/test/source/screenshot_test.cxx +++ b/test/source/screenshot_test.cxx @@ -220,14 +220,7 @@ void ScreenshotTest::dumpDialogToPath(const OString& rUIXMLDescription) rUIXMLDescription == "modules/dbreport/ui/conditionwin.ui"; if (bNonConforming) // skip these broken ones return; - bool bLegacy = rUIXMLDescription == "fps/ui/explorerfiledialog.ui" || - rUIXMLDescription == "fps/ui/remotefilesdialog.ui" || - rUIXMLDescription == "sfx/ui/floatingrecord.ui"; - std::unique_ptr<weld::Builder> xBuilder; - if (bLegacy) - xBuilder.reset(Application::CreateInterimBuilder(mxParentWidget.get(), OStringToOUString(rUIXMLDescription, RTL_TEXTENCODING_UTF8))); - else - xBuilder.reset(Application::CreateBuilder(mxParentWidget.get(), OStringToOUString(rUIXMLDescription, RTL_TEXTENCODING_UTF8))); + std::unique_ptr<weld::Builder> xBuilder(Application::CreateBuilder(mxParentWidget.get(), OStringToOUString(rUIXMLDescription, RTL_TEXTENCODING_UTF8))); dumpDialogToPath(*xBuilder); } } commit f6e054bd47b84abc2235594bc9677e4b3d3ffa3e Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Dec 17 17:25:57 2019 +0000 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:37 2020 +0200 add a SystemChildWindow::GetOptimalSize override Change-Id: I812d996e78a6d627fda6612307ca4cb2f111b6a9 Reviewed-on: https://gerrit.libreoffice.org/85325 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/syschild.hxx b/include/vcl/syschild.hxx index bdfd913fe929..11d85b029bf5 100644 --- a/include/vcl/syschild.hxx +++ b/include/vcl/syschild.hxx @@ -41,6 +41,7 @@ public: // create a SystemChildWindow using the given SystemWindowData explicit SystemChildWindow( vcl::Window* pParent, WinBits nStyle, SystemWindowData *pData, bool bShow = true ); virtual ~SystemChildWindow() override; + virtual Size GetOptimalSize() const override; virtual void dispose() override; virtual const SystemEnvData* GetSystemData() const override; diff --git a/vcl/inc/salobj.hxx b/vcl/inc/salobj.hxx index a9ba622c24b1..6e79e49208bb 100644 --- a/vcl/inc/salobj.hxx +++ b/vcl/inc/salobj.hxx @@ -56,6 +56,8 @@ public: virtual const SystemEnvData* GetSystemData() const = 0; + virtual Size GetOptimalSize() const { return Size(); } + void SetCallback( SystemChildWindow* pInst, SALOBJECTPROC pProc ) { m_pInst = pInst; m_pCallback = pProc; } void CallCallback( SalObjEvent nEvent ) diff --git a/vcl/source/window/syschild.cxx b/vcl/source/window/syschild.cxx index 2ba10a2bcc75..81cbc43abd11 100644 --- a/vcl/source/window/syschild.cxx +++ b/vcl/source/window/syschild.cxx @@ -140,6 +140,13 @@ void SystemChildWindow::EnableEraseBackground( bool bEnable ) mpWindowImpl->mpSysObj->EnableEraseBackground( bEnable ); } +Size SystemChildWindow::GetOptimalSize() const +{ + if (mpWindowImpl->mpSysObj) + return mpWindowImpl->mpSysObj->GetOptimalSize(); + return vcl::Window::GetOptimalSize(); +} + void SystemChildWindow::SetLeaveEnterBackgrounds(const css::uno::Sequence<css::uno::Any>& rLeaveArgs, const css::uno::Sequence<css::uno::Any>& rEnterArgs) { if (mpWindowImpl->mpSysObj) commit a7c33596a135d2548d04cc3a59930d36797d767f Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Dec 17 17:27:30 2019 +0000 Commit: Szymon Kłos <eszka...@gmail.com> CommitDate: Wed Jun 3 12:28:37 2020 +0200 get native gtk widgets in sidebars working Change-Id: If65aef1249f54a87d7854c3fa2db4319a24a5a05 Reviewed-on: https://gerrit.libreoffice.org/85326 Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/svx/sidebar/PanelLayout.hxx b/include/svx/sidebar/PanelLayout.hxx index 6439ed51afdb..01cb0ff4a447 100644 --- a/include/svx/sidebar/PanelLayout.hxx +++ b/include/svx/sidebar/PanelLayout.hxx @@ -14,6 +14,7 @@ #include <vcl/builder.hxx> #include <vcl/ctrl.hxx> +#include <vcl/layout.hxx> #include <vcl/timer.hxx> #include <vcl/idle.hxx> #include <vcl/weld.hxx> @@ -25,6 +26,7 @@ class SVX_DLLPUBLIC PanelLayout : public Control, public VclBuilderContainer { protected: std::unique_ptr<weld::Builder> m_xBuilder; + VclPtr<VclVBox> m_xVclContentArea; std::unique_ptr<weld::Container> m_xContainer; private: diff --git a/include/vcl/svapp.hxx b/include/vcl/svapp.hxx index b3ed1feac501..5129ed16f210 100644 --- a/include/vcl/svapp.hxx +++ b/include/vcl/svapp.hxx @@ -1341,9 +1341,7 @@ public: static void setDeInitHook(Link<LinkParamNone*,void> const & hook); static weld::Builder* CreateBuilder(weld::Widget* pParent, const OUString &rUIFile, bool bMobile = false); - static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types - static weld::Builder* CreateInterimBuilder(weld::Widget* pParent, const OUString &rUIFile); //for the duration of same SfxTabPages in mixed parent types - + static weld::Builder* CreateInterimBuilder(vcl::Window* pParent, const OUString &rUIFile); //for the duration of vcl parent windows static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString& rPrimaryMessage, bool bMobile = false); diff --git a/include/vcl/sysdata.hxx b/include/vcl/sysdata.hxx index 9c4e271a2963..89122f51c75d 100644 --- a/include/vcl/sysdata.hxx +++ b/include/vcl/sysdata.hxx @@ -181,6 +181,7 @@ struct SystemWindowData // Nothing #elif defined( UNX ) void* pVisual; // the visual to be used + bool bClipUsingNativeWidget; // default is false, true will attempt to clip the childwindow with a native widget #endif }; diff --git a/svx/source/sidebar/PanelLayout.cxx b/svx/source/sidebar/PanelLayout.cxx index 105bb1c1d6da..e82c03fdc513 100644 --- a/svx/source/sidebar/PanelLayout.cxx +++ b/svx/source/sidebar/PanelLayout.cxx @@ -30,11 +30,18 @@ PanelLayout::PanelLayout(vcl::Window* pParent, const OString& rID, const OUStrin // VclBuilder will trigger resize and start Idle ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits