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 void wxGenericMessageDialog::DoCreateMsgdialog()
98 wxDialog::Create(m_parent
, wxID_ANY
, m_caption
, m_pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
);
100 bool is_pda
= (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA
);
102 wxBoxSizer
*topsizer
= new wxBoxSizer( wxVERTICAL
);
104 wxBoxSizer
*icon_text
= new wxBoxSizer( wxHORIZONTAL
);
108 if (m_dialogStyle
& wxICON_MASK
)
110 wxStaticBitmap
*icon
= new wxStaticBitmap
114 wxArtProvider::GetMessageBoxIcon(m_dialogStyle
)
117 topsizer
->Add( icon
, 0, wxTOP
|wxLEFT
|wxRIGHT
| wxALIGN_LEFT
, 10 );
119 icon_text
->Add(icon
, wxSizerFlags().Top().Border(wxRIGHT
, 20));
121 #endif // wxUSE_STATBMP
126 wxBoxSizer
* const textsizer
= new wxBoxSizer(wxVERTICAL
);
128 // We want to show the main message in a different font to make it stand
129 // out if the extended message is used as well. This looks better and is
130 // more consistent with the native dialogs under MSW and GTK.
131 wxString lowerMessage
;
132 if ( !m_extendedMessage
.empty() )
134 wxTitleTextWrapper
titleWrapper(this);
135 textsizer
->Add(CreateTextSizer(GetMessage(), titleWrapper
),
136 wxSizerFlags().Border(wxBOTTOM
, 20));
138 lowerMessage
= GetExtendedMessage();
140 else // no extended message
142 lowerMessage
= GetMessage();
145 textsizer
->Add(CreateTextSizer(lowerMessage
));
147 icon_text
->Add(textsizer
, 0, wxALIGN_CENTER
, 10);
148 topsizer
->Add( icon_text
, 1, wxCENTER
| wxLEFT
|wxRIGHT
|wxTOP
, 10 );
149 #endif // wxUSE_STATTEXT
151 // 3) optional checkbox and detailed text
152 AddMessageDialogCheckBox( topsizer
);
153 AddMessageDialogDetails( topsizer
);
156 int center_flag
= wxEXPAND
;
157 if (m_dialogStyle
& wxYES_NO
)
158 center_flag
= wxALIGN_CENTRE
;
159 wxSizer
*sizerBtn
= CreateSeparatedButtonSizer
161 m_dialogStyle
& (wxOK
| wxCANCEL
| wxYES_NO
|
162 wxNO_DEFAULT
| wxCANCEL_DEFAULT
)
165 topsizer
->Add(sizerBtn
, 0, center_flag
| wxALL
, 10 );
167 SetAutoLayout( true );
168 SetSizer( topsizer
);
170 topsizer
->SetSizeHints( this );
171 topsizer
->Fit( this );
172 wxSize
size( GetSize() );
173 if (size
.x
< size
.y
*3/2)
179 Centre( wxBOTH
| wxCENTER_FRAME
);
182 void wxGenericMessageDialog::OnYes(wxCommandEvent
& WXUNUSED(event
))
184 EndModal( wxID_YES
);
187 void wxGenericMessageDialog::OnNo(wxCommandEvent
& WXUNUSED(event
))
192 void wxGenericMessageDialog::OnCancel(wxCommandEvent
& WXUNUSED(event
))
194 // Allow cancellation via ESC/Close button except if
195 // only YES and NO are specified.
196 const long style
= GetMessageDialogStyle();
197 if ( (style
& wxYES_NO
) != wxYES_NO
|| (style
& wxCANCEL
) )
199 EndModal( wxID_CANCEL
);
203 int wxGenericMessageDialog::ShowModal()
211 return wxMessageDialogBase::ShowModal();
214 #endif // wxUSE_MSGDLG