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