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'
63 NATIVE_CTRLS
= 1 << NATIVE_PAGE
,
64 GENERIC_CTRLS
= 1 << GENERIC_PAGE
,
65 PICKER_CTRLS
= 1 << PICKER_PAGE
,
66 COMBO_CTRLS
= 1 << COMBO_PAGE
,
67 WITH_ITEMS_CTRLS
= 1 << WITH_ITEMS_PAGE
,
68 EDITABLE_CTRLS
= 1 << EDITABLE_PAGE
,
69 BOOK_CTRLS
= 1 << BOOK_PAGE
,
70 ALL_CTRLS
= 1 << ALL_PAGE
73 // ----------------------------------------------------------------------------
74 // WidgetsPage: a book page demonstrating some widget
75 // ----------------------------------------------------------------------------
77 class WidgetsPage
: public wxPanel
80 WidgetsPage(WidgetsBookCtrl
*book
);
82 // return the control shown by this page
83 virtual wxControl
*GetWidget() const = 0;
85 // some pages show 2 controls, in this case override this one as well
86 virtual wxControl
*GetWidget2() const { return NULL
; }
88 // recreate the control shown by this page
90 // this is currently used only to take into account the border flags
91 virtual void RecreateWidget() = 0;
93 // the default flags for the widget, currently only contains border flags
94 static int ms_defaultFlags
;
97 // several helper functions for page creation
99 // create a horz sizer containing the given control and the text ctrl
100 // (pointer to which will be saved in the provided variable if not NULL)
101 // with the specified id
102 wxSizer
*CreateSizerWithText(wxControl
*control
,
103 wxWindowID id
= wxID_ANY
,
104 wxTextCtrl
**ppText
= NULL
);
106 // create a sizer containing a label and a text ctrl
107 wxSizer
*CreateSizerWithTextAndLabel(const wxString
& label
,
108 wxWindowID id
= wxID_ANY
,
109 wxTextCtrl
**ppText
= NULL
);
111 // create a sizer containing a button and a text ctrl
112 wxSizer
*CreateSizerWithTextAndButton(wxWindowID idBtn
,
113 const wxString
& labelBtn
,
114 wxWindowID id
= wxID_ANY
,
115 wxTextCtrl
**ppText
= NULL
);
117 // create a checkbox and add it to the sizer
118 wxCheckBox
*CreateCheckBoxAndAddToSizer(wxSizer
*sizer
,
119 const wxString
& label
,
120 wxWindowID id
= wxID_ANY
);
123 // the head of the linked list containinginfo about all pages
124 static WidgetsPageInfo
*ms_widgetPages
;
127 // ----------------------------------------------------------------------------
128 // dynamic WidgetsPage creation helpers
129 // ----------------------------------------------------------------------------
131 class WidgetsPageInfo
134 typedef WidgetsPage
*(*Constructor
)(WidgetsBookCtrl
*book
,
135 wxImageList
*imaglist
);
138 WidgetsPageInfo(Constructor ctor
, const wxChar
*label
, int categories
);
141 const wxString
& GetLabel() const { return m_label
; }
142 int GetCategories() const { return m_categories
; }
143 Constructor
GetCtor() const { return m_ctor
; }
144 WidgetsPageInfo
*GetNext() const { return m_next
; }
146 void SetNext(WidgetsPageInfo
*next
) { m_next
= next
; }
149 // the label of the page
152 // the list (flags) for sharing page between categories
155 // the function to create this page
158 // next node in the linked list or NULL
159 WidgetsPageInfo
*m_next
;
162 // to declare a page, this macro must be used in the class declaration
163 #define DECLARE_WIDGETS_PAGE(classname) \
165 static WidgetsPageInfo ms_info##classname; \
167 const WidgetsPageInfo *GetPageInfo() const \
168 { return &ms_info##classname; }
170 // and this one must be inserted somewhere in the source file
171 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
172 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
173 wxImageList *imaglist) \
174 { return new classname(book, imaglist); } \
175 WidgetsPageInfo classname:: \
176 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
178 #endif // _WX_SAMPLE_WIDGETS_H_