confirm.c 9.2 KB

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