LibreOffice Module vcl (master) 1
NotebookBarAddonsMerger.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <sal/config.h>
21
22#include <cstddef>
23
26#include <vcl/menu.hxx>
27#include <vcl/vclenum.hxx>
28#include <vcl/toolbox.hxx>
29#include <IPrioritable.hxx>
30#include <OptionalBox.hxx>
31
32const char STYLE_TEXT[] = "Text";
33const char STYLE_ICON[] = "Icon";
34
35const char MERGE_NOTEBOOKBAR_URL[] = "URL";
36const char MERGE_NOTEBOOKBAR_TITLE[] = "Title";
37const char MERGE_NOTEBOOKBAR_CONTEXT[] = "Context";
38const char MERGE_NOTEBOOKBAR_TARGET[] = "Target";
39const char MERGE_NOTEBOOKBAR_CONTROLTYPE[] = "ControlType";
40const char MERGE_NOTEBOOKBAR_WIDTH[] = "Width";
41const char MERGE_NOTEBOOKBAR_STYLE[] = "Style";
42
43static void GetAddonNotebookBarItem(const css::uno::Sequence<css::beans::PropertyValue>& pExtension,
44 AddonNotebookBarItem& aAddonNotebookBarItem)
45{
46 for (const auto& i : pExtension)
47 {
48 if (i.Name == MERGE_NOTEBOOKBAR_URL)
49 i.Value >>= aAddonNotebookBarItem.sCommandURL;
50 else if (i.Name == MERGE_NOTEBOOKBAR_TITLE)
51 i.Value >>= aAddonNotebookBarItem.sLabel;
52 else if (i.Name == MERGE_NOTEBOOKBAR_CONTEXT)
53 i.Value >>= aAddonNotebookBarItem.sContext;
54 else if (i.Name == MERGE_NOTEBOOKBAR_TARGET)
55 i.Value >>= aAddonNotebookBarItem.sTarget;
56 else if (i.Name == MERGE_NOTEBOOKBAR_CONTROLTYPE)
57 i.Value >>= aAddonNotebookBarItem.sControlType;
58 else if (i.Name == MERGE_NOTEBOOKBAR_WIDTH)
59 i.Value >>= aAddonNotebookBarItem.nWidth;
60 else if (i.Name == MERGE_NOTEBOOKBAR_STYLE)
61 i.Value >>= aAddonNotebookBarItem.sStyle;
62 }
63}
64
65static void CreateNotebookBarToolBox(vcl::Window* pNotebookbarToolBox,
66 const css::uno::Reference<css::frame::XFrame>& m_xFrame,
67 const AddonNotebookBarItem& aAddonNotebookBarItem,
68 const std::vector<Image>& aImageVec, const tools::ULong nIter)
69{
70 ToolBoxItemId nItemId(0);
71 ToolBox* pToolbox = dynamic_cast<ToolBox*>(pNotebookbarToolBox);
72 if (!pToolbox)
73 return;
74
75 pToolbox->InsertSeparator();
76 pToolbox->Show();
77 Size aSize(0, 0);
78 Image sImage;
79 pToolbox->InsertItem(aAddonNotebookBarItem.sCommandURL, m_xFrame, ToolBoxItemBits::NONE, aSize);
80 nItemId = pToolbox->GetItemId(aAddonNotebookBarItem.sCommandURL);
81 pToolbox->SetQuickHelpText(nItemId, aAddonNotebookBarItem.sLabel);
82
83 if (nIter < aImageVec.size())
84 {
85 sImage = aImageVec[nIter];
86 if (!sImage)
87 {
88 sImage = vcl::CommandInfoProvider::GetImageForCommand(aAddonNotebookBarItem.sCommandURL,
89 m_xFrame);
90 }
91 }
92
93 if (aAddonNotebookBarItem.sStyle == STYLE_TEXT)
94 pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
95 else if (aAddonNotebookBarItem.sStyle == STYLE_ICON)
96 pToolbox->SetItemImage(nItemId, sImage);
97 else
98 {
99 pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
100 pToolbox->SetItemImage(nItemId, sImage);
101 }
102 pToolbox->Show();
103}
104
106{
108 const css::uno::Reference<css::frame::XFrame>& m_xFrame,
109 const NotebookBarAddonsItem& aNotebookBarAddonsItem,
111{
112 std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
113 tools::ULong nIter = 0;
114 sal_uInt16 nPriorityIdx = aImageVec.size();
115 css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
116 for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
117 {
118 aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
119
120 for (const css::uno::Sequence<css::beans::PropertyValue>& pExtension :
121 std::as_const(aExtension))
122 {
123 VclPtr<vcl::Window> pOptionalParent;
124 pOptionalParent = VclPtr<OptionalBox>::Create(pParent);
125 pOptionalParent->Show();
126
127 vcl::IPrioritable* pPrioritable
128 = dynamic_cast<vcl::IPrioritable*>(pOptionalParent.get());
129 if (pPrioritable)
130 pPrioritable->SetPriority(nPriorityIdx - nIter);
131
132 VclPtr<vcl::Window> pNotebookbarToolBox;
133 pFunction(pNotebookbarToolBox, pOptionalParent, rMap);
134
135 AddonNotebookBarItem aAddonNotebookBarItem;
136 GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
137
138 CreateNotebookBarToolBox(pNotebookbarToolBox, m_xFrame, aAddonNotebookBarItem,
139 aImageVec, nIter);
140 nIter++;
141 }
142 }
143}
144
145void MergeNotebookBarMenuAddons(Menu* pPopupMenu, sal_Int16 nItemId, const OUString& sItemIdName,
146 NotebookBarAddonsItem& aNotebookBarAddonsItem)
147{
148 std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
149 tools::ULong nIter = 0;
150 css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
151 for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
152 {
153 aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
154
155 for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
156 {
157 AddonNotebookBarItem aAddonNotebookBarItem;
158 Image sImage;
160 const css::uno::Sequence<css::beans::PropertyValue> pExtension = aExtension[nSecIdx];
161
162 GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
163
164 pPopupMenu->InsertItem(nItemId, aAddonNotebookBarItem.sLabel, nBits, sItemIdName);
165 pPopupMenu->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
166
167 if (nIter < aImageVec.size())
168 {
169 sImage = aImageVec[nIter];
170 nIter++;
171 }
172 pPopupMenu->SetItemImage(nItemId, sImage);
173
174 if (nSecIdx == aExtension.getLength() - 1)
175 pPopupMenu->InsertSeparator();
176
177 ++nItemId;
178 }
179 }
180}
181}
182
183/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char STYLE_ICON[]
const char MERGE_NOTEBOOKBAR_TARGET[]
const char MERGE_NOTEBOOKBAR_CONTEXT[]
const char MERGE_NOTEBOOKBAR_WIDTH[]
const char STYLE_TEXT[]
const char MERGE_NOTEBOOKBAR_STYLE[]
static void GetAddonNotebookBarItem(const css::uno::Sequence< css::beans::PropertyValue > &pExtension, AddonNotebookBarItem &aAddonNotebookBarItem)
const char MERGE_NOTEBOOKBAR_TITLE[]
static void CreateNotebookBarToolBox(vcl::Window *pNotebookbarToolBox, const css::uno::Reference< css::frame::XFrame > &m_xFrame, const AddonNotebookBarItem &aAddonNotebookBarItem, const std::vector< Image > &aImageVec, const tools::ULong nIter)
const char MERGE_NOTEBOOKBAR_CONTROLTYPE[]
const char MERGE_NOTEBOOKBAR_URL[]
css::uno::Reference< css::lang::XComponent > m_xFrame
Definition: image.hxx:40
Definition: menu.hxx:116
void SetItemImage(sal_uInt16 nItemId, const Image &rImage)
Definition: menu.cxx:1028
void InsertSeparator(const OUString &rIdent={}, sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:472
void SetItemCommand(sal_uInt16 nItemId, const OUString &rCommand)
Definition: menu.cxx:1054
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OUString &rIdent={}, sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:432
A toolbar: contains all those icons, typically below the menu bar.
Definition: toolbox.hxx:74
ToolBoxItemId GetItemId(ImplToolItems::size_type nPos) const
Definition: toolbox2.cxx:746
void SetQuickHelpText(ToolBoxItemId nItemId, const OUString &rText)
Definition: toolbox2.cxx:1321
void InsertSeparator(ImplToolItems::size_type nPos=APPEND, sal_uInt16 nPixSize=0)
Definition: toolbox2.cxx:503
virtual void InsertItem(const OUString &rCommand, const css::uno::Reference< css::frame::XFrame > &rFrame, ToolBoxItemBits nBits, const Size &rRequestedSize, ImplToolItems::size_type nPos=APPEND)
Insert a command (like '.uno:Save').
Definition: toolbox2.cxx:440
void SetItemText(ToolBoxItemId nItemId, const OUString &rText)
Definition: toolbox2.cxx:1018
void SetItemImage(ToolBoxItemId nItemId, const Image &rImage)
Definition: toolbox2.cxx:966
void(* customMakeWidget)(VclPtr< vcl::Window > &rRet, const VclPtr< vcl::Window > &pParent, stringmap &rVec)
These functions create a new widget with parent pParent and return it in rRet.
Definition: builder.hxx:74
std::map< OUString, OUString > stringmap
Definition: builder.hxx:71
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2187
void MergeNotebookBarAddons(vcl::Window *pParent, const VclBuilder::customMakeWidget &pFunction, const css::uno::Reference< css::frame::XFrame > &m_xFrame, const NotebookBarAddonsItem &aNotebookBarAddonsItem, VclBuilder::stringmap &rMap)
void MergeNotebookBarMenuAddons(Menu *pPopupMenu, sal_Int16 nItemId, const OUString &sItemIdName, NotebookBarAddonsItem &aNotebookBarAddonsItem)
int i
unsigned long ULong
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
std::vector< Image > aImageValues
std::vector< css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > > aAddonValues
MenuItemBits
Definition: vclenum.hxx:33