]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/msgdlg.cpp
Missing header.
[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
VS
47 {
48 buttons = GTK_BUTTONS_YES_NO;
49 }
50
e5b50758 51 if (style & wxOK)
13a7abf9 52 {
e5b50758 53 if (style & wxCANCEL)
13a7abf9
VS
54 buttons = GTK_BUTTONS_OK_CANCEL;
55 else
56 buttons = GTK_BUTTONS_OK;
57 }
b63b07a8 58
e5b50758 59 if (style & wxICON_EXCLAMATION)
13a7abf9 60 type = GTK_MESSAGE_WARNING;
e5b50758 61 else if (style & wxICON_ERROR)
13a7abf9 62 type = GTK_MESSAGE_ERROR;
e5b50758 63 else if (style & wxICON_INFORMATION)
13a7abf9 64 type = GTK_MESSAGE_INFO;
e5b50758 65 else if (style & wxICON_QUESTION)
13a7abf9 66 type = GTK_MESSAGE_QUESTION;
b63b07a8 67 else
e0ae1a0a
VZ
68 {
69 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
e5b50758 70 type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
e0ae1a0a 71 }
13a7abf9 72
b2ce5e1b
RD
73 m_widget = gtk_message_dialog_new(m_parent ?
74 GTK_WINDOW(m_parent->m_widget) : NULL,
75 GTK_DIALOG_MODAL,
76 type, buttons,
77 "%s", (const char*)wxGTK_CONV(m_message));
13a7abf9 78 if (m_caption != wxMessageBoxCaptionStr)
b2ce5e1b 79 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
13a7abf9 80
e5b50758 81 if (style & wxYES_NO)
13a7abf9 82 {
e5b50758 83 if (style & wxCANCEL)
b2ce5e1b 84 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
13a7abf9 85 GTK_RESPONSE_CANCEL);
e5b50758 86 if (style & wxNO_DEFAULT)
b2ce5e1b 87 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
13a7abf9 88 else
b2ce5e1b 89 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
13a7abf9 90 }
633c71ef 91
3b439e60 92 if (m_parent)
633c71ef
VS
93 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
94 GTK_WINDOW(m_parent->m_widget));
b2ce5e1b 95}
e5b50758 96
f1dec25f
RR
97wxMessageDialog::~wxMessageDialog()
98{
f1dec25f
RR
99}
100
b2ce5e1b
RD
101int wxMessageDialog::ShowModal()
102{
3b439e60
RR
103 // This should be necessary, but otherwise the
104 // parent TLW will disappear..
105 if (m_parent)
106 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
e5b50758 107
b2ce5e1b
RD
108 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
109 gtk_widget_destroy(m_widget);
110 m_widget = NULL;
13a7abf9
VS
111
112 switch (result)
113 {
114 default:
115 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
116 // fall through
117
b63b07a8 118 case GTK_RESPONSE_CANCEL:
0e4a7045
VS
119 case GTK_RESPONSE_DELETE_EVENT:
120 case GTK_RESPONSE_CLOSE:
13a7abf9
VS
121 return wxID_CANCEL;
122 case GTK_RESPONSE_OK:
123 return wxID_OK;
124 case GTK_RESPONSE_YES:
125 return wxID_YES;
126 case GTK_RESPONSE_NO:
127 return wxID_NO;
128 }
129}
130
b2ce5e1b 131
88a7a4e1 132#endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)