]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
b6c588e1 | 2 | // Name: src/msw/dialog.cpp |
2bda0e17 KB |
3 | // Purpose: wxDialog class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
b6c588e1 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
b6c588e1 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
b6c588e1 VZ |
28 | #include "wx/dialog.h" |
29 | #include "wx/utils.h" | |
30 | #include "wx/frame.h" | |
31 | #include "wx/app.h" | |
95e92d90 | 32 | #include "wx/button.h" |
b6c588e1 VZ |
33 | #include "wx/settings.h" |
34 | #include "wx/intl.h" | |
35 | #include "wx/log.h" | |
2bda0e17 KB |
36 | #endif |
37 | ||
38 | #include "wx/msw/private.h" | |
dbda9e86 | 39 | #include "wx/log.h" |
ac8d0c11 | 40 | #include "wx/evtloop.h" |
8c7f5f03 | 41 | #include "wx/ptr_scpd.h" |
2bda0e17 | 42 | |
660296aa | 43 | #include "wx/msw/wrapcdlg.h" |
2bda0e17 | 44 | |
3180bc0e | 45 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
ef6d716b | 46 | #include "wx/msw/wince/resources.h" |
3180bc0e | 47 | #endif // __SMARTPHONE__ && __WXWINCE__ |
ef6d716b | 48 | |
ec5f0c24 JS |
49 | #if wxUSE_TOOLBAR && defined(__POCKETPC__) |
50 | #include "wx/toolbar.h" | |
51 | #endif | |
52 | ||
b6c588e1 VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // wxWin macros | |
55 | // ---------------------------------------------------------------------------- | |
56 | ||
ffca575c SC |
57 | #if wxUSE_EXTENDED_RTTI |
58 | WX_DEFINE_FLAGS( wxDialogStyle ) | |
59 | ||
3ff066a4 | 60 | wxBEGIN_FLAGS( wxDialogStyle ) |
ffca575c SC |
61 | // new style border flags, we put them first to |
62 | // use them for streaming out | |
3ff066a4 SC |
63 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
64 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
65 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
66 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
67 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
68 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
044fe836 | 69 | |
ffca575c | 70 | // old style border flags |
3ff066a4 SC |
71 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
72 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
73 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
74 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
75 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
76 | wxFLAGS_MEMBER(wxNO_BORDER) | |
ffca575c SC |
77 | |
78 | // standard window styles | |
3ff066a4 SC |
79 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
80 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
ffca575c SC |
81 | |
82 | // dialog styles | |
3ff066a4 SC |
83 | wxFLAGS_MEMBER(wxWS_EX_VALIDATE_RECURSIVELY) |
84 | wxFLAGS_MEMBER(wxSTAY_ON_TOP) | |
85 | wxFLAGS_MEMBER(wxCAPTION) | |
86 | wxFLAGS_MEMBER(wxTHICK_FRAME) | |
87 | wxFLAGS_MEMBER(wxSYSTEM_MENU) | |
88 | wxFLAGS_MEMBER(wxRESIZE_BORDER) | |
89 | wxFLAGS_MEMBER(wxRESIZE_BOX) | |
90 | wxFLAGS_MEMBER(wxCLOSE_BOX) | |
91 | wxFLAGS_MEMBER(wxMAXIMIZE_BOX) | |
92 | wxFLAGS_MEMBER(wxMINIMIZE_BOX) | |
93 | wxEND_FLAGS( wxDialogStyle ) | |
ffca575c SC |
94 | |
95 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxDialog, wxTopLevelWindow,"wx/dialog.h") | |
96 | ||
3ff066a4 | 97 | wxBEGIN_PROPERTIES_TABLE(wxDialog) |
af498247 VZ |
98 | wxPROPERTY( Title, wxString, SetTitle, GetTitle, wxString() , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) |
99 | wxPROPERTY_FLAGS( WindowStyle , wxDialogStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , EMPTY_MACROVALUE , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
3ff066a4 | 100 | wxEND_PROPERTIES_TABLE() |
ffca575c | 101 | |
3ff066a4 SC |
102 | wxBEGIN_HANDLERS_TABLE(wxDialog) |
103 | wxEND_HANDLERS_TABLE() | |
ffca575c | 104 | |
044fe836 | 105 | wxCONSTRUCTOR_6( wxDialog , wxWindow* , Parent , wxWindowID , Id , wxString , Title , wxPoint , Position , wxSize , Size , long , WindowStyle) |
ffca575c SC |
106 | |
107 | #else | |
82c9f85c | 108 | IMPLEMENT_DYNAMIC_CLASS(wxDialog, wxTopLevelWindow) |
ffca575c | 109 | #endif |
066f1b7a | 110 | |
138e1502 | 111 | BEGIN_EVENT_TABLE(wxDialog, wxDialogBase) |
1b6452df VZ |
112 | EVT_BUTTON(wxID_OK, wxDialog::OnOK) |
113 | EVT_BUTTON(wxID_APPLY, wxDialog::OnApply) | |
114 | EVT_BUTTON(wxID_CANCEL, wxDialog::OnCancel) | |
b6c588e1 | 115 | |
1b6452df | 116 | EVT_SYS_COLOUR_CHANGED(wxDialog::OnSysColourChanged) |
b6c588e1 | 117 | |
1b6452df VZ |
118 | EVT_CLOSE(wxDialog::OnCloseWindow) |
119 | END_EVENT_TABLE() | |
2bda0e17 | 120 | |
6757b5e3 VZ |
121 | // ---------------------------------------------------------------------------- |
122 | // wxDialogModalData | |
123 | // ---------------------------------------------------------------------------- | |
124 | ||
8c7f5f03 VZ |
125 | // this is simply a container for any data we need to implement modality which |
126 | // allows us to avoid changing wxDialog each time the implementation changes | |
6757b5e3 VZ |
127 | class wxDialogModalData |
128 | { | |
129 | public: | |
8c7f5f03 | 130 | wxDialogModalData(wxDialog *dialog) : m_evtLoop(dialog) { } |
6757b5e3 | 131 | |
8c7f5f03 | 132 | void RunLoop() |
6757b5e3 | 133 | { |
6757b5e3 VZ |
134 | m_evtLoop.Run(); |
135 | } | |
136 | ||
137 | void ExitLoop() | |
138 | { | |
6757b5e3 VZ |
139 | m_evtLoop.Exit(); |
140 | } | |
141 | ||
6757b5e3 | 142 | private: |
8c7f5f03 | 143 | wxModalEventLoop m_evtLoop; |
6757b5e3 VZ |
144 | }; |
145 | ||
259c43f6 | 146 | wxDEFINE_TIED_SCOPED_PTR_TYPE(wxDialogModalData) |
8c7f5f03 | 147 | |
b6c588e1 VZ |
148 | // ============================================================================ |
149 | // implementation | |
150 | // ============================================================================ | |
151 | ||
152 | // ---------------------------------------------------------------------------- | |
153 | // wxDialog construction | |
154 | // ---------------------------------------------------------------------------- | |
155 | ||
b0a6bb75 | 156 | void wxDialog::Init() |
2bda0e17 | 157 | { |
52a07708 | 158 | m_oldFocus = (wxWindow *)NULL; |
044fe836 | 159 | m_isShown = false; |
6757b5e3 | 160 | m_modalData = NULL; |
044fe836 | 161 | m_endModalCalled = false; |
ec5f0c24 JS |
162 | #if wxUSE_TOOLBAR && defined(__POCKETPC__) |
163 | m_dialogToolBar = NULL; | |
164 | #endif | |
2bda0e17 KB |
165 | } |
166 | ||
b3daa5a3 VZ |
167 | bool wxDialog::Create(wxWindow *parent, |
168 | wxWindowID id, | |
462e2437 VZ |
169 | const wxString& title, |
170 | const wxPoint& pos, | |
171 | const wxSize& size, | |
172 | long style, | |
173 | const wxString& name) | |
2bda0e17 | 174 | { |
82c9f85c | 175 | SetExtraStyle(GetExtraStyle() | wxTOPLEVEL_EX_DIALOG); |
bd9d76cb | 176 | |
b225f659 | 177 | // save focus before doing anything which can potentially change it |
82c9f85c | 178 | m_oldFocus = FindFocus(); |
462e2437 | 179 | |
706bb5f9 | 180 | // All dialogs should really have this style |
b225f659 | 181 | style |= wxTAB_TRAVERSAL; |
2bda0e17 | 182 | |
b225f659 | 183 | if ( !wxTopLevelWindow::Create(parent, id, title, pos, size, style, name) ) |
044fe836 | 184 | return false; |
00233716 VZ |
185 | |
186 | if ( !m_hasFont ) | |
6f951810 | 187 | SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); |
e1bdd507 | 188 | |
3180bc0e | 189 | #if defined(__SMARTPHONE__) && defined(__WXWINCE__) |
ef6d716b WS |
190 | SetLeftMenu(wxID_OK, _("OK")); |
191 | #endif | |
ec5f0c24 JS |
192 | #if wxUSE_TOOLBAR && defined(__POCKETPC__) |
193 | CreateToolBar(); | |
194 | #endif | |
ef6d716b | 195 | |
044fe836 | 196 | return true; |
2bda0e17 KB |
197 | } |
198 | ||
f46f4c86 VZ |
199 | // deprecated ctor |
200 | wxDialog::wxDialog(wxWindow *parent, | |
201 | const wxString& title, | |
202 | bool WXUNUSED(modal), | |
203 | int x, | |
204 | int y, | |
205 | int w, | |
206 | int h, | |
207 | long style, | |
208 | const wxString& name) | |
2bda0e17 | 209 | { |
f46f4c86 VZ |
210 | Init(); |
211 | ||
d71cc120 | 212 | Create(parent, wxID_ANY, title, wxPoint(x, y), wxSize(w, h), style, name); |
f46f4c86 VZ |
213 | } |
214 | ||
215 | void wxDialog::SetModal(bool WXUNUSED(flag)) | |
216 | { | |
217 | // nothing to do, obsolete method | |
2bda0e17 KB |
218 | } |
219 | ||
220 | wxDialog::~wxDialog() | |
221 | { | |
044fe836 | 222 | m_isBeingDeleted = true; |
2bda0e17 | 223 | |
b0a6bb75 | 224 | // this will also reenable all the other windows for a modal dialog |
044fe836 | 225 | Show(false); |
2bda0e17 KB |
226 | } |
227 | ||
b6c588e1 VZ |
228 | // ---------------------------------------------------------------------------- |
229 | // showing the dialogs | |
230 | // ---------------------------------------------------------------------------- | |
22cf5fec | 231 | |
b6c588e1 | 232 | bool wxDialog::IsModalShowing() const |
2bda0e17 | 233 | { |
f46f4c86 | 234 | return IsModal(); |
2bda0e17 KB |
235 | } |
236 | ||
a543e3ce VZ |
237 | wxWindow *wxDialog::FindSuitableParent() const |
238 | { | |
239 | // first try to use the currently active window | |
240 | HWND hwndFg = ::GetForegroundWindow(); | |
241 | wxWindow *parent = hwndFg ? wxFindWinFromHandle((WXHWND)hwndFg) | |
242 | : NULL; | |
243 | if ( !parent ) | |
244 | { | |
245 | // next try the main app window | |
246 | parent = wxTheApp->GetTopWindow(); | |
247 | } | |
248 | ||
249 | // finally, check if the parent we found is really suitable | |
250 | if ( !parent || parent == (wxWindow *)this || !parent->IsShown() ) | |
251 | { | |
252 | // don't use this one | |
253 | parent = NULL; | |
254 | } | |
255 | ||
256 | return parent; | |
257 | } | |
258 | ||
b6c588e1 | 259 | bool wxDialog::Show(bool show) |
2bda0e17 | 260 | { |
044fe836 VZ |
261 | if ( show == IsShown() ) |
262 | return false; | |
263 | ||
6757b5e3 | 264 | if ( !show && m_modalData ) |
86ad564e | 265 | { |
6757b5e3 VZ |
266 | // we need to do this before calling wxDialogBase version because if we |
267 | // had disabled other app windows, they must be reenabled right now as | |
b0a6bb75 | 268 | // if they stay disabled Windows will activate another window (one |
6757b5e3 VZ |
269 | // which is enabled, anyhow) when we're hidden in the base class Show() |
270 | // and we will lose activation | |
271 | m_modalData->ExitLoop(); | |
86ad564e JS |
272 | } |
273 | ||
044fe836 | 274 | if ( show ) |
b6c588e1 | 275 | { |
044fe836 VZ |
276 | // this usually will result in TransferDataToWindow() being called |
277 | // which will change the controls values so do it before showing as | |
278 | // otherwise we could have some flicker | |
279 | InitDialog(); | |
b6c588e1 | 280 | } |
2bda0e17 | 281 | |
044fe836 VZ |
282 | wxDialogBase::Show(show); |
283 | ||
b6c588e1 VZ |
284 | if ( show ) |
285 | { | |
2b5f62a0 VZ |
286 | // dialogs don't get WM_SIZE message after creation unlike most (all?) |
287 | // other windows and so could start their life non laid out correctly | |
288 | // if we didn't call Layout() from here | |
289 | // | |
290 | // NB: normally we should call it just the first time but doing it | |
291 | // every time is simpler than keeping a flag | |
292 | Layout(); | |
b6c588e1 | 293 | } |
2bda0e17 | 294 | |
044fe836 | 295 | return true; |
2bda0e17 KB |
296 | } |
297 | ||
313901f3 JS |
298 | void wxDialog::Raise() |
299 | { | |
300 | ::SetForegroundWindow(GetHwnd()); | |
301 | } | |
302 | ||
f46f4c86 | 303 | // show dialog modally |
a23fd0e1 | 304 | int wxDialog::ShowModal() |
2bda0e17 | 305 | { |
f46f4c86 VZ |
306 | wxASSERT_MSG( !IsModal(), _T("wxDialog::ShowModal() reentered?") ); |
307 | ||
044fe836 | 308 | m_endModalCalled = false; |
f46f4c86 VZ |
309 | |
310 | Show(); | |
311 | ||
312 | // EndModal may have been called from InitDialog handler (called from | |
313 | // inside Show()), which would cause an infinite loop if we didn't take it | |
314 | // into account | |
315 | if ( !m_endModalCalled ) | |
5e1febfa | 316 | { |
f46f4c86 VZ |
317 | // modal dialog needs a parent window, so try to find one |
318 | wxWindow *parent = GetParent(); | |
319 | if ( !parent ) | |
320 | { | |
321 | parent = FindSuitableParent(); | |
322 | } | |
5e1febfa | 323 | |
f46f4c86 VZ |
324 | // remember where the focus was |
325 | wxWindow *oldFocus = m_oldFocus; | |
326 | if ( !oldFocus ) | |
327 | { | |
328 | // VZ: do we really want to do this? | |
329 | oldFocus = parent; | |
330 | } | |
331 | ||
332 | // We have to remember the HWND because we need to check | |
333 | // the HWND still exists (oldFocus can be garbage when the dialog | |
334 | // exits, if it has been destroyed) | |
335 | HWND hwndOldFocus = oldFocus ? GetHwndOf(oldFocus) : NULL; | |
336 | ||
337 | ||
338 | // enter and run the modal loop | |
339 | { | |
340 | wxDialogModalDataTiedPtr modalData(&m_modalData, | |
341 | new wxDialogModalData(this)); | |
342 | modalData->RunLoop(); | |
343 | } | |
344 | ||
345 | ||
346 | // and restore focus | |
347 | // Note that this code MUST NOT access the dialog object's data | |
348 | // in case the object has been deleted (which will be the case | |
349 | // for a modal dialog that has been destroyed before calling EndModal). | |
350 | if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus)) | |
351 | { | |
352 | // This is likely to prove that the object still exists | |
353 | if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus) | |
354 | oldFocus->SetFocus(); | |
355 | } | |
356 | } | |
5e1febfa | 357 | |
b6c588e1 | 358 | return GetReturnCode(); |
2bda0e17 KB |
359 | } |
360 | ||
361 | void wxDialog::EndModal(int retCode) | |
362 | { | |
f46f4c86 VZ |
363 | wxASSERT_MSG( IsModal(), _T("EndModal() called for non modal dialog") ); |
364 | ||
044fe836 | 365 | m_endModalCalled = true; |
b6c588e1 | 366 | SetReturnCode(retCode); |
6a088435 | 367 | |
12b58624 VZ |
368 | Hide(); |
369 | } | |
370 | ||
371 | void wxDialog::EndDialog(int rc) | |
372 | { | |
373 | if ( IsModal() ) | |
374 | EndModal(rc); | |
375 | else | |
376 | Hide(); | |
2bda0e17 KB |
377 | } |
378 | ||
b6c588e1 VZ |
379 | // ---------------------------------------------------------------------------- |
380 | // wxWin event handlers | |
381 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 382 | |
f55fee08 VZ |
383 | bool wxDialog::EmulateButtonClickIfPresent(int id) |
384 | { | |
385 | wxButton *btn = wxDynamicCast(FindWindow(id), wxButton); | |
386 | ||
08f80371 | 387 | if ( !btn || !btn->IsEnabled() || !btn->IsShown() ) |
f55fee08 VZ |
388 | return false; |
389 | ||
390 | btn->MSWCommand(BN_CLICKED, 0 /* unused */); | |
391 | return true; | |
392 | } | |
393 | ||
2bda0e17 | 394 | // Standard buttons |
33ac7e6f | 395 | void wxDialog::OnOK(wxCommandEvent& WXUNUSED(event)) |
2bda0e17 | 396 | { |
dc1c4b62 VZ |
397 | if ( Validate() && TransferDataFromWindow() ) |
398 | { | |
12b58624 | 399 | EndDialog(wxID_OK); |
dc1c4b62 | 400 | } |
2bda0e17 KB |
401 | } |
402 | ||
33ac7e6f | 403 | void wxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) |
2bda0e17 | 404 | { |
b6c588e1 VZ |
405 | if ( Validate() ) |
406 | TransferDataFromWindow(); | |
407 | ||
408 | // TODO probably need to disable the Apply button until things change again | |
2bda0e17 KB |
409 | } |
410 | ||
33ac7e6f | 411 | void wxDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) |
2bda0e17 | 412 | { |
12b58624 | 413 | EndDialog(wxID_CANCEL); |
2bda0e17 KB |
414 | } |
415 | ||
33ac7e6f | 416 | void wxDialog::OnCloseWindow(wxCloseEvent& WXUNUSED(event)) |
2bda0e17 | 417 | { |
b6c588e1 | 418 | // We'll send a Cancel message by default, which may close the dialog. |
e3065973 JS |
419 | // Check for looping if the Cancel event handler calls Close(). |
420 | ||
421 | // Note that if a cancel button and handler aren't present in the dialog, | |
422 | // nothing will happen when you close the dialog via the window manager, or | |
b6c588e1 VZ |
423 | // via Close(). We wouldn't want to destroy the dialog by default, since |
424 | // the dialog may have been created on the stack. However, this does mean | |
425 | // that calling dialog->Close() won't delete the dialog unless the handler | |
426 | // for wxID_CANCEL does so. So use Destroy() if you want to be sure to | |
427 | // destroy the dialog. The default OnCancel (above) simply ends a modal | |
428 | // dialog, and hides a modeless dialog. | |
429 | ||
430 | // VZ: this is horrible and MT-unsafe. Can't we reuse some of these global | |
431 | // lists here? don't dare to change it now, but should be done later! | |
2bda0e17 | 432 | static wxList closing; |
bd9d76cb | 433 | |
2bda0e17 | 434 | if ( closing.Member(this) ) |
e3065973 | 435 | return; |
bd9d76cb | 436 | |
2bda0e17 | 437 | closing.Append(this); |
bd9d76cb | 438 | |
387a3b02 JS |
439 | wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); |
440 | cancelEvent.SetEventObject( this ); | |
e3065973 | 441 | GetEventHandler()->ProcessEvent(cancelEvent); // This may close the dialog |
2bda0e17 KB |
442 | |
443 | closing.DeleteObject(this); | |
e3065973 | 444 | } |
2bda0e17 | 445 | |
33ac7e6f | 446 | void wxDialog::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(event)) |
2bda0e17 | 447 | { |
a756f210 | 448 | SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); |
b6c588e1 | 449 | Refresh(); |
68ad65f8 | 450 | } |
42e69d6b | 451 | |
9ceeecb9 JS |
452 | #ifdef __POCKETPC__ |
453 | // Responds to the OK button in a PocketPC titlebar. This | |
454 | // can be overridden, or you can change the id used for | |
455 | // sending the event, by calling SetAffirmativeId. | |
456 | bool wxDialog::DoOK() | |
457 | { | |
f55fee08 VZ |
458 | const int idOk = GetAffirmativeId(); |
459 | if ( EmulateButtonClickIfPresent(idOk) ) | |
9ceeecb9 | 460 | return true; |
9ceeecb9 | 461 | |
f55fee08 VZ |
462 | wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetAffirmativeId()); |
463 | event.SetEventObject(this); | |
464 | ||
465 | return GetEventHandler()->ProcessEvent(event); | |
9ceeecb9 | 466 | } |
f55fee08 | 467 | #endif // __POCKETPC__ |
9ceeecb9 | 468 | |
ec5f0c24 JS |
469 | #if wxUSE_TOOLBAR && defined(__POCKETPC__) |
470 | // create main toolbar by calling OnCreateToolBar() | |
471 | wxToolBar* wxDialog::CreateToolBar(long style, wxWindowID winid, const wxString& name) | |
472 | { | |
473 | m_dialogToolBar = OnCreateToolBar(style, winid, name); | |
474 | ||
475 | return m_dialogToolBar; | |
476 | } | |
477 | ||
478 | // return a new toolbar | |
479 | wxToolBar *wxDialog::OnCreateToolBar(long style, | |
480 | wxWindowID winid, | |
481 | const wxString& name) | |
482 | { | |
483 | return new wxToolMenuBar(this, winid, | |
484 | wxDefaultPosition, wxDefaultSize, | |
485 | style, name); | |
660296aa | 486 | } |
ec5f0c24 | 487 | #endif |
9ceeecb9 | 488 | |
42e69d6b | 489 | // --------------------------------------------------------------------------- |
f55fee08 | 490 | // dialog Windows messages processing |
42e69d6b VZ |
491 | // --------------------------------------------------------------------------- |
492 | ||
f55fee08 VZ |
493 | bool wxDialog::MSWProcessMessage(WXMSG* pMsg) |
494 | { | |
495 | const MSG * const msg = wx_reinterpret_cast(MSG *, pMsg); | |
496 | if ( msg->message == WM_KEYDOWN && msg->wParam == VK_ESCAPE ) | |
497 | { | |
498 | int idCancel = GetEscapeId(); | |
499 | switch ( idCancel ) | |
500 | { | |
501 | case wxID_NONE: | |
502 | // don't handle Esc specially at all | |
503 | break; | |
504 | ||
505 | case wxID_ANY: | |
506 | // this value is special: it means translate Esc to wxID_CANCEL | |
507 | // but if there is no such button, then fall back to wxID_OK | |
508 | if ( EmulateButtonClickIfPresent(wxID_CANCEL) ) | |
509 | return true; | |
510 | idCancel = wxID_OK; | |
511 | // fall through | |
512 | ||
513 | default: | |
514 | // translate Esc to button press for the button with given id | |
515 | if ( EmulateButtonClickIfPresent(idCancel) ) | |
516 | return true; | |
517 | } | |
518 | } | |
519 | ||
520 | return wxDialogBase::MSWProcessMessage(pMsg); | |
521 | } | |
522 | ||
c140b7e7 | 523 | WXLRESULT wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) |
42e69d6b | 524 | { |
c140b7e7 | 525 | WXLRESULT rc = 0; |
044fe836 | 526 | bool processed = false; |
42e69d6b VZ |
527 | |
528 | switch ( message ) | |
529 | { | |
0fc58b86 RR |
530 | #ifdef __WXWINCE__ |
531 | // react to pressing the OK button in the title | |
532 | case WM_COMMAND: | |
ef6d716b WS |
533 | { |
534 | switch ( LOWORD(wParam) ) | |
0fc58b86 | 535 | { |
9ceeecb9 | 536 | #ifdef __POCKETPC__ |
ef6d716b | 537 | case IDOK: |
9ceeecb9 JS |
538 | processed = DoOK(); |
539 | if (!processed) | |
b554cf63 | 540 | processed = !Close(); |
9ceeecb9 JS |
541 | #endif |
542 | #ifdef __SMARTPHONE__ | |
ef6d716b WS |
543 | case IDM_LEFT: |
544 | case IDM_RIGHT: | |
545 | processed = HandleCommand( LOWORD(wParam) , 0 , NULL ); | |
0fc58b86 | 546 | break; |
ef6d716b | 547 | #endif // __SMARTPHONE__ |
0fc58b86 RR |
548 | } |
549 | break; | |
ef6d716b | 550 | } |
044fe836 | 551 | #endif |
42e69d6b VZ |
552 | case WM_CLOSE: |
553 | // if we can't close, tell the system that we processed the | |
554 | // message - otherwise it would close us | |
555 | processed = !Close(); | |
556 | break; | |
abceee76 | 557 | |
f73f67be VZ |
558 | case WM_SIZE: |
559 | // the Windows dialogs unfortunately are not meant to be resizeable | |
560 | // at all and their standard class doesn't include CS_[VH]REDRAW | |
561 | // styles which means that the window is not refreshed properly | |
562 | // after the resize and no amount of WS_CLIPCHILDREN/SIBLINGS can | |
563 | // help with it - so we have to refresh it manually which certainly | |
564 | // creates flicker but at least doesn't show garbage on the screen | |
565 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
044fe836 | 566 | processed = true; |
e441e1f4 | 567 | if ( HasFlag(wxFULL_REPAINT_ON_RESIZE) ) |
f73f67be | 568 | { |
044fe836 | 569 | ::InvalidateRect(GetHwnd(), NULL, false /* erase bg */); |
f73f67be VZ |
570 | } |
571 | break; | |
572 | ||
04ef50df | 573 | #ifndef __WXMICROWIN__ |
abceee76 VZ |
574 | case WM_SETCURSOR: |
575 | // we want to override the busy cursor for modal dialogs: | |
576 | // typically, wxBeginBusyCursor() is called and then a modal dialog | |
bfbd6dc1 | 577 | // is shown, but the modal dialog shouldn't have hourglass cursor |
f46f4c86 | 578 | if ( IsModal() && wxIsBusy() ) |
abceee76 | 579 | { |
bfbd6dc1 VZ |
580 | // set our cursor for all windows (but see below) |
581 | wxCursor cursor = m_cursor; | |
582 | if ( !cursor.Ok() ) | |
583 | cursor = wxCURSOR_ARROW; | |
abceee76 | 584 | |
bfbd6dc1 VZ |
585 | ::SetCursor(GetHcursorOf(cursor)); |
586 | ||
587 | // in any case, stop here and don't let wxWindow process this | |
588 | // message (it would set the busy cursor) | |
044fe836 | 589 | processed = true; |
bfbd6dc1 | 590 | |
044fe836 | 591 | // but return false to tell the child window (if the event |
bfbd6dc1 VZ |
592 | // comes from one of them and not from ourselves) that it can |
593 | // set its own cursor if it has one: thus, standard controls | |
594 | // (e.g. text ctrl) still have correct cursors in a dialog | |
595 | // invoked while wxIsBusy() | |
044fe836 | 596 | rc = false; |
abceee76 | 597 | } |
bfbd6dc1 | 598 | break; |
82c9f85c | 599 | #endif // __WXMICROWIN__ |
42e69d6b VZ |
600 | } |
601 | ||
602 | if ( !processed ) | |
603 | rc = wxWindow::MSWWindowProc(message, wParam, lParam); | |
604 | ||
605 | return rc; | |
606 | } | |
b6c588e1 | 607 |