1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/msgdlg.cpp 
   3 // Purpose:     wxMessageDialog 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  14 #include "wx/msgdlg.h" 
  21 #include "wx/mac/uma.h" 
  24 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
) 
  27 wxMessageDialog::wxMessageDialog(wxWindow 
*parent
, 
  28                                  const wxString
& message
, 
  29                                  const wxString
& caption
, 
  32                : wxMessageDialogBase(parent
, message
, caption
, style
) 
  37     m_cancel 
= _("Cancel"); 
  40 bool wxMessageDialog::SetYesNoLabels(const wxString
& yes
,const wxString
& no
) 
  47 bool wxMessageDialog::SetYesNoCancelLabels(const wxString
& yes
, const wxString
& no
, const wxString
& cancel
) 
  55 bool wxMessageDialog::SetOKLabel(const wxString
& ok
) 
  61 bool wxMessageDialog::SetOKCancelLabels(const wxString
& ok
, const wxString
& cancel
) 
  68 int wxMessageDialog::ShowModal() 
  70     int resultbutton 
= wxID_CANCEL
; 
  72     const long style 
= GetMessageDialogStyle(); 
  74     wxASSERT_MSG( (style 
& 0x3F) != wxYES
, wxT("this style is not supported on Mac") ); 
  76     AlertType alertType 
= kAlertPlainAlert
; 
  77     if (style 
& wxICON_EXCLAMATION
) 
  78         alertType 
= kAlertNoteAlert
; 
  79     else if (style 
& wxICON_HAND
) 
  80         alertType 
= kAlertStopAlert
; 
  81     else if (style 
& wxICON_INFORMATION
) 
  82         alertType 
= kAlertNoteAlert
; 
  83     else if (style 
& wxICON_QUESTION
) 
  84         alertType 
= kAlertCautionAlert
; 
  87     // work out what to display 
  88     // if the extended text is empty then we use the caption as the title 
  89     // and the message as the text (for backwards compatibility) 
  90     // but if the extended message is not empty then we use the message as the title 
  91     // and the extended message as the text because that makes more sense 
  93     wxString msgtitle
,msgtext
; 
  94     if(m_extendedMessage
.IsEmpty()) 
 101         msgtitle 
= m_message
; 
 102         msgtext  
= m_extendedMessage
; 
 106 #if TARGET_API_MAC_OSX 
 107     if ( !wxIsMainThread() ) 
 109         CFStringRef defaultButtonTitle 
= NULL
; 
 110         CFStringRef alternateButtonTitle 
= NULL
; 
 111         CFStringRef otherButtonTitle 
= NULL
; 
 113         wxMacCFStringHolder 
cfTitle( msgtitle
, m_font
.GetEncoding() ); 
 114         wxMacCFStringHolder 
cfText( msgtext
, m_font
.GetEncoding() ); 
 116         wxMacCFStringHolder 
cfNoString( m_no
.c_str(), m_font
.GetEncoding() ); 
 117         wxMacCFStringHolder 
cfYesString( m_yes
.c_str(), m_font
.GetEncoding() ); 
 118         wxMacCFStringHolder 
cfOKString( m_ok
.c_str() , m_font
.GetEncoding()) ; 
 119         wxMacCFStringHolder 
cfCancelString( m_cancel
.c_str(), m_font
.GetEncoding() ); 
 121         int buttonId
[4] = { 0, 0, 0, wxID_CANCEL 
/* time-out */ }; 
 123         if (style 
& wxYES_NO
) 
 125             if ( style 
& wxNO_DEFAULT 
) 
 127                 defaultButtonTitle 
= cfNoString
; 
 128                 alternateButtonTitle 
= cfYesString
; 
 129                 buttonId
[0] = wxID_NO
; 
 130                 buttonId
[1] = wxID_YES
; 
 134                 defaultButtonTitle 
= cfYesString
; 
 135                 alternateButtonTitle 
= cfNoString
; 
 136                 buttonId
[0] = wxID_YES
; 
 137                 buttonId
[1] = wxID_NO
; 
 139             if (style 
& wxCANCEL
) 
 141                 otherButtonTitle 
= cfCancelString
; 
 142                 buttonId
[2] = wxID_CANCEL
; 
 147             // the MSW implementation even shows an OK button if it is not specified, we'll do the same 
 148             buttonId
[0] = wxID_OK
; 
 149             // using null as default title does not work on earlier systems 
 150             defaultButtonTitle 
= cfOKString
; 
 151             if (style 
& wxCANCEL
) 
 153                 alternateButtonTitle 
= cfCancelString
; 
 154                 buttonId
[1] = wxID_CANCEL
; 
 158         CFOptionFlags exitButton
; 
 159         OSStatus err 
= CFUserNotificationDisplayAlert( 
 160             0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
, 
 161             defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton 
); 
 163             resultbutton 
= buttonId
[exitButton
]; 
 170         AlertStdCFStringAlertParamRec param
; 
 171         wxMacCFStringHolder 
cfNoString( m_no
.c_str(), m_font
.GetEncoding() ); 
 172         wxMacCFStringHolder 
cfYesString( m_yes
.c_str(), m_font
.GetEncoding() ); 
 173         wxMacCFStringHolder 
cfOKString( m_ok
.c_str(), m_font
.GetEncoding() ); 
 174         wxMacCFStringHolder 
cfCancelString( m_cancel
.c_str(), m_font
.GetEncoding() ); 
 176         wxMacCFStringHolder 
cfTitle( msgtitle
, m_font
.GetEncoding() ); 
 177         wxMacCFStringHolder 
cfText( msgtext
, m_font
.GetEncoding() ); 
 179         param
.movable 
= true; 
 181         param
.version 
= kStdCFStringAlertVersionOne
; 
 183         bool skipDialog 
= false; 
 185         if (style 
& wxYES_NO
) 
 187             if (style 
& wxCANCEL
) 
 189                 param
.defaultText 
= cfYesString
; 
 190                 param
.cancelText 
= cfCancelString
; 
 191                 param
.otherText 
= cfNoString
; 
 192                 param
.helpButton 
= false; 
 193                 param
.defaultButton 
= style 
& wxNO_DEFAULT 
? kAlertStdAlertOtherButton 
: kAlertStdAlertOKButton
; 
 194                 param
.cancelButton 
= kAlertStdAlertCancelButton
; 
 198                 param
.defaultText 
= cfYesString
; 
 199                 param
.cancelText 
= NULL
; 
 200                 param
.otherText 
= cfNoString
; 
 201                 param
.helpButton 
= false; 
 202                 param
.defaultButton 
= style 
& wxNO_DEFAULT 
? kAlertStdAlertOtherButton 
: kAlertStdAlertOKButton
; 
 203                 param
.cancelButton 
= 0; 
 206         // the MSW implementation even shows an OK button if it is not specified, we'll do the same 
 209             if (style 
& wxCANCEL
) 
 211                 // that's a cancel missing 
 212                 param
.defaultText 
= cfOKString
; 
 213                 param
.cancelText 
= cfCancelString
; 
 214                 param
.otherText 
= NULL
; 
 215                 param
.helpButton 
= false; 
 216                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 217                 param
.cancelButton 
= 0; 
 221                 param
.defaultText 
= cfOKString
; 
 222                 param
.cancelText 
= NULL
; 
 223                 param
.otherText 
= NULL
; 
 224                 param
.helpButton 
= false; 
 225                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 226                 param
.cancelButton 
= 0; 
 230         param
.position 
= kWindowDefaultPosition
; 
 234             CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef 
); 
 235             RunStandardAlert( alertRef
, NULL
, &result 
); 
 247                 resultbutton 
= wxID_OK
; 
 251                 // TODO: add Cancel button 
 252                 // if (style & wxCANCEL) 
 253                 //     resultbutton = wxID_CANCEL; 
 261         else if (style 
& wxYES_NO
) 
 266                 resultbutton 
= wxID_YES
; 
 270                 if (!(style 
& wxCANCEL
)) 
 271                     resultbutton 
= wxID_CANCEL
; 
 275                 resultbutton 
= wxID_NO
;