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 
32 const char STYLE_TEXT[] = "Text";
33 const char STYLE_ICON[] = "Icon";
34 
35 const char MERGE_NOTEBOOKBAR_URL[] = "URL";
36 const char MERGE_NOTEBOOKBAR_TITLE[] = "Title";
37 const char MERGE_NOTEBOOKBAR_CONTEXT[] = "Context";
38 const char MERGE_NOTEBOOKBAR_TARGET[] = "Target";
39 const char MERGE_NOTEBOOKBAR_CONTROLTYPE[] = "ControlType";
40 const char MERGE_NOTEBOOKBAR_WIDTH[] = "Width";
41 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 (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 
65 static 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->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
82  pToolbox->SetQuickHelpText(nItemId, aAddonNotebookBarItem.sLabel);
83 
84  if (nIter < aImageVec.size())
85  {
86  sImage = aImageVec[nIter];
87  if (!sImage)
88  {
89  sImage = vcl::CommandInfoProvider::GetImageForCommand(aAddonNotebookBarItem.sCommandURL,
90  m_xFrame);
91  }
92  }
93 
94  if (aAddonNotebookBarItem.sStyle == STYLE_TEXT)
95  pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
96  else if (aAddonNotebookBarItem.sStyle == STYLE_ICON)
97  pToolbox->SetItemImage(nItemId, sImage);
98  else
99  {
100  pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
101  pToolbox->SetItemImage(nItemId, sImage);
102  }
103  pToolbox->Show();
104 }
105 
107 {
109  const css::uno::Reference<css::frame::XFrame>& m_xFrame,
110  const NotebookBarAddonsItem& aNotebookBarAddonsItem,
111  VclBuilder::stringmap& rMap)
112 {
113  std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
114  tools::ULong nIter = 0;
115  sal_uInt16 nPriorityIdx = aImageVec.size();
116  css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
117  for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
118  {
119  aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
120 
121  for (const css::uno::Sequence<css::beans::PropertyValue>& pExtension :
122  std::as_const(aExtension))
123  {
124  VclPtr<vcl::Window> pOptionalParent;
125  pOptionalParent = VclPtr<OptionalBox>::Create(pParent);
126  pOptionalParent->Show();
127 
128  vcl::IPrioritable* pPrioritable
129  = dynamic_cast<vcl::IPrioritable*>(pOptionalParent.get());
130  if (pPrioritable)
131  pPrioritable->SetPriority(nPriorityIdx - nIter);
132 
133  VclPtr<vcl::Window> pNotebookbarToolBox;
134  pFunction(pNotebookbarToolBox, pOptionalParent, rMap);
135 
136  AddonNotebookBarItem aAddonNotebookBarItem;
137  GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
138 
139  CreateNotebookBarToolBox(pNotebookbarToolBox, m_xFrame, aAddonNotebookBarItem,
140  aImageVec, nIter);
141  nIter++;
142  }
143  }
144 }
145 
146 void MergeNotebookBarMenuAddons(Menu* pPopupMenu, sal_Int16 nItemId, const OString& sItemIdName,
147  NotebookBarAddonsItem& aNotebookBarAddonsItem)
148 {
149  std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
150  tools::ULong nIter = 0;
151  css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
152  for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
153  {
154  aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
155 
156  for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
157  {
158  AddonNotebookBarItem aAddonNotebookBarItem;
159  Image sImage;
161  const css::uno::Sequence<css::beans::PropertyValue> pExtension = aExtension[nSecIdx];
162 
163  GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
164 
165  pPopupMenu->InsertItem(nItemId, aAddonNotebookBarItem.sLabel, nBits, sItemIdName);
166  pPopupMenu->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
167 
168  if (nIter < aImageVec.size())
169  {
170  sImage = aImageVec[nIter];
171  nIter++;
172  }
173  pPopupMenu->SetItemImage(nItemId, sImage);
174 
175  if (nSecIdx == aExtension.getLength() - 1)
176  pPopupMenu->InsertSeparator();
177 
178  ++nItemId;
179  }
180  }
181 }
182 }
183 
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const char MERGE_NOTEBOOKBAR_TARGET[]
const char MERGE_NOTEBOOKBAR_CONTEXT[]
void SetItemImage(sal_uInt16 nItemId, const Image &rImage)
Definition: menu.cxx:1025
std::vector< css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > > aAddonValues
static void GetAddonNotebookBarItem(const css::uno::Sequence< css::beans::PropertyValue > &pExtension, AddonNotebookBarItem &aAddonNotebookBarItem)
MenuItemBits
Definition: vclenum.hxx:32
void MergeNotebookBarMenuAddons(Menu *pPopupMenu, sal_Int16 nItemId, const OString &sItemIdName, NotebookBarAddonsItem &aNotebookBarAddonsItem)
unsigned long ULong
void SetItemText(ToolBoxItemId nItemId, const OUString &rText)
Definition: toolbox2.cxx:1040
void SetItemCommand(sal_uInt16 nItemId, const OUString &rCommand)
Definition: menu.cxx:1051
const char MERGE_NOTEBOOKBAR_TITLE[]
void InsertSeparator(const OString &rIdent=OString(), sal_uInt16 nPos=MENU_APPEND)
Definition: menu.cxx:494
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:435
void MergeNotebookBarAddons(vcl::Window *pParent, const VclBuilder::customMakeWidget &pFunction, const css::uno::Reference< css::frame::XFrame > &m_xFrame, const NotebookBarAddonsItem &aNotebookBarAddonsItem, VclBuilder::stringmap &rMap)
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
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:72
int i
void SetQuickHelpText(ToolBoxItemId nItemId, const OUString &rText)
Definition: toolbox2.cxx:1343
void SetItemImage(ToolBoxItemId nItemId, const Image &rImage)
Definition: toolbox2.cxx:943
std::map< OString, OUString > stringmap
Definition: builder.hxx:69
std::vector< Image > aImageValues
const char STYLE_ICON[]
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:432
Definition: menu.hxx:123
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_URL[]
Definition: image.hxx:39
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:498
void SetItemCommand(ToolBoxItemId nItemId, const OUString &rCommand)
Definition: toolbox2.cxx:1325
const char MERGE_NOTEBOOKBAR_CONTROLTYPE[]
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
void SetPriority(int nPriority)
const char STYLE_TEXT[]
ToolBoxItemId GetItemId(ImplToolItems::size_type nPos) const
Definition: toolbox2.cxx:741
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2180