1/*
2 *  messagebox.c
3 *
4 *  $Id: messagebox.c,v 1.7 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
78
79static gint
80delete_event (GtkWidget *widget, GdkEvent *event)
81{
82  return FALSE;
83}
84
85
86static void
87message_ok_clicked (GtkWidget *widget, GtkWidget *message)
88{
89  gtk_signal_disconnect_by_func (GTK_OBJECT (message),
90      GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
91  gtk_main_quit ();
92  gtk_widget_destroy (message);
93}
94
95
96void
97create_message (HWND hwnd, LPCSTR dsn, LPCSTR text)
98{
99  GtkWidget *message, *dialog_vbox1, *hbox1, *vbox1;
100  GtkWidget *l_message, *dialog_action_area1, *hbuttonbox1, *b_ok;
101  GtkAccelGroup *accel_group;
102  guint b_ok_key;
103  char msg[1024];
104
105  if (hwnd == NULL || !GTK_IS_WIDGET (hwnd))
106    return;
107
108  accel_group = gtk_accel_group_new ();
109
110  message = gtk_dialog_new ();
111  if (dsn)
112    sprintf (msg, "Message on DSN %s", dsn);
113  else
114    sprintf (msg, "Message ...");
115  gtk_object_set_data (GTK_OBJECT (message), "message", message);
116  gtk_window_set_title (GTK_WINDOW (message), msg);
117  gtk_window_set_position (GTK_WINDOW (message), GTK_WIN_POS_CENTER);
118  gtk_window_set_modal (GTK_WINDOW (message), TRUE);
119#if GTK_CHECK_VERSION(2,0,0)
120  gtk_window_set_policy (GTK_WINDOW (message), FALSE, FALSE, FALSE);
121#else
122  gtk_window_set_policy (GTK_WINDOW (message), TRUE, TRUE, FALSE);
123#endif
124
125#if GTK_CHECK_VERSION(2,0,0)
126  gtk_widget_show (message);
127#endif
128
129  dialog_vbox1 = GTK_DIALOG (message)->vbox;
130  gtk_object_set_data (GTK_OBJECT (message), "dialog_vbox1", dialog_vbox1);
131  gtk_widget_show (dialog_vbox1);
132
133  hbox1 = gtk_hbox_new (FALSE, 6);
134  gtk_widget_ref (hbox1);
135  gtk_object_set_data_full (GTK_OBJECT (message), "hbox1", hbox1,
136      (GtkDestroyNotify) gtk_widget_unref);
137  gtk_widget_show (hbox1);
138  gtk_box_pack_start (GTK_BOX (dialog_vbox1), hbox1, TRUE, TRUE, 0);
139  gtk_container_set_border_width (GTK_CONTAINER (hbox1), 6);
140
141  vbox1 = gtk_vbox_new (TRUE, 0);
142  gtk_widget_ref (vbox1);
143  gtk_object_set_data_full (GTK_OBJECT (message), "vbox1", vbox1,
144      (GtkDestroyNotify) gtk_widget_unref);
145  gtk_widget_show (vbox1);
146  gtk_box_pack_start (GTK_BOX (hbox1), vbox1, TRUE, TRUE, 0);
147
148  l_message = gtk_label_new ("");
149  gtk_label_parse_uline (GTK_LABEL (l_message), (text) ? text : "");
150  gtk_widget_ref (l_message);
151  gtk_object_set_data_full (GTK_OBJECT (message), "l_message", l_message,
152      (GtkDestroyNotify) gtk_widget_unref);
153  gtk_widget_show (l_message);
154  gtk_box_pack_start (GTK_BOX (vbox1), l_message, FALSE, TRUE, 0);
155  gtk_label_set_justify (GTK_LABEL (l_message), GTK_JUSTIFY_LEFT);
156  gtk_label_set_line_wrap (GTK_LABEL (l_message), TRUE);
157
158  dialog_action_area1 = GTK_DIALOG (message)->action_area;
159  gtk_object_set_data (GTK_OBJECT (message), "dialog_action_area1",
160      dialog_action_area1);
161  gtk_widget_show (dialog_action_area1);
162  gtk_container_set_border_width (GTK_CONTAINER (dialog_action_area1), 5);
163
164  hbuttonbox1 = gtk_hbutton_box_new ();
165  gtk_widget_ref (hbuttonbox1);
166  gtk_object_set_data_full (GTK_OBJECT (message), "hbuttonbox1", hbuttonbox1,
167      (GtkDestroyNotify) gtk_widget_unref);
168  gtk_widget_show (hbuttonbox1);
169  gtk_box_pack_start (GTK_BOX (dialog_action_area1), hbuttonbox1, TRUE, TRUE,
170      0);
171  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbuttonbox1), GTK_BUTTONBOX_END);
172  gtk_button_box_set_spacing (GTK_BUTTON_BOX (hbuttonbox1), 10);
173
174  b_ok = gtk_button_new_with_label ("");
175  b_ok_key = gtk_label_parse_uline (GTK_LABEL (GTK_BIN (b_ok)->child), "_Ok");
176  gtk_widget_add_accelerator (b_ok, "clicked", accel_group,
177      b_ok_key, GDK_MOD1_MASK, 0);
178  gtk_widget_ref (b_ok);
179  gtk_object_set_data_full (GTK_OBJECT (message), "b_ok", b_ok,
180      (GtkDestroyNotify) gtk_widget_unref);
181  gtk_widget_show (b_ok);
182  gtk_container_add (GTK_CONTAINER (hbuttonbox1), b_ok);
183  GTK_WIDGET_SET_FLAGS (b_ok, GTK_CAN_DEFAULT);
184
185  /* Ok button events */
186  gtk_signal_connect (GTK_OBJECT (b_ok), "clicked",
187      GTK_SIGNAL_FUNC (message_ok_clicked), message);
188  /* Close window button events */
189  gtk_signal_connect (GTK_OBJECT (message), "delete_event",
190      GTK_SIGNAL_FUNC (delete_event), NULL);
191  gtk_signal_connect (GTK_OBJECT (message), "destroy",
192      GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
193
194  gtk_window_add_accel_group (GTK_WINDOW (message), accel_group);
195
196  gtk_widget_show_all (message);
197  gtk_main ();
198}
199
200void
201create_messagew (HWND hwnd, LPCWSTR dsn, LPCWSTR text)
202{
203  LPSTR _dsn = NULL;
204  LPSTR _text = NULL;
205
206  _dsn = dm_SQL_WtoU8(dsn, SQL_NTS);
207  _text = dm_SQL_WtoU8(text, SQL_NTS);
208
209  create_message(hwnd, _dsn, _text);
210
211  if (_dsn)
212    free(_dsn);
213  if (_text)
214    free(_text);
215}
216