]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/msgdlg.cpp
fix wxStringOutputStream::Write() in Unicode build when the output overlaps a boundar...
[wxWidgets.git] / src / gtk / msgdlg.cpp
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
30 IMPLEMENT_CLASS(wxMessageDialog, wxDialog)
31
32 wxMessageDialog::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;
40 SetMessageDialogStyle(style);
41
42 m_parent = GetParentForModalDialog(parent);
43
44 GtkMessageType type = GTK_MESSAGE_ERROR;
45 GtkButtonsType buttons = GTK_BUTTONS_OK;
46
47 if (style & wxYES_NO)
48 {
49 if (style & wxCANCEL)
50 buttons = GTK_BUTTONS_NONE;
51 else
52 buttons = GTK_BUTTONS_YES_NO;
53 }
54
55 if (style & wxOK)
56 {
57 if (style & wxCANCEL)
58 buttons = GTK_BUTTONS_OK_CANCEL;
59 else
60 buttons = GTK_BUTTONS_OK;
61 }
62
63 if (style & wxICON_EXCLAMATION)
64 type = GTK_MESSAGE_WARNING;
65 else if (style & wxICON_ERROR)
66 type = GTK_MESSAGE_ERROR;
67 else if (style & wxICON_INFORMATION)
68 type = GTK_MESSAGE_INFO;
69 else if (style & wxICON_QUESTION)
70 type = GTK_MESSAGE_QUESTION;
71 else
72 {
73 // GTK+ doesn't have a "typeless" msg box, so try to auto detect...
74 type = style & wxYES ? GTK_MESSAGE_QUESTION : GTK_MESSAGE_INFO;
75 }
76
77 m_widget = gtk_message_dialog_new(m_parent ?
78 GTK_WINDOW(m_parent->m_widget) : NULL,
79 GTK_DIALOG_MODAL,
80 type, buttons,
81 "%s", (const char*)wxGTK_CONV(m_message));
82 if (m_caption != wxMessageBoxCaptionStr)
83 gtk_window_set_title(GTK_WINDOW(m_widget), wxGTK_CONV(m_caption));
84
85 if (style & wxYES_NO)
86 {
87 if (style & wxCANCEL)
88 {
89 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_NO,
90 GTK_RESPONSE_NO);
91 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_CANCEL,
92 GTK_RESPONSE_CANCEL);
93 gtk_dialog_add_button(GTK_DIALOG(m_widget), GTK_STOCK_YES,
94 GTK_RESPONSE_YES);
95 }
96 if (style & wxNO_DEFAULT)
97 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_NO);
98 else
99 gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_YES);
100 }
101
102 if (m_parent)
103 gtk_window_set_transient_for(GTK_WINDOW(m_widget),
104 GTK_WINDOW(m_parent->m_widget));
105 }
106
107 wxMessageDialog::~wxMessageDialog()
108 {
109 }
110
111 int wxMessageDialog::ShowModal()
112 {
113 // This should be necessary, but otherwise the
114 // parent TLW will disappear..
115 if (m_parent)
116 gtk_window_present( GTK_WINDOW(m_parent->m_widget) );
117
118 gint result = gtk_dialog_run(GTK_DIALOG(m_widget));
119 gtk_widget_destroy(m_widget);
120 m_widget = NULL;
121
122 switch (result)
123 {
124 default:
125 wxFAIL_MSG(_T("unexpected GtkMessageDialog return code"));
126 // fall through
127
128 case GTK_RESPONSE_CANCEL:
129 case GTK_RESPONSE_DELETE_EVENT:
130 case GTK_RESPONSE_CLOSE:
131 return wxID_CANCEL;
132 case GTK_RESPONSE_OK:
133 return wxID_OK;
134 case GTK_RESPONSE_YES:
135 return wxID_YES;
136 case GTK_RESPONSE_NO:
137 return wxID_NO;
138 }
139 }
140
141
142 #endif // wxUSE_MSGDLG && defined(__WXGTK20__) && !defined(__WXGPE__)