diff options
Diffstat (limited to 'prev/gtkdtp')
| -rw-r--r-- | prev/gtkdtp/dtp.c | 140 | ||||
| -rw-r--r-- | prev/gtkdtp/dtp.h | 21 | ||||
| -rw-r--r-- | prev/gtkdtp/mockup.ui | 299 | ||||
| -rw-r--r-- | prev/gtkdtp/test.c | 16 |
4 files changed, 476 insertions, 0 deletions
diff --git a/prev/gtkdtp/dtp.c b/prev/gtkdtp/dtp.c new file mode 100644 index 0000000..70876bd --- /dev/null +++ b/prev/gtkdtp/dtp.c @@ -0,0 +1,140 @@ +// 9 january 2015 +#include "dtp.h" + +/* notes: +https://git.gnome.org/browse/gtk+/tree/gtk/gtkcombobox.c?h=gtk-3-4 +*/ + +#define GDTP(x) ((goDateTimePicker *) x) +#define PRIV(x) (GDTP(x)->priv) +#define GDTPC(x) ((goDateTimePickerClass *) x) + +struct goDateTimePickerPrivate { + gint year; + gint month; + gint day; +}; + +G_DEFINE_TYPE_WITH_CODE(goDateTimePicker, goDateTimePicker, GTK_TYPE_BOX, + ;) + +// TODO figure out how to share these between C and Go +enum { + gtkMargin = 12, + gtkXPadding = 12, + gtkYPadding = 6, +}; + +static void goDateTimePicker_init(goDateTimePicker *dtp) +{ + dtp->priv = G_TYPE_INSTANCE_GET_PRIVATE(dtp, goDateTimePicker_get_type(), goDateTimePickerPrivate); +} + +static void goDateTimePicker_dispose(GObject *obj) +{ + goDateTimePickerPrivate *d = PRIV(obj); + + // TODO really with g_clear_object()? + G_OBJECT_CLASS(goDateTimePicker_parent_class)->dispose(obj); +} + +static void goDateTimePicker_finalize(GObject *obj) +{ + G_OBJECT_CLASS(goDateTimePicker_parent_class)->finalize(obj); +} + +enum { + pYear = 1, + pMonth, + pDay, + nParams, +}; + +static GParamSpec *gdtpParams[] = { + NULL, // always null + NULL, // year + NULL, // month + NULL, // day +}; + +static void goDateTimePicker_set_property(GObject *obj, guint prop, const GValue *value, GParamSpec *spec) +{ + goDateTimePickerPrivate *d = PRIV(obj); + + switch (prop) { + case pYear: + d->year = g_value_get_int(value); + break; + case pMonth: + d->month = g_value_get_int(value); + break; + case pDay: + d->day = g_value_get_int(value); + // see note on GtkCalendar comaptibility below + if (d->day == 0) + ; // TODO + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, spec); + return; + } + // TODO refresh everything here +} + +static void goDateTimePicker_get_property(GObject *obj, guint prop, GValue *value, GParamSpec *spec) +{ + goDateTimePickerPrivate *d = PRIV(obj); + + switch (prop) { + case pYear: + g_value_set_int(value, d->year); + break; + case pMonth: + g_value_set_int(value, d->month); + break; + case pDay: + g_value_set_int(value, d->day); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, prop, spec); + return; + } +} + +static void goDateTimePicker_class_init(goDateTimePickerClass *class) +{ + g_type_class_add_private(class, sizeof (goDateTimePickerPrivate)); + + G_OBJECT_CLASS(class)->dispose = goDateTimePicker_dispose; + G_OBJECT_CLASS(class)->finalize = goDateTimePicker_finalize; + G_OBJECT_CLASS(class)->set_property = goDateTimePicker_set_property; + G_OBJECT_CLASS(class)->get_property = goDateTimePicker_get_property; + + // types and values are to be compatible with the 3.4 GtkCalendar parameters + gdtpParams[pYear] = g_param_spec_int("year", + "current year", + "Current year", + 0, + G_MAXINT >> 9, + 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + gdtpParams[pMonth] = g_param_spec_uint("month", + "current month", + "Current month", + 0, + 11, + 0, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + // because of the requirement to be compatible with GtkCalendar, we have to follow its rules about dates + // values are 1..31 with 0 meaning no date selected + // we will not allow no date to be selected, so we will set the default to 1 instead of 0 + // TODO is this an issue for binding? + gdtpParams[pDay] = g_param_spec_uint("day", + "current day", + "Current day", + 0, + 31, + 1, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); + g_object_class_install_properties(G_OBJECT_CLASS(class), nParams, gdtpParams); +} diff --git a/prev/gtkdtp/dtp.h b/prev/gtkdtp/dtp.h new file mode 100644 index 0000000..3c936c6 --- /dev/null +++ b/prev/gtkdtp/dtp.h @@ -0,0 +1,21 @@ +// 9 january 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> + +typedef struct goDateTimePicker goDateTimePicker; +typedef struct goDateTimePickerClass goDateTimePickerClass; +typedef struct goDateTimePickerPrivate goDateTimePickerPrivate; + +struct goDateTimePicker { + GtkBox parent_instance; + goDateTimePickerPrivate *priv; +}; + +struct goDateTimePickerClass { + GtkBoxClass parent_class; +}; + +GType goDateTimePicker_get_type(void); diff --git a/prev/gtkdtp/mockup.ui b/prev/gtkdtp/mockup.ui new file mode 100644 index 0000000..ebd12d8 --- /dev/null +++ b/prev/gtkdtp/mockup.ui @@ -0,0 +1,299 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- Generated with glade 3.18.3 --> +<interface> + <requires lib="gtk+" version="3.12"/> + <object class="GtkAdjustment" id="adjustment1"> + <property name="lower">1</property> + <property name="upper">12</property> + <property name="step_increment">1</property> + <property name="page_increment">10</property> + </object> + <object class="GtkAdjustment" id="adjustment2"> + <property name="upper">59</property> + <property name="step_increment">1</property> + <property name="page_increment">10</property> + </object> + <object class="GtkWindow" id="window1"> + <property name="can_focus">False</property> + <child> + <object class="GtkBox" id="box1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">12</property> + <property name="margin_right">12</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="spacing">12</property> + <child> + <object class="GtkBox" id="box2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="label1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Unopened</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="comboboxtext1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="has_entry">True</property> + <child internal-child="entry"> + <object class="GtkEntry" id="comboboxtext-entry"> + <property name="can_focus">False</property> + <property name="text" translatable="yes">10 Jan 2015 7:01 PM</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Each component of the date/time string is a clickable item; free-form text cannot be entered. Clicking an item selects it; typing and the arrow keys change the values. Right clicking produces a Copy item and possibly an Undo item; the standard keyboard shortcuts will also work.</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkSeparator" id="separator1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="orientation">vertical</property> + <child> + <object class="GtkLabel" id="label3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">Opened</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="comboboxtext2"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="has_entry">True</property> + <child internal-child="entry"> + <object class="GtkEntry" id="comboboxtext-entry1"> + <property name="can_focus">False</property> + <property name="text" translatable="yes">10 Jan 2015 7:01 PM</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkFrame" id="frame1"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label_xalign">0</property> + <property name="shadow_type">out</property> + <child> + <object class="GtkBox" id="box4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="margin_left">12</property> + <property name="margin_right">12</property> + <property name="margin_top">12</property> + <property name="margin_bottom">12</property> + <property name="orientation">vertical</property> + <property name="spacing">6</property> + <child> + <object class="GtkCalendar" id="calendar1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="year">2015</property> + <property name="day">10</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <child> + <object class="GtkSpinButton" id="spinbutton1"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="adjustment">adjustment1</property> + <property name="value">7</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label4"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">:</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkSpinButton" id="spinbutton2"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="adjustment">adjustment2</property> + <property name="value">1</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="comboboxtext3"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="active">1</property> + <items> + <item translatable="yes">AM</item> + <item translatable="yes">PM</item> + </items> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkBox" id="box6"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="halign">end</property> + <property name="spacing">6</property> + <property name="homogeneous">True</property> + <child> + <object class="GtkButton" id="button1"> + <property name="label" translatable="yes">Today</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkButton" id="button2"> + <property name="label" translatable="yes">Revert</property> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="pack_type">end</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + <child type="label_item"> + <placeholder/> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> + <object class="GtkLabel" id="label5"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes">The combobox part works exactly like in the unopened mode. When opened, the popup shows a calendar, more conventional time editing, and buttons to select the current date/time and undo any changes made while the popup was open. Closing the popup (in the same way you would close a combobox popup) applies changes. +The label of the Today button changes depending on whether dates only, times only, or both can be chosen.</property> + <property name="wrap">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">3</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + </object> + </child> + </object> +</interface> diff --git a/prev/gtkdtp/test.c b/prev/gtkdtp/test.c new file mode 100644 index 0000000..c867c11 --- /dev/null +++ b/prev/gtkdtp/test.c @@ -0,0 +1,16 @@ +// 9 january 2015 +#include "dtp.h" + +// #qo pkg-config: gtk+-3.0 + +int main(void) +{ + GtkWidget *mainwin; + + gtk_init(NULL, NULL); + mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_container_add(GTK_CONTAINER(mainwin), g_object_new(goDateTimePicker_get_type(), NULL)); + gtk_widget_show_all(mainwin); + gtk_main(); + return 0; +} |
