]> git.saurik.com Git - wxWidgets.git/blame - samples/dialogs/dialogs.cpp
Only use native wxHyperlinkCtrl in Unicode build under MSW.
[wxWidgets.git] / samples / dialogs / dialogs.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialogs.cpp
3// Purpose: Common dialogs demo
5b05ce47 4// Author: Julian Smart, Vadim Zeitlin, ABX
457814b5
JS
5// Created: 04/01/98
6// RCS-ID: $Id$
6aa89a22 7// Copyright: (c) Julian Smart
5b05ce47
VZ
8// (c) 2004 ABX
9// (c) Vadim Zeitlin
526954c5 10// Licence: wxWindows licence
457814b5
JS
11/////////////////////////////////////////////////////////////////////////////
12
457814b5
JS
13// For compilers that support precompilation, includes "wx/wx.h".
14#include "wx/wxprec.h"
15
16#ifdef __BORLANDC__
17#pragma hdrstop
18#endif
19
20#ifndef WX_PRECOMP
21#include "wx/wx.h"
22#endif
23
0f5d8ecf
JS
24#include "../sample.xpm"
25
9ad2fe62 26#include "wx/apptrait.h"
fb8a56b7 27#include "wx/datetime.h"
f517634c 28#include "wx/image.h"
5378558e 29#include "wx/bookctrl.h"
cc8bc5aa 30#include "wx/artprov.h"
2b923807 31#include "wx/imaglist.h"
1baa0a9d 32#include "wx/minifram.h"
684883e3 33#include "wx/sysopt.h"
e36a1739 34#include "wx/notifmsg.h"
457814b5 35
a1bdd4ab
VZ
36#if wxUSE_RICHMSGDLG
37 #include "wx/richmsgdlg.h"
38#endif // wxUSE_RICHMSGDLG
39
13188def
WS
40#if wxUSE_COLOURDLG
41 #include "wx/colordlg.h"
42#endif // wxUSE_COLOURDLG
dfad0599 43
13188def
WS
44#if wxUSE_CHOICEDLG
45 #include "wx/choicdlg.h"
46#endif // wxUSE_CHOICEDLG
457814b5 47
5a5f305a
VZ
48#include "wx/rearrangectrl.h"
49
13188def
WS
50#if wxUSE_STARTUP_TIPS
51 #include "wx/tipdlg.h"
52#endif // wxUSE_STARTUP_TIPS
d7d17624 53
13188def 54#if wxUSE_PROGRESSDLG
9b16ffef 55#if wxUSE_STOPWATCH && wxUSE_LONGLONG
b20edf8b 56 #include "wx/datetime.h" // wxDateTime
9b16ffef
VZ
57#endif
58
13188def
WS
59 #include "wx/progdlg.h"
60#endif // wxUSE_PROGRESSDLG
61
ca7adbf8
VZ
62#if wxUSE_ABOUTDLG
63 #include "wx/aboutdlg.h"
453c9e3b
VZ
64
65 // these headers are only needed for custom about dialog
66 #include "wx/statline.h"
67 #include "wx/generic/aboutdlgg.h"
ca7adbf8
VZ
68#endif // wxUSE_ABOUTDLG
69
13188def
WS
70#if wxUSE_BUSYINFO
71 #include "wx/busyinfo.h"
72#endif // wxUSE_BUSYINFO
73
74#if wxUSE_NUMBERDLG
75 #include "wx/numdlg.h"
76#endif // wxUSE_NUMBERDLG
77
78#if wxUSE_FILEDLG
79 #include "wx/filedlg.h"
80#endif // wxUSE_FILEDLG
81
82#if wxUSE_DIRDLG
83 #include "wx/dirdlg.h"
84#endif // wxUSE_DIRDLG
85
86#if wxUSE_FONTDLG
87 #include "wx/fontdlg.h"
88#endif // wxUSE_FONTDLG
89
90#if wxUSE_FINDREPLDLG
91 #include "wx/fdrepdlg.h"
92#endif // wxUSE_FINDREPLDLG
4ad3c82f 93
a92b5dfe
VZ
94#if wxUSE_INFOBAR
95 #include "wx/infobar.h"
96#endif // wxUSE_INFOBAR
97
0f5d8ecf
JS
98#include "wx/spinctrl.h"
99#include "wx/propdlg.h"
100
457814b5
JS
101#include "dialogs.h"
102
13188def
WS
103#if USE_COLOURDLG_GENERIC
104 #include "wx/generic/colrdlgg.h"
105#endif // USE_COLOURDLG_GENERIC
106
13188def
WS
107#if USE_DIRDLG_GENERIC
108 #include "wx/generic/dirdlgg.h"
109#endif // USE_DIRDLG_GENERIC
110
695fe764
WS
111#if USE_FILEDLG_GENERIC
112 #include "wx/generic/filedlgg.h"
113#endif // USE_FILEDLG_GENERIC
114
115#if USE_FONTDLG_GENERIC
116 #include "wx/generic/fontdlgg.h"
117#endif // USE_FONTDLG_GENERIC
118
457814b5
JS
119IMPLEMENT_APP(MyApp)
120
4c45f240
VZ
121BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
122 EVT_PAINT(MyCanvas::OnPaint)
123END_EVENT_TABLE()
124
13188def
WS
125
126
4c45f240 127BEGIN_EVENT_TABLE(MyFrame, wxFrame)
8cf304f8 128#if wxUSE_MSGDLG
13188def 129 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
86c3808c 130 EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, MyFrame::MessageBoxWindowModal)
44b25eac 131 EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog)
8cf304f8
VZ
132 EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo)
133#endif // wxUSE_MSGDLG
a1bdd4ab
VZ
134#if wxUSE_RICHMSGDLG
135 EVT_MENU(DIALOGS_RICH_MESSAGE_DIALOG, MyFrame::RichMessageDialog)
136#endif // wxUSE_RICHMSGDLG
13188def 137#if wxUSE_COLOURDLG
4c45f240 138 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
e6ef9ea4 139 EVT_MENU(DIALOGS_GET_COLOUR, MyFrame::GetColour)
13188def
WS
140#endif // wxUSE_COLOURDLG
141
142#if wxUSE_FONTDLG
4c45f240 143 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
13188def
WS
144#endif // wxUSE_FONTDLG
145
146#if wxUSE_LOG_DIALOG
4c45f240 147 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
13188def 148#endif // wxUSE_LOG_DIALOG
a92b5dfe
VZ
149#if wxUSE_INFOBAR
150 EVT_MENU(DIALOGS_INFOBAR_SIMPLE, MyFrame::InfoBarSimple)
151 EVT_MENU(DIALOGS_INFOBAR_ADVANCED, MyFrame::InfoBarAdvanced)
152#endif // wxUSE_INFOBAR
13188def
WS
153
154#if wxUSE_TEXTDLG
4c45f240
VZ
155 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
156 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
13188def
WS
157#endif // wxUSE_TEXTDLG
158
159#if wxUSE_NUMBERDLG
4c45f240 160 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
13188def
WS
161#endif // wxUSE_NUMBERDLG
162
163#if wxUSE_CHOICEDLG
4c45f240 164 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
d6c9c1b7 165 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
13188def
WS
166#endif // wxUSE_CHOICEDLG
167
81496fea 168#if wxUSE_REARRANGECTRL
5a5f305a 169 EVT_MENU(DIALOGS_REARRANGE, MyFrame::Rearrange)
81496fea 170#endif // wxUSE_REARRANGECTRL
5a5f305a 171
13188def 172#if wxUSE_FILEDLG
4c45f240 173 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
35b45b33 174 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
4c45f240
VZ
175 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
176 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
13188def
WS
177#endif // wxUSE_FILEDLG
178
695fe764
WS
179#if USE_FILEDLG_GENERIC
180 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric)
181 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric)
182 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric)
183#endif // USE_FILEDLG_GENERIC
184
13188def 185#if wxUSE_DIRDLG
4c45f240 186 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
f09c8393 187 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
13188def
WS
188#endif // wxUSE_DIRDLG
189
190#if USE_MODAL_PRESENTATION
f6bcfd97 191 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
1baa0a9d 192#endif // USE_MODAL_PRESENTATION
4c45f240 193 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
cae50e6b
VZ
194 EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen)
195 EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent)
81496fea 196#if wxUSE_MINIFRAME
1baa0a9d 197 EVT_MENU(DIALOGS_MINIFRAME, MyFrame::MiniFrame)
81496fea 198#endif // wxUSE_MINIFRAME
8e5dbcdd 199 EVT_MENU(DIALOGS_ONTOP, MyFrame::DlgOnTop)
13188def
WS
200
201#if wxUSE_STARTUP_TIPS
4c45f240 202 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
13188def
WS
203#endif // wxUSE_STARTUP_TIPS
204
205#if USE_FONTDLG_GENERIC
4c45f240 206 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
13188def
WS
207#endif // USE_FONTDLG_GENERIC
208
209#if USE_DIRDLG_GENERIC
210 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
211#endif // wxMSW || wxMAC
212
213#if USE_COLOURDLG_GENERIC
214 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
215#endif // USE_COLOURDLG_GENERIC
a62b0bcc 216
abceee76
VZ
217#if wxUSE_PROGRESSDLG
218 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
761989ff 219#endif // wxUSE_PROGRESSDLG
a62b0bcc 220
ca7adbf8
VZ
221#if wxUSE_ABOUTDLG
222 EVT_MENU(DIALOGS_ABOUTDLG_SIMPLE, MyFrame::ShowSimpleAboutDialog)
223 EVT_MENU(DIALOGS_ABOUTDLG_FANCY, MyFrame::ShowFancyAboutDialog)
453c9e3b
VZ
224 EVT_MENU(DIALOGS_ABOUTDLG_FULL, MyFrame::ShowFullAboutDialog)
225 EVT_MENU(DIALOGS_ABOUTDLG_CUSTOM, MyFrame::ShowCustomAboutDialog)
ca7adbf8
VZ
226#endif // wxUSE_ABOUTDLG
227
a62b0bcc
VZ
228#if wxUSE_BUSYINFO
229 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
230#endif // wxUSE_BUSYINFO
231
761989ff
VZ
232#if wxUSE_FINDREPLDLG
233 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
234 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
235
13188def
WS
236 EVT_FIND(wxID_ANY, MyFrame::OnFindDialog)
237 EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog)
238 EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog)
239 EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog)
240 EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog)
761989ff 241#endif // wxUSE_FINDREPLDLG
13188def 242
532d575b 243#if USE_SETTINGS_DIALOG
0f5d8ecf 244 EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet)
64d3ed17
JS
245 EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheet)
246 EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet)
e36a1739 247#endif // USE_SETTINGS_DIALOG
532d575b 248
8e1dac82 249 EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog)
a625c5b6 250 EVT_MENU(DIALOGS_TEST_DEFAULT_ACTION, MyFrame::OnTestDefaultActionDialog)
e36a1739 251
0f5d8ecf 252 EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention)
e36a1739
VZ
253#if wxUSE_NOTIFICATION_MESSAGE
254 EVT_MENU(DIALOGS_NOTIFY_AUTO, MyFrame::OnNotifMsgAuto)
255 EVT_MENU(DIALOGS_NOTIFY_SHOW, MyFrame::OnNotifMsgShow)
256 EVT_MENU(DIALOGS_NOTIFY_HIDE, MyFrame::OnNotifMsgHide)
257#endif // wxUSE_NOTIFICATION_MESSAGE
9b16ffef 258
4c45f240 259 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
4c45f240 260END_EVENT_TABLE()
abceee76 261
13188def 262#if USE_MODAL_PRESENTATION
f6bcfd97 263
13188def
WS
264 BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
265 EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton)
266 END_EVENT_TABLE()
5d987909 267
13188def
WS
268 BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
269 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
270 EVT_CLOSE(MyModelessDialog::OnClose)
271 END_EVENT_TABLE()
272
273#endif // USE_MODAL_PRESENTATION
abceee76 274
8e1dac82
VZ
275BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog)
276 EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent)
277 EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent)
278END_EVENT_TABLE()
279
457814b5 280// `Main program' equivalent, creating windows and returning main app frame
4c45f240 281bool MyApp::OnInit()
457814b5 282{
45e6e6f8
VZ
283 if ( !wxApp::OnInit() )
284 return false;
285
f517634c 286#if wxUSE_IMAGE
013e1fee 287 wxInitAllImageHandlers();
f517634c 288#endif
013e1fee 289
13188def 290 // Create the main frame window
5b05ce47 291 MyFrame *frame = new MyFrame(wxT("wxWidgets dialogs example"));
457814b5 292
13188def 293 // Make a menubar
ca7adbf8 294 wxMenu *menuDlg = new wxMenu;
dabbc6a5 295
9a83f860 296 menuDlg->Append(DIALOGS_MESSAGE_BOX, wxT("&Message box\tCtrl-M"));
86c3808c 297 menuDlg->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, wxT("Window-Modal Message box "));
9a83f860 298 menuDlg->Append(DIALOGS_MESSAGE_DIALOG, wxT("Message dialog\tShift-Ctrl-M"));
a1bdd4ab
VZ
299#if wxUSE_RICHMSGDLG
300 menuDlg->Append(DIALOGS_RICH_MESSAGE_DIALOG, wxT("Rich message dialog"));
301#endif // wxUSE_RICHMSGDLG
457814b5 302
457814b5 303
33bcca32 304#if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
f09c8393 305
33bcca32 306 wxMenu *choices_menu = new wxMenu;
f09c8393 307
33bcca32 308 #if wxUSE_COLOURDLG
9a83f860
VZ
309 choices_menu->Append(DIALOGS_CHOOSE_COLOUR, wxT("&Choose bg colour"));
310 choices_menu->Append(DIALOGS_GET_COLOUR, wxT("&Choose fg colour"));
33bcca32 311 #endif // wxUSE_COLOURDLG
f09c8393 312
33bcca32 313 #if wxUSE_FONTDLG
9a83f860 314 choices_menu->Append(DIALOGS_CHOOSE_FONT, wxT("Choose &font"));
33bcca32 315 #endif // wxUSE_FONTDLG
457814b5 316
33bcca32 317 #if wxUSE_CHOICEDLG
9a83f860
VZ
318 choices_menu->Append(DIALOGS_SINGLE_CHOICE, wxT("&Single choice\tCtrl-C"));
319 choices_menu->Append(DIALOGS_MULTI_CHOICE, wxT("M&ultiple choice\tCtrl-U"));
33bcca32 320 #endif // wxUSE_CHOICEDLG
695fe764 321
81496fea 322 #if wxUSE_REARRANGECTRL
9a83f860 323 choices_menu->Append(DIALOGS_REARRANGE, wxT("&Rearrange dialog\tCtrl-R"));
81496fea 324 #endif // wxUSE_REARRANGECTRL
5a5f305a 325
33bcca32
VZ
326 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
327 choices_menu->AppendSeparator();
328 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
695fe764 329
33bcca32 330 #if USE_COLOURDLG_GENERIC
9a83f860 331 choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, wxT("&Choose colour (generic)"));
33bcca32 332 #endif // USE_COLOURDLG_GENERIC
695fe764 333
33bcca32 334 #if USE_FONTDLG_GENERIC
9a83f860 335 choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, wxT("Choose &font (generic)"));
33bcca32 336 #endif // USE_FONTDLG_GENERIC
d93c719a 337
9a83f860 338 menuDlg->Append(wxID_ANY,wxT("&Choices and selectors"),choices_menu);
33bcca32 339#endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
457814b5 340
457814b5 341
33bcca32 342#if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def 343
33bcca32 344 wxMenu *entry_menu = new wxMenu;
13188def 345
33bcca32 346 #if wxUSE_TEXTDLG
9a83f860
VZ
347 entry_menu->Append(DIALOGS_TEXT_ENTRY, wxT("Text &entry\tCtrl-E"));
348 entry_menu->Append(DIALOGS_PASSWORD_ENTRY, wxT("&Password entry\tCtrl-P"));
33bcca32 349 #endif // wxUSE_TEXTDLG
13188def 350
33bcca32 351 #if wxUSE_NUMBERDLG
9a83f860 352 entry_menu->Append(DIALOGS_NUM_ENTRY, wxT("&Numeric entry\tCtrl-N"));
33bcca32 353 #endif // wxUSE_NUMBERDLG
13188def 354
9a83f860 355 menuDlg->Append(wxID_ANY,wxT("&Entry dialogs"),entry_menu);
13188def 356
33bcca32 357#endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
13188def
WS
358
359
33bcca32 360#if wxUSE_FILEDLG
13188def 361
33bcca32 362 wxMenu *filedlg_menu = new wxMenu;
9a83f860
VZ
363 filedlg_menu->Append(DIALOGS_FILE_OPEN, wxT("&Open file\tCtrl-O"));
364 filedlg_menu->Append(DIALOGS_FILE_OPEN2, wxT("&Second open file\tCtrl-2"));
365 filedlg_menu->Append(DIALOGS_FILES_OPEN, wxT("Open &files\tCtrl-Q"));
366 filedlg_menu->Append(DIALOGS_FILE_SAVE, wxT("Sa&ve file\tCtrl-S"));
695fe764 367
8ce68f7f
VZ
368#if USE_FILEDLG_GENERIC
369 filedlg_menu->AppendSeparator();
9a83f860
VZ
370 filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, wxT("&Open file (generic)"));
371 filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, wxT("Open &files (generic)"));
372 filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, wxT("Sa&ve file (generic)"));
8ce68f7f 373#endif // USE_FILEDLG_GENERIC
695fe764 374
9a83f860 375 menuDlg->Append(wxID_ANY,wxT("&File operations"),filedlg_menu);
13188def 376
33bcca32 377#endif // wxUSE_FILEDLG
13188def 378
33bcca32
VZ
379#if wxUSE_DIRDLG
380 wxMenu *dir_menu = new wxMenu;
13188def 381
9a83f860
VZ
382 dir_menu->Append(DIALOGS_DIR_CHOOSE, wxT("&Choose a directory\tCtrl-D"));
383 dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, wxT("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
384 menuDlg->Append(wxID_ANY,wxT("&Directory operations"),dir_menu);
13188def 385
33bcca32
VZ
386 #if USE_DIRDLG_GENERIC
387 dir_menu->AppendSeparator();
9a83f860 388 dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, wxT("&Choose a directory (generic)"));
33bcca32 389 #endif // USE_DIRDLG_GENERIC
13188def 390
33bcca32 391#endif // wxUSE_DIRDLG
13188def
WS
392
393
8cf304f8
VZ
394#if wxUSE_STARTUP_TIPS || \
395 wxUSE_PROGRESSDLG || \
396 wxUSE_BUSYINFO || \
397 wxUSE_LOG_DIALOG || \
398 wxUSE_MSGDLG
13188def 399
33bcca32 400 wxMenu *info_menu = new wxMenu;
13188def 401
33bcca32 402 #if wxUSE_STARTUP_TIPS
9a83f860 403 info_menu->Append(DIALOGS_TIP, wxT("&Tip of the day\tCtrl-T"));
33bcca32 404 #endif // wxUSE_STARTUP_TIPS
13188def 405
33bcca32 406 #if wxUSE_PROGRESSDLG
9a83f860 407 info_menu->Append(DIALOGS_PROGRESS, wxT("Pro&gress dialog\tCtrl-G"));
33bcca32 408 #endif // wxUSE_PROGRESSDLG
13188def 409
33bcca32 410 #if wxUSE_BUSYINFO
9a83f860 411 info_menu->Append(DIALOGS_BUSYINFO, wxT("&Busy info dialog\tCtrl-B"));
33bcca32 412 #endif // wxUSE_BUSYINFO
13188def 413
33bcca32 414 #if wxUSE_LOG_DIALOG
9a83f860 415 info_menu->Append(DIALOGS_LOG_DIALOG, wxT("&Log dialog\tCtrl-L"));
33bcca32 416 #endif // wxUSE_LOG_DIALOG
13188def 417
a92b5dfe
VZ
418 #if wxUSE_INFOBAR
419 info_menu->Append(DIALOGS_INFOBAR_SIMPLE, "Simple &info bar\tCtrl-I");
420 info_menu->Append(DIALOGS_INFOBAR_ADVANCED, "&Advanced info bar\tShift-Ctrl-I");
421 #endif // wxUSE_INFOBAR
422
8cf304f8
VZ
423 #if wxUSE_MSGDLG
424 info_menu->Append(DIALOGS_MESSAGE_BOX_WXINFO,
a92b5dfe 425 wxT("&wxWidgets information\tCtrl-W"));
8cf304f8
VZ
426 #endif // wxUSE_MSGDLG
427
9a83f860 428 menuDlg->Append(wxID_ANY,wxT("&Informative dialogs"),info_menu);
13188def 429
33bcca32 430#endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
13188def
WS
431
432
33bcca32
VZ
433#if wxUSE_FINDREPLDLG
434 wxMenu *find_menu = new wxMenu;
9a83f860
VZ
435 find_menu->AppendCheckItem(DIALOGS_FIND, wxT("&Find dialog\tCtrl-F"));
436 find_menu->AppendCheckItem(DIALOGS_REPLACE, wxT("Find and &replace dialog\tShift-Ctrl-F"));
437 menuDlg->Append(wxID_ANY,wxT("&Searching"),find_menu);
33bcca32 438#endif // wxUSE_FINDREPLDLG
13188def 439
cae50e6b 440 wxMenu *dialogs_menu = new wxMenu;
1baa0a9d 441#if USE_MODAL_PRESENTATION
a92b5dfe 442 dialogs_menu->Append(DIALOGS_MODAL, wxT("&Modal dialog\tShift-Ctrl-W"));
1baa0a9d 443#endif // USE_MODAL_PRESENTATION
a92b5dfe 444 dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, wxT("Mode&less dialog\tShift-Ctrl-Z"));
9a83f860
VZ
445 dialogs_menu->Append(DIALOGS_CENTRE_SCREEN, wxT("Centered on &screen\tShift-Ctrl-1"));
446 dialogs_menu->Append(DIALOGS_CENTRE_PARENT, wxT("Centered on &parent\tShift-Ctrl-2"));
81496fea 447#if wxUSE_MINIFRAME
9a83f860 448 dialogs_menu->Append(DIALOGS_MINIFRAME, wxT("&Mini frame"));
81496fea 449#endif // wxUSE_MINIFRAME
9a83f860
VZ
450 dialogs_menu->Append(DIALOGS_ONTOP, wxT("Dialog staying on &top"));
451 menuDlg->Append(wxID_ANY, wxT("&Generic dialogs"), dialogs_menu);
13188def 452
532d575b 453#if USE_SETTINGS_DIALOG
b40bb73e 454 wxMenu *sheet_menu = new wxMenu;
9a83f860
VZ
455 sheet_menu->Append(DIALOGS_PROPERTY_SHEET, wxT("&Standard property sheet\tShift-Ctrl-P"));
456 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, wxT("&Toolbook sheet\tShift-Ctrl-T"));
e031f1df 457
5c351979 458 if (wxPlatformIs(wxPORT_MAC))
9a83f860 459 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
230c9077 460/*
b887dc7b 461#ifdef __WXMAC__
9a83f860 462 sheet_menu->Append(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, wxT("Button &Toolbook sheet\tShift-Ctrl-U"));
b887dc7b 463#endif
230c9077 464*/
9a83f860 465 menuDlg->Append(wxID_ANY, wxT("&Property sheets"), sheet_menu);
b40bb73e 466#endif // USE_SETTINGS_DIALOG
532d575b 467
e36a1739 468 wxMenu *menuNotif = new wxMenu;
9a83f860 469 menuNotif->Append(DIALOGS_REQUEST, wxT("&Request user attention\tCtrl-Shift-R"));
e36a1739
VZ
470#if wxUSE_NOTIFICATION_MESSAGE
471 menuNotif->Append(DIALOGS_NOTIFY_AUTO, "&Automatically hidden notification");
472 menuNotif->Append(DIALOGS_NOTIFY_SHOW, "&Show manual notification");
473 menuNotif->Append(DIALOGS_NOTIFY_HIDE, "&Hide manual notification");
474#endif // wxUSE_NOTIFICATION_MESSAGE
475 menuDlg->AppendSubMenu(menuNotif, "&User notifications");
8e1dac82 476
9a83f860
VZ
477 menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, wxT("&Standard Buttons Sizer Dialog"));
478 menuDlg->Append(DIALOGS_TEST_DEFAULT_ACTION, wxT("&Test dialog default action"));
ca7adbf8
VZ
479
480 menuDlg->AppendSeparator();
9a83f860 481 menuDlg->Append(wxID_EXIT, wxT("E&xit\tAlt-X"));
9b16ffef 482
ca7adbf8
VZ
483#if wxUSE_ABOUTDLG
484 wxMenu *menuHelp = new wxMenu;
9a83f860
VZ
485 menuHelp->Append(DIALOGS_ABOUTDLG_SIMPLE, wxT("&About (simple)...\tF1"));
486 menuHelp->Append(DIALOGS_ABOUTDLG_FANCY, wxT("About (&fancy)...\tShift-F1"));
487 menuHelp->Append(DIALOGS_ABOUTDLG_FULL, wxT("About (f&ull)...\tCtrl-F1"));
488 menuHelp->Append(DIALOGS_ABOUTDLG_CUSTOM, wxT("About (&custom)...\tCtrl-Shift-F1"));
ca7adbf8 489#endif // wxUSE_ABOUTDLG
13188def 490
ca7adbf8 491 wxMenuBar *menubar = new wxMenuBar;
9a83f860 492 menubar->Append(menuDlg, wxT("&Dialogs"));
ca7adbf8 493#if wxUSE_ABOUTDLG
9a83f860 494 menubar->Append(menuHelp, wxT("&Help"));
ca7adbf8
VZ
495#endif // wxUSE_ABOUTDLG
496
497 frame->SetMenuBar(menubar);
13188def 498
13188def 499 frame->Centre(wxBOTH);
13188def
WS
500 frame->Show(true);
501
13188def 502 return true;
457814b5
JS
503}
504
505// My frame constructor
5b05ce47
VZ
506MyFrame::MyFrame(const wxString& title)
507 : wxFrame(NULL, wxID_ANY, title)
4c45f240 508{
3cb332c1 509 SetIcon(wxICON(sample));
532d575b 510
13188def 511#if USE_MODAL_PRESENTATION
4c45f240 512 m_dialog = (MyModelessDialog *)NULL;
13188def 513#endif // USE_MODAL_PRESENTATION
f1e1ed3b 514
043dcdaa 515#if wxUSE_FINDREPLDLG
14fca738
VZ
516 m_dlgFind =
517 m_dlgReplace = NULL;
043dcdaa 518#endif
dabbc6a5
DS
519
520#if wxUSE_COLOURDLG
d33dd9ef 521 m_clrData.SetChooseFull(true);
e6ef9ea4 522 for (int i = 0; i < wxColourData::NUM_CUSTOM; i++)
d33dd9ef 523 {
e6ef9ea4
VZ
524 unsigned char n = i*16;
525 m_clrData.SetCustomColour(i, wxColour(n, n, n));
d33dd9ef 526 }
13188def 527#endif // wxUSE_COLOURDLG
f9d0e439 528
e36a1739
VZ
529#if wxUSE_NOTIFICATION_MESSAGE
530 m_notifMsg = NULL;
531#endif // wxUSE_NOTIFICATION_MESSAGE
532
f9d0e439
VZ
533#if wxUSE_STATUSBAR
534 CreateStatusBar();
535#endif // wxUSE_STATUSBAR
87a18679
VZ
536
537 m_canvas = new MyCanvas(this);
a92b5dfe
VZ
538
539#if wxUSE_INFOBAR
374ae80f 540 // an info bar can be created very simply and used without any extra effort
a92b5dfe 541 m_infoBarSimple = new wxInfoBar(this);
374ae80f 542
c0945eb2 543 // or it can also be customized by
374ae80f 544 m_infoBarAdvanced = new wxInfoBar(this);
c0945eb2
VZ
545
546 // ... adding extra buttons (but more than two will usually be too many)
374ae80f 547 m_infoBarAdvanced->AddButton(wxID_UNDO);
e6b2aae1
VZ
548 m_infoBarAdvanced->AddButton(wxID_REDO);
549
c0945eb2
VZ
550 m_infoBarAdvanced->Connect(wxID_REDO, wxEVT_COMMAND_BUTTON_CLICKED,
551 wxCommandEventHandler(MyFrame::OnInfoBarRedo),
552 NULL,
553 this);
554
e6b2aae1
VZ
555 // adding and removing a button immediately doesn't make sense here, of
556 // course, it's done just to show that it is possible
557 m_infoBarAdvanced->AddButton(wxID_EXIT);
558 m_infoBarAdvanced->RemoveButton(wxID_EXIT);
374ae80f 559
c0945eb2 560 // ... changing the colours and/or fonts
374ae80f 561 m_infoBarAdvanced->SetOwnBackgroundColour(0xc8ffff);
c0945eb2
VZ
562 m_infoBarAdvanced->SetFont(GetFont().Bold().Larger());
563
564 // ... and changing the effect (only does anything under MSW currently)
374ae80f
VZ
565 m_infoBarAdvanced->SetShowHideEffects(wxSHOW_EFFECT_EXPAND,
566 wxSHOW_EFFECT_EXPAND);
567 m_infoBarAdvanced->SetEffectDuration(1500);
a92b5dfe 568
c0945eb2 569
a92b5dfe
VZ
570 // to use the info bars we need to use sizer for the window layout
571 wxBoxSizer * const sizer = new wxBoxSizer(wxVERTICAL);
572 sizer->Add(m_infoBarSimple, wxSizerFlags().Expand());
573 sizer->Add(m_canvas, wxSizerFlags(1).Expand());
374ae80f 574 sizer->Add(m_infoBarAdvanced, wxSizerFlags().Expand());
a92b5dfe 575 SetSizer(sizer);
15ea6e20
VZ
576
577 // final touch: under MSW the info bars are shown progressively and parts
578 // of the parent window can be seen during the process, so use the same
579 // background colour for our background as for the canvas window which
580 // covers our entire client area to avoid jarring colour jumps
581 SetOwnBackgroundColour(m_canvas->GetBackgroundColour());
a92b5dfe 582#endif // wxUSE_INFOBAR
4c45f240 583}
457814b5 584
e36a1739
VZ
585MyFrame::~MyFrame()
586{
587#if wxUSE_NOTIFICATION_MESSAGE
588 delete m_notifMsg;
589#endif // wxUSE_NOTIFICATION_MESSAGE
590}
591
13188def 592#if wxUSE_COLOURDLG
e6ef9ea4
VZ
593
594void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event))
457814b5 595{
87a18679 596 m_clrData.SetColour(m_canvas->GetBackgroundColour());
d93c719a 597
d33dd9ef 598 wxColourDialog dialog(this, &m_clrData);
e6ef9ea4
VZ
599 dialog.SetTitle(_("Please choose the background colour"));
600 if ( dialog.ShowModal() == wxID_OK )
f6bcfd97 601 {
d33dd9ef 602 m_clrData = dialog.GetColourData();
87a18679
VZ
603 m_canvas->SetBackgroundColour(m_clrData.GetColour());
604 m_canvas->ClearBackground();
605 m_canvas->Refresh();
f6bcfd97 606 }
457814b5 607}
e6ef9ea4
VZ
608
609void MyFrame::GetColour(wxCommandEvent& WXUNUSED(event))
610{
611 wxColour clr = wxGetColourFromUser
612 (
613 this,
3406ebd4 614 m_canvas->GetForegroundColour(),
e6ef9ea4
VZ
615 "Please choose the foreground colour"
616 );
617 if ( clr.IsOk() )
618 {
3406ebd4 619 m_canvas->SetForegroundColour(clr);
87a18679 620 m_canvas->Refresh();
e6ef9ea4
VZ
621 }
622 //else: dialog cancelled by user
623}
624
13188def 625#endif // wxUSE_COLOURDLG
457814b5 626
e6ef9ea4 627
1e72e3cc
RN
628#if USE_COLOURDLG_GENERIC
629void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
630{
87a18679 631 m_clrData.SetColour(m_canvas->GetBackgroundColour());
1e72e3cc
RN
632
633 //FIXME:TODO:This has no effect...
634 m_clrData.SetChooseFull(true);
635
636 for (int i = 0; i < 16; i++)
637 {
638 wxColour colour(
639 (unsigned char)(i*16),
640 (unsigned char)(i*16),
641 (unsigned char)(i*16)
642 );
643 m_clrData.SetCustomColour(i, colour);
644 }
645
646 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData);
647 if (dialog->ShowModal() == wxID_OK)
648 {
649 m_clrData = dialog->GetColourData();
87a18679
VZ
650 m_canvas->SetBackgroundColour(m_clrData.GetColour());
651 m_canvas->ClearBackground();
652 m_canvas->Refresh();
1e72e3cc
RN
653 }
654 dialog->Destroy();
655}
656#endif // USE_COLOURDLG_GENERIC
657
13188def 658#if wxUSE_FONTDLG
d355d3fe 659void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
457814b5 660{
dbc65e27 661 wxFontData data;
3406ebd4
VZ
662 data.SetInitialFont(m_canvas->GetFont());
663 data.SetColour(m_canvas->GetForegroundColour());
d93c719a 664
dbc65e27
VZ
665 // you might also do this:
666 //
667 // wxFontDialog dialog;
668 // if ( !dialog.Create(this, data) { ... error ... }
669 //
670 wxFontDialog dialog(this, data);
671
672 if (dialog.ShowModal() == wxID_OK)
673 {
674 wxFontData retData = dialog.GetFontData();
3406ebd4
VZ
675 m_canvas->SetFont(retData.GetChosenFont());
676 m_canvas->SetForegroundColour(retData.GetColour());
87a18679 677 m_canvas->Refresh();
dbc65e27
VZ
678 }
679 //else: cancelled by the user, don't change the font
457814b5 680}
13188def 681#endif // wxUSE_FONTDLG
457814b5 682
13188def 683#if USE_FONTDLG_GENERIC
d355d3fe 684void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
457814b5 685{
13188def 686 wxFontData data;
3406ebd4
VZ
687 data.SetInitialFont(m_canvas->GetFont());
688 data.SetColour(m_canvas->GetForegroundColour());
457814b5 689
ca3e85cf 690 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, data);
13188def
WS
691 if (dialog->ShowModal() == wxID_OK)
692 {
457814b5 693 wxFontData retData = dialog->GetFontData();
3406ebd4
VZ
694 m_canvas->SetFont(retData.GetChosenFont());
695 m_canvas->SetForegroundColour(retData.GetColour());
87a18679 696 m_canvas->Refresh();
13188def
WS
697 }
698 dialog->Destroy();
457814b5 699}
13188def 700#endif // USE_FONTDLG_GENERIC
d93c719a 701
b4954d19 702#if wxUSE_LOG_DIALOG
87728739 703void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
d93c719a 704{
2c8e4738
VZ
705 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
706 // being flushed -- test it
707 {
708 wxBusyCursor bc;
4693b20c
MB
709 wxLogMessage(wxT("This is some message - everything is ok so far."));
710 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
711 wxLogWarning(wxT("And then something went wrong!"));
9fe52545
VZ
712
713 // and if ~wxBusyCursor doesn't do it, then call it manually
714 wxYield();
2c8e4738
VZ
715 }
716
4693b20c
MB
717 wxLogError(wxT("Intermediary error handler decided to abort."));
718 wxLogError(wxT("The top level caller detected an unrecoverable error."));
5888ef1e 719
7923c649
VZ
720 wxLog::FlushActive();
721
4693b20c 722 wxLogMessage(wxT("And this is the same dialog but with only one message."));
d93c719a 723}
b4954d19 724#endif // wxUSE_LOG_DIALOG
457814b5 725
a92b5dfe
VZ
726#if wxUSE_INFOBAR
727
728void MyFrame::InfoBarSimple(wxCommandEvent& WXUNUSED(event))
729{
730 static int s_count = 0;
731 m_infoBarSimple->ShowMessage
732 (
733 wxString::Format("Message #%d in the info bar.", ++s_count)
734 );
735}
736
737void MyFrame::InfoBarAdvanced(wxCommandEvent& WXUNUSED(event))
738{
374ae80f 739 m_infoBarAdvanced->ShowMessage("Sorry, it didn't work out.", wxICON_WARNING);
a92b5dfe
VZ
740}
741
c0945eb2
VZ
742void MyFrame::OnInfoBarRedo(wxCommandEvent& WXUNUSED(event))
743{
744 m_infoBarAdvanced->ShowMessage("Still no, sorry again.", wxICON_ERROR);
745}
746
a92b5dfe
VZ
747#endif // wxUSE_INFOBAR
748
749
8cf304f8 750#if wxUSE_MSGDLG
44b25eac 751void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
457814b5 752{
1d89da8a 753 wxMessageDialog dialog(this,
4223fc75 754 "This is a message box\n"
0a29d575 755 "This is a long, long string to test out if the message box "
ebaa7e48 756 "is laid out properly.",
4223fc75 757 "Message box text",
f3fe2d4e 758 wxCENTER |
44b25eac
VZ
759 wxNO_DEFAULT | wxYES_NO | wxCANCEL |
760 wxICON_INFORMATION);
86c3808c 761
4223fc75
VZ
762 wxString extmsg;
763 if ( dialog.SetYesNoCancelLabels
86c3808c
SC
764 (
765 "Answer &Yes",
766 "Answer &No",
767 "Refuse to answer"
768 ) )
769 {
770 extmsg = "This platform supports custom button labels,\n"
771 "so you should see the descriptive labels below.";
772 }
773 else
774 {
775 extmsg = "Custom button labels are not supported on this platform,\n"
776 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
777 }
778 dialog.SetExtendedMessage(extmsg);
779
780 switch ( dialog.ShowModal() )
781 {
782 case wxID_YES:
783 wxLogStatus(wxT("You pressed \"Yes\""));
784 break;
785
786 case wxID_NO:
787 wxLogStatus(wxT("You pressed \"No\""));
788 break;
789
790 case wxID_CANCEL:
791 wxLogStatus(wxT("You pressed \"Cancel\""));
792 break;
793
794 default:
795 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
796 }
797}
798
799void MyFrame::MessageBoxWindowModal(wxCommandEvent& WXUNUSED(event))
800{
801 wxMessageDialog* dialog = new wxMessageDialog(this,
802 "This is a message box\n"
803 "This is a long, long string to test out if the message box "
804 "is laid out properly.",
805 "Message box text",
806 wxCENTER |
807 wxNO_DEFAULT | wxYES_NO | wxCANCEL |
808 wxICON_INFORMATION);
809
810 wxString extmsg;
811 if ( dialog->SetYesNoCancelLabels
4223fc75
VZ
812 (
813 "Answer &Yes",
814 "Answer &No",
815 "Refuse to answer"
816 ) )
2afb9e16 817 {
4223fc75 818 extmsg = "This platform supports custom button labels,\n"
5150a29a 819 "so you should see the descriptive labels below.";
2afb9e16
VZ
820 }
821 else
822 {
4223fc75
VZ
823 extmsg = "Custom button labels are not supported on this platform,\n"
824 "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used.";
2afb9e16 825 }
86c3808c
SC
826 dialog->SetExtendedMessage(extmsg);
827 dialog->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed), NULL, this );
828 dialog->ShowWindowModal();
829}
457814b5 830
86c3808c
SC
831void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event)
832{
833 wxDialog* dialog = event.GetDialog();
834 switch ( dialog->GetReturnCode() )
13188def
WS
835 {
836 case wxID_YES:
837 wxLogStatus(wxT("You pressed \"Yes\""));
838 break;
49b957be 839
13188def
WS
840 case wxID_NO:
841 wxLogStatus(wxT("You pressed \"No\""));
842 break;
49b957be 843
13188def
WS
844 case wxID_CANCEL:
845 wxLogStatus(wxT("You pressed \"Cancel\""));
846 break;
49b957be 847
13188def
WS
848 default:
849 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
850 }
86c3808c 851 delete dialog;
457814b5
JS
852}
853
44b25eac
VZ
854void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
855{
856 TestMessageBoxDialog dlg(this);
a1bdd4ab 857 dlg.Create();
44b25eac
VZ
858 dlg.ShowModal();
859}
860
8cf304f8
VZ
861void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event))
862{
863 ::wxInfoMessageBox(this);
864}
865#endif // wxUSE_MSGDLG
866
a1bdd4ab
VZ
867#if wxUSE_RICHMSGDLG
868void MyFrame::RichMessageDialog(wxCommandEvent& WXUNUSED(event))
869{
870 TestRichMessageDialog dlg(this);
871 dlg.Create();
872 dlg.ShowModal();
873}
874#endif // wxUSE_RICHMSGDLG
875
13188def 876#if wxUSE_NUMBERDLG
8cf304f8 877void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event))
c49245f8 878{
9a83f860
VZ
879 long res = wxGetNumberFromUser( wxT("This is some text, actually a lot of text.\n")
880 wxT("Even two rows of text."),
881 wxT("Enter a number:"), wxT("Numeric input test"),
e65cc56a 882 50, 0, 100, this );
c49245f8
VZ
883
884 wxString msg;
885 int icon;
886 if ( res == -1 )
887 {
9a83f860 888 msg = wxT("Invalid number entered or dialog cancelled.");
c49245f8
VZ
889 icon = wxICON_HAND;
890 }
891 else
d93c719a 892 {
9a83f860 893 msg.Printf(wxT("You've entered %lu"), res );
c49245f8
VZ
894 icon = wxICON_INFORMATION;
895 }
896
9a83f860 897 wxMessageBox(msg, wxT("Numeric test result"), wxOK | icon, this);
c49245f8 898}
13188def 899#endif // wxUSE_NUMBERDLG
c49245f8 900
13188def 901#if wxUSE_TEXTDLG
a294c6d5 902void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
457814b5 903{
9a83f860
VZ
904 wxString pwd = wxGetPasswordFromUser(wxT("Enter password:"),
905 wxT("Password entry dialog"),
dabbc6a5 906 wxEmptyString,
a294c6d5 907 this);
ecda9475 908 if ( !pwd.empty() )
a294c6d5 909 {
4693b20c 910 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
9a83f860 911 wxT("Got password"), wxOK | wxICON_INFORMATION, this);
a294c6d5
VZ
912 }
913}
914
915void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
916{
13188def 917 wxTextEntryDialog dialog(this,
9a83f860
VZ
918 wxT("This is a small sample\n")
919 wxT("A long, long string to test out the text entrybox"),
920 wxT("Please enter a string"),
921 wxT("Default value"),
13188def 922 wxOK | wxCANCEL);
457814b5 923
13188def
WS
924 if (dialog.ShowModal() == wxID_OK)
925 {
9a83f860 926 wxMessageBox(dialog.GetValue(), wxT("Got string"), wxOK | wxICON_INFORMATION, this);
13188def 927 }
457814b5 928}
13188def 929#endif // wxUSE_TEXTDLG
457814b5 930
13188def 931#if wxUSE_CHOICEDLG
d355d3fe 932void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
457814b5 933{
9a83f860 934 const wxString choices[] = { wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five") } ;
457814b5 935
5f95bb70 936 wxSingleChoiceDialog dialog(this,
9a83f860
VZ
937 wxT("This is a small sample\n")
938 wxT("A single-choice convenience dialog"),
939 wxT("Please select a value"),
5f95bb70 940 WXSIZEOF(choices), choices);
457814b5 941
ef77f91e
JS
942 dialog.SetSelection(2);
943
944 if (dialog.ShowModal() == wxID_OK)
945 {
9a83f860 946 wxMessageDialog dialog2(this, dialog.GetStringSelection(), wxT("Got string"));
ef77f91e
JS
947 dialog2.ShowModal();
948 }
457814b5
JS
949}
950
d6c9c1b7
VZ
951void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
952{
5f95bb70
VZ
953 const wxString choices[] =
954 {
9a83f860
VZ
955 wxT("One"), wxT("Two"), wxT("Three"), wxT("Four"), wxT("Five"),
956 wxT("Six"), wxT("Seven"), wxT("Eight"), wxT("Nine"), wxT("Ten"),
957 wxT("Eleven"), wxT("Twelve"), wxT("Seventeen"),
5f95bb70 958 };
d6c9c1b7
VZ
959
960 wxArrayInt selections;
e5cfb314 961 const int count = wxGetSelectedChoices(selections,
9a83f860
VZ
962 wxT("This is a small sample\n")
963 wxT("A multi-choice convenience dialog"),
964 wxT("Please select a value"),
5f95bb70 965 WXSIZEOF(choices), choices,
d6c9c1b7 966 this);
e5cfb314 967 if ( count >= 0 )
d6c9c1b7 968 {
3d49ce44 969 wxString msg;
e5cfb314 970 if ( count == 0 )
d6c9c1b7 971 {
e5cfb314
VZ
972 msg = wxT("You did not select any items");
973 }
974 else
975 {
976 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
977 for ( int n = 0; n < count; n++ )
978 {
979 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
980 (unsigned)n, (unsigned)selections[n],
981 choices[selections[n]].c_str());
982 }
d6c9c1b7 983 }
3d49ce44 984 wxLogMessage(msg);
d6c9c1b7 985 }
e5cfb314 986 //else: cancelled
d6c9c1b7 987}
13188def 988#endif // wxUSE_CHOICEDLG
d6c9c1b7 989
81496fea 990#if wxUSE_REARRANGECTRL
5a5f305a
VZ
991// custom rearrange dialog: it adds the possibility to rename an item to the
992// base class functionality
993class MyRearrangeDialog : public wxRearrangeDialog
994{
995public:
996 MyRearrangeDialog(wxWindow *parent,
997 wxArrayInt& order,
998 wxArrayString& labels,
999 wxArrayString& labelsOrig)
1000 : wxRearrangeDialog
1001 (
1002 parent,
1003 "Configure the columns shown:",
1004 "wxRearrangeDialog example",
1005 order,
1006 labels
1007 ),
1008 m_order(order),
1009 m_labels(labels),
1010 m_labelsOrig(labelsOrig)
1011 {
1012 m_sel = wxNOT_FOUND;
1013
1014 wxPanel * const panel = new wxPanel(this);
1015 wxSizer * const sizer = new wxBoxSizer(wxHORIZONTAL);
1016
1017 m_labelOrig = new wxStaticText(panel, wxID_ANY, "");
1018 sizer->Add(m_labelOrig, wxSizerFlags().Centre().Border(wxRIGHT));
1019
1020 m_text = new wxTextCtrl(panel, wxID_ANY, "",
1021 wxDefaultPosition, wxDefaultSize,
1022 wxTE_PROCESS_ENTER);
1023 sizer->Add(m_text, wxSizerFlags().Centre().Border(wxRIGHT));
1024
1025 sizer->Add(new wxButton(panel, wxID_APPLY, "&Rename"),
1026 wxSizerFlags().Centre());
1027
1028 panel->SetSizer(sizer);
1029
1030 // call this first to ensure that the controls have a reasonable best
1031 // size before they're added
1032 DoUpdateExtraControls(GetList()->GetSelection());
1033
1034 AddExtraControls(panel);
e9bef302
VZ
1035
1036
1037 // another customization not directly supported by the dialog: add a
1038 // custom button
1039 wxWindow * const btnOk = FindWindow(wxID_OK);
1040 wxCHECK_RET( btnOk, "no Ok button?" );
1041
1042 wxSizer * const sizerBtns = btnOk->GetContainingSizer();
1043 wxCHECK_RET( sizerBtns, "no buttons sizer?" );
1044
1045 sizerBtns->Add(new wxButton(this, wxID_RESET, "&Reset all"),
1046 wxSizerFlags().Border(wxLEFT));
5a5f305a
VZ
1047 }
1048
1049 // call this instead of ShowModal() to update order and labels array in
1050 // case the dialog was not cancelled
1051 bool Rearrange()
1052 {
e9bef302
VZ
1053 switch ( ShowModal() )
1054 {
1055 case wxID_CANCEL:
1056 return false;
5a5f305a 1057
e9bef302
VZ
1058 case wxID_OK:
1059 m_order = GetOrder();
1060 break;
1061
1062 case wxID_RESET:
1063 // order already reset
1064 break;
1065 }
5a5f305a
VZ
1066
1067 return true;
1068 }
1069
1070private:
1071 void OnSelChange(wxCommandEvent& event)
1072 {
1073 DoUpdateExtraControls(event.GetInt());
1074 }
1075
1076 void OnUpdateUIRename(wxUpdateUIEvent& event)
1077 {
1078 event.Enable( CanRename() );
1079 }
1080
1081 void OnRename(wxCommandEvent& WXUNUSED(event))
1082 {
1083 if ( !CanRename() )
1084 return;
1085
1086 m_labels[m_sel] = m_text->GetValue();
1087 GetList()->SetString(m_sel, m_labels[m_sel]);
1088 }
1089
e9bef302
VZ
1090 void OnReset(wxCommandEvent& WXUNUSED(event))
1091 {
1092 // in a real program we should probably ask if the user really wants to
1093 // do this but here we just go ahead and reset all columns labels and
1094 // their order without confirmation
1095 const unsigned count = m_order.size();
1096 for ( unsigned n = 0; n < count; n++ )
1097 {
1098 m_order[n] = n;
1099 m_labels[n] = m_labelsOrig[n];
1100 }
1101
1102 EndModal(wxID_RESET);
1103 }
1104
5a5f305a
VZ
1105 bool CanRename() const
1106 {
1107 // only allow renaming if the user modified the currently selected item
1108 // text (which presupposes that we do have a current item)
1109 return m_sel != wxNOT_FOUND && m_text->GetValue() != m_labels[m_sel];
1110 }
1111
1112 void DoUpdateExtraControls(int sel)
1113 {
1114 m_sel = sel;
1115
1116 if ( m_sel == wxNOT_FOUND )
1117 {
1118 m_labelOrig->SetLabel("<no selection>");
1119 m_text->Clear();
1120 m_text->Disable();
1121 }
1122 else // have valid item
1123 {
1124 m_labelOrig->SetLabelText(m_labelsOrig[m_sel]);
1125 m_text->Enable();
1126 m_text->SetValue(m_labels[m_sel]);
1127 }
1128 }
1129
1130 wxArrayInt& m_order;
1131 wxArrayString& m_labels,
1132 m_labelsOrig;
1133
1134 int m_sel;
1135 wxStaticText *m_labelOrig;
1136 wxTextCtrl *m_text;
1137
1138 DECLARE_EVENT_TABLE()
c0c133e1 1139 wxDECLARE_NO_COPY_CLASS(MyRearrangeDialog);
5a5f305a
VZ
1140};
1141
1142BEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog)
1143 EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange)
e9bef302 1144
5a5f305a 1145 EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename)
e9bef302 1146
5a5f305a 1147 EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename)
e9bef302
VZ
1148 EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename)
1149 EVT_BUTTON(wxID_RESET, MyRearrangeDialog::OnReset)
5a5f305a
VZ
1150END_EVENT_TABLE()
1151
1152void MyFrame::Rearrange(wxCommandEvent& WXUNUSED(event))
1153{
1154 // the arrays are static so that we preserve the items order between calls
1155 // to this function
1156 static wxArrayInt s_order;
1157 static wxArrayString s_labels,
1158 s_labelsOrig;
1159
1160 // initialize them on the first call
1161 if ( s_labelsOrig.empty() )
1162 {
1163 static const struct ItemInfo
1164 {
1165 const char *label;
1166 const char *labelOrig;
1167 int order;
1168 } items[] =
1169 {
1170 { "File name", "Name", 0 },
1171 { "File type", "Ext", 1 },
1172 { "Size", "Size", 2 },
1173 { "Creation time", "Ctime", ~3 }, // negated so hidden
1174 { "Last accessed", "Atime", ~4 },
1175 { "Last modified", "Mtime", 5 },
1176 };
1177
1178 s_order.reserve(WXSIZEOF(items));
1179 s_labels.reserve(WXSIZEOF(items));
1180 s_labelsOrig.reserve(WXSIZEOF(items));
1181 for ( unsigned n = 0; n < WXSIZEOF(items); n++ )
1182 {
1183 const ItemInfo& item = items[n];
1184 s_order.push_back(item.order);
1185 s_labels.push_back(item.label);
1186 s_labelsOrig.push_back(item.labelOrig);
1187 }
1188 }
1189
1190 MyRearrangeDialog dlg(this, s_order, s_labels, s_labelsOrig);
1191 if ( !dlg.Rearrange() )
1192 return;
1193
1194 wxString columns;
1195 for ( unsigned n = 0; n < s_order.size(); n++ )
1196 {
1197 columns += wxString::Format("\n %u: ", n);
1198 int idx = s_order[n];
1199 if ( idx < 0 )
1200 {
1201 columns += "[hidden] ";
1202 idx = ~idx;
1203 }
1204
1205 columns += s_labels[idx];
1206 if ( s_labels[idx] != s_labelsOrig[idx] )
1207 {
1208 columns += wxString::Format(" (original label: \"%s\")",
1209 s_labelsOrig[idx]);
1210 }
1211 }
1212
1213 wxLogMessage("The columns order now is:%s", columns);
1214}
81496fea 1215#endif // wxUSE_REARRANGECTRL
5a5f305a 1216
13188def 1217#if wxUSE_FILEDLG
8ce68f7f
VZ
1218
1219// panel with custom controls for file dialog
1220class MyExtraPanel : public wxPanel
1221{
1222public:
1223 MyExtraPanel(wxWindow *parent);
1224 void OnCheckBox(wxCommandEvent& event) { m_btn->Enable(event.IsChecked()); }
1225 wxString GetInfo() const
1226 {
1227 return wxString::Format("checkbox value = %d", (int) m_cb->GetValue());
1228 }
1229private:
1230 wxButton *m_btn;
1231 wxCheckBox *m_cb;
1232};
1233
1234MyExtraPanel::MyExtraPanel(wxWindow *parent)
1235 : wxPanel(parent)
1236{
9a83f860 1237 m_btn = new wxButton(this, -1, wxT("Custom Button"));
8ce68f7f 1238 m_btn->Enable(false);
9a83f860 1239 m_cb = new wxCheckBox(this, -1, wxT("Enable Custom Button"));
8ce68f7f
VZ
1240 m_cb->Connect(wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED,
1241 wxCommandEventHandler(MyExtraPanel::OnCheckBox), NULL, this);
1242 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
1243 sizerTop->Add(m_cb, wxSizerFlags().Centre().Border());
1244 sizerTop->AddStretchSpacer();
1245 sizerTop->Add(m_btn, wxSizerFlags().Right().Border());
1246 SetSizerAndFit(sizerTop);
1247}
1248
1249// a static method can be used instead of a function with most of compilers
1250static wxWindow* createMyExtraPanel(wxWindow *parent)
1251{
1252 return new MyExtraPanel(parent);
1253}
1254
d355d3fe 1255void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
457814b5 1256{
fbf4eacb
VZ
1257 wxFileDialog dialog
1258 (
1259 this,
9a83f860 1260 wxT("Testing open file dialog"),
dabbc6a5
DS
1261 wxEmptyString,
1262 wxEmptyString,
a4e64fb5 1263#ifdef __WXMOTIF__
9a83f860 1264 wxT("C++ files (*.cpp)|*.cpp")
a4e64fb5 1265#else
9a83f860 1266 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
a4e64fb5 1267#endif
fbf4eacb 1268 );
457814b5 1269
8ce68f7f 1270 dialog.SetExtraControlCreator(&createMyExtraPanel);
3b6c3fc8 1271 dialog.CentreOnParent();
cd7afaff 1272 dialog.SetDirectory(wxGetHomeDir());
5b636c67 1273
c50f1fb9
VZ
1274 if (dialog.ShowModal() == wxID_OK)
1275 {
5919d76b 1276 wxString info;
cece89a4 1277 wxWindow * const extra = dialog.GetExtraControl();
9a83f860
VZ
1278 info.Printf(wxT("Full file name: %s\n")
1279 wxT("Path: %s\n")
1280 wxT("Name: %s\n")
1281 wxT("Custom window: %s"),
5919d76b
VZ
1282 dialog.GetPath().c_str(),
1283 dialog.GetDirectory().c_str(),
8ce68f7f 1284 dialog.GetFilename().c_str(),
cece89a4
VZ
1285 extra ? static_cast<MyExtraPanel*>(extra)->GetInfo()
1286 : wxString("None"));
9a83f860 1287 wxMessageDialog dialog2(this, info, wxT("Selected file"));
c50f1fb9
VZ
1288 dialog2.ShowModal();
1289 }
457814b5
JS
1290}
1291
35b45b33
VZ
1292// this shows how to take advantage of specifying a default extension in the
1293// call to wxFileSelector: it is remembered after each new call and the next
1294// one will use it by default
1295void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
1296{
1297 static wxString s_extDef;
1298 wxString path = wxFileSelector(
9a83f860 1299 wxT("Select the file to load"),
dabbc6a5 1300 wxEmptyString, wxEmptyString,
35b45b33 1301 s_extDef,
3601f639
VZ
1302 wxString::Format
1303 (
9a83f860 1304 wxT("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"),
3601f639
VZ
1305 wxFileSelectorDefaultWildcardStr,
1306 wxFileSelectorDefaultWildcardStr
1307 ),
9f057af5 1308 wxFD_OPEN|wxFD_CHANGE_DIR|wxFD_PREVIEW,
35b45b33
VZ
1309 this
1310 );
1311
1312 if ( !path )
1313 return;
1314
1315 // it is just a sample, would use wxSplitPath in real program
9a83f860 1316 s_extDef = path.AfterLast(wxT('.'));
35b45b33 1317
9a83f860 1318 wxLogMessage(wxT("You selected the file '%s', remembered extension '%s'"),
a342cb00 1319 path, s_extDef);
35b45b33
VZ
1320}
1321
c61f4f6d
VZ
1322void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
1323{
dabbc6a5 1324 wxString wildcards =
f0f43012 1325#ifdef __WXMOTIF__
9a83f860 1326 wxT("C++ files (*.cpp)|*.cpp");
f0f43012 1327#else
3601f639
VZ
1328 wxString::Format
1329 (
9a83f860 1330 wxT("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"),
3601f639
VZ
1331 wxFileSelectorDefaultWildcardStr,
1332 wxFileSelectorDefaultWildcardStr
1333 );
f0f43012 1334#endif
9a83f860 1335 wxFileDialog dialog(this, wxT("Testing open multiple file dialog"),
dabbc6a5 1336 wxEmptyString, wxEmptyString, wildcards,
ff3e84ff 1337 wxFD_OPEN|wxFD_MULTIPLE);
c61f4f6d
VZ
1338
1339 if (dialog.ShowModal() == wxID_OK)
1340 {
1341 wxArrayString paths, filenames;
1342
1343 dialog.GetPaths(paths);
1344 dialog.GetFilenames(filenames);
1345
1346 wxString msg, s;
1347 size_t count = paths.GetCount();
1348 for ( size_t n = 0; n < count; n++ )
1349 {
9a83f860 1350 s.Printf(wxT("File %d: %s (%s)\n"),
fba1b53b 1351 (int)n, paths[n].c_str(), filenames[n].c_str());
c61f4f6d
VZ
1352
1353 msg += s;
1354 }
9a83f860 1355 s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
f0f43012 1356 msg += s;
c61f4f6d 1357
9a83f860 1358 wxMessageDialog dialog2(this, msg, wxT("Selected files"));
c61f4f6d
VZ
1359 dialog2.ShowModal();
1360 }
1361}
1362
d355d3fe 1363void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
457814b5 1364{
2f1cd905 1365 wxFileDialog dialog(this,
9a83f860 1366 wxT("Testing save file dialog"),
dabbc6a5 1367 wxEmptyString,
9a83f860
VZ
1368 wxT("myletter.doc"),
1369 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
ff3e84ff 1370 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
c50f1fb9 1371
2b5f62a0
VZ
1372 dialog.SetFilterIndex(1);
1373
c50f1fb9
VZ
1374 if (dialog.ShowModal() == wxID_OK)
1375 {
9a83f860 1376 wxLogMessage(wxT("%s, filter %d"),
2b5f62a0 1377 dialog.GetPath().c_str(), dialog.GetFilterIndex());
c50f1fb9 1378 }
457814b5 1379}
13188def 1380#endif // wxUSE_FILEDLG
457814b5 1381
695fe764
WS
1382#if USE_FILEDLG_GENERIC
1383void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1384{
1385 wxGenericFileDialog dialog
1386 (
1387 this,
9a83f860 1388 wxT("Testing open file dialog"),
695fe764
WS
1389 wxEmptyString,
1390 wxEmptyString,
9a83f860 1391 wxT("C++ files (*.cpp;*.h)|*.cpp;*.h")
695fe764
WS
1392 );
1393
8ce68f7f 1394 dialog.SetExtraControlCreator(&createMyExtraPanel);
695fe764
WS
1395 dialog.SetDirectory(wxGetHomeDir());
1396
1397 if (dialog.ShowModal() == wxID_OK)
1398 {
1399 wxString info;
9a83f860
VZ
1400 info.Printf(wxT("Full file name: %s\n")
1401 wxT("Path: %s\n")
1402 wxT("Name: %s"),
695fe764
WS
1403 dialog.GetPath().c_str(),
1404 dialog.GetDirectory().c_str(),
1405 dialog.GetFilename().c_str());
9a83f860 1406 wxMessageDialog dialog2(this, info, wxT("Selected file"));
695fe764
WS
1407 dialog2.ShowModal();
1408 }
1409}
1410
1411void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
1412{
684883e3
WS
1413 // On PocketPC you can disable OK-only dialogs policy using system option
1414 int buttons = wxSystemOptions::GetOptionInt(wxT("wince.dialog.real-ok-cancel"));
1415 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), 1);
1416
9a83f860
VZ
1417 wxString wildcards = wxT("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
1418 wxGenericFileDialog dialog(this, wxT("Testing open multiple file dialog"),
695fe764 1419 wxEmptyString, wxEmptyString, wildcards,
e031f1df 1420 wxFD_MULTIPLE);
695fe764
WS
1421
1422 if (dialog.ShowModal() == wxID_OK)
1423 {
1424 wxArrayString paths, filenames;
1425
1426 dialog.GetPaths(paths);
1427 dialog.GetFilenames(filenames);
1428
1429 wxString msg, s;
1430 size_t count = paths.GetCount();
1431 for ( size_t n = 0; n < count; n++ )
1432 {
9a83f860 1433 s.Printf(wxT("File %d: %s (%s)\n"),
695fe764
WS
1434 (int)n, paths[n].c_str(), filenames[n].c_str());
1435
1436 msg += s;
1437 }
9a83f860 1438 s.Printf(wxT("Filter index: %d"), dialog.GetFilterIndex());
695fe764
WS
1439 msg += s;
1440
9a83f860 1441 wxMessageDialog dialog2(this, msg, wxT("Selected files"));
695fe764
WS
1442 dialog2.ShowModal();
1443 }
684883e3
WS
1444
1445 // restore system option
1446 wxSystemOptions::SetOption(wxT("wince.dialog.real-ok-cancel"), buttons);
695fe764
WS
1447}
1448
1449void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
1450{
1451 wxGenericFileDialog dialog(this,
9a83f860 1452 wxT("Testing save file dialog"),
695fe764 1453 wxEmptyString,
9a83f860
VZ
1454 wxT("myletter.doc"),
1455 wxT("Text files (*.txt)|*.txt|Document files (*.doc;*.ods)|*.doc;*.ods"),
e031f1df 1456 wxFD_SAVE|wxFD_OVERWRITE_PROMPT);
695fe764
WS
1457
1458 dialog.SetFilterIndex(1);
1459
1460 if (dialog.ShowModal() == wxID_OK)
1461 {
9a83f860 1462 wxLogMessage(wxT("%s, filter %d"),
695fe764
WS
1463 dialog.GetPath().c_str(), dialog.GetFilterIndex());
1464 }
1465}
1466#endif // USE_FILEDLG_GENERIC
1467
13188def 1468#if wxUSE_DIRDLG
f09c8393 1469void MyFrame::DoDirChoose(int style)
457814b5 1470{
3f2711d5
VZ
1471 // pass some initial dir to wxDirDialog
1472 wxString dirHome;
1473 wxGetHomeDir(&dirHome);
1474
9a83f860 1475 wxDirDialog dialog(this, wxT("Testing directory picker"), dirHome, style);
c50f1fb9
VZ
1476
1477 if (dialog.ShowModal() == wxID_OK)
1478 {
9a83f860 1479 wxLogMessage(wxT("Selected path: %s"), dialog.GetPath().c_str());
c50f1fb9
VZ
1480 }
1481}
1482
f09c8393
VZ
1483void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
1484{
ff3e84ff 1485 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST);
f09c8393
VZ
1486}
1487
1488void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
1489{
ff3e84ff 1490 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_DIR_MUST_EXIST);
f09c8393 1491}
13188def 1492#endif // wxUSE_DIRDLG
f09c8393 1493
13188def 1494#if USE_DIRDLG_GENERIC
51a58d8b
JS
1495void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
1496{
1497 // pass some initial dir to wxDirDialog
1498 wxString dirHome;
1499 wxGetHomeDir(&dirHome);
1500
9a83f860 1501 wxGenericDirDialog dialog(this, wxT("Testing generic directory picker"), dirHome);
51a58d8b
JS
1502
1503 if (dialog.ShowModal() == wxID_OK)
1504 {
9a83f860 1505 wxMessageDialog dialog2(this, dialog.GetPath(), wxT("Selected path"));
51a58d8b
JS
1506 dialog2.ShowModal();
1507 }
1508}
13188def 1509#endif // USE_DIRDLG_GENERIC
51a58d8b 1510
13188def 1511#if USE_MODAL_PRESENTATION
f6bcfd97
BP
1512void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
1513{
1514 MyModalDialog dlg(this);
1515 dlg.ShowModal();
1516}
1baa0a9d 1517#endif // USE_MODAL_PRESENTATION
f6bcfd97 1518
4c45f240
VZ
1519void MyFrame::ModelessDlg(wxCommandEvent& event)
1520{
2f82899b 1521 bool show = GetMenuBar()->IsChecked(event.GetId());
4c45f240
VZ
1522
1523 if ( show )
1524 {
1525 if ( !m_dialog )
1526 {
1527 m_dialog = new MyModelessDialog(this);
1528 }
1529
13188def 1530 m_dialog->Show(true);
4c45f240
VZ
1531 }
1532 else // hide
1533 {
26a12ab3
JS
1534 // If m_dialog is NULL, then possibly the system
1535 // didn't report the checked menu item status correctly.
1536 // It should be true just after the menu item was selected,
1537 // if there was no modeless dialog yet.
1538
1539 wxASSERT( m_dialog != NULL );
1540 if (m_dialog)
1541 m_dialog->Hide();
4c45f240
VZ
1542 }
1543}
cae50e6b
VZ
1544
1545void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event))
1546{
9a83f860 1547 wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on screen"),
cae50e6b 1548 wxDefaultPosition, wxSize(200, 100));
9a83f860 1549 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
cae50e6b
VZ
1550 dlg.CentreOnScreen();
1551 dlg.ShowModal();
1552}
1553
1554void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event))
1555{
9a83f860 1556 wxDialog dlg(this, wxID_ANY, wxT("Dialog centered on parent"),
cae50e6b 1557 wxDefaultPosition, wxSize(200, 100));
9a83f860 1558 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
cae50e6b
VZ
1559 dlg.CentreOnParent();
1560 dlg.ShowModal();
1561}
1562
81496fea 1563#if wxUSE_MINIFRAME
1baa0a9d
VZ
1564void MyFrame::MiniFrame(wxCommandEvent& WXUNUSED(event))
1565{
9a83f860 1566 wxFrame *frame = new wxMiniFrame(this, wxID_ANY, wxT("Mini frame"),
1baa0a9d
VZ
1567 wxDefaultPosition, wxSize(300, 100),
1568 wxCAPTION | wxCLOSE_BOX);
1569 new wxStaticText(frame,
1570 wxID_ANY,
9a83f860 1571 wxT("Mini frames have slightly different appearance"),
1baa0a9d
VZ
1572 wxPoint(5, 5));
1573 new wxStaticText(frame,
1574 wxID_ANY,
9a83f860 1575 wxT("from the normal frames but that's the only difference."),
1baa0a9d
VZ
1576 wxPoint(5, 25));
1577
1578 frame->CentreOnParent();
1579 frame->Show();
1580}
81496fea 1581#endif // wxUSE_MINIFRAME
4c45f240 1582
8e5dbcdd
VZ
1583void MyFrame::DlgOnTop(wxCommandEvent& WXUNUSED(event))
1584{
9a83f860 1585 wxDialog dlg(this, wxID_ANY, wxT("Dialog staying on top of other windows"),
8e5dbcdd
VZ
1586 wxDefaultPosition, wxSize(300, 100),
1587 wxDEFAULT_DIALOG_STYLE | wxSTAY_ON_TOP);
9a83f860 1588 (new wxButton(&dlg, wxID_OK, wxT("Close")))->Centre();
8e5dbcdd
VZ
1589 dlg.ShowModal();
1590}
1591
13188def 1592#if wxUSE_STARTUP_TIPS
87728739 1593void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event))
c50f1fb9
VZ
1594{
1595 static size_t s_index = (size_t)-1;
1596
1597 if ( s_index == (size_t)-1 )
1598 {
1599 srand(time(NULL));
1600
1601 // this is completely bogus, we don't know how many lines are there
1602 // in the file, but who cares, it's a demo only...
1603 s_index = rand() % 5;
1604 }
1605
9a83f860 1606 wxTipProvider *tipProvider = wxCreateFileTipProvider(wxT("tips.txt"), s_index);
c50f1fb9
VZ
1607
1608 bool showAtStartup = wxShowTip(this, tipProvider);
1609
1610 if ( showAtStartup )
1611 {
9a83f860 1612 wxMessageBox(wxT("Will show tips on startup"), wxT("Tips dialog"),
c50f1fb9
VZ
1613 wxOK | wxICON_INFORMATION, this);
1614 }
457814b5 1615
c50f1fb9
VZ
1616 s_index = tipProvider->GetCurrentTip();
1617 delete tipProvider;
457814b5 1618}
13188def 1619#endif // wxUSE_STARTUP_TIPS
457814b5 1620
532d575b 1621#if USE_SETTINGS_DIALOG
64d3ed17 1622void MyFrame::OnPropertySheet(wxCommandEvent& event)
0f5d8ecf 1623{
64d3ed17 1624 SettingsDialog dialog(this, event.GetId());
cc8bc5aa
JS
1625 dialog.ShowModal();
1626}
532d575b 1627#endif // USE_SETTINGS_DIALOG
0f5d8ecf 1628
9b16ffef
VZ
1629void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event))
1630{
9a83f860 1631 wxLogStatus(wxT("Sleeping for 3 seconds to allow you to switch to another window"));
9b16ffef
VZ
1632
1633 wxSleep(3);
1634
1635 RequestUserAttention(wxUSER_ATTENTION_ERROR);
1636}
1637
e36a1739
VZ
1638#if wxUSE_NOTIFICATION_MESSAGE
1639
1640void MyFrame::OnNotifMsgAuto(wxCommandEvent& WXUNUSED(event))
1641{
1642 if ( !wxNotificationMessage
1643 (
1644 "Automatic Notification",
1645 "Nothing important has happened\n"
1646 "this notification will disappear soon."
1647 ).Show() )
1648 {
1649 wxLogStatus("Failed to show notification message");
1650 }
1651}
1652
1653void MyFrame::OnNotifMsgShow(wxCommandEvent& WXUNUSED(event))
1654{
1655 if ( !m_notifMsg )
1656 {
1657 m_notifMsg = new wxNotificationMessage
1658 (
1659 "wxWidgets Manual Notification",
1660 "You can hide this notification from the menu",
1661 this
1662 );
1663 }
1664
1665 if ( !m_notifMsg->Show(wxNotificationMessage::Timeout_Never) )
1666 {
1667 wxLogStatus("Failed to show manual notification message");
1668 }
1669}
1670
1671void MyFrame::OnNotifMsgHide(wxCommandEvent& WXUNUSED(event))
1672{
af588446 1673 if ( m_notifMsg && !m_notifMsg->Close() )
e36a1739 1674 {
af588446 1675 wxLogStatus("Failed to hide manual notification message");
e36a1739
VZ
1676 }
1677}
1678
1679#endif // wxUSE_NOTIFICATION_MESSAGE
1680
8e1dac82
VZ
1681void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
1682{
1683 StdButtonSizerDialog dialog(this);
1684 dialog.ShowModal();
1685}
1686
a625c5b6
RR
1687// TestDefaultAction
1688
1689#define ID_CATCH_LISTBOX_DCLICK 100
1690#define ID_LISTBOX 101
1691
1692BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
1693 EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK, TestDefaultActionDialog::OnCatchListBoxDClick)
1694 EVT_LISTBOX_DCLICK(ID_LISTBOX, TestDefaultActionDialog::OnListBoxDClick)
1695END_EVENT_TABLE()
1696
1697TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
1698 wxDialog( parent, -1, "Test default action" )
1699{
1700 m_catchListBoxDClick = false;
1701
1702 wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
44b25eac 1703
a625c5b6 1704 wxFlexGridSizer *grid_sizer = new wxFlexGridSizer( 2, 5, 5 );
44b25eac 1705
81496fea 1706#if wxUSE_LISTBOX
a625c5b6
RR
1707 wxListBox *listbox = new wxListBox( this, ID_LISTBOX );
1708 listbox->Append( "String 1" );
1709 listbox->Append( "String 2" );
1710 listbox->Append( "String 3" );
1711 listbox->Append( "String 4" );
1712 grid_sizer->Add( listbox );
81496fea 1713#endif // wxUSE_LISTBOX
44b25eac 1714
a625c5b6 1715 grid_sizer->Add( new wxCheckBox( this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox" ), 0, wxALIGN_CENTRE_VERTICAL );
44b25eac 1716
a625c5b6
RR
1717 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), 0 ), 0, wxALIGN_CENTRE_VERTICAL );
1718 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl without wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
44b25eac 1719
a625c5b6
RR
1720 grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
1721 grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
44b25eac 1722
a625c5b6 1723 main_sizer->Add( grid_sizer, 0, wxALL, 10 );
44b25eac 1724
a625c5b6
RR
1725 wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
1726 if (button_sizer)
1727 main_sizer->Add( button_sizer, 0, wxALL|wxGROW, 5 );
44b25eac 1728
8ce68f7f 1729 SetSizerAndFit( main_sizer );
a625c5b6 1730}
44b25eac 1731
a625c5b6
RR
1732void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
1733{
1734 event.Skip( !m_catchListBoxDClick );
1735}
1736
1737void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(event))
1738{
1739 m_catchListBoxDClick = !m_catchListBoxDClick;
1740}
1741
1742void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
1743{
1744 TestDefaultActionDialog dialog( this );
1745 dialog.ShowModal();
1746}
1747
d355d3fe 1748void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
457814b5 1749{
13188def 1750 Close(true);
457814b5
JS
1751}
1752
abceee76
VZ
1753#if wxUSE_PROGRESSDLG
1754
1755void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
1756{
b2c782f2 1757 static const int max = 100;
abceee76 1758
9a83f860
VZ
1759 wxProgressDialog dialog(wxT("Progress dialog example"),
1760 wxT("An informative message"),
abceee76
VZ
1761 max, // range
1762 this, // parent
1763 wxPD_CAN_ABORT |
ecda9475 1764 wxPD_CAN_SKIP |
abceee76 1765 wxPD_APP_MODAL |
df26c4c6 1766 // wxPD_AUTO_HIDE | -- try this as well
abceee76
VZ
1767 wxPD_ELAPSED_TIME |
1768 wxPD_ESTIMATED_TIME |
f4aa7ec3 1769 wxPD_REMAINING_TIME
b2c782f2 1770 | wxPD_SMOOTH // - makes indeterminate mode bar on WinXP very small
f4aa7ec3 1771 );
abceee76 1772
13188def 1773 bool cont = true;
b2c782f2 1774 for ( int i = 0; i <= max; i++ )
abceee76 1775 {
b2c782f2 1776 wxMilliSleep(200);
ecda9475
WS
1777
1778 wxString msg;
1779
b2c782f2
VZ
1780 // test both modes of wxProgressDialog behaviour: start in
1781 // indeterminate mode but switch to the determinate one later
1782 const bool determinate = i > max/2;
f4aa7ec3 1783
abceee76
VZ
1784 if ( i == max )
1785 {
9a83f860 1786 msg = wxT("That's all, folks!");
abceee76 1787 }
b2c782f2 1788 else if ( !determinate )
f4aa7ec3 1789 {
9a83f860 1790 msg = wxT("Testing indeterminate mode");
f4aa7ec3 1791 }
b2c782f2 1792 else if ( determinate )
abceee76 1793 {
9a83f860 1794 msg = wxT("Now in standard determinate mode");
abceee76 1795 }
ecda9475 1796
b2c782f2
VZ
1797 // will be set to true if "Skip" button was pressed
1798 bool skip = false;
1799 if ( determinate )
abceee76 1800 {
ecda9475 1801 cont = dialog.Update(i, msg, &skip);
abceee76 1802 }
f4aa7ec3
VZ
1803 else
1804 {
f4aa7ec3 1805 cont = dialog.Pulse(msg, &skip);
f4aa7ec3 1806 }
ecda9475 1807
b2c782f2
VZ
1808 // each skip will move progress about quarter forward
1809 if ( skip )
1810 i += max/4;
1811
d8ddee9c
VZ
1812 if ( !cont )
1813 {
9a83f860
VZ
1814 if ( wxMessageBox(wxT("Do you really want to cancel?"),
1815 wxT("Progress dialog question"), // caption
78a189c9 1816 wxYES_NO | wxICON_QUESTION) == wxYES )
d8ddee9c
VZ
1817 break;
1818
9b16ffef 1819 cont = true;
d8ddee9c
VZ
1820 dialog.Resume();
1821 }
abceee76
VZ
1822 }
1823
1824 if ( !cont )
1825 {
4693b20c 1826 wxLogStatus(wxT("Progress dialog aborted!"));
abceee76
VZ
1827 }
1828 else
1829 {
4693b20c 1830 wxLogStatus(wxT("Countdown from %d finished"), max);
abceee76
VZ
1831 }
1832}
1833
1834#endif // wxUSE_PROGRESSDLG
1835
ca7adbf8
VZ
1836#if wxUSE_ABOUTDLG
1837
453c9e3b 1838static void InitAboutInfoMinimal(wxAboutDialogInfo& info)
ca7adbf8 1839{
9a83f860 1840 info.SetName(wxT("Dialogs Sample"));
704006b3
VZ
1841 info.SetVersion(wxVERSION_NUM_DOT_STRING,
1842 wxString::Format
1843 (
1844 "%s version %s",
1845 wxMINOR_VERSION % 2 ? "Development" : "Stable",
1846 wxVERSION_NUM_DOT_STRING
1847 ));
9a83f860
VZ
1848 info.SetDescription(wxT("This sample shows different wxWidgets dialogs"));
1849 info.SetCopyright(wxT("(C) 1998-2006 wxWidgets dev team"));
1850 info.AddDeveloper(wxT("Vadim Zeitlin"));
ca7adbf8
VZ
1851}
1852
453c9e3b
VZ
1853static void InitAboutInfoWebsite(wxAboutDialogInfo& info)
1854{
1855 InitAboutInfoMinimal(info);
1856
9a83f860 1857 info.SetWebSite(wxT("http://www.wxwidgets.org/"), wxT("wxWidgets web site"));
453c9e3b
VZ
1858}
1859
1860static void InitAboutInfoAll(wxAboutDialogInfo& info)
1861{
20fe9c5a 1862 InitAboutInfoWebsite(info);
453c9e3b
VZ
1863
1864 // we can add a second developer
9a83f860 1865 info.AddDeveloper(wxT("A.N. Other"));
453c9e3b
VZ
1866
1867 // or we can add several persons at once like this
1868 static const wxChar *docwriters[] =
1869 {
9a83f860
VZ
1870 wxT("First D. Writer"),
1871 wxT("Second One"),
453c9e3b
VZ
1872 };
1873
1874 info.SetDocWriters(wxArrayString(WXSIZEOF(docwriters), docwriters));
1875 info.SetLicence(wxString::FromAscii(
1876" wxWindows Library Licence, Version 3.1\n"
1877" ======================================\n"
1878"\n"
1879" Copyright (c) 1998-2005 Julian Smart, Robert Roebling et al\n"
1880"\n"
1881" Everyone is permitted to copy and distribute verbatim copies\n"
1882" of this licence document, but changing it is not allowed.\n"
1883"\n"
1884" WXWINDOWS LIBRARY LICENCE\n"
1885" TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n"
1886"\n"
1887" ...and so on and so forth...\n"
1888 ));
fb4f85bf 1889
9a83f860 1890 info.AddTranslator(wxT("Wun Ngo Wen (Martian)"));
453c9e3b
VZ
1891}
1892
ca7adbf8
VZ
1893void MyFrame::ShowSimpleAboutDialog(wxCommandEvent& WXUNUSED(event))
1894{
1895 wxAboutDialogInfo info;
453c9e3b 1896 InitAboutInfoMinimal(info);
ca7adbf8 1897
c173e541 1898 wxAboutBox(info, this);
ca7adbf8
VZ
1899}
1900
1901void MyFrame::ShowFancyAboutDialog(wxCommandEvent& WXUNUSED(event))
1902{
1903 wxAboutDialogInfo info;
453c9e3b 1904 InitAboutInfoWebsite(info);
ca7adbf8 1905
c173e541 1906 wxAboutBox(info, this);
ca7adbf8
VZ
1907}
1908
453c9e3b
VZ
1909void MyFrame::ShowFullAboutDialog(wxCommandEvent& WXUNUSED(event))
1910{
1911 wxAboutDialogInfo info;
1912 InitAboutInfoAll(info);
1913
c173e541 1914 wxAboutBox(info, this);
453c9e3b
VZ
1915}
1916
1dcfc333
VZ
1917// a trivial example of a custom dialog class
1918class MyAboutDialog : public wxGenericAboutDialog
453c9e3b 1919{
1dcfc333 1920public:
c173e541 1921 MyAboutDialog(const wxAboutDialogInfo& info, wxWindow* parent)
453c9e3b 1922 {
c173e541 1923 Create(info, parent);
1dcfc333 1924 }
453c9e3b 1925
1dcfc333
VZ
1926 // add some custom controls
1927 virtual void DoAddCustomControls()
1928 {
1929 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
9a83f860 1930 AddText(wxT("Some custom text"));
1dcfc333
VZ
1931 AddControl(new wxStaticLine(this), wxSizerFlags().Expand());
1932 }
1933};
453c9e3b 1934
1dcfc333
VZ
1935void MyFrame::ShowCustomAboutDialog(wxCommandEvent& WXUNUSED(event))
1936{
453c9e3b
VZ
1937 wxAboutDialogInfo info;
1938 InitAboutInfoAll(info);
1939
c173e541 1940 MyAboutDialog dlg(info, this);
453c9e3b
VZ
1941 dlg.ShowModal();
1942}
1943
ca7adbf8
VZ
1944#endif // wxUSE_ABOUTDLG
1945
a62b0bcc
VZ
1946#if wxUSE_BUSYINFO
1947
1948void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
1949{
21977bac
VZ
1950 wxWindowDisabler disableAll;
1951
9a83f860 1952 wxBusyInfo info(wxT("Working, please wait..."), this);
a62b0bcc 1953
5b636c67 1954 for ( int i = 0; i < 18; i++ )
a62b0bcc 1955 {
f2335ba5 1956 wxMilliSleep(100);
a62b0bcc
VZ
1957 wxTheApp->Yield();
1958 }
5b636c67
VZ
1959
1960 wxSleep(2);
1961 //wxWakeUpIdle();
a62b0bcc
VZ
1962}
1963
1964#endif // wxUSE_BUSYINFO
1965
761989ff
VZ
1966#if wxUSE_FINDREPLDLG
1967
1968void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
1969{
14fca738
VZ
1970 if ( m_dlgReplace )
1971 {
5276b0a5 1972 wxDELETE(m_dlgReplace);
14fca738
VZ
1973 }
1974 else
1975 {
1976 m_dlgReplace = new wxFindReplaceDialog
1977 (
1978 this,
1979 &m_findData,
9a83f860 1980 wxT("Find and replace dialog"),
14fca738
VZ
1981 wxFR_REPLACEDIALOG
1982 );
1983
13188def 1984 m_dlgReplace->Show(true);
14fca738 1985 }
761989ff
VZ
1986}
1987
1988void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
1989{
14fca738
VZ
1990 if ( m_dlgFind )
1991 {
5276b0a5 1992 wxDELETE(m_dlgFind);
14fca738
VZ
1993 }
1994 else
1995 {
1996 m_dlgFind = new wxFindReplaceDialog
1997 (
1998 this,
1999 &m_findData,
9a83f860 2000 wxT("Find dialog"),
14fca738
VZ
2001 // just for testing
2002 wxFR_NOWHOLEWORD
2003 );
2004
13188def 2005 m_dlgFind->Show(true);
14fca738 2006 }
761989ff
VZ
2007}
2008
2009static wxString DecodeFindDialogEventFlags(int flags)
2010{
2011 wxString str;
9a83f860
VZ
2012 str << (flags & wxFR_DOWN ? wxT("down") : wxT("up")) << wxT(", ")
2013 << (flags & wxFR_WHOLEWORD ? wxT("whole words only, ") : wxT(""))
2014 << (flags & wxFR_MATCHCASE ? wxT("") : wxT("not "))
2015 << wxT("case sensitive");
761989ff
VZ
2016
2017 return str;
2018}
2019
2020void MyFrame::OnFindDialog(wxFindDialogEvent& event)
2021{
2022 wxEventType type = event.GetEventType();
2023
2024 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
2025 {
4693b20c 2026 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
eba33006 2027 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
761989ff
VZ
2028 event.GetFindString().c_str(),
2029 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
2030 }
2031 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
2032 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
2033 {
4693b20c 2034 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
9a83f860 2035 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? wxT("all ") : wxT(""),
761989ff
VZ
2036 event.GetFindString().c_str(),
2037 event.GetReplaceString().c_str(),
2038 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
2039 }
2040 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
2041 {
14fca738
VZ
2042 wxFindReplaceDialog *dlg = event.GetDialog();
2043
df26c4c6 2044 int idMenu;
14fca738
VZ
2045 const wxChar *txt;
2046 if ( dlg == m_dlgFind )
2047 {
9a83f860 2048 txt = wxT("Find");
df26c4c6 2049 idMenu = DIALOGS_FIND;
14fca738
VZ
2050 m_dlgFind = NULL;
2051 }
2052 else if ( dlg == m_dlgReplace )
2053 {
9a83f860 2054 txt = wxT("Replace");
df26c4c6 2055 idMenu = DIALOGS_REPLACE;
14fca738
VZ
2056 m_dlgReplace = NULL;
2057 }
2058 else
2059 {
9a83f860 2060 txt = wxT("Unknown");
13188def 2061 idMenu = wxID_ANY;
14fca738 2062
9a83f860 2063 wxFAIL_MSG( wxT("unexpected event") );
14fca738
VZ
2064 }
2065
df26c4c6
VZ
2066 wxLogMessage(wxT("%s dialog is being closed."), txt);
2067
13188def 2068 if ( idMenu != wxID_ANY )
df26c4c6 2069 {
13188def 2070 GetMenuBar()->Check(idMenu, false);
df26c4c6 2071 }
761989ff 2072
14fca738 2073 dlg->Destroy();
761989ff
VZ
2074 }
2075 else
2076 {
4693b20c 2077 wxLogError(wxT("Unknown find dialog event!"));
761989ff
VZ
2078 }
2079}
2080
2081#endif // wxUSE_FINDREPLDLG
2082
abceee76
VZ
2083// ----------------------------------------------------------------------------
2084// MyCanvas
2085// ----------------------------------------------------------------------------
2086
d355d3fe 2087void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
457814b5 2088{
c50f1fb9 2089 wxPaintDC dc(this);
457814b5 2090 dc.SetBackgroundMode(wxTRANSPARENT);
dc96b1b6 2091 dc.DrawText(
9a83f860 2092 wxT("wxWidgets common dialogs")
dc96b1b6 2093#if !defined(__SMARTPHONE__)
9a83f860 2094 wxT(" test application")
dc96b1b6
WS
2095#endif
2096 , 10, 10);
457814b5
JS
2097}
2098
b4954d19
WS
2099#if USE_MODAL_PRESENTATION
2100
4c45f240
VZ
2101// ----------------------------------------------------------------------------
2102// MyModelessDialog
2103// ----------------------------------------------------------------------------
457814b5 2104
4c45f240 2105MyModelessDialog::MyModelessDialog(wxWindow *parent)
9a83f860 2106 : wxDialog(parent, wxID_ANY, wxString(wxT("Modeless dialog")))
4c45f240 2107{
cbc66a27
VZ
2108 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
2109
9a83f860
VZ
2110 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, wxT("Press me"));
2111 wxCheckBox *check = new wxCheckBox(this, wxID_ANY, wxT("Should be disabled"));
cbc66a27
VZ
2112 check->Disable();
2113
2114 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
2115 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
2116
8ce68f7f 2117 SetSizerAndFit(sizerTop);
4c45f240 2118}
abceee76 2119
5d987909
VZ
2120void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
2121{
9a83f860 2122 wxMessageBox(wxT("Button pressed in modeless dialog"), wxT("Info"),
5d987909
VZ
2123 wxOK | wxICON_INFORMATION, this);
2124}
2125
abceee76
VZ
2126void MyModelessDialog::OnClose(wxCloseEvent& event)
2127{
2128 if ( event.CanVeto() )
2129 {
9a83f860
VZ
2130 wxMessageBox(wxT("Use the menu item to close this dialog"),
2131 wxT("Modeless dialog"),
abceee76
VZ
2132 wxOK | wxICON_INFORMATION, this);
2133
2134 event.Veto();
2135 }
2136}
2137
f6bcfd97
BP
2138// ----------------------------------------------------------------------------
2139// MyModalDialog
2140// ----------------------------------------------------------------------------
2141
2142MyModalDialog::MyModalDialog(wxWindow *parent)
9a83f860 2143 : wxDialog(parent, wxID_ANY, wxString(wxT("Modal dialog")))
f6bcfd97
BP
2144{
2145 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
2146
9a83f860
VZ
2147 m_btnModal = new wxButton(this, wxID_ANY, wxT("&Modal dialog..."));
2148 m_btnModeless = new wxButton(this, wxID_ANY, wxT("Mode&less dialog"));
2149 m_btnDelete = new wxButton(this, wxID_ANY, wxT("&Delete button"));
5315ebfa 2150
5315ebfa
VZ
2151 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
2152 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 2153 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
5a58a134 2154 sizerTop->Add(new wxButton(this, wxID_CLOSE), 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 2155
8ce68f7f 2156 SetSizerAndFit(sizerTop);
f6bcfd97 2157
5a58a134
VZ
2158 SetEscapeId(wxID_CLOSE);
2159
5315ebfa
VZ
2160 m_btnModal->SetFocus();
2161 m_btnModal->SetDefault();
f6bcfd97
BP
2162}
2163
2164void MyModalDialog::OnButton(wxCommandEvent& event)
2165{
2166 if ( event.GetEventObject() == m_btnDelete )
2167 {
5276b0a5 2168 wxDELETE(m_btnModal);
f6bcfd97
BP
2169 m_btnDelete->Disable();
2170 }
5315ebfa 2171 else if ( event.GetEventObject() == m_btnModal )
f6bcfd97 2172 {
13188def 2173#if wxUSE_TEXTDLG
9a83f860
VZ
2174 wxGetTextFromUser(wxT("Dummy prompt"),
2175 wxT("Modal dialog called from dialog"),
dabbc6a5 2176 wxEmptyString, this);
13188def 2177#else
9a83f860 2178 wxMessageBox(wxT("Modal dialog called from dialog"));
13188def 2179#endif // wxUSE_TEXTDLG
f6bcfd97 2180 }
5315ebfa
VZ
2181 else if ( event.GetEventObject() == m_btnModeless )
2182 {
2183 (new MyModelessDialog(this))->Show();
2184 }
f6bcfd97
BP
2185 else
2186 {
2187 event.Skip();
2188 }
2189}
b4954d19
WS
2190
2191#endif // USE_MODAL_PRESENTATION
2192
8e1dac82
VZ
2193// ----------------------------------------------------------------------------
2194// StdButtonSizerDialog
2195// ----------------------------------------------------------------------------
2196
2197StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent)
9a83f860 2198 : wxDialog(parent, wxID_ANY, wxString(wxT("StdButtonSizer dialog")),
8e1dac82
VZ
2199 wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER),
2200 m_buttonsSizer(NULL)
2201{
2202 wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL);
2203
2204 wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL);
2205 wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL);
2206
2207 m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button"));
2208
2209 wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button"));
2210
2211 m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2212 m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes"));
2213
2214 wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL);
2215
2216 m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button"));
2217
2218 wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button"));
2219
2220 m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
2221 m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close"));
2222
2223 wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL);
2224
2225 m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No"));
2226 m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help"));
2227 m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply"));
2228
2229 m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default"));
2230
2231 sizer1->Add(m_radiobtnOk, 0, wxALL, 5);
2232 sizer1->Add(m_radiobtnYes, 0, wxALL, 5);
2233
2234 sizer->Add(sizerInside1, 0, 0, 0);
2235 sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5);
2236 sizerInside1->Add(sizer1, 0, wxALL, 5);
2237 sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2238
2239 sizer2->Add(m_radiobtnCancel, 0, wxALL, 5);
2240 sizer2->Add(m_radiobtnClose, 0, wxALL, 5);
2241
2242 sizer->Add(sizerInside2, 0, 0, 0);
2243 sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5);
2244 sizerInside2->Add(sizer2, 0, wxALL, 5);
2245 sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label
2246
2247 sizerTop->Add(sizer, 0, wxALL, 5);
2248
2249 sizer3->Add(m_chkboxNo, 0, wxALL, 5);
2250 sizer3->Add(m_chkboxHelp, 0, wxALL, 5);
2251 sizer3->Add(m_chkboxApply, 0, wxALL, 5);
2252
2253 sizerTop->Add(sizer3, 0, wxALL, 5);
2254
2255 sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10);
2256
2257 EnableDisableControls();
2258
8ce68f7f 2259 SetSizerAndFit(sizerTop);
8e1dac82 2260
8e1dac82
VZ
2261 wxCommandEvent ev;
2262 OnEvent(ev);
2263}
2264
2265void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event))
2266{
2267 if (m_buttonsSizer)
2268 {
2269 m_buttonsSizer->DeleteWindows();
2270 GetSizer()->Remove(m_buttonsSizer);
2271 }
2272
2273 EnableDisableControls();
2274
2275 long flags = 0;
2276 unsigned long numButtons = 0;
2277
2278 if (m_chkboxAffirmativeButton->IsChecked())
2279 {
2280 if (m_radiobtnOk->GetValue())
2281 {
2282 flags |= wxOK;
2283 numButtons ++;
2284 }
2285 else if (m_radiobtnYes->GetValue())
2286 {
2287 flags |= wxYES;
2288 numButtons ++;
2289 }
2290 }
2291
2292 if (m_chkboxDismissButton->IsChecked())
2293 {
2294 if (m_radiobtnCancel->GetValue())
2295 {
2296 flags |= wxCANCEL;
2297 numButtons ++;
2298 }
2299
2300 else if (m_radiobtnClose->GetValue())
2301 {
2302 flags |= wxCLOSE;
2303 numButtons ++;
2304 }
2305
2306 }
2307
2308 if (m_chkboxApply->IsChecked())
2309 {
2310 flags |= wxAPPLY;
2311 numButtons ++;
2312 }
2313
2314 if (m_chkboxNo->IsChecked())
2315 {
2316 flags |= wxNO;
2317 numButtons ++;
2318 }
2319
2320 if (m_chkboxHelp->IsChecked())
2321 {
2322 flags |= wxHELP;
2323 numButtons ++;
2324 }
2325
2326 if (m_chkboxNoDefault->IsChecked())
2327 {
2328 flags |= wxNO_DEFAULT;
2329 }
2330
2331 m_buttonsSizer = CreateStdDialogButtonSizer(flags);
2332 GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5);
2333
2334 Layout();
2335 GetSizer()->SetSizeHints(this);
2336}
2337
2338void StdButtonSizerDialog::EnableDisableControls()
2339{
2340 const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked();
2341
2342 m_radiobtnOk->Enable(affButtonEnabled);
2343 m_radiobtnYes->Enable(affButtonEnabled);
2344
2345 const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked();
2346
2347 m_radiobtnCancel->Enable(dismissButtonEnabled);
2348 m_radiobtnClose->Enable(dismissButtonEnabled);
2349}
2350
532d575b 2351#if USE_SETTINGS_DIALOG
0f5d8ecf
JS
2352// ----------------------------------------------------------------------------
2353// SettingsDialog
2354// ----------------------------------------------------------------------------
2355
2356IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog)
2357
2358BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog)
2359END_EVENT_TABLE()
2360
64d3ed17 2361SettingsDialog::SettingsDialog(wxWindow* win, int dialogType)
0f5d8ecf 2362{
0f4991f4 2363 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY);
0f5d8ecf 2364
cc8bc5aa
JS
2365 int tabImage1 = -1;
2366 int tabImage2 = -1;
e031f1df 2367
64d3ed17 2368 bool useToolBook = (dialogType == DIALOGS_PROPERTY_SHEET_TOOLBOOK || dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK);
77631b1d 2369 int resizeBorder = wxRESIZE_BORDER;
684883e3 2370
cc8bc5aa
JS
2371 if (useToolBook)
2372 {
77631b1d 2373 resizeBorder = 0;
cc8bc5aa
JS
2374 tabImage1 = 0;
2375 tabImage2 = 1;
e031f1df 2376
64d3ed17
JS
2377 int sheetStyle = wxPROPSHEET_SHRINKTOFIT;
2378 if (dialogType == DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK)
2379 sheetStyle |= wxPROPSHEET_BUTTONTOOLBOOK;
2380 else
2381 sheetStyle |= wxPROPSHEET_TOOLBOOK;
e031f1df 2382
64d3ed17 2383 SetSheetStyle(sheetStyle);
77631b1d
JS
2384 SetSheetInnerBorder(0);
2385 SetSheetOuterBorder(0);
cc8bc5aa
JS
2386
2387 // create a dummy image list with a few icons
2388 const wxSize imageSize(32, 32);
2389
2390 m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight());
2391 m_imageList->
2392 Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize));
2393 m_imageList->
2394 Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize));
2395 m_imageList->
2396 Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize));
2397 m_imageList->
2398 Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize));
2399 }
2400 else
2401 m_imageList = NULL;
2402
532d575b 2403 Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize,
654ffe9f 2404 wxDEFAULT_DIALOG_STYLE| (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, resizeBorder)
3103e8a9 2405 );
cc8bc5aa 2406
684883e3 2407 // If using a toolbook, also follow Mac style and don't create buttons
cc8bc5aa 2408 if (!useToolBook)
654ffe9f
VZ
2409 CreateButtons(wxOK | wxCANCEL |
2410 (int)wxPlatform::IfNot(wxOS_WINDOWS_CE, wxHELP)
897b24cf 2411 );
0f5d8ecf
JS
2412
2413 wxBookCtrlBase* notebook = GetBookCtrl();
cc8bc5aa 2414 notebook->SetImageList(m_imageList);
0f5d8ecf
JS
2415
2416 wxPanel* generalSettings = CreateGeneralSettingsPage(notebook);
2417 wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook);
2418
cc8bc5aa
JS
2419 notebook->AddPage(generalSettings, _("General"), true, tabImage1);
2420 notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2);
0f5d8ecf
JS
2421
2422 LayoutDialog();
2423}
2424
cc8bc5aa
JS
2425SettingsDialog::~SettingsDialog()
2426{
2427 delete m_imageList;
2428}
2429
0f5d8ecf
JS
2430wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent)
2431{
2432 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2433
2434 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2435 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2436
2437 //// LOAD LAST FILE
2438
2439 wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL );
2440 wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize);
2441 itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2442 item0->Add(itemSizer3, 0, wxGROW|wxALL, 0);
2443
2444 //// AUTOSAVE
2445
2446 wxString autoSaveLabel = _("&Auto-save every");
2447 wxString minsLabel = _("mins");
2448
2449 wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL );
2450 wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize);
62675ef3
JS
2451
2452#if wxUSE_SPINCTRL
0f5d8ecf 2453 wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString,
532d575b 2454 wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1);
62675ef3 2455#endif
532d575b 2456
0f5d8ecf 2457 itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 2458#if wxUSE_SPINCTRL
0f5d8ecf 2459 itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
62675ef3 2460#endif
0f5d8ecf
JS
2461 itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2462 item0->Add(itemSizer12, 0, wxGROW|wxALL, 0);
2463
2464 //// TOOLTIPS
532d575b 2465
0f5d8ecf
JS
2466 wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL );
2467 wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize);
2468 itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2469 item0->Add(itemSizer8, 0, wxGROW|wxALL, 0);
2470
2471 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
2472
8ce68f7f 2473 panel->SetSizerAndFit(topSizer);
532d575b 2474
0f5d8ecf
JS
2475 return panel;
2476}
2477
2478wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
2479{
2480 wxPanel* panel = new wxPanel(parent, wxID_ANY);
2481
2482 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
2483 wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL );
2484
2485 //// PROJECT OR GLOBAL
2486 wxString globalOrProjectChoices[2];
2487 globalOrProjectChoices[0] = _("&New projects");
2488 globalOrProjectChoices[1] = _("&This project");
2489
2490 wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"),
2491 wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices);
2492 item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5);
2493
2494 projectOrGlobal->SetSelection(0);
2495
2496 //// BACKGROUND STYLE
2497 wxArrayString backgroundStyleChoices;
2498 backgroundStyleChoices.Add(wxT("Colour"));
2499 backgroundStyleChoices.Add(wxT("Image"));
532d575b 2500 wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:"));
0f5d8ecf
JS
2501
2502 wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL );
2503 item0->Add(styleSizer, 0, wxGROW|wxALL, 5);
2504
2505 wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL );
2506
2507 wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices);
2508
2509 itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2510 itemSizer2->Add(5, 5, 1, wxALL, 0);
2511 itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
2512
2513 styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5);
2514
62675ef3 2515#if wxUSE_SPINCTRL
0f5d8ecf
JS
2516 //// FONT SIZE SELECTION
2517
532d575b 2518 wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:"));
0f5d8ecf
JS
2519 wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL );
2520
2521 wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition,
532d575b 2522 wxSize(80, wxDefaultCoord));
0f5d8ecf
JS
2523 itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
2524
2525 item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5);
62675ef3 2526#endif
0f5d8ecf
JS
2527
2528 topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 );
0f4991f4 2529 topSizer->AddSpacer(5);
0f5d8ecf 2530
8ce68f7f 2531 panel->SetSizerAndFit(topSizer);
532d575b 2532
0f5d8ecf
JS
2533 return panel;
2534}
2535
a1bdd4ab
VZ
2536#endif // USE_SETTINGS_DIALOG
2537
2538#if wxUSE_MSGDLG
44b25eac
VZ
2539// ----------------------------------------------------------------------------
2540// TestMessageBoxDialog
2541// ----------------------------------------------------------------------------
2542
b3ca7c85
VZ
2543/* static */
2544const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
44b25eac
VZ
2545{
2546 { wxYES, "&Yes" },
2547 { wxNO, "&No" },
2548 { wxOK, "&Ok" },
2549 { wxCANCEL, "&Cancel" },
2550};
2551
2552BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
2553 EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
2554 EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
2555END_EVENT_TABLE()
2556
2557TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
2558 : wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
2559 wxDefaultPosition, wxDefaultSize,
2560 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
a1bdd4ab
VZ
2561{
2562}
2563
2564bool TestMessageBoxDialog::Create()
44b25eac
VZ
2565{
2566 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
2567
2568 // this sizer allows to configure the messages shown in the message box
2569 wxSizer * const
2570 sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
2571 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
4e2dc789 2572 m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
44b25eac
VZ
2573 wxDefaultPosition, wxDefaultSize,
2574 wxTE_MULTILINE);
2575 sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
2576
2577 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
2578 m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
2579 wxDefaultPosition, wxDefaultSize,
2580 wxTE_MULTILINE);
2581 sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand());
2582
2583 sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
2584
a1bdd4ab
VZ
2585 // if a derived class provides more message configurations, add these.
2586 AddAdditionalTextOptions(sizerTop);
44b25eac
VZ
2587
2588 // this one is for configuring the buttons
f68376d9
SC
2589 wxSizer * const
2590 sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
a1bdd4ab 2591
44b25eac
VZ
2592 wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
2593 sizerBtns->AddGrowableCol(1);
2594
2595 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
2596 sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
2597
2598 for ( int n = 0; n < Btn_Max; n++ )
2599 {
2600 m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
2601 sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
2602
2603 m_labels[n] = new wxTextCtrl(this, wxID_ANY);
2604 sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand());
2605
2606 m_labels[n]->Connect(wxEVT_UPDATE_UI,
2607 wxUpdateUIEventHandler(
2608 TestMessageBoxDialog::OnUpdateLabelUI),
2609 NULL,
2610 this);
2611 }
2612
44b25eac
VZ
2613 sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand());
2614 sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
2615
2616
2617 // icon choice
8783d72f
VZ
2618 const wxString icons[] =
2619 {
2620 "&Not specified",
2621 "E&xplicitly none",
2622 "&Information icon",
2623 "&Question icon",
2624 "&Warning icon",
2625 "&Error icon"
44b25eac
VZ
2626 };
2627
e1cf09d9 2628 wxCOMPILE_TIME_ASSERT( WXSIZEOF(icons) == MsgDlgIcon_Max, IconMismatch );
e1cf09d9 2629
8783d72f 2630 m_icons = new wxRadioBox(this, wxID_ANY, "&Icon style",
44b25eac 2631 wxDefaultPosition, wxDefaultSize,
8783d72f
VZ
2632 WXSIZEOF(icons), icons,
2633 2, wxRA_SPECIFY_ROWS);
7e3204b4 2634 // Make the 'Information' icon the default one:
8783d72f 2635 m_icons->SetSelection(MsgDlgIcon_Info);
44b25eac
VZ
2636 sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
2637
2638
4e2dc789
VZ
2639 // miscellaneous other stuff
2640 wxSizer * const
2641 sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
2642
2643 m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
2644 m_chkNoDefault->Connect(wxEVT_UPDATE_UI,
2645 wxUpdateUIEventHandler(
2646 TestMessageBoxDialog::OnUpdateNoDefaultUI),
2647 NULL,
2648 this);
2649 sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border());
2650
2651 m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
2652 sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border());
2653
a1bdd4ab
VZ
2654 // add any additional flag from subclasses
2655 AddAdditionalFlags(sizerFlags);
2656
4e2dc789
VZ
2657 sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
2658
44b25eac
VZ
2659 // finally buttons to show the resulting message box and close this dialog
2660 sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
2661 wxSizerFlags().Right().Border());
2662
2663 SetSizerAndFit(sizerTop);
4e2dc789
VZ
2664
2665 m_buttons[Btn_Ok]->SetValue(true);
a1bdd4ab
VZ
2666
2667 return true;
44b25eac
VZ
2668}
2669
2670void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
2671{
2672 for ( int n = 0; n < Btn_Max; n++ )
2673 {
2674 if ( event.GetEventObject() == m_labels[n] )
2675 {
2676 event.Enable( m_buttons[n]->IsChecked() );
2677 return;
2678 }
2679 }
2680
2681 wxFAIL_MSG( "called for unknown label" );
2682}
2683
4e2dc789
VZ
2684void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
2685{
2686 event.Enable( m_buttons[Btn_No]->IsChecked() );
2687}
2688
a1bdd4ab 2689long TestMessageBoxDialog::GetStyle()
44b25eac
VZ
2690{
2691 long style = 0;
2692
2693 for ( int n = 0; n < Btn_Max; n++ )
2694 {
2695 if ( m_buttons[n]->IsChecked() )
2696 style |= ms_btnInfo[n].flag;
2697 }
2698
2699 switch ( m_icons->GetSelection() )
2700 {
8783d72f
VZ
2701 case MsgDlgIcon_Max:
2702 wxFAIL_MSG( "unexpected selection" );
2703
2704 case MsgDlgIcon_No:
2705 break;
2706
2707 case MsgDlgIcon_None:
2708 style |= wxICON_NONE;
2709 break;
2710
2711 case MsgDlgIcon_Info:
2712 style |= wxICON_INFORMATION;
2713 break;
2714
2715 case MsgDlgIcon_Question:
2716 style |= wxICON_QUESTION;
2717 break;
2718
2719 case MsgDlgIcon_Warning:
2720 style |= wxICON_WARNING;
2721 break;
2722
2723 case MsgDlgIcon_Error:
2724 style |= wxICON_ERROR;
2725 break;
44b25eac
VZ
2726 }
2727
4e2dc789
VZ
2728 if ( m_chkCentre->IsChecked() )
2729 style |= wxCENTRE;
2730
2731 if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
2732 style |= wxNO_DEFAULT;
2733
a1bdd4ab
VZ
2734 return style;
2735}
2736
2737void TestMessageBoxDialog::PrepareMessageDialog(wxMessageDialogBase &dlg)
2738{
2739 long style = dlg.GetMessageDialogStyle();
4e2dc789 2740
44b25eac
VZ
2741 if ( !m_textExtMsg->IsEmpty() )
2742 dlg.SetExtendedMessage(m_textExtMsg->GetValue());
2743
2744 if ( style & wxYES_NO )
2745 {
2746 if ( style & wxCANCEL )
2747 {
2748 dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
2749 m_labels[Btn_No]->GetValue(),
2750 m_labels[Btn_Cancel]->GetValue());
2751 }
2752 else
2753 {
2754 dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
2755 m_labels[Btn_No]->GetValue());
2756 }
2757 }
2758 else
2759 {
2760 if ( style & wxCANCEL )
2761 {
2762 dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
2763 m_labels[Btn_Cancel]->GetValue());
2764 }
2765 else
2766 {
2767 dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
2768 }
2769 }
a1bdd4ab
VZ
2770}
2771
2772void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
2773{
2774 wxMessageDialog dlg(this, GetMessage(), "Test Message Box", GetStyle());
2775 PrepareMessageDialog(dlg);
44b25eac
VZ
2776
2777 dlg.ShowModal();
2778}
2779
2780void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
2781{
2782 EndModal(wxID_CANCEL);
2783}
a1bdd4ab 2784#endif // wxUSE_MSGDLG
44b25eac 2785
a1bdd4ab
VZ
2786#if wxUSE_RICHMSGDLG
2787// ----------------------------------------------------------------------------
2788// TestRichMessageDialog
2789// ----------------------------------------------------------------------------
2790
2791BEGIN_EVENT_TABLE(TestRichMessageDialog, TestMessageBoxDialog)
2792 EVT_BUTTON(wxID_APPLY, TestRichMessageDialog::OnApply)
2793END_EVENT_TABLE()
2794
2795TestRichMessageDialog::TestRichMessageDialog(wxWindow *parent)
2796 : TestMessageBoxDialog(parent)
2797{
2798 SetTitle("Rich Message Dialog Test Dialog");
2799}
2800
2801void TestRichMessageDialog::AddAdditionalTextOptions(wxSizer *sizer)
2802{
2803 wxSizer * const sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this,
2804 "&Additional Elements");
2805
2806 // add a option to show a check box.
2807 wxFlexGridSizer * const sizerCheckBox = new wxFlexGridSizer(2, 5, 5);
2808 sizerCheckBox->AddGrowableCol(1);
2809 sizerCheckBox->Add(new wxStaticText(this, wxID_ANY, "&Check box:"));
2810 m_textCheckBox = new wxTextCtrl(this, wxID_ANY);
2811 sizerCheckBox->Add(m_textCheckBox, wxSizerFlags(1).Expand().Border(wxBOTTOM));
2812 sizerMsgs->Add(sizerCheckBox, wxSizerFlags(1).Expand());
2813
2814 // add option to show a detailed text.
2815 sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Detailed message:"));
2816 m_textDetailed = new wxTextCtrl(this, wxID_ANY, "",
2817 wxDefaultPosition, wxDefaultSize,
2818 wxTE_MULTILINE);
2819 sizerMsgs->Add(m_textDetailed, wxSizerFlags(1).Expand());
2820
2821 sizer->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
2822}
2823
2824void TestRichMessageDialog::AddAdditionalFlags(wxSizer *sizer)
2825{
2826 // add checkbox to set the initial state for the checkbox shown
2827 // in the dialog.
2828 m_initialValueCheckBox =
2829 new wxCheckBox(this, wxID_ANY, "Checkbox initially checked");
2830 sizer->Add(m_initialValueCheckBox, wxSizerFlags(1).Border());
2831}
2832
2833void TestRichMessageDialog::OnApply(wxCommandEvent& WXUNUSED(event))
2834{
2835 wxRichMessageDialog dlg(this, GetMessage(), "Test Rich Message Dialog",
2836 GetStyle());
2837 PrepareMessageDialog(dlg);
2838
2839 dlg.ShowCheckBox(m_textCheckBox->GetValue(),
2840 m_initialValueCheckBox->GetValue());
2841 dlg.ShowDetailedText(m_textDetailed->GetValue());
2842
2843 dlg.ShowModal();
2844}
2845
2846#endif // wxUSE_RICHMSGDLG
9ad2fe62
VZ
2847
2848#if wxUSE_LOG
2849
2850// ----------------------------------------------------------------------------
2851// custom log target
2852// ----------------------------------------------------------------------------
2853
2854class MyLogGui : public wxLogGui
2855{
2856private:
2857 virtual void DoShowSingleLogMessage(const wxString& message,
2858 const wxString& title,
2859 int style)
2860 {
f0afc953
VZ
2861 wxMessageDialog dlg(NULL, message, title,
2862 wxOK | wxCANCEL | wxCANCEL_DEFAULT | style);
2863 dlg.SetOKCancelLabels(wxID_COPY, wxID_OK);
9ad2fe62
VZ
2864 dlg.SetExtendedMessage("Note that this is a custom log dialog.");
2865 dlg.ShowModal();
2866 }
2867};
2868
2869wxLog *MyAppTraits::CreateLogTarget()
2870{
2871 return new MyLogGui;
2872}
2873
2874#endif // wxUSE_LOG