aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-month-view.c
blob: bfb3d1f2d667f6414f9a86ed89fe289fc500a6bf (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
/*
 * e-month-view.c
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * This program 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>
 *
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-month-view.h"

#define E_MONTH_VIEW_GET_PRIVATE(obj) \
    (G_TYPE_INSTANCE_GET_PRIVATE \
    ((obj), E_TYPE_MONTH_VIEW, EMonthViewPrivate))

struct _EMonthViewPrivate {
    gint placeholder;
};

G_DEFINE_TYPE (EMonthView, e_month_view, E_TYPE_WEEK_VIEW)

static void
month_view_cursor_key_up (EWeekView *week_view)
{
    if (week_view->selection_start_day == -1)
        return;

    if (week_view->selection_start_day < 7) {
        /* No easy way to calculate new selection_start_day, so
         * calculate a time_t value and set_selected_time_range. */
        time_t current;

        if (e_calendar_view_get_selected_time_range (
            E_CALENDAR_VIEW (week_view), &current, NULL)) {

            current = time_add_week (current, -1);
            e_week_view_scroll_a_step (
                week_view, E_CAL_VIEW_MOVE_PAGE_UP);
            e_week_view_set_selected_time_range_visible (
                week_view, current, current);
        }
    } else {
        week_view->selection_start_day -= 7;
        week_view->selection_end_day = week_view->selection_start_day;
    }

    g_signal_emit_by_name (week_view, "selected-time-changed");
    gtk_widget_queue_draw (week_view->main_canvas);
}

static void
month_view_cursor_key_down (EWeekView *week_view)
{
    gint weeks_shown;

    if (week_view->selection_start_day == -1)
        return;

    weeks_shown = e_week_view_get_weeks_shown (week_view);

    if (week_view->selection_start_day >= (weeks_shown - 1) * 7) {
        /* No easy way to calculate new selection_start_day, so
         * calculate a time_t value and set_selected_time_range. */
        time_t current;

        if (e_calendar_view_get_selected_time_range (
            E_CALENDAR_VIEW (week_view), &current, NULL)) {

            current = time_add_week (current, -1);
            e_week_view_scroll_a_step (
                week_view, E_CAL_VIEW_MOVE_PAGE_DOWN);
            e_week_view_set_selected_time_range_visible (
                week_view, current, current);
        }
    } else {
        week_view->selection_start_day += 7;
        week_view->selection_end_day = week_view->selection_start_day;
    }

    g_signal_emit_by_name (week_view, "selected-time-changed");
    gtk_widget_queue_draw (week_view->main_canvas);
}

static void
month_view_cursor_key_left (EWeekView *week_view)
{
    if (week_view->selection_start_day == -1)
        return;

    if (week_view->selection_start_day == 0) {
        /* No easy way to calculate new selection_start_day, so
         * calculate a time_t value and set_selected_time_range. */
        time_t current;

        if (e_calendar_view_get_selected_time_range (
            E_CALENDAR_VIEW (week_view), &current, NULL)) {

            current = time_add_day (current, -1);
            e_week_view_scroll_a_step (
                week_view, E_CAL_VIEW_MOVE_PAGE_UP);
            e_week_view_set_selected_time_range_visible (
                week_view, current, current);
        }
    } else {
        week_view->selection_start_day--;
        week_view->selection_end_day = week_view->selection_start_day;
    }

    g_signal_emit_by_name (week_view, "selected-time-changed");
    gtk_widget_queue_draw (week_view->main_canvas);
}

static void
month_view_cursor_key_right (EWeekView *week_view)
{
    gint weeks_shown;

    if (week_view->selection_start_day == -1)
        return;

    weeks_shown = e_week_view_get_weeks_shown (week_view);

    if (week_view->selection_start_day == weeks_shown * 7 - 1) {
        /* No easy way to calculate new selection_start_day, so
         * calculate a time_t value and set_selected_time_range. */
        time_t current;

        if (e_calendar_view_get_selected_time_range (
            E_CALENDAR_VIEW (week_view), &current, NULL)) {

            current = time_add_day (current, 1);
            e_week_view_scroll_a_step (
                week_view, E_CAL_VIEW_MOVE_PAGE_DOWN);
            e_week_view_set_selected_time_range_visible (
                week_view, current, current);
        }
    } else {
        week_view->selection_start_day++;
        week_view->selection_end_day = week_view->selection_start_day;
    }

    g_signal_emit_by_name (week_view, "selected-time-changed");
    gtk_widget_queue_draw (week_view->main_canvas);
}

static void
e_month_view_class_init (EMonthViewClass *class)
{
    EWeekViewClass *week_view_class;

    g_type_class_add_private (class, sizeof (EMonthViewPrivate));

    week_view_class = E_WEEK_VIEW_CLASS (class);
    week_view_class->cursor_key_up = month_view_cursor_key_up;
    week_view_class->cursor_key_down = month_view_cursor_key_down;
    week_view_class->cursor_key_left = month_view_cursor_key_left;
    week_view_class->cursor_key_right = month_view_cursor_key_right;
}

static void
e_month_view_init (EMonthView *month_view)
{
    month_view->priv = E_MONTH_VIEW_GET_PRIVATE (month_view);
}

ECalendarView *
e_month_view_new (ECalModel *model)
{
    g_return_val_if_fail (E_IS_CAL_MODEL (model), NULL);

    return g_object_new (E_TYPE_MONTH_VIEW, "model", model, NULL);
}