1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/msgdlgg.cpp
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
8 // Copyright: (c) Julian Smart and Robert Roebling
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.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"
32 #include "wx/settings.h"
38 #define __WX_COMPILING_MSGDLGG_CPP__ 1
39 #include "wx/msgdlg.h"
40 #include "wx/artprov.h"
41 #include "wx/textwrapper.h"
42 #include "wx/testing.h"
45 #include "wx/statline.h"
48 // ----------------------------------------------------------------------------
49 // wxTitleTextWrapper: simple class to create wrapped text in "title font"
50 // ----------------------------------------------------------------------------
52 class wxTitleTextWrapper
: public wxTextSizerWrapper
55 wxTitleTextWrapper(wxWindow
*win
)
56 : wxTextSizerWrapper(win
)
61 virtual wxWindow
*OnCreateLine(const wxString
& s
)
63 wxWindow
* const win
= wxTextSizerWrapper::OnCreateLine(s
);
65 win
->SetFont(win
->GetFont().Larger().MakeBold());
71 // ----------------------------------------------------------------------------
73 // ----------------------------------------------------------------------------
75 BEGIN_EVENT_TABLE(wxGenericMessageDialog
, wxDialog
)
76 EVT_BUTTON(wxID_YES
, wxGenericMessageDialog::OnYes
)
77 EVT_BUTTON(wxID_NO
, wxGenericMessageDialog::OnNo
)
78 EVT_BUTTON(wxID_HELP
, wxGenericMessageDialog::OnHelp
)
79 EVT_BUTTON(wxID_CANCEL
, wxGenericMessageDialog::OnCancel
)
82 IMPLEMENT_CLASS(wxGenericMessageDialog
, wxDialog
)
84 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow
*parent
,
85 const wxString
& message
,
86 const wxString
& caption
,
89 : wxMessageDialogBase(GetParentForModalDialog(parent
, style
),
98 wxSizer
*wxGenericMessageDialog::CreateMsgDlgButtonSizer()
100 #ifndef __SMARTPHONE__
101 if ( HasCustomLabels() )
103 wxStdDialogButtonSizer
* const sizerStd
= new wxStdDialogButtonSizer
;
105 wxButton
*btnDef
= NULL
;
107 if ( m_dialogStyle
& wxOK
)
109 btnDef
= new wxButton(this, wxID_OK
, GetCustomOKLabel());
110 sizerStd
->AddButton(btnDef
);
113 if ( m_dialogStyle
& wxCANCEL
)
116 cancel
= new wxButton(this, wxID_CANCEL
, GetCustomCancelLabel());
117 sizerStd
->AddButton(cancel
);
119 if ( m_dialogStyle
& wxCANCEL_DEFAULT
)
123 if ( m_dialogStyle
& wxYES_NO
)
126 yes
= new wxButton(this, wxID_YES
, GetCustomYesLabel());
127 sizerStd
->AddButton(yes
);
130 no
= new wxButton(this, wxID_NO
, GetCustomNoLabel());
131 sizerStd
->AddButton(no
);
132 if ( m_dialogStyle
& wxNO_DEFAULT
)
138 if ( m_dialogStyle
& wxHELP
)
141 help
= new wxButton(this, wxID_HELP
, GetCustomHelpLabel());
142 sizerStd
->AddButton(help
);
147 btnDef
->SetDefault();
153 return CreateSeparatedSizer(sizerStd
);
155 #endif // !__SMARTPHONE__
157 // Use standard labels for all buttons
158 return CreateSeparatedButtonSizer
160 m_dialogStyle
& (wxOK
| wxCANCEL
| wxHELP
| wxYES_NO
|
161 wxNO_DEFAULT
| wxCANCEL_DEFAULT
)
165 void wxGenericMessageDialog::DoCreateMsgdialog()
167 wxDialog::Create(m_parent
, wxID_ANY
, m_caption
, m_pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
169 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
171 wxBoxSizer
*icon_text
= new wxBoxSizer( wxHORIZONTAL
);
175 if (m_dialogStyle
& wxICON_MASK
)
177 wxStaticBitmap
*icon
= new wxStaticBitmap
181 wxArtProvider::GetMessageBoxIcon(m_dialogStyle
)
183 if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
)
184 topsizer
->Add( icon
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxALIGN_LEFT
, 10 );
186 icon_text
->Add(icon
, wxSizerFlags().Top().Border(wxRIGHT
, 20));
188 #endif // wxUSE_STATBMP
193 wxBoxSizer
* const textsizer
= new wxBoxSizer(wxVERTICAL
);
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() )
201 wxTitleTextWrapper
titleWrapper(this);
202 textsizer
->Add(CreateTextSizer(GetMessage(), titleWrapper
),
203 wxSizerFlags().Border(wxBOTTOM
, 20));
205 lowerMessage
= GetExtendedMessage();
207 else // no extended message
209 lowerMessage
= GetMessage();
212 textsizer
->Add(CreateTextSizer(lowerMessage
));
214 icon_text
->Add(textsizer
, 0, wxALIGN_CENTER
, 10);
215 topsizer
->Add( icon_text
, 1, wxLEFT
|wxRIGHT
|wxTOP
, 10 );
216 #endif // wxUSE_STATTEXT
218 // 3) optional checkbox and detailed text
219 AddMessageDialogCheckBox( topsizer
);
220 AddMessageDialogDetails( topsizer
);
223 wxSizer
*sizerBtn
= CreateMsgDlgButtonSizer();
225 topsizer
->Add(sizerBtn
, 0, wxEXPAND
| wxALL
, 10 );
227 SetAutoLayout( true );
228 SetSizer( topsizer
);
230 topsizer
->SetSizeHints( this );
231 topsizer
->Fit( this );
232 wxSize
size( GetSize() );
233 if (size
.x
< size
.y
*3/2)
239 Centre( wxBOTH
| wxCENTER_FRAME
);
242 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
))
244 EndModal( wxID_YES
);
247 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
))
252 void wxGenericMessageDialog::OnHelp(wxCommandEvent
& WXUNUSED(event
))
254 EndModal( wxID_HELP
);
257 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
259 // Allow cancellation via ESC/Close button except if
260 // only YES and NO are specified.
261 const long style
= GetMessageDialogStyle();
262 if ( (style
& wxYES_NO
) != wxYES_NO
|| (style
& wxCANCEL
) )
264 EndModal( wxID_CANCEL
);
268 int wxGenericMessageDialog::ShowModal()
270 WX_TESTING_SHOW_MODAL_HOOK();
278 return wxMessageDialogBase::ShowModal();
281 #endif // wxUSE_MSGDLG