]> git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
Handle Shift-TAB correctly in wxOSX/Carbon wxComboBox.
[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 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
170
171 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
172
173 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
174
175 #if wxUSE_STATBMP
176 // 1) icon
177 if (m_dialogStyle & wxICON_MASK)
178 {
179 wxStaticBitmap *icon = new wxStaticBitmap
180 (
181 this,
182 wxID_ANY,
183 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
184 );
185 if (is_pda)
186 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
187 else
188 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
189 }
190 #endif // wxUSE_STATBMP
191
192 #if wxUSE_STATTEXT
193 // 2) text
194
195 wxBoxSizer * const textsizer = new wxBoxSizer(wxVERTICAL);
196
197 // We want to show the main message in a different font to make it stand
198 // out if the extended message is used as well. This looks better and is
199 // more consistent with the native dialogs under MSW and GTK.
200 wxString lowerMessage;
201 if ( !m_extendedMessage.empty() )
202 {
203 wxTitleTextWrapper titleWrapper(this);
204 textsizer->Add(CreateTextSizer(GetMessage(), titleWrapper),
205 wxSizerFlags().Border(wxBOTTOM, 20));
206
207 lowerMessage = GetExtendedMessage();
208 }
209 else // no extended message
210 {
211 lowerMessage = GetMessage();
212 }
213
214 textsizer->Add(CreateTextSizer(lowerMessage));
215
216 icon_text->Add(textsizer, 0, wxALIGN_CENTER, 10);
217 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
218 #endif // wxUSE_STATTEXT
219
220 // 3) optional checkbox and detailed text
221 AddMessageDialogCheckBox( topsizer );
222 AddMessageDialogDetails( topsizer );
223
224 // 4) buttons
225 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
226 if ( sizerBtn )
227 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
228
229 SetAutoLayout( true );
230 SetSizer( topsizer );
231
232 topsizer->SetSizeHints( this );
233 topsizer->Fit( this );
234 wxSize size( GetSize() );
235 if (size.x < size.y*3/2)
236 {
237 size.x = size.y*3/2;
238 SetSize( size );
239 }
240
241 Centre( wxBOTH | wxCENTER_FRAME);
242 }
243
244 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
245 {
246 EndModal( wxID_YES );
247 }
248
249 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
250 {
251 EndModal( wxID_NO );
252 }
253
254 void wxGenericMessageDialog::OnHelp(wxCommandEvent& WXUNUSED(event))
255 {
256 EndModal( wxID_HELP );
257 }
258
259 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
260 {
261 // Allow cancellation via ESC/Close button except if
262 // only YES and NO are specified.
263 const long style = GetMessageDialogStyle();
264 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
265 {
266 EndModal( wxID_CANCEL );
267 }
268 }
269
270 int wxGenericMessageDialog::ShowModal()
271 {
272 WX_TESTING_SHOW_MODAL_HOOK();
273
274 if ( !m_created )
275 {
276 m_created = true;
277 DoCreateMsgdialog();
278 }
279
280 return wxMessageDialogBase::ShowModal();
281 }
282
283 #endif // wxUSE_MSGDLG