1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/generic/msgdlgg.cpp
3 // Purpose: wxGenericMessageDialog
4 // Author: Julian Smart, Robert Roebling
7 // Copyright: (c) Julian Smart and Robert Roebling
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.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"
31 #include "wx/settings.h"
37 #define __WX_COMPILING_MSGDLGG_CPP__ 1
38 #include "wx/msgdlg.h"
39 #include "wx/artprov.h"
40 #include "wx/textwrapper.h"
41 #include "wx/modalhook.h"
44 #include "wx/statline.h"
47 // ----------------------------------------------------------------------------
48 // wxTitleTextWrapper: simple class to create wrapped text in "title font"
49 // ----------------------------------------------------------------------------
51 class wxTitleTextWrapper
: public wxTextSizerWrapper
54 wxTitleTextWrapper(wxWindow
*win
)
55 : wxTextSizerWrapper(win
)
60 virtual wxWindow
*OnCreateLine(const wxString
& s
)
62 wxWindow
* const win
= wxTextSizerWrapper::OnCreateLine(s
);
64 win
->SetFont(win
->GetFont().Larger().MakeBold());
70 // ----------------------------------------------------------------------------
72 // ----------------------------------------------------------------------------
74 BEGIN_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
)
81 IMPLEMENT_CLASS(wxGenericMessageDialog
, wxDialog
)
83 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow
*parent
,
84 const wxString
& message
,
85 const wxString
& caption
,
88 : wxMessageDialogBase(GetParentForModalDialog(parent
, style
),
97 wxSizer
*wxGenericMessageDialog::CreateMsgDlgButtonSizer()
99 #ifndef __SMARTPHONE__
100 if ( HasCustomLabels() )
102 wxStdDialogButtonSizer
* const sizerStd
= new wxStdDialogButtonSizer
;
104 wxButton
*btnDef
= NULL
;
106 if ( m_dialogStyle
& wxOK
)
108 btnDef
= new wxButton(this, wxID_OK
, GetCustomOKLabel());
109 sizerStd
->AddButton(btnDef
);
112 if ( m_dialogStyle
& wxCANCEL
)
115 cancel
= new wxButton(this, wxID_CANCEL
, GetCustomCancelLabel());
116 sizerStd
->AddButton(cancel
);
118 if ( m_dialogStyle
& wxCANCEL_DEFAULT
)
122 if ( m_dialogStyle
& wxYES_NO
)
125 yes
= new wxButton(this, wxID_YES
, GetCustomYesLabel());
126 sizerStd
->AddButton(yes
);
129 no
= new wxButton(this, wxID_NO
, GetCustomNoLabel());
130 sizerStd
->AddButton(no
);
131 if ( m_dialogStyle
& wxNO_DEFAULT
)
137 if ( m_dialogStyle
& wxHELP
)
140 help
= new wxButton(this, wxID_HELP
, GetCustomHelpLabel());
141 sizerStd
->AddButton(help
);
146 btnDef
->SetDefault();
152 return CreateSeparatedSizer(sizerStd
);
154 #endif // !__SMARTPHONE__
156 // Use standard labels for all buttons
157 return CreateSeparatedButtonSizer
159 m_dialogStyle
& (wxOK
| wxCANCEL
| wxHELP
| wxYES_NO
|
160 wxNO_DEFAULT
| wxCANCEL_DEFAULT
)
164 void wxGenericMessageDialog::DoCreateMsgdialog()
166 wxDialog::Create(m_parent
, wxID_ANY
, m_caption
, m_pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
168 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
170 wxBoxSizer
*icon_text
= new wxBoxSizer( wxHORIZONTAL
);
174 if (m_dialogStyle
& wxICON_MASK
)
176 wxStaticBitmap
*icon
= new wxStaticBitmap
180 wxArtProvider::GetMessageBoxIcon(m_dialogStyle
)
182 if ( wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
)
183 topsizer
->Add( icon
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxALIGN_LEFT
, 10 );
185 icon_text
->Add(icon
, wxSizerFlags().Top().Border(wxRIGHT
, 20));
187 #endif // wxUSE_STATBMP
192 wxBoxSizer
* const textsizer
= new wxBoxSizer(wxVERTICAL
);
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() )
200 wxTitleTextWrapper
titleWrapper(this);
201 textsizer
->Add(CreateTextSizer(GetMessage(), titleWrapper
),
202 wxSizerFlags().Border(wxBOTTOM
, 20));
204 lowerMessage
= GetExtendedMessage();
206 else // no extended message
208 lowerMessage
= GetMessage();
211 textsizer
->Add(CreateTextSizer(lowerMessage
));
213 icon_text
->Add(textsizer
, 0, wxALIGN_CENTER
, 10);
214 topsizer
->Add( icon_text
, 1, wxLEFT
|wxRIGHT
|wxTOP
, 10 );
215 #endif // wxUSE_STATTEXT
217 // 3) optional checkbox and detailed text
218 AddMessageDialogCheckBox( topsizer
);
219 AddMessageDialogDetails( topsizer
);
222 wxSizer
*sizerBtn
= CreateMsgDlgButtonSizer();
224 topsizer
->Add(sizerBtn
, 0, wxEXPAND
| wxALL
, 10 );
226 SetAutoLayout( true );
227 SetSizer( topsizer
);
229 topsizer
->SetSizeHints( this );
230 topsizer
->Fit( this );
231 wxSize
size( GetSize() );
232 if (size
.x
< size
.y
*3/2)
238 Centre( wxBOTH
| wxCENTER_FRAME
);
241 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
))
243 EndModal( wxID_YES
);
246 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
))
251 void wxGenericMessageDialog::OnHelp(wxCommandEvent
& WXUNUSED(event
))
253 EndModal( wxID_HELP
);
256 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
258 // Allow cancellation via ESC/Close button except if
259 // only YES and NO are specified.
260 const long style
= GetMessageDialogStyle();
261 if ( (style
& wxYES_NO
) != wxYES_NO
|| (style
& wxCANCEL
) )
263 EndModal( wxID_CANCEL
);
267 int wxGenericMessageDialog::ShowModal()
269 WX_HOOK_MODAL_DIALOG();
277 return wxMessageDialogBase::ShowModal();
280 #endif // wxUSE_MSGDLG