]>
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 | ||
fe5dc33d | 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 | |
3e859739 | 20 | #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_TREEBOOK_PAGE_CHANGING(id,func) |
0cebbfc2 WS |
21 | #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_COMMAND_TREEBOOK_PAGE_CHANGED |
22 | #define wxWidgetsbookEventHandler(func) wxTreebookEventHandler(func) | |
f2fdc4d5 WS |
23 | #else |
24 | #include "wx/bookctrl.h" | |
25 | #define USE_TREEBOOK 0 | |
26 | #define WidgetsBookCtrl wxBookCtrl | |
27 | #define WidgetsBookCtrlEvent wxBookCtrlEvent | |
3e859739 | 28 | #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_BOOKCTRL_PAGE_CHANGING(id,func) |
0cebbfc2 | 29 | #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_COMMAND_BOOKCTRL_PAGE_CHANGED |
d3d256ef | 30 | #define wxWidgetsbookEventHandler(func) wxBookCtrlEventHandler(func) |
f2fdc4d5 WS |
31 | #endif |
32 | ||
261357eb | 33 | #if wxUSE_LOG && !defined(__WXHANDHELD__) |
f2fdc4d5 WS |
34 | #define USE_LOG 1 |
35 | #else | |
36 | #define USE_LOG 0 | |
37 | #endif | |
38 | ||
261357eb WS |
39 | #if defined(__WXHANDHELD__) |
40 | #define USE_ICONS_IN_BOOK 0 | |
41 | #else | |
42 | #define USE_ICONS_IN_BOOK 1 | |
993b016d | 43 | #define ICON_SIZE 16 |
261357eb WS |
44 | #endif |
45 | ||
7742ea6a PC |
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; | |
32b8ec41 | 51 | |
2b5f62a0 | 52 | class WidgetsPageInfo; |
32b8ec41 | 53 | |
0b90b51c GD |
54 | #include "wx/panel.h" |
55 | ||
f2fdc4d5 WS |
56 | // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories' |
57 | enum | |
58 | { | |
d8d07a79 WS |
59 | // On wxUniversal-based build (wxX11, wxMGL, wxMSWUniv, wxGTKUniv, etc.) |
60 | // 'native' means 'made with wxUniv port renderer' | |
f2fdc4d5 | 61 | NATIVE_PAGE = 0, |
d8d07a79 | 62 | UNIVERSAL_PAGE = NATIVE_PAGE, |
f2fdc4d5 WS |
63 | GENERIC_PAGE, |
64 | PICKER_PAGE, | |
65 | COMBO_PAGE, | |
66 | WITH_ITEMS_PAGE, | |
67 | EDITABLE_PAGE, | |
68 | BOOK_PAGE, | |
69 | ALL_PAGE, | |
70 | MAX_PAGES | |
71 | }; | |
72 | ||
73 | enum | |
74 | { | |
75 | NATIVE_CTRLS = 1 << NATIVE_PAGE, | |
d8d07a79 | 76 | UNIVERSAL_CTRLS = NATIVE_CTRLS, |
f2fdc4d5 WS |
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 | |
84 | }; | |
49abcb2f | 85 | |
32b8ec41 | 86 | // ---------------------------------------------------------------------------- |
61c083e7 | 87 | // WidgetsPage: a book page demonstrating some widget |
32b8ec41 VZ |
88 | // ---------------------------------------------------------------------------- |
89 | ||
90 | class WidgetsPage : public wxPanel | |
91 | { | |
92 | public: | |
261357eb WS |
93 | WidgetsPage(WidgetsBookCtrl *book, |
94 | wxImageList *imaglist, | |
747d7d7c | 95 | const char *const icon[]); |
32b8ec41 | 96 | |
195df7a7 VZ |
97 | // return the control shown by this page |
98 | virtual wxControl *GetWidget() const = 0; | |
99 | ||
6a8d7937 VZ |
100 | // return the control shown by this page, if it supports text entry interface |
101 | virtual wxTextEntryBase *GetTextEntry() const { return NULL; } | |
102 | ||
453535a7 WS |
103 | // lazy creation of the content |
104 | virtual void CreateContent() = 0; | |
105 | ||
1c01dd16 VZ |
106 | // some pages show 2 controls, in this case override this one as well |
107 | virtual wxControl *GetWidget2() const { return NULL; } | |
108 | ||
1301e228 VZ |
109 | // recreate the control shown by this page |
110 | // | |
111 | // this is currently used only to take into account the border flags | |
112 | virtual void RecreateWidget() = 0; | |
113 | ||
114 | // the default flags for the widget, currently only contains border flags | |
115 | static int ms_defaultFlags; | |
116 | ||
32b8ec41 VZ |
117 | protected: |
118 | // several helper functions for page creation | |
119 | ||
120 | // create a horz sizer containing the given control and the text ctrl | |
121 | // (pointer to which will be saved in the provided variable if not NULL) | |
122 | // with the specified id | |
123 | wxSizer *CreateSizerWithText(wxControl *control, | |
206d3a16 | 124 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
125 | wxTextCtrl **ppText = NULL); |
126 | ||
127 | // create a sizer containing a label and a text ctrl | |
128 | wxSizer *CreateSizerWithTextAndLabel(const wxString& label, | |
206d3a16 | 129 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
130 | wxTextCtrl **ppText = NULL); |
131 | ||
132 | // create a sizer containing a button and a text ctrl | |
133 | wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn, | |
134 | const wxString& labelBtn, | |
206d3a16 | 135 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
136 | wxTextCtrl **ppText = NULL); |
137 | ||
138 | // create a checkbox and add it to the sizer | |
139 | wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
140 | const wxString& label, | |
206d3a16 | 141 | wxWindowID id = wxID_ANY); |
32b8ec41 VZ |
142 | |
143 | public: | |
144 | // the head of the linked list containinginfo about all pages | |
145 | static WidgetsPageInfo *ms_widgetPages; | |
146 | }; | |
147 | ||
148 | // ---------------------------------------------------------------------------- | |
149 | // dynamic WidgetsPage creation helpers | |
150 | // ---------------------------------------------------------------------------- | |
151 | ||
2b5f62a0 | 152 | class WidgetsPageInfo |
32b8ec41 VZ |
153 | { |
154 | public: | |
f2fdc4d5 | 155 | typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book, |
32b8ec41 VZ |
156 | wxImageList *imaglist); |
157 | ||
158 | // our ctor | |
f2fdc4d5 | 159 | WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories); |
32b8ec41 VZ |
160 | |
161 | // accessors | |
162 | const wxString& GetLabel() const { return m_label; } | |
f2fdc4d5 | 163 | int GetCategories() const { return m_categories; } |
32b8ec41 VZ |
164 | Constructor GetCtor() const { return m_ctor; } |
165 | WidgetsPageInfo *GetNext() const { return m_next; } | |
166 | ||
2673bcb0 DS |
167 | void SetNext(WidgetsPageInfo *next) { m_next = next; } |
168 | ||
32b8ec41 VZ |
169 | private: |
170 | // the label of the page | |
171 | wxString m_label; | |
172 | ||
f2fdc4d5 WS |
173 | // the list (flags) for sharing page between categories |
174 | int m_categories; | |
175 | ||
32b8ec41 VZ |
176 | // the function to create this page |
177 | Constructor m_ctor; | |
178 | ||
179 | // next node in the linked list or NULL | |
180 | WidgetsPageInfo *m_next; | |
181 | }; | |
182 | ||
183 | // to declare a page, this macro must be used in the class declaration | |
184 | #define DECLARE_WIDGETS_PAGE(classname) \ | |
185 | private: \ | |
186 | static WidgetsPageInfo ms_info##classname; \ | |
187 | public: \ | |
188 | const WidgetsPageInfo *GetPageInfo() const \ | |
189 | { return &ms_info##classname; } | |
190 | ||
191 | // and this one must be inserted somewhere in the source file | |
f2fdc4d5 WS |
192 | #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \ |
193 | WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \ | |
32b8ec41 | 194 | wxImageList *imaglist) \ |
61c083e7 | 195 | { return new classname(book, imaglist); } \ |
32b8ec41 | 196 | WidgetsPageInfo classname:: \ |
f2fdc4d5 | 197 | ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories) |
32b8ec41 VZ |
198 | |
199 | #endif // _WX_SAMPLE_WIDGETS_H_ |