]> git.saurik.com Git - wxWidgets.git/blame - src/os2/msgdlg.cpp
Use wxDELETE() and wxDELETEA() when possible.
[wxWidgets.git] / src / os2 / msgdlg.cpp
CommitLineData
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
246c5004
WS
15#include "wx/msgdlg.h"
16
cdf1e714 17#ifndef WX_PRECOMP
7520f3da
WS
18 #include <stdio.h>
19 #include "wx/utils.h"
20 #include "wx/dialog.h"
21 #include "wx/app.h"
7520f3da 22 #include "wx/math.h"
0e320a79
DW
23#endif
24
cdf1e714
DW
25#include "wx/os2/private.h"
26
cdf1e714
DW
27#include <stdlib.h>
28#include <string.h>
29
30#define wxDIALOG_DEFAULT_X 300
31#define wxDIALOG_DEFAULT_Y 300
0e320a79 32
0e320a79 33IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
0e320a79 34
0e320a79
DW
35int wxMessageDialog::ShowModal()
36{
f6bcfd97
BP
37 HWND hWnd = 0;
38 ULONG ulStyle = MB_OK;
39 int nAns = wxOK;
e5b50758 40 const long lStyle = GetMessageDialogStyle();
f6bcfd97
BP
41
42 if (!wxTheApp->GetTopWindow())
43 {
44 //
45 // when the message box is shown from wxApp::OnInit() (i.e. before the
46 // message loop is entered), this must be done or the next message box
47 // will never be shown - just try putting 2 calls to wxMessageBox() in
48 // OnInit() to see it
49 //
50 while (wxTheApp->Pending())
51 wxTheApp->Dispatch();
52 }
53
2afb9e16
VZ
54 if (m_parent)
55 hWnd = (HWND) m_parent->GetHWND();
f6bcfd97
BP
56 else
57 hWnd = HWND_DESKTOP;
e5b50758 58 if (lStyle & wxYES_NO)
f6bcfd97 59 {
e5b50758 60 if (lStyle & wxCANCEL)
f6bcfd97
BP
61 ulStyle = MB_YESNOCANCEL;
62 else
63 ulStyle = MB_YESNO;
64
e5b50758 65 if (lStyle & wxNO_DEFAULT)
f6bcfd97
BP
66 ulStyle |= MB_DEFBUTTON2;
67 }
68
e5b50758 69 if (lStyle & wxOK)
f6bcfd97 70 {
e5b50758 71 if (lStyle & wxCANCEL)
f6bcfd97
BP
72 ulStyle = MB_OKCANCEL;
73 else
74 ulStyle = MB_OK;
75 }
a4578b0c
VZ
76
77 switch ( GetEffectiveIcon() )
78 {
79 case wxICON_ERROR:
80 ulStyle |= MB_ERROR;
81 break;
82
83 case wxICON_WARNING:
84 ulStyle |= MB_WARNING;
85 break;
86
87 case wxICON_QUESTION:
88 ulStyle |= MB_QUERY;
89 break;
90
91 case wxICON_INFORMATION:
92 ulStyle |= MB_INFORMATION;
93 break;
94 }
f6bcfd97
BP
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
2afb9e16
VZ
111 ,GetFullMessage().c_str()
112 ,m_caption.c_str()
f6bcfd97
BP
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