build: removed unused/faulty code
This cleaning is made in order to merge this branch into master as soon as possible. The implementation of GcalDayView is planned to go on the same lines as GcalWeekView but for two days alone, so much of the code of the latter could be reused. The approach of using shallow container and kinda layout manager objects inside GcalDayView didn't worked that well for my expertise at this time.
This commit is contained in:
@@ -27,14 +27,10 @@ gnome_calendar_SOURCES = \
|
||||
main.c \
|
||||
gcal-application.h \
|
||||
gcal-application.c \
|
||||
gcal-floating-container.c \
|
||||
gcal-floating-container.h \
|
||||
gcal-window.h \
|
||||
gcal-window.c \
|
||||
gcal-view.c \
|
||||
gcal-view.h \
|
||||
gcal-day-view.c \
|
||||
gcal-day-view.h \
|
||||
gcal-month-view.c \
|
||||
gcal-month-view.h \
|
||||
gcal-week-view.c \
|
||||
@@ -55,12 +51,6 @@ gnome_calendar_SOURCES = \
|
||||
gcal-manager.h \
|
||||
gcal-nav-bar.h \
|
||||
gcal-nav-bar.c \
|
||||
gcal-viewport.c \
|
||||
gcal-viewport.h \
|
||||
gcal-all-day-grid.c \
|
||||
gcal-all-day-grid.h \
|
||||
gcal-days-grid.c \
|
||||
gcal-days-grid.h \
|
||||
gcal-utils.c \
|
||||
gcal-utils.h
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* gcal-all-day-grid.h
|
||||
*
|
||||
* Copyright (C) 2012 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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_ALL_DAY_GRID_H__
|
||||
#define __GCAL_ALL_DAY_GRID_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_ALL_DAY_GRID (gcal_all_day_grid_get_type ())
|
||||
#define GCAL_ALL_DAY_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_ALL_DAY_GRID, GcalAllDayGrid))
|
||||
#define GCAL_ALL_DAY_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_ALL_DAY_GRID, GcalAllDayGridClass))
|
||||
#define GCAL_IS_ALL_DAY_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_ALL_DAY_GRID))
|
||||
#define GCAL_IS_ALL_DAY_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_ALL_DAY_GRID))
|
||||
#define GCAL_ALL_DAY_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_ALL_DAY_GRID, GcalAllDayGridClass))
|
||||
|
||||
typedef struct _GcalAllDayGrid GcalAllDayGrid;
|
||||
typedef struct _GcalAllDayGridClass GcalAllDayGridClass;
|
||||
|
||||
struct _GcalAllDayGrid
|
||||
{
|
||||
GtkContainer parent;
|
||||
};
|
||||
|
||||
struct _GcalAllDayGridClass
|
||||
{
|
||||
GtkContainerClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*marked) (guint start_cell, guint end_cell);
|
||||
};
|
||||
|
||||
GType gcal_all_day_grid_get_type (void);
|
||||
|
||||
GtkWidget* gcal_all_day_grid_new (guint columns);
|
||||
|
||||
void gcal_all_day_grid_set_column_headers (GcalAllDayGrid *all_day,
|
||||
...);
|
||||
|
||||
void gcal_all_day_grid_place (GcalAllDayGrid *all_day,
|
||||
GtkWidget *widget,
|
||||
guint column_idx,
|
||||
guint column_span);
|
||||
|
||||
GtkWidget* gcal_all_day_grid_get_by_uuid (GcalAllDayGrid *all_day,
|
||||
const gchar *uuid);
|
||||
|
||||
void gcal_all_day_grid_clear_marks (GcalAllDayGrid *all_day);
|
||||
|
||||
void gcal_all_day_grid_get_cell_position (GcalAllDayGrid *all_day,
|
||||
guint cell,
|
||||
gint *x,
|
||||
gint *y);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_ALL_DAY_GRID_H__ */
|
||||
@@ -1,690 +0,0 @@
|
||||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* gcal-day-view.c
|
||||
*
|
||||
* Copyright (C) 2013 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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/>.
|
||||
*/
|
||||
|
||||
#include "gcal-day-view.h"
|
||||
#include "gcal-all-day-grid.h"
|
||||
#include "gcal-days-grid.h"
|
||||
#include "gcal-viewport.h"
|
||||
#include "gcal-utils.h"
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-event-widget.h"
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
#include <libecal/libecal.h>
|
||||
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_DATE
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* property */
|
||||
icaltimetype *date;
|
||||
|
||||
GtkWidget *viewport;
|
||||
GtkWidget *fold_button;
|
||||
|
||||
/* events widgets parents */
|
||||
GtkWidget *all_day_grid;
|
||||
GtkWidget *day_grid;
|
||||
} GcalDayViewPrivate;
|
||||
|
||||
static void viewport_shown (GtkWidget *widget,
|
||||
gpointer user_data);
|
||||
|
||||
static void days_grid_clicked (GcalDaysGrid *days_grid,
|
||||
guint start_cell,
|
||||
guint end_cell,
|
||||
gpointer user_data);
|
||||
|
||||
static void all_day_grid_clicked (GcalAllDayGrid *all_day_grid,
|
||||
guint start_cell,
|
||||
guint end_cell,
|
||||
gpointer user_data);
|
||||
|
||||
static void gcal_view_interface_init (GcalViewIface *iface);
|
||||
|
||||
static void gcal_day_view_constructed (GObject *object);
|
||||
|
||||
static void gcal_day_view_finalize (GObject *object);
|
||||
|
||||
static void gcal_day_view_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gcal_day_view_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec);
|
||||
|
||||
static void gcal_day_view_add (GtkContainer *container,
|
||||
GtkWidget *widget);
|
||||
|
||||
static void gcal_day_view_remove (GtkContainer *container,
|
||||
GtkWidget *widget);
|
||||
|
||||
static icaltimetype* gcal_day_view_get_initial_date (GcalView *view);
|
||||
|
||||
static icaltimetype* gcal_day_view_get_final_date (GcalView *view);
|
||||
|
||||
static void gcal_day_view_mark_current_unit (GcalView *view,
|
||||
gint *x,
|
||||
gint *y);
|
||||
|
||||
static void gcal_day_view_clear_marks (GcalView *view);
|
||||
|
||||
static gchar* gcal_day_view_get_left_header (GcalView *view);
|
||||
|
||||
static gchar* gcal_day_view_get_right_header (GcalView *view);
|
||||
|
||||
static gboolean gcal_day_view_draw_event (GcalView *view,
|
||||
icaltimetype *start_date,
|
||||
icaltimetype *end_date);
|
||||
|
||||
static GtkWidget* gcal_day_view_get_by_uuid (GcalView *view,
|
||||
const gchar *uuid);
|
||||
|
||||
static void gcal_day_view_clear (GcalView *view);
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GcalDayView,
|
||||
gcal_day_view,
|
||||
GTK_TYPE_GRID,
|
||||
G_ADD_PRIVATE (GcalDayView)
|
||||
G_IMPLEMENT_INTERFACE (GCAL_TYPE_VIEW,
|
||||
gcal_view_interface_init));
|
||||
|
||||
static void
|
||||
viewport_shown (GtkWidget *widget,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
icaltimetype date;
|
||||
gdouble value;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (user_data));
|
||||
|
||||
if (priv->date == NULL)
|
||||
return;
|
||||
|
||||
date = icaltime_current_time_with_zone (priv->date->zone);
|
||||
|
||||
/* FIXME: This isn't working as expected */
|
||||
/* - 2.0 is spacing to the let running hour show */
|
||||
value = ((gdouble) date.hour - 2.0) / 24.0;
|
||||
|
||||
g_debug ("Getting into here, with value: %f", value);
|
||||
gcal_viewport_scroll_to (GCAL_VIEWPORT (priv->viewport), value);
|
||||
}
|
||||
|
||||
static void
|
||||
days_grid_clicked (GcalDaysGrid *days_grid,
|
||||
guint start_cell,
|
||||
guint end_cell,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
icaltimetype *start_date;
|
||||
icaltimetype *end_date;
|
||||
|
||||
gint x, y;
|
||||
gint new_x, new_y;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (user_data));
|
||||
|
||||
g_debug ("Cells positions: %d, %d", start_cell, end_cell);
|
||||
|
||||
start_date = gcal_dup_icaltime (priv->date);
|
||||
end_date = gcal_dup_icaltime (priv->date);
|
||||
|
||||
start_date->hour = start_cell / 2;
|
||||
start_date->minute = 0;
|
||||
start_date->second = 0;
|
||||
*start_date = icaltime_normalize (*start_date);
|
||||
if (start_cell % 2 == 1)
|
||||
start_date->minute = 30;
|
||||
|
||||
end_date->hour = end_cell / 2;
|
||||
end_date->minute = 0;
|
||||
end_date->second = 0;
|
||||
if (end_cell % 2 == 1)
|
||||
end_date->hour++;
|
||||
else
|
||||
end_date->minute = 30;
|
||||
*end_date = icaltime_normalize (*end_date);
|
||||
|
||||
gcal_days_grid_get_cell_position (GCAL_DAYS_GRID (priv->day_grid),
|
||||
start_cell, &x, &y);
|
||||
g_debug ("Click Position: %d, %d", x, y);
|
||||
|
||||
gtk_widget_translate_coordinates (priv->day_grid,
|
||||
GTK_WIDGET (user_data),
|
||||
x, y,
|
||||
&new_x, &new_y);
|
||||
g_debug ("Translated Click Position: %d, %d", new_x, new_y);
|
||||
|
||||
g_signal_emit_by_name (GCAL_VIEW (user_data),
|
||||
"create-event",
|
||||
start_date, end_date,
|
||||
(gdouble) new_x, (gdouble) new_y);
|
||||
|
||||
g_free (start_date);
|
||||
g_free (end_date);
|
||||
}
|
||||
|
||||
static void
|
||||
all_day_grid_clicked (GcalAllDayGrid *all_day_grid,
|
||||
guint start_cell,
|
||||
guint end_cell,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
icaltimetype *start_date;
|
||||
icaltimetype *end_date;
|
||||
|
||||
gint x, y;
|
||||
gint new_x, new_y;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (user_data));
|
||||
|
||||
g_debug ("Receiving marked signal in day-view from all-day-grid");
|
||||
g_debug ("Cells positions: %d, %d", start_cell, end_cell);
|
||||
|
||||
start_date = gcal_dup_icaltime (priv->date);
|
||||
end_date = gcal_dup_icaltime (priv->date);
|
||||
|
||||
start_date->is_date = 1;
|
||||
end_date->is_date = 1;
|
||||
|
||||
if (start_cell != end_cell)
|
||||
{
|
||||
end_date->day++;
|
||||
*end_date = icaltime_normalize (*end_date);
|
||||
}
|
||||
else if (start_cell == 1)
|
||||
{
|
||||
start_date->day++;
|
||||
*start_date = icaltime_normalize (*start_date);
|
||||
end_date->day++;
|
||||
*end_date = icaltime_normalize (*end_date);
|
||||
}
|
||||
|
||||
gcal_all_day_grid_get_cell_position (GCAL_ALL_DAY_GRID (priv->all_day_grid),
|
||||
start_cell, &x, &y);
|
||||
g_debug ("Click Position: %d, %d", x, y);
|
||||
|
||||
gtk_widget_translate_coordinates (priv->all_day_grid,
|
||||
GTK_WIDGET (user_data),
|
||||
x, y,
|
||||
&new_x, &new_y);
|
||||
g_debug ("Translated Click Position: %d, %d", new_x, new_y);
|
||||
|
||||
g_signal_emit_by_name (GCAL_VIEW (user_data),
|
||||
"create-event",
|
||||
start_date, end_date,
|
||||
(gdouble) new_x, (gdouble) new_y);
|
||||
|
||||
g_debug ("start_date: %s", icaltime_as_ical_string (*start_date));
|
||||
g_debug ("end_date: %s", icaltime_as_ical_string (*end_date));
|
||||
|
||||
g_free (start_date);
|
||||
g_free (end_date);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_class_init (GcalDayViewClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GtkContainerClass *container_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->constructed = gcal_day_view_constructed;
|
||||
object_class->finalize = gcal_day_view_finalize;
|
||||
object_class->set_property = gcal_day_view_set_property;
|
||||
object_class->get_property = gcal_day_view_get_property;
|
||||
|
||||
container_class = GTK_CONTAINER_CLASS (klass);
|
||||
container_class->add = gcal_day_view_add;
|
||||
container_class->remove = gcal_day_view_remove;
|
||||
/* FIXME: Uncomment stuff here */
|
||||
/* gtk_container_class_handle_border_width (container_class); */
|
||||
|
||||
g_object_class_override_property (object_class, PROP_DATE, "active-date");
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_init (GcalDayView *self)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_view_interface_init (GcalViewIface *iface)
|
||||
{
|
||||
/* New API */
|
||||
iface->get_initial_date = gcal_day_view_get_initial_date;
|
||||
iface->get_final_date = gcal_day_view_get_final_date;
|
||||
|
||||
iface->mark_current_unit = gcal_day_view_mark_current_unit;
|
||||
iface->clear_marks = gcal_day_view_clear_marks;
|
||||
|
||||
iface->get_left_header = gcal_day_view_get_left_header;
|
||||
iface->get_right_header = gcal_day_view_get_right_header;
|
||||
|
||||
iface->draw_event = gcal_day_view_draw_event;
|
||||
iface->get_by_uuid = gcal_day_view_get_by_uuid;
|
||||
iface->clear = gcal_day_view_clear;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_constructed (GObject *object)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (object));
|
||||
|
||||
if (G_OBJECT_CLASS (gcal_day_view_parent_class)->constructed != NULL)
|
||||
G_OBJECT_CLASS (gcal_day_view_parent_class)->constructed (object);
|
||||
|
||||
priv->fold_button = gtk_button_new_with_label (_("Fold"));
|
||||
g_object_set (priv->fold_button,
|
||||
"valign", GTK_ALIGN_END,
|
||||
"margin", 6,
|
||||
NULL);
|
||||
gtk_style_context_add_class (
|
||||
gtk_widget_get_style_context (priv->fold_button),
|
||||
"nav-button");
|
||||
gtk_grid_attach (GTK_GRID (object), priv->fold_button, 0, 0, 1, 1);
|
||||
|
||||
/* event widget holders */
|
||||
priv->all_day_grid = gcal_all_day_grid_new (2);
|
||||
gcal_all_day_grid_set_column_headers (GCAL_ALL_DAY_GRID (priv->all_day_grid),
|
||||
_("Today"),
|
||||
_("Tomorrow"));
|
||||
gtk_widget_set_size_request (priv->all_day_grid, -1, 64);
|
||||
gtk_widget_set_hexpand (priv->all_day_grid, TRUE);
|
||||
|
||||
priv->day_grid = gcal_days_grid_new (2);
|
||||
gcal_days_grid_set_preferred_cell_height (GCAL_DAYS_GRID (priv->day_grid), 60);
|
||||
|
||||
gtk_widget_set_hexpand (priv->day_grid, TRUE);
|
||||
gtk_widget_set_vexpand (priv->day_grid, TRUE);
|
||||
|
||||
gtk_grid_attach (GTK_GRID (object), priv->all_day_grid, 1, 0, 1, 1);
|
||||
|
||||
priv->viewport = gcal_viewport_new ();
|
||||
gcal_viewport_add (GCAL_VIEWPORT (priv->viewport), priv->day_grid);
|
||||
gtk_grid_attach (GTK_GRID (object), priv->viewport, 0, 1, 2, 1);
|
||||
|
||||
/* binding sizes */
|
||||
gtk_widget_set_size_request (
|
||||
priv->fold_button,
|
||||
gcal_days_grid_get_scale_width (GCAL_DAYS_GRID (priv->day_grid)) - 12,
|
||||
-1);
|
||||
|
||||
gtk_widget_show_all (GTK_WIDGET (object));
|
||||
|
||||
/* signal handling */
|
||||
g_signal_connect_after (object, "map", G_CALLBACK (viewport_shown), object);
|
||||
g_signal_connect (priv->day_grid, "marked",
|
||||
G_CALLBACK (days_grid_clicked), object);
|
||||
g_signal_connect (priv->all_day_grid, "marked",
|
||||
G_CALLBACK (all_day_grid_clicked), object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_finalize (GObject *object)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (object));
|
||||
|
||||
if (priv->date != NULL)
|
||||
g_free (priv->date);
|
||||
|
||||
/* Chain up to parent's finalize() method. */
|
||||
G_OBJECT_CLASS (gcal_day_view_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_set_property (GObject *object,
|
||||
guint property_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_DATE:
|
||||
if (priv->date != NULL)
|
||||
g_free (priv->date);
|
||||
|
||||
priv->date = g_value_dup_boxed (value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_get_property (GObject *object,
|
||||
guint property_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (object));
|
||||
|
||||
switch (property_id)
|
||||
{
|
||||
case PROP_DATE:
|
||||
g_value_set_boxed (value, priv->date);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* GtkContainer API */
|
||||
static void
|
||||
gcal_day_view_add (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
icaltimetype *tomorrow;
|
||||
icaltimetype *dt_start;
|
||||
icaltimetype *dt_end;
|
||||
gchar* summ;
|
||||
|
||||
g_return_if_fail (GCAL_IS_EVENT_WIDGET (widget));
|
||||
g_return_if_fail (gtk_widget_get_parent (widget) == NULL);
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (container));
|
||||
|
||||
summ = gcal_event_widget_get_summary (GCAL_EVENT_WIDGET (widget));
|
||||
|
||||
tomorrow = gcal_day_view_get_final_date (GCAL_VIEW (container));
|
||||
dt_start = gcal_event_widget_get_date (GCAL_EVENT_WIDGET (widget));
|
||||
dt_end = gcal_event_widget_get_end_date (GCAL_EVENT_WIDGET (widget));
|
||||
|
||||
/* FIXME: recheck conditions to add, what, where */
|
||||
/* Maybe, should be good to add, inside days views only contained events */
|
||||
g_debug ("[processing] %s from %s to %s",
|
||||
summ,
|
||||
icaltime_as_ical_string (*dt_start),
|
||||
icaltime_as_ical_string (*dt_end));
|
||||
|
||||
if (! gcal_event_widget_get_all_day (GCAL_EVENT_WIDGET (widget)) &&
|
||||
(dt_start->day == dt_end->day) &&
|
||||
(dt_start->day == priv->date->day ||
|
||||
dt_start->day == tomorrow->day))
|
||||
{
|
||||
g_debug ("[days-grid] %s from %s to %s",
|
||||
summ,
|
||||
icaltime_as_ical_string (*dt_start),
|
||||
icaltime_as_ical_string (*dt_end));
|
||||
|
||||
gcal_days_grid_place (GCAL_DAYS_GRID (priv->day_grid),
|
||||
widget,
|
||||
priv->date->day == dt_start->day ? 0 : 1,
|
||||
dt_start->hour * 2 + (dt_start->minute / 30),
|
||||
dt_end->hour * 2 + (dt_end->minute / 30)); /* FIXME Include half hour and length */
|
||||
}
|
||||
else
|
||||
{
|
||||
gboolean start_tomorrow;
|
||||
guint length;
|
||||
g_debug ("[all-day-grid] %s from %s to %s",
|
||||
summ,
|
||||
icaltime_as_ical_string (*dt_start),
|
||||
icaltime_as_ical_string (*dt_end));
|
||||
start_tomorrow = icaltime_compare_date_only (*dt_start, *tomorrow) == 0;
|
||||
|
||||
if (start_tomorrow)
|
||||
length = 1;
|
||||
else if (dt_start->day != dt_end->day)
|
||||
length = 2;
|
||||
else
|
||||
length = 1;
|
||||
gcal_all_day_grid_place (GCAL_ALL_DAY_GRID (priv->all_day_grid),
|
||||
widget,
|
||||
start_tomorrow ? 1 : 0, length);
|
||||
}
|
||||
|
||||
g_free (tomorrow);
|
||||
g_free (dt_start);
|
||||
g_free (dt_end);
|
||||
g_free (summ);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_remove (GtkContainer *container,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (container));
|
||||
|
||||
if (gtk_widget_get_parent (widget) == (GtkWidget*) container)
|
||||
{
|
||||
GTK_CONTAINER_CLASS (gcal_day_view_parent_class)->remove (container,
|
||||
widget);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_container_remove (GTK_CONTAINER (priv->all_day_grid), widget);
|
||||
gtk_container_remove (GTK_CONTAINER (priv->day_grid), widget);
|
||||
}
|
||||
}
|
||||
|
||||
/* GcalView API */
|
||||
static icaltimetype*
|
||||
gcal_day_view_get_initial_date (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
icaltimetype *new_date;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
new_date = g_new0 (icaltimetype, 1);
|
||||
*new_date = *(priv->date);
|
||||
new_date->hour = 0;
|
||||
new_date->minute = 0;
|
||||
new_date->second = 0;
|
||||
|
||||
return new_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_day_view_get_final_date:
|
||||
* @view: a #GcalDayView
|
||||
*
|
||||
* Returns the date of "tomorrow" at 23:59
|
||||
*
|
||||
* Returns:
|
||||
**/
|
||||
static icaltimetype*
|
||||
gcal_day_view_get_final_date (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
icaltimetype *new_date;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
new_date = g_new0 (icaltimetype, 1);
|
||||
*new_date = *(priv->date);
|
||||
|
||||
icaltime_adjust (new_date, 1, 0, 0, 0);
|
||||
|
||||
new_date->hour = 23;
|
||||
new_date->minute = 59;
|
||||
new_date->second = 59;
|
||||
|
||||
return new_date;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_mark_current_unit (GcalView *view,
|
||||
gint *x,
|
||||
gint *y)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
guint cell;
|
||||
gint orig_x, orig_y;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
|
||||
cell = priv->date->hour * 2 + (priv->date->minute / 30);
|
||||
gcal_days_grid_mark_cell (GCAL_DAYS_GRID (priv->day_grid), cell);
|
||||
gcal_days_grid_get_cell_position (GCAL_DAYS_GRID (priv->day_grid),
|
||||
cell, &orig_x, &orig_y);
|
||||
g_debug ("Click Position: %d, %d", orig_x, orig_y);
|
||||
|
||||
gtk_widget_translate_coordinates (priv->day_grid,
|
||||
GTK_WIDGET (view),
|
||||
orig_x, orig_y,
|
||||
x, y);
|
||||
g_debug ("Translated Click Position: %d, %d", *x, *y);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_clear_marks (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
gcal_days_grid_clear_marks (GCAL_DAYS_GRID (priv->day_grid));
|
||||
gcal_all_day_grid_clear_marks (GCAL_ALL_DAY_GRID (priv->all_day_grid));
|
||||
}
|
||||
|
||||
static gchar*
|
||||
gcal_day_view_get_left_header (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
gchar str_date[64];
|
||||
|
||||
struct tm tm_date;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
|
||||
tm_date = icaltimetype_to_tm (priv->date);
|
||||
e_utf8_strftime_fix_am_pm (str_date, 64, "%A %B", &tm_date);
|
||||
|
||||
return g_strdup_printf ("%s, %d", str_date, priv->date->day);
|
||||
}
|
||||
|
||||
static gchar*
|
||||
gcal_day_view_get_right_header (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
|
||||
return g_strdup_printf ("%d", priv->date->year);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_day_view_draw_event (GcalView *view,
|
||||
icaltimetype *start_date,
|
||||
icaltimetype *end_date)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
icaltimetype *first_day;
|
||||
icaltimetype *last_day;
|
||||
gint left_boundary;
|
||||
gint right_boundary;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
first_day = gcal_day_view_get_initial_date (view);
|
||||
last_day = gcal_day_view_get_final_date (view);
|
||||
|
||||
if (priv->date == NULL)
|
||||
return FALSE;
|
||||
|
||||
/* XXX: Check for date_only comparison since might drop timezone info */
|
||||
left_boundary = icaltime_compare_date_only (*end_date, *first_day);
|
||||
right_boundary = icaltime_compare_date_only (*last_day, *start_date);
|
||||
|
||||
if (left_boundary == -1 || right_boundary == -1)
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GtkWidget*
|
||||
gcal_day_view_get_by_uuid (GcalView *view,
|
||||
const gchar *uuid)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
GtkWidget *widget;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
|
||||
widget =
|
||||
gcal_all_day_grid_get_by_uuid (GCAL_ALL_DAY_GRID (priv->all_day_grid),
|
||||
uuid);
|
||||
if (widget != NULL)
|
||||
return widget;
|
||||
|
||||
widget =
|
||||
gcal_days_grid_get_by_uuid (GCAL_DAYS_GRID (priv->day_grid),
|
||||
uuid);
|
||||
if (widget != NULL)
|
||||
return widget;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_day_view_clear (GcalView *view)
|
||||
{
|
||||
GcalDayViewPrivate *priv;
|
||||
|
||||
priv = gcal_day_view_get_instance_private (GCAL_DAY_VIEW (view));
|
||||
|
||||
gtk_container_foreach (GTK_CONTAINER (priv->all_day_grid),
|
||||
(GtkCallback) gtk_widget_destroy, NULL);
|
||||
gtk_container_foreach (GTK_CONTAINER (priv->day_grid),
|
||||
(GtkCallback) gtk_widget_destroy, NULL);
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
/**
|
||||
* gcal_day_view_new:
|
||||
* @date:
|
||||
*
|
||||
* Since: 0.1
|
||||
* Return value: A new #GcalDayView
|
||||
* Returns: (transfer full):
|
||||
**/
|
||||
GtkWidget*
|
||||
gcal_day_view_new (void)
|
||||
{
|
||||
return g_object_new (GCAL_TYPE_DAY_VIEW, NULL);
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* gcal-day-view.h
|
||||
*
|
||||
* Copyright (C) 2013 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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_DAY_VIEW_H__
|
||||
#define __GCAL_DAY_VIEW_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_DAY_VIEW (gcal_day_view_get_type ())
|
||||
#define GCAL_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_DAY_VIEW, GcalDayView))
|
||||
#define GCAL_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_DAY_VIEW, GcalDayViewClass))
|
||||
#define GCAL_IS_DAY_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_DAY_VIEW))
|
||||
#define GCAL_IS_DAY_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_DAY_VIEW))
|
||||
#define GCAL_DAY_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_DAY_VIEW, GcalDayViewClass))
|
||||
|
||||
typedef struct _GcalDayView GcalDayView;
|
||||
typedef struct _GcalDayViewClass GcalDayViewClass;
|
||||
|
||||
struct _GcalDayView
|
||||
{
|
||||
GtkGrid parent;
|
||||
};
|
||||
|
||||
struct _GcalDayViewClass
|
||||
{
|
||||
GtkGridClass parent_class;
|
||||
};
|
||||
|
||||
GType gcal_day_view_get_type (void);
|
||||
|
||||
GtkWidget* gcal_day_view_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_DAY_VIEW_H__ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* gcal-days-grid.h
|
||||
*
|
||||
* Copyright (C) 2012 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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_DAYS_GRID_H__
|
||||
#define __GCAL_DAYS_GRID_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_DAYS_GRID (gcal_days_grid_get_type ())
|
||||
#define GCAL_DAYS_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_DAYS_GRID, GcalDaysGrid))
|
||||
#define GCAL_DAYS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_DAYS_GRID, GcalDaysGridClass))
|
||||
#define GCAL_IS_DAYS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_DAYS_GRID))
|
||||
#define GCAL_IS_DAYS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_DAYS_GRID))
|
||||
#define GCAL_DAYS_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_DAYS_GRID, GcalDaysGridClass))
|
||||
|
||||
typedef struct _GcalDaysGrid GcalDaysGrid;
|
||||
typedef struct _GcalDaysGridClass GcalDaysGridClass;
|
||||
|
||||
struct _GcalDaysGrid
|
||||
{
|
||||
GtkContainer parent;
|
||||
};
|
||||
|
||||
struct _GcalDaysGridClass
|
||||
{
|
||||
GtkContainerClass parent_class;
|
||||
|
||||
/* signals */
|
||||
void (*marked) (guint start_cell, guint end_cell);
|
||||
};
|
||||
|
||||
GType gcal_days_grid_get_type (void);
|
||||
|
||||
GtkWidget* gcal_days_grid_new (guint columns);
|
||||
|
||||
void gcal_days_grid_set_preferred_cell_height (GcalDaysGrid *days_grid,
|
||||
guint cell_height);
|
||||
|
||||
guint gcal_days_grid_get_scale_width (GcalDaysGrid *days_grid);
|
||||
|
||||
void gcal_days_grid_place (GcalDaysGrid *days_grid,
|
||||
GtkWidget *widget,
|
||||
guint column_idx,
|
||||
guint start_cell,
|
||||
guint end_cell);
|
||||
|
||||
/* GcalView API helpers */
|
||||
GtkWidget* gcal_days_grid_get_by_uuid (GcalDaysGrid *days_grid,
|
||||
const gchar *uuid);
|
||||
|
||||
void gcal_days_grid_clear_marks (GcalDaysGrid *days_grid);
|
||||
|
||||
void gcal_days_grid_mark_cell (GcalDaysGrid *days_grid,
|
||||
guint cell);
|
||||
|
||||
void gcal_days_grid_get_cell_position (GcalDaysGrid *days_grid,
|
||||
guint cell,
|
||||
gint *x,
|
||||
gint *y);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_DAYS_GRID_H__ */
|
||||
@@ -1,337 +0,0 @@
|
||||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* gcal-floating-container.c
|
||||
* Copyright (C) 2012 Erick Pérez Castellanos <erickpc@gnome.org>
|
||||
*
|
||||
* gnome-calendar 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.
|
||||
*
|
||||
* gnome-calendar 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/>.
|
||||
*/
|
||||
|
||||
#include "gcal-floating-container.h"
|
||||
|
||||
struct _GcalFloatingContainerPrivate
|
||||
{
|
||||
guint border;
|
||||
};
|
||||
|
||||
static void gcal_floating_container_get_preferred_width (GtkWidget *widget,
|
||||
gint *minimum_width,
|
||||
gint *natural_width);
|
||||
|
||||
static void gcal_floating_container_get_preferred_height_for_width (GtkWidget *widget,
|
||||
gint width,
|
||||
gint *minimum_height,
|
||||
gint *natural_height);
|
||||
|
||||
static void gcal_floating_container_get_preferred_height (GtkWidget *widget,
|
||||
gint *minimum_height,
|
||||
gint *natural_height);
|
||||
|
||||
static void gcal_floating_container_get_preferred_width_for_height (GtkWidget *widget,
|
||||
gint height,
|
||||
gint *minimum_width,
|
||||
gint *natural_width);
|
||||
|
||||
static void gcal_floating_container_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation);
|
||||
|
||||
static gboolean gcal_floating_container_draw (GtkWidget *widget,
|
||||
cairo_t *cr);
|
||||
|
||||
static void gcal_floating_container_add (GtkContainer *container,
|
||||
GtkWidget *child);
|
||||
|
||||
static void gcal_floating_container_get_padding_and_border (GtkWidget *widget,
|
||||
GtkBorder *border);
|
||||
|
||||
G_DEFINE_TYPE(GcalFloatingContainer, gcal_floating_container, GTK_TYPE_BIN)
|
||||
|
||||
static void
|
||||
gcal_floating_container_class_init (GcalFloatingContainerClass *klass)
|
||||
{
|
||||
GtkWidgetClass* widget_class;
|
||||
GtkContainerClass *container_class;
|
||||
|
||||
widget_class = GTK_WIDGET_CLASS (klass);
|
||||
container_class = GTK_CONTAINER_CLASS (klass);
|
||||
|
||||
widget_class->get_preferred_width =
|
||||
gcal_floating_container_get_preferred_width;
|
||||
widget_class->get_preferred_height_for_width =
|
||||
gcal_floating_container_get_preferred_height_for_width;
|
||||
widget_class->get_preferred_height =
|
||||
gcal_floating_container_get_preferred_height;
|
||||
widget_class->get_preferred_width_for_height =
|
||||
gcal_floating_container_get_preferred_width_for_height;
|
||||
widget_class->size_allocate = gcal_floating_container_size_allocate;
|
||||
widget_class->draw = gcal_floating_container_draw;
|
||||
|
||||
container_class->add = gcal_floating_container_add;
|
||||
|
||||
g_type_class_add_private ((gpointer)klass, sizeof (GcalFloatingContainerPrivate));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
gcal_floating_container_init (GcalFloatingContainer *self)
|
||||
{
|
||||
gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
|
||||
|
||||
self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
|
||||
GCAL_TYPE_FLOATING_CONTAINER,
|
||||
GcalFloatingContainerPrivate);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_get_preferred_width (GtkWidget *widget,
|
||||
gint *minimum_width,
|
||||
gint *natural_width)
|
||||
{
|
||||
gint child_min, child_nat;
|
||||
GtkWidget *child;
|
||||
GtkBorder padding;
|
||||
gint minimum, natural;
|
||||
|
||||
gcal_floating_container_get_padding_and_border (widget, &padding);
|
||||
|
||||
minimum = 0;
|
||||
natural = 0;
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child && gtk_widget_get_visible (child))
|
||||
{
|
||||
gtk_widget_get_preferred_width (child,
|
||||
&child_min, &child_nat);
|
||||
minimum += child_min;
|
||||
natural += child_nat;
|
||||
}
|
||||
|
||||
minimum += padding.left + padding.right;
|
||||
natural += padding.left + padding.right;
|
||||
|
||||
if (minimum_width)
|
||||
*minimum_width = minimum;
|
||||
|
||||
if (natural_width)
|
||||
*natural_width = natural;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_get_preferred_height_for_width (GtkWidget *widget,
|
||||
gint width,
|
||||
gint *minimum_height,
|
||||
gint *natural_height)
|
||||
{
|
||||
gint child_min, child_nat, child_width;
|
||||
GtkWidget *child;
|
||||
GtkBorder padding;
|
||||
gint minimum;
|
||||
gint natural;
|
||||
|
||||
gcal_floating_container_get_padding_and_border (widget, &padding);
|
||||
|
||||
minimum = 0;
|
||||
natural = 0;
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child && gtk_widget_get_visible (child))
|
||||
{
|
||||
child_width = width - padding.left - padding.top;
|
||||
|
||||
gtk_widget_get_preferred_height_for_width (child, child_width,
|
||||
&child_min, &child_nat);
|
||||
minimum = MAX (minimum, child_min);
|
||||
natural = MAX (natural, child_nat);
|
||||
}
|
||||
|
||||
minimum += padding.top + padding.top;
|
||||
natural += padding.top + padding.top;
|
||||
|
||||
if (minimum_height)
|
||||
*minimum_height = minimum;
|
||||
|
||||
if (natural_height)
|
||||
*natural_height = natural;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_get_preferred_height (GtkWidget *widget,
|
||||
gint *minimum_height,
|
||||
gint *natural_height)
|
||||
{
|
||||
gint child_min, child_nat;
|
||||
GtkWidget *child;
|
||||
GtkBorder padding;
|
||||
gint minimum;
|
||||
gint natural;
|
||||
|
||||
gcal_floating_container_get_padding_and_border (widget, &padding);
|
||||
|
||||
minimum = 0;
|
||||
natural = 0;
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child && gtk_widget_get_visible (child))
|
||||
{
|
||||
gtk_widget_get_preferred_height (child,
|
||||
&child_min, &child_nat);
|
||||
minimum = child_min;
|
||||
natural = child_nat;
|
||||
}
|
||||
|
||||
minimum += padding.top + padding.top;
|
||||
natural += padding.top + padding.top;
|
||||
|
||||
if (minimum_height)
|
||||
*minimum_height = minimum;
|
||||
|
||||
if (natural_height)
|
||||
*natural_height = natural;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_get_preferred_width_for_height (GtkWidget *widget,
|
||||
gint height,
|
||||
gint *minimum_width,
|
||||
gint *natural_width)
|
||||
{
|
||||
gint child_min, child_nat, child_height;
|
||||
GtkWidget *child;
|
||||
GtkBorder padding;
|
||||
gint minimum;
|
||||
gint natural;
|
||||
|
||||
gcal_floating_container_get_padding_and_border (widget, &padding);
|
||||
|
||||
minimum = 0;
|
||||
natural = 0;
|
||||
|
||||
child_height = height - padding.top - padding.bottom;
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child && gtk_widget_get_visible (child))
|
||||
{
|
||||
gtk_widget_get_preferred_width_for_height (child, child_height,
|
||||
&child_min, &child_nat);
|
||||
minimum += child_min;
|
||||
natural += child_nat;
|
||||
}
|
||||
|
||||
minimum += padding.left + padding.right;
|
||||
natural += padding.left + padding.right;
|
||||
|
||||
if (minimum_width)
|
||||
*minimum_width = minimum;
|
||||
|
||||
if (natural_width)
|
||||
*natural_width = natural;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_size_allocate (GtkWidget *widget,
|
||||
GtkAllocation *allocation)
|
||||
{
|
||||
GtkAllocation child_allocation;
|
||||
GtkBorder padding;
|
||||
GtkWidget *child;
|
||||
|
||||
gtk_widget_set_allocation (widget, allocation);
|
||||
|
||||
gcal_floating_container_get_padding_and_border (widget, &padding);
|
||||
|
||||
if (gtk_widget_get_realized (widget))
|
||||
{
|
||||
gdk_window_move_resize (gtk_widget_get_window (widget),
|
||||
allocation->x,
|
||||
allocation->y,
|
||||
allocation->width,
|
||||
allocation->height);
|
||||
}
|
||||
|
||||
child_allocation.x = padding.left;
|
||||
child_allocation.y = padding.top;
|
||||
child_allocation.height =
|
||||
MAX (1,
|
||||
allocation->height - padding.top - padding.bottom);
|
||||
|
||||
child_allocation.width =
|
||||
MAX (1,
|
||||
allocation->width - padding.left - padding.right);
|
||||
|
||||
child = gtk_bin_get_child (GTK_BIN (widget));
|
||||
if (child && gtk_widget_get_visible (child))
|
||||
gtk_widget_size_allocate (child, &child_allocation);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_floating_container_draw (GtkWidget *widget,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
guint border_width;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
||||
|
||||
gtk_render_background (context, cr,
|
||||
border_width, border_width,
|
||||
gtk_widget_get_allocated_width (widget) - 2 * border_width,
|
||||
gtk_widget_get_allocated_height (widget) - 2 * border_width);
|
||||
gtk_render_frame (context, cr,
|
||||
border_width, border_width,
|
||||
gtk_widget_get_allocated_width (widget) - 2 * border_width,
|
||||
gtk_widget_get_allocated_height (widget) - 2 * border_width);
|
||||
if (GTK_WIDGET_CLASS (gcal_floating_container_parent_class)->draw != NULL)
|
||||
GTK_WIDGET_CLASS (gcal_floating_container_parent_class)->draw (widget, cr);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_add (GtkContainer *container,
|
||||
GtkWidget *child)
|
||||
{
|
||||
g_return_if_fail (gtk_bin_get_child (GTK_BIN (container)) == NULL);
|
||||
|
||||
GTK_CONTAINER_CLASS (gcal_floating_container_parent_class)->add (container, child);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_floating_container_get_padding_and_border (GtkWidget *widget,
|
||||
GtkBorder *border)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
GtkStateFlags state;
|
||||
GtkBorder tmp;
|
||||
|
||||
guint border_width;
|
||||
|
||||
context = gtk_widget_get_style_context (widget);
|
||||
state = gtk_widget_get_state_flags (widget);
|
||||
|
||||
gtk_style_context_get_padding (context, state, border);
|
||||
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
||||
|
||||
gtk_style_context_get_border (context, state, &tmp);
|
||||
border->top += tmp.top + border_width;
|
||||
border->right += tmp.right + border_width;
|
||||
border->bottom += tmp.bottom + border_width;
|
||||
border->left += tmp.left + border_width;
|
||||
}
|
||||
|
||||
GtkWidget*
|
||||
gcal_floating_container_new (void)
|
||||
{
|
||||
return g_object_new (GCAL_TYPE_FLOATING_CONTAINER, NULL);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* gcal-floating-container.h
|
||||
* Copyright (C) 2012 Erick Pérez Castellanos <erickpc@gnome.org>
|
||||
*
|
||||
* gnome-calendar 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.
|
||||
*
|
||||
* gnome-calendar 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_FLOATING_CONTAINER_H__
|
||||
#define __GCAL_FLOATING_CONTAINER_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
#define GCAL_TYPE_FLOATING_CONTAINER (gcal_floating_container_get_type ())
|
||||
#define GCAL_FLOATING_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_FLOATING_CONTAINER, GcalFloatingContainer))
|
||||
#define GCAL_FLOATING_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_FLOATING_CONTAINER, GcalFloatingContainerClass))
|
||||
#define GCAL_IS_FLOATING_CONTAINER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_FLOATING_CONTAINER))
|
||||
#define GCAL_IS_FLOATING_CONTAINER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_FLOATING_CONTAINER))
|
||||
#define GCAL_FLOATING_CONTAINER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_FLOATING_CONTAINER, GcalFloatingContainerClass))
|
||||
|
||||
typedef struct _GcalFloatingContainer GcalFloatingContainer;
|
||||
typedef struct _GcalFloatingContainerClass GcalFloatingContainerClass;
|
||||
typedef struct _GcalFloatingContainerPrivate GcalFloatingContainerPrivate;
|
||||
|
||||
struct _GcalFloatingContainer
|
||||
{
|
||||
GtkBin parent;
|
||||
/* add your public declarations here */
|
||||
|
||||
GcalFloatingContainerPrivate *priv;
|
||||
};
|
||||
|
||||
struct _GcalFloatingContainerClass
|
||||
{
|
||||
GtkBinClass parent_class;
|
||||
};
|
||||
|
||||
|
||||
GType gcal_floating_container_get_type (void);
|
||||
GtkWidget* gcal_floating_container_new (void);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_FLOATING_CONTAINER_H__ */
|
||||
@@ -1,277 +0,0 @@
|
||||
/* -*- mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* gcal-viewport.c
|
||||
*
|
||||
* Copyright (C) 2012 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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/>.
|
||||
*/
|
||||
|
||||
#include "gcal-viewport.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <math.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
/* property */
|
||||
GtkWidget *viewport;
|
||||
GtkWidget *hscrollbar;
|
||||
GtkWidget *vscrollbar;
|
||||
} GcalViewportPrivate;
|
||||
|
||||
static void gcal_viewport_constructed (GObject *object);
|
||||
|
||||
static void gcal_viewport_get_preferred_width (GtkWidget *widget,
|
||||
gint *minimum,
|
||||
gint *natural);
|
||||
|
||||
static void gcal_viewport_get_preferred_height (GtkWidget *widget,
|
||||
gint *minimum,
|
||||
gint *natural);
|
||||
|
||||
static gboolean gcal_viewport_scroll_event (GtkWidget *widget,
|
||||
GdkEventScroll *event);
|
||||
|
||||
static void gcal_viewport_child_allocated (GtkWidget *widget,
|
||||
GdkRectangle *allocation,
|
||||
gpointer user_data);
|
||||
|
||||
G_DEFINE_TYPE_WITH_PRIVATE (GcalViewport,gcal_viewport, GTK_TYPE_OVERLAY);
|
||||
|
||||
static void
|
||||
gcal_viewport_class_init (GcalViewportClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
object_class->constructed = gcal_viewport_constructed;
|
||||
|
||||
widget_class = GTK_WIDGET_CLASS (klass);
|
||||
widget_class->get_preferred_width = gcal_viewport_get_preferred_width;
|
||||
widget_class->get_preferred_height = gcal_viewport_get_preferred_height;
|
||||
widget_class->scroll_event = gcal_viewport_scroll_event;
|
||||
|
||||
/* Setup the template GtkBuilder xml for this class */
|
||||
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/calendar/viewport.ui");
|
||||
|
||||
/* Bind internals widgets */
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GcalViewport, hscrollbar);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GcalViewport, vscrollbar);
|
||||
gtk_widget_class_bind_template_child_private (widget_class, GcalViewport, viewport);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
gcal_viewport_init (GcalViewport *self)
|
||||
{
|
||||
gtk_widget_init_template (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_viewport_constructed (GObject *object)
|
||||
{
|
||||
GcalViewportPrivate *priv;
|
||||
|
||||
GtkAdjustment *adj;
|
||||
|
||||
priv = gcal_viewport_get_instance_private (GCAL_VIEWPORT (object));
|
||||
|
||||
adj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE (priv->viewport));
|
||||
gtk_range_set_adjustment (GTK_RANGE (priv->hscrollbar), adj);
|
||||
|
||||
adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (priv->viewport));
|
||||
gtk_range_set_adjustment (GTK_RANGE (priv->vscrollbar), adj);
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_viewport_get_preferred_width (GtkWidget *widget,
|
||||
gint *minimum,
|
||||
gint *natural)
|
||||
{
|
||||
if (minimum != NULL)
|
||||
*minimum = 12;
|
||||
if (natural != NULL)
|
||||
*natural = 12;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_viewport_get_preferred_height (GtkWidget *widget,
|
||||
gint *minimum,
|
||||
gint *natural)
|
||||
{
|
||||
if (minimum != NULL)
|
||||
*minimum = 12;
|
||||
if (natural != NULL)
|
||||
*natural = 12;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gcal_viewport_scroll_event (GtkWidget *widget,
|
||||
GdkEventScroll *event)
|
||||
{
|
||||
GcalViewportPrivate *priv;
|
||||
|
||||
gdouble delta_y;
|
||||
gdouble delta;
|
||||
|
||||
g_return_val_if_fail (event != NULL, FALSE);
|
||||
|
||||
priv = gcal_viewport_get_instance_private (GCAL_VIEWPORT (widget));
|
||||
|
||||
if (gdk_event_get_scroll_deltas ((GdkEvent *) event, NULL, &delta_y))
|
||||
{
|
||||
if (delta_y != 0.0 &&
|
||||
priv->vscrollbar != NULL &&
|
||||
gtk_widget_get_visible (priv->vscrollbar))
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
gdouble new_value;
|
||||
gdouble page_size;
|
||||
gdouble scroll_unit;
|
||||
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
|
||||
page_size = gtk_adjustment_get_page_size (adj);
|
||||
scroll_unit = pow (page_size, 2.0 / 3.0);
|
||||
|
||||
new_value = CLAMP (gtk_adjustment_get_value (adj) + delta_y * scroll_unit,
|
||||
gtk_adjustment_get_lower (adj),
|
||||
gtk_adjustment_get_upper (adj) -
|
||||
gtk_adjustment_get_page_size (adj));
|
||||
|
||||
gtk_adjustment_set_value (adj, new_value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkWidget *range = NULL;
|
||||
|
||||
if (event->direction == GDK_SCROLL_UP || event->direction == GDK_SCROLL_DOWN)
|
||||
range = priv->vscrollbar;
|
||||
|
||||
if (range != NULL && gtk_widget_get_visible (range))
|
||||
{
|
||||
GtkAdjustment *adj;
|
||||
gdouble new_value;
|
||||
gdouble page_size;
|
||||
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (range));
|
||||
page_size = gtk_adjustment_get_page_size (adj);
|
||||
delta = pow (page_size, 2.0 / 3.0);
|
||||
|
||||
new_value = CLAMP (gtk_adjustment_get_value (adj) + delta,
|
||||
gtk_adjustment_get_lower (adj),
|
||||
gtk_adjustment_get_upper (adj) -
|
||||
gtk_adjustment_get_page_size (adj));
|
||||
|
||||
gtk_adjustment_set_value (adj, new_value);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gcal_viewport_child_allocated (GtkWidget *widget,
|
||||
GdkRectangle *allocation,
|
||||
gpointer user_data)
|
||||
{
|
||||
GcalViewportPrivate *priv;
|
||||
gint width, height;
|
||||
|
||||
priv = gcal_viewport_get_instance_private (GCAL_VIEWPORT (user_data));
|
||||
|
||||
width = gtk_widget_get_allocated_width (GTK_WIDGET (user_data));
|
||||
height = gtk_widget_get_allocated_height (GTK_WIDGET (user_data));
|
||||
|
||||
if (width >= allocation->width)
|
||||
gtk_widget_hide (priv->hscrollbar);
|
||||
else
|
||||
gtk_widget_show (priv->hscrollbar);
|
||||
|
||||
if (height >= allocation->height)
|
||||
gtk_widget_hide (priv->vscrollbar);
|
||||
else
|
||||
gtk_widget_show (priv->vscrollbar);
|
||||
}
|
||||
|
||||
/* Public API */
|
||||
/**
|
||||
* gcal_viewport_new:
|
||||
*
|
||||
* Since: 0.1
|
||||
* Return value: A new #GcalViewport
|
||||
* Returns: (transfer full):
|
||||
**/
|
||||
GtkWidget*
|
||||
gcal_viewport_new ()
|
||||
{
|
||||
return g_object_new (GCAL_TYPE_VIEWPORT, NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_viewport_add:
|
||||
* @viewport: a #GcalViewport
|
||||
* @widget: the widget to add
|
||||
*
|
||||
* Add @widget to internal viewport of #GcalViewport
|
||||
**/
|
||||
void
|
||||
gcal_viewport_add (GcalViewport *viewport,
|
||||
GtkWidget *widget)
|
||||
{
|
||||
GcalViewportPrivate *priv;
|
||||
|
||||
priv = gcal_viewport_get_instance_private (viewport);
|
||||
gtk_container_add (GTK_CONTAINER (priv->viewport), widget);
|
||||
|
||||
/* signals handlers */
|
||||
g_signal_connect_after (widget, "size-allocate",
|
||||
G_CALLBACK (gcal_viewport_child_allocated), viewport);
|
||||
}
|
||||
|
||||
/**
|
||||
* gcal_viewport_scroll_to:
|
||||
* @viewport: a #GcalViewport
|
||||
* @value: a value between 0 and 1.0 for scrolling the child.
|
||||
*
|
||||
* If no scrollbar is shown, this method does nothing
|
||||
**/
|
||||
void
|
||||
gcal_viewport_scroll_to (GcalViewport *viewport,
|
||||
gdouble value)
|
||||
{
|
||||
GcalViewportPrivate *priv;
|
||||
GtkAdjustment *adj;
|
||||
gdouble lower, upper, page_size;
|
||||
|
||||
priv = gcal_viewport_get_instance_private (viewport);
|
||||
|
||||
value = CLAMP (value, 0.0, 1.0);
|
||||
|
||||
adj = gtk_range_get_adjustment (GTK_RANGE (priv->vscrollbar));
|
||||
page_size = gtk_adjustment_get_page_size (adj);
|
||||
lower = gtk_adjustment_get_lower (adj);
|
||||
upper = gtk_adjustment_get_upper (adj);
|
||||
|
||||
value = ((upper - page_size) - lower) * value;
|
||||
gtk_adjustment_set_value (adj, value);
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/*
|
||||
* gcal-viewport.h
|
||||
*
|
||||
* Copyright (C) 2012 - Erick Pérez Castellanos
|
||||
*
|
||||
* 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 2 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_VIEWPORT_H__
|
||||
#define __GCAL_VIEWPORT_H__
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GCAL_TYPE_VIEWPORT (gcal_viewport_get_type ())
|
||||
#define GCAL_VIEWPORT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GCAL_TYPE_VIEWPORT, GcalViewport))
|
||||
#define GCAL_VIEWPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GCAL_TYPE_VIEWPORT, GcalViewportClass))
|
||||
#define GCAL_IS_VIEWPORT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GCAL_TYPE_VIEWPORT))
|
||||
#define GCAL_IS_VIEWPORT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GCAL_TYPE_VIEWPORT))
|
||||
#define GCAL_VIEWPORT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GCAL_TYPE_VIEWPORT, GcalViewportClass))
|
||||
|
||||
typedef struct _GcalViewport GcalViewport;
|
||||
typedef struct _GcalViewportClass GcalViewportClass;
|
||||
|
||||
struct _GcalViewport
|
||||
{
|
||||
GtkOverlay parent;
|
||||
};
|
||||
|
||||
struct _GcalViewportClass
|
||||
{
|
||||
GtkOverlayClass parent_class;
|
||||
};
|
||||
|
||||
GType gcal_viewport_get_type (void);
|
||||
|
||||
GtkWidget* gcal_viewport_new (void);
|
||||
|
||||
void gcal_viewport_add (GcalViewport *viewport,
|
||||
GtkWidget *widget);
|
||||
|
||||
void gcal_viewport_scroll_to (GcalViewport *viewport,
|
||||
gdouble value);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GCAL_VIEWPORT_H__ */
|
||||
@@ -22,9 +22,7 @@
|
||||
|
||||
#include "gcal-nav-bar.h"
|
||||
#include "gcal-manager.h"
|
||||
#include "gcal-floating-container.h"
|
||||
#include "gcal-view.h"
|
||||
#include "gcal-day-view.h"
|
||||
#include "gcal-month-view.h"
|
||||
#include "gcal-week-view.h"
|
||||
#include "gcal-year-view.h"
|
||||
@@ -995,14 +993,6 @@ gcal_window_constructed (GObject *object)
|
||||
gtk_widget_get_style_context (priv->views_stack),
|
||||
"views");
|
||||
|
||||
priv->views[GCAL_WINDOW_VIEW_DAY] = gcal_day_view_new ();
|
||||
gtk_stack_add_titled (GTK_STACK (priv->views_stack),
|
||||
priv->views[GCAL_WINDOW_VIEW_DAY],
|
||||
"day", _("Day"));
|
||||
g_object_bind_property (GCAL_WINDOW (object), "active-date",
|
||||
priv->views[GCAL_WINDOW_VIEW_DAY], "active-date",
|
||||
G_BINDING_DEFAULT);
|
||||
|
||||
priv->views[GCAL_WINDOW_VIEW_WEEK] = gcal_week_view_new ();
|
||||
gtk_stack_add_titled (GTK_STACK (priv->views_stack),
|
||||
priv->views[GCAL_WINDOW_VIEW_WEEK],
|
||||
|
||||
Reference in New Issue
Block a user