]> git.saurik.com Git - wxWidgets.git/blob - src/os2/msgdlg.cpp
Add doc for wxGraphicsContext.Create(), which is a lightweight context with no target...
[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/modalhook.h"
26 #include "wx/os2/private.h"
27
28 #include <stdlib.h>
29 #include <string.h>
30
31 #define wxDIALOG_DEFAULT_X 300
32 #define wxDIALOG_DEFAULT_Y 300
33
34 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
35
36 int wxMessageDialog::ShowModal()
37 {
38 WX_HOOK_MODAL_DIALOG();
39
40 HWND hWnd = 0;
41 ULONG ulStyle = MB_OK;
42 int nAns = wxOK;
43 const long lStyle = GetMessageDialogStyle();
44
45 if (!wxTheApp->GetTopWindow())
46 {
47 //
48 // when the message box is shown from wxApp::OnInit() (i.e. before the
49 // message loop is entered), this must be done or the next message box
50 // will never be shown - just try putting 2 calls to wxMessageBox() in
51 // OnInit() to see it
52 //
53 while (wxTheApp->Pending())
54 wxTheApp->Dispatch();
55 }
56
57 if (m_parent)
58 hWnd = (HWND) m_parent->GetHWND();
59 else
60 hWnd = HWND_DESKTOP;
61 if (lStyle & wxYES_NO)
62 {
63 if (lStyle & wxCANCEL)
64 ulStyle = MB_YESNOCANCEL;
65 else
66 ulStyle = MB_YESNO;
67
68 if (lStyle & wxNO_DEFAULT)
69 ulStyle |= MB_DEFBUTTON2;
70 }
71
72 if (lStyle & wxOK)
73 {
74 if (lStyle & wxCANCEL)
75 ulStyle = MB_OKCANCEL;
76 else
77 ulStyle = MB_OK;
78 }
79
80 switch ( GetEffectiveIcon() )
81 {
82 case wxICON_ERROR:
83 ulStyle |= MB_ERROR;
84 break;
85
86 case wxICON_WARNING:
87 ulStyle |= MB_WARNING;
88 break;
89
90 case wxICON_QUESTION:
91 ulStyle |= MB_QUERY;
92 break;
93
94 case wxICON_INFORMATION:
95 ulStyle |= MB_INFORMATION;
96 break;
97 }
98
99 if (hWnd != HWND_DESKTOP)
100 ulStyle |= MB_APPLMODAL;
101 else
102 ulStyle |= MB_SYSTEMMODAL;
103
104 //
105 // This little line of code is get message boxes under OS/2 to
106 // behve like the other ports. In OS/2 if the parent is a window
107 // it displays, clipped, in the window. This centers it on the
108 // desktop, like the other ports but still allows control over modality
109 //
110 hWnd = HWND_DESKTOP;
111
112 ULONG ulAns = ::WinMessageBox( hWnd
113 ,hWnd
114 ,GetFullMessage().c_str()
115 ,m_caption.c_str()
116 ,0L
117 ,ulStyle);
118 switch (ulAns)
119 {
120 case MBID_CANCEL:
121 nAns = wxID_CANCEL;
122 break;
123 case MBID_OK:
124 nAns = wxID_OK;
125 break;
126 case MBID_YES:
127 nAns = wxID_YES;
128 break;
129 case MBID_NO:
130 nAns = wxID_NO;
131 break;
132 default:
133 nAns = wxID_CANCEL;
134 }
135 return nAns;
136 } // end of wxMessageDialog::ShowModal