Started the newer date-time picker.
This commit is contained in:
parent
4818c4b093
commit
92ece84f7b
|
@ -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 <gtk/gtk.h>
|
||||
|
||||
#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);
|
|
@ -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));
|
||||
}
|
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue