Debian Codegraph @

src/af/xap/gtk/xap_UnixDlg_MessageBox.cpp

raw
1 /* AbiSource Application Framework
2 * Copyright (C) 1998-2000 AbiSource, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 /*
21 * Port to Maemo Development Platform
22 * Author: INdT - Renato Araujo <[email protected]>
23 */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <glib.h>
32 #include "ut_assert.h"
33 #include "ut_vector.h"
34 #include "ut_debugmsg.h"
35 #include "xap_Gtk2Compat.h"
36 #include "xap_UnixDialogHelper.h"
37 #include "xap_UnixDlg_MessageBox.h"
38 #include "xap_UnixApp.h"
39 #include "xap_Frame.h"
40 #include "xap_UnixFrameImpl.h"
41
42 #include "xap_Strings.h"
43
44 /*****************************************************************/
45 XAP_Dialog * XAP_UnixDialog_MessageBox::static_constructor(XAP_DialogFactory * pFactory,
46 XAP_Dialog_Id id)
47 {
48 XAP_UnixDialog_MessageBox * p = new XAP_UnixDialog_MessageBox(pFactory,id);
49 return p;
50 }
51
52 XAP_UnixDialog_MessageBox::XAP_UnixDialog_MessageBox(XAP_DialogFactory * pDlgFactory,
53 XAP_Dialog_Id id)
54 : XAP_Dialog_MessageBox(pDlgFactory,id)
55 {
56 }
57
58 XAP_UnixDialog_MessageBox::~XAP_UnixDialog_MessageBox(void)
59 {
60 }
61
62 /*****************************************************************/
63
64 void XAP_UnixDialog_MessageBox::runModal(XAP_Frame * pFrame)
65 {
66 XAP_UnixFrameImpl * pUnixFrameImpl = static_cast<XAP_UnixFrameImpl *>(pFrame->getFrameImpl());
67 UT_return_if_fail(pUnixFrameImpl);
68
69 XAP_UnixApp * pApp = static_cast<XAP_UnixApp *>(XAP_App::getApp());
70 UT_return_if_fail(pApp);
71
72 GtkWidget * message = 0; // initialize to prevent compiler warning
73 GtkWindow * toplevel;
74
75 #if defined(EMBEDDED_TARGET) && EMBEDDED_TARGET == EMBEDDED_TARGET_HILDON
76 toplevel = GTK_WINDOW(gtk_widget_get_parent (pUnixFrameImpl->getTopLevelWindow()));
77 #else
78 toplevel = GTK_WINDOW(pUnixFrameImpl->getTopLevelWindow());
79 #endif
80
81 int dflFlags =
82 #if !GTK_CHECK_VERSION(3,0,0)
83 GTK_DIALOG_NO_SEPARATOR |
84 #endif
85 GTK_DIALOG_MODAL;
86
87 int dflResponse = GTK_RESPONSE_OK;
88
89 switch (m_buttons)
90 {
91 case b_O:
92 // just put up an information box
93 message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
94 GTK_MESSAGE_INFO,
95 GTK_BUTTONS_OK,
96 "%s",
97 m_szMessage ) ;
98
99 break;
100
101 case b_YN:
102 // YES - NO - most certainly a question
103 message = gtk_message_dialog_new ( toplevel, GTK_DIALOG_MODAL,
104 GTK_MESSAGE_QUESTION,
105 GTK_BUTTONS_YES_NO,
106 "%s",
107 m_szMessage ) ;
108 if(m_defaultAnswer == XAP_Dialog_MessageBox::a_YES)
109 {
110 gtk_dialog_set_default_response (GTK_DIALOG(message),
111 GTK_RESPONSE_YES);
112 }
113 else
114 {
115 gtk_dialog_set_default_response (GTK_DIALOG(message),
116 GTK_RESPONSE_NO);
117 }
118 break;
119
120 case b_YNC:
121 {
122 // YES - NO - CANCEL
123 // this is only used for saving files.
124 #ifndef EMBEDDED_TARGET
125 std::string s;
126 UT_String labelText;
127 const XAP_StringSet * pSS = pApp->getStringSet ();
128
129 pSS->getValueUTF8(XAP_STRING_ID_DLG_Exit_CloseWithoutSaving,s);
130 char * tmp_str = g_strdup(s.c_str());
131 convertMnemonics(tmp_str);
132 message = gtk_dialog_new_with_buttons("",
133 toplevel,
134 static_cast<GtkDialogFlags>(dflFlags),
135 NULL, NULL);
136 GtkWidget *button_no = gtk_dialog_add_button(GTK_DIALOG(message), tmp_str, GTK_RESPONSE_NO);
137 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_DELETE, GTK_ICON_SIZE_BUTTON);
138 gtk_button_set_image(GTK_BUTTON(button_no), img);
139 gtk_dialog_add_buttons(GTK_DIALOG(message),
140 GTK_STOCK_CANCEL,
141 GTK_RESPONSE_CANCEL,
142 GTK_STOCK_SAVE,
143 GTK_RESPONSE_YES,
144 NULL);
145
146 dflResponse = GTK_RESPONSE_YES;
147 FREEP(tmp_str);
148
149 GtkWidget * label = gtk_label_new(NULL);
150 const char * separator;
151 if (m_szSecondaryMessage == NULL)
152 separator = "";
153 else
154 separator = "\n\n";
155
156 gchar * msg = g_markup_escape_text (m_szMessage, -1);
157 labelText = UT_String_sprintf(labelText, "<span weight=\"bold\" size=\"larger\">%s</span>%s%s",
158 msg, separator, m_szSecondaryMessage);
159 g_free (msg); msg = NULL;
160
161 gtk_label_set_markup(GTK_LABEL(label), labelText.c_str());
162
163 GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
164
165 gtk_box_pack_start (GTK_BOX (hbox),
166 gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
167 GTK_ICON_SIZE_DIALOG),
168 FALSE, FALSE, 0);
169
170 gtk_box_pack_start (GTK_BOX (hbox), label,
171 TRUE, TRUE, 0);
172
173 GtkBox *content_area = GTK_BOX (gtk_dialog_get_content_area(GTK_DIALOG(message)));
174 gtk_box_pack_start (content_area, hbox, FALSE, FALSE, 0);
175
176 gtk_box_set_spacing(content_area, 12);
177 gtk_container_set_border_width(GTK_CONTAINER(hbox), 6);
178 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
179
180 gtk_widget_show_all (hbox);
181
182 #else
183 message = gtk_message_dialog_new (toplevel,
184 static_cast<GtkDialogFlags>(dflFlags),
185 GTK_MESSAGE_QUESTION,
186 GTK_BUTTONS_NONE,
187 "%s",
188 m_szMessage);
189
190 gtk_dialog_add_buttons(GTK_DIALOG(message),
191 GTK_STOCK_NO,
192 GTK_RESPONSE_NO,
193 GTK_STOCK_CANCEL,
194 GTK_RESPONSE_CANCEL,
195 GTK_STOCK_YES,
196 GTK_RESPONSE_YES,
197 NULL);
198 #endif
199 gtk_dialog_set_default_response (GTK_DIALOG(message),
200 GTK_RESPONSE_CANCEL);
201
202 break;
203 }
204 default:
205 UT_ASSERT_NOT_REACHED();
206 }
207
208 // set the title to '', as per GNOME HIG, Section 3, Alerts
209 gtk_window_set_title (GTK_WINDOW(message), "");
210
211 UT_ASSERT(message);
212
213 switch ( abiRunModalDialog ( GTK_DIALOG(message), pFrame,
214 this, dflResponse, true, ATK_ROLE_ALERT ) )
215 {
216 case GTK_RESPONSE_OK:
217 m_answer = XAP_Dialog_MessageBox::a_OK; break;
218 case GTK_RESPONSE_YES:
219 m_answer = XAP_Dialog_MessageBox::a_YES; break;
220 case GTK_RESPONSE_NO:
221 m_answer = XAP_Dialog_MessageBox::a_NO; break;
222 case GTK_RESPONSE_CANCEL:
223 default:
224 m_answer = XAP_Dialog_MessageBox::a_CANCEL; break;
225 }
226 }