]> git.saurik.com Git - wxWidgets.git/blobdiff - src/generic/msgdlgg.cpp
remove duplicate deletion
[wxWidgets.git] / src / generic / msgdlgg.cpp
index 0b8eea5424732d3f738c5b19cd235d719c3052fc..18bd2ba2ba42323dbcf3a971575bcd9fa9888ba1 100644 (file)
@@ -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__
 #endif
 
 #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/app.h"
 #endif
 
 #include <stdio.h>
 // 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)
@@ -71,9 +62,6 @@ 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();
@@ -81,75 +69,18 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
     wxLayoutConstraints *c;
     SetAutoLayout(TRUE);
 
-    // create an icon
-    enum
-    {
-        Icon_Information,
-        Icon_Question,
-        Icon_Warning,
-        Icon_Error
-    } which;
-
-#ifdef __WXMSW__
-    static char *icons[] =
-    {
-        "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]));
+    wxStaticBitmap *icon = new wxStaticBitmap(this, -1,
+                                              wxTheApp->GetStdIcon(style & wxICON_MASK));
     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;
-        }
-    }
+    wxSize sizeText = SplitTextMessage(message, &lines);
+    long widthTextMax = sizeText.GetWidth(),
+         heightTextMax = sizeText.GetHeight();
+    size_t nLineCount = lines.GetCount();
 
     // calculate the total dialog size
     enum
@@ -194,11 +125,11 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
 
     // get the longest caption and also calc the number of buttons
     size_t nBtn, nButtons = 0;
-    long widthBtnMax = 0;
+    int width, widthBtnMax = 0;
     for ( nBtn = 0; nBtn < Btn_Max; nBtn++ ) {
         if ( buttons[nBtn] ) {
             nButtons++;
-            dc.GetTextExtent(buttons[nBtn]->GetLabel(), &width, NULL);
+            GetTextExtent(buttons[nBtn]->GetLabel(), &width, NULL);
             if ( width > widthBtnMax )
                 widthBtnMax = width;
         }
@@ -215,8 +146,6 @@ wxGenericMessageDialog::wxGenericMessageDialog( wxWindow *parent,
     heightTextMax *= 12;
     heightTextMax /= 10;
 
-    size_t nLineCount = lines.Count();
-
     long widthButtonsTotal = nButtons * (widthBtnMax + LAYOUT_X_MARGIN) -
                              LAYOUT_X_MARGIN;