aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/table/e-table-field-chooser-dialog.c
blob: e4116f101dcee9555cd7d9d1b7c7c7590965ed19 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * e-table-field-chooser-dialog.c
 * Copyright 2000, 2001, Ximian, Inc.
 *
 * Authors:
 *   Chris Lahey <clahey@ximian.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License, version 2, as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 */

#include <config.h>
#include "e-table-field-chooser-dialog.h"
#include "gal/util/e-i18n.h"

static void e_table_field_chooser_dialog_init       (ETableFieldChooserDialog        *card);
static void e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass   *klass);
static void e_table_field_chooser_dialog_set_arg (GtkObject *o, GtkArg *arg, guint arg_id);
static void e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id);
static void e_table_field_chooser_dialog_destroy (GtkObject *object);
static void e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, gint button);

static GnomeDialogClass *parent_class = NULL;

/* The arguments we take */
enum {
    ARG_0,
    ARG_DND_CODE,
    ARG_FULL_HEADER,
    ARG_HEADER
};

GtkType
e_table_field_chooser_dialog_get_type (void)
{
    static GtkType table_field_chooser_dialog_type = 0;

    if (!table_field_chooser_dialog_type)
        {
            static const GtkTypeInfo table_field_chooser_dialog_info =
            {

                "ETableFieldChooserDialog",
                sizeof (ETableFieldChooserDialog),
                sizeof (ETableFieldChooserDialogClass),
                (GtkClassInitFunc) e_table_field_chooser_dialog_class_init,
                (GtkObjectInitFunc) e_table_field_chooser_dialog_init,
                /* reserved_1 */ NULL,
                /* reserved_2 */ NULL,
                (GtkClassInitFunc) NULL,
            };

            table_field_chooser_dialog_type = gtk_type_unique (gnome_dialog_get_type (), &table_field_chooser_dialog_info);
        }

    return table_field_chooser_dialog_type;
}

static void
e_table_field_chooser_dialog_class_init (ETableFieldChooserDialogClass *klass)
{
    GtkObjectClass *object_class;
    GnomeDialogClass *dialog_class;

    object_class = (GtkObjectClass*) klass;
    dialog_class = GNOME_DIALOG_CLASS (klass);

    parent_class = gtk_type_class (gnome_dialog_get_type ());

    object_class->destroy = e_table_field_chooser_dialog_destroy;
    object_class->set_arg = e_table_field_chooser_dialog_set_arg;
    object_class->get_arg = e_table_field_chooser_dialog_get_arg;

    dialog_class->clicked = e_table_field_chooser_dialog_clicked;

    gtk_object_add_arg_type ("ETableFieldChooserDialog::dnd_code", GTK_TYPE_STRING,
                 GTK_ARG_READWRITE, ARG_DND_CODE);
    gtk_object_add_arg_type ("ETableFieldChooserDialog::full_header", GTK_TYPE_OBJECT,
                 GTK_ARG_READWRITE, ARG_FULL_HEADER);
    gtk_object_add_arg_type ("ETableFieldChooserDialog::header", GTK_TYPE_OBJECT,
                 GTK_ARG_READWRITE, ARG_HEADER);
}

static void
e_table_field_chooser_dialog_init (ETableFieldChooserDialog *e_table_field_chooser_dialog)
{
    GtkWidget *widget;

    e_table_field_chooser_dialog->etfc = NULL;
    e_table_field_chooser_dialog->dnd_code = g_strdup("");
    e_table_field_chooser_dialog->full_header = NULL;
    e_table_field_chooser_dialog->header = NULL;

    gnome_dialog_append_buttons(GNOME_DIALOG(e_table_field_chooser_dialog),
                    GTK_STOCK_CLOSE,
                    NULL);

    gtk_window_set_policy(GTK_WINDOW(e_table_field_chooser_dialog), FALSE, TRUE, FALSE);

    widget = e_table_field_chooser_new();
    e_table_field_chooser_dialog->etfc = E_TABLE_FIELD_CHOOSER(widget);
    
    gtk_object_set(GTK_OBJECT(widget),
               "dnd_code", e_table_field_chooser_dialog->dnd_code,
               "full_header", e_table_field_chooser_dialog->full_header,
               "header", e_table_field_chooser_dialog->header,
               NULL);
    
    gtk_box_pack_start(GTK_BOX(GNOME_DIALOG(e_table_field_chooser_dialog)->vbox),
               widget, TRUE, TRUE, 0);

    gtk_widget_show(GTK_WIDGET(widget));

    gtk_window_set_title (GTK_WINDOW (e_table_field_chooser_dialog), _("Add a column..."));
}

GtkWidget*
e_table_field_chooser_dialog_new (void)
{
    GtkWidget *widget = GTK_WIDGET (gtk_type_new (e_table_field_chooser_dialog_get_type ()));
    return widget;
}

static void
e_table_field_chooser_dialog_destroy (GtkObject *object)
{
    ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG (object);

    g_free (etfcd->dnd_code);
    etfcd->dnd_code = NULL;

    if (etfcd->full_header)
        g_object_unref (etfcd->full_header);
    etfcd->full_header = NULL;

    if (etfcd->header)
        g_object_unref (etfcd->header);
    etfcd->header = NULL;
}

static void
e_table_field_chooser_dialog_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
    ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object);
    switch (arg_id){
    case ARG_DND_CODE:
        g_free(etfcd->dnd_code);
        etfcd->dnd_code = g_strdup(GTK_VALUE_STRING (*arg));
        if (etfcd->etfc)
            gtk_object_set(GTK_OBJECT(etfcd->etfc),
                       "dnd_code", etfcd->dnd_code,
                       NULL);
        break;
    case ARG_FULL_HEADER:
        if (etfcd->full_header)
            g_object_unref (etfcd->full_header);
        if (GTK_VALUE_OBJECT(*arg))
            etfcd->full_header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg));
        else
            etfcd->full_header = NULL;
        if (etfcd->full_header)
            g_object_ref (etfcd->full_header);
        if (etfcd->etfc)
            gtk_object_set(GTK_OBJECT(etfcd->etfc),
                       "full_header", etfcd->full_header,
                       NULL);
        break;
    case ARG_HEADER:
        if (etfcd->header)
            g_object_unref (etfcd->header);
        if (GTK_VALUE_OBJECT(*arg))
            etfcd->header = E_TABLE_HEADER(GTK_VALUE_OBJECT(*arg));
        else
            etfcd->header = NULL;
        if (etfcd->header)
            g_object_ref (etfcd->header);
        if (etfcd->etfc)
            gtk_object_set(GTK_OBJECT(etfcd->etfc),
                       "header", etfcd->header,
                       NULL);
        break;
    default:
        break;
    }
}

static void
e_table_field_chooser_dialog_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
    ETableFieldChooserDialog *etfcd = E_TABLE_FIELD_CHOOSER_DIALOG(object);
    switch (arg_id) {
    case ARG_DND_CODE:
        GTK_VALUE_STRING (*arg) = g_strdup (etfcd->dnd_code);
        break;
    case ARG_FULL_HEADER:
        GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfcd->full_header);
        break;
    case ARG_HEADER:
        GTK_VALUE_OBJECT (*arg) = GTK_OBJECT(etfcd->header);
        break;
    default:
        arg->type = GTK_TYPE_INVALID;
        break;
    }
}

static void
e_table_field_chooser_dialog_clicked (GnomeDialog *dialog, int button)
{
    if (button == 0)
        gnome_dialog_close(dialog);
}