]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
don't use border styles for windows in wxUniversal
[wxWidgets.git] / src / msw / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "msgdlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include "wx/app.h"
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
29 #endif
30
31 #include "wx/msw/private.h"
32
33 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
34
35 wxMessageDialog::wxMessageDialog(wxWindow *parent,
36 const wxString& message,
37 const wxString& caption,
38 long style,
39 const wxPoint& WXUNUSED(pos))
40 {
41 m_caption = caption;
42 m_message = message;
43 m_dialogStyle = style;
44 m_parent = parent;
45 }
46
47 int wxMessageDialog::ShowModal()
48 {
49 wxWindow *winTop = wxTheApp->GetTopWindow();
50 if ( !winTop )
51 {
52 // when the message box is shown from wxApp::OnInit() (i.e. before the
53 // message loop is entered), this must be done or the next message box
54 // will never be shown - just try putting 2 calls to wxMessageBox() in
55 // OnInit() to see it
56 while ( wxTheApp->Pending() )
57 wxTheApp->Dispatch();
58 }
59
60 // use the top level window as parent if none specified
61 HWND hWnd = 0;
62 if ( m_parent )
63 hWnd = GetHwndOf(m_parent);
64 else if ( winTop )
65 hWnd = GetHwndOf(winTop);
66
67 // translate wx style in MSW
68 unsigned int msStyle = MB_OK;
69 if (m_dialogStyle & wxYES_NO)
70 {
71 if (m_dialogStyle & wxCANCEL)
72 msStyle = MB_YESNOCANCEL;
73 else
74 msStyle = MB_YESNO;
75
76 if (m_dialogStyle & wxNO_DEFAULT)
77 msStyle |= MB_DEFBUTTON2;
78 }
79
80 if (m_dialogStyle & wxOK)
81 {
82 if (m_dialogStyle & wxCANCEL)
83 msStyle = MB_OKCANCEL;
84 else
85 msStyle = MB_OK;
86 }
87 if (m_dialogStyle & wxICON_EXCLAMATION)
88 msStyle |= MB_ICONEXCLAMATION;
89 else if (m_dialogStyle & wxICON_HAND)
90 msStyle |= MB_ICONHAND;
91 else if (m_dialogStyle & wxICON_INFORMATION)
92 msStyle |= MB_ICONINFORMATION;
93 else if (m_dialogStyle & wxICON_QUESTION)
94 msStyle |= MB_ICONQUESTION;
95
96 if (hWnd)
97 msStyle |= MB_APPLMODAL;
98 else
99 msStyle |= MB_TASKMODAL;
100
101 // do show the dialog
102 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
103 int ans;
104 switch (msAns)
105 {
106 default:
107 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
108 // fall through
109
110 case IDCANCEL:
111 ans = wxID_CANCEL;
112 break;
113 case IDOK:
114 ans = wxID_OK;
115 break;
116 case IDYES:
117 ans = wxID_YES;
118 break;
119 case IDNO:
120 ans = wxID_NO;
121 break;
122 }
123 return ans;
124 }
125