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