]> git.saurik.com Git - wxWidgets.git/blob - samples/widgets/widgets.h
cb07dde40667863a3fb4bc9dca7d7c7ae1d33de6
[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
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
35 class WXDLLEXPORT wxCheckBox;
36 class WXDLLEXPORT wxSizer;
37 class WXDLLEXPORT wxTextCtrl;
38 class WXDLLEXPORT WidgetsBookCtrl;
39
40 class WidgetsPageInfo;
41
42 #include "wx/panel.h"
43
44 // all source files use wxImageList
45 #include "wx/imaglist.h"
46
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 };
72
73 // ----------------------------------------------------------------------------
74 // WidgetsPage: a book page demonstrating some widget
75 // ----------------------------------------------------------------------------
76
77 class WidgetsPage : public wxPanel
78 {
79 public:
80 WidgetsPage(WidgetsBookCtrl *book);
81
82 // return the control shown by this page
83 virtual wxControl *GetWidget() const = 0;
84
85 // some pages show 2 controls, in this case override this one as well
86 virtual wxControl *GetWidget2() const { return NULL; }
87
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
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,
103 wxWindowID id = wxID_ANY,
104 wxTextCtrl **ppText = NULL);
105
106 // create a sizer containing a label and a text ctrl
107 wxSizer *CreateSizerWithTextAndLabel(const wxString& label,
108 wxWindowID id = wxID_ANY,
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,
114 wxWindowID id = wxID_ANY,
115 wxTextCtrl **ppText = NULL);
116
117 // create a checkbox and add it to the sizer
118 wxCheckBox *CreateCheckBoxAndAddToSizer(wxSizer *sizer,
119 const wxString& label,
120 wxWindowID id = wxID_ANY);
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
131 class WidgetsPageInfo
132 {
133 public:
134 typedef WidgetsPage *(*Constructor)(WidgetsBookCtrl *book,
135 wxImageList *imaglist);
136
137 // our ctor
138 WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories);
139
140 // accessors
141 const wxString& GetLabel() const { return m_label; }
142 int GetCategories() const { return m_categories; }
143 Constructor GetCtor() const { return m_ctor; }
144 WidgetsPageInfo *GetNext() const { return m_next; }
145
146 void SetNext(WidgetsPageInfo *next) { m_next = next; }
147
148 private:
149 // the label of the page
150 wxString m_label;
151
152 // the list (flags) for sharing page between categories
153 int m_categories;
154
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
171 #define IMPLEMENT_WIDGETS_PAGE(classname, label, categories) \
172 WidgetsPage *wxCtorFor##classname(WidgetsBookCtrl *book, \
173 wxImageList *imaglist) \
174 { return new classname(book, imaglist); } \
175 WidgetsPageInfo classname:: \
176 ms_info##classname(wxCtorFor##classname, label, ALL_CTRLS | categories)
177
178 #endif // _WX_SAMPLE_WIDGETS_H_