]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/msgdlg.cpp
3 // Purpose: wxMessageDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/msgdlg.h"
24 #include "wx/dialog.h"
27 #include "wx/msw/private.h"
31 #include "wx/msw/wince/missing.h"
34 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
)
36 int wxMessageDialog::ShowModal()
38 if ( !wxTheApp
->GetTopWindow() )
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
44 while ( wxTheApp
->Pending() )
48 // use the top level window as parent if none specified
50 m_parent
= FindSuitableParent();
51 HWND hWnd
= m_parent
? GetHwndOf(m_parent
) : NULL
;
53 // translate wx style in MSW
54 unsigned int msStyle
= MB_OK
;
55 const long wxStyle
= GetMessageDialogStyle();
56 if (wxStyle
& wxYES_NO
)
58 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
59 if (wxStyle
& wxCANCEL
)
60 msStyle
= MB_YESNOCANCEL
;
62 #endif // !(__SMARTPHONE__ && __WXWINCE__)
65 if (wxStyle
& wxNO_DEFAULT
)
66 msStyle
|= MB_DEFBUTTON2
;
71 if (wxStyle
& wxCANCEL
)
72 msStyle
= MB_OKCANCEL
;
76 if (wxStyle
& wxICON_EXCLAMATION
)
77 msStyle
|= MB_ICONEXCLAMATION
;
78 else if (wxStyle
& wxICON_HAND
)
79 msStyle
|= MB_ICONHAND
;
80 else if (wxStyle
& wxICON_INFORMATION
)
81 msStyle
|= MB_ICONINFORMATION
;
82 else if (wxStyle
& wxICON_QUESTION
)
83 msStyle
|= MB_ICONQUESTION
;
85 if ( wxStyle
& wxSTAY_ON_TOP
)
86 msStyle
|= MB_TOPMOST
;
89 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
90 msStyle
|= MB_RTLREADING
| MB_RIGHT
;
94 msStyle
|= MB_APPLMODAL
;
96 msStyle
|= MB_TASKMODAL
;
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)
101 wxString message
= GetFullMessage();
103 if ( wxTheApp
->GetLayoutDirection() == wxLayout_RightToLeft
)
105 // NB: not all compilers support \u escapes
106 static const wchar_t wchRLM
= 0x200f;
107 message
.Prepend(wxString(wchRLM
, 2));
109 #endif // wxUSE_UNICODE
111 // do show the dialog
112 int msAns
= MessageBox(hWnd
, message
.wx_str(), m_caption
.wx_str(), msStyle
);
117 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));