tdf#130857 qt weld: Support "Java Start Parameters" dialog
[LibreOffice.git] / vcl / source / window / NotebookBarAddonsMerger.cxx
blobdf744aeca84b9a69811fdb06cbdd041aa8d6e2bf
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <cstddef>
24 #include <vcl/notebookbar/NotebookBarAddonsMerger.hxx>
25 #include <vcl/commandinfoprovider.hxx>
26 #include <vcl/menu.hxx>
27 #include <vcl/vclenum.hxx>
28 #include <vcl/toolbox.hxx>
29 #include <IPrioritable.hxx>
30 #include <OptionalBox.hxx>
32 const char STYLE_TEXT[] = "Text";
33 const char STYLE_ICON[] = "Icon";
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";
43 static void GetAddonNotebookBarItem(const css::uno::Sequence<css::beans::PropertyValue>& pExtension,
44 AddonNotebookBarItem& aAddonNotebookBarItem)
46 for (const auto& i : pExtension)
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;
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)
70 ToolBoxItemId nItemId(0);
71 ToolBox* pToolbox = dynamic_cast<ToolBox*>(pNotebookbarToolBox);
72 if (!pToolbox)
73 return;
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);
83 if (nIter < aImageVec.size())
85 sImage = aImageVec[nIter];
86 if (!sImage)
88 sImage = vcl::CommandInfoProvider::GetImageForCommand(aAddonNotebookBarItem.sCommandURL,
89 m_xFrame);
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
99 pToolbox->SetItemText(nItemId, aAddonNotebookBarItem.sLabel);
100 pToolbox->SetItemImage(nItemId, sImage);
102 pToolbox->Show();
105 namespace NotebookBarAddonsMerger
107 void MergeNotebookBarAddons(vcl::Window* pParent, const VclBuilder::customMakeWidget& pFunction,
108 const css::uno::Reference<css::frame::XFrame>& m_xFrame,
109 const NotebookBarAddonsItem& aNotebookBarAddonsItem,
110 VclBuilder::stringmap& rMap)
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++)
118 aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
120 for (const css::uno::Sequence<css::beans::PropertyValue>& pExtension : aExtension)
122 VclPtr<vcl::Window> pOptionalParent;
123 pOptionalParent = VclPtr<OptionalBox>::Create(pParent);
124 pOptionalParent->Show();
126 vcl::IPrioritable* pPrioritable
127 = dynamic_cast<vcl::IPrioritable*>(pOptionalParent.get());
128 if (pPrioritable)
129 pPrioritable->SetPriority(nPriorityIdx - nIter);
131 VclPtr<vcl::Window> pNotebookbarToolBox;
132 pFunction(pNotebookbarToolBox, pOptionalParent, rMap);
134 AddonNotebookBarItem aAddonNotebookBarItem;
135 GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
137 CreateNotebookBarToolBox(pNotebookbarToolBox, m_xFrame, aAddonNotebookBarItem,
138 aImageVec, nIter);
139 nIter++;
144 void MergeNotebookBarMenuAddons(Menu* pPopupMenu, sal_Int16 nItemId, const OUString& sItemIdName,
145 NotebookBarAddonsItem& aNotebookBarAddonsItem)
147 std::vector<Image> aImageVec = aNotebookBarAddonsItem.aImageValues;
148 tools::ULong nIter = 0;
149 css::uno::Sequence<css::uno::Sequence<css::beans::PropertyValue>> aExtension;
150 for (std::size_t nIdx = 0; nIdx < aNotebookBarAddonsItem.aAddonValues.size(); nIdx++)
152 aExtension = aNotebookBarAddonsItem.aAddonValues[nIdx];
154 for (int nSecIdx = 0; nSecIdx < aExtension.getLength(); nSecIdx++)
156 AddonNotebookBarItem aAddonNotebookBarItem;
157 Image sImage;
158 MenuItemBits nBits = MenuItemBits::ICON;
159 const css::uno::Sequence<css::beans::PropertyValue>& pExtension = aExtension[nSecIdx];
161 GetAddonNotebookBarItem(pExtension, aAddonNotebookBarItem);
163 pPopupMenu->InsertItem(nItemId, aAddonNotebookBarItem.sLabel, nBits, sItemIdName);
164 pPopupMenu->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
166 if (nIter < aImageVec.size())
168 sImage = aImageVec[nIter];
169 nIter++;
171 pPopupMenu->SetItemImage(nItemId, sImage);
173 if (nSecIdx == aExtension.getLength() - 1)
174 pPopupMenu->InsertSeparator();
176 ++nItemId;
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */