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