]> git.saurik.com Git - wxWidgets.git/blame - samples/dialogs/dialogs.cpp
fix for dmc compilation of projects with more than one obj
[wxWidgets.git] / samples / dialogs / dialogs.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: dialogs.cpp
3// Purpose: Common dialogs demo
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
c50f1fb9 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation
14#pragma interface
15#endif
16
17// For compilers that support precompilation, includes "wx/wx.h".
18#include "wx/wxprec.h"
19
20#ifdef __BORLANDC__
21#pragma hdrstop
22#endif
23
24#ifndef WX_PRECOMP
25#include "wx/wx.h"
26#endif
27
329e86bf
RR
28#include "wx/colordlg.h"
29#include "wx/filedlg.h"
30#include "wx/dirdlg.h"
31#include "wx/fontdlg.h"
32#include "wx/choicdlg.h"
33#include "wx/tipdlg.h"
abceee76 34#include "wx/progdlg.h"
761989ff 35#include "wx/fdrepdlg.h"
a62b0bcc 36#include "wx/busyinfo.h"
457814b5 37
dfad0599
JS
38#define wxTEST_GENERIC_DIALOGS_IN_MSW 0
39
40#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
012f2cb2
GD
41#include "wx/generic/colrdlgg.h"
42#include "wx/generic/fontdlgg.h"
457814b5
JS
43#endif
44
7e5c1138 45#define wxUSE_DIRDLGG 0
d7d17624 46
4ad3c82f 47#if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
d7d17624 48#include "wx/generic/dirdlgg.h"
4ad3c82f
VZ
49#endif
50
457814b5
JS
51#include "dialogs.h"
52
53IMPLEMENT_APP(MyApp)
54
4c45f240
VZ
55BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
56 EVT_PAINT(MyCanvas::OnPaint)
57END_EVENT_TABLE()
58
59BEGIN_EVENT_TABLE(MyFrame, wxFrame)
60 EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour)
61 EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont)
62 EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog)
63 EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
64 EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry)
65 EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry)
66 EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry)
67 EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice)
d6c9c1b7 68 EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice)
4c45f240 69 EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
35b45b33 70 EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
4c45f240
VZ
71 EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
72 EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
73 EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose)
f09c8393 74 EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew)
af2b012d 75#if defined(__WXMSW__) || defined(__WXMAC__)
51a58d8b 76 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose)
af2b012d 77#endif // wxMSW || wxMAC
f6bcfd97 78 EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg)
4c45f240
VZ
79 EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg)
80 EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip)
81#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
82 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric)
83 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric)
abceee76 84#endif
a62b0bcc 85
abceee76
VZ
86#if wxUSE_PROGRESSDLG
87 EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress)
761989ff 88#endif // wxUSE_PROGRESSDLG
a62b0bcc
VZ
89
90#if wxUSE_BUSYINFO
91 EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo)
92#endif // wxUSE_BUSYINFO
93
761989ff
VZ
94#if wxUSE_FINDREPLDLG
95 EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog)
96 EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog)
97
98 EVT_FIND(-1, MyFrame::OnFindDialog)
99 EVT_FIND_NEXT(-1, MyFrame::OnFindDialog)
100 EVT_FIND_REPLACE(-1, MyFrame::OnFindDialog)
101 EVT_FIND_REPLACE_ALL(-1, MyFrame::OnFindDialog)
102 EVT_FIND_CLOSE(-1, MyFrame::OnFindDialog)
103#endif // wxUSE_FINDREPLDLG
4c45f240 104 EVT_MENU(wxID_EXIT, MyFrame::OnExit)
4c45f240 105END_EVENT_TABLE()
abceee76 106
f6bcfd97
BP
107BEGIN_EVENT_TABLE(MyModalDialog, wxDialog)
108 EVT_BUTTON(-1, MyModalDialog::OnButton)
109END_EVENT_TABLE()
110
abceee76 111BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog)
5d987909
VZ
112 EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton)
113
abceee76
VZ
114 EVT_CLOSE(MyModelessDialog::OnClose)
115END_EVENT_TABLE()
116
c67daf87 117MyCanvas *myCanvas = (MyCanvas *) NULL;
457814b5 118
457814b5 119// `Main program' equivalent, creating windows and returning main app frame
4c45f240 120bool MyApp::OnInit()
457814b5 121{
e5ea3f7a 122#if defined(__WXGTK__) && defined(wxUSE_UNICODE)
dcf924a3 123 wxConvCurrent = &wxConvLibc;
e5ea3f7a
RR
124#endif
125
9f84eccd 126 m_canvasTextColour = wxColour(_T("BLACK"));
66bd6b93 127 m_canvasFont = *wxNORMAL_FONT;
457814b5
JS
128
129 // Create the main frame window
2f1cd905 130 MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWindows dialogs example"), wxPoint(20, 20), wxSize(400, 300));
457814b5
JS
131
132 // Make a menubar
133 wxMenu *file_menu = new wxMenu;
134
78a189c9 135 file_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
457814b5 136
dfad0599 137#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
78a189c9 138 file_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("Choose colour (&generic)"));
457814b5
JS
139#endif
140
141 file_menu->AppendSeparator();
78a189c9 142 file_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
457814b5 143
dfad0599 144#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
78a189c9 145 file_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose f&ont (generic)"));
457814b5 146#endif
f09c8393 147
457814b5 148 file_menu->AppendSeparator();
78a189c9
VZ
149 file_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L"));
150 file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
151 file_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E"));
152 file_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P"));
153 file_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N"));
154 file_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C"));
155 file_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U"));
457814b5 156 file_menu->AppendSeparator();
78a189c9 157 file_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T"));
c50f1fb9 158 file_menu->AppendSeparator();
78a189c9
VZ
159 file_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O"));
160 file_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2"));
161 file_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q"));
162 file_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S"));
163 file_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D"));
f09c8393 164 file_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
af2b012d 165#if defined(__WXMSW__) || defined(__WXMAC__)
78a189c9 166 file_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic implementation)"));
af2b012d 167#endif // wxMSW || wxMAC
f09c8393
VZ
168 file_menu->AppendSeparator();
169
abceee76 170#if wxUSE_PROGRESSDLG
78a189c9 171 file_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G"));
abceee76 172#endif // wxUSE_PROGRESSDLG
a62b0bcc 173#if wxUSE_BUSYINFO
78a189c9 174 file_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B"));
a62b0bcc 175#endif // wxUSE_BUSYINFO
761989ff 176#if wxUSE_FINDREPLDLG
9f84eccd
MB
177 file_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), _T(""), TRUE);
178 file_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), _T(""), TRUE);
761989ff 179#endif // wxUSE_FINDREPLDLG
f6bcfd97 180 file_menu->AppendSeparator();
f09c8393 181
78a189c9 182 file_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
9f84eccd 183 file_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), _T(""), TRUE);
4c45f240 184 file_menu->AppendSeparator();
f09c8393 185
78a189c9 186 file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X"));
457814b5 187 wxMenuBar *menu_bar = new wxMenuBar;
78a189c9 188 menu_bar->Append(file_menu, _T("&File"));
457814b5
JS
189 frame->SetMenuBar(menu_bar);
190
191 myCanvas = new MyCanvas(frame);
192 myCanvas->SetBackgroundColour(*wxWHITE);
193
194 frame->Centre(wxBOTH);
d93c719a 195
457814b5
JS
196 // Show the frame
197 frame->Show(TRUE);
198
199 SetTopWindow(frame);
200
201 return TRUE;
202}
203
204// My frame constructor
4c45f240
VZ
205MyFrame::MyFrame(wxWindow *parent,
206 const wxString& title,
207 const wxPoint& pos,
208 const wxSize& size)
209 : wxFrame(parent, -1, title, pos, size)
210{
211 m_dialog = (MyModelessDialog *)NULL;
f1e1ed3b 212
043dcdaa 213#if wxUSE_FINDREPLDLG
14fca738
VZ
214 m_dlgFind =
215 m_dlgReplace = NULL;
043dcdaa
JJ
216#endif
217
f1e1ed3b 218 CreateStatusBar();
4c45f240 219}
457814b5 220
d355d3fe 221void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
457814b5 222{
afbd36dd
VZ
223 wxColour col = myCanvas->GetBackgroundColour();
224
f6bcfd97 225 wxColourData data;
afbd36dd 226 data.SetColour(col);
f6bcfd97
BP
227 data.SetChooseFull(TRUE);
228 for (int i = 0; i < 16; i++)
229 {
457814b5
JS
230 wxColour colour(i*16, i*16, i*16);
231 data.SetCustomColour(i, colour);
f6bcfd97 232 }
d93c719a 233
afbd36dd 234 wxColourDialog dialog(this, &data);
9f84eccd 235 dialog.SetTitle(_T("Choose the background colour"));
afbd36dd 236 if (dialog.ShowModal() == wxID_OK)
f6bcfd97 237 {
afbd36dd
VZ
238 wxColourData retData = dialog.GetColourData();
239 col = retData.GetColour();
457814b5
JS
240 myCanvas->SetBackgroundColour(col);
241 myCanvas->Clear();
242 myCanvas->Refresh();
f6bcfd97 243 }
457814b5
JS
244}
245
d355d3fe 246void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
457814b5 247{
dbc65e27
VZ
248 wxFontData data;
249 data.SetInitialFont(wxGetApp().m_canvasFont);
250 data.SetColour(wxGetApp().m_canvasTextColour);
d93c719a 251
dbc65e27
VZ
252 // you might also do this:
253 //
254 // wxFontDialog dialog;
255 // if ( !dialog.Create(this, data) { ... error ... }
256 //
257 wxFontDialog dialog(this, data);
258
259 if (dialog.ShowModal() == wxID_OK)
260 {
261 wxFontData retData = dialog.GetFontData();
457814b5
JS
262 wxGetApp().m_canvasFont = retData.GetChosenFont();
263 wxGetApp().m_canvasTextColour = retData.GetColour();
264 myCanvas->Refresh();
dbc65e27
VZ
265 }
266 //else: cancelled by the user, don't change the font
457814b5
JS
267}
268
dfad0599 269#if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
d355d3fe 270void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event))
457814b5
JS
271{
272 wxColourData data;
273 data.SetChooseFull(TRUE);
274 for (int i = 0; i < 16; i++)
275 {
276 wxColour colour(i*16, i*16, i*16);
277 data.SetCustomColour(i, colour);
278 }
d93c719a 279
457814b5
JS
280 wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &data);
281 if (dialog->ShowModal() == wxID_OK)
282 {
283 wxColourData retData = dialog->GetColourData();
284 wxColour col = retData.GetColour();
285// wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
286 myCanvas->SetBackgroundColour(col);
287 myCanvas->Clear();
288 myCanvas->Refresh();
289 }
5919d76b 290 dialog->Destroy();
457814b5
JS
291}
292
d355d3fe 293void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
457814b5
JS
294{
295 wxFontData data;
296 data.SetInitialFont(wxGetApp().m_canvasFont);
297 data.SetColour(wxGetApp().m_canvasTextColour);
298
299 wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data);
300 if (dialog->ShowModal() == wxID_OK)
301 {
302 wxFontData retData = dialog->GetFontData();
303 wxGetApp().m_canvasFont = retData.GetChosenFont();
304 wxGetApp().m_canvasTextColour = retData.GetColour();
305 myCanvas->Refresh();
306 }
5919d76b 307 dialog->Destroy();
457814b5 308}
d93c719a
VZ
309#endif // wxTEST_GENERIC_DIALOGS_IN_MSW
310
311void MyFrame::LogDialog(wxCommandEvent& event)
312{
2c8e4738
VZ
313 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
314 // being flushed -- test it
315 {
316 wxBusyCursor bc;
4693b20c
MB
317 wxLogMessage(wxT("This is some message - everything is ok so far."));
318 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
319 wxLogWarning(wxT("And then something went wrong!"));
9fe52545
VZ
320
321 // and if ~wxBusyCursor doesn't do it, then call it manually
322 wxYield();
2c8e4738
VZ
323 }
324
4693b20c
MB
325 wxLogError(wxT("Intermediary error handler decided to abort."));
326 wxLogError(wxT("The top level caller detected an unrecoverable error."));
5888ef1e 327
7923c649
VZ
328 wxLog::FlushActive();
329
4693b20c 330 wxLogMessage(wxT("And this is the same dialog but with only one message."));
d93c719a 331}
457814b5 332
d355d3fe 333void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
457814b5 334{
78a189c9
VZ
335 wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"),
336 _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
457814b5 337
49b957be
VZ
338 switch ( dialog.ShowModal() )
339 {
340 case wxID_YES:
4fce73fc 341 wxLogStatus(wxT("You pressed \"Yes\""));
49b957be
VZ
342 break;
343
344 case wxID_NO:
4fce73fc 345 wxLogStatus(wxT("You pressed \"No\""));
49b957be
VZ
346 break;
347
348 case wxID_CANCEL:
4fce73fc 349 wxLogStatus(wxT("You pressed \"Cancel\""));
49b957be
VZ
350 break;
351
352 default:
4fce73fc 353 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
49b957be 354 }
457814b5
JS
355}
356
c49245f8
VZ
357void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )
358{
78a189c9
VZ
359 long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
360 _T("Even two rows of text."),
361 _T("Enter a number:"), _T("Numeric input test"),
e65cc56a 362 50, 0, 100, this );
c49245f8
VZ
363
364 wxString msg;
365 int icon;
366 if ( res == -1 )
367 {
78a189c9 368 msg = _T("Invalid number entered or dialog cancelled.");
c49245f8
VZ
369 icon = wxICON_HAND;
370 }
371 else
d93c719a
VZ
372 {
373 msg.Printf(_T("You've entered %lu"), res );
c49245f8
VZ
374 icon = wxICON_INFORMATION;
375 }
376
78a189c9 377 wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this);
c49245f8
VZ
378}
379
a294c6d5 380void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event))
457814b5 381{
2f1cd905 382 wxString pwd = wxGetPasswordFromUser(_T("Enter password:"),
78a189c9 383 _T("Password entry dialog"),
9f84eccd 384 _T(""),
a294c6d5
VZ
385 this);
386 if ( !!pwd )
387 {
4693b20c 388 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()),
78a189c9 389 _T("Got password"), wxOK | wxICON_INFORMATION, this);
a294c6d5
VZ
390 }
391}
392
393void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
394{
395 wxTextEntryDialog dialog(this,
78a189c9
VZ
396 _T("This is a small sample\n")
397 _T("A long, long string to test out the text entrybox"),
398 _T("Please enter a string"),
399 _T("Default value"),
a294c6d5 400 wxOK | wxCANCEL);
457814b5
JS
401
402 if (dialog.ShowModal() == wxID_OK)
403 {
78a189c9 404 wxMessageDialog dialog2(this, dialog.GetValue(), _T("Got string"));
c50f1fb9 405 dialog2.ShowModal();
457814b5
JS
406 }
407}
408
d355d3fe 409void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) )
457814b5 410{
78a189c9 411 const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
457814b5 412
5f95bb70 413 wxSingleChoiceDialog dialog(this,
78a189c9
VZ
414 _T("This is a small sample\n")
415 _T("A single-choice convenience dialog"),
416 _T("Please select a value"),
5f95bb70 417 WXSIZEOF(choices), choices);
457814b5 418
ef77f91e
JS
419 dialog.SetSelection(2);
420
421 if (dialog.ShowModal() == wxID_OK)
422 {
78a189c9 423 wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string"));
ef77f91e
JS
424 dialog2.ShowModal();
425 }
457814b5
JS
426}
427
d6c9c1b7
VZ
428void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) )
429{
5f95bb70
VZ
430 const wxString choices[] =
431 {
78a189c9
VZ
432 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
433 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
434 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
5f95bb70 435 };
d6c9c1b7
VZ
436
437 wxArrayInt selections;
438 size_t count = wxGetMultipleChoices(selections,
78a189c9
VZ
439 _T("This is a small sample\n")
440 _T("A multi-choice convenience dialog"),
441 _T("Please select a value"),
5f95bb70 442 WXSIZEOF(choices), choices,
d6c9c1b7
VZ
443 this);
444 if ( count )
445 {
3d49ce44 446 wxString msg;
fba1b53b 447 msg.Printf(wxT("You selected %u items:\n"), (unsigned)count);
d6c9c1b7
VZ
448 for ( size_t n = 0; n < count; n++ )
449 {
fba1b53b
VZ
450 msg += wxString::Format(wxT("\t%u: %u (%s)\n"),
451 (unsigned)n, (unsigned)selections[n],
3d49ce44 452 choices[selections[n]].c_str());
d6c9c1b7 453 }
3d49ce44 454 wxLogMessage(msg);
d6c9c1b7
VZ
455 }
456 //else: cancelled or nothing selected
457}
458
d355d3fe 459void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
457814b5 460{
fbf4eacb
VZ
461 wxFileDialog dialog
462 (
463 this,
464 _T("Testing open file dialog"),
465 _T(""),
466 _T(""),
a4e64fb5
MB
467#ifdef __WXMOTIF__
468 _T("C++ files (*.cpp)|*.cpp")
469#else
fbf4eacb 470 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
a4e64fb5 471#endif
fbf4eacb 472 );
457814b5 473
5b636c67
VZ
474 dialog.SetDirectory(wxGetHomeDir());
475
c50f1fb9
VZ
476 if (dialog.ShowModal() == wxID_OK)
477 {
5919d76b 478 wxString info;
13393ab6
RR
479 info.Printf(_T("Full file name: %s\n")
480 _T("Path: %s\n")
481 _T("Name: %s"),
5919d76b
VZ
482 dialog.GetPath().c_str(),
483 dialog.GetDirectory().c_str(),
484 dialog.GetFilename().c_str());
78a189c9 485 wxMessageDialog dialog2(this, info, _T("Selected file"));
c50f1fb9
VZ
486 dialog2.ShowModal();
487 }
457814b5
JS
488}
489
35b45b33
VZ
490// this shows how to take advantage of specifying a default extension in the
491// call to wxFileSelector: it is remembered after each new call and the next
492// one will use it by default
493void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) )
494{
495 static wxString s_extDef;
496 wxString path = wxFileSelector(
497 _T("Select the file to load"),
2f1cd905 498 _T(""), _T(""),
35b45b33
VZ
499 s_extDef,
500 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
fbf4eacb 501 wxCHANGE_DIR,
35b45b33
VZ
502 this
503 );
504
505 if ( !path )
506 return;
507
508 // it is just a sample, would use wxSplitPath in real program
509 s_extDef = path.AfterLast(_T('.'));
510
511 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
37d403aa 512 (const wxChar*) path, (const wxChar*) s_extDef);
35b45b33
VZ
513}
514
c61f4f6d
VZ
515void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
516{
78a189c9 517 wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
811ad6a1 518 _T(""), _T(""), wxFileSelectorDefaultWildcardStr,
470caaf9 519 wxMULTIPLE);
c61f4f6d
VZ
520
521 if (dialog.ShowModal() == wxID_OK)
522 {
523 wxArrayString paths, filenames;
524
525 dialog.GetPaths(paths);
526 dialog.GetFilenames(filenames);
527
528 wxString msg, s;
529 size_t count = paths.GetCount();
530 for ( size_t n = 0; n < count; n++ )
531 {
532 s.Printf(_T("File %d: %s (%s)\n"),
fba1b53b 533 (int)n, paths[n].c_str(), filenames[n].c_str());
c61f4f6d
VZ
534
535 msg += s;
536 }
537
78a189c9 538 wxMessageDialog dialog2(this, msg, _T("Selected files"));
c61f4f6d
VZ
539 dialog2.ShowModal();
540 }
541}
542
d355d3fe 543void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
457814b5 544{
2f1cd905
VZ
545 wxFileDialog dialog(this,
546 _T("Testing save file dialog"),
547 _T(""),
2b5f62a0 548 _T("myletter.doc"),
2f1cd905
VZ
549 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
550 wxSAVE|wxOVERWRITE_PROMPT);
c50f1fb9 551
2b5f62a0
VZ
552 dialog.SetFilterIndex(1);
553
c50f1fb9
VZ
554 if (dialog.ShowModal() == wxID_OK)
555 {
2b5f62a0
VZ
556 wxLogMessage(_T("%s, filter %d"),
557 dialog.GetPath().c_str(), dialog.GetFilterIndex());
c50f1fb9 558 }
457814b5
JS
559}
560
f09c8393 561void MyFrame::DoDirChoose(int style)
457814b5 562{
3f2711d5
VZ
563 // pass some initial dir to wxDirDialog
564 wxString dirHome;
565 wxGetHomeDir(&dirHome);
566
f09c8393 567 wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style);
c50f1fb9
VZ
568
569 if (dialog.ShowModal() == wxID_OK)
570 {
2b5f62a0 571 wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str());
c50f1fb9
VZ
572 }
573}
574
f09c8393
VZ
575void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) )
576{
577 DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON);
578}
579
580void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) )
581{
8768548b 582 DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON);
f09c8393
VZ
583}
584
af2b012d
VZ
585#if defined(__WXMSW__) || defined(__WXMAC__)
586
51a58d8b
JS
587void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) )
588{
4ad3c82f 589#if !defined(__WXMSW__) || defined(wxUSE_DIRDLGG) && wxUSE_DIRDLGG
51a58d8b
JS
590 // pass some initial dir to wxDirDialog
591 wxString dirHome;
592 wxGetHomeDir(&dirHome);
593
78a189c9 594 wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome);
51a58d8b
JS
595
596 if (dialog.ShowModal() == wxID_OK)
597 {
78a189c9 598 wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path"));
51a58d8b
JS
599 dialog2.ShowModal();
600 }
4ad3c82f 601#else
4693b20c
MB
602 wxLogError(wxT("Sorry, generic dir dialog not available:\n")
603 wxT("set wxUSE_DIRDLGG to 1 and recompile"));
4ad3c82f 604#endif
51a58d8b
JS
605}
606
af2b012d
VZ
607#endif // wxMSW || wxMAC
608
f6bcfd97
BP
609void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event))
610{
611 MyModalDialog dlg(this);
612 dlg.ShowModal();
613}
614
4c45f240
VZ
615void MyFrame::ModelessDlg(wxCommandEvent& event)
616{
2f82899b 617 bool show = GetMenuBar()->IsChecked(event.GetId());
4c45f240
VZ
618
619 if ( show )
620 {
621 if ( !m_dialog )
622 {
623 m_dialog = new MyModelessDialog(this);
624 }
625
626 m_dialog->Show(TRUE);
627 }
628 else // hide
629 {
630 m_dialog->Hide();
631 }
632}
633
c50f1fb9
VZ
634void MyFrame::ShowTip(wxCommandEvent& event)
635{
78bd7ed3 636#if wxUSE_STARTUP_TIPS
c50f1fb9
VZ
637 static size_t s_index = (size_t)-1;
638
639 if ( s_index == (size_t)-1 )
640 {
641 srand(time(NULL));
642
643 // this is completely bogus, we don't know how many lines are there
644 // in the file, but who cares, it's a demo only...
645 s_index = rand() % 5;
646 }
647
2f1cd905 648 wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index);
c50f1fb9
VZ
649
650 bool showAtStartup = wxShowTip(this, tipProvider);
651
652 if ( showAtStartup )
653 {
2f1cd905 654 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
c50f1fb9
VZ
655 wxOK | wxICON_INFORMATION, this);
656 }
457814b5 657
c50f1fb9
VZ
658 s_index = tipProvider->GetCurrentTip();
659 delete tipProvider;
78bd7ed3 660#endif
457814b5
JS
661}
662
d355d3fe 663void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) )
457814b5 664{
c50f1fb9 665 Close(TRUE);
457814b5
JS
666}
667
abceee76
VZ
668#if wxUSE_PROGRESSDLG
669
670void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) )
671{
672 static const int max = 10;
673
2f1cd905 674 wxProgressDialog dialog(_T("Progress dialog example"),
78a189c9 675 _T("An informative message"),
abceee76
VZ
676 max, // range
677 this, // parent
678 wxPD_CAN_ABORT |
679 wxPD_APP_MODAL |
df26c4c6 680 // wxPD_AUTO_HIDE | -- try this as well
abceee76
VZ
681 wxPD_ELAPSED_TIME |
682 wxPD_ESTIMATED_TIME |
683 wxPD_REMAINING_TIME);
684
685 bool cont = TRUE;
d8ddee9c 686 for ( int i = 0; i <= max; i++ )
abceee76
VZ
687 {
688 wxSleep(1);
689 if ( i == max )
690 {
78a189c9 691 cont = dialog.Update(i, _T("That's all, folks!"));
abceee76
VZ
692 }
693 else if ( i == max / 2 )
694 {
78a189c9 695 cont = dialog.Update(i, _T("Only a half left (very long message)!"));
abceee76
VZ
696 }
697 else
698 {
699 cont = dialog.Update(i);
700 }
d8ddee9c
VZ
701
702 if ( !cont )
703 {
78a189c9
VZ
704 if ( wxMessageBox(_T("Do you really want to cancel?"),
705 _T("Progress dialog question"), // caption
706 wxYES_NO | wxICON_QUESTION) == wxYES )
d8ddee9c
VZ
707 break;
708
709 dialog.Resume();
710 }
abceee76
VZ
711 }
712
713 if ( !cont )
714 {
4693b20c 715 wxLogStatus(wxT("Progress dialog aborted!"));
abceee76
VZ
716 }
717 else
718 {
4693b20c 719 wxLogStatus(wxT("Countdown from %d finished"), max);
abceee76
VZ
720 }
721}
722
723#endif // wxUSE_PROGRESSDLG
724
a62b0bcc
VZ
725#if wxUSE_BUSYINFO
726
727void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
728{
21977bac
VZ
729 wxWindowDisabler disableAll;
730
9f84eccd 731 wxBusyInfo info(_T("Working, please wait..."), this);
a62b0bcc 732
5b636c67 733 for ( int i = 0; i < 18; i++ )
a62b0bcc 734 {
5b636c67 735 //wxUsleep(100);
a62b0bcc
VZ
736 wxTheApp->Yield();
737 }
5b636c67
VZ
738
739 wxSleep(2);
740 //wxWakeUpIdle();
a62b0bcc
VZ
741}
742
743#endif // wxUSE_BUSYINFO
744
761989ff
VZ
745#if wxUSE_FINDREPLDLG
746
747void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
748{
14fca738
VZ
749 if ( m_dlgReplace )
750 {
751 delete m_dlgReplace;
752 m_dlgReplace = NULL;
753 }
754 else
755 {
756 m_dlgReplace = new wxFindReplaceDialog
757 (
758 this,
759 &m_findData,
78a189c9 760 _T("Find and replace dialog"),
14fca738
VZ
761 wxFR_REPLACEDIALOG
762 );
763
764 m_dlgReplace->Show(TRUE);
765 }
761989ff
VZ
766}
767
768void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
769{
14fca738
VZ
770 if ( m_dlgFind )
771 {
772 delete m_dlgFind;
773 m_dlgFind = NULL;
774 }
775 else
776 {
777 m_dlgFind = new wxFindReplaceDialog
778 (
779 this,
780 &m_findData,
78a189c9 781 _T("Find dialog"),
14fca738
VZ
782 // just for testing
783 wxFR_NOWHOLEWORD
784 );
785
786 m_dlgFind->Show(TRUE);
787 }
761989ff
VZ
788}
789
790static wxString DecodeFindDialogEventFlags(int flags)
791{
792 wxString str;
78a189c9 793 str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ")
2f1cd905
VZ
794 << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T(""))
795 << (flags & wxFR_MATCHCASE ? _T("") : _T("not "))
78a189c9 796 << _T("case sensitive");
761989ff
VZ
797
798 return str;
799}
800
801void MyFrame::OnFindDialog(wxFindDialogEvent& event)
802{
803 wxEventType type = event.GetEventType();
804
805 if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT )
806 {
4693b20c 807 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
eba33006 808 type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""),
761989ff
VZ
809 event.GetFindString().c_str(),
810 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
811 }
812 else if ( type == wxEVT_COMMAND_FIND_REPLACE ||
813 type == wxEVT_COMMAND_FIND_REPLACE_ALL )
814 {
4693b20c 815 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
eba33006 816 type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""),
761989ff
VZ
817 event.GetFindString().c_str(),
818 event.GetReplaceString().c_str(),
819 DecodeFindDialogEventFlags(event.GetFlags()).c_str());
820 }
821 else if ( type == wxEVT_COMMAND_FIND_CLOSE )
822 {
14fca738
VZ
823 wxFindReplaceDialog *dlg = event.GetDialog();
824
df26c4c6 825 int idMenu;
14fca738
VZ
826 const wxChar *txt;
827 if ( dlg == m_dlgFind )
828 {
829 txt = _T("Find");
df26c4c6 830 idMenu = DIALOGS_FIND;
14fca738
VZ
831 m_dlgFind = NULL;
832 }
833 else if ( dlg == m_dlgReplace )
834 {
835 txt = _T("Replace");
df26c4c6 836 idMenu = DIALOGS_REPLACE;
14fca738
VZ
837 m_dlgReplace = NULL;
838 }
839 else
840 {
841 txt = _T("Unknown");
df26c4c6 842 idMenu = -1;
14fca738 843
2f1cd905 844 wxFAIL_MSG( _T("unexpected event") );
14fca738
VZ
845 }
846
df26c4c6
VZ
847 wxLogMessage(wxT("%s dialog is being closed."), txt);
848
849 if ( idMenu != -1 )
850 {
851 GetMenuBar()->Check(idMenu, FALSE);
852 }
761989ff 853
14fca738 854 dlg->Destroy();
761989ff
VZ
855 }
856 else
857 {
4693b20c 858 wxLogError(wxT("Unknown find dialog event!"));
761989ff
VZ
859 }
860}
861
862#endif // wxUSE_FINDREPLDLG
863
abceee76
VZ
864// ----------------------------------------------------------------------------
865// MyCanvas
866// ----------------------------------------------------------------------------
867
d355d3fe 868void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
457814b5 869{
c50f1fb9 870 wxPaintDC dc(this);
457814b5
JS
871 dc.SetFont(wxGetApp().m_canvasFont);
872 dc.SetTextForeground(wxGetApp().m_canvasTextColour);
873 dc.SetBackgroundMode(wxTRANSPARENT);
9f84eccd 874 dc.DrawText(_T("wxWindows common dialogs test application"), 10, 10);
457814b5
JS
875}
876
4c45f240
VZ
877// ----------------------------------------------------------------------------
878// MyModelessDialog
879// ----------------------------------------------------------------------------
457814b5 880
4c45f240 881MyModelessDialog::MyModelessDialog(wxWindow *parent)
9f84eccd 882 : wxDialog(parent, -1, wxString(_T("Modeless dialog")))
4c45f240 883{
cbc66a27
VZ
884 wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL);
885
78a189c9
VZ
886 wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me"));
887 wxCheckBox *check = new wxCheckBox(this, -1, _T("Should be disabled"));
cbc66a27
VZ
888 check->Disable();
889
890 sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5);
891 sizerTop->Add(check, 1, wxEXPAND | wxALL, 5);
892
893 SetAutoLayout(TRUE);
894 SetSizer(sizerTop);
895
896 sizerTop->SetSizeHints(this);
897 sizerTop->Fit(this);
4c45f240 898}
abceee76 899
5d987909
VZ
900void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event))
901{
2f1cd905 902 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
5d987909
VZ
903 wxOK | wxICON_INFORMATION, this);
904}
905
abceee76
VZ
906void MyModelessDialog::OnClose(wxCloseEvent& event)
907{
908 if ( event.CanVeto() )
909 {
2f1cd905 910 wxMessageBox(_T("Use the menu item to close this dialog"),
78a189c9 911 _T("Modeless dialog"),
abceee76
VZ
912 wxOK | wxICON_INFORMATION, this);
913
914 event.Veto();
915 }
916}
917
f6bcfd97
BP
918// ----------------------------------------------------------------------------
919// MyModalDialog
920// ----------------------------------------------------------------------------
921
922MyModalDialog::MyModalDialog(wxWindow *parent)
f3dbeba4 923 : wxDialog(parent, -1, wxString(_T("Modal dialog")))
f6bcfd97
BP
924{
925 wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
926
5315ebfa
VZ
927 m_btnModal = new wxButton(this, -1, _T("&Modal dialog..."));
928 m_btnModeless = new wxButton(this, -1, _T("Mode&less dialog"));
78a189c9 929 m_btnDelete = new wxButton(this, -1, _T("&Delete button"));
5315ebfa 930
78a189c9 931 wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close"));
5315ebfa
VZ
932 sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5);
933 sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97 934 sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5);
9b70bb91 935 sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5);
f6bcfd97
BP
936
937 SetAutoLayout(TRUE);
938 SetSizer(sizerTop);
939
940 sizerTop->SetSizeHints(this);
941 sizerTop->Fit(this);
942
5315ebfa
VZ
943 m_btnModal->SetFocus();
944 m_btnModal->SetDefault();
f6bcfd97
BP
945}
946
947void MyModalDialog::OnButton(wxCommandEvent& event)
948{
949 if ( event.GetEventObject() == m_btnDelete )
950 {
5315ebfa
VZ
951 delete m_btnModal;
952 m_btnModal = NULL;
f6bcfd97
BP
953
954 m_btnDelete->Disable();
955 }
5315ebfa 956 else if ( event.GetEventObject() == m_btnModal )
f6bcfd97 957 {
78a189c9
VZ
958 wxGetTextFromUser(_T("Dummy prompt"),
959 _T("Modal dialog called from dialog"),
960 _T(""), this);
f6bcfd97 961 }
5315ebfa
VZ
962 else if ( event.GetEventObject() == m_btnModeless )
963 {
964 (new MyModelessDialog(this))->Show();
965 }
f6bcfd97
BP
966 else
967 {
968 event.Skip();
969 }
970}