[goffice] GOCalendarButton: new widget.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [goffice] GOCalendarButton: new widget.
- Date: Fri, 22 May 2009 15:25:06 -0400 (EDT)
commit 9c96e2457f926ff2a623f9145ad72ad4193450af
Author: Morten Welinder <terra gnome org>
Date: Fri May 22 15:24:44 2009 -0400
GOCalendarButton: new widget.
---
ChangeLog | 10 +++
NEWS | 1 +
goffice/gtk/Makefile.am | 4 +-
goffice/gtk/go-calendar-button.c | 134 ++++++++++++++++++++++++++++++++++++++
goffice/gtk/go-calendar-button.h | 44 ++++++++++++
goffice/gtk/go-combo-box.c | 20 ++++--
6 files changed, 204 insertions(+), 9 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d643ae9..5332aaf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2009-05-22 Morten Welinder <terra gnome org>
+
+ * goffice/gtk/go-calendar-button.c: New file.
+
+ * goffice/gtk/go-combo-box.c (cb_state_change,
+ go_combo_box_set_display, go_combo_box_construct): Handle NULL
+ display_widget.
+
+ * goffice/gtk/Makefile.am: Add go-calendar-button.c
+
2009-05-21 Morten Welinder <terra gnome org>
* goffice/graph/gog-axis.c (map_time_get_dim_format): New
diff --git a/NEWS b/NEWS
index fe87ef2..659770f 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Morten:
* Properly handle date conventions in graphs.
* Support formatted editing of graph limits that are dates and
times. [#574681]
+ * Implement new calendar button widget.
--------------------------------------------------------------------------
goffice 0.7.6:
diff --git a/goffice/gtk/Makefile.am b/goffice/gtk/Makefile.am
index c250c79..ece67ea 100644
--- a/goffice/gtk/Makefile.am
+++ b/goffice/gtk/Makefile.am
@@ -23,6 +23,7 @@ libgoffice_gtk_la_SOURCES = \
go-action-combo-stack.c \
go-action-combo-text.c \
\
+ go-calendar-button.c \
go-palette.c \
go-selector.c \
go-color-selector.c \
@@ -60,6 +61,7 @@ libgoffice_gtk_la_HEADERS = \
go-action-combo-stack.h \
go-action-combo-text.h \
\
+ go-calendar-button.h \
go-palette.h \
go-selector.h \
go-color-selector.h \
@@ -78,7 +80,7 @@ dist_glade_DATA = \
go-rotation-sel.glade \
go-font-sel.glade \
go-format-sel.glade \
- go-3d-rotation-sel.glade \
+ go-3d-rotation-sel.glade \
go-image-save-dialog-extra.glade \
go-image-sel.glade
diff --git a/goffice/gtk/go-calendar-button.c b/goffice/gtk/go-calendar-button.c
new file mode 100644
index 0000000..b9a1f89
--- /dev/null
+++ b/goffice/gtk/go-calendar-button.c
@@ -0,0 +1,134 @@
+/*
+ * go-calendar-button.h: A custom GtkAction to chose among a set of images
+ *
+ * Copyright (C) 2009 Morten Welinder (terra gnome org)
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **/
+
+#include <goffice/goffice-config.h>
+#include "go-calendar-button.h"
+#include "go-combo-box.h"
+#include <gsf/gsf-impl-utils.h>
+
+struct _GOCalendarButton {
+ GOComboBox base;
+ GtkCalendar *calendar;
+};
+
+typedef struct {
+ GOComboBoxClass base;
+ void (* changed) (GOCalendarButton *);
+} GOCalendarButtonClass;
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+static guint go_calendar_button_signals[LAST_SIGNAL] = { 0, };
+
+static void
+cb_calendar_changed (GtkCalendar *cal, GOCalendarButton *calb)
+{
+ g_signal_emit (G_OBJECT (calb), go_calendar_button_signals[CHANGED], 0);
+}
+
+static void
+go_calendar_button_init (GOCalendarButton *calb)
+{
+ GtkWidget *w = gtk_calendar_new ();
+ calb->calendar = GTK_CALENDAR (w);
+ go_combo_box_construct (GO_COMBO_BOX (calb),
+ NULL,
+ w, w);
+
+ g_signal_connect (G_OBJECT (w), "month_changed",
+ G_CALLBACK (cb_calendar_changed),
+ calb);
+ g_signal_connect (G_OBJECT (w), "day_selected",
+ G_CALLBACK (cb_calendar_changed),
+ calb);
+}
+
+static void
+go_calendar_button_class_init (GObjectClass *gobject_class)
+{
+ go_calendar_button_signals[CHANGED] =
+ g_signal_new ("changed",
+ G_OBJECT_CLASS_TYPE (gobject_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (GOCalendarButtonClass, changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+GSF_CLASS (GOCalendarButton, go_calendar_button,
+ go_calendar_button_class_init, go_calendar_button_init,
+ GO_TYPE_COMBO_BOX)
+
+GtkWidget *
+go_calendar_button_new (void)
+{
+ return g_object_new (GO_TYPE_CALENDAR_BUTTON, NULL);
+}
+
+GtkCalendar *
+go_calendar_button_get_calendar (GOCalendarButton *calb)
+{
+ g_return_val_if_fail (GO_IS_CALENDAR_BUTTON (calb), NULL);
+ return calb->calendar;
+}
+
+gboolean
+go_calendar_button_get_date (GOCalendarButton *calb, GDate *date)
+{
+ GtkCalendar *cal;
+ int d, m, y;
+
+ g_return_val_if_fail (GO_IS_CALENDAR_BUTTON (calb), FALSE);
+ g_return_val_if_fail (date != NULL, FALSE);
+
+ cal = go_calendar_button_get_calendar (calb);
+ gtk_calendar_get_date (cal, &y, &m, &d);
+ m += 1; /* Zero-based. */
+
+ g_date_clear (date, 1);
+ if (g_date_valid_dmy (d, m, y))
+ g_date_set_dmy (date, d, m, y);
+
+ return g_date_valid (date);
+}
+
+void
+go_calendar_button_set_date (GOCalendarButton *calb, GDate const *date)
+{
+ GtkCalendar *cal;
+ GDate old_date;
+
+ g_return_if_fail (GO_IS_CALENDAR_BUTTON (calb));
+ g_return_if_fail (g_date_valid (date));
+
+ if (go_calendar_button_get_date (calb, &old_date) &&
+ g_date_compare (date, &old_date) == 0)
+ return;
+
+ cal = go_calendar_button_get_calendar (calb);
+ gtk_calendar_select_month (cal,
+ g_date_get_month (date) - 1,
+ g_date_get_year (date));
+ gtk_calendar_select_day (cal, g_date_get_day (date));
+}
diff --git a/goffice/gtk/go-calendar-button.h b/goffice/gtk/go-calendar-button.h
new file mode 100644
index 0000000..469419a
--- /dev/null
+++ b/goffice/gtk/go-calendar-button.h
@@ -0,0 +1,44 @@
+/*
+ * go-calendar-button.h: A custom GtkAction to chose among a set of images
+ *
+ * Copyright (C) 2009 Morten Welinder (terra gnome org)
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ **/
+
+#ifndef _GO_CALENDAR_BUTTON_H_
+#define _GO_CALENDAR_BUTTON_H_
+
+#include <gtk/gtk.h>
+
+G_BEGIN_DECLS
+
+#define GO_TYPE_CALENDAR_BUTTON (go_calendar_button_get_type ())
+#define GO_CALENDAR_BUTTON(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GO_TYPE_CALENDAR_BUTTON, GOCalendarButton))
+#define GO_IS_CALENDAR_BUTTON(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GO_TYPE_CALENDAR_BUTTON))
+
+typedef struct _GOCalendarButton GOCalendarButton;
+
+GType go_calendar_button_get_type (void);
+GtkWidget *go_calendar_button_new (void);
+GtkCalendar *go_calendar_button_get_calendar (GOCalendarButton *calb);
+void go_calendar_button_set_date (GOCalendarButton *calb,
+ GDate const *date);
+gboolean go_calendar_button_get_date (GOCalendarButton *calb,
+ GDate *date);
+
+G_END_DECLS
+
+#endif /* _GO_CALENDAR_BUTTON_H_ */
diff --git a/goffice/gtk/go-combo-box.c b/goffice/gtk/go-combo-box.c
index ce66734..6d6cd77 100644
--- a/goffice/gtk/go-combo-box.c
+++ b/goffice/gtk/go-combo-box.c
@@ -526,8 +526,10 @@ go_combo_box_button_press (GtkWidget *widget, GdkEventButton *event, GOComboBox
static void
cb_state_change (GtkWidget *widget, GtkStateType old_state, GOComboBox *combo_box)
{
- GtkStateType const new_state = GTK_WIDGET_STATE(widget);
- gtk_widget_set_state (combo_box->priv->display_widget, new_state);
+ GtkStateType const new_state = GTK_WIDGET_STATE (widget);
+ if (combo_box->priv->display_widget)
+ gtk_widget_set_state (combo_box->priv->display_widget,
+ new_state);
}
static void
@@ -602,16 +604,19 @@ GSF_CLASS (GOComboBox, go_combo_box,
go_combo_box_set_display (GOComboBox *combo_box, GtkWidget *display_widget)
{
g_return_if_fail (GO_IS_COMBO_BOX (combo_box));
- g_return_if_fail (GTK_IS_WIDGET (display_widget));
+ g_return_if_fail (!display_widget || GTK_IS_WIDGET (display_widget));
- if (combo_box->priv->display_widget != NULL &&
- combo_box->priv->display_widget != display_widget)
+ if (display_widget == combo_box->priv->display_widget)
+ return;
+
+ if (combo_box->priv->display_widget)
gtk_container_remove (GTK_CONTAINER (combo_box),
combo_box->priv->display_widget);
-
combo_box->priv->display_widget = display_widget;
- gtk_box_pack_start (GTK_BOX (combo_box), display_widget, TRUE, TRUE, 0);
+ if (display_widget)
+ gtk_box_pack_start (GTK_BOX (combo_box), display_widget,
+ FALSE, TRUE, 0);
}
static gboolean
@@ -697,7 +702,6 @@ go_combo_box_construct (GOComboBox *combo,
GtkWidget *vbox;
g_return_if_fail (GO_IS_COMBO_BOX (combo));
- g_return_if_fail (GTK_IS_WIDGET (display_widget));
GTK_BOX (combo)->spacing = 0;
GTK_BOX (combo)->homogeneous = FALSE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]