]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
fixed another place where wxString was used as bool
[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__
88a7a4e1 16 #pragma hdrstop
13a7abf9
VS
17#endif
18
47e118ba 19#if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
13a7abf9 20
e1bf3ad3 21#include "wx/msgdlg.h"
88a7a4e1
WS
22
23#ifndef WX_PRECOMP
24 #include "wx/intl.h"
25#endif
26
13a7abf9
VS
27#include "wx/gtk/private.h"
28#include <gtk/gtk.h>
29
13a7abf9
VS
30IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
31
32wxMessageDialog::wxMessageDialog(wxWindow *parent,
33 const wxString& message,
34 const wxString& caption,
35 long style,
36 const wxPoint& WXUNUSED(pos))
37{
38 m_caption = caption;
39 m_message = message;
e5b50758 40 SetMessageDialogStyle(style);
1840af03 41 m_parent = wxGetTopLevelParent(parent);
13a7abf9 42
b63b07a8 43 GtkMessageType type = GTK_MESSAGE_ERROR;
13a7abf9 44 GtkButtonsType buttons = GTK_BUTTONS_OK;
b63b07a8 45
e5b50758 46 if (style & wxYES_NO)
13a7abf9 47 {
f4322df6
VZ
48 if (style & wxCANCEL)
49 buttons = GTK_BUTTONS_NONE;
50 else
51 buttons = GTK_BUTTONS_YES_NO;
13a7abf9
VS
52 }
53
e5b50758 54 if (style & wxOK)
13a7abf9 55 {
e5b50758 56 if (style & wxCANCEL)
13a7abf9
VS
57 buttons = GTK_BUTTONS_OK_CANCEL;
58 else
59 buttons = GTK_BUTTONS_OK;
60 }
b63b07a8 61
e5b50758 62 if (style & wxICON_EXCLAMATION)
13a7abf9 63 type = GTK_MESSAGE_WARNING;
e5b50758 64 else if (style & wxICON_ERROR)
13a7abf9 65 type = GTK_MESSAGE_ERROR;
e5b50758 66 else if (style & wxICON_INFORMATION)
13a7abf9 67 type = GTK_MESSAGE_INFO;
e5b50758 68 else if (style & wxICON_QUESTION)
13a7abf9 69 type = GTK_MESSAGE_QUESTION;
b63b07a8 70 else
e0ae1a0a
VZ
71 {
72 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
e5b50758 73 type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
e0ae1a0a 74 }
13a7abf9 75
b2ce5e1b
RD
76 m_widget = gtk_message_dialog_new(m_parent ?
77 GTK_WINDOW(m_parent->m_widget) : NULL,
78 GTK_DIALOG_MODAL,
79 type, buttons,
80 "%s", (const char*)wxGTK_CONV(m_message));
13a7abf9 81 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 82 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 83
e5b50758 84 if (style & wxYES_NO)
13a7abf9 85 {
e5b50758 86 if (style & wxCANCEL)
f4322df6 87 {
d182ca1b
RR
88 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
89 GTK_RESPONSE_NO);
b2ce5e1b 90 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
13a7abf9 91 GTK_RESPONSE_CANCEL);
d182ca1b
RR
92 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
93 GTK_RESPONSE_YES);
f4322df6 94 }
e5b50758 95 if (style & wxNO_DEFAULT)
b2ce5e1b 96 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
13a7abf9 97 else
b2ce5e1b 98 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
13a7abf9 99 }
633c71ef 100
3b439e60 101 if (m_parent)
633c71ef
VS
102 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
103 GTK_WINDOW(m_parent->m_widget));
b2ce5e1b 104}
e5b50758 105
f1dec25f
RR
106wxMessageDialog::~wxMessageDialog()
107{
f1dec25f
RR
108}
109
b2ce5e1b
RD
110int wxMessageDialog::ShowModal()
111{
3b439e60
RR
112 // This should be necessary, but otherwise the
113 // parent TLW will disappear..
114 if (m_parent)
115 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 116
b2ce5e1b
RD
117 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
118 gtk_widget_destroy(m_widget);
119 m_widget = NULL;
13a7abf9
VS
120
121 switch (result)
122 {
123 default:
124 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
125 // fall through
126
b63b07a8 127 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
128 case GTK_RESPONSE_DELETE_EVENT:
129 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
130 return wxID_CANCEL;
131 case GTK_RESPONSE_OK:
132 return wxID_OK;
133 case GTK_RESPONSE_YES:
134 return wxID_YES;
135 case GTK_RESPONSE_NO:
136 return wxID_NO;
137 }
138}
139
b2ce5e1b 140
88a7a4e1 141#endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)