]> git.saurik.com Git - wxWidgets.git/blob - src/msw/msgdlg.cpp
rename g_openDialogs to wxOpenModalDialogsCount and define it in toplevel.cpp to...
[wxWidgets.git] / src / msw / msgdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/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 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #if wxUSE_MSGDLG
20
21 #include "wx/msgdlg.h"
22
23 #ifndef WX_PRECOMP
24 #include "wx/app.h"
25 #include "wx/utils.h"
26 #include "wx/dialog.h"
27 #endif
28
29 #include "wx/msw/private.h"
30
31 // For MB_TASKMODAL
32 #ifdef __WXWINCE__
33 #include "wx/msw/wince/missing.h"
34 #endif
35
36 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
37
38 int wxMessageDialog::ShowModal()
39 {
40 if ( !wxTheApp->GetTopWindow() )
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 }
49
50 // use the top level window as parent if none specified
51 if ( !m_parent )
52 m_parent = FindSuitableParent();
53 HWND hWnd = m_parent ? GetHwndOf(m_parent) : NULL;
54
55 // translate wx style in MSW
56 unsigned int msStyle = MB_OK;
57 const long wxStyle = GetMessageDialogStyle();
58 if (wxStyle & wxYES_NO)
59 {
60 #if !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
61 if (wxStyle & wxCANCEL)
62 msStyle = MB_YESNOCANCEL;
63 else
64 #endif // !(__SMARTPHONE__ && __WXWINCE__)
65 msStyle = MB_YESNO;
66
67 if (wxStyle & wxNO_DEFAULT)
68 msStyle |= MB_DEFBUTTON2;
69 }
70
71 if (wxStyle & wxOK)
72 {
73 if (wxStyle & wxCANCEL)
74 msStyle = MB_OKCANCEL;
75 else
76 msStyle = MB_OK;
77 }
78 if (wxStyle & wxICON_EXCLAMATION)
79 msStyle |= MB_ICONEXCLAMATION;
80 else if (wxStyle & wxICON_HAND)
81 msStyle |= MB_ICONHAND;
82 else if (wxStyle & wxICON_INFORMATION)
83 msStyle |= MB_ICONINFORMATION;
84 else if (wxStyle & wxICON_QUESTION)
85 msStyle |= MB_ICONQUESTION;
86
87 if ( wxStyle & wxSTAY_ON_TOP )
88 msStyle |= MB_TOPMOST;
89
90 #ifndef __WXWINCE__
91 if ( wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft )
92 msStyle |= MB_RTLREADING | MB_RIGHT;
93 #endif
94
95 if (hWnd)
96 msStyle |= MB_APPLMODAL;
97 else
98 msStyle |= MB_TASKMODAL;
99
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)
103 wxString message = GetFullMessage();
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
113 // do show the dialog
114 int msAns = MessageBox(hWnd, message.wx_str(), m_caption.wx_str(), msStyle);
115 int ans;
116 switch (msAns)
117 {
118 default:
119 wxFAIL_MSG(_T("unexpected ::MessageBox() return code"));
120 // fall through
121
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;
136 }
137
138 #endif // wxUSE_MSGDLG