]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk/msgdlg.cpp
Preserve original menu label for later retrieval
[wxWidgets.git] / src / gtk / msgdlg.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/gtk/msgdlg.cpp
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
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#if wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)
20
21#include "wx/msgdlg.h"
22
23#ifndef WX_PRECOMP
24 #include "wx/intl.h"
25#endif
26
27#include "wx/gtk/private.h"
28#include <gtk/gtk.h>
29
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 : wxMessageDialogBase(GetParentForModalDialog(parent),
38 message,
39 caption,
40 style)
41{
42}
43
44void wxMessageDialog::GTKCreateMsgDialog()
45{
46 GtkMessageType type = GTK_MESSAGE_ERROR;
47 GtkButtonsType buttons = GTK_BUTTONS_OK;
48
49 if (m_dialogStyle & wxYES_NO)
50 {
51 if (m_dialogStyle & wxCANCEL)
52 buttons = GTK_BUTTONS_NONE;
53 else
54 buttons = GTK_BUTTONS_YES_NO;
55 }
56
57 if (m_dialogStyle & wxOK)
58 {
59 if (m_dialogStyle & wxCANCEL)
60 buttons = GTK_BUTTONS_OK_CANCEL;
61 else
62 buttons = GTK_BUTTONS_OK;
63 }
64
65 if (m_dialogStyle & wxICON_EXCLAMATION)
66 type = GTK_MESSAGE_WARNING;
67 else if (m_dialogStyle & wxICON_ERROR)
68 type = GTK_MESSAGE_ERROR;
69 else if (m_dialogStyle & wxICON_INFORMATION)
70 type = GTK_MESSAGE_INFO;
71 else if (m_dialogStyle & wxICON_QUESTION)
72 type = GTK_MESSAGE_QUESTION;
73 else
74 {
75 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
76 type = m_dialogStyle & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
77 }
78
79 wxString message;
80#if GTK_CHECK_VERSION(2, 6, 0)
81 bool needsExtMessage = false;
82 if ( gtk_check_version(2, 6, 0) == NULL && !m_extendedMessage.empty() )
83 {
84 message = m_message;
85 needsExtMessage = true;
86 }
87 else // extended message not needed or not supported
88#endif // GTK+ 2.4+
89 {
90 message = GetFullMessage();
91 }
92
93 m_widget = gtk_message_dialog_new(m_parent ? GTK_WINDOW(m_parent->m_widget)
94 : NULL,
95 GTK_DIALOG_MODAL,
96 type,
97 buttons,
98 "%s",
99 (const char*)wxGTK_CONV(message));
100
101#if GTK_CHECK_VERSION(2, 6, 0)
102 if ( needsExtMessage )
103 {
104 gtk_message_dialog_format_secondary_text
105 (
106 (GtkMessageDialog *)m_widget,
107 "%s",
108 (const char *)wxGTK_CONV(m_extendedMessage)
109 );
110 }
111#endif // GTK+ 2.4+
112
113 if (m_caption != wxMessageBoxCaptionStr)
114 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
115
116 if (m_dialogStyle & wxYES_NO)
117 {
118 if (m_dialogStyle & wxCANCEL)
119 {
120 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
121 GTK_RESPONSE_NO);
122 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
123 GTK_RESPONSE_CANCEL);
124 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
125 GTK_RESPONSE_YES);
126 }
127 if (m_dialogStyle & wxNO_DEFAULT)
128 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
129 else
130 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
131 }
132
133 if (m_parent)
134 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
135 GTK_WINDOW(m_parent->m_widget));
136}
137
138int wxMessageDialog::ShowModal()
139{
140 if ( !m_widget )
141 {
142 GTKCreateMsgDialog();
143 wxCHECK_MSG( m_widget, wxID_CANCEL,
144 _T("failed to create GtkMessageDialog") );
145 }
146
147 // This should be necessary, but otherwise the
148 // parent TLW will disappear..
149 if (m_parent)
150 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
151
152 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
153 gtk_widget_destroy(m_widget);
154 m_widget = NULL;
155
156 switch (result)
157 {
158 default:
159 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
160 // fall through
161
162 case GTK_RESPONSE_CANCEL:
163 case GTK_RESPONSE_DELETE_EVENT:
164 case GTK_RESPONSE_CLOSE:
165 return wxID_CANCEL;
166 case GTK_RESPONSE_OK:
167 return wxID_OK;
168 case GTK_RESPONSE_YES:
169 return wxID_YES;
170 case GTK_RESPONSE_NO:
171 return wxID_NO;
172 }
173}
174
175
176#endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)