]> git.saurik.com Git - wxWidgets.git/blame - samples/dialogs/dialogs.cpp
don't output -DwxUSE_GUI=0 in cflags by default, do output it if 'base' is specified...
[wxWidgets.git] / samples / dialogs / dialogs.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialogs.cpp
3// Purpose: Common dialogs demo
4// Author: Julian Smart
695fe764 5// Modified by: ABX (2004) - adjustements for conditional building + new menu
457814b5
JS
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
c50f1fb9 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
457814b5
JS
12// For compilers that support precompilation, includes "wx/wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
0f5d8ecf
JS
23#include "../sample.xpm"
24
fb8a56b7 25#include "wx/datetime.h"
f517634c 26#include "wx/image.h"
5378558e 27#include "wx/bookctrl.h"
cc8bc5aa 28#include "wx/artprov.h"
2b923807 29#include "wx/imaglist.h"
684883e3 30#include "wx/sysopt.h"
457814b5 31
13188def
WS
32#if wxUSE_COLOURDLG
33 #include "wx/colordlg.h"
34#endif // wxUSE_COLOURDLG
dfad0599 35
13188def
WS
36#if wxUSE_CHOICEDLG
37 #include "wx/choicdlg.h"
38#endif // wxUSE_CHOICEDLG
457814b5 39
13188def
WS
40#if wxUSE_STARTUP_TIPS
41 #include "wx/tipdlg.h"
42#endif // wxUSE_STARTUP_TIPS
d7d17624 43
13188def 44#if wxUSE_PROGRESSDLG
9b16ffef 45#if wxUSE_STOPWATCH && wxUSE_LONGLONG
b20edf8b 46 #include "wx/datetime.h" // wxDateTime
9b16ffef
VZ
47#endif
48
13188def
WS
49 #include "wx/progdlg.h"
50#endif // wxUSE_PROGRESSDLG
51
ca7adbf8
VZ
52#if wxUSE_ABOUTDLG
53 #include "wx/aboutdlg.h"
453c9e3b
VZ
54
55 // these headers are only needed for custom about dialog
56 #include "wx/statline.h"
57 #include "wx/generic/aboutdlgg.h"
ca7adbf8
VZ
58#endif // wxUSE_ABOUTDLG
59
13188def
WS
60#if wxUSE_BUSYINFO
61 #include "wx/busyinfo.h"
62#endif // wxUSE_BUSYINFO
63
64#if wxUSE_NUMBERDLG
65 #include "wx/numdlg.h"
66#endif // wxUSE_NUMBERDLG
67
68#if wxUSE_FILEDLG
69 #include "wx/filedlg.h"
70#endif // wxUSE_FILEDLG
71
72#if wxUSE_DIRDLG
73 #include "wx/dirdlg.h"
74#endif // wxUSE_DIRDLG
75
76#if wxUSE_FONTDLG
77 #include "wx/fontdlg.h"
78#endif // wxUSE_FONTDLG
79
80#if wxUSE_FINDREPLDLG
81 #include "wx/fdrepdlg.h"
82#endif // wxUSE_FINDREPLDLG
4ad3c82f 83
62675ef3 84#if wxUSE_SPINCTRL
0f5d8ecf 85#include "wx/spinctrl.h"
62675ef3
JS
86#endif
87
0f5d8ecf
JS
88#include "wx/propdlg.h"
89
457814b5
JS
90#include "dialogs.h"
91
13188def
WS
92#if USE_COLOURDLG_GENERIC
93 #include "wx/generic/colrdlgg.h"
94#endif // USE_COLOURDLG_GENERIC
95
13188def
WS
96#if USE_DIRDLG_GENERIC
97 #include "wx/generic/dirdlgg.h"
98#endif // USE_DIRDLG_GENERIC
99
695fe764
WS
100#if USE_FILEDLG_GENERIC
101 #include "wx/generic/filedlgg.h"
102#endif // USE_FILEDLG_GENERIC
103
104#if USE_FONTDLG_GENERIC
105 #include "wx/generic/fontdlgg.h"
106#endif // USE_FONTDLG_GENERIC
107
457814b5
JS
108IMPLEMENT_APP(MyApp)
109
4c45f240
VZ
110BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
111 EVT_PAINT(MyCanvas::OnPaint)
112END_EVENT_TABLE()
113
13188def
WS
114
115
4c45f240 116BEGIN_EVENT_TABLE(MyFrame, wxFrame)
13188def
WS
117 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
118
119#if wxUSE_COLOURDLG
4c45f240 120 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
13188def
WS
121#endif // wxUSE_COLOURDLG
122
123#if wxUSE_FONTDLG
4c45f240 124 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
13188def
WS
125#endif // wxUSE_FONTDLG
126
127#if wxUSE_LOG_DIALOG
4c45f240 128 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
13188def
WS
129#endif // wxUSE_LOG_DIALOG
130
131#if wxUSE_TEXTDLG
4c45f240
VZ
132 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
133 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
13188def
WS
134#endif // wxUSE_TEXTDLG
135
136#if wxUSE_NUMBERDLG
4c45f240 137 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
13188def
WS
138#endif // wxUSE_NUMBERDLG
139
140#if wxUSE_CHOICEDLG
4c45f240 141 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
d6c9c1b7 142 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
13188def
WS
143#endif // wxUSE_CHOICEDLG
144
145#if wxUSE_FILEDLG
4c45f240 146 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
35b45b33 147 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
4c45f240
VZ
148 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
149 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
13188def
WS
150#endif // wxUSE_FILEDLG
151
695fe764
WS
152#if USE_FILEDLG_GENERIC
153 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
154 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
155 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
156#endif // USE_FILEDLG_GENERIC
157
13188def 158#if wxUSE_DIRDLG
4c45f240 159 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
f09c8393 160 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
13188def
WS
161#endif // wxUSE_DIRDLG
162
163#if USE_MODAL_PRESENTATION
f6bcfd97 164 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
4c45f240 165 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
cae50e6b
VZ
166 EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen)
167 EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent)
13188def
WS
168#endif // USE_MODAL
169
170#if wxUSE_STARTUP_TIPS
4c45f240 171 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
13188def
WS
172#endif // wxUSE_STARTUP_TIPS
173
174#if USE_FONTDLG_GENERIC
4c45f240 175 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
13188def
WS
176#endif // USE_FONTDLG_GENERIC
177
178#if USE_DIRDLG_GENERIC
179 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
180#endif // wxMSW || wxMAC
181
182#if USE_COLOURDLG_GENERIC
183 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
184#endif // USE_COLOURDLG_GENERIC
a62b0bcc 185
abceee76
VZ
186#if wxUSE_PROGRESSDLG
187 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
761989ff 188#endif // wxUSE_PROGRESSDLG
a62b0bcc 189
ca7adbf8
VZ
190#if wxUSE_ABOUTDLG
191 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
192 EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
453c9e3b
VZ
193 EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog)
194 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog)
ca7adbf8
VZ
195#endif // wxUSE_ABOUTDLG
196
a62b0bcc
VZ
197#if wxUSE_BUSYINFO
198 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
199#endif // wxUSE_BUSYINFO
200
761989ff
VZ
201#if wxUSE_FINDREPLDLG
202 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
203 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
204
13188def
WS
205 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
206 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
207 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
208 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
209 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
761989ff 210#endif // wxUSE_FINDREPLDLG
13188def 211
532d575b 212#if USE_SETTINGS_DIALOG
0f5d8ecf 213 EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
64d3ed17
JS
214 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet)
215 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet)
532d575b
WS
216#endif
217
8e1dac82 218 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
0f5d8ecf 219 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
9b16ffef 220
4c45f240 221 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
4c45f240 222END_EVENT_TABLE()
abceee76 223
13188def 224#if USE_MODAL_PRESENTATION
f6bcfd97 225
13188def
WS
226 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
227 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
228 END_EVENT_TABLE()
5d987909 229
13188def
WS
230 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
231 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
232 EVT_CLOSE(MyModelessDialog::OnClose)
233 END_EVENT_TABLE()
234
235#endif // USE_MODAL_PRESENTATION
abceee76 236
8e1dac82
VZ
237BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
238 EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent)
239 EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
240END_EVENT_TABLE()
241
c67daf87 242MyCanvas *myCanvas = (MyCanvas *) NULL;
457814b5 243
457814b5 244// `Main program' equivalent, creating windows and returning main app frame
4c45f240 245bool MyApp::OnInit()
457814b5 246{
45e6e6f8
VZ
247 if ( !wxApp::OnInit() )
248 return false;
249
f517634c 250#if wxUSE_IMAGE
013e1fee 251 wxInitAllImageHandlers();
f517634c 252#endif
013e1fee 253
19bc1514 254 m_canvasTextColour = *wxBLACK;
13188def 255 m_canvasFont = *wxNORMAL_FONT;
457814b5 256
13188def
WS
257 // Create the main frame window
258 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example"));
457814b5 259
13188def 260 // Make a menubar
ca7adbf8 261 wxMenu *menuDlg = new wxMenu;
dabbc6a5 262
ca7adbf8 263 menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
457814b5 264
457814b5 265
33bcca32 266#if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
f09c8393 267
33bcca32 268 wxMenu *choices_menu = new wxMenu;
f09c8393 269
33bcca32
VZ
270 #if wxUSE_COLOURDLG
271 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
272 #endif // wxUSE_COLOURDLG
f09c8393 273
33bcca32
VZ
274 #if wxUSE_FONTDLG
275 choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
276 #endif // wxUSE_FONTDLG
457814b5 277
33bcca32
VZ
278 #if wxUSE_CHOICEDLG
279 choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
280 choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
281 #endif // wxUSE_CHOICEDLG
695fe764 282
33bcca32
VZ
283 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
284 choices_menu->AppendSeparator();
285 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
695fe764 286
33bcca32
VZ
287 #if USE_COLOURDLG_GENERIC
288 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
289 #endif // USE_COLOURDLG_GENERIC
695fe764 290
33bcca32
VZ
291 #if USE_FONTDLG_GENERIC
292 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
293 #endif // USE_FONTDLG_GENERIC
d93c719a 294
ca7adbf8 295 menuDlg->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu);
33bcca32 296#endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
457814b5 297
457814b5 298
33bcca32 299#if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def 300
33bcca32 301 wxMenu *entry_menu = new wxMenu;
13188def 302
33bcca32
VZ
303 #if wxUSE_TEXTDLG
304 entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
305 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
306 #endif // wxUSE_TEXTDLG
13188def 307
33bcca32
VZ
308 #if wxUSE_NUMBERDLG
309 entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
310 #endif // wxUSE_NUMBERDLG
13188def 311
ca7adbf8 312 menuDlg->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu);
13188def 313
33bcca32 314#endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def
WS
315
316
33bcca32 317#if wxUSE_FILEDLG
13188def 318
33bcca32
VZ
319 wxMenu *filedlg_menu = new wxMenu;
320 filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
321 filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
322 filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
323 filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
695fe764 324
33bcca32
VZ
325 #if USE_FILEDLG_GENERIC
326 filedlg_menu->AppendSeparator();
327 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)"));
328 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)"));
329 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)"));
330 #endif // USE_FILEDLG_GENERIC
695fe764 331
ca7adbf8 332 menuDlg->Append(wxID_ANY,_T("&File operations"),filedlg_menu);
13188def 333
33bcca32 334#endif // wxUSE_FILEDLG
13188def 335
33bcca32
VZ
336#if wxUSE_DIRDLG
337 wxMenu *dir_menu = new wxMenu;
13188def 338
33bcca32
VZ
339 dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
340 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
ca7adbf8 341 menuDlg->Append(wxID_ANY,_T("&Directory operations"),dir_menu);
13188def 342
33bcca32
VZ
343 #if USE_DIRDLG_GENERIC
344 dir_menu->AppendSeparator();
345 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)"));
346 #endif // USE_DIRDLG_GENERIC
13188def 347
33bcca32 348#endif // wxUSE_DIRDLG
13188def
WS
349
350
33bcca32 351#if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
13188def 352
33bcca32 353 wxMenu *info_menu = new wxMenu;
13188def 354
33bcca32
VZ
355 #if wxUSE_STARTUP_TIPS
356 info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
357 #endif // wxUSE_STARTUP_TIPS
13188def 358
33bcca32
VZ
359 #if wxUSE_PROGRESSDLG
360 info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
361 #endif // wxUSE_PROGRESSDLG
13188def 362
33bcca32
VZ
363 #if wxUSE_BUSYINFO
364 info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
365 #endif // wxUSE_BUSYINFO
13188def 366
33bcca32
VZ
367 #if wxUSE_LOG_DIALOG
368 info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
369 #endif // wxUSE_LOG_DIALOG
13188def 370
ca7adbf8 371 menuDlg->Append(wxID_ANY,_T("&Informative dialogs"),info_menu);
13188def 372
33bcca32 373#endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
13188def
WS
374
375
33bcca32
VZ
376#if wxUSE_FINDREPLDLG
377 wxMenu *find_menu = new wxMenu;
378 find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
379 find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
ca7adbf8 380 menuDlg->Append(wxID_ANY,_T("&Searching"),find_menu);
33bcca32 381#endif // wxUSE_FINDREPLDLG
13188def 382
33bcca32 383#if USE_MODAL_PRESENTATION
cae50e6b
VZ
384 wxMenu *dialogs_menu = new wxMenu;
385 dialogs_menu->Append(DIALOGS_MODAL, _T("&Modal dialog\tCtrl-W"));
386 dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Mode&less dialog\tCtrl-Z"));
a8eb5f88
VZ
387 dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, _T("Centered on &screen\tShift-Ctrl-1"));
388 dialogs_menu->Append(DIALOGS_CENTRE_PARENT, _T("Centered on &parent\tShift-Ctrl-2"));
ca7adbf8 389 menuDlg->Append(wxID_ANY, _T("&Generic dialogs"), dialogs_menu);
33bcca32 390#endif // USE_MODAL_PRESENTATION
13188def 391
532d575b 392#if USE_SETTINGS_DIALOG
b40bb73e
VZ
393 wxMenu *sheet_menu = new wxMenu;
394 sheet_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Standard property sheet\tShift-Ctrl-P"));
395 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("&Toolbook sheet\tShift-Ctrl-T"));
e031f1df 396
5c351979 397 if (wxPlatformIs(wxPORT_MAC))
230c9077
JS
398 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
399/*
b887dc7b 400#ifdef __WXMAC__
64d3ed17 401 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, _T("Button &Toolbook sheet\tShift-Ctrl-U"));
b887dc7b 402#endif
230c9077 403*/
ca7adbf8 404 menuDlg->Append(wxID_ANY, _T("&Property sheets"), sheet_menu);
b40bb73e 405#endif // USE_SETTINGS_DIALOG
532d575b 406
8e1dac82
VZ
407 menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog"));
408
ca7adbf8
VZ
409 menuDlg->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R"));
410
411 menuDlg->AppendSeparator();
412 menuDlg->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
9b16ffef 413
ca7adbf8
VZ
414#if wxUSE_ABOUTDLG
415 wxMenu *menuHelp = new wxMenu;
453c9e3b
VZ
416 menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, _T("&About (simple)...\tF1"));
417 menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, _T("About (&fancy)...\tShift-F1"));
418 menuHelp->Append(DIALOGS_ABOUTDLG_FULL, _T("About (f&ull)...\tCtrl-F1"));
419 menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, _T("About (&custom)...\tCtrl-Shift-F1"));
ca7adbf8 420#endif // wxUSE_ABOUTDLG
13188def 421
ca7adbf8
VZ
422 wxMenuBar *menubar = new wxMenuBar;
423 menubar->Append(menuDlg, _T("&Dialogs"));
424#if wxUSE_ABOUTDLG
425 menubar->Append(menuHelp, _T("&Help"));
426#endif // wxUSE_ABOUTDLG
427
428 frame->SetMenuBar(menubar);
13188def
WS
429
430 myCanvas = new MyCanvas(frame);
431 myCanvas->SetBackgroundColour(*wxWHITE);
432
433 frame->Centre(wxBOTH);
434
435 // Show the frame
436 frame->Show(true);
437
438 SetTopWindow(frame);
439
440 return true;
457814b5
JS
441}
442
443// My frame constructor
4c45f240 444MyFrame::MyFrame(wxWindow *parent,
13188def
WS
445 const wxString& title)
446 : wxFrame(parent, wxID_ANY, title)
4c45f240 447{
0f5d8ecf 448 SetIcon(sample_xpm);
532d575b 449
13188def 450#if USE_MODAL_PRESENTATION
4c45f240 451 m_dialog = (MyModelessDialog *)NULL;
13188def 452#endif // USE_MODAL_PRESENTATION
f1e1ed3b 453
043dcdaa 454#if wxUSE_FINDREPLDLG
14fca738
VZ
455 m_dlgFind =
456 m_dlgReplace = NULL;
043dcdaa 457#endif
dabbc6a5
DS
458
459#if wxUSE_COLOURDLG
d33dd9ef
VS
460 m_clrData.SetChooseFull(true);
461 for (int i = 0; i < 16; i++)
462 {
8f6eaec9
WS
463 m_clrData.SetCustomColour(
464 i,
465 wxColour(
466 (unsigned char)(i*16),
467 (unsigned char)(i*16),
468 (unsigned char)(i*16)
469 )
470 );
d33dd9ef 471 }
13188def 472#endif // wxUSE_COLOURDLG
f9d0e439
VZ
473
474#if wxUSE_STATUSBAR
475 CreateStatusBar();
476#endif // wxUSE_STATUSBAR
4c45f240 477}
457814b5 478
13188def 479#if wxUSE_COLOURDLG
d355d3fe 480void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
457814b5 481{
d33dd9ef 482 m_clrData.SetColour(myCanvas->GetBackgroundColour());
d93c719a 483
d33dd9ef 484 wxColourDialog dialog(this, &m_clrData);
9f84eccd 485 dialog.SetTitle(_T("Choose the background colour"));
afbd36dd 486 if (dialog.ShowModal() == wxID_OK)
f6bcfd97 487 {
d33dd9ef
VS
488 m_clrData = dialog.GetColourData();
489 myCanvas->SetBackgroundColour(m_clrData.GetColour());
1d14c005 490 myCanvas->ClearBackground();
457814b5 491 myCanvas->Refresh();
f6bcfd97 492 }
457814b5 493}
13188def 494#endif // wxUSE_COLOURDLG
457814b5 495
1e72e3cc
RN
496#if USE_COLOURDLG_GENERIC
497void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
498{
499 m_clrData.SetColour(myCanvas->GetBackgroundColour());
500
501 //FIXME:TODO:This has no effect...
502 m_clrData.SetChooseFull(true);
503
504 for (int i = 0; i < 16; i++)
505 {
506 wxColour colour(
507 (unsigned char)(i*16),
508 (unsigned char)(i*16),
509 (unsigned char)(i*16)
510 );
511 m_clrData.SetCustomColour(i, colour);
512 }
513
514 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
515 if (dialog->ShowModal() == wxID_OK)
516 {
517 m_clrData = dialog->GetColourData();
518 myCanvas->SetBackgroundColour(m_clrData.GetColour());
519 myCanvas->ClearBackground();
520 myCanvas->Refresh();
521 }
522 dialog->Destroy();
523}
524#endif // USE_COLOURDLG_GENERIC
525
13188def 526#if wxUSE_FONTDLG
d355d3fe 527void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
457814b5 528{
dbc65e27
VZ
529 wxFontData data;
530 data.SetInitialFont(wxGetApp().m_canvasFont);
531 data.SetColour(wxGetApp().m_canvasTextColour);
d93c719a 532
dbc65e27
VZ
533 // you might also do this:
534 //
535 // wxFontDialog dialog;
536 // if ( !dialog.Create(this, data) { ... error ... }
537 //
538 wxFontDialog dialog(this, data);
539
540 if (dialog.ShowModal() == wxID_OK)
541 {
542 wxFontData retData = dialog.GetFontData();
457814b5
JS
543 wxGetApp().m_canvasFont = retData.GetChosenFont();
544 wxGetApp().m_canvasTextColour = retData.GetColour();
545 myCanvas->Refresh();
dbc65e27
VZ
546 }
547 //else: cancelled by the user, don't change the font
457814b5 548}
13188def 549#endif // wxUSE_FONTDLG
457814b5 550
13188def 551#if USE_FONTDLG_GENERIC
d355d3fe 552void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
457814b5 553{
13188def
WS
554 wxFontData data;
555 data.SetInitialFont(wxGetApp().m_canvasFont);
556 data.SetColour(wxGetApp().m_canvasTextColour);
457814b5 557
ca3e85cf 558 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
13188def
WS
559 if (dialog->ShowModal() == wxID_OK)
560 {
457814b5
JS
561 wxFontData retData = dialog->GetFontData();
562 wxGetApp().m_canvasFont = retData.GetChosenFont();
563 wxGetApp().m_canvasTextColour = retData.GetColour();
564 myCanvas->Refresh();
13188def
WS
565 }
566 dialog->Destroy();
457814b5 567}
13188def 568#endif // USE_FONTDLG_GENERIC
d93c719a 569
b4954d19 570#if wxUSE_LOG_DIALOG
87728739 571void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
d93c719a 572{
2c8e4738
VZ
573 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
574 // being flushed -- test it
575 {
576 wxBusyCursor bc;
4693b20c
MB
577 wxLogMessage(wxT("This is some message - everything is ok so far."));
578 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
579 wxLogWarning(wxT("And then something went wrong!"));
9fe52545
VZ
580
581 // and if ~wxBusyCursor doesn't do it, then call it manually
582 wxYield();
2c8e4738
VZ
583 }
584
4693b20c
MB
585 wxLogError(wxT("Intermediary error handler decided to abort."));
586 wxLogError(wxT("The top level caller detected an unrecoverable error."));
5888ef1e 587
7923c649
VZ
588 wxLog::FlushActive();
589
4693b20c 590 wxLogMessage(wxT("And this is the same dialog but with only one message."));
d93c719a 591}
b4954d19 592#endif // wxUSE_LOG_DIALOG
457814b5 593
d355d3fe 594void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
457814b5 595{
2afb9e16
VZ
596 wxMessageDialog dialog(NULL,
597 _T("This is a message box\nA long, long string to test out the message box properly"),
598 _T("Message box text"),
599 wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION);
600
601 if ( dialog.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) )
602 {
603 dialog.SetExtendedMessage(_T("This platform supports custom button labels"));
604 }
605 else
606 {
607 dialog.SetExtendedMessage(_T("Custom button labels are not supported."));
608 }
457814b5 609
13188def
WS
610 switch ( dialog.ShowModal() )
611 {
612 case wxID_YES:
613 wxLogStatus(wxT("You pressed \"Yes\""));
614 break;
49b957be 615
13188def
WS
616 case wxID_NO:
617 wxLogStatus(wxT("You pressed \"No\""));
618 break;
49b957be 619
13188def
WS
620 case wxID_CANCEL:
621 wxLogStatus(wxT("You pressed \"Cancel\""));
622 break;
49b957be 623
13188def
WS
624 default:
625 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
626 }
457814b5
JS
627}
628
13188def 629#if wxUSE_NUMBERDLG
c49245f8
VZ
630void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
631{
78a189c9
VZ
632 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
633 _T("Even two rows of text."),
634 _T("Enter a number:"), _T("Numeric input test"),
e65cc56a 635 50, 0, 100, this );
c49245f8
VZ
636
637 wxString msg;
638 int icon;
639 if ( res == -1 )
640 {
78a189c9 641 msg = _T("Invalid number entered or dialog cancelled.");
c49245f8
VZ
642 icon = wxICON_HAND;
643 }
644 else
d93c719a
VZ
645 {
646 msg.Printf(_T("You've entered %lu"), res );
c49245f8
VZ
647 icon = wxICON_INFORMATION;
648 }
649
78a189c9 650 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
c49245f8 651}
13188def 652#endif // wxUSE_NUMBERDLG
c49245f8 653
13188def 654#if wxUSE_TEXTDLG
a294c6d5 655void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
457814b5 656{
2f1cd905 657 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
78a189c9 658 _T("Password entry dialog"),
dabbc6a5 659 wxEmptyString,
a294c6d5 660 this);
ecda9475 661 if ( !pwd.empty() )
a294c6d5 662 {
4693b20c 663 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
78a189c9 664 _T("Got password"), wxOK | wxICON_INFORMATION, this);
a294c6d5
VZ
665 }
666}
667
668void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
669{
13188def
WS
670 wxTextEntryDialog dialog(this,
671 _T("This is a small sample\n")
672 _T("A long, long string to test out the text entrybox"),
673 _T("Please enter a string"),
674 _T("Default value"),
675 wxOK | wxCANCEL);
457814b5 676
13188def
WS
677 if (dialog.ShowModal() == wxID_OK)
678 {
b4954d19 679 wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
13188def 680 }
457814b5 681}
13188def 682#endif // wxUSE_TEXTDLG
457814b5 683
13188def 684#if wxUSE_CHOICEDLG
d355d3fe 685void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
457814b5 686{
78a189c9 687 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
457814b5 688
5f95bb70 689 wxSingleChoiceDialog dialog(this,
78a189c9
VZ
690 _T("This is a small sample\n")
691 _T("A single-choice convenience dialog"),
692 _T("Please select a value"),
5f95bb70 693 WXSIZEOF(choices), choices);
457814b5 694
ef77f91e
JS
695 dialog.SetSelection(2);
696
697 if (dialog.ShowModal() == wxID_OK)
698 {
78a189c9 699 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
ef77f91e
JS
700 dialog2.ShowModal();
701 }
457814b5
JS
702}
703
d6c9c1b7
VZ
704void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
705{
5f95bb70
VZ
706 const wxString choices[] =
707 {
78a189c9
VZ
708 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
709 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
710 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
5f95bb70 711 };
d6c9c1b7
VZ
712
713 wxArrayInt selections;
714 size_t count = wxGetMultipleChoices(selections,
78a189c9
VZ
715 _T("This is a small sample\n")
716 _T("A multi-choice convenience dialog"),
717 _T("Please select a value"),
5f95bb70 718 WXSIZEOF(choices), choices,
d6c9c1b7
VZ
719 this);
720 if ( count )
721 {
3d49ce44 722 wxString msg;
fba1b53b 723 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
d6c9c1b7
VZ
724 for ( size_t n = 0; n < count; n++ )
725 {
fba1b53b
VZ
726 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
727 (unsigned)n, (unsigned)selections[n],
3d49ce44 728 choices[selections[n]].c_str());
d6c9c1b7 729 }
3d49ce44 730 wxLogMessage(msg);
d6c9c1b7
VZ
731 }
732 //else: cancelled or nothing selected
733}
13188def 734#endif // wxUSE_CHOICEDLG
d6c9c1b7 735
13188def 736#if wxUSE_FILEDLG
d355d3fe 737void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
457814b5 738{
fbf4eacb
VZ
739 wxFileDialog dialog
740 (
741 this,
742 _T("Testing open file dialog"),
dabbc6a5
DS
743 wxEmptyString,
744 wxEmptyString,
a4e64fb5
MB
745#ifdef __WXMOTIF__
746 _T("C++ files (*.cpp)|*.cpp")
747#else
daf32463 748 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
a4e64fb5 749#endif
fbf4eacb 750 );
457814b5 751
3b6c3fc8 752 dialog.CentreOnParent();
cd7afaff 753 dialog.SetDirectory(wxGetHomeDir());
5b636c67 754
c50f1fb9
VZ
755 if (dialog.ShowModal() == wxID_OK)
756 {
5919d76b 757 wxString info;
13393ab6
RR
758 info.Printf(_T("Full file name: %s\n")
759 _T("Path: %s\n")
760 _T("Name: %s"),
5919d76b
VZ
761 dialog.GetPath().c_str(),
762 dialog.GetDirectory().c_str(),
763 dialog.GetFilename().c_str());
78a189c9 764 wxMessageDialog dialog2(this, info, _T("Selected file"));
c50f1fb9
VZ
765 dialog2.ShowModal();
766 }
457814b5
JS
767}
768
35b45b33
VZ
769// this shows how to take advantage of specifying a default extension in the
770// call to wxFileSelector: it is remembered after each new call and the next
771// one will use it by default
772void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
773{
774 static wxString s_extDef;
775 wxString path = wxFileSelector(
776 _T("Select the file to load"),
dabbc6a5 777 wxEmptyString, wxEmptyString,
35b45b33 778 s_extDef,
3601f639
VZ
779 wxString::Format
780 (
781 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
782 wxFileSelectorDefaultWildcardStr,
783 wxFileSelectorDefaultWildcardStr
784 ),
9f057af5 785 wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW,
35b45b33
VZ
786 this
787 );
788
789 if ( !path )
790 return;
791
792 // it is just a sample, would use wxSplitPath in real program
793 s_extDef = path.AfterLast(_T('.'));
794
795 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
a342cb00 796 path, s_extDef);
35b45b33
VZ
797}
798
c61f4f6d
VZ
799void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
800{
dabbc6a5 801 wxString wildcards =
f0f43012
JS
802#ifdef __WXMOTIF__
803 _T("C++ files (*.cpp)|*.cpp");
804#else
3601f639
VZ
805 wxString::Format
806 (
807 _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
808 wxFileSelectorDefaultWildcardStr,
809 wxFileSelectorDefaultWildcardStr
810 );
f0f43012 811#endif
78a189c9 812 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
dabbc6a5 813 wxEmptyString, wxEmptyString, wildcards,
ff3e84ff 814 wxFD_OPEN|wxFD_MULTIPLE);
c61f4f6d
VZ
815
816 if (dialog.ShowModal() == wxID_OK)
817 {
818 wxArrayString paths, filenames;
819
820 dialog.GetPaths(paths);
821 dialog.GetFilenames(filenames);
822
823 wxString msg, s;
824 size_t count = paths.GetCount();
825 for ( size_t n = 0; n < count; n++ )
826 {
827 s.Printf(_T("File %d: %s (%s)\n"),
fba1b53b 828 (int)n, paths[n].c_str(), filenames[n].c_str());
c61f4f6d
VZ
829
830 msg += s;
831 }
f0f43012
JS
832 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
833 msg += s;
c61f4f6d 834
78a189c9 835 wxMessageDialog dialog2(this, msg, _T("Selected files"));
c61f4f6d
VZ
836 dialog2.ShowModal();
837 }
838}
839
d355d3fe 840void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
457814b5 841{
2f1cd905
VZ
842 wxFileDialog dialog(this,
843 _T("Testing save file dialog"),
dabbc6a5 844 wxEmptyString,
2b5f62a0 845 _T("myletter.doc"),
3de9120b 846 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
ff3e84ff 847 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
c50f1fb9 848
2b5f62a0
VZ
849 dialog.SetFilterIndex(1);
850
c50f1fb9
VZ
851 if (dialog.ShowModal() == wxID_OK)
852 {
2b5f62a0
VZ
853 wxLogMessage(_T("%s, filter %d"),
854 dialog.GetPath().c_str(), dialog.GetFilterIndex());
c50f1fb9 855 }
457814b5 856}
13188def 857#endif // wxUSE_FILEDLG
457814b5 858
695fe764
WS
859#if USE_FILEDLG_GENERIC
860void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
861{
862 wxGenericFileDialog dialog
863 (
864 this,
865 _T("Testing open file dialog"),
866 wxEmptyString,
867 wxEmptyString,
daf32463 868 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
695fe764
WS
869 );
870
871 dialog.SetDirectory(wxGetHomeDir());
872
873 if (dialog.ShowModal() == wxID_OK)
874 {
875 wxString info;
876 info.Printf(_T("Full file name: %s\n")
877 _T("Path: %s\n")
878 _T("Name: %s"),
879 dialog.GetPath().c_str(),
880 dialog.GetDirectory().c_str(),
881 dialog.GetFilename().c_str());
882 wxMessageDialog dialog2(this, info, _T("Selected file"));
883 dialog2.ShowModal();
884 }
885}
886
887void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
888{
684883e3
WS
889 // On PocketPC you can disable OK-only dialogs policy using system option
890 int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
891 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
892
daf32463 893 wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
695fe764
WS
894 wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
895 wxEmptyString, wxEmptyString, wildcards,
e031f1df 896 wxFD_MULTIPLE);
695fe764
WS
897
898 if (dialog.ShowModal() == wxID_OK)
899 {
900 wxArrayString paths, filenames;
901
902 dialog.GetPaths(paths);
903 dialog.GetFilenames(filenames);
904
905 wxString msg, s;
906 size_t count = paths.GetCount();
907 for ( size_t n = 0; n < count; n++ )
908 {
909 s.Printf(_T("File %d: %s (%s)\n"),
910 (int)n, paths[n].c_str(), filenames[n].c_str());
911
912 msg += s;
913 }
914 s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
915 msg += s;
916
917 wxMessageDialog dialog2(this, msg, _T("Selected files"));
918 dialog2.ShowModal();
919 }
684883e3
WS
920
921 // restore system option
922 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons);
695fe764
WS
923}
924
925void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
926{
927 wxGenericFileDialog dialog(this,
928 _T("Testing save file dialog"),
929 wxEmptyString,
930 _T("myletter.doc"),
3de9120b 931 _T("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
e031f1df 932 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
695fe764
WS
933
934 dialog.SetFilterIndex(1);
935
936 if (dialog.ShowModal() == wxID_OK)
937 {
938 wxLogMessage(_T("%s, filter %d"),
939 dialog.GetPath().c_str(), dialog.GetFilterIndex());
940 }
941}
942#endif // USE_FILEDLG_GENERIC
943
13188def 944#if wxUSE_DIRDLG
f09c8393 945void MyFrame::DoDirChoose(int style)
457814b5 946{
3f2711d5
VZ
947 // pass some initial dir to wxDirDialog
948 wxString dirHome;
949 wxGetHomeDir(&dirHome);
950
f09c8393 951 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
c50f1fb9
VZ
952
953 if (dialog.ShowModal() == wxID_OK)
954 {
2b5f62a0 955 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
c50f1fb9
VZ
956 }
957}
958
f09c8393
VZ
959void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
960{
ff3e84ff 961 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
f09c8393
VZ
962}
963
964void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
965{
ff3e84ff 966 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST);
f09c8393 967}
13188def 968#endif // wxUSE_DIRDLG
f09c8393 969
13188def 970#if USE_DIRDLG_GENERIC
51a58d8b
JS
971void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
972{
973 // pass some initial dir to wxDirDialog
974 wxString dirHome;
975 wxGetHomeDir(&dirHome);
976
78a189c9 977 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
51a58d8b
JS
978
979 if (dialog.ShowModal() == wxID_OK)
980 {
78a189c9 981 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
51a58d8b
JS
982 dialog2.ShowModal();
983 }
984}
13188def 985#endif // USE_DIRDLG_GENERIC
51a58d8b 986
13188def 987#if USE_MODAL_PRESENTATION
f6bcfd97
BP
988void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
989{
990 MyModalDialog dlg(this);
991 dlg.ShowModal();
992}
993
4c45f240
VZ
994void MyFrame::ModelessDlg(wxCommandEvent& event)
995{
2f82899b 996 bool show = GetMenuBar()->IsChecked(event.GetId());
4c45f240
VZ
997
998 if ( show )
999 {
1000 if ( !m_dialog )
1001 {
1002 m_dialog = new MyModelessDialog(this);
1003 }
1004
13188def 1005 m_dialog->Show(true);
4c45f240
VZ
1006 }
1007 else // hide
1008 {
26a12ab3
JS
1009 // If m_dialog is NULL, then possibly the system
1010 // didn't report the checked menu item status correctly.
1011 // It should be true just after the menu item was selected,
1012 // if there was no modeless dialog yet.
1013
1014 wxASSERT( m_dialog != NULL );
1015 if (m_dialog)
1016 m_dialog->Hide();
4c45f240
VZ
1017 }
1018}
cae50e6b
VZ
1019
1020void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event))
1021{
1022 wxDialog dlg(this, wxID_ANY, _T("Dialog centered on screen"),
1023 wxDefaultPosition, wxSize(200, 100));
cd7afaff 1024 (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre();
cae50e6b
VZ
1025 dlg.CentreOnScreen();
1026 dlg.ShowModal();
1027}
1028
1029void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event))
1030{
1031 wxDialog dlg(this, wxID_ANY, _T("Dialog centered on parent"),
1032 wxDefaultPosition, wxSize(200, 100));
cd7afaff 1033 (new wxButton(&dlg, wxID_OK, _T("Close")))->Centre();
cae50e6b
VZ
1034 dlg.CentreOnParent();
1035 dlg.ShowModal();
1036}
1037
13188def 1038#endif // USE_MODAL_PRESENTATION
4c45f240 1039
13188def 1040#if wxUSE_STARTUP_TIPS
87728739 1041void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
c50f1fb9
VZ
1042{
1043 static size_t s_index = (size_t)-1;
1044
1045 if ( s_index == (size_t)-1 )
1046 {
1047 srand(time(NULL));
1048
1049 // this is completely bogus, we don't know how many lines are there
1050 // in the file, but who cares, it's a demo only...
1051 s_index = rand() % 5;
1052 }
1053
2f1cd905 1054 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
c50f1fb9
VZ
1055
1056 bool showAtStartup = wxShowTip(this, tipProvider);
1057
1058 if ( showAtStartup )
1059 {
2f1cd905 1060 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
c50f1fb9
VZ
1061 wxOK | wxICON_INFORMATION, this);
1062 }
457814b5 1063
c50f1fb9
VZ
1064 s_index = tipProvider->GetCurrentTip();
1065 delete tipProvider;
457814b5 1066}
13188def 1067#endif // wxUSE_STARTUP_TIPS
457814b5 1068
532d575b 1069#if USE_SETTINGS_DIALOG
64d3ed17 1070void MyFrame::OnPropertySheet(wxCommandEvent& event)
0f5d8ecf 1071{
64d3ed17 1072 SettingsDialog dialog(this, event.GetId());
cc8bc5aa
JS
1073 dialog.ShowModal();
1074}
532d575b 1075#endif // USE_SETTINGS_DIALOG
0f5d8ecf 1076
9b16ffef
VZ
1077void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
1078{
1079 wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window"));
1080
1081 wxSleep(3);
1082
1083 RequestUserAttention(wxUSER_ATTENTION_ERROR);
1084}
1085
8e1dac82
VZ
1086void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
1087{
1088 StdButtonSizerDialog dialog(this);
1089 dialog.ShowModal();
1090}
1091
d355d3fe 1092void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
457814b5 1093{
13188def 1094 Close(true);
457814b5
JS
1095}
1096
abceee76
VZ
1097#if wxUSE_PROGRESSDLG
1098
1099void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
1100{
b2c782f2 1101 static const int max = 100;
abceee76 1102
2f1cd905 1103 wxProgressDialog dialog(_T("Progress dialog example"),
78a189c9 1104 _T("An informative message"),
abceee76
VZ
1105 max, // range
1106 this, // parent
1107 wxPD_CAN_ABORT |
ecda9475 1108 wxPD_CAN_SKIP |
abceee76 1109 wxPD_APP_MODAL |
df26c4c6 1110 // wxPD_AUTO_HIDE | -- try this as well
abceee76
VZ
1111 wxPD_ELAPSED_TIME |
1112 wxPD_ESTIMATED_TIME |
f4aa7ec3 1113 wxPD_REMAINING_TIME
b2c782f2 1114 | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
f4aa7ec3 1115 );
abceee76 1116
13188def 1117 bool cont = true;
b2c782f2 1118 for ( int i = 0; i <= max; i++ )
abceee76 1119 {
b2c782f2 1120 wxMilliSleep(200);
ecda9475
WS
1121
1122 wxString msg;
1123
b2c782f2
VZ
1124 // test both modes of wxProgressDialog behaviour: start in
1125 // indeterminate mode but switch to the determinate one later
1126 const bool determinate = i > max/2;
f4aa7ec3 1127
abceee76
VZ
1128 if ( i == max )
1129 {
ecda9475 1130 msg = _T("That's all, folks!");
abceee76 1131 }
b2c782f2 1132 else if ( !determinate )
f4aa7ec3 1133 {
b2c782f2 1134 msg = _T("Testing indeterminate mode");
f4aa7ec3 1135 }
b2c782f2 1136 else if ( determinate )
abceee76 1137 {
b2c782f2 1138 msg = _T("Now in standard determinate mode");
abceee76 1139 }
ecda9475 1140
b2c782f2
VZ
1141 // will be set to true if "Skip" button was pressed
1142 bool skip = false;
1143 if ( determinate )
abceee76 1144 {
ecda9475 1145 cont = dialog.Update(i, msg, &skip);
abceee76 1146 }
f4aa7ec3
VZ
1147 else
1148 {
f4aa7ec3 1149 cont = dialog.Pulse(msg, &skip);
f4aa7ec3 1150 }
ecda9475 1151
b2c782f2
VZ
1152 // each skip will move progress about quarter forward
1153 if ( skip )
1154 i += max/4;
1155
d8ddee9c
VZ
1156 if ( !cont )
1157 {
78a189c9
VZ
1158 if ( wxMessageBox(_T("Do you really want to cancel?"),
1159 _T("Progress dialog question"), // caption
1160 wxYES_NO | wxICON_QUESTION) == wxYES )
d8ddee9c
VZ
1161 break;
1162
9b16ffef 1163 cont = true;
d8ddee9c
VZ
1164 dialog.Resume();
1165 }
abceee76
VZ
1166 }
1167
1168 if ( !cont )
1169 {
4693b20c 1170 wxLogStatus(wxT("Progress dialog aborted!"));
abceee76
VZ
1171 }
1172 else
1173 {
4693b20c 1174 wxLogStatus(wxT("Countdown from %d finished"), max);
abceee76
VZ
1175 }
1176}
1177
1178#endif // wxUSE_PROGRESSDLG
1179
ca7adbf8
VZ
1180#if wxUSE_ABOUTDLG
1181
453c9e3b 1182static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
ca7adbf8
VZ
1183{
1184 info.SetName(_T("Dialogs Sample"));
1a1ecce6 1185 info.SetVersion(wxVERSION_NUM_DOT_STRING_T);
ca7adbf8 1186 info.SetDescription(_T("This sample shows different wxWidgets dialogs"));
730654ee 1187 info.SetCopyright(_T("(C) 1998-2006 wxWidgets dev team"));
50671311 1188 info.AddDeveloper(_T("Vadim Zeitlin"));
ca7adbf8
VZ
1189}
1190
453c9e3b
VZ
1191static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
1192{
1193 InitAboutInfoMinimal(info);
1194
1195 info.SetWebSite(_T("http://www.wxwidgets.org/"), _T("wxWidgets web site"));
1196}
1197
1198static void InitAboutInfoAll(wxAboutDialogInfo& info)
1199{
1200 InitAboutInfoMinimal(info);
1201
1202 // we can add a second developer
1203 info.AddDeveloper(_T("A.N. Other"));
1204
1205 // or we can add several persons at once like this
1206 static const wxChar *docwriters[] =
1207 {
1208 _T("First D. Writer"),
1209 _T("Second One"),
1210 };
1211
1212 info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
1213 info.SetLicence(wxString::FromAscii(
1214" wxWindows Library Licence, Version 3.1\n"
1215" ======================================\n"
1216"\n"
1217" Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1218"\n"
1219" Everyone is permitted to copy and distribute verbatim copies\n"
1220" of this licence document, but changing it is not allowed.\n"
1221"\n"
1222" WXWINDOWS LIBRARY LICENCE\n"
1223" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1224"\n"
1225" ...and so on and so forth...\n"
1226 ));
fb4f85bf
VZ
1227
1228 info.AddTranslator(_T("Wun Ngo Wen (Martian)"));
453c9e3b
VZ
1229}
1230
ca7adbf8
VZ
1231void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
1232{
1233 wxAboutDialogInfo info;
453c9e3b 1234 InitAboutInfoMinimal(info);
ca7adbf8
VZ
1235
1236 wxAboutBox(info);
1237}
1238
1239void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
1240{
1241 wxAboutDialogInfo info;
453c9e3b 1242 InitAboutInfoWebsite(info);
ca7adbf8
VZ
1243
1244 wxAboutBox(info);
1245}
1246
453c9e3b
VZ
1247void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
1248{
1249 wxAboutDialogInfo info;
1250 InitAboutInfoAll(info);
1251
1252 wxAboutBox(info);
1253}
1254
1dcfc333
VZ
1255// a trivial example of a custom dialog class
1256class MyAboutDialog : public wxGenericAboutDialog
453c9e3b 1257{
1dcfc333
VZ
1258public:
1259 MyAboutDialog(const wxAboutDialogInfo& info)
453c9e3b 1260 {
1dcfc333
VZ
1261 Create(info);
1262 }
453c9e3b 1263
1dcfc333
VZ
1264 // add some custom controls
1265 virtual void DoAddCustomControls()
1266 {
1267 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1268 AddText(_T("Some custom text"));
1269 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1270 }
1271};
453c9e3b 1272
1dcfc333
VZ
1273void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
1274{
453c9e3b
VZ
1275 wxAboutDialogInfo info;
1276 InitAboutInfoAll(info);
1277
1278 MyAboutDialog dlg(info);
1279 dlg.ShowModal();
1280}
1281
ca7adbf8
VZ
1282#endif // wxUSE_ABOUTDLG
1283
a62b0bcc
VZ
1284#if wxUSE_BUSYINFO
1285
1286void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1287{
21977bac
VZ
1288 wxWindowDisabler disableAll;
1289
9f84eccd 1290 wxBusyInfo info(_T("Working, please wait..."), this);
a62b0bcc 1291
5b636c67 1292 for ( int i = 0; i < 18; i++ )
a62b0bcc 1293 {
5b636c67 1294 //wxUsleep(100);
a62b0bcc
VZ
1295 wxTheApp->Yield();
1296 }
5b636c67
VZ
1297
1298 wxSleep(2);
1299 //wxWakeUpIdle();
a62b0bcc
VZ
1300}
1301
1302#endif // wxUSE_BUSYINFO
1303
761989ff
VZ
1304#if wxUSE_FINDREPLDLG
1305
1306void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1307{
14fca738
VZ
1308 if ( m_dlgReplace )
1309 {
1310 delete m_dlgReplace;
1311 m_dlgReplace = NULL;
1312 }
1313 else
1314 {
1315 m_dlgReplace = new wxFindReplaceDialog
1316 (
1317 this,
1318 &m_findData,
78a189c9 1319 _T("Find and replace dialog"),
14fca738
VZ
1320 wxFR_REPLACEDIALOG
1321 );
1322
13188def 1323 m_dlgReplace->Show(true);
14fca738 1324 }
761989ff
VZ
1325}
1326
1327void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1328{
14fca738
VZ
1329 if ( m_dlgFind )
1330 {
1331 delete m_dlgFind;
1332 m_dlgFind = NULL;
1333 }
1334 else
1335 {
1336 m_dlgFind = new wxFindReplaceDialog
1337 (
1338 this,
1339 &m_findData,
78a189c9 1340 _T("Find dialog"),
14fca738
VZ
1341 // just for testing
1342 wxFR_NOWHOLEWORD
1343 );
1344
13188def 1345 m_dlgFind->Show(true);
14fca738 1346 }
761989ff
VZ
1347}
1348
1349static wxString DecodeFindDialogEventFlags(int flags)
1350{
1351 wxString str;
78a189c9 1352 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
2f1cd905
VZ
1353 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
1354 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
78a189c9 1355 << _T("case sensitive");
761989ff
VZ
1356
1357 return str;
1358}
1359
1360void MyFrame::OnFindDialog(wxFindDialogEvent& event)
1361{
1362 wxEventType type = event.GetEventType();
1363
1364 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
1365 {
4693b20c 1366 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
eba33006 1367 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
761989ff
VZ
1368 event.GetFindString().c_str(),
1369 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1370 }
1371 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
1372 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
1373 {
4693b20c 1374 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
eba33006 1375 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
761989ff
VZ
1376 event.GetFindString().c_str(),
1377 event.GetReplaceString().c_str(),
1378 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
1379 }
1380 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
1381 {
14fca738
VZ
1382 wxFindReplaceDialog *dlg = event.GetDialog();
1383
df26c4c6 1384 int idMenu;
14fca738
VZ
1385 const wxChar *txt;
1386 if ( dlg == m_dlgFind )
1387 {
1388 txt = _T("Find");
df26c4c6 1389 idMenu = DIALOGS_FIND;
14fca738
VZ
1390 m_dlgFind = NULL;
1391 }
1392 else if ( dlg == m_dlgReplace )
1393 {
1394 txt = _T("Replace");
df26c4c6 1395 idMenu = DIALOGS_REPLACE;
14fca738
VZ
1396 m_dlgReplace = NULL;
1397 }
1398 else
1399 {
1400 txt = _T("Unknown");
13188def 1401 idMenu = wxID_ANY;
14fca738 1402
2f1cd905 1403 wxFAIL_MSG( _T("unexpected event") );
14fca738
VZ
1404 }
1405
df26c4c6
VZ
1406 wxLogMessage(wxT("%s dialog is being closed."), txt);
1407
13188def 1408 if ( idMenu != wxID_ANY )
df26c4c6 1409 {
13188def 1410 GetMenuBar()->Check(idMenu, false);
df26c4c6 1411 }
761989ff 1412
14fca738 1413 dlg->Destroy();
761989ff
VZ
1414 }
1415 else
1416 {
4693b20c 1417 wxLogError(wxT("Unknown find dialog event!"));
761989ff
VZ
1418 }
1419}
1420
1421#endif // wxUSE_FINDREPLDLG
1422
abceee76
VZ
1423// ----------------------------------------------------------------------------
1424// MyCanvas
1425// ----------------------------------------------------------------------------
1426
d355d3fe 1427void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
457814b5 1428{
c50f1fb9 1429 wxPaintDC dc(this);
457814b5
JS
1430 dc.SetFont(wxGetApp().m_canvasFont);
1431 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
1432 dc.SetBackgroundMode(wxTRANSPARENT);
dc96b1b6
WS
1433 dc.DrawText(
1434 _T("wxWidgets common dialogs")
1435#if !defined(__SMARTPHONE__)
1436 _T(" test application")
1437#endif
1438 , 10, 10);
457814b5
JS
1439}
1440
b4954d19
WS
1441#if USE_MODAL_PRESENTATION
1442
4c45f240
VZ
1443// ----------------------------------------------------------------------------
1444// MyModelessDialog
1445// ----------------------------------------------------------------------------
457814b5 1446
4c45f240 1447MyModelessDialog::MyModelessDialog(wxWindow *parent)
13188def 1448 : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog")))
4c45f240 1449{
cbc66a27
VZ
1450 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
1451
78a189c9 1452 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
13188def 1453 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled"));
cbc66a27
VZ
1454 check->Disable();
1455
1456 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
1457 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
1458
cbc66a27
VZ
1459 SetSizer(sizerTop);
1460
1461 sizerTop->SetSizeHints(this);
1462 sizerTop->Fit(this);
4c45f240 1463}
abceee76 1464
5d987909
VZ
1465void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
1466{
2f1cd905 1467 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
5d987909
VZ
1468 wxOK | wxICON_INFORMATION, this);
1469}
1470
abceee76
VZ
1471void MyModelessDialog::OnClose(wxCloseEvent& event)
1472{
1473 if ( event.CanVeto() )
1474 {
2f1cd905 1475 wxMessageBox(_T("Use the menu item to close this dialog"),
78a189c9 1476 _T("Modeless dialog"),
abceee76
VZ
1477 wxOK | wxICON_INFORMATION, this);
1478
1479 event.Veto();
1480 }
1481}
1482
f6bcfd97
BP
1483// ----------------------------------------------------------------------------
1484// MyModalDialog
1485// ----------------------------------------------------------------------------
1486
1487MyModalDialog::MyModalDialog(wxWindow *parent)
13188def 1488 : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog")))
f6bcfd97
BP
1489{
1490 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1491
13188def
WS
1492 m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog..."));
1493 m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog"));
1494 m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button"));
5315ebfa 1495
78a189c9 1496 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
5315ebfa
VZ
1497 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
1498 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 1499 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
9b70bb91 1500 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 1501
f6bcfd97
BP
1502 SetSizer(sizerTop);
1503
1504 sizerTop->SetSizeHints(this);
1505 sizerTop->Fit(this);
1506
5315ebfa
VZ
1507 m_btnModal->SetFocus();
1508 m_btnModal->SetDefault();
f6bcfd97
BP
1509}
1510
1511void MyModalDialog::OnButton(wxCommandEvent& event)
1512{
1513 if ( event.GetEventObject() == m_btnDelete )
1514 {
5315ebfa
VZ
1515 delete m_btnModal;
1516 m_btnModal = NULL;
f6bcfd97
BP
1517
1518 m_btnDelete->Disable();
1519 }
5315ebfa 1520 else if ( event.GetEventObject() == m_btnModal )
f6bcfd97 1521 {
13188def 1522#if wxUSE_TEXTDLG
78a189c9
VZ
1523 wxGetTextFromUser(_T("Dummy prompt"),
1524 _T("Modal dialog called from dialog"),
dabbc6a5 1525 wxEmptyString, this);
13188def
WS
1526#else
1527 wxMessageBox(_T("Modal dialog called from dialog"));
1528#endif // wxUSE_TEXTDLG
f6bcfd97 1529 }
5315ebfa
VZ
1530 else if ( event.GetEventObject() == m_btnModeless )
1531 {
1532 (new MyModelessDialog(this))->Show();
1533 }
f6bcfd97
BP
1534 else
1535 {
1536 event.Skip();
1537 }
1538}
b4954d19
WS
1539
1540#endif // USE_MODAL_PRESENTATION
1541
8e1dac82
VZ
1542// ----------------------------------------------------------------------------
1543// StdButtonSizerDialog
1544// ----------------------------------------------------------------------------
1545
1546StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
1547 : wxDialog(parent, wxID_ANY, wxString(_T("StdButtonSizer dialog")),
1548 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
1549 m_buttonsSizer(NULL)
1550{
1551 wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
1552
1553 wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
1554 wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
1555
1556 m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button"));
1557
1558 wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button"));
1559
1560 m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
1561 m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes"));
1562
1563 wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
1564
1565 m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button"));
1566
1567 wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button"));
1568
1569 m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
1570 m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close"));
1571
1572 wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
1573
1574 m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No"));
1575 m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help"));
1576 m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply"));
1577
1578 m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default"));
1579
1580 sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
1581 sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
1582
1583 sizer->Add(sizerInside1, 0, 0, 0);
1584 sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
1585 sizerInside1->Add(sizer1, 0, wxALL, 5);
1586 sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1587
1588 sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
1589 sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
1590
1591 sizer->Add(sizerInside2, 0, 0, 0);
1592 sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
1593 sizerInside2->Add(sizer2, 0, wxALL, 5);
1594 sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
1595
1596 sizerTop->Add(sizer, 0, wxALL, 5);
1597
1598 sizer3->Add(m_chkboxNo, 0, wxALL, 5);
1599 sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
1600 sizer3->Add(m_chkboxApply, 0, wxALL, 5);
1601
1602 sizerTop->Add(sizer3, 0, wxALL, 5);
1603
1604 sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
1605
1606 EnableDisableControls();
1607
1608 SetSizer(sizerTop);
1609
1610 sizerTop->SetSizeHints(this);
1611 wxCommandEvent ev;
1612 OnEvent(ev);
1613}
1614
1615void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
1616{
1617 if (m_buttonsSizer)
1618 {
1619 m_buttonsSizer->DeleteWindows();
1620 GetSizer()->Remove(m_buttonsSizer);
1621 }
1622
1623 EnableDisableControls();
1624
1625 long flags = 0;
1626 unsigned long numButtons = 0;
1627
1628 if (m_chkboxAffirmativeButton->IsChecked())
1629 {
1630 if (m_radiobtnOk->GetValue())
1631 {
1632 flags |= wxOK;
1633 numButtons ++;
1634 }
1635 else if (m_radiobtnYes->GetValue())
1636 {
1637 flags |= wxYES;
1638 numButtons ++;
1639 }
1640 }
1641
1642 if (m_chkboxDismissButton->IsChecked())
1643 {
1644 if (m_radiobtnCancel->GetValue())
1645 {
1646 flags |= wxCANCEL;
1647 numButtons ++;
1648 }
1649
1650 else if (m_radiobtnClose->GetValue())
1651 {
1652 flags |= wxCLOSE;
1653 numButtons ++;
1654 }
1655
1656 }
1657
1658 if (m_chkboxApply->IsChecked())
1659 {
1660 flags |= wxAPPLY;
1661 numButtons ++;
1662 }
1663
1664 if (m_chkboxNo->IsChecked())
1665 {
1666 flags |= wxNO;
1667 numButtons ++;
1668 }
1669
1670 if (m_chkboxHelp->IsChecked())
1671 {
1672 flags |= wxHELP;
1673 numButtons ++;
1674 }
1675
1676 if (m_chkboxNoDefault->IsChecked())
1677 {
1678 flags |= wxNO_DEFAULT;
1679 }
1680
1681 m_buttonsSizer = CreateStdDialogButtonSizer(flags);
1682 GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
1683
1684 Layout();
1685 GetSizer()->SetSizeHints(this);
1686}
1687
1688void StdButtonSizerDialog::EnableDisableControls()
1689{
1690 const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
1691
1692 m_radiobtnOk->Enable(affButtonEnabled);
1693 m_radiobtnYes->Enable(affButtonEnabled);
1694
1695 const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
1696
1697 m_radiobtnCancel->Enable(dismissButtonEnabled);
1698 m_radiobtnClose->Enable(dismissButtonEnabled);
1699}
1700
532d575b 1701#if USE_SETTINGS_DIALOG
0f5d8ecf
JS
1702// ----------------------------------------------------------------------------
1703// SettingsDialog
1704// ----------------------------------------------------------------------------
1705
1706IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
1707
1708BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
1709END_EVENT_TABLE()
1710
64d3ed17 1711SettingsDialog::SettingsDialog(wxWindow* win, int dialogType)
0f5d8ecf 1712{
0f4991f4 1713 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
0f5d8ecf 1714
cc8bc5aa
JS
1715 int tabImage1 = -1;
1716 int tabImage2 = -1;
e031f1df 1717
64d3ed17 1718 bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
77631b1d 1719 int resizeBorder = wxRESIZE_BORDER;
684883e3 1720
cc8bc5aa
JS
1721 if (useToolBook)
1722 {
77631b1d 1723 resizeBorder = 0;
cc8bc5aa
JS
1724 tabImage1 = 0;
1725 tabImage2 = 1;
e031f1df 1726
64d3ed17
JS
1727 int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
1728 if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
1729 sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
1730 else
1731 sheetStyle |= wxPROPSHEET_TOOLBOOK;
e031f1df 1732
64d3ed17 1733 SetSheetStyle(sheetStyle);
77631b1d
JS
1734 SetSheetInnerBorder(0);
1735 SetSheetOuterBorder(0);
cc8bc5aa
JS
1736
1737 // create a dummy image list with a few icons
1738 const wxSize imageSize(32, 32);
1739
1740 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
1741 m_imageList->
1742 Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
1743 m_imageList->
1744 Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
1745 m_imageList->
1746 Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
1747 m_imageList->
1748 Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
1749 }
1750 else
1751 m_imageList = NULL;
1752
532d575b 1753 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
654ffe9f 1754 wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder)
3103e8a9 1755 );
cc8bc5aa 1756
684883e3 1757 // If using a toolbook, also follow Mac style and don't create buttons
cc8bc5aa 1758 if (!useToolBook)
654ffe9f
VZ
1759 CreateButtons(wxOK | wxCANCEL |
1760 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP)
897b24cf 1761 );
0f5d8ecf
JS
1762
1763 wxBookCtrlBase* notebook = GetBookCtrl();
cc8bc5aa 1764 notebook->SetImageList(m_imageList);
0f5d8ecf
JS
1765
1766 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
1767 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
1768
cc8bc5aa
JS
1769 notebook->AddPage(generalSettings, _("General"), true, tabImage1);
1770 notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
0f5d8ecf
JS
1771
1772 LayoutDialog();
1773}
1774
cc8bc5aa
JS
1775SettingsDialog::~SettingsDialog()
1776{
1777 delete m_imageList;
1778}
1779
0f5d8ecf
JS
1780wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
1781{
1782 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1783
1784 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1785 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1786
1787 //// LOAD LAST FILE
1788
1789 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
1790 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
1791 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1792 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
1793
1794 //// AUTOSAVE
1795
1796 wxString autoSaveLabel = _("&Auto-save every");
1797 wxString minsLabel = _("mins");
1798
1799 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
1800 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
62675ef3
JS
1801
1802#if wxUSE_SPINCTRL
0f5d8ecf 1803 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
532d575b 1804 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
62675ef3 1805#endif
532d575b 1806
0f5d8ecf 1807 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 1808#if wxUSE_SPINCTRL
0f5d8ecf 1809 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 1810#endif
0f5d8ecf
JS
1811 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1812 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
1813
1814 //// TOOLTIPS
532d575b 1815
0f5d8ecf
JS
1816 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
1817 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
1818 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1819 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
1820
1821 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
1822
1823 panel->SetSizer(topSizer);
1824 topSizer->Fit(panel);
532d575b 1825
0f5d8ecf
JS
1826 return panel;
1827}
1828
1829wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
1830{
1831 wxPanel* panel = new wxPanel(parent, wxID_ANY);
1832
1833 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
1834 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
1835
1836 //// PROJECT OR GLOBAL
1837 wxString globalOrProjectChoices[2];
1838 globalOrProjectChoices[0] = _("&New projects");
1839 globalOrProjectChoices[1] = _("&This project");
1840
1841 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
1842 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
1843 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
1844
1845 projectOrGlobal->SetSelection(0);
1846
1847 //// BACKGROUND STYLE
1848 wxArrayString backgroundStyleChoices;
1849 backgroundStyleChoices.Add(wxT("Colour"));
1850 backgroundStyleChoices.Add(wxT("Image"));
532d575b 1851 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
0f5d8ecf
JS
1852
1853 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
1854 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
1855
1856 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
1857
1858 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
1859
1860 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1861 itemSizer2->Add(5, 5, 1, wxALL, 0);
1862 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
1863
1864 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
1865
62675ef3 1866#if wxUSE_SPINCTRL
0f5d8ecf
JS
1867 //// FONT SIZE SELECTION
1868
532d575b 1869 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
0f5d8ecf
JS
1870 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
1871
1872 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
532d575b 1873 wxSize(80, wxDefaultCoord));
0f5d8ecf
JS
1874 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
1875
1876 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
62675ef3 1877#endif
0f5d8ecf
JS
1878
1879 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
0f4991f4 1880 topSizer->AddSpacer(5);
0f5d8ecf
JS
1881
1882 panel->SetSizer(topSizer);
1883 topSizer->Fit(panel);
532d575b 1884
0f5d8ecf
JS
1885 return panel;
1886}
1887
532d575b 1888#endif // USE_SETTINGS_DIALOG