]> git.saurik.com Git - wxWidgets.git/blob - src/os2/msgdlg.cpp
Fix crash in wxDC::GetMultiLineTextExtent() after last commit.
[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 #include "wx/msgdlg.h"
16
17 #ifndef WX_PRECOMP
18 #include <stdio.h>
19 #include "wx/utils.h"
20 #include "wx/dialog.h"
21 #include "wx/app.h"
22 #include "wx/math.h"
23 #endif
24
25 #include "wx/os2/private.h"
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #define wxDIALOG_DEFAULT_X 300
31 #define wxDIALOG_DEFAULT_Y 300
32
33 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
34
35 int wxMessageDialog::ShowModal()
36 {
37 HWND hWnd = 0;
38 ULONG ulStyle = MB_OK;
39 int nAns = wxOK;
40 const long lStyle = GetMessageDialogStyle();
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
54 if (m_parent)
55 hWnd = (HWND) m_parent->GetHWND();
56 else
57 hWnd = HWND_DESKTOP;
58 if (lStyle & wxYES_NO)
59 {
60 if (lStyle & wxCANCEL)
61 ulStyle = MB_YESNOCANCEL;
62 else
63 ulStyle = MB_YESNO;
64
65 if (lStyle & wxNO_DEFAULT)
66 ulStyle |= MB_DEFBUTTON2;
67 }
68
69 if (lStyle & wxOK)
70 {
71 if (lStyle & wxCANCEL)
72 ulStyle = MB_OKCANCEL;
73 else
74 ulStyle = MB_OK;
75 }
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 }
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 ,GetFullMessage().c_str()
112 ,m_caption.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