[gnome-calendar] month-view: add view headers of its own
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] month-view: add view headers of its own
- Date: Tue, 20 Jan 2015 18:51:58 +0000 (UTC)
commit bdacaeaa599a716a1e0a14b15e652d7c4a6c8aa6
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Jan 20 13:19:37 2015 -0500
month-view: add view headers of its own
data/theme/gtk-styles.css | 1 +
src/gcal-month-view.c | 87 +++++++++++++++++++++++++++++++--------------
2 files changed, 61 insertions(+), 27 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index db3d1fe..64fa21e 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -66,6 +66,7 @@
.calendar-view.second-view-header {
font: bold 18;
padding: 12px;
+ color: alpha(@theme_fg_color, 0.55);
}
/* Header the padding if for sizing, on drawing the spacing between cells,
diff --git a/src/gcal-month-view.c b/src/gcal-month-view.c
index 85726b1..41a5cd9 100644
--- a/src/gcal-month-view.c
+++ b/src/gcal-month-view.c
@@ -262,13 +262,26 @@ get_start_grid_y (GtkWidget *widget)
context = gtk_widget_get_style_context (widget);
state_flags = gtk_widget_get_state_flags (widget);
+ layout = gtk_widget_create_pango_layout (widget, NULL);
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "first-view-header");
+ gtk_style_context_get (context, state_flags, "padding-top", &padding_top, "font", &font_desc, NULL);
+
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_size (layout, NULL, &font_height);
+
+ pango_font_description_free (font_desc);
+ gtk_style_context_restore (context);
+
+ start_grid_y = 2 * padding_top + font_height;
+
gtk_style_context_get (context, state_flags, "font", &font_desc, "padding-top", &padding_top, NULL);
- layout = pango_layout_new (gtk_widget_get_pango_context (widget));
pango_layout_set_font_description (layout, font_desc);
pango_layout_get_pixel_size (layout, NULL, &font_height);
- start_grid_y = padding_top + font_height;
+ start_grid_y += padding_top + font_height;
pango_font_description_free (font_desc);
g_object_unref (layout);
@@ -1016,23 +1029,14 @@ gcal_month_view_draw (GtkWidget *widget,
GdkRGBA color;
+ gchar *header_str;
PangoLayout *layout;
- PangoFontDescription *font_desc;
- PangoFontDescription *sfont_desc;
-
- gint font_width, font_height;
-
- gint pos_x, pos_y;
- gdouble start_grid_y, cell_width, cell_height;
+ PangoFontDescription *font_desc, *sfont_desc;
+ gint font_width, font_height, pos_x, pos_y, shown_rows;
+ gint i, j, sw, lower_mark = 43, upper_mark = -2;
+ gdouble start_grid_y, cell_width, cell_height, first_row_gap = 0.0;
gdouble days;
- gint shown_rows;
- gdouble first_row_gap = 0.0;
-
- gint i, j, sw;
-
- gint lower_mark = 43;
- gint upper_mark = -2;
priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (widget));
ppriv = GCAL_SUBSCRIBER_VIEW (widget)->priv;
@@ -1041,7 +1045,6 @@ gcal_month_view_draw (GtkWidget *widget,
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
- gtk_style_context_get_padding (context, state, &padding);
gtk_style_context_get (context, state | GTK_STATE_FLAG_SELECTED, "font", &sfont_desc, NULL);
gtk_widget_get_allocation (widget, &alloc);
@@ -1075,6 +1078,44 @@ gcal_month_view_draw (GtkWidget *widget,
upper_mark -= priv->days_delay;
}
+ /* view headers */
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "first-view-header");
+
+ gtk_style_context_get (context, state, "font", &font_desc, NULL);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ header_str = g_strdup_printf ("%s", gcal_get_month_name (priv->date->month - 1));
+ pango_layout_set_text (layout, header_str, -1);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_size (layout, &font_width, NULL);
+
+ gtk_render_layout (context, cr, priv->k * (alloc.width - font_width) + sw * padding.left, padding.top,
layout);
+
+ pango_font_description_free (font_desc);
+ g_free (header_str);
+ gtk_style_context_restore (context);
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "second-view-header");
+
+ gtk_style_context_get (context, state, "font", &font_desc, NULL);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ header_str = g_strdup_printf ("%d", priv->date->year);
+ pango_layout_set_text (layout, header_str, -1);
+ pango_layout_set_font_description (layout, font_desc);
+ pango_layout_get_pixel_size (layout, &font_width, NULL);
+
+ gtk_render_layout (context, cr, (1 - priv->k) * (alloc.width - font_width) - sw * padding.left,
padding.top, layout);
+
+ pango_font_description_free (font_desc);
+ g_free (header_str);
+ gtk_style_context_restore (context);
+
+ /*same padding for the rest of the view */
+ gtk_style_context_get_padding (context, state, &padding);
+
/* grid header */
gtk_style_context_save (context);
gtk_style_context_add_class (context, "header");
@@ -1633,17 +1674,9 @@ gcal_month_view_clear_marks (GcalView *view)
static gchar*
gcal_month_view_get_left_header (GcalView *view)
{
- GcalMonthViewPrivate *priv;
-
- gchar str_date[64];
- struct tm tm_date;
-
- priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (view));
-
- tm_date = icaltimetype_to_tm (priv->date);
- e_utf8_strftime_fix_am_pm (str_date, 64, "%B", &tm_date);
+ GcalMonthViewPrivate *priv = gcal_month_view_get_instance_private (GCAL_MONTH_VIEW (view));
- return g_strdup_printf ("%s", str_date);
+ return g_strdup_printf ("%s", gcal_get_month_name (priv->date->month - 1));
}
static gchar*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]