1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
);
75 pToolbox
->InsertSeparator();
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
];
88 sImage
= vcl::CommandInfoProvider::GetImageForCommand(aAddonNotebookBarItem
.sCommandURL
,
93 if (aAddonNotebookBarItem
.sStyle
== STYLE_TEXT
)
94 pToolbox
->SetItemText(nItemId
, aAddonNotebookBarItem
.sLabel
);
95 else if (aAddonNotebookBarItem
.sStyle
== STYLE_ICON
)
96 pToolbox
->SetItemImage(nItemId
, sImage
);
99 pToolbox
->SetItemText(nItemId
, aAddonNotebookBarItem
.sLabel
);
100 pToolbox
->SetItemImage(nItemId
, sImage
);
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
:
121 std::as_const(aExtension
))
123 VclPtr
<vcl::Window
> pOptionalParent
;
124 pOptionalParent
= VclPtr
<OptionalBox
>::Create(pParent
);
125 pOptionalParent
->Show();
127 vcl::IPrioritable
* pPrioritable
128 = dynamic_cast<vcl::IPrioritable
*>(pOptionalParent
.get());
130 pPrioritable
->SetPriority(nPriorityIdx
- nIter
);
132 VclPtr
<vcl::Window
> pNotebookbarToolBox
;
133 pFunction(pNotebookbarToolBox
, pOptionalParent
, rMap
);
135 AddonNotebookBarItem aAddonNotebookBarItem
;
136 GetAddonNotebookBarItem(pExtension
, aAddonNotebookBarItem
);
138 CreateNotebookBarToolBox(pNotebookbarToolBox
, m_xFrame
, aAddonNotebookBarItem
,
145 void MergeNotebookBarMenuAddons(Menu
* pPopupMenu
, sal_Int16 nItemId
, const OUString
& sItemIdName
,
146 NotebookBarAddonsItem
& aNotebookBarAddonsItem
)
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
++)
153 aExtension
= aNotebookBarAddonsItem
.aAddonValues
[nIdx
];
155 for (int nSecIdx
= 0; nSecIdx
< aExtension
.getLength(); nSecIdx
++)
157 AddonNotebookBarItem aAddonNotebookBarItem
;
159 MenuItemBits nBits
= MenuItemBits::ICON
;
160 const css::uno::Sequence
<css::beans::PropertyValue
> pExtension
= aExtension
[nSecIdx
];
162 GetAddonNotebookBarItem(pExtension
, aAddonNotebookBarItem
);
164 pPopupMenu
->InsertItem(nItemId
, aAddonNotebookBarItem
.sLabel
, nBits
, sItemIdName
);
165 pPopupMenu
->SetItemCommand(nItemId
, aAddonNotebookBarItem
.sCommandURL
);
167 if (nIter
< aImageVec
.size())
169 sImage
= aImageVec
[nIter
];
172 pPopupMenu
->SetItemImage(nItemId
, sImage
);
174 if (nSecIdx
== aExtension
.getLength() - 1)
175 pPopupMenu
->InsertSeparator();
183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */