summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2013-05-30 18:25:09 +0200
committerJan Holesovsky <kendy@suse.cz>2013-06-02 04:54:54 +0200
commit6fe1ff54c667a4f669feee6954dd9b859fd442b2 (patch)
tree25076e5502ad6cbf44ffff9406887e9dfc4485cf
parent4f14ed6d346a488976262e69fdbc2fd21881b659 (diff)
sidebar: Allow creation of toolboxes using Widget layout / .ui.
Change-Id: Idc07614005a00401a51007b1a0aef00e17507daa
-rw-r--r--include/svx/sidebar/PanelLayout.hxx5
-rw-r--r--include/vcl/builder.hxx9
-rw-r--r--include/vcl/toolbox.hxx12
-rw-r--r--svx/source/sidebar/PanelLayout.cxx4
-rw-r--r--vcl/source/window/builder.cxx34
-rw-r--r--vcl/source/window/toolbox.cxx5
-rw-r--r--vcl/source/window/toolbox2.cxx107
7 files changed, 168 insertions, 8 deletions
diff --git a/include/svx/sidebar/PanelLayout.hxx b/include/svx/sidebar/PanelLayout.hxx
index c29f6b90f4ed..3395e7f9aab7 100644
--- a/include/svx/sidebar/PanelLayout.hxx
+++ b/include/svx/sidebar/PanelLayout.hxx
@@ -15,11 +15,14 @@
#include <vcl/builder.hxx>
#include <vcl/ctrl.hxx>
+#include <com/sun/star/frame/XFrame.hpp>
+
/// This class is the base for the Widget Layout-based sidebar panels.
class SVX_DLLPUBLIC PanelLayout : public Control, public VclBuilderContainer
{
public:
- PanelLayout(Window* pParent, const OString& rID, const OUString& rUIXMLDescription);
+ PanelLayout(Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
+ const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> &rFrame);
virtual ~PanelLayout() {}
virtual Size GetOptimalSize() const;
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 31a82418447a..d699d504278d 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -23,6 +23,8 @@
#include <boost/noncopyable.hpp>
#include <boost/ptr_container/ptr_map.hpp>
+#include <com/sun/star/frame/XFrame.hpp>
+
class ListBox;
class NumericFormatter;
class PopupMenu;
@@ -235,8 +237,13 @@ private:
}
bool operator()(const Window *pA, const Window *pB) const;
};
+
+ /// XFrame to be able to extract labels and other properties of the UNO commands (like of .uno:Bold).
+ com::sun::star::uno::Reference<com::sun::star::frame::XFrame> m_xFrame;
+
public:
- VclBuilder(Window *pParent, OUString sUIRootDir, OUString sUIFile, OString sID = OString());
+ VclBuilder(Window *pParent, OUString sUIRootDir, OUString sUIFile, OString sID = OString(),
+ const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> &rFrame = com::sun::star::uno::Reference<com::sun::star::frame::XFrame>());
~VclBuilder();
Window *get_widget_root();
//sID must exist and be of type T
diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx
index 3b1f69e36477..501eeedb6ac1 100644
--- a/include/vcl/toolbox.hxx
+++ b/include/vcl/toolbox.hxx
@@ -28,6 +28,8 @@
#include <vcl/timer.hxx>
#include <vector>
+#include <com/sun/star/frame/XFrame.hpp>
+
class UserDrawEvent;
struct ImplToolItem;
@@ -333,9 +335,15 @@ public:
virtual sal_Bool Docking( const Point& rPos, Rectangle& rRect );
virtual void EndDocking( const Rectangle& rRect, sal_Bool bFloatMode );
virtual void Resizing( Size& rSize );
+ virtual Size GetOptimalSize() const;
void InsertItem( const ResId& rResId,
sal_uInt16 nPos = TOOLBOX_APPEND );
+ /// Insert a command (like '.uno:Save').
+ void InsertItem( const OUString& rCommand,
+ const com::sun::star::uno::Reference<com::sun::star::frame::XFrame>& rFrame,
+ ToolBoxItemBits nBits = 0,
+ sal_uInt16 nPos = TOOLBOX_APPEND );
void InsertItem( sal_uInt16 nItemId, const Image& rImage,
ToolBoxItemBits nBits = 0,
sal_uInt16 nPos = TOOLBOX_APPEND );
@@ -386,10 +394,12 @@ public:
sal_uInt16 GetItemPos( const Point& rPos ) const;
sal_uInt16 GetItemId( sal_uInt16 nPos ) const;
sal_uInt16 GetItemId( const Point& rPos ) const;
+ /// Map the command name (like .uno:Save) back to item id.
+ sal_uInt16 GetItemId( const OUString& rCommand ) const;
Rectangle GetItemRect( sal_uInt16 nItemId ) const;
Rectangle GetItemPosRect( sal_uInt16 nPos ) const;
- // retrieves the optimal position to place a popup window for this item (subtoolbar or dropdown)
+ /// Retrieves the optimal position to place a popup window for this item (subtoolbar or dropdown)
Point GetItemPopupPosition( sal_uInt16 nItemId, const Size& rSize ) const;
Rectangle GetScrollRect() const;
diff --git a/svx/source/sidebar/PanelLayout.cxx b/svx/source/sidebar/PanelLayout.cxx
index 17c1e30e9a78..03ff1305570d 100644
--- a/svx/source/sidebar/PanelLayout.cxx
+++ b/svx/source/sidebar/PanelLayout.cxx
@@ -10,10 +10,10 @@
#include <svx/sidebar/PanelLayout.hxx>
#include <vcl/layout.hxx>
-PanelLayout::PanelLayout(Window* pParent, const OString& rID, const OUString& rUIXMLDescription)
+PanelLayout::PanelLayout(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const com::sun::star::uno::Reference<com::sun::star::frame::XFrame> &rFrame)
: Control(pParent)
{
- m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
+ m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID, rFrame);
}
Size PanelLayout::GetOptimalSize() const
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 3a584084652e..380c5e663357 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -26,11 +26,14 @@
#include <vcl/svapp.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabpage.hxx>
+#include <vcl/toolbox.hxx>
#include <vcl/vclmedit.hxx>
#include <svdata.hxx>
#include <svids.hrc>
#include <window.h>
+using namespace com::sun::star;
+
#ifdef DISABLE_DYNLOADING
#include <dlfcn.h> // For RTLD_DEFAULT
#endif
@@ -135,13 +138,14 @@ namespace
}
#endif
-VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OString sID)
+VclBuilder::VclBuilder(Window *pParent, OUString sUIDir, OUString sUIFile, OString sID, const uno::Reference<frame::XFrame>& rFrame)
: m_sID(sID)
, m_sHelpRoot(OUStringToOString(sUIFile, RTL_TEXTENCODING_UTF8))
, m_pStringReplace(ResMgr::GetReadStringHook())
, m_pParent(pParent)
, m_bToplevelParentFound(false)
, m_pParserState(new ParserState)
+ , m_xFrame(rFrame)
{
m_bToplevelHasDeferredInit = (pParent && pParent->IsDialog()) ? ((Dialog*)pParent)->isDeferredInit() : false;
m_bToplevelHasDeferredProperties = m_bToplevelHasDeferredInit;
@@ -617,6 +621,18 @@ namespace
return sType;
}
+ OString extractActionName(VclBuilder::stringmap &rMap)
+ {
+ OString sActionName;
+ VclBuilder::stringmap::iterator aFind = rMap.find(OString("action-name"));
+ if (aFind != rMap.end())
+ {
+ sActionName = aFind->second;
+ rMap.erase(aFind);
+ }
+ return sActionName;
+ }
+
Window * extractStockAndBuildPushButton(Window *pParent, VclBuilder::stringmap &rMap)
{
WinBits nBits = WB_CENTER|WB_VCENTER|WB_3DLOOK;
@@ -1209,6 +1225,22 @@ Window *VclBuilder::makeObject(Window *pParent, const OString &name, const OStri
if (pRealParent != pParent)
cleanupWidgetOwnScrolling(pParent, pWindow, rMap);
}
+ else if (name == "GtkToolbar")
+ {
+ pWindow = new ToolBox(pParent, WB_3DLOOK | WB_TABSTOP);
+ }
+ else if (name == "GtkToolButton")
+ {
+ ToolBox *pToolBox = dynamic_cast<ToolBox*>(pParent);
+ if (pToolBox)
+ {
+ OUString aCommand(OStringToOUString(extractActionName(rMap), RTL_TEXTENCODING_UTF8));
+ if (!aCommand.isEmpty())
+ pToolBox->InsertItem(aCommand, m_xFrame);
+
+ return NULL; // no widget to be created
+ }
+ }
else
{
sal_Int32 nDelim = name.indexOf('-');
diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx
index 73b4d2132b24..7582fcedd78e 100644
--- a/vcl/source/window/toolbox.cxx
+++ b/vcl/source/window/toolbox.cxx
@@ -4777,7 +4777,10 @@ void ToolBox::Resizing( Size& rSize )
mnLastResizeDY = rSize.Height();
}
-// -----------------------------------------------------------------------
+Size ToolBox::GetOptimalSize() const
+{
+ return ImplCalcSize( this, mnLines );
+}
Size ToolBox::CalcWindowSizePixel( sal_uInt16 nCalcLines ) const
{
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx
index c90b075c3c79..7c671fbf4df8 100644
--- a/vcl/source/window/toolbox2.cxx
+++ b/vcl/source/window/toolbox2.cxx
@@ -38,10 +38,18 @@
#include <unotools/confignode.hxx>
+#include <com/sun/star/frame/ModuleManager.hpp>
+#include <com/sun/star/frame/UICommandDescription.hpp>
+#include <com/sun/star/frame/XModuleManager2.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
+#include <com/sun/star/ui/ImageType.hpp>
+#include <com/sun/star/ui/ModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/XImageManager.hpp>
+#include <com/sun/star/ui/XModuleUIConfigurationManagerSupplier.hpp>
+#include <com/sun/star/ui/XUIConfigurationManager.hpp>
using namespace vcl;
-
+using namespace com::sun::star;
// =======================================================================
@@ -652,6 +660,92 @@ void ToolBox::InsertItem( sal_uInt16 nItemId, const XubString& rText,
ImplCallEventListeners( VCLEVENT_TOOLBOX_ITEMADDED, reinterpret_cast< void* >( nNewPos ) );
}
+/// Get label of the command (like of .uno:Save) from the description service.
+static OUString getCommandLabel(const OUString& rCommand, const uno::Reference<uno::XComponentContext>& rContext, const OUString& rModuleId)
+{
+ if (rCommand.isEmpty())
+ return OUString();
+
+ try
+ {
+ uno::Reference<container::XNameAccess> xUICommandLabels;
+ uno::Reference<container::XNameAccess> xUICommandDescription(frame::UICommandDescription::create(rContext));
+
+ if ((xUICommandDescription->getByName(rModuleId) >>= xUICommandLabels) && xUICommandLabels.is())
+ {
+ uno::Sequence<beans::PropertyValue> aProperties;
+ if (xUICommandLabels->getByName(rCommand) >>= aProperties)
+ {
+ for ( sal_Int32 i = 0; i < aProperties.getLength(); i++ )
+ {
+ if (aProperties[i].Name == "Label")
+ {
+ OUString aLabel;
+ if (aProperties[i].Value >>= aLabel)
+ return aLabel;
+ }
+ }
+ }
+ }
+ }
+ catch (uno::Exception&)
+ {
+ }
+
+ return OUString();
+}
+
+
+/// Get label of the command (like of .uno:Save) from the description service.
+static Image getCommandImage(const OUString& rCommand, bool bLarge, const uno::Reference<uno::XComponentContext>& rContext, const OUString& rModuleId)
+{
+ if (rCommand.isEmpty())
+ return Image();
+
+ try {
+ uno::Reference<ui::XModuleUIConfigurationManagerSupplier> xModuleCfgMgrSupplier(ui::ModuleUIConfigurationManagerSupplier::create(rContext));
+ uno::Reference<ui::XUIConfigurationManager> xUICfgMgr(xModuleCfgMgrSupplier->getUIConfigurationManager(rModuleId));
+
+ uno::Sequence< uno::Reference<graphic::XGraphic> > aGraphicSeq;
+ uno::Reference<ui::XImageManager> xModuleImageManager(xUICfgMgr->getImageManager(), uno::UNO_QUERY);
+
+ uno::Sequence<OUString> aImageCmdSeq(1);
+ aImageCmdSeq[0] = rCommand;
+
+ sal_Int16 nImageType(ui::ImageType::COLOR_NORMAL | ui::ImageType::SIZE_DEFAULT);
+ if (bLarge)
+ nImageType |= ui::ImageType::SIZE_LARGE;
+
+ aGraphicSeq = xModuleImageManager->getImages(nImageType, aImageCmdSeq);
+
+ uno::Reference<graphic::XGraphic> xGraphic(aGraphicSeq[0]);
+
+ return Image(xGraphic);
+ }
+ catch (uno::Exception&)
+ {
+ }
+
+ return Image();
+}
+
+void ToolBox::InsertItem(const OUString& rCommand, const uno::Reference<frame::XFrame>& rFrame, ToolBoxItemBits nBits, sal_uInt16 nPos)
+{
+ uno::Reference<uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
+ uno::Reference<frame::XModuleManager2> xModuleManager(frame::ModuleManager::create(xContext));
+ OUString aModuleId(xModuleManager->identify(rFrame));
+
+ OUString aLabel(getCommandLabel(rCommand, xContext, aModuleId));
+ Image aImage(getCommandImage(rCommand, false /*FIXME large or small?*/, xContext, aModuleId));
+
+ // let's invent an ItemId
+ const sal_uInt16 COMMAND_ITEMID_START = 30000;
+ sal_uInt16 nItemId = COMMAND_ITEMID_START + GetItemCount();
+
+ InsertItem(nItemId, aImage, aLabel, nBits, nPos);
+ SetItemCommand(nItemId, rCommand);
+}
+
// -----------------------------------------------------------------------
void ToolBox::InsertWindow( sal_uInt16 nItemId, Window* pWindow,
@@ -1012,6 +1106,17 @@ sal_uInt16 ToolBox::GetItemId( const Point& rPos ) const
return 0;
}
+sal_uInt16 ToolBox::GetItemId(const OUString &rCommand) const
+{
+ for (std::vector<ImplToolItem>::const_iterator it = mpData->m_aItems.begin(); it != mpData->m_aItems.end(); ++it)
+ {
+ if (it->maCommandStr == rCommand)
+ return it->mnId;
+ }
+
+ return 0;
+}
+
// -----------------------------------------------------------------------
Point ToolBox::ImplGetPopupPosition( const Rectangle& rRect, const Size& rSize ) const