]> git.saurik.com Git - wxWidgets.git/blob - src/generic/msgdlgg.cpp
Fix compiler warnings in the IE backend.
[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
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
51 class wxTitleTextWrapper : public wxTextSizerWrapper
52 {
53 public:
54 wxTitleTextWrapper(wxWindow *win)
55 : wxTextSizerWrapper(win)
56 {
57 }
58
59 protected:
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
74 BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog)
75 EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes)
76 EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo)
77 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
78 END_EVENT_TABLE()
79
80 IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
81
82 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
83 const wxString& message,
84 const wxString& caption,
85 long style,
86 const wxPoint& pos)
87 : wxMessageDialogBase(GetParentForModalDialog(parent, style),
88 message,
89 caption,
90 style),
91 m_pos(pos)
92 {
93 m_created = false;
94 }
95
96 wxSizer *wxGenericMessageDialog::CreateMsgDlgButtonSizer()
97 {
98 #ifndef __SMARTPHONE__
99 if ( HasCustomLabels() )
100 {
101 wxStdDialogButtonSizer * const sizerStd = new wxStdDialogButtonSizer;
102
103 wxButton *btnDef = NULL;
104
105 if ( m_dialogStyle & wxOK )
106 {
107 btnDef = new wxButton(this, wxID_OK, GetCustomOKLabel());
108 sizerStd->AddButton(btnDef);
109 }
110
111 if ( m_dialogStyle & wxCANCEL )
112 {
113 wxButton * const
114 cancel = new wxButton(this, wxID_CANCEL, GetCustomCancelLabel());
115 sizerStd->AddButton(cancel);
116
117 if ( m_dialogStyle & wxCANCEL_DEFAULT )
118 btnDef = cancel;
119 }
120
121 if ( m_dialogStyle & wxYES_NO )
122 {
123 wxButton * const
124 yes = new wxButton(this, wxID_YES, GetCustomYesLabel());
125 sizerStd->AddButton(yes);
126
127 wxButton * const
128 no = new wxButton(this, wxID_NO, GetCustomNoLabel());
129 sizerStd->AddButton(no);
130 if ( m_dialogStyle & wxNO_DEFAULT )
131 btnDef = no;
132 else if ( !btnDef )
133 btnDef = yes;
134 }
135
136 if ( btnDef )
137 {
138 btnDef->SetDefault();
139 btnDef->SetFocus();
140 }
141
142 sizerStd->Realize();
143
144 return CreateSeparatedSizer(sizerStd);
145 }
146 #endif // !__SMARTPHONE__
147
148 // Use standard labels for all buttons
149 return CreateSeparatedButtonSizer
150 (
151 m_dialogStyle & (wxOK | wxCANCEL | wxYES_NO |
152 wxNO_DEFAULT | wxCANCEL_DEFAULT)
153 );
154 }
155
156 void wxGenericMessageDialog::DoCreateMsgdialog()
157 {
158 wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
159
160 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
161
162 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
163
164 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
165
166 #if wxUSE_STATBMP
167 // 1) icon
168 if (m_dialogStyle & wxICON_MASK)
169 {
170 wxStaticBitmap *icon = new wxStaticBitmap
171 (
172 this,
173 wxID_ANY,
174 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
175 );
176 if (is_pda)
177 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
178 else
179 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
180 }
181 #endif // wxUSE_STATBMP
182
183 #if wxUSE_STATTEXT
184 // 2) text
185
186 wxBoxSizer * const textsizer = new wxBoxSizer(wxVERTICAL);
187
188 // We want to show the main message in a different font to make it stand
189 // out if the extended message is used as well. This looks better and is
190 // more consistent with the native dialogs under MSW and GTK.
191 wxString lowerMessage;
192 if ( !m_extendedMessage.empty() )
193 {
194 wxTitleTextWrapper titleWrapper(this);
195 textsizer->Add(CreateTextSizer(GetMessage(), titleWrapper),
196 wxSizerFlags().Border(wxBOTTOM, 20));
197
198 lowerMessage = GetExtendedMessage();
199 }
200 else // no extended message
201 {
202 lowerMessage = GetMessage();
203 }
204
205 textsizer->Add(CreateTextSizer(lowerMessage));
206
207 icon_text->Add(textsizer, 0, wxALIGN_CENTER, 10);
208 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
209 #endif // wxUSE_STATTEXT
210
211 // 3) optional checkbox and detailed text
212 AddMessageDialogCheckBox( topsizer );
213 AddMessageDialogDetails( topsizer );
214
215 // 4) buttons
216 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
217 if ( sizerBtn )
218 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
219
220 SetAutoLayout( true );
221 SetSizer( topsizer );
222
223 topsizer->SetSizeHints( this );
224 topsizer->Fit( this );
225 wxSize size( GetSize() );
226 if (size.x < size.y*3/2)
227 {
228 size.x = size.y*3/2;
229 SetSize( size );
230 }
231
232 Centre( wxBOTH | wxCENTER_FRAME);
233 }
234
235 void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
236 {
237 EndModal( wxID_YES );
238 }
239
240 void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
241 {
242 EndModal( wxID_NO );
243 }
244
245 void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
246 {
247 // Allow cancellation via ESC/Close button except if
248 // only YES and NO are specified.
249 const long style = GetMessageDialogStyle();
250 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
251 {
252 EndModal( wxID_CANCEL );
253 }
254 }
255
256 int wxGenericMessageDialog::ShowModal()
257 {
258 if ( !m_created )
259 {
260 m_created = true;
261 DoCreateMsgdialog();
262 }
263
264 return wxMessageDialogBase::ShowModal();
265 }
266
267 #endif // wxUSE_MSGDLG