]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/widgets.h
Make storing non-trivial data in wxThreadSpecificInfo possible.
[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 // Copyright: (c) 2001 Vadim Zeitlin
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_SAMPLE_WIDGETS_H_
12 #define _WX_SAMPLE_WIDGETS_H_
13
14 #if wxUSE_TREEBOOK && !defined(__WXHANDHELD__)
15 #include "wx/treebook.h"
16 #define USE_TREEBOOK 1
17 #define WidgetsBookCtrl wxTreebook
18 #define WidgetsBookCtrlEvent wxTreebookEvent
19 #define EVT_WIDGETS_PAGE_CHANGING(id,func) EVT_TREEBOOK_PAGE_CHANGING(id,func)
20 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_TREEBOOK_PAGE_CHANGED
21 #define wxWidgetsbookEventHandler(func) wxTreebookEventHandler(func)
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_CHANGING(id,func) EVT_BOOKCTRL_PAGE_CHANGING(id,func)
28 #define wxEVT_COMMAND_WIDGETS_PAGE_CHANGED wxEVT_BOOKCTRL_PAGE_CHANGED
29 #define wxWidgetsbookEventHandler(func) wxBookCtrlEventHandler(func)
30 #endif
31
32 #if wxUSE_LOG && !defined(__WXHANDHELD__)
33 #define USE_LOG 1
34 #else
35 #define USE_LOG 0
36 #endif
37
38 #if defined(__WXHANDHELD__)
39 #define USE_ICONS_IN_BOOK 0
40 #else
41 #define USE_ICONS_IN_BOOK 1
42 #define ICON_SIZE 16
43 #endif
44
45 class WXDLLIMPEXP_FWD_CORE wxCheckBox;
46 class WXDLLIMPEXP_FWD_CORE wxSizer;
47 class WXDLLIMPEXP_FWD_CORE wxImageList;
48 class WXDLLIMPEXP_FWD_CORE wxTextCtrl;
49 class WXDLLIMPEXP_FWD_CORE WidgetsBookCtrl;
50
51 class WidgetsPageInfo;
52
53 #include "wx/panel.h"
54 #include "wx/vector.h"
55
56 // INTRODUCING NEW PAGES DON'T FORGET TO ADD ENTRIES TO 'WidgetsCategories'
57 enum
58 {
59 // In wxUniversal-based builds 'native' means 'made with wxUniv port
60 // renderer'
61 NATIVE_PAGE = 0,
62 UNIVERSAL_PAGE = NATIVE_PAGE,
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,
76 UNIVERSAL_CTRLS = NATIVE_CTRLS,
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 };
85
86 typedef wxVector<wxControl *> Widgets;
87
88 // ----------------------------------------------------------------------------
89 // WidgetsPage: a book page demonstrating some widget
90 // ----------------------------------------------------------------------------
91
92 class WidgetsPage : public wxPanel
93 {
94 public:
95 WidgetsPage(WidgetsBookCtrl *book,
96 wxImageList *imaglist,
97 const char *const icon[]);
98
99 // return the control shown by this page
100 virtual wxControl *GetWidget() const = 0;
101
102 // return the control shown by this page, if it supports text entry interface
103 virtual wxTextEntryBase *GetTextEntry() const { return NULL; }
104
105 // lazy creation of the content
106 virtual void CreateContent() = 0;
107
108 // some pages show additional controls, in this case override this one to
109 // return all of them (including the one returned by GetWidget())
110 virtual Widgets GetWidgets() const
111 {
112 Widgets widgets;
113 widgets.push_back(GetWidget());
114 return widgets;
115 }
116
117 // recreate the control shown by this page
118 //
119 // this is currently used only to take into account the border flags
120 virtual void RecreateWidget() = 0;
121
122 // the default flags for the widget, currently only contains border flags
123 static int ms_defaultFlags;
124
125 protected:
126 // several helper functions for page creation
127
128 // create a horz sizer containing the given control and the text ctrl
129 // (pointer to which will be saved in the provided variable if not NULL)
130 // with the specified id
131 wxSizer *CreateSizerWithText(wxControl *control,
132 wxWindowID id = wxID_ANY,
133 wxTextCtrl **ppText = NULL);
134
135 // create a sizer containing a label and a text ctrl
136 wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
137 wxWindowID id = wxID_ANY,
138 wxTextCtrl **ppText = NULL);
139
140 // create a sizer containing a button and a text ctrl
141 wxSizer *CreateSizerWithTextAndButton(wxWindowID idBtn,
142 const wxString& labelBtn,
143 wxWindowID id = wxID_ANY,
144 wxTextCtrl **ppText = NULL);
145
146 // create a checkbox and add it to the sizer
147 wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
148 const wxString& label,
149 wxWindowID id = wxID_ANY);
150
151 public:
152 // the head of the linked list containinginfo about all pages
153 static WidgetsPageInfo *ms_widgetPages;
154 };
155
156 // ----------------------------------------------------------------------------
157 // dynamic WidgetsPage creation helpers
158 // ----------------------------------------------------------------------------
159
160 class WidgetsPageInfo
161 {
162 public:
163 typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book,
164 wxImageList *imaglist);
165
166 // our ctor
167 WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories);
168
169 // accessors
170 const wxString& GetLabel() const { return m_label; }
171 int GetCategories() const { return m_categories; }
172 Constructor GetCtor() const { return m_ctor; }
173 WidgetsPageInfo *GetNext() const { return m_next; }
174
175 void SetNext(WidgetsPageInfo *next) { m_next = next; }
176
177 private:
178 // the label of the page
179 wxString m_label;
180
181 // the list (flags) for sharing page between categories
182 int m_categories;
183
184 // the function to create this page
185 Constructor m_ctor;
186
187 // next node in the linked list or NULL
188 WidgetsPageInfo *m_next;
189 };
190
191 // to declare a page, this macro must be used in the class declaration
192 #define DECLARE_WIDGETS_PAGE(classname) \
193 private: \
194 static WidgetsPageInfo ms_info##classname; \
195 public: \
196 const WidgetsPageInfo *GetPageInfo() const \
197 { return &ms_info##classname; }
198
199 // and this one must be inserted somewhere in the source file
200 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
201 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
202 wxImageList *imaglist) \
203 { return new classname(book, imaglist); } \
204 WidgetsPageInfo classname:: \
205 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
206
207 #endif // _WX_SAMPLE_WIDGETS_H_