int wxMessageDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); int resultbutton = wxID_CANCEL; const long style = GetMessageDialogStyle(); wxASSERT_MSG( (style & 0x3F) != wxYES, "this style is not supported on Mac" ); AlertType alertType = kAlertPlainAlert; switch ( GetEffectiveIcon() ) { case wxICON_ERROR: alertType = kAlertStopAlert; break; case wxICON_WARNING: alertType = kAlertCautionAlert; break; case wxICON_QUESTION: case wxICON_INFORMATION: alertType = kAlertNoteAlert; break; } // (the standard alert has two slots [title, text] // for the three wxStrings [caption, message, extended message]) // // if the extended text is empty we use the caption and // the message (for backwards compatibility) // // if the extended text is not empty we ignore the caption // and use the message and the extended message wxString msgtitle,msgtext; if(m_extendedMessage.IsEmpty()) { if ( m_caption.IsEmpty() ) msgtitle = m_message; else { msgtitle = m_caption; msgtext = m_message; } } else { msgtitle = m_message; msgtext = m_extendedMessage; } if ( !wxIsMainThread() ) { CFStringRef defaultButtonTitle = NULL; CFStringRef alternateButtonTitle = NULL; CFStringRef otherButtonTitle = NULL; wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); wxCFStringRef cfText( msgtext, GetFont().GetEncoding() ); wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfOKString( GetOKLabel().c_str() , GetFont().GetEncoding()) ; wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() ); int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; if (style & wxYES_NO) { if ( style & wxNO_DEFAULT ) { defaultButtonTitle = cfNoString; alternateButtonTitle = cfYesString; buttonId[0] = wxID_NO; buttonId[1] = wxID_YES; } else { defaultButtonTitle = cfYesString; alternateButtonTitle = cfNoString; buttonId[0] = wxID_YES; buttonId[1] = wxID_NO; } if (style & wxCANCEL) { otherButtonTitle = cfCancelString; buttonId[2] = wxID_CANCEL; } } else { // the MSW implementation even shows an OK button if it is not specified, we'll do the same buttonId[0] = wxID_OK; // using null as default title does not work on earlier systems defaultButtonTitle = cfOKString; if (style & wxCANCEL) { alternateButtonTitle = cfCancelString; buttonId[1] = wxID_CANCEL; } } CFOptionFlags exitButton; OSStatus err = CFUserNotificationDisplayAlert( 0, alertType, NULL, NULL, NULL, cfTitle, cfText, defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); if (err == noErr) resultbutton = buttonId[exitButton]; } else { short result; AlertStdCFStringAlertParamRec param; wxCFStringRef cfNoString( GetNoLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfYesString( GetYesLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfOKString( GetOKLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfCancelString( GetCancelLabel().c_str(), GetFont().GetEncoding() ); wxCFStringRef cfTitle( msgtitle, GetFont().GetEncoding() ); wxCFStringRef cfText = msgtext.IsEmpty() ? wxCFStringRef() : wxCFStringRef( msgtext, GetFont().GetEncoding() ); param.movable = true; param.flags = 0; param.version = kStdCFStringAlertVersionOne; bool skipDialog = false; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString; param.cancelText = cfCancelString; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString; param.cancelText = NULL; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = 0; } } // the MSW implementation even shows an OK button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // that's a cancel missing param.defaultText = cfOKString; param.cancelText = cfCancelString; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = cfOKString; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef; CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); wxDialog::OSXBeginModalDialog(); RunStandardAlert( alertRef, NULL, &result ); wxDialog::OSXEndModalDialog(); } else { return wxID_CANCEL; } if (style & wxOK) { switch ( result ) { case 1: resultbutton = wxID_OK; break; case 2: // TODO: add Cancel button // if (style & wxCANCEL) // resultbutton = wxID_CANCEL; break; case 3: default: break; } } else if (style & wxYES_NO) { switch ( result ) { case 1: resultbutton = wxID_YES; break; case 2: if (!(style & wxCANCEL)) resultbutton = wxID_CANCEL; break; case 3: resultbutton = wxID_NO; break; default: break; } } } SetReturnCode(resultbutton); return resultbutton; }
bool wxGUIAppTraitsBase::ShowAssertDialog(const wxString& msg) { #if defined(__WXMSW__) || !wxUSE_MSGDLG // under MSW we prefer to use the base class version using ::MessageBox() // even if wxMessageBox() is available because it has less chances to // double fault our app than our wxMessageBox() return wxAppTraitsBase::ShowAssertDialog(msg); #else // wxUSE_MSGDLG wxString msgDlg = msg; #if wxUSE_STACKWALKER // on Unix stack frame generation may take some time, depending on the // size of the executable mainly... warn the user that we are working wxFprintf(stderr, wxT("[Debug] Generating a stack trace... please wait")); fflush(stderr); const wxString stackTrace = GetAssertStackTrace(); if ( !stackTrace.empty() ) msgDlg << _T("\n\nCall stack:\n") << stackTrace; #endif // wxUSE_STACKWALKER // this message is intentionally not translated -- it is for // developpers only msgDlg += wxT("\nDo you want to stop the program?\n") wxT("You can also choose [Cancel] to suppress ") wxT("further warnings."); #ifdef __WXMAC__ // in order to avoid reentrancy problems, use the lowest alert API available CFOptionFlags exitButton; wxMacCFStringHolder cfText(msgDlg); OSStatus err = CFUserNotificationDisplayAlert( 0, kAlertStopAlert, NULL, NULL, NULL, CFSTR("wxWidgets Debug Alert"), cfText, CFSTR("Yes"), CFSTR("No"), CFSTR("Cancel"), &exitButton ); if ( err == noErr ) { switch( exitButton ) { case 0 : // yes wxTrap(); break; case 2 : // cancel // no more asserts return true; case 1 : // no -> nothing to do break ; } } #else switch ( wxMessageBox(msgDlg, wxT("wxWidgets Debug Alert"), wxYES_NO | wxCANCEL | wxICON_STOP ) ) { case wxYES: wxTrap(); break; case wxCANCEL: // no more asserts return true; //case wxNO: nothing to do } #endif return false; #endif // !wxUSE_MSGDLG/wxUSE_MSGDLG }
int wxMessageDialog::ShowModal() { int resultbutton = wxID_CANCEL ; short result ; const long style = GetMessageDialogStyle(); wxASSERT_MSG( ( style & 0x3F ) != wxYES , wxT("this style is not supported on mac") ) ; AlertType alertType = kAlertPlainAlert ; if (style & wxICON_EXCLAMATION) alertType = kAlertNoteAlert ; else if (style & wxICON_HAND) alertType = kAlertStopAlert ; else if (style & wxICON_INFORMATION) alertType = kAlertNoteAlert ; else if (style & wxICON_QUESTION) alertType = kAlertCautionAlert ; #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 ) { AlertStdCFStringAlertParamRec param ; wxMacCFStringHolder cfNoString(_("No") , m_font.GetEncoding()) ; wxMacCFStringHolder cfYesString( _("Yes") , m_font.GetEncoding()) ; wxMacCFStringHolder cfTitle(m_caption , m_font.GetEncoding()); wxMacCFStringHolder cfText(m_message , m_font.GetEncoding()); param.movable = true; param.flags = 0 ; bool skipDialog = false ; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString ; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = cfNoString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString ; param.cancelText = NULL; param.otherText = cfNoString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } // the msw implementation even shows an ok button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // thats a cancel missing param.defaultText = (CFStringRef) kAlertDefaultOKText ; param.cancelText = (CFStringRef) kAlertDefaultCancelText ; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (CFStringRef) kAlertDefaultOKText ; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } /* else { skipDialog = true ; } */ param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef ; CreateStandardAlert( alertType , cfTitle , cfText , ¶m , &alertRef ) ; RunStandardAlert( alertRef , NULL , &result ) ; } if ( skipDialog ) return wxID_CANCEL ; } else #endif { AlertStdAlertParamRec param; Str255 yesPString ; Str255 noPString ; Str255 pascalTitle ; Str255 pascalText ; wxMacStringToPascal( m_caption , pascalTitle ) ; wxMacStringToPascal( _("Yes") , yesPString ) ; wxMacStringToPascal( _("No") , noPString ) ; wxMacStringToPascal( m_message , pascalText ) ; param.movable = true; param.filterProc = NULL ; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = yesPString ; param.cancelText = (StringPtr) kAlertDefaultCancelText; param.otherText = noPString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = yesPString ; param.cancelText = NULL; param.otherText = noPString ; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } else if (style & wxOK) { if (style & wxCANCEL) { param.defaultText = (StringPtr) kAlertDefaultOKText ; param.cancelText = (StringPtr) kAlertDefaultCancelText ; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (StringPtr) kAlertDefaultOKText ; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false ; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } else { return resultbutton ; } param.position = 0; StandardAlert( alertType, pascalTitle, pascalText, ¶m, &result ); } if (style & wxOK) { if (style & wxCANCEL) { //TODO add Cancelbutton switch( result ) { case 1 : resultbutton = wxID_OK ; break ; case 2 : break ; case 3 : break ; } } else { switch( result ) { case 1 : resultbutton = wxID_OK ; break ; case 2 : break ; case 3 : break ; } } } else if (style & wxYES_NO) { if (style & wxCANCEL) { switch( result ) { case 1 : resultbutton = wxID_YES ; break ; case 2 : resultbutton = wxID_CANCEL ; break ; case 3 : resultbutton = wxID_NO ; break ; } } else { switch( result ) { case 1 : resultbutton = wxID_YES ; break ; case 2 : break ; case 3 : resultbutton = wxID_NO ; break ; } } } return resultbutton ; }
int wxMessageDialog::ShowModal() { int resultbutton = wxID_CANCEL; const long style = GetMessageDialogStyle(); wxASSERT_MSG( (style & 0x3F) != wxYES, wxT("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; #if TARGET_API_MAC_OSX if ( !wxIsMainThread() ) { CFStringRef defaultButtonTitle = NULL; CFStringRef alternateButtonTitle = NULL; CFStringRef otherButtonTitle = NULL; wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfOKString( _("OK") , m_font.GetEncoding()) ; wxMacCFStringHolder cfCancelString( _("Cancel"), m_font.GetEncoding() ); int buttonId[4] = { 0, 0, 0, wxID_CANCEL /* time-out */ }; if (style & wxYES_NO) { if ( style & wxNO_DEFAULT ) { defaultButtonTitle = cfNoString; alternateButtonTitle = cfYesString; buttonId[0] = wxID_NO; buttonId[1] = wxID_YES; } else { defaultButtonTitle = cfYesString; alternateButtonTitle = cfNoString; buttonId[0] = wxID_YES; buttonId[1] = wxID_NO; } if (style & wxCANCEL) { otherButtonTitle = cfCancelString; buttonId[2] = wxID_CANCEL; } } else { // the MSW implementation even shows an OK button if it is not specified, we'll do the same buttonId[0] = wxID_OK; // using null as default title does not work on earlier systems defaultButtonTitle = cfOKString; if (style & wxCANCEL) { alternateButtonTitle = cfCancelString; buttonId[1] = wxID_CANCEL; } } CFOptionFlags exitButton; OSStatus err = CFUserNotificationDisplayAlert( 0, alertType, NULL, NULL, NULL, cfTitle, cfText, defaultButtonTitle, alternateButtonTitle, otherButtonTitle, &exitButton ); if (err == noErr) resultbutton = buttonId[exitButton]; } else #endif { short result; AlertStdCFStringAlertParamRec param; wxMacCFStringHolder cfNoString( _("No"), m_font.GetEncoding() ); wxMacCFStringHolder cfYesString( _("Yes"), m_font.GetEncoding() ); wxMacCFStringHolder cfTitle( m_caption, m_font.GetEncoding() ); wxMacCFStringHolder cfText( m_message, m_font.GetEncoding() ); param.movable = true; param.flags = 0; param.version = kStdCFStringAlertVersionOne; bool skipDialog = false; if (style & wxYES_NO) { if (style & wxCANCEL) { param.defaultText = cfYesString; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = kAlertStdAlertCancelButton; } else { param.defaultText = cfYesString; param.cancelText = NULL; param.otherText = cfNoString; param.helpButton = false; param.defaultButton = style & wxNO_DEFAULT ? kAlertStdAlertOtherButton : kAlertStdAlertOKButton; param.cancelButton = 0; } } // the MSW implementation even shows an OK button if it is not specified, we'll do the same else { if (style & wxCANCEL) { // that's a cancel missing param.defaultText = (CFStringRef) kAlertDefaultOKText; param.cancelText = (CFStringRef) kAlertDefaultCancelText; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } else { param.defaultText = (CFStringRef) kAlertDefaultOKText; param.cancelText = NULL; param.otherText = NULL; param.helpButton = false; param.defaultButton = kAlertStdAlertOKButton; param.cancelButton = 0; } } param.position = kWindowDefaultPosition; if ( !skipDialog ) { DialogRef alertRef; CreateStandardAlert( alertType, cfTitle, cfText, ¶m, &alertRef ); RunStandardAlert( alertRef, NULL, &result ); } else { return wxID_CANCEL; } if (style & wxOK) { switch ( result ) { case 1: resultbutton = wxID_OK; break; case 2: // TODO: add Cancel button // if (style & wxCANCEL) // resultbutton = wxID_CANCEL; break; case 3: default: break; } } else if (style & wxYES_NO) { switch ( result ) { case 1: resultbutton = wxID_YES; break; case 2: if (!(style & wxCANCEL)) resultbutton = wxID_CANCEL; break; case 3: resultbutton = wxID_NO; break; default: break; } } } return resultbutton; }