]>
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 JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
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 | ||
2bda0e17 | 33 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
2bda0e17 | 34 | |
0d7ea902 VZ |
35 | wxMessageDialog::wxMessageDialog(wxWindow *parent, |
36 | const wxString& message, | |
37 | const wxString& caption, | |
38 | long style, | |
39 | const wxPoint& WXUNUSED(pos)) | |
2bda0e17 | 40 | { |
e8e4025d VZ |
41 | #ifdef __WXDEBUG__ |
42 | // check for common programming errors | |
43 | if ( (style & wxID_OK) == wxID_OK ) | |
44 | { | |
45 | // programmer probably confused wxID_OK with wxOK. Correct one is wxOK. | |
46 | wxFAIL_MSG( _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") ); | |
47 | } | |
48 | #endif // __WXDEBUG__ | |
49 | ||
2bda0e17 KB |
50 | m_caption = caption; |
51 | m_message = message; | |
52 | m_dialogStyle = style; | |
53 | m_parent = parent; | |
54 | } | |
55 | ||
0d7ea902 | 56 | int wxMessageDialog::ShowModal() |
2bda0e17 | 57 | { |
a543e3ce | 58 | if ( !wxTheApp->GetTopWindow() ) |
0d7ea902 VZ |
59 | { |
60 | // when the message box is shown from wxApp::OnInit() (i.e. before the | |
61 | // message loop is entered), this must be done or the next message box | |
62 | // will never be shown - just try putting 2 calls to wxMessageBox() in | |
63 | // OnInit() to see it | |
64 | while ( wxTheApp->Pending() ) | |
65 | wxTheApp->Dispatch(); | |
66 | } | |
93c95e18 | 67 | |
b8505921 | 68 | // use the top level window as parent if none specified |
a543e3ce VZ |
69 | if ( !m_parent ) |
70 | m_parent = FindSuitableParent(); | |
71 | HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL; | |
b8505921 VZ |
72 | |
73 | // translate wx style in MSW | |
0d7ea902 VZ |
74 | unsigned int msStyle = MB_OK; |
75 | if (m_dialogStyle & wxYES_NO) | |
76 | { | |
77 | if (m_dialogStyle & wxCANCEL) | |
78 | msStyle = MB_YESNOCANCEL; | |
79 | else | |
80 | msStyle = MB_YESNO; | |
93c95e18 | 81 | |
0d7ea902 VZ |
82 | if (m_dialogStyle & wxNO_DEFAULT) |
83 | msStyle |= MB_DEFBUTTON2; | |
84 | } | |
85 | ||
86 | if (m_dialogStyle & wxOK) | |
87 | { | |
88 | if (m_dialogStyle & wxCANCEL) | |
89 | msStyle = MB_OKCANCEL; | |
90 | else | |
91 | msStyle = MB_OK; | |
92 | } | |
93 | if (m_dialogStyle & wxICON_EXCLAMATION) | |
94 | msStyle |= MB_ICONEXCLAMATION; | |
95 | else if (m_dialogStyle & wxICON_HAND) | |
96 | msStyle |= MB_ICONHAND; | |
97 | else if (m_dialogStyle & wxICON_INFORMATION) | |
98 | msStyle |= MB_ICONINFORMATION; | |
99 | else if (m_dialogStyle & wxICON_QUESTION) | |
100 | msStyle |= MB_ICONQUESTION; | |
2bda0e17 | 101 | |
a7fd7c78 VZ |
102 | if ( m_dialogStyle & wxSTAY_ON_TOP ) |
103 | msStyle |= MB_TOPMOST; | |
104 | ||
0d7ea902 VZ |
105 | if (hWnd) |
106 | msStyle |= MB_APPLMODAL; | |
107 | else | |
108 | msStyle |= MB_TASKMODAL; | |
93c95e18 | 109 | |
b8505921 VZ |
110 | // do show the dialog |
111 | int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle); | |
112 | int ans; | |
0d7ea902 VZ |
113 | switch (msAns) |
114 | { | |
b8505921 VZ |
115 | default: |
116 | wxFAIL_MSG(_T("unexpected ::MessageBox() return code")); | |
117 | // fall through | |
118 | ||
0d7ea902 VZ |
119 | case IDCANCEL: |
120 | ans = wxID_CANCEL; | |
121 | break; | |
122 | case IDOK: | |
123 | ans = wxID_OK; | |
124 | break; | |
125 | case IDYES: | |
126 | ans = wxID_YES; | |
127 | break; | |
128 | case IDNO: | |
129 | ans = wxID_NO; | |
130 | break; | |
131 | } | |
132 | return ans; | |
2bda0e17 KB |
133 | } |
134 |