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