]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
32b8ec41 VZ |
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 | ||
727eb4c1 | 15 | #if wxUSE_TREEBOOK && !defined(__WXHANDHELD__) |
f2fdc4d5 WS |
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) | |
261357eb | 21 | #define WidgetBookStyle (wxBK_DEFAULT) |
f2fdc4d5 WS |
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) | |
261357eb WS |
28 | #ifdef __POCKETPC__ |
29 | #define WidgetBookStyle (wxBK_BOTTOM|wxNB_FLAT) | |
30 | #else | |
31 | #define WidgetBookStyle (wxBK_DEFAULT) | |
32 | #endif | |
f2fdc4d5 WS |
33 | #endif |
34 | ||
261357eb | 35 | #if wxUSE_LOG && !defined(__WXHANDHELD__) |
f2fdc4d5 WS |
36 | #define USE_LOG 1 |
37 | #else | |
38 | #define USE_LOG 0 | |
39 | #endif | |
40 | ||
261357eb WS |
41 | #if defined(__WXHANDHELD__) |
42 | #define USE_ICONS_IN_BOOK 0 | |
43 | #else | |
44 | #define USE_ICONS_IN_BOOK 1 | |
45 | #endif | |
46 | ||
32b8ec41 | 47 | class WXDLLEXPORT wxCheckBox; |
32b8ec41 | 48 | class WXDLLEXPORT wxSizer; |
261357eb | 49 | class WXDLLEXPORT wxImageList; |
32b8ec41 | 50 | class WXDLLEXPORT wxTextCtrl; |
f2fdc4d5 | 51 | class WXDLLEXPORT WidgetsBookCtrl; |
32b8ec41 | 52 | |
2b5f62a0 | 53 | class WidgetsPageInfo; |
32b8ec41 | 54 | |
0b90b51c GD |
55 | #include "wx/panel.h" |
56 | ||
f2fdc4d5 WS |
57 | // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories' |
58 | enum | |
59 | { | |
d8d07a79 WS |
60 | // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.) |
61 | // 'native' means 'made with wxUniv port renderer' | |
f2fdc4d5 | 62 | NATIVE_PAGE = 0, |
d8d07a79 | 63 | UNIVERSAL_PAGE = NATIVE_PAGE, |
f2fdc4d5 WS |
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, | |
d8d07a79 | 77 | UNIVERSAL_CTRLS = NATIVE_CTRLS, |
f2fdc4d5 WS |
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 | }; | |
49abcb2f | 86 | |
32b8ec41 | 87 | // ---------------------------------------------------------------------------- |
61c083e7 | 88 | // WidgetsPage: a book page demonstrating some widget |
32b8ec41 VZ |
89 | // ---------------------------------------------------------------------------- |
90 | ||
91 | class WidgetsPage : public wxPanel | |
92 | { | |
93 | public: | |
261357eb WS |
94 | WidgetsPage(WidgetsBookCtrl *book, |
95 | wxImageList *imaglist, | |
96 | char* icon[]); | |
32b8ec41 | 97 | |
195df7a7 VZ |
98 | // return the control shown by this page |
99 | virtual wxControl *GetWidget() const = 0; | |
100 | ||
1c01dd16 VZ |
101 | // some pages show 2 controls, in this case override this one as well |
102 | virtual wxControl *GetWidget2() const { return NULL; } | |
103 | ||
1301e228 VZ |
104 | // recreate the control shown by this page |
105 | // | |
106 | // this is currently used only to take into account the border flags | |
107 | virtual void RecreateWidget() = 0; | |
108 | ||
109 | // the default flags for the widget, currently only contains border flags | |
110 | static int ms_defaultFlags; | |
111 | ||
32b8ec41 VZ |
112 | protected: |
113 | // several helper functions for page creation | |
114 | ||
115 | // create a horz sizer containing the given control and the text ctrl | |
116 | // (pointer to which will be saved in the provided variable if not NULL) | |
117 | // with the specified id | |
118 | wxSizer *CreateSizerWithText(wxControl *control, | |
206d3a16 | 119 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
120 | wxTextCtrl **ppText = NULL); |
121 | ||
122 | // create a sizer containing a label and a text ctrl | |
123 | wxSizer *CreateSizerWithTextAndLabel(const wxString& label, | |
206d3a16 | 124 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
125 | wxTextCtrl **ppText = NULL); |
126 | ||
127 | // create a sizer containing a button and a text ctrl | |
128 | wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn, | |
129 | const wxString& labelBtn, | |
206d3a16 | 130 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
131 | wxTextCtrl **ppText = NULL); |
132 | ||
133 | // create a checkbox and add it to the sizer | |
134 | wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
135 | const wxString& label, | |
206d3a16 | 136 | wxWindowID id = wxID_ANY); |
32b8ec41 VZ |
137 | |
138 | public: | |
139 | // the head of the linked list containinginfo about all pages | |
140 | static WidgetsPageInfo *ms_widgetPages; | |
141 | }; | |
142 | ||
143 | // ---------------------------------------------------------------------------- | |
144 | // dynamic WidgetsPage creation helpers | |
145 | // ---------------------------------------------------------------------------- | |
146 | ||
2b5f62a0 | 147 | class WidgetsPageInfo |
32b8ec41 VZ |
148 | { |
149 | public: | |
f2fdc4d5 | 150 | typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book, |
32b8ec41 VZ |
151 | wxImageList *imaglist); |
152 | ||
153 | // our ctor | |
f2fdc4d5 | 154 | WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories); |
32b8ec41 VZ |
155 | |
156 | // accessors | |
157 | const wxString& GetLabel() const { return m_label; } | |
f2fdc4d5 | 158 | int GetCategories() const { return m_categories; } |
32b8ec41 VZ |
159 | Constructor GetCtor() const { return m_ctor; } |
160 | WidgetsPageInfo *GetNext() const { return m_next; } | |
161 | ||
2673bcb0 DS |
162 | void SetNext(WidgetsPageInfo *next) { m_next = next; } |
163 | ||
32b8ec41 VZ |
164 | private: |
165 | // the label of the page | |
166 | wxString m_label; | |
167 | ||
f2fdc4d5 WS |
168 | // the list (flags) for sharing page between categories |
169 | int m_categories; | |
170 | ||
32b8ec41 VZ |
171 | // the function to create this page |
172 | Constructor m_ctor; | |
173 | ||
174 | // next node in the linked list or NULL | |
175 | WidgetsPageInfo *m_next; | |
176 | }; | |
177 | ||
178 | // to declare a page, this macro must be used in the class declaration | |
179 | #define DECLARE_WIDGETS_PAGE(classname) \ | |
180 | private: \ | |
181 | static WidgetsPageInfo ms_info##classname; \ | |
182 | public: \ | |
183 | const WidgetsPageInfo *GetPageInfo() const \ | |
184 | { return &ms_info##classname; } | |
185 | ||
186 | // and this one must be inserted somewhere in the source file | |
f2fdc4d5 WS |
187 | #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \ |
188 | WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \ | |
32b8ec41 | 189 | wxImageList *imaglist) \ |
61c083e7 | 190 | { return new classname(book, imaglist); } \ |
32b8ec41 | 191 | WidgetsPageInfo classname:: \ |
f2fdc4d5 | 192 | ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories) |
32b8ec41 VZ |
193 | |
194 | #endif // _WX_SAMPLE_WIDGETS_H_ |