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