]> git.saurik.com Git - wxWidgets.git/blame - src/generic/msgdlgg.cpp
Handle Shift-TAB correctly in wxOSX/Carbon wxComboBox.
[wxWidgets.git] / src / generic / msgdlgg.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/generic/msgdlgg.cpp
c801d85f 3// Purpose: wxGenericMessageDialog
15b24b14 4// Author: Julian Smart, Robert Roebling
c801d85f
KB
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart and Robert Roebling
65571936 9// Licence: wxWindows licence
c801d85f
KB
10/////////////////////////////////////////////////////////////////////////////
11
c801d85f
KB
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
ede7b017 19#if wxUSE_MSGDLG
1e6feb95 20
c801d85f 21#ifndef WX_PRECOMP
c50f1fb9
VZ
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"
dfe1eee3 29 #include "wx/icon.h"
92afa2b1
RR
30 #include "wx/sizer.h"
31 #include "wx/app.h"
9eddec69 32 #include "wx/settings.h"
c801d85f
KB
33#endif
34
35#include <stdio.h>
36#include <string.h>
37
a685a06c
DE
38#define __WX_COMPILING_MSGDLGG_CPP__ 1
39#include "wx/msgdlg.h"
389d906b 40#include "wx/artprov.h"
c79510ca 41#include "wx/textwrapper.h"
643e9cf9 42#include "wx/testing.h"
c801d85f 43
dcf924a3 44#if wxUSE_STATLINE
9eddec69 45 #include "wx/statline.h"
b0351fc9
RR
46#endif
47
c79510ca
VZ
48// ----------------------------------------------------------------------------
49// wxTitleTextWrapper: simple class to create wrapped text in "title font"
50// ----------------------------------------------------------------------------
51
52class wxTitleTextWrapper : public wxTextSizerWrapper
53{
54public:
55 wxTitleTextWrapper(wxWindow *win)
56 : wxTextSizerWrapper(win)
57 {
58 }
59
60protected:
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
917b3d40
VZ
71// ----------------------------------------------------------------------------
72// icons
73// ----------------------------------------------------------------------------
74
c801d85f 75BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
f03fc89f
VZ
76 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
77 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
7112cdd1 78 EVT_BUTTON(wxID_HELP, wxGenericMessageDialog::OnHelp)
f03fc89f 79 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
c801d85f
KB
80END_EVENT_TABLE()
81
82IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
c801d85f 83
917b3d40
VZ
84wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
85 const wxString& message,
86 const wxString& caption,
87 long style,
88 const wxPoint& pos)
cdc48273 89 : wxMessageDialogBase(GetParentForModalDialog(parent, style),
2afb9e16
VZ
90 message,
91 caption,
92 style),
93 m_pos(pos)
c801d85f 94{
2afb9e16
VZ
95 m_created = false;
96}
c801d85f 97
d20ba5f8
VZ
98wxSizer *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
7112cdd1
VZ
138 if ( m_dialogStyle & wxHELP )
139 {
140 wxButton * const
141 help = new wxButton(this, wxID_HELP, GetCustomHelpLabel());
142 sizerStd->AddButton(help);
143 }
144
d20ba5f8
VZ
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 (
7112cdd1 160 m_dialogStyle & (wxOK | wxCANCEL | wxHELP | wxYES_NO |
d20ba5f8
VZ
161 wxNO_DEFAULT | wxCANCEL_DEFAULT)
162 );
163}
164
2afb9e16
VZ
165void wxGenericMessageDialog::DoCreateMsgdialog()
166{
167 wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
2229243b 168
2b5f62a0
VZ
169 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
170
92afa2b1 171 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
c801d85f 172
92afa2b1 173 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
479cd5de 174
9a6384ca 175#if wxUSE_STATBMP
92afa2b1 176 // 1) icon
2afb9e16 177 if (m_dialogStyle & wxICON_MASK)
dfc54541 178 {
1970409e
VZ
179 wxStaticBitmap *icon = new wxStaticBitmap
180 (
181 this,
182 wxID_ANY,
183 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
184 );
2b5f62a0
VZ
185 if (is_pda)
186 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
187 else
8d5016b1 188 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
dfc54541 189 }
9a6384ca 190#endif // wxUSE_STATBMP
479cd5de 191
9a6384ca 192#if wxUSE_STATTEXT
92afa2b1 193 // 2) text
479cd5de 194
c79510ca
VZ
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);
bb612373 217 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
9a6384ca 218#endif // wxUSE_STATTEXT
479cd5de 219
ede7b017
VZ
220 // 3) optional checkbox and detailed text
221 AddMessageDialogCheckBox( topsizer );
222 AddMessageDialogDetails( topsizer );
223
224 // 4) buttons
d20ba5f8 225 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
bd9f3519 226 if ( sizerBtn )
bb612373 227 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
917b3d40 228
ca65c044 229 SetAutoLayout( true );
8b17ba72 230 SetSizer( topsizer );
479cd5de 231
92afa2b1
RR
232 topsizer->SetSizeHints( this );
233 topsizer->Fit( this );
8b17ba72 234 wxSize size( GetSize() );
e6daf794 235 if (size.x < size.y*3/2)
8b17ba72 236 {
e6daf794 237 size.x = size.y*3/2;
f1df0927 238 SetSize( size );
8b17ba72 239 }
917b3d40 240
92afa2b1 241 Centre( wxBOTH | wxCENTER_FRAME);
c801d85f
KB
242}
243
244void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
245{
15b24b14 246 EndModal( wxID_YES );
c801d85f
KB
247}
248
249void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
250{
15b24b14 251 EndModal( wxID_NO );
c801d85f
KB
252}
253
7112cdd1
VZ
254void wxGenericMessageDialog::OnHelp(wxCommandEvent& WXUNUSED(event))
255{
256 EndModal( wxID_HELP );
257}
258
c801d85f
KB
259void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
260{
2b5f62a0
VZ
261 // Allow cancellation via ESC/Close button except if
262 // only YES and NO are specified.
e5b50758
WS
263 const long style = GetMessageDialogStyle();
264 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
15b24b14
RR
265 {
266 EndModal( wxID_CANCEL );
267 }
c801d85f
KB
268}
269
2afb9e16
VZ
270int wxGenericMessageDialog::ShowModal()
271{
643e9cf9
VS
272 WX_TESTING_SHOW_MODAL_HOOK();
273
2afb9e16
VZ
274 if ( !m_created )
275 {
276 m_created = true;
277 DoCreateMsgdialog();
278 }
279
280 return wxMessageDialogBase::ShowModal();
281}
282
ede7b017 283#endif // wxUSE_MSGDLG