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