1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
4 // Purpose: Common stuff for all widgets project files
5 // Author: Vadim Zeitlin
7 // Copyright: (c) 2001 Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_SAMPLE_WIDGETS_H_
12 #define _WX_SAMPLE_WIDGETS_H_
14 #if wxUSE_TREEBOOK && !defined(__WXHANDHELD__)
15 #include "wx/treebook.h"
16 #define USE_TREEBOOK 1
17 #define WidgetsBookCtrl wxTreebook
18 #define WidgetsBookCtrlEvent wxTreebookEvent
19 #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_TREEBOOK_PAGE_CHANGING(id,func)
20 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_TREEBOOK_PAGE_CHANGED
21 #define wxWidgetsbookEventHandler(func) wxTreebookEventHandler(func)
23 #include "wx/bookctrl.h"
24 #define USE_TREEBOOK 0
25 #define WidgetsBookCtrl wxBookCtrl
26 #define WidgetsBookCtrlEvent wxBookCtrlEvent
27 #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_BOOKCTRL_PAGE_CHANGING(id,func)
28 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_BOOKCTRL_PAGE_CHANGED
29 #define wxWidgetsbookEventHandler(func) wxBookCtrlEventHandler(func)
32 #if wxUSE_LOG && !defined(__WXHANDHELD__)
38 #if defined(__WXHANDHELD__)
39 #define USE_ICONS_IN_BOOK 0
41 #define USE_ICONS_IN_BOOK 1
45 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
46 class WXDLLIMPEXP_FWD_CORE wxSizer
;
47 class WXDLLIMPEXP_FWD_CORE wxImageList
;
48 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
49 class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl
;
51 class WidgetsPageInfo
;
54 #include "wx/vector.h"
56 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
59 // In wxUniversal-based builds 'native' means 'made with wxUniv port
62 UNIVERSAL_PAGE
= NATIVE_PAGE
,
75 NATIVE_CTRLS
= 1 << NATIVE_PAGE
,
76 UNIVERSAL_CTRLS
= NATIVE_CTRLS
,
77 GENERIC_CTRLS
= 1 << GENERIC_PAGE
,
78 PICKER_CTRLS
= 1 << PICKER_PAGE
,
79 COMBO_CTRLS
= 1 << COMBO_PAGE
,
80 WITH_ITEMS_CTRLS
= 1 << WITH_ITEMS_PAGE
,
81 EDITABLE_CTRLS
= 1 << EDITABLE_PAGE
,
82 BOOK_CTRLS
= 1 << BOOK_PAGE
,
83 ALL_CTRLS
= 1 << ALL_PAGE
86 typedef wxVector
<wxControl
*> Widgets
;
88 // ----------------------------------------------------------------------------
89 // WidgetsPage: a book page demonstrating some widget
90 // ----------------------------------------------------------------------------
92 class WidgetsPage
: public wxPanel
95 WidgetsPage(WidgetsBookCtrl
*book
,
96 wxImageList
*imaglist
,
97 const char *const icon
[]);
99 // return the control shown by this page
100 virtual wxControl
*GetWidget() const = 0;
102 // return the control shown by this page, if it supports text entry interface
103 virtual wxTextEntryBase
*GetTextEntry() const { return NULL
; }
105 // lazy creation of the content
106 virtual void CreateContent() = 0;
108 // some pages show additional controls, in this case override this one to
109 // return all of them (including the one returned by GetWidget())
110 virtual Widgets
GetWidgets() const
113 widgets
.push_back(GetWidget());
117 // recreate the control shown by this page
119 // this is currently used only to take into account the border flags
120 virtual void RecreateWidget() = 0;
122 // the default flags for the widget, currently only contains border flags
123 static int ms_defaultFlags
;
126 // several helper functions for page creation
128 // create a horz sizer containing the given control and the text ctrl
129 // (pointer to which will be saved in the provided variable if not NULL)
130 // with the specified id
131 wxSizer
*CreateSizerWithText(wxControl
*control
,
132 wxWindowID id
= wxID_ANY
,
133 wxTextCtrl
**ppText
= NULL
);
135 // create a sizer containing a label and a text ctrl
136 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
137 wxWindowID id
= wxID_ANY
,
138 wxTextCtrl
**ppText
= NULL
);
140 // create a sizer containing a button and a text ctrl
141 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
142 const wxString
& labelBtn
,
143 wxWindowID id
= wxID_ANY
,
144 wxTextCtrl
**ppText
= NULL
);
146 // create a checkbox and add it to the sizer
147 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
148 const wxString
& label
,
149 wxWindowID id
= wxID_ANY
);
152 // the head of the linked list containinginfo about all pages
153 static WidgetsPageInfo
*ms_widgetPages
;
156 // ----------------------------------------------------------------------------
157 // dynamic WidgetsPage creation helpers
158 // ----------------------------------------------------------------------------
160 class WidgetsPageInfo
163 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
164 wxImageList
*imaglist
);
167 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
170 const wxString
& GetLabel() const { return m_label
; }
171 int GetCategories() const { return m_categories
; }
172 Constructor
GetCtor() const { return m_ctor
; }
173 WidgetsPageInfo
*GetNext() const { return m_next
; }
175 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
178 // the label of the page
181 // the list (flags) for sharing page between categories
184 // the function to create this page
187 // next node in the linked list or NULL
188 WidgetsPageInfo
*m_next
;
191 // to declare a page, this macro must be used in the class declaration
192 #define DECLARE_WIDGETS_PAGE(classname) \
194 static WidgetsPageInfo ms_info##classname; \
196 const WidgetsPageInfo *GetPageInfo() const \
197 { return &ms_info##classname; }
199 // and this one must be inserted somewhere in the source file
200 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
201 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
202 wxImageList *imaglist) \
203 { return new classname(book, imaglist); } \
204 WidgetsPageInfo classname:: \
205 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
207 #endif // _WX_SAMPLE_WIDGETS_H_