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