errorbox.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /*
  2. * errorbox.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 "gui.h"
  75. #include "error.xpm"
  76. static gint
  77. delete_event (GtkWidget *widget, GdkEvent *event)
  78. {
  79. return FALSE;
  80. }
  81. static void
  82. error_ok_clicked (GtkWidget *widget, GtkWidget *error)
  83. {
  84. gtk_signal_disconnect_by_func (GTK_OBJECT (error),
  85. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  86. gtk_main_quit ();
  87. gtk_widget_destroy (error);
  88. }
  89. void
  90. create_error (HWND hwnd, LPCSTR dsn, LPCSTR text, LPCSTR errmsg)
  91. {
  92. GtkWidget *error, *dialog_vbox1, *hbox1, *pixmap1, *vbox1;
  93. GtkWidget *l_text, *l_error, *dialog_action_area1, *hbuttonbox1, *b_ok;
  94. GtkAccelGroup *accel_group;
  95. GdkPixmap *pixmap;
  96. GdkBitmap *mask;
  97. GtkStyle *style;
  98. guint b_ok_key;
  99. char msg[1024];
  100. if (hwnd == NULL || !GTK_IS_WIDGET (hwnd))
  101. return;
  102. accel_group = gtk_accel_group_new ();
  103. error = gtk_dialog_new ();
  104. if (dsn)
  105. sprintf (msg, "Error : %s", dsn);
  106. else
  107. sprintf (msg, "Error ...");
  108. gtk_object_set_data (GTK_OBJECT (error), "error", error);
  109. gtk_window_set_title (GTK_WINDOW (error), msg);
  110. gtk_widget_set_size_request (error, 400, 150);
  111. gtk_window_set_position (GTK_WINDOW (error), GTK_WIN_POS_CENTER);
  112. gtk_window_set_modal (GTK_WINDOW (error), TRUE);
  113. gtk_window_set_default_size (GTK_WINDOW (error), 400, 150);
  114. gtk_window_set_type_hint (GTK_WINDOW (error), GDK_WINDOW_TYPE_HINT_DIALOG);
  115. #if GTK_CHECK_VERSION(2,0,0)
  116. gtk_widget_show (error);
  117. #endif
  118. dialog_vbox1 = GTK_DIALOG (error)->vbox;
  119. gtk_object_set_data (GTK_OBJECT (error), "dialog_vbox1", dialog_vbox1);
  120. gtk_widget_show (dialog_vbox1);
  121. hbox1 = gtk_hbox_new (FALSE, 6);
  122. gtk_widget_ref (hbox1);
  123. gtk_object_set_data_full (GTK_OBJECT (error), "hbox1", hbox1,
  124. (GtkDestroyNotify) gtk_widget_unref);
  125. gtk_widget_show (hbox1);
  126. gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
  127. gtk_container_set_border_width (GTK_CONTAINER (hbox1), 6);
  128. #if GTK_CHECK_VERSION(2,0,0)
  129. style = gtk_widget_get_style (error);
  130. pixmap =
  131. gdk_pixmap_create_from_xpm_d (error->window, &mask,
  132. &style->bg[GTK_STATE_NORMAL], (gchar **) error_xpm);
  133. #else
  134. style = gtk_widget_get_style (GTK_WIDGET (hwnd));
  135. pixmap =
  136. gdk_pixmap_create_from_xpm_d (GTK_WIDGET (hwnd)->window, &mask,
  137. &style->bg[GTK_STATE_NORMAL], (gchar **) error_xpm);
  138. #endif
  139. pixmap1 = gtk_pixmap_new (pixmap, mask);
  140. gtk_widget_ref (pixmap1);
  141. gtk_object_set_data_full (GTK_OBJECT (error), "pixmap1", pixmap1,
  142. (GtkDestroyNotify) gtk_widget_unref);
  143. gtk_widget_show (pixmap1);
  144. gtk_box_pack_start (GTK_BOX (hbox1), pixmap1, FALSE, FALSE, 0);
  145. vbox1 = gtk_vbox_new (TRUE, 0);
  146. gtk_widget_ref (vbox1);
  147. gtk_object_set_data_full (GTK_OBJECT (error), "vbox1", vbox1,
  148. (GtkDestroyNotify) gtk_widget_unref);
  149. gtk_widget_show (vbox1);
  150. gtk_box_pack_start (GTK_BOX (hbox1), vbox1, TRUE, TRUE, 0);
  151. l_text = gtk_label_new ("");
  152. gtk_label_parse_uline (GTK_LABEL (l_text), (text) ? text : "");
  153. gtk_widget_ref (l_text);
  154. gtk_object_set_data_full (GTK_OBJECT (error), "l_text", l_text,
  155. (GtkDestroyNotify) gtk_widget_unref);
  156. gtk_widget_show (l_text);
  157. gtk_box_pack_start (GTK_BOX (vbox1), l_text, FALSE, TRUE, 0);
  158. gtk_label_set_justify (GTK_LABEL (l_text), GTK_JUSTIFY_LEFT);
  159. gtk_label_set_line_wrap (GTK_LABEL (l_text), TRUE);
  160. l_error = gtk_label_new ("");
  161. gtk_label_parse_uline (GTK_LABEL (l_error), (errmsg) ? errmsg : "");
  162. gtk_widget_ref (l_error);
  163. gtk_object_set_data_full (GTK_OBJECT (error), "l_error", l_error,
  164. (GtkDestroyNotify) gtk_widget_unref);
  165. gtk_widget_show (l_error);
  166. gtk_box_pack_start (GTK_BOX (vbox1), l_error, FALSE, TRUE, 0);
  167. gtk_label_set_justify (GTK_LABEL (l_error), GTK_JUSTIFY_LEFT);
  168. gtk_label_set_line_wrap (GTK_LABEL (l_error), TRUE);
  169. dialog_action_area1 = GTK_DIALOG (error)->action_area;
  170. gtk_object_set_data (GTK_OBJECT (error), "dialog_action_area1",
  171. dialog_action_area1);
  172. gtk_widget_show (dialog_action_area1);
  173. gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5);
  174. hbuttonbox1 = gtk_hbutton_box_new ();
  175. gtk_widget_ref (hbuttonbox1);
  176. gtk_object_set_data_full (GTK_OBJECT (error), "hbuttonbox1", hbuttonbox1,
  177. (GtkDestroyNotify) gtk_widget_unref);
  178. gtk_widget_show (hbuttonbox1);
  179. gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE,
  180. 0);
  181. gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END);
  182. gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10);
  183. b_ok = gtk_button_new_from_stock ("gtk-ok");
  184. gtk_widget_ref (b_ok);
  185. gtk_object_set_data_full (GTK_OBJECT (error), "b_ok", b_ok,
  186. (GtkDestroyNotify) gtk_widget_unref);
  187. gtk_widget_show (b_ok);
  188. gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_ok);
  189. gtk_dialog_add_action_widget (GTK_DIALOG (error), b_ok, GTK_RESPONSE_OK);
  190. GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT);
  191. /* Ok button events */
  192. gtk_signal_connect (GTK_OBJECT (b_ok), "clicked",
  193. GTK_SIGNAL_FUNC (error_ok_clicked), error);
  194. /* Close window button events */
  195. gtk_signal_connect (GTK_OBJECT (error), "delete_event",
  196. GTK_SIGNAL_FUNC (delete_event), NULL);
  197. gtk_signal_connect (GTK_OBJECT (error), "destroy",
  198. GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
  199. gtk_window_add_accel_group (GTK_WINDOW (error), accel_group);
  200. gtk_widget_show_all (error);
  201. gtk_main ();
  202. }
  203. void
  204. create_errorw (HWND hwnd, LPCWSTR dsn, LPCWSTR text, LPCWSTR errmsg)
  205. {
  206. LPSTR _dsn = NULL;
  207. LPSTR _text = NULL;
  208. LPSTR _errmsg = NULL;
  209. _dsn = dm_SQL_WtoU8((SQLWCHAR*)dsn, SQL_NTS);
  210. _text = dm_SQL_WtoU8((SQLWCHAR*)text, SQL_NTS);
  211. _errmsg = dm_SQL_WtoU8((SQLWCHAR*)errmsg, SQL_NTS);
  212. create_error(hwnd, _dsn, _text, _errmsg);
  213. if (_dsn)
  214. free(_dsn);
  215. if (_text)
  216. free(_text);
  217. if (_errmsg)
  218. free(_errmsg);
  219. }