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/NotebookBarAddonsMerger.hxx>
25 #include <vcl/commandinfoprovider.hxx>
26 #include <vcl/vclenum.hxx>
27 #include <vcl/toolbox.hxx>
28 #include <vcl/OptionalBox.hxx>
29 #include <vcl/IPrioritable.hxx>
31 static const char STYLE_TEXT
[] = "Text";
32 static const char STYLE_ICON
[] = "Icon";
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";
43 static void GetAddonNotebookBarItem(const css::uno::Sequence
<css::beans::PropertyValue
>& pExtension
,
44 AddonNotebookBarItem
& aAddonNotebookBarItem
)
46 for (int nIdx
= 0; nIdx
< pExtension
.getLength(); nIdx
++)
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
;
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
)
73 sal_uInt16 nItemId
= 0;
74 ToolBox
* pToolbox
= dynamic_cast<ToolBox
*>(pNotebookbarToolBox
);
77 pToolbox
->InsertSeparator();
81 pToolbox
->InsertItem(aAddonNotebookBarItem
.sCommandURL
, m_xFrame
, ToolBoxItemBits::NONE
,
83 nItemId
= pToolbox
->GetItemId(aAddonNotebookBarItem
.sCommandURL
);
84 pToolbox
->SetItemCommand(nItemId
, aAddonNotebookBarItem
.sCommandURL
);
85 pToolbox
->SetQuickHelpText(nItemId
, aAddonNotebookBarItem
.sLabel
);
87 if (nIter
< aImageVec
.size())
89 sImage
= aImageVec
[nIter
];
92 sImage
= vcl::CommandInfoProvider::GetImageForCommand(
93 aAddonNotebookBarItem
.sImageIdentifier
, m_xFrame
);
97 if (aAddonNotebookBarItem
.sStyle
== STYLE_TEXT
)
98 pToolbox
->SetItemText(nItemId
, aAddonNotebookBarItem
.sLabel
);
99 else if (aAddonNotebookBarItem
.sStyle
== STYLE_ICON
)
100 pToolbox
->SetItemImage(nItemId
, sImage
);
103 pToolbox
->SetItemText(nItemId
, aAddonNotebookBarItem
.sLabel
);
104 pToolbox
->SetItemImage(nItemId
, sImage
);
110 NotebookBarAddonsMerger::NotebookBarAddonsMerger() {}
112 NotebookBarAddonsMerger::~NotebookBarAddonsMerger() {}
114 void NotebookBarAddonsMerger::MergeNotebookBarAddons(
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
)
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
++)
125 aExtension
= aNotebookBarAddonsItem
.aAddonValues
[nIdx
];
127 for (int nSecIdx
= 0; nSecIdx
< aExtension
.getLength(); nSecIdx
++)
129 VclPtr
<vcl::Window
> pOptionalParent
;
130 pOptionalParent
= VclPtr
<OptionalBox
>::Create(pParent
);
131 pOptionalParent
->Show();
133 vcl::IPrioritable
* pPrioritable
134 = dynamic_cast<vcl::IPrioritable
*>(pOptionalParent
.get());
136 pPrioritable
->SetPriority(nPriorityIdx
- nIter
);
138 VclPtr
<vcl::Window
> pNotebookbarToolBox
;
139 pFunction(pNotebookbarToolBox
, pOptionalParent
, rMap
);
141 AddonNotebookBarItem aAddonNotebookBarItem
;
142 const css::uno::Sequence
<css::beans::PropertyValue
> pExtension
= aExtension
[nSecIdx
];
143 GetAddonNotebookBarItem(pExtension
, aAddonNotebookBarItem
);
145 CreateNotebookBarToolBox(pNotebookbarToolBox
, m_xFrame
, aAddonNotebookBarItem
,
152 void NotebookBarAddonsMerger::MergeNotebookBarMenuAddons(
153 Menu
* pPopupMenu
, sal_Int16 nItemId
, const OString
& sItemIdName
,
154 NotebookBarAddonsItem
& aNotebookBarAddonsItem
)
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
++)
161 aExtension
= aNotebookBarAddonsItem
.aAddonValues
[nIdx
];
163 for (int nSecIdx
= 0; nSecIdx
< aExtension
.getLength(); nSecIdx
++)
165 AddonNotebookBarItem aAddonNotebookBarItem
;
167 MenuItemBits nBits
= MenuItemBits::ICON
;
168 const css::uno::Sequence
<css::beans::PropertyValue
> pExtension
= aExtension
[nSecIdx
];
170 GetAddonNotebookBarItem(pExtension
, aAddonNotebookBarItem
);
172 pPopupMenu
->InsertItem(nItemId
, aAddonNotebookBarItem
.sLabel
, nBits
, sItemIdName
);
173 pPopupMenu
->SetItemCommand(nItemId
, aAddonNotebookBarItem
.sCommandURL
);
175 if (nIter
< aImageVec
.size())
177 sImage
= aImageVec
[nIter
];
180 pPopupMenu
->SetItemImage(nItemId
, sImage
);
182 if (nSecIdx
== aExtension
.getLength() - 1)
183 pPopupMenu
->InsertSeparator();
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */