aboutsummaryrefslogtreecommitdiffstats
path: root/widgets/e-table-group.c
blob: 76c317369e918c9fa36ef9ddbd72e51199c02b3b (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
/*
 * E-Table-Group.c: Implements the grouping objects for elements on a table
 *
 * Author:
 *   Miguel de Icaza (miguel@gnu.org()
 *
 * Copyright 1999, Helix Code, Inc.
 */

#include <config.h>
#include <gtk/gtksignal.h>
#include "e-table-group.h"
#include <libgnomeui/gnome-canvas-rect-ellipse.h>
#include "e-util.h"

#define TITLE_HEIGHT         16
#define GROUP_INDENT         10

#define PARENT_TYPE gnome_canvas_group_get_type ()

static GnomeCanvasGroupClass *etg_parent_class;

static void
etg_destroy (GtkObject *object)
{
    ETableGroup *etg = E_TABLE_GROUP (object);
    
    gtk_object_unref (GTK_OBJECT (etg->ecol));
    
    GTK_OBJECT_CLASS (etg_parent_class)->destroy (object);
}

static int
etg_width (ETableGroup *etg)
{
    return e_table_header_total_width (etg->header) + GROUP_INDENT;
}

static int
etg_height (ETableGroup *etg)
{
    GnomeCanvasItem *child = etg->child;
    
    return TITLE_HEIGHT + (child->y2 - child->y1);
}

static void
etg_header_changed (ETableHeader *header, ETableGroup *etg)
{
    gnome_canvas_item_set (
        etg->rect,
        "x2", (double) etg_width (etg),
        NULL);
}

void
e_table_group_construct (GnomeCanvasGroup *parent, ETableGroup *etg, 
             ETableHeader *header, int col,
             GnomeCanvasItem *child, int open)
{
    gnome_canvas_item_constructv (GNOME_CANVAS_ITEM (etg), parent, 0, NULL);
    
    gtk_object_ref (GTK_OBJECT (header));

    etg->header = header;
    etg->col = col;
    etg->ecol = e_table_header_get_column (header, col);
    etg->open = open;

    gtk_signal_connect (
        GTK_OBJECT (header), "dimension_change",
        GTK_SIGNAL_FUNC (etg_header_changed), etg);

    etg->child = child;

    etg->rect = gnome_canvas_item_new (
        GNOME_CANVAS_GROUP (etg),
        gnome_canvas_rect_get_type (),
        "fill_color", "gray",
        "outline_color", "gray20",
        "x1", 0.0,
        "y1", 0.0,
        "x2", (double) etg_width (etg),
        "y2", (double) etg_height (etg),
        NULL);

    
    /*
     * Reparent the child into our space.
     */
    gnome_canvas_item_reparent (child, GNOME_CANVAS_GROUP (etg));

    gnome_canvas_item_set (
        child,
        "x", (double) GROUP_INDENT,
        "y", (double) TITLE_HEIGHT,
        NULL);
}

GnomeCanvasItem *
e_table_group_new (GnomeCanvasGroup *parent, ETableHeader *header, int col, GnomeCanvasItem *child, int open)
{
    ETableGroup *etg;

    g_return_val_if_fail (parent != NULL, NULL);
    g_return_val_if_fail (header != NULL, NULL);    
    g_return_val_if_fail (child != NULL, NULL);
    
    etg = gtk_type_new (e_table_group_get_type ());

    e_table_group_construct (parent, etg, header, col, child, open);

    return GNOME_CANVAS_ITEM (etg);
}

static void
etg_realize (GnomeCanvasItem *item)
{
    ETableGroup *etg = E_TABLE_GROUP (item);
    
    GNOME_CANVAS_ITEM_CLASS (etg_parent_class)->realize (item);
}

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

    object_class->destroy = etg_destroy;

    item_class->realize = etg_realize;

    etg_parent_class = gtk_type_class (PARENT_TYPE);
}

E_MAKE_TYPE (e_table_group, "ETableGroup", ETableGroup, etg_class_init, NULL, PARENT_TYPE);