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/vclenum.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <vcl/OptionalBox.hxx>
29 #include <vcl/IPrioritable.hxx>
30 
31 static const char STYLE_TEXT[] = "Text";
32 static const char STYLE_ICON[] = "Icon";
33 
34 static const char MERGE_NOTEBOOKBAR_URL[] = "URL";
35 static const char MERGE_NOTEBOOKBAR_TITLE[] = "Title";
36 static const char MERGE_NOTEBOOKBAR_IMAGEID[] = "ImageIdentifier";
37 static const char MERGE_NOTEBOOKBAR_CONTEXT[] = "Context";
38 static const char MERGE_NOTEBOOKBAR_TARGET[] = "Target";
39 static const char MERGE_NOTEBOOKBAR_CONTROLTYPE[] = "ControlType";
40 static const char MERGE_NOTEBOOKBAR_WIDTH[] = "Width";
41 static const char MERGE_NOTEBOOKBAR_STYLE[] = "Style";
42 
43 static void GetAddonNotebookBarItem(const css::uno::Sequence<css::beans::PropertyValue>& pExtension,
44  AddonNotebookBarItem& aAddonNotebookBarItem)
45 {
46  for (int nIdx = 0; nIdx < pExtension.getLength(); nIdx++)
47  {
48  if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_URL)
49  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sCommandURL;
50  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_TITLE)
51  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sLabel;
52  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_IMAGEID)
53  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sImageIdentifier;
54  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_CONTEXT)
55  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sContext;
56  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_TARGET)
57  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sTarget;
58  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_CONTROLTYPE)
59  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sControlType;
60  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_WIDTH)
61  pExtension[nIdx].Value >>= aAddonNotebookBarItem.nWidth;
62  else if (pExtension[nIdx].Name == MERGE_NOTEBOOKBAR_STYLE)
63  pExtension[nIdx].Value >>= aAddonNotebookBarItem.sStyle;
64  }
65 }
66 
67 static void CreateNotebookBarToolBox(vcl::Window* pNotebookbarToolBox,
68  const css::uno::Reference<css::frame::XFrame>& m_xFrame,
69  const AddonNotebookBarItem& aAddonNotebookBarItem,
70  const std::vector<Image>& aImageVec,
71  const unsigned long& nIter)
72 {
73  sal_uInt16 nItemId = 0;
74  ToolBox* pToolbox = dynamic_cast<ToolBox*>(pNotebookbarToolBox);
75  if (pToolbox)
76  {
77  pToolbox->InsertSeparator();
78  pToolbox->Show();
79  Size aSize(0, 0);
80  Image sImage;
81  pToolbox->InsertItem(aAddonNotebookBarItem.sCommandURL, m_xFrame, ToolBoxItemBits::NONE,
82  aSize);
83  nItemId = pToolbox->GetItemId(aAddonNotebookBarItem.sCommandURL);
84  pToolbox->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
85  pToolbox->SetQuickHelpText(nItemId, aAddonNotebookBarItem.sLabel);
86 
87  if (nIter < aImageVec.size())
88  {
89  sImage = aImageVec[nIter];
90  if (!sImage)
91  {
93  aAddonNotebookBarItem.sImageIdentifier, m_xFrame);
94  }
95  }
96 
97  if (aAddonNotebookBarItem.sStyle == STYLE_TEXT)
98  pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
99  else if (aAddonNotebookBarItem.sStyle == STYLE_ICON)
100  pToolbox->SetItemImage(nItemId, sImage);
101  else
102  {
103  pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
104  pToolbox->SetItemImage(nItemId, sImage);
105  }
106  pToolbox->Show();
107  }
108 }
109 
111 
113 
115  vcl::Window* pParent, const VclBuilder::customMakeWidget& pFunction,
116  const css::uno::Reference<css::frame::XFrame>& m_xFrame,
117  const NotebookBarAddonsItem& aNotebookBarAddonsItem, VclBuilder::stringmap& rMap)
118 {
119  std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
120  unsigned long nIter = 0;
121  sal_uInt16 nPriorityIdx = aImageVec.size();
122  css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
123  for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
124  {
125  aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
126 
127  for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
128  {
129  VclPtr<vcl::Window> pOptionalParent;
130  pOptionalParent = VclPtr<OptionalBox>::Create(pParent);
131  pOptionalParent->Show();
132 
133  vcl::IPrioritable* pPrioritable
134  = dynamic_cast<vcl::IPrioritable*>(pOptionalParent.get());
135  if (pPrioritable)
136  pPrioritable->SetPriority(nPriorityIdx - nIter);
137 
138  VclPtr<vcl::Window> pNotebookbarToolBox;
139  pFunction(pNotebookbarToolBox, pOptionalParent, rMap);
140 
141  AddonNotebookBarItem aAddonNotebookBarItem;
142  const css::uno::Sequence<css::beans::PropertyValue> pExtension = aExtension[nSecIdx];
143  GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
144 
145  CreateNotebookBarToolBox(pNotebookbarToolBox, m_xFrame, aAddonNotebookBarItem,
146  aImageVec, nIter);
147  nIter++;
148  }
149  }
150 }
151 
153  Menu* pPopupMenu, sal_Int16 nItemId, const OString& sItemIdName,
154  NotebookBarAddonsItem& aNotebookBarAddonsItem)
155 {
156  std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
157  unsigned long nIter = 0;
158  css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
159  for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
160  {
161  aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
162 
163  for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
164  {
165  AddonNotebookBarItem aAddonNotebookBarItem;
166  Image sImage;
168  const css::uno::Sequence<css::beans::PropertyValue> pExtension = aExtension[nSecIdx];
169 
170  GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
171 
172  pPopupMenu->InsertItem(nItemId, aAddonNotebookBarItem.sLabel, nBits, sItemIdName);
173  pPopupMenu->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
174 
175  if (nIter < aImageVec.size())
176  {
177  sImage = aImageVec[nIter];
178  nIter++;
179  }
180  pPopupMenu->SetItemImage(nItemId, sImage);
181 
182  if (nSecIdx == aExtension.getLength() - 1)
183  pPopupMenu->InsertSeparator();
184 
185  ++nItemId;
186  }
187  }
188 }
189 
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const char MERGE_NOTEBOOKBAR_TARGET[]
static const char MERGE_NOTEBOOKBAR_CONTEXT[]
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
Definition: toolbox2.cxx:1356
void SetItemImage(sal_uInt16 nItemId, const Image &rImage)
Definition: menu.cxx:1012
std::vector< css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > > aAddonValues
void SetItemCommand(sal_uInt16 nItemId, const OUString &rCommand)
Definition: toolbox2.cxx:1338
static void GetAddonNotebookBarItem(const css::uno::Sequence< css::beans::PropertyValue > &pExtension, AddonNotebookBarItem &aAddonNotebookBarItem)
OUString Name
void SetItemText(sal_uInt16 nItemId, const OUString &rText)
Definition: toolbox2.cxx:1037
MenuItemBits
Definition: vclenum.hxx:32
void SetItemCommand(sal_uInt16 nItemId, const OUString &rCommand)
Definition: menu.cxx:1038
static const char MERGE_NOTEBOOKBAR_TITLE[]
void InsertSeparator(const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:481
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:421
static void MergeNotebookBarMenuAddons(Menu *pPopupMenu, sal_Int16 nItemId, const OString &sItemIdName, NotebookBarAddonsItem &aNotebookBarAddonsItem)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
static const char MERGE_NOTEBOOKBAR_WIDTH[]
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:69
std::map< OString, OUString > stringmap
Definition: builder.hxx:66
std::vector< Image > aImageValues
static const char STYLE_ICON[]
static void CreateNotebookBarToolBox(vcl::Window *pNotebookbarToolBox, const css::uno::Reference< css::frame::XFrame > &m_xFrame, const AddonNotebookBarItem &aAddonNotebookBarItem, const std::vector< Image > &aImageVec, const unsigned long &nIter)
static const char MERGE_NOTEBOOKBAR_STYLE[]
void InsertItem(sal_uInt16 nItemId, const OUString &rStr, MenuItemBits nItemBits=MenuItemBits::NONE, const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:420
Definition: menu.hxx:121
static const char MERGE_NOTEBOOKBAR_IMAGEID[]
static const char MERGE_NOTEBOOKBAR_URL[]
void SetItemImage(sal_uInt16 nItemId, const Image &rImage)
Definition: toolbox2.cxx:918
Definition: image.hxx:40
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
void InsertSeparator(ImplToolItems::size_type nPos=APPEND, sal_uInt16 nPixSize=0)
Definition: toolbox2.cxx:483
static const char MERGE_NOTEBOOKBAR_CONTROLTYPE[]
static void MergeNotebookBarAddons(vcl::Window *pParent, const VclBuilder::customMakeWidget &pFunction, const css::uno::Reference< css::frame::XFrame > &rFrame, const NotebookBarAddonsItem &aNotebookBarAddonsItem, VclBuilder::stringmap &rVec)
sal_uInt16 GetItemId(ImplToolItems::size_type nPos) const
Definition: toolbox2.cxx:726
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
void SetPriority(int nPriority)
static const char STYLE_TEXT[]
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2151