]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
e5b50758 | 2 | // Name: src/os2/msgdlg.cpp |
0e320a79 | 3 | // Purpose: wxMessageDialog |
cdf1e714 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
cdf1e714 | 6 | // Created: 10/10/99 |
e5b50758 | 7 | // RCS-ID: $Id$ |
cdf1e714 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
cdf1e714 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
246c5004 WS |
15 | #include "wx/msgdlg.h" |
16 | ||
cdf1e714 | 17 | #ifndef WX_PRECOMP |
7520f3da WS |
18 | #include <stdio.h> |
19 | #include "wx/utils.h" | |
20 | #include "wx/dialog.h" | |
21 | #include "wx/app.h" | |
7520f3da | 22 | #include "wx/math.h" |
0e320a79 DW |
23 | #endif |
24 | ||
cdf1e714 DW |
25 | #include "wx/os2/private.h" |
26 | ||
cdf1e714 DW |
27 | #include <stdlib.h> |
28 | #include <string.h> | |
29 | ||
30 | #define wxDIALOG_DEFAULT_X 300 | |
31 | #define wxDIALOG_DEFAULT_Y 300 | |
0e320a79 | 32 | |
0e320a79 | 33 | IMPLEMENT_CLASS(wxMessageDialog, wxDialog) |
0e320a79 | 34 | |
6670f564 WS |
35 | wxMessageDialog::wxMessageDialog( wxWindow* WXUNUSED(pParent), |
36 | const wxString& rsMessage, | |
37 | const wxString& rsCaption, | |
38 | long lStyle, | |
39 | const wxPoint& WXUNUSED(pPos) ) | |
0e320a79 | 40 | { |
f6bcfd97 BP |
41 | m_sCaption = rsCaption; |
42 | m_sMessage = rsMessage; | |
f6bcfd97 | 43 | m_pParent = NULL; // pParent; |
e5b50758 | 44 | SetMessageDialogStyle(lStyle); |
f6bcfd97 | 45 | } // end of wxMessageDialog::wxMessageDialog |
0e320a79 DW |
46 | |
47 | int wxMessageDialog::ShowModal() | |
48 | { | |
f6bcfd97 BP |
49 | HWND hWnd = 0; |
50 | ULONG ulStyle = MB_OK; | |
51 | int nAns = wxOK; | |
e5b50758 | 52 | const long lStyle = GetMessageDialogStyle(); |
f6bcfd97 BP |
53 | |
54 | if (!wxTheApp->GetTopWindow()) | |
55 | { | |
56 | // | |
57 | // when the message box is shown from wxApp::OnInit() (i.e. before the | |
58 | // message loop is entered), this must be done or the next message box | |
59 | // will never be shown - just try putting 2 calls to wxMessageBox() in | |
60 | // OnInit() to see it | |
61 | // | |
62 | while (wxTheApp->Pending()) | |
63 | wxTheApp->Dispatch(); | |
64 | } | |
65 | ||
66 | if (m_pParent) | |
67 | hWnd = (HWND) m_pParent->GetHWND(); | |
68 | else | |
69 | hWnd = HWND_DESKTOP; | |
e5b50758 | 70 | if (lStyle & wxYES_NO) |
f6bcfd97 | 71 | { |
e5b50758 | 72 | if (lStyle & wxCANCEL) |
f6bcfd97 BP |
73 | ulStyle = MB_YESNOCANCEL; |
74 | else | |
75 | ulStyle = MB_YESNO; | |
76 | ||
e5b50758 | 77 | if (lStyle & wxNO_DEFAULT) |
f6bcfd97 BP |
78 | ulStyle |= MB_DEFBUTTON2; |
79 | } | |
80 | ||
e5b50758 | 81 | if (lStyle & wxOK) |
f6bcfd97 | 82 | { |
e5b50758 | 83 | if (lStyle & wxCANCEL) |
f6bcfd97 BP |
84 | ulStyle = MB_OKCANCEL; |
85 | else | |
86 | ulStyle = MB_OK; | |
87 | } | |
e5b50758 | 88 | if (lStyle & wxICON_EXCLAMATION) |
f6bcfd97 | 89 | ulStyle |= MB_ICONEXCLAMATION; |
e5b50758 | 90 | else if (lStyle & wxICON_HAND) |
f6bcfd97 | 91 | ulStyle |= MB_ICONHAND; |
e5b50758 | 92 | else if (lStyle & wxICON_INFORMATION) |
f6bcfd97 | 93 | ulStyle |= MB_ICONEXCLAMATION; |
e5b50758 | 94 | else if (lStyle & wxICON_QUESTION) |
f6bcfd97 BP |
95 | ulStyle |= MB_ICONQUESTION; |
96 | ||
97 | if (hWnd != HWND_DESKTOP) | |
98 | ulStyle |= MB_APPLMODAL; | |
99 | else | |
100 | ulStyle |= MB_SYSTEMMODAL; | |
101 | ||
102 | // | |
103 | // This little line of code is get message boxes under OS/2 to | |
104 | // behve like the other ports. In OS/2 if the parent is a window | |
105 | // it displays, clipped, in the window. This centers it on the | |
106 | // desktop, like the other ports but still allows control over modality | |
107 | // | |
108 | hWnd = HWND_DESKTOP; | |
109 | ||
110 | ULONG ulAns = ::WinMessageBox( hWnd | |
111 | ,hWnd | |
112 | ,(PSZ)m_sMessage.c_str() | |
113 | ,(PSZ)m_sCaption.c_str() | |
114 | ,0L | |
115 | ,ulStyle); | |
116 | switch (ulAns) | |
117 | { | |
118 | case MBID_CANCEL: | |
119 | nAns = wxID_CANCEL; | |
120 | break; | |
121 | case MBID_OK: | |
122 | nAns = wxID_OK; | |
123 | break; | |
124 | case MBID_YES: | |
125 | nAns = wxID_YES; | |
126 | break; | |
127 | case MBID_NO: | |
128 | nAns = wxID_NO; | |
129 | break; | |
130 | default: | |
131 | nAns = wxID_CANCEL; | |
132 | } | |
133 | return nAns; | |
134 | } // end of wxMessageDialog::ShowModal |