1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Common stuff for all widgets project files
5 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_SAMPLE_WIDGETS_H_
13 #define _WX_SAMPLE_WIDGETS_H_
15 #if wxUSE_TREEBOOK && !defined(__WXHANDHELD__)
16 #include "wx/treebook.h"
17 #define USE_TREEBOOK 1
18 #define WidgetsBookCtrl wxTreebook
19 #define WidgetsBookCtrlEvent wxTreebookEvent
20 #define EVT_WIDGETS_PAGE_CHANGED(id,func) EVT_TREEBOOK_PAGE_CHANGED(id,func)
22 #include "wx/bookctrl.h"
23 #define USE_TREEBOOK 0
24 #define WidgetsBookCtrl wxBookCtrl
25 #define WidgetsBookCtrlEvent wxBookCtrlEvent
26 #define EVT_WIDGETS_PAGE_CHANGED(id,func) EVT_BOOKCTRL_PAGE_CHANGED(id,func)
29 #if wxUSE_LOG && !defined(__WXHANDHELD__)
35 #if defined(__WXHANDHELD__)
36 #define USE_ICONS_IN_BOOK 0
38 #define USE_ICONS_IN_BOOK 1
41 class WXDLLEXPORT wxCheckBox
;
42 class WXDLLEXPORT wxSizer
;
43 class WXDLLEXPORT wxImageList
;
44 class WXDLLEXPORT wxTextCtrl
;
45 class WXDLLEXPORT WidgetsBookCtrl
;
47 class WidgetsPageInfo
;
51 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
54 // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.)
55 // 'native' means 'made with wxUniv port renderer'
57 UNIVERSAL_PAGE
= NATIVE_PAGE
,
70 NATIVE_CTRLS
= 1 << NATIVE_PAGE
,
71 UNIVERSAL_CTRLS
= NATIVE_CTRLS
,
72 GENERIC_CTRLS
= 1 << GENERIC_PAGE
,
73 PICKER_CTRLS
= 1 << PICKER_PAGE
,
74 COMBO_CTRLS
= 1 << COMBO_PAGE
,
75 WITH_ITEMS_CTRLS
= 1 << WITH_ITEMS_PAGE
,
76 EDITABLE_CTRLS
= 1 << EDITABLE_PAGE
,
77 BOOK_CTRLS
= 1 << BOOK_PAGE
,
78 ALL_CTRLS
= 1 << ALL_PAGE
81 // ----------------------------------------------------------------------------
82 // WidgetsPage: a book page demonstrating some widget
83 // ----------------------------------------------------------------------------
85 class WidgetsPage
: public wxPanel
88 WidgetsPage(WidgetsBookCtrl
*book
,
89 wxImageList
*imaglist
,
92 // return the control shown by this page
93 virtual wxControl
*GetWidget() const = 0;
95 // lazy creation of the content
96 virtual void CreateContent() = 0;
98 // some pages show 2 controls, in this case override this one as well
99 virtual wxControl
*GetWidget2() const { return NULL
; }
101 // recreate the control shown by this page
103 // this is currently used only to take into account the border flags
104 virtual void RecreateWidget() = 0;
106 // the default flags for the widget, currently only contains border flags
107 static int ms_defaultFlags
;
110 // several helper functions for page creation
112 // create a horz sizer containing the given control and the text ctrl
113 // (pointer to which will be saved in the provided variable if not NULL)
114 // with the specified id
115 wxSizer
*CreateSizerWithText(wxControl
*control
,
116 wxWindowID id
= wxID_ANY
,
117 wxTextCtrl
**ppText
= NULL
);
119 // create a sizer containing a label and a text ctrl
120 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
121 wxWindowID id
= wxID_ANY
,
122 wxTextCtrl
**ppText
= NULL
);
124 // create a sizer containing a button and a text ctrl
125 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
126 const wxString
& labelBtn
,
127 wxWindowID id
= wxID_ANY
,
128 wxTextCtrl
**ppText
= NULL
);
130 // create a checkbox and add it to the sizer
131 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
132 const wxString
& label
,
133 wxWindowID id
= wxID_ANY
);
136 // the head of the linked list containinginfo about all pages
137 static WidgetsPageInfo
*ms_widgetPages
;
140 // ----------------------------------------------------------------------------
141 // dynamic WidgetsPage creation helpers
142 // ----------------------------------------------------------------------------
144 class WidgetsPageInfo
147 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
148 wxImageList
*imaglist
);
151 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
154 const wxString
& GetLabel() const { return m_label
; }
155 int GetCategories() const { return m_categories
; }
156 Constructor
GetCtor() const { return m_ctor
; }
157 WidgetsPageInfo
*GetNext() const { return m_next
; }
159 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
162 // the label of the page
165 // the list (flags) for sharing page between categories
168 // the function to create this page
171 // next node in the linked list or NULL
172 WidgetsPageInfo
*m_next
;
175 // to declare a page, this macro must be used in the class declaration
176 #define DECLARE_WIDGETS_PAGE(classname) \
178 static WidgetsPageInfo ms_info##classname; \
180 const WidgetsPageInfo *GetPageInfo() const \
181 { return &ms_info##classname; }
183 // and this one must be inserted somewhere in the source file
184 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
185 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
186 wxImageList *imaglist) \
187 { return new classname(book, imaglist); } \
188 WidgetsPageInfo classname:: \
189 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
191 #endif // _WX_SAMPLE_WIDGETS_H_