]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
don't keep dangling m_prevRadio pointer (2nd part of patch 1836644)
[wxWidgets.git] / src / msw / msgdlg.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/msw/msgdlg.cpp
2bda0e17
KB
3// Purpose: wxMessageDialog
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
2bda0e17
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
7520f3da 16 #pragma hdrstop
2bda0e17
KB
17#endif
18
a8ff046b
VZ
19#if wxUSE_MSGDLG
20
246c5004
WS
21#include "wx/msgdlg.h"
22
2bda0e17 23#ifndef WX_PRECOMP
35bc781e 24 #include "wx/app.h"
0d7ea902
VZ
25 #include "wx/utils.h"
26 #include "wx/dialog.h"
2bda0e17
KB
27#endif
28
29#include "wx/msw/private.h"
30
676d6550
JS
31// For MB_TASKMODAL
32#ifdef __WXWINCE__
33#include "wx/msw/wince/missing.h"
34#endif
35
2bda0e17 36IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
2bda0e17 37
0d7ea902 38int wxMessageDialog::ShowModal()
2bda0e17 39{
a543e3ce 40 if ( !wxTheApp->GetTopWindow() )
0d7ea902
VZ
41 {
42 // when the message box is shown from wxApp::OnInit() (i.e. before the
43 // message loop is entered), this must be done or the next message box
44 // will never be shown - just try putting 2 calls to wxMessageBox() in
45 // OnInit() to see it
46 while ( wxTheApp->Pending() )
47 wxTheApp->Dispatch();
48 }
93c95e18 49
b8505921 50 // use the top level window as parent if none specified
a543e3ce
VZ
51 if ( !m_parent )
52 m_parent = FindSuitableParent();
53 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
b8505921
VZ
54
55 // translate wx style in MSW
0d7ea902 56 unsigned int msStyle = MB_OK;
e5b50758
WS
57 const long wxStyle = GetMessageDialogStyle();
58 if (wxStyle & wxYES_NO)
0d7ea902 59 {
3180bc0e 60#if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
e5b50758 61 if (wxStyle & wxCANCEL)
0d7ea902
VZ
62 msStyle = MB_YESNOCANCEL;
63 else
3180bc0e 64#endif // !(__SMARTPHONE__ && __WXWINCE__)
0d7ea902 65 msStyle = MB_YESNO;
93c95e18 66
e5b50758 67 if (wxStyle & wxNO_DEFAULT)
0d7ea902
VZ
68 msStyle |= MB_DEFBUTTON2;
69 }
70
e5b50758 71 if (wxStyle & wxOK)
0d7ea902 72 {
e5b50758 73 if (wxStyle & wxCANCEL)
0d7ea902
VZ
74 msStyle = MB_OKCANCEL;
75 else
76 msStyle = MB_OK;
77 }
e5b50758 78 if (wxStyle & wxICON_EXCLAMATION)
0d7ea902 79 msStyle |= MB_ICONEXCLAMATION;
e5b50758 80 else if (wxStyle & wxICON_HAND)
0d7ea902 81 msStyle |= MB_ICONHAND;
e5b50758 82 else if (wxStyle & wxICON_INFORMATION)
0d7ea902 83 msStyle |= MB_ICONINFORMATION;
e5b50758 84 else if (wxStyle & wxICON_QUESTION)
0d7ea902 85 msStyle |= MB_ICONQUESTION;
2bda0e17 86
e5b50758 87 if ( wxStyle & wxSTAY_ON_TOP )
a7fd7c78
VZ
88 msStyle |= MB_TOPMOST;
89
08a58133 90#ifndef __WXWINCE__
978af864
VZ
91 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
92 msStyle |= MB_RTLREADING | MB_RIGHT;
08a58133 93#endif
978af864 94
0d7ea902
VZ
95 if (hWnd)
96 msStyle |= MB_APPLMODAL;
97 else
98 msStyle |= MB_TASKMODAL;
93c95e18 99
12e424d2
VZ
100 // per MSDN documentation for MessageBox() we can prefix the message with 2
101 // right-to-left mark characters to tell the function to use RTL layout
102 // (unfortunately this only works in Unicode builds)
2afb9e16 103 wxString message = GetFullMessage();
12e424d2
VZ
104#if wxUSE_UNICODE
105 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
106 {
107 // NB: not all compilers support \u escapes
108 static const wchar_t wchRLM = 0x200f;
109 message.Prepend(wxString(wchRLM, 2));
110 }
111#endif // wxUSE_UNICODE
112
b8505921 113 // do show the dialog
e0a050e3 114 int msAns = MessageBox(hWnd, message.wx_str(), m_caption.wx_str(), msStyle);
b8505921 115 int ans;
0d7ea902
VZ
116 switch (msAns)
117 {
b8505921
VZ
118 default:
119 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
120 // fall through
121
0d7ea902
VZ
122 case IDCANCEL:
123 ans = wxID_CANCEL;
124 break;
125 case IDOK:
126 ans = wxID_OK;
127 break;
128 case IDYES:
129 ans = wxID_YES;
130 break;
131 case IDNO:
132 ans = wxID_NO;
133 break;
134 }
135 return ans;
2bda0e17 136}
a8ff046b
VZ
137
138#endif // wxUSE_MSGDLG