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