From 92ece84f7b09ce2c1afab0c41573a87d94a0581d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 4 Sep 2015 12:40:02 -0400 Subject: [PATCH] Started the newer date-time picker. --- gtkdtp/dtp.h | 27 ++++++++++++++++ gtkdtp/dtpwidget.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++ gtkdtp/main.c | 23 +++++++++++++ 3 files changed, 130 insertions(+) create mode 100644 gtkdtp/dtp.h create mode 100644 gtkdtp/dtpwidget.c create mode 100644 gtkdtp/main.c diff --git a/gtkdtp/dtp.h b/gtkdtp/dtp.h new file mode 100644 index 00000000..0155ce6e --- /dev/null +++ b/gtkdtp/dtp.h @@ -0,0 +1,27 @@ +// 4 september 2015 +#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_32 +#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_32 +#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4 +#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4 +#include + +#define dateTimePickerWidgetType (dateTimePickerWidget_get_type()) +#define dateTimePickerWidget(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), dateTimePickerWidgetType, dateTimePickerWidget)) +#define isDateTimePickerWidget(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), dateTimePickerWidgetType)) +#define dateTimePickerWidgetClass(class) (G_TYPE_CHECK_CLASS_CAST((class), dateTimePickerWidgetType, dateTimePickerWidgetClass)) +#define isDateTimePickerWidgetClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), dateTimePickerWidget)) +#define getDateTimePickerWidgetClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), dateTimePickerWidgetType, dateTimePickerWidgetClass)) + +typedef struct dateTimePickerWidget dateTimePickerWidget; +typedef struct dateTimePickerWidgetClass dateTimePickerWidgetClass; + +struct dateTimePickerWidget { + GtkBox parent_instance; + struct dtpPrivate *priv; +}; + +struct dateTimePickerWidgetClass { + GtkBoxClass parent_class; +}; + +extern GType dateTimePickerWidget_get_type(void); diff --git a/gtkdtp/dtpwidget.c b/gtkdtp/dtpwidget.c new file mode 100644 index 00000000..c7665efb --- /dev/null +++ b/gtkdtp/dtpwidget.c @@ -0,0 +1,80 @@ +// 4 september 2015 +#include "dtp.h" + +struct dtpPrivate { + GtkWidget *calendar; + GtkWidget *timebox; + GtkWidget *hours; + GtkWidget *minutes; + GtkWidget *seconds; + GtkWidget *ampm; +}; + +G_DEFINE_TYPE(dateTimePickerWidget, dateTimePickerWidget, GTK_TYPE_BOX) + +static GtkWidget *newSpinbox(int min, int max) +{ + GtkWidget *sb; + + sb = gtk_spin_button_new_with_range(min, max, 1); + gtk_spin_button_set_digits(GTK_SPIN_BUTTON(sb), 0); + gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(sb), TRUE); + gtk_orientable_set_orientation(GTK_ORIENTABLE(sb), GTK_ORIENTATION_VERTICAL); + return sb; +} + +static void dateTimePickerWidget_init(dateTimePickerWidget *d) +{ + d->priv = G_TYPE_INSTANCE_GET_PRIVATE(d, dateTimePickerWidgetType, struct dtpPrivate); + + gtk_orientable_set_orientation(GTK_ORIENTABLE(d), GTK_ORIENTATION_VERTICAL); + gtk_box_set_spacing(GTK_BOX(d), 6); + + d->priv->calendar = gtk_calendar_new(); + gtk_container_add(GTK_CONTAINER(d), d->priv->calendar); + + d->priv->timebox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1); + gtk_container_add(GTK_CONTAINER(d), d->priv->timebox); + + d->priv->hours = newSpinbox(1, 12); + gtk_container_add(GTK_CONTAINER(d->priv->timebox), d->priv->hours); + + gtk_container_add(GTK_CONTAINER(d->priv->timebox), + gtk_label_new(":")); + + d->priv->minutes = newSpinbox(0, 59); + gtk_container_add(GTK_CONTAINER(d->priv->timebox), d->priv->minutes); + + gtk_container_add(GTK_CONTAINER(d->priv->timebox), + gtk_label_new(":")); + + d->priv->seconds = newSpinbox(0, 59); + gtk_container_add(GTK_CONTAINER(d->priv->timebox), d->priv->seconds); + + d->priv->ampm = gtk_combo_box_text_new(); + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(d->priv->ampm), NULL, "AM"); + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(d->priv->ampm), NULL, "PM"); + gtk_widget_set_valign(d->priv->ampm, GTK_ALIGN_CENTER); + gtk_container_add(GTK_CONTAINER(d->priv->timebox), d->priv->ampm); + + gtk_widget_show(d->priv->calendar); + gtk_widget_show_all(d->priv->timebox); +} + +static void dateTimePickerWidget_dispose(GObject *obj) +{ + G_OBJECT_CLASS(dateTimePickerWidget_parent_class)->dispose(obj); +} + +static void dateTimePickerWidget_finalize(GObject *obj) +{ + G_OBJECT_CLASS(dateTimePickerWidget_parent_class)->finalize(obj); +} + +static void dateTimePickerWidget_class_init(dateTimePickerWidgetClass *class) +{ + G_OBJECT_CLASS(class)->dispose = dateTimePickerWidget_dispose; + G_OBJECT_CLASS(class)->finalize = dateTimePickerWidget_finalize; + + g_type_class_add_private(G_OBJECT_CLASS(class), sizeof (struct dtpPrivate)); +} diff --git a/gtkdtp/main.c b/gtkdtp/main.c new file mode 100644 index 00000000..07fb44e6 --- /dev/null +++ b/gtkdtp/main.c @@ -0,0 +1,23 @@ +// 4 september 2015 +#include "dtp.h" + +// #qo pkg-config: gtk+-3.0 + +int main(void) +{ + GtkWidget *mainwin; + GtkWidget *dtp; + + gtk_init(NULL, NULL); + + mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_set_border_width(GTK_CONTAINER(mainwin), 12); + g_signal_connect(mainwin, "destroy", G_CALLBACK(gtk_main_quit), NULL); + + dtp = GTK_WIDGET(g_object_new(dateTimePickerWidget_get_type(), NULL)); + gtk_container_add(GTK_CONTAINER(mainwin), dtp); + + gtk_widget_show_all(mainwin); + gtk_main(); + return 0; +}