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