]> git.saurik.com Git - wxWidgets.git/blame - src/generic/msgdlgg.cpp
Added ability to switch off more components of the size page UI
[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
92afa2b1 169 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
c801d85f 170
92afa2b1 171 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
479cd5de 172
9a6384ca 173#if wxUSE_STATBMP
92afa2b1 174 // 1) icon
2afb9e16 175 if (m_dialogStyle & wxICON_MASK)
dfc54541 176 {
1970409e
VZ
177 wxStaticBitmap *icon = new wxStaticBitmap
178 (
179 this,
180 wxID_ANY,
181 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
182 );
ef68861e 183 if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA )
2b5f62a0
VZ
184 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
185 else
8d5016b1 186 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
dfc54541 187 }
9a6384ca 188#endif // wxUSE_STATBMP
479cd5de 189
9a6384ca 190#if wxUSE_STATTEXT
92afa2b1 191 // 2) text
479cd5de 192
c79510ca
VZ
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);
bb612373 215 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
9a6384ca 216#endif // wxUSE_STATTEXT
479cd5de 217
ede7b017
VZ
218 // 3) optional checkbox and detailed text
219 AddMessageDialogCheckBox( topsizer );
220 AddMessageDialogDetails( topsizer );
221
222 // 4) buttons
d20ba5f8 223 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
bd9f3519 224 if ( sizerBtn )
bb612373 225 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
917b3d40 226
ca65c044 227 SetAutoLayout( true );
8b17ba72 228 SetSizer( topsizer );
479cd5de 229
92afa2b1
RR
230 topsizer->SetSizeHints( this );
231 topsizer->Fit( this );
8b17ba72 232 wxSize size( GetSize() );
e6daf794 233 if (size.x < size.y*3/2)
8b17ba72 234 {
e6daf794 235 size.x = size.y*3/2;
f1df0927 236 SetSize( size );
8b17ba72 237 }
917b3d40 238
92afa2b1 239 Centre( wxBOTH | wxCENTER_FRAME);
c801d85f
KB
240}
241
242void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
243{
15b24b14 244 EndModal( wxID_YES );
c801d85f
KB
245}
246
247void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
248{
15b24b14 249 EndModal( wxID_NO );
c801d85f
KB
250}
251
7112cdd1
VZ
252void wxGenericMessageDialog::OnHelp(wxCommandEvent& WXUNUSED(event))
253{
254 EndModal( wxID_HELP );
255}
256
c801d85f
KB
257void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
258{
2b5f62a0
VZ
259 // Allow cancellation via ESC/Close button except if
260 // only YES and NO are specified.
e5b50758
WS
261 const long style = GetMessageDialogStyle();
262 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
15b24b14
RR
263 {
264 EndModal( wxID_CANCEL );
265 }
c801d85f
KB
266}
267
2afb9e16
VZ
268int wxGenericMessageDialog::ShowModal()
269{
643e9cf9
VS
270 WX_TESTING_SHOW_MODAL_HOOK();
271
2afb9e16
VZ
272 if ( !m_created )
273 {
274 m_created = true;
275 DoCreateMsgdialog();
276 }
277
278 return wxMessageDialogBase::ShowModal();
279}
280
ede7b017 281#endif // wxUSE_MSGDLG