LibreOffice Module vcl (master) 1
builder.hxx
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
10#ifndef INCLUDED_VCL_BUILDER_HXX
11#define INCLUDED_VCL_BUILDER_HXX
12
13#include <typeinfo>
14#include <sal/log.hxx>
15#include <unotools/resmgr.hxx>
16#include <tools/fldunit.hxx>
17#include <vcl/dllapi.h>
18#include <vcl/window.hxx>
19#include <vcl/vclptr.hxx>
20#include <vcl/toolboxid.hxx>
21#include <tools/wintypes.hxx>
22#include <vcl/EnumContext.hxx>
23
24#include <memory>
25#include <map>
26#include <string_view>
27#include <vector>
28#ifdef check
29# //some problem with MacOSX and a check define
30# undef check
31#endif
32
33class Button;
34class ComboBox;
35class FormattedField;
36class ListBox;
37class Menu;
38class MessageDialog;
40class PopupMenu;
42class ScreenshotTest;
43class ScrollBar;
44class SvTabListBox;
45class Slider;
46class DateField;
47class TimeField;
48class ToolBox;
49class VclExpander;
52namespace xmlreader { class XmlReader; }
53namespace com::sun::star::frame { class XFrame; }
54
56{
57 OUString m_sItem;
58 OString m_sId;
59 ComboBoxTextItem(const OUString& rItem, const OString& rId)
60 : m_sItem(rItem)
61 , m_sId(rId)
62 {
63 }
64};
65
68{
69public:
70 typedef std::map<OString, OUString> stringmap;
71 typedef std::map<OString, std::pair<OString, OString>> accelmap;
73 typedef void (*customMakeWidget)(VclPtr<vcl::Window> &rRet, const VclPtr<vcl::Window> &pParent, stringmap &rVec);
74
75public:
76 VclBuilder(vcl::Window* pParent, const OUString& sUIRootDir, const OUString& sUIFile,
77 const OString& sID = OString(),
78 const css::uno::Reference<css::frame::XFrame>& rFrame
79 = css::uno::Reference<css::frame::XFrame>(),
80 bool bLegacy = true,
81 const NotebookBarAddonsItem* pNotebookBarAddonsItem = nullptr);
84 void disposeBuilder();
85 //sID must exist and be of type T
86 template <typename T> T* get(VclPtr<T>& ret, const OString& sID);
87
88 //sID may not exist, but must be of type T if it does
89 template <typename T = vcl::Window> T* get(const OString& sID);
90
91 vcl::Window* get_widget_root();
92
93 //sID may not exist
94 PopupMenu* get_menu(std::string_view sID);
95
96 //release ownership of pWindow, i.e. don't delete it
97 void drop_ownership(const vcl::Window *pWindow);
98
99 //see m_aDeferredProperties, you need this for toplevel dialogs
100 //which build themselves from their ctor. The properties on
101 //the top level are stored in m_aDeferredProperties and need
102 //to be applied post ctor
103 void setDeferredProperties();
104
106 const OString& getUIFile() const
107 {
108 return m_sHelpRoot;
109 }
110
111 static SymbolType mapStockToSymbol(std::u16string_view icon_name);
112
113private:
114 VclBuilder(const VclBuilder&) = delete;
115 VclBuilder& operator=(const VclBuilder&) = delete;
116
117 // owner for ListBox/ComboBox UserData
118 std::vector<std::unique_ptr<OUString>> m_aUserData;
119
120 //If the toplevel window has any properties which need to be set on it,
121 //but the toplevel is the owner of the builder, then its ctor
122 //has not been completed during the building, so properties for it
123 //are collected here and need to be set afterwards, e.g. during
124 //Show or Execute
126
127 std::unique_ptr<NotebookBarAddonsItem> m_pNotebookBarAddonsItem;
128
130 {
132 sal_Int32 m_nPosition;
133 PackingData(bool bVerticalOrient = false)
134 : m_bVerticalOrient(bVerticalOrient)
135 , m_nPosition(-1)
136 {
137 }
138 };
139
140 struct WinAndId
141 {
142 OString m_sID;
145 WinAndId(const OString &rId, vcl::Window *pWindow, bool bVertical)
146 : m_sID(rId)
147 , m_pWindow(pWindow)
148 , m_aPackingData(bVertical)
149 {
150 }
151 };
152 std::vector<WinAndId> m_aChildren;
153
155 {
156 OString m_sID;
158 MenuAndId(const OString &rId, Menu *pMenu);
159 };
160 std::vector<MenuAndId> m_aMenus;
161
163 {
164 OString m_sID;
165 OString m_sValue;
166 StringPair(const OString &rId, const OString &rValue)
167 : m_sID(rId)
168 , m_sValue(rValue)
169 {
170 }
171 };
172
174 {
175 OString m_sID;
176 OUString m_sValue;
177 UStringPair(const OString &rId, const OUString &rValue)
178 : m_sID(rId)
179 , m_sValue(rValue)
180 {
181 }
182 };
183
185
187 {
188 OString m_sID;
189 OUString m_sValue;
191 ButtonImageWidgetMap(const OString &rId, const OUString &rValue, bool bRadio)
192 : m_sID(rId)
193 , m_sValue(rValue)
194 , m_bRadio(bRadio)
195 {
196 }
197 };
198
203
205 {
206 OString m_sID;
207 OUString m_sValue;
208 sal_Int32 m_nActiveId;
209 ComboBoxModelMap(const OString &rId, const OUString &rValue, sal_Int32 nActiveId)
210 : m_sID(rId)
211 , m_sValue(rValue)
212 , m_nActiveId(nActiveId)
213 {
214 }
215 };
216
218 {
219 typedef std::vector<OUString> row;
220 std::vector<row> m_aEntries;
221 };
222
223 const ListStore* get_model_by_name(const OString& sID) const;
224 void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
225 void mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
226 void mungeModel(SvTabListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
227
229 const TextBuffer* get_buffer_by_name(const OString& sID) const;
230
231 static void mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer);
232
234 const Adjustment* get_adjustment_by_name(const OString& sID) const;
235
236 static void mungeAdjustment(NumericFormatter &rTarget, const Adjustment &rAdjustment);
237 static void mungeAdjustment(FormattedField &rTarget, const Adjustment &rAdjustment);
238 static void mungeAdjustment(ScrollBar &rTarget, const Adjustment &rAdjustment);
239 static void mungeAdjustment(Slider &rTarget, const Adjustment &rAdjustment);
240
241 typedef std::map<OString, int> ImageSizeMap;
242
244 {
245 std::vector<OString> m_aWidgets;
248 };
249
250
252 {
253 std::locale m_aResLocale;
254
255 std::vector<RadioButtonGroupMap> m_aGroupMaps;
256
257 std::vector<ComboBoxModelMap> m_aModelMaps;
258 std::map<OString, ListStore> m_aModels;
259
260 std::vector<TextBufferMap> m_aTextBufferMaps;
261 std::map<OString, TextBuffer> m_aTextBuffers;
262
263 std::vector<WidgetAdjustmentMap> m_aNumericFormatterAdjustmentMaps;
264 std::vector<WidgetAdjustmentMap> m_aFormattedFormatterAdjustmentMaps;
265 std::vector<WidgetAdjustmentMap> m_aScrollAdjustmentMaps;
266 std::vector<WidgetAdjustmentMap> m_aSliderAdjustmentMaps;
267
268 std::map<OString, Adjustment> m_aAdjustments;
269
270 std::vector<ButtonImageWidgetMap> m_aButtonImageWidgetMaps;
272
273 std::vector<ButtonMenuMap> m_aButtonMenuMaps;
274
275 std::map<VclPtr<vcl::Window>, VclPtr<vcl::Window>> m_aRedundantParentWidgets;
276
277 std::vector<SizeGroup> m_aSizeGroups;
278
279 std::map<VclPtr<vcl::Window>, stringmap> m_aAtkInfo;
280
281 std::vector<MnemonicWidgetMap> m_aMnemonicWidgetMaps;
282
283 std::vector< VclPtr<VclExpander> > m_aExpanderWidgets;
284
285 std::vector< VclPtr<MessageDialog> > m_aMessageDialogs;
286
288
290
291 ParserState();
292 };
293
294 OString m_sID;
295 OString m_sHelpRoot;
302 std::unique_ptr<ParserState> m_pParserState;
303
304 vcl::Window *get_by_name(std::string_view sID);
305 void delete_by_name(const OString& sID);
306
308 {
309 public:
311 : m_pBuilder(pBuilder) {}
312
313 bool operator()(const vcl::Window *pA, const vcl::Window *pB) const;
314
315 private:
317 };
318
320 css::uno::Reference<css::frame::XFrame> m_xFrame;
321
322private:
323 VclPtr<vcl::Window> insertObject(vcl::Window *pParent,
324 const OString &rClass, const OString &rID,
325 stringmap &rProps, stringmap &rPangoAttributes,
326 stringmap &rAtkProps);
327
328 VclPtr<vcl::Window> makeObject(vcl::Window *pParent,
329 const OString &rClass, const OString &rID,
330 stringmap &rVec);
331
332 void connectNumericFormatterAdjustment(const OString &id, const OUString &rAdjustment);
333 void connectFormattedFormatterAdjustment(const OString &id, const OUString &rAdjustment);
334
335 static int getImageSize(const stringmap &rMap);
336
337 void extractGroup(const OString &id, stringmap &rVec);
338 void extractModel(const OString &id, stringmap &rVec);
339 void extractBuffer(const OString &id, stringmap &rVec);
340 static bool extractAdjustmentToMap(const OString &id, stringmap &rVec, std::vector<WidgetAdjustmentMap>& rAdjustmentMap);
341 void extractButtonImage(const OString &id, stringmap &rMap, bool bRadio);
342 void extractMnemonicWidget(const OString &id, stringmap &rMap);
343
344 // either pParent or pAtkProps must be set, pParent for a child of a widget, pAtkProps for
345 // collecting the atk info for a GtkMenuItem
346 void handleChild(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader);
347 VclPtr<vcl::Window> handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader);
348 void handlePacking(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader);
349 static std::vector<vcl::EnumContext::Context> handleStyle(xmlreader::XmlReader &reader, int &nPriority);
350 static OString getStyleClass(xmlreader::XmlReader &reader);
351 void applyPackingProperty(vcl::Window *pCurrent, vcl::Window *pParent, xmlreader::XmlReader &reader);
352 void collectProperty(xmlreader::XmlReader &reader, stringmap &rVec) const;
353 static void collectPangoAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
354 static void collectAtkRelationAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
355 static void collectAtkRoleAttribute(xmlreader::XmlReader &reader, stringmap &rMap);
356 static void collectAccelerator(xmlreader::XmlReader &reader, accelmap &rMap);
357
358 void insertMenuObject(
359 Menu *pParent,
360 PopupMenu *pSubMenu,
361 const OString &rClass,
362 const OString &rID,
363 stringmap &rProps,
364 stringmap &rAtkProps,
365 accelmap &rAccels);
366
367 void handleMenuChild(Menu *pParent, xmlreader::XmlReader &reader);
368 void handleMenuObject(Menu *pParent, xmlreader::XmlReader &reader);
369
370 void handleListStore(xmlreader::XmlReader &reader, const OString &rID, std::string_view rClass);
371 void handleRow(xmlreader::XmlReader &reader, const OString &rID);
372 void handleTabChild(vcl::Window *pParent, xmlreader::XmlReader &reader);
373 VclPtr<Menu> handleMenu(xmlreader::XmlReader &reader, const OString &rID, bool bMenuBar);
374 std::vector<ComboBoxTextItem> handleItems(xmlreader::XmlReader &reader) const;
375
376 void handleSizeGroup(xmlreader::XmlReader &reader);
377
378 stringmap handleAtkObject(xmlreader::XmlReader &reader) const;
379
380 static void applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties);
381
382 void handleActionWidget(xmlreader::XmlReader &reader);
383
384 PackingData get_window_packing_data(const vcl::Window *pWindow) const;
385 void set_window_packing_position(const vcl::Window *pWindow, sal_Int32 nPosition);
386
387 static vcl::Window* prepareWidgetOwnScrolling(vcl::Window *pParent, WinBits &rWinStyle);
388 void cleanupWidgetOwnScrolling(vcl::Window *pScrollParent, vcl::Window *pWindow, stringmap &rMap);
389
390 void set_response(std::string_view sID, short nResponse);
391
392 OString get_by_window(const vcl::Window *pWindow) const;
393 void delete_by_window(vcl::Window *pWindow);
394};
395
396namespace BuilderUtils
397{
398 //apply the properties of rProps to pWindow
400
401 //Convert _ gtk markup to ~ vcl markup
402 VCL_DLLPUBLIC OUString convertMnemonicMarkup(std::u16string_view rIn);
403
405
407
408 //add a default value of 25 width-chars to a map if width-chars not set
410
411 //Helpers to retrofit all the existing code to the builder
412 VCL_DLLPUBLIC void reorderWithinParent(std::vector< vcl::Window*>& rChilds, bool bIsButtonBox);
413 VCL_DLLPUBLIC void reorderWithinParent(vcl::Window &rWindow, sal_uInt16 nNewPosition);
414
415 //Convert an accessibility role name to accessibility role number
416 VCL_DLLPUBLIC sal_Int16 getRoleFromName(const OString& roleName);
417}
418
419template <typename T>
420inline T* VclBuilder::get(VclPtr<T>& ret, const OString& sID)
421{
422 vcl::Window *w = get_by_name(sID);
423 SAL_WARN_IF(!w, "vcl.layout", "widget \"" << sID << "\" not found in .ui");
424 SAL_WARN_IF(!dynamic_cast<T*>(w),
425 "vcl.layout", ".ui widget \"" << sID << "\" needs to correspond to vcl type " << typeid(T).name());
426 assert(w);
427 assert(dynamic_cast<T*>(w));
428 ret = static_cast<T*>(w);
429 return ret.get();
430}
431
432//sID may not exist, but must be of type T if it does
433template <typename T>
434inline T* VclBuilder::get(const OString& sID)
435{
436 vcl::Window *w = get_by_name(sID);
437 SAL_WARN_IF(w && !dynamic_cast<T*>(w),
438 "vcl.layout", ".ui widget \"" << sID << "\" needs to correspond to vcl type " << typeid(T).name());
439 assert(!w || dynamic_cast<T*>(w));
440 return static_cast<T*>(w);
441}
442
443/*
444 * @return true if rValue is "True", "true", "1", etc.
445 */
446VCL_DLLPUBLIC bool toBool(std::u16string_view rValue);
447
448#endif
449
450/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 m_nPosition
VCL_DLLPUBLIC bool toBool(std::u16string_view rValue)
Definition: layout.cxx:1376
A widget used to choose from a list of items and which has an entry.
Definition: combobox.hxx:39
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:83
Definition: menu.hxx:116
A toolbar: contains all those icons, typically below the menu bar.
Definition: toolbox.hxx:76
sortIntoBestTabTraversalOrder(VclBuilder *pBuilder)
Definition: builder.hxx:310
Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar,...
Definition: builder.hxx:68
const OString & getUIFile() const
return UI-File name (without '.ui')
Definition: builder.hxx:106
stringmap m_aDeferredProperties
Definition: builder.hxx:125
UStringPair WidgetAdjustmentMap
Definition: builder.hxx:200
VclPtr< vcl::Window > m_pParent
Definition: builder.hxx:297
OString m_sHelpRoot
Definition: builder.hxx:295
css::uno::Reference< css::frame::XFrame > m_xFrame
XFrame to be able to extract labels and other properties of the UNO commands (like of ....
Definition: builder.hxx:320
VclBuilder(const VclBuilder &)=delete
bool m_bToplevelHasDeferredInit
Definition: builder.hxx:298
std::vector< WinAndId > m_aChildren
Definition: builder.hxx:152
std::map< OString, OUString > stringmap
Definition: builder.hxx:70
bool m_bToplevelHasDeferredProperties
Definition: builder.hxx:299
std::vector< std::unique_ptr< OUString > > m_aUserData
Definition: builder.hxx:118
ResHookProc m_pStringReplace
Definition: builder.hxx:296
bool m_bToplevelParentFound
Definition: builder.hxx:300
UStringPair ButtonMenuMap
Definition: builder.hxx:201
std::map< OString, std::pair< OString, OString > > accelmap
Definition: builder.hxx:71
OString m_sID
Definition: builder.hxx:294
StringPair RadioButtonGroupMap
Definition: builder.hxx:184
T * get(VclPtr< T > &ret, const OString &sID)
Definition: builder.hxx:420
std::vector< MenuAndId > m_aMenus
Definition: builder.hxx:160
vcl::Window * get_by_name(std::string_view sID)
Definition: builder.cxx:4027
std::unique_ptr< ParserState > m_pParserState
Definition: builder.hxx:302
std::map< OString, int > ImageSizeMap
Definition: builder.hxx:241
VclBuilder & operator=(const VclBuilder &)=delete
UStringPair TextBufferMap
Definition: builder.hxx:199
UStringPair MnemonicWidgetMap
Definition: builder.hxx:202
bool m_bLegacy
Definition: builder.hxx:301
stringmap Adjustment
Definition: builder.hxx:233
stringmap TextBuffer
Definition: builder.hxx:228
std::unique_ptr< NotebookBarAddonsItem > m_pNotebookBarAddonsItem
Definition: builder.hxx:127
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
const char * name
#define SAL_WARN_IF(condition, area, stream)
void ensureDefaultWidthChars(VclBuilder::stringmap &rMap)
Definition: builder.cxx:2253
sal_Int16 getRoleFromName(const OString &roleName)
Definition: builder.cxx:2305
void set_properties(vcl::Window *pWindow, const VclBuilder::stringmap &rProps)
Definition: builder.cxx:2214
OUString convertMnemonicMarkup(std::u16string_view rIn)
Definition: builder.cxx:2224
bool extractDropdown(VclBuilder::stringmap &rMap)
Definition: builder.cxx:2261
OUString extractCustomProperty(VclBuilder::stringmap &rMap)
Definition: builder.cxx:2241
void reorderWithinParent(vcl::Window &rWindow, sal_uInt16 nNewPosition)
Definition: builder.cxx:2273
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
sal_Int32 w
OUString(* ResHookProc)(const OUString &rStr)
ComboBoxTextItem(const OUString &rItem, const OString &rId)
Definition: builder.hxx:59
OUString m_sItem
Definition: builder.hxx:57
OString m_sId
Definition: builder.hxx:58
ButtonImageWidgetMap(const OString &rId, const OUString &rValue, bool bRadio)
Definition: builder.hxx:191
ComboBoxModelMap(const OString &rId, const OUString &rValue, sal_Int32 nActiveId)
Definition: builder.hxx:209
std::vector< row > m_aEntries
Definition: builder.hxx:220
std::vector< OUString > row
Definition: builder.hxx:219
VclPtr< Menu > m_pMenu
Definition: builder.hxx:157
PackingData(bool bVerticalOrient=false)
Definition: builder.hxx:133
ToolBoxItemId m_nLastToolbarId
Definition: builder.hxx:287
std::vector< MnemonicWidgetMap > m_aMnemonicWidgetMaps
Definition: builder.hxx:281
std::vector< ButtonImageWidgetMap > m_aButtonImageWidgetMaps
Definition: builder.hxx:270
ImageSizeMap m_aImageSizeMap
Definition: builder.hxx:271
std::vector< WidgetAdjustmentMap > m_aScrollAdjustmentMaps
Definition: builder.hxx:265
std::vector< RadioButtonGroupMap > m_aGroupMaps
Definition: builder.hxx:255
std::vector< VclPtr< MessageDialog > > m_aMessageDialogs
Definition: builder.hxx:285
std::vector< SizeGroup > m_aSizeGroups
Definition: builder.hxx:277
std::vector< WidgetAdjustmentMap > m_aFormattedFormatterAdjustmentMaps
Definition: builder.hxx:264
std::vector< TextBufferMap > m_aTextBufferMaps
Definition: builder.hxx:260
std::locale m_aResLocale
Definition: builder.hxx:253
std::map< VclPtr< vcl::Window >, stringmap > m_aAtkInfo
Definition: builder.hxx:279
std::map< OString, TextBuffer > m_aTextBuffers
Definition: builder.hxx:261
std::vector< WidgetAdjustmentMap > m_aSliderAdjustmentMaps
Definition: builder.hxx:266
sal_uInt16 m_nLastMenuItemId
Definition: builder.hxx:289
std::vector< ButtonMenuMap > m_aButtonMenuMaps
Definition: builder.hxx:273
std::map< VclPtr< vcl::Window >, VclPtr< vcl::Window > > m_aRedundantParentWidgets
Definition: builder.hxx:275
std::map< OString, Adjustment > m_aAdjustments
Definition: builder.hxx:268
std::vector< ComboBoxModelMap > m_aModelMaps
Definition: builder.hxx:257
std::map< OString, ListStore > m_aModels
Definition: builder.hxx:258
std::vector< WidgetAdjustmentMap > m_aNumericFormatterAdjustmentMaps
Definition: builder.hxx:263
std::vector< VclPtr< VclExpander > > m_aExpanderWidgets
Definition: builder.hxx:283
std::vector< OString > m_aWidgets
Definition: builder.hxx:245
stringmap m_aProperties
Definition: builder.hxx:246
StringPair(const OString &rId, const OString &rValue)
Definition: builder.hxx:166
UStringPair(const OString &rId, const OUString &rValue)
Definition: builder.hxx:177
WinAndId(const OString &rId, vcl::Window *pWindow, bool bVertical)
Definition: builder.hxx:145
PackingData m_aPackingData
Definition: builder.hxx:144
VclPtr< vcl::Window > m_pWindow
Definition: builder.hxx:143
weld::Builder * m_pBuilder
SymbolType
Definition: vclenum.hxx:74
sal_Int64 WinBits