[gnome-calendar] gcal-all-day-grid: make it reactive
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] gcal-all-day-grid: make it reactive
- Date: Thu, 4 Dec 2014 22:22:06 +0000 (UTC)
commit 05c2d6064b21c085cf36ee0cd60f35456ae2cec6
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Jun 11 17:13:05 2013 -0400
gcal-all-day-grid: make it reactive
Missing to communicate click actions
src/gcal-all-day-grid.c | 173 ++++++++++++++++++++++++++++++++++++++---------
1 files changed, 142 insertions(+), 31 deletions(-)
---
diff --git a/src/gcal-all-day-grid.c b/src/gcal-all-day-grid.c
index eab121e..54a3470 100644
--- a/src/gcal-all-day-grid.c
+++ b/src/gcal-all-day-grid.c
@@ -37,43 +37,49 @@ struct _GcalAllDayGridPrivate
GList *column_headers;
GList *children;
+
+ GdkWindow *event_window;
};
-static void gcal_all_day_grid_finalize (GObject *object);
+static void gcal_all_day_grid_finalize (GObject *object);
+
+static void gcal_all_day_grid_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec);
+
+static void gcal_all_day_grid_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec);
-static void gcal_all_day_grid_set_property (GObject *object,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec);
+static void gcal_all_day_grid_get_preferred_width (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
-static void gcal_all_day_grid_get_property (GObject *object,
- guint property_id,
- GValue *value,
- GParamSpec *pspec);
+static void gcal_all_day_grid_get_preferred_height (GtkWidget *widget,
+ gint *minimum,
+ gint *natural);
-static void gcal_all_day_grid_get_preferred_width (GtkWidget *widget,
- gint *minimum,
- gint *natural);
+static void gcal_all_day_grid_realize (GtkWidget *widget);
-static void gcal_all_day_grid_get_preferred_height (GtkWidget *widget,
- gint *minimum,
- gint *natural);
+static void gcal_all_day_grid_unrealize (GtkWidget *widget);
-/* FIXME: realize/unrealize/map/unmap commented out tll testing
- not needed because I'm not using event-window here */
-/* static void gcal_all_day_grid_realize (GtkWidget *widget); */
+static void gcal_all_day_grid_map (GtkWidget *widget);
-/* static void gcal_all_day_grid_unrealize (GtkWidget *widget); */
+static void gcal_all_day_grid_unmap (GtkWidget *widget);
-/* static void gcal_all_day_grid_map (GtkWidget *widget); */
+static void gcal_all_day_grid_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation);
-/* static void gcal_all_day_grid_unmap (GtkWidget *widget); */
+static gboolean gcal_all_day_grid_draw (GtkWidget *widget,
+ cairo_t *cr);
-static void gcal_all_day_grid_size_allocate (GtkWidget *widget,
- GtkAllocation *allocation);
+static gboolean gcal_all_day_grid_button_press_event (GtkWidget *widget,
+ GdkEventButton *event);
-static gboolean gcal_all_day_grid_draw (GtkWidget *widget,
- cairo_t *cr);
+static gboolean gcal_all_day_grid_button_release_event (GtkWidget *widget,
+ GdkEventButton *event);
static void gcal_all_day_grid_add (GtkContainer *container,
GtkWidget *widget);
@@ -103,14 +109,14 @@ gcal_all_day_grid_class_init (GcalAllDayGridClass *klass)
widget_class = GTK_WIDGET_CLASS (klass);
widget_class->get_preferred_width = gcal_all_day_grid_get_preferred_width;
widget_class->get_preferred_height = gcal_all_day_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_all_day_grid_realize; */
- /* widget_class->unrealize = gcal_all_day_grid_unrealize; */
- /* widget_class->map = gcal_all_day_grid_map; */
- /* widget_class->unmap = gcal_all_day_grid_unmap; */
+ widget_class->realize = gcal_all_day_grid_realize;
+ widget_class->unrealize = gcal_all_day_grid_unrealize;
+ widget_class->map = gcal_all_day_grid_map;
+ widget_class->unmap = gcal_all_day_grid_unmap;
widget_class->size_allocate = gcal_all_day_grid_size_allocate;
widget_class->draw = gcal_all_day_grid_draw;
+ widget_class->button_press_event = gcal_all_day_grid_button_press_event;
+ widget_class->button_release_event = gcal_all_day_grid_button_release_event;
container_class = GTK_CONTAINER_CLASS (klass);
container_class->add = gcal_all_day_grid_add;
@@ -361,6 +367,86 @@ gcal_all_day_grid_get_preferred_height (GtkWidget *widget,
}
static void
+gcal_all_day_grid_realize (GtkWidget *widget)
+{
+ GcalAllDayGridPrivate *priv;
+ GdkWindow *parent_window;
+ GdkWindowAttr attributes;
+ gint attributes_mask;
+ GtkAllocation allocation;
+
+ priv = GCAL_ALL_DAY_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_all_day_grid_unrealize (GtkWidget *widget)
+{
+ GcalAllDayGridPrivate *priv;
+
+ priv = GCAL_ALL_DAY_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_all_day_grid_parent_class)->unrealize (widget);
+}
+
+static void
+gcal_all_day_grid_map (GtkWidget *widget)
+{
+ GcalAllDayGridPrivate *priv;
+
+ priv = GCAL_ALL_DAY_GRID (widget)->priv;
+ if (priv->event_window != NULL)
+ gdk_window_show (priv->event_window);
+
+ GTK_WIDGET_CLASS (gcal_all_day_grid_parent_class)->map (widget);
+}
+
+static void
+gcal_all_day_grid_unmap (GtkWidget *widget)
+{
+ GcalAllDayGridPrivate *priv;
+
+ priv = GCAL_ALL_DAY_GRID (widget)->priv;
+ if (priv->event_window != NULL)
+ gdk_window_hide (priv->event_window);
+
+ GTK_WIDGET_CLASS (gcal_all_day_grid_parent_class)->map (widget);
+}
+
+static void
gcal_all_day_grid_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
@@ -395,6 +481,16 @@ gcal_all_day_grid_size_allocate (GtkWidget *widget,
g_object_unref (layout);
+ /* Placing the event_window */
+ if (gtk_widget_get_realized (widget))
+ {
+ gdk_window_move_resize (priv->event_window,
+ allocation->x,
+ y_gap,
+ allocation->width,
+ allocation->height - y_gap);
+ }
+
/* Placing children */
for (columns = priv->children, idx = 0;
columns != NULL;
@@ -521,6 +617,21 @@ gcal_all_day_grid_draw (GtkWidget *widget,
return FALSE;
}
+static gboolean
+gcal_all_day_grid_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ g_debug ("Button pressed on all-day area");
+ return FALSE;
+}
+
+static gboolean
+gcal_all_day_grid_button_release_event (GtkWidget *widget,
+ GdkEventButton *event)
+{
+ g_debug ("Button released on all-day area");
+ return FALSE;
+}
/* GtkContainer API */
/*
* gcal_all_day_grid_add:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]