]> git.saurik.com Git - wxWidgets.git/blob - src/os2/msgdlg.cpp
wxGTK1 : wx/private/eventloopsourcesmanager.h was missing in evtloop.cpp
[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 // Copyright: (c) David Webster
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/msgdlg.h"
15
16 #ifndef WX_PRECOMP
17 #include <stdio.h>
18 #include "wx/utils.h"
19 #include "wx/dialog.h"
20 #include "wx/app.h"
21 #include "wx/math.h"
22 #endif
23
24 #include "wx/modalhook.h"
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 WX_HOOK_MODAL_DIALOG();
38
39 HWND hWnd = 0;
40 ULONG ulStyle = MB_OK;
41 int nAns = wxOK;
42 const long lStyle = GetMessageDialogStyle();
43
44 if (!wxTheApp->GetTopWindow())
45 {
46 //
47 // when the message box is shown from wxApp::OnInit() (i.e. before the
48 // message loop is entered), this must be done or the next message box
49 // will never be shown - just try putting 2 calls to wxMessageBox() in
50 // OnInit() to see it
51 //
52 while (wxTheApp->Pending())
53 wxTheApp->Dispatch();
54 }
55
56 if (m_parent)
57 hWnd = (HWND) m_parent->GetHWND();
58 else
59 hWnd = HWND_DESKTOP;
60 if (lStyle & wxYES_NO)
61 {
62 if (lStyle & wxCANCEL)
63 ulStyle = MB_YESNOCANCEL;
64 else
65 ulStyle = MB_YESNO;
66
67 if (lStyle & wxNO_DEFAULT)
68 ulStyle |= MB_DEFBUTTON2;
69 }
70
71 if (lStyle & wxOK)
72 {
73 if (lStyle & wxCANCEL)
74 ulStyle = MB_OKCANCEL;
75 else
76 ulStyle = MB_OK;
77 }
78
79 switch ( GetEffectiveIcon() )
80 {
81 case wxICON_ERROR:
82 ulStyle |= MB_ERROR;
83 break;
84
85 case wxICON_WARNING:
86 ulStyle |= MB_WARNING;
87 break;
88
89 case wxICON_QUESTION:
90 ulStyle |= MB_QUERY;
91 break;
92
93 case wxICON_INFORMATION:
94 ulStyle |= MB_INFORMATION;
95 break;
96 }
97
98 if (hWnd != HWND_DESKTOP)
99 ulStyle |= MB_APPLMODAL;
100 else
101 ulStyle |= MB_SYSTEMMODAL;
102
103 //
104 // This little line of code is get message boxes under OS/2 to
105 // behve like the other ports. In OS/2 if the parent is a window
106 // it displays, clipped, in the window. This centers it on the
107 // desktop, like the other ports but still allows control over modality
108 //
109 hWnd = HWND_DESKTOP;
110
111 ULONG ulAns = ::WinMessageBox( hWnd
112 ,hWnd
113 ,GetFullMessage().c_str()
114 ,m_caption.c_str()
115 ,0L
116 ,ulStyle);
117 switch (ulAns)
118 {
119 case MBID_CANCEL:
120 nAns = wxID_CANCEL;
121 break;
122 case MBID_OK:
123 nAns = wxID_OK;
124 break;
125 case MBID_YES:
126 nAns = wxID_YES;
127 break;
128 case MBID_NO:
129 nAns = wxID_NO;
130 break;
131 default:
132 nAns = wxID_CANCEL;
133 }
134 return nAns;
135 } // end of wxMessageDialog::ShowModal