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
46 class WXDLLIMPEXP_FWD_CORE wxCheckBox
;
47 class WXDLLIMPEXP_FWD_CORE wxSizer
;
48 class WXDLLIMPEXP_FWD_CORE wxImageList
;
49 class WXDLLIMPEXP_FWD_CORE wxTextCtrl
;
50 class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl
;
52 class WidgetsPageInfo
;
56 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
59 // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.)
60 // 'native' means 'made with wxUniv port renderer'
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 // ----------------------------------------------------------------------------
87 // WidgetsPage: a book page demonstrating some widget
88 // ----------------------------------------------------------------------------
90 class WidgetsPage
: public wxPanel
93 WidgetsPage(WidgetsBookCtrl
*book
,
94 wxImageList
*imaglist
,
95 const char *const icon
[]);
97 // return the control shown by this page
98 virtual wxControl
*GetWidget() const = 0;
100 // lazy creation of the content
101 virtual void CreateContent() = 0;
103 // some pages show 2 controls, in this case override this one as well
104 virtual wxControl
*GetWidget2() const { return NULL
; }
106 // recreate the control shown by this page
108 // this is currently used only to take into account the border flags
109 virtual void RecreateWidget() = 0;
111 // the default flags for the widget, currently only contains border flags
112 static int ms_defaultFlags
;
115 // several helper functions for page creation
117 // create a horz sizer containing the given control and the text ctrl
118 // (pointer to which will be saved in the provided variable if not NULL)
119 // with the specified id
120 wxSizer
*CreateSizerWithText(wxControl
*control
,
121 wxWindowID id
= wxID_ANY
,
122 wxTextCtrl
**ppText
= NULL
);
124 // create a sizer containing a label and a text ctrl
125 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
126 wxWindowID id
= wxID_ANY
,
127 wxTextCtrl
**ppText
= NULL
);
129 // create a sizer containing a button and a text ctrl
130 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
131 const wxString
& labelBtn
,
132 wxWindowID id
= wxID_ANY
,
133 wxTextCtrl
**ppText
= NULL
);
135 // create a checkbox and add it to the sizer
136 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
137 const wxString
& label
,
138 wxWindowID id
= wxID_ANY
);
141 // the head of the linked list containinginfo about all pages
142 static WidgetsPageInfo
*ms_widgetPages
;
145 // ----------------------------------------------------------------------------
146 // dynamic WidgetsPage creation helpers
147 // ----------------------------------------------------------------------------
149 class WidgetsPageInfo
152 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
153 wxImageList
*imaglist
);
156 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
159 const wxString
& GetLabel() const { return m_label
; }
160 int GetCategories() const { return m_categories
; }
161 Constructor
GetCtor() const { return m_ctor
; }
162 WidgetsPageInfo
*GetNext() const { return m_next
; }
164 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
167 // the label of the page
170 // the list (flags) for sharing page between categories
173 // the function to create this page
176 // next node in the linked list or NULL
177 WidgetsPageInfo
*m_next
;
180 // to declare a page, this macro must be used in the class declaration
181 #define DECLARE_WIDGETS_PAGE(classname) \
183 static WidgetsPageInfo ms_info##classname; \
185 const WidgetsPageInfo *GetPageInfo() const \
186 { return &ms_info##classname; }
188 // and this one must be inserted somewhere in the source file
189 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
190 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
191 wxImageList *imaglist) \
192 { return new classname(book, imaglist); } \
193 WidgetsPageInfo classname:: \
194 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
196 #endif // _WX_SAMPLE_WIDGETS_H_