Base for wxMessageDialog with common checks for style.
[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 #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 #ifndef WX_PRECOMP
20 #include <stdio.h>
21 #include "wx/defs.h"
22 #include "wx/utils.h"
23 #include "wx/dialog.h"
24 #include "wx/app.h"
25 #include "wx/msgdlg.h"
26 #include "wx/math.h"
27 #endif
28
29 #include "wx/os2/private.h"
30
31 #include <stdlib.h>
32 #include <string.h>
33
34 #define wxDIALOG_DEFAULT_X 300
35 #define wxDIALOG_DEFAULT_Y 300
36
37 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
38
39 wxMessageDialog::wxMessageDialog(
40 wxWindow* pParent
41 , const wxString& rsMessage
42 , const wxString& rsCaption
43 , long lStyle
44 , const wxPoint& pPos
45 )
46 {
47 m_sCaption = rsCaption;
48 m_sMessage = rsMessage;
49 m_pParent = NULL; // pParent;
50 SetMessageDialogStyle(lStyle);
51 } // end of wxMessageDialog::wxMessageDialog
52
53 int wxMessageDialog::ShowModal()
54 {
55 HWND hWnd = 0;
56 ULONG ulStyle = MB_OK;
57 int nAns = wxOK;
58 const long lStyle = GetMessageDialogStyle();
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;
76 if (lStyle & wxYES_NO)
77 {
78 if (lStyle & wxCANCEL)
79 ulStyle = MB_YESNOCANCEL;
80 else
81 ulStyle = MB_YESNO;
82
83 if (lStyle & wxNO_DEFAULT)
84 ulStyle |= MB_DEFBUTTON2;
85 }
86
87 if (lStyle & wxOK)
88 {
89 if (lStyle & wxCANCEL)
90 ulStyle = MB_OKCANCEL;
91 else
92 ulStyle = MB_OK;
93 }
94 if (lStyle & wxICON_EXCLAMATION)
95 ulStyle |= MB_ICONEXCLAMATION;
96 else if (lStyle & wxICON_HAND)
97 ulStyle |= MB_ICONHAND;
98 else if (lStyle & wxICON_INFORMATION)
99 ulStyle |= MB_ICONEXCLAMATION;
100 else if (lStyle & wxICON_QUESTION)
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
141