]> git.saurik.com Git - wxWidgets.git/blame - src/generic/msgdlgg.cpp
Fix compiler warnings in the IE backend.
[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"
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)
77 EVT_BUTTON(wxID_CANCEL, wxGenericMessageDialog::OnCancel)
c801d85f
KB
78END_EVENT_TABLE()
79
80IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog)
c801d85f 81
917b3d40
VZ
82wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
83 const wxString& message,
84 const wxString& caption,
85 long style,
86 const wxPoint& pos)
cdc48273 87 : wxMessageDialogBase(GetParentForModalDialog(parent, style),
2afb9e16
VZ
88 message,
89 caption,
90 style),
91 m_pos(pos)
c801d85f 92{
2afb9e16
VZ
93 m_created = false;
94}
c801d85f 95
d20ba5f8
VZ
96wxSizer *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
2afb9e16
VZ
156void wxGenericMessageDialog::DoCreateMsgdialog()
157{
158 wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE);
2229243b 159
2b5f62a0
VZ
160 bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
161
92afa2b1 162 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
c801d85f 163
92afa2b1 164 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
479cd5de 165
9a6384ca 166#if wxUSE_STATBMP
92afa2b1 167 // 1) icon
2afb9e16 168 if (m_dialogStyle & wxICON_MASK)
dfc54541 169 {
1970409e
VZ
170 wxStaticBitmap *icon = new wxStaticBitmap
171 (
172 this,
173 wxID_ANY,
174 wxArtProvider::GetMessageBoxIcon(m_dialogStyle)
175 );
2b5f62a0
VZ
176 if (is_pda)
177 topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 );
178 else
8d5016b1 179 icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20));
dfc54541 180 }
9a6384ca 181#endif // wxUSE_STATBMP
479cd5de 182
9a6384ca 183#if wxUSE_STATTEXT
92afa2b1 184 // 2) text
479cd5de 185
c79510ca
VZ
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);
bb612373 208 topsizer->Add( icon_text, 1, wxLEFT|wxRIGHT|wxTOP, 10 );
9a6384ca 209#endif // wxUSE_STATTEXT
479cd5de 210
ede7b017
VZ
211 // 3) optional checkbox and detailed text
212 AddMessageDialogCheckBox( topsizer );
213 AddMessageDialogDetails( topsizer );
214
215 // 4) buttons
d20ba5f8 216 wxSizer *sizerBtn = CreateMsgDlgButtonSizer();
bd9f3519 217 if ( sizerBtn )
bb612373 218 topsizer->Add(sizerBtn, 0, wxEXPAND | wxALL, 10 );
917b3d40 219
ca65c044 220 SetAutoLayout( true );
8b17ba72 221 SetSizer( topsizer );
479cd5de 222
92afa2b1
RR
223 topsizer->SetSizeHints( this );
224 topsizer->Fit( this );
8b17ba72 225 wxSize size( GetSize() );
e6daf794 226 if (size.x < size.y*3/2)
8b17ba72 227 {
e6daf794 228 size.x = size.y*3/2;
f1df0927 229 SetSize( size );
8b17ba72 230 }
917b3d40 231
92afa2b1 232 Centre( wxBOTH | wxCENTER_FRAME);
c801d85f
KB
233}
234
235void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event))
236{
15b24b14 237 EndModal( wxID_YES );
c801d85f
KB
238}
239
240void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event))
241{
15b24b14 242 EndModal( wxID_NO );
c801d85f
KB
243}
244
245void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event))
246{
2b5f62a0
VZ
247 // Allow cancellation via ESC/Close button except if
248 // only YES and NO are specified.
e5b50758
WS
249 const long style = GetMessageDialogStyle();
250 if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) )
15b24b14
RR
251 {
252 EndModal( wxID_CANCEL );
253 }
c801d85f
KB
254}
255
2afb9e16
VZ
256int wxGenericMessageDialog::ShowModal()
257{
258 if ( !m_created )
259 {
260 m_created = true;
261 DoCreateMsgdialog();
262 }
263
264 return wxMessageDialogBase::ShowModal();
265}
266
ede7b017 267#endif // wxUSE_MSGDLG