--- clock.c	2003-12-16 18:41:51.000000000 -0700
+++ clock.c	2003-12-16 19:00:02.000000000 -0700
@@ -3,6 +3,7 @@
  *  Copyright (C) 2002 Jasper Huijsmans(huysmans@users.sourceforge.net)
  *                     Xavier Maillard (zedek@fxgsproject.org)
  *                     Olivier Fourdan (fourdan@xfce.org)
+ *                     Choe Hwanjin(krisna@kldp.org)
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -85,7 +86,9 @@
 {
     GtkWidget *eventbox;
     GtkWidget *clock;		/* our XfceClock widget */
+	GtkWidget *calendar;	/* our XfceCalendar popup */
 
+	gint orientation;	/* panel orientation */
     int timeout_id;		/* update the date tooltip */
 }
 t_clock;
@@ -115,6 +118,119 @@
 }
 ClockDialog;
 
+/* creation of calendar popup */
+static GtkWidget *
+pop_calendar_window(GtkWidget *parent, int orientation)
+{
+	GtkWidget *window;
+	GtkWidget *cal;
+	gint parent_x, parent_y, parent_w, parent_h;
+	gint root_w, root_h;
+	gint width, height, x, y;
+	guint day;
+	GtkRequisition requisition;
+	GtkAllocation allocation;
+
+	window = gtk_window_new(GTK_WINDOW_POPUP);
+
+	cal = gtk_calendar_new();
+
+	gtk_calendar_get_date(GTK_CALENDAR(cal), NULL, NULL, &day);
+	gtk_calendar_mark_day(GTK_CALENDAR(cal), day);
+	gtk_container_add(GTK_CONTAINER(window), cal);
+
+	gdk_window_get_origin(GDK_WINDOW(parent->window), &parent_x, &parent_y);
+	gdk_drawable_get_size(GDK_DRAWABLE(parent->window), &parent_w, &parent_h);
+
+	root_w = gdk_screen_width();
+	root_h = gdk_screen_height();
+
+	gtk_widget_realize(GTK_WIDGET(window));
+
+	gtk_widget_size_request(GTK_WIDGET(cal), &requisition);
+
+	allocation.x = requisition.width;
+	allocation.y = requisition.height;
+	gtk_widget_size_allocate(GTK_WIDGET(cal), &allocation);
+
+	gtk_widget_size_request(GTK_WIDGET(cal), &requisition);
+	width = requisition.width;
+	height = requisition.height;
+
+	if (orientation == GTK_ORIENTATION_VERTICAL) {
+		if (parent_x < root_w / 2) {
+			if (parent_y < root_h / 2) {
+				/* upper left */
+				x = parent_x + parent_w;
+				y = parent_y;
+			} else {
+				/* lower left */
+				x = parent_x + parent_w;
+				y = parent_y + parent_h - height;
+			}
+		} else {
+			if (parent_y < root_h / 2) {
+				/* upper right */
+				x = parent_x - parent_w;
+				y = parent_y;
+			} else {
+				/* lower right */
+				x = parent_x - parent_w;
+				y = parent_y + parent_h - height;
+			}
+		}
+	} else {
+		if (parent_x < root_w / 2) {
+			if (parent_y < root_h / 2) {
+				/* upper left */
+				x = parent_x;
+				y = parent_y + parent_h;
+			} else {
+				/* lower left */
+				x = parent_x;
+				y = parent_y - height;
+			}
+		} else {
+			if (parent_y < root_h / 2) {
+				/* upper right */
+				x = parent_x + parent_w - width;
+				y = parent_y + parent_h;
+			} else {
+				/* lower right */
+				x = parent_x + parent_w - width;
+				y = parent_y - height;
+			}
+		}
+	}
+
+	gtk_window_move(GTK_WINDOW(window), x, y);
+	gtk_widget_show(cal);
+	gtk_widget_show(window);
+
+	return window;
+}
+
+/* input handler for mouse clicks on clock */
+static gboolean
+on_button_press_event_cb(GtkWidget *widget, GdkEventButton *event, gpointer data)
+{
+	if (event->button == 1) {
+		t_clock *clock;
+
+		if (data == NULL) return FALSE;
+
+		clock = (t_clock *)data;
+		if (clock->calendar != NULL) {
+			gtk_widget_destroy(clock->calendar);
+			clock->calendar = NULL;
+		} else {
+			clock->calendar = pop_calendar_window(clock->eventbox, clock->orientation);
+		}
+		return TRUE;
+	}
+	return FALSE;
+}
+
 /* creation and destruction */
 gboolean
 clock_date_tooltip (GtkWidget * widget)
@@ -162,6 +278,11 @@
     /* Add tooltip to show the current date */
     clock_date_tooltip (clock->eventbox);
 
+	/* Calendar popup */
+	clock->calendar = NULL;
+	clock->orientation = GTK_ORIENTATION_HORIZONTAL;
+	g_signal_connect(clock->eventbox, "button-press-event", G_CALLBACK(on_button_press_event_cb), clock);
+
     clock->timeout_id =
 	g_timeout_add (60000, (GSourceFunc) clock_date_tooltip,
 		       clock->eventbox);
@@ -231,6 +352,13 @@
     update_clock_size (tmp, size);
 }
 
+void
+clock_set_orientation(Control *control, int orientation)
+{
+	t_clock *clock= control->data;
+	clock->orientation = orientation;
+}
+
 /* Write the configuration at exit */
 void
 clock_write_config (Control * control, xmlNodePtr parent)
@@ -608,6 +736,7 @@
     cc->create_options = clock_create_options;
 
     cc->set_size = clock_set_size;
+	cc->set_orientation = clock_set_orientation;
 }
 
 /* macro defined in plugins.h */

