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