X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/917b3d40f2da1f02a81cbe385118a504072c401c..63efc55ff74b1b9b9d20497a0741bf84593df986:/src/generic/msgdlgg.cpp diff --git a/src/generic/msgdlgg.cpp b/src/generic/msgdlgg.cpp index 0b8eea5424..f4f383f676 100644 --- a/src/generic/msgdlgg.cpp +++ b/src/generic/msgdlgg.cpp @@ -6,7 +6,7 @@ // Created: 04/01/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart, Markus Holzem, Robert Roebling -// Licence: wxWindows license +// Licence: wxWindows license ///////////////////////////////////////////////////////////////////////////// #ifdef __GNUG__ @@ -20,16 +20,19 @@ #pragma hdrstop #endif +#if wxUSE_MSGDLG + #ifndef WX_PRECOMP - #include "wx/utils.h" - #include "wx/dialog.h" - #include "wx/button.h" - #include "wx/stattext.h" - #include "wx/statbmp.h" - #include "wx/layout.h" - #include "wx/intl.h" - #include "wx/dcclient.h" - #include "wx/settings.h" + #include "wx/utils.h" + #include "wx/dialog.h" + #include "wx/button.h" + #include "wx/stattext.h" + #include "wx/statbmp.h" + #include "wx/layout.h" + #include "wx/intl.h" + #include "wx/icon.h" + #include "wx/sizer.h" + #include "wx/app.h" #endif #include @@ -45,16 +48,6 @@ // icons // ---------------------------------------------------------------------------- -// MSW icons are in the ressources, for all other platforms - in XPM files -#ifndef __WXMSW__ - #include "wx/generic/info.xpm" - #include "wx/generic/question.xpm" - #include "wx/generic/warning.xpm" - #include "wx/generic/error.xpm" -#endif // __WXMSW__ - - -#if !USE_SHARED_LIBRARY BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog) EVT_BUTTON(wxID_YES, wxGenericMessageDialog::OnYes) EVT_BUTTON(wxID_NO, wxGenericMessageDialog::OnNo) @@ -62,7 +55,6 @@ BEGIN_EVENT_TABLE(wxGenericMessageDialog, wxDialog) END_EVENT_TABLE() IMPLEMENT_CLASS(wxGenericMessageDialog, wxDialog) -#endif wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxString& message, @@ -71,238 +63,46 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent, const wxPoint& pos) : wxDialog( parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE ) { - static const int LAYOUT_X_MARGIN = 5; - static const int LAYOUT_Y_MARGIN = 5; - m_dialogStyle = style; - wxBeginBusyCursor(); - - wxLayoutConstraints *c; - SetAutoLayout(TRUE); + wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL ); - // create an icon - enum - { - Icon_Information, - Icon_Question, - Icon_Warning, - Icon_Error - } which; + wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL ); -#ifdef __WXMSW__ - static char *icons[] = + // 1) icon + if (style & wxICON_MASK) { - "wxICON_INFO", - "wxICON_QUESTION", - "wxICON_WARNING", - "wxICON_ERROR", - }; -#else // XPM icons - static char **icons[] = - { - info, - question, - warning, - error, - }; -#endif // !XPM/XPM - - if ( style & wxICON_EXCLAMATION ) - which = Icon_Warning; - else if ( style & wxICON_HAND ) - which = Icon_Error; - else if ( style & wxICON_QUESTION ) - which = Icon_Question; - else - which = Icon_Information; - - wxStaticBitmap *icon = new wxStaticBitmap(this, -1, wxIcon(icons[which])); - const int iconSize = icon->GetBitmap().GetWidth(); - - // split the message in lines - // -------------------------- - wxClientDC dc(this); - dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT)); - - wxArrayString lines; - wxString curLine; - long height, width, heightTextMax = 0, widthTextMax = 0; - for ( const char *pc = message; ; pc++ ) { - if ( *pc == '\n' || *pc == '\0' ) { - dc.GetTextExtent(curLine, &width, &height); - if ( width > widthTextMax ) - widthTextMax = width; - if ( height > heightTextMax ) - heightTextMax = height; - - lines.Add(curLine); - - if ( *pc == '\n' ) { - curLine.Empty(); - } - else { - // the end of string - break; - } - } - else { - curLine += *pc; - } - } - - // calculate the total dialog size - enum - { - Btn_Ok, - Btn_Yes, - Btn_No, - Btn_Cancel, - Btn_Max - }; - wxButton *buttons[Btn_Max] = { NULL, NULL, NULL, NULL }; - int nDefaultBtn = -1; - - // some checks are in order... - wxASSERT_MSG( !(style & wxOK) || !(style & wxYES_NO), - "don't create dialog with both Yes/No and Ok buttons!" ); - - wxASSERT_MSG( (style & wxOK ) || (style & wxYES_NO), - "don't create dialog with only the Cancel button!" ); - - if ( style & wxYES_NO ) { - buttons[Btn_Yes] = new wxButton(this, wxID_YES, _("Yes")); - buttons[Btn_No] = new wxButton(this, wxID_NO, _("No")); - - - if(style & wxNO_DEFAULT) - nDefaultBtn = Btn_No; - else - nDefaultBtn = Btn_Yes; + wxStaticBitmap *icon = new wxStaticBitmap( + this, -1, wxTheApp->GetStdIcon((int)(style & wxICON_MASK))); + icon_text->Add( icon, 0, wxCENTER ); } - if (style & wxOK) { - buttons[Btn_Ok] = new wxButton(this, wxID_OK, _("OK")); + // 2) text + icon_text->Add( CreateTextSizer( message ), 0, wxCENTER | wxLEFT, 10 ); - if ( nDefaultBtn == -1 ) - nDefaultBtn = Btn_Ok; - } - - if (style & wxCANCEL) { - buttons[Btn_Cancel] = new wxButton(this, wxID_CANCEL, _("Cancel")); - } + topsizer->Add( icon_text, 0, wxCENTER | wxLEFT|wxRIGHT|wxTOP, 10 ); - // get the longest caption and also calc the number of buttons - size_t nBtn, nButtons = 0; - long widthBtnMax = 0; - for ( nBtn = 0; nBtn < Btn_Max; nBtn++ ) { - if ( buttons[nBtn] ) { - nButtons++; - dc.GetTextExtent(buttons[nBtn]->GetLabel(), &width, NULL); - if ( width > widthBtnMax ) - widthBtnMax = width; - } - } - - // now we can place the buttons - if ( widthBtnMax < 75 ) - widthBtnMax = 75; - else - widthBtnMax += 10; - long heightButton = widthBtnMax*23/75; - - // *1.2 baselineskip - heightTextMax *= 12; - heightTextMax /= 10; - - size_t nLineCount = lines.Count(); - - long widthButtonsTotal = nButtons * (widthBtnMax + LAYOUT_X_MARGIN) - - LAYOUT_X_MARGIN; - - // the size of the dialog - long widthDlg = wxMax(widthTextMax + iconSize + 4*LAYOUT_X_MARGIN, - wxMax(widthButtonsTotal, width)) + - 2*LAYOUT_X_MARGIN, - heightDlg = 8*LAYOUT_Y_MARGIN + heightButton + - heightTextMax*(nLineCount + 1); - - // create the controls - // ------------------- - - // the icon first - c = new wxLayoutConstraints; - c->width.Absolute(iconSize); - c->height.Absolute(iconSize); - c->top.SameAs(this, wxTop, 3*LAYOUT_Y_MARGIN); - c->left.SameAs(this, wxLeft, 2*LAYOUT_X_MARGIN); - icon->SetConstraints(c); - - wxStaticText *text = NULL; - for ( size_t nLine = 0; nLine < nLineCount; nLine++ ) { - c = new wxLayoutConstraints; - if ( text == NULL ) - c->top.SameAs(this, wxTop, 3*LAYOUT_Y_MARGIN); - else - c->top.Below(text); - - c->left.RightOf(icon, 2*LAYOUT_X_MARGIN); - c->width.Absolute(widthTextMax); - c->height.Absolute(heightTextMax); - text = new wxStaticText(this, -1, lines[nLine]); - text->SetConstraints(c); - } - - // create the buttons - wxButton *btnPrevious = (wxButton *)NULL; - for ( nBtn = 0; nBtn < Btn_Max; nBtn++ ) { - if ( buttons[nBtn] ) { - c = new wxLayoutConstraints; - - if ( btnPrevious ) { - c->left.RightOf(btnPrevious, LAYOUT_X_MARGIN); - } - else { - c->left.SameAs(this, wxLeft, - (widthDlg - widthButtonsTotal) / 2); - } - - c->width.Absolute(widthBtnMax); - c->top.Below(text, 4*LAYOUT_Y_MARGIN); - c->height.Absolute(heightButton); - buttons[nBtn]->SetConstraints(c); +#if wxUSE_STATLINE + // 3) static line + topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 ); +#endif - btnPrevious = buttons[nBtn]; - } - } + // 4) buttons + topsizer->Add( CreateButtonSizer( style ), 0, wxCENTRE | wxALL, 10 ); - // set default button - // ------------------ + SetAutoLayout( TRUE ); + SetSizer( topsizer ); - if ( nDefaultBtn != -1 ) { - buttons[nDefaultBtn]->SetDefault(); - buttons[nDefaultBtn]->SetFocus(); - } - else { - wxFAIL_MSG( "can't find default button for this dialog." ); + topsizer->SetSizeHints( this ); + topsizer->Fit( this ); + wxSize size( GetSize() ); + if (size.x < size.y*3/2) + { + size.x = size.y*3/2; + SetSize( size ); } - // position the controls and the dialog itself - // ------------------------------------------- - - SetClientSize(widthDlg, heightDlg); - - // SetSizeHints() wants the size of the whole dialog, not just client size - wxSize sizeTotal = GetSize(), - sizeClient = GetClientSize(); - SetSizeHints(widthDlg + sizeTotal.GetWidth() - sizeClient.GetWidth(), - heightDlg + sizeTotal.GetHeight() - sizeClient.GetHeight()); - - Layout(); - - Centre(wxCENTER_FRAME | wxBOTH); - - wxEndBusyCursor(); + Centre( wxBOTH | wxCENTER_FRAME); } void wxGenericMessageDialog::OnYes(wxCommandEvent& WXUNUSED(event)) @@ -325,4 +125,5 @@ void wxGenericMessageDialog::OnCancel(wxCommandEvent& WXUNUSED(event)) } } +#endif // wxUSE_MSGDLG