diff options
author | Jan Holesovsky <kendy@suse.cz> | 2013-05-30 18:25:09 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-06-05 10:06:49 +0100 |
commit | 0346a83833d2ed82715b0425abe36051cfb3f3a9 (patch) | |
tree | 478fa6552e140248338ba6b7911106b462528ddc /vcl | |
parent | e6354cc0752c5de0efefb9e3bdb9b196b205a73a (diff) |
sidebar: Allow creation of toolboxes using Widget layout / .ui.
Change-Id: Idc07614005a00401a51007b1a0aef00e17507daa
(cherry picked from commit 6fe1ff54c667a4f669feee6954dd9b859fd442b2)
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/window/builder.cxx | 34 | ||||
-rw-r--r-- | vcl/source/window/toolbox.cxx | 5 | ||||
-rw-r--r-- | vcl/source/window/toolbox2.cxx | 107 |
3 files changed, 143 insertions, 3 deletions
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 |