diff --git a/include/vcl/NotebookBarAddonsMerger.hxx b/include/vcl/NotebookBarAddonsMerger.hxx new file mode 100644 index 000000000000..c3b9998c7750 --- /dev/null +++ b/include/vcl/NotebookBarAddonsMerger.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_VCL_NOTEBOOKBARADDONSMERGER_HXX +#define INCLUDED_VCL_NOTEBOOKBARADDONSMERGER_HXX + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct NotebookBarAddonsItem +{ + Image aImage; + std::vector aImageValues; + std::vector>> aAddonValues; +}; + +struct AddonsParams +{ + OUString sImageId; + OUString sControlType; + sal_uInt16 nWidth; +}; + +struct AddonNotebookBarItem +{ + OUString sCommandURL; + OUString sLabel; + OUString sImageIdentifier; + OUString sTarget; + OUString sContext; + OUString sControlType; + sal_uInt16 nWidth; + OUString sStyle; +}; + +class NotebookBarAddonsMerger +{ +public: + NotebookBarAddonsMerger(vcl::Window* pParent, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem); + static void MergeNotebookBarAddons(vcl::Window* pParent, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 2fa8f445199f..adefc6d39713 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -67,18 +68,16 @@ public: typedef void (*customMakeWidget)(VclPtr &rRet, VclPtr &pParent, stringmap &rVec); public: - VclBuilder( - vcl::Window *pParent, - const OUString& sUIRootDir, - const OUString& sUIFile, - const OString& sID = OString(), - const css::uno::Reference &rFrame = css::uno::Reference(), - bool bLegacy = true); + VclBuilder(vcl::Window* pParent, const OUString& sUIRootDir, const OUString& sUIFile, + const OString& sID = OString(), + const css::uno::Reference& rFrame + = css::uno::Reference(), + bool bLegacy = true, + const NotebookBarAddonsItem& aNotebookBarAddonsItem = NotebookBarAddonsItem()); ~VclBuilder(); - ///releases references and disposes all children. void disposeBuilder(); - + NotebookBarAddonsItem m_pNotebookBarAddonsItem; //sID must exist and be of type T template T* get(VclPtr& ret, const OString& sID); diff --git a/include/vcl/notebookbar.hxx b/include/vcl/notebookbar.hxx index e7ed5c79dc44..4d69ced959b4 100644 --- a/include/vcl/notebookbar.hxx +++ b/include/vcl/notebookbar.hxx @@ -12,6 +12,7 @@ #include #include +#include #include #include @@ -25,7 +26,9 @@ class VCL_DLLPUBLIC NotebookBar : public Control, public VclBuilderContainer { friend class NotebookBarContextChangeEventListener; public: - NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference &rFrame); + NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem); virtual ~NotebookBar() override; virtual void dispose() override; diff --git a/include/vcl/syswin.hxx b/include/vcl/syswin.hxx index 22dd359e927b..402aebeb381e 100644 --- a/include/vcl/syswin.hxx +++ b/include/vcl/syswin.hxx @@ -27,6 +27,7 @@ #include #include #include +#include class MenuBar; class NotebookBar; @@ -217,6 +218,7 @@ public: void SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem, bool bReloadNotebookbar = false); void CloseNotebookBar(); diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index d1fb95dd730a..3b56156b7c2c 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -30,17 +30,51 @@ #include #include #include - +#include +#include +#include using namespace sfx2; using namespace css::uno; using namespace css::ui; using namespace css; #define MENUBAR_STR "private:resource/menubar/menubar" +static const char MERGE_NOTEBOOKBAR_IMAGEID[] = "ImageIdentifier"; bool SfxNotebookBar::m_bLock = false; bool SfxNotebookBar::m_bHide = false; +static void NotebookbarAddonValues( + std::vector& aImageValues, + std::vector>>& + aExtensionValues) +{ + framework::AddonsOptions aAddonsItems; + + for (int nIdx = 0; nIdx < aAddonsItems.GetAddonsNotebookBarCount(); nIdx++) + { + css::uno::Sequence> aExtension + = aAddonsItems.GetAddonsNotebookBarPart(nIdx); + for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++) + { + css::uno::Sequence pExtensionVal = aExtension[nSecIdx]; + Image aImage; + + for (int nRes = 0; nRes < pExtensionVal.getLength(); nRes++) + { + OUString sImage; + if (pExtensionVal[nRes].Name == MERGE_NOTEBOOKBAR_IMAGEID) + { + pExtensionVal[nRes].Value >>= sImage; + aImage = framework::AddonsOptions().GetImageFromURL(sImage, false); + } + } + aImageValues.push_back(aImage); + } + aExtensionValues.push_back(aExtension); + } +} + static Reference lcl_getLayoutManager( const Reference& xFrame ) { css::uno::Reference xLayoutManager; @@ -336,8 +370,16 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, OUStringBuffer aBuf(rUIFile); aBuf.append( sFile ); + //Addons For Notebookbar + std::vector aImageValues; + std::vector > > aExtensionValues; + NotebookBarAddonsItem aNotebookBarAddonsItem; + NotebookbarAddonValues(aImageValues , aExtensionValues); + aNotebookBarAddonsItem.aAddonValues = aExtensionValues; + aNotebookBarAddonsItem.aImageValues = aImageValues; + // setup if necessary - pSysWindow->SetNotebookBar(aBuf.makeStringAndClear(), xFrame, bReloadNotebookbar); + pSysWindow->SetNotebookBar(aBuf.makeStringAndClear(), xFrame, aNotebookBarAddonsItem , bReloadNotebookbar); pNotebookBar = pSysWindow->GetNotebookBar(); pNotebookBar->Show(); pNotebookBar->GetParent()->Resize(); diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 3540606d4b07..25f11f0cbaea 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -159,6 +159,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/window/mnemonicengine \ vcl/source/window/mouse \ vcl/source/window/msgbox \ + vcl/source/window/NotebookBarAddonsMerger \ vcl/source/window/popupmenuwindow \ vcl/source/window/printdlg \ vcl/source/window/scrwnd \ diff --git a/vcl/inc/brdwin.hxx b/vcl/inc/brdwin.hxx index 6a7fbcc2cada..0510006fa3ea 100644 --- a/vcl/inc/brdwin.hxx +++ b/vcl/inc/brdwin.hxx @@ -23,6 +23,7 @@ #include #include #include +#include #include @@ -152,8 +153,10 @@ public: void SetMenuBarWindow( vcl::Window* pWindow ); void SetMenuBarMode( bool bHide ); - void SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference& rFrame); - void CloseNotebookBar(); + void SetNotebookBar(const OUString& rUIXMLDescription, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem &aNotebookBarAddonsItem); + void CloseNotebookBar(); const VclPtr& GetNotebookBar() const { return mpNotebookBar; } void SetMinOutputSize( long nWidth, long nHeight ) diff --git a/vcl/source/control/notebookbar.cxx b/vcl/source/control/notebookbar.cxx index 8ea1a51d5989..5d960f1d81d6 100644 --- a/vcl/source/control/notebookbar.cxx +++ b/vcl/source/control/notebookbar.cxx @@ -51,17 +51,19 @@ public: virtual void SAL_CALL disposing(const ::css::lang::EventObject&) override; }; - - -NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, const css::uno::Reference &rFrame) - : Control(pParent), m_pEventListener(new NotebookBarContextChangeEventListener(this)) +NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem) + : Control(pParent) + , m_pEventListener(new NotebookBarContextChangeEventListener(this)) { SetStyle(GetStyle() | WB_DIALOGCONTROL); OUString sUIDir = getUIRootDir(); bool doesCustomizedUIExist = doesFileExist(getCustomizedUIRootDir(), rUIXMLDescription); if ( doesCustomizedUIExist ) sUIDir = getCustomizedUIRootDir(); - m_pUIBuilder.reset( new VclBuilder(this, sUIDir, rUIXMLDescription, rID, rFrame)); + m_pUIBuilder.reset( + new VclBuilder(this, sUIDir, rUIXMLDescription, rID, rFrame, true, aNotebookBarAddonsItem)); mxFrame = rFrame; // In the Notebookbar's .ui file must exist control handling context // - implementing NotebookbarContextControl interface with id "ContextContainer" diff --git a/vcl/source/window/NotebookBarAddonsMerger.cxx b/vcl/source/window/NotebookBarAddonsMerger.cxx new file mode 100644 index 000000000000..9bab4a4ea425 --- /dev/null +++ b/vcl/source/window/NotebookBarAddonsMerger.cxx @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include + +static const char MERGE_NOTEBOOKBAR_URL[] = "URL"; +static const char MERGE_NOTEBOOKBAR_TITLE[] = "Title"; +static const char MERGE_NOTEBOOKBAR_IMAGEID[] = "ImageIdentifier"; +static const char MERGE_NOTEBOOKBAR_CONTEXT[] = "Context"; +static const char MERGE_NOTEBOOKBAR_TARGET[] = "Target"; +static const char MERGE_NOTEBOOKBAR_CONTROLTYPE[] = "ControlType"; +static const char MERGE_NOTEBOOKBAR_WIDTH[] = "Width"; +static const char MERGE_NOTEBOOKBAR_STYLE[] = "Style"; + +NotebookBarAddonsMerger::NotebookBarAddonsMerger( + vcl::Window* pParent, const css::uno::Reference& m_xFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem) +{ + MergeNotebookBarAddons(pParent, m_xFrame, aNotebookBarAddonsItem); +} + +void NotebookBarAddonsMerger::MergeNotebookBarAddons( + vcl::Window* pParent, const css::uno::Reference& m_xFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem) +{ + std::vector aImageVec = aNotebookBarAddonsItem.aImageValues; + unsigned long nIter = 0; + css::uno::Sequence> aExtension; + for (unsigned long nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++) + { + aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx]; + + for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++) + { + AddonNotebookBarItem aAddonNotebookBarItem; + const css::uno::Sequence pExtension = aExtension[nSecIdx]; + for (int nRes = 0; nRes < pExtension.getLength(); nRes++) + { + if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_URL) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sCommandURL; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_TITLE) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sLabel; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_IMAGEID) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sImageIdentifier; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_CONTEXT) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sContext; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_TARGET) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sTarget; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_CONTROLTYPE) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sControlType; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_WIDTH) + pExtension[nRes].Value >>= aAddonNotebookBarItem.nWidth; + else if (pExtension[nRes].Name == MERGE_NOTEBOOKBAR_STYLE) + pExtension[nRes].Value >>= aAddonNotebookBarItem.sStyle; + } + + sal_uInt16 nItemId = 0; + ToolBox* pToolbox = dynamic_cast(pParent); + if (pToolbox) + { + Size aSize(0, 0); + pToolbox->InsertItem(aAddonNotebookBarItem.sCommandURL, m_xFrame, + ToolBoxItemBits::NONE, aSize); + nItemId = pToolbox->GetItemId(aAddonNotebookBarItem.sCommandURL); + pToolbox->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL); + pToolbox->SetQuickHelpText(nItemId, aAddonNotebookBarItem.sLabel); + pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel); + if (nIter < aImageVec.size()) + { + Image sImage = aImageVec[nIter]; + if (!sImage) + sImage = vcl::CommandInfoProvider::GetImageForCommand( + aAddonNotebookBarItem.sImageIdentifier, m_xFrame); + pToolbox->SetItemImage(nItemId, sImage); + } + nIter++; + } + pToolbox->InsertSeparator(); + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file diff --git a/vcl/source/window/brdwin.cxx b/vcl/source/window/brdwin.cxx index 6315b5dbc918..70976df86988 100644 --- a/vcl/source/window/brdwin.cxx +++ b/vcl/source/window/brdwin.cxx @@ -2015,11 +2015,14 @@ void ImplBorderWindow::SetMenuBarMode( bool bHide ) UpdateMenuHeight(); } -void ImplBorderWindow::SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference& rFrame) +void ImplBorderWindow::SetNotebookBar(const OUString& rUIXMLDescription, + const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem) { if (mpNotebookBar) mpNotebookBar.disposeAndClear(); - mpNotebookBar = VclPtr::Create(this, "NotebookBar", rUIXMLDescription, rFrame); + mpNotebookBar = VclPtr::Create(this, "NotebookBar", rUIXMLDescription, rFrame, + aNotebookBarAddonsItem); Resize(); } diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 835f056999fd..604d9950dece 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -399,8 +399,9 @@ namespace weld } } -VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUString& sUIFile, const OString& sID, - const css::uno::Reference& rFrame, bool bLegacy) +VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUString& sUIFile, + const OString& sID, const css::uno::Reference& rFrame, + bool bLegacy, const NotebookBarAddonsItem& aNotebookBarAddonsItem) : m_sID(sID) , m_sHelpRoot(OUStringToOString(sUIFile, RTL_TEXTENCODING_UTF8)) , m_pStringReplace(Translate::GetReadStringHook()) @@ -410,6 +411,7 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr , m_pParserState(new ParserState) , m_xFrame(rFrame) { + m_pNotebookBarAddonsItem = aNotebookBarAddonsItem; m_bToplevelHasDeferredInit = pParent && ((pParent->IsSystemWindow() && static_cast(pParent)->isDeferredInit()) || (pParent->IsDockingWindow() && static_cast(pParent)->isDeferredInit())); @@ -2168,6 +2170,11 @@ VclPtr VclBuilder::makeObject(vcl::Window *pParent, const OString & { xWindow = VclPtr::Create(pParent, WB_3DLOOK | WB_TABSTOP); } + else if (name == "NotebookBarAddonsMergePoint") + { + NotebookBarAddonsMerger aNotebookBarAddonsMerger(pParent,m_xFrame, m_pNotebookBarAddonsItem); + return nullptr; + } else if (name == "GtkToolButton" || name == "GtkMenuToolButton" || name == "GtkToggleToolButton" || name == "GtkRadioToolButton") { diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx index 59d3b2e97189..76d6a7c30b05 100644 --- a/vcl/source/window/syswin.cxx +++ b/vcl/source/window/syswin.cxx @@ -968,11 +968,13 @@ void SystemWindow::SetMenuBar(MenuBar* pMenuBar) void SystemWindow::SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference& rFrame, + const NotebookBarAddonsItem& aNotebookBarAddonsItem, bool bReloadNotebookbar) { if (rUIXMLDescription != maNotebookBarUIFile || bReloadNotebookbar) { - static_cast(mpWindowImpl->mpBorderWindow.get())->SetNotebookBar(rUIXMLDescription, rFrame); + static_cast(mpWindowImpl->mpBorderWindow.get()) + ->SetNotebookBar(rUIXMLDescription, rFrame, aNotebookBarAddonsItem); maNotebookBarUIFile = rUIXMLDescription; if(GetNotebookBar()) GetNotebookBar()->SetSystemWindow(this);