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