]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
wxOS2 warning fixes after daily build log.
[wxWidgets.git] / src / gtk / msgdlg.cpp
CommitLineData
13a7abf9 1/////////////////////////////////////////////////////////////////////////////
e5b50758 2// Name: src/gtk/msgdlg.cpp
13a7abf9
VS
3// Purpose: wxMessageDialog for GTK+2
4// Author: Vaclav Slavik
5// Modified by:
6// Created: 2003/02/28
7// RCS-ID: $Id$
8// Copyright: (c) Vaclav Slavik, 2003
e5b50758 9// Licence: wxWindows licence
13a7abf9
VS
10/////////////////////////////////////////////////////////////////////////////
11
13a7abf9
VS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
47e118ba 19#if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
13a7abf9 20
e1bf3ad3 21#include "wx/msgdlg.h"
13a7abf9
VS
22#include "wx/gtk/private.h"
23#include <gtk/gtk.h>
24
13a7abf9
VS
25#include "wx/intl.h"
26
27IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
28
29wxMessageDialog::wxMessageDialog(wxWindow *parent,
30 const wxString& message,
31 const wxString& caption,
32 long style,
33 const wxPoint& WXUNUSED(pos))
34{
35 m_caption = caption;
36 m_message = message;
e5b50758 37 SetMessageDialogStyle(style);
1840af03 38 m_parent = wxGetTopLevelParent(parent);
13a7abf9 39
b63b07a8 40 GtkMessageType type = GTK_MESSAGE_ERROR;
13a7abf9 41 GtkButtonsType buttons = GTK_BUTTONS_OK;
b63b07a8 42
e5b50758 43 if (style & wxYES_NO)
13a7abf9
VS
44 {
45 buttons = GTK_BUTTONS_YES_NO;
46 }
47
e5b50758 48 if (style & wxOK)
13a7abf9 49 {
e5b50758 50 if (style & wxCANCEL)
13a7abf9
VS
51 buttons = GTK_BUTTONS_OK_CANCEL;
52 else
53 buttons = GTK_BUTTONS_OK;
54 }
b63b07a8 55
e5b50758 56 if (style & wxICON_EXCLAMATION)
13a7abf9 57 type = GTK_MESSAGE_WARNING;
e5b50758 58 else if (style & wxICON_ERROR)
13a7abf9 59 type = GTK_MESSAGE_ERROR;
e5b50758 60 else if (style & wxICON_INFORMATION)
13a7abf9 61 type = GTK_MESSAGE_INFO;
e5b50758 62 else if (style & wxICON_QUESTION)
13a7abf9 63 type = GTK_MESSAGE_QUESTION;
b63b07a8 64 else
e0ae1a0a
VZ
65 {
66 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
e5b50758 67 type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
e0ae1a0a 68 }
13a7abf9 69
b2ce5e1b
RD
70 m_widget = gtk_message_dialog_new(m_parent ?
71 GTK_WINDOW(m_parent->m_widget) : NULL,
72 GTK_DIALOG_MODAL,
73 type, buttons,
74 "%s", (const char*)wxGTK_CONV(m_message));
13a7abf9 75 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 76 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 77
e5b50758 78 if (style & wxYES_NO)
13a7abf9 79 {
e5b50758 80 if (style & wxCANCEL)
b2ce5e1b 81 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
13a7abf9 82 GTK_RESPONSE_CANCEL);
e5b50758 83 if (style & wxNO_DEFAULT)
b2ce5e1b 84 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
13a7abf9 85 else
b2ce5e1b 86 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
13a7abf9 87 }
633c71ef 88
3b439e60 89 if (m_parent)
633c71ef
VS
90 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
91 GTK_WINDOW(m_parent->m_widget));
b2ce5e1b 92}
e5b50758 93
f1dec25f
RR
94wxMessageDialog::~wxMessageDialog()
95{
f1dec25f
RR
96}
97
b2ce5e1b
RD
98int wxMessageDialog::ShowModal()
99{
3b439e60
RR
100 // This should be necessary, but otherwise the
101 // parent TLW will disappear..
102 if (m_parent)
103 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 104
b2ce5e1b
RD
105 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
106 gtk_widget_destroy(m_widget);
107 m_widget = NULL;
13a7abf9
VS
108
109 switch (result)
110 {
111 default:
112 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
113 // fall through
114
b63b07a8 115 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
116 case GTK_RESPONSE_DELETE_EVENT:
117 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
118 return wxID_CANCEL;
119 case GTK_RESPONSE_OK:
120 return wxID_OK;
121 case GTK_RESPONSE_YES:
122 return wxID_YES;
123 case GTK_RESPONSE_NO:
124 return wxID_NO;
125 }
126}
127
b2ce5e1b 128
13a7abf9
VS
129#endif // wxUSE_MSGDLG && defined(__WXGTK20__)
130