1/*
2 *  confirm.c
3 *
4 *  $Id: confirm.c,v 1.3 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 <odbcinst.h>
77#include <unicode.h>
78#include "gui.h"
79#include "question.xpm"
80
81
82static void
83confirm_yes_clicked (GtkWidget *widget, TCONFIRM *confirm_t)
84{
85  if (confirm_t)
86    {
87      confirm_t->yes_no = TRUE;
88
89      gtk_signal_disconnect_by_func (GTK_OBJECT (confirm_t->mainwnd),
90	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
91      gtk_main_quit ();
92      gtk_widget_destroy (confirm_t->mainwnd);
93    }
94}
95
96
97static void
98confirm_no_clicked (GtkWidget *widget, TCONFIRM *confirm_t)
99{
100  if (confirm_t)
101    {
102      confirm_t->yes_no = FALSE;
103
104      gtk_signal_disconnect_by_func (GTK_OBJECT (confirm_t->mainwnd),
105	  GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
106      gtk_main_quit ();
107      gtk_widget_destroy (confirm_t->mainwnd);
108    }
109}
110
111
112static gint
113delete_event (GtkWidget *widget, GdkEvent *event, TCONFIRM *confirm_t)
114{
115  confirm_no_clicked (widget, confirm_t);
116
117  return FALSE;
118}
119
120
121BOOL
122create_confirm (HWND hwnd, LPCSTR dsn, LPCSTR text)
123{
124  GtkWidget *confirm, *dialog_vbox1, *hbox1, *pixmap1, *l_text;
125  GtkWidget *dialog_action_area1, *hbuttonbox1, *b_yes, *b_no;
126  guint b_yes_key, b_no_key;
127  GdkPixmap *pixmap;
128  GdkBitmap *mask;
129  GtkStyle *style;
130  GtkAccelGroup *accel_group;
131  char msg[1024];
132  TCONFIRM confirm_t;
133
134  if (hwnd == NULL || !GTK_IS_WIDGET (hwnd))
135    return FALSE;
136
137  accel_group = gtk_accel_group_new ();
138
139  confirm = gtk_dialog_new ();
140  if (dsn)
141    sprintf (msg, "Confirm action/operation on %s", dsn);
142  else
143    sprintf (msg, "Confirm action/operation ...");
144  gtk_object_set_data (GTK_OBJECT (confirm), "confirm", confirm);
145  gtk_window_set_title (GTK_WINDOW (confirm), msg);
146  gtk_window_set_position (GTK_WINDOW (confirm), GTK_WIN_POS_CENTER);
147  gtk_window_set_modal (GTK_WINDOW (confirm), TRUE);
148  gtk_window_set_policy (GTK_WINDOW (confirm), FALSE, FALSE, FALSE);
149
150#if GTK_CHECK_VERSION(2,0,0)
151  gtk_widget_show (confirm);
152#endif
153
154  dialog_vbox1 = GTK_DIALOG (confirm)->vbox;
155  gtk_object_set_data (GTK_OBJECT (confirm), "dialog_vbox1", dialog_vbox1);
156  gtk_widget_show (dialog_vbox1);
157
158  hbox1 = gtk_hbox_new (FALSE, 6);
159  gtk_widget_ref (hbox1);
160  gtk_object_set_data_full (GTK_OBJECT (confirm), "hbox1", hbox1,
161      (GtkDestroyNotify) gtk_widget_unref);
162  gtk_widget_show (hbox1);
163  gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
164  gtk_container_set_border_width (GTK_CONTAINER (hbox1), 6);
165
166#if GTK_CHECK_VERSION(2,0,0)
167  style = gtk_widget_get_style (confirm);
168  pixmap =
169      gdk_pixmap_create_from_xpm_d (confirm->window, &mask,
170      &style->bg[GTK_STATE_NORMAL], (gchar **) question_xpm);
171#else
172  style = gtk_widget_get_style (GTK_WIDGET (hwnd));
173  pixmap =
174      gdk_pixmap_create_from_xpm_d (GTK_WIDGET (hwnd)->window, &mask,
175      &style->bg[GTK_STATE_NORMAL], (gchar **) question_xpm);
176#endif
177
178  pixmap1 = gtk_pixmap_new (pixmap, mask);
179  gtk_widget_ref (pixmap1);
180  gtk_object_set_data_full (GTK_OBJECT (confirm), "pixmap1", pixmap1,
181      (GtkDestroyNotify) gtk_widget_unref);
182  gtk_widget_show (pixmap1);
183  gtk_box_pack_start (GTK_BOX (hbox1), pixmap1, FALSE, FALSE, 0);
184
185  l_text = gtk_label_new ("");
186  gtk_label_parse_uline (GTK_LABEL (l_text), text);
187  gtk_widget_ref (l_text);
188  gtk_object_set_data_full (GTK_OBJECT (confirm), "l_text", l_text,
189      (GtkDestroyNotify) gtk_widget_unref);
190  gtk_widget_show (l_text);
191  gtk_box_pack_start (GTK_BOX (hbox1), l_text, TRUE, TRUE, 0);
192  gtk_label_set_justify (GTK_LABEL (l_text), GTK_JUSTIFY_LEFT);
193  gtk_label_set_line_wrap (GTK_LABEL (l_text), TRUE);
194
195  dialog_action_area1 = GTK_DIALOG (confirm)->action_area;
196  gtk_object_set_data (GTK_OBJECT (confirm), "dialog_action_area1",
197      dialog_action_area1);
198  gtk_widget_show (dialog_action_area1);
199  gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5);
200
201  hbuttonbox1 = gtk_hbutton_box_new ();
202  gtk_widget_ref (hbuttonbox1);
203  gtk_object_set_data_full (GTK_OBJECT (confirm), "hbuttonbox1", hbuttonbox1,
204      (GtkDestroyNotify) gtk_widget_unref);
205  gtk_widget_show (hbuttonbox1);
206  gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE,
207      0);
208  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END);
209  gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10);
210
211  b_yes = gtk_button_new_with_label ("");
212  b_yes_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_yes)->child),
213      "_Yes");
214  gtk_widget_add_accelerator (b_yes, "clicked", accel_group,
215      b_yes_key, GDK_MOD1_MASK, 0);
216  gtk_widget_ref (b_yes);
217  gtk_object_set_data_full (GTK_OBJECT (confirm), "b_yes", b_yes,
218      (GtkDestroyNotify) gtk_widget_unref);
219  gtk_widget_show (b_yes);
220  gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_yes);
221  GTK_WIDGET_SET_FLAGS (b_yes, GTK_CAN_DEFAULT);
222
223  b_no = gtk_button_new_with_label ("");
224  b_no_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_no)->child), "_No");
225  gtk_widget_add_accelerator (b_no, "clicked", accel_group,
226      b_no_key, GDK_MOD1_MASK, 0);
227  gtk_widget_ref (b_no);
228  gtk_object_set_data_full (GTK_OBJECT (confirm), "b_no", b_no,
229      (GtkDestroyNotify) gtk_widget_unref);
230  gtk_widget_show (b_no);
231  gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_no);
232  GTK_WIDGET_SET_FLAGS (b_no, GTK_CAN_DEFAULT);
233
234  /* Yes button events */
235  gtk_signal_connect (GTK_OBJECT (b_yes), "clicked",
236      GTK_SIGNAL_FUNC (confirm_yes_clicked), &confirm_t);
237  /* No button events */
238  gtk_signal_connect (GTK_OBJECT (b_no), "clicked",
239      GTK_SIGNAL_FUNC (confirm_no_clicked), &confirm_t);
240  /* Close window button events */
241  gtk_signal_connect (GTK_OBJECT (confirm), "delete_event",
242      GTK_SIGNAL_FUNC (delete_event), &confirm_t);
243  gtk_signal_connect (GTK_OBJECT (confirm), "destroy",
244      GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
245
246  gtk_window_add_accel_group (GTK_WINDOW (confirm), accel_group);
247
248  confirm_t.yes_no = FALSE;
249  confirm_t.mainwnd = confirm;
250
251  gtk_widget_show_all (confirm);
252  gtk_main ();
253
254  return confirm_t.yes_no;
255}
256
257BOOL
258create_confirmw (HWND hwnd, LPCWSTR dsn, LPCWSTR text)
259{
260  LPSTR _dsn = NULL;
261  LPSTR _text = NULL;
262
263  _dsn = dm_SQL_WtoU8(dsn, SQL_NTS);
264  _text = dm_SQL_WtoU8(text, SQL_NTS);
265
266  create_message(hwnd, _dsn, _text);
267
268  if (_dsn)
269    free(_dsn);
270  if (_text)
271    free(_text);
272}
273