month-view: rewrite was a template widget

This commit is contained in:
Georges Basile Stavracas Neto
2017-10-06 20:32:00 -03:00
parent 857409a46e
commit e59910f0e9
13 changed files with 1730 additions and 1363 deletions
+2
View File
@@ -7,6 +7,8 @@
<file alias="date-selector.ui" compressed="true" preprocess="xml-stripblanks">ui/date-selector.ui</file>
<file alias="edit-dialog.ui" compressed="true" preprocess="xml-stripblanks">ui/edit-dialog.ui</file>
<file alias="event-widget.ui" compressed="true" preprocess="xml-stripblanks">ui/event-widget.ui</file>
<file alias="month-cell.ui" compressed="true" preprocess="xml-stripblanks">ui/month-cell.ui</file>
<file alias="month-view.ui" compressed="true" preprocess="xml-stripblanks">ui/month-view.ui</file>
<file alias="multi-choice.ui" compressed="true" preprocess="xml-stripblanks">ui/multi-choice.ui</file>
<file alias="online-account-row.ui" compressed="true" preprocess="xml-stripblanks">ui/online-account-row.ui</file>
<file alias="quick-add-popover.ui" compressed="true" preprocess="xml-stripblanks">ui/quick-add-popover.ui</file>
+2
View File
@@ -54,6 +54,8 @@ resource_data = files(
'ui/edit-dialog.ui',
'ui/help-overlay.ui',
'ui/menus.ui',
'ui/month-cell.ui',
'ui/month-view.ui',
'ui/multi-choice.ui',
'ui/quick-add-popover.ui',
'ui/search-view.ui',
+67 -35
View File
@@ -1,19 +1,14 @@
@define-color event_shadow_color alpha(black, 0.2);
.nav-button {
background-color: transparent;
background-image: none;
}
/* nav-bar labels */
.start-header {
/* Header labels */
label.primary-label {
font-size: 16pt;
font-weight: bold;
color: @theme_selected_bg_color;
padding: 12px;
}
.end-header {
label.secondary-label {
font-size: 16pt;
font-weight: bold;
padding: 12px;
@@ -25,7 +20,8 @@ calendar-view {
font-size: 10pt;
}
calendar-view.header {
calendar-view.header,
label.header {
font-size: 10pt;
font-weight: bold;
color: alpha(@theme_fg_color, 0.55);
@@ -41,25 +37,6 @@ calendar-view:selected {
font-weight: bold;
}
calendar-view.overflow:hover {
font-weight: bold;
color: @theme_selected_bg_color;
background-image: linear-gradient(to bottom, shade(@theme_bg_color, 0.9), alpha(@theme_bg_color, 0.2) 10%,
alpha(@theme_bg_color, 0.2) 95%, shade(@theme_bg_color, 0.95) 100%);
}
calendar-view.overflow {
font-size: 8pt;
}
calendar-view.lines {
color: alpha(@theme_fg_color, 0.4);
}
calendar-view.offset {
background-color: alpha(@theme_bg_color, 0.5);
}
/* Year View CSS */
.year-view {
padding: 0px;
@@ -364,6 +341,13 @@ datechooser day:selected:hover {
font-weight: bold;
}
label.month-name {
font-size: 16pt;
font-weight: bold;
color: alpha(@theme_selected_bg_color, 0.75);
padding: 12px;
}
/* Week View CSS */
.week-header {
@@ -371,13 +355,6 @@ datechooser day:selected:hover {
border-bottom: solid @borders 1px;
}
.week-header .month-name {
font-size: 16pt;
font-weight: bold;
color: alpha(@theme_selected_bg_color, 0.75);
padding: 12px;
}
.week-header .week-number {
font-size: 16pt;
font-weight: bold;
@@ -437,3 +414,58 @@ weekgrid:selected,
.week-header:selected {
border: solid 1px alpha(@theme_selected_bg_color, 0.8);
}
/*
* Month cell
*/
monthcell {
border: solid 1px @borders;
border-width: 1px 0 0 1px;
background: transparent;
padding: 1px 0 1px 0;
transition: background-color 200ms;
}
monthcell:selected {
font-weight: bold;
background-color: alpha(@theme_selected_bg_color, 0.1);
}
monthcell.today {
background-color: alpha(@theme_selected_bg_color, 0.25);
}
monthcell:selected.today {
background-color: alpha(@theme_selected_bg_color, 0.33);
}
monthcell.out-of-month {
background-color: alpha(@theme_bg_color, 0.4);
}
monthcell label {
color: @theme_fg_color;
font-size: 0.9rem;
}
monthcell:hover:not(.out-of-month) {
background-color: @theme_bg_color;
transition: background-color 200ms;
}
monthcell:dir(ltr):nth-child(7n + 1) {
border-left-width: 0;
}
monthcell:dir(rtl):nth-child(7n + 1) {
border-right-width: 0;
}
monthcell button {
padding: 0 4px;
border-radius: 0;
border-bottom: none;
border-right: none;
}
+75
View File
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthCell" parent="GtkEventBox">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="expand">True</property>
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
<child>
<object class="GtkOverlay" id="overlay">
<property name="visible">True</property>
<property name="can-focus">True</property>
<!-- HACK: in Gtk3, insensitive widgets receive no events. We "fix" this
limitation by adding an always-sensitive GtkEventBox above the event,
and when the event is insensitive, the event box's event window is
above it -->
<child type="overlay">
<object class="GtkEventBox" id="button_event_box">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="above-child" bind-source="overflow_button" bind-property="sensitive" bind-flags="default|invert-boolean|sync-create" />
<signal name="enter-notify-event" handler="enter_notify_event_cb" object="GcalMonthCell" swapped="no" />
<signal name="leave-notify-event" handler="leave_notify_event_cb" object="GcalMonthCell" swapped="no" />
<child>
<object class="GtkButton" id="overflow_button">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="valign">end</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="overflow_button_clicked_cb" object="GcalMonthCell" swapped="no" />
<style>
<class name="flat" />
</style>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="spacing">6</property>
<property name="valign">center</property>
<child type="center">
<object class="GtkLabel" id="overflow_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="ellipsize">end</property>
</object>
</child>
<child>
<object class="GtkLabel" id="day_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
<child>
<object class="GtkImage" id="weather_icon">
<property name="can-focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="pack-type">end</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
+206
View File
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<template class="GcalMonthView" parent="GtkContainer">
<!-- Header -->
<child type="header">
<object class="GtkBox">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<child>
<object class="GtkLabel" id="month_label">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="month-name" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="year_label">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">1.0</property>
<style>
<class name="secondary-label" />
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<property name="spacing">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="margin-bottom">6</property>
<child>
<object class="GtkLabel" id="label_0">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_1">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_2">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_3">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_4">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_5">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="label_6">
<property name="visible">true</property>
<property name="can_focus">false</property>
<property name="hexpand">true</property>
<property name="xalign">0.0</property>
<style>
<class name="header" />
</style>
</object>
</child>
</object>
</child>
</object>
</child>
<!-- Grid -->
<child type="grid">
<object class="GtkGrid" id="grid">
<property name="visible">true</property>
<property name="can-focus">false</property>
<property name="row-homogeneous">true</property>
<property name="column-homogeneous">true</property>
</object>
</child>
</template>
<!-- Overflow popover -->
<object class="GtkPopover" id="overflow_popover">
<property name="can-focus">false</property>
<property name="position">bottom</property>
<signal name="drag-motion" handler="cancel_dnd_from_overflow_popover" object="GcalMonthView" swapped="yes" />
<style>
<class name="events" />
</style>
<child>
<object class="GtkBox">
<property name="visible">true</property>
<property name="can-focus">false</property>
<property name="spacing">6</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="popover_title">
<property name="visible">true</property>
<property name="can-focus">false</property>
<property name="margin-top">6</property>
<property name="margin-start">6</property>
<property name="margin-end">6</property>
<property name="xalign">0.0</property>
<style>
<class name="sidebar-header" />
</style>
</object>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">true</property>
<property name="can-focus">false</property>
<property name="hscrollbar-policy">never</property>
<property name="vscrollbar-policy">automatic</property>
<property name="max-content-height">400</property>
<property name="propagate-natural-height">true</property>
<child>
<object class="GtkBox" id="events_box">
<property name="visible">true</property>
<property name="orientation">vertical</property>
<property name="margin-start">2</property>
<property name="margin-end">2</property>
<property name="spacing">2</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">true</property>
<property name="hexpand">true</property>
<property name="label" translatable="yes">Add Event…</property>
<signal name="clicked" handler="add_new_event_button_cb" object="GcalMonthView" swapped="no" />
</object>
</child>
</object>
</child>
</object>
</interface>
+3 -3
View File
@@ -17,7 +17,7 @@
<property name="label">Month</property>
<property name="yalign">0</property>
<style>
<class name="start-header" />
<class name="primary-label" />
</style>
</object>
</child>
@@ -29,7 +29,7 @@
<property name="yalign">0</property>
<property name="label">Week</property>
<style>
<class name="end-header" />
<class name="secondary-label" />
</style>
</object>
</child>
@@ -39,7 +39,7 @@
<property name="label">Year</property>
<property name="yalign">0</property>
<style>
<class name="end-header" />
<class name="secondary-label" />
</style>
</object>
</child>
+34
View File
@@ -1401,3 +1401,37 @@ filter_event_list_by_uid_and_modtype (GList *widgets,
return result;
}
gboolean
gcal_translate_child_window_position (GtkWidget *target,
GdkWindow *child_window,
gdouble src_x,
gdouble src_y,
gdouble *real_x,
gdouble *real_y)
{
GdkWindow *window;
gdouble x, y;
x = src_x;
y = src_y;
/* Find the (x, y) values relative to the workbench */
window = child_window;
while (window && window != gtk_widget_get_window (target))
{
gdk_window_coords_to_parent (window, x, y, &x, &y);
window = gdk_window_get_parent (window);
}
if (!window)
return FALSE;
if (real_x)
*real_x = x;
if (real_y)
*real_y = y;
return TRUE;
}
+6
View File
@@ -162,4 +162,10 @@ GList* filter_event_list_by_uid_and_modtype (GList
GcalRecurrenceModType mod,
const gchar *uid);
gboolean gcal_translate_child_window_position (GtkWidget *target,
GdkWindow *child_window,
gdouble src_x,
gdouble src_y,
gdouble *real_x,
gdouble *real_y);
#endif // __GCAL_UTILS_H__
+1
View File
@@ -18,6 +18,7 @@ gcal_deps = [
]
sources = files(
'views/gcal-month-cell.c',
'views/gcal-month-view.c',
'views/gcal-range-tree.c',
'views/gcal-view.c',
+616
View File
@@ -0,0 +1,616 @@
/* gcal-month-cell.c
*
* Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define G_LOG_DOMAIN "GcalMonthCell"
#include "config.h"
#include "gcal-event-widget.h"
#include "gcal-utils.h"
#include "gcal-month-cell.h"
struct _GcalMonthCell
{
GtkEventBox parent;
GDateTime *date;
guint n_overflow;
GtkLabel *day_label;
GtkWidget *overflow_button;
GtkWidget *overflow_label;
GtkWidget *overlay;
gboolean different_month;
gboolean selected;
/* internal fields */
gboolean hovered : 1;
gboolean pressed : 1;
GcalManager *manager;
};
G_DEFINE_TYPE (GcalMonthCell, gcal_month_cell, GTK_TYPE_EVENT_BOX)
enum
{
SHOW_OVERFLOW,
N_SIGNALS
};
enum
{
PROP_0,
PROP_MANAGER,
N_PROPS
};
static guint signals[N_SIGNALS] = { 0, };
static GParamSpec *properties[N_PROPS] = { 0, };
/*
* Auxiliary methods
*/
static void
update_style_flags (GcalMonthCell *self)
{
g_autoptr (GDateTime) today;
GtkStyleContext *context;
GtkStateFlags flags;
GtkWidget *widget;
widget = GTK_WIDGET (self);
flags = gtk_widget_get_state_flags (widget);
if (self->hovered)
flags |= GTK_STATE_FLAG_PRELIGHT;
else
flags &= ~GTK_STATE_FLAG_PRELIGHT;
gtk_widget_set_state_flags (widget, flags, TRUE);
/* Today */
today = g_date_time_new_now_local ();
context = gtk_widget_get_style_context (GTK_WIDGET (self));
if (datetime_compare_date (self->date, today) == 0)
gtk_style_context_add_class (context, "today");
else
gtk_style_context_remove_class (context, "today");
}
static gboolean
should_propagate_button_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self;
gdouble x, y;
gint button_height, height;
self = GCAL_MONTH_CELL (widget);
height = gtk_widget_get_allocated_height (widget);
button_height = gtk_widget_get_allocated_height (self->overflow_button);
x = event_button->x;
y = event_button->y;
if (!gcal_translate_child_window_position (widget, event_button->window, x, y, &x, &y))
return GDK_EVENT_PROPAGATE;
if (self->n_overflow > 0 && y > height - button_height)
return GDK_EVENT_STOP;
return GDK_EVENT_PROPAGATE;
}
/*
* Callbacks
*/
static void
day_changed_cb (GcalClock *clock,
GcalMonthCell *self)
{
update_style_flags (self);
}
static gboolean
enter_notify_event_cb (GtkWidget *widget,
GdkEventCrossing *event_crossing,
GcalMonthCell *self)
{
self->hovered = TRUE;
update_style_flags (self);
return GDK_EVENT_PROPAGATE;
}
static gboolean
leave_notify_event_cb (GtkWidget *widget,
GdkEventCrossing *event_crossing,
GcalMonthCell *self)
{
self->hovered = FALSE;
update_style_flags (self);
return GDK_EVENT_PROPAGATE;
}
static void
overflow_button_clicked_cb (GtkWidget *button,
GcalMonthCell *self)
{
g_signal_emit (self, signals[SHOW_OVERFLOW], 0, button);
}
/*
* GtkWidget overrides
*/
static gboolean
gcal_month_cell_drag_motion (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GcalMonthCell *self;
self = GCAL_MONTH_CELL (widget);
if (self->different_month)
gtk_drag_unhighlight (widget);
else
gtk_drag_highlight (widget);
gdk_drag_status (context, self->different_month ? 0 : GDK_ACTION_MOVE, time);
return !self->different_month;
}
static gboolean
gcal_month_cell_drag_drop (GtkWidget *widget,
GdkDragContext *context,
gint x,
gint y,
guint time)
{
GcalRecurrenceModType mod;
GcalMonthCell *self;
GtkWidget *event_widget;
GDateTime *start_dt, *end_dt;
GcalEvent *event;
ESource *source;
gint diff;
gint start_month, current_month;
gint start_year, current_year;
GTimeSpan timespan = 0;
self = GCAL_MONTH_CELL (widget);
event_widget = gtk_drag_get_source_widget (context);
mod = GCAL_RECURRENCE_MOD_THIS_ONLY;
if (!GCAL_IS_EVENT_WIDGET (event_widget))
return FALSE;
if (self->different_month)
return FALSE;
event = gcal_event_widget_get_event (GCAL_EVENT_WIDGET (event_widget));
source = gcal_event_get_source (event);
if (gcal_event_has_recurrence (event) &&
!ask_recurrence_modification_type (widget, &mod, source))
{
goto out;
}
/* Move the event's date */
start_dt = gcal_event_get_date_start (event);
end_dt = gcal_event_get_date_end (event);
start_month = g_date_time_get_month (start_dt);
start_year = g_date_time_get_year (start_dt);
current_month = g_date_time_get_month (self->date);
current_year = g_date_time_get_year (self->date);
timespan = g_date_time_difference (end_dt, start_dt);
start_dt = g_date_time_add_full (start_dt,
current_year - start_year,
current_month - start_month,
0, 0, 0, 0);
diff = g_date_time_get_day_of_month (self->date) - g_date_time_get_day_of_month (start_dt);
if (diff != 0 ||
current_month != start_month ||
current_year != start_year)
{
g_autoptr (GDateTime) new_start;
new_start = g_date_time_add_days (start_dt, diff);
gcal_event_set_date_start (event, new_start);
/* The event may have a NULL end date, so we have to check it here */
if (end_dt)
{
GDateTime *new_end = g_date_time_add (new_start, timespan);
gcal_event_set_date_end (event, new_end);
g_clear_pointer (&new_end, g_date_time_unref);
}
gcal_manager_update_event (self->manager, event, mod);
}
g_clear_pointer (&start_dt, g_date_time_unref);
out:
/* Cancel the DnD */
gtk_drag_unhighlight (widget);
gtk_drag_finish (context, TRUE, FALSE, time);
return TRUE;
}
static void
gcal_month_cell_drag_leave (GtkWidget *widget,
GdkDragContext *context,
guint time)
{
gtk_drag_unhighlight (widget);
}
static gboolean
gcal_month_cell_button_press_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self = GCAL_MONTH_CELL (widget);
self->pressed = TRUE;
return should_propagate_button_event (widget, event_button);
}
static gboolean
gcal_month_cell_button_release_event (GtkWidget *widget,
GdkEventButton *event_button)
{
GcalMonthCell *self = GCAL_MONTH_CELL (widget);
if (!self->pressed)
return GDK_EVENT_STOP;
self->pressed = FALSE;
return should_propagate_button_event (widget, event_button);
}
static gboolean
gcal_month_cell_draw (GtkWidget *widget,
cairo_t *cr)
{
GtkStyleContext *context;
gint width, height;
width = gtk_widget_get_allocated_width (widget);
height = gtk_widget_get_allocated_height (widget);
context = gtk_widget_get_style_context (widget);
gtk_render_background (context, cr, 0, 0, width, height);
gtk_render_frame (context, cr, 0, 0, width, height);
if (gtk_widget_has_focus (widget))
gtk_render_focus (context, cr, 0, 0, width, height);
return GTK_WIDGET_CLASS (gcal_month_cell_parent_class)->draw (widget, cr);
}
/*
* GObject overrides
*/
static void
gcal_month_cell_finalize (GObject *object)
{
GcalMonthCell *self = (GcalMonthCell *)object;
gcal_clear_datetime (&self->date);
g_clear_object (&self->manager);
G_OBJECT_CLASS (gcal_month_cell_parent_class)->finalize (object);
}
static void
gcal_month_cell_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
GcalMonthCell *self = (GcalMonthCell *) object;
switch (property_id)
{
case PROP_MANAGER:
gcal_month_cell_set_manager (self, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_month_cell_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
GcalMonthCell *self = (GcalMonthCell *) object;
switch (property_id)
{
case PROP_MANAGER:
g_value_set_object (value, self->manager);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
gcal_month_cell_class_init (GcalMonthCellClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->finalize = gcal_month_cell_finalize;
object_class->set_property = gcal_month_cell_set_property;
object_class->get_property = gcal_month_cell_get_property;
widget_class->button_press_event = gcal_month_cell_button_press_event;
widget_class->button_release_event = gcal_month_cell_button_release_event;
widget_class->drag_motion = gcal_month_cell_drag_motion;
widget_class->drag_drop = gcal_month_cell_drag_drop;
widget_class->drag_leave = gcal_month_cell_drag_leave;
widget_class->draw = gcal_month_cell_draw;
signals[SHOW_OVERFLOW] = g_signal_new ("show-overflow",
GCAL_TYPE_MONTH_CELL,
G_SIGNAL_RUN_LAST,
0, NULL, NULL, NULL,
G_TYPE_NONE,
1,
GTK_TYPE_WIDGET);
properties[PROP_MANAGER] = g_param_spec_object ("manager",
"Manager",
"The GcalManager of the application",
GCAL_TYPE_MANAGER,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS);
g_object_class_install_properties (object_class, N_PROPS, properties);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/month-cell.ui");
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, day_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overflow_button);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overflow_label);
gtk_widget_class_bind_template_child (widget_class, GcalMonthCell, overlay);
gtk_widget_class_bind_template_callback (widget_class, enter_notify_event_cb);
gtk_widget_class_bind_template_callback (widget_class, leave_notify_event_cb);
gtk_widget_class_bind_template_callback (widget_class, overflow_button_clicked_cb);
gtk_widget_class_set_css_name (widget_class, "monthcell");
}
static void
gcal_month_cell_init (GcalMonthCell *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
/* Setup the month cell as a drag n' drop destination */
gtk_drag_dest_set (GTK_WIDGET (self),
0,
NULL,
0,
GDK_ACTION_MOVE);
}
GtkWidget*
gcal_month_cell_new (void)
{
return g_object_new (GCAL_TYPE_MONTH_CELL, NULL);
}
GDateTime*
gcal_month_cell_get_date (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), NULL);
return self->date;
}
void
gcal_month_cell_set_date (GcalMonthCell *self,
GDateTime *date)
{
g_autofree gchar *text = NULL;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
gcal_clear_datetime (&self->date);
self->date = g_date_time_ref (date);
/* Day label */
text = g_strdup_printf ("%d", g_date_time_get_day_of_month (date));
gtk_label_set_text (self->day_label, text);
update_style_flags (self);
}
gboolean
gcal_month_cell_get_different_month (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), FALSE);
return self->different_month;
}
void
gcal_month_cell_set_different_month (GcalMonthCell *self,
gboolean different)
{
GtkStyleContext *context;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (self->different_month == different)
return;
self->different_month = different;
context = gtk_widget_get_style_context (GTK_WIDGET (self));
if (different)
gtk_style_context_add_class (context, "out-of-month");
else
gtk_style_context_remove_class (context, "out-of-month");
}
GcalManager*
gcal_month_cell_get_manager (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), NULL);
return self->manager;
}
void
gcal_month_cell_set_manager (GcalMonthCell *self,
GcalManager *manager)
{
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (g_set_object (&self->manager, manager))
{
g_signal_connect_swapped (gcal_manager_get_clock (manager),
"day-changed",
G_CALLBACK (day_changed_cb),
self);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MANAGER]);
}
}
guint
gcal_month_cell_get_overflow (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), 0);
return self->n_overflow;
}
void
gcal_month_cell_set_overflow (GcalMonthCell *self,
guint n_overflow)
{
g_autofree gchar *text = NULL;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
gtk_widget_set_visible (self->overflow_label, n_overflow > 0);
gtk_widget_set_sensitive (self->overflow_button, n_overflow > 0);
if (self->n_overflow == n_overflow)
return;
self->n_overflow = n_overflow;
text = g_strdup_printf (g_dngettext (GETTEXT_PACKAGE, "Other event", "Other %d events", n_overflow), n_overflow);
gtk_label_set_text (GTK_LABEL (self->overflow_label), text);
}
gint
gcal_month_cell_get_real_height (GcalMonthCell *self)
{
GtkStyleContext *context;
GtkBorder padding;
GtkBorder border;
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), -1);
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_style_context_get_padding (context, gtk_style_context_get_state (context), &padding);
gtk_style_context_get_border (context, gtk_style_context_get_state (context), &border);
return gtk_widget_get_allocated_height (GTK_WIDGET (self)) -
gtk_widget_get_allocated_height (self->overflow_button) -
padding.top - padding.bottom -
border.top - border.bottom;
}
gboolean
gcal_month_cell_get_selected (GcalMonthCell *self)
{
g_return_val_if_fail (GCAL_IS_MONTH_CELL (self), FALSE);
return self->selected;
}
void
gcal_month_cell_set_selected (GcalMonthCell *self,
gboolean selected)
{
GtkStateFlags flags;
g_return_if_fail (GCAL_IS_MONTH_CELL (self));
if (self->selected == selected)
return;
self->selected = selected;
/* Update style context state */
flags = gtk_widget_get_state_flags (GTK_WIDGET (self));
if (selected)
flags |= GTK_STATE_FLAG_SELECTED;
else
flags &= ~GTK_STATE_FLAG_SELECTED;
gtk_widget_set_state_flags (GTK_WIDGET (self), flags, TRUE);
gtk_widget_queue_resize (GTK_WIDGET (self));
}
+64
View File
@@ -0,0 +1,64 @@
/* gcal-month-cell.h
*
* Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GCAL_MONTH_CELL_H
#define GCAL_MONTH_CELL_H
#include "gcal-manager.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GCAL_TYPE_MONTH_CELL (gcal_month_cell_get_type())
G_DECLARE_FINAL_TYPE (GcalMonthCell, gcal_month_cell, GCAL, MONTH_CELL, GtkEventBox)
GtkWidget* gcal_month_cell_new (void);
GDateTime* gcal_month_cell_get_date (GcalMonthCell *self);
void gcal_month_cell_set_date (GcalMonthCell *self,
GDateTime *date);
gboolean gcal_month_cell_get_different_month (GcalMonthCell *self);
void gcal_month_cell_set_different_month (GcalMonthCell *self,
gboolean out);
GcalManager* gcal_month_cell_get_manager (GcalMonthCell *self);
void gcal_month_cell_set_manager (GcalMonthCell *self,
GcalManager *manager);
guint gcal_month_cell_get_overflow (GcalMonthCell *self);
void gcal_month_cell_set_overflow (GcalMonthCell *self,
guint n_overflow);
gint gcal_month_cell_get_real_height (GcalMonthCell *self);
gboolean gcal_month_cell_get_selected (GcalMonthCell *self);
void gcal_month_cell_set_selected (GcalMonthCell *self,
gboolean selected);
G_END_DECLS
#endif /* GCAL_MONTH_VIEW_CELL_H */
+652 -1323
View File
File diff suppressed because it is too large Load Diff
+2 -2
View File
@@ -1065,7 +1065,7 @@ draw_navigator (GcalYearView *year_view,
/* read header from CSS code related to the view */
gtk_style_context_save (context);
gtk_style_context_add_class (context, "start-header");
gtk_style_context_add_class (context, "primary-label");
header_str = g_strdup_printf ("%d", year_view->date->year);
gtk_style_context_get (context, state_flags, "font", &font_desc, NULL);
@@ -1348,7 +1348,7 @@ calculate_sizes (GcalYearView *self)
/* get header info from CSS */
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_style_context_save (context);
gtk_style_context_add_class (context, "start-header");
gtk_style_context_add_class (context, "primary-label");
gtk_style_context_get (context, gtk_style_context_get_state (context),
"padding-top", &padding_top,
"padding-bottom", &padding_bottom,