aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/month-view.c
blob: a23938b350505c56f58e110af5d0209321e2c461 (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
/* Month view display for gncal
 *
 * Copyright (C) 1998 Red Hat Software, Inc.
 *
 * Author: Federico Mena <federico@nuclecu.unam.mx>
 */

#include <config.h>
#include "month-view.h"


static void month_view_class_init    (MonthViewClass *class);
static void month_view_init          (MonthView      *mv);
static void month_view_size_request  (GtkWidget      *widget,
                      GtkRequisition *requisition);
static void month_view_size_allocate (GtkWidget      *widget,
                      GtkAllocation  *allocation);


static GnomeCanvasClass *parent_class;


GtkType
month_view_get_type (void)
{
    static GtkType month_view_type = 0;

    if (!month_view_type) {
        GtkTypeInfo month_view_info = {
            "MonthView",
            sizeof (MonthView),
            sizeof (MonthViewClass),
            (GtkClassInitFunc) month_view_class_init,
            (GtkObjectInitFunc) month_view_init,
            NULL, /* reserved_1 */
            NULL, /* reserved_2 */
            (GtkClassInitFunc) NULL
        };

        month_view_type = gtk_type_unique (gnome_canvas_get_type (), &month_view_info);
    }

    return month_view_type;
}

static void
month_view_class_init (MonthViewClass *class)
{
    GtkWidgetClass *widget_class;

    widget_class = (GtkWidgetClass *) class;

    parent_class = gtk_type_class (gnome_canvas_get_type ());

    widget_class->size_request = month_view_size_request;
    widget_class->size_allocate = month_view_size_allocate;
}

static void
month_view_init (MonthView *mv)
{
    mv->mitem = gnome_month_item_new (GNOME_CANVAS_GROUP (mv->canvas.root));
    gnome_canvas_item_set (mv->mitem,
                   "x", 0.0,
                   "y", 0.0,
                   "anchor", GTK_ANCHOR_NW,
                   "day_anchor", GTK_ANCHOR_NE,
#if 0
                   "start_on_monday", TRUE,
#endif
                   NULL);
}

GtkWidget *
month_view_new (GnomeCalendar *calendar)
{
    MonthView *mv;

    g_return_val_if_fail (calendar != NULL, NULL);

    mv = gtk_type_new (month_view_get_type ());

    mv->calendar = calendar;

    return GTK_WIDGET (mv);
}

static void
month_view_size_request (GtkWidget *widget, GtkRequisition *requisition)
{
    g_return_if_fail (widget != NULL);
    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_return_if_fail (requisition != NULL);

    if (GTK_WIDGET_CLASS (parent_class)->size_request)
        (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition);

    requisition->width = 200;
    requisition->height = 150;
}

static void
month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
{
    MonthView *mv;

    g_return_if_fail (widget != NULL);
    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_return_if_fail (allocation != NULL);

    mv = MONTH_VIEW (widget);

    if (GTK_WIDGET_CLASS (parent_class)->size_allocate)
        (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation);

    gnome_canvas_set_scroll_region (GNOME_CANVAS (mv), 0, 0, allocation->width, allocation->height);
    gnome_canvas_item_set (mv->mitem,
                   "width", (double) (allocation->width - 1),
                   "height", (double) (allocation->height - 1),
                   NULL);
}