]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/generic/msgdlgg.cpp
Rename wxWebNavigationError to wxWebViewNavigationError and wxWebNavigationEvent...
[wxWidgets.git] / src / generic / msgdlgg.cpp
... / ...
CommitLineData
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
43#if wxUSE_STATLINE
44 #include "wx/statline.h"
45#endif
46
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
70// ----------------------------------------------------------------------------
71// icons
72// ----------------------------------------------------------------------------
73
74BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
75 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
76 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
77 EVT_BUTTON(wxID_HELP, wxGenericMessageDialog::OnHelp)
78 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
79END_EVENT_TABLE()
80
81IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
82
83wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
84 const wxString& message,
85 const wxString& caption,
86 long style,
87 const wxPoint& pos)
88 : wxMessageDialogBase(GetParentForModalDialog(parent, style),
89 message,
90 caption,
91 style),
92 m_pos(pos)
93{
94 m_created = false;
95}
96
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
137 if ( m_dialogStyle & wxHELP )
138 {
139 wxButton * const
140 help = new wxButton(this, wxID_HELP, GetCustomHelpLabel());
141 sizerStd->AddButton(help);
142 }
143
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 (
159 m_dialogStyle & (wxOK | wxCANCEL | wxHELP | wxYES_NO |
160 wxNO_DEFAULT | wxCANCEL_DEFAULT)
161 );
162}
163
164void wxGenericMessageDialog::DoCreateMsgdialog()
165{
166 wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
167
168 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
169
170 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
171
172 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
173
174#if wxUSE_STATBMP
175 // 1) icon
176 if (m_dialogStyle & wxICON_MASK)
177 {
178 wxStaticBitmap *icon = new wxStaticBitmap
179 (
180 this,
181 wxID_ANY,
182 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
183 );
184 if (is_pda)
185 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
186 else
187 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
188 }
189#endif // wxUSE_STATBMP
190
191#if wxUSE_STATTEXT
192 // 2) text
193
194 wxBoxSizer * const textsizer = new wxBoxSizer(wxVERTICAL);
195
196 // We want to show the main message in a different font to make it stand
197 // out if the extended message is used as well. This looks better and is
198 // more consistent with the native dialogs under MSW and GTK.
199 wxString lowerMessage;
200 if ( !m_extendedMessage.empty() )
201 {
202 wxTitleTextWrapper titleWrapper(this);
203 textsizer->Add(CreateTextSizer(GetMessage(), titleWrapper),
204 wxSizerFlags().Border(wxBOTTOM, 20));
205
206 lowerMessage = GetExtendedMessage();
207 }
208 else // no extended message
209 {
210 lowerMessage = GetMessage();
211 }
212
213 textsizer->Add(CreateTextSizer(lowerMessage));
214
215 icon_text->Add(textsizer, 0, wxALIGN_CENTER, 10);
216 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
217#endif // wxUSE_STATTEXT
218
219 // 3) optional checkbox and detailed text
220 AddMessageDialogCheckBox( topsizer );
221 AddMessageDialogDetails( topsizer );
222
223 // 4) buttons
224 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
225 if ( sizerBtn )
226 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
227
228 SetAutoLayout( true );
229 SetSizer( topsizer );
230
231 topsizer->SetSizeHints( this );
232 topsizer->Fit( this );
233 wxSize size( GetSize() );
234 if (size.x < size.y*3/2)
235 {
236 size.x = size.y*3/2;
237 SetSize( size );
238 }
239
240 Centre( wxBOTH | wxCENTER_FRAME);
241}
242
243void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
244{
245 EndModal( wxID_YES );
246}
247
248void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
249{
250 EndModal( wxID_NO );
251}
252
253void wxGenericMessageDialog::OnHelp(wxCommandEvent& WXUNUSED(event))
254{
255 EndModal( wxID_HELP );
256}
257
258void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
259{
260 // Allow cancellation via ESC/Close button except if
261 // only YES and NO are specified.
262 const long style = GetMessageDialogStyle();
263 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
264 {
265 EndModal( wxID_CANCEL );
266 }
267}
268
269int wxGenericMessageDialog::ShowModal()
270{
271 if ( !m_created )
272 {
273 m_created = true;
274 DoCreateMsgdialog();
275 }
276
277 return wxMessageDialogBase::ShowModal();
278}
279
280#endif // wxUSE_MSGDLG