]> git.saurik.com Git - wxWidgets.git/blob - src/os2/msgdlg.cpp
use quotes, not angle brackets, for wx headers
[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( wxWindow* WXUNUSED(pParent),
40 const wxString& rsMessage,
41 const wxString& rsCaption,
42 long lStyle,
43 const wxPoint& WXUNUSED(pPos) )
44 {
45 m_sCaption = rsCaption;
46 m_sMessage = rsMessage;
47 m_pParent = NULL; // pParent;
48 SetMessageDialogStyle(lStyle);
49 } // end of wxMessageDialog::wxMessageDialog
50
51 int wxMessageDialog::ShowModal()
52 {
53 HWND hWnd = 0;
54 ULONG ulStyle = MB_OK;
55 int nAns = wxOK;
56 const long lStyle = GetMessageDialogStyle();
57
58 if (!wxTheApp->GetTopWindow())
59 {
60 //
61 // when the message box is shown from wxApp::OnInit() (i.e. before the
62 // message loop is entered), this must be done or the next message box
63 // will never be shown - just try putting 2 calls to wxMessageBox() in
64 // OnInit() to see it
65 //
66 while (wxTheApp->Pending())
67 wxTheApp->Dispatch();
68 }
69
70 if (m_pParent)
71 hWnd = (HWND) m_pParent->GetHWND();
72 else
73 hWnd = HWND_DESKTOP;
74 if (lStyle & wxYES_NO)
75 {
76 if (lStyle & wxCANCEL)
77 ulStyle = MB_YESNOCANCEL;
78 else
79 ulStyle = MB_YESNO;
80
81 if (lStyle & wxNO_DEFAULT)
82 ulStyle |= MB_DEFBUTTON2;
83 }
84
85 if (lStyle & wxOK)
86 {
87 if (lStyle & wxCANCEL)
88 ulStyle = MB_OKCANCEL;
89 else
90 ulStyle = MB_OK;
91 }
92 if (lStyle & wxICON_EXCLAMATION)
93 ulStyle |= MB_ICONEXCLAMATION;
94 else if (lStyle & wxICON_HAND)
95 ulStyle |= MB_ICONHAND;
96 else if (lStyle & wxICON_INFORMATION)
97 ulStyle |= MB_ICONEXCLAMATION;
98 else if (lStyle & wxICON_QUESTION)
99 ulStyle |= MB_ICONQUESTION;
100
101 if (hWnd != HWND_DESKTOP)
102 ulStyle |= MB_APPLMODAL;
103 else
104 ulStyle |= MB_SYSTEMMODAL;
105
106 //
107 // This little line of code is get message boxes under OS/2 to
108 // behve like the other ports. In OS/2 if the parent is a window
109 // it displays, clipped, in the window. This centers it on the
110 // desktop, like the other ports but still allows control over modality
111 //
112 hWnd = HWND_DESKTOP;
113
114 ULONG ulAns = ::WinMessageBox( hWnd
115 ,hWnd
116 ,(PSZ)m_sMessage.c_str()
117 ,(PSZ)m_sCaption.c_str()
118 ,0L
119 ,ulStyle);
120 switch (ulAns)
121 {
122 case MBID_CANCEL:
123 nAns = wxID_CANCEL;
124 break;
125 case MBID_OK:
126 nAns = wxID_OK;
127 break;
128 case MBID_YES:
129 nAns = wxID_YES;
130 break;
131 case MBID_NO:
132 nAns = wxID_NO;
133 break;
134 default:
135 nAns = wxID_CANCEL;
136 }
137 return nAns;
138 } // end of wxMessageDialog::ShowModal