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_CHANGING(id,func) EVT_TREEBOOK_PAGE_CHANGING(id,func)
21 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED
22 #define wxWidgetsbookEventHandler(func) wxTreebookEventHandler(func)
24 #include "wx/bookctrl.h"
25 #define USE_TREEBOOK 0
26 #define WidgetsBookCtrl wxBookCtrl
27 #define WidgetsBookCtrlEvent wxBookCtrlEvent
28 #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_BOOKCTRL_PAGE_CHANGING(id,func)
29 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED
30 #define wxWidgetsbookEventHandler(func) wxBookctrlEventHandler(func)
33 #if wxUSE_LOG && !defined(__WXHANDHELD__)
39 #if defined(__WXHANDHELD__)
40 #define USE_ICONS_IN_BOOK 0
42 #define USE_ICONS_IN_BOOK 1
45 class WXDLLEXPORT wxCheckBox
;
46 class WXDLLEXPORT wxSizer
;
47 class WXDLLEXPORT wxImageList
;
48 class WXDLLEXPORT wxTextCtrl
;
49 class WXDLLEXPORT WidgetsBookCtrl
;
51 class WidgetsPageInfo
;
55 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
58 // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.)
59 // 'native' means 'made with wxUniv port renderer'
61 UNIVERSAL_PAGE
= NATIVE_PAGE
,
74 NATIVE_CTRLS
= 1 << NATIVE_PAGE
,
75 UNIVERSAL_CTRLS
= NATIVE_CTRLS
,
76 GENERIC_CTRLS
= 1 << GENERIC_PAGE
,
77 PICKER_CTRLS
= 1 << PICKER_PAGE
,
78 COMBO_CTRLS
= 1 << COMBO_PAGE
,
79 WITH_ITEMS_CTRLS
= 1 << WITH_ITEMS_PAGE
,
80 EDITABLE_CTRLS
= 1 << EDITABLE_PAGE
,
81 BOOK_CTRLS
= 1 << BOOK_PAGE
,
82 ALL_CTRLS
= 1 << ALL_PAGE
85 // ----------------------------------------------------------------------------
86 // WidgetsPage: a book page demonstrating some widget
87 // ----------------------------------------------------------------------------
89 class WidgetsPage
: public wxPanel
92 WidgetsPage(WidgetsBookCtrl
*book
,
93 wxImageList
*imaglist
,
96 // return the control shown by this page
97 virtual wxControl
*GetWidget() const = 0;
99 // lazy creation of the content
100 virtual void CreateContent() = 0;
102 // some pages show 2 controls, in this case override this one as well
103 virtual wxControl
*GetWidget2() const { return NULL
; }
105 // recreate the control shown by this page
107 // this is currently used only to take into account the border flags
108 virtual void RecreateWidget() = 0;
110 // the default flags for the widget, currently only contains border flags
111 static int ms_defaultFlags
;
114 // several helper functions for page creation
116 // create a horz sizer containing the given control and the text ctrl
117 // (pointer to which will be saved in the provided variable if not NULL)
118 // with the specified id
119 wxSizer
*CreateSizerWithText(wxControl
*control
,
120 wxWindowID id
= wxID_ANY
,
121 wxTextCtrl
**ppText
= NULL
);
123 // create a sizer containing a label and a text ctrl
124 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
125 wxWindowID id
= wxID_ANY
,
126 wxTextCtrl
**ppText
= NULL
);
128 // create a sizer containing a button and a text ctrl
129 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
130 const wxString
& labelBtn
,
131 wxWindowID id
= wxID_ANY
,
132 wxTextCtrl
**ppText
= NULL
);
134 // create a checkbox and add it to the sizer
135 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
136 const wxString
& label
,
137 wxWindowID id
= wxID_ANY
);
140 // the head of the linked list containinginfo about all pages
141 static WidgetsPageInfo
*ms_widgetPages
;
144 // ----------------------------------------------------------------------------
145 // dynamic WidgetsPage creation helpers
146 // ----------------------------------------------------------------------------
148 class WidgetsPageInfo
151 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
152 wxImageList
*imaglist
);
155 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
158 const wxString
& GetLabel() const { return m_label
; }
159 int GetCategories() const { return m_categories
; }
160 Constructor
GetCtor() const { return m_ctor
; }
161 WidgetsPageInfo
*GetNext() const { return m_next
; }
163 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
166 // the label of the page
169 // the list (flags) for sharing page between categories
172 // the function to create this page
175 // next node in the linked list or NULL
176 WidgetsPageInfo
*m_next
;
179 // to declare a page, this macro must be used in the class declaration
180 #define DECLARE_WIDGETS_PAGE(classname) \
182 static WidgetsPageInfo ms_info##classname; \
184 const WidgetsPageInfo *GetPageInfo() const \
185 { return &ms_info##classname; }
187 // and this one must be inserted somewhere in the source file
188 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
189 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
190 wxImageList *imaglist) \
191 { return new classname(book, imaglist); } \
192 WidgetsPageInfo classname:: \
193 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
195 #endif // _WX_SAMPLE_WIDGETS_H_