1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxMessageDialog 
   8 // Copyright:   (c) AUTHOR 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  13 #pragma implementation "msgdlg.h" 
  16 #include "wx/msgdlg.h" 
  17 #include "wx/mac/uma.h" 
  19 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
) 
  21 #define kMacOKAlertResourceID 128 
  22 #define kMacYesNoAlertResourceID 129 
  23 #define kMacYesNoCancelAlertResourceID 130 
  24 #define kMacNoYesAlertResourceID 131 
  25 #define kMacNoYesCancelAlertResourceID 132 
  29 void wxMacConvertNewlines( const char *source 
, char * destination 
) 
  31         const char *s 
= source 
; 
  32         char *d 
= destination 
; 
  56 wxMessageDialog::wxMessageDialog(wxWindow 
*parent
, const wxString
& message
, const wxString
& caption
, 
  57         long style
, const wxPoint
& pos
) 
  61     m_dialogStyle 
= style
; 
  65 int wxMessageDialog::ShowModal() 
  67         int resultbutton 
= wxID_CANCEL 
; 
  74         if (wxApp::s_macDefaultEncodingIsPC
) 
  76                 strcpy( (char*) pascalTitle 
, wxMacMakeMacStringFromPC( m_caption 
) ) ; 
  77                 strcpy( (char*) pascalText 
, wxMacMakeMacStringFromPC( m_message
) ) ; 
  81                 strcpy( (char*) pascalTitle 
, m_caption 
) ; 
  82                 strcpy( (char*) pascalText 
, m_message 
) ; 
  85         c2pstr( (char*) pascalTitle 
) ; 
  86         wxMacConvertNewlines( (char*)pascalText 
,(char*) pascalText
) ; 
  87         c2pstr( (char*) pascalText 
) ; 
  89         wxASSERT_MSG( ( m_dialogStyle 
& 0x3F ) != wxYES 
, "this style is not supported on mac" ) ; 
  91         if ( !UMAHasAppearance() ) 
  95           if (m_dialogStyle 
& wxYES_NO
) 
  97             if (m_dialogStyle 
& wxCANCEL
) 
  98               resourceID 
= kMacYesNoCancelAlertResourceID
; 
 100               resourceID 
= kMacYesNoAlertResourceID 
+ language 
* 10 ; 
 102           else if (m_dialogStyle 
& wxOK
) 
 104             if (m_dialogStyle 
& wxCANCEL
) 
 105               resourceID 
= kMacOKAlertResourceID
; // wrong 
 107               resourceID 
= kMacOKAlertResourceID
; 
 111                         return resultbutton 
; 
 115             msStyle |= MB_APPLMODAL; 
 117             msStyle |= MB_TASKMODAL; 
 120                 ParamText( pascalTitle 
, pascalText 
, NULL 
, NULL 
) ; 
 122           if (m_dialogStyle 
& wxICON_EXCLAMATION
) 
 123                                 result 
= Alert( resourceID 
, NULL 
) ; 
 124           else if (m_dialogStyle 
& wxICON_HAND
) 
 125                         result 
= StopAlert( resourceID 
, NULL 
) ; 
 126           else if (m_dialogStyle 
& wxICON_INFORMATION
) 
 127                                 result 
= NoteAlert( resourceID 
, NULL 
) ; 
 128           else if (m_dialogStyle 
& wxICON_QUESTION
) 
 129                                 result 
= CautionAlert( resourceID 
, NULL 
) ; 
 131                                 result 
= Alert( resourceID 
, NULL 
) ; 
 133                 resultbutton 
= result 
; 
 135           if (m_dialogStyle 
& wxYES_NO
) 
 137             if (m_dialogStyle 
& wxCANCEL
) 
 142                                                 resultbutton 
= wxID_YES 
; 
 145                                                 resultbutton 
= wxID_NO 
; 
 148                                                 resultbutton 
= wxID_CANCEL 
; 
 157                                                 resultbutton 
= wxID_YES 
; 
 160                                                 resultbutton 
= wxID_NO 
; 
 170                 AlertStdAlertParamRec   param
; 
 172                 param
.movable           
= true; 
 173                 param
.filterProc        
= NULL 
; 
 175           if (m_dialogStyle 
& wxYES_NO
) 
 177             if (m_dialogStyle 
& wxCANCEL
) 
 179                                 param
.defaultText       
= "\pYes" ; 
 180                                 param
.cancelText        
= (StringPtr
) kAlertDefaultCancelText
; 
 181                                 param
.otherText         
= "\pNo"; 
 182                                 param
.helpButton        
= false ; 
 183                                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 184                                 param
.cancelButton      
= kAlertStdAlertCancelButton
; 
 188                                 param
.defaultText       
= "\pYes" ; 
 189                                 param
.cancelText        
= NULL
; 
 190                                 param
.otherText         
= "\pNo"; 
 191                                 param
.helpButton        
= false ; 
 192                                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 193                                 param
.cancelButton      
= 0; 
 196           else if (m_dialogStyle 
& wxOK
) 
 198             if (m_dialogStyle 
& wxCANCEL
) 
 200                 // thats a cancel missing 
 201                                 param
.defaultText       
= (StringPtr
) kAlertDefaultOKText 
; 
 202                                 param
.cancelText        
= NULL
; 
 203                                 param
.otherText         
= NULL
; 
 204                                 param
.helpButton        
= false ; 
 205                                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 206                                 param
.cancelButton      
= 0; 
 210                                 param
.defaultText       
= (StringPtr
) kAlertDefaultOKText 
; 
 211                                 param
.cancelText        
= NULL
; 
 212                                 param
.otherText         
= NULL
; 
 213                                 param
.helpButton        
= false ; 
 214                                 param
.defaultButton 
= kAlertStdAlertOKButton
; 
 215                                 param
.cancelButton      
= 0; 
 220                         return resultbutton 
; 
 225           if (m_dialogStyle 
& wxICON_EXCLAMATION
) 
 226                                 StandardAlert( kAlertNoteAlert
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 227           else if (m_dialogStyle 
& wxICON_HAND
) 
 228                                 StandardAlert( kAlertStopAlert
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 229           else if (m_dialogStyle 
& wxICON_INFORMATION
) 
 230                         StandardAlert( kAlertNoteAlert
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 231           else if (m_dialogStyle 
& wxICON_QUESTION
) 
 232                                 StandardAlert( kAlertCautionAlert
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 234                                 StandardAlert( kAlertPlainAlert
, pascalTitle
, pascalText
, ¶m
, &result 
); 
 236                 if (m_dialogStyle 
& wxOK
) 
 238             if (m_dialogStyle 
& wxCANCEL
)                                
 240                 //TODO add Cancelbutton 
 244                                                 resultbutton 
= wxID_OK 
; 
 257                                                 resultbutton 
= wxID_OK 
; 
 266           else if (m_dialogStyle 
& wxYES_NO
) 
 268             if (m_dialogStyle 
& wxCANCEL
) 
 273                                                 resultbutton 
= wxID_YES 
; 
 276                                                 resultbutton 
= wxID_CANCEL 
; 
 279                                                 resultbutton 
= wxID_NO 
; 
 288                                                 resultbutton 
= wxID_YES 
; 
 293                                                 resultbutton 
= wxID_NO 
; 
 299         return resultbutton 
;