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 #if !defined( __SMARTPHONE__ )
354 wxMenuBar
*menu_bar
= new wxMenuBar
;
355 menu_bar
->Append(file_menu
, _T("&File"));
356 frame
->SetMenuBar(menu_bar
);
358 frame
->SetRightMenu(wxID_ANY
, _T("Menu"), file_menu
);
359 #endif // __SMARTPHONE__
361 myCanvas
= new MyCanvas(frame
);
362 myCanvas
->SetBackgroundColour(*wxWHITE
);
364 frame
->Centre(wxBOTH
);
374 // My frame constructor
375 MyFrame::MyFrame(wxWindow
*parent
,
376 const wxString
& title
)
377 : wxFrame(parent
, wxID_ANY
, title
)
379 #if USE_MODAL_PRESENTATION
380 m_dialog
= (MyModelessDialog
*)NULL
;
381 #endif // USE_MODAL_PRESENTATION
383 #if wxUSE_FINDREPLDLG
389 m_clrData
.SetChooseFull(true);
390 for (int i
= 0; i
< 16; i
++)
392 m_clrData
.SetCustomColour(i
, wxColour(i
*16, i
*16, i
*16));
394 #endif // wxUSE_COLOURDLG
398 #endif // wxUSE_STATUSBAR
402 void MyFrame::ChooseColour(wxCommandEvent
& WXUNUSED(event
) )
404 m_clrData
.SetColour(myCanvas
->GetBackgroundColour());
406 wxColourDialog
dialog(this, &m_clrData
);
407 dialog
.SetTitle(_T("Choose the background colour"));
408 if (dialog
.ShowModal() == wxID_OK
)
410 m_clrData
= dialog
.GetColourData();
411 myCanvas
->SetBackgroundColour(m_clrData
.GetColour());
412 myCanvas
->ClearBackground();
416 #endif // wxUSE_COLOURDLG
419 void MyFrame::ChooseFont(wxCommandEvent
& WXUNUSED(event
) )
422 data
.SetInitialFont(wxGetApp().m_canvasFont
);
423 data
.SetColour(wxGetApp().m_canvasTextColour
);
425 // you might also do this:
427 // wxFontDialog dialog;
428 // if ( !dialog.Create(this, data) { ... error ... }
430 wxFontDialog
dialog(this, data
);
432 if (dialog
.ShowModal() == wxID_OK
)
434 wxFontData retData
= dialog
.GetFontData();
435 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
436 wxGetApp().m_canvasTextColour
= retData
.GetColour();
439 //else: cancelled by the user, don't change the font
441 #endif // wxUSE_FONTDLG
443 #if USE_COLOURDLG_GENERIC
444 void MyFrame::ChooseColourGeneric(wxCommandEvent
& WXUNUSED(event
))
447 data
.SetChooseFull(true);
448 for (int i
= 0; i
< 16; i
++)
450 wxColour
colour(i
*16, i
*16, i
*16);
451 data
.SetCustomColour(i
, colour
);
454 wxGenericColourDialog
*dialog
= new wxGenericColourDialog(this, &data
);
455 if (dialog
->ShowModal() == wxID_OK
)
457 wxColourData retData
= dialog
->GetColourData();
458 wxColour col
= retData
.GetColour();
459 // wxBrush *brush = wxTheBrushList->FindOrCreateBrush(&col, wxSOLID);
460 myCanvas
->SetBackgroundColour(col
);
461 myCanvas
->ClearBackground();
466 #endif // USE_COLOURDLG_GENERIC
468 #if USE_FONTDLG_GENERIC
469 void MyFrame::ChooseFontGeneric(wxCommandEvent
& WXUNUSED(event
) )
472 data
.SetInitialFont(wxGetApp().m_canvasFont
);
473 data
.SetColour(wxGetApp().m_canvasTextColour
);
475 wxGenericFontDialog
*dialog
= new wxGenericFontDialog(this, &data
);
476 if (dialog
->ShowModal() == wxID_OK
)
478 wxFontData retData
= dialog
->GetFontData();
479 wxGetApp().m_canvasFont
= retData
.GetChosenFont();
480 wxGetApp().m_canvasTextColour
= retData
.GetColour();
485 #endif // USE_FONTDLG_GENERIC
487 void MyFrame::LogDialog(wxCommandEvent
& WXUNUSED(event
))
489 // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
490 // being flushed -- test it
493 wxLogMessage(wxT("This is some message - everything is ok so far."));
494 wxLogMessage(wxT("Another message...\n... this one is on multiple lines"));
495 wxLogWarning(wxT("And then something went wrong!"));
497 // and if ~wxBusyCursor doesn't do it, then call it manually
501 wxLogError(wxT("Intermediary error handler decided to abort."));
502 wxLogError(wxT("The top level caller detected an unrecoverable error."));
504 wxLog::FlushActive();
506 wxLogMessage(wxT("And this is the same dialog but with only one message."));
509 void MyFrame::MessageBox(wxCommandEvent
& WXUNUSED(event
) )
511 wxMessageDialog
dialog( NULL
, _T("This is a message box\nA long, long string to test out the message box properly"),
512 _T("Message box text"), wxNO_DEFAULT
|wxYES_NO
|wxCANCEL
|wxICON_INFORMATION
);
514 switch ( dialog
.ShowModal() )
517 wxLogStatus(wxT("You pressed \"Yes\""));
521 wxLogStatus(wxT("You pressed \"No\""));
525 wxLogStatus(wxT("You pressed \"Cancel\""));
529 wxLogError(wxT("Unexpected wxMessageDialog return code!"));
534 void MyFrame::NumericEntry(wxCommandEvent
& WXUNUSED(event
) )
536 long res
= wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n")
537 _T("Even two rows of text."),
538 _T("Enter a number:"), _T("Numeric input test"),
545 msg
= _T("Invalid number entered or dialog cancelled.");
550 msg
.Printf(_T("You've entered %lu"), res
);
551 icon
= wxICON_INFORMATION
;
554 wxMessageBox(msg
, _T("Numeric test result"), wxOK
| icon
, this);
556 #endif // wxUSE_NUMBERDLG
559 void MyFrame::PasswordEntry(wxCommandEvent
& WXUNUSED(event
))
561 wxString pwd
= wxGetPasswordFromUser(_T("Enter password:"),
562 _T("Password entry dialog"),
567 wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd
.c_str()),
568 _T("Got password"), wxOK
| wxICON_INFORMATION
, this);
572 void MyFrame::TextEntry(wxCommandEvent
& WXUNUSED(event
))
574 wxTextEntryDialog
dialog(this,
575 _T("This is a small sample\n")
576 _T("A long, long string to test out the text entrybox"),
577 _T("Please enter a string"),
581 if (dialog
.ShowModal() == wxID_OK
)
583 wxMessageDialog
dialog2(this, dialog
.GetValue(), _T("Got string"));
587 #endif // wxUSE_TEXTDLG
590 void MyFrame::SingleChoice(wxCommandEvent
& WXUNUSED(event
) )
592 const wxString choices
[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ;
594 wxSingleChoiceDialog
dialog(this,
595 _T("This is a small sample\n")
596 _T("A single-choice convenience dialog"),
597 _T("Please select a value"),
598 WXSIZEOF(choices
), choices
);
600 dialog
.SetSelection(2);
602 if (dialog
.ShowModal() == wxID_OK
)
604 wxMessageDialog
dialog2(this, dialog
.GetStringSelection(), _T("Got string"));
609 void MyFrame::MultiChoice(wxCommandEvent
& WXUNUSED(event
) )
611 const wxString choices
[] =
613 _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"),
614 _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"),
615 _T("Eleven"), _T("Twelve"), _T("Seventeen"),
618 wxArrayInt selections
;
619 size_t count
= wxGetMultipleChoices(selections
,
620 _T("This is a small sample\n")
621 _T("A multi-choice convenience dialog"),
622 _T("Please select a value"),
623 WXSIZEOF(choices
), choices
,
628 msg
.Printf(wxT("You selected %u items:\n"), (unsigned)count
);
629 for ( size_t n
= 0; n
< count
; n
++ )
631 msg
+= wxString::Format(wxT("\t%u: %u (%s)\n"),
632 (unsigned)n
, (unsigned)selections
[n
],
633 choices
[selections
[n
]].c_str());
637 //else: cancelled or nothing selected
639 #endif // wxUSE_CHOICEDLG
642 void MyFrame::FileOpen(wxCommandEvent
& WXUNUSED(event
) )
647 _T("Testing open file dialog"),
651 _T("C++ files (*.cpp)|*.cpp")
653 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
657 dialog
.SetDirectory(wxGetHomeDir());
659 if (dialog
.ShowModal() == wxID_OK
)
662 info
.Printf(_T("Full file name: %s\n")
665 dialog
.GetPath().c_str(),
666 dialog
.GetDirectory().c_str(),
667 dialog
.GetFilename().c_str());
668 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
673 // this shows how to take advantage of specifying a default extension in the
674 // call to wxFileSelector: it is remembered after each new call and the next
675 // one will use it by default
676 void MyFrame::FileOpen2(wxCommandEvent
& WXUNUSED(event
) )
678 static wxString s_extDef
;
679 wxString path
= wxFileSelector(
680 _T("Select the file to load"),
681 wxEmptyString
, wxEmptyString
,
683 _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"),
691 // it is just a sample, would use wxSplitPath in real program
692 s_extDef
= path
.AfterLast(_T('.'));
694 wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"),
695 (const wxChar
*) path
, (const wxChar
*) s_extDef
);
698 void MyFrame::FilesOpen(wxCommandEvent
& WXUNUSED(event
) )
702 _T("C++ files (*.cpp)|*.cpp");
704 _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
706 wxFileDialog
dialog(this, _T("Testing open multiple file dialog"),
707 wxEmptyString
, wxEmptyString
, wildcards
,
710 if (dialog
.ShowModal() == wxID_OK
)
712 wxArrayString paths
, filenames
;
714 dialog
.GetPaths(paths
);
715 dialog
.GetFilenames(filenames
);
718 size_t count
= paths
.GetCount();
719 for ( size_t n
= 0; n
< count
; n
++ )
721 s
.Printf(_T("File %d: %s (%s)\n"),
722 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
726 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
729 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
734 void MyFrame::FileSave(wxCommandEvent
& WXUNUSED(event
) )
736 wxFileDialog
dialog(this,
737 _T("Testing save file dialog"),
740 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
741 wxSAVE
|wxOVERWRITE_PROMPT
);
743 dialog
.SetFilterIndex(1);
745 if (dialog
.ShowModal() == wxID_OK
)
747 wxLogMessage(_T("%s, filter %d"),
748 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
751 #endif // wxUSE_FILEDLG
753 #if USE_FILEDLG_GENERIC
754 void MyFrame::FileOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
756 wxGenericFileDialog dialog
759 _T("Testing open file dialog"),
762 _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
765 dialog
.SetDirectory(wxGetHomeDir());
767 if (dialog
.ShowModal() == wxID_OK
)
770 info
.Printf(_T("Full file name: %s\n")
773 dialog
.GetPath().c_str(),
774 dialog
.GetDirectory().c_str(),
775 dialog
.GetFilename().c_str());
776 wxMessageDialog
dialog2(this, info
, _T("Selected file"));
781 void MyFrame::FilesOpenGeneric(wxCommandEvent
& WXUNUSED(event
) )
783 wxString wildcards
= _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
784 wxGenericFileDialog
dialog(this, _T("Testing open multiple file dialog"),
785 wxEmptyString
, wxEmptyString
, wildcards
,
788 if (dialog
.ShowModal() == wxID_OK
)
790 wxArrayString paths
, filenames
;
792 dialog
.GetPaths(paths
);
793 dialog
.GetFilenames(filenames
);
796 size_t count
= paths
.GetCount();
797 for ( size_t n
= 0; n
< count
; n
++ )
799 s
.Printf(_T("File %d: %s (%s)\n"),
800 (int)n
, paths
[n
].c_str(), filenames
[n
].c_str());
804 s
.Printf(_T("Filter index: %d"), dialog
.GetFilterIndex());
807 wxMessageDialog
dialog2(this, msg
, _T("Selected files"));
812 void MyFrame::FileSaveGeneric(wxCommandEvent
& WXUNUSED(event
) )
814 wxGenericFileDialog
dialog(this,
815 _T("Testing save file dialog"),
818 _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
819 wxSAVE
|wxOVERWRITE_PROMPT
);
821 dialog
.SetFilterIndex(1);
823 if (dialog
.ShowModal() == wxID_OK
)
825 wxLogMessage(_T("%s, filter %d"),
826 dialog
.GetPath().c_str(), dialog
.GetFilterIndex());
829 #endif // USE_FILEDLG_GENERIC
832 void MyFrame::DoDirChoose(int style
)
834 // pass some initial dir to wxDirDialog
836 wxGetHomeDir(&dirHome
);
838 wxDirDialog
dialog(this, _T("Testing directory picker"), dirHome
, style
);
840 if (dialog
.ShowModal() == wxID_OK
)
842 wxLogMessage(_T("Selected path: %s"), dialog
.GetPath().c_str());
846 void MyFrame::DirChoose(wxCommandEvent
& WXUNUSED(event
) )
848 DoDirChoose(wxDD_DEFAULT_STYLE
& ~wxDD_NEW_DIR_BUTTON
);
851 void MyFrame::DirChooseNew(wxCommandEvent
& WXUNUSED(event
) )
853 DoDirChoose(wxDD_DEFAULT_STYLE
| wxDD_NEW_DIR_BUTTON
);
855 #endif // wxUSE_DIRDLG
857 #if USE_DIRDLG_GENERIC
858 void MyFrame::GenericDirChoose(wxCommandEvent
& WXUNUSED(event
) )
860 // pass some initial dir to wxDirDialog
862 wxGetHomeDir(&dirHome
);
864 wxGenericDirDialog
dialog(this, _T("Testing generic directory picker"), dirHome
);
866 if (dialog
.ShowModal() == wxID_OK
)
868 wxMessageDialog
dialog2(this, dialog
.GetPath(), _T("Selected path"));
872 #endif // USE_DIRDLG_GENERIC
874 #if USE_MODAL_PRESENTATION
875 void MyFrame::ModalDlg(wxCommandEvent
& WXUNUSED(event
))
877 MyModalDialog
dlg(this);
881 void MyFrame::ModelessDlg(wxCommandEvent
& event
)
883 bool show
= GetMenuBar()->IsChecked(event
.GetId());
889 m_dialog
= new MyModelessDialog(this);
892 m_dialog
->Show(true);
899 #endif // USE_MODAL_PRESENTATION
901 #if wxUSE_STARTUP_TIPS
902 void MyFrame::ShowTip(wxCommandEvent
& WXUNUSED(event
))
904 static size_t s_index
= (size_t)-1;
906 if ( s_index
== (size_t)-1 )
910 // this is completely bogus, we don't know how many lines are there
911 // in the file, but who cares, it's a demo only...
912 s_index
= rand() % 5;
915 wxTipProvider
*tipProvider
= wxCreateFileTipProvider(_T("tips.txt"), s_index
);
917 bool showAtStartup
= wxShowTip(this, tipProvider
);
921 wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"),
922 wxOK
| wxICON_INFORMATION
, this);
925 s_index
= tipProvider
->GetCurrentTip();
928 #endif // wxUSE_STARTUP_TIPS
930 void MyFrame::OnExit(wxCommandEvent
& WXUNUSED(event
) )
935 #if wxUSE_PROGRESSDLG
937 void MyFrame::ShowProgress( wxCommandEvent
& WXUNUSED(event
) )
939 static const int max
= 10;
941 wxProgressDialog
dialog(_T("Progress dialog example"),
942 _T("An informative message"),
947 // wxPD_AUTO_HIDE | -- try this as well
949 wxPD_ESTIMATED_TIME
|
950 wxPD_REMAINING_TIME
);
953 for ( int i
= 0; i
<= max
; i
++ )
958 cont
= dialog
.Update(i
, _T("That's all, folks!"));
960 else if ( i
== max
/ 2 )
962 cont
= dialog
.Update(i
, _T("Only a half left (very long message)!"));
966 cont
= dialog
.Update(i
);
971 if ( wxMessageBox(_T("Do you really want to cancel?"),
972 _T("Progress dialog question"), // caption
973 wxYES_NO
| wxICON_QUESTION
) == wxYES
)
982 wxLogStatus(wxT("Progress dialog aborted!"));
986 wxLogStatus(wxT("Countdown from %d finished"), max
);
990 #endif // wxUSE_PROGRESSDLG
994 void MyFrame::ShowBusyInfo(wxCommandEvent
& WXUNUSED(event
))
996 wxWindowDisabler disableAll
;
998 wxBusyInfo
info(_T("Working, please wait..."), this);
1000 for ( int i
= 0; i
< 18; i
++ )
1010 #endif // wxUSE_BUSYINFO
1012 #if wxUSE_FINDREPLDLG
1014 void MyFrame::ShowReplaceDialog( wxCommandEvent
& WXUNUSED(event
) )
1018 delete m_dlgReplace
;
1019 m_dlgReplace
= NULL
;
1023 m_dlgReplace
= new wxFindReplaceDialog
1027 _T("Find and replace dialog"),
1031 m_dlgReplace
->Show(true);
1035 void MyFrame::ShowFindDialog( wxCommandEvent
& WXUNUSED(event
) )
1044 m_dlgFind
= new wxFindReplaceDialog
1053 m_dlgFind
->Show(true);
1057 static wxString
DecodeFindDialogEventFlags(int flags
)
1060 str
<< (flags
& wxFR_DOWN
? _T("down") : _T("up")) << _T(", ")
1061 << (flags
& wxFR_WHOLEWORD
? _T("whole words only, ") : _T(""))
1062 << (flags
& wxFR_MATCHCASE
? _T("") : _T("not "))
1063 << _T("case sensitive");
1068 void MyFrame::OnFindDialog(wxFindDialogEvent
& event
)
1070 wxEventType type
= event
.GetEventType();
1072 if ( type
== wxEVT_COMMAND_FIND
|| type
== wxEVT_COMMAND_FIND_NEXT
)
1074 wxLogMessage(wxT("Find %s'%s' (flags: %s)"),
1075 type
== wxEVT_COMMAND_FIND_NEXT
? wxT("next ") : wxT(""),
1076 event
.GetFindString().c_str(),
1077 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1079 else if ( type
== wxEVT_COMMAND_FIND_REPLACE
||
1080 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
)
1082 wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"),
1083 type
== wxEVT_COMMAND_FIND_REPLACE_ALL
? _T("all ") : wxT(""),
1084 event
.GetFindString().c_str(),
1085 event
.GetReplaceString().c_str(),
1086 DecodeFindDialogEventFlags(event
.GetFlags()).c_str());
1088 else if ( type
== wxEVT_COMMAND_FIND_CLOSE
)
1090 wxFindReplaceDialog
*dlg
= event
.GetDialog();
1094 if ( dlg
== m_dlgFind
)
1097 idMenu
= DIALOGS_FIND
;
1100 else if ( dlg
== m_dlgReplace
)
1102 txt
= _T("Replace");
1103 idMenu
= DIALOGS_REPLACE
;
1104 m_dlgReplace
= NULL
;
1108 txt
= _T("Unknown");
1111 wxFAIL_MSG( _T("unexpected event") );
1114 wxLogMessage(wxT("%s dialog is being closed."), txt
);
1116 if ( idMenu
!= wxID_ANY
)
1118 GetMenuBar()->Check(idMenu
, false);
1125 wxLogError(wxT("Unknown find dialog event!"));
1129 #endif // wxUSE_FINDREPLDLG
1131 // ----------------------------------------------------------------------------
1133 // ----------------------------------------------------------------------------
1135 void MyCanvas::OnPaint(wxPaintEvent
& WXUNUSED(event
) )
1138 dc
.SetFont(wxGetApp().m_canvasFont
);
1139 dc
.SetTextForeground(wxGetApp().m_canvasTextColour
);
1140 dc
.SetBackgroundMode(wxTRANSPARENT
);
1141 dc
.DrawText(_T("wxWidgets common dialogs test application"), 10, 10);
1144 // ----------------------------------------------------------------------------
1146 // ----------------------------------------------------------------------------
1148 MyModelessDialog::MyModelessDialog(wxWindow
*parent
)
1149 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modeless dialog")))
1151 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxVERTICAL
);
1153 wxButton
*btn
= new wxButton(this, DIALOGS_MODELESS_BTN
, _T("Press me"));
1154 wxCheckBox
*check
= new wxCheckBox(this, wxID_ANY
, _T("Should be disabled"));
1157 sizerTop
->Add(btn
, 1, wxEXPAND
| wxALL
, 5);
1158 sizerTop
->Add(check
, 1, wxEXPAND
| wxALL
, 5);
1162 sizerTop
->SetSizeHints(this);
1163 sizerTop
->Fit(this);
1166 void MyModelessDialog::OnButton(wxCommandEvent
& WXUNUSED(event
))
1168 wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"),
1169 wxOK
| wxICON_INFORMATION
, this);
1172 void MyModelessDialog::OnClose(wxCloseEvent
& event
)
1174 if ( event
.CanVeto() )
1176 wxMessageBox(_T("Use the menu item to close this dialog"),
1177 _T("Modeless dialog"),
1178 wxOK
| wxICON_INFORMATION
, this);
1184 // ----------------------------------------------------------------------------
1186 // ----------------------------------------------------------------------------
1188 MyModalDialog::MyModalDialog(wxWindow
*parent
)
1189 : wxDialog(parent
, wxID_ANY
, wxString(_T("Modal dialog")))
1191 wxBoxSizer
*sizerTop
= new wxBoxSizer(wxHORIZONTAL
);
1193 m_btnModal
= new wxButton(this, wxID_ANY
, _T("&Modal dialog..."));
1194 m_btnModeless
= new wxButton(this, wxID_ANY
, _T("Mode&less dialog"));
1195 m_btnDelete
= new wxButton(this, wxID_ANY
, _T("&Delete button"));
1197 wxButton
*btnOk
= new wxButton(this, wxID_CANCEL
, _T("&Close"));
1198 sizerTop
->Add(m_btnModal
, 0, wxALIGN_CENTER
| wxALL
, 5);
1199 sizerTop
->Add(m_btnModeless
, 0, wxALIGN_CENTER
| wxALL
, 5);
1200 sizerTop
->Add(m_btnDelete
, 0, wxALIGN_CENTER
| wxALL
, 5);
1201 sizerTop
->Add(btnOk
, 0, wxALIGN_CENTER
| wxALL
, 5);
1205 sizerTop
->SetSizeHints(this);
1206 sizerTop
->Fit(this);
1208 m_btnModal
->SetFocus();
1209 m_btnModal
->SetDefault();
1212 void MyModalDialog::OnButton(wxCommandEvent
& event
)
1214 if ( event
.GetEventObject() == m_btnDelete
)
1219 m_btnDelete
->Disable();
1221 else if ( event
.GetEventObject() == m_btnModal
)
1224 wxGetTextFromUser(_T("Dummy prompt"),
1225 _T("Modal dialog called from dialog"),
1226 wxEmptyString
, this);
1228 wxMessageBox(_T("Modal dialog called from dialog"));
1229 #endif // wxUSE_TEXTDLG
1231 else if ( event
.GetEventObject() == m_btnModeless
)
1233 (new MyModelessDialog(this))->Show();