]> git.saurik.com Git - wxWidgets.git/blame - src/os2/msgdlg.cpp
better handling of empty MDI parent frame visibility: show it only when there are...
[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
aa213887
SN
12#ifdef __GNUG__
13#pragma implementation "msgdlg.h"
14#endif
15
cdf1e714
DW
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"
f6bcfd97 24#include "wx/app.h"
cdf1e714 25#include "wx/msgdlg.h"
463c4d71 26#include "wx/math.h"
0e320a79
DW
27#endif
28
cdf1e714
DW
29#include "wx/os2/private.h"
30
cdf1e714
DW
31#include <stdlib.h>
32#include <string.h>
33
34#define wxDIALOG_DEFAULT_X 300
35#define wxDIALOG_DEFAULT_Y 300
0e320a79 36
0e320a79 37IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
0e320a79 38
6670f564
WS
39wxMessageDialog::wxMessageDialog( wxWindow* WXUNUSED(pParent),
40 const wxString& rsMessage,
41 const wxString& rsCaption,
42 long lStyle,
43 const wxPoint& WXUNUSED(pPos) )
0e320a79 44{
f6bcfd97
BP
45 m_sCaption = rsCaption;
46 m_sMessage = rsMessage;
f6bcfd97 47 m_pParent = NULL; // pParent;
e5b50758 48 SetMessageDialogStyle(lStyle);
f6bcfd97 49} // end of wxMessageDialog::wxMessageDialog
0e320a79
DW
50
51int wxMessageDialog::ShowModal()
52{
f6bcfd97
BP
53 HWND hWnd = 0;
54 ULONG ulStyle = MB_OK;
55 int nAns = wxOK;
e5b50758 56 const long lStyle = GetMessageDialogStyle();
f6bcfd97
BP
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;
e5b50758 74 if (lStyle & wxYES_NO)
f6bcfd97 75 {
e5b50758 76 if (lStyle & wxCANCEL)
f6bcfd97
BP
77 ulStyle = MB_YESNOCANCEL;
78 else
79 ulStyle = MB_YESNO;
80
e5b50758 81 if (lStyle & wxNO_DEFAULT)
f6bcfd97
BP
82 ulStyle |= MB_DEFBUTTON2;
83 }
84
e5b50758 85 if (lStyle & wxOK)
f6bcfd97 86 {
e5b50758 87 if (lStyle & wxCANCEL)
f6bcfd97
BP
88 ulStyle = MB_OKCANCEL;
89 else
90 ulStyle = MB_OK;
91 }
e5b50758 92 if (lStyle & wxICON_EXCLAMATION)
f6bcfd97 93 ulStyle |= MB_ICONEXCLAMATION;
e5b50758 94 else if (lStyle & wxICON_HAND)
f6bcfd97 95 ulStyle |= MB_ICONHAND;
e5b50758 96 else if (lStyle & wxICON_INFORMATION)
f6bcfd97 97 ulStyle |= MB_ICONEXCLAMATION;
e5b50758 98 else if (lStyle & wxICON_QUESTION)
f6bcfd97
BP
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