]>
Commit | Line | Data |
---|---|---|
457814b5 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dialogs.cpp | |
3 | // Purpose: Common dialogs demo | |
4 | // Author: Julian Smart | |
695fe764 | 5 | // Modified by: ABX (2004) - adjustements for conditional building + new menu |
457814b5 JS |
6 | // Created: 04/01/98 |
7 | // RCS-ID: $Id$ | |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
c50f1fb9 | 9 | // Licence: wxWindows license |
457814b5 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
457814b5 JS |
12 | // For compilers that support precompilation, includes "wx/wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifdef __BORLANDC__ | |
16 | #pragma hdrstop | |
17 | #endif | |
18 | ||
19 | #ifndef WX_PRECOMP | |
20 | #include "wx/wx.h" | |
21 | #endif | |
22 | ||
0f5d8ecf JS |
23 | #include "../sample.xpm" |
24 | ||
fb8a56b7 | 25 | #include "wx/datetime.h" |
f517634c | 26 | #include "wx/image.h" |
5378558e | 27 | #include "wx/bookctrl.h" |
cc8bc5aa | 28 | #include "wx/artprov.h" |
2b923807 | 29 | #include "wx/imaglist.h" |
457814b5 | 30 | |
13188def WS |
31 | #if wxUSE_COLOURDLG |
32 | #include "wx/colordlg.h" | |
33 | #endif // wxUSE_COLOURDLG | |
dfad0599 | 34 | |
13188def WS |
35 | #if wxUSE_CHOICEDLG |
36 | #include "wx/choicdlg.h" | |
37 | #endif // wxUSE_CHOICEDLG | |
457814b5 | 38 | |
13188def WS |
39 | #if wxUSE_STARTUP_TIPS |
40 | #include "wx/tipdlg.h" | |
41 | #endif // wxUSE_STARTUP_TIPS | |
d7d17624 | 42 | |
13188def | 43 | #if wxUSE_PROGRESSDLG |
9b16ffef | 44 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
b20edf8b | 45 | #include "wx/datetime.h" // wxDateTime |
9b16ffef VZ |
46 | #endif |
47 | ||
13188def WS |
48 | #include "wx/progdlg.h" |
49 | #endif // wxUSE_PROGRESSDLG | |
50 | ||
51 | #if wxUSE_BUSYINFO | |
52 | #include "wx/busyinfo.h" | |
53 | #endif // wxUSE_BUSYINFO | |
54 | ||
55 | #if wxUSE_NUMBERDLG | |
56 | #include "wx/numdlg.h" | |
57 | #endif // wxUSE_NUMBERDLG | |
58 | ||
59 | #if wxUSE_FILEDLG | |
60 | #include "wx/filedlg.h" | |
61 | #endif // wxUSE_FILEDLG | |
62 | ||
63 | #if wxUSE_DIRDLG | |
64 | #include "wx/dirdlg.h" | |
65 | #endif // wxUSE_DIRDLG | |
66 | ||
67 | #if wxUSE_FONTDLG | |
68 | #include "wx/fontdlg.h" | |
69 | #endif // wxUSE_FONTDLG | |
70 | ||
71 | #if wxUSE_FINDREPLDLG | |
72 | #include "wx/fdrepdlg.h" | |
73 | #endif // wxUSE_FINDREPLDLG | |
4ad3c82f | 74 | |
62675ef3 | 75 | #if wxUSE_SPINCTRL |
0f5d8ecf | 76 | #include "wx/spinctrl.h" |
62675ef3 JS |
77 | #endif |
78 | ||
0f5d8ecf JS |
79 | #include "wx/propdlg.h" |
80 | ||
457814b5 JS |
81 | #include "dialogs.h" |
82 | ||
13188def WS |
83 | #if USE_COLOURDLG_GENERIC |
84 | #include "wx/generic/colrdlgg.h" | |
85 | #endif // USE_COLOURDLG_GENERIC | |
86 | ||
13188def WS |
87 | #if USE_DIRDLG_GENERIC |
88 | #include "wx/generic/dirdlgg.h" | |
89 | #endif // USE_DIRDLG_GENERIC | |
90 | ||
695fe764 WS |
91 | #if USE_FILEDLG_GENERIC |
92 | #include "wx/generic/filedlgg.h" | |
93 | #endif // USE_FILEDLG_GENERIC | |
94 | ||
95 | #if USE_FONTDLG_GENERIC | |
96 | #include "wx/generic/fontdlgg.h" | |
97 | #endif // USE_FONTDLG_GENERIC | |
98 | ||
457814b5 JS |
99 | IMPLEMENT_APP(MyApp) |
100 | ||
4c45f240 VZ |
101 | BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow) |
102 | EVT_PAINT(MyCanvas::OnPaint) | |
103 | END_EVENT_TABLE() | |
104 | ||
13188def WS |
105 | |
106 | ||
4c45f240 | 107 | BEGIN_EVENT_TABLE(MyFrame, wxFrame) |
13188def WS |
108 | EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) |
109 | ||
110 | #if wxUSE_COLOURDLG | |
4c45f240 | 111 | EVT_MENU(DIALOGS_CHOOSE_COLOUR, MyFrame::ChooseColour) |
13188def WS |
112 | #endif // wxUSE_COLOURDLG |
113 | ||
114 | #if wxUSE_FONTDLG | |
4c45f240 | 115 | EVT_MENU(DIALOGS_CHOOSE_FONT, MyFrame::ChooseFont) |
13188def WS |
116 | #endif // wxUSE_FONTDLG |
117 | ||
118 | #if wxUSE_LOG_DIALOG | |
4c45f240 | 119 | EVT_MENU(DIALOGS_LOG_DIALOG, MyFrame::LogDialog) |
13188def WS |
120 | #endif // wxUSE_LOG_DIALOG |
121 | ||
122 | #if wxUSE_TEXTDLG | |
4c45f240 VZ |
123 | EVT_MENU(DIALOGS_TEXT_ENTRY, MyFrame::TextEntry) |
124 | EVT_MENU(DIALOGS_PASSWORD_ENTRY, MyFrame::PasswordEntry) | |
13188def WS |
125 | #endif // wxUSE_TEXTDLG |
126 | ||
127 | #if wxUSE_NUMBERDLG | |
4c45f240 | 128 | EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) |
13188def WS |
129 | #endif // wxUSE_NUMBERDLG |
130 | ||
131 | #if wxUSE_CHOICEDLG | |
4c45f240 | 132 | EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) |
d6c9c1b7 | 133 | EVT_MENU(DIALOGS_MULTI_CHOICE, MyFrame::MultiChoice) |
13188def WS |
134 | #endif // wxUSE_CHOICEDLG |
135 | ||
136 | #if wxUSE_FILEDLG | |
4c45f240 | 137 | EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) |
35b45b33 | 138 | EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) |
4c45f240 VZ |
139 | EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) |
140 | EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) | |
13188def WS |
141 | #endif // wxUSE_FILEDLG |
142 | ||
695fe764 WS |
143 | #if USE_FILEDLG_GENERIC |
144 | EVT_MENU(DIALOGS_FILE_OPEN_GENERIC, MyFrame::FileOpenGeneric) | |
145 | EVT_MENU(DIALOGS_FILES_OPEN_GENERIC, MyFrame::FilesOpenGeneric) | |
146 | EVT_MENU(DIALOGS_FILE_SAVE_GENERIC, MyFrame::FileSaveGeneric) | |
147 | #endif // USE_FILEDLG_GENERIC | |
148 | ||
13188def | 149 | #if wxUSE_DIRDLG |
4c45f240 | 150 | EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) |
f09c8393 | 151 | EVT_MENU(DIALOGS_DIRNEW_CHOOSE, MyFrame::DirChooseNew) |
13188def WS |
152 | #endif // wxUSE_DIRDLG |
153 | ||
154 | #if USE_MODAL_PRESENTATION | |
f6bcfd97 | 155 | EVT_MENU(DIALOGS_MODAL, MyFrame::ModalDlg) |
4c45f240 | 156 | EVT_MENU(DIALOGS_MODELESS, MyFrame::ModelessDlg) |
cae50e6b VZ |
157 | EVT_MENU(DIALOGS_CENTRE_SCREEN, MyFrame::DlgCenteredScreen) |
158 | EVT_MENU(DIALOGS_CENTRE_PARENT, MyFrame::DlgCenteredParent) | |
13188def WS |
159 | #endif // USE_MODAL |
160 | ||
161 | #if wxUSE_STARTUP_TIPS | |
4c45f240 | 162 | EVT_MENU(DIALOGS_TIP, MyFrame::ShowTip) |
13188def WS |
163 | #endif // wxUSE_STARTUP_TIPS |
164 | ||
165 | #if USE_FONTDLG_GENERIC | |
4c45f240 | 166 | EVT_MENU(DIALOGS_CHOOSE_FONT_GENERIC, MyFrame::ChooseFontGeneric) |
13188def WS |
167 | #endif // USE_FONTDLG_GENERIC |
168 | ||
169 | #if USE_DIRDLG_GENERIC | |
170 | EVT_MENU(DIALOGS_GENERIC_DIR_CHOOSE, MyFrame::GenericDirChoose) | |
171 | #endif // wxMSW || wxMAC | |
172 | ||
173 | #if USE_COLOURDLG_GENERIC | |
174 | EVT_MENU(DIALOGS_CHOOSE_COLOUR_GENERIC, MyFrame::ChooseColourGeneric) | |
175 | #endif // USE_COLOURDLG_GENERIC | |
a62b0bcc | 176 | |
abceee76 VZ |
177 | #if wxUSE_PROGRESSDLG |
178 | EVT_MENU(DIALOGS_PROGRESS, MyFrame::ShowProgress) | |
761989ff | 179 | #endif // wxUSE_PROGRESSDLG |
a62b0bcc VZ |
180 | |
181 | #if wxUSE_BUSYINFO | |
182 | EVT_MENU(DIALOGS_BUSYINFO, MyFrame::ShowBusyInfo) | |
183 | #endif // wxUSE_BUSYINFO | |
184 | ||
761989ff VZ |
185 | #if wxUSE_FINDREPLDLG |
186 | EVT_MENU(DIALOGS_FIND, MyFrame::ShowFindDialog) | |
187 | EVT_MENU(DIALOGS_REPLACE, MyFrame::ShowReplaceDialog) | |
188 | ||
13188def WS |
189 | EVT_FIND(wxID_ANY, MyFrame::OnFindDialog) |
190 | EVT_FIND_NEXT(wxID_ANY, MyFrame::OnFindDialog) | |
191 | EVT_FIND_REPLACE(wxID_ANY, MyFrame::OnFindDialog) | |
192 | EVT_FIND_REPLACE_ALL(wxID_ANY, MyFrame::OnFindDialog) | |
193 | EVT_FIND_CLOSE(wxID_ANY, MyFrame::OnFindDialog) | |
761989ff | 194 | #endif // wxUSE_FINDREPLDLG |
13188def | 195 | |
532d575b | 196 | #if USE_SETTINGS_DIALOG |
0f5d8ecf | 197 | EVT_MENU(DIALOGS_PROPERTY_SHEET, MyFrame::OnPropertySheet) |
cc8bc5aa | 198 | EVT_MENU(DIALOGS_PROPERTY_SHEET_TOOLBOOK, MyFrame::OnPropertySheetToolBook) |
532d575b WS |
199 | #endif |
200 | ||
0f5d8ecf | 201 | EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) |
9b16ffef | 202 | |
4c45f240 | 203 | EVT_MENU(wxID_EXIT, MyFrame::OnExit) |
4c45f240 | 204 | END_EVENT_TABLE() |
abceee76 | 205 | |
13188def | 206 | #if USE_MODAL_PRESENTATION |
f6bcfd97 | 207 | |
13188def WS |
208 | BEGIN_EVENT_TABLE(MyModalDialog, wxDialog) |
209 | EVT_BUTTON(wxID_ANY, MyModalDialog::OnButton) | |
210 | END_EVENT_TABLE() | |
5d987909 | 211 | |
13188def WS |
212 | BEGIN_EVENT_TABLE(MyModelessDialog, wxDialog) |
213 | EVT_BUTTON(DIALOGS_MODELESS_BTN, MyModelessDialog::OnButton) | |
214 | EVT_CLOSE(MyModelessDialog::OnClose) | |
215 | END_EVENT_TABLE() | |
216 | ||
217 | #endif // USE_MODAL_PRESENTATION | |
abceee76 | 218 | |
c67daf87 | 219 | MyCanvas *myCanvas = (MyCanvas *) NULL; |
457814b5 | 220 | |
457814b5 | 221 | // `Main program' equivalent, creating windows and returning main app frame |
4c45f240 | 222 | bool MyApp::OnInit() |
457814b5 | 223 | { |
f517634c | 224 | #if wxUSE_IMAGE |
013e1fee | 225 | wxInitAllImageHandlers(); |
f517634c | 226 | #endif |
013e1fee | 227 | |
13188def WS |
228 | m_canvasTextColour = wxColour(_T("BLACK")); |
229 | m_canvasFont = *wxNORMAL_FONT; | |
457814b5 | 230 | |
13188def WS |
231 | // Create the main frame window |
232 | MyFrame *frame = new MyFrame((wxFrame *) NULL, _T("wxWidgets dialogs example")); | |
457814b5 | 233 | |
13188def WS |
234 | // Make a menubar |
235 | wxMenu *file_menu = new wxMenu; | |
dabbc6a5 | 236 | |
13188def | 237 | file_menu->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); |
457814b5 | 238 | |
457814b5 | 239 | |
33bcca32 | 240 | #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG |
f09c8393 | 241 | |
33bcca32 | 242 | wxMenu *choices_menu = new wxMenu; |
f09c8393 | 243 | |
33bcca32 VZ |
244 | #if wxUSE_COLOURDLG |
245 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour")); | |
246 | #endif // wxUSE_COLOURDLG | |
f09c8393 | 247 | |
33bcca32 VZ |
248 | #if wxUSE_FONTDLG |
249 | choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font")); | |
250 | #endif // wxUSE_FONTDLG | |
457814b5 | 251 | |
33bcca32 VZ |
252 | #if wxUSE_CHOICEDLG |
253 | choices_menu->Append(DIALOGS_SINGLE_CHOICE, _T("&Single choice\tCtrl-C")); | |
254 | choices_menu->Append(DIALOGS_MULTI_CHOICE, _T("M&ultiple choice\tCtrl-U")); | |
255 | #endif // wxUSE_CHOICEDLG | |
695fe764 | 256 | |
33bcca32 VZ |
257 | #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC |
258 | choices_menu->AppendSeparator(); | |
259 | #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC | |
695fe764 | 260 | |
33bcca32 VZ |
261 | #if USE_COLOURDLG_GENERIC |
262 | choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)")); | |
263 | #endif // USE_COLOURDLG_GENERIC | |
695fe764 | 264 | |
33bcca32 VZ |
265 | #if USE_FONTDLG_GENERIC |
266 | choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)")); | |
267 | #endif // USE_FONTDLG_GENERIC | |
d93c719a | 268 | |
33bcca32 VZ |
269 | file_menu->Append(wxID_ANY,_T("&Choices and selectors"),choices_menu); |
270 | #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG | |
457814b5 | 271 | |
457814b5 | 272 | |
33bcca32 | 273 | #if wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def | 274 | |
33bcca32 | 275 | wxMenu *entry_menu = new wxMenu; |
13188def | 276 | |
33bcca32 VZ |
277 | #if wxUSE_TEXTDLG |
278 | entry_menu->Append(DIALOGS_TEXT_ENTRY, _T("Text &entry\tCtrl-E")); | |
279 | entry_menu->Append(DIALOGS_PASSWORD_ENTRY, _T("&Password entry\tCtrl-P")); | |
280 | #endif // wxUSE_TEXTDLG | |
13188def | 281 | |
33bcca32 VZ |
282 | #if wxUSE_NUMBERDLG |
283 | entry_menu->Append(DIALOGS_NUM_ENTRY, _T("&Numeric entry\tCtrl-N")); | |
284 | #endif // wxUSE_NUMBERDLG | |
13188def | 285 | |
33bcca32 | 286 | file_menu->Append(wxID_ANY,_T("&Entry dialogs"),entry_menu); |
13188def | 287 | |
33bcca32 | 288 | #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG |
13188def WS |
289 | |
290 | ||
33bcca32 | 291 | #if wxUSE_FILEDLG |
13188def | 292 | |
33bcca32 VZ |
293 | wxMenu *filedlg_menu = new wxMenu; |
294 | filedlg_menu->Append(DIALOGS_FILE_OPEN, _T("&Open file\tCtrl-O")); | |
295 | filedlg_menu->Append(DIALOGS_FILE_OPEN2, _T("&Second open file\tCtrl-2")); | |
296 | filedlg_menu->Append(DIALOGS_FILES_OPEN, _T("Open &files\tCtrl-Q")); | |
297 | filedlg_menu->Append(DIALOGS_FILE_SAVE, _T("Sa&ve file\tCtrl-S")); | |
695fe764 | 298 | |
33bcca32 VZ |
299 | #if USE_FILEDLG_GENERIC |
300 | filedlg_menu->AppendSeparator(); | |
301 | filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC, _T("&Open file (generic)")); | |
302 | filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC, _T("Open &files (generic)")); | |
303 | filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, _T("Sa&ve file (generic)")); | |
304 | #endif // USE_FILEDLG_GENERIC | |
695fe764 | 305 | |
33bcca32 | 306 | file_menu->Append(wxID_ANY,_T("&File operations"),filedlg_menu); |
13188def | 307 | |
33bcca32 | 308 | #endif // wxUSE_FILEDLG |
13188def | 309 | |
33bcca32 VZ |
310 | #if wxUSE_DIRDLG |
311 | wxMenu *dir_menu = new wxMenu; | |
13188def | 312 | |
33bcca32 VZ |
313 | dir_menu->Append(DIALOGS_DIR_CHOOSE, _T("&Choose a directory\tCtrl-D")); |
314 | dir_menu->Append(DIALOGS_DIRNEW_CHOOSE, _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D")); | |
315 | file_menu->Append(wxID_ANY,_T("&Directory operations"),dir_menu); | |
13188def | 316 | |
33bcca32 VZ |
317 | #if USE_DIRDLG_GENERIC |
318 | dir_menu->AppendSeparator(); | |
319 | dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE, _T("&Choose a directory (generic)")); | |
320 | #endif // USE_DIRDLG_GENERIC | |
13188def | 321 | |
33bcca32 | 322 | #endif // wxUSE_DIRDLG |
13188def WS |
323 | |
324 | ||
33bcca32 | 325 | #if wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG |
13188def | 326 | |
33bcca32 | 327 | wxMenu *info_menu = new wxMenu; |
13188def | 328 | |
33bcca32 VZ |
329 | #if wxUSE_STARTUP_TIPS |
330 | info_menu->Append(DIALOGS_TIP, _T("&Tip of the day\tCtrl-T")); | |
331 | #endif // wxUSE_STARTUP_TIPS | |
13188def | 332 | |
33bcca32 VZ |
333 | #if wxUSE_PROGRESSDLG |
334 | info_menu->Append(DIALOGS_PROGRESS, _T("Pro&gress dialog\tCtrl-G")); | |
335 | #endif // wxUSE_PROGRESSDLG | |
13188def | 336 | |
33bcca32 VZ |
337 | #if wxUSE_BUSYINFO |
338 | info_menu->Append(DIALOGS_BUSYINFO, _T("&Busy info dialog\tCtrl-B")); | |
339 | #endif // wxUSE_BUSYINFO | |
13188def | 340 | |
33bcca32 VZ |
341 | #if wxUSE_LOG_DIALOG |
342 | info_menu->Append(DIALOGS_LOG_DIALOG, _T("&Log dialog\tCtrl-L")); | |
343 | #endif // wxUSE_LOG_DIALOG | |
13188def | 344 | |
33bcca32 | 345 | file_menu->Append(wxID_ANY,_T("&Informative dialogs"),info_menu); |
13188def | 346 | |
33bcca32 | 347 | #endif // wxUSE_STARTUP_TIPS || wxUSE_PROGRESSDLG || wxUSE_BUSYINFO || wxUSE_LOG_DIALOG |
13188def WS |
348 | |
349 | ||
33bcca32 VZ |
350 | #if wxUSE_FINDREPLDLG |
351 | wxMenu *find_menu = new wxMenu; | |
352 | find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F")); | |
353 | find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F")); | |
354 | file_menu->Append(wxID_ANY,_T("&Searching"),find_menu); | |
355 | #endif // wxUSE_FINDREPLDLG | |
13188def | 356 | |
33bcca32 | 357 | #if USE_MODAL_PRESENTATION |
cae50e6b VZ |
358 | wxMenu *dialogs_menu = new wxMenu; |
359 | dialogs_menu->Append(DIALOGS_MODAL, _T("&Modal dialog\tCtrl-W")); | |
360 | dialogs_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Mode&less dialog\tCtrl-Z")); | |
361 | dialogs_menu->AppendCheckItem(DIALOGS_CENTRE_SCREEN, _T("Centered on &screen\tShift-Ctrl-1")); | |
362 | dialogs_menu->AppendCheckItem(DIALOGS_CENTRE_PARENT, _T("Centered on &parent\tShift-Ctrl-2")); | |
363 | file_menu->Append(wxID_ANY, _T("&Generic dialogs"), dialogs_menu); | |
33bcca32 | 364 | #endif // USE_MODAL_PRESENTATION |
13188def | 365 | |
532d575b | 366 | #if USE_SETTINGS_DIALOG |
b40bb73e VZ |
367 | wxMenu *sheet_menu = new wxMenu; |
368 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET, _T("&Standard property sheet\tShift-Ctrl-P")); | |
369 | sheet_menu->Append(DIALOGS_PROPERTY_SHEET_TOOLBOOK, _T("&Toolbook sheet\tShift-Ctrl-T")); | |
370 | file_menu->Append(wxID_ANY, _T("&Property sheets"), sheet_menu); | |
371 | #endif // USE_SETTINGS_DIALOG | |
532d575b | 372 | |
9b16ffef VZ |
373 | file_menu->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); |
374 | ||
13188def WS |
375 | file_menu->AppendSeparator(); |
376 | file_menu->Append(wxID_EXIT, _T("E&xit\tAlt-X")); | |
377 | ||
378 | wxMenuBar *menu_bar = new wxMenuBar; | |
379 | menu_bar->Append(file_menu, _T("&File")); | |
380 | frame->SetMenuBar(menu_bar); | |
381 | ||
382 | myCanvas = new MyCanvas(frame); | |
383 | myCanvas->SetBackgroundColour(*wxWHITE); | |
384 | ||
385 | frame->Centre(wxBOTH); | |
386 | ||
387 | // Show the frame | |
388 | frame->Show(true); | |
389 | ||
390 | SetTopWindow(frame); | |
391 | ||
392 | return true; | |
457814b5 JS |
393 | } |
394 | ||
395 | // My frame constructor | |
4c45f240 | 396 | MyFrame::MyFrame(wxWindow *parent, |
13188def WS |
397 | const wxString& title) |
398 | : wxFrame(parent, wxID_ANY, title) | |
4c45f240 | 399 | { |
0f5d8ecf | 400 | SetIcon(sample_xpm); |
532d575b | 401 | |
13188def | 402 | #if USE_MODAL_PRESENTATION |
4c45f240 | 403 | m_dialog = (MyModelessDialog *)NULL; |
13188def | 404 | #endif // USE_MODAL_PRESENTATION |
f1e1ed3b | 405 | |
043dcdaa | 406 | #if wxUSE_FINDREPLDLG |
14fca738 VZ |
407 | m_dlgFind = |
408 | m_dlgReplace = NULL; | |
043dcdaa | 409 | #endif |
dabbc6a5 DS |
410 | |
411 | #if wxUSE_COLOURDLG | |
d33dd9ef VS |
412 | m_clrData.SetChooseFull(true); |
413 | for (int i = 0; i < 16; i++) | |
414 | { | |
8f6eaec9 WS |
415 | m_clrData.SetCustomColour( |
416 | i, | |
417 | wxColour( | |
418 | (unsigned char)(i*16), | |
419 | (unsigned char)(i*16), | |
420 | (unsigned char)(i*16) | |
421 | ) | |
422 | ); | |
d33dd9ef | 423 | } |
13188def | 424 | #endif // wxUSE_COLOURDLG |
4c45f240 | 425 | } |
457814b5 | 426 | |
13188def | 427 | #if wxUSE_COLOURDLG |
d355d3fe | 428 | void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 429 | { |
d33dd9ef | 430 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); |
d93c719a | 431 | |
d33dd9ef | 432 | wxColourDialog dialog(this, &m_clrData); |
9f84eccd | 433 | dialog.SetTitle(_T("Choose the background colour")); |
afbd36dd | 434 | if (dialog.ShowModal() == wxID_OK) |
f6bcfd97 | 435 | { |
d33dd9ef VS |
436 | m_clrData = dialog.GetColourData(); |
437 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
1d14c005 | 438 | myCanvas->ClearBackground(); |
457814b5 | 439 | myCanvas->Refresh(); |
f6bcfd97 | 440 | } |
457814b5 | 441 | } |
13188def | 442 | #endif // wxUSE_COLOURDLG |
457814b5 | 443 | |
1e72e3cc RN |
444 | #if USE_COLOURDLG_GENERIC |
445 | void MyFrame::ChooseColourGeneric(wxCommandEvent& WXUNUSED(event)) | |
446 | { | |
447 | m_clrData.SetColour(myCanvas->GetBackgroundColour()); | |
448 | ||
449 | //FIXME:TODO:This has no effect... | |
450 | m_clrData.SetChooseFull(true); | |
451 | ||
452 | for (int i = 0; i < 16; i++) | |
453 | { | |
454 | wxColour colour( | |
455 | (unsigned char)(i*16), | |
456 | (unsigned char)(i*16), | |
457 | (unsigned char)(i*16) | |
458 | ); | |
459 | m_clrData.SetCustomColour(i, colour); | |
460 | } | |
461 | ||
462 | wxGenericColourDialog *dialog = new wxGenericColourDialog(this, &m_clrData); | |
463 | if (dialog->ShowModal() == wxID_OK) | |
464 | { | |
465 | m_clrData = dialog->GetColourData(); | |
466 | myCanvas->SetBackgroundColour(m_clrData.GetColour()); | |
467 | myCanvas->ClearBackground(); | |
468 | myCanvas->Refresh(); | |
469 | } | |
470 | dialog->Destroy(); | |
471 | } | |
472 | #endif // USE_COLOURDLG_GENERIC | |
473 | ||
13188def | 474 | #if wxUSE_FONTDLG |
d355d3fe | 475 | void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 476 | { |
dbc65e27 VZ |
477 | wxFontData data; |
478 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
479 | data.SetColour(wxGetApp().m_canvasTextColour); | |
d93c719a | 480 | |
dbc65e27 VZ |
481 | // you might also do this: |
482 | // | |
483 | // wxFontDialog dialog; | |
484 | // if ( !dialog.Create(this, data) { ... error ... } | |
485 | // | |
486 | wxFontDialog dialog(this, data); | |
487 | ||
488 | if (dialog.ShowModal() == wxID_OK) | |
489 | { | |
490 | wxFontData retData = dialog.GetFontData(); | |
457814b5 JS |
491 | wxGetApp().m_canvasFont = retData.GetChosenFont(); |
492 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
493 | myCanvas->Refresh(); | |
dbc65e27 VZ |
494 | } |
495 | //else: cancelled by the user, don't change the font | |
457814b5 | 496 | } |
13188def | 497 | #endif // wxUSE_FONTDLG |
457814b5 | 498 | |
13188def | 499 | #if USE_FONTDLG_GENERIC |
d355d3fe | 500 | void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 501 | { |
13188def WS |
502 | wxFontData data; |
503 | data.SetInitialFont(wxGetApp().m_canvasFont); | |
504 | data.SetColour(wxGetApp().m_canvasTextColour); | |
457814b5 | 505 | |
13188def WS |
506 | wxGenericFontDialog *dialog = new wxGenericFontDialog(this, &data); |
507 | if (dialog->ShowModal() == wxID_OK) | |
508 | { | |
457814b5 JS |
509 | wxFontData retData = dialog->GetFontData(); |
510 | wxGetApp().m_canvasFont = retData.GetChosenFont(); | |
511 | wxGetApp().m_canvasTextColour = retData.GetColour(); | |
512 | myCanvas->Refresh(); | |
13188def WS |
513 | } |
514 | dialog->Destroy(); | |
457814b5 | 515 | } |
13188def | 516 | #endif // USE_FONTDLG_GENERIC |
d93c719a | 517 | |
b4954d19 | 518 | #if wxUSE_LOG_DIALOG |
87728739 | 519 | void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) |
d93c719a | 520 | { |
2c8e4738 VZ |
521 | // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages |
522 | // being flushed -- test it | |
523 | { | |
524 | wxBusyCursor bc; | |
4693b20c MB |
525 | wxLogMessage(wxT("This is some message - everything is ok so far.")); |
526 | wxLogMessage(wxT("Another message...\n... this one is on multiple lines")); | |
527 | wxLogWarning(wxT("And then something went wrong!")); | |
9fe52545 VZ |
528 | |
529 | // and if ~wxBusyCursor doesn't do it, then call it manually | |
530 | wxYield(); | |
2c8e4738 VZ |
531 | } |
532 | ||
4693b20c MB |
533 | wxLogError(wxT("Intermediary error handler decided to abort.")); |
534 | wxLogError(wxT("The top level caller detected an unrecoverable error.")); | |
5888ef1e | 535 | |
7923c649 VZ |
536 | wxLog::FlushActive(); |
537 | ||
4693b20c | 538 | wxLogMessage(wxT("And this is the same dialog but with only one message.")); |
d93c719a | 539 | } |
b4954d19 | 540 | #endif // wxUSE_LOG_DIALOG |
457814b5 | 541 | |
d355d3fe | 542 | void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 543 | { |
13188def WS |
544 | wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), |
545 | _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); | |
457814b5 | 546 | |
13188def WS |
547 | switch ( dialog.ShowModal() ) |
548 | { | |
549 | case wxID_YES: | |
550 | wxLogStatus(wxT("You pressed \"Yes\"")); | |
551 | break; | |
49b957be | 552 | |
13188def WS |
553 | case wxID_NO: |
554 | wxLogStatus(wxT("You pressed \"No\"")); | |
555 | break; | |
49b957be | 556 | |
13188def WS |
557 | case wxID_CANCEL: |
558 | wxLogStatus(wxT("You pressed \"Cancel\"")); | |
559 | break; | |
49b957be | 560 | |
13188def WS |
561 | default: |
562 | wxLogError(wxT("Unexpected wxMessageDialog return code!")); | |
563 | } | |
457814b5 JS |
564 | } |
565 | ||
13188def | 566 | #if wxUSE_NUMBERDLG |
c49245f8 VZ |
567 | void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) ) |
568 | { | |
78a189c9 VZ |
569 | long res = wxGetNumberFromUser( _T("This is some text, actually a lot of text.\n") |
570 | _T("Even two rows of text."), | |
571 | _T("Enter a number:"), _T("Numeric input test"), | |
e65cc56a | 572 | 50, 0, 100, this ); |
c49245f8 VZ |
573 | |
574 | wxString msg; | |
575 | int icon; | |
576 | if ( res == -1 ) | |
577 | { | |
78a189c9 | 578 | msg = _T("Invalid number entered or dialog cancelled."); |
c49245f8 VZ |
579 | icon = wxICON_HAND; |
580 | } | |
581 | else | |
d93c719a VZ |
582 | { |
583 | msg.Printf(_T("You've entered %lu"), res ); | |
c49245f8 VZ |
584 | icon = wxICON_INFORMATION; |
585 | } | |
586 | ||
78a189c9 | 587 | wxMessageBox(msg, _T("Numeric test result"), wxOK | icon, this); |
c49245f8 | 588 | } |
13188def | 589 | #endif // wxUSE_NUMBERDLG |
c49245f8 | 590 | |
13188def | 591 | #if wxUSE_TEXTDLG |
a294c6d5 | 592 | void MyFrame::PasswordEntry(wxCommandEvent& WXUNUSED(event)) |
457814b5 | 593 | { |
2f1cd905 | 594 | wxString pwd = wxGetPasswordFromUser(_T("Enter password:"), |
78a189c9 | 595 | _T("Password entry dialog"), |
dabbc6a5 | 596 | wxEmptyString, |
a294c6d5 | 597 | this); |
ecda9475 | 598 | if ( !pwd.empty() ) |
a294c6d5 | 599 | { |
4693b20c | 600 | wxMessageBox(wxString::Format(wxT("Your password is '%s'"), pwd.c_str()), |
78a189c9 | 601 | _T("Got password"), wxOK | wxICON_INFORMATION, this); |
a294c6d5 VZ |
602 | } |
603 | } | |
604 | ||
605 | void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event)) | |
606 | { | |
13188def WS |
607 | wxTextEntryDialog dialog(this, |
608 | _T("This is a small sample\n") | |
609 | _T("A long, long string to test out the text entrybox"), | |
610 | _T("Please enter a string"), | |
611 | _T("Default value"), | |
612 | wxOK | wxCANCEL); | |
457814b5 | 613 | |
13188def WS |
614 | if (dialog.ShowModal() == wxID_OK) |
615 | { | |
b4954d19 | 616 | wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this); |
13188def | 617 | } |
457814b5 | 618 | } |
13188def | 619 | #endif // wxUSE_TEXTDLG |
457814b5 | 620 | |
13188def | 621 | #if wxUSE_CHOICEDLG |
d355d3fe | 622 | void MyFrame::SingleChoice(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 623 | { |
78a189c9 | 624 | const wxString choices[] = { _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five") } ; |
457814b5 | 625 | |
5f95bb70 | 626 | wxSingleChoiceDialog dialog(this, |
78a189c9 VZ |
627 | _T("This is a small sample\n") |
628 | _T("A single-choice convenience dialog"), | |
629 | _T("Please select a value"), | |
5f95bb70 | 630 | WXSIZEOF(choices), choices); |
457814b5 | 631 | |
ef77f91e JS |
632 | dialog.SetSelection(2); |
633 | ||
634 | if (dialog.ShowModal() == wxID_OK) | |
635 | { | |
78a189c9 | 636 | wxMessageDialog dialog2(this, dialog.GetStringSelection(), _T("Got string")); |
ef77f91e JS |
637 | dialog2.ShowModal(); |
638 | } | |
457814b5 JS |
639 | } |
640 | ||
d6c9c1b7 VZ |
641 | void MyFrame::MultiChoice(wxCommandEvent& WXUNUSED(event) ) |
642 | { | |
5f95bb70 VZ |
643 | const wxString choices[] = |
644 | { | |
78a189c9 VZ |
645 | _T("One"), _T("Two"), _T("Three"), _T("Four"), _T("Five"), |
646 | _T("Six"), _T("Seven"), _T("Eight"), _T("Nine"), _T("Ten"), | |
647 | _T("Eleven"), _T("Twelve"), _T("Seventeen"), | |
5f95bb70 | 648 | }; |
d6c9c1b7 VZ |
649 | |
650 | wxArrayInt selections; | |
651 | size_t count = wxGetMultipleChoices(selections, | |
78a189c9 VZ |
652 | _T("This is a small sample\n") |
653 | _T("A multi-choice convenience dialog"), | |
654 | _T("Please select a value"), | |
5f95bb70 | 655 | WXSIZEOF(choices), choices, |
d6c9c1b7 VZ |
656 | this); |
657 | if ( count ) | |
658 | { | |
3d49ce44 | 659 | wxString msg; |
fba1b53b | 660 | msg.Printf(wxT("You selected %u items:\n"), (unsigned)count); |
d6c9c1b7 VZ |
661 | for ( size_t n = 0; n < count; n++ ) |
662 | { | |
fba1b53b VZ |
663 | msg += wxString::Format(wxT("\t%u: %u (%s)\n"), |
664 | (unsigned)n, (unsigned)selections[n], | |
3d49ce44 | 665 | choices[selections[n]].c_str()); |
d6c9c1b7 | 666 | } |
3d49ce44 | 667 | wxLogMessage(msg); |
d6c9c1b7 VZ |
668 | } |
669 | //else: cancelled or nothing selected | |
670 | } | |
13188def | 671 | #endif // wxUSE_CHOICEDLG |
d6c9c1b7 | 672 | |
13188def | 673 | #if wxUSE_FILEDLG |
d355d3fe | 674 | void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 675 | { |
fbf4eacb VZ |
676 | wxFileDialog dialog |
677 | ( | |
678 | this, | |
679 | _T("Testing open file dialog"), | |
dabbc6a5 DS |
680 | wxEmptyString, |
681 | wxEmptyString, | |
a4e64fb5 MB |
682 | #ifdef __WXMOTIF__ |
683 | _T("C++ files (*.cpp)|*.cpp") | |
684 | #else | |
daf32463 | 685 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") |
a4e64fb5 | 686 | #endif |
fbf4eacb | 687 | ); |
457814b5 | 688 | |
5b636c67 | 689 | dialog.SetDirectory(wxGetHomeDir()); |
3b6c3fc8 | 690 | dialog.CentreOnParent(); |
5b636c67 | 691 | |
c50f1fb9 VZ |
692 | if (dialog.ShowModal() == wxID_OK) |
693 | { | |
5919d76b | 694 | wxString info; |
13393ab6 RR |
695 | info.Printf(_T("Full file name: %s\n") |
696 | _T("Path: %s\n") | |
697 | _T("Name: %s"), | |
5919d76b VZ |
698 | dialog.GetPath().c_str(), |
699 | dialog.GetDirectory().c_str(), | |
700 | dialog.GetFilename().c_str()); | |
78a189c9 | 701 | wxMessageDialog dialog2(this, info, _T("Selected file")); |
c50f1fb9 VZ |
702 | dialog2.ShowModal(); |
703 | } | |
457814b5 JS |
704 | } |
705 | ||
35b45b33 VZ |
706 | // this shows how to take advantage of specifying a default extension in the |
707 | // call to wxFileSelector: it is remembered after each new call and the next | |
708 | // one will use it by default | |
709 | void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) | |
710 | { | |
711 | static wxString s_extDef; | |
712 | wxString path = wxFileSelector( | |
713 | _T("Select the file to load"), | |
dabbc6a5 | 714 | wxEmptyString, wxEmptyString, |
35b45b33 | 715 | s_extDef, |
3601f639 VZ |
716 | wxString::Format |
717 | ( | |
718 | _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (%s)|%s"), | |
719 | wxFileSelectorDefaultWildcardStr, | |
720 | wxFileSelectorDefaultWildcardStr | |
721 | ), | |
fbf4eacb | 722 | wxCHANGE_DIR, |
35b45b33 VZ |
723 | this |
724 | ); | |
725 | ||
726 | if ( !path ) | |
727 | return; | |
728 | ||
729 | // it is just a sample, would use wxSplitPath in real program | |
730 | s_extDef = path.AfterLast(_T('.')); | |
731 | ||
732 | wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), | |
37d403aa | 733 | (const wxChar*) path, (const wxChar*) s_extDef); |
35b45b33 VZ |
734 | } |
735 | ||
c61f4f6d VZ |
736 | void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) |
737 | { | |
dabbc6a5 | 738 | wxString wildcards = |
f0f43012 JS |
739 | #ifdef __WXMOTIF__ |
740 | _T("C++ files (*.cpp)|*.cpp"); | |
741 | #else | |
3601f639 VZ |
742 | wxString::Format |
743 | ( | |
744 | _T("All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h"), | |
745 | wxFileSelectorDefaultWildcardStr, | |
746 | wxFileSelectorDefaultWildcardStr | |
747 | ); | |
f0f43012 | 748 | #endif |
78a189c9 | 749 | wxFileDialog dialog(this, _T("Testing open multiple file dialog"), |
dabbc6a5 | 750 | wxEmptyString, wxEmptyString, wildcards, |
470caaf9 | 751 | wxMULTIPLE); |
c61f4f6d VZ |
752 | |
753 | if (dialog.ShowModal() == wxID_OK) | |
754 | { | |
755 | wxArrayString paths, filenames; | |
756 | ||
757 | dialog.GetPaths(paths); | |
758 | dialog.GetFilenames(filenames); | |
759 | ||
760 | wxString msg, s; | |
761 | size_t count = paths.GetCount(); | |
762 | for ( size_t n = 0; n < count; n++ ) | |
763 | { | |
764 | s.Printf(_T("File %d: %s (%s)\n"), | |
fba1b53b | 765 | (int)n, paths[n].c_str(), filenames[n].c_str()); |
c61f4f6d VZ |
766 | |
767 | msg += s; | |
768 | } | |
f0f43012 JS |
769 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); |
770 | msg += s; | |
c61f4f6d | 771 | |
78a189c9 | 772 | wxMessageDialog dialog2(this, msg, _T("Selected files")); |
c61f4f6d VZ |
773 | dialog2.ShowModal(); |
774 | } | |
775 | } | |
776 | ||
d355d3fe | 777 | void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 778 | { |
2f1cd905 VZ |
779 | wxFileDialog dialog(this, |
780 | _T("Testing save file dialog"), | |
dabbc6a5 | 781 | wxEmptyString, |
2b5f62a0 | 782 | _T("myletter.doc"), |
2f1cd905 VZ |
783 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), |
784 | wxSAVE|wxOVERWRITE_PROMPT); | |
c50f1fb9 | 785 | |
2b5f62a0 VZ |
786 | dialog.SetFilterIndex(1); |
787 | ||
c50f1fb9 VZ |
788 | if (dialog.ShowModal() == wxID_OK) |
789 | { | |
2b5f62a0 VZ |
790 | wxLogMessage(_T("%s, filter %d"), |
791 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
c50f1fb9 | 792 | } |
457814b5 | 793 | } |
13188def | 794 | #endif // wxUSE_FILEDLG |
457814b5 | 795 | |
695fe764 WS |
796 | #if USE_FILEDLG_GENERIC |
797 | void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
798 | { | |
799 | wxGenericFileDialog dialog | |
800 | ( | |
801 | this, | |
802 | _T("Testing open file dialog"), | |
803 | wxEmptyString, | |
804 | wxEmptyString, | |
daf32463 | 805 | _T("C++ files (*.cpp;*.h)|*.cpp;*.h") |
695fe764 WS |
806 | ); |
807 | ||
808 | dialog.SetDirectory(wxGetHomeDir()); | |
809 | ||
810 | if (dialog.ShowModal() == wxID_OK) | |
811 | { | |
812 | wxString info; | |
813 | info.Printf(_T("Full file name: %s\n") | |
814 | _T("Path: %s\n") | |
815 | _T("Name: %s"), | |
816 | dialog.GetPath().c_str(), | |
817 | dialog.GetDirectory().c_str(), | |
818 | dialog.GetFilename().c_str()); | |
819 | wxMessageDialog dialog2(this, info, _T("Selected file")); | |
820 | dialog2.ShowModal(); | |
821 | } | |
822 | } | |
823 | ||
824 | void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) ) | |
825 | { | |
daf32463 | 826 | wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h"); |
695fe764 WS |
827 | wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"), |
828 | wxEmptyString, wxEmptyString, wildcards, | |
829 | wxMULTIPLE); | |
830 | ||
831 | if (dialog.ShowModal() == wxID_OK) | |
832 | { | |
833 | wxArrayString paths, filenames; | |
834 | ||
835 | dialog.GetPaths(paths); | |
836 | dialog.GetFilenames(filenames); | |
837 | ||
838 | wxString msg, s; | |
839 | size_t count = paths.GetCount(); | |
840 | for ( size_t n = 0; n < count; n++ ) | |
841 | { | |
842 | s.Printf(_T("File %d: %s (%s)\n"), | |
843 | (int)n, paths[n].c_str(), filenames[n].c_str()); | |
844 | ||
845 | msg += s; | |
846 | } | |
847 | s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex()); | |
848 | msg += s; | |
849 | ||
850 | wxMessageDialog dialog2(this, msg, _T("Selected files")); | |
851 | dialog2.ShowModal(); | |
852 | } | |
853 | } | |
854 | ||
855 | void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) ) | |
856 | { | |
857 | wxGenericFileDialog dialog(this, | |
858 | _T("Testing save file dialog"), | |
859 | wxEmptyString, | |
860 | _T("myletter.doc"), | |
861 | _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"), | |
862 | wxSAVE|wxOVERWRITE_PROMPT); | |
863 | ||
864 | dialog.SetFilterIndex(1); | |
865 | ||
866 | if (dialog.ShowModal() == wxID_OK) | |
867 | { | |
868 | wxLogMessage(_T("%s, filter %d"), | |
869 | dialog.GetPath().c_str(), dialog.GetFilterIndex()); | |
870 | } | |
871 | } | |
872 | #endif // USE_FILEDLG_GENERIC | |
873 | ||
13188def | 874 | #if wxUSE_DIRDLG |
f09c8393 | 875 | void MyFrame::DoDirChoose(int style) |
457814b5 | 876 | { |
3f2711d5 VZ |
877 | // pass some initial dir to wxDirDialog |
878 | wxString dirHome; | |
879 | wxGetHomeDir(&dirHome); | |
880 | ||
f09c8393 | 881 | wxDirDialog dialog(this, _T("Testing directory picker"), dirHome, style); |
c50f1fb9 VZ |
882 | |
883 | if (dialog.ShowModal() == wxID_OK) | |
884 | { | |
2b5f62a0 | 885 | wxLogMessage(_T("Selected path: %s"), dialog.GetPath().c_str()); |
c50f1fb9 VZ |
886 | } |
887 | } | |
888 | ||
f09c8393 VZ |
889 | void MyFrame::DirChoose(wxCommandEvent& WXUNUSED(event) ) |
890 | { | |
891 | DoDirChoose(wxDD_DEFAULT_STYLE & ~wxDD_NEW_DIR_BUTTON); | |
892 | } | |
893 | ||
894 | void MyFrame::DirChooseNew(wxCommandEvent& WXUNUSED(event) ) | |
895 | { | |
8768548b | 896 | DoDirChoose(wxDD_DEFAULT_STYLE | wxDD_NEW_DIR_BUTTON); |
f09c8393 | 897 | } |
13188def | 898 | #endif // wxUSE_DIRDLG |
f09c8393 | 899 | |
13188def | 900 | #if USE_DIRDLG_GENERIC |
51a58d8b JS |
901 | void MyFrame::GenericDirChoose(wxCommandEvent& WXUNUSED(event) ) |
902 | { | |
903 | // pass some initial dir to wxDirDialog | |
904 | wxString dirHome; | |
905 | wxGetHomeDir(&dirHome); | |
906 | ||
78a189c9 | 907 | wxGenericDirDialog dialog(this, _T("Testing generic directory picker"), dirHome); |
51a58d8b JS |
908 | |
909 | if (dialog.ShowModal() == wxID_OK) | |
910 | { | |
78a189c9 | 911 | wxMessageDialog dialog2(this, dialog.GetPath(), _T("Selected path")); |
51a58d8b JS |
912 | dialog2.ShowModal(); |
913 | } | |
914 | } | |
13188def | 915 | #endif // USE_DIRDLG_GENERIC |
51a58d8b | 916 | |
13188def | 917 | #if USE_MODAL_PRESENTATION |
f6bcfd97 BP |
918 | void MyFrame::ModalDlg(wxCommandEvent& WXUNUSED(event)) |
919 | { | |
920 | MyModalDialog dlg(this); | |
921 | dlg.ShowModal(); | |
922 | } | |
923 | ||
4c45f240 VZ |
924 | void MyFrame::ModelessDlg(wxCommandEvent& event) |
925 | { | |
2f82899b | 926 | bool show = GetMenuBar()->IsChecked(event.GetId()); |
4c45f240 VZ |
927 | |
928 | if ( show ) | |
929 | { | |
930 | if ( !m_dialog ) | |
931 | { | |
932 | m_dialog = new MyModelessDialog(this); | |
933 | } | |
934 | ||
13188def | 935 | m_dialog->Show(true); |
4c45f240 VZ |
936 | } |
937 | else // hide | |
938 | { | |
26a12ab3 JS |
939 | // If m_dialog is NULL, then possibly the system |
940 | // didn't report the checked menu item status correctly. | |
941 | // It should be true just after the menu item was selected, | |
942 | // if there was no modeless dialog yet. | |
943 | ||
944 | wxASSERT( m_dialog != NULL ); | |
945 | if (m_dialog) | |
946 | m_dialog->Hide(); | |
4c45f240 VZ |
947 | } |
948 | } | |
cae50e6b VZ |
949 | |
950 | void MyFrame::DlgCenteredScreen(wxCommandEvent& WXUNUSED(event)) | |
951 | { | |
952 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on screen"), | |
953 | wxDefaultPosition, wxSize(200, 100)); | |
954 | new wxButton(&dlg, wxID_OK, _T("Close"), wxPoint(10, 10)); | |
955 | dlg.CentreOnScreen(); | |
956 | dlg.ShowModal(); | |
957 | } | |
958 | ||
959 | void MyFrame::DlgCenteredParent(wxCommandEvent& WXUNUSED(event)) | |
960 | { | |
961 | wxDialog dlg(this, wxID_ANY, _T("Dialog centered on parent"), | |
962 | wxDefaultPosition, wxSize(200, 100)); | |
963 | new wxButton(&dlg, wxID_OK, _T("Close"), wxPoint(10, 10)); | |
964 | dlg.CentreOnParent(); | |
965 | dlg.ShowModal(); | |
966 | } | |
967 | ||
13188def | 968 | #endif // USE_MODAL_PRESENTATION |
4c45f240 | 969 | |
13188def | 970 | #if wxUSE_STARTUP_TIPS |
87728739 | 971 | void MyFrame::ShowTip(wxCommandEvent& WXUNUSED(event)) |
c50f1fb9 VZ |
972 | { |
973 | static size_t s_index = (size_t)-1; | |
974 | ||
975 | if ( s_index == (size_t)-1 ) | |
976 | { | |
977 | srand(time(NULL)); | |
978 | ||
979 | // this is completely bogus, we don't know how many lines are there | |
980 | // in the file, but who cares, it's a demo only... | |
981 | s_index = rand() % 5; | |
982 | } | |
983 | ||
2f1cd905 | 984 | wxTipProvider *tipProvider = wxCreateFileTipProvider(_T("tips.txt"), s_index); |
c50f1fb9 VZ |
985 | |
986 | bool showAtStartup = wxShowTip(this, tipProvider); | |
987 | ||
988 | if ( showAtStartup ) | |
989 | { | |
2f1cd905 | 990 | wxMessageBox(_T("Will show tips on startup"), _T("Tips dialog"), |
c50f1fb9 VZ |
991 | wxOK | wxICON_INFORMATION, this); |
992 | } | |
457814b5 | 993 | |
c50f1fb9 VZ |
994 | s_index = tipProvider->GetCurrentTip(); |
995 | delete tipProvider; | |
457814b5 | 996 | } |
13188def | 997 | #endif // wxUSE_STARTUP_TIPS |
457814b5 | 998 | |
532d575b | 999 | #if USE_SETTINGS_DIALOG |
0f5d8ecf JS |
1000 | void MyFrame::OnPropertySheet(wxCommandEvent& WXUNUSED(event)) |
1001 | { | |
1002 | SettingsDialog dialog(this); | |
1003 | dialog.ShowModal(); | |
1004 | } | |
cc8bc5aa JS |
1005 | |
1006 | void MyFrame::OnPropertySheetToolBook(wxCommandEvent& WXUNUSED(event)) | |
1007 | { | |
1008 | SettingsDialog dialog(this, true); | |
1009 | dialog.ShowModal(); | |
1010 | } | |
532d575b | 1011 | #endif // USE_SETTINGS_DIALOG |
0f5d8ecf | 1012 | |
9b16ffef VZ |
1013 | void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) |
1014 | { | |
1015 | wxLogStatus(_T("Sleeping for 3 seconds to allow you to switch to another window")); | |
1016 | ||
1017 | wxSleep(3); | |
1018 | ||
1019 | RequestUserAttention(wxUSER_ATTENTION_ERROR); | |
1020 | } | |
1021 | ||
d355d3fe | 1022 | void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) |
457814b5 | 1023 | { |
13188def | 1024 | Close(true); |
457814b5 JS |
1025 | } |
1026 | ||
abceee76 VZ |
1027 | #if wxUSE_PROGRESSDLG |
1028 | ||
1029 | void MyFrame::ShowProgress( wxCommandEvent& WXUNUSED(event) ) | |
1030 | { | |
9b16ffef VZ |
1031 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
1032 | // check the performance | |
1033 | int countrandomnumbers = 0, count = 0; | |
1034 | wxTimeSpan tsTest(0,0,0,250); | |
1035 | wxDateTime DT2, DT1 = wxDateTime::UNow(); | |
1036 | srand(0); | |
1037 | while(1) | |
1038 | { | |
1039 | rand(); | |
1040 | ++countrandomnumbers; | |
1041 | if ( countrandomnumbers == 1000 ) | |
1042 | { | |
1043 | srand(0); | |
1044 | countrandomnumbers = 0; | |
1045 | ++count; | |
1046 | DT2 = wxDateTime::UNow(); | |
1047 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
1048 | if ( ts.IsLongerThan( tsTest ) ) | |
1049 | { | |
1050 | break; | |
1051 | } | |
1052 | } | |
1053 | } | |
1054 | const int max = 40 * count; | |
1055 | #else | |
abceee76 | 1056 | static const int max = 10; |
9b16ffef | 1057 | #endif // wxUSE_STOPWATCH && wxUSE_LONGLONG |
abceee76 | 1058 | |
2f1cd905 | 1059 | wxProgressDialog dialog(_T("Progress dialog example"), |
78a189c9 | 1060 | _T("An informative message"), |
abceee76 VZ |
1061 | max, // range |
1062 | this, // parent | |
1063 | wxPD_CAN_ABORT | | |
ecda9475 | 1064 | wxPD_CAN_SKIP | |
abceee76 | 1065 | wxPD_APP_MODAL | |
df26c4c6 | 1066 | // wxPD_AUTO_HIDE | -- try this as well |
abceee76 VZ |
1067 | wxPD_ELAPSED_TIME | |
1068 | wxPD_ESTIMATED_TIME | | |
ecda9475 WS |
1069 | wxPD_REMAINING_TIME | |
1070 | wxPD_SMOOTH); | |
abceee76 | 1071 | |
13188def | 1072 | bool cont = true; |
ecda9475 WS |
1073 | bool skip = false; |
1074 | // each skip will move progress about quarter forward | |
1075 | for ( int i = 0; i <= max; i = wxMin(i+(skip?int(max/4):1), max+1), skip = false ) | |
abceee76 | 1076 | { |
9b16ffef VZ |
1077 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG |
1078 | // do (almost) the same operations as we did for the performance test | |
1079 | srand(0); | |
1080 | for ( int j = 0; j < 1000; j++ ) | |
1081 | { | |
1082 | rand(); | |
1083 | if ( j == 999 ) | |
1084 | { | |
1085 | DT2 = wxDateTime::UNow(); | |
1086 | wxTimeSpan ts = DT2.Subtract( DT1 ); | |
1087 | if ( ts.IsLongerThan( tsTest ) ) | |
1088 | { | |
1089 | // nothing to do | |
1090 | } | |
1091 | } | |
1092 | } | |
1093 | #else | |
abceee76 | 1094 | wxSleep(1); |
9b16ffef | 1095 | #endif |
ecda9475 WS |
1096 | |
1097 | wxString msg; | |
1098 | ||
abceee76 VZ |
1099 | if ( i == max ) |
1100 | { | |
ecda9475 | 1101 | msg = _T("That's all, folks!"); |
abceee76 | 1102 | } |
ecda9475 | 1103 | else if ( i > max / 2 ) |
abceee76 | 1104 | { |
ecda9475 | 1105 | msg = _T("Only a half left (very long message)!"); |
abceee76 | 1106 | } |
ecda9475 WS |
1107 | |
1108 | #if wxUSE_STOPWATCH && wxUSE_LONGLONG | |
1109 | if ( (i % (max/100)) == 0 ) // // only 100 updates, this makes it much faster | |
abceee76 | 1110 | { |
ecda9475 | 1111 | cont = dialog.Update(i, msg, &skip); |
abceee76 | 1112 | } |
ecda9475 WS |
1113 | #else |
1114 | cont = dialog.Update(i, msg, &skip); | |
1115 | #endif | |
1116 | ||
d8ddee9c VZ |
1117 | if ( !cont ) |
1118 | { | |
78a189c9 VZ |
1119 | if ( wxMessageBox(_T("Do you really want to cancel?"), |
1120 | _T("Progress dialog question"), // caption | |
1121 | wxYES_NO | wxICON_QUESTION) == wxYES ) | |
d8ddee9c VZ |
1122 | break; |
1123 | ||
9b16ffef | 1124 | cont = true; |
d8ddee9c VZ |
1125 | dialog.Resume(); |
1126 | } | |
abceee76 VZ |
1127 | } |
1128 | ||
1129 | if ( !cont ) | |
1130 | { | |
4693b20c | 1131 | wxLogStatus(wxT("Progress dialog aborted!")); |
abceee76 VZ |
1132 | } |
1133 | else | |
1134 | { | |
4693b20c | 1135 | wxLogStatus(wxT("Countdown from %d finished"), max); |
abceee76 VZ |
1136 | } |
1137 | } | |
1138 | ||
1139 | #endif // wxUSE_PROGRESSDLG | |
1140 | ||
a62b0bcc VZ |
1141 | #if wxUSE_BUSYINFO |
1142 | ||
1143 | void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event)) | |
1144 | { | |
21977bac VZ |
1145 | wxWindowDisabler disableAll; |
1146 | ||
9f84eccd | 1147 | wxBusyInfo info(_T("Working, please wait..."), this); |
a62b0bcc | 1148 | |
5b636c67 | 1149 | for ( int i = 0; i < 18; i++ ) |
a62b0bcc | 1150 | { |
5b636c67 | 1151 | //wxUsleep(100); |
a62b0bcc VZ |
1152 | wxTheApp->Yield(); |
1153 | } | |
5b636c67 VZ |
1154 | |
1155 | wxSleep(2); | |
1156 | //wxWakeUpIdle(); | |
a62b0bcc VZ |
1157 | } |
1158 | ||
1159 | #endif // wxUSE_BUSYINFO | |
1160 | ||
761989ff VZ |
1161 | #if wxUSE_FINDREPLDLG |
1162 | ||
1163 | void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) ) | |
1164 | { | |
14fca738 VZ |
1165 | if ( m_dlgReplace ) |
1166 | { | |
1167 | delete m_dlgReplace; | |
1168 | m_dlgReplace = NULL; | |
1169 | } | |
1170 | else | |
1171 | { | |
1172 | m_dlgReplace = new wxFindReplaceDialog | |
1173 | ( | |
1174 | this, | |
1175 | &m_findData, | |
78a189c9 | 1176 | _T("Find and replace dialog"), |
14fca738 VZ |
1177 | wxFR_REPLACEDIALOG |
1178 | ); | |
1179 | ||
13188def | 1180 | m_dlgReplace->Show(true); |
14fca738 | 1181 | } |
761989ff VZ |
1182 | } |
1183 | ||
1184 | void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) ) | |
1185 | { | |
14fca738 VZ |
1186 | if ( m_dlgFind ) |
1187 | { | |
1188 | delete m_dlgFind; | |
1189 | m_dlgFind = NULL; | |
1190 | } | |
1191 | else | |
1192 | { | |
1193 | m_dlgFind = new wxFindReplaceDialog | |
1194 | ( | |
1195 | this, | |
1196 | &m_findData, | |
78a189c9 | 1197 | _T("Find dialog"), |
14fca738 VZ |
1198 | // just for testing |
1199 | wxFR_NOWHOLEWORD | |
1200 | ); | |
1201 | ||
13188def | 1202 | m_dlgFind->Show(true); |
14fca738 | 1203 | } |
761989ff VZ |
1204 | } |
1205 | ||
1206 | static wxString DecodeFindDialogEventFlags(int flags) | |
1207 | { | |
1208 | wxString str; | |
78a189c9 | 1209 | str << (flags & wxFR_DOWN ? _T("down") : _T("up")) << _T(", ") |
2f1cd905 VZ |
1210 | << (flags & wxFR_WHOLEWORD ? _T("whole words only, ") : _T("")) |
1211 | << (flags & wxFR_MATCHCASE ? _T("") : _T("not ")) | |
78a189c9 | 1212 | << _T("case sensitive"); |
761989ff VZ |
1213 | |
1214 | return str; | |
1215 | } | |
1216 | ||
1217 | void MyFrame::OnFindDialog(wxFindDialogEvent& event) | |
1218 | { | |
1219 | wxEventType type = event.GetEventType(); | |
1220 | ||
1221 | if ( type == wxEVT_COMMAND_FIND || type == wxEVT_COMMAND_FIND_NEXT ) | |
1222 | { | |
4693b20c | 1223 | wxLogMessage(wxT("Find %s'%s' (flags: %s)"), |
eba33006 | 1224 | type == wxEVT_COMMAND_FIND_NEXT ? wxT("next ") : wxT(""), |
761989ff VZ |
1225 | event.GetFindString().c_str(), |
1226 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1227 | } | |
1228 | else if ( type == wxEVT_COMMAND_FIND_REPLACE || | |
1229 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ) | |
1230 | { | |
4693b20c | 1231 | wxLogMessage(wxT("Replace %s'%s' with '%s' (flags: %s)"), |
eba33006 | 1232 | type == wxEVT_COMMAND_FIND_REPLACE_ALL ? _T("all ") : wxT(""), |
761989ff VZ |
1233 | event.GetFindString().c_str(), |
1234 | event.GetReplaceString().c_str(), | |
1235 | DecodeFindDialogEventFlags(event.GetFlags()).c_str()); | |
1236 | } | |
1237 | else if ( type == wxEVT_COMMAND_FIND_CLOSE ) | |
1238 | { | |
14fca738 VZ |
1239 | wxFindReplaceDialog *dlg = event.GetDialog(); |
1240 | ||
df26c4c6 | 1241 | int idMenu; |
14fca738 VZ |
1242 | const wxChar *txt; |
1243 | if ( dlg == m_dlgFind ) | |
1244 | { | |
1245 | txt = _T("Find"); | |
df26c4c6 | 1246 | idMenu = DIALOGS_FIND; |
14fca738 VZ |
1247 | m_dlgFind = NULL; |
1248 | } | |
1249 | else if ( dlg == m_dlgReplace ) | |
1250 | { | |
1251 | txt = _T("Replace"); | |
df26c4c6 | 1252 | idMenu = DIALOGS_REPLACE; |
14fca738 VZ |
1253 | m_dlgReplace = NULL; |
1254 | } | |
1255 | else | |
1256 | { | |
1257 | txt = _T("Unknown"); | |
13188def | 1258 | idMenu = wxID_ANY; |
14fca738 | 1259 | |
2f1cd905 | 1260 | wxFAIL_MSG( _T("unexpected event") ); |
14fca738 VZ |
1261 | } |
1262 | ||
df26c4c6 VZ |
1263 | wxLogMessage(wxT("%s dialog is being closed."), txt); |
1264 | ||
13188def | 1265 | if ( idMenu != wxID_ANY ) |
df26c4c6 | 1266 | { |
13188def | 1267 | GetMenuBar()->Check(idMenu, false); |
df26c4c6 | 1268 | } |
761989ff | 1269 | |
14fca738 | 1270 | dlg->Destroy(); |
761989ff VZ |
1271 | } |
1272 | else | |
1273 | { | |
4693b20c | 1274 | wxLogError(wxT("Unknown find dialog event!")); |
761989ff VZ |
1275 | } |
1276 | } | |
1277 | ||
1278 | #endif // wxUSE_FINDREPLDLG | |
1279 | ||
abceee76 VZ |
1280 | // ---------------------------------------------------------------------------- |
1281 | // MyCanvas | |
1282 | // ---------------------------------------------------------------------------- | |
1283 | ||
d355d3fe | 1284 | void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) ) |
457814b5 | 1285 | { |
c50f1fb9 | 1286 | wxPaintDC dc(this); |
457814b5 JS |
1287 | dc.SetFont(wxGetApp().m_canvasFont); |
1288 | dc.SetTextForeground(wxGetApp().m_canvasTextColour); | |
1289 | dc.SetBackgroundMode(wxTRANSPARENT); | |
dc96b1b6 WS |
1290 | dc.DrawText( |
1291 | _T("wxWidgets common dialogs") | |
1292 | #if !defined(__SMARTPHONE__) | |
1293 | _T(" test application") | |
1294 | #endif | |
1295 | , 10, 10); | |
457814b5 JS |
1296 | } |
1297 | ||
b4954d19 WS |
1298 | #if USE_MODAL_PRESENTATION |
1299 | ||
4c45f240 VZ |
1300 | // ---------------------------------------------------------------------------- |
1301 | // MyModelessDialog | |
1302 | // ---------------------------------------------------------------------------- | |
457814b5 | 1303 | |
4c45f240 | 1304 | MyModelessDialog::MyModelessDialog(wxWindow *parent) |
13188def | 1305 | : wxDialog(parent, wxID_ANY, wxString(_T("Modeless dialog"))) |
4c45f240 | 1306 | { |
cbc66a27 VZ |
1307 | wxBoxSizer *sizerTop = new wxBoxSizer(wxVERTICAL); |
1308 | ||
78a189c9 | 1309 | wxButton *btn = new wxButton(this, DIALOGS_MODELESS_BTN, _T("Press me")); |
13188def | 1310 | wxCheckBox *check = new wxCheckBox(this, wxID_ANY, _T("Should be disabled")); |
cbc66a27 VZ |
1311 | check->Disable(); |
1312 | ||
1313 | sizerTop->Add(btn, 1, wxEXPAND | wxALL, 5); | |
1314 | sizerTop->Add(check, 1, wxEXPAND | wxALL, 5); | |
1315 | ||
cbc66a27 VZ |
1316 | SetSizer(sizerTop); |
1317 | ||
1318 | sizerTop->SetSizeHints(this); | |
1319 | sizerTop->Fit(this); | |
4c45f240 | 1320 | } |
abceee76 | 1321 | |
5d987909 VZ |
1322 | void MyModelessDialog::OnButton(wxCommandEvent& WXUNUSED(event)) |
1323 | { | |
2f1cd905 | 1324 | wxMessageBox(_T("Button pressed in modeless dialog"), _T("Info"), |
5d987909 VZ |
1325 | wxOK | wxICON_INFORMATION, this); |
1326 | } | |
1327 | ||
abceee76 VZ |
1328 | void MyModelessDialog::OnClose(wxCloseEvent& event) |
1329 | { | |
1330 | if ( event.CanVeto() ) | |
1331 | { | |
2f1cd905 | 1332 | wxMessageBox(_T("Use the menu item to close this dialog"), |
78a189c9 | 1333 | _T("Modeless dialog"), |
abceee76 VZ |
1334 | wxOK | wxICON_INFORMATION, this); |
1335 | ||
1336 | event.Veto(); | |
1337 | } | |
1338 | } | |
1339 | ||
f6bcfd97 BP |
1340 | // ---------------------------------------------------------------------------- |
1341 | // MyModalDialog | |
1342 | // ---------------------------------------------------------------------------- | |
1343 | ||
1344 | MyModalDialog::MyModalDialog(wxWindow *parent) | |
13188def | 1345 | : wxDialog(parent, wxID_ANY, wxString(_T("Modal dialog"))) |
f6bcfd97 BP |
1346 | { |
1347 | wxBoxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL); | |
1348 | ||
13188def WS |
1349 | m_btnModal = new wxButton(this, wxID_ANY, _T("&Modal dialog...")); |
1350 | m_btnModeless = new wxButton(this, wxID_ANY, _T("Mode&less dialog")); | |
1351 | m_btnDelete = new wxButton(this, wxID_ANY, _T("&Delete button")); | |
5315ebfa | 1352 | |
78a189c9 | 1353 | wxButton *btnOk = new wxButton(this, wxID_CANCEL, _T("&Close")); |
5315ebfa VZ |
1354 | sizerTop->Add(m_btnModal, 0, wxALIGN_CENTER | wxALL, 5); |
1355 | sizerTop->Add(m_btnModeless, 0, wxALIGN_CENTER | wxALL, 5); | |
f6bcfd97 | 1356 | sizerTop->Add(m_btnDelete, 0, wxALIGN_CENTER | wxALL, 5); |
9b70bb91 | 1357 | sizerTop->Add(btnOk, 0, wxALIGN_CENTER | wxALL, 5); |
f6bcfd97 | 1358 | |
f6bcfd97 BP |
1359 | SetSizer(sizerTop); |
1360 | ||
1361 | sizerTop->SetSizeHints(this); | |
1362 | sizerTop->Fit(this); | |
1363 | ||
5315ebfa VZ |
1364 | m_btnModal->SetFocus(); |
1365 | m_btnModal->SetDefault(); | |
f6bcfd97 BP |
1366 | } |
1367 | ||
1368 | void MyModalDialog::OnButton(wxCommandEvent& event) | |
1369 | { | |
1370 | if ( event.GetEventObject() == m_btnDelete ) | |
1371 | { | |
5315ebfa VZ |
1372 | delete m_btnModal; |
1373 | m_btnModal = NULL; | |
f6bcfd97 BP |
1374 | |
1375 | m_btnDelete->Disable(); | |
1376 | } | |
5315ebfa | 1377 | else if ( event.GetEventObject() == m_btnModal ) |
f6bcfd97 | 1378 | { |
13188def | 1379 | #if wxUSE_TEXTDLG |
78a189c9 VZ |
1380 | wxGetTextFromUser(_T("Dummy prompt"), |
1381 | _T("Modal dialog called from dialog"), | |
dabbc6a5 | 1382 | wxEmptyString, this); |
13188def WS |
1383 | #else |
1384 | wxMessageBox(_T("Modal dialog called from dialog")); | |
1385 | #endif // wxUSE_TEXTDLG | |
f6bcfd97 | 1386 | } |
5315ebfa VZ |
1387 | else if ( event.GetEventObject() == m_btnModeless ) |
1388 | { | |
1389 | (new MyModelessDialog(this))->Show(); | |
1390 | } | |
f6bcfd97 BP |
1391 | else |
1392 | { | |
1393 | event.Skip(); | |
1394 | } | |
1395 | } | |
b4954d19 WS |
1396 | |
1397 | #endif // USE_MODAL_PRESENTATION | |
1398 | ||
532d575b | 1399 | #if USE_SETTINGS_DIALOG |
0f5d8ecf JS |
1400 | // ---------------------------------------------------------------------------- |
1401 | // SettingsDialog | |
1402 | // ---------------------------------------------------------------------------- | |
1403 | ||
1404 | IMPLEMENT_CLASS(SettingsDialog, wxPropertySheetDialog) | |
1405 | ||
1406 | BEGIN_EVENT_TABLE(SettingsDialog, wxPropertySheetDialog) | |
1407 | END_EVENT_TABLE() | |
1408 | ||
cc8bc5aa | 1409 | SettingsDialog::SettingsDialog(wxWindow* win, bool useToolBook) |
0f5d8ecf | 1410 | { |
0f4991f4 | 1411 | SetExtraStyle(wxDIALOG_EX_CONTEXTHELP|wxWS_EX_VALIDATE_RECURSIVELY); |
0f5d8ecf | 1412 | |
cc8bc5aa JS |
1413 | int tabImage1 = -1; |
1414 | int tabImage2 = -1; | |
1415 | ||
1416 | if (useToolBook) | |
1417 | { | |
1418 | tabImage1 = 0; | |
1419 | tabImage2 = 1; | |
1420 | SetSheetStyle(wxPROPSHEET_TOOLBOOK|wxPROPSHEET_SHRINKTOFIT); | |
1421 | ||
1422 | // create a dummy image list with a few icons | |
1423 | const wxSize imageSize(32, 32); | |
1424 | ||
1425 | m_imageList = new wxImageList(imageSize.GetWidth(), imageSize.GetHeight()); | |
1426 | m_imageList-> | |
1427 | Add(wxArtProvider::GetIcon(wxART_INFORMATION, wxART_OTHER, imageSize)); | |
1428 | m_imageList-> | |
1429 | Add(wxArtProvider::GetIcon(wxART_QUESTION, wxART_OTHER, imageSize)); | |
1430 | m_imageList-> | |
1431 | Add(wxArtProvider::GetIcon(wxART_WARNING, wxART_OTHER, imageSize)); | |
1432 | m_imageList-> | |
1433 | Add(wxArtProvider::GetIcon(wxART_ERROR, wxART_OTHER, imageSize)); | |
1434 | } | |
1435 | else | |
1436 | m_imageList = NULL; | |
1437 | ||
532d575b | 1438 | Create(win, wxID_ANY, _("Preferences"), wxDefaultPosition, wxDefaultSize, |
3103e8a9 JS |
1439 | wxDEFAULT_DIALOG_STYLE |
1440 | #ifndef __WXWINCE__ | |
1441 | |wxRESIZE_BORDER | |
532d575b | 1442 | #endif |
3103e8a9 | 1443 | ); |
cc8bc5aa JS |
1444 | |
1445 | // If using a toolbook, also follow Mac style and don't create buttons | |
1446 | if (!useToolBook) | |
1447 | CreateButtons(wxOK|wxCANCEL | |
897b24cf | 1448 | #ifndef __POCKETPC__ |
cc8bc5aa | 1449 | |wxHELP |
897b24cf WS |
1450 | #endif |
1451 | ); | |
0f5d8ecf JS |
1452 | |
1453 | wxBookCtrlBase* notebook = GetBookCtrl(); | |
cc8bc5aa | 1454 | notebook->SetImageList(m_imageList); |
0f5d8ecf JS |
1455 | |
1456 | wxPanel* generalSettings = CreateGeneralSettingsPage(notebook); | |
1457 | wxPanel* aestheticSettings = CreateAestheticSettingsPage(notebook); | |
1458 | ||
cc8bc5aa JS |
1459 | notebook->AddPage(generalSettings, _("General"), true, tabImage1); |
1460 | notebook->AddPage(aestheticSettings, _("Aesthetics"), false, tabImage2); | |
0f5d8ecf JS |
1461 | |
1462 | LayoutDialog(); | |
1463 | } | |
1464 | ||
cc8bc5aa JS |
1465 | SettingsDialog::~SettingsDialog() |
1466 | { | |
1467 | delete m_imageList; | |
1468 | } | |
1469 | ||
0f5d8ecf JS |
1470 | wxPanel* SettingsDialog::CreateGeneralSettingsPage(wxWindow* parent) |
1471 | { | |
1472 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1473 | ||
1474 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1475 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1476 | ||
1477 | //// LOAD LAST FILE | |
1478 | ||
1479 | wxBoxSizer* itemSizer3 = new wxBoxSizer( wxHORIZONTAL ); | |
1480 | wxCheckBox* checkBox3 = new wxCheckBox(panel, ID_LOAD_LAST_PROJECT, _("&Load last project on startup"), wxDefaultPosition, wxDefaultSize); | |
1481 | itemSizer3->Add(checkBox3, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1482 | item0->Add(itemSizer3, 0, wxGROW|wxALL, 0); | |
1483 | ||
1484 | //// AUTOSAVE | |
1485 | ||
1486 | wxString autoSaveLabel = _("&Auto-save every"); | |
1487 | wxString minsLabel = _("mins"); | |
1488 | ||
1489 | wxBoxSizer* itemSizer12 = new wxBoxSizer( wxHORIZONTAL ); | |
1490 | wxCheckBox* checkBox12 = new wxCheckBox(panel, ID_AUTO_SAVE, autoSaveLabel, wxDefaultPosition, wxDefaultSize); | |
62675ef3 JS |
1491 | |
1492 | #if wxUSE_SPINCTRL | |
0f5d8ecf | 1493 | wxSpinCtrl* spinCtrl12 = new wxSpinCtrl(panel, ID_AUTO_SAVE_MINS, wxEmptyString, |
532d575b | 1494 | wxDefaultPosition, wxSize(40, wxDefaultCoord), wxSP_ARROW_KEYS, 1, 60, 1); |
62675ef3 | 1495 | #endif |
532d575b | 1496 | |
0f5d8ecf | 1497 | itemSizer12->Add(checkBox12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 1498 | #if wxUSE_SPINCTRL |
0f5d8ecf | 1499 | itemSizer12->Add(spinCtrl12, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
62675ef3 | 1500 | #endif |
0f5d8ecf JS |
1501 | itemSizer12->Add(new wxStaticText(panel, wxID_STATIC, minsLabel), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); |
1502 | item0->Add(itemSizer12, 0, wxGROW|wxALL, 0); | |
1503 | ||
1504 | //// TOOLTIPS | |
532d575b | 1505 | |
0f5d8ecf JS |
1506 | wxBoxSizer* itemSizer8 = new wxBoxSizer( wxHORIZONTAL ); |
1507 | wxCheckBox* checkBox6 = new wxCheckBox(panel, ID_SHOW_TOOLTIPS, _("Show &tooltips"), wxDefaultPosition, wxDefaultSize); | |
1508 | itemSizer8->Add(checkBox6, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1509 | item0->Add(itemSizer8, 0, wxGROW|wxALL, 0); | |
1510 | ||
1511 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
1512 | ||
1513 | panel->SetSizer(topSizer); | |
1514 | topSizer->Fit(panel); | |
532d575b | 1515 | |
0f5d8ecf JS |
1516 | return panel; |
1517 | } | |
1518 | ||
1519 | wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent) | |
1520 | { | |
1521 | wxPanel* panel = new wxPanel(parent, wxID_ANY); | |
1522 | ||
1523 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); | |
1524 | wxBoxSizer *item0 = new wxBoxSizer( wxVERTICAL ); | |
1525 | ||
1526 | //// PROJECT OR GLOBAL | |
1527 | wxString globalOrProjectChoices[2]; | |
1528 | globalOrProjectChoices[0] = _("&New projects"); | |
1529 | globalOrProjectChoices[1] = _("&This project"); | |
1530 | ||
1531 | wxRadioBox* projectOrGlobal = new wxRadioBox(panel, ID_APPLY_SETTINGS_TO, _("&Apply settings to:"), | |
1532 | wxDefaultPosition, wxDefaultSize, 2, globalOrProjectChoices); | |
1533 | item0->Add(projectOrGlobal, 0, wxGROW|wxALL, 5); | |
1534 | ||
1535 | projectOrGlobal->SetSelection(0); | |
1536 | ||
1537 | //// BACKGROUND STYLE | |
1538 | wxArrayString backgroundStyleChoices; | |
1539 | backgroundStyleChoices.Add(wxT("Colour")); | |
1540 | backgroundStyleChoices.Add(wxT("Image")); | |
532d575b | 1541 | wxStaticBox* staticBox3 = new wxStaticBox(panel, wxID_ANY, _("Background style:")); |
0f5d8ecf JS |
1542 | |
1543 | wxBoxSizer* styleSizer = new wxStaticBoxSizer( staticBox3, wxVERTICAL ); | |
1544 | item0->Add(styleSizer, 0, wxGROW|wxALL, 5); | |
1545 | ||
1546 | wxBoxSizer* itemSizer2 = new wxBoxSizer( wxHORIZONTAL ); | |
1547 | ||
1548 | wxChoice* choice2 = new wxChoice(panel, ID_BACKGROUND_STYLE, wxDefaultPosition, wxDefaultSize, backgroundStyleChoices); | |
1549 | ||
1550 | itemSizer2->Add(new wxStaticText(panel, wxID_ANY, _("&Window:")), 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1551 | itemSizer2->Add(5, 5, 1, wxALL, 0); | |
1552 | itemSizer2->Add(choice2, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5); | |
1553 | ||
1554 | styleSizer->Add(itemSizer2, 0, wxGROW|wxALL, 5); | |
1555 | ||
62675ef3 | 1556 | #if wxUSE_SPINCTRL |
0f5d8ecf JS |
1557 | //// FONT SIZE SELECTION |
1558 | ||
532d575b | 1559 | wxStaticBox* staticBox1 = new wxStaticBox(panel, wxID_ANY, _("Tile font size:")); |
0f5d8ecf JS |
1560 | wxBoxSizer* itemSizer5 = new wxStaticBoxSizer( staticBox1, wxHORIZONTAL ); |
1561 | ||
1562 | wxSpinCtrl* spinCtrl = new wxSpinCtrl(panel, ID_FONT_SIZE, wxEmptyString, wxDefaultPosition, | |
532d575b | 1563 | wxSize(80, wxDefaultCoord)); |
0f5d8ecf JS |
1564 | itemSizer5->Add(spinCtrl, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5); |
1565 | ||
1566 | item0->Add(itemSizer5, 0, wxGROW|wxLEFT|wxRIGHT, 5); | |
62675ef3 | 1567 | #endif |
0f5d8ecf JS |
1568 | |
1569 | topSizer->Add( item0, 1, wxGROW|wxALIGN_CENTRE|wxALL, 5 ); | |
0f4991f4 | 1570 | topSizer->AddSpacer(5); |
0f5d8ecf JS |
1571 | |
1572 | panel->SetSizer(topSizer); | |
1573 | topSizer->Fit(panel); | |
532d575b | 1574 | |
0f5d8ecf JS |
1575 | return panel; |
1576 | } | |
1577 | ||
532d575b | 1578 | #endif // USE_SETTINGS_DIALOG |