2 * app_calendar - zavai calendar applet
4 * Copyright (C) 2009 Enrico Zini <enrico@enricozini.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 public class Calendar : Applet
27 protected Gtk.Calendar calendar;
28 protected Gtk.ScrolledWindow scroll;
29 protected Gtk.TextBuffer text_buffer;
30 protected Gtk.TextView text;
35 calendar = new Gtk.Calendar();
36 calendar.day_selected += on_day_selected;
37 calendar.month_changed += on_month_changed;
38 pack_start(calendar, false, false, 0);
40 text_buffer = new Gtk.TextBuffer(null);
41 text = new Gtk.TextView.with_buffer(text_buffer);
42 text.wrap_mode = Gtk.WrapMode.WORD;
43 text.cursor_visible = false;
44 text.editable = false;
45 scroll = new Gtk.ScrolledWindow (null, null);
46 scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC);
48 pack_start(scroll, true, true, 0);
53 private void on_month_changed()
55 calendar.clear_marks();
59 private void on_day_selected()
61 string day = "%02d/%02d/%04d".printf(calendar.day, calendar.month, calendar.year);
62 text_buffer.text = day;
64 text_buffer.get_iter_at_offset(out iter, 0);
65 Gtk.TextMark mark = text_buffer.create_mark(null, iter, true);
66 text.scroll_mark_onscreen(mark);
69 public override void start()
72 var now = Time.local(time_t());
73 calendar.year = now.year + 1900;
74 calendar.month = now.month;
75 calendar.day = now.day;
77 public override void stop()
86 calendar = new Calendar();
87 zavai.registry.register_applet("ui.calendar", calendar);
88 zavai.registry.getmenu("menu.misc").add_applet("ui.calendar");