]>
Commit | Line | Data |
---|---|---|
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 | ||
51 | class wxTitleTextWrapper : public wxTextSizerWrapper | |
52 | { | |
53 | public: | |
54 | wxTitleTextWrapper(wxWindow *win) | |
55 | : wxTextSizerWrapper(win) | |
56 | { | |
57 | } | |
58 | ||
59 | protected: | |
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 | 74 | BEGIN_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 |
78 | END_EVENT_TABLE() |
79 | ||
80 | IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog) | |
c801d85f | 81 | |
917b3d40 VZ |
82 | wxGenericMessageDialog::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 | |
2afb9e16 VZ |
96 | void wxGenericMessageDialog::DoCreateMsgdialog() |
97 | { | |
98 | wxDialog::Create(m_parent, wxID_ANY, m_caption, m_pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE); | |
2229243b | 99 | |
2b5f62a0 VZ |
100 | bool is_pda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA); |
101 | ||
92afa2b1 | 102 | wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); |
c801d85f | 103 | |
92afa2b1 | 104 | wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL ); |
479cd5de | 105 | |
9a6384ca | 106 | #if wxUSE_STATBMP |
92afa2b1 | 107 | // 1) icon |
2afb9e16 | 108 | if (m_dialogStyle & wxICON_MASK) |
dfc54541 | 109 | { |
1970409e VZ |
110 | wxStaticBitmap *icon = new wxStaticBitmap |
111 | ( | |
112 | this, | |
113 | wxID_ANY, | |
114 | wxArtProvider::GetMessageBoxIcon(m_dialogStyle) | |
115 | ); | |
2b5f62a0 VZ |
116 | if (is_pda) |
117 | topsizer->Add( icon, 0, wxTOP|wxLEFT|wxRIGHT | wxALIGN_LEFT, 10 ); | |
118 | else | |
8d5016b1 | 119 | icon_text->Add(icon, wxSizerFlags().Top().Border(wxRIGHT, 20)); |
dfc54541 | 120 | } |
9a6384ca | 121 | #endif // wxUSE_STATBMP |
479cd5de | 122 | |
9a6384ca | 123 | #if wxUSE_STATTEXT |
92afa2b1 | 124 | // 2) text |
479cd5de | 125 | |
c79510ca VZ |
126 | wxBoxSizer * const textsizer = new wxBoxSizer(wxVERTICAL); |
127 | ||
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() ) | |
133 | { | |
134 | wxTitleTextWrapper titleWrapper(this); | |
135 | textsizer->Add(CreateTextSizer(GetMessage(), titleWrapper), | |
136 | wxSizerFlags().Border(wxBOTTOM, 20)); | |
137 | ||
138 | lowerMessage = GetExtendedMessage(); | |
139 | } | |
140 | else // no extended message | |
141 | { | |
142 | lowerMessage = GetMessage(); | |
143 | } | |
144 | ||
145 | textsizer->Add(CreateTextSizer(lowerMessage)); | |
146 | ||
147 | icon_text->Add(textsizer, 0, wxALIGN_CENTER, 10); | |
2b5f62a0 | 148 | topsizer->Add( icon_text, 1, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); |
9a6384ca | 149 | #endif // wxUSE_STATTEXT |
479cd5de | 150 | |
ede7b017 VZ |
151 | // 3) optional checkbox and detailed text |
152 | AddMessageDialogCheckBox( topsizer ); | |
153 | AddMessageDialogDetails( topsizer ); | |
154 | ||
155 | // 4) buttons | |
39caed1f | 156 | int center_flag = wxEXPAND; |
2afb9e16 | 157 | if (m_dialogStyle & wxYES_NO) |
bd9f3519 | 158 | center_flag = wxALIGN_CENTRE; |
12a124dd VZ |
159 | wxSizer *sizerBtn = CreateSeparatedButtonSizer |
160 | ( | |
161 | m_dialogStyle & (wxOK | wxCANCEL | wxYES_NO | | |
162 | wxNO_DEFAULT | wxCANCEL_DEFAULT) | |
163 | ); | |
bd9f3519 VZ |
164 | if ( sizerBtn ) |
165 | topsizer->Add(sizerBtn, 0, center_flag | wxALL, 10 ); | |
917b3d40 | 166 | |
ca65c044 | 167 | SetAutoLayout( true ); |
8b17ba72 | 168 | SetSizer( topsizer ); |
479cd5de | 169 | |
92afa2b1 RR |
170 | topsizer->SetSizeHints( this ); |
171 | topsizer->Fit( this ); | |
8b17ba72 | 172 | wxSize size( GetSize() ); |
e6daf794 | 173 | if (size.x < size.y*3/2) |
8b17ba72 | 174 | { |
e6daf794 | 175 | size.x = size.y*3/2; |
f1df0927 | 176 | SetSize( size ); |
8b17ba72 | 177 | } |
917b3d40 | 178 | |
92afa2b1 | 179 | Centre( wxBOTH | wxCENTER_FRAME); |
c801d85f KB |
180 | } |
181 | ||
182 | void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) | |
183 | { | |
15b24b14 | 184 | EndModal( wxID_YES ); |
c801d85f KB |
185 | } |
186 | ||
187 | void wxGenericMessageDialog::OnNo(wxCommandEvent& WXUNUSED(event)) | |
188 | { | |
15b24b14 | 189 | EndModal( wxID_NO ); |
c801d85f KB |
190 | } |
191 | ||
192 | void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) | |
193 | { | |
2b5f62a0 VZ |
194 | // Allow cancellation via ESC/Close button except if |
195 | // only YES and NO are specified. | |
e5b50758 WS |
196 | const long style = GetMessageDialogStyle(); |
197 | if ( (style & wxYES_NO) != wxYES_NO || (style & wxCANCEL) ) | |
15b24b14 RR |
198 | { |
199 | EndModal( wxID_CANCEL ); | |
200 | } | |
c801d85f KB |
201 | } |
202 | ||
2afb9e16 VZ |
203 | int wxGenericMessageDialog::ShowModal() |
204 | { | |
205 | if ( !m_created ) | |
206 | { | |
207 | m_created = true; | |
208 | DoCreateMsgdialog(); | |
209 | } | |
210 | ||
211 | return wxMessageDialogBase::ShowModal(); | |
212 | } | |
213 | ||
ede7b017 | 214 | #endif // wxUSE_MSGDLG |