1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMessageDialogEx
4 // Author: Julian Smart
7 // RCS-ID: $Id: msgdlgex.cpp,v 1.2 2001/06/11 14:22:31 julians Exp $
8 // Copyright: (c) Julian Smart
10 // This program is part of the eCos host tools.
12 // This program is free software; you can redistribute it and/or modify it
13 // under the terms of the GNU General Public License as published by the Free
14 // Software Foundation; either version 2 of the License, or (at your option)
17 // This program is distributed in the hope that it will be useful, but WITHOUT
18 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
22 // You should have received a copy of the GNU General Public License along with
23 // this program; if not, write to the Free Software Foundation, Inc.,
24 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /////////////////////////////////////////////////////////////////////////////
29 #pragma implementation "msgdlgex.cpp"
32 // For compilers that support precompilation, includes "wx/wx.h".
33 //#include "wx/wxprec.h"
42 // Include wxWindow's headers
45 #include "wx/statline.h"
46 #include "wx/statbox.h"
47 #include "wx/stattext.h"
48 #include "wx/statbmp.h"
49 #include "wx/bmpbuttn.h"
51 //----------------------------------------------------------------------------
53 //----------------------------------------------------------------------------
55 IMPLEMENT_CLASS(wxMessageDialogEx,wxDialog)
57 BEGIN_EVENT_TABLE(wxMessageDialogEx,wxDialog)
58 EVT_BUTTON( -1, wxMessageDialogEx::OnCommand )
61 wxMessageDialogEx::wxMessageDialogEx( wxWindow *parent, const wxString& message, const wxString &caption,
62 long style, const wxPoint& position) :
63 wxDialog( parent, -1, caption, position, wxDefaultSize, wxDEFAULT_DIALOG_STYLE )
65 m_dialogStyle = style;
69 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
71 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
74 if (style & wxICON_MASK)
76 wxStaticBitmap *icon = new wxStaticBitmap(
77 this, -1, wxTheApp->GetStdIcon((int)(style & wxICON_MASK)));
78 icon_text->Add( icon, 0, wxCENTER );
82 icon_text->Add( CreateTextSizer( message ), 0, wxCENTER | wxLEFT, 10 );
84 topsizer->Add( icon_text, 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 );
88 topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
92 topsizer->Add( CreateButtonSizer( style ), 0, wxCENTRE | wxALL, 10 );
94 SetAutoLayout( TRUE );
97 topsizer->SetSizeHints( this );
98 topsizer->Fit( this );
99 wxSize size( GetSize() );
100 if (size.x < size.y*3/2)
106 Centre( wxBOTH | wxCENTER_FRAME);
111 wxMessageDialogEx::wxMessageDialogEx()
116 wxMessageDialogEx::~wxMessageDialogEx()
120 void wxMessageDialogEx::OnCommand(wxCommandEvent &event)
122 EndModal(event.GetId());
125 wxSizer *wxMessageDialogEx::CreateButtonSizer( long flags )
127 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
129 #if defined(__WXMSW__) || defined(__WXMAC__)
130 static const int margin = 6;
132 static const int margin = 10;
135 wxButton *ok = (wxButton *) NULL;
136 wxButton *cancel = (wxButton *) NULL;
137 wxButton *yes = (wxButton *) NULL;
138 wxButton *no = (wxButton *) NULL;
139 wxButton *yestoall = (wxButton *) NULL;
140 wxButton *notoall = (wxButton *) NULL;
141 wxButton *abort = (wxButton *) NULL;
142 wxButton *retry = (wxButton *) NULL;
143 wxButton *ignore = (wxButton *) NULL;
145 // always show an OK button, unless only YES_NO is given
146 // NO, not in this dialog.
147 //if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
149 if (flags & wxMD_YES_NO)
151 yes = new wxButton( this, wxID_YES, _("Yes") );
152 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
153 no = new wxButton( this, wxID_NO, _("No") );
154 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
157 if (flags & wxMD_YES)
161 yes = new wxButton( this, wxID_YES, _("Yes") );
162 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
166 if (flags & wxMD_YESTOALL)
168 yestoall = new wxButton( this, wxID_YESTOALL, _("Yes to All") );
169 box->Add( yestoall, 0, wxLEFT|wxRIGHT, margin );
176 no = new wxButton( this, wxID_NO, _("No") );
177 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
181 if (flags & wxMD_NOTOALL)
183 notoall = new wxButton( this, wxID_NOTOALL, _("No to All") );
184 box->Add( notoall, 0, wxLEFT|wxRIGHT, margin );
187 if (flags & wxMD_ABORT)
189 abort = new wxButton( this, wxID_ABORT, _("Abort") );
190 box->Add( abort, 0, wxLEFT|wxRIGHT, margin );
193 if (flags & wxMD_RETRY)
195 retry = new wxButton( this, wxID_RETRY, _("Retry") );
196 box->Add( retry, 0, wxLEFT|wxRIGHT, margin );
199 if (flags & wxMD_IGNORE)
201 ignore = new wxButton( this, wxID_IGNORE, _("Ignore") );
202 box->Add( ignore, 0, wxLEFT|wxRIGHT, margin );
207 ok = new wxButton( this, wxID_OK, _("OK") );
208 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
211 if (flags & wxMD_CANCEL)
213 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
214 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
217 if (flags & wxMD_HELP)
218 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
220 bool setDefault = FALSE;
222 if (flags & wxMD_NO_DEFAULT)
231 else if (flags & wxMD_YES_DEFAULT)
240 else if (flags & wxMD_YESTOALL_DEFAULT)
244 yestoall->SetDefault();
245 yestoall->SetFocus();
249 else if (flags & wxMD_NOTOALL_DEFAULT)
253 notoall->SetDefault();
258 else if (flags & wxMD_ABORT_DEFAULT)
267 else if (flags & wxMD_RETRY_DEFAULT)
276 else if (flags & wxMD_IGNORE_DEFAULT)
280 ignore->SetDefault();