From 52181e48798a9fdee6788f723d4ed0478ed40683 Mon Sep 17 00:00:00 2001 From: Andre Fischer Date: Thu, 16 May 2013 11:43:55 +0000 Subject: Resolves: #i121960# Improve creation of toolbox/toolbar controllers (cherry picked from commit 3608a33d8362cbc44a2eb7203b7d1bffe481c7ab) Conflicts: sfx2/inc/sfx2/sidebar/ControlFactory.hxx sfx2/inc/sfx2/sidebar/ControllerFactory.hxx sfx2/inc/sfx2/sidebar/SidebarToolBox.hxx sfx2/inc/sfx2/sidebar/Tools.hxx sfx2/source/sidebar/ToolBoxBackground.cxx Change-Id: I833a33bbc58ebe46bd28c6d97a4d76329f1f0186 (cherry picked from commit edaca7c6e1d1ade6bf6cdae753028ee62297f0b1) --- include/sfx2/sidebar/ControlFactory.hxx | 29 ++++- include/sfx2/sidebar/ControllerFactory.hxx | 16 ++- include/sfx2/sidebar/SidebarToolBox.hxx | 4 +- include/sfx2/sidebar/Tools.hxx | 3 + sfx2/source/sidebar/ControlFactory.cxx | 5 +- sfx2/source/sidebar/ControllerFactory.cxx | 132 +++++++++++++++++++--- sfx2/source/sidebar/ResourceManager.cxx | 26 +---- sfx2/source/sidebar/ResourceManager.hxx | 3 - sfx2/source/sidebar/SidebarToolBox.cxx | 28 +++-- sfx2/source/sidebar/ToolBoxBackground.cxx | 13 ++- sfx2/source/sidebar/ToolBoxBackground.hxx | 4 +- sfx2/source/sidebar/Tools.cxx | 25 ++++ svx/source/sidebar/insert/InsertPropertyPanel.hxx | 2 + 13 files changed, 224 insertions(+), 66 deletions(-) diff --git a/include/sfx2/sidebar/ControlFactory.hxx b/include/sfx2/sidebar/ControlFactory.hxx index 3b286e927975..b4d329acc27b 100644 --- a/include/sfx2/sidebar/ControlFactory.hxx +++ b/include/sfx2/sidebar/ControlFactory.hxx @@ -28,26 +28,49 @@ namespace sfx2 { namespace sidebar { class ToolBoxBackground; +/** Factory for controls used in sidebar panels. + The reason to use this factory instead of creating the controls + directly is that this way the sidebar has a little more control + over look and feel of its controls. +*/ class SFX2_DLLPUBLIC ControlFactory { public: + /** Create the menu button for the task bar. + */ static CheckBox* CreateMenuButton (Window* pParentWindow); + static ImageRadioButton* CreateTabItem (Window* pParentWindow); - /** Create a tool box that does *not* handle its items. + /** Create a tool box that does *not* handle its items. The + caller has to register callbacks to process, among others, + click and selection events. */ static SidebarToolBox* CreateToolBox ( Window* pParentWindow, const ResId& rResId); - /** Create a tool box that *does* handle its items. + /** Create a tool box that *does* handle its items. All event + processing is done by toolbox controllers. */ static SidebarToolBox* CreateToolBox ( Window* pParentWindow, const ResId& rResId, const ::com::sun::star::uno::Reference& rxFrame); - static Window* CreateToolBoxBackground (Window* pParentWindow); + /** Create a window that acts as background of a tool box. + In general it is slightly larger than the tool box. + @param pParentWindow + The parent window of the new background control. + @param bShowBorder + When then the background control is made slightly + larger then its tool box child, once that is created. + Otherwise the background control will not be visible. + */ + static Window* CreateToolBoxBackground ( + Window* pParentWindow, + const bool bShowBorder = true); + static ImageRadioButton* CreateCustomImageRadionButton( Window* pParentWindow, const ResId& rResId ); diff --git a/include/sfx2/sidebar/ControllerFactory.hxx b/include/sfx2/sidebar/ControllerFactory.hxx index 030b050adfb9..fa341f13cb2a 100644 --- a/include/sfx2/sidebar/ControllerFactory.hxx +++ b/include/sfx2/sidebar/ControllerFactory.hxx @@ -19,8 +19,9 @@ #define SFX_SIDEBAR_CONTROLLER_FACTORY_HXX #include "sfx2/dllapi.h" -#include +#include #include +#include namespace css = ::com::sun::star; namespace cssu = ::com::sun::star::uno; @@ -29,7 +30,7 @@ class ToolBox; namespace sfx2 { namespace sidebar { -/** Convenience class for easy creation of toolbox controllers. +/** Convenience class for the easy creation of toolbox controllers. */ class SFX2_DLLPUBLIC ControllerFactory { @@ -38,7 +39,16 @@ public: ToolBox* pToolBox, const sal_uInt16 nItemId, const ::rtl::OUString& rsCommandName, - const cssu::Reference& rxFrame); + const cssu::Reference& rxFrame, + const cssu::Reference& rxParentWindow, + const sal_Int32 nItemWidth); + +private: + static cssu::Reference CreateToolBarController( + ToolBox* pToolBox, + const ::rtl::OUString& rsCommandName, + const cssu::Reference& rxFrame, + const sal_Int32 nWidth); }; diff --git a/include/sfx2/sidebar/SidebarToolBox.hxx b/include/sfx2/sidebar/SidebarToolBox.hxx index 4d5625c3961a..bb96a9ee69eb 100644 --- a/include/sfx2/sidebar/SidebarToolBox.hxx +++ b/include/sfx2/sidebar/SidebarToolBox.hxx @@ -76,7 +76,6 @@ private: cssu::Reference mxController; css::util::URL maURL; rtl::OUString msCurrentCommand; - cssu::Reference mxDispatch; }; typedef ::std::map ControllerContainer; ControllerContainer maControllers; @@ -90,7 +89,8 @@ private: void CreateController ( const sal_uInt16 nItemId, - const cssu::Reference& rxFrame); + const cssu::Reference& rxFrame, + const sal_Int32 nItemWidth = 0); void UpdateIcons ( const cssu::Reference& rxFrame); }; diff --git a/include/sfx2/sidebar/Tools.hxx b/include/sfx2/sidebar/Tools.hxx index 769cd04d10f4..db72103c6e94 100644 --- a/include/sfx2/sidebar/Tools.hxx +++ b/include/sfx2/sidebar/Tools.hxx @@ -60,6 +60,9 @@ public: static cssu::Reference GetDispatch ( const cssu::Reference& rxFrame, const css::util::URL& rURL); + + static ::rtl::OUString GetModuleName ( + const cssu::Reference& rxFrame); }; diff --git a/sfx2/source/sidebar/ControlFactory.cxx b/sfx2/source/sidebar/ControlFactory.cxx index 1a6f9a5e159f..3c0c02ae64cd 100644 --- a/sfx2/source/sidebar/ControlFactory.cxx +++ b/sfx2/source/sidebar/ControlFactory.cxx @@ -76,9 +76,10 @@ SidebarToolBox* ControlFactory::CreateToolBox ( Window* ControlFactory::CreateToolBoxBackground ( - Window* pParentWindow) + Window* pParentWindow, + const bool bShowBorder) { - ToolBoxBackground* pBorderWindow = new ToolBoxBackground(pParentWindow); + ToolBoxBackground* pBorderWindow = new ToolBoxBackground(pParentWindow, bShowBorder); pBorderWindow->Show(); return pBorderWindow; } diff --git a/sfx2/source/sidebar/ControllerFactory.cxx b/sfx2/source/sidebar/ControllerFactory.cxx index 7ce9eb8ea907..cc5fe34f09eb 100644 --- a/sfx2/source/sidebar/ControllerFactory.cxx +++ b/sfx2/source/sidebar/ControllerFactory.cxx @@ -22,10 +22,12 @@ #include #include +#include #include #include #include +#include using namespace css; @@ -39,17 +41,30 @@ Reference ControllerFactory::CreateToolBoxController( ToolBox* pToolBox, const sal_uInt16 nItemId, const OUString& rsCommandName, - const Reference& rxFrame) + const Reference& rxFrame, + const Reference& rxParentWindow, + const sal_Int32 nWidth) { + Reference xController ( + CreateToolBarController( + pToolBox, + rsCommandName, + rxFrame, + nWidth)); + // Create a controller for the new item. - Reference xController( - static_cast(::framework::CreateToolBoxController( - rxFrame, - pToolBox, - nItemId, - rsCommandName)), + if ( ! xController.is()) + { + xController.set( + static_cast(::framework::CreateToolBoxController( + rxFrame, + pToolBox, + nItemId, + rsCommandName)), UNO_QUERY); + } if ( ! xController.is()) + { xController.set( static_cast(new svt::GenericToolboxController( ::comphelper::getProcessComponentContext(), @@ -58,6 +73,7 @@ Reference ControllerFactory::CreateToolBoxController( nItemId, rsCommandName)), UNO_QUERY); + } // Initialize the controller with eg a service factory. Reference xInitialization (xController, UNO_QUERY); @@ -82,22 +98,104 @@ Reference ControllerFactory::CreateToolBoxController( xInitialization->initialize(aArgs); } - Reference xUpdatable (xController, UNO_QUERY); - if (xUpdatable.is()) - xUpdatable->update(); - - // Add label. if (xController.is()) { - const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( - rsCommandName, - rxFrame)); - pToolBox->SetQuickHelpText(nItemId, sLabel); - pToolBox->EnableItem(nItemId); + if (rxParentWindow.is()) + { + Reference xItemWindow (xController->createItemWindow(rxParentWindow)); + Window* pItemWindow = VCLUnoHelper::GetWindow(xItemWindow); + if (pItemWindow != NULL) + { + WindowType nType = pItemWindow->GetType(); + if (nType == WINDOW_LISTBOX || nType == WINDOW_MULTILISTBOX || nType == WINDOW_COMBOBOX) + pItemWindow->SetAccessibleName(pToolBox->GetItemText(nItemId)); + if (nWidth > 0) + pItemWindow->SetSizePixel(Size(nWidth, pItemWindow->GetSizePixel().Height())); + pToolBox->SetItemWindow(nItemId, pItemWindow); + } + } + + Reference xUpdatable (xController, UNO_QUERY); + if (xUpdatable.is()) + xUpdatable->update(); + + // Add label. + if (xController.is()) + { + const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( + rsCommandName, + rxFrame)); + pToolBox->SetQuickHelpText(nItemId, sLabel); + pToolBox->EnableItem(nItemId); + } } return xController; } + + +Reference ControllerFactory::CreateToolBarController( + ToolBox* pToolBox, + const OUString& rsCommandName, + const Reference& rxFrame, + const sal_Int32 nWidth) +{ + try + { + Reference xFactory ( + comphelper::getProcessServiceFactory()->createInstance(A2S("com.sun.star.frame.ToolbarControllerFactory")), + UNO_QUERY); + OUString sModuleName (Tools::GetModuleName(rxFrame)); + + if (xFactory.is() && xFactory->hasController(rsCommandName, sModuleName)) + { + beans::PropertyValue aPropValue; + std::vector aPropertyVector; + + aPropValue.Name = A2S("ModuleIdentifier"); + aPropValue.Value <<= sModuleName; + aPropertyVector.push_back( makeAny( aPropValue )); + + aPropValue.Name = A2S("Frame"); + aPropValue.Value <<= rxFrame; + aPropertyVector.push_back( makeAny( aPropValue )); + + aPropValue.Name = A2S("ServiceManager"); + aPropValue.Value <<= comphelper::getProcessServiceFactory(); + aPropertyVector.push_back( makeAny( aPropValue )); + + aPropValue.Name = A2S("ParentWindow"); + aPropValue.Value <<= VCLUnoHelper::GetInterface(pToolBox); + aPropertyVector.push_back( makeAny( aPropValue )); + + if (nWidth > 0) + { + aPropValue.Name = A2S("Width"); + aPropValue.Value <<= nWidth; + aPropertyVector.push_back( makeAny( aPropValue )); + } + + Reference xFactoryProperties (comphelper::getProcessServiceFactory(), UNO_QUERY); + Reference xComponentContext; + if (xFactoryProperties.is()) + xFactoryProperties->getPropertyValue(A2S("DefaultContext")) >>= xComponentContext; + + Sequence aArgs (comphelper::containerToSequence(aPropertyVector)); + return Reference( + xFactory->createInstanceWithArgumentsAndContext( + rsCommandName, + aArgs, + xComponentContext), + UNO_QUERY); + } + } + catch (Exception& rException) + { + // Ignore exception. + } + return NULL; +} + } } // end of namespace sfx2::sidebar diff --git a/sfx2/source/sidebar/ResourceManager.cxx b/sfx2/source/sidebar/ResourceManager.cxx index eaf4beac645f..2821293dd4d8 100644 --- a/sfx2/source/sidebar/ResourceManager.cxx +++ b/sfx2/source/sidebar/ResourceManager.cxx @@ -495,7 +495,7 @@ void ResourceManager::ReadContextList ( void ResourceManager::ReadLegacyAddons (const Reference& rxFrame) { // Get module name for given frame. - ::rtl::OUString sModuleName (GetModuleName(rxFrame)); + ::rtl::OUString sModuleName (Tools::GetModuleName(rxFrame)); if (sModuleName.getLength() == 0) return; if (maProcessedApplications.find(sModuleName) != maProcessedApplications.end()) @@ -586,30 +586,6 @@ void ResourceManager::StorePanelExpansionState ( -::rtl::OUString ResourceManager::GetModuleName ( - const cssu::Reference& rxFrame) -{ - if ( ! rxFrame.is() || ! rxFrame->getController().is()) - return OUString(); - - try - { - const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); - const Reference xModuleManager ( - aContext.createComponent("com.sun.star.frame.ModuleManager"), - UNO_QUERY_THROW); - return xModuleManager->identify(rxFrame); - } - catch (const Exception&) - { - DBG_UNHANDLED_EXCEPTION(); - } - return OUString(); -} - - - - ::utl::OConfigurationTreeRoot ResourceManager::GetLegacyAddonRootNode ( const ::rtl::OUString& rsModuleName) const { diff --git a/sfx2/source/sidebar/ResourceManager.hxx b/sfx2/source/sidebar/ResourceManager.hxx index e1b6e68afe21..8d617d9b16da 100644 --- a/sfx2/source/sidebar/ResourceManager.hxx +++ b/sfx2/source/sidebar/ResourceManager.hxx @@ -98,9 +98,6 @@ public: const bool bExpansionState, const Context& rContext); - static ::rtl::OUString GetModuleName ( - const cssu::Reference& rxFrame); - private: ResourceManager (void); ~ResourceManager (void); diff --git a/sfx2/source/sidebar/SidebarToolBox.cxx b/sfx2/source/sidebar/SidebarToolBox.cxx index 0fcf64e45fdf..d4aa7b6afe78 100644 --- a/sfx2/source/sidebar/SidebarToolBox.cxx +++ b/sfx2/source/sidebar/SidebarToolBox.cxx @@ -23,6 +23,7 @@ #include "sfx2/sidebar/Tools.hxx" #include +#include #include #include #include @@ -51,8 +52,15 @@ SidebarToolBox::SidebarToolBox ( if (rxFrame.is()) { const sal_uInt16 nItemCount (GetItemCount()); - for (sal_uInt16 nItemIndex=0; nItemIndex& rxFrame) + const cssu::Reference& rxFrame, + const sal_Int32 nItemWidth) { ItemDescriptor aDescriptor; @@ -225,13 +234,16 @@ void SidebarToolBox::CreateController ( this, nItemId, sCommandName, - rxFrame); - aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName); - aDescriptor.msCurrentCommand = sCommandName; - aDescriptor.mxDispatch = sfx2::sidebar::Tools::GetDispatch(rxFrame, aDescriptor.maURL); + rxFrame, + VCLUnoHelper::GetInterface(this), + nItemWidth); + if (aDescriptor.mxController.is()) + { + aDescriptor.maURL = sfx2::sidebar::Tools::GetURL(sCommandName); + aDescriptor.msCurrentCommand = sCommandName; - if (aDescriptor.mxController.is() && aDescriptor.mxDispatch.is()) maControllers.insert(::std::make_pair(nItemId, aDescriptor)); + } } diff --git a/sfx2/source/sidebar/ToolBoxBackground.cxx b/sfx2/source/sidebar/ToolBoxBackground.cxx index a5105c9f3f64..23c6af3ce4f5 100644 --- a/sfx2/source/sidebar/ToolBoxBackground.cxx +++ b/sfx2/source/sidebar/ToolBoxBackground.cxx @@ -28,10 +28,19 @@ namespace sfx2 { namespace sidebar { -ToolBoxBackground::ToolBoxBackground (Window* pParentWindow) +ToolBoxBackground::ToolBoxBackground ( + Window* pParentWindow, + const bool bShowBorder) : Window(pParentWindow, WB_DIALOGCONTROL), - maPadding(Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding))) + maPadding(bShowBorder + ? Tools::RectangleToSvBorder(Theme::GetRectangle(Theme::Rect_ToolBoxPadding)) + : SvBorder()) { + if (bShowBorder) + SetBackground(Theme::GetPaint(Theme::Paint_ToolBoxBackground).GetWallpaper()); + else + SetBackground(Wallpaper()); + #ifdef DEBUG SetText(A2S("ToolBoxBackground")); #endif diff --git a/sfx2/source/sidebar/ToolBoxBackground.hxx b/sfx2/source/sidebar/ToolBoxBackground.hxx index f1d1bdc62318..375e6d9ae57b 100644 --- a/sfx2/source/sidebar/ToolBoxBackground.hxx +++ b/sfx2/source/sidebar/ToolBoxBackground.hxx @@ -32,7 +32,9 @@ class ToolBoxBackground : public Window { public: - ToolBoxBackground (Window* pParentWindow); + ToolBoxBackground ( + Window* pParentWindow, + const bool bShowBorder); virtual ~ToolBoxBackground (void); /** Call this method once to diff --git a/sfx2/source/sidebar/Tools.cxx b/sfx2/source/sidebar/Tools.cxx index 881545864ae9..62c244cd6045 100644 --- a/sfx2/source/sidebar/Tools.cxx +++ b/sfx2/source/sidebar/Tools.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -179,4 +180,28 @@ Reference Tools::GetDispatch ( } + + +::rtl::OUString Tools::GetModuleName ( + const cssu::Reference& rxFrame) +{ + if ( ! rxFrame.is() || ! rxFrame->getController().is()) + return ::rtl::OUString(); + + try + { + const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); + const Reference xModuleManager ( + aContext.createComponent("com.sun.star.frame.ModuleManager"), + UNO_QUERY_THROW); + return xModuleManager->identify(rxFrame); + } + catch (const Exception&) + { + // Ignored. + } + return ::rtl::OUString(); +} + + } } // end of namespace sfx2::sidebar diff --git a/svx/source/sidebar/insert/InsertPropertyPanel.hxx b/svx/source/sidebar/insert/InsertPropertyPanel.hxx index 6f50d9308e0f..bd58a3a0f256 100644 --- a/svx/source/sidebar/insert/InsertPropertyPanel.hxx +++ b/svx/source/sidebar/insert/InsertPropertyPanel.hxx @@ -35,6 +35,8 @@ class ToolBox; namespace svx { namespace sidebar { +/** This panel provides buttons for inserting shapes into a document. +*/ class InsertPropertyPanel : public Control { -- cgit v1.2.3