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:
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

View 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];

View 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)

View 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;

View 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;

View 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

View 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.