aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-table/e-table-column-item.c
blob: 0616327a9358127d0681671c30c2616f1db96bb1 (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
/*
 * E-table-column-view.c: A canvas view of the TableColumn.
 *
 * Author:
 *   Miguel de Icaza (miguel@gnu.org)
 *
 * Copyright 1999, Helix Code, Inc.
 */
#include <config.h>
#include "e-table-column.h"
#include "e-table-column-view.h"

#define PARENT_OBJECT_TYPE gnome_canvas_item_get_type ()

static GnomeCanvasItemClass *etci_parent_class;

enum {
    ARG_0,
    ARG_TABLE_COLUMN
};

static void
etci_destroy (GtkObject *object)
{
    ETableColumnItem *etcv = E_TABLE_COLUMN_VIEW (object);

    gtk_object_unref (GTK_OBJECT (etcv));
    
    if (GTK_OBJECT_CLASS (etcv_parent_class)->destroy)
        (*GTK_OBJECT_CLASS (etcv_parent_class)->destroy) (object);
}

static void
etci_update (GnomeCanvasItem *item, double *affine, ArtSVP *clip_path, int flags)
{
    if (GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update)
        (*GNOME_CANVAS_ITEM_CLASS(item_bar_parent_class)->update)(item, affine, clip_path, flags);

    item->x1 = 0;
    item->y1 = 0;
    item->x2 = INT_MAX;
    item->y2 = INT_MAX;
    gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
}

static void
etci_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
{
    GnomeCanvasItem *item;
    ETableColumnItem *etci;
    int v;

    item = GNOME_CANVAS_ITEM (o);
    etci = E_TABLE_COLUMN_ITEM (o);

    switch (arg_id){
    case ARG_TABLE_COLUMN:
        etci->etci = GTK_VALUE_POINTER (*arg);
        break;
    }
    etci_update (item, NULL, NULL, 0);
}

static void
etci_realize (GnomeCanvasItem *item)
{
    ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item);
    GdkWindow *window;
    GdkColor c;
    
    if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)-> realize)
        (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->realize)(item);

    window = GTK_WIDGET (item->canvas)->window;

    etci->gc = gdk_gc_new (window);
    gnome_canvas_get_color (item->canvas, "black", &c);
    gdk_gc_set_foreground (etci->gc, &c);

    etci->normal_cursor = gdk_cursor_new (GDK_ARROW);
}

static void
etci_unrealize (GnomeCanvasItem *item)
{
    ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item);

    gdk_gc_unref (etci->gc);
    etci->gc = NULL;

    gdk_cursor_destroy (etci->change_cursor);
    etci->change_cursor = NULL;
    
    gdk_cursor_destroy (etci->normal_cursor);
    etci->normal_cursor = NULL;

    if (GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize)
        (*GNOME_CANVAS_ITEM_CLASS (etci_parent_class)->unrealize)(item);
}

static void
etci_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x1, int y1, int width, int height)
{
    ETableColumnItem *etci = E_TABLE_COLUMN_ITEM (item);
    GnomeCanvas *canvas = item->canvas;
    GdkGC *gc;
    const int cols = e_table_column_count (etci->etc);
    int x2 = x1 + width;
    int col, total;

    total = 0;
    for (col = 0; col < cols; col++){
        ETableCol *col = e_table_column_get_column (etci->etc, col);
        const int col_width = col->width;

        if (x1 > total + col_width)
            continue;

        if (x2 < total)
            return;

        gc = canvas->style->bg_gc [GTK_STATE_ACTIVE];
        gdk_draw_rectangle (drawble, gc, TRUE, 
        gtk_draw_shadow (canvas->style, drawable, GTK_STATE_NORMAL, GTK_SHADOW_OUT,
                 x, y, width, height
    }
}

static double
etci_point (GnomeCanvasItem *item, double x, double y, int cx, int cy,
        GnomeCanvasItem **actual_item)
{
    *actual_item = *item;
    return 0.0;
}

static void
etci_event (GnomeCanvasItem *item, GdkEvent *e)
{
    switch (e->type){
    default:
        return FALSE;
    }
    return TRUE;
}

static void
etci_class_init (GtkObjectClass *object_class)
{
    GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class;

    object_class->destroy = etci_destroy;
    object_class->set_arg = etci_set_arg;

    item_class->update      = etci_update;
    item_class->realize     = etci_realize;
    item_class->unrealize   = etci_unrealize;
    item_class->draw        = etci_draw;
    item_class->point       = etci_point;
    item_class->event       = etci_event;
    
    gtk_object_add_arg_type ("ETableColumnItem::ETableColumn", GTK_TYPE_POINTER,
                 GTK_ARG_WRITABLE, ARG_TABLE_COLUMN);
}

static void
etci_init (GnomeCanvasItem *item)
{
    item->x1 = 0;
    item->y1 = 0;
    item->x2 = 0;
    item->y2 = 0;
}

GtkType
e_table_column_view_get_type (void)
{
    static GtkType type = 0;

    if (!type){
        GtkTypeInfo info = {
            "ETableColumnItem",
            sizeof (ETableColumnItem),
            sizeof (ETableColumnItemClass),
            (GtkClassInitFunc) etci_class_init,
            (GtkObjectInitFunc) etci_init,
            NULL, /* reserved 1 */
            NULL, /* reserved 2 */
            (GtkClassInitFunc) NULL
        };

        type = gtk_type_unique (PARENT_OBJECT_TYPE, &info);
    }

    return type;
}