1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Common dialogs demo
4 // Author: Julian Smart
5 // Modified by: ABX (2004) - adjustements for conditional building + new menu
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(__APPLE__)
13 #pragma implementation
17 // For compilers that support precompilation, includes "wx/wx.h".
18 #include "wx/wxprec.h"
28 #include "wx/datetime.h"
32 #include "wx/colordlg.h"
33 #endif // wxUSE_COLOURDLG
36 #include "wx/choicdlg.h"
37 #endif // wxUSE_CHOICEDLG
39 #if wxUSE_STARTUP_TIPS
40 #include "wx/tipdlg.h"
41 #endif // wxUSE_STARTUP_TIPS
44 #include "wx/progdlg.h"
45 #endif // wxUSE_PROGRESSDLG
48 #include "wx/busyinfo.h"
49 #endif // wxUSE_BUSYINFO
52 #include "wx/numdlg.h"
53 #endif // wxUSE_NUMBERDLG
56 #include "wx/filedlg.h"
57 #endif // wxUSE_FILEDLG
60 #include "wx/dirdlg.h"
61 #endif // wxUSE_DIRDLG
64 #include "wx/fontdlg.h"
65 #endif // wxUSE_FONTDLG
68 #include "wx/fdrepdlg.h"
69 #endif // wxUSE_FINDREPLDLG
73 #if USE_COLOURDLG_GENERIC
74 #include "wx/generic/colrdlgg.h"
75 #endif // USE_COLOURDLG_GENERIC
77 #if USE_DIRDLG_GENERIC
78 #include "wx/generic/dirdlgg.h"
79 #endif // USE_DIRDLG_GENERIC
81 #if USE_FILEDLG_GENERIC
82 #include "wx/generic/filedlgg.h"
83 #endif // USE_FILEDLG_GENERIC
85 #if USE_FONTDLG_GENERIC
86 #include "wx/generic/fontdlgg.h"
87 #endif // USE_FONTDLG_GENERIC
91 BEGIN_EVENT_TABLE(MyCanvas
, wxScrolledWindow
)
92 EVT_PAINT(MyCanvas::OnPaint
)
97 BEGIN_EVENT_TABLE(MyFrame
, wxFrame
)
98 EVT_MENU(DIALOGS_MESSAGE_BOX
, MyFrame::MessageBox
)
101 EVT_MENU(DIALOGS_CHOOSE_COLOUR
, MyFrame::ChooseColour
)
102 #endif // wxUSE_COLOURDLG
105 EVT_MENU(DIALOGS_CHOOSE_FONT
, MyFrame::ChooseFont
)
106 #endif // wxUSE_FONTDLG
109 EVT_MENU(DIALOGS_LOG_DIALOG
, MyFrame::LogDialog
)
110 #endif // wxUSE_LOG_DIALOG
113 EVT_MENU(DIALOGS_TEXT_ENTRY
, MyFrame::TextEntry
)
114 EVT_MENU(DIALOGS_PASSWORD_ENTRY
, MyFrame::PasswordEntry
)
115 #endif // wxUSE_TEXTDLG
118 EVT_MENU(DIALOGS_NUM_ENTRY
, MyFrame::NumericEntry
)
119 #endif // wxUSE_NUMBERDLG
122 EVT_MENU(DIALOGS_SINGLE_CHOICE
, MyFrame::SingleChoice
)
123 EVT_MENU(DIALOGS_MULTI_CHOICE
, MyFrame::MultiChoice
)
124 #endif // wxUSE_CHOICEDLG
127 EVT_MENU(DIALOGS_FILE_OPEN
, MyFrame::FileOpen
)
128 EVT_MENU(DIALOGS_FILE_OPEN2
, MyFrame::FileOpen2
)
129 EVT_MENU(DIALOGS_FILES_OPEN
, MyFrame::FilesOpen
)
130 EVT_MENU(DIALOGS_FILE_SAVE
, MyFrame::FileSave
)
131 #endif // wxUSE_FILEDLG
133 #if USE_FILEDLG_GENERIC
134 EVT_MENU(DIALOGS_FILE_OPEN_GENERIC
, MyFrame::FileOpenGeneric
)
135 EVT_MENU(DIALOGS_FILES_OPEN_GENERIC
, MyFrame::FilesOpenGeneric
)
136 EVT_MENU(DIALOGS_FILE_SAVE_GENERIC
, MyFrame::FileSaveGeneric
)
137 #endif // USE_FILEDLG_GENERIC
140 EVT_MENU(DIALOGS_DIR_CHOOSE
, MyFrame::DirChoose
)
141 EVT_MENU(DIALOGS_DIRNEW_CHOOSE
, MyFrame::DirChooseNew
)
142 #endif // wxUSE_DIRDLG
144 #if USE_MODAL_PRESENTATION
145 EVT_MENU(DIALOGS_MODAL
, MyFrame::ModalDlg
)
146 EVT_MENU(DIALOGS_MODELESS
, MyFrame::ModelessDlg
)
149 #if wxUSE_STARTUP_TIPS
150 EVT_MENU(DIALOGS_TIP
, MyFrame::ShowTip
)
151 #endif // wxUSE_STARTUP_TIPS
153 #if USE_FONTDLG_GENERIC
154 EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC
, MyFrame::ChooseFontGeneric
)
155 #endif // USE_FONTDLG_GENERIC
157 #if USE_DIRDLG_GENERIC
158 EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE
, MyFrame::GenericDirChoose
)
159 #endif // wxMSW || wxMAC
161 #if USE_COLOURDLG_GENERIC
162 EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC
, MyFrame::ChooseColourGeneric
)
163 #endif // USE_COLOURDLG_GENERIC
165 #if wxUSE_PROGRESSDLG
166 EVT_MENU(DIALOGS_PROGRESS
, MyFrame::ShowProgress
)
167 #endif // wxUSE_PROGRESSDLG
170 EVT_MENU(DIALOGS_BUSYINFO
, MyFrame::ShowBusyInfo
)
171 #endif // wxUSE_BUSYINFO
173 #if wxUSE_FINDREPLDLG
174 EVT_MENU(DIALOGS_FIND
, MyFrame::ShowFindDialog
)
175 EVT_MENU(DIALOGS_REPLACE
, MyFrame::ShowReplaceDialog
)
177 EVT_FIND(wxID_ANY
, MyFrame::OnFindDialog
)
178 EVT_FIND_NEXT(wxID_ANY
, MyFrame::OnFindDialog
)
179 EVT_FIND_REPLACE(wxID_ANY
, MyFrame::OnFindDialog
)
180 EVT_FIND_REPLACE_ALL(wxID_ANY
, MyFrame::OnFindDialog
)
181 EVT_FIND_CLOSE(wxID_ANY
, MyFrame::OnFindDialog
)
182 #endif // wxUSE_FINDREPLDLG
184 EVT_MENU(wxID_EXIT
, MyFrame::OnExit
)
187 #if USE_MODAL_PRESENTATION
189 BEGIN_EVENT_TABLE(MyModalDialog
, wxDialog
)
190 EVT_BUTTON(wxID_ANY
, MyModalDialog::OnButton
)
193 BEGIN_EVENT_TABLE(MyModelessDialog
, wxDialog
)
194 EVT_BUTTON(DIALOGS_MODELESS_BTN
, MyModelessDialog::OnButton
)
195 EVT_CLOSE(MyModelessDialog::OnClose
)
198 #endif // USE_MODAL_PRESENTATION
200 MyCanvas
*myCanvas
= (MyCanvas
*) NULL
;
202 // `Main program' equivalent, creating windows and returning main app frame
206 wxInitAllImageHandlers();
209 #if defined(__WXGTK__) && defined(wxUSE_UNICODE)
210 wxConvCurrent
= &wxConvLibc
;
213 m_canvasTextColour
= wxColour(_T("BLACK"));
214 m_canvasFont
= *wxNORMAL_FONT
;
216 // Create the main frame window
217 MyFrame
*frame
= new MyFrame((wxFrame
*) NULL
, _T("wxWidgets dialogs example"));
220 wxMenu
*file_menu
= new wxMenu
;
222 file_menu
->Append(DIALOGS_MESSAGE_BOX
, _T("&Message box\tCtrl-M"));
225 #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
227 wxMenu
*choices_menu
= new wxMenu
;
230 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR
, _T("&Choose colour"));
231 #endif // wxUSE_COLOURDLG
234 choices_menu
->Append(DIALOGS_CHOOSE_FONT
, _T("Choose &font"));
235 #endif // wxUSE_FONTDLG
238 choices_menu
->Append(DIALOGS_SINGLE_CHOICE
, _T("&Single choice\tCtrl-C"));
239 choices_menu
->Append(DIALOGS_MULTI_CHOICE
, _T("M&ultiple choice\tCtrl-U"));
240 #endif // wxUSE_CHOICEDLG
242 #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
243 choices_menu
->AppendSeparator();
244 #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
246 #if USE_COLOURDLG_GENERIC
247 choices_menu
->Append(DIALOGS_CHOOSE_COLOUR_GENERIC
, _T("&Choose colour (generic)"));
248 #endif // USE_COLOURDLG_GENERIC
250 #if USE_FONTDLG_GENERIC
251 choices_menu
->Append(DIALOGS_CHOOSE_FONT_GENERIC
, _T("Choose &font (generic)"));
252 #endif // USE_FONTDLG_GENERIC
254 file_menu
->Append(wxID_ANY
,_T("Choices and selectors"),choices_menu
);
256 #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
259 #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG
261 wxMenu
*entry_menu
= new wxMenu
;
264 entry_menu
->Append(DIALOGS_TEXT_ENTRY
, _T("Text &entry\tCtrl-E"));
265 entry_menu
->Append(DIALOGS_PASSWORD_ENTRY
, _T("&Password entry\tCtrl-P"));
266 #endif // wxUSE_TEXTDLG
269 entry_menu
->Append(DIALOGS_NUM_ENTRY
, _T("&Numeric entry\tCtrl-N"));
270 #endif // wxUSE_NUMBERDLG
272 file_menu
->Append(wxID_ANY
,_T("Entry dialogs"),entry_menu
);
274 #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
279 wxMenu
*filedlg_menu
= new wxMenu
;
280 filedlg_menu
->Append(DIALOGS_FILE_OPEN
, _T("&Open file\tCtrl-O"));
281 filedlg_menu
->Append(DIALOGS_FILE_OPEN2
, _T("&Second open file\tCtrl-2"));
282 filedlg_menu
->Append(DIALOGS_FILES_OPEN
, _T("Open &files\tCtrl-Q"));
283 filedlg_menu
->Append(DIALOGS_FILE_SAVE
, _T("Sa&ve file\tCtrl-S"));
285 #if USE_FILEDLG_GENERIC
286 filedlg_menu
->AppendSeparator();
287 filedlg_menu
->Append(DIALOGS_FILE_OPEN_GENERIC
, _T("&Open file (generic)"));
288 filedlg_menu
->Append(DIALOGS_FILES_OPEN_GENERIC
, _T("Open &files (generic)"));
289 filedlg_menu
->Append(DIALOGS_FILE_SAVE_GENERIC
, _T("Sa&ve file (generic)"));
290 #endif // USE_FILEDLG_GENERIC
292 file_menu
->Append(wxID_ANY
,_T("File operations"),filedlg_menu
);
294 #endif // wxUSE_FILEDLG
297 wxMenu
*dir_menu
= new wxMenu
;
299 dir_menu
->Append(DIALOGS_DIR_CHOOSE
, _T("&Choose a directory\tCtrl-D"));
300 dir_menu
->Append(DIALOGS_DIRNEW_CHOOSE
, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
301 file_menu
->Append(wxID_ANY
,_T("Directory operations"),dir_menu
);
303 #if USE_DIRDLG_GENERIC
304 dir_menu
->AppendSeparator();
305 dir_menu
->Append(DIALOGS_GENERIC_DIR_CHOOSE
, _T("&Choose a directory (generic)"));
306 #endif // USE_DIRDLG_GENERIC
308 #endif // wxUSE_DIRDLG
311 #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
313 wxMenu
*info_menu
= new wxMenu
;
315 #if wxUSE_STARTUP_TIPS
316 info_menu
->Append(DIALOGS_TIP
, _T("&Tip of the day\tCtrl-T"));
317 #endif // wxUSE_STARTUP_TIPS
319 #if wxUSE_PROGRESSDLG
320 info_menu
->Append(DIALOGS_PROGRESS
, _T("Pro&gress dialog\tCtrl-G"));
321 #endif // wxUSE_PROGRESSDLG
324 info_menu
->Append(DIALOGS_BUSYINFO
, _T("&Busy info dialog\tCtrl-B"));
325 #endif // wxUSE_BUSYINFO
328 info_menu
->Append(DIALOGS_LOG_DIALOG
, _T("&Log dialog\tCtrl-L"));
329 #endif // wxUSE_LOG_DIALOG
331 file_menu
->Append(wxID_ANY
,_T("Informative dialogs"),info_menu
);
333 #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG
336 #if wxUSE_FINDREPLDLG
337 wxMenu
*find_menu
= new wxMenu
;
338 find_menu
->AppendCheckItem(DIALOGS_FIND
, _T("&Find dialog\tCtrl-F"));
339 find_menu
->AppendCheckItem(DIALOGS_REPLACE
, _T("Find and &replace dialog\tShift-Ctrl-F"));
340 file_menu
->Append(wxID_ANY
,_T("Searching"),find_menu
);
341 #endif // wxUSE_FINDREPLDLG
343 #if USE_MODAL_PRESENTATION
344 wxMenu
*modal_menu
= new wxMenu
;
345 modal_menu
->Append(DIALOGS_MODAL
, _T("Mo&dal dialog\tCtrl-W"));
346 modal_menu
->AppendCheckItem(DIALOGS_MODELESS
, _T("Modeless &dialog\tCtrl-Z"));
347 file_menu
->Append(wxID_ANY
,_T("Modal/Modeless"),modal_menu
);
348 #endif // USE_MODAL_PRESENTATION
350 file_menu
->AppendSeparator();
351 file_menu
->Append(wxID_EXIT
, _T("E&xit\tAlt-X"));
353 wxMenuBar
*menu_bar
= new wxMenuBar
;
354 menu_bar
->Append(file_menu
, _T("&File"));
355 frame
->SetMenuBar(menu_bar
);
357 myCanvas
= new MyCanvas(frame
);
358 myCanvas
->SetBackgroundColour(*wxWHITE
);
360 frame
->Centre(wxBOTH
);
370 // My frame constructor
371 MyFrame::MyFrame(wxWindow
*parent
,
372 const wxString
& title
)
373 : wxFrame(parent
, wxID_ANY
, title
)
375 #if USE_MODAL_PRESENTATION
376 m_dialog
= (MyModelessDialog
*)NULL
;
377 #endif // USE_MODAL_PRESENTATION
379 #if wxUSE_FINDREPLDLG
385 m_clrData
.SetChooseFull(true);
386 for (int i
= 0; i
< 16; i
++)
388 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
390 #endif // wxUSE_COLOURDLG
394 #endif // wxUSE_STATUSBAR
398 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
400 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
402 wxColourDialog
dialog(this, &m_clrData
);
403 dialog
.SetTitle(_T("Choose the background colour"));
404 if (dialog
.ShowModal() == wxID_OK
)
406 m_clrData
= dialog
.GetColourData();
407 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
408 myCanvas
->ClearBackground();
412 #endif // wxUSE_COLOURDLG
415 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
418 data
.SetInitialFont(wxGetApp().m_canvasFont
);
419 data
.SetColour(wxGetApp().m_canvasTextColour
);
421 // you might also do this:
423 // wxFontDialog dialog;
424 // if ( !dialog.Create(this, data) { ... error ... }
426 wxFontDialog
dialog(this, data
);
428 if (dialog
.ShowModal() == wxID_OK
)
430 wxFontData retData
= dialog
.GetFontData();
431 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
432 wxGetApp().m_canvasTextColour
= retData
.GetColour();
435 //else: cancelled by the user, don't change the font
437 #endif // wxUSE_FONTDLG
439 #if USE_COLOURDLG_GENERIC
440 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
443 data
.SetChooseFull(true);
444 for (int i
= 0; i
< 16; i
++)
446 wxColour
colour(i
*16, i
*16, i
*16);
447 data
.SetCustomColour(i
, colour
);
450 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
451 if (dialog
->ShowModal() == wxID_OK
)
453 wxColourData retData
= dialog
->GetColourData();
454 wxColour col
= retData
.GetColour();
455 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
456 myCanvas
->SetBackgroundColour(col
);
457 myCanvas
->ClearBackground();
462 #endif // USE_COLOURDLG_GENERIC
464 #if USE_FONTDLG_GENERIC
465 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
468 data
.SetInitialFont(wxGetApp().m_canvasFont
);
469 data
.SetColour(wxGetApp().m_canvasTextColour
);
471 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
472 if (dialog
->ShowModal() == wxID_OK
)
474 wxFontData retData
= dialog
->GetFontData();
475 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
476 wxGetApp().m_canvasTextColour
= retData
.GetColour();
481 #endif // USE_FONTDLG_GENERIC
484 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
486 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
487 // being flushed -- test it
490 wxLogMessage(wxT("This is some message - everything is ok so far."));
491 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
492 wxLogWarning(wxT("And then something went wrong!"));
494 // and if ~wxBusyCursor doesn't do it, then call it manually
498 wxLogError(wxT("Intermediary error handler decided to abort."));
499 wxLogError(wxT("The top level caller detected an unrecoverable error."));
501 wxLog::FlushActive();
503 wxLogMessage(wxT("And this is the same dialog but with only one message."));
505 #endif // wxUSE_LOG_DIALOG
507 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
509 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
510 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
512 switch ( dialog
.ShowModal() )
515 wxLogStatus(wxT("You pressed \"Yes\""));
519 wxLogStatus(wxT("You pressed \"No\""));
523 wxLogStatus(wxT("You pressed \"Cancel\""));
527 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
532 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
534 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
535 _T("Even two rows of text."),
536 _T("Enter a number:"), _T("Numeric input test"),
543 msg
= _T("Invalid number entered or dialog cancelled.");
548 msg
.Printf(_T("You've entered %lu"), res
);
549 icon
= wxICON_INFORMATION
;
552 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
554 #endif // wxUSE_NUMBERDLG
557 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
559 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
560 _T("Password entry dialog"),
565 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
566 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
570 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
572 wxTextEntryDialog
dialog(this,
573 _T("This is a small sample\n")
574 _T("A long, long string to test out the text entrybox"),
575 _T("Please enter a string"),
579 if (dialog
.ShowModal() == wxID_OK
)
581 wxMessageBox(dialog
.GetValue(), _T("Got string"), wxOK
| wxICON_INFORMATION
, this);
584 #endif // wxUSE_TEXTDLG
587 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
589 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
591 wxSingleChoiceDialog
dialog(this,
592 _T("This is a small sample\n")
593 _T("A single-choice convenience dialog"),
594 _T("Please select a value"),
595 WXSIZEOF(choices
), choices
);
597 dialog
.SetSelection(2);
599 if (dialog
.ShowModal() == wxID_OK
)
601 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
606 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
608 const wxString choices
[] =
610 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
611 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
612 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
615 wxArrayInt selections
;
616 size_t count
= wxGetMultipleChoices(selections
,
617 _T("This is a small sample\n")
618 _T("A multi-choice convenience dialog"),
619 _T("Please select a value"),
620 WXSIZEOF(choices
), choices
,
625 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
626 for ( size_t n
= 0; n
< count
; n
++ )
628 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
629 (unsigned)n
, (unsigned)selections
[n
],
630 choices
[selections
[n
]].c_str());
634 //else: cancelled or nothing selected
636 #endif // wxUSE_CHOICEDLG
639 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
644 _T("Testing open file dialog"),
648 _T("C++ files (*.cpp)|*.cpp")
650 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
654 dialog
.SetDirectory(wxGetHomeDir());
656 if (dialog
.ShowModal() == wxID_OK
)
659 info
.Printf(_T("Full file name: %s\n")
662 dialog
.GetPath().c_str(),
663 dialog
.GetDirectory().c_str(),
664 dialog
.GetFilename().c_str());
665 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
670 // this shows how to take advantage of specifying a default extension in the
671 // call to wxFileSelector: it is remembered after each new call and the next
672 // one will use it by default
673 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
675 static wxString s_extDef
;
676 wxString path
= wxFileSelector(
677 _T("Select the file to load"),
678 wxEmptyString
, wxEmptyString
,
680 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
688 // it is just a sample, would use wxSplitPath in real program
689 s_extDef
= path
.AfterLast(_T('.'));
691 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
692 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
695 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
699 _T("C++ files (*.cpp)|*.cpp");
701 _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
703 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
704 wxEmptyString
, wxEmptyString
, wildcards
,
707 if (dialog
.ShowModal() == wxID_OK
)
709 wxArrayString paths
, filenames
;
711 dialog
.GetPaths(paths
);
712 dialog
.GetFilenames(filenames
);
715 size_t count
= paths
.GetCount();
716 for ( size_t n
= 0; n
< count
; n
++ )
718 s
.Printf(_T("File %d: %s (%s)\n"),
719 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
723 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
726 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
731 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
733 wxFileDialog
dialog(this,
734 _T("Testing save file dialog"),
737 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
738 wxSAVE
|wxOVERWRITE_PROMPT
);
740 dialog
.SetFilterIndex(1);
742 if (dialog
.ShowModal() == wxID_OK
)
744 wxLogMessage(_T("%s, filter %d"),
745 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
748 #endif // wxUSE_FILEDLG
750 #if USE_FILEDLG_GENERIC
751 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
753 wxGenericFileDialog dialog
756 _T("Testing open file dialog"),
759 _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
762 dialog
.SetDirectory(wxGetHomeDir());
764 if (dialog
.ShowModal() == wxID_OK
)
767 info
.Printf(_T("Full file name: %s\n")
770 dialog
.GetPath().c_str(),
771 dialog
.GetDirectory().c_str(),
772 dialog
.GetFilename().c_str());
773 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
778 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
780 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
781 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
782 wxEmptyString
, wxEmptyString
, wildcards
,
785 if (dialog
.ShowModal() == wxID_OK
)
787 wxArrayString paths
, filenames
;
789 dialog
.GetPaths(paths
);
790 dialog
.GetFilenames(filenames
);
793 size_t count
= paths
.GetCount();
794 for ( size_t n
= 0; n
< count
; n
++ )
796 s
.Printf(_T("File %d: %s (%s)\n"),
797 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
801 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
804 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
809 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
811 wxGenericFileDialog
dialog(this,
812 _T("Testing save file dialog"),
815 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
816 wxSAVE
|wxOVERWRITE_PROMPT
);
818 dialog
.SetFilterIndex(1);
820 if (dialog
.ShowModal() == wxID_OK
)
822 wxLogMessage(_T("%s, filter %d"),
823 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
826 #endif // USE_FILEDLG_GENERIC
829 void MyFrame::DoDirChoose(int style
)
831 // pass some initial dir to wxDirDialog
833 wxGetHomeDir(&dirHome
);
835 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
837 if (dialog
.ShowModal() == wxID_OK
)
839 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
843 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
845 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
848 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
850 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
852 #endif // wxUSE_DIRDLG
854 #if USE_DIRDLG_GENERIC
855 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
857 // pass some initial dir to wxDirDialog
859 wxGetHomeDir(&dirHome
);
861 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
863 if (dialog
.ShowModal() == wxID_OK
)
865 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
869 #endif // USE_DIRDLG_GENERIC
871 #if USE_MODAL_PRESENTATION
872 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
874 MyModalDialog
dlg(this);
878 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
880 bool show
= GetMenuBar()->IsChecked(event
.GetId());
886 m_dialog
= new MyModelessDialog(this);
889 m_dialog
->Show(true);
896 #endif // USE_MODAL_PRESENTATION
898 #if wxUSE_STARTUP_TIPS
899 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
901 static size_t s_index
= (size_t)-1;
903 if ( s_index
== (size_t)-1 )
907 // this is completely bogus, we don't know how many lines are there
908 // in the file, but who cares, it's a demo only...
909 s_index
= rand() % 5;
912 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
914 bool showAtStartup
= wxShowTip(this, tipProvider
);
918 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
919 wxOK
| wxICON_INFORMATION
, this);
922 s_index
= tipProvider
->GetCurrentTip();
925 #endif // wxUSE_STARTUP_TIPS
927 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
932 #if wxUSE_PROGRESSDLG
934 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
936 static const int max
= 10;
938 wxProgressDialog
dialog(_T("Progress dialog example"),
939 _T("An informative message"),
944 // wxPD_AUTO_HIDE | -- try this as well
946 wxPD_ESTIMATED_TIME
|
947 wxPD_REMAINING_TIME
);
950 for ( int i
= 0; i
<= max
; i
++ )
955 cont
= dialog
.Update(i
, _T("That's all, folks!"));
957 else if ( i
== max
/ 2 )
959 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
963 cont
= dialog
.Update(i
);
968 if ( wxMessageBox(_T("Do you really want to cancel?"),
969 _T("Progress dialog question"), // caption
970 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
979 wxLogStatus(wxT("Progress dialog aborted!"));
983 wxLogStatus(wxT("Countdown from %d finished"), max
);
987 #endif // wxUSE_PROGRESSDLG
991 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
993 wxWindowDisabler disableAll
;
995 wxBusyInfo
info(_T("Working, please wait..."), this);
997 for ( int i
= 0; i
< 18; i
++ )
1007 #endif // wxUSE_BUSYINFO
1009 #if wxUSE_FINDREPLDLG
1011 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1015 delete m_dlgReplace
;
1016 m_dlgReplace
= NULL
;
1020 m_dlgReplace
= new wxFindReplaceDialog
1024 _T("Find and replace dialog"),
1028 m_dlgReplace
->Show(true);
1032 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1041 m_dlgFind
= new wxFindReplaceDialog
1050 m_dlgFind
->Show(true);
1054 static wxString
DecodeFindDialogEventFlags(int flags
)
1057 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1058 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1059 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1060 << _T("case sensitive");
1065 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1067 wxEventType type
= event
.GetEventType();
1069 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1071 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1072 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1073 event
.GetFindString().c_str(),
1074 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1076 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1077 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1079 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1080 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1081 event
.GetFindString().c_str(),
1082 event
.GetReplaceString().c_str(),
1083 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1085 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1087 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1091 if ( dlg
== m_dlgFind
)
1094 idMenu
= DIALOGS_FIND
;
1097 else if ( dlg
== m_dlgReplace
)
1099 txt
= _T("Replace");
1100 idMenu
= DIALOGS_REPLACE
;
1101 m_dlgReplace
= NULL
;
1105 txt
= _T("Unknown");
1108 wxFAIL_MSG( _T("unexpected event") );
1111 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1113 if ( idMenu
!= wxID_ANY
)
1115 GetMenuBar()->Check(idMenu
, false);
1122 wxLogError(wxT("Unknown find dialog event!"));
1126 #endif // wxUSE_FINDREPLDLG
1128 // ----------------------------------------------------------------------------
1130 // ----------------------------------------------------------------------------
1132 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1135 dc
.SetFont(wxGetApp().m_canvasFont
);
1136 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1137 dc
.SetBackgroundMode(wxTRANSPARENT
);
1139 _T("wxWidgets common dialogs")
1140 #if !defined(__SMARTPHONE__)
1141 _T(" test application")
1146 #if USE_MODAL_PRESENTATION
1148 // ----------------------------------------------------------------------------
1150 // ----------------------------------------------------------------------------
1152 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1153 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1155 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1157 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1158 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1161 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1162 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1166 sizerTop
->SetSizeHints(this);
1167 sizerTop
->Fit(this);
1170 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1172 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1173 wxOK
| wxICON_INFORMATION
, this);
1176 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1178 if ( event
.CanVeto() )
1180 wxMessageBox(_T("Use the menu item to close this dialog"),
1181 _T("Modeless dialog"),
1182 wxOK
| wxICON_INFORMATION
, this);
1188 // ----------------------------------------------------------------------------
1190 // ----------------------------------------------------------------------------
1192 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1193 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1195 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1197 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1198 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1199 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1201 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1202 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1203 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1204 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1205 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1209 sizerTop
->SetSizeHints(this);
1210 sizerTop
->Fit(this);
1212 m_btnModal
->SetFocus();
1213 m_btnModal
->SetDefault();
1216 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1218 if ( event
.GetEventObject() == m_btnDelete
)
1223 m_btnDelete
->Disable();
1225 else if ( event
.GetEventObject() == m_btnModal
)
1228 wxGetTextFromUser(_T("Dummy prompt"),
1229 _T("Modal dialog called from dialog"),
1230 wxEmptyString
, this);
1232 wxMessageBox(_T("Modal dialog called from dialog"));
1233 #endif // wxUSE_TEXTDLG
1235 else if ( event
.GetEventObject() == m_btnModeless
)
1237 (new MyModelessDialog(this))->Show();
1245 #endif // USE_MODAL_PRESENTATION