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