]> git.saurik.com Git - wxWidgets.git/commitdiff
Add wxMessageDialog::GetEffectiveIcon() and use it in all ports.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 20 Mar 2010 13:18:23 +0000 (13:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 20 Mar 2010 13:18:23 +0000 (13:18 +0000)
Remove code duplication and inconsistencies among different ports by using a
single function in the base class for the determination of the effective icon
style to use, correctly handling both wxICON_NONE and the absence of any
wxICON_XXX styles.

Closes #11822.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63725 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msgdlg.h
src/cocoa/msgdlg.mm
src/gtk/msgdlg.cpp
src/msw/msgdlg.cpp
src/os2/msgdlg.cpp
src/osx/carbon/msgdlg.cpp
src/palmos/msgdlg.cpp

index 1f69aba4f984dc45a1af87407273c6f251e330d9..de2d6abe1bc060aee36ba40d32931230762769c3 100644 (file)
@@ -168,6 +168,26 @@ public:
 protected:
     long GetMessageDialogStyle() const { return m_dialogStyle; }
 
+    // based on message dialog style, returns exactly one of: wxICON_NONE,
+    // wxICON_ERROR, wxICON_WARNING, wxICON_QUESTION, wxICON_INFORMATION
+    long GetEffectiveIcon() const
+    {
+        if ( m_dialogStyle & wxICON_NONE )
+            return wxICON_NONE;
+        else if ( m_dialogStyle & wxICON_ERROR )
+            return wxICON_ERROR;
+        else if ( m_dialogStyle & wxICON_WARNING )
+            return wxICON_WARNING;
+        else if ( m_dialogStyle & wxICON_QUESTION )
+            return wxICON_QUESTION;
+        else if ( m_dialogStyle & wxICON_INFORMATION )
+            return wxICON_INFORMATION;
+        else if ( m_dialogStyle & wxYES )
+            return wxICON_QUESTION;
+        else
+            return wxICON_INFORMATION;
+    }
+
 
     // for the platforms not supporting separate main and extended messages
     // this function should be used to combine both of them in a single string
index 3dfe3f0a15e4f5ab32d7f1d51ed75dfd55afc9ae..772ec2489de7a35f5b0fdcc7f1c0c18e4db9c936 100644 (file)
@@ -79,14 +79,17 @@ int wxCocoaMessageDialog::ShowModal()
     const long style = GetMessageDialogStyle();
 
     NSAlertStyle nsStyle = NSInformationalAlertStyle;
-    if (style & wxICON_EXCLAMATION)
-        nsStyle = NSWarningAlertStyle;
-    else if (style & wxICON_HAND)
-        nsStyle = NSCriticalAlertStyle;
-    else if (style & wxICON_INFORMATION)
-        nsStyle = NSInformationalAlertStyle;
-    else if (style & wxICON_QUESTION)
-        nsStyle = NSInformationalAlertStyle;
+
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            nsStyle = NSCriticalAlertStyle;
+            break;
+
+        case wxICON_WARNING:
+            nsStyle = NSWarningAlertStyle;
+            break;
+    }
 
     [alert setAlertStyle:nsStyle];
 
index 3badb45c6324850dfc134380b5c290b70a020813..eee220b449bf566d9fcbfeddaa3fdebe03b28eab 100644 (file)
@@ -90,19 +90,26 @@ void wxMessageDialog::GTKCreateMsgDialog()
     GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL;
 
 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
-    const char *stockIcon;
-    if ( m_dialogStyle & wxICON_NONE )
-        stockIcon = "";
-    else if ( m_dialogStyle & wxICON_ERROR )
-        stockIcon = "qgn_note_gene_syserror";
-    else if ( m_dialogStyle & wxICON_EXCLAMATION )
-        stockIcon = "qgn_note_gene_syswarning";
-    else if ( m_dialogStyle & wxICON_INFORMATION )
-        stockIcon = "qgn_note_info";
-    else if ( m_dialogStyle & wxICON_QUESTION )
-        stockIcon = "qgn_note_confirm";
-    else
-        stockIcon = "";
+    const char *stockIcon = "";
+
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            stockIcon = "qgn_note_gene_syserror";
+            break;
+
+        case wxICON_WARNING:
+            stockIcon = "qgn_note_gene_syswarning";
+            break;
+
+        case wxICON_QUESTION:
+            stockIcon = "qgn_note_confirm";
+            break;
+
+        case wxICON_INFORMATION:
+            stockIcon = "qgn_note_info";
+            break;
+    }
 
     // there is no generic note creation function in public API so we have no
     // choice but to use g_object_new() directly
@@ -138,7 +145,7 @@ void wxMessageDialog::GTKCreateMsgDialog()
         }
     }
 
-    if ( !wxGTKImpl::ConvertMessageTypeFromWX(m_dialogStyle, &type) )
+    if ( !wxGTKImpl::ConvertMessageTypeFromWX(GetEffectiveIcon(), &type) )
     {
         // if no style is explicitly specified, detect the suitable icon
         // ourselves (this can be disabled by using wxICON_NONE)
index a4c79cc53aa47b0849fc187eb177c115a9910ba0..feddca75214a8eba9c69b9d419456d73ad06be27 100644 (file)
@@ -508,16 +508,24 @@ int wxMessageDialog::ShowModal()
     }
 
     // set the icon style
-    if (wxStyle & wxICON_EXCLAMATION)
-        msStyle |= MB_ICONEXCLAMATION;
-    else if (wxStyle & wxICON_HAND)
-        msStyle |= MB_ICONHAND;
-    else if (wxStyle & wxICON_INFORMATION)
-        msStyle |= MB_ICONINFORMATION;
-    else if (wxStyle & wxICON_QUESTION)
-        msStyle |= MB_ICONQUESTION;
-    else if (!(wxStyle & wxICON_NONE))
-        msStyle |= wxStyle & wxYES ? MB_ICONQUESTION : MB_ICONINFORMATION;
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            msStyle |= MB_ICONHAND;
+            break;
+
+        case wxICON_WARNING:
+            msStyle |= MB_ICONEXCLAMATION;
+            break;
+
+        case wxICON_QUESTION:
+            msStyle |= MB_ICONQUESTION;
+            break;
+
+        case wxICON_INFORMATION:
+            msStyle |= MB_ICONINFORMATION;
+            break;
+    }
 
     if ( wxStyle & wxSTAY_ON_TOP )
         msStyle |= MB_TOPMOST;
index 4504fd97c7006f4ddebec42919f77367c2d8ae4b..97e9b8f99c4ca1d7e317208b7a86616c1d04f355 100644 (file)
@@ -73,14 +73,25 @@ int wxMessageDialog::ShowModal()
         else
             ulStyle = MB_OK;
     }
-    if (lStyle & wxICON_EXCLAMATION)
-        ulStyle |= MB_ICONEXCLAMATION;
-    else if (lStyle & wxICON_HAND)
-        ulStyle |= MB_ICONHAND;
-    else if (lStyle & wxICON_INFORMATION)
-        ulStyle |= MB_ICONEXCLAMATION;
-    else if (lStyle & wxICON_QUESTION)
-        ulStyle |= MB_ICONQUESTION;
+
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            ulStyle |= MB_ERROR;
+            break;
+
+        case wxICON_WARNING:
+            ulStyle |= MB_WARNING;
+            break;
+
+        case wxICON_QUESTION:
+            ulStyle |= MB_QUERY;
+            break;
+
+        case wxICON_INFORMATION:
+            ulStyle |= MB_INFORMATION;
+            break;
+    }
 
     if (hWnd != HWND_DESKTOP)
         ulStyle |= MB_APPLMODAL;
index d7d024529c8b90439b3050e54cc717fe039a26c2..20be0469e530f34d303cf89d3842408c7e30af4c 100644 (file)
@@ -40,17 +40,26 @@ int wxMessageDialog::ShowModal()
 
     const long style = GetMessageDialogStyle();
 
-    wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("this style is not supported on Mac") );
+    wxASSERT_MSG( (style & 0x3F) != wxYES,
+        "this style is not supported on Mac" );
 
     AlertType alertType = kAlertPlainAlert;
-    if (style & wxICON_EXCLAMATION)
-        alertType = kAlertCautionAlert;
-    else if (style & wxICON_HAND)
-        alertType = kAlertStopAlert;
-    else if (style & wxICON_INFORMATION)
-        alertType = kAlertNoteAlert;
-    else if (style & wxICON_QUESTION)
-        alertType = kAlertNoteAlert;
+
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            alertType = kAlertStopAlert;
+            break;
+
+        case wxICON_WARNING:
+            alertType = kAlertCautionAlert;
+            break;
+
+        case wxICON_QUESTION:
+        case wxICON_INFORMATION:
+            alertType = kAlertNoteAlert;
+            break;
+    }
 
 
     // work out what to display
index 48445b23c5dc7a9a8bc62a4b65f3f8e97918b322..29bbb0e56a7db79e6704038f0a802df1342a8d24 100644 (file)
@@ -63,14 +63,25 @@ int wxMessageDialog::ShowModal()
     }
 
     // Add the icon styles
-    if (style & wxICON_EXCLAMATION)
-        AlertID=AlertID+0; // Warning
-    else if (style & wxICON_HAND)
-        AlertID=AlertID+1; // Error
-    else if (style & wxICON_INFORMATION)
-        AlertID=AlertID+2; // Information
-    else if (style & wxICON_QUESTION)
-        AlertID=AlertID+3; // Confirmation
+    switch ( GetEffectiveIcon() )
+    {
+        case wxICON_ERROR:
+            AlertID = AlertID + 1;
+            break;
+
+        case wxICON_WARNING:
+            AlertID = AlertID + 0;
+            break;
+
+        case wxICON_QUESTION:
+            AlertID = AlertID + 3;
+            break;
+
+        case wxICON_NONE:
+        case wxICON_INFORMATION:
+            AlertID = AlertID + 2;
+            break;
+    }
 
     // The Palm OS Dialog API does not support custom titles in a dialog box.
     // So we have to set the title by manipulating the resource.