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