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"
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_CANCEL
, wxGenericMessageDialog::OnCancel
)
80 IMPLEMENT_CLASS(wxGenericMessageDialog
, wxDialog
)
82 wxGenericMessageDialog::wxGenericMessageDialog( wxWindow
*parent
,
83 const wxString
& message
,
84 const wxString
& caption
,
87 : wxMessageDialogBase(GetParentForModalDialog(parent
, style
),
96 wxSizer
*wxGenericMessageDialog::CreateMsgDlgButtonSizer()
98 #ifndef __SMARTPHONE__
99 if ( HasCustomLabels() )
101 wxStdDialogButtonSizer
* const sizerStd
= new wxStdDialogButtonSizer
;
103 wxButton
*btnDef
= NULL
;
105 if ( m_dialogStyle
& wxOK
)
107 btnDef
= new wxButton(this, wxID_OK
, GetCustomOKLabel());
108 sizerStd
->AddButton(btnDef
);
111 if ( m_dialogStyle
& wxCANCEL
)
114 cancel
= new wxButton(this, wxID_CANCEL
, GetCustomCancelLabel());
115 sizerStd
->AddButton(cancel
);
117 if ( m_dialogStyle
& wxCANCEL_DEFAULT
)
121 if ( m_dialogStyle
& wxYES_NO
)
124 yes
= new wxButton(this, wxID_YES
, GetCustomYesLabel());
125 sizerStd
->AddButton(yes
);
128 no
= new wxButton(this, wxID_NO
, GetCustomNoLabel());
129 sizerStd
->AddButton(no
);
130 if ( m_dialogStyle
& wxNO_DEFAULT
)
138 btnDef
->SetDefault();
144 return CreateSeparatedSizer(sizerStd
);
146 #endif // !__SMARTPHONE__
148 // Use standard labels for all buttons
149 return CreateSeparatedButtonSizer
151 m_dialogStyle
& (wxOK
| wxCANCEL
| wxYES_NO
|
152 wxNO_DEFAULT
| wxCANCEL_DEFAULT
)
156 void wxGenericMessageDialog::DoCreateMsgdialog()
158 wxDialog::Create(m_parent
, wxID_ANY
, m_caption
, m_pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
160 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
162 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
164 wxBoxSizer
*icon_text
= new wxBoxSizer( wxHORIZONTAL
);
168 if (m_dialogStyle
& wxICON_MASK
)
170 wxStaticBitmap
*icon
= new wxStaticBitmap
174 wxArtProvider::GetMessageBoxIcon(m_dialogStyle
)
177 topsizer
->Add( icon
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxALIGN_LEFT
, 10 );
179 icon_text
->Add(icon
, wxSizerFlags().Top().Border(wxRIGHT
, 20));
181 #endif // wxUSE_STATBMP
186 wxBoxSizer
* const textsizer
= new wxBoxSizer(wxVERTICAL
);
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() )
194 wxTitleTextWrapper
titleWrapper(this);
195 textsizer
->Add(CreateTextSizer(GetMessage(), titleWrapper
),
196 wxSizerFlags().Border(wxBOTTOM
, 20));
198 lowerMessage
= GetExtendedMessage();
200 else // no extended message
202 lowerMessage
= GetMessage();
205 textsizer
->Add(CreateTextSizer(lowerMessage
));
207 icon_text
->Add(textsizer
, 0, wxALIGN_CENTER
, 10);
208 topsizer
->Add( icon_text
, 1, wxLEFT
|wxRIGHT
|wxTOP
, 10 );
209 #endif // wxUSE_STATTEXT
211 // 3) optional checkbox and detailed text
212 AddMessageDialogCheckBox( topsizer
);
213 AddMessageDialogDetails( topsizer
);
216 wxSizer
*sizerBtn
= CreateMsgDlgButtonSizer();
218 topsizer
->Add(sizerBtn
, 0, wxEXPAND
| wxALL
, 10 );
220 SetAutoLayout( true );
221 SetSizer( topsizer
);
223 topsizer
->SetSizeHints( this );
224 topsizer
->Fit( this );
225 wxSize
size( GetSize() );
226 if (size
.x
< size
.y
*3/2)
232 Centre( wxBOTH
| wxCENTER_FRAME
);
235 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
))
237 EndModal( wxID_YES
);
240 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
))
245 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
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
) )
252 EndModal( wxID_CANCEL
);
256 int wxGenericMessageDialog::ShowModal()
264 return wxMessageDialogBase::ShowModal();
267 #endif // wxUSE_MSGDLG