[gnome-calendar/wip/pandusonu/week-view: 19/60] week-header: use stack-allocated structure



commit 9ff7d79d7dbb94422fc6cc0421d8eb0951b77bf9
Author: pandusonu2 <pandu sonu yahoo com>
Date:   Fri Jun 10 21:23:54 2016 +0530

    week-header: use stack-allocated structure
    
    Using stack allocated structure for certain variable in the draw(). Also disabling the week-grid for now.

 data/ui/week-view.ui         |    4 ++--
 src/views/gcal-week-header.c |   22 +++++++++++-----------
 src/views/gcal-week-view.c   |    6 ++++++
 3 files changed, 19 insertions(+), 13 deletions(-)
---
diff --git a/data/ui/week-view.ui b/data/ui/week-view.ui
index 83a5357..00bdcd4 100644
--- a/data/ui/week-view.ui
+++ b/data/ui/week-view.ui
@@ -16,9 +16,9 @@
           <object class="GtkViewport">
             <property name="visible">True</property>
             <child>
-              <object class="GcalWeekGrid">
+              <!--<object class="GcalWeekGrid">
                 <property name="visible">True</property>
-              </object>
+              </object>-->
             </child>
           </object>
         </child>
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index 6bc266a..0e49677 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -119,8 +119,8 @@ gcal_week_header_draw (GcalWeekHeader *self,
   GtkStyleContext *context;
   GtkStateFlags state;
   GdkRGBA color;
-  GtkAllocation *alloc;
-  GtkBorder *padding;
+  GtkAllocation alloc;
+  GtkBorder padding;
 
   PangoLayout *layout;
   PangoFontDescription *bold_font;
@@ -143,8 +143,8 @@ gcal_week_header_draw (GcalWeekHeader *self,
   context = gtk_widget_get_style_context (widget);
   state = gtk_widget_get_state_flags (widget);
 
-  gtk_style_context_get_padding (context, state, padding);
-  gtk_widget_get_allocation (widget, alloc);
+  gtk_style_context_get_padding (context, state, &padding);
+  gtk_widget_get_allocation (widget, &alloc);
 
   pattern = cairo_pattern_create_linear (0, start_grid_y - 18,
                                          0, start_grid_y + 6);
@@ -155,7 +155,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
   cairo_set_source (cr, pattern);
   cairo_pattern_destroy (pattern);
 
-  cairo_rectangle (cr, 0, start_grid_y, alloc->width, 6);
+  cairo_rectangle (cr, 0, start_grid_y, alloc.width, 6);
   cairo_fill (cr);
 
   gtk_style_context_get_color (context, state, &color);
@@ -171,14 +171,14 @@ gcal_week_header_draw (GcalWeekHeader *self,
   current_cell = (7 + current_cell - self->first_weekday) % 7;
 
   sidebar_width = gcal_week_view_get_sidebar_width (widget);
-  cell_width = (alloc->width - sidebar_width) / 7;
+  cell_width = (alloc.width - sidebar_width) / 7;
   pango_layout_get_pixel_size (layout, NULL, &font_height);
 
   gtk_style_context_save (context);
   gtk_style_context_add_class (context, "current");
   gtk_render_background (context, cr,
                          cell_width * current_cell + sidebar_width,
-                         font_height + padding->bottom,
+                         font_height + padding.bottom,
                          cell_width,
                          ALL_DAY_CELLS_HEIGHT);
   gtk_style_context_remove_class (context, "current");
@@ -204,7 +204,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
 
       pango_layout_set_text (layout, weekday_header, -1);
       cairo_move_to (cr,
-                     padding->left + cell_width * i + sidebar_width,
+                     padding.left + cell_width * i + sidebar_width,
                      0.0);
       pango_cairo_show_layout (cr, layout);
 
@@ -212,7 +212,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
       cairo_save (cr);
       cairo_move_to (cr,
                      cell_width * i + sidebar_width + 0.3,
-                     font_height + padding->bottom);
+                     font_height + padding.bottom);
       cairo_rel_line_to (cr, 0.0, ALL_DAY_CELLS_HEIGHT);
       cairo_stroke (cr);
       cairo_restore (cr);
@@ -224,9 +224,9 @@ gcal_week_header_draw (GcalWeekHeader *self,
                                state | GTK_STATE_FLAG_INSENSITIVE,
                                &color);
   gdk_cairo_set_source_rgba (cr, &color);
-  pos_i = font_height + padding->bottom;
+  pos_i = font_height + padding.bottom;
   cairo_move_to (cr, sidebar_width, pos_i + 0.3);
-  cairo_rel_line_to (cr, alloc->width - sidebar_width, 0);
+  cairo_rel_line_to (cr, alloc.width - sidebar_width, 0);
 
   cairo_stroke (cr);
 
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 7e96a88..437bf5c 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -58,6 +58,8 @@ struct _GcalWeekView
 {
   GtkBox          parent;
 
+  GtkWidget      *header;
+
   /*
    * first day of the week according to user locale, being
    * 0 for Sunday, 1 for Monday and so on 
@@ -283,6 +285,8 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
 
   gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-view.ui");
 
+  gtk_widget_class_bind_template_child (widget_class, GcalWeekView, header);
+
   gtk_widget_class_set_css_name (widget_class, "calendar-view");
 }
 
@@ -521,5 +525,7 @@ gcal_week_view_set_current_date (GcalWeekView *self,
 {
   g_return_if_fail (GCAL_IS_WEEK_VIEW (self));
 
+  gcal_week_header_set_current_date (GCAL_WEEK_HEADER (self->header), current_date);
+
   self->current_date = current_date;
 }
\ No newline at end of file


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