[gnome-calendar/ui-rewrite] gcal-all-day-grid: added get_cell_position helper



commit 979f61db11a20be7e1fc8852484ed28161194eb9
Author: Erick Pérez Castellanos <erick red gmail com>
Date:   Sat Jul 27 20:16:05 2013 -0400

    gcal-all-day-grid: added get_cell_position helper
    
    Helper to detect the position of a marked cell

 src/gcal-all-day-grid.c |   41 +++++++++++++++++++++++++++++++++++++++++
 src/gcal-all-day-grid.h |    5 +++++
 2 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/src/gcal-all-day-grid.c b/src/gcal-all-day-grid.c
index f11b6f1..5616ec3 100644
--- a/src/gcal-all-day-grid.c
+++ b/src/gcal-all-day-grid.c
@@ -1010,3 +1010,44 @@ gcal_all_day_grid_clear_marks (GcalAllDayGrid *all_day)
   priv->end_mark_cell = -1;
   gtk_widget_queue_draw (GTK_WIDGET (all_day));
 }
+
+void
+gcal_all_day_grid_get_cell_position (GcalAllDayGrid *all_day,
+                                     guint           cell,
+                                     gint           *x,
+                                     gint           *y)
+{
+  GcalAllDayGridPrivate *priv;
+
+  GtkWidget *widget;
+
+  GtkBorder padding;
+  PangoLayout *layout;
+  PangoRectangle logical_rect;
+
+  gint width_block;
+
+  priv = gcal_all_day_grid_get_instance_private (all_day);
+
+  widget = GTK_WIDGET (all_day);
+  width_block = gtk_widget_get_allocated_width (widget) / priv->columns_nr;
+
+  if (x != NULL)
+    *x = cell * width_block + width_block / 2;
+
+  if (y != NULL)
+    {
+      layout = gtk_widget_create_pango_layout (widget, "0");
+
+      gtk_style_context_get_padding (gtk_widget_get_style_context (widget),
+                                     gtk_widget_get_state_flags (widget),
+                                     &padding);
+      pango_layout_get_extents (layout, NULL, &logical_rect);
+      pango_extents_to_pixels (&logical_rect, NULL);
+
+      *y = (gtk_widget_get_allocated_height (widget) -
+            (padding.top + logical_rect.height + padding.bottom)) / 2;
+
+      g_object_unref (layout);
+    }
+}
diff --git a/src/gcal-all-day-grid.h b/src/gcal-all-day-grid.h
index 99af796..f152118 100644
--- a/src/gcal-all-day-grid.h
+++ b/src/gcal-all-day-grid.h
@@ -64,6 +64,11 @@ GtkWidget*     gcal_all_day_grid_get_by_uuid         (GcalAllDayGrid *all_day,
 
 void           gcal_all_day_grid_clear_marks         (GcalAllDayGrid *all_day);
 
+void           gcal_all_day_grid_get_cell_position   (GcalAllDayGrid *all_day,
+                                                     guint           cell,
+                                                     gint           *x,
+                                                     gint           *y);
+
 G_END_DECLS
 
 #endif /* __GCAL_ALL_DAY_GRID_H__ */


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