wx/wxprec.h already includes wx/defs.h (with other minor cleaning).
[wxWidgets.git] / src / os2 / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
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"
22 #endif
23
24 #include "wx/os2/private.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28
29 #define wxDIALOG_DEFAULT_X 300
30 #define wxDIALOG_DEFAULT_Y 300
31
32 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
33
34 wxMessageDialog::wxMessageDialog( wxWindow* WXUNUSED(pParent),
35 const wxString& rsMessage,
36 const wxString& rsCaption,
37 long lStyle,
38 const wxPoint& WXUNUSED(pPos) )
39 {
40 m_sCaption = rsCaption;
41 m_sMessage = rsMessage;
42 m_pParent = NULL; // pParent;
43 SetMessageDialogStyle(lStyle);
44 } // end of wxMessageDialog::wxMessageDialog
45
46 int wxMessageDialog::ShowModal()
47 {
48 HWND hWnd = 0;
49 ULONG ulStyle = MB_OK;
50 int nAns = wxOK;
51 const long lStyle = GetMessageDialogStyle();
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;
69 if (lStyle & wxYES_NO)
70 {
71 if (lStyle & wxCANCEL)
72 ulStyle = MB_YESNOCANCEL;
73 else
74 ulStyle = MB_YESNO;
75
76 if (lStyle & wxNO_DEFAULT)
77 ulStyle |= MB_DEFBUTTON2;
78 }
79
80 if (lStyle & wxOK)
81 {
82 if (lStyle & wxCANCEL)
83 ulStyle = MB_OKCANCEL;
84 else
85 ulStyle = MB_OK;
86 }
87 if (lStyle & wxICON_EXCLAMATION)
88 ulStyle |= MB_ICONEXCLAMATION;
89 else if (lStyle & wxICON_HAND)
90 ulStyle |= MB_ICONHAND;
91 else if (lStyle & wxICON_INFORMATION)
92 ulStyle |= MB_ICONEXCLAMATION;
93 else if (lStyle & wxICON_QUESTION)
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