]>
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 VZ |
32 | #include "wx/menu.h" |
33 | ||
32b8ec41 VZ |
34 | #include "wx/button.h" |
35 | #include "wx/checkbox.h" | |
36 | #include "wx/listbox.h" | |
37 | #include "wx/statbox.h" | |
38 | #include "wx/stattext.h" | |
39 | #include "wx/textctrl.h" | |
bd018e7e | 40 | #include "wx/msgdlg.h" |
32b8ec41 VZ |
41 | #endif |
42 | ||
25057aba | 43 | #include "wx/sysopt.h" |
61c083e7 | 44 | #include "wx/bookctrl.h" |
32b8ec41 | 45 | #include "wx/sizer.h" |
195df7a7 | 46 | #include "wx/colordlg.h" |
822b9009 | 47 | #include "wx/fontdlg.h" |
1bdd1007 | 48 | #include "wx/textdlg.h" |
32b8ec41 VZ |
49 | |
50 | #include "widgets.h" | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // constants | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | // control ids | |
57 | enum | |
58 | { | |
59 | Widgets_ClearLog = 100, | |
195df7a7 | 60 | Widgets_Quit, |
1c01dd16 VZ |
61 | #if wxUSE_TOOLTIPS |
62 | Widgets_SetTooltip, | |
63 | #endif // wxUSE_TOOLTIPS | |
195df7a7 | 64 | Widgets_SetFgColour, |
822b9009 | 65 | Widgets_SetBgColour, |
a17c1df4 VZ |
66 | Widgets_SetFont, |
67 | Widgets_Enable | |
32b8ec41 VZ |
68 | }; |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // our classes | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | // Define a new application type, each program should derive a class from wxApp | |
75 | class WidgetsApp : public wxApp | |
76 | { | |
77 | public: | |
78 | // override base class virtuals | |
79 | // ---------------------------- | |
80 | ||
81 | // this one is called on application startup and is a good place for the app | |
82 | // initialization (doing it here and not in the ctor allows to have an error | |
83 | // return: if OnInit() returns false, the application terminates) | |
84 | virtual bool OnInit(); | |
85 | }; | |
86 | ||
87 | // Define a new frame type: this is going to be our main frame | |
88 | class WidgetsFrame : public wxFrame | |
89 | { | |
90 | public: | |
91 | // ctor(s) and dtor | |
92 | WidgetsFrame(const wxString& title); | |
93 | virtual ~WidgetsFrame(); | |
94 | ||
95 | protected: | |
96 | // event handlers | |
49abcb2f | 97 | #if USE_LOG |
32b8ec41 | 98 | void OnButtonClearLog(wxCommandEvent& event); |
49abcb2f | 99 | #endif // USE_LOG |
195df7a7 | 100 | void OnExit(wxCommandEvent& event); |
a17c1df4 | 101 | |
195df7a7 | 102 | #if wxUSE_MENUS |
1c01dd16 VZ |
103 | #if wxUSE_TOOLTIPS |
104 | void OnSetTooltip(wxCommandEvent& event); | |
105 | #endif // wxUSE_TOOLTIPS | |
195df7a7 VZ |
106 | void OnSetFgCol(wxCommandEvent& event); |
107 | void OnSetBgCol(wxCommandEvent& event); | |
822b9009 | 108 | void OnSetFont(wxCommandEvent& event); |
a17c1df4 | 109 | void OnEnable(wxCommandEvent& event); |
195df7a7 | 110 | #endif // wxUSE_MENUS |
32b8ec41 | 111 | |
61c083e7 WS |
112 | // initialize the book: add all pages to it |
113 | void InitBook(); | |
32b8ec41 VZ |
114 | |
115 | private: | |
116 | // the panel containing everything | |
117 | wxPanel *m_panel; | |
118 | ||
49abcb2f | 119 | #if USE_LOG |
32b8ec41 VZ |
120 | // the listbox for logging messages |
121 | wxListBox *m_lboxLog; | |
122 | ||
123 | // the log target we use to redirect messages to the listbox | |
124 | wxLog *m_logTarget; | |
49abcb2f | 125 | #endif // USE_LOG |
32b8ec41 | 126 | |
61c083e7 | 127 | // the book containing the test pages |
5378558e | 128 | wxBookCtrlBase *m_book; |
32b8ec41 VZ |
129 | |
130 | // and the image list for it | |
131 | wxImageList *m_imaglist; | |
132 | ||
195df7a7 | 133 | #if wxUSE_MENUS |
822b9009 | 134 | // last chosen fg/bg colours and font |
195df7a7 VZ |
135 | wxColour m_colFg, |
136 | m_colBg; | |
822b9009 | 137 | wxFont m_font; |
195df7a7 VZ |
138 | #endif // wxUSE_MENUS |
139 | ||
be5a51fb | 140 | // any class wishing to process wxWidgets events must use this macro |
32b8ec41 VZ |
141 | DECLARE_EVENT_TABLE() |
142 | }; | |
143 | ||
49abcb2f | 144 | #if USE_LOG |
32b8ec41 VZ |
145 | // A log target which just redirects the messages to a listbox |
146 | class LboxLogger : public wxLog | |
147 | { | |
148 | public: | |
149 | LboxLogger(wxListBox *lbox, wxLog *logOld) | |
150 | { | |
151 | m_lbox = lbox; | |
152 | //m_lbox->Disable(); -- looks ugly under MSW | |
153 | m_logOld = logOld; | |
154 | } | |
155 | ||
156 | virtual ~LboxLogger() | |
157 | { | |
158 | wxLog::SetActiveTarget(m_logOld); | |
159 | } | |
160 | ||
161 | private: | |
162 | // implement sink functions | |
163 | virtual void DoLog(wxLogLevel level, const wxChar *szString, time_t t) | |
164 | { | |
165 | // don't put trace messages into listbox or we can get into infinite | |
166 | // recursion | |
167 | if ( level == wxLOG_Trace ) | |
168 | { | |
169 | if ( m_logOld ) | |
170 | { | |
171 | // cast is needed to call protected method | |
172 | ((LboxLogger *)m_logOld)->DoLog(level, szString, t); | |
173 | } | |
174 | } | |
175 | else | |
176 | { | |
177 | wxLog::DoLog(level, szString, t); | |
178 | } | |
179 | } | |
180 | ||
c02e5a31 | 181 | virtual void DoLogString(const wxChar *szString, time_t WXUNUSED(t)) |
32b8ec41 VZ |
182 | { |
183 | wxString msg; | |
184 | TimeStamp(&msg); | |
185 | msg += szString; | |
186 | ||
187 | #ifdef __WXUNIVERSAL__ | |
188 | m_lbox->AppendAndEnsureVisible(msg); | |
189 | #else // other ports don't have this method yet | |
190 | m_lbox->Append(msg); | |
191 | m_lbox->SetFirstItem(m_lbox->GetCount() - 1); | |
192 | #endif | |
193 | } | |
194 | ||
195 | // the control we use | |
196 | wxListBox *m_lbox; | |
197 | ||
198 | // the old log target | |
199 | wxLog *m_logOld; | |
200 | }; | |
49abcb2f | 201 | #endif // USE_LOG |
32b8ec41 VZ |
202 | |
203 | // array of pages | |
38d6b957 | 204 | WX_DEFINE_ARRAY_PTR(WidgetsPage *, ArrayWidgetsPage); |
32b8ec41 VZ |
205 | |
206 | // ---------------------------------------------------------------------------- | |
207 | // misc macros | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
210 | IMPLEMENT_APP(WidgetsApp) | |
211 | ||
32b8ec41 VZ |
212 | // ---------------------------------------------------------------------------- |
213 | // event tables | |
214 | // ---------------------------------------------------------------------------- | |
215 | ||
216 | BEGIN_EVENT_TABLE(WidgetsFrame, wxFrame) | |
49abcb2f | 217 | #if USE_LOG |
32b8ec41 | 218 | EVT_BUTTON(Widgets_ClearLog, WidgetsFrame::OnButtonClearLog) |
49abcb2f | 219 | #endif // USE_LOG |
195df7a7 VZ |
220 | EVT_BUTTON(Widgets_Quit, WidgetsFrame::OnExit) |
221 | ||
1c01dd16 VZ |
222 | #if wxUSE_TOOLTIPS |
223 | EVT_MENU(Widgets_SetTooltip, WidgetsFrame::OnSetTooltip) | |
224 | #endif // wxUSE_TOOLTIPS | |
225 | ||
195df7a7 VZ |
226 | EVT_MENU(Widgets_SetFgColour, WidgetsFrame::OnSetFgCol) |
227 | EVT_MENU(Widgets_SetBgColour, WidgetsFrame::OnSetBgCol) | |
822b9009 | 228 | EVT_MENU(Widgets_SetFont, WidgetsFrame::OnSetFont) |
a17c1df4 | 229 | EVT_MENU(Widgets_Enable, WidgetsFrame::OnEnable) |
1c01dd16 VZ |
230 | |
231 | EVT_MENU(wxID_EXIT, WidgetsFrame::OnExit) | |
32b8ec41 VZ |
232 | END_EVENT_TABLE() |
233 | ||
234 | // ============================================================================ | |
235 | // implementation | |
236 | // ============================================================================ | |
237 | ||
238 | // ---------------------------------------------------------------------------- | |
239 | // app class | |
240 | // ---------------------------------------------------------------------------- | |
241 | ||
242 | bool WidgetsApp::OnInit() | |
243 | { | |
bf188f1a | 244 | if ( !wxApp::OnInit() ) |
206d3a16 | 245 | return false; |
1bdd1007 | 246 | |
32b8ec41 VZ |
247 | // the reason for having these ifdef's is that I often run two copies of |
248 | // this sample side by side and it is useful to see which one is which | |
24e78d27 | 249 | wxString title; |
32b8ec41 | 250 | #if defined(__WXUNIVERSAL__) |
085a1f3c | 251 | title = _T("wxUniv/"); |
24e78d27 VZ |
252 | #endif |
253 | ||
254 | #if defined(__WXMSW__) | |
255 | title += _T("wxMSW"); | |
32b8ec41 | 256 | #elif defined(__WXGTK__) |
24e78d27 | 257 | title += _T("wxGTK"); |
0f9390c3 GD |
258 | #elif defined(__WXMAC__) |
259 | title += _T("wxMAC"); | |
260 | #elif defined(__WXMOTIF__) | |
261 | title += _T("wxMOTIF"); | |
32b8ec41 | 262 | #else |
be5a51fb | 263 | title += _T("wxWidgets"); |
32b8ec41 | 264 | #endif |
32b8ec41 VZ |
265 | |
266 | wxFrame *frame = new WidgetsFrame(title + _T(" widgets demo")); | |
267 | frame->Show(); | |
268 | ||
269 | //wxLog::AddTraceMask(_T("listbox")); | |
270 | //wxLog::AddTraceMask(_T("scrollbar")); | |
58ec2255 | 271 | //wxLog::AddTraceMask(_T("focus")); |
32b8ec41 | 272 | |
206d3a16 | 273 | return true; |
32b8ec41 VZ |
274 | } |
275 | ||
276 | // ---------------------------------------------------------------------------- | |
277 | // WidgetsFrame construction | |
278 | // ---------------------------------------------------------------------------- | |
279 | ||
280 | WidgetsFrame::WidgetsFrame(const wxString& title) | |
206d3a16 | 281 | : wxFrame(NULL, wxID_ANY, title, |
df0787b6 VZ |
282 | wxPoint(0, 50), wxDefaultSize, |
283 | wxDEFAULT_FRAME_STYLE | | |
284 | wxNO_FULL_REPAINT_ON_RESIZE | | |
285 | wxCLIP_CHILDREN | | |
286 | wxTAB_TRAVERSAL) | |
32b8ec41 VZ |
287 | { |
288 | // init everything | |
49abcb2f | 289 | #if USE_LOG |
32b8ec41 VZ |
290 | m_lboxLog = (wxListBox *)NULL; |
291 | m_logTarget = (wxLog *)NULL; | |
49abcb2f | 292 | #endif // USE_LOG |
5378558e | 293 | m_book = (wxBookCtrlBase *)NULL; |
32b8ec41 VZ |
294 | m_imaglist = (wxImageList *)NULL; |
295 | ||
195df7a7 VZ |
296 | #if wxUSE_MENUS |
297 | // create the menubar | |
298 | wxMenuBar *mbar = new wxMenuBar; | |
299 | wxMenu *menuWidget = new wxMenu; | |
1c01dd16 VZ |
300 | #if wxUSE_TOOLTIPS |
301 | menuWidget->Append(Widgets_SetTooltip, _T("Set &tooltip...\tCtrl-T")); | |
302 | menuWidget->AppendSeparator(); | |
303 | #endif // wxUSE_TOOLTIPS | |
195df7a7 VZ |
304 | menuWidget->Append(Widgets_SetFgColour, _T("Set &foreground...\tCtrl-F")); |
305 | menuWidget->Append(Widgets_SetBgColour, _T("Set &background...\tCtrl-B")); | |
822b9009 | 306 | menuWidget->Append(Widgets_SetFont, _T("Set f&ont...\tCtrl-O")); |
a17c1df4 | 307 | menuWidget->AppendCheckItem(Widgets_Enable, _T("&Enable/disable\tCtrl-E")); |
195df7a7 VZ |
308 | menuWidget->AppendSeparator(); |
309 | menuWidget->Append(wxID_EXIT, _T("&Quit\tCtrl-Q")); | |
310 | mbar->Append(menuWidget, _T("&Widget")); | |
311 | SetMenuBar(mbar); | |
a17c1df4 VZ |
312 | |
313 | mbar->Check(Widgets_Enable, true); | |
195df7a7 VZ |
314 | #endif // wxUSE_MENUS |
315 | ||
32b8ec41 | 316 | // create controls |
206d3a16 JS |
317 | m_panel = new wxPanel(this, wxID_ANY, |
318 | wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN); | |
32b8ec41 VZ |
319 | |
320 | wxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); | |
321 | ||
25057aba | 322 | // we have 2 panes: book with pages demonstrating the controls in the |
32b8ec41 | 323 | // upper one and the log window with some buttons in the lower |
1bdd1007 | 324 | |
2ddb4d13 | 325 | int style = wxNO_FULL_REPAINT_ON_RESIZE|wxCLIP_CHILDREN|wxBK_DEFAULT; |
25057aba | 326 | // Uncomment to suppress page theme (draw in solid colour) |
8c9f8f91 | 327 | //style |= wxNB_NOPAGETHEME; |
32b8ec41 | 328 | |
61c083e7 | 329 | m_book = new wxBookCtrl(m_panel, wxID_ANY, wxDefaultPosition, |
6bae6726 | 330 | #ifdef __WXMOTIF__ |
2ddb4d13 | 331 | wxSize(500, wxDefaultCoord), // under Motif, height is a function of the width... |
6bae6726 MB |
332 | #else |
333 | wxDefaultSize, | |
334 | #endif | |
335 | style); | |
61c083e7 | 336 | InitBook(); |
32b8ec41 | 337 | |
49abcb2f | 338 | #ifndef __SMARTPHONE__ |
32b8ec41 | 339 | // the lower one only has the log listbox and a button to clear it |
49abcb2f | 340 | #if USE_LOG |
206d3a16 JS |
341 | wxSizer *sizerDown = new wxStaticBoxSizer( |
342 | new wxStaticBox( m_panel, wxID_ANY, _T("&Log window") ), | |
343 | wxVERTICAL); | |
344 | ||
345 | m_lboxLog = new wxListBox(m_panel, wxID_ANY); | |
32b8ec41 | 346 | sizerDown->Add(m_lboxLog, 1, wxGROW | wxALL, 5); |
7b127900 | 347 | sizerDown->SetMinSize(100, 150); |
b29903d4 WS |
348 | #else |
349 | wxSizer *sizerDown = new wxBoxSizer(wxVERTICAL); | |
49abcb2f | 350 | #endif // USE_LOG |
88633ca7 | 351 | |
32b8ec41 | 352 | wxBoxSizer *sizerBtns = new wxBoxSizer(wxHORIZONTAL); |
b29903d4 | 353 | wxButton *btn; |
49abcb2f | 354 | #if USE_LOG |
b29903d4 | 355 | btn = new wxButton(m_panel, Widgets_ClearLog, _T("Clear &log")); |
32b8ec41 VZ |
356 | sizerBtns->Add(btn); |
357 | sizerBtns->Add(10, 0); // spacer | |
49abcb2f | 358 | #endif // USE_LOG |
32b8ec41 VZ |
359 | btn = new wxButton(m_panel, Widgets_Quit, _T("E&xit")); |
360 | sizerBtns->Add(btn); | |
361 | sizerDown->Add(sizerBtns, 0, wxALL | wxALIGN_RIGHT, 5); | |
362 | ||
363 | // put everything together | |
61c083e7 | 364 | sizerTop->Add(m_book, 1, wxGROW | (wxALL & ~(wxTOP | wxBOTTOM)), 10); |
32b8ec41 VZ |
365 | sizerTop->Add(0, 5, 0, wxGROW); // spacer in between |
366 | sizerTop->Add(sizerDown, 0, wxGROW | (wxALL & ~wxTOP), 10); | |
367 | ||
49abcb2f WS |
368 | #else // !__SMARTPHONE__/__SMARTPHONE__ |
369 | ||
370 | sizerTop->Add(m_book, 1, wxGROW | wxALL ); | |
371 | ||
372 | #endif // __SMARTPHONE__ | |
373 | ||
32b8ec41 VZ |
374 | m_panel->SetSizer(sizerTop); |
375 | ||
376 | sizerTop->Fit(this); | |
377 | sizerTop->SetSizeHints(this); | |
378 | ||
49abcb2f | 379 | #if USE_LOG && !defined(__WXCOCOA__) |
7bb70733 | 380 | // wxCocoa's listbox is too flakey to use for logging right now |
32b8ec41 VZ |
381 | // now that everything is created we can redirect the log messages to the |
382 | // listbox | |
383 | m_logTarget = new LboxLogger(m_lboxLog, wxLog::GetActiveTarget()); | |
384 | wxLog::SetActiveTarget(m_logTarget); | |
b29903d4 | 385 | #endif |
32b8ec41 VZ |
386 | } |
387 | ||
61c083e7 | 388 | void WidgetsFrame::InitBook() |
32b8ec41 VZ |
389 | { |
390 | m_imaglist = new wxImageList(32, 32); | |
391 | ||
392 | ArrayWidgetsPage pages; | |
393 | wxArrayString labels; | |
394 | ||
61c083e7 | 395 | // we need to first create all pages and only then add them to the book |
32b8ec41 VZ |
396 | // as we need the image list first |
397 | WidgetsPageInfo *info = WidgetsPage::ms_widgetPages; | |
398 | while ( info ) | |
399 | { | |
61c083e7 | 400 | WidgetsPage *page = (*info->GetCtor())(m_book, m_imaglist); |
32b8ec41 VZ |
401 | pages.Add(page); |
402 | ||
403 | labels.Add(info->GetLabel()); | |
404 | ||
405 | info = info->GetNext(); | |
406 | } | |
407 | ||
61c083e7 | 408 | m_book->SetImageList(m_imaglist); |
32b8ec41 VZ |
409 | |
410 | // now do add them | |
411 | size_t count = pages.GetCount(); | |
412 | for ( size_t n = 0; n < count; n++ ) | |
413 | { | |
61c083e7 WS |
414 | m_book->AddPage( |
415 | pages[n], | |
416 | labels[n], | |
417 | false, // don't select | |
418 | n // image id | |
419 | ); | |
25057aba JS |
420 | |
421 | /* | |
422 | wxColour colour = m_book->MSWGetBgColourForChild(pages[n]); | |
423 | pages[n]->SetBackgroundColour(colour); | |
424 | */ | |
32b8ec41 VZ |
425 | } |
426 | } | |
427 | ||
428 | WidgetsFrame::~WidgetsFrame() | |
429 | { | |
49abcb2f | 430 | #if USE_LOG |
32b8ec41 | 431 | delete m_logTarget; |
49abcb2f | 432 | #endif // USE_LOG |
32b8ec41 VZ |
433 | delete m_imaglist; |
434 | } | |
435 | ||
436 | // ---------------------------------------------------------------------------- | |
437 | // WidgetsFrame event handlers | |
438 | // ---------------------------------------------------------------------------- | |
439 | ||
195df7a7 | 440 | void WidgetsFrame::OnExit(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
441 | { |
442 | Close(); | |
443 | } | |
444 | ||
49abcb2f | 445 | #if USE_LOG |
c02e5a31 | 446 | void WidgetsFrame::OnButtonClearLog(wxCommandEvent& WXUNUSED(event)) |
32b8ec41 VZ |
447 | { |
448 | m_lboxLog->Clear(); | |
449 | } | |
49abcb2f | 450 | #endif // USE_LOG |
32b8ec41 | 451 | |
195df7a7 VZ |
452 | #if wxUSE_MENUS |
453 | ||
1c01dd16 VZ |
454 | #if wxUSE_TOOLTIPS |
455 | ||
456 | void WidgetsFrame::OnSetTooltip(wxCommandEvent& WXUNUSED(event)) | |
457 | { | |
458 | static wxString s_tip = _T("This is a tooltip"); | |
459 | ||
460 | wxString s = wxGetTextFromUser | |
461 | ( | |
462 | _T("Tooltip text: "), | |
463 | _T("Widgets sample"), | |
464 | s_tip, | |
465 | this | |
466 | ); | |
467 | ||
468 | if ( s.empty() ) | |
469 | return; | |
470 | ||
bd018e7e WS |
471 | s_tip = s; |
472 | ||
473 | if( wxMessageBox( _T("Test multiline tooltip text?"), | |
474 | _T("Widgets sample"), | |
475 | wxYES_NO, | |
476 | this | |
477 | ) == wxYES ) | |
478 | { | |
479 | s = _T("#1 ") + s_tip + _T("\n") + _T("#2 ") + s_tip; | |
480 | } | |
481 | ||
1c01dd16 | 482 | WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); |
bd018e7e | 483 | page->GetWidget()->SetToolTip(s); |
1c01dd16 VZ |
484 | |
485 | wxControl *ctrl2 = page->GetWidget2(); | |
486 | if ( ctrl2 ) | |
487 | ctrl2->SetToolTip(s); | |
488 | } | |
489 | ||
490 | #endif // wxUSE_TOOLTIPS | |
491 | ||
195df7a7 VZ |
492 | void WidgetsFrame::OnSetFgCol(wxCommandEvent& WXUNUSED(event)) |
493 | { | |
923f4e79 | 494 | #if wxUSE_COLOURDLG |
822b9009 VZ |
495 | // allow for debugging the default colour the first time this is called |
496 | WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); | |
497 | if (!m_colFg.Ok()) | |
498 | m_colFg = page->GetForegroundColour(); | |
499 | ||
195df7a7 VZ |
500 | wxColour col = wxGetColourFromUser(this, m_colFg); |
501 | if ( !col.Ok() ) | |
502 | return; | |
503 | ||
504 | m_colFg = col; | |
505 | ||
195df7a7 | 506 | page->GetWidget()->SetForegroundColour(m_colFg); |
750972ab | 507 | page->GetWidget()->Refresh(); |
1c01dd16 VZ |
508 | |
509 | wxControl *ctrl2 = page->GetWidget2(); | |
510 | if ( ctrl2 ) | |
511 | { | |
512 | ctrl2->SetForegroundColour(m_colFg); | |
513 | ctrl2->Refresh(); | |
514 | } | |
923f4e79 | 515 | #else |
1c01dd16 | 516 | wxLogMessage(_T("Colour selection dialog not available in current build.")); |
923f4e79 | 517 | #endif |
195df7a7 VZ |
518 | } |
519 | ||
520 | void WidgetsFrame::OnSetBgCol(wxCommandEvent& WXUNUSED(event)) | |
521 | { | |
923f4e79 | 522 | #if wxUSE_COLOURDLG |
822b9009 VZ |
523 | WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); |
524 | if ( !m_colBg.Ok() ) | |
525 | m_colBg = page->GetBackgroundColour(); | |
526 | ||
195df7a7 VZ |
527 | wxColour col = wxGetColourFromUser(this, m_colBg); |
528 | if ( !col.Ok() ) | |
529 | return; | |
530 | ||
531 | m_colBg = col; | |
532 | ||
195df7a7 | 533 | page->GetWidget()->SetBackgroundColour(m_colBg); |
750972ab | 534 | page->GetWidget()->Refresh(); |
1c01dd16 VZ |
535 | |
536 | wxControl *ctrl2 = page->GetWidget2(); | |
537 | if ( ctrl2 ) | |
538 | { | |
539 | ctrl2->SetBackgroundColour(m_colFg); | |
540 | ctrl2->Refresh(); | |
541 | } | |
923f4e79 | 542 | #else |
1c01dd16 | 543 | wxLogMessage(_T("Colour selection dialog not available in current build.")); |
923f4e79 | 544 | #endif |
195df7a7 VZ |
545 | } |
546 | ||
822b9009 VZ |
547 | void WidgetsFrame::OnSetFont(wxCommandEvent& WXUNUSED(event)) |
548 | { | |
549 | #if wxUSE_FONTDLG | |
550 | WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); | |
551 | if (!m_font.Ok()) | |
552 | m_font = page->GetFont(); | |
553 | ||
554 | wxFont font = wxGetFontFromUser(this, m_font); | |
555 | if ( !font.Ok() ) | |
556 | return; | |
557 | ||
558 | m_font = font; | |
559 | ||
560 | page->GetWidget()->SetFont(m_font); | |
561 | page->GetWidget()->Refresh(); | |
562 | ||
563 | wxControl *ctrl2 = page->GetWidget2(); | |
564 | if ( ctrl2 ) | |
565 | { | |
566 | ctrl2->SetFont(m_font); | |
567 | ctrl2->Refresh(); | |
568 | } | |
569 | #else | |
570 | wxLogMessage(_T("Font selection dialog not available in current build.")); | |
571 | #endif | |
572 | } | |
573 | ||
a17c1df4 VZ |
574 | void WidgetsFrame::OnEnable(wxCommandEvent& event) |
575 | { | |
576 | WidgetsPage *page = wxStaticCast(m_book->GetCurrentPage(), WidgetsPage); | |
577 | page->GetWidget()->Enable(event.IsChecked()); | |
578 | } | |
579 | ||
195df7a7 VZ |
580 | #endif // wxUSE_MENUS |
581 | ||
32b8ec41 VZ |
582 | // ---------------------------------------------------------------------------- |
583 | // WidgetsPageInfo | |
584 | // ---------------------------------------------------------------------------- | |
585 | ||
586 | WidgetsPageInfo *WidgetsPage::ms_widgetPages = NULL; | |
587 | ||
588 | WidgetsPageInfo::WidgetsPageInfo(Constructor ctor, const wxChar *label) | |
589 | : m_label(label) | |
590 | { | |
591 | m_ctor = ctor; | |
592 | ||
2673bcb0 DS |
593 | m_next = NULL; |
594 | ||
595 | // dummy sorting: add and immediately sort on list according to label | |
596 | ||
597 | if(WidgetsPage::ms_widgetPages) | |
598 | { | |
599 | WidgetsPageInfo *node_prev = WidgetsPage::ms_widgetPages; | |
600 | if(wxStrcmp(label,node_prev->GetLabel().c_str())<0) | |
601 | { | |
602 | // add as first | |
603 | m_next = node_prev; | |
604 | WidgetsPage::ms_widgetPages = this; | |
605 | } | |
606 | else | |
607 | { | |
608 | WidgetsPageInfo *node_next; | |
609 | do | |
610 | { | |
611 | node_next = node_prev->GetNext(); | |
612 | if(node_next) | |
613 | { | |
614 | // add if between two | |
615 | if(wxStrcmp(label,node_next->GetLabel().c_str())<0) | |
616 | { | |
617 | node_prev->SetNext(this); | |
618 | m_next = node_next; | |
619 | // force to break loop | |
620 | node_next = NULL; | |
621 | } | |
622 | } | |
623 | else | |
624 | { | |
625 | // add as last | |
626 | node_prev->SetNext(this); | |
627 | m_next = node_next; | |
628 | } | |
629 | node_prev = node_next; | |
630 | }while(node_next); | |
631 | } | |
632 | } | |
633 | else | |
634 | { | |
635 | // add when first | |
636 | ||
637 | WidgetsPage::ms_widgetPages = this; | |
638 | ||
639 | } | |
640 | ||
32b8ec41 VZ |
641 | } |
642 | ||
643 | // ---------------------------------------------------------------------------- | |
644 | // WidgetsPage | |
645 | // ---------------------------------------------------------------------------- | |
646 | ||
5378558e | 647 | WidgetsPage::WidgetsPage(wxBookCtrlBase *book) |
61c083e7 | 648 | : wxPanel(book, wxID_ANY, |
df0787b6 VZ |
649 | wxDefaultPosition, wxDefaultSize, |
650 | wxNO_FULL_REPAINT_ON_RESIZE | | |
651 | wxCLIP_CHILDREN | | |
652 | wxTAB_TRAVERSAL) | |
32b8ec41 VZ |
653 | { |
654 | } | |
655 | ||
656 | wxSizer *WidgetsPage::CreateSizerWithText(wxControl *control, | |
657 | wxWindowID id, | |
658 | wxTextCtrl **ppText) | |
659 | { | |
660 | wxSizer *sizerRow = new wxBoxSizer(wxHORIZONTAL); | |
206d3a16 JS |
661 | wxTextCtrl *text = new wxTextCtrl(this, id, wxEmptyString, |
662 | wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); | |
4589ec39 | 663 | |
32b8ec41 VZ |
664 | sizerRow->Add(control, 0, wxRIGHT | wxALIGN_CENTRE_VERTICAL, 5); |
665 | sizerRow->Add(text, 1, wxLEFT | wxALIGN_CENTRE_VERTICAL, 5); | |
666 | ||
667 | if ( ppText ) | |
668 | *ppText = text; | |
669 | ||
670 | return sizerRow; | |
671 | } | |
672 | ||
673 | // create a sizer containing a label and a text ctrl | |
674 | wxSizer *WidgetsPage::CreateSizerWithTextAndLabel(const wxString& label, | |
675 | wxWindowID id, | |
676 | wxTextCtrl **ppText) | |
677 | { | |
206d3a16 JS |
678 | return CreateSizerWithText(new wxStaticText(this, wxID_ANY, label), |
679 | id, ppText); | |
32b8ec41 VZ |
680 | } |
681 | ||
682 | // create a sizer containing a button and a text ctrl | |
683 | wxSizer *WidgetsPage::CreateSizerWithTextAndButton(wxWindowID idBtn, | |
684 | const wxString& label, | |
685 | wxWindowID id, | |
686 | wxTextCtrl **ppText) | |
687 | { | |
688 | return CreateSizerWithText(new wxButton(this, idBtn, label), id, ppText); | |
689 | } | |
690 | ||
691 | wxCheckBox *WidgetsPage::CreateCheckBoxAndAddToSizer(wxSizer *sizer, | |
692 | const wxString& label, | |
693 | wxWindowID id) | |
694 | { | |
695 | wxCheckBox *checkbox = new wxCheckBox(this, id, label); | |
696 | sizer->Add(checkbox, 0, wxLEFT | wxRIGHT, 5); | |
697 | sizer->Add(0, 2, 0, wxGROW); // spacer | |
698 | ||
699 | return checkbox; | |
700 | } |