]> git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
Ensure there is valid context for DrawRectangle
[wxWidgets.git] / src / generic / msgdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/msgdlgg.cpp
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Robert Roebling
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 #ifndef WX_PRECOMP
22 #include "wx/utils.h"
23 #include "wx/dialog.h"
24 #include "wx/button.h"
25 #include "wx/stattext.h"
26 #include "wx/statbmp.h"
27 #include "wx/layout.h"
28 #include "wx/intl.h"
29 #include "wx/icon.h"
30 #include "wx/sizer.h"
31 #include "wx/app.h"
32 #include "wx/settings.h"
33 #endif
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #define __WX_COMPILING_MSGDLGG_CPP__ 1
39 #include "wx/msgdlg.h"
40 #include "wx/artprov.h"
41 #include "wx/textwrapper.h"
42 #include "wx/testing.h"
43
44 #if wxUSE_STATLINE
45 #include "wx/statline.h"
46 #endif
47
48 // ----------------------------------------------------------------------------
49 // wxTitleTextWrapper: simple class to create wrapped text in "title font"
50 // ----------------------------------------------------------------------------
51
52 class wxTitleTextWrapper : public wxTextSizerWrapper
53 {
54 public:
55 wxTitleTextWrapper(wxWindow *win)
56 : wxTextSizerWrapper(win)
57 {
58 }
59
60 protected:
61 virtual wxWindow *OnCreateLine(const wxString& s)
62 {
63 wxWindow * const win = wxTextSizerWrapper::OnCreateLine(s);
64
65 win->SetFont(win->GetFont().Larger().MakeBold());
66
67 return win;
68 }
69 };
70
71 // ----------------------------------------------------------------------------
72 // icons
73 // ----------------------------------------------------------------------------
74
75 BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
76 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
77 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
78 EVT_BUTTON(wxID_HELP, wxGenericMessageDialog::OnHelp)
79 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
80 END_EVENT_TABLE()
81
82 IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
83
84 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
85 const wxString& message,
86 const wxString& caption,
87 long style,
88 const wxPoint& pos)
89 : wxMessageDialogBase(GetParentForModalDialog(parent, style),
90 message,
91 caption,
92 style),
93 m_pos(pos)
94 {
95 m_created = false;
96 }
97
98 wxSizer *wxGenericMessageDialog::CreateMsgDlgButtonSizer()
99 {
100 #ifndef __SMARTPHONE__
101 if ( HasCustomLabels() )
102 {
103 wxStdDialogButtonSizer * const sizerStd = new wxStdDialogButtonSizer;
104
105 wxButton *btnDef = NULL;
106
107 if ( m_dialogStyle & wxOK )
108 {
109 btnDef = new wxButton(this, wxID_OK, GetCustomOKLabel());
110 sizerStd->AddButton(btnDef);
111 }
112
113 if ( m_dialogStyle & wxCANCEL )
114 {
115 wxButton * const
116 cancel = new wxButton(this, wxID_CANCEL, GetCustomCancelLabel());
117 sizerStd->AddButton(cancel);
118
119 if ( m_dialogStyle & wxCANCEL_DEFAULT )
120 btnDef = cancel;
121 }
122
123 if ( m_dialogStyle & wxYES_NO )
124 {
125 wxButton * const
126 yes = new wxButton(this, wxID_YES, GetCustomYesLabel());
127 sizerStd->AddButton(yes);
128
129 wxButton * const
130 no = new wxButton(this, wxID_NO, GetCustomNoLabel());
131 sizerStd->AddButton(no);
132 if ( m_dialogStyle & wxNO_DEFAULT )
133 btnDef = no;
134 else if ( !btnDef )
135 btnDef = yes;
136 }
137
138 if ( m_dialogStyle & wxHELP )
139 {
140 wxButton * const
141 help = new wxButton(this, wxID_HELP, GetCustomHelpLabel());
142 sizerStd->AddButton(help);
143 }
144
145 if ( btnDef )
146 {
147 btnDef->SetDefault();
148 btnDef->SetFocus();
149 }
150
151 sizerStd->Realize();
152
153 return CreateSeparatedSizer(sizerStd);
154 }
155 #endif // !__SMARTPHONE__
156
157 // Use standard labels for all buttons
158 return CreateSeparatedButtonSizer
159 (
160 m_dialogStyle & (wxOK | wxCANCEL | wxHELP | wxYES_NO |
161 wxNO_DEFAULT | wxCANCEL_DEFAULT)
162 );
163 }
164
165 void wxGenericMessageDialog::DoCreateMsgdialog()
166 {
167 wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
168
169 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
170
171 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
172
173 #if wxUSE_STATBMP
174 // 1) icon
175 if (m_dialogStyle & wxICON_MASK)
176 {
177 wxStaticBitmap *icon = new wxStaticBitmap
178 (
179 this,
180 wxID_ANY,
181 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
182 );
183 if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA )
184 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
185 else
186 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
187 }
188 #endif // wxUSE_STATBMP
189
190 #if wxUSE_STATTEXT
191 // 2) text
192
193 wxBoxSizer * const textsizer = new wxBoxSizer(wxVERTICAL);
194
195 // We want to show the main message in a different font to make it stand
196 // out if the extended message is used as well. This looks better and is
197 // more consistent with the native dialogs under MSW and GTK.
198 wxString lowerMessage;
199 if ( !m_extendedMessage.empty() )
200 {
201 wxTitleTextWrapper titleWrapper(this);
202 textsizer->Add(CreateTextSizer(GetMessage(), titleWrapper),
203 wxSizerFlags().Border(wxBOTTOM, 20));
204
205 lowerMessage = GetExtendedMessage();
206 }
207 else // no extended message
208 {
209 lowerMessage = GetMessage();
210 }
211
212 textsizer->Add(CreateTextSizer(lowerMessage));
213
214 icon_text->Add(textsizer, 0, wxALIGN_CENTER, 10);
215 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
216 #endif // wxUSE_STATTEXT
217
218 // 3) optional checkbox and detailed text
219 AddMessageDialogCheckBox( topsizer );
220 AddMessageDialogDetails( topsizer );
221
222 // 4) buttons
223 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
224 if ( sizerBtn )
225 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
226
227 SetAutoLayout( true );
228 SetSizer( topsizer );
229
230 topsizer->SetSizeHints( this );
231 topsizer->Fit( this );
232 wxSize size( GetSize() );
233 if (size.x < size.y*3/2)
234 {
235 size.x = size.y*3/2;
236 SetSize( size );
237 }
238
239 Centre( wxBOTH | wxCENTER_FRAME);
240 }
241
242 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
243 {
244 EndModal( wxID_YES );
245 }
246
247 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
248 {
249 EndModal( wxID_NO );
250 }
251
252 void wxGenericMessageDialog::OnHelp(wxCommandEvent& WXUNUSED(event))
253 {
254 EndModal( wxID_HELP );
255 }
256
257 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
258 {
259 // Allow cancellation via ESC/Close button except if
260 // only YES and NO are specified.
261 const long style = GetMessageDialogStyle();
262 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
263 {
264 EndModal( wxID_CANCEL );
265 }
266 }
267
268 int wxGenericMessageDialog::ShowModal()
269 {
270 WX_TESTING_SHOW_MODAL_HOOK();
271
272 if ( !m_created )
273 {
274 m_created = true;
275 DoCreateMsgdialog();
276 }
277
278 return wxMessageDialogBase::ShowModal();
279 }
280
281 #endif // wxUSE_MSGDLG