[gnome-calendar/wip/pandusonu/week-view] week-view, week-grid: various fixed
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/wip/pandusonu/week-view] week-view, week-grid: various fixed
- Date: Wed, 2 Nov 2016 16:37:46 +0000 (UTC)
commit 65a4ba3257140042d9925e4e33741917f1a5a6ee
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Nov 2 14:05:48 2016 -0200
week-view, week-grid: various fixed
This commit is a rebase, compile-warning remover and a
misbehaviour fixer too.
data/ui/week-header.ui | 36 +++++++++----
data/ui/week-view.ui | 8 ++-
src/gcal-window.c | 8 +++-
src/views/gcal-week-grid.c | 122 +++++++++++++++++++++++++++++++++---------
src/views/gcal-week-header.c | 77 ++++++++------------------
src/views/gcal-week-header.h | 31 +++++++----
src/views/gcal-week-view.c | 97 ++++++++-------------------------
7 files changed, 201 insertions(+), 178 deletions(-)
---
diff --git a/data/ui/week-header.ui b/data/ui/week-header.ui
index 06f5172..6154d3d 100644
--- a/data/ui/week-header.ui
+++ b/data/ui/week-header.ui
@@ -63,19 +63,29 @@
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
- <object class="GtkButton" id="expand_button">
+ <object class="GtkBox" id="expand_button_box">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="valign">GTK_ALIGN_END</property>
- <signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader"
swapped="yes"/>
- <style>
- <class name="flat" />
- <class name="circular" />
- </style>
+ <property name="can_focus">False</property>
+ <property name="hexpand">False</property>
<child>
- <object class="GtkImage" id="expand_button_image">
+ <object class="GtkButton" id="expand_button">
<property name="visible">True</property>
- <property name="icon_name">go-down-symbolic</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ <property name="margin-bottom">6</property>
+ <signal name="clicked" handler="on_expand_action_activated" object="GcalWeekHeader"
swapped="yes"/>
+ <style>
+ <class name="flat" />
+ <class name="circular" />
+ </style>
+ <child>
+ <object class="GtkImage" id="expand_button_image">
+ <property name="visible">True</property>
+ <property name="icon_name">go-down-symbolic</property>
+ </object>
+ </child>
</object>
</child>
</object>
@@ -186,4 +196,10 @@
</object>
</child>
</template>
+ <object class="GtkSizeGroup" id="sizegroup">
+ <property name="mode">horizontal</property>
+ <widgets>
+ <widget name="expand_button_box"/>
+ </widgets>
+</object>
</interface>
diff --git a/data/ui/week-view.ui b/data/ui/week-view.ui
index 43789d7..075a4c7 100644
--- a/data/ui/week-view.ui
+++ b/data/ui/week-view.ui
@@ -10,12 +10,13 @@
<object class="GcalWeekHeader" id="header">
<property name="visible">True</property>
<property name="active-date" bind-source="GcalWeekView" bind-property="active-date"
bind-flags="default" />
- <property name="sidebar-width-offset" bind-source="GcalWeekView"
bind-property="sidebar-width-offset" bind-flags="default" />
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
@@ -28,12 +29,13 @@
<property name="visible">True</property>
<property name="height-request">2568</property>
<signal name="draw" handler="gcal_week_view_draw_hours" object="GcalWeekView"
swapped="yes" />
- <signal name="size-allocate" handler="gcal_week_view_hours_bar_size_allocate"
object="GcalWeekView" swapped="yes" />
</object>
</child>
<child>
<object class="GcalWeekGrid" id="week_grid">
<property name="visible">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
</object>
</child>
</object>
@@ -43,4 +45,4 @@
</object>
</child>
</template>
-</interface>
\ No newline at end of file
+</interface>
diff --git a/src/gcal-window.c b/src/gcal-window.c
index e896f1e..f4ff24e 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -402,10 +402,16 @@ update_active_date (GcalWindow *window,
}
/* week_view */
- g_date_set_dmy (&old_week, previous_date->day, previous_date->month, previous_date->year);
+ g_date_clear (&old_week, 1);
+
+ if (previous_date->day > 0 && previous_date->month > 0 && previous_date->year)
+ g_date_set_dmy (&old_week, previous_date->day, previous_date->month, previous_date->year);
+
+ g_date_clear (&new_week, 1);
g_date_set_dmy (&new_week, new_date->day, new_date->month, new_date->year);
if (previous_date->year != new_date->year ||
+ !g_date_valid (&old_week) ||
g_date_get_iso8601_week_of_year (&old_week) != g_date_get_iso8601_week_of_year(&new_week))
{
date_start = g_date_time_new_local (new_date->year, new_date->month, new_date->day, 0, 0, 0);
diff --git a/src/views/gcal-week-grid.c b/src/views/gcal-week-grid.c
index a9e4546..91db16d 100644
--- a/src/views/gcal-week-grid.c
+++ b/src/views/gcal-week-grid.c
@@ -113,13 +113,7 @@ gcal_week_grid_get_property (GObject *object,
GValue *value,
GParamSpec *pspec)
{
- GcalWeekGrid *self = GCAL_WEEK_GRID (object);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
static void
@@ -128,13 +122,7 @@ gcal_week_grid_set_property (GObject *object,
const GValue *value,
GParamSpec *pspec)
{
- GcalWeekGrid *self = GCAL_WEEK_GRID (object);
-
- switch (prop_id)
- {
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- }
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
static void
@@ -147,11 +135,9 @@ gcal_week_grid_realize (GtkWidget *widget)
GtkAllocation allocation;
self = GCAL_WEEK_GRID (widget);
-
- gtk_widget_set_realized (widget, TRUE);
-
parent_window = gtk_widget_get_parent_window (widget);
+ gtk_widget_set_realized (widget, TRUE);
gtk_widget_set_window (widget, parent_window);
g_object_ref (parent_window);
@@ -164,6 +150,15 @@ gcal_week_grid_realize (GtkWidget *widget)
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 |
+ GDK_SCROLL_MASK |
+ GDK_SMOOTH_SCROLL_MASK);
attributes_mask = GDK_WA_X | GDK_WA_Y;
self->event_window = gdk_window_new (parent_window,
@@ -179,7 +174,7 @@ gcal_week_grid_unrealize (GtkWidget *widget)
self = GCAL_WEEK_GRID (widget);
- if (self->event_window != NULL)
+ if (self->event_window)
{
gtk_widget_unregister_window (widget, self->event_window);
gdk_window_destroy (self->event_window);
@@ -196,7 +191,7 @@ gcal_week_grid_map (GtkWidget *widget)
self = GCAL_WEEK_GRID (widget);
- if (self->event_window != NULL)
+ if (self->event_window)
gdk_window_show (self->event_window);
GTK_WIDGET_CLASS (gcal_week_grid_parent_class)->map (widget);
@@ -209,7 +204,7 @@ gcal_week_grid_unmap (GtkWidget *widget)
self = GCAL_WEEK_GRID (widget);
- if (self->event_window != NULL)
+ if (self->event_window)
gdk_window_hide (self->event_window);
GTK_WIDGET_CLASS (gcal_week_grid_parent_class)->unmap (widget);
@@ -219,7 +214,6 @@ static gboolean
gcal_week_grid_draw (GtkWidget *widget,
cairo_t *cr)
{
- GcalWeekGrid *self;
GtkStyleContext *context;
GtkStateFlags state;
GtkBorder padding;
@@ -230,8 +224,6 @@ gcal_week_grid_draw (GtkWidget *widget,
PangoLayout *layout;
PangoFontDescription *font_desc;
- self = GCAL_WEEK_GRID (widget);
-
context = gtk_widget_get_style_context (widget);
state = gtk_widget_get_state_flags (widget);
@@ -280,11 +272,87 @@ gcal_week_grid_draw (GtkWidget *widget,
}
static void
+gcal_week_grid_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
+{
+ GcalWeekGrid *self = GCAL_WEEK_GRID (widget);
+
+ /* No need to relayout stuff if nothing changed */
+ if (allocation->height == gtk_widget_get_allocated_height (widget) &&
+ allocation->width == gtk_widget_get_allocated_width (widget))
+ {
+ return;
+ }
+
+ /* Allocate the widget */
+ gtk_widget_set_allocation (widget, allocation);
+
+ if (gtk_widget_get_realized (widget))
+ {
+ gdk_window_move_resize (self->event_window,
+ allocation->x,
+ allocation->y,
+ allocation->width,
+ allocation->height);
+ }
+}
+
+static void
+gcal_week_grid_get_preferred_height (GtkWidget *widget,
+ gint *minimum_height,
+ gint *natural_height)
+{
+ GtkStyleContext *context;
+ GtkStateFlags state;
+ GtkBorder padding;
+
+ PangoLayout *layout;
+ PangoFontDescription *font_desc;
+
+ gint hours_12_height, hours_24_height, cell_height, height;
+
+ context = gtk_widget_get_style_context (widget);
+ state = gtk_style_context_get_state (context);
+
+ gtk_style_context_save (context);
+ gtk_style_context_add_class (context, "hours");
+
+ gtk_style_context_get (context, state,
+ "font", &font_desc,
+ NULL);
+ gtk_style_context_get_padding (context, state, &padding);
+
+ layout = pango_layout_new (gtk_widget_get_pango_context (widget));
+ pango_layout_set_font_description (layout, font_desc);
+
+ pango_layout_set_text (layout, _("00 AM"), -1);
+ pango_layout_get_pixel_size (layout, NULL, &hours_12_height);
+
+ pango_layout_set_text (layout, _("00:00"), -1);
+ pango_layout_get_pixel_size (layout, NULL, &hours_24_height);
+
+ cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom;
+ height = cell_height * 48;
+
+ gtk_style_context_restore (context);
+
+ pango_font_description_free (font_desc);
+ g_object_unref (layout);
+
+ /* Report the height */
+ if (minimum_height)
+ *minimum_height = height;
+
+ if (natural_height)
+ *natural_height = height;
+}
+
+static void
gcal_week_grid_class_init (GcalWeekGridClass *klass)
{
GtkContainerClass *contianer_class = GTK_CONTAINER_CLASS (klass);
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
contianer_class->add = gcal_week_grid_add;
contianer_class->remove = gcal_week_grid_remove;
@@ -295,10 +363,12 @@ gcal_week_grid_class_init (GcalWeekGridClass *klass)
object_class->set_property = gcal_week_grid_set_property;
widget_class->draw = gcal_week_grid_draw;
+ widget_class->size_allocate = gcal_week_grid_size_allocate;
widget_class->realize = gcal_week_grid_realize;
widget_class->unrealize = gcal_week_grid_unrealize;
widget_class->map = gcal_week_grid_map;
widget_class->unmap = gcal_week_grid_unmap;
+ widget_class->get_preferred_height = gcal_week_grid_get_preferred_height;
gtk_widget_class_set_css_name (widget_class, "calendar-view");
}
@@ -306,7 +376,7 @@ gcal_week_grid_class_init (GcalWeekGridClass *klass)
static void
gcal_week_grid_init (GcalWeekGrid *self)
{
- gtk_widget_init_template (GTK_WIDGET (self));
+ gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
}
/* Public API */
@@ -346,4 +416,4 @@ gcal_week_grid_set_current_date (GcalWeekGrid *self,
self->current_date = gcal_dup_icaltime (current_date);
gtk_widget_queue_draw (GTK_WIDGET (self));
-}
\ No newline at end of file
+}
diff --git a/src/views/gcal-week-header.c b/src/views/gcal-week-header.c
index 6fc625c..24e5a6e 100644
--- a/src/views/gcal-week-header.c
+++ b/src/views/gcal-week-header.c
@@ -41,6 +41,7 @@ struct _GcalWeekHeader
GtkWidget *year_label;
GtkWidget *scrolledwindow;
GtkWidget *expand_button;
+ GtkWidget *expand_button_box;
GtkWidget *expand_button_image;
GcalManager *manager;
@@ -54,8 +55,6 @@ struct _GcalWeekHeader
gint first_weekday;
- gint sidebar_width_offset;
-
/*
* Used for checking if the header is in collapsed state or expand state
* false is collapse state true is expand state
@@ -66,6 +65,8 @@ struct _GcalWeekHeader
icaltimetype *active_date;
icaltimetype *current_date;
+
+ GtkSizeGroup *sizegroup;
};
static GDateTime* get_start_of_week (GcalWeekHeader *self);
@@ -112,8 +113,7 @@ static gboolean gcal_week_header_draw (GcalWeekHeader *sel
enum
{
PROP_0,
- PROP_ACTIVE_DATE,
- PROP_SIDEBAR_WIDTH
+ PROP_ACTIVE_DATE
};
G_DEFINE_TYPE (GcalWeekHeader, gcal_week_header, GTK_TYPE_GRID);
@@ -530,10 +530,6 @@ gcal_week_header_get_property (GObject *object,
g_value_set_boxed (value, self->active_date);
return;
- case PROP_SIDEBAR_WIDTH:
- g_value_set_int (value, self->sidebar_width_offset);
- return;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -561,13 +557,6 @@ gcal_week_header_set_property (GObject *object,
return;
- case PROP_SIDEBAR_WIDTH:
- self->sidebar_width_offset = MAX (g_value_get_int (value),
- gtk_widget_get_allocated_width (self->expand_button));
-
- gtk_widget_queue_draw (self->draw_area);
- return;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -578,43 +567,22 @@ gcal_week_header_size_allocate (GtkWidget *widget,
GtkAllocation *alloc)
{
GcalWeekHeader *self = GCAL_WEEK_HEADER (widget);
+ PangoFontDescription *bold_font;
GtkStyleContext *context;
GtkStateFlags state;
GtkAllocation draw_alloc;
- gint sidebar_width, cell_width;
-
- PangoFontDescription *bold_font;
-
- if (gtk_widget_get_allocated_width (self->expand_button) > self->sidebar_width_offset)
- {
- self->sidebar_width_offset = gtk_widget_get_allocated_width (self->expand_button);
- g_object_notify (G_OBJECT (self), "sidebar-width-offset");
- }
-
context = gtk_widget_get_style_context (self->draw_area);
state = gtk_widget_get_state_flags (self->draw_area);
- sidebar_width = self->sidebar_width_offset;
gtk_widget_get_allocation (self->draw_area, &draw_alloc);
- cell_width = (draw_alloc.width - sidebar_width) / 7;
-
gtk_style_context_get (context, state, "font", &bold_font, NULL);
pango_font_description_set_weight (bold_font, PANGO_WEIGHT_SEMIBOLD);
- gtk_widget_set_margin_start (self->scrolledwindow,
- self->sidebar_width_offset - gtk_widget_get_allocated_width
(self->expand_button));
-
- gtk_widget_set_margin_end (self->scrolledwindow,
- gtk_widget_get_allocated_width (self->draw_area) - cell_width * 7 -
sidebar_width);
-
gtk_widget_set_margin_top (self->scrolledwindow,
(4 * pango_font_description_get_size (bold_font)) / PANGO_SCALE);
- gtk_widget_set_margin_start (self->expand_button, 6);
- gtk_widget_set_margin_bottom (self->expand_button, 6);
-
GTK_WIDGET_CLASS (gcal_week_header_parent_class)->size_allocate (widget, alloc);
}
@@ -659,7 +627,7 @@ gcal_week_header_draw (GcalWeekHeader *self,
current_cell = icaltime_day_of_week (*(self->active_date)) - 1;
current_cell = (7 + current_cell - self->first_weekday) % 7;
- sidebar_width = self->sidebar_width_offset;
+ sidebar_width = gtk_widget_get_allocated_width (self->expand_button_box);
cell_width = (alloc.width - sidebar_width) / 7;
pango_layout_get_pixel_size (layout, NULL, &font_height);
@@ -763,8 +731,6 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
widget_class->size_allocate = gcal_week_header_size_allocate;
- gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-header.ui");
-
g_object_class_install_property (object_class,
PROP_ACTIVE_DATE,
g_param_spec_boxed ("active-date",
@@ -772,26 +738,23 @@ gcal_week_header_class_init (GcalWeekHeaderClass *kclass)
"The active selected date",
ICAL_TIME_TYPE,
G_PARAM_CONSTRUCT | G_PARAM_READWRITE));
- g_object_class_install_property (object_class,
- PROP_SIDEBAR_WIDTH,
- g_param_spec_int ("sidebar-width-offset",
- "Sidebar Width",
- "The width of the sidebar",
- G_MININT, G_MAXINT, 10,
- G_PARAM_READWRITE));
- gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, grid);
- gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, month_label);
- gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, year_label);
- gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, week_label);
+ gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-header.ui");
+
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, draw_area);
- gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, scrolledwindow);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, expand_button);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, expand_button_box);
gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, expand_button_image);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, grid);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, month_label);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, scrolledwindow);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, sizegroup);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, week_label);
+ gtk_widget_class_bind_template_child (widget_class, GcalWeekHeader, year_label);
+ gtk_widget_class_bind_template_callback (widget_class, fix_background_size_request);
gtk_widget_class_bind_template_callback (widget_class, gcal_week_header_draw);
gtk_widget_class_bind_template_callback (widget_class, on_expand_action_activated);
- gtk_widget_class_bind_template_callback (widget_class, fix_background_size_request);
gtk_widget_class_set_css_name (widget_class, "calendar-view");
}
@@ -847,3 +810,11 @@ gcal_week_header_set_current_date (GcalWeekHeader *self,
gtk_widget_queue_draw (self->draw_area);
}
+
+GtkSizeGroup*
+gcal_week_header_get_sidebar_size_group (GcalWeekHeader *self)
+{
+ g_return_val_if_fail (GCAL_IS_WEEK_HEADER (self), NULL);
+
+ return self->sizegroup;
+}
diff --git a/src/views/gcal-week-header.h b/src/views/gcal-week-header.h
index 9492a2a..00d16ed 100644
--- a/src/views/gcal-week-header.h
+++ b/src/views/gcal-week-header.h
@@ -31,18 +31,25 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GcalWeekHeader, gcal_week_header, GCAL, WEEK_HEADER, GtkGrid)
-void gcal_week_header_set_manager (GcalWeekHeader *self,
- GcalManager *manager);
-void gcal_week_header_set_first_weekday (GcalWeekHeader *self,
- gint nr_day);
-void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
- gboolean use_24h_format);
-void gcal_week_header_set_current_date (GcalWeekHeader *self,
- icaltimetype *current_date);
-void gcal_week_header_add_event (GcalWeekHeader *self,
- GcalEvent *event);
-void gcal_week_header_remove_event (GcalWeekHeader *self,
- gchar *uuid);
+void gcal_week_header_set_manager (GcalWeekHeader *self,
+ GcalManager *manager);
+
+void gcal_week_header_set_first_weekday (GcalWeekHeader *self,
+ gint nr_day);
+
+void gcal_week_header_set_use_24h_format (GcalWeekHeader *self,
+ gboolean use_24h_format);
+
+void gcal_week_header_set_current_date (GcalWeekHeader *self,
+ icaltimetype *current_date);
+
+void gcal_week_header_add_event (GcalWeekHeader *self,
+ GcalEvent *event);
+
+void gcal_week_header_remove_event (GcalWeekHeader *self,
+ gchar *uuid);
+
+GtkSizeGroup* gcal_week_header_get_sidebar_size_group (GcalWeekHeader *self);
G_END_DECLS
diff --git a/src/views/gcal-week-view.c b/src/views/gcal-week-view.c
index 616294c..fe0e8ab 100644
--- a/src/views/gcal-week-view.c
+++ b/src/views/gcal-week-view.c
@@ -40,8 +40,7 @@ static const double dashed [] =
enum
{
PROP_0,
- PROP_DATE,
- PROP_SIDEBAR_WIDTH
+ PROP_DATE
};
struct _GcalWeekView
@@ -58,8 +57,6 @@ struct _GcalWeekView
*/
gint first_weekday;
- gint sidebar_width_offset;
-
/*
* clock format from GNOME desktop settings
*/
@@ -98,8 +95,6 @@ static void gcal_view_interface_init (GcalViewInterfa
static void gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *iface);
-static void gcal_week_view_constructed (GObject *object);
-
static void gcal_week_view_finalize (GObject *object);
static void gcal_week_view_set_property (GObject *object,
@@ -173,18 +168,22 @@ gcal_week_view_get_final_date (GcalView *view)
return new_date;
}
-static gint
-gcal_week_view_get_sidebar_width (GtkWidget *widget)
+static void
+update_hours_sidebar_size (GcalWeekView *self)
{
GtkStyleContext *context;
GtkStateFlags state;
+ GtkSizeGroup *sidebar_sizegroup;
+ GtkWidget *widget;
GtkBorder padding;
PangoLayout *layout;
PangoFontDescription *font_desc;
gint hours_12_width, hours_24_width, sidebar_width;
+ gint hours_12_height, hours_24_height, cell_height;
+ widget = GTK_WIDGET (self);
context = gtk_widget_get_style_context (widget);
state = gtk_style_context_get_state (context);
@@ -200,19 +199,27 @@ gcal_week_view_get_sidebar_width (GtkWidget *widget)
pango_layout_set_font_description (layout, font_desc);
pango_layout_set_text (layout, _("00 AM"), -1);
- pango_layout_get_pixel_size (layout, &hours_12_width, NULL);
+ pango_layout_get_pixel_size (layout, &hours_12_width, &hours_12_height);
pango_layout_set_text (layout, _("00:00"), -1);
- pango_layout_get_pixel_size (layout, &hours_24_width, NULL);
+ pango_layout_get_pixel_size (layout, &hours_24_width, &hours_24_height);
sidebar_width = MAX (hours_12_width, hours_24_width) + padding.left + padding.right;
+ cell_height = MAX (hours_12_height, hours_24_height) + padding.top + padding.bottom;
gtk_style_context_restore (context);
+ /* Update the size requests */
+ gtk_widget_set_size_request (self->hours_bar,
+ sidebar_width,
+ 48 * cell_height);
+
+ /* Sync with the week header sidebar */
+ sidebar_sizegroup = gcal_week_header_get_sidebar_size_group (GCAL_WEEK_HEADER (self->header));
+ gtk_size_group_add_widget (sidebar_sizegroup, self->hours_bar);
+
pango_font_description_free (font_desc);
g_object_unref (layout);
-
- return sidebar_width;
}
static void
@@ -288,28 +295,6 @@ gcal_week_view_thaw (ECalDataModelSubscriber *subscriber)
{
}
-static void
-gcal_week_view_hours_bar_size_allocate (GtkWidget *widget,
- GtkAllocation *alloc)
-{
- GcalWeekView *self;
-
- self = GCAL_WEEK_VIEW (widget);
-
- if (gcal_week_view_get_sidebar_width (GTK_WIDGET (self)) > self->sidebar_width_offset)
- {
- self->sidebar_width_offset = gcal_week_view_get_sidebar_width (GTK_WIDGET (self));
- g_object_notify (G_OBJECT (self), "sidebar-width-offset");
- }
-
- gtk_widget_set_size_request (self->hours_bar, self->sidebar_width_offset, 2568);
- gtk_widget_set_size_request (self->week_grid,
- gtk_widget_get_allocated_width (GTK_WIDGET (self)) -
self->sidebar_width_offset,
- 2568);
-
- GTK_WIDGET_CLASS (gcal_week_view_parent_class)->size_allocate (widget, alloc);
-}
-
static gboolean
gcal_week_view_draw_hours (GcalWeekView *self,
cairo_t *cr,
@@ -373,7 +358,7 @@ gcal_week_view_draw_hours (GcalWeekView *self,
cairo_set_line_width (cr, 0.65);
- cairo_move_to (cr, self->sidebar_width_offset, 0);
+ cairo_move_to (cr, gtk_widget_get_allocated_width (self->hours_bar), 0);
cairo_rel_line_to (cr, 0, height);
/* Draws the horizontal complete lines */
@@ -408,20 +393,11 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- object_class->constructed = gcal_week_view_constructed;
object_class->finalize = gcal_week_view_finalize;
object_class->set_property = gcal_week_view_set_property;
object_class->get_property = gcal_week_view_get_property;
- g_object_class_override_property (object_class,
- PROP_DATE, "active-date");
- g_object_class_install_property (object_class,
- PROP_SIDEBAR_WIDTH,
- g_param_spec_int ("sidebar-width-offset",
- "Sidebar Width",
- "The width of the sidebar",
- G_MININT, G_MAXINT, 10,
- G_PARAM_READWRITE));
+ g_object_class_override_property (object_class, PROP_DATE, "active-date");
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/week-view.ui");
@@ -430,7 +406,6 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
gtk_widget_class_bind_template_child (widget_class, GcalWeekView, week_grid);
gtk_widget_class_bind_template_callback (widget_class, gcal_week_view_draw_hours);
- gtk_widget_class_bind_template_callback (widget_class, gcal_week_view_hours_bar_size_allocate);
gtk_widget_class_set_css_name (widget_class, "calendar-view");
}
@@ -438,9 +413,9 @@ gcal_week_view_class_init (GcalWeekViewClass *klass)
static void
gcal_week_view_init (GcalWeekView *self)
{
- self->sidebar_width_offset = 10;
-
gtk_widget_init_template (GTK_WIDGET (self));
+
+ update_hours_sidebar_size (self);
}
static void
@@ -463,18 +438,6 @@ gcal_data_model_subscriber_interface_init (ECalDataModelSubscriberInterface *ifa
}
static void
-gcal_week_view_constructed (GObject *object)
-{
- GcalWeekView *self;
-
- g_return_if_fail (GCAL_IS_WEEK_VIEW (object));
- self = GCAL_WEEK_VIEW (object);
-
- if (G_OBJECT_CLASS (gcal_week_view_parent_class)->constructed != NULL)
- G_OBJECT_CLASS (gcal_week_view_parent_class)->constructed (object);
-}
-
-static void
gcal_week_view_finalize (GObject *object)
{
GcalWeekView *self;
@@ -526,14 +489,6 @@ gcal_week_view_set_property (GObject *object,
break;
}
- case PROP_SIDEBAR_WIDTH:
- {
- self->sidebar_width_offset = g_value_get_int (value);
-
- gtk_widget_set_size_request (self->hours_bar, self->sidebar_width_offset, 2568);
- break;
- }
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -557,10 +512,6 @@ gcal_week_view_get_property (GObject *object,
g_value_set_boxed (value, self->date);
break;
- case PROP_SIDEBAR_WIDTH:
- g_value_set_int (value, self->sidebar_width_offset);
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
@@ -632,4 +583,4 @@ gcal_week_view_set_current_date (GcalWeekView *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]