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