From cf7db8226240ca7f425cf649e164767988c80001 Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Wed, 19 Aug 2015 23:43:39 +0200 Subject: handle new color picker correctly in chart sidebar This implements the basics for that and implements it in the AreaPanel. Change-Id: I6d9e5012bbcc2c953d478a09a839f35f2ef64c5b --- chart2/Library_chartcontroller.mk | 1 + .../source/controller/sidebar/ChartAreaPanel.cxx | 9 ++- .../source/controller/sidebar/ChartAreaPanel.hxx | 3 + .../controller/sidebar/ChartColorWrapper.cxx | 80 ++++++++++++++++++++++ .../controller/sidebar/ChartColorWrapper.hxx | 41 +++++++++++ include/sfx2/sidebar/SidebarToolBox.hxx | 2 + include/svx/PaletteManager.hxx | 5 ++ include/svx/sidebar/AreaPropertyPanelBase.hxx | 3 +- include/svx/tbcontrl.hxx | 4 ++ sfx2/source/sidebar/SidebarToolBox.cxx | 8 +++ svx/source/tbxctrls/PaletteManager.cxx | 10 ++- svx/source/tbxctrls/colorwindow.hxx | 7 +- svx/source/tbxctrls/tbcontrl.cxx | 24 +++++-- 13 files changed, 185 insertions(+), 12 deletions(-) create mode 100644 chart2/source/controller/sidebar/ChartColorWrapper.cxx create mode 100644 chart2/source/controller/sidebar/ChartColorWrapper.hxx diff --git a/chart2/Library_chartcontroller.mk b/chart2/Library_chartcontroller.mk index e06edd176ba1..9f8b65f8045f 100644 --- a/chart2/Library_chartcontroller.mk +++ b/chart2/Library_chartcontroller.mk @@ -191,6 +191,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcontroller,\ chart2/source/controller/sidebar/Chart2PanelFactory \ chart2/source/controller/sidebar/ChartAreaPanel \ chart2/source/controller/sidebar/ChartAxisPanel \ + chart2/source/controller/sidebar/ChartColorWrapper \ chart2/source/controller/sidebar/ChartElementsPanel \ chart2/source/controller/sidebar/ChartErrorBarPanel \ chart2/source/controller/sidebar/ChartLinePanel \ diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.cxx b/chart2/source/controller/sidebar/ChartAreaPanel.cxx index 3230e7c32534..dbf9a6837b6b 100644 --- a/chart2/source/controller/sidebar/ChartAreaPanel.cxx +++ b/chart2/source/controller/sidebar/ChartAreaPanel.cxx @@ -19,6 +19,8 @@ #include #include +#include + namespace chart { namespace sidebar { namespace { @@ -237,7 +239,8 @@ ChartAreaPanel::ChartAreaPanel(vcl::Window* pParent, mxListener(new ChartSidebarModifyListener(this)), mxSelectionListener(new ChartSidebarSelectionListener(this)), mbUpdate(true), - mbModelValid(true) + mbModelValid(true), + maFillColorWrapper(mxModel) { std::vector aAcceptedTypes { OBJECTTYPE_PAGE, OBJECTTYPE_DIAGRAM, OBJECTTYPE_DATA_SERIES, OBJECTTYPE_TITLE, OBJECTTYPE_LEGEND}; mxSelectionListener->setAcceptedTypes(aAcceptedTypes); @@ -270,6 +273,10 @@ void ChartAreaPanel::Initialize() if (xSelectionSupplier.is()) xSelectionSupplier->addSelectionChangeListener(mxSelectionListener.get()); + css::uno::Reference xController = mpToolBoxColor->GetFirstController(); + SvxColorToolBoxControl* pToolBoxColor = dynamic_cast(xController.get()); + pToolBoxColor->setColorSelectFunction(maFillColorWrapper); + updateData(); } diff --git a/chart2/source/controller/sidebar/ChartAreaPanel.hxx b/chart2/source/controller/sidebar/ChartAreaPanel.hxx index 48df2ace78c7..aa66339d975c 100644 --- a/chart2/source/controller/sidebar/ChartAreaPanel.hxx +++ b/chart2/source/controller/sidebar/ChartAreaPanel.hxx @@ -30,6 +30,7 @@ #include "ChartSidebarModifyListener.hxx" #include "ChartSidebarSelectionListener.hxx" +#include "ChartColorWrapper.hxx" class XFillFloatTransparenceItem; class XFillTransparenceItem; @@ -92,6 +93,8 @@ private: bool mbUpdate; bool mbModelValid; + + ChartColorWrapper maFillColorWrapper; }; } } // end of namespace svx::sidebar diff --git a/chart2/source/controller/sidebar/ChartColorWrapper.cxx b/chart2/source/controller/sidebar/ChartColorWrapper.cxx new file mode 100644 index 000000000000..d8a8f870f28f --- /dev/null +++ b/chart2/source/controller/sidebar/ChartColorWrapper.cxx @@ -0,0 +1,80 @@ +/* -*- 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 "ChartColorWrapper.hxx" + +#include "ChartController.hxx" + +namespace chart { namespace sidebar { + +namespace { + +OUString getCID(css::uno::Reference xModel) +{ + css::uno::Reference xController(xModel->getCurrentController()); + css::uno::Reference xSelectionSupplier(xController, css::uno::UNO_QUERY); + if (!xSelectionSupplier.is()) + return OUString(); + + css::uno::Any aAny = xSelectionSupplier->getSelection(); + if (!aAny.hasValue()) + return OUString(); + + OUString aCID; + aAny >>= aCID; + + return aCID; +} + +css::uno::Reference getPropSet( + css::uno::Reference xModel) +{ + OUString aCID = getCID(xModel); + css::uno::Reference xPropSet = + ObjectIdentifier::getObjectPropertySet(aCID, xModel); + + ObjectType eType = ObjectIdentifier::getObjectType(aCID); + if (eType == OBJECTTYPE_DIAGRAM) + { + css::uno::Reference xDiagram( + xPropSet, css::uno::UNO_QUERY); + if (!xDiagram.is()) + return xPropSet; + + xPropSet.set(xDiagram->getWall()); + } + + return xPropSet; +} + +} + +ChartColorWrapper::ChartColorWrapper( + css::uno::Reference xModel): + mxModel(xModel), + maPropertyName("FillColor") +{ +} + +void ChartColorWrapper::operator()(const OUString& rCommand, const Color& rColor) +{ + css::uno::Reference xPropSet = getPropSet(mxModel); + assert(xPropSet.is()); + + xPropSet->setPropertyValue(maPropertyName, css::uno::makeAny(rColor.GetColor())); +} + +void ChartColorWrapper::updateModel(css::uno::Reference xModel) +{ + mxModel = xModel; +} + +} } + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/controller/sidebar/ChartColorWrapper.hxx b/chart2/source/controller/sidebar/ChartColorWrapper.hxx new file mode 100644 index 000000000000..adbe9ef0d05f --- /dev/null +++ b/chart2/source/controller/sidebar/ChartColorWrapper.hxx @@ -0,0 +1,41 @@ +/* -*- 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_CHART2_SOURCE_CONTROLLER_SIDEBAR_CHARTCOLORWRAPPER_HXX +#define INCLUDED_CHART2_SOURCE_CONTROLLER_SIDEBAR_CHARTCOLORWRAPPER_HXX + +#include +#include + +namespace chart { namespace sidebar { + +class ChartColorWrapper +{ +private: + +public: + ChartColorWrapper(css::uno::Reference xModel); + + void operator()(const OUString& rCommand, const Color& rColor); + + void updateModel(css::uno::Reference xModel); +private: + + // not the chart frame + // you need to get the chart frame through getActiveFrame + css::uno::Reference mxModel; + + OUString maPropertyName; +}; + +} } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/sidebar/SidebarToolBox.hxx b/include/sfx2/sidebar/SidebarToolBox.hxx index a3959698278e..574603b22e6d 100644 --- a/include/sfx2/sidebar/SidebarToolBox.hxx +++ b/include/sfx2/sidebar/SidebarToolBox.hxx @@ -61,6 +61,8 @@ public: const css::uno::Reference& rxController, const OUString& rsCommandName); + css::uno::Reference GetFirstController(); + private: Image maItemSeparator; diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx index 7ad0cdb8ee86..561dcac43d93 100644 --- a/include/svx/PaletteManager.hxx +++ b/include/svx/PaletteManager.hxx @@ -50,6 +50,8 @@ class PaletteManager std::deque maRecentColors; std::vector> m_Palettes; + std::function maColorSelectFunction; + public: PaletteManager(); ~PaletteManager(); @@ -69,6 +71,9 @@ public: void SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater); void PopupColorPicker(const OUString& aCommand); + + void SetColorSelectFunction(std::function aColorSelectFunction); + static void DispatchColorCommand(const OUString& aCommand, const Color& rColor); }; diff --git a/include/svx/sidebar/AreaPropertyPanelBase.hxx b/include/svx/sidebar/AreaPropertyPanelBase.hxx index 9fdbba114366..24ebcedc07ba 100644 --- a/include/svx/sidebar/AreaPropertyPanelBase.hxx +++ b/include/svx/sidebar/AreaPropertyPanelBase.hxx @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -124,7 +125,7 @@ protected: VclPtr mpColorTextFT; VclPtr mpLbFillType; VclPtr mpLbFillAttr; - VclPtr mpToolBoxColor; // for new color picker + VclPtr mpToolBoxColor; // for new color picker VclPtr mpTrspTextFT; VclPtr mpLBTransType; VclPtr mpMTRTransparent; diff --git a/include/svx/tbcontrl.hxx b/include/svx/tbcontrl.hxx index 9e589ac44f59..584b99ed64eb 100644 --- a/include/svx/tbcontrl.hxx +++ b/include/svx/tbcontrl.hxx @@ -225,6 +225,7 @@ public: Color GetColor(); }; +typedef std::function ColorSelectFunction; class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl { using SfxToolBoxControl::StateChanged; @@ -233,6 +234,7 @@ class SVX_DLLPUBLIC SvxColorToolBoxControl : public SfxToolBoxControl PaletteManager mPaletteManager; BorderColorStatus maBorderColorStatus; bool bSidebarType; + ColorSelectFunction maColorSelectFunction; DECL_LINK(SelectedHdl, Color*); public: SFX_DECL_TOOLBOX_CONTROL(); @@ -247,6 +249,8 @@ public: // XSubToolbarController virtual sal_Bool SAL_CALL opensSubToolbar() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; virtual void SAL_CALL updateImage() throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE; + + void setColorSelectFunction(ColorSelectFunction aColorSelectFunction); }; class SVX_DLLPUBLIC SvxFrameToolBoxControl : public SfxToolBoxControl diff --git a/sfx2/source/sidebar/SidebarToolBox.cxx b/sfx2/source/sidebar/SidebarToolBox.cxx index ce02e9ebb2ed..542088a437a9 100644 --- a/sfx2/source/sidebar/SidebarToolBox.cxx +++ b/sfx2/source/sidebar/SidebarToolBox.cxx @@ -205,6 +205,14 @@ sal_uInt16 SidebarToolBox::GetItemIdForSubToolbarName (const OUString& rsSubTool return 0; } +css::uno::Reference SidebarToolBox::GetFirstController() +{ + if (maControllers.empty()) + return css::uno::Reference(); + + return maControllers.begin()->second.mxController; +} + void SidebarToolBox::RegisterHandlers() { if ( ! mbAreHandlersRegistered) diff --git a/svx/source/tbxctrls/PaletteManager.cxx b/svx/source/tbxctrls/PaletteManager.cxx index 658348fcf3eb..8f0ff658bf30 100644 --- a/svx/source/tbxctrls/PaletteManager.cxx +++ b/svx/source/tbxctrls/PaletteManager.cxx @@ -36,7 +36,8 @@ PaletteManager::PaletteManager() : mnCurrentPalette(0), mnColorCount(0), mpBtnUpdater(NULL), - mLastColor(COL_AUTO) + mLastColor(COL_AUTO), + maColorSelectFunction(PaletteManager::DispatchColorCommand) { LoadPalettes(); mnNumOfPalettes += m_Palettes.size(); @@ -217,6 +218,11 @@ void PaletteManager::SetBtnUpdater(svx::ToolboxButtonColorUpdater* pBtnUpdater) mpBtnUpdater = pBtnUpdater; } +void PaletteManager::SetColorSelectFunction(std::function aColorSelectFunction) +{ + maColorSelectFunction = aColorSelectFunction; +} + void PaletteManager::PopupColorPicker(const OUString& aCommand) { // The calling object goes away during aColorDlg.Execute(), so we must copy this @@ -230,7 +236,7 @@ void PaletteManager::PopupColorPicker(const OUString& aCommand) mpBtnUpdater->Update( aColorDlg.GetColor() ); mLastColor = aColorDlg.GetColor(); AddRecentColor( mLastColor ); - DispatchColorCommand(aCommandCopy, mLastColor); + maColorSelectFunction(aCommandCopy, mLastColor); } } diff --git a/svx/source/tbxctrls/colorwindow.hxx b/svx/source/tbxctrls/colorwindow.hxx index 97cccc5ff4d2..9cb27fdf4c9d 100644 --- a/svx/source/tbxctrls/colorwindow.hxx +++ b/svx/source/tbxctrls/colorwindow.hxx @@ -29,6 +29,8 @@ #include #include +#include + class BorderColorStatus; class SvxColorWindow_Impl : public SfxPopupWindow @@ -50,6 +52,8 @@ private: PaletteManager& mrPaletteManager; BorderColorStatus& mrBorderColorStatus; + std::function maColorSelectFunction; + DECL_LINK( SelectHdl, SvxColorValueSet* ); DECL_LINK( SelectPaletteHdl, void *); DECL_LINK( AutoColorClickHdl, void * ); @@ -66,7 +70,8 @@ public: sal_uInt16 nSlotId, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rFrame, const OUString& rWndTitle, - vcl::Window* pParentWindow); + vcl::Window* pParentWindow, + std::function maColorSelectFunction); virtual ~SvxColorWindow_Impl(); virtual void dispose() SAL_OVERRIDE; void StartSelection(); diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx index bc0912ff1c12..528b4eac14ef 100644 --- a/svx/source/tbxctrls/tbcontrl.cxx +++ b/svx/source/tbxctrls/tbcontrl.cxx @@ -1215,7 +1215,8 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, sal_uInt16 nSlotId, const Reference< XFrame >& rFrame, const OUString& rWndTitle, - vcl::Window* pParentWindow ): + vcl::Window* pParentWindow, + std::function aFunction): SfxPopupWindow( nSlotId, pParentWindow, "palette_popup_window", "svx/ui/colorwindow.ui", @@ -1223,7 +1224,8 @@ SvxColorWindow_Impl::SvxColorWindow_Impl( const OUString& rCommand, theSlotId( nSlotId ), maCommand( rCommand ), mrPaletteManager( rPaletteManager ), - mrBorderColorStatus( rBorderColorStatus ) + mrBorderColorStatus( rBorderColorStatus ), + maColorSelectFunction(aFunction) { get(mpPaletteListBox, "palette_listbox"); get(mpButtonAutoColor, "auto_color_button"); @@ -1365,7 +1367,7 @@ IMPL_LINK(SvxColorWindow_Impl, SelectHdl, SvxColorValueSet*, pColorSet) if ( maSelectedLink.IsSet() ) maSelectedLink.Call(&aColor); - PaletteManager::DispatchColorCommand(maCommand, aColor); + maColorSelectFunction(maCommand, aColor); return 0; } @@ -1407,7 +1409,7 @@ IMPL_LINK_NOARG(SvxColorWindow_Impl, AutoColorClickHdl) if ( maSelectedLink.IsSet() ) maSelectedLink.Call(&aColor); - PaletteManager::DispatchColorCommand(maCommand, aColor); + maColorSelectFunction(maCommand, aColor); return 0; } @@ -2537,8 +2539,9 @@ VclPtr SvxFontNameToolBoxControl::CreateItemWindow( vcl::Window *pP SvxColorToolBoxControl::SvxColorToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, - ToolBox& rTbx ) : - SfxToolBoxControl( nSlotId, nId, rTbx ) + ToolBox& rTbx ): + SfxToolBoxControl( nSlotId, nId, rTbx ), + maColorSelectFunction(PaletteManager::DispatchColorCommand) { if ( dynamic_cast< sfx2::sidebar::SidebarToolBox* >(&rTbx) ) bSidebarType = true; @@ -2611,6 +2614,12 @@ SvxColorToolBoxControl::~SvxColorToolBoxControl() { } +void SvxColorToolBoxControl::setColorSelectFunction(ColorSelectFunction aColorSelectFunction) +{ + maColorSelectFunction = aColorSelectFunction; + mPaletteManager.SetColorSelectFunction(aColorSelectFunction); +} + VclPtr SvxColorToolBoxControl::CreatePopupWindow() { SvxColorWindow_Impl* pColorWin = @@ -2622,7 +2631,8 @@ VclPtr SvxColorToolBoxControl::CreatePopupWindow() GetSlotId(), m_xFrame, SVX_RESSTR( RID_SVXITEMS_EXTRAS_CHARCOLOR ), - &GetToolBox() ); + &GetToolBox(), + maColorSelectFunction); switch( GetSlotId() ) { -- cgit