glom r1390 - in trunk: . glom/utility_widgets glom/utility_widgets/calendar



Author: murrayc
Date: Fri Jan 18 13:47:20 2008
New Revision: 1390
URL: http://svn.gnome.org/viewvc/glom?rev=1390&view=rev

Log:
2008-01-18  Murray Cumming  <murrayc murrayc com>

* configure.in:
* glom/utility_widgets/Makefile.am:
* glom/utility_widgets/calendar/Makefile.am:
* glom/utility_widgets/calendar/README:
* glom/utility_widgets/calendar/glomcalendar.cc:
* glom/utility_widgets/calendar/glomcalendar.h:
* glom/utility_widgets/calendar/glomgtkcalendar.c:
* glom/utility_widgets/calendar/glomgtkcalendar.h:
Added copied (and renamed) versions of Gtk::Calendar and 
GtkCalendar with the new details callback function, 
instead of depending on unreleased/unstable GTK+ and gtkmm.

Added:
   trunk/glom/utility_widgets/calendar/
   trunk/glom/utility_widgets/calendar/Makefile.am
      - copied, changed from r1386, /trunk/glom/utility_widgets/cellrendererlist/Makefile.am
   trunk/glom/utility_widgets/calendar/README
   trunk/glom/utility_widgets/calendar/glomcalendar.cc
   trunk/glom/utility_widgets/calendar/glomcalendar.h
   trunk/glom/utility_widgets/calendar/glomgtkcalendar.c
   trunk/glom/utility_widgets/calendar/glomgtkcalendar.h
Modified:
   trunk/ChangeLog
   trunk/configure.in
   trunk/glom/utility_widgets/Makefile.am

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Fri Jan 18 13:47:20 2008
@@ -209,6 +209,7 @@
     glom/mode_find/Makefile \
     glom/navigation/Makefile \
     glom/utility_widgets/Makefile \
+      glom/utility_widgets/calendar/Makefile \
       glom/utility_widgets/cellrendererlist/Makefile \
       glom/utility_widgets/adddel/Makefile \
         glom/utility_widgets/adddel/eggcolumnchooser/Makefile \

Modified: trunk/glom/utility_widgets/Makefile.am
==============================================================================
--- trunk/glom/utility_widgets/Makefile.am	(original)
+++ trunk/glom/utility_widgets/Makefile.am	Fri Jan 18 13:47:20 2008
@@ -1,6 +1,6 @@
 #AM_CPPFLAGS = -I top_srcdir@/ $(GLOM_CFLAGS)
 
-SUBDIRS = cellrendererlist adddel db_adddel canvas
+SUBDIRS = cellrendererlist adddel db_adddel canvas calendar
 
 gladedir = $(datadir)/glom/glade/
 glom_icon_dir = $(datadir)/glom/pixmaps

Copied: trunk/glom/utility_widgets/calendar/Makefile.am (from r1386, /trunk/glom/utility_widgets/cellrendererlist/Makefile.am)
==============================================================================
--- /trunk/glom/utility_widgets/cellrendererlist/Makefile.am	(original)
+++ trunk/glom/utility_widgets/calendar/Makefile.am	Fri Jan 18 13:47:20 2008
@@ -3,4 +3,5 @@
 AM_CPPFLAGS = -I top_srcdir@/ $(GLOM_CFLAGS)
 
 noinst_LIBRARIES = libutility_widgets_cellrendererlist.a
-libutility_widgets_cellrendererlist_a_SOURCES = cellrendererlist.h cellrendererlist.cc 
+libutility_widgets_cellrendererlist_a_SOURCES = glomgtkcalendar.c glomgtkcalendar.h \
+                                                glomcalendar.cc glomcalendar.h

Added: trunk/glom/utility_widgets/calendar/README
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/calendar/README	Fri Jan 18 13:47:20 2008
@@ -0,0 +1,4 @@
+This is a copy of GtkCalendar and Gtk::Calendar, to 
+avoiding depending on an unreleased version of GTK+, 
+so we can use new API. It should be removed when 
+GTK+ 2.16.0 has been released.

Added: trunk/glom/utility_widgets/calendar/glomcalendar.cc
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/calendar/glomcalendar.cc	Fri Jan 18 13:47:20 2008
@@ -0,0 +1,887 @@
+#include "glomcalendar.h"
+
+#include <gtk/gtk.h>
+#if !GTK_CHECK_VERSION(2,16,0)
+
+#include <gtkmm/private/widget_p.h>
+
+#include <glibmm/class.h>
+
+namespace GlomGtk
+{
+
+class Calendar_Class : public Glib::Class
+{
+public:
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+  typedef Calendar CppObjectType;
+  typedef GlomGtkCalendar BaseObjectType;
+  typedef GlomGtkCalendarClass BaseClassType;
+  typedef Gtk::Widget_Class CppClassParent;
+  typedef GtkWidgetClass BaseClassParent;
+
+  friend class Calendar;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+  const Glib::Class& init();
+
+  static void class_init_function(void* g_class, void* class_data);
+
+  static Glib::ObjectBase* wrap_new(GObject*);
+
+protected:
+
+#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  //Callbacks (default signal handlers):
+  //These will call the *_impl member methods, which will then call the existing default signal callbacks, if any.
+  //You could prevent the original default signal handlers being called by overriding the *_impl method.
+  static void month_changed_callback(GlomGtkCalendar* self);
+  static void day_selected_callback(GlomGtkCalendar* self);
+  static void day_selected_double_click_callback(GlomGtkCalendar* self);
+  static void prev_month_callback(GlomGtkCalendar* self);
+  static void next_month_callback(GlomGtkCalendar* self);
+  static void prev_year_callback(GlomGtkCalendar* self);
+  static void next_year_callback(GlomGtkCalendar* self);
+#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+  //Callbacks (virtual functions):
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+};
+
+
+} // namespace GlomGtk
+
+// Generated by gtkmmproc -- DO NOT MODIFY!
+
+
+#include "glomgtkcalendar.h"
+#include <gtkmm/private/calendar_p.h>
+
+#include <gtk/gtktypebuiltins.h>
+// -*- c++ -*-
+/* $Id: calendar.ccg,v 1.1 2003/01/21 13:38:43 murrayc Exp $ */
+
+/* 
+ *
+ * Copyright 1998-2002 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gtk/gtkcalendar.h>
+
+
+static gchar* SignalProxy_Details_gtk_callback(GlomGtkCalendar* model, guint year, guint month, guint day, gpointer user_data)
+{
+  GlomGtk::Calendar::SlotDetails* the_slot = static_cast<GlomGtk::Calendar::SlotDetails*>(user_data);
+
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  try
+  {
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+    const Glib::ustring temp = (*the_slot)(year, month, day);
+    return g_strdup(temp.c_str()); //Freed by GlomGtkCalendar.
+  #ifdef GLIBMM_EXCEPTIONS_ENABLED
+  }
+  catch(...)
+  {
+    Glib::exception_handlers_invoke();
+  }
+
+  return 0; // arbitrary value
+  #endif //GLIBMM_EXCEPTIONS_ENABLED
+}
+
+static void SignalProxy_Details_gtk_callback_destroy(void* data)
+{
+  delete static_cast<GlomGtk::Calendar::SlotDetails*>(data);
+}
+
+namespace GlomGtk
+{
+
+void Calendar::get_date(Glib::Date& date) const
+{
+  guint year = 0;
+  guint month = 0;
+  guint day = 0;
+  
+  get_date(year, month, day);
+  
+  date.set_year(year);
+  date.set_month(static_cast<Glib::Date::Month>(Glib::Date::JANUARY + month)); // Month from 1 to 12 instead from 0 to 11
+  date.set_day(day);  
+}
+
+void Calendar::set_detail_func(const SlotDetails& slot)
+{
+  SlotDetails* slot_copy = new SlotDetails(slot);
+  glom_gtk_calendar_set_detail_func(gobj(), &SignalProxy_Details_gtk_callback, slot_copy, &SignalProxy_Details_gtk_callback_destroy);
+}
+
+
+} //namespace GlomGtk
+
+
+namespace
+{
+
+
+static const Glib::SignalProxyInfo Calendar_signal_month_changed_info =
+{
+  "month_changed",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_day_selected_info =
+{
+  "day_selected",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_day_selected_double_click_info =
+{
+  "day_selected_double_click",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_prev_month_info =
+{
+  "prev_month",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_next_month_info =
+{
+  "next_month",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_prev_year_info =
+{
+  "prev_year",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+static const Glib::SignalProxyInfo Calendar_signal_next_year_info =
+{
+  "next_year",
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback,
+  (GCallback) &Glib::SignalProxyNormal::slot0_void_callback
+};
+
+
+} // anonymous namespace
+
+namespace Glib
+{
+
+GlomGtk::Calendar* wrap(GlomGtkCalendar* object, bool take_copy)
+{
+  return dynamic_cast<GlomGtk::Calendar *> (Glib::wrap_auto ((GObject*)(object), take_copy));
+}
+
+} /* namespace Glib */
+
+namespace GlomGtk
+{
+
+
+/* The *_Class implementation: */
+
+const Glib::Class& Calendar_Class::init()
+{
+  if(!gtype_) // create the GType if necessary
+  {
+    // Glib::Class has to know the class init function to clone custom types.
+    class_init_func_ = &Calendar_Class::class_init_function;
+
+    // This is actually just optimized away, apparently with no harm.
+    // Make sure that the parent type has been created.
+    //CppClassParent::CppObjectType::get_type();
+
+    // Create the wrapper type, with the same class/instance size as the base type.
+    register_derived_type(glom_gtk_calendar_get_type());
+
+    // Add derived versions of interfaces, if the C type implements any interfaces:
+  }
+
+  return *this;
+}
+
+void Calendar_Class::class_init_function(void* g_class, void* class_data)
+{
+  BaseClassType *const klass = static_cast<BaseClassType*>(g_class);
+  CppClassParent::class_init_function(klass, class_data);
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  klass->month_changed = &month_changed_callback;
+  klass->day_selected = &day_selected_callback;
+  klass->day_selected_double_click = &day_selected_double_click_callback;
+  klass->prev_month = &prev_month_callback;
+  klass->next_month = &next_month_callback;
+  klass->prev_year = &prev_year_callback;
+  klass->next_year = &next_year_callback;
+#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+}
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+void Calendar_Class::month_changed_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_month_changed();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->month_changed)
+    (*base->month_changed)(self);
+}
+void Calendar_Class::day_selected_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_day_selected();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->day_selected)
+    (*base->day_selected)(self);
+}
+void Calendar_Class::day_selected_double_click_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_day_selected_double_click();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->day_selected_double_click)
+    (*base->day_selected_double_click)(self);
+}
+void Calendar_Class::prev_month_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_prev_month();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->prev_month)
+    (*base->prev_month)(self);
+}
+void Calendar_Class::next_month_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_next_month();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->next_month)
+    (*base->next_month)(self);
+}
+void Calendar_Class::prev_year_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_prev_year();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->prev_year)
+    (*base->prev_year)(self);
+}
+void Calendar_Class::next_year_callback(GlomGtkCalendar* self)
+{
+  Glib::ObjectBase *const obj_base = static_cast<Glib::ObjectBase*>(
+      Glib::ObjectBase::_get_current_wrapper((GObject*)self));
+
+  // Non-gtkmmproc-generated custom classes implicitly call the default
+  // Glib::ObjectBase constructor, which sets is_derived_. But gtkmmproc-
+  // generated classes can use this optimisation, which avoids the unnecessary
+  // parameter conversions if there is no possibility of the virtual function
+  // being overridden:
+  if(obj_base && obj_base->is_derived_())
+  {
+    CppObjectType *const obj = dynamic_cast<CppObjectType* const>(obj_base);
+    if(obj) // This can be NULL during destruction.
+    {
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      try // Trap C++ exceptions which would normally be lost because this is a C callback.
+      {
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+        // Call the virtual member method, which derived classes might override.
+        obj->on_next_year();
+        return;
+      #ifdef GLIBMM_EXCEPTIONS_ENABLED
+      }
+      catch(...)
+      {
+        Glib::exception_handlers_invoke();
+      }
+      #endif //GLIBMM_EXCEPTIONS_ENABLED
+    }
+  }
+  
+  BaseClassType *const base = static_cast<BaseClassType*>(
+        g_type_class_peek_parent(G_OBJECT_GET_CLASS(self)) // Get the parent class of the object class (The original underlying C class).
+    );
+
+  // Call the original underlying C function:
+  if(base && base->next_year)
+    (*base->next_year)(self);
+}
+#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+
+Glib::ObjectBase* Calendar_Class::wrap_new(GObject* o)
+{
+  return manage(new Calendar((GlomGtkCalendar*)(o)));
+
+}
+
+
+/* The implementation: */
+
+Calendar::Calendar(const Glib::ConstructParams& construct_params)
+:
+  Gtk::Widget(construct_params)
+{
+  }
+
+Calendar::Calendar(GlomGtkCalendar* castitem)
+:
+  Gtk::Widget((GtkWidget*)(castitem))
+{
+  }
+
+Calendar::~Calendar()
+{
+  destroy_();
+}
+
+Calendar::CppClassType Calendar::calendar_class_; // initialize static member
+
+GType Calendar::get_type()
+{
+  return calendar_class_.init().get_type();
+}
+
+GType Calendar::get_base_type()
+{
+  return glom_gtk_calendar_get_type();
+}
+
+
+Calendar::Calendar()
+:
+  // Mark this class as non-derived to allow C++ vfuncs to be skipped.
+  Glib::ObjectBase(0),
+  Gtk::Widget(Glib::ConstructParams(calendar_class_.init()))
+{
+  
+
+}
+
+int Calendar::select_month(guint month, guint year)
+{
+  return glom_gtk_calendar_select_month(gobj(), month, year);
+}
+
+void Calendar::select_day(guint day)
+{
+glom_gtk_calendar_select_day(gobj(), day); 
+}
+
+int Calendar::mark_day(guint day)
+{
+  return glom_gtk_calendar_mark_day(gobj(), day);
+}
+
+int Calendar::unmark_day(guint day)
+{
+  return glom_gtk_calendar_unmark_day(gobj(), day);
+}
+
+void Calendar::clear_marks()
+{
+glom_gtk_calendar_clear_marks(gobj()); 
+}
+
+#ifndef GTKMM_DISABLE_DEPRECATED
+
+void Calendar::display_options(CalendarDisplayOptions flags)
+{
+glom_gtk_calendar_display_options(gobj(), ((GlomGtkCalendarDisplayOptions)(flags))); 
+}
+
+#endif // GTKMM_DISABLE_DEPRECATED
+
+void Calendar::set_display_options(CalendarDisplayOptions flags)
+{
+glom_gtk_calendar_set_display_options(gobj(), ((GlomGtkCalendarDisplayOptions)(flags))); 
+}
+
+CalendarDisplayOptions Calendar::get_display_options() const
+{
+  return ((CalendarDisplayOptions)(glom_gtk_calendar_get_display_options(const_cast<GlomGtkCalendar*>(gobj()))));
+}
+
+void Calendar::get_date(guint& year, guint& month, guint& day) const
+{
+glom_gtk_calendar_get_date(const_cast<GlomGtkCalendar*>(gobj()), &(year), &(month), &(day)); 
+}
+
+void Calendar::set_detail_width_chars(int chars)
+{
+glom_gtk_calendar_set_detail_width_chars(gobj(), chars); 
+}
+
+void Calendar::set_detail_height_rows(int rows)
+{
+glom_gtk_calendar_set_detail_height_rows(gobj(), rows); 
+}
+
+int Calendar::get_detail_width_chars() const
+{
+  return glom_gtk_calendar_get_detail_width_chars(const_cast<GlomGtkCalendar*>(gobj()));
+}
+
+int Calendar::get_detail_height_rows() const
+{
+  return glom_gtk_calendar_get_detail_height_rows(const_cast<GlomGtkCalendar*>(gobj()));
+}
+
+void Calendar::freeze()
+{
+glom_gtk_calendar_freeze(gobj()); 
+}
+
+void Calendar::thaw()
+{
+glom_gtk_calendar_thaw(gobj()); 
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_month_changed()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_month_changed_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_day_selected()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_day_selected_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_day_selected_double_click()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_day_selected_double_click_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_prev_month()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_prev_month_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_next_month()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_next_month_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_prev_year()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_prev_year_info);
+}
+
+
+Glib::SignalProxy0< void > Calendar::signal_next_year()
+{
+  return Glib::SignalProxy0< void >(this, &Calendar_signal_next_year_info);
+}
+
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<int> Calendar::property_year() 
+{
+  return Glib::PropertyProxy<int>(this, "year");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<int> Calendar::property_year() const
+{
+  return Glib::PropertyProxy_ReadOnly<int>(this, "year");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<int> Calendar::property_month() 
+{
+  return Glib::PropertyProxy<int>(this, "month");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<int> Calendar::property_month() const
+{
+  return Glib::PropertyProxy_ReadOnly<int>(this, "month");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<int> Calendar::property_day() 
+{
+  return Glib::PropertyProxy<int>(this, "day");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<int> Calendar::property_day() const
+{
+  return Glib::PropertyProxy_ReadOnly<int>(this, "day");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<bool> Calendar::property_show_heading() 
+{
+  return Glib::PropertyProxy<bool>(this, "show-heading");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<bool> Calendar::property_show_heading() const
+{
+  return Glib::PropertyProxy_ReadOnly<bool>(this, "show-heading");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<bool> Calendar::property_show_day_names() 
+{
+  return Glib::PropertyProxy<bool>(this, "show-day-names");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<bool> Calendar::property_show_day_names() const
+{
+  return Glib::PropertyProxy_ReadOnly<bool>(this, "show-day-names");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<bool> Calendar::property_no_month_change() 
+{
+  return Glib::PropertyProxy<bool>(this, "no-month-change");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<bool> Calendar::property_no_month_change() const
+{
+  return Glib::PropertyProxy_ReadOnly<bool>(this, "no-month-change");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy<bool> Calendar::property_show_week_numbers() 
+{
+  return Glib::PropertyProxy<bool>(this, "show-week-numbers");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+Glib::PropertyProxy_ReadOnly<bool> Calendar::property_show_week_numbers() const
+{
+  return Glib::PropertyProxy_ReadOnly<bool>(this, "show-week-numbers");
+}
+#endif //GLIBMM_PROPERTIES_ENABLED
+
+
+#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+void GlomGtk::Calendar::on_month_changed()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->month_changed)
+    (*base->month_changed)(gobj());
+}
+void GlomGtk::Calendar::on_day_selected()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->day_selected)
+    (*base->day_selected)(gobj());
+}
+void GlomGtk::Calendar::on_day_selected_double_click()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->day_selected_double_click)
+    (*base->day_selected_double_click)(gobj());
+}
+void GlomGtk::Calendar::on_prev_month()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->prev_month)
+    (*base->prev_month)(gobj());
+}
+void GlomGtk::Calendar::on_next_month()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->next_month)
+    (*base->next_month)(gobj());
+}
+void GlomGtk::Calendar::on_prev_year()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->prev_year)
+    (*base->prev_year)(gobj());
+}
+void GlomGtk::Calendar::on_next_year()
+{
+  BaseClassType *const base = static_cast<BaseClassType*>(
+      g_type_class_peek_parent(G_OBJECT_GET_CLASS(gobject_)) // Get the parent class of the object class (The original underlying C class).
+  );
+
+  if(base && base->next_year)
+    (*base->next_year)(gobj());
+}
+#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+
+} // namespace GlomGtk
+
+
+
+#endif //!GTK_CHECK_VERSION(2,16,0)

Added: trunk/glom/utility_widgets/calendar/glomcalendar.h
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/calendar/glomcalendar.h	Fri Jan 18 13:47:20 2008
@@ -0,0 +1,564 @@
+/* This is copied from gtkmm 2.15/16 so we can use new API without waiting 
+ * for stable release of GTK+ 2.16. Life would be easier if GTK+ followed 
+ * the GNOME release schedule.
+ */
+//#include <gtk/gtkcalendar.h>
+#include <gtkmm/calendar.h>
+#include <gtk/gtk.h>
+#if GTK_CHECK_VERSION(2,16,0)
+namespace GlomGtk
+{
+  typedef GlomGtk::Calendar Calendar;
+}
+#else
+
+
+// -*- c++ -*-
+// Generated by gtkmmproc -- DO NOT MODIFY!
+#ifndef _GLOM_GTKMM_CALENDAR_H
+#define _GLOM_GTKMM_CALENDAR_H
+
+
+#include <glibmm.h>
+
+/* $Id: calendar.hg,v 1.6 2006/02/25 12:38:11 murrayc Exp $ */
+
+/* calendar.h
+ * 
+ * Copyright (C) 1998-2002 The gtkmm Development Team
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gtkmm/widget.h>
+#include <glibmm/date.h>
+
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+typedef struct _GlomGtkCalendar GlomGtkCalendar;
+typedef struct _GlomGtkCalendarClass GlomGtkCalendarClass;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+
+namespace GlomGtk
+{ class Calendar_Class; } // namespace GlomGtk
+namespace GlomGtk
+{
+
+
+/** @addtogroup gtkmmEnums Enums and Flags */
+
+/**
+ * @ingroup gtkmmEnums
+ * @par Bitwise operators:
+ * <tt>%CalendarDisplayOptions operator|(CalendarDisplayOptions, CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions operator&(CalendarDisplayOptions, CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions operator^(CalendarDisplayOptions, CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions operator~(CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions& operator|=(CalendarDisplayOptions&, CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions& operator&=(CalendarDisplayOptions&, CalendarDisplayOptions)</tt><br>
+ * <tt>%CalendarDisplayOptions& operator^=(CalendarDisplayOptions&, CalendarDisplayOptions)</tt><br>
+ */
+enum CalendarDisplayOptions
+{
+  CALENDAR_SHOW_HEADING = 1 << 0,
+  CALENDAR_SHOW_DAY_NAMES = 1 << 1,
+  CALENDAR_NO_MONTH_CHANGE = 1 << 2,
+  CALENDAR_SHOW_WEEK_NUMBERS = 1 << 3,
+  CALENDAR_WEEK_START_MONDAY = 1 << 4,
+  CALENDAR_SHOW_DETAILS = 1 << 5
+};
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions operator|(CalendarDisplayOptions lhs, CalendarDisplayOptions rhs)
+  { return static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs)); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions operator&(CalendarDisplayOptions lhs, CalendarDisplayOptions rhs)
+  { return static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs)); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions operator^(CalendarDisplayOptions lhs, CalendarDisplayOptions rhs)
+  { return static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs)); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions operator~(CalendarDisplayOptions flags)
+  { return static_cast<CalendarDisplayOptions>(~static_cast<unsigned>(flags)); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions& operator|=(CalendarDisplayOptions& lhs, CalendarDisplayOptions rhs)
+  { return (lhs = static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) | static_cast<unsigned>(rhs))); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions& operator&=(CalendarDisplayOptions& lhs, CalendarDisplayOptions rhs)
+  { return (lhs = static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) & static_cast<unsigned>(rhs))); }
+
+/** @ingroup gtkmmEnums */
+inline CalendarDisplayOptions& operator^=(CalendarDisplayOptions& lhs, CalendarDisplayOptions rhs)
+  { return (lhs = static_cast<CalendarDisplayOptions>(static_cast<unsigned>(lhs) ^ static_cast<unsigned>(rhs))); }
+
+} // namespace GlomGtk
+
+
+
+namespace GlomGtk
+{
+
+
+/** Display a calendar and/or allow the user to select a date.
+ *
+ * This is a widget that displays a calendar, one month at a time.
+ *
+ * The month and year currently displayed can be altered with
+ * select_month().  The exact day can be selected from the displayed month
+ * using select_day().
+ *
+ * The way in which the calendar itself is displayed can be altered using
+ * set_display_options().
+ *
+ * The selected date can be retrieved from a GlomGtkCalendar using get_date().
+ *
+ * If performing many 'mark' operations, the calendar can be frozen to
+ * prevent flicker, using freeze(), and 'thawed' again using thaw().
+ *
+ * @ingroup Widgets
+ */
+
+class Calendar : public Gtk::Widget
+{
+  public:
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+  typedef Calendar CppObjectType;
+  typedef Calendar_Class CppClassType;
+  typedef GlomGtkCalendar BaseObjectType;
+  typedef GlomGtkCalendarClass BaseClassType;
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+  virtual ~Calendar();
+
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+
+private:
+  friend class Calendar_Class;
+  static CppClassType calendar_class_;
+
+  // noncopyable
+  Calendar(const Calendar&);
+  Calendar& operator=(const Calendar&);
+
+protected:
+  explicit Calendar(const Glib::ConstructParams& construct_params);
+  explicit Calendar(GlomGtkCalendar* castitem);
+
+#endif /* DOXYGEN_SHOULD_SKIP_THIS */
+
+public:
+#ifndef DOXYGEN_SHOULD_SKIP_THIS
+  static GType get_type()      G_GNUC_CONST;
+  static GType get_base_type() G_GNUC_CONST;
+#endif
+
+  ///Provides access to the underlying C GtkObject.
+  GlomGtkCalendar*       gobj()       { return reinterpret_cast<GlomGtkCalendar*>(gobject_); }
+
+  ///Provides access to the underlying C GtkObject.
+  const GlomGtkCalendar* gobj() const { return reinterpret_cast<GlomGtkCalendar*>(gobject_); }
+
+
+public:
+  //C++ methods used to invoke GTK+ virtual functions:
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+protected:
+  //GTK+ Virtual Functions (override these to change behaviour):
+#ifdef GLIBMM_VFUNCS_ENABLED
+#endif //GLIBMM_VFUNCS_ENABLED
+
+  //Default Signal Handlers::
+#ifdef GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+  virtual void on_month_changed();
+  virtual void on_day_selected();
+  virtual void on_day_selected_double_click();
+  virtual void on_prev_month();
+  virtual void on_next_month();
+  virtual void on_prev_year();
+  virtual void on_next_year();
+#endif //GLIBMM_DEFAULT_SIGNAL_HANDLERS_ENABLED
+
+
+private:
+
+public:
+  Calendar();
+  
+  
+  /** Shifts the calendar to a different month.
+   * @param month A month number between 0 and 11.
+   * @param year The year the month is in.
+   * @return <tt>true</tt>, always.
+   */
+  int select_month(guint month, guint year);
+  
+  /** Selects a day from the current month.
+   * @param day The day number between 1 and 31, or 0 to unselect 
+   * the currently selected day.
+   */
+  void select_day(guint day);
+  
+  /** Places a visual marker on a particular day.
+   * @param day The day number to mark between 1 and 31.
+   * @return <tt>true</tt>, always.
+   */
+  int mark_day(guint day);
+  
+  /** Removes the visual marker from a particular day.
+   * @param day The day number to unmark between 1 and 31.
+   * @return <tt>true</tt>, always.
+   */
+  int unmark_day(guint day);
+  
+  /** Remove all visual markers.
+   */
+  void clear_marks();
+
+  
+#ifndef GTKMM_DISABLE_DEPRECATED
+
+  /** Sets display options (whether to display the heading and the month headings).
+   * 
+   * Deprecated: 2.4: Use set_display_options() instead
+   * @param flags The display options to set.
+   */
+  void display_options(CalendarDisplayOptions flags);
+#endif // GTKMM_DISABLE_DEPRECATED
+
+
+  /** Sets display options (whether to display the heading and the month  
+   * headings).
+   * 
+   * @newin2p4
+   * @param flags The display options to set.
+   */
+  void set_display_options(CalendarDisplayOptions flags);
+  
+  /** Return value: the display options.
+   * @return The display options.
+   * 
+   * @newin2p4.
+   */
+  CalendarDisplayOptions get_display_options() const;
+
+  
+  /** Obtains the selected date from a GlomGtk::Calendar.
+   * @param year Location to store the year number, or <tt>0</tt>.
+   * @param month Location to store the month number (between 0 and 11), or <tt>0</tt>.
+   * @param day Location to store the day number (between 1 and 31), or <tt>0</tt>.
+   */
+  void get_date(guint& year, guint& month, guint& day) const;
+  // Additional method not in GTK (#350584)
+  /** Get the date as Glib::Date
+   *
+   * @param date Referenz to set the date
+   */
+  void get_date(Glib::Date& date) const;
+  
+
+  /** For instance,
+   * @code
+   * Glib::ustring on_calendar_details(guint year, guint month, guint day);
+   * @endcode
+   *
+   * @param year The year for which details are needed.
+   * @param month The month for which details are needed.
+   * @param day The day of @month for which details are needed.
+   * @result Pango markup with details for the specified day, or an empty string.
+   *
+   * This callback function provides Pango markup with detail information for the
+   * specified day. Examples for such details are holidays or appointments. The
+   * function should return an empty string when no information is available.
+   *
+   * @newin2p16 
+   */
+  typedef sigc::slot<Glib::ustring, guint, guint, guint> SlotDetails;
+
+
+  /** Installs a function which provides Pango markup with detail information
+   * for each day. Examples for such details are holidays or appointments. That
+   * information is shown below each day when show-details is set.
+   * A tooltip containing full detail information is provided if the entire
+   * text could not fit into the details area, or if the show-details property
+   * is not set.
+   *
+   * The size of the details area can be restricted by setting the
+   * detail-width-chars and detail-height-rows properties.
+   *
+   * @param slot A callback function providing details for each day.
+   *
+   * @newin2p16
+   */
+  void set_detail_func(const SlotDetails& slot);
+  ;
+  	 
+  
+  void set_detail_width_chars(int chars);
+  
+  void set_detail_height_rows(int rows);
+	  	 
+  
+  int get_detail_width_chars() const;
+  
+  int get_detail_height_rows() const;
+
+  
+  /** Does nothing. Previously locked the display of the calendar until
+   * it was thawed with thaw().
+   * 
+   * Deprecated: 2.8:
+   */
+  void freeze();
+  
+  /** Does nothing. Previously defrosted a calendar; all the changes made
+   * since the last freeze() were displayed.
+   * 
+   * Deprecated: 2.8:
+   */
+  void thaw();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%month_changed()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_month_changed();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%day_selected()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_day_selected();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%day_selected_double_click()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_day_selected_double_click();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%prev_month()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_prev_month();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%next_month()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_next_month();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%prev_year()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_prev_year();
+
+  
+  /**
+   * @par Prototype:
+   * <tt>void on_my_%next_year()</tt>
+   */
+
+  Glib::SignalProxy0< void > signal_next_year();
+
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected year.
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<int> property_year() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected year.
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<int> property_year() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected month (as a number between 0 and 11).
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<int> property_month() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected month (as a number between 0 and 11).
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<int> property_month() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day).
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<int> property_day() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day).
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<int> property_day() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<bool> property_show_heading() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<bool> property_show_heading() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<bool> property_show_day_names() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<bool> property_show_day_names() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<bool> property_no_month_change() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<bool> property_no_month_change() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  #ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy<bool> property_show_week_numbers() ;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+#ifdef GLIBMM_PROPERTIES_ENABLED
+/** If TRUE
+   *
+   * You rarely need to use properties because there are get_ and set_ methods for almost all of them.
+   * @return A PropertyProxy that allows you to get or set the property of the value, or receive notification when
+   * the value of the property changes.
+   */
+  Glib::PropertyProxy_ReadOnly<bool> property_show_week_numbers() const;
+#endif //#GLIBMM_PROPERTIES_ENABLED
+
+  //gtkmmproc error: show-details : property defs lookup failed.;
+  //gtkmmproc error: detail-width-chars : property defs lookup failed.;
+  //gtkmmproc error: detail-height-chars : property defs lookup failed.;
+
+
+};
+
+} /* namespace GlomGtk */
+
+
+namespace Glib
+{
+  /** A Glib::wrap() method for this object.
+   * 
+   * @param object The C instance.
+   * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref.
+   * @result A C++ instance that wraps this C instance.
+   *
+   * @relates GlomGtk::Calendar
+   */
+  GlomGtk::Calendar* wrap(GlomGtkCalendar* object, bool take_copy = false);
+} //namespace Glib
+
+
+#endif /* _GLOM_GTKMM_CALENDAR_H */
+
+
+#endif //GTK_CHECK_VERSION(2,16,0)

Added: trunk/glom/utility_widgets/calendar/glomgtkcalendar.c
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/calendar/glomgtkcalendar.c	Fri Jan 18 13:47:20 2008
@@ -0,0 +1,4090 @@
+/* This is copied from GTK+ 2.15/16 so we can use new API without waiting 
+ * for stable release of GTK+ 2.16. Life would be easier if GTK+ followed 
+ * the GNOME release schedule.
+ */
+#include <gtk/gtk.h>
+#if !GTK_CHECK_VERSION(2,16,0)
+
+#include <config.h>
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
+#include <langinfo.h>
+#endif
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
+#undef GTK_DISABLE_DEPRECATED
+#include "glomgtkcalendar.h"
+
+#include <gtk/gtkdnd.h>
+
+#include <gtk/gtkmain.h>
+#include <gdk/gdkkeysyms.h>
+
+
+/* #include "gtkintl.h" */
+#include <glib/gi18n-lib.h>
+
+#ifdef ENABLE_NLS
+#define P_(String) dgettext(GETTEXT_PACKAGE "-properties",String)
+#else 
+#define P_(String) (String)
+#endif
+
+/* not really I18N-related, but also a string marker macro */
+#define I_(string) g_intern_static_string (string)
+
+
+
+/* #include "gtkmarshalers.h" */
+#define _gtk_marshal_VOID__VOID	g_cclosure_marshal_VOID__VOID
+
+
+/* #include "gtkprivate.h" */
+#define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+#define GTK_PARAM_WRITABLE G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+#define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
+
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * GTK Calendar Widget
+ * Copyright (C) 1998 Cesar Miquel, Shawn T. Amundson and Mattias Groenlund
+ * 
+ * lib_date routines
+ * Copyright (c) 1995, 1996, 1997, 1998 by Steffen Beyer
+ *
+ * This library 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) any later version.
+ *
+ * This library 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 this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#include <config.h>
+
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
+#include <langinfo.h>
+#endif
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+
+#include <glib.h>
+
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
+
+#undef GTK_DISABLE_DEPRECATED
+#include "glomgtkcalendar.h"
+
+#include <gtk/gtktooltip.h>
+
+/***************************************************************************/
+/* The following date routines are taken from the lib_date package. 
+ * They have been minimally edited to avoid conflict with types defined
+ * in win32 headers.
+ */
+
+static const guint month_length[2][13] =
+{
+  { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+  { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
+
+static const guint days_in_months[2][14] =
+{
+  { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
+  { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
+};
+
+static glong  calc_days(guint year, guint mm, guint dd);
+static guint  day_of_week(guint year, guint mm, guint dd);
+static glong  dates_difference(guint year1, guint mm1, guint dd1,
+			       guint year2, guint mm2, guint dd2);
+static guint  weeks_in_year(guint year);
+
+static gboolean 
+leap (guint year)
+{
+  return((((year % 4) == 0) && ((year % 100) != 0)) || ((year % 400) == 0));
+}
+
+static guint 
+day_of_week (guint year, guint mm, guint dd)
+{
+  glong  days;
+  
+  days = calc_days(year, mm, dd);
+  if (days > 0L)
+    {
+      days--;
+      days %= 7L;
+      days++;
+    }
+  return( (guint) days );
+}
+
+static guint weeks_in_year(guint year)
+{
+  return(52 + ((day_of_week(year,1,1)==4) || (day_of_week(year,12,31)==4)));
+}
+
+static gboolean 
+check_date(guint year, guint mm, guint dd)
+{
+  if (year < 1) return FALSE;
+  if ((mm < 1) || (mm > 12)) return FALSE;
+  if ((dd < 1) || (dd > month_length[leap(year)][mm])) return FALSE;
+  return TRUE;
+}
+
+static guint 
+week_number(guint year, guint mm, guint dd)
+{
+  guint first;
+  
+  first = day_of_week(year,1,1) - 1;
+  return( (guint) ( (dates_difference(year,1,1, year,mm,dd) + first) / 7L ) +
+	  (first < 4) );
+}
+
+static glong 
+year_to_days(guint year)
+{
+  return( year * 365L + (year / 4) - (year / 100) + (year / 400) );
+}
+
+
+static glong 
+calc_days(guint year, guint mm, guint dd)
+{
+  gboolean lp;
+  
+  if (year < 1) return(0L);
+  if ((mm < 1) || (mm > 12)) return(0L);
+  if ((dd < 1) || (dd > month_length[(lp = leap(year))][mm])) return(0L);
+  return( year_to_days(--year) + days_in_months[lp][mm] + dd );
+}
+
+static gboolean 
+week_of_year(guint *week, guint *year, guint mm, guint dd)
+{
+  if (check_date(*year,mm,dd))
+    {
+      *week = week_number(*year,mm,dd);
+      if (*week == 0) 
+	*week = weeks_in_year(--(*year));
+      else if (*week > weeks_in_year(*year))
+	{
+	  *week = 1;
+	  (*year)++;
+	}
+      return TRUE;
+    }
+  return FALSE;
+}
+
+static glong 
+dates_difference(guint year1, guint mm1, guint dd1,
+		 guint year2, guint mm2, guint dd2)
+{
+  return( calc_days(year2, mm2, dd2) - calc_days(year1, mm1, dd1) );
+}
+
+/*** END OF lib_date routines ********************************************/
+
+/* Spacing around day/week headers and main area, inside those windows */
+#define CALENDAR_MARGIN		 0
+/* Spacing around day/week headers and main area, outside those windows */
+#define INNER_BORDER		 4
+/* Separation between day headers and main area */
+#define CALENDAR_YSEP		 4
+/* Separation between week headers and main area */
+#define CALENDAR_XSEP		 4
+
+#define DAY_XSEP		 0 /* not really good for small calendar */
+#define DAY_YSEP		 0 /* not really good for small calendar */
+
+#define SCROLL_DELAY_FACTOR      5
+
+/* Color usage */
+#define HEADER_FG_COLOR(widget)		 (& (widget)->style->fg[GTK_WIDGET_STATE (widget)])
+#define HEADER_BG_COLOR(widget)		 (& (widget)->style->bg[GTK_WIDGET_STATE (widget)])
+#define SELECTED_BG_COLOR(widget)	 (& (widget)->style->base[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
+#define SELECTED_FG_COLOR(widget)	 (& (widget)->style->text[GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE])
+#define NORMAL_DAY_COLOR(widget)	 (& (widget)->style->text[GTK_WIDGET_STATE (widget)])
+#define PREV_MONTH_COLOR(widget)	 (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
+#define NEXT_MONTH_COLOR(widget)	 (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
+#define MARKED_COLOR(widget)		 (& (widget)->style->text[GTK_WIDGET_STATE (widget)])
+#define BACKGROUND_COLOR(widget)	 (& (widget)->style->base[GTK_WIDGET_STATE (widget)])
+#define HIGHLIGHT_BACK_COLOR(widget)	 (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
+
+enum {
+  ARROW_YEAR_LEFT,
+  ARROW_YEAR_RIGHT,
+  ARROW_MONTH_LEFT,
+  ARROW_MONTH_RIGHT
+};
+
+enum {
+  MONTH_PREV,
+  MONTH_CURRENT,
+  MONTH_NEXT
+};
+
+enum {
+  MONTH_CHANGED_SIGNAL,
+  DAY_SELECTED_SIGNAL,
+  DAY_SELECTED_DOUBLE_CLICK_SIGNAL,
+  PREV_MONTH_SIGNAL,
+  NEXT_MONTH_SIGNAL,
+  PREV_YEAR_SIGNAL,
+  NEXT_YEAR_SIGNAL,
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+  PROP_YEAR,
+  PROP_MONTH,
+  PROP_DAY,
+  PROP_SHOW_HEADING,
+  PROP_SHOW_DAY_NAMES,
+  PROP_NO_MONTH_CHANGE,
+  PROP_SHOW_WEEK_NUMBERS,
+  PROP_SHOW_DETAILS,
+  PROP_DETAIL_WIDTH_CHARS,
+  PROP_DETAIL_HEIGHT_ROWS,
+  PROP_LAST
+};
+
+static guint glom_gtk_calendar_signals[LAST_SIGNAL] = { 0 };
+
+struct _GlomGtkCalendarPrivate
+{
+  GdkWindow *header_win;
+  GdkWindow *day_name_win;
+  GdkWindow *main_win;
+  GdkWindow *week_win;
+  GdkWindow *arrow_win[4];
+
+  guint header_h;
+  guint day_name_h;
+  guint main_h;
+
+  guint	     arrow_state[4];
+  guint	     arrow_width;
+  guint	     max_month_width;
+  guint	     max_year_width;
+  
+  guint day_width;
+  guint week_width;
+
+  guint min_day_width;
+  guint max_day_char_width;
+  guint max_day_char_ascent;
+  guint max_day_char_descent;
+  guint max_label_char_ascent;
+  guint max_label_char_descent;
+  guint max_week_char_width;
+  
+  /* flags */
+  guint year_before : 1;
+
+  guint need_timer  : 1;
+
+  guint in_drag : 1;
+  guint drag_highlight : 1;
+
+  guint32 timer;
+  gint click_child;
+
+  gint week_start;
+
+  gint drag_start_x;
+  gint drag_start_y;
+
+  /* Optional callback, used to display extra information for each day. */
+  GlomGtkCalendarDetailFunc detail_func;
+  gpointer              detail_func_user_data;
+  GDestroyNotify        detail_func_destroy;
+
+  /* Size requistion for details provided by the hook. */
+  gint detail_height_rows;
+  gint detail_width_chars;
+  gint detail_overflow[6];
+};
+
+#define GLOM_GTK_CALENDAR_GET_PRIVATE(widget)  (GLOM_GTK_CALENDAR (widget)->priv)
+
+static void glom_gtk_calendar_finalize     (GObject      *calendar);
+static void glom_gtk_calendar_destroy      (GtkObject    *calendar);
+static void glom_gtk_calendar_set_property (GObject      *object,
+				       guint         prop_id,
+				       const GValue *value,
+				       GParamSpec   *pspec);
+static void glom_gtk_calendar_get_property (GObject      *object,
+				       guint         prop_id,
+				       GValue       *value,
+				       GParamSpec   *pspec);
+
+static void     glom_gtk_calendar_realize        (GtkWidget        *widget);
+static void     glom_gtk_calendar_unrealize      (GtkWidget        *widget);
+static void     glom_gtk_calendar_size_request   (GtkWidget        *widget,
+					     GtkRequisition   *requisition);
+static void     glom_gtk_calendar_size_allocate  (GtkWidget        *widget,
+					     GtkAllocation    *allocation);
+static gboolean glom_gtk_calendar_expose         (GtkWidget        *widget,
+					     GdkEventExpose   *event);
+static gboolean glom_gtk_calendar_button_press   (GtkWidget        *widget,
+					     GdkEventButton   *event);
+static gboolean glom_gtk_calendar_button_release (GtkWidget        *widget,
+					     GdkEventButton   *event);
+static gboolean glom_gtk_calendar_motion_notify  (GtkWidget        *widget,
+					     GdkEventMotion   *event);
+static gboolean glom_gtk_calendar_enter_notify   (GtkWidget        *widget,
+					     GdkEventCrossing *event);
+static gboolean glom_gtk_calendar_leave_notify   (GtkWidget        *widget,
+					     GdkEventCrossing *event);
+static gboolean glom_gtk_calendar_scroll         (GtkWidget        *widget,
+					     GdkEventScroll   *event);
+static gboolean glom_gtk_calendar_key_press      (GtkWidget        *widget,
+					     GdkEventKey      *event);
+static gboolean glom_gtk_calendar_focus_out      (GtkWidget        *widget,
+					     GdkEventFocus    *event);
+static void     glom_gtk_calendar_grab_notify    (GtkWidget        *widget,
+					     gboolean          was_grabbed);
+static void     glom_gtk_calendar_state_changed  (GtkWidget        *widget,
+					     GtkStateType      previous_state);
+static void     glom_gtk_calendar_style_set      (GtkWidget        *widget,
+					     GtkStyle         *previous_style);
+static gboolean glom_gtk_calendar_query_tooltip  (GtkWidget        *widget,
+					     gint              x,
+					     gint              y,
+					     gboolean          keyboard_mode,
+					     GtkTooltip       *tooltip);
+
+static void     glom_gtk_calendar_drag_data_get      (GtkWidget        *widget,
+						 GdkDragContext   *context,
+						 GtkSelectionData *selection_data,
+						 guint             info,
+						 guint             time);
+static void     glom_gtk_calendar_drag_data_received (GtkWidget        *widget,
+						 GdkDragContext   *context,
+						 gint              x,
+						 gint              y,
+						 GtkSelectionData *selection_data,
+						 guint             info,
+						 guint             time);
+static gboolean glom_gtk_calendar_drag_motion        (GtkWidget        *widget,
+						 GdkDragContext   *context,
+						 gint              x,
+						 gint              y,
+						 guint             time);
+static void     glom_gtk_calendar_drag_leave         (GtkWidget        *widget,
+						 GdkDragContext   *context,
+						 guint             time);
+static gboolean glom_gtk_calendar_drag_drop          (GtkWidget        *widget,
+						 GdkDragContext   *context,
+						 gint              x,
+						 gint              y,
+						 guint             time);
+
+static void calendar_start_spinning (GlomGtkCalendar *calendar,
+				     gint         click_child);
+static void calendar_stop_spinning  (GlomGtkCalendar *calendar);
+
+static void calendar_invalidate_day     (GlomGtkCalendar *widget,
+					 gint       row,
+					 gint       col);
+static void calendar_invalidate_day_num (GlomGtkCalendar *widget,
+					 gint       day);
+static void calendar_invalidate_arrow   (GlomGtkCalendar *widget,
+					 guint      arrow);
+
+static void calendar_compute_days      (GlomGtkCalendar *calendar);
+     
+static char    *default_abbreviated_dayname[7];
+static char    *default_monthname[12];
+
+G_DEFINE_TYPE (GlomGtkCalendar, glom_gtk_calendar, GTK_TYPE_WIDGET)
+
+static void
+glom_gtk_calendar_class_init (GlomGtkCalendarClass *class)
+{
+  GObjectClass   *gobject_class;
+  GtkObjectClass   *object_class;
+  GtkWidgetClass *widget_class;
+
+  gobject_class = (GObjectClass*)  class;
+  object_class = (GtkObjectClass*)  class;
+  widget_class = (GtkWidgetClass*) class;
+  
+  gobject_class->set_property = glom_gtk_calendar_set_property;
+  gobject_class->get_property = glom_gtk_calendar_get_property;
+  gobject_class->finalize = glom_gtk_calendar_finalize;
+
+  object_class->destroy = glom_gtk_calendar_destroy;
+
+  widget_class->realize = glom_gtk_calendar_realize;
+  widget_class->unrealize = glom_gtk_calendar_unrealize;
+  widget_class->expose_event = glom_gtk_calendar_expose;
+  widget_class->size_request = glom_gtk_calendar_size_request;
+  widget_class->size_allocate = glom_gtk_calendar_size_allocate;
+  widget_class->button_press_event = glom_gtk_calendar_button_press;
+  widget_class->button_release_event = glom_gtk_calendar_button_release;
+  widget_class->motion_notify_event = glom_gtk_calendar_motion_notify;
+  widget_class->enter_notify_event = glom_gtk_calendar_enter_notify;
+  widget_class->leave_notify_event = glom_gtk_calendar_leave_notify;
+  widget_class->key_press_event = glom_gtk_calendar_key_press;
+  widget_class->scroll_event = glom_gtk_calendar_scroll;
+  widget_class->style_set = glom_gtk_calendar_style_set;
+  widget_class->state_changed = glom_gtk_calendar_state_changed;
+  widget_class->grab_notify = glom_gtk_calendar_grab_notify;
+  widget_class->focus_out_event = glom_gtk_calendar_focus_out;
+  widget_class->query_tooltip = glom_gtk_calendar_query_tooltip;
+
+  widget_class->drag_data_get = glom_gtk_calendar_drag_data_get;
+  widget_class->drag_motion = glom_gtk_calendar_drag_motion;
+  widget_class->drag_leave = glom_gtk_calendar_drag_leave;
+  widget_class->drag_drop = glom_gtk_calendar_drag_drop;
+  widget_class->drag_data_received = glom_gtk_calendar_drag_data_received;
+  
+  /**
+   * GlomGtkCalendar:year:
+   *
+   * The selected year. 
+   * This property gets initially set to the current year.
+   */  
+  g_object_class_install_property (gobject_class,
+                                   PROP_YEAR,
+                                   g_param_spec_int ("year",
+						     P_("Year"),
+						     P_("The selected year"),
+						     0, G_MAXINT, 0,
+						     GTK_PARAM_READWRITE));
+
+  /**
+   * GlomGtkCalendar:month:
+   *
+   * The selected month (as a number between 0 and 11). 
+   * This property gets initially set to the current month.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_MONTH,
+                                   g_param_spec_int ("month",
+						     P_("Month"),
+						     P_("The selected month (as a number between 0 and 11)"),
+						     0, 11, 0,
+						     GTK_PARAM_READWRITE));
+
+  /**
+   * GlomGtkCalendar:day:
+   *
+   * The selected day (as a number between 1 and 31, or 0 
+   * to unselect the currently selected day).
+   * This property gets initially set to the current day.
+   */
+  g_object_class_install_property (gobject_class,
+                                   PROP_DAY,
+                                   g_param_spec_int ("day",
+						     P_("Day"),
+						     P_("The selected day (as a number between 1 and 31, or 0 to unselect the currently selected day)"),
+						     0, 31, 0,
+						     GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:show-heading:
+ *
+ * Determines whether a heading is displayed.
+ *
+ * Since: 2.4
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHOW_HEADING,
+                                   g_param_spec_boolean ("show-heading",
+							 P_("Show Heading"),
+							 P_("If TRUE, a heading is displayed"),
+							 TRUE,
+							 GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:show-day-names:
+ *
+ * Determines whether day names are displayed.
+ *
+ * Since: 2.4
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHOW_DAY_NAMES,
+                                   g_param_spec_boolean ("show-day-names",
+							 P_("Show Day Names"),
+							 P_("If TRUE, day names are displayed"),
+							 TRUE,
+							 GTK_PARAM_READWRITE));
+/**
+ * GlomGtkCalendar:no-month-change:
+ *
+ * Determines whether the selected month can be changed.
+ *
+ * Since: 2.4
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_NO_MONTH_CHANGE,
+                                   g_param_spec_boolean ("no-month-change",
+							 P_("No Month Change"),
+							 P_("If TRUE, the selected month cannot be changed"),
+							 FALSE,
+							 GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:show-week-numbers:
+ *
+ * Determines whether week numbers are displayed.
+ *
+ * Since: 2.4
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHOW_WEEK_NUMBERS,
+                                   g_param_spec_boolean ("show-week-numbers",
+							 P_("Show Week Numbers"),
+							 P_("If TRUE, week numbers are displayed"),
+							 FALSE,
+							 GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:detail-width-chars:
+ *
+ * Width of a detail cell, in characters.
+ * A value of 0 allows any width. See glom_gtk_calendar_set_detail_func().
+ *
+ * Since: 2.16
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_DETAIL_WIDTH_CHARS,
+                                   g_param_spec_int ("detail-width-chars",
+						     P_("Details Width"),
+						     P_("Details width in characters"),
+						     0, 127, 0,
+						     GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:detail-height-rows:
+ *
+ * Height of a detail cell, in rows.
+ * A value of 0 allows any width. See glom_gtk_calendar_set_detail_func().
+ *
+ * Since: 2.16
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_DETAIL_HEIGHT_ROWS,
+                                   g_param_spec_int ("detail-height-rows",
+						     P_("Details Height"),
+						     P_("Details height in rows"),
+						     0, 127, 0,
+						     GTK_PARAM_READWRITE));
+
+/**
+ * GlomGtkCalendar:show-details:
+ *
+ * Determines whether details are shown directly in the widget, or if they are
+ * available only as tooltip. When this property is set days with details are
+ * marked.
+ *
+ * Since: 2.16
+ */
+  g_object_class_install_property (gobject_class,
+                                   PROP_SHOW_DETAILS,
+                                   g_param_spec_boolean ("show-details",
+							 P_("Show Details"),
+							 P_("If TRUE, details are shown"),
+							 TRUE,
+							 GTK_PARAM_READWRITE));
+
+  glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL] =
+    g_signal_new (I_("month_changed"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, month_changed),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[DAY_SELECTED_SIGNAL] =
+    g_signal_new (I_("day_selected"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, day_selected),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL] =
+    g_signal_new (I_("day_selected_double_click"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, day_selected_double_click),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[PREV_MONTH_SIGNAL] =
+    g_signal_new (I_("prev_month"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, prev_month),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[NEXT_MONTH_SIGNAL] =
+    g_signal_new (I_("next_month"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, next_month),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[PREV_YEAR_SIGNAL] =
+    g_signal_new (I_("prev_year"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, prev_year),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  glom_gtk_calendar_signals[NEXT_YEAR_SIGNAL] =
+    g_signal_new (I_("next_year"),
+		  G_OBJECT_CLASS_TYPE (gobject_class),
+		  G_SIGNAL_RUN_FIRST,
+		  G_STRUCT_OFFSET (GlomGtkCalendarClass, next_year),
+		  NULL, NULL,
+		  _gtk_marshal_VOID__VOID,
+		  G_TYPE_NONE, 0);
+  
+  g_type_class_add_private (gobject_class, sizeof (GlomGtkCalendarPrivate));
+}
+
+static void
+glom_gtk_calendar_init (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  time_t secs;
+  struct tm *tm;
+  gint i;
+#ifdef G_OS_WIN32
+  wchar_t wbuffer[100];
+#else
+  char buffer[255];
+  time_t tmp_time;
+#endif
+  GlomGtkCalendarPrivate *priv;
+  gchar *year_before;
+#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
+  union { unsigned int word; char *string; } langinfo;
+  gint week_1stday = 0;
+  gint first_weekday = 1;
+  guint week_origin;
+#else
+  gchar *week_start;
+#endif
+
+  priv = calendar->priv = G_TYPE_INSTANCE_GET_PRIVATE (calendar,
+						       GTK_TYPE_CALENDAR,
+						       GlomGtkCalendarPrivate);
+
+  GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
+  
+  if (!default_abbreviated_dayname[0])
+    for (i=0; i<7; i++)
+      {
+#ifndef G_OS_WIN32
+	tmp_time= (i+3)*86400;
+	strftime ( buffer, sizeof (buffer), "%a", gmtime (&tmp_time));
+	default_abbreviated_dayname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+	if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SABBREVDAYNAME1 + (i+6)%7,
+			     wbuffer, G_N_ELEMENTS (wbuffer)))
+	  default_abbreviated_dayname[i] = g_strdup_printf ("(%d)", i);
+	else
+	  default_abbreviated_dayname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+#endif
+      }
+  
+  if (!default_monthname[0])
+    for (i=0; i<12; i++)
+      {
+#ifndef G_OS_WIN32
+	tmp_time=i*2764800;
+	strftime ( buffer, sizeof (buffer), "%B", gmtime (&tmp_time));
+	default_monthname[i] = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+#else
+	if (!GetLocaleInfoW (GetThreadLocale (), LOCALE_SMONTHNAME1 + i,
+			     wbuffer, G_N_ELEMENTS (wbuffer)))
+	  default_monthname[i] = g_strdup_printf ("(%d)", i);
+	else
+	  default_monthname[i] = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+#endif
+      }
+  
+  /* Set defaults */
+  secs = time (NULL);
+  tm = localtime (&secs);
+  calendar->month = tm->tm_mon;
+  calendar->year  = 1900 + tm->tm_year;
+
+  for (i=0;i<31;i++)
+    calendar->marked_date[i] = FALSE;
+  calendar->num_marked_dates = 0;
+  calendar->selected_day = tm->tm_mday;
+  
+  calendar->display_flags = (GLOM_GTK_CALENDAR_SHOW_HEADING |
+			     GLOM_GTK_CALENDAR_SHOW_DAY_NAMES |
+			     GLOM_GTK_CALENDAR_SHOW_DETAILS);
+  
+  calendar->highlight_row = -1;
+  calendar->highlight_col = -1;
+  
+  calendar->focus_row = -1;
+  calendar->focus_col = -1;
+
+  priv->max_year_width = 0;
+  priv->max_month_width = 0;
+  priv->max_day_char_width = 0;
+  priv->max_week_char_width = 0;
+
+  priv->max_day_char_ascent = 0;
+  priv->max_day_char_descent = 0;
+  priv->max_label_char_ascent = 0;
+  priv->max_label_char_descent = 0;
+
+  priv->arrow_width = 10;
+
+  priv->need_timer = 0;
+  priv->timer = 0;
+  priv->click_child = -1;
+
+  priv->in_drag = 0;
+  priv->drag_highlight = 0;
+
+  gtk_drag_dest_set (widget, 0, NULL, 0, GDK_ACTION_COPY);
+  gtk_drag_dest_add_text_targets (widget);
+
+  priv->year_before = 0;
+
+  /* Translate to calendar:YM if you want years to be displayed
+   * before months; otherwise translate to calendar:MY.
+   * Do *not* translate it to anything else, if it
+   * it isn't calendar:YM or calendar:MY it will not work.
+   *
+   * Note that this flipping is in top of the text direction flipping,
+   * so if you have a default text direction of RTL and YM, then
+   * the year will appear on the right.
+   */
+  year_before = _("calendar:MY");
+  if (strcmp (year_before, "calendar:YM") == 0)
+    priv->year_before = 1;
+  else if (strcmp (year_before, "calendar:MY") != 0)
+    g_warning ("Whoever translated calendar:MY did so wrongly.\n");
+
+#ifdef G_OS_WIN32
+  priv->week_start = 0;
+  week_start = NULL;
+
+  if (GetLocaleInfoW (GetThreadLocale (), LOCALE_IFIRSTDAYOFWEEK,
+		      wbuffer, G_N_ELEMENTS (wbuffer)))
+    week_start = g_utf16_to_utf8 (wbuffer, -1, NULL, NULL, NULL);
+      
+  if (week_start != NULL)
+    {
+      priv->week_start = (week_start[0] - '0' + 1) % 7;
+      g_free(week_start);
+    }
+#else
+#ifdef HAVE__NL_TIME_FIRST_WEEKDAY
+  langinfo.string = nl_langinfo (_NL_TIME_FIRST_WEEKDAY);
+  first_weekday = langinfo.string[0];
+  langinfo.string = nl_langinfo (_NL_TIME_WEEK_1STDAY);
+  week_origin = langinfo.word;
+  if (week_origin == 19971130) /* Sunday */
+    week_1stday = 0;
+  else if (week_origin == 19971201) /* Monday */
+    week_1stday = 1;
+  else
+    g_warning ("Unknown value of _NL_TIME_WEEK_1STDAY.\n");
+
+  priv->week_start = (week_1stday + first_weekday - 1) % 7;
+#else
+  /* Translate to calendar:week_start:0 if you want Sunday to be the
+   * first day of the week to calendar:week_start:1 if you want Monday
+   * to be the first day of the week, and so on.
+   */  
+  week_start = _("calendar:week_start:0");
+
+  if (strncmp (week_start, "calendar:week_start:", 20) == 0)
+    priv->week_start = *(week_start + 20) - '0';
+  else 
+    priv->week_start = -1;
+  
+  if (priv->week_start < 0 || priv->week_start > 6)
+    {
+      g_warning ("Whoever translated calendar:week_start:0 did so wrongly.\n");
+      priv->week_start = 0;
+    }
+#endif
+#endif
+
+  calendar_compute_days (calendar);
+}
+
+
+/****************************************
+ *          Utility Functions           *
+ ****************************************/
+
+static void
+calendar_queue_refresh (GlomGtkCalendar *calendar)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (!(priv->detail_func) ||
+      !(calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DETAILS) ||
+       (priv->detail_width_chars && priv->detail_height_rows))
+    gtk_widget_queue_draw (GTK_WIDGET (calendar));
+  else
+    gtk_widget_queue_resize (GTK_WIDGET (calendar));
+}
+
+static void
+calendar_set_month_next (GlomGtkCalendar *calendar)
+{
+  gint month_len;
+  
+  g_return_if_fail (GTK_IS_WIDGET (calendar));
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    return;
+  
+  
+  if (calendar->month == 11)
+    {
+      calendar->month = 0;
+      calendar->year++;
+    } 
+  else 
+    calendar->month++;
+  
+  calendar_compute_days (calendar);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[NEXT_MONTH_SIGNAL],
+		 0);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+		 0);
+  
+  month_len = month_length[leap (calendar->year)][calendar->month + 1];
+  
+  if (month_len < calendar->selected_day)
+    {
+      calendar->selected_day = 0;
+      glom_gtk_calendar_select_day (calendar, month_len);
+    }
+  else
+    glom_gtk_calendar_select_day (calendar, calendar->selected_day);
+
+  calendar_queue_refresh (calendar);
+}
+
+static void
+calendar_set_year_prev (GlomGtkCalendar *calendar)
+{
+  gint month_len;
+  
+  g_return_if_fail (GTK_IS_WIDGET (calendar));
+  
+  calendar->year--;
+  calendar_compute_days (calendar);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[PREV_YEAR_SIGNAL],
+		 0);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+		 0);
+  
+  month_len = month_length[leap (calendar->year)][calendar->month + 1];
+  
+  if (month_len < calendar->selected_day)
+    {
+      calendar->selected_day = 0;
+      glom_gtk_calendar_select_day (calendar, month_len);
+    }
+  else
+    glom_gtk_calendar_select_day (calendar, calendar->selected_day);
+  
+  calendar_queue_refresh (calendar);
+}
+
+static void
+calendar_set_year_next (GlomGtkCalendar *calendar)
+{
+  gint month_len;
+  
+  g_return_if_fail (GTK_IS_WIDGET (calendar));
+  
+  calendar->year++;
+  calendar_compute_days (calendar);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[NEXT_YEAR_SIGNAL],
+		 0);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+		 0);
+  
+  month_len = month_length[leap (calendar->year)][calendar->month + 1];
+  
+  if (month_len < calendar->selected_day)
+    {
+      calendar->selected_day = 0;
+      glom_gtk_calendar_select_day (calendar, month_len);
+    }
+  else
+    glom_gtk_calendar_select_day (calendar, calendar->selected_day);
+  
+  calendar_queue_refresh (calendar);
+}
+
+static void
+calendar_compute_days (GlomGtkCalendar *calendar)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (GTK_WIDGET (calendar));
+  gint month;
+  gint year;
+  gint ndays_in_month;
+  gint ndays_in_prev_month;
+  gint first_day;
+  gint row;
+  gint col;
+  gint day;
+
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+
+  year = calendar->year;
+  month = calendar->month + 1;
+  
+  ndays_in_month = month_length[leap (year)][month];
+  
+  first_day = day_of_week (year, month, 1);
+  first_day = (first_day + 7 - priv->week_start) % 7;
+  
+  /* Compute days of previous month */
+  if (month > 1)
+    ndays_in_prev_month = month_length[leap (year)][month-1];
+  else
+    ndays_in_prev_month = month_length[leap (year)][12];
+  day = ndays_in_prev_month - first_day + 1;
+  
+  row = 0;
+  if (first_day > 0)
+    {
+      for (col = 0; col < first_day; col++)
+	{
+	  calendar->day[row][col] = day;
+	  calendar->day_month[row][col] = MONTH_PREV;
+	  day++;
+	}
+    }
+  
+  /* Compute days of current month */
+  col = first_day;
+  for (day = 1; day <= ndays_in_month; day++)
+    {
+      calendar->day[row][col] = day;
+      calendar->day_month[row][col] = MONTH_CURRENT;
+      
+      col++;
+      if (col == 7)
+	{
+	  row++;
+	  col = 0;
+	}
+    }
+  
+  /* Compute days of next month */
+  day = 1;
+  for (; row <= 5; row++)
+    {
+      for (; col <= 6; col++)
+	{
+	  calendar->day[row][col] = day;
+	  calendar->day_month[row][col] = MONTH_NEXT;
+	  day++;
+	}
+      col = 0;
+    }
+}
+
+static void
+calendar_select_and_focus_day (GlomGtkCalendar *calendar,
+			       guint        day)
+{
+  gint old_focus_row = calendar->focus_row;
+  gint old_focus_col = calendar->focus_col;
+  gint row;
+  gint col;
+  
+  for (row = 0; row < 6; row ++)
+    for (col = 0; col < 7; col++)
+      {
+	if (calendar->day_month[row][col] == MONTH_CURRENT 
+	    && calendar->day[row][col] == day)
+	  {
+	    calendar->focus_row = row;
+	    calendar->focus_col = col;
+	  }
+      }
+
+  if (old_focus_row != -1 && old_focus_col != -1)
+    calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+  
+  glom_gtk_calendar_select_day (calendar, day);
+}
+
+
+/****************************************
+ *     Layout computation utilities     *
+ ****************************************/
+
+static gint
+calendar_row_height (GlomGtkCalendar *calendar)
+{
+  return (GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->main_h - CALENDAR_MARGIN
+	  - ((calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+	     ? CALENDAR_YSEP : CALENDAR_MARGIN)) / 6;
+}
+
+
+/* calendar_left_x_for_column: returns the x coordinate
+ * for the left of the column */
+static gint
+calendar_left_x_for_column (GlomGtkCalendar *calendar,
+			    gint	 column)
+{
+  gint width;
+  gint x_left;
+  
+  if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
+    column = 6 - column;
+
+  width = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    x_left = CALENDAR_XSEP + (width + DAY_XSEP) * column;
+  else
+    x_left = CALENDAR_MARGIN + (width + DAY_XSEP) * column;
+  
+  return x_left;
+}
+
+/* column_from_x: returns the column 0-6 that the
+ * x pixel of the xwindow is in */
+static gint
+calendar_column_from_x (GlomGtkCalendar *calendar,
+			gint	     event_x)
+{
+  gint c, column;
+  gint x_left, x_right;
+  
+  column = -1;
+  
+  for (c = 0; c < 7; c++)
+    {
+      x_left = calendar_left_x_for_column (calendar, c);
+      x_right = x_left + GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->day_width;
+      
+      if (event_x >= x_left && event_x < x_right)
+	{
+	  column = c;
+	  break;
+	}
+    }
+  
+  return column;
+}
+
+/* calendar_top_y_for_row: returns the y coordinate
+ * for the top of the row */
+static gint
+calendar_top_y_for_row (GlomGtkCalendar *calendar,
+			gint	     row)
+{
+  
+  return (GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->main_h 
+	  - (CALENDAR_MARGIN + (6 - row)
+	     * calendar_row_height (calendar)));
+}
+
+/* row_from_y: returns the row 0-5 that the
+ * y pixel of the xwindow is in */
+static gint
+calendar_row_from_y (GlomGtkCalendar *calendar,
+		     gint	  event_y)
+{
+  gint r, row;
+  gint height;
+  gint y_top, y_bottom;
+  
+  height = calendar_row_height (calendar);
+  row = -1;
+  
+  for (r = 0; r < 6; r++)
+    {
+      y_top = calendar_top_y_for_row (calendar, r);
+      y_bottom = y_top + height;
+      
+      if (event_y >= y_top && event_y < y_bottom)
+	{
+	  row = r;
+	  break;
+	}
+    }
+  
+  return row;
+}
+
+static void
+calendar_arrow_rectangle (GlomGtkCalendar  *calendar,
+			  guint	        arrow,
+			  GdkRectangle *rect)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  gboolean year_left;
+
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
+    year_left = priv->year_before;
+  else
+    year_left = !priv->year_before;
+    
+  rect->y = 3;
+  rect->width = priv->arrow_width;
+  rect->height = priv->header_h - 7;
+  
+  switch (arrow)
+    {
+    case ARROW_MONTH_LEFT:
+      if (year_left) 
+	rect->x = (widget->allocation.width - 2 * widget->style->xthickness
+		   - (3 + 2*priv->arrow_width 
+		      + priv->max_month_width));
+      else
+	rect->x = 3;
+      break;
+    case ARROW_MONTH_RIGHT:
+      if (year_left) 
+	rect->x = (widget->allocation.width - 2 * widget->style->xthickness 
+		   - 3 - priv->arrow_width);
+      else
+	rect->x = (priv->arrow_width 
+		   + priv->max_month_width);
+      break;
+    case ARROW_YEAR_LEFT:
+      if (year_left) 
+	rect->x = 3;
+      else
+	rect->x = (widget->allocation.width - 2 * widget->style->xthickness
+		   - (3 + 2*priv->arrow_width 
+		      + priv->max_year_width));
+      break;
+    case ARROW_YEAR_RIGHT:
+      if (year_left) 
+	rect->x = (priv->arrow_width 
+		   + priv->max_year_width);
+      else
+	rect->x = (widget->allocation.width - 2 * widget->style->xthickness 
+		   - 3 - priv->arrow_width);
+      break;
+    }
+}
+
+static void
+calendar_day_rectangle (GlomGtkCalendar  *calendar,
+			gint          row,
+			gint          col,
+			GdkRectangle *rect)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  rect->x = calendar_left_x_for_column (calendar, col);
+  rect->y = calendar_top_y_for_row (calendar, row);
+  rect->height = calendar_row_height (calendar);
+  rect->width = priv->day_width;
+}
+
+static void
+calendar_set_month_prev (GlomGtkCalendar *calendar)
+{
+  gint month_len;
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    return;
+  
+  if (calendar->month == 0)
+    {
+      calendar->month = 11;
+      calendar->year--;
+    } 
+  else 
+    calendar->month--;
+  
+  month_len = month_length[leap (calendar->year)][calendar->month + 1];
+  
+  calendar_compute_days (calendar);
+  
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[PREV_MONTH_SIGNAL],
+		 0);
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+		 0);
+  
+  if (month_len < calendar->selected_day)
+    {
+      calendar->selected_day = 0;
+      glom_gtk_calendar_select_day (calendar, month_len);
+    }
+  else
+    {
+      if (calendar->selected_day < 0)
+	calendar->selected_day = calendar->selected_day + 1 + month_length[leap (calendar->year)][calendar->month + 1];
+      glom_gtk_calendar_select_day (calendar, calendar->selected_day);
+    }
+
+  calendar_queue_refresh (calendar);
+}
+
+
+/****************************************
+ *           Basic object methods       *
+ ****************************************/
+
+static void
+glom_gtk_calendar_finalize (GObject *object)
+{
+  (* G_OBJECT_CLASS (glom_gtk_calendar_parent_class)->finalize) (object);
+}
+
+static void
+glom_gtk_calendar_destroy (GtkObject *object)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (object);
+
+  calendar_stop_spinning (GLOM_GTK_CALENDAR (object));
+  
+  /* Call the destroy function for the extra display callback: */
+  if (priv->detail_func_destroy && priv->detail_func_user_data)
+    {
+      priv->detail_func_destroy (priv->detail_func_user_data);
+      priv->detail_func_user_data = NULL;
+      priv->detail_func_destroy = NULL;
+    }
+
+  GTK_OBJECT_CLASS (glom_gtk_calendar_parent_class)->destroy (object);
+}
+
+
+static void
+calendar_set_display_option (GlomGtkCalendar              *calendar,
+			     GlomGtkCalendarDisplayOptions flag,
+			     gboolean                  setting)
+{
+  GlomGtkCalendarDisplayOptions flags;
+  if (setting) 
+    flags = calendar->display_flags | flag;
+  else
+    flags = calendar->display_flags & ~flag; 
+  glom_gtk_calendar_display_options (calendar, flags);
+}
+
+static gboolean
+calendar_get_display_option (GlomGtkCalendar              *calendar,
+			     GlomGtkCalendarDisplayOptions flag)
+{
+  return (calendar->display_flags & flag) != 0;
+}
+
+static void 
+glom_gtk_calendar_set_property (GObject      *object,
+			   guint         prop_id,
+			   const GValue *value,
+			   GParamSpec   *pspec)
+{
+  GlomGtkCalendar *calendar;
+
+  calendar = GLOM_GTK_CALENDAR (object);
+
+  switch (prop_id) 
+    {
+    case PROP_YEAR:
+      glom_gtk_calendar_select_month (calendar,
+				 calendar->month,
+				 g_value_get_int (value));
+      break;
+    case PROP_MONTH:
+      glom_gtk_calendar_select_month (calendar,
+				 g_value_get_int (value),
+				 calendar->year);
+      break;
+    case PROP_DAY:
+      glom_gtk_calendar_select_day (calendar,
+			       g_value_get_int (value));
+      break;
+    case PROP_SHOW_HEADING:
+      calendar_set_display_option (calendar,
+				   GLOM_GTK_CALENDAR_SHOW_HEADING,
+				   g_value_get_boolean (value));
+      break;
+    case PROP_SHOW_DAY_NAMES:
+      calendar_set_display_option (calendar,
+				   GLOM_GTK_CALENDAR_SHOW_DAY_NAMES,
+				   g_value_get_boolean (value));
+      break;
+    case PROP_NO_MONTH_CHANGE:
+      calendar_set_display_option (calendar,
+				   GLOM_GTK_CALENDAR_NO_MONTH_CHANGE,
+				   g_value_get_boolean (value));
+      break;
+    case PROP_SHOW_WEEK_NUMBERS:
+      calendar_set_display_option (calendar,
+				   GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS,
+				   g_value_get_boolean (value));
+      break;
+    case PROP_SHOW_DETAILS:
+      calendar_set_display_option (calendar,
+				   GLOM_GTK_CALENDAR_SHOW_DETAILS,
+				   g_value_get_boolean (value));
+      break;
+    case PROP_DETAIL_WIDTH_CHARS:
+      glom_gtk_calendar_set_detail_width_chars (calendar,
+                                           g_value_get_int (value));
+      break;
+    case PROP_DETAIL_HEIGHT_ROWS:
+      glom_gtk_calendar_set_detail_height_rows (calendar,
+                                           g_value_get_int (value));
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+static void 
+glom_gtk_calendar_get_property (GObject      *object,
+			   guint         prop_id,
+			   GValue       *value,
+			   GParamSpec   *pspec)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (object);
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (object);
+
+  switch (prop_id) 
+    {
+    case PROP_YEAR:
+      g_value_set_int (value, calendar->year);
+      break;
+    case PROP_MONTH:
+      g_value_set_int (value, calendar->month);
+      break;
+    case PROP_DAY:
+      g_value_set_int (value, calendar->selected_day);
+      break;
+    case PROP_SHOW_HEADING:
+      g_value_set_boolean (value, calendar_get_display_option (calendar,
+							       GLOM_GTK_CALENDAR_SHOW_HEADING));
+      break;
+    case PROP_SHOW_DAY_NAMES:
+      g_value_set_boolean (value, calendar_get_display_option (calendar,
+							       GLOM_GTK_CALENDAR_SHOW_DAY_NAMES));
+      break;
+    case PROP_NO_MONTH_CHANGE:
+      g_value_set_boolean (value, calendar_get_display_option (calendar,
+							       GLOM_GTK_CALENDAR_NO_MONTH_CHANGE));
+      break;
+    case PROP_SHOW_WEEK_NUMBERS:
+      g_value_set_boolean (value, calendar_get_display_option (calendar,
+							       GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS));
+      break;
+    case PROP_SHOW_DETAILS:
+      g_value_set_boolean (value, calendar_get_display_option (calendar,
+							       GLOM_GTK_CALENDAR_SHOW_DETAILS));
+      break;
+    case PROP_DETAIL_WIDTH_CHARS:
+      g_value_set_int (value, priv->detail_width_chars);
+      break;
+    case PROP_DETAIL_HEIGHT_ROWS:
+      g_value_set_int (value, priv->detail_height_rows);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+    }
+}
+
+
+/****************************************
+ *             Realization              *
+ ****************************************/
+
+static void
+calendar_realize_arrows (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  gint i;
+  
+  /* Arrow windows ------------------------------------- */
+  if (! (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+      && (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_HEADING))
+    {
+      attributes.wclass = GDK_INPUT_OUTPUT;
+      attributes.window_type = GDK_WINDOW_CHILD;
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.colormap = gtk_widget_get_colormap (widget);
+      attributes.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
+			       | GDK_BUTTON_PRESS_MASK	| GDK_BUTTON_RELEASE_MASK
+			       | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK);
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+      for (i = 0; i < 4; i++)
+	{
+	  GdkRectangle rect;
+	  calendar_arrow_rectangle (calendar, i, &rect);
+	  
+	  attributes.x = rect.x;
+	  attributes.y = rect.y;
+	  attributes.width = rect.width;
+	  attributes.height = rect.height;
+	  priv->arrow_win[i] = gdk_window_new (priv->header_win,
+					       &attributes, 
+					       attributes_mask);
+	  if (GTK_WIDGET_IS_SENSITIVE (widget))
+	    priv->arrow_state[i] = GTK_STATE_NORMAL;
+	  else 
+	    priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
+	  gdk_window_set_background (priv->arrow_win[i],
+				     HEADER_BG_COLOR (GTK_WIDGET (calendar)));
+	  gdk_window_show (priv->arrow_win[i]);
+	  gdk_window_set_user_data (priv->arrow_win[i], widget);
+	}
+    }
+  else
+    {
+      for (i = 0; i < 4; i++)
+	priv->arrow_win[i] = NULL;
+    }
+}
+
+static void
+calendar_realize_header (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  
+  /* Header window ------------------------------------- */
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_HEADING)
+    {
+      attributes.wclass = GDK_INPUT_OUTPUT;
+      attributes.window_type = GDK_WINDOW_CHILD;
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.colormap = gtk_widget_get_colormap (widget);
+      attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+      attributes.x = widget->style->xthickness;
+      attributes.y = widget->style->ythickness;
+      attributes.width = widget->allocation.width - 2 * attributes.x;
+      attributes.height = priv->header_h;
+      priv->header_win = gdk_window_new (widget->window,
+					 &attributes, attributes_mask);
+      
+      gdk_window_set_background (priv->header_win,
+				 HEADER_BG_COLOR (GTK_WIDGET (calendar)));
+      gdk_window_show (priv->header_win);
+      gdk_window_set_user_data (priv->header_win, widget);
+      
+    }
+  else
+    {
+      priv->header_win = NULL;
+    }
+  calendar_realize_arrows (calendar);
+}
+
+static void
+calendar_realize_day_names (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  
+  /* Day names	window --------------------------------- */
+  if ( calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+    {
+      attributes.wclass = GDK_INPUT_OUTPUT;
+      attributes.window_type = GDK_WINDOW_CHILD;
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.colormap = gtk_widget_get_colormap (widget);
+      attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+      attributes.x = (widget->style->xthickness + INNER_BORDER);
+      attributes.y = priv->header_h + (widget->style->ythickness 
+					   + INNER_BORDER);
+      attributes.width = (widget->allocation.width 
+			  - (widget->style->xthickness + INNER_BORDER) 
+			  * 2);
+      attributes.height = priv->day_name_h;
+      priv->day_name_win = gdk_window_new (widget->window,
+					   &attributes, 
+					   attributes_mask);
+      gdk_window_set_background (priv->day_name_win, 
+				 BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
+      gdk_window_show (priv->day_name_win);
+      gdk_window_set_user_data (priv->day_name_win, widget);
+    }
+  else
+    {
+      priv->day_name_win = NULL;
+    }
+}
+
+static void
+calendar_realize_week_numbers (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+  
+  /* Week number window -------------------------------- */
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    {
+      attributes.wclass = GDK_INPUT_OUTPUT;
+      attributes.window_type = GDK_WINDOW_CHILD;
+      attributes.visual = gtk_widget_get_visual (widget);
+      attributes.colormap = gtk_widget_get_colormap (widget);
+      attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
+      
+      attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+      attributes.x = widget->style->xthickness + INNER_BORDER;
+      attributes.y = (priv->header_h + priv->day_name_h 
+		      + (widget->style->ythickness + INNER_BORDER));
+      attributes.width = priv->week_width;
+      attributes.height = priv->main_h;
+      priv->week_win = gdk_window_new (widget->window,
+				       &attributes, attributes_mask);
+      gdk_window_set_background (priv->week_win,  
+				 BACKGROUND_COLOR (GTK_WIDGET (calendar)));
+      gdk_window_show (priv->week_win);
+      gdk_window_set_user_data (priv->week_win, widget);
+    } 
+  else
+    {
+      priv->week_win = NULL;
+    }
+}
+
+static void
+glom_gtk_calendar_realize (GtkWidget *widget)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  GdkWindowAttr attributes;
+  gint attributes_mask;
+
+  GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
+  
+  attributes.x = widget->allocation.x;
+  attributes.y = widget->allocation.y;
+  attributes.width = widget->allocation.width;
+  attributes.height = widget->allocation.height;
+  attributes.wclass = GDK_INPUT_OUTPUT;
+  attributes.window_type = GDK_WINDOW_CHILD;
+  attributes.event_mask =  (gtk_widget_get_events (widget) 
+			    | GDK_EXPOSURE_MASK |GDK_KEY_PRESS_MASK | GDK_SCROLL_MASK);
+  attributes.visual = gtk_widget_get_visual (widget);
+  attributes.colormap = gtk_widget_get_colormap (widget);
+  
+  attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
+  widget->window = gdk_window_new (widget->parent->window,
+				   &attributes, attributes_mask);
+  
+  widget->style = gtk_style_attach (widget->style, widget->window);
+  
+  /* Header window ------------------------------------- */
+  calendar_realize_header (calendar);
+  /* Day names	window --------------------------------- */
+  calendar_realize_day_names (calendar);
+  /* Week number window -------------------------------- */
+  calendar_realize_week_numbers (calendar);
+  /* Main Window --------------------------------------	 */
+  attributes.event_mask =  (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK
+			    | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK
+			    | GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
+  
+  attributes.x = priv->week_width + (widget->style->ythickness + INNER_BORDER);
+  attributes.y = (priv->header_h + priv->day_name_h 
+		  + (widget->style->ythickness + INNER_BORDER));
+  attributes.width = (widget->allocation.width - attributes.x 
+		      - (widget->style->xthickness + INNER_BORDER));
+  attributes.height = priv->main_h;
+  priv->main_win = gdk_window_new (widget->window,
+				   &attributes, attributes_mask);
+  gdk_window_set_background (priv->main_win, 
+			     BACKGROUND_COLOR ( GTK_WIDGET ( calendar)));
+  gdk_window_show (priv->main_win);
+  gdk_window_set_user_data (priv->main_win, widget);
+  gdk_window_set_background (widget->window, BACKGROUND_COLOR (widget));
+  gdk_window_show (widget->window);
+  gdk_window_set_user_data (widget->window, widget);
+}
+
+static void
+glom_gtk_calendar_unrealize (GtkWidget *widget)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint i;
+  
+  if (priv->header_win)
+    {
+      for (i = 0; i < 4; i++)
+	{
+	  if (priv->arrow_win[i])
+	    {
+	      gdk_window_set_user_data (priv->arrow_win[i], NULL);
+	      gdk_window_destroy (priv->arrow_win[i]);
+	      priv->arrow_win[i] = NULL;
+	    }
+	}
+      gdk_window_set_user_data (priv->header_win, NULL);
+      gdk_window_destroy (priv->header_win);
+      priv->header_win = NULL;
+    }
+  
+  if (priv->week_win)
+    {
+      gdk_window_set_user_data (priv->week_win, NULL);
+      gdk_window_destroy (priv->week_win);
+      priv->week_win = NULL;      
+    }
+  
+  if (priv->main_win)
+    {
+      gdk_window_set_user_data (priv->main_win, NULL);
+      gdk_window_destroy (priv->main_win);
+      priv->main_win = NULL;      
+    }
+  if (priv->day_name_win)
+    {
+      gdk_window_set_user_data (priv->day_name_win, NULL);
+      gdk_window_destroy (priv->day_name_win);
+      priv->day_name_win = NULL;      
+    }
+  
+  if (GTK_WIDGET_CLASS (glom_gtk_calendar_parent_class)->unrealize)
+    (* GTK_WIDGET_CLASS (glom_gtk_calendar_parent_class)->unrealize) (widget);
+}
+
+static gchar*
+glom_gtk_calendar_get_detail (GlomGtkCalendar *calendar,
+                         gint         row,
+                         gint         column)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  gint year, month;
+
+  year = calendar->year;
+  month = calendar->month + calendar->day_month[row][column] - MONTH_CURRENT;
+
+  if (month < 0)
+    {
+      month += 12;
+      year -= 1;
+    }
+  else if (month > 11)
+    {
+      month -= 12;
+      year += 1;
+    }
+
+  return priv->detail_func (calendar,
+                            year, month,
+                            calendar->day[row][column],
+                            priv->detail_func_user_data);
+}
+
+static gboolean
+glom_gtk_calendar_query_tooltip (GtkWidget  *widget,
+                            gint        x,
+                            gint        y,
+                            gboolean    keyboard_mode,
+                            GtkTooltip *tooltip)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  gchar *detail = NULL;
+  GdkRectangle day_rect;
+
+  if (priv->main_win)
+    {
+      gint x0, y0, row, col;
+
+      gdk_window_get_position (priv->main_win, &x0, &y0);
+      col = calendar_column_from_x (calendar, x - x0);
+      row = calendar_row_from_y (calendar, y - y0);
+
+      if (0 != (priv->detail_overflow[row] & (1 << col)) ||
+          0 == (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DETAILS))
+        {
+          detail = glom_gtk_calendar_get_detail (calendar, row, col);
+          calendar_day_rectangle (calendar, row, col, &day_rect);
+
+          day_rect.x += x0;
+          day_rect.y += y0;
+        }
+    }
+
+  if (detail)
+    {
+      gtk_tooltip_set_tip_area (tooltip, &day_rect);
+      gtk_tooltip_set_markup (tooltip, detail);
+
+      g_free (detail);
+
+      return TRUE;
+    }
+
+  if (GTK_WIDGET_CLASS (glom_gtk_calendar_parent_class)->query_tooltip)
+    return GTK_WIDGET_CLASS (glom_gtk_calendar_parent_class)->query_tooltip (widget, x, y, keyboard_mode, tooltip);
+
+  return FALSE;
+}
+
+
+/****************************************
+ *       Size Request and Allocate      *
+ ****************************************/
+
+static void
+glom_gtk_calendar_size_request (GtkWidget	  *widget,
+			   GtkRequisition *requisition)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+
+  gint height;
+  gint i, r, c;
+  gint calendar_margin = CALENDAR_MARGIN;
+  gint header_width, main_width;
+  gint max_header_height = 0;
+  gint focus_width;
+  gint focus_padding;
+  gint max_detail_height;
+
+  gtk_widget_style_get (GTK_WIDGET (widget),
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_padding,
+			NULL);
+
+  layout = gtk_widget_create_pango_layout (widget, NULL);
+  
+  /*
+   * Calculate the requisition	width for the widget.
+   */
+  
+  /* Header width */
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_HEADING)
+    {
+      priv->max_month_width = 0;
+      for (i = 0; i < 12; i++)
+	{
+	  pango_layout_set_text (layout, default_monthname[i], -1);
+	  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+	  priv->max_month_width = MAX (priv->max_month_width,
+					       logical_rect.width + 8);
+	  max_header_height = MAX (max_header_height, logical_rect.height); 
+	}
+
+      priv->max_year_width = 0;
+      /* Translators:  This is a text measurement template.
+       * Translate it to the widest year text. 
+       * 
+       * Don't include the prefix "year measurement template|" 
+       * in the translation.
+       *
+       * If you don't understand this, leave it as "2000"
+       */
+      pango_layout_set_text (layout, Q_("year measurement template|2000"), -1);	  
+      pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+      priv->max_year_width = MAX (priv->max_year_width,
+				  logical_rect.width + 8);
+      max_header_height = MAX (max_header_height, logical_rect.height); 
+    } 
+  else 
+    {
+      priv->max_month_width = 0;
+      priv->max_year_width = 0;
+    }
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    header_width = (priv->max_month_width 
+		    + priv->max_year_width
+		    + 3 * 3);
+  else
+    header_width = (priv->max_month_width 
+		    + priv->max_year_width
+		    + 4 * priv->arrow_width + 3 * 3);
+
+  /* Mainwindow labels width */
+  
+  priv->max_day_char_width = 0;
+  priv->max_day_char_ascent = 0;
+  priv->max_day_char_descent = 0;
+  priv->min_day_width = 0;
+
+  for (i = 0; i < 9; i++)
+    {
+      gchar buffer[32];
+      g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), i * 11);
+      pango_layout_set_text (layout, buffer, -1);	  
+      pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+      priv->min_day_width = MAX (priv->min_day_width,
+					 logical_rect.width);
+
+      priv->max_day_char_ascent = MAX (priv->max_day_char_ascent,
+					       PANGO_ASCENT (logical_rect));
+      priv->max_day_char_descent = MAX (priv->max_day_char_descent, 
+						PANGO_DESCENT (logical_rect));
+    }
+  
+  priv->max_label_char_ascent = 0;
+  priv->max_label_char_descent = 0;
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+    for (i = 0; i < 7; i++)
+      {
+	pango_layout_set_text (layout, default_abbreviated_dayname[i], -1);
+	pango_layout_line_get_pixel_extents (pango_layout_get_lines_readonly (layout)->data, NULL, &logical_rect);
+
+	priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
+	priv->max_label_char_ascent = MAX (priv->max_label_char_ascent,
+						   PANGO_ASCENT (logical_rect));
+	priv->max_label_char_descent = MAX (priv->max_label_char_descent, 
+						    PANGO_DESCENT (logical_rect));
+      }
+  
+  priv->max_week_char_width = 0;
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    for (i = 0; i < 9; i++)
+      {
+	gchar buffer[32];
+	g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), i * 11);
+	pango_layout_set_text (layout, buffer, -1);	  
+	pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+	priv->max_week_char_width = MAX (priv->max_week_char_width,
+					   logical_rect.width / 2);
+      }
+  
+  /* Calculate detail extents. Do this as late as possible since
+   * pango_layout_set_markup is called which alters font settings. */
+  max_detail_height = 0;
+
+  if (priv->detail_func && (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DETAILS))
+    {
+      gchar *markup, *tail;
+
+      if (priv->detail_width_chars || priv->detail_height_rows)
+        {
+          gint rows = MAX (1, priv->detail_height_rows) - 1;
+          gsize len = priv->detail_width_chars + rows + 16;
+
+          markup = tail = g_alloca (len);
+
+          memcpy (tail,     "<small>", 7);
+          tail += 7;
+
+          memset (tail, 'm', priv->detail_width_chars);
+          tail += priv->detail_width_chars;
+
+          memset (tail, '\n', rows);
+          tail += rows;
+
+          memcpy (tail,     "</small>", 9);
+          tail += 9;
+
+          g_assert (len == (tail - markup));
+
+          pango_layout_set_markup (layout, markup, -1);
+          pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+          if (priv->detail_width_chars)
+            priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
+          if (priv->detail_height_rows)
+            max_detail_height = MAX (max_detail_height, logical_rect.height);
+        }
+
+      if (!priv->detail_width_chars || !priv->detail_height_rows)
+        for (r = 0; r < 6; r++)
+          for (c = 0; c < 7; c++)
+            {
+              gchar *detail = glom_gtk_calendar_get_detail (calendar, r, c);
+
+              if (detail)
+                {
+                  markup = g_strconcat ("<small>", detail, "</small>", NULL);
+                  pango_layout_set_markup (layout, markup, -1);
+
+                  if (priv->detail_width_chars)
+                    {
+                      pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
+                      pango_layout_set_width (layout, PANGO_SCALE * priv->min_day_width);
+                    }
+
+                  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+                  if (!priv->detail_width_chars)
+                    priv->min_day_width = MAX (priv->min_day_width, logical_rect.width);
+                  if (!priv->detail_height_rows)
+                    max_detail_height = MAX (max_detail_height, logical_rect.height);
+
+                  g_free (markup);
+                  g_free (detail);
+                }
+            }
+    }
+
+  /* We add one to max_day_char_width to be able to make the marked day "bold" */
+  priv->max_day_char_width = priv->min_day_width / 2 + 1;
+
+  main_width = (7 * (priv->min_day_width + (focus_padding + focus_width) * 2) + (DAY_XSEP * 6) + CALENDAR_MARGIN * 2
+		+ (priv->max_week_char_width
+		   ? priv->max_week_char_width * 2 + (focus_padding + focus_width) * 2 + CALENDAR_XSEP * 2
+		   : 0));
+  
+  
+  requisition->width = MAX (header_width, main_width + INNER_BORDER * 2) + widget->style->xthickness * 2;
+  
+  /*
+   * Calculate the requisition height for the widget.
+   */
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_HEADING)
+    {
+      priv->header_h = (max_header_height + CALENDAR_YSEP * 2);
+    }
+  else
+    {
+      priv->header_h = 0;
+    }
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+    {
+      priv->day_name_h = (priv->max_label_char_ascent
+				  + priv->max_label_char_descent
+				  + 2 * (focus_padding + focus_width) + calendar_margin);
+      calendar_margin = CALENDAR_YSEP;
+    } 
+  else
+    {
+      priv->day_name_h = 0;
+    }
+
+  priv->main_h = (CALENDAR_MARGIN + calendar_margin
+			  + 6 * (priv->max_day_char_ascent
+				 + priv->max_day_char_descent 
+                                 + max_detail_height
+				 + 2 * (focus_padding + focus_width))
+			  + DAY_YSEP * 5);
+  
+  height = (priv->header_h + priv->day_name_h 
+	    + priv->main_h);
+  
+  requisition->height = height + (widget->style->ythickness + INNER_BORDER) * 2;
+
+  g_object_unref (layout);
+}
+
+static void
+glom_gtk_calendar_size_allocate (GtkWidget	  *widget,
+			    GtkAllocation *allocation)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint xthickness = widget->style->xthickness;
+  gint ythickness = widget->style->xthickness;
+  guint i;
+  
+  widget->allocation = *allocation;
+    
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    {
+      priv->day_width = (priv->min_day_width
+			 * ((allocation->width - (xthickness + INNER_BORDER) * 2
+			     - (CALENDAR_MARGIN * 2) -  (DAY_XSEP * 6) - CALENDAR_XSEP * 2))
+			 / (7 * priv->min_day_width + priv->max_week_char_width * 2));
+      priv->week_width = ((allocation->width - (xthickness + INNER_BORDER) * 2
+			   - (CALENDAR_MARGIN * 2) - (DAY_XSEP * 6) - CALENDAR_XSEP * 2 )
+			  - priv->day_width * 7 + CALENDAR_MARGIN + CALENDAR_XSEP);
+    } 
+  else 
+    {
+      priv->day_width = (allocation->width
+			 - (xthickness + INNER_BORDER) * 2
+			 - (CALENDAR_MARGIN * 2)
+			 - (DAY_XSEP * 6))/7;
+      priv->week_width = 0;
+    }
+  
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      gdk_window_move_resize (widget->window,
+			      allocation->x, allocation->y,
+			      allocation->width, allocation->height);
+      if (priv->header_win)
+	gdk_window_move_resize (priv->header_win,
+				xthickness, ythickness,
+				allocation->width - 2 * xthickness, priv->header_h);
+
+      for (i = 0 ; i < 4 ; i++)
+	{
+	  if (priv->arrow_win[i])
+	    {
+	      GdkRectangle rect;
+	      calendar_arrow_rectangle (calendar, i, &rect);
+	  
+	      gdk_window_move_resize (priv->arrow_win[i],
+				      rect.x, rect.y, rect.width, rect.height);
+	    }
+	}
+      
+      if (priv->day_name_win)
+	gdk_window_move_resize (priv->day_name_win,
+				xthickness + INNER_BORDER,
+				priv->header_h + (widget->style->ythickness + INNER_BORDER),
+				allocation->width - (xthickness + INNER_BORDER) * 2,
+				priv->day_name_h);
+      if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
+	{
+	  if (priv->week_win)
+	    gdk_window_move_resize (priv->week_win,
+				    (xthickness + INNER_BORDER),
+				    priv->header_h + priv->day_name_h
+				    + (widget->style->ythickness + INNER_BORDER),
+				    priv->week_width,
+				    priv->main_h);
+	  gdk_window_move_resize (priv->main_win,
+				  priv->week_width + (xthickness + INNER_BORDER),
+				  priv->header_h + priv->day_name_h
+				  + (widget->style->ythickness + INNER_BORDER),
+				  allocation->width 
+				  - priv->week_width 
+				  - (xthickness + INNER_BORDER) * 2,
+				  priv->main_h);
+	}
+      else 
+	{
+	  gdk_window_move_resize (priv->main_win,
+				  (xthickness + INNER_BORDER),
+				  priv->header_h + priv->day_name_h
+				  + (widget->style->ythickness + INNER_BORDER),
+				  allocation->width 
+				  - priv->week_width 
+				  - (xthickness + INNER_BORDER) * 2,
+				  priv->main_h);
+	  if (priv->week_win)
+	    gdk_window_move_resize (priv->week_win,
+				    allocation->width 
+				    - priv->week_width 
+				    - (xthickness + INNER_BORDER),
+				    priv->header_h + priv->day_name_h
+				    + (widget->style->ythickness + INNER_BORDER),
+				    priv->week_width,
+				    priv->main_h);
+	}
+    }
+}
+
+
+/****************************************
+ *              Repainting              *
+ ****************************************/
+
+static void
+calendar_paint_header (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  cairo_t *cr;
+  char buffer[255];
+  int x, y;
+  gint header_width;
+  gint max_month_width;
+  gint max_year_width;
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  gboolean year_left;
+  time_t tmp_time;
+  struct tm *tm;
+  gchar *str;
+
+  if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR) 
+    year_left = priv->year_before;
+  else
+    year_left = !priv->year_before;
+
+  cr = gdk_cairo_create (priv->header_win);
+  
+  header_width = widget->allocation.width - 2 * widget->style->xthickness;
+  
+  max_month_width = priv->max_month_width;
+  max_year_width = priv->max_year_width;
+  
+  gtk_paint_shadow (widget->style, priv->header_win,
+		    GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+		    NULL, widget, "calendar",
+		    0, 0, header_width, priv->header_h);
+
+  tmp_time = 1;  /* Jan 1 1970, 00:00:01 UTC */
+  tm = gmtime (&tmp_time);
+  tm->tm_year = calendar->year - 1900;
+
+  /* Translators: This dictates how the year is displayed in
+   * gtkcalendar widget.  See strftime() manual for the format.
+   * Use only ASCII in the translation.
+   *
+   * Also look for the msgid "year measurement template|2000".  
+   * Translate that entry to a year with the widest output of this
+   * msgid. 
+   * 
+   * Don't include the prefix "calendar year format|" in the 
+   * translation. "%Y" is appropriate for most locales.
+   */
+  strftime (buffer, sizeof (buffer), Q_("calendar year format|%Y"), tm);
+  str = g_locale_to_utf8 (buffer, -1, NULL, NULL, NULL);
+  layout = gtk_widget_create_pango_layout (widget, str);
+  g_free (str);
+  
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+  
+  /* Draw title */
+  y = (priv->header_h - logical_rect.height) / 2;
+  
+  /* Draw year and its arrows */
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    if (year_left)
+      x = 3 + (max_year_width - logical_rect.width)/2;
+    else
+      x = header_width - (3 + max_year_width
+			  - (max_year_width - logical_rect.width)/2);
+  else
+    if (year_left)
+      x = 3 + priv->arrow_width + (max_year_width - logical_rect.width)/2;
+    else
+      x = header_width - (3 + priv->arrow_width + max_year_width
+			  - (max_year_width - logical_rect.width)/2);
+  
+
+  gdk_cairo_set_source_color (cr, HEADER_FG_COLOR (GTK_WIDGET (calendar)));
+  cairo_move_to (cr, x, y);
+  pango_cairo_show_layout (cr, layout);
+  
+  /* Draw month */
+  g_snprintf (buffer, sizeof (buffer), "%s", default_monthname[calendar->month]);
+  pango_layout_set_text (layout, buffer, -1);
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    if (year_left)
+      x = header_width - (3 + max_month_width
+			  - (max_month_width - logical_rect.width)/2);      
+    else
+    x = 3 + (max_month_width - logical_rect.width) / 2;
+  else
+    if (year_left)
+      x = header_width - (3 + priv->arrow_width + max_month_width
+			  - (max_month_width - logical_rect.width)/2);
+    else
+    x = 3 + priv->arrow_width + (max_month_width - logical_rect.width)/2;
+
+  cairo_move_to (cr, x, y);
+  pango_cairo_show_layout (cr, layout);
+
+  g_object_unref (layout);
+  cairo_destroy (cr);
+}
+
+static void
+calendar_paint_day_names (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  cairo_t *cr;
+  char buffer[255];
+  int day,i;
+  int day_width, cal_width;
+  int day_wid_sep;
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  gint focus_padding;
+  gint focus_width;
+  
+  cr = gdk_cairo_create (priv->day_name_win);
+  
+  gtk_widget_style_get (GTK_WIDGET (widget),
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_padding,
+			NULL);
+  
+  day_width = priv->day_width;
+  cal_width = widget->allocation.width;
+  day_wid_sep = day_width + DAY_XSEP;
+  
+  /*
+   * Draw rectangles as inverted background for the labels.
+   */
+
+  gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
+  cairo_rectangle (cr,
+		   CALENDAR_MARGIN, CALENDAR_MARGIN,
+		   cal_width-CALENDAR_MARGIN * 2,
+		   priv->day_name_h - CALENDAR_MARGIN);
+  cairo_fill (cr);
+  
+  if (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    {
+      cairo_rectangle (cr, 
+		       CALENDAR_MARGIN,
+		       priv->day_name_h - CALENDAR_YSEP,
+		       priv->week_width - CALENDAR_YSEP - CALENDAR_MARGIN,
+		       CALENDAR_YSEP);
+      cairo_fill (cr);
+    }
+  
+  /*
+   * Write the labels
+   */
+
+  layout = gtk_widget_create_pango_layout (widget, NULL);
+
+  gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
+  for (i = 0; i < 7; i++)
+    {
+      if (gtk_widget_get_direction (GTK_WIDGET (calendar)) == GTK_TEXT_DIR_RTL)
+	day = 6 - i;
+      else
+	day = i;
+      day = (day + priv->week_start) % 7;
+      g_snprintf (buffer, sizeof (buffer), "%s", default_abbreviated_dayname[day]);
+
+      pango_layout_set_text (layout, buffer, -1);
+      pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+      cairo_move_to (cr, 
+		     (CALENDAR_MARGIN +
+		      + (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_LTR ?
+			 (priv->week_width + (priv->week_width ? CALENDAR_XSEP : 0))
+			 : 0)
+		      + day_wid_sep * i
+		      + (day_width - logical_rect.width)/2),
+		     CALENDAR_MARGIN + focus_width + focus_padding + logical_rect.y);
+      pango_cairo_show_layout (cr, layout);
+    }
+  
+  g_object_unref (layout);
+  cairo_destroy (cr);
+}
+
+static void
+calendar_paint_week_numbers (GlomGtkCalendar *calendar)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  cairo_t *cr;
+
+  guint week = 0, year;
+  gint row, x_loc, y_loc;
+  gint day_height;
+  char buffer[32];
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  gint focus_padding;
+  gint focus_width;
+  
+  cr = gdk_cairo_create (priv->week_win);
+  
+  gtk_widget_style_get (GTK_WIDGET (widget),
+			"focus-line-width", &focus_width,
+			"focus-padding", &focus_padding,
+			NULL);
+  
+  /*
+   * Draw a rectangle as inverted background for the labels.
+   */
+
+  gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
+  if (priv->day_name_win)
+    cairo_rectangle (cr, 
+		     CALENDAR_MARGIN,
+		     0,
+		     priv->week_width - CALENDAR_MARGIN,
+		     priv->main_h - CALENDAR_MARGIN);
+  else
+    cairo_rectangle (cr,
+		     CALENDAR_MARGIN,
+		     CALENDAR_MARGIN,
+		     priv->week_width - CALENDAR_MARGIN,
+		     priv->main_h - 2 * CALENDAR_MARGIN);
+  cairo_fill (cr);
+  
+  /*
+   * Write the labels
+   */
+  
+  layout = gtk_widget_create_pango_layout (widget, NULL);
+  
+  gdk_cairo_set_source_color (cr, SELECTED_FG_COLOR (widget));
+  day_height = calendar_row_height (calendar);
+  for (row = 0; row < 6; row++)
+    {
+      gboolean result;
+      
+      year = calendar->year;
+      if (calendar->day[row][6] < 15 && row > 3 && calendar->month == 11)
+	year++;
+
+      result = week_of_year (&week, &year,		
+			     ((calendar->day[row][6] < 15 && row > 3 ? 1 : 0)
+			      + calendar->month) % 12 + 1, calendar->day[row][6]);
+      g_return_if_fail (result);
+
+      /* Translators: this defines whether the week numbers should use
+       * localized digits or the ones used in English (0123...).
+       *
+       * Translate to "%Id" if you want to use localized digits, or
+       * translate to "%d" otherwise.  Don't include the
+       * "calendar:week:digits|" part in the translation.
+       *
+       * Note that translating this doesn't guarantee that you get localized
+       * digits.  That needs support from your system and locale definition
+       * too.
+       */
+      g_snprintf (buffer, sizeof (buffer), Q_("calendar:week:digits|%d"), week);
+      pango_layout_set_text (layout, buffer, -1);
+      pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+
+      y_loc = calendar_top_y_for_row (calendar, row) + (day_height - logical_rect.height) / 2;
+
+      x_loc = (priv->week_width
+	       - logical_rect.width
+	       - CALENDAR_XSEP - focus_padding - focus_width);
+
+      cairo_move_to (cr, x_loc, y_loc);
+      pango_cairo_show_layout (cr, layout);
+    }
+  
+  g_object_unref (layout);
+  cairo_destroy (cr);
+}
+
+static void
+calendar_invalidate_day_num (GlomGtkCalendar *calendar,
+			     gint         day)
+{
+  gint r, c, row, col;
+  
+  row = -1;
+  col = -1;
+  for (r = 0; r < 6; r++)
+    for (c = 0; c < 7; c++)
+      if (calendar->day_month[r][c] == MONTH_CURRENT &&
+	  calendar->day[r][c] == day)
+	{
+	  row = r;
+	  col = c;
+	}
+  
+  g_return_if_fail (row != -1);
+  g_return_if_fail (col != -1);
+  
+  calendar_invalidate_day (calendar, row, col);
+}
+
+static void
+calendar_invalidate_day (GlomGtkCalendar *calendar,
+			 gint         row,
+			 gint         col)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (priv->main_win)
+    {
+      GdkRectangle day_rect;
+      
+      calendar_day_rectangle (calendar, row, col, &day_rect);
+      gdk_window_invalidate_rect (priv->main_win, &day_rect, FALSE);
+    }
+}
+
+static gboolean
+is_color_attribute (PangoAttribute *attribute,
+                    gpointer        data)
+{
+  return (attribute->klass->type == PANGO_ATTR_FOREGROUND ||
+          attribute->klass->type == PANGO_ATTR_BACKGROUND);
+}
+
+static void
+calendar_paint_day (GlomGtkCalendar *calendar,
+		    gint	     row,
+		    gint	     col)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  cairo_t *cr;
+  GdkColor *text_color;
+  gchar *detail;
+  gchar buffer[32];
+  gint day;
+  gint x_loc, y_loc;
+  GdkRectangle day_rect;
+
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+  gboolean overflow = FALSE;
+  gboolean show_details;
+
+  g_return_if_fail (row < 6);
+  g_return_if_fail (col < 7);
+
+  cr = gdk_cairo_create (priv->main_win);
+
+  day = calendar->day[row][col];
+  show_details = (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_DETAILS);
+
+  calendar_day_rectangle (calendar, row, col, &day_rect);
+  
+  if (calendar->day_month[row][col] == MONTH_PREV)
+    {
+      text_color = PREV_MONTH_COLOR (widget);
+    } 
+  else if (calendar->day_month[row][col] == MONTH_NEXT)
+    {
+      text_color =  NEXT_MONTH_COLOR (widget);
+    } 
+  else 
+    {
+#if 0      
+      if (calendar->highlight_row == row && calendar->highlight_col == col)
+	{
+	  cairo_set_source_color (cr, HIGHLIGHT_BG_COLOR (widget));
+	  gdk_cairo_rectangle (cr, &day_rect);
+	  cairo_fill (cr);
+	}
+#endif     
+      if (calendar->selected_day == day)
+	{
+	  gdk_cairo_set_source_color (cr, SELECTED_BG_COLOR (widget));
+	  gdk_cairo_rectangle (cr, &day_rect);
+	  cairo_fill (cr);
+	}
+      if (calendar->selected_day == day)
+	text_color = SELECTED_FG_COLOR (widget);
+      else if (calendar->marked_date[day-1])
+	text_color = MARKED_COLOR (widget);
+      else
+	text_color = NORMAL_DAY_COLOR (widget);
+    }
+
+  /* Translators: this defines whether the day numbers should use
+   * localized digits or the ones used in English (0123...).
+   *
+   * Translate to "%Id" if you want to use localized digits, or
+   * translate to "%d" otherwise.  Don't include the "calendar:day:digits|"
+   * part in the translation.
+   *
+   * Note that translating this doesn't guarantee that you get localized
+   * digits.  That needs support from your system and locale definition
+   * too.
+   */
+  g_snprintf (buffer, sizeof (buffer), Q_("calendar:day:digits|%d"), day);
+
+  /* Get extra information to show, if any: */
+
+  if (priv->detail_func)
+    detail = glom_gtk_calendar_get_detail (calendar, row, col);
+  else
+    detail = NULL;
+
+  layout = gtk_widget_create_pango_layout (widget, buffer);
+  pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+  pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
+  
+  x_loc = day_rect.x + (day_rect.width - logical_rect.width) / 2;
+  y_loc = day_rect.y;
+
+  gdk_cairo_set_source_color (cr, text_color);
+  cairo_move_to (cr, x_loc, y_loc);
+  pango_cairo_show_layout (cr, layout);
+
+  if (calendar->day_month[row][col] == MONTH_CURRENT &&
+     (calendar->marked_date[day-1] || (detail && !show_details)))
+    {
+      cairo_move_to (cr, x_loc - 1, y_loc);
+      pango_cairo_show_layout (cr, layout);
+    }
+
+  y_loc += priv->max_day_char_descent;
+
+  if (priv->detail_func && show_details)
+    {
+      cairo_save (cr);
+
+      if (calendar->selected_day == day)
+        gdk_cairo_set_source_color (cr, &widget->style->text[GTK_STATE_ACTIVE]);
+      else if (calendar->day_month[row][col] == MONTH_CURRENT)
+        gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_ACTIVE]);
+      else
+        gdk_cairo_set_source_color (cr, &widget->style->base[GTK_STATE_INSENSITIVE]);
+
+      cairo_set_line_width (cr, 1);
+      cairo_move_to (cr, day_rect.x + 2, y_loc + 0.5);
+      cairo_line_to (cr, day_rect.x + day_rect.width - 2, y_loc + 0.5);
+      cairo_stroke (cr);
+
+      cairo_restore (cr);
+
+      y_loc += 2;
+    }
+
+  if (detail && show_details)
+    {
+      gint i, n_lines;
+
+      gchar *markup = g_strconcat ("<small>", detail, "</small>", NULL);
+      pango_layout_set_markup (layout, markup, -1);
+      g_free (markup);
+
+      if (day == calendar->selected_day)
+        {
+          /* Stripping colors as they conflict with selection marking. */
+
+          PangoAttrList *attrs = pango_layout_get_attributes (layout);
+          PangoAttrList *colors = NULL;
+
+          if (attrs)
+            colors = pango_attr_list_filter (attrs, is_color_attribute, NULL);
+          if (colors)
+            pango_attr_list_unref (colors);
+        }
+
+      if (priv->detail_width_chars)
+        {
+          pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
+          pango_layout_set_width (layout, PANGO_SCALE * priv->min_day_width);
+        }
+
+      n_lines = pango_layout_get_line_count (layout);
+
+      if (priv->detail_height_rows &&
+          n_lines > priv->detail_height_rows)
+        {
+          n_lines = priv->detail_height_rows;
+          overflow = TRUE;
+        }
+
+      for (i = 0; i < n_lines; ++i)
+        {
+          PangoLayoutLine *line = pango_layout_get_line_readonly (layout, i);
+          pango_layout_line_get_pixel_extents (line, NULL, &logical_rect);
+
+          x_loc  = day_rect.x + (day_rect.width - logical_rect.width) / 2;
+          y_loc += PANGO_ASCENT (logical_rect);
+
+          cairo_move_to (cr, x_loc, y_loc);
+          pango_cairo_show_layout_line (cr, line);
+
+          y_loc += PANGO_DESCENT (logical_rect);
+        }
+    }
+
+  if (GTK_WIDGET_HAS_FOCUS (calendar) 
+      && calendar->focus_row == row && calendar->focus_col == col)
+    {
+      GtkStateType state;
+
+      if (calendar->selected_day == day)
+	state = GTK_WIDGET_HAS_FOCUS (widget) ? GTK_STATE_SELECTED : GTK_STATE_ACTIVE;
+      else
+	state = GTK_STATE_NORMAL;
+      
+      gtk_paint_focus (widget->style, 
+		       priv->main_win,
+	               state,
+		       NULL, widget, "calendar-day",
+		       day_rect.x,     day_rect.y, 
+		       day_rect.width, day_rect.height);
+    }
+
+  if (overflow)
+    priv->detail_overflow[row] |= (1 << col);
+  else
+    priv->detail_overflow[row] &= ~(1 << col);
+
+  g_object_unref (layout);
+  cairo_destroy (cr);
+  g_free (detail);
+}
+
+static void
+calendar_paint_main (GlomGtkCalendar *calendar)
+{
+  gint row, col;
+  
+  for (col = 0; col < 7; col++)
+    for (row = 0; row < 6; row++)
+      calendar_paint_day (calendar, row, col);
+}
+
+static void
+calendar_invalidate_arrow (GlomGtkCalendar *calendar,
+			   guint        arrow)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  GdkWindow *window;
+  
+  window = priv->arrow_win[arrow];
+  if (window)
+    gdk_window_invalidate_rect (window, NULL, FALSE);
+}
+
+static void
+calendar_paint_arrow (GlomGtkCalendar *calendar,
+		      guint	       arrow)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  GdkWindow *window;
+  
+  window = priv->arrow_win[arrow];
+  if (window)
+    {
+      cairo_t *cr = gdk_cairo_create (window);
+      gint width, height;
+      gint state;
+	
+      state = priv->arrow_state[arrow];
+
+      gdk_cairo_set_source_color (cr, &widget->style->bg[state]);
+      cairo_paint (cr);
+      cairo_destroy (cr);
+      
+      gdk_drawable_get_size (window, &width, &height);
+      if (arrow == ARROW_MONTH_LEFT || arrow == ARROW_YEAR_LEFT)
+	gtk_paint_arrow (widget->style, window, state, 
+			 GTK_SHADOW_OUT, NULL, widget, "calendar",
+			 GTK_ARROW_LEFT, TRUE, 
+			 width/2 - 3, height/2 - 4, 8, 8);
+      else 
+	gtk_paint_arrow (widget->style, window, state, 
+			 GTK_SHADOW_OUT, NULL, widget, "calendar",
+			 GTK_ARROW_RIGHT, TRUE, 
+			 width/2 - 4, height/2 - 4, 8, 8);
+    }
+}
+
+static gboolean
+glom_gtk_calendar_expose (GtkWidget	    *widget,
+		     GdkEventExpose *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  int i;
+
+  if (GTK_WIDGET_DRAWABLE (widget))
+    {
+      if (event->window == priv->main_win)
+	calendar_paint_main (calendar);
+      
+      if (event->window == priv->header_win)
+	calendar_paint_header (calendar);
+
+      for (i = 0; i < 4; i++)
+	if (event->window == priv->arrow_win[i])
+	  calendar_paint_arrow (calendar, i);
+      
+      if (event->window == priv->day_name_win)
+	calendar_paint_day_names (calendar);
+      
+      if (event->window == priv->week_win)
+	calendar_paint_week_numbers (calendar);
+      if (event->window == widget->window)
+	{
+	  gtk_paint_shadow (widget->style, widget->window, GTK_WIDGET_STATE (widget),
+			    GTK_SHADOW_IN, NULL, widget, "calendar",
+			    0, 0, widget->allocation.width, widget->allocation.height);
+	}
+    }
+  
+  return FALSE;
+}
+
+
+/****************************************
+ *           Mouse handling             *
+ ****************************************/
+
+static void
+calendar_arrow_action (GlomGtkCalendar *calendar,
+		       guint        arrow)
+{
+  switch (arrow)
+    {
+    case ARROW_YEAR_LEFT:
+      calendar_set_year_prev (calendar);
+      break;
+    case ARROW_YEAR_RIGHT:
+      calendar_set_year_next (calendar);
+      break;
+    case ARROW_MONTH_LEFT:
+      calendar_set_month_prev (calendar);
+      break;
+    case ARROW_MONTH_RIGHT:
+      calendar_set_month_next (calendar);
+      break;
+    default:;
+      /* do nothing */
+    }
+}
+
+static gboolean
+calendar_timer (gpointer data)
+{
+  GlomGtkCalendar *calendar = data;
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  gboolean retval = FALSE;
+  
+  if (priv->timer)
+    {
+      calendar_arrow_action (calendar, priv->click_child);
+
+      if (priv->need_timer)
+	{
+          GtkSettings *settings;
+          guint        timeout;
+
+          settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
+          g_object_get (settings, "gtk-timeout-repeat", &timeout, NULL);
+
+	  priv->need_timer = FALSE;
+	  priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
+					    timeout * SCROLL_DELAY_FACTOR,
+					    (GSourceFunc) calendar_timer,
+					    (gpointer) calendar, NULL);
+	}
+      else 
+	retval = TRUE;
+    }
+
+  return retval;
+}
+
+static void
+calendar_start_spinning (GlomGtkCalendar *calendar,
+			 gint         click_child)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  priv->click_child = click_child;
+  
+  if (!priv->timer)
+    {
+      GtkSettings *settings;
+      guint        timeout;
+
+      settings = gtk_widget_get_settings (GTK_WIDGET (calendar));
+      g_object_get (settings, "gtk-timeout-initial", &timeout, NULL);
+
+      priv->need_timer = TRUE;
+      priv->timer = gdk_threads_add_timeout_full (G_PRIORITY_DEFAULT_IDLE,
+					timeout,
+					(GSourceFunc) calendar_timer,
+					(gpointer) calendar, NULL);
+    }
+}
+
+static void
+calendar_stop_spinning (GlomGtkCalendar *calendar)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (priv->timer)
+    {
+      g_source_remove (priv->timer);
+      priv->timer = 0;
+      priv->need_timer = FALSE;
+    }
+}
+
+static void
+calendar_main_button_press (GlomGtkCalendar	   *calendar,
+			    GdkEventButton *event)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  gint x, y;
+  gint row, col;
+  gint day_month;
+  gint day;
+  
+  x = (gint) (event->x);
+  y = (gint) (event->y);
+  
+  row = calendar_row_from_y (calendar, y);
+  col = calendar_column_from_x (calendar, x);
+
+  /* If row or column isn't found, just return. */
+  if (row == -1 || col == -1)
+    return;
+  
+  day_month = calendar->day_month[row][col];
+
+  if (event->type == GDK_BUTTON_PRESS)
+    {
+      day = calendar->day[row][col];
+      
+      if (day_month == MONTH_PREV)
+	calendar_set_month_prev (calendar);
+      else if (day_month == MONTH_NEXT)
+	calendar_set_month_next (calendar);
+      
+      if (!GTK_WIDGET_HAS_FOCUS (widget))
+	gtk_widget_grab_focus (widget);
+	  
+      if (event->button == 1) 
+	{
+	  priv->in_drag = 1;
+	  priv->drag_start_x = x;
+	  priv->drag_start_y = y;
+	}
+
+      calendar_select_and_focus_day (calendar, day);
+    }
+  else if (event->type == GDK_2BUTTON_PRESS)
+    {
+      priv->in_drag = 0;
+      if (day_month == MONTH_CURRENT)
+	g_signal_emit (calendar,
+		       glom_gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL],
+		       0);
+    }
+}
+
+static gboolean
+glom_gtk_calendar_button_press (GtkWidget	  *widget,
+			   GdkEventButton *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint arrow = -1;
+  
+  if (event->window == priv->main_win)
+    calendar_main_button_press (calendar, event);
+
+  if (!GTK_WIDGET_HAS_FOCUS (widget))
+    gtk_widget_grab_focus (widget);
+
+  for (arrow = ARROW_YEAR_LEFT; arrow <= ARROW_MONTH_RIGHT; arrow++)
+    {
+      if (event->window == priv->arrow_win[arrow])
+	{
+	  
+	  /* only call the action on single click, not double */
+	  if (event->type == GDK_BUTTON_PRESS)
+	    {
+	      if (event->button == 1)
+		calendar_start_spinning (calendar, arrow);
+
+	      calendar_arrow_action (calendar, arrow);	      
+	    }
+
+	  return TRUE;
+	}
+    }
+
+  return FALSE;
+}
+
+static gboolean
+glom_gtk_calendar_button_release (GtkWidget	  *widget,
+			     GdkEventButton *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+
+  if (event->button == 1) 
+    {
+      calendar_stop_spinning (calendar);
+
+      if (priv->in_drag)
+	priv->in_drag = 0;
+    }
+
+  return TRUE;
+}
+
+static gboolean
+glom_gtk_calendar_motion_notify (GtkWidget	   *widget,
+			    GdkEventMotion *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint event_x, event_y;
+  gint row, col;
+  gint old_row, old_col;
+  
+  event_x = (gint) (event->x);
+  event_y = (gint) (event->y);
+  
+  if (event->window == priv->main_win)
+    {
+      
+      if (priv->in_drag) 
+	{
+	  if (gtk_drag_check_threshold (widget,
+					priv->drag_start_x, priv->drag_start_y,
+					event->x, event->y))
+	    {
+	      GdkDragContext *context;
+	      GtkTargetList *target_list = gtk_target_list_new (NULL, 0);
+	      gtk_target_list_add_text_targets (target_list, 0);
+	      context = gtk_drag_begin (widget, target_list, GDK_ACTION_COPY,
+					1, (GdkEvent *)event);
+
+	  
+	      priv->in_drag = 0;
+	      
+	      gtk_target_list_unref (target_list);
+	      gtk_drag_set_icon_default (context);
+	    }
+	}
+      else 
+	{
+	  row = calendar_row_from_y (calendar, event_y);
+	  col = calendar_column_from_x (calendar, event_x);
+	  
+	  if (row != calendar->highlight_row || calendar->highlight_col != col)
+	    {
+	      old_row = calendar->highlight_row;
+	      old_col = calendar->highlight_col;
+	      if (old_row > -1 && old_col > -1)
+		{
+		  calendar->highlight_row = -1;
+		  calendar->highlight_col = -1;
+		  calendar_invalidate_day (calendar, old_row, old_col);
+		}
+	      
+	      calendar->highlight_row = row;
+	      calendar->highlight_col = col;
+	      
+	      if (row > -1 && col > -1)
+		calendar_invalidate_day (calendar, row, col);
+	    }
+	}
+    }
+  return TRUE;
+}
+
+static gboolean
+glom_gtk_calendar_enter_notify (GtkWidget	    *widget,
+			   GdkEventCrossing *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  
+  if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
+    {
+      priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_PRELIGHT;
+      calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
+    {
+      priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_PRELIGHT;
+      calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
+    {
+      priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_PRELIGHT;
+      calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
+    {
+      priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_PRELIGHT;
+      calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
+    }
+  
+  return TRUE;
+}
+
+static gboolean
+glom_gtk_calendar_leave_notify (GtkWidget	    *widget,
+			   GdkEventCrossing *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint row;
+  gint col;
+  
+  if (event->window == priv->main_win)
+    {
+      row = calendar->highlight_row;
+      col = calendar->highlight_col;
+      calendar->highlight_row = -1;
+      calendar->highlight_col = -1;
+      if (row > -1 && col > -1)
+	calendar_invalidate_day (calendar, row, col);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_MONTH_LEFT])
+    {
+      priv->arrow_state[ARROW_MONTH_LEFT] = GTK_STATE_NORMAL;
+      calendar_invalidate_arrow (calendar, ARROW_MONTH_LEFT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_MONTH_RIGHT])
+    {
+      priv->arrow_state[ARROW_MONTH_RIGHT] = GTK_STATE_NORMAL;
+      calendar_invalidate_arrow (calendar, ARROW_MONTH_RIGHT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_YEAR_LEFT])
+    {
+      priv->arrow_state[ARROW_YEAR_LEFT] = GTK_STATE_NORMAL;
+      calendar_invalidate_arrow (calendar, ARROW_YEAR_LEFT);
+    }
+  
+  if (event->window == priv->arrow_win[ARROW_YEAR_RIGHT])
+    {
+      priv->arrow_state[ARROW_YEAR_RIGHT] = GTK_STATE_NORMAL;
+      calendar_invalidate_arrow (calendar, ARROW_YEAR_RIGHT);
+    }
+  
+  return TRUE;
+}
+
+static gboolean
+glom_gtk_calendar_scroll (GtkWidget      *widget,
+		     GdkEventScroll *event)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+
+  if (event->direction == GDK_SCROLL_UP) 
+    {
+      if (!GTK_WIDGET_HAS_FOCUS (widget))
+	gtk_widget_grab_focus (widget);
+      calendar_set_month_prev (calendar);
+    }
+  else if (event->direction == GDK_SCROLL_DOWN) 
+    {
+      if (!GTK_WIDGET_HAS_FOCUS (widget))
+	gtk_widget_grab_focus (widget);
+      calendar_set_month_next (calendar);
+    }
+  else
+    return FALSE;
+
+  return TRUE;
+}
+
+
+/****************************************
+ *             Key handling              *
+ ****************************************/
+
+static void 
+move_focus (GlomGtkCalendar *calendar, 
+	    gint         direction)
+{
+  GtkTextDirection text_dir = gtk_widget_get_direction (GTK_WIDGET (calendar));
+ 
+  if ((text_dir == GTK_TEXT_DIR_LTR && direction == -1) ||
+      (text_dir == GTK_TEXT_DIR_RTL && direction == 1)) 
+    {
+      if (calendar->focus_col > 0)
+	  calendar->focus_col--;
+      else if (calendar->focus_row > 0)
+	{
+	  calendar->focus_col = 6;
+	  calendar->focus_row--;
+	}
+
+      if (calendar->focus_col < 0)
+        calendar->focus_col = 6;
+      if (calendar->focus_row < 0)
+        calendar->focus_row = 5;
+    }
+  else 
+    {
+      if (calendar->focus_col < 6)
+	calendar->focus_col++;
+      else if (calendar->focus_row < 5)
+	{
+	  calendar->focus_col = 0;
+	  calendar->focus_row++;
+	}
+
+      if (calendar->focus_col < 0)
+        calendar->focus_col = 0;
+      if (calendar->focus_row < 0)
+        calendar->focus_row = 0;
+    }
+}
+
+static gboolean
+glom_gtk_calendar_key_press (GtkWidget   *widget,
+			GdkEventKey *event)
+{
+  GlomGtkCalendar *calendar;
+  gint return_val;
+  gint old_focus_row;
+  gint old_focus_col;
+  gint row, col, day;
+  
+  calendar = GLOM_GTK_CALENDAR (widget);
+  return_val = FALSE;
+  
+  old_focus_row = calendar->focus_row;
+  old_focus_col = calendar->focus_col;
+
+  switch (event->keyval)
+    {
+    case GDK_KP_Left:
+    case GDK_Left:
+      return_val = TRUE;
+      if (event->state & GDK_CONTROL_MASK)
+	calendar_set_month_prev (calendar);
+      else
+	{
+	  move_focus (calendar, -1);
+	  calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+	  calendar_invalidate_day (calendar, calendar->focus_row,
+				   calendar->focus_col);
+	}
+      break;
+    case GDK_KP_Right:
+    case GDK_Right:
+      return_val = TRUE;
+      if (event->state & GDK_CONTROL_MASK)
+	calendar_set_month_next (calendar);
+      else
+	{
+	  move_focus (calendar, 1);
+	  calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+	  calendar_invalidate_day (calendar, calendar->focus_row,
+				   calendar->focus_col);
+	}
+      break;
+    case GDK_KP_Up:
+    case GDK_Up:
+      return_val = TRUE;
+      if (event->state & GDK_CONTROL_MASK)
+	calendar_set_year_prev (calendar);
+      else
+	{
+	  if (calendar->focus_row > 0)
+	    calendar->focus_row--;
+          if (calendar->focus_row < 0)
+            calendar->focus_row = 5;
+          if (calendar->focus_col < 0)
+            calendar->focus_col = 6;
+	  calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+	  calendar_invalidate_day (calendar, calendar->focus_row,
+				   calendar->focus_col);
+	}
+      break;
+    case GDK_KP_Down:
+    case GDK_Down:
+      return_val = TRUE;
+      if (event->state & GDK_CONTROL_MASK)
+	calendar_set_year_next (calendar);
+      else
+	{
+	  if (calendar->focus_row < 5)
+	    calendar->focus_row++;
+          if (calendar->focus_col < 0)
+            calendar->focus_col = 0;
+	  calendar_invalidate_day (calendar, old_focus_row, old_focus_col);
+	  calendar_invalidate_day (calendar, calendar->focus_row,
+				   calendar->focus_col);
+	}
+      break;
+    case GDK_KP_Space:
+    case GDK_space:
+      row = calendar->focus_row;
+      col = calendar->focus_col;
+      
+      if (row > -1 && col > -1)
+	{
+	  return_val = TRUE;
+
+          day = calendar->day[row][col];
+	  if (calendar->day_month[row][col] == MONTH_PREV)
+	    calendar_set_month_prev (calendar);
+	  else if (calendar->day_month[row][col] == MONTH_NEXT)
+	    calendar_set_month_next (calendar);
+
+	  calendar_select_and_focus_day (calendar, day);
+	}
+    }	
+  
+  return return_val;
+}
+
+
+/****************************************
+ *           Misc widget methods        *
+ ****************************************/
+
+static void
+calendar_set_background (GtkWidget *widget)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  gint i;
+  
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      for (i = 0; i < 4; i++)
+	{
+	  if (priv->arrow_win[i])
+	    gdk_window_set_background (priv->arrow_win[i], 
+				       HEADER_BG_COLOR (widget));
+	}
+      if (priv->header_win)
+	gdk_window_set_background (priv->header_win, 
+				   HEADER_BG_COLOR (widget));
+      if (priv->day_name_win)
+	gdk_window_set_background (priv->day_name_win, 
+				   BACKGROUND_COLOR (widget));
+      if (priv->week_win)
+	gdk_window_set_background (priv->week_win,
+				   BACKGROUND_COLOR (widget));
+      if (priv->main_win)
+	gdk_window_set_background (priv->main_win,
+				   BACKGROUND_COLOR (widget));
+      if (widget->window)
+	gdk_window_set_background (widget->window,
+				   BACKGROUND_COLOR (widget)); 
+    }
+}
+
+static void
+glom_gtk_calendar_style_set (GtkWidget *widget,
+			GtkStyle  *previous_style)
+{
+  if (previous_style && GTK_WIDGET_REALIZED (widget))
+    calendar_set_background (widget);
+}
+
+static void
+glom_gtk_calendar_state_changed (GtkWidget	   *widget,
+			    GtkStateType    previous_state)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  int i;
+  
+  if (!GTK_WIDGET_IS_SENSITIVE (widget))
+    {
+      priv->in_drag = 0;
+      calendar_stop_spinning (calendar);    
+    }
+
+  for (i = 0; i < 4; i++)
+    if (GTK_WIDGET_IS_SENSITIVE (widget))
+      priv->arrow_state[i] = GTK_STATE_NORMAL;
+    else 
+      priv->arrow_state[i] = GTK_STATE_INSENSITIVE;
+  
+  calendar_set_background (widget);
+}
+
+static void
+glom_gtk_calendar_grab_notify (GtkWidget *widget,
+			  gboolean   was_grabbed)
+{
+  if (!was_grabbed)
+    calendar_stop_spinning (GLOM_GTK_CALENDAR (widget));
+}
+
+static gboolean
+glom_gtk_calendar_focus_out (GtkWidget     *widget,
+			GdkEventFocus *event)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+
+  calendar_queue_refresh (calendar);
+  calendar_stop_spinning (calendar);
+  
+  priv->in_drag = 0; 
+
+  return FALSE;
+}
+
+
+/****************************************
+ *          Drag and Drop               *
+ ****************************************/
+
+static void
+glom_gtk_calendar_drag_data_get (GtkWidget        *widget,
+			    GdkDragContext   *context,
+			    GtkSelectionData *selection_data,
+			    guint             info,
+			    guint             time)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  GDate *date;
+  gchar str[128];
+  gsize len;
+
+  date = g_date_new_dmy (calendar->selected_day, calendar->month + 1, calendar->year);
+  len = g_date_strftime (str, 127, "%x", date);
+  gtk_selection_data_set_text (selection_data, str, len);
+  
+  g_free (date);
+}
+
+/* Get/set whether drag_motion requested the drag data and
+ * drag_data_received should thus not actually insert the data,
+ * since the data doesn't result from a drop.
+ */
+static void
+set_status_pending (GdkDragContext *context,
+                    GdkDragAction   suggested_action)
+{
+  g_object_set_data (G_OBJECT (context),
+                     I_("gtk-calendar-status-pending"),
+                     GINT_TO_POINTER (suggested_action));
+}
+
+static GdkDragAction
+get_status_pending (GdkDragContext *context)
+{
+  return GPOINTER_TO_INT (g_object_get_data (G_OBJECT (context),
+                                             "gtk-calendar-status-pending"));
+}
+
+static void
+glom_gtk_calendar_drag_leave (GtkWidget      *widget,
+			 GdkDragContext *context,
+			 guint           time)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+
+  priv->drag_highlight = 0;
+  gtk_drag_unhighlight (widget);
+  
+}
+
+static gboolean
+glom_gtk_calendar_drag_motion (GtkWidget      *widget,
+			  GdkDragContext *context,
+			  gint            x,
+			  gint            y,
+			  guint           time)
+{
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (widget);
+  GdkAtom target;
+  
+  if (!priv->drag_highlight) 
+    {
+      priv->drag_highlight = 1;
+      gtk_drag_highlight (widget);
+    }
+  
+  target = gtk_drag_dest_find_target (widget, context, NULL);
+  if (target == GDK_NONE || context->suggested_action == 0)
+    gdk_drag_status (context, 0, time);
+  else
+    {
+      set_status_pending (context, context->suggested_action);
+      gtk_drag_get_data (widget, context, target, time);
+    }
+  
+  return TRUE;
+}
+
+static gboolean
+glom_gtk_calendar_drag_drop (GtkWidget      *widget,
+			GdkDragContext *context,
+			gint            x,
+			gint            y,
+			guint           time)
+{
+  GdkAtom target;
+
+  target = gtk_drag_dest_find_target (widget, context, NULL);  
+  if (target != GDK_NONE)
+    {
+      gtk_drag_get_data (widget, context, 
+			 target, 
+			 time);
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+static void
+glom_gtk_calendar_drag_data_received (GtkWidget        *widget,
+				 GdkDragContext   *context,
+				 gint              x,
+				 gint              y,
+				 GtkSelectionData *selection_data,
+				 guint             info,
+				 guint             time)
+{
+  GlomGtkCalendar *calendar = GLOM_GTK_CALENDAR (widget);
+  guint day, month, year;
+  gchar *str;
+  GDate *date;
+  GdkDragAction suggested_action;
+
+  suggested_action = get_status_pending (context);
+
+  if (suggested_action) 
+    {
+      set_status_pending (context, 0);
+     
+      /* We are getting this data due to a request in drag_motion,
+       * rather than due to a request in drag_drop, so we are just
+       * supposed to call drag_status, not actually paste in the
+       * data.
+       */
+      str = (gchar*) gtk_selection_data_get_text (selection_data);
+
+      if (str) 
+	{
+	  date = g_date_new ();
+	  g_date_set_parse (date, str);
+	  if (!g_date_valid (date)) 
+	      suggested_action = 0;
+	  g_date_free (date);
+	  g_free (str);
+	}
+      else
+	suggested_action = 0;
+
+      gdk_drag_status (context, suggested_action, time);
+
+      return;
+    }
+
+  date = g_date_new ();
+  str = (gchar*) gtk_selection_data_get_text (selection_data);
+  if (str) 
+    {
+      g_date_set_parse (date, str);
+      g_free (str);
+    }
+  
+  if (!g_date_valid (date)) 
+    {
+      g_warning ("Received invalid date data\n");
+      g_date_free (date);	
+      gtk_drag_finish (context, FALSE, FALSE, time);
+      return;
+    }
+
+  day = g_date_get_day (date);
+  month = g_date_get_month (date);
+  year = g_date_get_year (date);
+  g_date_free (date);	
+
+  gtk_drag_finish (context, TRUE, FALSE, time);
+
+  
+  g_object_freeze_notify (G_OBJECT (calendar));
+  if (!(calendar->display_flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+      && (calendar->display_flags & GLOM_GTK_CALENDAR_SHOW_HEADING))
+    glom_gtk_calendar_select_month (calendar, month - 1, year);
+  glom_gtk_calendar_select_day (calendar, day);
+  g_object_thaw_notify (G_OBJECT (calendar));  
+}
+
+
+/****************************************
+ *              Public API              *
+ ****************************************/
+
+/**
+ * glom_gtk_calendar_new:
+ * 
+ * Creates a new calendar, with the current date being selected. 
+ * 
+ * Return value: a newly #GlomGtkCalendar widget
+ **/
+GtkWidget*
+glom_gtk_calendar_new (void)
+{
+  return g_object_new (GTK_TYPE_CALENDAR, NULL);
+}
+
+/**
+ * glom_gtk_calendar_display_options:
+ * @calendar: a #GlomGtkCalendar.
+ * @flags: the display options to set.
+ *
+ * Sets display options (whether to display the heading and the month headings).
+ * 
+ * Deprecated: 2.4: Use glom_gtk_calendar_set_display_options() instead
+ **/
+void
+glom_gtk_calendar_display_options (GlomGtkCalendar	       *calendar,
+			      GlomGtkCalendarDisplayOptions flags)
+{
+  glom_gtk_calendar_set_display_options (calendar, flags);
+}
+
+/**
+ * glom_gtk_calendar_get_display_options:
+ * @calendar: a #GlomGtkCalendar
+ * 
+ * Returns the current display options of @calendar. 
+ * 
+ * Return value: the display options.
+ *
+ * Since: 2.4
+ **/
+GlomGtkCalendarDisplayOptions 
+glom_gtk_calendar_get_display_options (GlomGtkCalendar         *calendar)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), 0);
+
+  return calendar->display_flags;
+}
+
+/**
+ * glom_gtk_calendar_set_display_options:
+ * @calendar: a #GlomGtkCalendar
+ * @flags: the display options to set
+ * 
+ * Sets display options (whether to display the heading and the month  
+ * headings).
+ *
+ * Since: 2.4
+ **/
+void
+glom_gtk_calendar_set_display_options (GlomGtkCalendar	       *calendar,
+				  GlomGtkCalendarDisplayOptions flags)
+{
+  GtkWidget *widget = GTK_WIDGET (calendar);
+  GlomGtkCalendarPrivate *priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+  gint resize = 0;
+  gint i;
+  GlomGtkCalendarDisplayOptions old_flags;
+  
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+  
+  old_flags = calendar->display_flags;
+  
+  if (GTK_WIDGET_REALIZED (widget))
+    {
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+	{
+	  resize ++;
+	  if (! (flags & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+	      && (priv->header_win))
+	    {
+	      calendar->display_flags &= ~GLOM_GTK_CALENDAR_NO_MONTH_CHANGE;
+	      calendar_realize_arrows (calendar);
+	    }
+	  else
+	    {
+	      for (i = 0; i < 4; i++)
+		{
+		  if (priv->arrow_win[i])
+		    {
+		      gdk_window_set_user_data (priv->arrow_win[i], 
+						NULL);
+		      gdk_window_destroy (priv->arrow_win[i]);
+		      priv->arrow_win[i] = NULL;
+		    }
+		}
+	    }
+	}
+      
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_HEADING)
+	{
+	  resize++;
+	  
+	  if (flags & GLOM_GTK_CALENDAR_SHOW_HEADING)
+	    {
+	      calendar->display_flags |= GLOM_GTK_CALENDAR_SHOW_HEADING;
+	      calendar_realize_header (calendar);
+	    }
+	  else
+	    {
+	      for (i = 0; i < 4; i++)
+		{
+		  if (priv->arrow_win[i])
+		    {
+		      gdk_window_set_user_data (priv->arrow_win[i], 
+						NULL);
+		      gdk_window_destroy (priv->arrow_win[i]);
+		      priv->arrow_win[i] = NULL;
+		    }
+		}
+	      gdk_window_set_user_data (priv->header_win, NULL);
+	      gdk_window_destroy (priv->header_win);
+	      priv->header_win = NULL;
+	    }
+	}
+      
+      
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+	{
+	  resize++;
+	  
+	  if (flags & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+	    {
+	      calendar->display_flags |= GLOM_GTK_CALENDAR_SHOW_DAY_NAMES;
+	      calendar_realize_day_names (calendar);
+	    }
+	  else
+	    {
+	      gdk_window_set_user_data (priv->day_name_win, NULL);
+	      gdk_window_destroy (priv->day_name_win);
+	      priv->day_name_win = NULL;
+	    }
+	}
+      
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+	{
+	  resize++;
+	  
+	  if (flags & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+	    {
+	      calendar->display_flags |= GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS;
+	      calendar_realize_week_numbers (calendar);
+	    }
+	  else
+	    {
+	      gdk_window_set_user_data (priv->week_win, NULL);
+	      gdk_window_destroy (priv->week_win);
+	      priv->week_win = NULL;
+	    }
+	}
+
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_WEEK_START_MONDAY)
+	g_warning ("GLOM_GTK_CALENDAR_WEEK_START_MONDAY is ignored; the first day of the week is determined from the locale");
+      
+      if ((flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_DETAILS)
+        resize++;
+
+      calendar->display_flags = flags;
+      if (resize)
+	gtk_widget_queue_resize (GTK_WIDGET (calendar));
+      
+    } 
+  else
+    calendar->display_flags = flags;
+  
+  g_object_freeze_notify (G_OBJECT (calendar));
+  if ((old_flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_HEADING)
+    g_object_notify (G_OBJECT (calendar), "show-heading");
+  if ((old_flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_DAY_NAMES)
+    g_object_notify (G_OBJECT (calendar), "show-day-names");
+  if ((old_flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_NO_MONTH_CHANGE)
+    g_object_notify (G_OBJECT (calendar), "no-month-change");
+  if ((old_flags ^ calendar->display_flags) & GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS)
+    g_object_notify (G_OBJECT (calendar), "show-week-numbers");
+  g_object_thaw_notify (G_OBJECT (calendar));
+}
+
+/**
+ * glom_gtk_calendar_select_month:
+ * @calendar: a #GlomGtkCalendar
+ * @month: a month number between 0 and 11.
+ * @year: the year the month is in.
+ * 
+ * Shifts the calendar to a different month.
+ * 
+ * Return value: %TRUE, always
+ **/
+gboolean
+glom_gtk_calendar_select_month (GlomGtkCalendar *calendar,
+			   guint	month,
+			   guint	year)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), FALSE);
+  g_return_val_if_fail (month <= 11, FALSE);
+  
+  calendar->month = month;
+  calendar->year  = year;
+  
+  calendar_compute_days (calendar);
+  calendar_queue_refresh (calendar);
+
+  g_object_freeze_notify (G_OBJECT (calendar));
+  g_object_notify (G_OBJECT (calendar), "month");
+  g_object_notify (G_OBJECT (calendar), "year");
+  g_object_thaw_notify (G_OBJECT (calendar));
+
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[MONTH_CHANGED_SIGNAL],
+		 0);
+  return TRUE;
+}
+
+/**
+ * glom_gtk_calendar_select_day:
+ * @calendar: a #GlomGtkCalendar.
+ * @day: the day number between 1 and 31, or 0 to unselect 
+ *   the currently selected day.
+ * 
+ * Selects a day from the current month.
+ **/
+void
+glom_gtk_calendar_select_day (GlomGtkCalendar *calendar,
+			 guint	      day)
+{
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+  g_return_if_fail (day <= 31);
+  
+  /* Deselect the old day */
+  if (calendar->selected_day > 0)
+    {
+      gint selected_day;
+      
+      selected_day = calendar->selected_day;
+      calendar->selected_day = 0;
+      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
+	calendar_invalidate_day_num (calendar, selected_day);
+    }
+  
+  calendar->selected_day = day;
+  
+  /* Select the new day */
+  if (day != 0)
+    {
+      if (GTK_WIDGET_DRAWABLE (GTK_WIDGET (calendar)))
+	calendar_invalidate_day_num (calendar, day);
+    }
+  
+  g_object_notify (G_OBJECT (calendar), "day");
+
+  g_signal_emit (calendar,
+		 glom_gtk_calendar_signals[DAY_SELECTED_SIGNAL],
+		 0);
+}
+
+/**
+ * glom_gtk_calendar_clear_marks:
+ * @calendar: a #GlomGtkCalendar
+ * 
+ * Remove all visual markers.
+ **/
+void
+glom_gtk_calendar_clear_marks (GlomGtkCalendar *calendar)
+{
+  guint day;
+  
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+  
+  for (day = 0; day < 31; day++)
+    {
+      calendar->marked_date[day] = FALSE;
+    }
+
+  calendar->num_marked_dates = 0;
+  calendar_queue_refresh (calendar);
+}
+
+/**
+ * glom_gtk_calendar_mark_day:
+ * @calendar: a #GlomGtkCalendar 
+ * @day: the day number to mark between 1 and 31.
+ * 
+ * Places a visual marker on a particular day.
+ * 
+ * Return value: %TRUE, always
+ **/
+gboolean
+glom_gtk_calendar_mark_day (GlomGtkCalendar *calendar,
+		       guint	    day)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), FALSE);
+  
+  if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == FALSE)
+    {
+      calendar->marked_date[day - 1] = TRUE;
+      calendar->num_marked_dates++;
+      calendar_invalidate_day_num (calendar, day);
+    }
+  
+  return TRUE;
+}
+
+/**
+ * glom_gtk_calendar_unmark_day:
+ * @calendar: a #GlomGtkCalendar.
+ * @day: the day number to unmark between 1 and 31.
+ * 
+ * Removes the visual marker from a particular day.
+ * 
+ * Return value: %TRUE, always
+ **/
+gboolean
+glom_gtk_calendar_unmark_day (GlomGtkCalendar *calendar,
+			 guint	      day)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), FALSE);
+  
+  if (day >= 1 && day <= 31 && calendar->marked_date[day-1] == TRUE)
+    {
+      calendar->marked_date[day - 1] = FALSE;
+      calendar->num_marked_dates--;
+      calendar_invalidate_day_num (calendar, day);
+    }
+  
+  return TRUE;
+}
+
+/**
+ * glom_gtk_calendar_get_date:
+ * @calendar: a #GlomGtkCalendar
+ * @year: location to store the year number, or %NULL
+ * @month: location to store the month number (between 0 and 11), or %NULL
+ * @day: location to store the day number (between 1 and 31), or %NULL
+ * 
+ * Obtains the selected date from a #GlomGtkCalendar.
+ **/
+void
+glom_gtk_calendar_get_date (GlomGtkCalendar *calendar,
+		       guint	   *year,
+		       guint	   *month,
+		       guint	   *day)
+{
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+  
+  if (year)
+    *year = calendar->year;
+  
+  if (month)
+    *month = calendar->month;
+  
+  if (day)
+    *day = calendar->selected_day;
+}
+
+/**
+ * glom_gtk_calendar_set_detail_func:
+ * @calendar: a #GlomGtkCalendar.
+ * @func: a function providing details for each day.
+ * @data: data to pass to @func invokations.
+ * @destroy: a function for releasing @data.
+ *
+ * Installs a function which provides Pango markup with detail information
+ * for each day. Examples for such details are holidays or appointments. That
+ * information is shown below each day when #GlomGtkCalendar:show-details is set.
+ * A tooltip containing with full detail information is provided, if the entire
+ * text should not fit into the details area, or if #GlomGtkCalendar:show-details
+ * is not set.
+ *
+ * The size of the details area can be restricted by setting the
+ * #GlomGtkCalendar:detail-width-chars and #GlomGtkCalendar:detail-height-rows
+ * properties.
+ *
+ * Since: 2.16
+ */
+void
+glom_gtk_calendar_set_detail_func (GlomGtkCalendar           *calendar,
+                              GlomGtkCalendarDetailFunc  func,
+                              gpointer               data,
+                              GDestroyNotify         destroy)
+{
+  GlomGtkCalendarPrivate *priv;
+
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+
+  priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (priv->detail_func_destroy)
+    priv->detail_func_destroy (priv->detail_func_user_data);
+
+  priv->detail_func = func;
+  priv->detail_func_user_data = data;
+  priv->detail_func_destroy = destroy;
+
+  gtk_widget_set_has_tooltip (GTK_WIDGET (calendar),
+                              NULL != priv->detail_func);
+  gtk_widget_queue_resize (GTK_WIDGET (calendar));
+}
+
+/**
+ * glom_gtk_calendar_set_detail_width_chars:
+ * @calendar: a #GlomGtkCalendar.
+ * @chars: detail width in characters.
+ *
+ * Updates the width of detail cells.
+ * See #GlomGtkCalendar:detail-width-chars.
+ *
+ * Since: 2.16
+ */
+void
+glom_gtk_calendar_set_detail_width_chars (GlomGtkCalendar *calendar,
+                                     gint         chars)
+{
+  GlomGtkCalendarPrivate *priv;
+
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+
+  priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (chars != priv->detail_width_chars)
+    {
+      priv->detail_width_chars = chars;
+      g_object_notify (G_OBJECT (calendar), "detail-width-chars");
+      gtk_widget_queue_resize_no_redraw (GTK_WIDGET (calendar));
+    }
+}
+
+/**
+ * glom_gtk_calendar_set_detail_height_rows:
+ * @calendar: a #GlomGtkCalendar.
+ * @rows: detail height in rows.
+ *
+ * Updates the height of detail cells.
+ * See #GlomGtkCalendar:detail-height-rows.
+ *
+ * Since: 2.16
+ */
+void
+glom_gtk_calendar_set_detail_height_rows (GlomGtkCalendar *calendar,
+                                     gint         rows)
+{
+  GlomGtkCalendarPrivate *priv;
+
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+
+  priv = GLOM_GTK_CALENDAR_GET_PRIVATE (calendar);
+
+  if (rows != priv->detail_height_rows)
+    {
+      priv->detail_height_rows = rows;
+      g_object_notify (G_OBJECT (calendar), "detail-height-rows");
+      gtk_widget_queue_resize_no_redraw (GTK_WIDGET (calendar));
+    }
+}
+
+/**
+ * glom_gtk_calendar_get_detail_width_chars:
+ * @calendar: a #GlomGtkCalendar.
+ *
+ * Queries the width of detail cells, in characters.
+ * See #GlomGtkCalendar:detail-width-chars.
+ *
+ * Since: 2.16
+ *
+ * Return value: The width of detail cells, in characters.
+ */
+gint
+glom_gtk_calendar_get_detail_width_chars (GlomGtkCalendar *calendar)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), 0);
+  return GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->detail_width_chars;
+}
+
+/**
+ * glom_gtk_calendar_get_detail_height_rows:
+ * @calendar: a #GlomGtkCalendar.
+ *
+ * Queries the height of detail cells, in rows.
+ * See #GlomGtkCalendar:detail-width-chars.
+ *
+ * Since: 2.16
+ *
+ * Return value: The height of detail cells, in rows.
+ */
+gint
+glom_gtk_calendar_get_detail_height_rows (GlomGtkCalendar *calendar)
+{
+  g_return_val_if_fail (GLOM_GTK_IS_CALENDAR (calendar), 0);
+  return GLOM_GTK_CALENDAR_GET_PRIVATE (calendar)->detail_height_rows;
+}
+
+/**
+ * glom_gtk_calendar_freeze:
+ * @calendar: a #GlomGtkCalendar
+ * 
+ * Does nothing. Previously locked the display of the calendar until
+ * it was thawed with glom_gtk_calendar_thaw().
+ *
+ * Deprecated: 2.8: 
+ **/
+void
+glom_gtk_calendar_freeze (GlomGtkCalendar *calendar)
+{
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+}
+
+/**
+ * glom_gtk_calendar_thaw:
+ * @calendar: a #GlomGtkCalendar
+ * 
+ * Does nothing. Previously defrosted a calendar; all the changes made
+ * since the last glom_gtk_calendar_freeze() were displayed.
+ *
+ * Deprecated: 2.8: 
+ **/
+void
+glom_gtk_calendar_thaw (GlomGtkCalendar *calendar)
+{
+  g_return_if_fail (GLOM_GTK_IS_CALENDAR (calendar));
+}
+
+#endif //!GTK_CHECK_VERSION(2,16,0)

Added: trunk/glom/utility_widgets/calendar/glomgtkcalendar.h
==============================================================================
--- (empty file)
+++ trunk/glom/utility_widgets/calendar/glomgtkcalendar.h	Fri Jan 18 13:47:20 2008
@@ -0,0 +1,215 @@
+/* This is copied from GTK+ 2.15/16 so we can use new API without waiting 
+ * for stable release of GTK+ 2.16. Life would be easier if GTK+ followed 
+ * the GNOME release schedule.
+ */
+#include <gtk/gtkcalendar.h>
+#if GTK_CHECK_VERSION(2,16,0)
+typedef GlomGlomGtkCalendar GlomGlomGtkCalendar; 
+#else
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * GTK Calendar Widget
+ * Copyright (C) 1998 Cesar Miquel and Shawn T. Amundson
+ *
+ * This library 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) any later version.
+ *
+ * This library 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 this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
+ * file for a list of people on the GTK+ Team.  See the ChangeLog
+ * files for a list of changes.  These files are distributed with
+ * GTK+ at ftp://ftp.gtk.org/pub/gtk/. 
+ */
+
+#ifndef __GLOM_GTK_CALENDAR_H__
+#define __GLOM_GTK_CALENDAR_H__
+
+#include <gdk/gdk.h>
+#include <gtk/gtkwidget.h>
+
+/* Not needed, retained for compatibility -Yosh */
+#include <gtk/gtksignal.h>
+
+
+G_BEGIN_DECLS
+
+#define GLOM_GTK_TYPE_CALENDAR                  (glom_gtk_calendar_get_type ())
+#define GLOM_GTK_CALENDAR(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GLOM_GTK_TYPE_CALENDAR, GlomGtkCalendar))
+#define GLOM_GTK_CALENDAR_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GLOM_GTK_TYPE_CALENDAR, GlomGtkCalendarClass))
+#define GLOM_GTK_IS_CALENDAR(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GLOM_GTK_TYPE_CALENDAR))
+#define GLOM_GTK_IS_CALENDAR_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GLOM_GTK_TYPE_CALENDAR))
+#define GLOM_GTK_CALENDAR_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GLOM_GTK_TYPE_CALENDAR, GlomGtkCalendarClass))
+
+
+typedef struct _GlomGtkCalendar	       GlomGtkCalendar;
+typedef struct _GlomGtkCalendarClass       GlomGtkCalendarClass;
+
+typedef struct _GlomGtkCalendarPrivate     GlomGtkCalendarPrivate;
+
+/**
+ * GlomGtkCalendarDisplayOptions:
+ * @GLOM_GTK_CALENDAR_SHOW_HEADING: Specifies that the month and year should be displayed.
+ * @GLOM_GTK_CALENDAR_SHOW_DAY_NAMES: Specifies that three letter day descriptions should be present.
+ * @GLOM_GTK_CALENDAR_NO_MONTH_CHANGE: Prevents the user from switching months with the calendar.
+ * @GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS: Displays each week numbers of the current year, down the
+ * left side of the calendar.
+ * @GLOM_GTK_CALENDAR_WEEK_START_MONDAY: Since GTK+ 2.4, this option is deprecated and ignored by GTK+.
+ * The information on which day the calendar week starts is derived from the locale.
+ * @GLOM_GTK_CALENDAR_SHOW_DETAILS: Just show an indicator, not the full details
+ * text when details are provided. See glom_gtk_calendar_set_detail_func().
+ *
+ * These options can be used to influence the display and behaviour of a #GlomGtkCalendar.
+ */
+typedef enum
+{
+  GLOM_GTK_CALENDAR_SHOW_HEADING		= 1 << 0,
+  GLOM_GTK_CALENDAR_SHOW_DAY_NAMES		= 1 << 1,
+  GLOM_GTK_CALENDAR_NO_MONTH_CHANGE		= 1 << 2,
+  GLOM_GTK_CALENDAR_SHOW_WEEK_NUMBERS	= 1 << 3,
+  GLOM_GTK_CALENDAR_WEEK_START_MONDAY	= 1 << 4,
+  GLOM_GTK_CALENDAR_SHOW_DETAILS		= 1 << 5,
+} GlomGtkCalendarDisplayOptions;
+
+/**
+ * GlomGtkCalendarDetailFunc:
+ * @calendar: a #GlomGtkCalendar.
+ * @year: the year for which details are needed.
+ * @month: the month for which details are needed.
+ * @day: the day of @month for which details are needed.
+ * @user_data: the data passed with glom_gtk_calendar_set_detail_func().
+ *
+ * This kind of functions provide Pango markup with detail information for the
+ * specified day. Examples for such details are holidays or appointments. The
+ * function returns %NULL when no information is available.
+ *
+ * Since: 2.16
+ *
+ * Return value: Newly allocated string with Pango markup with details
+ * for the specified day, or %NULL.
+ */
+typedef gchar* (*GlomGtkCalendarDetailFunc) (GlomGtkCalendar *calendar,
+                                         guint        year,
+                                         guint        month,
+                                         guint        day,
+                                         gpointer     user_data);
+
+struct _GlomGtkCalendar
+{
+  GtkWidget widget;
+  
+  GtkStyle  *header_style;
+  GtkStyle  *label_style;
+  
+  gint month;
+  gint year;
+  gint selected_day;
+  
+  gint day_month[6][7];
+  gint day[6][7];
+  
+  gint num_marked_dates;
+  gint marked_date[31];
+  GlomGtkCalendarDisplayOptions  display_flags;
+  GdkColor marked_date_color[31];
+  
+  GdkGC *gc;			/* unused */
+  GdkGC *xor_gc;		/* unused */
+
+  gint focus_row;
+  gint focus_col;
+
+  gint highlight_row;
+  gint highlight_col;
+  
+  GlomGtkCalendarPrivate *priv;
+  gchar grow_space [32];
+
+  /* Padding for future expansion */
+  void (*_gtk_reserved1) (void);
+  void (*_gtk_reserved2) (void);
+  void (*_gtk_reserved3) (void);
+  void (*_gtk_reserved4) (void);
+};
+
+struct _GlomGtkCalendarClass
+{
+  GtkWidgetClass parent_class;
+  
+  /* Signal handlers */
+  void (* month_changed)		(GlomGtkCalendar *calendar);
+  void (* day_selected)			(GlomGtkCalendar *calendar);
+  void (* day_selected_double_click)	(GlomGtkCalendar *calendar);
+  void (* prev_month)			(GlomGtkCalendar *calendar);
+  void (* next_month)			(GlomGtkCalendar *calendar);
+  void (* prev_year)			(GlomGtkCalendar *calendar);
+  void (* next_year)			(GlomGtkCalendar *calendar);
+  
+};
+
+
+GType	   glom_gtk_calendar_get_type	(void) G_GNUC_CONST;
+GtkWidget* glom_gtk_calendar_new		(void);
+
+gboolean   glom_gtk_calendar_select_month	(GlomGtkCalendar *calendar, 
+					 guint	      month,
+					 guint	      year);
+void	   glom_gtk_calendar_select_day	(GlomGtkCalendar *calendar,
+					 guint	      day);
+
+gboolean   glom_gtk_calendar_mark_day	(GlomGtkCalendar *calendar,
+					 guint	      day);
+gboolean   glom_gtk_calendar_unmark_day	(GlomGtkCalendar *calendar,
+					 guint	      day);
+void	   glom_gtk_calendar_clear_marks	(GlomGtkCalendar *calendar);
+
+
+void	   glom_gtk_calendar_set_display_options (GlomGtkCalendar    	      *calendar,
+					     GlomGtkCalendarDisplayOptions flags);
+GlomGtkCalendarDisplayOptions
+           glom_gtk_calendar_get_display_options (GlomGtkCalendar   	      *calendar);
+#ifndef GTK_DISABLE_DEPRECATED
+void	   glom_gtk_calendar_display_options (GlomGtkCalendar		  *calendar,
+					 GlomGtkCalendarDisplayOptions flags);
+#endif
+
+void	   glom_gtk_calendar_get_date	(GlomGtkCalendar *calendar, 
+					 guint	     *year,
+					 guint	     *month,
+					 guint	     *day);
+
+void       glom_gtk_calendar_set_detail_func (GlomGtkCalendar           *calendar,
+                                         GlomGtkCalendarDetailFunc  func,
+                                         gpointer               data,
+                                         GDestroyNotify         destroy);
+
+void       glom_gtk_calendar_set_detail_width_chars (GlomGtkCalendar    *calendar,
+                                                gint            chars);
+void       glom_gtk_calendar_set_detail_height_rows (GlomGtkCalendar    *calendar,
+                                                gint            rows);
+
+gint       glom_gtk_calendar_get_detail_width_chars (GlomGtkCalendar    *calendar);
+gint       glom_gtk_calendar_get_detail_height_rows (GlomGtkCalendar    *calendar);
+
+#ifndef GTK_DISABLE_DEPRECATED
+void	   glom_gtk_calendar_freeze		(GlomGtkCalendar *calendar);
+void	   glom_gtk_calendar_thaw		(GlomGtkCalendar *calendar);
+#endif
+
+G_END_DECLS
+
+#endif /* __GLOM_GTK_CALENDAR_H__ */
+
+#endif //!GTK_CHECK_VERSION(2.16.0)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]