Debian Codegraph @

wxcrafter/src/wxc_widget.h

raw
1 #ifndef WRAPPERBASE_H
2 #define WRAPPERBASE_H
3
4 #include "aui_pane_info.h"
5 #include "bitmap_picker_property.h"
6 #include "bool_property.h"
7 #include "category_property.h"
8 #include "events_database.h"
9 #include "int_property.h"
10 #include "json_node.h"
11 #include "property_base.h"
12 #include "string_property.h"
13 #include "wx_ordered_map.h"
14 #include "wxc_settings.h"
15 #include "wxgui_defs.h"
16
17 #include <list>
18 #include <map>
19 #include <set>
20 #include <wx/menu.h>
21 #include <wx/sizer.h>
22 #include <wx/string.h>
23 #include <wx/xrc/xmlres.h>
24
25 typedef unsigned long long FLAGS_t;
26
27 static const wxString DEFAULT_AUI_DROPDOWN_FUNCTION = "ShowAuiToolMenu";
28 static const wxString DEFAULT_AUI_DROPDOWN_FUNCTION_AND_SIG =
29 DEFAULT_AUI_DROPDOWN_FUNCTION + "(wxAuiToolBarEvent& event)";
30
31 enum CONTROL_TYPE {
32 TYPE_SIZER = 0, // 0
33 TYPE_CONTROL, // 1
34 TYPE_LIST_CTRL, // 2
35 TYPE_LIST_CTRL_COL, // 3
36 TYPE_CONTAINER, // 4
37 TYPE_BOOK, // 5
38 TYPE_FORM, // 6
39 TYPE_FORM_FRAME, // 7
40 TYPE_WIZARD, // 8
41 TYPE_WIZARD_PAGE, // 9
42 TYPE_NOTEBOOK_PAGE, // 10
43 TYPE_SPLITTERWIN_PAGE, // 11
44 TYPE_SPLITTER_WINDOW, // 12
45 TYPE_SPACER, // 13
46 TYPE_MENUBAR, // 14
47 TYPE_MENU, // 15
48 TYPE_SUBMENU, // 16
49 TYPE_MENUITEM, // 17
50 TYPE_TOOLBAR, // 18
51 TYPE_TOOLITEM, // 19
52 TYPE_STATUSABR, // 20
53 TYPE_AUITOOLBAR, // 21
54 TYPE_STD_BUTTON_SIZER, // 22
55 TYPE_STD_BUTTON, // 23
56 TYPE_DV_WITH_COLUMNS, // 24
57 TYPE_DV_LISTCTRLCOL, // 25
58 TYPE_COLOLAPSIBLEPANE, // 26
59 TYPE_COLOLAPSIBLEPANE_PANE, // 27
60 TYPE_INFO_BAR, // 28
61 TYPE_INFO_BAR_BUTTON, // 29
62 TYPE_AUI_MGR, // 30
63 TYPE_BITMAP, // 31
64 TYPE_IMGLIST, // 32
65 TYPE_TIMER, // 33
66 TYPE_PG_MGR, // 34
67 TYPE_PG_PROPERTY, // 35
68 TYPE_RIBBON_BAR, // 36
69 TYPE_RIBBON_PAGE, // 37
70 TYPE_RIBBON_PANEL, // 38
71 TYPE_RIBBON_BUTTONBAR, // 39
72 TYPE_RIBBON_BUTTON, // 40
73 TYPE_RIBBON_TOOLBAR, // 41
74 TYPE_RIBBON_TOOL, // 42
75 TYPE_RIBBON_GALLERY, // 43
76 TYPE_RIBBON_GALLERY_ITEM, // 44
77 TYPE_GRID, // 45
78 TYPE_GRID_CHILD, // 46
79 TYPE_TREE_LIST_CTRL, // 47
80 TYPE_TREE_LIST_CTRL_COL, // 48
81 TYPE_TASKBARICON, // 49
82 TYPE_UNKNOWN
83 };
84
85 enum SIZER_FLAG_VALUE {
86 SZ_ALL = 0x00000001,
87 SZ_LEFT = 0x00000002,
88 SZ_RIGHT = 0x00000004,
89 SZ_TOP = 0x00000008,
90 SZ_BOTTOM = 0x00000010,
91 SZ_EXPAND = 0x00000020,
92 SZ_ALIGN_CENTER = 0x00000040,
93 SZ_ALIGN_LEFT = 0x00000080,
94 SZ_ALIGN_CENTER_HORIZONTAL = 0x00000100,
95 SZ_ALIGN_RIGHT = 0x00000200,
96 SZ_ALIGN_TOP = 0x00000400,
97 SZ_ALIGN_CENTER_VERTICAL = 0x00000800,
98 SZ_ALIGN_BOTTOM = 0x00001000,
99 SZ_RESERVE_SPACE_EVEN_IF_HIDDEN = 0x00002000,
100 // There's a value-clash between wxALIGN_LEFT and wxALIGN_TOP (both are wxALIGN_NOT == 0)
101 // This made it impossible to select only one in Properties (or the toolbar). So provide a fake fake value.
102 crafterALIGN_TOP = 0x10000000,
103 };
104
105 enum DuplicatingOptions {
106 DO_renameNone = 0x00,
107 DO_renameAllChildrenExceptUsernamed = 0x01,
108 DO_renameAllChildren = 0x02,
109 DO_copyEventsToo = 0x04
110 };
111
112 class AuiToolbarWrapperBase;
113
114 class wxcSizerItem : public wxSizerItem
115 {
116 public:
117 wxcSizerItem() {}
118 virtual ~wxcSizerItem() {}
119 wxString GetBorderScaled() const;
120 };
121
122 class wxcWidget
123 {
124 friend class AuiToolbarWrapperBase;
125
126 protected:
127 static size_t s_objCounter;
128
129 public:
130 enum XRC_TYPE { XRC_PREVIEW, XRC_DESIGNER, XRC_LIVE };
131
132 enum COPY_REASON {
133 CR_Copy,
134 CR_Cut,
135 };
136
137 public:
138 typedef std::list<wxcWidget*> List_t;
139 typedef wxOrderedMap<wxString, WxStyleInfo> MapStyles_t;
140 typedef wxOrderedMap<wxString, PropertyBase*> MapProperties_t;
141 typedef wxOrderedMap<wxString, ConnectDetails> MapEvents_t;
142 typedef std::map<wxString, ConnectDetails> Map_t;
143 typedef std::map<wxString, wxArrayString> AntiGroupMap_t;
144 typedef std::map<int, int> SizerFlagsValueSet_t;
145
146 static AntiGroupMap_t s_antiGroup;
147 static SizerFlagsValueSet_t s_sizerFlagsValue;
148
149 protected:
150 wxcWidget* m_parent;
151 List_t m_children;
152 wxcSizerItem m_sizerItem;
153 wxString m_gbSpan;
154 wxString m_gbPos;
155 MapStyles_t m_styles;
156 MapStyles_t m_sizerFlags;
157 MapProperties_t m_properties;
158 wxString m_namePattern;
159 int m_type;
160 wxMenu* m_eventsMenu;
161 MapEvents_t m_connectedEvents;
162 EventsDatabase m_controlEvents;
163 AuiPaneInfo m_auiPaneInfo;
164
165 static int m_copyCounter; /// An internal counter that holds a unique string that allows renaming copied items
166 COPY_REASON m_copyReason; /// The reason for the copy
167 wxString m_condname;
168
169 static CustomControlTemplateMap_t ms_customControlsUsed;
170
171 protected:
172 wxString BaseDoGenerateClassMember() const;
173
174 void AddProperty(PropertyBase* prop);
175
176 /**
177 * @brief make the code generated by this widgets surrounded with
178 * #if <condname>
179 * ...
180 * #endif
181 */
182 void SetIfBlockCond(const wxString& condname);
183 /**
184 * @brief wrap 'code' with the proper #if / #endif block
185 * if needed. The code will get wrapped if !GetCondname().IsEmpty()
186 * @param code
187 */
188 void WrapInIfBlockIfNeeded(wxString& code) const;
189
190 const wxString& GetCondname() const { return m_condname; }
191
192 /// aliases for adding property
193 void AddCategory(const wxString& name) { AddProperty(new CategoryProperty(name)); }
194 /**
195 * @brief add string property
196 */
197 void AddText(const wxString& name, const wxString& description, const wxString& defaultValue = wxEmptyString)
198 {
199 AddProperty(new StringProperty(name, defaultValue, description));
200 }
201
202 /**
203 * @brief add bool property
204 */
205 void AddBool(const wxString& name, const wxString& description, bool defaultValue)
206 {
207 AddProperty(new BoolProperty(name, defaultValue, description));
208 }
209
210 /**
211 * @brief add integer property
212 */
213 void AddInteger(const wxString& name, const wxString& description, int defaultValue)
214 {
215 AddProperty(new IntProperty(name, defaultValue, description));
216 }
217
218 void DelProperty(const wxString& name);
219 void DoClearFlags(MapStyles_t& mp);
220 void DoAddSizerFlag(const wxString& name, WxStyleInfo info);
221 virtual void ImportEventsFromXRC(const wxString& events);
222 virtual void ImportEventFromwxSmith(const wxString& eventname, const wxString& handlername);
223 virtual void ImportEventFromFB(const wxString& eventname, const wxString& handlername);
224
225 // Properties accessors for
226 ///////////////////////////////
227 void DoSetPropertyStringValue(const wxString& propname, const wxString& value);
228
229 bool DoCheckNameUniqueness(const wxString& name, const wxcWidget* widget) const;
230 // Copy current wxcWidget children into 'widget'
231 void DoCopyChildren(wxcWidget* widget, enum DuplicatingOptions nametypesToChange,
232 const std::set<wxString>& existingNames) const;
233 virtual void DoDeepCopy(const wxcWidget& rhs, enum DuplicatingOptions nametypesToChange,
234 const std::set<wxString>& existingNames, const wxString& chosenName = "",
235 const wxString& chosenInheritedName = "", const wxString& chosenFilename = "");
236
237 public:
238 void SetCopyReason(COPY_REASON cr) { m_copyReason = cr; }
239 COPY_REASON GetCopyReason() const { return m_copyReason; }
240
241 static void SetMsCustomControlsUsed(const CustomControlTemplateMap_t& customControlsUsed)
242 {
243 ms_customControlsUsed = customControlsUsed;
244 }
245 static CustomControlTemplateMap_t& GetMsCustomControlsUsed() { return ms_customControlsUsed; }
246
247 /**
248 * @brief check whether 'name' is unique accross all children of this wxcWidget
249 */
250 virtual bool IsNameUnique(const wxString& name) const;
251 wxString PropertyString(const wxString& propname, const wxString& defaultValue = "") const;
252 int PropertyInt(const wxString& propname, int defval = -1) const;
253 wxString PropertyFile(const wxString& propname) const;
254 wxString PropertyBool(const wxString& propname) const;
255
256 bool IsPropertyChecked(const wxString& propname) const { return PropertyBool(propname) == "true"; }
257
258 /**
259 * @brief return an ordered map of all events connected by this item and its children.
260 * Unlike other WrapperBase::Map_t, the key in this map is the function name
261 * and the value is the ConnectDetails
262 */
263 wxcWidget::Map_t GetConnectedEventsRecrusively() const;
264
265 /**
266 * @brief return property by its name
267 * @return return the property or NULL if not found
268 */
269 PropertyBase* GetProperty(const wxString& name);
270
271 /**
272 * @brief return the real class name taking subclass property into consideration
273 * @return
274 */
275 wxString GetRealClassName() const;
276
277 protected:
278 void DoGetConnectedEventsRecrusively(wxcWidget::Map_t& events, const wxcWidget* wb) const;
279
280 // Helpers
281 wxString XRCPrefix(const wxString& class_name = wxEmptyString) const;
282 wxString XRCSuffix() const;
283 wxString XRCStyle(bool forPreview = false) const;
284 wxString XRCSize(bool dontEmitDefault = true) const;
285 wxString XRCValue() const;
286 wxString XRCLabel() const;
287 wxString XRCContentItems(bool ensureAtLeastOneEntry = false) const;
288 wxString XRCUnknown() const;
289 wxString XRCCommonAttributes() const;
290 wxString XRCBitmap(const wxString& labelname = "bitmap") const;
291 wxString XRCBitmap(const wxString& label, const wxString& bitmap) const;
292
293 // Code Generator helpers
294 wxString CPPStandardWxCtor(const wxString& defaultStyle) const;
295 wxString CPPStandardWxCtorWithValue(const wxString& defaultStyle) const;
296 wxString CPPStandardWxCtorWithLabel(const wxString& defaultStyle) const;
297 wxString CPPCommonAttributes() const;
298
299 /**
300 * @brief
301 * @return
302 */
303 wxString XRCSelection() const;
304
305 public:
306 // Common properties accessors
307 wxString SizeAsString() const;
308 wxString Size() const;
309 wxString ValueAsString() const;
310 wxString WindowID() const;
311 wxString Label() const;
312 wxString CPPLabel() const;
313
314 static size_t GetObjCounter() { return s_objCounter; }
315
316 /**
317 * @brief return true if this widget has a window style
318 * @param styleBit the style bit
319 */
320 bool HasStyle(int styleBit) const;
321
322 static int SizerFakeValue(int realValue);
323
324 static void SetObjCounter(size_t counter) { s_objCounter = counter; }
325
326 protected:
327 // Pure virtual
328 virtual void GetIncludeFile(wxArrayString& headers) const = 0;
329 void DoTraverseAndGenCode(wxArrayString& headers, wxString& ctorCode, wxString& members, wxString& eventFunctions,
330 wxString& eventConnectCode, wxStringMap_t& additionalFiles, wxString& dtorCode,
331 wxString& extraFunctionsImpl, wxString& extraFunctionsDecl) const;
332
333 void DoGetCustomControlsName(const wxcWidget* widget, wxArrayString& controls) const;
334 wxString DoGenerateEventStubs() const;
335 wxString DoGenerateConnectCode() const;
336 wxString DoGetScopeName() const;
337
338 /**
339 * @brief return a C++ code that represents this class
340 */
341 wxString DoGenerateCppCtorCode() const;
342 wxString DoGenerateCppDtorCode() const;
343 virtual wxString DoGenerateCppCtorCode_End() const;
344
345 // NOP stub
346 virtual void DoGenerateExtraFunctions(wxString& decl, wxString& impl) const
347 {
348 wxUnusedVar(decl);
349 wxUnusedVar(impl);
350 }
351
352 /**
353 * @brief generate getter for the control
354 */
355 virtual void DoGenerateGetters(wxString& decl) const;
356
357 virtual wxString DoGenerateClassMember() const;
358
359 /**
360 * @brief a helper class that return the name property
361 * or 'this' incase we are top-level window
362 * This method is mainly used when connecting events.
363 * It is advised to override it for wrappers of tool kind (like wxRibbonBar button, wxRibbonToolBar's tool etc)
364 * and return the <code>GetParent()->GetName()</code> instead
365 */
366 virtual wxString GetCppName() const;
367
368 /**
369 * @brief when generating the connect code (for events)
370 * decide whether to use:
371 *
372 * w->Connect(EVT_NAME, Handler, NULL, this);
373 * <b>OR</b>
374 * w->Connect(<b><i>ID</i></b>, EVT_NAME, Handler, NULL, this);
375 */
376 virtual bool UseIdInConnect() const { return false; }
377 /**
378 * @brief returns either <GetName()>BaseClass or,
379 * if GetName() already ends in 'Base', <GetName()>Class
380 */
381 virtual wxString CreateBaseclassName() const;
382
383 void RegisterEvent(const wxString& eventName, const wxString& className, const wxString& description,
384 const wxString& handlerName = "", const wxString& functionNameAndSig = "", bool noBody = false);
385 /**
386 * @brief acroynm for RegisterEvent(eventName, "wxCommandEvent", "wxCommandEventHandler")
387 */
388 void RegisterEventCommand(const wxString& eventName, const wxString& description)
389 {
390 RegisterEvent(eventName, "wxCommandEvent", description, "wxCommandEventHandler");
391 }
392
393 const wxcWidget* DoFindByName(const wxcWidget* parent, const wxString& name) const;
394
395 public:
396 void GetCustomControlsName(wxArrayString& controls) const;
397 wxString WrapInSizerXRC(const wxString& objXRC) const;
398 wxString WrapInAuiPaneXRC(const wxString& objXRC) const;
399 void AddEvent(const ConnectDetails& eventDetails);
400 void RemoveEvent(const wxString& eventName);
401 bool HasEvent(const wxString& eventName) const;
402 ConnectDetails GetEvent(const wxString& eventName) const;
403 ConnectDetails GetEventMetaData(const wxString& eventName) const;
404
405 bool IsSizerFlagChecked(const wxString& style) const;
406 void DoEnableStyle(wxcWidget::MapStyles_t& mp, const wxString& style, bool enable);
407
408 virtual void FixPaths(const wxString& cwd);
409 virtual void Serialize(JSONElement& json) const;
410 virtual void UnSerialize(const JSONElement& json);
411
412 /**
413 * @brief Extract properties from this XRC object node.
414 * Derived classes may extract their own, more specific, ones too
415 */
416 virtual void LoadPropertiesFromXRC(const wxXmlNode* node);
417
418 /**
419 * @brief Extract properties from this wxSmith object node.
420 * Derived classes may extract their own, more specific, ones too
421 */
422 virtual void LoadPropertiesFromwxSmith(const wxXmlNode* node);
423
424 /**
425 * @brief Extract properties from this wxFB object node.
426 * Derived classes may extract their own, more specific, ones too
427 */
428 virtual void LoadPropertiesFromwxFB(const wxXmlNode* node);
429
430 // Cleanup
431 /**
432 * @brief remove and delete all the widget children
433 */
434 void DeleteAllChildren();
435 /**
436 * @brief change the parent of this widget
437 */
438 void Reparent(wxcWidget* parent);
439 // Children manipulation
440 void MoveUp();
441 void MoveDown();
442 bool CanMoveUp() const;
443 bool CanMoveDown() const;
444 bool CanMoveRight() const
445 { // i.e. can move into an adjacent sibling that's a sizer
446 return (GetAdjacentSiblingSizer() != NULL);
447 }
448 /**
449 * @brief copy all oldWidget's children into newWidget and place newWidget in the
450 * same location as oldWidget occupied. In addition, this function also frees the memory
451 * allocated by 'newWidget' (Eran, should that read 'oldWidget'?)
452 */
453 static void ReplaceWidget(wxcWidget* oldWidget, wxcWidget* newWidget);
454
455 /**
456 * @brief move oldWidget into newWidget and place newWidget in the
457 * same location as oldWidget occupied.
458 */
459 static void InsertWidgetInto(wxcWidget* oldWidget, wxcWidget* newWidget);
460
461 /**
462 * @brief copy sizer and wxAUI info from source widget to target widget
463 */
464 static void CopySizerAndAuiInfo(const wxcWidget* source, wxcWidget* target);
465
466 /**
467 * @brief update the registered events if needed
468 * By default this function does nothing. See comment inside GetControlEvents() below for more details
469 */
470 virtual void UpdateRegisteredEventsIfNeeded() {}
471
472 /**
473 * @brief Is this a 'real' control, or something else e.g. a sizer or a toolbar separator, that doesn't do events
474 * Relevant derived classes can return false instead.
475 */
476 virtual bool IsEventHandler() const { return true; }
477
478 public:
479 wxcWidget(int type);
480 virtual ~wxcWidget();
481
482 void SetGbPos(const wxString& gbPos) { this->m_gbPos = gbPos; }
483 void SetGbSpan(const wxString& gbSpan) { this->m_gbSpan = gbSpan; }
484 const wxString& GetGbPos() const { return m_gbPos; }
485 const wxString& GetGbSpan() const { return m_gbSpan; }
486 EventsDatabase& GetControlEvents()
487 {
488 /// Allow the widget to register / remove events based on information which was
489 /// not available while the widget was constructed.
490 /// A good example is ToolBarItem: it serves 2 widgets wx{Aui}ToolBar
491 /// However, there is no way to determine the parent of the toolbar item at the creation time
492 /// this functions attempts to fix this by allowing the widget to adjust its content after a parent has been
493 /// asigned to it
494 UpdateRegisteredEventsIfNeeded();
495 return m_controlEvents;
496 }
497
498 void SetType(int type) { this->m_type = type; }
499 int GetType() const { return m_type; }
500 /**
501 * @brief return the top level window for this control
502 */
503 wxcWidget* GetTopLevel() const;
504
505 /**
506 * @brief find the first child with a given name (recursive)
507 */
508 const wxcWidget* FindChildByName(const wxString& name) const;
509
510 const wxcWidget* FindFirstDirectChildOfType(int type) const;
511 /**
512 * @brief create an XRC code that represents this class
513 */
514 virtual void ToXRC(wxString& text, XRC_TYPE type) const = 0;
515
516 /**
517 * @brief return the CPP code suitable for this class
518 */
519 virtual wxString CppCtorCode() const = 0;
520
521 /**
522 * @brief an optional d-tor code
523 */
524 virtual wxString CppDtorCode() const { return ""; }
525
526 /**
527 * @brief return the underlyging WX class represented by
528 * this class
529 */
530 virtual wxString GetWxClassName() const = 0;
531
532 /**
533 * @brief return a new instance of this class
534 */
535 virtual wxcWidget* Clone() const = 0;
536
537 /**
538 * @brief create a copy of this class - with all its properties / sizers / styles and wxAUI properties copied
539 */
540 virtual wxcWidget* Copy(enum DuplicatingOptions nametypesToChange, const std::set<wxString>& existingNames,
541 const wxString& chosenName = "", const wxString& chosenInheritedName = "",
542 const wxString& chosenFilename = "") const;
543
544 /**
545 * @brief if the controls requires an additional files, generate their content / names
546 * and place them inside the 'additionalFiles' variable
547 */
548 virtual void GenerateAdditionalFiles(wxStringMap_t& additionalFiles) const;
549
550 wxcSizerItem& SizerItem() { return m_sizerItem; }
551
552 // UI Helper methods
553 const wxcWidget::MapProperties_t& GetProperties() const { return m_properties; }
554
555 void SetSizerFlags(const MapStyles_t& sizerFlags)
556 {
557 MapStyles_t::const_iterator iter = sizerFlags.begin();
558 for(; iter != sizerFlags.end(); ++iter) {
559 if(m_sizerFlags.Contains(iter->second.style_name)) {
560 m_sizerFlags.Item(iter->second.style_name).is_set = iter->second.is_set;
561 }
562 }
563 }
564
565 void SetStyles(size_t value);
566
567 void ClearStyles() { DoClearFlags(m_styles); }
568
569 void EnableStyle(const wxString& style, bool enable) { DoEnableStyle(m_styles, style, enable); }
570
571 void EnableSizerFlag(const wxString& flag, bool enable);
572
573 void SetStyles(const MapStyles_t& styles)
574 {
575 MapStyles_t::const_iterator iter = styles.begin();
576 for(; iter != styles.end(); ++iter) {
577 if(m_styles.Contains(iter->second.style_name)) {
578 m_styles.Item(iter->second.style_name).is_set = iter->second.is_set;
579 }
580 }
581 }
582
583 const MapStyles_t& GetStyles() const { return m_styles; }
584
585 const MapStyles_t& GetSizerFlags() const { return m_sizerFlags; }
586
587 /*!
588 * \brief Clears all sizeritem and similar things
589 */
590 void ClearSizerAll()
591 {
592 ClearSizerFlags();
593 SizerItem().SetBorder(0);
594 SizerItem().SetProportion(0);
595 SetGbSpan("");
596 SetGbPos("");
597 }
598
599 void ClearSizerFlags() { DoClearFlags(m_sizerFlags); }
600 wxString GenerateName() const
601 {
602 wxString n;
603 n << m_namePattern << ++s_objCounter;
604 return n;
605 }
606
607 void SetId(const wxString& id) { DoSetPropertyStringValue(PROP_WINDOW_ID, id); }
608
609 wxString GetId() const;
610
611 /**
612 * @brief return the Windowed parent i.e. an actual window that can be the parent when constructing
613 * this object
614 * @return parent name or the "NULL" string
615 */
616 wxString GetWindowParent() const;
617 /**
618 * @brief can this wrapper be a window parent?
619 */
620 virtual bool IsValidParent() const { return true; }
621 /**
622 * @brief return true if this item is inside a sizer
623 */
624 bool IsSizerItem() const;
625
626 /**
627 * @brief return true if this element is an AUI pane
628 *
629 */
630 bool IsAuiPane() const;
631
632 /**
633 * @brief return true if the widget is a toolbar item (but not a control)
634 */
635 virtual bool IsToolBarTool() const { return false; }
636 /**
637 * @brief by default, we are not managed by wxAUIManager
638 */
639 virtual bool IsAuiManaged() const;
640
641 bool IsGridBagSizerItem() const;
642
643 /**
644 * @brief return true of this child is the last child of its parent
645 */
646 bool IsLastChild() const;
647
648 /**
649 * @brief return true if this item as a toolbar item
650 * @return
651 */
652 bool IsParentToolbar() const;
653
654 /**
655 * @brief return true if the direct parent of this control is
656 * of type wxAuiToolBar
657 */
658 bool IsParentAuiToolbar() const;
659
660 /**
661 * @brief is this wrapper represents a top window class?
662 */
663 virtual bool IsTopWindow() const { return false; }
664
665 /**
666 * @brief is this wxcWidget represents a wxWindow derived object?
667 */
668 virtual bool IsWxWindow() const { return true; }
669 /**
670 * @brief return true if this window has a child of type toolbar
671 */
672 bool HasToolBar() const;
673 /**
674 * @brief return true if this window has a child of type menubar
675 */
676 bool HasMenuBar() const;
677 /**
678 * @brief return true if this window has a child of type status bar
679 */
680 bool HasStatusBar() const;
681
682 virtual bool IsSizer() const { return false; }
683
684 /**
685 * @brief return true if this window is a container and MUST have sizer
686 * an example for this is 'wxPanel', wxScrolledWindow'
687 */
688 virtual bool IsContainer() const { return false; }
689
690 /**
691 * @brief return true of this class represents a real window (i.e. not sizer) AND
692 * has at least one direct child of type sizer
693 * @return
694 */
695 virtual bool HasMainSizer() const;
696
697 /**
698 * @brief return true if this item has to be kept as a class member
699 */
700 virtual bool KeepAsClassMember() const { return true; }
701
702 virtual void ChildrenXRC(wxString& text, XRC_TYPE type) const;
703
704 void RemoveChild(wxcWidget* child);
705 void AddChild(wxcWidget* child)
706 {
707 child->SetParent(this);
708 m_children.push_back(child);
709 }
710
711 void InsertBefore(wxcWidget* item, wxcWidget* insertBefore);
712 void InsertAfter(wxcWidget* item, wxcWidget* insertAfter);
713 wxcWidget* GetAdjacentSibling(bool previous) const; // i.e. the previous (or next) control with the same parent
714 wxcWidget* GetAdjacentSiblingSizer(bool* isAbove = NULL) const; // Return an adjacent sibling that's a sizer, or
715 // NULL. If non-NULL, direction will hold whether
716 // above or below
717
718 void SetChildren(const List_t& children) { this->m_children = children; }
719
720 void SetPropertyString(const wxString& property, const wxString& value)
721 {
722 DoSetPropertyStringValue(property, value);
723 }
724
725 void SetName(const wxString& name) { DoSetPropertyStringValue(PROP_NAME, name); }
726
727 void SetTitle(const wxString& title) { DoSetPropertyStringValue(PROP_TITLE, title); }
728
729 void SetFilename(const wxString& filename) { DoSetPropertyStringValue(PROP_FILE, filename); }
730
731 void SetVirtualFolder(const wxString& vd) { DoSetPropertyStringValue(PROP_VIRTUAL_FOLDER, vd); }
732
733 virtual void SetParent(wxcWidget* parent);
734
735 const List_t& GetChildren() const { return m_children; }
736 List_t& GetChildren() { return m_children; }
737
738 virtual wxString GetName() const { return PropertyString(PROP_NAME); }
739
740 /**
741 * @brief return the "real" control name. By default the widget name is the name entered by the user
742 * in the "Name" field. In order for the code to compile properly, this name should be unique (in the top level
743 * window)
744 * However, some wxcWidgets have a "Name" property, but it should not be a unique (a good example for this, is a
745 * column name, which is not a real control)
746 * Such wxcWidgets may override this function and provide an empty string (or anything else)
747 */
748 virtual wxString GetRealName() const { return PropertyString(PROP_NAME); }
749
750 wxString GetVirtualFolder() const { return PropertyString(PROP_VIRTUAL_FOLDER); }
751 wxcWidget* GetParent() const { return m_parent; }
752 wxSize GetSize() const;
753 void RemoveFromParent();
754 wxString SizerFlags(const wxString& defaultFlags) const;
755 size_t SizerFlagsAsInteger() const;
756 wxString StyleFlags(const wxString& deafultStyle = "") const;
757 size_t StyleFlagsAsInteger() const;
758 virtual wxMenu* GetEventsMenu() { return m_eventsMenu; }
759
760 static CONTROL_TYPE GetWidgetType(int type);
761 CONTROL_TYPE GetWidgetType() const;
762
763 /**
764 * @brief return true of 'this' is a child (direct or indirect)
765 * of 'p'
766 */
767 bool IsDirectOrIndirectChildOf(wxcWidget* p) const;
768 void SetAuiPaneInfo(const AuiPaneInfo& auiPaneInfo) { this->m_auiPaneInfo = auiPaneInfo; }
769 const AuiPaneInfo& GetAuiPaneInfo() const { return m_auiPaneInfo; }
770
771 AuiPaneInfo& GetAuiPaneInfo() { return m_auiPaneInfo; }
772
773 /**
774 * @brief Recursively fills the set with every control's names in this (initially) top-level window
775 */
776 void StoreNames(std::set<wxString>& store);
777 };
778
779 #endif // WRAPPERBASE_H