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
This commit is contained in:
Vadim Zeitlin
2010-03-20 13:18:23 +00:00
parent 5eb342f9a2
commit a4578b0ced
7 changed files with 126 additions and 57 deletions

View File

@@ -168,6 +168,26 @@ public:
protected: protected:
long GetMessageDialogStyle() const { return m_dialogStyle; } 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 // for the platforms not supporting separate main and extended messages
// this function should be used to combine both of them in a single string // this function should be used to combine both of them in a single string

View File

@@ -79,14 +79,17 @@ int wxCocoaMessageDialog::ShowModal()
const long style = GetMessageDialogStyle(); const long style = GetMessageDialogStyle();
NSAlertStyle nsStyle = NSInformationalAlertStyle; NSAlertStyle nsStyle = NSInformationalAlertStyle;
if (style & wxICON_EXCLAMATION)
nsStyle = NSWarningAlertStyle; switch ( GetEffectiveIcon() )
else if (style & wxICON_HAND) {
case wxICON_ERROR:
nsStyle = NSCriticalAlertStyle; nsStyle = NSCriticalAlertStyle;
else if (style & wxICON_INFORMATION) break;
nsStyle = NSInformationalAlertStyle;
else if (style & wxICON_QUESTION) case wxICON_WARNING:
nsStyle = NSInformationalAlertStyle; nsStyle = NSWarningAlertStyle;
break;
}
[alert setAlertStyle:nsStyle]; [alert setAlertStyle:nsStyle];

View File

@@ -90,19 +90,26 @@ void wxMessageDialog::GTKCreateMsgDialog()
GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL; GtkWindow * const parent = m_parent ? GTK_WINDOW(m_parent->m_widget) : NULL;
#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2 #if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
const char *stockIcon; const char *stockIcon = "";
if ( m_dialogStyle & wxICON_NONE )
stockIcon = ""; switch ( GetEffectiveIcon() )
else if ( m_dialogStyle & wxICON_ERROR ) {
case wxICON_ERROR:
stockIcon = "qgn_note_gene_syserror"; stockIcon = "qgn_note_gene_syserror";
else if ( m_dialogStyle & wxICON_EXCLAMATION ) break;
case wxICON_WARNING:
stockIcon = "qgn_note_gene_syswarning"; stockIcon = "qgn_note_gene_syswarning";
else if ( m_dialogStyle & wxICON_INFORMATION ) break;
stockIcon = "qgn_note_info";
else if ( m_dialogStyle & wxICON_QUESTION ) case wxICON_QUESTION:
stockIcon = "qgn_note_confirm"; stockIcon = "qgn_note_confirm";
else break;
stockIcon = "";
case wxICON_INFORMATION:
stockIcon = "qgn_note_info";
break;
}
// there is no generic note creation function in public API so we have no // there is no generic note creation function in public API so we have no
// choice but to use g_object_new() directly // 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 // if no style is explicitly specified, detect the suitable icon
// ourselves (this can be disabled by using wxICON_NONE) // ourselves (this can be disabled by using wxICON_NONE)

View File

@@ -508,16 +508,24 @@ int wxMessageDialog::ShowModal()
} }
// set the icon style // set the icon style
if (wxStyle & wxICON_EXCLAMATION) switch ( GetEffectiveIcon() )
msStyle |= MB_ICONEXCLAMATION; {
else if (wxStyle & wxICON_HAND) case wxICON_ERROR:
msStyle |= MB_ICONHAND; msStyle |= MB_ICONHAND;
else if (wxStyle & wxICON_INFORMATION) break;
msStyle |= MB_ICONINFORMATION;
else if (wxStyle & wxICON_QUESTION) case wxICON_WARNING:
msStyle |= MB_ICONEXCLAMATION;
break;
case wxICON_QUESTION:
msStyle |= MB_ICONQUESTION; msStyle |= MB_ICONQUESTION;
else if (!(wxStyle & wxICON_NONE)) break;
msStyle |= wxStyle & wxYES ? MB_ICONQUESTION : MB_ICONINFORMATION;
case wxICON_INFORMATION:
msStyle |= MB_ICONINFORMATION;
break;
}
if ( wxStyle & wxSTAY_ON_TOP ) if ( wxStyle & wxSTAY_ON_TOP )
msStyle |= MB_TOPMOST; msStyle |= MB_TOPMOST;

View File

@@ -73,14 +73,25 @@ int wxMessageDialog::ShowModal()
else else
ulStyle = MB_OK; ulStyle = MB_OK;
} }
if (lStyle & wxICON_EXCLAMATION)
ulStyle |= MB_ICONEXCLAMATION; switch ( GetEffectiveIcon() )
else if (lStyle & wxICON_HAND) {
ulStyle |= MB_ICONHAND; case wxICON_ERROR:
else if (lStyle & wxICON_INFORMATION) ulStyle |= MB_ERROR;
ulStyle |= MB_ICONEXCLAMATION; break;
else if (lStyle & wxICON_QUESTION)
ulStyle |= MB_ICONQUESTION; 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) if (hWnd != HWND_DESKTOP)
ulStyle |= MB_APPLMODAL; ulStyle |= MB_APPLMODAL;

View File

@@ -40,17 +40,26 @@ int wxMessageDialog::ShowModal()
const long style = GetMessageDialogStyle(); 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; AlertType alertType = kAlertPlainAlert;
if (style & wxICON_EXCLAMATION)
alertType = kAlertCautionAlert; switch ( GetEffectiveIcon() )
else if (style & wxICON_HAND) {
case wxICON_ERROR:
alertType = kAlertStopAlert; alertType = kAlertStopAlert;
else if (style & wxICON_INFORMATION) break;
alertType = kAlertNoteAlert;
else if (style & wxICON_QUESTION) case wxICON_WARNING:
alertType = kAlertCautionAlert;
break;
case wxICON_QUESTION:
case wxICON_INFORMATION:
alertType = kAlertNoteAlert; alertType = kAlertNoteAlert;
break;
}
// work out what to display // work out what to display

View File

@@ -63,14 +63,25 @@ int wxMessageDialog::ShowModal()
} }
// Add the icon styles // Add the icon styles
if (style & wxICON_EXCLAMATION) switch ( GetEffectiveIcon() )
AlertID=AlertID+0; // Warning {
else if (style & wxICON_HAND) case wxICON_ERROR:
AlertID=AlertID+1; // Error AlertID = AlertID + 1;
else if (style & wxICON_INFORMATION) break;
AlertID=AlertID+2; // Information
else if (style & wxICON_QUESTION) case wxICON_WARNING:
AlertID=AlertID+3; // Confirmation 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. // 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. // So we have to set the title by manipulating the resource.