From a4578b0ceda90e103620894d3aa86284178ab1cd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 20 Mar 2010 13:18:23 +0000 Subject: [PATCH] Add wxMessageDialog::GetEffectiveIcon() and use it in all ports. 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 | 20 ++++++++++++++++++++ src/cocoa/msgdlg.mm | 19 +++++++++++-------- src/gtk/msgdlg.cpp | 35 +++++++++++++++++++++-------------- src/msw/msgdlg.cpp | 28 ++++++++++++++++++---------- src/os2/msgdlg.cpp | 27 +++++++++++++++++++-------- src/osx/carbon/msgdlg.cpp | 27 ++++++++++++++++++--------- src/palmos/msgdlg.cpp | 27 +++++++++++++++++++-------- 7 files changed, 126 insertions(+), 57 deletions(-) diff --git a/include/wx/msgdlg.h b/include/wx/msgdlg.h index 1f69aba4f9..de2d6abe1b 100644 --- a/include/wx/msgdlg.h +++ b/include/wx/msgdlg.h @@ -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 diff --git a/src/cocoa/msgdlg.mm b/src/cocoa/msgdlg.mm index 3dfe3f0a15..772ec2489d 100644 --- a/src/cocoa/msgdlg.mm +++ b/src/cocoa/msgdlg.mm @@ -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]; diff --git a/src/gtk/msgdlg.cpp b/src/gtk/msgdlg.cpp index 3badb45c63..eee220b449 100644 --- a/src/gtk/msgdlg.cpp +++ b/src/gtk/msgdlg.cpp @@ -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) diff --git a/src/msw/msgdlg.cpp b/src/msw/msgdlg.cpp index a4c79cc53a..feddca7521 100644 --- a/src/msw/msgdlg.cpp +++ b/src/msw/msgdlg.cpp @@ -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; diff --git a/src/os2/msgdlg.cpp b/src/os2/msgdlg.cpp index 4504fd97c7..97e9b8f99c 100644 --- a/src/os2/msgdlg.cpp +++ b/src/os2/msgdlg.cpp @@ -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; diff --git a/src/osx/carbon/msgdlg.cpp b/src/osx/carbon/msgdlg.cpp index d7d024529c..20be0469e5 100644 --- a/src/osx/carbon/msgdlg.cpp +++ b/src/osx/carbon/msgdlg.cpp @@ -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 diff --git a/src/palmos/msgdlg.cpp b/src/palmos/msgdlg.cpp index 48445b23c5..29bbb0e56a 100644 --- a/src/palmos/msgdlg.cpp +++ b/src/palmos/msgdlg.cpp @@ -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. -- 2.47.2