~ubuntu-branches/ubuntu/maverick/gwhere/maverick

« back to all changes in this revision

Viewing changes to src/gui/gwdialogbox.c

  • Committer: Bazaar Package Importer
  • Author(s): Sébastien LECACHEUR
  • Date: 2004-09-27 00:41:00 UTC
  • Revision ID: james.westby@ubuntu.com-20040927004100-q23139ty7b94kryi
Tags: upstream-0.1.6
Import upstream version 0.1.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  GWhere
 
2
 *  Copyright (C) 2000  S�bastien LECACHEUR
 
3
 *
 
4
 *  This program is free software; you can redistribute it and/or modify
 
5
 *  it under the terms of the GNU General Public License as published by
 
6
 *  the Free Software Foundation; either version 2 of the License, or
 
7
 *  (at your option) any later version.
 
8
 *
 
9
 *  This program is distributed in the hope that it will be useful,
 
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 *  GNU General Public License for more details.
 
13
 *
 
14
 *  You should have received a copy of the GNU General Public License
 
15
 *  along with this program; if not, write to the Free Software
 
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
 
 
20
#include "../gwsupport.h"
 
21
#include "gwdialogbox.h"
 
22
 
 
23
 
 
24
/*! @define     GW_REF_DIALOG_BOX_PARENT_WINDOW The parent window */
 
25
#define GW_REF_DIALOG_BOX_PARENT_WINDOW "gw_ref_dialog_box_parent_window"
 
26
/*! @define     GW_REF_DIALOG_BOX_USER_DATA     The attached user data */
 
27
#define GW_REF_DIALOG_BOX_USER_DATA "gw_ref_dialog_box_user_data"
 
28
 
 
29
 
 
30
GtkWidget * gw_dialog_box_create ( GtkWindow *window, gchar *title, gchar *text, GtkSignalFunc ok, GtkSignalFunc no, GtkSignalFunc cancel, gpointer data)
 
31
{
 
32
        /*static */GtkWidget *w = NULL;
 
33
        GtkWidget *label;
 
34
        GtkWidget *button;
 
35
        guint button_key;
 
36
        GtkAccelGroup *accel;
 
37
        gchar *text_utf8 = NULL;
 
38
 
 
39
 
 
40
#ifdef GW_DEBUG_GUI_COMPONENT
 
41
        g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
 
42
#endif
 
43
 
 
44
        if ( !w )
 
45
        {
 
46
                accel = gtk_accel_group_new ( );
 
47
 
 
48
                w = gtk_dialog_new ( );
 
49
 
 
50
                if ( window != NULL )
 
51
                {
 
52
                        gtk_window_set_modal ( GTK_WINDOW ( w), TRUE);
 
53
                        gtk_window_set_transient_for ( GTK_WINDOW ( w), GTK_WINDOW ( window));
 
54
                        gtk_object_set_data ( GTK_OBJECT ( w), GW_REF_DIALOG_BOX_PARENT_WINDOW, window);
 
55
                }
 
56
 
 
57
                if ( data != NULL )
 
58
                {
 
59
                        gtk_object_set_data ( GTK_OBJECT ( w), GW_REF_DIALOG_BOX_USER_DATA, data);
 
60
                }
 
61
 
 
62
                gtk_window_set_position ( GTK_WINDOW ( w), GTK_WIN_POS_CENTER);
 
63
                gtk_container_set_border_width ( GTK_CONTAINER ( w), 10);
 
64
                gtk_window_set_policy ( GTK_WINDOW ( w), FALSE, FALSE, TRUE);
 
65
 
 
66
#ifdef HAVE_GTK12
 
67
                gtk_signal_connect ( GTK_OBJECT ( w), "destroy", GTK_SIGNAL_FUNC ( gtk_widget_destroyed), &w);
 
68
#endif
 
69
                g_strdup_to_gtk_text ( title, text_utf8);
 
70
                gtk_window_set_title ( GTK_WINDOW ( w), text_utf8);
 
71
                g_free ( text_utf8);
 
72
 
 
73
                g_strdup_to_gtk_text ( text, text_utf8);
 
74
                label = gtk_label_new ( text_utf8);
 
75
                g_free ( text_utf8);
 
76
                gtk_misc_set_padding ( GTK_MISC ( label), 10, 10);
 
77
                gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( w)->vbox), label, TRUE, TRUE, 0);
 
78
 
 
79
                button = gtk_button_new_with_label ( "");
 
80
                g_strdup_to_gtk_text ( _( "_OK"), text_utf8);
 
81
                button_key = gtk_label_parse_uline ( GTK_LABEL ( GTK_BIN ( button)->child), text_utf8);
 
82
                g_free ( text_utf8);
 
83
                gtk_widget_add_accelerator ( button, "clicked", accel, button_key, GDK_MOD1_MASK, 0);
 
84
 
 
85
                if ( ok != NULL )
 
86
                {
 
87
                        gtk_signal_connect ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( ok), w);
 
88
                }
 
89
                else
 
90
                {
 
91
                        gtk_signal_connect_object ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( gtk_widget_destroy), GTK_OBJECT ( w));
 
92
                }
 
93
 
 
94
                gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( w)->action_area), button, TRUE, TRUE, 0);
 
95
                gtk_widget_grab_focus ( button);
 
96
 
 
97
                button = gtk_button_new_with_label ( "");
 
98
                g_strdup_to_gtk_text ( _("_No"), text_utf8);
 
99
                button_key = gtk_label_parse_uline ( GTK_LABEL ( GTK_BIN ( button)->child), text_utf8);
 
100
                g_free ( text_utf8);
 
101
                gtk_widget_add_accelerator ( button, "clicked", accel, button_key, GDK_MOD1_MASK, 0);
 
102
 
 
103
                if ( no != NULL )
 
104
                {
 
105
                        gtk_signal_connect ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( no), w);
 
106
                }
 
107
                else
 
108
                {
 
109
                        gtk_signal_connect_object ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( gtk_widget_destroy), GTK_OBJECT ( w));
 
110
                }
 
111
 
 
112
                gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( w)->action_area), button, TRUE, TRUE, 0);
 
113
 
 
114
                button = gtk_button_new_with_label ( "");
 
115
                g_strdup_to_gtk_text ( _("_Cancel"), text_utf8);
 
116
                button_key = gtk_label_parse_uline ( GTK_LABEL ( GTK_BIN ( button)->child), text_utf8);
 
117
                g_free ( text_utf8);
 
118
                gtk_widget_add_accelerator ( button, "clicked", accel, button_key, GDK_MOD1_MASK, 0);
 
119
 
 
120
                if ( cancel != NULL )
 
121
                {
 
122
                        gtk_signal_connect ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( cancel), w);
 
123
                }
 
124
                else
 
125
                {
 
126
                        gtk_signal_connect_object ( GTK_OBJECT ( button), "clicked", GTK_SIGNAL_FUNC ( gtk_widget_destroy), GTK_OBJECT ( w));
 
127
                }
 
128
 
 
129
                gtk_box_pack_start ( GTK_BOX ( GTK_DIALOG ( w)->action_area), button, TRUE, TRUE, 0);
 
130
 
 
131
                gtk_window_add_accel_group ( GTK_WINDOW ( w), accel);
 
132
        }
 
133
 
 
134
        if ( !GTK_WIDGET_VISIBLE ( w) )
 
135
        {
 
136
                gtk_widget_show_all ( w);
 
137
        }
 
138
        else
 
139
        {
 
140
                gtk_widget_destroy ( w);
 
141
        }
 
142
 
 
143
        return w;
 
144
}
 
145
 
 
146
 
 
147
gpointer gw_dialog_box_get_user_data ( GtkWindow *w)
 
148
{
 
149
        gpointer data = NULL;
 
150
 
 
151
 
 
152
#ifdef GW_DEBUG_GUI_COMPONENT
 
153
        g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
 
154
#endif
 
155
 
 
156
        if ( w != NULL )
 
157
        {
 
158
                data = gtk_object_get_data ( GTK_OBJECT ( w), GW_REF_DIALOG_BOX_USER_DATA);
 
159
        }
 
160
 
 
161
        return data;
 
162
}
 
163
 
 
164
 
 
165
GtkWindow * gw_dialog_box_get_parent_window ( GtkWindow *w)
 
166
{
 
167
        GtkWindow *window = NULL;
 
168
 
 
169
 
 
170
#ifdef GW_DEBUG_GUI_COMPONENT
 
171
        g_print ( "*** GW - %s (%d) :: %s()\n", __FILE__, __LINE__, __PRETTY_FUNCTION__);
 
172
#endif
 
173
 
 
174
        if ( w != NULL )
 
175
        {
 
176
                window = gtk_object_get_data ( GTK_OBJECT ( w), GW_REF_DIALOG_BOX_PARENT_WINDOW);
 
177
        }
 
178
 
 
179
        return window;
 
180
}