1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/gtk/msgdlg.cpp 
   3 // Purpose:     wxMessageDialog for GTK+2 
   4 // Author:      Vaclav Slavik 
   8 // Copyright:   (c) Vaclav Slavik, 2003 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  19 #if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__) 
  21 #include "wx/msgdlg.h" 
  27 #include "wx/gtk/private.h" 
  30 IMPLEMENT_CLASS(wxMessageDialog
, wxDialog
) 
  32 wxMessageDialog::wxMessageDialog(wxWindow 
*parent
, 
  33                                  const wxString
& message
, 
  34                                  const wxString
& caption
, 
  36                                  const wxPoint
& WXUNUSED(pos
)) 
  40     SetMessageDialogStyle(style
); 
  41     m_parent 
= wxGetTopLevelParent(parent
); 
  43     GtkMessageType type 
= GTK_MESSAGE_ERROR
; 
  44     GtkButtonsType buttons 
= GTK_BUTTONS_OK
; 
  48         buttons 
= GTK_BUTTONS_YES_NO
; 
  54             buttons 
= GTK_BUTTONS_OK_CANCEL
; 
  56             buttons 
= GTK_BUTTONS_OK
; 
  59     if (style 
& wxICON_EXCLAMATION
) 
  60         type 
= GTK_MESSAGE_WARNING
; 
  61     else if (style 
& wxICON_ERROR
) 
  62         type 
= GTK_MESSAGE_ERROR
; 
  63     else if (style 
& wxICON_INFORMATION
) 
  64         type 
= GTK_MESSAGE_INFO
; 
  65     else if (style 
& wxICON_QUESTION
) 
  66         type 
= GTK_MESSAGE_QUESTION
; 
  69         // GTK+ doesn't have a "typeless" msg box, so try to auto detect... 
  70         type 
= style 
& wxYES 
? GTK_MESSAGE_QUESTION 
: GTK_MESSAGE_INFO
; 
  73     m_widget 
= gtk_message_dialog_new(m_parent 
? 
  74                                           GTK_WINDOW(m_parent
->m_widget
) : NULL
, 
  77                                       "%s", (const char*)wxGTK_CONV(m_message
)); 
  78     if (m_caption 
!= wxMessageBoxCaptionStr
) 
  79         gtk_window_set_title(GTK_WINDOW(m_widget
), wxGTK_CONV(m_caption
)); 
  84             gtk_dialog_add_button(GTK_DIALOG(m_widget
), GTK_STOCK_CANCEL
, 
  86         if (style 
& wxNO_DEFAULT
) 
  87             gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_NO
); 
  89             gtk_dialog_set_default_response(GTK_DIALOG(m_widget
), GTK_RESPONSE_YES
); 
  93         gtk_window_set_transient_for(GTK_WINDOW(m_widget
), 
  94                                      GTK_WINDOW(m_parent
->m_widget
)); 
  97 wxMessageDialog::~wxMessageDialog() 
 101 int wxMessageDialog::ShowModal() 
 103     // This should be necessary, but otherwise the 
 104     // parent TLW will disappear.. 
 106         gtk_window_present( GTK_WINDOW(m_parent
->m_widget
) ); 
 108     gint result 
= gtk_dialog_run(GTK_DIALOG(m_widget
)); 
 109     gtk_widget_destroy(m_widget
); 
 115             wxFAIL_MSG(_T("unexpected GtkMessageDialog return code")); 
 118         case GTK_RESPONSE_CANCEL
: 
 119         case GTK_RESPONSE_DELETE_EVENT
: 
 120         case GTK_RESPONSE_CLOSE
: 
 122         case GTK_RESPONSE_OK
: 
 124         case GTK_RESPONSE_YES
: 
 126         case GTK_RESPONSE_NO
: 
 132 #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)