1 ///////////////////////////////////////////////////////////////////////////// 
   3 // Purpose:     wxMessageDialog 
   4 // Author:      Julian Smart 
   8 // Copyright:   (c) Julian Smart 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  17     #pragma implementation "msgdlg.h" 
  20 // ---------------------------------------------------------------------------- 
  22 // ---------------------------------------------------------------------------- 
  25 #define XtDisplay XTDISPLAY 
  26 #pragma message disable nosimpint 
  27 #include <wx/vms_x_fix.h> 
  32 #include <Xm/MessageB.h> 
  34 #pragma message enable nosimpint 
  39 #include "wx/motif/msgdlg.h" 
  40 #include "wx/motif/private.h" 
  42 // ---------------------------------------------------------------------------- 
  44 // ---------------------------------------------------------------------------- 
  46     IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
) 
  48 // ============================================================================ 
  50 // ============================================================================ 
  52 // ---------------------------------------------------------------------------- 
  53 // the callbacks for message box buttons 
  54 // ---------------------------------------------------------------------------- 
  57 static void msgboxCallBack(Widget w
, void* client_data
, int id
) 
  62     wxMessageDialog 
*dlg 
= (wxMessageDialog 
*)client_data
; 
  66 static void msgboxCallBackOk(Widget w
, 
  68                              XmAnyCallbackStruct 
*WXUNUSED(call_data
)) 
  70     msgboxCallBack(w
, client_data
, wxID_OK
); 
  73 static void msgboxCallBackCancel(Widget w
, 
  75                                  XmAnyCallbackStruct 
*WXUNUSED(call_data
)) 
  77     msgboxCallBack(w
, client_data
, wxID_CANCEL
); 
  80 static void msgboxCallBackHelp(Widget w
, 
  82                                XmAnyCallbackStruct 
*WXUNUSED(call_data
)) 
  84     msgboxCallBack(w
, client_data
, wxID_HELP
); 
  87 static void msgboxCallBackClose(Widget w
, 
  89                                 XmAnyCallbackStruct 
*WXUNUSED(call_data
)) 
  91     msgboxCallBack(w
, client_data
, wxID_CANCEL
); 
  94 // ---------------------------------------------------------------------------- 
  96 // ---------------------------------------------------------------------------- 
  98 wxMessageDialog::wxMessageDialog(wxWindow 
*parent
, 
  99                                  const wxString
& message
, 
 100                                  const wxString
& caption
, 
 102                                  const wxPoint
& WXUNUSED(pos
)) 
 106     m_dialogStyle 
= style
; 
 110 int wxMessageDialog::ShowModal() 
 112     Widget (*dialogCreateFunction
)(Widget
, String
, ArgList
, Cardinal
) = NULL
; 
 113     if ( m_dialogStyle 
& wxYES_NO 
) 
 115         // if we have [Yes], it must be a question 
 116         dialogCreateFunction 
= XmCreateQuestionDialog
; 
 118     else if ( m_dialogStyle 
& wxICON_STOP 
) 
 120         // error dialog is the one with error icon... 
 121         dialogCreateFunction 
= XmCreateErrorDialog
; 
 123     else if ( m_dialogStyle 
& wxICON_EXCLAMATION 
) 
 125         // ...and the warning dialog too 
 126         dialogCreateFunction 
= XmCreateWarningDialog
; 
 130         // finally, use the info dialog by default 
 131         dialogCreateFunction 
= XmCreateInformationDialog
; 
 134     Widget wParent 
= m_parent 
? GetWidget(m_parent
) : (Widget
) 0; 
 137         wxWindow 
*window 
= wxTheApp
->GetTopWindow(); 
 140             wxFAIL_MSG("can't show message box without parent window"); 
 145         wParent 
= GetWidget(window
); 
 148     // prepare the arg list 
 152     wxXmString 
text(m_message
); 
 153     wxXmString 
title(m_caption
); 
 154     XtSetArg(args
[ac
], XmNmessageString
, text()); ac
++; 
 155     XtSetArg(args
[ac
], XmNdialogTitle
, title()); ac
++; 
 157     wxComputeColours (XtDisplay(wParent
), & m_backgroundColour
, 
 160     XtSetArg(args
[ac
], XmNbackground
, g_itemColors
[wxBACK_INDEX
].pixel
); ac
++; 
 161     XtSetArg(args
[ac
], XmNtopShadowColor
, g_itemColors
[wxTOPS_INDEX
].pixel
); ac
++; 
 162     XtSetArg(args
[ac
], XmNbottomShadowColor
, g_itemColors
[wxBOTS_INDEX
].pixel
); ac
++; 
 163     XtSetArg(args
[ac
], XmNforeground
, g_itemColors
[wxFORE_INDEX
].pixel
); ac
++; 
 165     // do create message box 
 167     Widget wMsgBox 
= (*dialogCreateFunction
)(wParent
, "", args
, ac
); 
 169     wxCHECK_MSG( wMsgBox
, wxID_CANCEL
, "msg box creation failed" ); 
 171     // get the buttons which we might either remove or rename 
 172     // depending on the requested style 
 174     Widget wBtnOk 
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_OK_BUTTON
); 
 175     Widget wBtnHelp 
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_HELP_BUTTON
); 
 176     Widget wBtnCancel 
= XmMessageBoxGetChild(wMsgBox
, XmDIALOG_CANCEL_BUTTON
); 
 178     if ( m_dialogStyle 
& wxYES_NO 
) 
 180         wxXmString 
yes(_("Yes")), no(_("No")), cancel(_("Cancel"));             
 182         if ( m_dialogStyle 
& wxCANCEL 
) 
 184             // use the cancel button for No and the help button for 
 187             XtVaSetValues(wBtnOk
, XmNlabelString
, yes(), NULL
); 
 188             XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
); 
 189             XtVaSetValues(wBtnHelp
, XmNlabelString
, cancel(), NULL
); 
 193             // no cancel button requested... 
 194             // remove the help button and use cancel for no 
 196             XtVaSetValues(wBtnCancel
, XmNlabelString
, no(), NULL
); 
 197             XtUnmanageChild(wBtnHelp
); 
 202         // remove the help button and the cancel button (unless it was 
 205         XtUnmanageChild(wBtnHelp
); 
 206         if ( !(m_dialogStyle 
& wxCANCEL 
) ) XtUnmanageChild(wBtnCancel
); 
 209     // set the callbacks for the message box buttons 
 210     XtAddCallback(wMsgBox
, XmNokCallback
, 
 211                   (XtCallbackProc
)msgboxCallBackOk
, (XtPointer
)this); 
 212     XtAddCallback(wMsgBox
, XmNcancelCallback
, 
 213                   (XtCallbackProc
)msgboxCallBackCancel
, (XtPointer
)this); 
 214     XtAddCallback(wMsgBox
, XmNhelpCallback
, 
 215                   (XtCallbackProc
)msgboxCallBackHelp
, (XtPointer
)this); 
 216     XtAddCallback(wMsgBox
, XmNunmapCallback
, 
 217                   (XtCallbackProc
)msgboxCallBackClose
, (XtPointer
)this); 
 219     // show it as a modal dialog 
 220     XtManageChild(wMsgBox
); 
 221     XtAddGrab(wMsgBox
, True
, False
); 
 223     // the m_result will be changed when message box goes away 
 226     // local message loop 
 227     XtAppContext context 
= XtWidgetToApplicationContext(wParent
); 
 229     while ( m_result 
== -1 ) 
 231         XtAppNextEvent(context
, &event
); 
 232         XtDispatchEvent(&event
); 
 235     // translate the result if necessary 
 236     if ( m_dialogStyle 
& wxYES_NO 
) 
 238         if ( m_result 
== wxID_OK 
) 
 240         else if ( m_result 
== wxID_CANCEL 
) 
 242         else if ( m_result 
== wxID_HELP 
) 
 243             m_result 
= wxID_CANCEL
;