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_
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(__SMARTPHONE__)
35 class WXDLLEXPORT wxCheckBox
;
36 class WXDLLEXPORT wxSizer
;
37 class WXDLLEXPORT wxTextCtrl
;
38 class WXDLLEXPORT WidgetsBookCtrl
;
40 class WidgetsPageInfo
;
44 // all source files use wxImageList
45 #include "wx/imaglist.h"
47 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
50 // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.)
51 // 'native' means 'made with wxUniv port renderer'
53 UNIVERSAL_PAGE
= NATIVE_PAGE
,
66 NATIVE_CTRLS
= 1 << NATIVE_PAGE
,
67 UNIVERSAL_CTRLS
= NATIVE_CTRLS
,
68 GENERIC_CTRLS
= 1 << GENERIC_PAGE
,
69 PICKER_CTRLS
= 1 << PICKER_PAGE
,
70 COMBO_CTRLS
= 1 << COMBO_PAGE
,
71 WITH_ITEMS_CTRLS
= 1 << WITH_ITEMS_PAGE
,
72 EDITABLE_CTRLS
= 1 << EDITABLE_PAGE
,
73 BOOK_CTRLS
= 1 << BOOK_PAGE
,
74 ALL_CTRLS
= 1 << ALL_PAGE
77 // ----------------------------------------------------------------------------
78 // WidgetsPage: a book page demonstrating some widget
79 // ----------------------------------------------------------------------------
81 class WidgetsPage
: public wxPanel
84 WidgetsPage(WidgetsBookCtrl
*book
);
86 // return the control shown by this page
87 virtual wxControl
*GetWidget() const = 0;
89 // some pages show 2 controls, in this case override this one as well
90 virtual wxControl
*GetWidget2() const { return NULL
; }
92 // recreate the control shown by this page
94 // this is currently used only to take into account the border flags
95 virtual void RecreateWidget() = 0;
97 // the default flags for the widget, currently only contains border flags
98 static int ms_defaultFlags
;
101 // several helper functions for page creation
103 // create a horz sizer containing the given control and the text ctrl
104 // (pointer to which will be saved in the provided variable if not NULL)
105 // with the specified id
106 wxSizer
*CreateSizerWithText(wxControl
*control
,
107 wxWindowID id
= wxID_ANY
,
108 wxTextCtrl
**ppText
= NULL
);
110 // create a sizer containing a label and a text ctrl
111 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
112 wxWindowID id
= wxID_ANY
,
113 wxTextCtrl
**ppText
= NULL
);
115 // create a sizer containing a button and a text ctrl
116 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
117 const wxString
& labelBtn
,
118 wxWindowID id
= wxID_ANY
,
119 wxTextCtrl
**ppText
= NULL
);
121 // create a checkbox and add it to the sizer
122 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
123 const wxString
& label
,
124 wxWindowID id
= wxID_ANY
);
127 // the head of the linked list containinginfo about all pages
128 static WidgetsPageInfo
*ms_widgetPages
;
131 // ----------------------------------------------------------------------------
132 // dynamic WidgetsPage creation helpers
133 // ----------------------------------------------------------------------------
135 class WidgetsPageInfo
138 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
139 wxImageList
*imaglist
);
142 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
145 const wxString
& GetLabel() const { return m_label
; }
146 int GetCategories() const { return m_categories
; }
147 Constructor
GetCtor() const { return m_ctor
; }
148 WidgetsPageInfo
*GetNext() const { return m_next
; }
150 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
153 // the label of the page
156 // the list (flags) for sharing page between categories
159 // the function to create this page
162 // next node in the linked list or NULL
163 WidgetsPageInfo
*m_next
;
166 // to declare a page, this macro must be used in the class declaration
167 #define DECLARE_WIDGETS_PAGE(classname) \
169 static WidgetsPageInfo ms_info##classname; \
171 const WidgetsPageInfo *GetPageInfo() const \
172 { return &ms_info##classname; }
174 // and this one must be inserted somewhere in the source file
175 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
176 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
177 wxImageList *imaglist) \
178 { return new classname(book, imaglist); } \
179 WidgetsPageInfo classname:: \
180 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
182 #endif // _WX_SAMPLE_WIDGETS_H_