1/* 2 * errorbox.c 3 * 4 * $Id: errorbox.c,v 1.8 2007/02/02 11:58:14 source Exp $ 5 * 6 * The iODBC driver manager. 7 * 8 * Copyright (C) 1996-2006 by OpenLink Software <iodbc@openlinksw.com> 9 * All Rights Reserved. 10 * 11 * This software is released under the terms of either of the following 12 * licenses: 13 * 14 * - GNU Library General Public License (see LICENSE.LGPL) 15 * - The BSD License (see LICENSE.BSD). 16 * 17 * Note that the only valid version of the LGPL license as far as this 18 * project is concerned is the original GNU Library General Public License 19 * Version 2, dated June 1991. 20 * 21 * While not mandated by the BSD license, any patches you make to the 22 * iODBC source code may be contributed back into the iODBC project 23 * at your discretion. Contributions will benefit the Open Source and 24 * Data Access community as a whole. Submissions may be made at: 25 * 26 * http://www.iodbc.org 27 * 28 * 29 * GNU Library Generic Public License Version 2 30 * ============================================ 31 * This library is free software; you can redistribute it and/or 32 * modify it under the terms of the GNU Library General Public 33 * License as published by the Free Software Foundation; only 34 * Version 2 of the License dated June 1991. 35 * 36 * This library is distributed in the hope that it will be useful, 37 * but WITHOUT ANY WARRANTY; without even the implied warranty of 38 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 39 * Library General Public License for more details. 40 * 41 * You should have received a copy of the GNU Library General Public 42 * License along with this library; if not, write to the Free 43 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 44 * 45 * 46 * The BSD License 47 * =============== 48 * Redistribution and use in source and binary forms, with or without 49 * modification, are permitted provided that the following conditions 50 * are met: 51 * 52 * 1. Redistributions of source code must retain the above copyright 53 * notice, this list of conditions and the following disclaimer. 54 * 2. Redistributions in binary form must reproduce the above copyright 55 * notice, this list of conditions and the following disclaimer in 56 * the documentation and/or other materials provided with the 57 * distribution. 58 * 3. Neither the name of OpenLink Software Inc. nor the names of its 59 * contributors may be used to endorse or promote products derived 60 * from this software without specific prior written permission. 61 * 62 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 63 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 64 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 65 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL OPENLINK OR 66 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 67 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 68 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 69 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 70 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 71 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 72 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 */ 74 75 76#include "gui.h" 77#include "error.xpm" 78 79 80static gint 81delete_event (GtkWidget *widget, GdkEvent *event) 82{ 83 return FALSE; 84} 85 86 87static void 88error_ok_clicked (GtkWidget *widget, GtkWidget *error) 89{ 90 gtk_signal_disconnect_by_func (GTK_OBJECT (error), 91 GTK_SIGNAL_FUNC (gtk_main_quit), NULL); 92 gtk_main_quit (); 93 gtk_widget_destroy (error); 94} 95 96 97void 98create_error (HWND hwnd, LPCSTR dsn, LPCSTR text, LPCSTR errmsg) 99{ 100 GtkWidget *error, *dialog_vbox1, *hbox1, *pixmap1, *vbox1; 101 GtkWidget *l_text, *l_error, *dialog_action_area1, *hbuttonbox1, *b_ok; 102 GtkAccelGroup *accel_group; 103 GdkPixmap *pixmap; 104 GdkBitmap *mask; 105 GtkStyle *style; 106 guint b_ok_key; 107 char msg[1024]; 108 109 if (hwnd == NULL || !GTK_IS_WIDGET (hwnd)) 110 return; 111 112 accel_group = gtk_accel_group_new (); 113 114 error = gtk_dialog_new (); 115 if (dsn) 116 sprintf (msg, "Error : %s", dsn); 117 else 118 sprintf (msg, "Error ..."); 119 120 gtk_object_set_data (GTK_OBJECT (error), "error", error); 121 gtk_window_set_title (GTK_WINDOW (error), msg); 122 gtk_window_set_position (GTK_WINDOW (error), GTK_WIN_POS_CENTER); 123 gtk_window_set_modal (GTK_WINDOW (error), TRUE); 124 gtk_window_set_policy (GTK_WINDOW (error), FALSE, FALSE, FALSE); 125 126#if GTK_CHECK_VERSION(2,0,0) 127 gtk_widget_show (error); 128#endif 129 130 dialog_vbox1 = GTK_DIALOG (error)->vbox; 131 gtk_object_set_data (GTK_OBJECT (error), "dialog_vbox1", dialog_vbox1); 132 gtk_widget_show (dialog_vbox1); 133 134 hbox1 = gtk_hbox_new (FALSE, 6); 135 gtk_widget_ref (hbox1); 136 gtk_object_set_data_full (GTK_OBJECT (error), "hbox1", hbox1, 137 (GtkDestroyNotify) gtk_widget_unref); 138 gtk_widget_show (hbox1); 139 gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0); 140 gtk_container_set_border_width (GTK_CONTAINER (hbox1), 6); 141 142#if GTK_CHECK_VERSION(2,0,0) 143 style = gtk_widget_get_style (error); 144 pixmap = 145 gdk_pixmap_create_from_xpm_d (error->window, &mask, 146 &style->bg[GTK_STATE_NORMAL], (gchar **) error_xpm); 147#else 148 style = gtk_widget_get_style (GTK_WIDGET (hwnd)); 149 pixmap = 150 gdk_pixmap_create_from_xpm_d (GTK_WIDGET (hwnd)->window, &mask, 151 &style->bg[GTK_STATE_NORMAL], (gchar **) error_xpm); 152#endif 153 154 pixmap1 = gtk_pixmap_new (pixmap, mask); 155 gtk_widget_ref (pixmap1); 156 gtk_object_set_data_full (GTK_OBJECT (error), "pixmap1", pixmap1, 157 (GtkDestroyNotify) gtk_widget_unref); 158 gtk_widget_show (pixmap1); 159 gtk_box_pack_start (GTK_BOX (hbox1), pixmap1, FALSE, FALSE, 0); 160 161 vbox1 = gtk_vbox_new (TRUE, 0); 162 gtk_widget_ref (vbox1); 163 gtk_object_set_data_full (GTK_OBJECT (error), "vbox1", vbox1, 164 (GtkDestroyNotify) gtk_widget_unref); 165 gtk_widget_show (vbox1); 166 gtk_box_pack_start (GTK_BOX (hbox1), vbox1, TRUE, TRUE, 0); 167 168 l_text = gtk_label_new (""); 169 gtk_label_parse_uline (GTK_LABEL (l_text), (text) ? text : ""); 170 gtk_widget_ref (l_text); 171 gtk_object_set_data_full (GTK_OBJECT (error), "l_text", l_text, 172 (GtkDestroyNotify) gtk_widget_unref); 173 gtk_widget_show (l_text); 174 gtk_box_pack_start (GTK_BOX (vbox1), l_text, FALSE, TRUE, 0); 175 gtk_label_set_justify (GTK_LABEL (l_text), GTK_JUSTIFY_LEFT); 176 gtk_label_set_line_wrap (GTK_LABEL (l_text), TRUE); 177 178 l_error = gtk_label_new (""); 179 gtk_label_parse_uline (GTK_LABEL (l_error), (errmsg) ? errmsg : ""); 180 gtk_widget_ref (l_error); 181 gtk_object_set_data_full (GTK_OBJECT (error), "l_error", l_error, 182 (GtkDestroyNotify) gtk_widget_unref); 183 gtk_widget_show (l_error); 184 gtk_box_pack_start (GTK_BOX (vbox1), l_error, FALSE, TRUE, 0); 185 gtk_label_set_justify (GTK_LABEL (l_error), GTK_JUSTIFY_LEFT); 186 gtk_label_set_line_wrap (GTK_LABEL (l_error), TRUE); 187 188 dialog_action_area1 = GTK_DIALOG (error)->action_area; 189 gtk_object_set_data (GTK_OBJECT (error), "dialog_action_area1", 190 dialog_action_area1); 191 gtk_widget_show (dialog_action_area1); 192 gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5); 193 194 hbuttonbox1 = gtk_hbutton_box_new (); 195 gtk_widget_ref (hbuttonbox1); 196 gtk_object_set_data_full (GTK_OBJECT (error), "hbuttonbox1", hbuttonbox1, 197 (GtkDestroyNotify) gtk_widget_unref); 198 gtk_widget_show (hbuttonbox1); 199 gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE, 200 0); 201 gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END); 202 gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10); 203 204 b_ok = gtk_button_new_with_label (""); 205 b_ok_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_ok)->child), "_Ok"); 206 gtk_widget_add_accelerator (b_ok, "clicked", accel_group, 207 b_ok_key, GDK_MOD1_MASK, 0); 208 gtk_widget_ref (b_ok); 209 gtk_object_set_data_full (GTK_OBJECT (error), "b_ok", b_ok, 210 (GtkDestroyNotify) gtk_widget_unref); 211 gtk_widget_show (b_ok); 212 gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_ok); 213 GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT); 214 215 /* Ok button events */ 216 gtk_signal_connect (GTK_OBJECT (b_ok), "clicked", 217 GTK_SIGNAL_FUNC (error_ok_clicked), error); 218 /* Close window button events */ 219 gtk_signal_connect (GTK_OBJECT (error), "delete_event", 220 GTK_SIGNAL_FUNC (delete_event), NULL); 221 gtk_signal_connect (GTK_OBJECT (error), "destroy", 222 GTK_SIGNAL_FUNC (gtk_main_quit), NULL); 223 224 gtk_window_add_accel_group (GTK_WINDOW (error), accel_group); 225 226 gtk_widget_show_all (error); 227 gtk_main (); 228} 229 230 231void 232create_errorw (HWND hwnd, LPCWSTR dsn, LPCWSTR text, LPCWSTR errmsg) 233{ 234 LPSTR _dsn = NULL; 235 LPSTR _text = NULL; 236 LPSTR _errmsg = NULL; 237 238 _dsn = dm_SQL_WtoU8(dsn, SQL_NTS); 239 _text = dm_SQL_WtoU8(text, SQL_NTS); 240 _errmsg = dm_SQL_WtoU8(errmsg, SQL_NTS); 241 242 create_error(hwnd, _dsn, _text, _errmsg); 243 244 if (_dsn) 245 free(_dsn); 246 if (_text) 247 free(_text); 248 if (_errmsg) 249 free(_errmsg); 250} 251 252