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