[gnome-calendar] ui: added GcalViewport widget.
- From: Erick Pérez Castellanos <erickpc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar] ui: added GcalViewport widget.
- Date: Thu, 4 Dec 2014 22:21:00 +0000 (UTC)
commit 984b65780a1b8b03edfd45b67cd1bcea964a3b85
Author: Erick Pérez Castellanos <erick red gmail com>
Date: Tue Jun 4 21:59:29 2013 -0400
ui: added GcalViewport widget.
Basically a Viewport with overlaying scrollbars, for using inside the views
data/theme/gtk-styles.css | 20 +++--
src/Makefile.am | 2 +
src/calendar.gresource.xml | 3 +-
src/gcal-viewport.c | 175 ++++++++++++++++++++++++++++++++++++++++++++
src/gcal-viewport.h | 60 +++++++++++++++
src/viewport.ui | 35 +++++++++
6 files changed, 285 insertions(+), 10 deletions(-)
---
diff --git a/data/theme/gtk-styles.css b/data/theme/gtk-styles.css
index b1421a8..bdc9ef0 100644
--- a/data/theme/gtk-styles.css
+++ b/data/theme/gtk-styles.css
@@ -14,6 +14,17 @@
padding: 12px;
}
+.view-overlay .frame {
+ border-left: 0;
+ border-right: 0;
+ border-bottom: 0;
+}
+
+.view-overlay .scrollbar.trough {
+ background-color: transparent;
+ background-image: none;
+}
+
.calendar-view {
padding: 6px;
font: 10;
@@ -43,15 +54,6 @@
border-radius: 0;
}
-.calendar-view .scrollbar.slider {
- background-color: alpha (@scrollbar_slider, 0.5);
- border: #6e6e6e 1px solid;
-}
-.calendar-view .scrollbar.trough {
- background-color: transparent;
- background-image: none;
-}
-
.entry {
border-radius: 0;
}
diff --git a/src/Makefile.am b/src/Makefile.am
index 24311a3..bb7eb8e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,6 +56,8 @@ 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-utils.c \
diff --git a/src/calendar.gresource.xml b/src/calendar.gresource.xml
index d06cc33..44ea605 100644
--- a/src/calendar.gresource.xml
+++ b/src/calendar.gresource.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/org/gnome/calendar">
- <file compressed="true">nav_bar.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">nav_bar.ui</file>
+ <file compressed="true" preprocess="xml-stripblanks">viewport.ui</file>
</gresource>
</gresources>
diff --git a/src/gcal-viewport.c b/src/gcal-viewport.c
new file mode 100644
index 0000000..1b5f960
--- /dev/null
+++ b/src/gcal-viewport.c
@@ -0,0 +1,175 @@
+/* -*- 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 <glib/gi18n.h>
+
+#include <string.h>
+
+struct _GcalViewportPrivate
+{
+ /* property */
+ GtkWidget *viewport;
+ GtkWidget *hscrollbar;
+ GtkWidget *vscrollbar;
+};
+
+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 void gcal_viewport_child_allocated (GtkWidget *widget,
+ GdkRectangle *allocation,
+ gpointer user_data);
+
+G_DEFINE_TYPE (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;
+
+ /* 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_child (widget_class, GcalViewportPrivate, hscrollbar);
+ gtk_widget_class_bind_child (widget_class, GcalViewportPrivate, vscrollbar);
+ gtk_widget_class_bind_child (widget_class, GcalViewportPrivate, viewport);
+
+ g_type_class_add_private ((gpointer)klass, sizeof (GcalViewportPrivate));
+}
+
+
+
+static void
+gcal_viewport_init (GcalViewport *self)
+{
+ self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+ GCAL_TYPE_VIEWPORT,
+ GcalViewportPrivate);
+
+ gtk_widget_init_template (GTK_WIDGET (self));
+}
+
+static void
+gcal_viewport_constructed (GObject *object)
+{
+ GcalViewportPrivate *priv;
+
+ GtkAdjustment *adj;
+
+ priv = GCAL_VIEWPORT (object)->priv;
+
+ 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 void
+gcal_viewport_child_allocated (GtkWidget *widget,
+ GdkRectangle *allocation,
+ gpointer user_data)
+{
+ GcalViewportPrivate *priv;
+ gint width, height;
+
+ priv = GCAL_VIEWPORT (user_data)->priv;
+
+ 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);
+}
+
+void
+gcal_viewport_add (GcalViewport *viewport,
+ GtkWidget *widget)
+{
+ GcalViewportPrivate *priv;
+
+ priv = viewport->priv;
+ gtk_container_add (GTK_CONTAINER (priv->viewport), widget);
+
+ /* signals handlers */
+ g_signal_connect_after (widget, "size-allocate",
+ G_CALLBACK (gcal_viewport_child_allocated), viewport);
+}
diff --git a/src/gcal-viewport.h b/src/gcal-viewport.h
new file mode 100644
index 0000000..fe659c1
--- /dev/null
+++ b/src/gcal-viewport.h
@@ -0,0 +1,60 @@
+/*
+ * 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;
+typedef struct _GcalViewportPrivate GcalViewportPrivate;
+
+struct _GcalViewport
+{
+ GtkOverlay parent;
+
+ /* add your public declarations here */
+ GcalViewportPrivate *priv;
+};
+
+struct _GcalViewportClass
+{
+ GtkOverlayClass parent_class;
+};
+
+GType gcal_viewport_get_type (void);
+
+GtkWidget* gcal_viewport_new (void);
+
+void gcal_viewport_add (GcalViewport *viewport,
+ GtkWidget *widget);
+
+G_END_DECLS
+
+#endif /* __GCAL_VIEWPORT_H__ */
diff --git a/src/viewport.ui b/src/viewport.ui
new file mode 100644
index 0000000..832d068
--- /dev/null
+++ b/src/viewport.ui
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+ <!-- interface-requires gtk+ 3.10 -->
+ <template class="GcalViewport" parent="GtkOverlay">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <style>
+ <class name="view-overlay"/>
+ </style>
+ <child type="overlay">
+ <object class="GtkScrollbar" id="vscrollbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">vertical</property>
+ <property name="halign">end</property>
+ <property name="vexpand">True</property>
+ </object>
+ </child>
+ <child type="overlay">
+ <object class="GtkScrollbar" id="hscrollbar">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="orientation">horizontal</property>
+ <property name="valign">end</property>
+ <property name="hexpand">True</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkViewport" id="viewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ </object>
+ </child>
+ </template>
+</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]