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( 
  28     wxWindow 
*parent
, const wxString
& message
, const wxString
& caption
, 
  29     long style
, const wxPoint
& pos 
) 
  34     SetMessageDialogStyle(style
); 
  37 int wxMessageDialog::ShowModal() 
  39     int resultbutton 
= wxID_CANCEL
; 
  41     const long style 
= GetMessageDialogStyle(); 
  43     wxASSERT_MSG( (style 
& 0x3F) != wxYES
, wxT("this style is not supported on Mac") ); 
  45     AlertType alertType 
= kAlertPlainAlert
; 
  46     if (style 
& wxICON_EXCLAMATION
) 
  47         alertType 
= kAlertNoteAlert
; 
  48     else if (style 
& wxICON_HAND
) 
  49         alertType 
= kAlertStopAlert
; 
  50     else if (style 
& wxICON_INFORMATION
) 
  51         alertType 
= kAlertNoteAlert
; 
  52     else if (style 
& wxICON_QUESTION
) 
  53         alertType 
= kAlertCautionAlert
; 
  55 #if TARGET_API_MAC_OSX 
  56     CFStringRef defaultButtonTitle 
= NULL
; 
  57     CFStringRef alternateButtonTitle 
= NULL
; 
  58     CFStringRef otherButtonTitle 
= NULL
; 
  60     wxMacCFStringHolder 
cfTitle( m_caption
, m_font
.GetEncoding() ); 
  61     wxMacCFStringHolder 
cfText( m_message
, m_font
.GetEncoding() ); 
  63     wxMacCFStringHolder 
cfNoString( wxT("No"), m_font
.GetEncoding() ); 
  64     wxMacCFStringHolder 
cfYesString( wxT("Yes"), m_font
.GetEncoding() ); 
  65     wxMacCFStringHolder 
cfCancelString( wxT("Cancel"), m_font
.GetEncoding() ); 
  67     int buttonId
[4] = { 0, 0, 0, wxID_CANCEL 
/* time-out */ }; 
  71         if ( style 
& wxNO_DEFAULT 
) 
  73             defaultButtonTitle 
= cfNoString
; 
  74             alternateButtonTitle 
= cfYesString
; 
  75             buttonId
[0] = wxID_NO
; 
  76             buttonId
[1] = wxID_YES
; 
  80             defaultButtonTitle 
= cfYesString
; 
  81             alternateButtonTitle 
= cfNoString
; 
  82             buttonId
[0] = wxID_YES
; 
  83             buttonId
[1] = wxID_NO
; 
  87             otherButtonTitle 
= cfCancelString
; 
  88             buttonId
[2] = wxID_CANCEL
; 
  93         // the MSW implementation even shows an OK button if it is not specified, we'll do the same 
  94         buttonId
[0] = wxID_OK
; 
  97             alternateButtonTitle 
= cfCancelString
; 
  98             buttonId
[1] = wxID_CANCEL
; 
 102     CFOptionFlags exitButton
; 
 103     OSStatus err 
= CFUserNotificationDisplayAlert( 
 104         0, alertType
, NULL
, NULL
, NULL
, cfTitle
, cfText
, 
 105         defaultButtonTitle
, alternateButtonTitle
, otherButtonTitle
, &exitButton 
); 
 107         resultbutton 
= buttonId
[exitButton
]; 
 113     if ( UMAGetSystemVersion() >= 0x1000 ) 
 115         AlertStdCFStringAlertParamRec param
; 
 116         wxMacCFStringHolder 
cfNoString( wxT("No"), m_font
.GetEncoding() ); 
 117         wxMacCFStringHolder 
cfYesString( wxT("Yes"), m_font
.GetEncoding() ); 
 119         wxMacCFStringHolder 
cfTitle( m_caption
, m_font
.GetEncoding() ); 
 120         wxMacCFStringHolder 
cfText( m_message
, m_font
.GetEncoding() ); 
 122         param
.movable 
= true; 
 124         param
.version 
= kStdCFStringAlertVersionOne
; 
 126         bool skipDialog 
= false; 
 128         if (style 
& wxYES_NO
) 
 130             if (style 
& wxCANCEL
) 
 132                 param
.defaultText 
= cfYesString
; 
 133                 param
.cancelText 
= (CFStringRef
) kAlertDefaultCancelText
; 
 134                 param
.otherText 
= cfNoString
; 
 135                 param
.helpButton 
= false; 
 136                 param
.defaultButton 
= style 
& wxNO_DEFAULT 
? kAlertStdAlertOtherButton 
: kAlertStdAlertOKButton
; 
 137                 param
.cancelButton 
= kAlertStdAlertCancelButton
; 
 141                 param
.defaultText 
= cfYesString
; 
 142                 param
.cancelText 
= NULL
; 
 143                 param
.otherText 
= cfNoString
; 
 144                 param
.helpButton 
= false; 
 145                 param
.defaultButton 
= style 
& wxNO_DEFAULT 
? kAlertStdAlertOtherButton 
: kAlertStdAlertOKButton
; 
 146                 param
.cancelButton 
= 0; 
 149         // the MSW implementation even shows an OK button if it is not specified, we'll do the same 
 152             if (style 
& wxCANCEL
) 
 154                 // that's a cancel missing 
 155                 param
.defaultText 
= (CFStringRef
) kAlertDefaultOKText
; 
 156                 param
.cancelText 
= (CFStringRef
) kAlertDefaultCancelText
; 
 157                 param
.otherText 
= NULL
; 
 158                 param
.helpButton 
= false; 
 159                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 160                 param
.cancelButton 
= 0; 
 164                 param
.defaultText 
= (CFStringRef
) kAlertDefaultOKText
; 
 165                 param
.cancelText 
= NULL
; 
 166                 param
.otherText 
= NULL
; 
 167                 param
.helpButton 
= false; 
 168                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 169                 param
.cancelButton 
= 0; 
 179         param
.position 
= kWindowDefaultPosition
; 
 183             CreateStandardAlert( alertType
, cfTitle
, cfText
, ¶m
, &alertRef 
); 
 184             RunStandardAlert( alertRef
, NULL
, &result 
); 
 194         AlertStdAlertParamRec param
; 
 195         Str255 yesPString
, noPString
; 
 196         Str255 pascalTitle
, pascalText
; 
 198         wxMacStringToPascal( m_caption
, pascalTitle 
); 
 199         wxMacStringToPascal( wxT("Yes"), yesPString 
); 
 200         wxMacStringToPascal( wxT("No"), noPString 
); 
 201         wxMacStringToPascal( m_message
, pascalText 
); 
 203         param
.movable 
= true; 
 204         param
.filterProc 
= NULL
; 
 206         if (style 
& wxYES_NO
) 
 208             if (style 
& wxCANCEL
) 
 210                 param
.defaultText 
= yesPString
; 
 211                 param
.cancelText 
= (StringPtr
) kAlertDefaultCancelText
; 
 212                 param
.otherText 
= noPString
; 
 213                 param
.helpButton 
= false; 
 214                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 215                 param
.cancelButton 
= kAlertStdAlertCancelButton
; 
 219                 param
.defaultText 
= yesPString
; 
 220                 param
.cancelText 
= NULL
; 
 221                 param
.otherText 
= noPString
; 
 222                 param
.helpButton 
= false; 
 223                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 224                 param
.cancelButton 
= 0; 
 227         else if (style 
& wxOK
) 
 229             if (style 
& wxCANCEL
) 
 231                 param
.defaultText 
= (StringPtr
) kAlertDefaultOKText
; 
 232                 param
.cancelText 
= (StringPtr
) kAlertDefaultCancelText
; 
 233                 param
.otherText 
= NULL
; 
 234                 param
.helpButton 
= false; 
 235                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 236                 param
.cancelButton 
= 0; 
 240                 param
.defaultText 
= (StringPtr
) kAlertDefaultOKText
; 
 241                 param
.cancelText 
= NULL
; 
 242                 param
.otherText 
= NULL
; 
 243                 param
.helpButton 
= false; 
 244                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 245                 param
.cancelButton 
= 0; 
 254         StandardAlert( alertType
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 262             resultbutton 
= wxID_OK
; 
 266             // TODO: add Cancel button 
 267             // if (style & wxCANCEL) 
 268             //     resultbutton = wxID_CANCEL; 
 276     else if (style 
& wxYES_NO
) 
 281             resultbutton 
= wxID_YES
; 
 285             if (!(style 
& wxCANCEL
)) 
 286                 resultbutton 
= wxID_CANCEL
; 
 290             resultbutton 
= wxID_NO
;