diff options
author | Andre Fischer <af@apache.org> | 2013-05-16 11:43:55 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-21 16:36:07 +0100 |
commit | edaca7c6e1d1ade6bf6cdae753028ee62297f0b1 (patch) | |
tree | 7d753b4337f8b993c3585fd4597a65e7672c2d49 /sfx2 | |
parent | aad035bd70b29253e9206de48259a9f0943bbc41 (diff) |
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
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/sidebar/ControlFactory.cxx | 5 | ||||
-rw-r--r-- | sfx2/source/sidebar/ControllerFactory.cxx | 132 | ||||
-rw-r--r-- | sfx2/source/sidebar/ResourceManager.cxx | 26 | ||||
-rw-r--r-- | sfx2/source/sidebar/ResourceManager.hxx | 3 | ||||
-rw-r--r-- | sfx2/source/sidebar/SidebarToolBox.cxx | 28 | ||||
-rw-r--r-- | sfx2/source/sidebar/ToolBoxBackground.cxx | 13 | ||||
-rw-r--r-- | sfx2/source/sidebar/ToolBoxBackground.hxx | 4 | ||||
-rw-r--r-- | sfx2/source/sidebar/Tools.cxx | 25 |
8 files changed, 178 insertions, 58 deletions
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 <com/sun/star/frame/XToolbarController.hpp> #include <com/sun/star/frame/XFrame.hpp> +#include <com/sun/star/frame/XUIControllerFactory.hpp> #include <framework/sfxhelperfunctions.hxx> #include <svtools/generictoolboxcontroller.hxx> #include <comphelper/processfactory.hxx> +#include <toolkit/helper/vclunohelper.hxx> using namespace css; @@ -39,17 +41,30 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( ToolBox* pToolBox, const sal_uInt16 nItemId, const OUString& rsCommandName, - const Reference<frame::XFrame>& rxFrame) + const Reference<frame::XFrame>& rxFrame, + const Reference<awt::XWindow>& rxParentWindow, + const sal_Int32 nWidth) { + Reference<frame::XToolbarController> xController ( + CreateToolBarController( + pToolBox, + rsCommandName, + rxFrame, + nWidth)); + // Create a controller for the new item. - Reference<frame::XToolbarController> xController( - static_cast<XWeak*>(::framework::CreateToolBoxController( - rxFrame, - pToolBox, - nItemId, - rsCommandName)), + if ( ! xController.is()) + { + xController.set( + static_cast<XWeak*>(::framework::CreateToolBoxController( + rxFrame, + pToolBox, + nItemId, + rsCommandName)), UNO_QUERY); + } if ( ! xController.is()) + { xController.set( static_cast<XWeak*>(new svt::GenericToolboxController( ::comphelper::getProcessComponentContext(), @@ -58,6 +73,7 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( nItemId, rsCommandName)), UNO_QUERY); + } // Initialize the controller with eg a service factory. Reference<lang::XInitialization> xInitialization (xController, UNO_QUERY); @@ -82,22 +98,104 @@ Reference<frame::XToolbarController> ControllerFactory::CreateToolBoxController( xInitialization->initialize(aArgs); } - Reference<util::XUpdatable> 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<awt::XWindow> 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<util::XUpdatable> 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<frame::XToolbarController> ControllerFactory::CreateToolBarController( + ToolBox* pToolBox, + const OUString& rsCommandName, + const Reference<frame::XFrame>& rxFrame, + const sal_Int32 nWidth) +{ + try + { + Reference<frame::XUIControllerFactory> 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<Any> 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<beans::XPropertySet> xFactoryProperties (comphelper::getProcessServiceFactory(), UNO_QUERY); + Reference<XComponentContext > xComponentContext; + if (xFactoryProperties.is()) + xFactoryProperties->getPropertyValue(A2S("DefaultContext")) >>= xComponentContext; + + Sequence<Any> aArgs (comphelper::containerToSequence(aPropertyVector)); + return Reference<frame::XToolbarController>( + 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<frame::XFrame>& 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<css::frame::XFrame>& rxFrame) -{ - if ( ! rxFrame.is() || ! rxFrame->getController().is()) - return OUString(); - - try - { - const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); - const Reference<frame::XModuleManager> 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<css::frame::XFrame>& 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 <vcl/gradient.hxx> +#include <toolkit/helper/vclunohelper.hxx> #include <svtools/miscopt.hxx> #include <framework/imageproducer.hxx> #include <com/sun/star/frame/XSubToolbarController.hpp> @@ -51,8 +52,15 @@ SidebarToolBox::SidebarToolBox ( if (rxFrame.is()) { const sal_uInt16 nItemCount (GetItemCount()); - for (sal_uInt16 nItemIndex=0; nItemIndex<nItemCount; ++nItemIndex) - CreateController(GetItemId(nItemIndex), rxFrame); + if (nItemCount == 1) + { + // When there is only one item then make that as wide as + // the tool box. + CreateController(GetItemId(0), rxFrame, GetSizePixel().Width()); + } + else + for (sal_uInt16 nItemIndex=0; nItemIndex<nItemCount; ++nItemIndex) + CreateController(GetItemId(nItemIndex), rxFrame, 0); UpdateIcons(rxFrame); SetSizePixel(CalcWindowSizePixel()); @@ -215,7 +223,8 @@ long SidebarToolBox::Notify (NotifyEvent& rEvent) void SidebarToolBox::CreateController ( const sal_uInt16 nItemId, - const cssu::Reference<css::frame::XFrame>& rxFrame) + const cssu::Reference<css::frame::XFrame>& 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 <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/graphic/XGraphicProvider.hpp> #include <com/sun/star/util/XURLTransformer.hpp> +#include <com/sun/star/frame/XModuleManager.hpp> #include <cstring> @@ -179,4 +180,28 @@ Reference<frame::XDispatch> Tools::GetDispatch ( } + + +::rtl::OUString Tools::GetModuleName ( + const cssu::Reference<css::frame::XFrame>& rxFrame) +{ + if ( ! rxFrame.is() || ! rxFrame->getController().is()) + return ::rtl::OUString(); + + try + { + const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); + const Reference<frame::XModuleManager> 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 |