]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/widgets.h
On-demand creation of the pages for speedup of sample launch.
[wxWidgets.git] / samples / widgets / widgets.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Program: wxWidgets Widgets Sample
3 // Name: widgets.h
4 // Purpose: Common stuff for all widgets project files
5 // Author: Vadim Zeitlin
6 // Created: 27.03.01
7 // Id: $Id$
8 // Copyright: (c) 2001 Vadim Zeitlin
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_SAMPLE_WIDGETS_H_
13 #define _WX_SAMPLE_WIDGETS_H_
14
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_CHANGED(id,func) EVT_TREEBOOK_PAGE_CHANGED(id,func)
21 #define WidgetBookStyle (wxBK_DEFAULT)
22 #else
23 #include "wx/bookctrl.h"
24 #define USE_TREEBOOK 0
25 #define WidgetsBookCtrl wxBookCtrl
26 #define WidgetsBookCtrlEvent wxBookCtrlEvent
27 #define EVT_WIDGETS_PAGE_CHANGED(id,func) EVT_BOOKCTRL_PAGE_CHANGED(id,func)
28 #ifdef __POCKETPC__
29 #define WidgetBookStyle (wxBK_BOTTOM|wxNB_FLAT)
30 #else
31 #define WidgetBookStyle (wxBK_DEFAULT)
32 #endif
33 #endif
34
35 #if wxUSE_LOG && !defined(__WXHANDHELD__)
36 #define USE_LOG 1
37 #else
38 #define USE_LOG 0
39 #endif
40
41 #if defined(__WXHANDHELD__)
42 #define USE_ICONS_IN_BOOK 0
43 #else
44 #define USE_ICONS_IN_BOOK 1
45 #endif
46
47 class WXDLLEXPORT wxCheckBox;
48 class WXDLLEXPORT wxSizer;
49 class WXDLLEXPORT wxImageList;
50 class WXDLLEXPORT wxTextCtrl;
51 class WXDLLEXPORT WidgetsBookCtrl;
52
53 class WidgetsPageInfo;
54
55 #include "wx/panel.h"
56
57 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
58 enum
59 {
60 // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.)
61 // 'native' means 'made with wxUniv port renderer'
62 NATIVE_PAGE = 0,
63 UNIVERSAL_PAGE = NATIVE_PAGE,
64 GENERIC_PAGE,
65 PICKER_PAGE,
66 COMBO_PAGE,
67 WITH_ITEMS_PAGE,
68 EDITABLE_PAGE,
69 BOOK_PAGE,
70 ALL_PAGE,
71 MAX_PAGES
72 };
73
74 enum
75 {
76 NATIVE_CTRLS = 1 << NATIVE_PAGE,
77 UNIVERSAL_CTRLS = NATIVE_CTRLS,
78 GENERIC_CTRLS = 1 << GENERIC_PAGE,
79 PICKER_CTRLS = 1 << PICKER_PAGE,
80 COMBO_CTRLS = 1 << COMBO_PAGE,
81 WITH_ITEMS_CTRLS = 1 << WITH_ITEMS_PAGE,
82 EDITABLE_CTRLS = 1 << EDITABLE_PAGE,
83 BOOK_CTRLS = 1 << BOOK_PAGE,
84 ALL_CTRLS = 1 << ALL_PAGE
85 };
86
87 // ----------------------------------------------------------------------------
88 // WidgetsPage: a book page demonstrating some widget
89 // ----------------------------------------------------------------------------
90
91 class WidgetsPage : public wxPanel
92 {
93 public:
94 WidgetsPage(WidgetsBookCtrl *book,
95 wxImageList *imaglist,
96 char* icon[]);
97
98 // return the control shown by this page
99 virtual wxControl *GetWidget() const = 0;
100
101 // lazy creation of the content
102 virtual void CreateContent() = 0;
103
104 // some pages show 2 controls, in this case override this one as well
105 virtual wxControl *GetWidget2() const { return NULL; }
106
107 // recreate the control shown by this page
108 //
109 // this is currently used only to take into account the border flags
110 virtual void RecreateWidget() = 0;
111
112 // the default flags for the widget, currently only contains border flags
113 static int ms_defaultFlags;
114
115 protected:
116 // several helper functions for page creation
117
118 // create a horz sizer containing the given control and the text ctrl
119 // (pointer to which will be saved in the provided variable if not NULL)
120 // with the specified id
121 wxSizer *CreateSizerWithText(wxControl *control,
122 wxWindowID id = wxID_ANY,
123 wxTextCtrl **ppText = NULL);
124
125 // create a sizer containing a label and a text ctrl
126 wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
127 wxWindowID id = wxID_ANY,
128 wxTextCtrl **ppText = NULL);
129
130 // create a sizer containing a button and a text ctrl
131 wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn,
132 const wxString& labelBtn,
133 wxWindowID id = wxID_ANY,
134 wxTextCtrl **ppText = NULL);
135
136 // create a checkbox and add it to the sizer
137 wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
138 const wxString& label,
139 wxWindowID id = wxID_ANY);
140
141 public:
142 // the head of the linked list containinginfo about all pages
143 static WidgetsPageInfo *ms_widgetPages;
144 };
145
146 // ----------------------------------------------------------------------------
147 // dynamic WidgetsPage creation helpers
148 // ----------------------------------------------------------------------------
149
150 class WidgetsPageInfo
151 {
152 public:
153 typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book,
154 wxImageList *imaglist);
155
156 // our ctor
157 WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories);
158
159 // accessors
160 const wxString& GetLabel() const { return m_label; }
161 int GetCategories() const { return m_categories; }
162 Constructor GetCtor() const { return m_ctor; }
163 WidgetsPageInfo *GetNext() const { return m_next; }
164
165 void SetNext(WidgetsPageInfo *next) { m_next = next; }
166
167 private:
168 // the label of the page
169 wxString m_label;
170
171 // the list (flags) for sharing page between categories
172 int m_categories;
173
174 // the function to create this page
175 Constructor m_ctor;
176
177 // next node in the linked list or NULL
178 WidgetsPageInfo *m_next;
179 };
180
181 // to declare a page, this macro must be used in the class declaration
182 #define DECLARE_WIDGETS_PAGE(classname) \
183 private: \
184 static WidgetsPageInfo ms_info##classname; \
185 public: \
186 const WidgetsPageInfo *GetPageInfo() const \
187 { return &ms_info##classname; }
188
189 // and this one must be inserted somewhere in the source file
190 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
191 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
192 wxImageList *imaglist) \
193 { return new classname(book, imaglist); } \
194 WidgetsPageInfo classname:: \
195 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
196
197 #endif // _WX_SAMPLE_WIDGETS_H_