]>
Commit | Line | Data |
---|---|---|
32b8ec41 | 1 | ///////////////////////////////////////////////////////////////////////////// |
be5a51fb | 2 | // Program: wxWidgets Widgets Sample |
2ddb4d13 | 3 | // Name: samples/widgets/widgets.cpp |
be5a51fb | 4 | // Purpose: Sample showing most of the simple wxWidgets widgets |
32b8ec41 VZ |
5 | // Author: Vadim Zeitlin |
6 | // Created: 27.03.01 | |
7 | // Id: $Id$ | |
8 | // Copyright: (c) 2001 Vadim Zeitlin | |
9 | // License: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx/wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | // for all others, include the necessary headers | |
28 | #ifndef WX_PRECOMP | |
29 | #include "wx/app.h" | |
30 | #include "wx/log.h" | |
32b8ec41 | 31 | #include "wx/frame.h" |
e6f3cbd2 | 32 | #include "wx/menu.h" |
e273c962 | 33 | #include "wx/image.h" |
e6f3cbd2 | 34 | |
32b8ec41 VZ |
35 | #include "wx/button.h" |
36 | #include "wx/checkbox.h" | |
37 | #include "wx/listbox.h" | |
38 | #include "wx/statbox.h" | |
39 | #include "wx/stattext.h" | |
40 | #include "wx/textctrl.h" | |
bd018e7e | 41 | #include "wx/msgdlg.h" |
32b8ec41 VZ |
42 | #endif |
43 | ||
25057aba | 44 | #include "wx/sysopt.h" |
61c083e7 | 45 | #include "wx/bookctrl.h" |
f2fdc4d5 | 46 | #include "wx/treebook.h" |
32b8ec41 | 47 | #include "wx/sizer.h" |
195df7a7 | 48 | #include "wx/colordlg.h" |
822b9009 | 49 | #include "wx/fontdlg.h" |
1bdd1007 | 50 | #include "wx/textdlg.h" |
261357eb | 51 | #include "wx/imaglist.h" |
453535a7 | 52 | #include "wx/wupdlock.h" |
32b8ec41 VZ |
53 | |
54 | #include "widgets.h" | |
55 | ||
f2fdc4d5 WS |
56 | #include "../sample.xpm" |
57 | ||
32b8ec41 VZ |
58 | // ---------------------------------------------------------------------------- |
59 | // constants | |
60 | // ---------------------------------------------------------------------------- | |
61 | ||
62 | // control ids | |
63 | enum | |
64 | { | |
65 | Widgets_ClearLog = 100, | |
195df7a7 | 66 | Widgets_Quit, |
1301e228 | 67 | |
3700e21b VZ |
68 | Widgets_BookCtrl, |
69 | ||
1c01dd16 VZ |
70 | #if wxUSE_TOOLTIPS |
71 | Widgets_SetTooltip, | |
72 | #endif // wxUSE_TOOLTIPS | |
195df7a7 | 73 | Widgets_SetFgColour, |
822b9009 | 74 | Widgets_SetBgColour, |
a17c1df4 | 75 | Widgets_SetFont, |
1301e228 VZ |
76 | Widgets_Enable, |
77 | ||
78 | Widgets_BorderNone, | |
79 | Widgets_BorderStatic, | |
80 | Widgets_BorderSimple, | |
81 | Widgets_BorderRaised, | |
82 | Widgets_BorderSunken, | |
83 | Widgets_BorderDouble, | |
3700e21b VZ |
84 | Widgets_BorderDefault, |
85 | ||
e32bcef6 VZ |
86 | Widgets_GlobalBusyCursor, |
87 | Widgets_BusyCursor, | |
88 | ||
3700e21b | 89 | Widgets_GoToPage, |
6a8d7937 VZ |
90 | Widgets_GoToPageLast = Widgets_GoToPage + 100, |
91 | ||
92 | ||
93 | TextEntry_Begin, | |
94 | TextEntry_DisableAutoComplete = TextEntry_Begin, | |
95 | TextEntry_AutoCompleteFixed, | |
96 | TextEntry_AutoCompleteFilenames, | |
97 | TextEntry_End | |
32b8ec41 VZ |
98 | }; |
99 | ||
f2fdc4d5 | 100 | const wxChar *WidgetsCategories[MAX_PAGES] = { |
d8d07a79 WS |
101 | #if defined(__WXUNIVERSAL__) |
102 | wxT("Universal"), | |
103 | #else | |
f2fdc4d5 | 104 | wxT("Native"), |
d8d07a79 | 105 | #endif |
f2fdc4d5 WS |
106 | wxT("Generic"), |
107 | wxT("Pickers"), | |
108 | wxT("Comboboxes"), | |
109 | wxT("With items"), | |
110 | wxT("Editable"), | |
111 | wxT("Books"), | |
112 | wxT("All controls") | |
113 | }; | |
114 | ||
32b8ec41 VZ |
115 | // ---------------------------------------------------------------------------- |
116 | // our classes | |
117 | // ---------------------------------------------------------------------------- | |
118 | ||
119 | // Define a new application type, each program should derive a class from wxApp | |
120 | class WidgetsApp : public wxApp | |
121 | { | |
122 | public: | |
123 | // override base class virtuals | |
124 | // ---------------------------- | |
125 | ||
126 | // this one is called on application startup and is a good place for the app | |
127 | // initialization (doing it here and not in the ctor allows to have an error | |
128 | // return: if OnInit() returns false, the application terminates) | |
129 | virtual bool OnInit(); | |
130 | }; | |
131 | ||
132 | // Define a new frame type: this is going to be our main frame | |
133 | class WidgetsFrame : public wxFrame | |
134 | { | |
135 | public: | |
136 | // ctor(s) and dtor | |
137 | WidgetsFrame(const wxString& title); | |
138 | virtual ~WidgetsFrame(); | |
139 | ||
140 | protected: | |
141 | // event handlers | |
49abcb2f | 142 | #if USE_LOG |
32b8ec41 | 143 | void OnButtonClearLog(wxCommandEvent& event); |
49abcb2f | 144 | #endif // USE_LOG |
195df7a7 | 145 | void OnExit(wxCommandEvent& event); |
a17c1df4 | 146 | |
195df7a7 | 147 | #if wxUSE_MENUS |
3e859739 | 148 | void OnPageChanging(WidgetsBookCtrlEvent& event); |
f2fdc4d5 | 149 | void OnPageChanged(WidgetsBookCtrlEvent& event); |
3700e21b VZ |
150 | void OnGoToPage(wxCommandEvent& event); |
151 | ||
1c01dd16 VZ |
152 | #if wxUSE_TOOLTIPS |
153 | void OnSetTooltip(wxCommandEvent& event); | |
154 | #endif // wxUSE_TOOLTIPS | |
195df7a7 VZ |
155 | void OnSetFgCol(wxCommandEvent& event); |
156 | void OnSetBgCol(wxCommandEvent& event); | |
822b9009 | 157 | void OnSetFont(wxCommandEvent& event); |
a17c1df4 | 158 | void OnEnable(wxCommandEvent& event); |
1301e228 | 159 | void OnSetBorder(wxCommandEvent& event); |
e32bcef6 VZ |
160 | |
161 | void OnToggleGlobalBusyCursor(wxCommandEvent& event); | |
162 | void OnToggleBusyCursor(wxCommandEvent& event); | |
6a8d7937 VZ |
163 | |
164 | void OnDisableAutoComplete(wxCommandEvent& event); | |
165 | void OnAutoCompleteFixed(wxCommandEvent& event); | |
166 | void OnAutoCompleteFilenames(wxCommandEvent& event); | |
167 | ||
168 | void OnUpdateTextUI(wxUpdateUIEvent& event) | |
169 | { | |
170 | event.Enable( CurrentPage()->GetTextEntry() != NULL ); | |
171 | } | |
195df7a7 | 172 | #endif // wxUSE_MENUS |
32b8ec41 | 173 | |
61c083e7 WS |
174 | // initialize the book: add all pages to it |
175 | void InitBook(); | |
32b8ec41 | 176 | |
3e859739 | 177 | // return the currently selected page (never NULL) |
f2fdc4d5 WS |
178 | WidgetsPage *CurrentPage(); |
179 | ||
32b8ec41 VZ |
180 | private: |
181 | // the panel containing everything | |
182 | wxPanel *m_panel; | |
183 | ||
49abcb2f | 184 | #if USE_LOG |
32b8ec41 VZ |
185 | // the listbox for logging messages |
186 | wxListBox *m_lboxLog; | |
187 | ||
188 | // the log target we use to redirect messages to the listbox | |
189 | wxLog *m_logTarget; | |
49abcb2f | 190 | #endif // USE_LOG |
32b8ec41 | 191 | |
61c083e7 | 192 | // the book containing the test pages |
f2fdc4d5 | 193 | WidgetsBookCtrl *m_book; |
32b8ec41 | 194 | |
195df7a7 | 195 | #if wxUSE_MENUS |
822b9009 | 196 | // last chosen fg/bg colours and font |
195df7a7 VZ |
197 | wxColour m_colFg, |
198 | m_colBg; | |
822b9009 | 199 | wxFont m_font; |
195df7a7 VZ |
200 | #endif // wxUSE_MENUS |
201 | ||
be5a51fb | 202 | // any class wishing to process wxWidgets events must use this macro |
32b8ec41 VZ |
203 | DECLARE_EVENT_TABLE() |
204 | }; | |
205 | ||
49abcb2f | 206 | #if USE_LOG |
32b8ec41 VZ |
207 | // A log target which just redirects the messages to a listbox |
208 | class LboxLogger : public wxLog | |
209 | { | |
210 | public: | |
211 | LboxLogger(wxListBox *lbox, wxLog *logOld) | |
212 | { | |
213 | m_lbox = lbox; | |
214 | //m_lbox->Disable(); -- looks ugly under MSW | |
215 | m_logOld = logOld; | |
216 | } | |
217 | ||
218 | virtual ~LboxLogger() | |
219 | { | |
220 | wxLog::SetActiveTarget(m_logOld); | |
221 | } | |
222 | ||
223 | private: | |
224 | // implement sink functions | |
8c714e06 | 225 | virtual void DoLog(wxLogLevel level, const wxString& str, time_t t) |
32b8ec41 VZ |
226 | { |
227 | // don't put trace messages into listbox or we can get into infinite | |
228 | // recursion | |
229 | if ( level == wxLOG_Trace ) | |
230 | { | |
231 | if ( m_logOld ) | |
232 | { | |
233 | // cast is needed to call protected method | |
8c714e06 | 234 | ((LboxLogger *)m_logOld)->DoLog(level, str, t); |
32b8ec41 VZ |
235 | } |
236 | } | |
237 | else | |
238 | { | |
8c714e06 | 239 | wxLog::DoLog(level, str, t); |
32b8ec41 VZ |
240 | } |
241 | } | |
242 | ||
8c714e06 | 243 | virtual void DoLogString(const wxString& str, time_t WXUNUSED(t)) |
32b8ec41 VZ |
244 | { |
245 | wxString msg; | |
246 | TimeStamp(&msg); | |
8c714e06 | 247 | msg += str; |
32b8ec41 VZ |
248 | |
249 | #ifdef __WXUNIVERSAL__ | |
250 | m_lbox->AppendAndEnsureVisible(msg); | |
251 | #else // other ports don't have this method yet | |
252 | m_lbox->Append(msg); | |
253 | m_lbox->SetFirstItem(m_lbox->GetCount() - 1); | |
254 | #endif | |
255 | } | |
256 | ||
257 | // the control we use | |
258 | wxListBox *m_lbox; | |
259 | ||
260 | // the old log target | |
261 | wxLog *m_logOld; | |
262 | }; | |
49abcb2f | 263 | #endif // USE_LOG |
32b8ec41 VZ |
264 | |
265 | // array of pages | |
38d6b957 | 266 | WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage); |
32b8ec41 VZ |
267 | |
268 | // ---------------------------------------------------------------------------- | |
269 | // misc macros | |
270 | // ---------------------------------------------------------------------------- | |
271 | ||
272 | IMPLEMENT_APP(WidgetsApp) | |
273 | ||
32b8ec41 VZ |
274 | // ---------------------------------------------------------------------------- |
275 | // event tables | |
276 | // ---------------------------------------------------------------------------- | |
277 | ||
278 | BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) | |
49abcb2f | 279 | #if USE_LOG |
32b8ec41 | 280 | EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog) |
49abcb2f | 281 | #endif // USE_LOG |
195df7a7 VZ |
282 | EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit) |
283 | ||
1c01dd16 VZ |
284 | #if wxUSE_TOOLTIPS |
285 | EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip) | |
286 | #endif // wxUSE_TOOLTIPS | |
287 | ||
3700e21b | 288 | #if wxUSE_MENUS |
3e859739 | 289 | EVT_WIDGETS_PAGE_CHANGING(wxID_ANY, WidgetsFrame::OnPageChanging) |
3700e21b VZ |
290 | EVT_MENU_RANGE(Widgets_GoToPage, Widgets_GoToPageLast, |
291 | WidgetsFrame::OnGoToPage) | |
292 | ||
195df7a7 VZ |
293 | EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol) |
294 | EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol) | |
822b9009 | 295 | EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont) |
a17c1df4 | 296 | EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable) |
1c01dd16 | 297 | |
1301e228 VZ |
298 | EVT_MENU_RANGE(Widgets_BorderNone, Widgets_BorderDefault, |
299 | WidgetsFrame::OnSetBorder) | |
300 | ||
e32bcef6 VZ |
301 | EVT_MENU(Widgets_GlobalBusyCursor, WidgetsFrame::OnToggleGlobalBusyCursor) |
302 | EVT_MENU(Widgets_BusyCursor, WidgetsFrame::OnToggleBusyCursor) | |
303 | ||
6a8d7937 VZ |
304 | EVT_MENU(TextEntry_DisableAutoComplete, WidgetsFrame::OnDisableAutoComplete) |
305 | EVT_MENU(TextEntry_AutoCompleteFixed, WidgetsFrame::OnAutoCompleteFixed) | |
306 | EVT_MENU(TextEntry_AutoCompleteFilenames, WidgetsFrame::OnAutoCompleteFilenames) | |
307 | ||
308 | EVT_UPDATE_UI_RANGE(TextEntry_Begin, TextEntry_End - 1, | |
309 | WidgetsFrame::OnUpdateTextUI) | |
310 | ||
1c01dd16 | 311 | EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit) |
3700e21b | 312 | #endif // wxUSE_MENUS |
32b8ec41 VZ |
313 | END_EVENT_TABLE() |
314 | ||
315 | // ============================================================================ | |
316 | // implementation | |
317 | // ============================================================================ | |
318 | ||
319 | // ---------------------------------------------------------------------------- | |
320 | // app class | |
321 | // ---------------------------------------------------------------------------- | |
322 | ||
323 | bool WidgetsApp::OnInit() | |
324 | { | |
bf188f1a | 325 | if ( !wxApp::OnInit() ) |
206d3a16 | 326 | return false; |
1bdd1007 | 327 | |
32b8ec41 VZ |
328 | // the reason for having these ifdef's is that I often run two copies of |
329 | // this sample side by side and it is useful to see which one is which | |
24e78d27 | 330 | wxString title; |
32b8ec41 | 331 | #if defined(__WXUNIVERSAL__) |
085a1f3c | 332 | title = _T("wxUniv/"); |
24e78d27 VZ |
333 | #endif |
334 | ||
335 | #if defined(__WXMSW__) | |
336 | title += _T("wxMSW"); | |
32b8ec41 | 337 | #elif defined(__WXGTK__) |
24e78d27 | 338 | title += _T("wxGTK"); |
0f9390c3 GD |
339 | #elif defined(__WXMAC__) |
340 | title += _T("wxMAC"); | |
341 | #elif defined(__WXMOTIF__) | |
342 | title += _T("wxMOTIF"); | |
027fe16c VZ |
343 | #elif __WXPALMOS5__ |
344 | title += _T("wxPALMOS5"); | |
345 | #elif __WXPALMOS6__ | |
346 | title += _T("wxPALMOS6"); | |
32b8ec41 | 347 | #else |
be5a51fb | 348 | title += _T("wxWidgets"); |
32b8ec41 | 349 | #endif |
32b8ec41 VZ |
350 | |
351 | wxFrame *frame = new WidgetsFrame(title + _T(" widgets demo")); | |
352 | frame->Show(); | |
353 | ||
354 | //wxLog::AddTraceMask(_T("listbox")); | |
355 | //wxLog::AddTraceMask(_T("scrollbar")); | |
58ec2255 | 356 | //wxLog::AddTraceMask(_T("focus")); |
32b8ec41 | 357 | |
206d3a16 | 358 | return true; |
32b8ec41 VZ |
359 | } |
360 | ||
361 | // ---------------------------------------------------------------------------- | |
362 | // WidgetsFrame construction | |
363 | // ---------------------------------------------------------------------------- | |
364 | ||
365 | WidgetsFrame::WidgetsFrame(const wxString& title) | |
1e3fc113 | 366 | : wxFrame(NULL, wxID_ANY, title) |
32b8ec41 | 367 | { |
f2fdc4d5 WS |
368 | // set the frame icon |
369 | SetIcon(wxICON(sample)); | |
370 | ||
32b8ec41 | 371 | // init everything |
49abcb2f | 372 | #if USE_LOG |
32b8ec41 VZ |
373 | m_lboxLog = (wxListBox *)NULL; |
374 | m_logTarget = (wxLog *)NULL; | |
49abcb2f | 375 | #endif // USE_LOG |
f2fdc4d5 | 376 | m_book = (WidgetsBookCtrl *)NULL; |
32b8ec41 | 377 | |
195df7a7 VZ |
378 | #if wxUSE_MENUS |
379 | // create the menubar | |
380 | wxMenuBar *mbar = new wxMenuBar; | |
381 | wxMenu *menuWidget = new wxMenu; | |
1c01dd16 VZ |
382 | #if wxUSE_TOOLTIPS |
383 | menuWidget->Append(Widgets_SetTooltip, _T("Set &tooltip...\tCtrl-T")); | |
384 | menuWidget->AppendSeparator(); | |
385 | #endif // wxUSE_TOOLTIPS | |
195df7a7 VZ |
386 | menuWidget->Append(Widgets_SetFgColour, _T("Set &foreground...\tCtrl-F")); |
387 | menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B")); | |
822b9009 | 388 | menuWidget->Append(Widgets_SetFont, _T("Set f&ont...\tCtrl-O")); |
a17c1df4 | 389 | menuWidget->AppendCheckItem(Widgets_Enable, _T("&Enable/disable\tCtrl-E")); |
1301e228 VZ |
390 | |
391 | wxMenu *menuBorders = new wxMenu; | |
392 | menuBorders->AppendRadioItem(Widgets_BorderDefault, _T("De&fault\tCtrl-Shift-9")); | |
393 | menuBorders->AppendRadioItem(Widgets_BorderNone, _T("&None\tCtrl-Shift-0")); | |
394 | menuBorders->AppendRadioItem(Widgets_BorderSimple, _T("&Simple\tCtrl-Shift-1")); | |
395 | menuBorders->AppendRadioItem(Widgets_BorderDouble, _T("&Double\tCtrl-Shift-2")); | |
396 | menuBorders->AppendRadioItem(Widgets_BorderStatic, _T("Stati&c\tCtrl-Shift-3")); | |
397 | menuBorders->AppendRadioItem(Widgets_BorderRaised, _T("&Raised\tCtrl-Shift-4")); | |
398 | menuBorders->AppendRadioItem(Widgets_BorderSunken, _T("S&unken\tCtrl-Shift-5")); | |
399 | menuWidget->AppendSubMenu(menuBorders, _T("Set &border")); | |
400 | ||
e32bcef6 VZ |
401 | menuWidget->AppendSeparator(); |
402 | menuWidget->AppendCheckItem(Widgets_GlobalBusyCursor, | |
403 | _T("Toggle &global busy cursor\tCtrl-Shift-U")); | |
404 | menuWidget->AppendCheckItem(Widgets_BusyCursor, | |
405 | _T("Toggle b&usy cursor\tCtrl-U")); | |
406 | ||
195df7a7 VZ |
407 | menuWidget->AppendSeparator(); |
408 | menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q")); | |
409 | mbar->Append(menuWidget, _T("&Widget")); | |
6a8d7937 VZ |
410 | |
411 | wxMenu *menuTextEntry = new wxMenu; | |
412 | menuTextEntry->AppendRadioItem(TextEntry_DisableAutoComplete, | |
413 | _T("&Disable auto-completion")); | |
414 | menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFixed, | |
415 | _T("Fixed-&list auto-completion")); | |
416 | menuTextEntry->AppendRadioItem(TextEntry_AutoCompleteFilenames, | |
417 | _T("&Files names auto-completion")); | |
418 | ||
419 | mbar->Append(menuTextEntry, _T("&Text")); | |
420 | ||
195df7a7 | 421 | SetMenuBar(mbar); |
a17c1df4 VZ |
422 | |
423 | mbar->Check(Widgets_Enable, true); | |
195df7a7 VZ |
424 | #endif // wxUSE_MENUS |
425 | ||
32b8ec41 | 426 | // create controls |
1e3fc113 | 427 | m_panel = new wxPanel(this, wxID_ANY); |
32b8ec41 VZ |
428 | |
429 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
430 | ||
25057aba | 431 | // we have 2 panes: book with pages demonstrating the controls in the |
32b8ec41 | 432 | // upper one and the log window with some buttons in the lower |
1bdd1007 | 433 | |
1e3fc113 | 434 | int style = wxBK_DEFAULT; |
25057aba | 435 | // Uncomment to suppress page theme (draw in solid colour) |
8c9f8f91 | 436 | //style |= wxNB_NOPAGETHEME; |
32b8ec41 | 437 | |
f2fdc4d5 | 438 | m_book = new WidgetsBookCtrl(m_panel, Widgets_BookCtrl, wxDefaultPosition, |
6bae6726 | 439 | #ifdef __WXMOTIF__ |
2ddb4d13 | 440 | wxSize(500, wxDefaultCoord), // under Motif, height is a function of the width... |
6bae6726 MB |
441 | #else |
442 | wxDefaultSize, | |
443 | #endif | |
444 | style); | |
61c083e7 | 445 | InitBook(); |
32b8ec41 | 446 | |
261357eb | 447 | #ifndef __WXHANDHELD__ |
32b8ec41 | 448 | // the lower one only has the log listbox and a button to clear it |
49abcb2f | 449 | #if USE_LOG |
206d3a16 JS |
450 | wxSizer *sizerDown = new wxStaticBoxSizer( |
451 | new wxStaticBox( m_panel, wxID_ANY, _T("&Log window") ), | |
452 | wxVERTICAL); | |
453 | ||
454 | m_lboxLog = new wxListBox(m_panel, wxID_ANY); | |
32b8ec41 | 455 | sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5); |
7b127900 | 456 | sizerDown->SetMinSize(100, 150); |
b29903d4 WS |
457 | #else |
458 | wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL); | |
49abcb2f | 459 | #endif // USE_LOG |
88633ca7 | 460 | |
32b8ec41 | 461 | wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL); |
b29903d4 | 462 | wxButton *btn; |
49abcb2f | 463 | #if USE_LOG |
b29903d4 | 464 | btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log")); |
32b8ec41 VZ |
465 | sizerBtns->Add(btn); |
466 | sizerBtns->Add(10, 0); // spacer | |
49abcb2f | 467 | #endif // USE_LOG |
32b8ec41 VZ |
468 | btn = new wxButton(m_panel, Widgets_Quit, _T("E&xit")); |
469 | sizerBtns->Add(btn); | |
470 | sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5); | |
471 | ||
472 | // put everything together | |
61c083e7 | 473 | sizerTop->Add(m_book, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10); |
32b8ec41 VZ |
474 | sizerTop->Add(0, 5, 0, wxGROW); // spacer in between |
475 | sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10); | |
476 | ||
261357eb | 477 | #else // !__WXHANDHELD__/__WXHANDHELD__ |
49abcb2f WS |
478 | |
479 | sizerTop->Add(m_book, 1, wxGROW | wxALL ); | |
480 | ||
261357eb | 481 | #endif // __WXHANDHELD__ |
49abcb2f | 482 | |
32b8ec41 VZ |
483 | m_panel->SetSizer(sizerTop); |
484 | ||
32b8ec41 VZ |
485 | sizerTop->SetSizeHints(this); |
486 | ||
49abcb2f | 487 | #if USE_LOG && !defined(__WXCOCOA__) |
7bb70733 | 488 | // wxCocoa's listbox is too flakey to use for logging right now |
32b8ec41 VZ |
489 | // now that everything is created we can redirect the log messages to the |
490 | // listbox | |
491 | m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget()); | |
492 | wxLog::SetActiveTarget(m_logTarget); | |
b29903d4 | 493 | #endif |
32b8ec41 VZ |
494 | } |
495 | ||
61c083e7 | 496 | void WidgetsFrame::InitBook() |
32b8ec41 | 497 | { |
261357eb | 498 | #if USE_ICONS_IN_BOOK |
993b016d | 499 | wxImageList *imageList = new wxImageList(ICON_SIZE, ICON_SIZE); |
32b8ec41 | 500 | |
993b016d VZ |
501 | wxImage img(sample_xpm); |
502 | imageList->Add(wxBitmap(img.Scale(ICON_SIZE, ICON_SIZE))); | |
261357eb WS |
503 | #else |
504 | wxImageList *imageList = NULL; | |
505 | #endif | |
f2fdc4d5 WS |
506 | |
507 | #if !USE_TREEBOOK | |
508 | WidgetsBookCtrl *books[MAX_PAGES]; | |
509 | #endif | |
510 | ||
511 | ArrayWidgetsPage pages[MAX_PAGES]; | |
512 | wxArrayString labels[MAX_PAGES]; | |
32b8ec41 | 513 | |
3700e21b | 514 | wxMenu *menuPages = new wxMenu; |
f2fdc4d5 WS |
515 | unsigned int nPage = 0, nFKey = 0; |
516 | int cat, imageId = 1; | |
3700e21b | 517 | |
61c083e7 | 518 | // we need to first create all pages and only then add them to the book |
32b8ec41 | 519 | // as we need the image list first |
3700e21b VZ |
520 | // |
521 | // we also construct the pages menu during this first iteration | |
f2fdc4d5 | 522 | for ( cat = 0; cat < MAX_PAGES; cat++ ) |
32b8ec41 | 523 | { |
f2fdc4d5 WS |
524 | #if USE_TREEBOOK |
525 | nPage++; // increase for parent page | |
526 | #else | |
261357eb WS |
527 | books[cat] = new WidgetsBookCtrl(m_book, |
528 | wxID_ANY, | |
529 | wxDefaultPosition, | |
530 | wxDefaultSize, | |
895cc205 | 531 | wxBK_DEFAULT); |
f2fdc4d5 WS |
532 | #endif |
533 | ||
534 | for ( WidgetsPageInfo *info = WidgetsPage::ms_widgetPages; | |
535 | info; | |
536 | info = info->GetNext() ) | |
537 | { | |
538 | if( (info->GetCategories() & ( 1 << cat )) == 0) | |
539 | continue; | |
540 | ||
541 | WidgetsPage *page = (*info->GetCtor())( | |
542 | #if USE_TREEBOOK | |
543 | m_book | |
544 | #else | |
545 | books[cat] | |
546 | #endif | |
547 | , imageList); | |
548 | pages[cat].Add(page); | |
549 | ||
550 | labels[cat].Add(info->GetLabel()); | |
551 | if ( cat == ALL_PAGE ) | |
552 | { | |
553 | wxString radioLabel(info->GetLabel()); | |
554 | nFKey++; | |
555 | if ( nFKey <= 12 ) | |
556 | { | |
557 | radioLabel << wxT("\tF" ) << nFKey; | |
558 | } | |
559 | ||
560 | menuPages->AppendRadioItem( | |
561 | Widgets_GoToPage + nPage, | |
562 | radioLabel | |
563 | ); | |
564 | #if !USE_TREEBOOK | |
565 | // consider only for book in book architecture | |
566 | nPage++; | |
567 | #endif | |
568 | } | |
569 | ||
570 | #if USE_TREEBOOK | |
571 | // consider only for treebook architecture (with subpages) | |
572 | nPage++; | |
573 | #endif | |
574 | } | |
32b8ec41 VZ |
575 | } |
576 | ||
3700e21b VZ |
577 | GetMenuBar()->Append(menuPages, _T("&Page")); |
578 | ||
261357eb | 579 | #if USE_ICONS_IN_BOOK |
f2fdc4d5 | 580 | m_book->AssignImageList(imageList); |
261357eb | 581 | #endif |
32b8ec41 | 582 | |
f2fdc4d5 | 583 | for ( cat = 0; cat < MAX_PAGES; cat++ ) |
32b8ec41 | 584 | { |
f2fdc4d5 WS |
585 | #if USE_TREEBOOK |
586 | m_book->AddPage(NULL,WidgetsCategories[cat],false,0); | |
587 | #else | |
588 | m_book->AddPage(books[cat],WidgetsCategories[cat],false,0); | |
261357eb | 589 | #if USE_ICONS_IN_BOOK |
f2fdc4d5 | 590 | books[cat]->SetImageList(imageList); |
261357eb | 591 | #endif |
f2fdc4d5 WS |
592 | #endif |
593 | ||
594 | // now do add them | |
595 | size_t count = pages[cat].GetCount(); | |
596 | for ( size_t n = 0; n < count; n++ ) | |
597 | { | |
598 | #if USE_TREEBOOK | |
3e859739 | 599 | m_book->AddSubPage |
f2fdc4d5 | 600 | #else |
3e859739 | 601 | books[cat]->AddPage |
f2fdc4d5 | 602 | #endif |
3e859739 | 603 | ( |
f2fdc4d5 WS |
604 | pages[cat][n], |
605 | labels[cat][n], | |
606 | false, // don't select | |
607 | imageId++ | |
608 | ); | |
609 | } | |
32b8ec41 | 610 | } |
f2fdc4d5 | 611 | |
0cebbfc2 WS |
612 | Connect( wxID_ANY, |
613 | wxEVT_COMMAND_WIDGETS_PAGE_CHANGED, | |
614 | wxWidgetsbookEventHandler(WidgetsFrame::OnPageChanged) ); | |
615 | ||
f2fdc4d5 | 616 | #if USE_TREEBOOK |
3e859739 VZ |
617 | // for treebook page #0 is empty parent page only so select the first page |
618 | // with some contents | |
f2fdc4d5 | 619 | m_book->SetSelection(1); |
3e859739 VZ |
620 | |
621 | // but ensure that the top of the tree is shown nevertheless | |
622 | wxTreeCtrl * const tree = m_book->GetTreeCtrl(); | |
23c2b62b VZ |
623 | |
624 | wxTreeItemIdValue cookie; | |
625 | tree->EnsureVisible(tree->GetFirstChild(tree->GetRootItem(), cookie)); | |
0cebbfc2 WS |
626 | #else |
627 | // for other books set selection twice to force connected event handler | |
628 | // to force lazy creation of initial visible content | |
629 | m_book->SetSelection(1); | |
630 | m_book->SetSelection(0); | |
3e859739 | 631 | #endif // USE_TREEBOOK |
f2fdc4d5 WS |
632 | } |
633 | ||
634 | WidgetsPage *WidgetsFrame::CurrentPage() | |
635 | { | |
453535a7 | 636 | wxWindow *page = m_book->GetCurrentPage(); |
453535a7 | 637 | |
3e859739 | 638 | #if !USE_TREEBOOK |
453535a7 | 639 | WidgetsBookCtrl *subBook = wxStaticCast(page, WidgetsBookCtrl); |
3e859739 VZ |
640 | wxCHECK_MSG( subBook, NULL, _T("no WidgetsBookCtrl?") ); |
641 | ||
453535a7 | 642 | page = subBook->GetCurrentPage(); |
3e859739 VZ |
643 | #endif // !USE_TREEBOOK |
644 | ||
453535a7 | 645 | return wxStaticCast(page, WidgetsPage); |
32b8ec41 VZ |
646 | } |
647 | ||
648 | WidgetsFrame::~WidgetsFrame() | |
649 | { | |
49abcb2f | 650 | #if USE_LOG |
32b8ec41 | 651 | delete m_logTarget; |
49abcb2f | 652 | #endif // USE_LOG |
32b8ec41 VZ |
653 | } |
654 | ||
655 | // ---------------------------------------------------------------------------- | |
656 | // WidgetsFrame event handlers | |
657 | // ---------------------------------------------------------------------------- | |
658 | ||
195df7a7 | 659 | void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
660 | { |
661 | Close(); | |
662 | } | |
663 | ||
49abcb2f | 664 | #if USE_LOG |
c02e5a31 | 665 | void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
666 | { |
667 | m_lboxLog->Clear(); | |
668 | } | |
49abcb2f | 669 | #endif // USE_LOG |
32b8ec41 | 670 | |
195df7a7 VZ |
671 | #if wxUSE_MENUS |
672 | ||
3e859739 VZ |
673 | void WidgetsFrame::OnPageChanging(WidgetsBookCtrlEvent& event) |
674 | { | |
0cebbfc2 WS |
675 | #if USE_TREEBOOK |
676 | // don't allow selection of entries without pages (categories) | |
3e859739 VZ |
677 | if ( !m_book->GetPage(event.GetSelection()) ) |
678 | event.Veto(); | |
b2b98dfd WS |
679 | #else |
680 | wxUnusedVar(event); | |
0cebbfc2 | 681 | #endif |
3e859739 VZ |
682 | } |
683 | ||
f2fdc4d5 | 684 | void WidgetsFrame::OnPageChanged(WidgetsBookCtrlEvent& event) |
3700e21b | 685 | { |
3e859739 VZ |
686 | const int sel = event.GetSelection(); |
687 | ||
453535a7 | 688 | // adjust "Page" menu selection |
3e859739 VZ |
689 | wxMenuItem *item = GetMenuBar()->FindItem(Widgets_GoToPage + sel); |
690 | if ( item ) | |
691 | item->Check(); | |
453535a7 | 692 | |
fe24a945 VZ |
693 | GetMenuBar()->Check(Widgets_BusyCursor, false); |
694 | ||
be16b859 VZ |
695 | // create the pages on demand, otherwise the sample startup is too slow as |
696 | // it creates hundreds of controls | |
3e859739 VZ |
697 | WidgetsPage *page = CurrentPage(); |
698 | if ( page->GetChildren().empty() ) | |
453535a7 WS |
699 | { |
700 | wxWindowUpdateLocker noUpdates(page); | |
701 | page->CreateContent(); | |
be16b859 VZ |
702 | //page->Layout(); |
703 | page->GetSizer()->Fit(page); | |
704 | ||
453535a7 WS |
705 | WidgetsBookCtrl *book = wxStaticCast(page->GetParent(), WidgetsBookCtrl); |
706 | wxSize size; | |
707 | for ( size_t i = 0; i < book->GetPageCount(); ++i ) | |
708 | { | |
709 | wxWindow *page = book->GetPage(i); | |
3e859739 | 710 | if ( page ) |
453535a7 WS |
711 | { |
712 | size.IncTo(page->GetSize()); | |
713 | } | |
714 | } | |
715 | page->SetSize(size); | |
716 | } | |
717 | ||
3700e21b VZ |
718 | event.Skip(); |
719 | } | |
720 | ||
721 | void WidgetsFrame::OnGoToPage(wxCommandEvent& event) | |
722 | { | |
f2fdc4d5 | 723 | #if USE_TREEBOOK |
3700e21b | 724 | m_book->SetSelection(event.GetId() - Widgets_GoToPage); |
f2fdc4d5 WS |
725 | #else |
726 | m_book->SetSelection(m_book->GetPageCount()-1); | |
727 | WidgetsBookCtrl *book = wxStaticCast(m_book->GetCurrentPage(), WidgetsBookCtrl); | |
728 | book->SetSelection(event.GetId() - Widgets_GoToPage); | |
729 | #endif | |
3700e21b VZ |
730 | } |
731 | ||
1c01dd16 VZ |
732 | #if wxUSE_TOOLTIPS |
733 | ||
734 | void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event)) | |
735 | { | |
736 | static wxString s_tip = _T("This is a tooltip"); | |
737 | ||
60c84f85 VZ |
738 | wxTextEntryDialog dialog |
739 | ( | |
740 | this, | |
741 | _T("Tooltip text (may use \\n, leave empty to remove): "), | |
742 | _T("Widgets sample"), | |
743 | s_tip | |
744 | ); | |
745 | ||
746 | if ( dialog.ShowModal() != wxID_OK ) | |
1c01dd16 VZ |
747 | return; |
748 | ||
60c84f85 | 749 | s_tip = dialog.GetValue(); |
0c113874 | 750 | s_tip.Replace(_T("\\n"), _T("\n")); |
bd018e7e | 751 | |
3e859739 VZ |
752 | WidgetsPage *page = CurrentPage(); |
753 | ||
60c84f85 | 754 | page->GetWidget()->SetToolTip(s_tip); |
1c01dd16 VZ |
755 | |
756 | wxControl *ctrl2 = page->GetWidget2(); | |
757 | if ( ctrl2 ) | |
60c84f85 | 758 | ctrl2->SetToolTip(s_tip); |
1c01dd16 VZ |
759 | } |
760 | ||
761 | #endif // wxUSE_TOOLTIPS | |
762 | ||
195df7a7 VZ |
763 | void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event)) |
764 | { | |
923f4e79 | 765 | #if wxUSE_COLOURDLG |
822b9009 | 766 | // allow for debugging the default colour the first time this is called |
f2fdc4d5 | 767 | WidgetsPage *page = CurrentPage(); |
63da71ba | 768 | |
822b9009 VZ |
769 | if (!m_colFg.Ok()) |
770 | m_colFg = page->GetForegroundColour(); | |
771 | ||
195df7a7 VZ |
772 | wxColour col = wxGetColourFromUser(this, m_colFg); |
773 | if ( !col.Ok() ) | |
774 | return; | |
775 | ||
776 | m_colFg = col; | |
777 | ||
195df7a7 | 778 | page->GetWidget()->SetForegroundColour(m_colFg); |
750972ab | 779 | page->GetWidget()->Refresh(); |
1c01dd16 VZ |
780 | |
781 | wxControl *ctrl2 = page->GetWidget2(); | |
782 | if ( ctrl2 ) | |
783 | { | |
784 | ctrl2->SetForegroundColour(m_colFg); | |
785 | ctrl2->Refresh(); | |
786 | } | |
923f4e79 | 787 | #else |
1c01dd16 | 788 | wxLogMessage(_T("Colour selection dialog not available in current build.")); |
923f4e79 | 789 | #endif |
195df7a7 VZ |
790 | } |
791 | ||
792 | void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event)) | |
793 | { | |
923f4e79 | 794 | #if wxUSE_COLOURDLG |
f2fdc4d5 | 795 | WidgetsPage *page = CurrentPage(); |
63da71ba | 796 | |
822b9009 VZ |
797 | if ( !m_colBg.Ok() ) |
798 | m_colBg = page->GetBackgroundColour(); | |
799 | ||
195df7a7 VZ |
800 | wxColour col = wxGetColourFromUser(this, m_colBg); |
801 | if ( !col.Ok() ) | |
802 | return; | |
803 | ||
804 | m_colBg = col; | |
805 | ||
195df7a7 | 806 | page->GetWidget()->SetBackgroundColour(m_colBg); |
750972ab | 807 | page->GetWidget()->Refresh(); |
1c01dd16 VZ |
808 | |
809 | wxControl *ctrl2 = page->GetWidget2(); | |
810 | if ( ctrl2 ) | |
811 | { | |
812 | ctrl2->SetBackgroundColour(m_colFg); | |
813 | ctrl2->Refresh(); | |
814 | } | |
923f4e79 | 815 | #else |
1c01dd16 | 816 | wxLogMessage(_T("Colour selection dialog not available in current build.")); |
923f4e79 | 817 | #endif |
195df7a7 VZ |
818 | } |
819 | ||
822b9009 VZ |
820 | void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event)) |
821 | { | |
822 | #if wxUSE_FONTDLG | |
f2fdc4d5 | 823 | WidgetsPage *page = CurrentPage(); |
63da71ba | 824 | |
822b9009 VZ |
825 | if (!m_font.Ok()) |
826 | m_font = page->GetFont(); | |
827 | ||
828 | wxFont font = wxGetFontFromUser(this, m_font); | |
829 | if ( !font.Ok() ) | |
830 | return; | |
831 | ||
832 | m_font = font; | |
833 | ||
834 | page->GetWidget()->SetFont(m_font); | |
835 | page->GetWidget()->Refresh(); | |
836 | ||
837 | wxControl *ctrl2 = page->GetWidget2(); | |
838 | if ( ctrl2 ) | |
839 | { | |
840 | ctrl2->SetFont(m_font); | |
841 | ctrl2->Refresh(); | |
842 | } | |
843 | #else | |
844 | wxLogMessage(_T("Font selection dialog not available in current build.")); | |
845 | #endif | |
846 | } | |
847 | ||
a17c1df4 VZ |
848 | void WidgetsFrame::OnEnable(wxCommandEvent& event) |
849 | { | |
3e859739 | 850 | CurrentPage()->GetWidget()->Enable(event.IsChecked()); |
a17c1df4 VZ |
851 | } |
852 | ||
1301e228 VZ |
853 | void WidgetsFrame::OnSetBorder(wxCommandEvent& event) |
854 | { | |
855 | int border; | |
856 | switch ( event.GetId() ) | |
857 | { | |
858 | case Widgets_BorderNone: border = wxBORDER_NONE; break; | |
859 | case Widgets_BorderStatic: border = wxBORDER_STATIC; break; | |
860 | case Widgets_BorderSimple: border = wxBORDER_SIMPLE; break; | |
861 | case Widgets_BorderRaised: border = wxBORDER_RAISED; break; | |
862 | case Widgets_BorderSunken: border = wxBORDER_SUNKEN; break; | |
863 | case Widgets_BorderDouble: border = wxBORDER_DOUBLE; break; | |
864 | ||
865 | default: | |
866 | wxFAIL_MSG( _T("unknown border style") ); | |
867 | // fall through | |
868 | ||
869 | case Widgets_BorderDefault: border = wxBORDER_DEFAULT; break; | |
870 | } | |
871 | ||
872 | WidgetsPage::ms_defaultFlags &= ~wxBORDER_MASK; | |
873 | WidgetsPage::ms_defaultFlags |= border; | |
874 | ||
f2fdc4d5 | 875 | WidgetsPage *page = CurrentPage(); |
63da71ba | 876 | |
1301e228 VZ |
877 | page->RecreateWidget(); |
878 | } | |
879 | ||
e32bcef6 VZ |
880 | void WidgetsFrame::OnToggleGlobalBusyCursor(wxCommandEvent& event) |
881 | { | |
882 | if ( event.IsChecked() ) | |
883 | wxBeginBusyCursor(); | |
884 | else | |
885 | wxEndBusyCursor(); | |
886 | } | |
887 | ||
888 | void WidgetsFrame::OnToggleBusyCursor(wxCommandEvent& event) | |
889 | { | |
3e859739 VZ |
890 | CurrentPage()->GetWidget()->SetCursor(*(event.IsChecked() |
891 | ? wxHOURGLASS_CURSOR | |
892 | : wxSTANDARD_CURSOR)); | |
e32bcef6 VZ |
893 | } |
894 | ||
6a8d7937 VZ |
895 | void WidgetsFrame::OnDisableAutoComplete(wxCommandEvent& WXUNUSED(event)) |
896 | { | |
897 | wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); | |
898 | wxCHECK_RET( entry, "menu item should be disabled" ); | |
899 | ||
900 | if ( entry->AutoComplete(wxArrayString()) ) | |
901 | wxLogMessage("Disabled auto completion."); | |
902 | else | |
903 | wxLogMessage("AutoComplete() failed."); | |
904 | } | |
905 | ||
906 | void WidgetsFrame::OnAutoCompleteFixed(wxCommandEvent& WXUNUSED(event)) | |
907 | { | |
908 | wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); | |
909 | wxCHECK_RET( entry, "menu item should be disabled" ); | |
910 | ||
911 | wxArrayString completion_choices; | |
912 | ||
913 | // add a few strings so a completion occurs on any letter typed | |
914 | for ( char idxc = 'a'; idxc < 'z'; ++idxc ) | |
915 | completion_choices.push_back(wxString::Format("%c%c", idxc, idxc)); | |
916 | ||
917 | completion_choices.push_back("is this string for test?"); | |
918 | completion_choices.push_back("this is a test string"); | |
919 | completion_choices.push_back("this is another test string"); | |
920 | completion_choices.push_back("this string is for test"); | |
921 | ||
922 | if ( entry->AutoComplete(completion_choices) ) | |
923 | wxLogMessage("Enabled auto completion of a set of fixed strings."); | |
924 | else | |
925 | wxLogMessage("AutoComplete() failed."); | |
926 | } | |
927 | ||
928 | void WidgetsFrame::OnAutoCompleteFilenames(wxCommandEvent& WXUNUSED(event)) | |
929 | { | |
930 | wxTextEntryBase *entry = CurrentPage()->GetTextEntry(); | |
931 | wxCHECK_RET( entry, "menu item should be disabled" ); | |
932 | ||
933 | if ( entry->AutoCompleteFileNames() ) | |
934 | wxLogMessage("Enable auto completion of file names."); | |
935 | else | |
936 | wxLogMessage("AutoCompleteFileNames() failed."); | |
937 | } | |
938 | ||
195df7a7 VZ |
939 | #endif // wxUSE_MENUS |
940 | ||
32b8ec41 VZ |
941 | // ---------------------------------------------------------------------------- |
942 | // WidgetsPageInfo | |
943 | // ---------------------------------------------------------------------------- | |
944 | ||
f2fdc4d5 | 945 | WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label, int categories) |
32b8ec41 | 946 | : m_label(label) |
f2fdc4d5 | 947 | , m_categories(categories) |
32b8ec41 VZ |
948 | { |
949 | m_ctor = ctor; | |
950 | ||
2673bcb0 DS |
951 | m_next = NULL; |
952 | ||
fdfe568d | 953 | // dummy sorting: add and immediately sort in the list according to label |
3700e21b | 954 | if ( WidgetsPage::ms_widgetPages ) |
2673bcb0 DS |
955 | { |
956 | WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages; | |
fdfe568d | 957 | if ( wxStrcmp(label, node_prev->GetLabel().c_str()) < 0 ) |
2673bcb0 DS |
958 | { |
959 | // add as first | |
960 | m_next = node_prev; | |
961 | WidgetsPage::ms_widgetPages = this; | |
962 | } | |
963 | else | |
964 | { | |
965 | WidgetsPageInfo *node_next; | |
966 | do | |
967 | { | |
968 | node_next = node_prev->GetNext(); | |
fdfe568d | 969 | if ( node_next ) |
2673bcb0 DS |
970 | { |
971 | // add if between two | |
fdfe568d | 972 | if ( wxStrcmp(label, node_next->GetLabel().c_str()) < 0 ) |
2673bcb0 DS |
973 | { |
974 | node_prev->SetNext(this); | |
975 | m_next = node_next; | |
976 | // force to break loop | |
977 | node_next = NULL; | |
978 | } | |
979 | } | |
980 | else | |
981 | { | |
982 | // add as last | |
983 | node_prev->SetNext(this); | |
984 | m_next = node_next; | |
985 | } | |
986 | node_prev = node_next; | |
fdfe568d VZ |
987 | } |
988 | while ( node_next ); | |
2673bcb0 DS |
989 | } |
990 | } | |
991 | else | |
992 | { | |
993 | // add when first | |
2673bcb0 | 994 | WidgetsPage::ms_widgetPages = this; |
2673bcb0 | 995 | } |
32b8ec41 VZ |
996 | } |
997 | ||
998 | // ---------------------------------------------------------------------------- | |
999 | // WidgetsPage | |
1000 | // ---------------------------------------------------------------------------- | |
1001 | ||
1301e228 VZ |
1002 | int WidgetsPage::ms_defaultFlags = wxBORDER_DEFAULT; |
1003 | WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL; | |
1004 | ||
261357eb WS |
1005 | WidgetsPage::WidgetsPage(WidgetsBookCtrl *book, |
1006 | wxImageList *imaglist, | |
747d7d7c | 1007 | const char *const icon[]) |
61c083e7 | 1008 | : wxPanel(book, wxID_ANY, |
df0787b6 VZ |
1009 | wxDefaultPosition, wxDefaultSize, |
1010 | wxNO_FULL_REPAINT_ON_RESIZE | | |
1011 | wxCLIP_CHILDREN | | |
1012 | wxTAB_TRAVERSAL) | |
32b8ec41 | 1013 | { |
261357eb | 1014 | #if USE_ICONS_IN_BOOK |
993b016d | 1015 | imaglist->Add(wxBitmap(wxImage(icon).Scale(ICON_SIZE, ICON_SIZE))); |
261357eb WS |
1016 | #else |
1017 | wxUnusedVar(imaglist); | |
1018 | wxUnusedVar(icon); | |
1019 | #endif | |
32b8ec41 VZ |
1020 | } |
1021 | ||
1022 | wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control, | |
1023 | wxWindowID id, | |
1024 | wxTextCtrl **ppText) | |
1025 | { | |
1026 | wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); | |
206d3a16 JS |
1027 | wxTextCtrl *text = new wxTextCtrl(this, id, wxEmptyString, |
1028 | wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); | |
4589ec39 | 1029 | |
32b8ec41 VZ |
1030 | sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5); |
1031 | sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5); | |
1032 | ||
1033 | if ( ppText ) | |
1034 | *ppText = text; | |
1035 | ||
1036 | return sizerRow; | |
1037 | } | |
1038 | ||
1039 | // create a sizer containing a label and a text ctrl | |
1040 | wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label, | |
1041 | wxWindowID id, | |
1042 | wxTextCtrl **ppText) | |
1043 | { | |
206d3a16 JS |
1044 | return CreateSizerWithText(new wxStaticText(this, wxID_ANY, label), |
1045 | id, ppText); | |
32b8ec41 VZ |
1046 | } |
1047 | ||
1048 | // create a sizer containing a button and a text ctrl | |
1049 | wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn, | |
1050 | const wxString& label, | |
1051 | wxWindowID id, | |
1052 | wxTextCtrl **ppText) | |
1053 | { | |
1054 | return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText); | |
1055 | } | |
1056 | ||
1057 | wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
1058 | const wxString& label, | |
1059 | wxWindowID id) | |
1060 | { | |
1061 | wxCheckBox *checkbox = new wxCheckBox(this, id, label); | |
1062 | sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5); | |
1063 | sizer->Add(0, 2, 0, wxGROW); // spacer | |
1064 | ||
1065 | return checkbox; | |
1066 | } |