evolution-3.6.4/widgets/misc/test-calendar.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *		Damon Chaplin <damon@ximian.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 /*
 24  * test-calendar - tests the ECalendar widget.
 25  */
 26 
 27 #ifdef HAVE_CONFIG_H
 28 #include <config.h>
 29 #endif
 30 
 31 #include <gtk/gtk.h>
 32 
 33 #include "e-calendar.h"
 34 
 35 /* Drag and Drop stuff. */
 36 enum {
 37 	TARGET_SHORTCUT
 38 };
 39 
 40 static GtkTargetEntry target_table[] = {
 41 	{ (gchar *) "E-SHORTCUT", 0, TARGET_SHORTCUT }
 42 };
 43 
 44 static void on_date_range_changed	(ECalendarItem *calitem);
 45 static void on_selection_changed	(ECalendarItem *calitem);
 46 
 47 static void
 48 delete_event_cb (GtkWidget *widget,
 49                  GdkEventAny *event,
 50                  gpointer data)
 51 {
 52 	gtk_main_quit ();
 53 }
 54 
 55 gint
 56 main (gint argc,
 57       gchar **argv)
 58 {
 59 	GtkWidget *window;
 60 	GtkWidget *cal;
 61 	GtkWidget *vbox;
 62 	ECalendarItem *calitem;
 63 
 64 	gtk_init (&argc, &argv);
 65 
 66 	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
 67 	gtk_window_set_title (GTK_WINDOW (window), "ECalendar Test");
 68 	gtk_window_set_default_size (GTK_WINDOW (window), 400, 400);
 69 	gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
 70 	gtk_container_set_border_width (GTK_CONTAINER (window), 8);
 71 
 72 	g_signal_connect (
 73 		window, "delete_event",
 74 		G_CALLBACK (delete_event_cb), NULL);
 75 
 76 	cal = e_calendar_new ();
 77 	e_calendar_set_minimum_size (E_CALENDAR (cal), 1, 1);
 78 	calitem = E_CALENDAR (cal)->calitem;
 79 	gtk_widget_show (cal);
 80 
 81 	g_signal_connect (
 82 		calitem, "date_range_changed",
 83 		G_CALLBACK (on_date_range_changed), NULL);
 84 	g_signal_connect (
 85 		calitem, "selection_changed",
 86 		G_CALLBACK (on_selection_changed), NULL);
 87 
 88 	gtk_drag_dest_set (
 89 		cal,
 90 		GTK_DEST_DEFAULT_ALL,
 91 		target_table, G_N_ELEMENTS (target_table),
 92 		GDK_ACTION_COPY | GDK_ACTION_MOVE);
 93 
 94 	vbox = gtk_vbox_new (FALSE, 0);
 95 	gtk_box_pack_start (GTK_BOX (vbox), cal, TRUE, TRUE, 0);
 96 	gtk_widget_show (vbox);
 97 
 98 	gtk_container_add (GTK_CONTAINER (window), vbox);
 99 	gtk_widget_show (window);
100 
101 	gtk_main ();
102 
103 	return 0;
104 }
105 
106 static void
107 on_date_range_changed (ECalendarItem *calitem)
108 {
109 	gint start_year, start_month, start_day;
110 	gint end_year, end_month, end_day;
111 
112 	e_calendar_item_get_date_range (
113 		calitem,
114 		&start_year, &start_month, &start_day,
115 		&end_year, &end_month, &end_day);
116 
117 	g_print (
118 		"Date range changed (D/M/Y): %i/%i/%i - %i/%i/%i\n",
119 		start_day, start_month + 1, start_year,
120 		end_day, end_month + 1, end_year);
121 
122 	/* These days should windowear bold. Remember month is 0 to 11. */
123 	e_calendar_item_mark_day (
124 		calitem, 2000, 7, 26, /* 26th Aug 2000. */
125 		E_CALENDAR_ITEM_MARK_BOLD, FALSE);
126 	e_calendar_item_mark_day (
127 		calitem, 2000, 8, 13, /* 13th Sep 2000. */
128 		E_CALENDAR_ITEM_MARK_BOLD, FALSE);
129 }
130 
131 static void
132 on_selection_changed (ECalendarItem *calitem)
133 {
134 	GDate start_date, end_date;
135 
136 	e_calendar_item_get_selection (calitem, &start_date, &end_date);
137 
138 	g_print (
139 		"Selection changed (D/M/Y): %i/%i/%i - %i/%i/%i\n",
140 		g_date_get_day (&start_date),
141 		g_date_get_month (&start_date),
142 		g_date_get_year (&start_date),
143 		g_date_get_day (&end_date),
144 		g_date_get_month (&end_date),
145 		g_date_get_year (&end_date));
146 }