[gnome-calendar] gcal-days-grid: make it reactive.
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] gcal-days-grid: make it reactive.
- Date: Thu, 4 Dec 2014 22:22:37 +0000 (UTC)
commit d54556a03079d4739cec3a3d4f088bf3f137a69c
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Wed Jun 12 12:31:59 2013 -0400
gcal-days-grid: make it reactive.
Added #GdkWindow for catching button events.
src/gcal-days-grid.c | 126 +++++++++++++++++++++++++++++++++++++++++++++-----
1 files changed, 114 insertions(+), 12 deletions(-)
---
diff --git a/src/gcal-days-grid.c b/src/gcal-days-grid.c
index b3bfab8..bdd041b 100644
--- a/src/gcal-days-grid.c
+++ b/src/gcal-days-grid.c
@@ -60,6 +60,8 @@ struct _GcalDaysGridPrivate
guint req_cell_height;
GList *children;
+
+ GdkWindow *event_window;
};
static void gcal_days_grid_finalize (GObject *object);
@@ -82,15 +84,13 @@ static void gcal_days_grid_get_preferred_height (GtkWidget *widg
gint *minimum,
gint *natural);
-/* FIXME: realize/unrealize/map/unmap commented out tll testing
- not needed because I'm not using event-window here */
-/* static void gcal_days_grid_realize (GtkWidget *widget); */
+static void gcal_days_grid_realize (GtkWidget *widget);
-/* static void gcal_days_grid_unrealize (GtkWidget *widget); */
+static void gcal_days_grid_unrealize (GtkWidget *widget);
-/* static void gcal_days_grid_map (GtkWidget *widget); */
+static void gcal_days_grid_map (GtkWidget *widget);
-/* static void gcal_days_grid_unmap (GtkWidget *widget); */
+static void gcal_days_grid_unmap (GtkWidget *widget);
static void gcal_days_grid_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
@@ -98,6 +98,12 @@ static void gcal_days_grid_size_allocate (GtkWidget *widg
static gboolean gcal_days_grid_draw (GtkWidget *widget,
cairo_t *cr);
+static gboolean gcal_days_grid_button_press_event (GtkWidget *widget,
+ GdkEventButton *event);
+
+static gboolean gcal_days_grid_button_release_event (GtkWidget *widget,
+ GdkEventButton *event);
+
static void gcal_days_grid_add (GtkContainer *container,
GtkWidget *widget);
@@ -126,14 +132,14 @@ gcal_days_grid_class_init (GcalDaysGridClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->get_preferred_width = gcal_days_grid_get_preferred_width;
widget_class->get_preferred_height = gcal_days_grid_get_preferred_height;
- /* FIXME: realize/unrealize/map/unmap commented out tll testing
- not needed because I'm not using event-window here */
- /* widget_class->realize = gcal_days_grid_realize; */
- /* widget_class->unrealize = gcal_days_grid_unrealize; */
- /* widget_class->map = gcal_days_grid_map; */
- /* widget_class->unmap = gcal_days_grid_unmap; */
+ widget_class->realize = gcal_days_grid_realize;
+ widget_class->unrealize = gcal_days_grid_unrealize;
+ widget_class->map = gcal_days_grid_map;
+ widget_class->unmap = gcal_days_grid_unmap;
widget_class->size_allocate = gcal_days_grid_size_allocate;
widget_class->draw = gcal_days_grid_draw;
+ widget_class->button_press_event = gcal_days_grid_button_press_event;
+ widget_class->button_release_event = gcal_days_grid_button_release_event;
container_class = GTK_CONTAINER_CLASS (klass);
container_class->add = gcal_days_grid_add;
@@ -360,6 +366,86 @@ gcal_days_grid_get_preferred_height (GtkWidget *widget,
}
static void
+gcal_days_grid_realize (GtkWidget *widget)
+{
+ GcalDaysGridPrivate *priv;
+ GdkWindow *parent_window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GtkAllocation allocation;
+
+ priv = GCAL_DAYS_GRID (widget)->priv;
+ gtk_widget_set_realized (widget, TRUE);
+
+ parent_window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_window (widget, parent_window);
+ g_object_ref (parent_window);
+
+ gtk_widget_get_allocation (widget, &allocation);
+
+ attributes.window_type = GDK_WINDOW_CHILD;
+ attributes.wclass = GDK_INPUT_ONLY;
+ attributes.x = allocation.x;
+ attributes.y = allocation.y;
+ attributes.width = allocation.width;
+ attributes.height = allocation.height;
+ attributes.event_mask = gtk_widget_get_events (widget);
+ attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
+ GDK_BUTTON_RELEASE_MASK |
+ GDK_BUTTON1_MOTION_MASK |
+ GDK_POINTER_MOTION_HINT_MASK |
+ GDK_POINTER_MOTION_MASK |
+ GDK_ENTER_NOTIFY_MASK |
+ GDK_LEAVE_NOTIFY_MASK);
+ attributes_mask = GDK_WA_X | GDK_WA_Y;
+
+ priv->event_window = gdk_window_new (parent_window,
+ &attributes,
+ attributes_mask);
+ gdk_window_set_user_data (priv->event_window, widget);
+}
+
+static void
+gcal_days_grid_unrealize (GtkWidget *widget)
+{
+ GcalDaysGridPrivate *priv;
+
+ priv = GCAL_DAYS_GRID (widget)->priv;
+ if (priv->event_window != NULL)
+ {
+ gdk_window_set_user_data (priv->event_window, NULL);
+ gdk_window_destroy (priv->event_window);
+ priv->event_window = NULL;
+ }
+
+ GTK_WIDGET_CLASS (gcal_days_grid_parent_class)->unrealize (widget);
+}
+
+static void
+gcal_days_grid_map (GtkWidget *widget)
+{
+ GcalDaysGridPrivate *priv;
+
+ priv = GCAL_DAYS_GRID (widget)->priv;
+ if (priv->event_window != NULL)
+ gdk_window_show (priv->event_window);
+
+ GTK_WIDGET_CLASS (gcal_days_grid_parent_class)->map (widget);
+}
+
+static void
+gcal_days_grid_unmap (GtkWidget *widget)
+{
+ GcalDaysGridPrivate *priv;
+
+ priv = GCAL_DAYS_GRID (widget)->priv;
+ if (priv->event_window != NULL)
+ gdk_window_hide (priv->event_window);
+
+ GTK_WIDGET_CLASS (gcal_days_grid_parent_class)->map (widget);
+}
+
+static void
gcal_days_grid_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
@@ -496,6 +582,22 @@ gcal_days_grid_draw (GtkWidget *widget,
return FALSE;
}
+static gboolean
+gcal_days_grid_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ g_debug ("Button pressed on days-grid area");
+ return FALSE;
+}
+
+static gboolean
+gcal_days_grid_button_release_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ g_debug ("Button released on days-grid area");
+ return FALSE;
+}
+
/* GtkContainer API */
/*
* gcal_days_grid_add:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]