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