]>
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 | ||
f2fdc4d5 WS |
15 | #if wxUSE_TREEBOOK |
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 | #else | |
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) | |
27 | #endif | |
28 | ||
29 | #if wxUSE_LOG && !defined(__SMARTPHONE__) | |
30 | #define USE_LOG 1 | |
31 | #else | |
32 | #define USE_LOG 0 | |
33 | #endif | |
34 | ||
32b8ec41 | 35 | class WXDLLEXPORT wxCheckBox; |
32b8ec41 VZ |
36 | class WXDLLEXPORT wxSizer; |
37 | class WXDLLEXPORT wxTextCtrl; | |
f2fdc4d5 | 38 | class WXDLLEXPORT WidgetsBookCtrl; |
32b8ec41 | 39 | |
2b5f62a0 | 40 | class WidgetsPageInfo; |
32b8ec41 | 41 | |
0b90b51c GD |
42 | #include "wx/panel.h" |
43 | ||
32b8ec41 VZ |
44 | // all source files use wxImageList |
45 | #include "wx/imaglist.h" | |
46 | ||
f2fdc4d5 WS |
47 | // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories' |
48 | enum | |
49 | { | |
50 | NATIVE_PAGE = 0, | |
51 | GENERIC_PAGE, | |
52 | PICKER_PAGE, | |
53 | COMBO_PAGE, | |
54 | WITH_ITEMS_PAGE, | |
55 | EDITABLE_PAGE, | |
56 | BOOK_PAGE, | |
57 | ALL_PAGE, | |
58 | MAX_PAGES | |
59 | }; | |
60 | ||
61 | enum | |
62 | { | |
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 | |
71 | }; | |
49abcb2f | 72 | |
32b8ec41 | 73 | // ---------------------------------------------------------------------------- |
61c083e7 | 74 | // WidgetsPage: a book page demonstrating some widget |
32b8ec41 VZ |
75 | // ---------------------------------------------------------------------------- |
76 | ||
77 | class WidgetsPage : public wxPanel | |
78 | { | |
79 | public: | |
f2fdc4d5 | 80 | WidgetsPage(WidgetsBookCtrl *book); |
32b8ec41 | 81 | |
195df7a7 VZ |
82 | // return the control shown by this page |
83 | virtual wxControl *GetWidget() const = 0; | |
84 | ||
1c01dd16 VZ |
85 | // some pages show 2 controls, in this case override this one as well |
86 | virtual wxControl *GetWidget2() const { return NULL; } | |
87 | ||
1301e228 VZ |
88 | // recreate the control shown by this page |
89 | // | |
90 | // this is currently used only to take into account the border flags | |
91 | virtual void RecreateWidget() = 0; | |
92 | ||
93 | // the default flags for the widget, currently only contains border flags | |
94 | static int ms_defaultFlags; | |
95 | ||
32b8ec41 VZ |
96 | protected: |
97 | // several helper functions for page creation | |
98 | ||
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, | |
206d3a16 | 103 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
104 | wxTextCtrl **ppText = NULL); |
105 | ||
106 | // create a sizer containing a label and a text ctrl | |
107 | wxSizer *CreateSizerWithTextAndLabel(const wxString& label, | |
206d3a16 | 108 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
109 | wxTextCtrl **ppText = NULL); |
110 | ||
111 | // create a sizer containing a button and a text ctrl | |
112 | wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn, | |
113 | const wxString& labelBtn, | |
206d3a16 | 114 | wxWindowID id = wxID_ANY, |
32b8ec41 VZ |
115 | wxTextCtrl **ppText = NULL); |
116 | ||
117 | // create a checkbox and add it to the sizer | |
118 | wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
119 | const wxString& label, | |
206d3a16 | 120 | wxWindowID id = wxID_ANY); |
32b8ec41 VZ |
121 | |
122 | public: | |
123 | // the head of the linked list containinginfo about all pages | |
124 | static WidgetsPageInfo *ms_widgetPages; | |
125 | }; | |
126 | ||
127 | // ---------------------------------------------------------------------------- | |
128 | // dynamic WidgetsPage creation helpers | |
129 | // ---------------------------------------------------------------------------- | |
130 | ||
2b5f62a0 | 131 | class WidgetsPageInfo |
32b8ec41 VZ |
132 | { |
133 | public: | |
f2fdc4d5 | 134 | typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book, |
32b8ec41 VZ |
135 | wxImageList *imaglist); |
136 | ||
137 | // our ctor | |
f2fdc4d5 | 138 | WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories); |
32b8ec41 VZ |
139 | |
140 | // accessors | |
141 | const wxString& GetLabel() const { return m_label; } | |
f2fdc4d5 | 142 | int GetCategories() const { return m_categories; } |
32b8ec41 VZ |
143 | Constructor GetCtor() const { return m_ctor; } |
144 | WidgetsPageInfo *GetNext() const { return m_next; } | |
145 | ||
2673bcb0 DS |
146 | void SetNext(WidgetsPageInfo *next) { m_next = next; } |
147 | ||
32b8ec41 VZ |
148 | private: |
149 | // the label of the page | |
150 | wxString m_label; | |
151 | ||
f2fdc4d5 WS |
152 | // the list (flags) for sharing page between categories |
153 | int m_categories; | |
154 | ||
32b8ec41 VZ |
155 | // the function to create this page |
156 | Constructor m_ctor; | |
157 | ||
158 | // next node in the linked list or NULL | |
159 | WidgetsPageInfo *m_next; | |
160 | }; | |
161 | ||
162 | // to declare a page, this macro must be used in the class declaration | |
163 | #define DECLARE_WIDGETS_PAGE(classname) \ | |
164 | private: \ | |
165 | static WidgetsPageInfo ms_info##classname; \ | |
166 | public: \ | |
167 | const WidgetsPageInfo *GetPageInfo() const \ | |
168 | { return &ms_info##classname; } | |
169 | ||
170 | // and this one must be inserted somewhere in the source file | |
f2fdc4d5 WS |
171 | #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \ |
172 | WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \ | |
32b8ec41 | 173 | wxImageList *imaglist) \ |
61c083e7 | 174 | { return new classname(book, imaglist); } \ |
32b8ec41 | 175 | WidgetsPageInfo classname:: \ |
f2fdc4d5 | 176 | ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories) |
32b8ec41 VZ |
177 | |
178 | #endif // _WX_SAMPLE_WIDGETS_H_ |