]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
pointer returned by GetNativeFontInfo() is now const and must not be deleted (replace...
[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
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 #ifdef __WXDEBUG__
42 // check for common programming errors
43 if ( (style & wxID_OK) == wxID_OK )
44 {
45 // programmer probably confused wxID_OK with wxOK. Correct one is wxOK.
46 wxFAIL_MSG( _T("wxMessageBox: Did you mean wxOK (and not wxID_OK)?") );
47 }
48 #endif // __WXDEBUG__
49
50 m_caption = caption;
51 m_message = message;
52 m_dialogStyle = style;
53 m_parent = parent;
54 }
55
56 int wxMessageDialog::ShowModal()
57 {
58 if ( !wxTheApp->GetTopWindow() )
59 {
60 // when the message box is shown from wxApp::OnInit() (i.e. before the
61 // message loop is entered), this must be done or the next message box
62 // will never be shown - just try putting 2 calls to wxMessageBox() in
63 // OnInit() to see it
64 while ( wxTheApp->Pending() )
65 wxTheApp->Dispatch();
66 }
67
68 // use the top level window as parent if none specified
69 if ( !m_parent )
70 m_parent = FindSuitableParent();
71 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
72
73 // translate wx style in MSW
74 unsigned int msStyle = MB_OK;
75 if (m_dialogStyle & wxYES_NO)
76 {
77 if (m_dialogStyle & wxCANCEL)
78 msStyle = MB_YESNOCANCEL;
79 else
80 msStyle = MB_YESNO;
81
82 if (m_dialogStyle & wxNO_DEFAULT)
83 msStyle |= MB_DEFBUTTON2;
84 }
85
86 if (m_dialogStyle & wxOK)
87 {
88 if (m_dialogStyle & wxCANCEL)
89 msStyle = MB_OKCANCEL;
90 else
91 msStyle = MB_OK;
92 }
93 if (m_dialogStyle & wxICON_EXCLAMATION)
94 msStyle |= MB_ICONEXCLAMATION;
95 else if (m_dialogStyle & wxICON_HAND)
96 msStyle |= MB_ICONHAND;
97 else if (m_dialogStyle & wxICON_INFORMATION)
98 msStyle |= MB_ICONINFORMATION;
99 else if (m_dialogStyle & wxICON_QUESTION)
100 msStyle |= MB_ICONQUESTION;
101
102 if ( m_dialogStyle & wxSTAY_ON_TOP )
103 msStyle |= MB_TOPMOST;
104
105 if (hWnd)
106 msStyle |= MB_APPLMODAL;
107 #ifndef __WXWINCE__
108 else
109 msStyle |= MB_TASKMODAL;
110 #endif
111
112 // do show the dialog
113 int msAns = MessageBox(hWnd, m_message.c_str(), m_caption.c_str(), msStyle);
114 int ans;
115 switch (msAns)
116 {
117 default:
118 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
119 // fall through
120
121 case IDCANCEL:
122 ans = wxID_CANCEL;
123 break;
124 case IDOK:
125 ans = wxID_OK;
126 break;
127 case IDYES:
128 ans = wxID_YES;
129 break;
130 case IDNO:
131 ans = wxID_NO;
132 break;
133 }
134 return ans;
135 }
136