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