summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndre Fischer <af@apache.org>2013-05-16 11:43:55 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-05-22 11:34:39 +0100
commit52181e48798a9fdee6788f723d4ed0478ed40683 (patch)
tree66356ca761dc08932e3538a085112c46c26edcce
parent1fb5a19fa3c80b4a33d8ccffad2127ebc1c17542 (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 (cherry picked from commit edaca7c6e1d1ade6bf6cdae753028ee62297f0b1)
-rw-r--r--include/sfx2/sidebar/ControlFactory.hxx29
-rw-r--r--include/sfx2/sidebar/ControllerFactory.hxx16
-rw-r--r--include/sfx2/sidebar/SidebarToolBox.hxx4
-rw-r--r--include/sfx2/sidebar/Tools.hxx3
-rw-r--r--sfx2/source/sidebar/ControlFactory.cxx5
-rw-r--r--sfx2/source/sidebar/ControllerFactory.cxx132
-rw-r--r--sfx2/source/sidebar/ResourceManager.cxx26
-rw-r--r--sfx2/source/sidebar/ResourceManager.hxx3
-rw-r--r--sfx2/source/sidebar/SidebarToolBox.cxx28
-rw-r--r--sfx2/source/sidebar/ToolBoxBackground.cxx13
-rw-r--r--sfx2/source/sidebar/ToolBoxBackground.hxx4
-rw-r--r--sfx2/source/sidebar/Tools.cxx25
-rw-r--r--svx/source/sidebar/insert/InsertPropertyPanel.hxx2
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<com::sun::star::frame::XFrame>& 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 <TRUE/> 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 <com/sun/star/frame/XToolbarController.hpp>
+#include <com/sun/star/awt/XWindow.hpp>
#include <com/sun/star/frame/XFrame.hpp>
+#include <com/sun/star/frame/XToolbarController.hpp>
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<css::frame::XFrame>& rxFrame);
+ const cssu::Reference<css::frame::XFrame>& rxFrame,
+ const cssu::Reference<css::awt::XWindow>& rxParentWindow,
+ const sal_Int32 nItemWidth);
+
+private:
+ static cssu::Reference<css::frame::XToolbarController> CreateToolBarController(
+ ToolBox* pToolBox,
+ const ::rtl::OUString& rsCommandName,
+ const cssu::Reference<css::frame::XFrame>& 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<css::frame::XToolbarController> mxController;
css::util::URL maURL;
rtl::OUString msCurrentCommand;
- cssu::Reference<css::frame::XDispatch> mxDispatch;
};
typedef ::std::map<sal_uInt16, ItemDescriptor> ControllerContainer;
ControllerContainer maControllers;
@@ -90,7 +89,8 @@ private:
void CreateController (
const sal_uInt16 nItemId,
- const cssu::Reference<css::frame::XFrame>& rxFrame);
+ const cssu::Reference<css::frame::XFrame>& rxFrame,
+ const sal_Int32 nItemWidth = 0);
void UpdateIcons (
const cssu::Reference<css::frame::XFrame>& 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<css::frame::XDispatch> GetDispatch (
const cssu::Reference<css::frame::XFrame>& rxFrame,
const css::util::URL& rURL);
+
+ static ::rtl::OUString GetModuleName (
+ const cssu::Reference<css::frame::XFrame>& 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 <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
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
{