]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: msgdlg.cpp | |
3 | // Purpose: wxMessageDialog | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
14f355c2 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
2bda0e17 KB |
13 | #pragma implementation "msgdlg.h" |
14 | #endif | |
15 | ||
16 | // For compilers that support precompilation, includes "wx.h". | |
17 | #include "wx/wxprec.h" | |
18 | ||
19 | #ifdef __BORLANDC__ | |
20 | #pragma hdrstop | |
21 | #endif | |
22 | ||
23 | #ifndef WX_PRECOMP | |
35bc781e | 24 | #include "wx/app.h" |
0d7ea902 VZ |
25 | #include "wx/defs.h" |
26 | #include "wx/utils.h" | |
27 | #include "wx/dialog.h" | |
28 | #include "wx/msgdlg.h" | |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #include "wx/msw/private.h" | |
32 | ||
676d6550 JS |
33 | // For MB_TASKMODAL |
34 | #ifdef __WXWINCE__ | |
35 | #include "wx/msw/wince/missing.h" | |
36 | #endif | |
37 | ||
2bda0e17 | 38 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
2bda0e17 | 39 | |
0d7ea902 VZ |
40 | wxMessageDialog::wxMessageDialog(wxWindow *parent, |
41 | const wxString& message, | |
42 | const wxString& caption, | |
43 | long style, | |
44 | const wxPoint& WXUNUSED(pos)) | |
2bda0e17 | 45 | { |
e8e4025d VZ |
46 | #ifdef __WXDEBUG__ |
47 | // check for common programming errors | |
48 | if ( (style & wxID_OK) == wxID_OK ) | |
49 | { | |
50 | // programmer probably confused wxID_OK with wxOK. Correct one is wxOK. | |
51 | wxFAIL_MSG( _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") ); | |
52 | } | |
53 | #endif // __WXDEBUG__ | |
54 | ||
2bda0e17 KB |
55 | m_caption = caption; |
56 | m_message = message; | |
57 | m_dialogStyle = style; | |
58 | m_parent = parent; | |
59 | } | |
60 | ||
0d7ea902 | 61 | int wxMessageDialog::ShowModal() |
2bda0e17 | 62 | { |
a543e3ce | 63 | if ( !wxTheApp->GetTopWindow() ) |
0d7ea902 VZ |
64 | { |
65 | // when the message box is shown from wxApp::OnInit() (i.e. before the | |
66 | // message loop is entered), this must be done or the next message box | |
67 | // will never be shown - just try putting 2 calls to wxMessageBox() in | |
68 | // OnInit() to see it | |
69 | while ( wxTheApp->Pending() ) | |
70 | wxTheApp->Dispatch(); | |
71 | } | |
93c95e18 | 72 | |
b8505921 | 73 | // use the top level window as parent if none specified |
a543e3ce VZ |
74 | if ( !m_parent ) |
75 | m_parent = FindSuitableParent(); | |
76 | HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL; | |
b8505921 VZ |
77 | |
78 | // translate wx style in MSW | |
0d7ea902 VZ |
79 | unsigned int msStyle = MB_OK; |
80 | if (m_dialogStyle & wxYES_NO) | |
81 | { | |
82 | if (m_dialogStyle & wxCANCEL) | |
83 | msStyle = MB_YESNOCANCEL; | |
84 | else | |
85 | msStyle = MB_YESNO; | |
93c95e18 | 86 | |
0d7ea902 VZ |
87 | if (m_dialogStyle & wxNO_DEFAULT) |
88 | msStyle |= MB_DEFBUTTON2; | |
89 | } | |
90 | ||
91 | if (m_dialogStyle & wxOK) | |
92 | { | |
93 | if (m_dialogStyle & wxCANCEL) | |
94 | msStyle = MB_OKCANCEL; | |
95 | else | |
96 | msStyle = MB_OK; | |
97 | } | |
98 | if (m_dialogStyle & wxICON_EXCLAMATION) | |
99 | msStyle |= MB_ICONEXCLAMATION; | |
100 | else if (m_dialogStyle & wxICON_HAND) | |
101 | msStyle |= MB_ICONHAND; | |
102 | else if (m_dialogStyle & wxICON_INFORMATION) | |
103 | msStyle |= MB_ICONINFORMATION; | |
104 | else if (m_dialogStyle & wxICON_QUESTION) | |
105 | msStyle |= MB_ICONQUESTION; | |
2bda0e17 | 106 | |
a7fd7c78 VZ |
107 | if ( m_dialogStyle & wxSTAY_ON_TOP ) |
108 | msStyle |= MB_TOPMOST; | |
109 | ||
0d7ea902 VZ |
110 | if (hWnd) |
111 | msStyle |= MB_APPLMODAL; | |
112 | else | |
113 | msStyle |= MB_TASKMODAL; | |
93c95e18 | 114 | |
b8505921 VZ |
115 | // do show the dialog |
116 | int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle); | |
117 | int ans; | |
0d7ea902 VZ |
118 | switch (msAns) |
119 | { | |
b8505921 VZ |
120 | default: |
121 | wxFAIL_MSG(_T("unexpected ::MessageBox() return code")); | |
122 | // fall through | |
123 | ||
0d7ea902 VZ |
124 | case IDCANCEL: |
125 | ans = wxID_CANCEL; | |
126 | break; | |
127 | case IDOK: | |
128 | ans = wxID_OK; | |
129 | break; | |
130 | case IDYES: | |
131 | ans = wxID_YES; | |
132 | break; | |
133 | case IDNO: | |
134 | ans = wxID_NO; | |
135 | break; | |
136 | } | |
137 | return ans; | |
2bda0e17 KB |
138 | } |
139 |