week-header: use stack-allocated structure

Using stack allocated structure for certain variable in the draw(). Also disabling the week-grid for now.
This commit is contained in:
pandusonu2
2016-12-01 23:48:53 -02:00
committed by Georges Basile Stavracas Neto
parent bffaa3bd76
commit 9ff7d79d7d
3 changed files with 19 additions and 13 deletions
+2 -2
View File
@@ -16,9 +16,9 @@
<object class="GtkViewport"> <object class="GtkViewport">
<property name="visible">True</property> <property name="visible">True</property>
<child> <child>
<object class="GcalWeekGrid"> <!--<object class="GcalWeekGrid">
<property name="visible">True</property> <property name="visible">True</property>
</object> </object>-->
</child> </child>
</object> </object>
</child> </child>
+11 -11
View File
@@ -119,8 +119,8 @@ gcal_week_header_draw (GcalWeekHeader *self,
GtkStyleContext *context; GtkStyleContext *context;
GtkStateFlags state; GtkStateFlags state;
GdkRGBA color; GdkRGBA color;
GtkAllocation *alloc; GtkAllocation alloc;
GtkBorder *padding; GtkBorder padding;
PangoLayout *layout; PangoLayout *layout;
PangoFontDescription *bold_font; PangoFontDescription *bold_font;
@@ -143,8 +143,8 @@ gcal_week_header_draw (GcalWeekHeader *self,
context = gtk_widget_get_style_context (widget); context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget); state = gtk_widget_get_state_flags (widget);
gtk_style_context_get_padding (context, state, padding); gtk_style_context_get_padding (context, state, &padding);
gtk_widget_get_allocation (widget, alloc); gtk_widget_get_allocation (widget, &alloc);
pattern = cairo_pattern_create_linear (0, start_grid_y - 18, pattern = cairo_pattern_create_linear (0, start_grid_y - 18,
0, start_grid_y + 6); 0, start_grid_y + 6);
@@ -155,7 +155,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
cairo_set_source (cr, pattern); cairo_set_source (cr, pattern);
cairo_pattern_destroy (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); cairo_fill (cr);
gtk_style_context_get_color (context, state, &color); 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; current_cell = (7 + current_cell - self->first_weekday) % 7;
sidebar_width = gcal_week_view_get_sidebar_width (widget); 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); pango_layout_get_pixel_size (layout, NULL, &font_height);
gtk_style_context_save (context); gtk_style_context_save (context);
gtk_style_context_add_class (context, "current"); gtk_style_context_add_class (context, "current");
gtk_render_background (context, cr, gtk_render_background (context, cr,
cell_width * current_cell + sidebar_width, cell_width * current_cell + sidebar_width,
font_height + padding->bottom, font_height + padding.bottom,
cell_width, cell_width,
ALL_DAY_CELLS_HEIGHT); ALL_DAY_CELLS_HEIGHT);
gtk_style_context_remove_class (context, "current"); 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); pango_layout_set_text (layout, weekday_header, -1);
cairo_move_to (cr, cairo_move_to (cr,
padding->left + cell_width * i + sidebar_width, padding.left + cell_width * i + sidebar_width,
0.0); 0.0);
pango_cairo_show_layout (cr, layout); pango_cairo_show_layout (cr, layout);
@@ -212,7 +212,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
cairo_save (cr); cairo_save (cr);
cairo_move_to (cr, cairo_move_to (cr,
cell_width * i + sidebar_width + 0.3, 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_rel_line_to (cr, 0.0, ALL_DAY_CELLS_HEIGHT);
cairo_stroke (cr); cairo_stroke (cr);
cairo_restore (cr); cairo_restore (cr);
@@ -224,9 +224,9 @@ gcal_week_header_draw (GcalWeekHeader *self,
state | GTK_STATE_FLAG_INSENSITIVE, state | GTK_STATE_FLAG_INSENSITIVE,
&color); &color);
gdk_cairo_set_source_rgba (cr, &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_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); cairo_stroke (cr);
+6
View File
@@ -58,6 +58,8 @@ struct _GcalWeekView
{ {
GtkBox parent; GtkBox parent;
GtkWidget *header;
/* /*
* first day of the week according to user locale, being * first day of the week according to user locale, being
* 0 for Sunday, 1 for Monday and so on * 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_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"); 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)); 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; self->current_date = current_date;
} }