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