Engine to add Extension inside extension tab in NotebookBar

The patch provides backend for adding the extension.Schema for the
adding extension in notebookbar can be seen here
https://gerrit.libreoffice.org/#/c/75134/

Change-Id: I10f0e83d1aaec5330c80b3b53cf59a21b93be015
Reviewed-on: https://gerrit.libreoffice.org/75650
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
This commit is contained in:
Sumit Chauhan 2019-07-15 22:19:00 +05:30 committed by Szymon Kłos
parent 147e820cc1
commit fbcd5f074c
12 changed files with 261 additions and 24 deletions

View File

@ -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 <vcl/dllapi.h>
#include <vcl/window.hxx>
#include <vcl/vclptr.hxx>
#include <vcl/image.hxx>
#include <com/sun/star/beans/PropertyValue.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/uno/Sequence.h>
#include <memory>
#include <vector>
struct NotebookBarAddonsItem
{
Image aImage;
std::vector<Image> aImageValues;
std::vector<css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>>> 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<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem);
static void MergeNotebookBarAddons(vcl::Window* pParent,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem);
};
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@ -15,6 +15,7 @@
#include <unotools/resmgr.hxx>
#include <tools/fldunit.hxx>
#include <vcl/dllapi.h>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <vcl/window.hxx>
#include <vcl/vclptr.hxx>
#include <tools/wintypes.hxx>
@ -67,18 +68,16 @@ public:
typedef void (*customMakeWidget)(VclPtr<vcl::Window> &rRet, VclPtr<vcl::Window> &pParent, stringmap &rVec);
public:
VclBuilder(
vcl::Window *pParent,
const OUString& sUIRootDir,
const OUString& sUIFile,
const OString& sID = OString(),
const css::uno::Reference<css::frame::XFrame> &rFrame = css::uno::Reference<css::frame::XFrame>(),
bool bLegacy = true);
VclBuilder(vcl::Window* pParent, const OUString& sUIRootDir, const OUString& sUIFile,
const OString& sID = OString(),
const css::uno::Reference<css::frame::XFrame>& rFrame
= css::uno::Reference<css::frame::XFrame>(),
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 <typename T> T* get(VclPtr<T>& ret, const OString& sID);

View File

@ -12,6 +12,7 @@
#include <vcl/builder.hxx>
#include <vcl/ctrl.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <vcl/settings.hxx>
#include <vector>
@ -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<css::frame::XFrame> &rFrame);
NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem);
virtual ~NotebookBar() override;
virtual void dispose() override;

View File

@ -27,6 +27,7 @@
#include <vcl/window.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <memory>
#include <vcl/NotebookBarAddonsMerger.hxx>
class MenuBar;
class NotebookBar;
@ -217,6 +218,7 @@ public:
void SetNotebookBar(const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem,
bool bReloadNotebookbar = false);
void CloseNotebookBar();

View File

@ -30,17 +30,51 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <unotools/confignode.hxx>
#include <comphelper/types.hxx>
#include <framework/addonsoptions.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <vector>
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<Image>& aImageValues,
std::vector<css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>>>&
aExtensionValues)
{
framework::AddonsOptions aAddonsItems;
for (int nIdx = 0; nIdx < aAddonsItems.GetAddonsNotebookBarCount(); nIdx++)
{
css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension
= aAddonsItems.GetAddonsNotebookBarPart(nIdx);
for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
{
css::uno::Sequence<css::beans::PropertyValue> 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<frame::XLayoutManager> lcl_getLayoutManager( const Reference<frame::XFrame>& xFrame )
{
css::uno::Reference<css::frame::XLayoutManager> xLayoutManager;
@ -336,8 +370,16 @@ bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow,
OUStringBuffer aBuf(rUIFile);
aBuf.append( sFile );
//Addons For Notebookbar
std::vector<Image> aImageValues;
std::vector<css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > > 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();

View File

@ -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 \

View File

@ -23,6 +23,7 @@
#include <vcl/notebookbar.hxx>
#include <vcl/window.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <vcl/NotebookBarAddonsMerger.hxx>
#include <com/sun/star/frame/XFrame.hpp>
@ -152,8 +153,10 @@ public:
void SetMenuBarWindow( vcl::Window* pWindow );
void SetMenuBarMode( bool bHide );
void SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame>& rFrame);
void CloseNotebookBar();
void SetNotebookBar(const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem &aNotebookBarAddonsItem);
void CloseNotebookBar();
const VclPtr<NotebookBar>& GetNotebookBar() const { return mpNotebookBar; }
void SetMinOutputSize( long nWidth, long nHeight )

View File

@ -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<css::frame::XFrame> &rFrame)
: Control(pParent), m_pEventListener(new NotebookBarContextChangeEventListener(this))
NotebookBar::NotebookBar(Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& 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"

View File

@ -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 <vcl/NotebookBarAddonsMerger.hxx>
#include <vcl/commandinfoprovider.hxx>
#include <vcl/toolbox.hxx>
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<css::frame::XFrame>& m_xFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem)
{
MergeNotebookBarAddons(pParent, m_xFrame, aNotebookBarAddonsItem);
}
void NotebookBarAddonsMerger::MergeNotebookBarAddons(
vcl::Window* pParent, const css::uno::Reference<css::frame::XFrame>& m_xFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem)
{
std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
unsigned long nIter = 0;
css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> 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<css::beans::PropertyValue> 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<ToolBox*>(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: */

View File

@ -2015,11 +2015,14 @@ void ImplBorderWindow::SetMenuBarMode( bool bHide )
UpdateMenuHeight();
}
void ImplBorderWindow::SetNotebookBar(const OUString& rUIXMLDescription, const css::uno::Reference<css::frame::XFrame>& rFrame)
void ImplBorderWindow::SetNotebookBar(const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem)
{
if (mpNotebookBar)
mpNotebookBar.disposeAndClear();
mpNotebookBar = VclPtr<NotebookBar>::Create(this, "NotebookBar", rUIXMLDescription, rFrame);
mpNotebookBar = VclPtr<NotebookBar>::Create(this, "NotebookBar", rUIXMLDescription, rFrame,
aNotebookBarAddonsItem);
Resize();
}

View File

@ -399,8 +399,9 @@ namespace weld
}
}
VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUString& sUIFile, const OString& sID,
const css::uno::Reference<css::frame::XFrame>& rFrame, bool bLegacy)
VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUString& sUIFile,
const OString& sID, const css::uno::Reference<css::frame::XFrame>& 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<SystemWindow*>(pParent)->isDeferredInit()) ||
(pParent->IsDockingWindow() && static_cast<DockingWindow*>(pParent)->isDeferredInit()));
@ -2168,6 +2170,11 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OString &
{
xWindow = VclPtr<ToolBox>::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")
{

View File

@ -968,11 +968,13 @@ void SystemWindow::SetMenuBar(MenuBar* pMenuBar)
void SystemWindow::SetNotebookBar(const OUString& rUIXMLDescription,
const css::uno::Reference<css::frame::XFrame>& rFrame,
const NotebookBarAddonsItem& aNotebookBarAddonsItem,
bool bReloadNotebookbar)
{
if (rUIXMLDescription != maNotebookBarUIFile || bReloadNotebookbar)
{
static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())->SetNotebookBar(rUIXMLDescription, rFrame);
static_cast<ImplBorderWindow*>(mpWindowImpl->mpBorderWindow.get())
->SetNotebookBar(rUIXMLDescription, rFrame, aNotebookBarAddonsItem);
maNotebookBarUIFile = rUIXMLDescription;
if(GetNotebookBar())
GetNotebookBar()->SetSystemWindow(this);