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