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