]> git.saurik.com Git - wxWidgets.git/blame - src/msw/msgdlg.cpp
do use the font in DoGetTextExtent()
[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
VZ
36wxMessageDialog::wxMessageDialog(wxWindow *parent,
37 const wxString& message,
38 const wxString& caption,
39 long style,
40 const wxPoint& WXUNUSED(pos))
2bda0e17
KB
41{
42 m_caption = caption;
43 m_message = message;
2bda0e17 44 m_parent = parent;
e5b50758 45 SetMessageDialogStyle(style);
2bda0e17
KB
46}
47
0d7ea902 48int wxMessageDialog::ShowModal()
2bda0e17 49{
a543e3ce 50 if ( !wxTheApp->GetTopWindow() )
0d7ea902
VZ
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 }
93c95e18 59
b8505921 60 // use the top level window as parent if none specified
a543e3ce
VZ
61 if ( !m_parent )
62 m_parent = FindSuitableParent();
63 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
b8505921
VZ
64
65 // translate wx style in MSW
0d7ea902 66 unsigned int msStyle = MB_OK;
e5b50758
WS
67 const long wxStyle = GetMessageDialogStyle();
68 if (wxStyle & wxYES_NO)
0d7ea902 69 {
3180bc0e 70#if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
e5b50758 71 if (wxStyle & wxCANCEL)
0d7ea902
VZ
72 msStyle = MB_YESNOCANCEL;
73 else
3180bc0e 74#endif // !(__SMARTPHONE__ && __WXWINCE__)
0d7ea902 75 msStyle = MB_YESNO;
93c95e18 76
e5b50758 77 if (wxStyle & wxNO_DEFAULT)
0d7ea902
VZ
78 msStyle |= MB_DEFBUTTON2;
79 }
80
e5b50758 81 if (wxStyle & wxOK)
0d7ea902 82 {
e5b50758 83 if (wxStyle & wxCANCEL)
0d7ea902
VZ
84 msStyle = MB_OKCANCEL;
85 else
86 msStyle = MB_OK;
87 }
e5b50758 88 if (wxStyle & wxICON_EXCLAMATION)
0d7ea902 89 msStyle |= MB_ICONEXCLAMATION;
e5b50758 90 else if (wxStyle & wxICON_HAND)
0d7ea902 91 msStyle |= MB_ICONHAND;
e5b50758 92 else if (wxStyle & wxICON_INFORMATION)
0d7ea902 93 msStyle |= MB_ICONINFORMATION;
e5b50758 94 else if (wxStyle & wxICON_QUESTION)
0d7ea902 95 msStyle |= MB_ICONQUESTION;
2bda0e17 96
e5b50758 97 if ( wxStyle & wxSTAY_ON_TOP )
a7fd7c78
VZ
98 msStyle |= MB_TOPMOST;
99
08a58133 100#ifndef __WXWINCE__
978af864
VZ
101 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
102 msStyle |= MB_RTLREADING | MB_RIGHT;
08a58133 103#endif
978af864 104
0d7ea902
VZ
105 if (hWnd)
106 msStyle |= MB_APPLMODAL;
107 else
108 msStyle |= MB_TASKMODAL;
93c95e18 109
12e424d2
VZ
110 // per MSDN documentation for MessageBox() we can prefix the message with 2
111 // right-to-left mark characters to tell the function to use RTL layout
112 // (unfortunately this only works in Unicode builds)
113 wxString message = m_message;
114#if wxUSE_UNICODE
115 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
116 {
117 // NB: not all compilers support \u escapes
118 static const wchar_t wchRLM = 0x200f;
119 message.Prepend(wxString(wchRLM, 2));
120 }
121#endif // wxUSE_UNICODE
122
b8505921 123 // do show the dialog
12e424d2 124 int msAns = MessageBox(hWnd, message, m_caption, msStyle);
b8505921 125 int ans;
0d7ea902
VZ
126 switch (msAns)
127 {
b8505921
VZ
128 default:
129 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
130 // fall through
131
0d7ea902
VZ
132 case IDCANCEL:
133 ans = wxID_CANCEL;
134 break;
135 case IDOK:
136 ans = wxID_OK;
137 break;
138 case IDYES:
139 ans = wxID_YES;
140 break;
141 case IDNO:
142 ans = wxID_NO;
143 break;
144 }
145 return ans;
2bda0e17 146}