39 #include <glib/gi18n.h>
40 #include <gdk/gdkkeysyms.h>
49 #include "dialog-utils.h"
50 #include "gnc-date-edit.h"
66 static guint date_edit_signals [LAST_SIGNAL] = { 0 };
71 static void gnc_date_edit_dispose (GObject *
object);
72 static void gnc_date_edit_finalize (GObject *
object);
73 static void gnc_date_edit_forall (GtkContainer *container,
74 gboolean include_internals,
76 gpointer callbabck_data);
77 static struct tm gnc_date_edit_get_date_internal (
GNCDateEdit *gde);
78 static int date_accel_key_press(GtkWidget *widget,
83 static GtkHBoxClass *parent_class;
91 gnc_date_edit_get_type (
void)
93 static GType date_edit_type = 0;
95 if (date_edit_type == 0)
97 static const GTypeInfo date_edit_info =
102 (GClassInitFunc) gnc_date_edit_class_init,
107 (GInstanceInitFunc) gnc_date_edit_init,
111 date_edit_type = g_type_register_static (GTK_TYPE_HBOX,
116 return date_edit_type;
121 gnc_strtok_r (
char *s,
const char *delim,
char **save_ptr)
129 s += strspn (s, delim);
135 s = strpbrk (token, delim);
138 *save_ptr = strchr (token,
'\0');
151 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
153 ENTER(
"gde %p", gde);
155 gtk_grab_remove (gde->cal_popup);
156 gtk_widget_hide (gde->cal_popup);
157 gdk_pointer_ungrab (GDK_CURRENT_TIME);
159 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button),
166 day_selected (GtkCalendar *calendar,
GNCDateEdit *gde)
169 guint year, month, day;
170 gde->in_selected_handler = TRUE;
171 gtk_calendar_get_date (calendar, &year, &month, &day);
174 gnc_date_edit_set_time_ts (gde, t);
175 gde->in_selected_handler = FALSE;
179 day_selected_double_click (GtkCalendar *calendar,
GNCDateEdit *gde)
181 gnc_date_edit_popdown (gde);
185 delete_popup (GtkWidget *widget, gpointer data)
190 gnc_date_edit_popdown (gde);
196 key_press_popup (GtkWidget *widget, GdkEventKey *event, gpointer data)
200 if (event->keyval != GDK_KEY_Return &&
201 event->keyval != GDK_KEY_KP_Enter &&
202 event->keyval != GDK_KEY_Escape)
203 return date_accel_key_press(gde->date_entry, event, data);
206 g_signal_stop_emission_by_name (G_OBJECT (widget),
"key-press-event");
207 gnc_date_edit_popdown (gde);
216 gint bwidth, bheight;
219 gtk_widget_size_request (gde->cal_popup, &req);
221 gdk_window_get_origin (gde->date_button->window, &x, &y);
223 x += gde->date_button->allocation.x;
224 y += gde->date_button->allocation.y;
225 bwidth = gde->date_button->allocation.width;
226 bheight = gde->date_button->allocation.height;
228 x += bwidth - req.width;
237 gtk_window_move (GTK_WINDOW (gde->cal_popup), x, y);
242 popup_grab_on_window (GdkWindow *window,
243 guint32 activate_time,
244 gboolean grab_keyboard)
246 if ((gdk_pointer_grab (window, TRUE,
247 GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
248 GDK_POINTER_MOTION_MASK,
249 NULL, NULL, activate_time) == 0))
251 if (!grab_keyboard ||
252 gdk_keyboard_grab (window, TRUE,
257 gdk_display_pointer_ungrab (gdk_drawable_get_display (window),
271 gboolean date_was_valid;
273 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
275 ENTER(
"gde %p", gde);
278 date_was_valid =
qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)),
279 &mtm.tm_mday, &mtm.tm_mon, &mtm.tm_year);
291 if (mtm.tm_year >= 1900)
294 gnc_tm_set_day_start(&mtm);
297 gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), 1);
298 gtk_calendar_select_month (GTK_CALENDAR (gde->calendar), mtm.tm_mon,
300 gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), mtm.tm_mday);
304 toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gde));
305 if (GTK_IS_WINDOW (toplevel))
307 gtk_window_group_add_window (
308 gtk_window_get_group (GTK_WINDOW (toplevel)),
309 GTK_WINDOW (gde->cal_popup));
310 gtk_window_set_transient_for (GTK_WINDOW (gde->cal_popup),
311 GTK_WINDOW (toplevel));
314 position_popup (gde);
316 gtk_widget_show (gde->cal_popup);
318 gtk_widget_grab_focus (gde->cal_popup);
319 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button),
322 if (!gtk_widget_has_focus (gde->calendar))
323 gtk_widget_grab_focus (gde->calendar);
325 if (!popup_grab_on_window ((GTK_WIDGET(gde->cal_popup))->window,
326 GDK_CURRENT_TIME, TRUE))
328 gtk_widget_hide (gde->cal_popup);
329 LEAVE(
"Failed to grab window");
333 gtk_grab_add (gde->cal_popup);
340 gnc_date_edit_button_pressed (GtkWidget *widget,
341 GdkEventButton *event,
345 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
347 ENTER(
"widget=%p, ewidget=%p, event=%p, gde=%p", widget, ewidget, event, gde);
350 if (ewidget == gde->cal_popup)
352 LEAVE(
"Press on calendar. Ignoring.");
357 if (ewidget != gde->date_button ||
358 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gde->date_button)))
360 LEAVE(
"Press, not on popup button, or while popup is raised.");
364 if (!gtk_widget_has_focus (gde->date_button))
365 gtk_widget_grab_focus (gde->date_button);
367 gde->popup_in_progress = TRUE;
369 gnc_date_edit_popup (gde);
371 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button), TRUE);
373 LEAVE(
"Popup in progress.");
378 gnc_date_edit_button_released (GtkWidget *widget,
379 GdkEventButton *event,
383 GtkWidget *ewidget = gtk_get_event_widget ((GdkEvent *)event);
384 gboolean popup_in_progress = FALSE;
386 ENTER(
"widget=%p, ewidget=%p, event=%p, gde=%p", widget, ewidget, event, gde);
388 if (gde->popup_in_progress)
390 popup_in_progress = TRUE;
391 gde->popup_in_progress = FALSE;
395 if (ewidget == gde->calendar)
397 LEAVE(
"Button release on calendar.");
401 if (ewidget == gde->date_button)
404 if (!popup_in_progress &&
405 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (gde->date_button)))
407 gnc_date_edit_popdown (gde);
408 LEAVE(
"Release on button, not in progress. Popped down.");
412 LEAVE(
"Button release on button. Allowing.");
417 gnc_date_edit_popdown (gde);
418 LEAVE(
"Release not on button or calendar. Popping down.");
423 gnc_date_edit_button_toggled (GtkWidget *widget,
GNCDateEdit *gde)
425 ENTER(
"widget %p, gde %p", widget, gde);
427 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
429 if (!gde->popup_in_progress)
430 gnc_date_edit_popup (gde);
433 gnc_date_edit_popdown (gde);
445 model = gtk_combo_box_get_model(GTK_COMBO_BOX(gde->time_combo));
446 gtk_combo_box_get_active_iter (GTK_COMBO_BOX(gde->time_combo), &iter);
447 gtk_tree_model_get( model, &iter, 0, &text, -1 );
449 gtk_entry_set_text (GTK_ENTRY (gde->time_entry), text);
452 g_signal_emit (G_OBJECT (gde), date_edit_signals [TIME_CHANGED], 0);
456 fill_time_combo (GtkWidget *widget,
GNCDateEdit *gde)
459 GtkTreeIter hour_iter, min_iter;
460 struct tm *tm_returned;
465 if (gde->lower_hour > gde->upper_hour)
468 model = gtk_combo_box_get_model (GTK_COMBO_BOX(gde->time_combo));
472 g_return_if_fail(tm_returned != NULL);
474 for (i = gde->lower_hour; i <= gde->upper_hour; i++)
480 if (gde->flags & GNC_DATE_EDIT_24_HR)
483 qof_strftime (buffer,
sizeof (buffer),
"%I:00 %p ", &mtm);
485 gtk_tree_store_append (GTK_TREE_STORE(model), &hour_iter, NULL);
486 gtk_tree_store_set (GTK_TREE_STORE(model), &hour_iter, 0, buffer, -1);
488 for (j = 0; j < 60; j += 15)
492 if (gde->flags & GNC_DATE_EDIT_24_HR)
495 qof_strftime (buffer,
sizeof (buffer),
"%I:%M %p", &mtm);
497 gtk_tree_store_append(GTK_TREE_STORE(model), &min_iter, &hour_iter );
498 gtk_tree_store_set (GTK_TREE_STORE(model), &min_iter, 0, buffer, -1);
509 g_return_if_fail(mytm != NULL);
515 1900 + mytm->tm_year);
516 gtk_entry_set_text(GTK_ENTRY(gde->date_entry), buffer);
519 if (!gde->in_selected_handler)
521 gtk_calendar_select_day(GTK_CALENDAR (gde->calendar), 1);
522 gtk_calendar_select_month(GTK_CALENDAR (gde->calendar),
523 mytm->tm_mon, 1900 + mytm->tm_year);
524 gtk_calendar_select_day(GTK_CALENDAR (gde->calendar), mytm->tm_mday);
528 if (gde->flags & GNC_DATE_EDIT_24_HR)
531 qof_strftime (buffer,
sizeof (buffer),
"%I:%M %p", mytm);
532 gtk_entry_set_text(GTK_ENTRY(gde->time_entry), buffer);
536 g_signal_emit (gde, date_edit_signals [DATE_CHANGED], 0);
537 g_signal_emit (gde, date_edit_signals [TIME_CHANGED], 0);
549 gnc_date_edit_get_property (GObject *
object,
559 g_value_set_int64 (value, gnc_date_edit_get_date (date_edit));
562 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
577 gnc_date_edit_set_property (GObject *
object,
587 gnc_date_edit_set_time_internal (date_edit, g_value_get_int64(value));
590 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, prop_id, pspec);
598 GtkContainerClass *container_class = (GtkContainerClass *) klass;
599 GObjectClass *object_class = (GObjectClass *) klass;
601 container_class->forall = gnc_date_edit_forall;
602 object_class->set_property = gnc_date_edit_set_property;
603 object_class->get_property = gnc_date_edit_get_property;
604 object_class->dispose = gnc_date_edit_dispose;
605 object_class->finalize = gnc_date_edit_finalize;
607 parent_class = g_type_class_ref(GTK_TYPE_HBOX);
609 date_edit_signals [TIME_CHANGED] =
610 g_signal_new (
"time_changed",
611 G_TYPE_FROM_CLASS (object_class),
615 g_cclosure_marshal_VOID__VOID,
618 date_edit_signals [DATE_CHANGED] =
619 g_signal_new (
"date_changed",
620 G_TYPE_FROM_CLASS (object_class),
624 g_cclosure_marshal_VOID__VOID,
627 g_object_class_install_property(object_class,
629 g_param_spec_int64(
"time",
630 "Date/time (seconds)",
631 "Date/time represented in seconds since Januari 31st, 1970",
637 klass->date_changed = NULL;
638 klass->time_changed = NULL;
644 gde->disposed = FALSE;
645 gde->popup_in_progress = FALSE;
647 gde->upper_hour = 19;
648 gde->flags = GNC_DATE_EDIT_SHOW_TIME;
649 gde->in_selected_handler = FALSE;
653 gnc_date_edit_finalize (GObject *
object)
656 g_return_if_fail (
object != NULL);
657 g_return_if_fail (GNC_IS_DATE_EDIT (
object));
659 if (G_OBJECT_CLASS (parent_class)->finalize)
660 (* G_OBJECT_CLASS (parent_class)->finalize) (
object);
664 gnc_date_edit_dispose (GObject *
object)
668 g_return_if_fail (
object != NULL);
669 g_return_if_fail (GNC_IS_DATE_EDIT (
object));
671 gde = GNC_DATE_EDIT (
object);
676 gde->disposed = TRUE;
680 gtk_widget_destroy (GTK_WIDGET(gde->date_entry));
681 gde->date_entry = NULL;
683 gtk_widget_destroy (GTK_WIDGET(gde->date_button));
684 gde->date_button = NULL;
686 gtk_widget_destroy (GTK_WIDGET(gde->time_entry));
687 gde->time_entry = NULL;
689 gtk_widget_destroy (GTK_WIDGET(gde->time_combo));
690 gde->time_combo = NULL;
692 if (G_OBJECT_CLASS (parent_class)->dispose)
693 (* G_OBJECT_CLASS (parent_class)->dispose) (
object);
697 gnc_date_edit_forall (GtkContainer *container, gboolean include_internals,
698 GtkCallback callback, gpointer callback_data)
700 g_return_if_fail (container != NULL);
701 g_return_if_fail (GNC_IS_DATE_EDIT (container));
702 g_return_if_fail (callback != NULL);
706 if (!include_internals)
709 if (!GTK_CONTAINER_CLASS (parent_class)->forall)
712 GTK_CONTAINER_CLASS (parent_class)->forall (container,
729 g_return_if_fail (gde != NULL);
730 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
734 gde->initial_time = the_time;
736 g_object_set (G_OBJECT (gde),
"time", the_time, NULL);
740 gnc_date_edit_set_gdate (
GNCDateEdit *gde,
const GDate *date)
745 g_return_if_fail(gde && GNC_IS_DATE_EDIT(gde) &&
746 date && g_date_valid(date));
747 g_date_to_struct_tm(date, &mytm);
749 gnc_date_edit_set_time(gde, t);
755 gnc_date_edit_set_time (gde, the_time.tv_sec);
768 gnc_date_edit_set_popup_range (
GNCDateEdit *gde,
int low_hour,
int up_hour)
770 g_return_if_fail (gde != NULL);
771 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
773 gde->lower_hour = low_hour;
774 gde->upper_hour = up_hour;
776 fill_time_combo(NULL, gde);
781 date_accel_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
787 string = gtk_entry_get_text (GTK_ENTRY (widget));
789 tm = gnc_date_edit_get_date_internal (gde);
791 if (!gnc_handle_date_accelerator (event, &tm,
string))
794 gnc_date_edit_set_time (gde,
gnc_mktime (&tm));
796 g_signal_emit (G_OBJECT (gde), date_edit_signals [TIME_CHANGED], 0);
801 key_press_entry (GtkWidget *widget, GdkEventKey *event, gpointer data)
803 if (!date_accel_key_press(widget, event, data))
806 g_signal_stop_emission_by_name (widget,
"key-press-event");
811 date_focus_out_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
817 tm = gnc_date_edit_get_date_internal (gde);
818 gnc_date_edit_set_time (gde,
gnc_mktime (&tm));
821 tm = gnc_date_edit_get_date_internal (gde);
823 g_signal_emit (gde, date_edit_signals [DATE_CHANGED], 0);
824 g_signal_emit (gde, date_edit_signals [TIME_CHANGED], 0);
837 GtkCellRenderer *cell;
840 gde->date_entry = gtk_entry_new ();
841 gtk_entry_set_width_chars (GTK_ENTRY (gde->date_entry), 11);
842 gtk_box_pack_start (GTK_BOX (gde), gde->date_entry, TRUE, TRUE, 0);
843 gtk_widget_show (GTK_WIDGET(gde->date_entry));
844 g_signal_connect (G_OBJECT (gde->date_entry),
"key-press-event",
845 G_CALLBACK (key_press_entry), gde);
846 g_signal_connect (G_OBJECT (gde->date_entry),
"focus-out-event",
847 G_CALLBACK (date_focus_out_event), gde);
850 gde->date_button = gtk_toggle_button_new ();
851 g_signal_connect (gde->date_button,
"button-press-event",
852 G_CALLBACK(gnc_date_edit_button_pressed), gde);
853 g_signal_connect (G_OBJECT (gde->date_button),
"toggled",
854 G_CALLBACK (gnc_date_edit_button_toggled), gde);
855 gtk_box_pack_start (GTK_BOX (gde), gde->date_button, FALSE, FALSE, 0);
857 hbox = gtk_hbox_new (FALSE, 3);
858 gtk_container_add (GTK_CONTAINER (gde->date_button), hbox);
859 gtk_widget_show (GTK_WIDGET(hbox));
862 gde->cal_label = gtk_label_new (_(
"Calendar"));
863 gtk_misc_set_alignment (GTK_MISC (gde->cal_label), 0.0, 0.5);
864 gtk_box_pack_start (GTK_BOX (hbox), gde->cal_label, TRUE, TRUE, 0);
865 if (gde->flags & GNC_DATE_EDIT_SHOW_TIME)
866 gtk_widget_show (GTK_WIDGET(gde->cal_label));
869 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_NONE);
870 gtk_box_pack_start (GTK_BOX (hbox), arrow, TRUE, FALSE, 0);
871 gtk_widget_show (GTK_WIDGET(arrow));
873 gtk_widget_show (GTK_WIDGET(gde->date_button));
876 gde->time_entry = gtk_entry_new ();
877 gtk_entry_set_max_length (GTK_ENTRY(gde->time_entry), 12);
878 gtk_widget_set_size_request (GTK_WIDGET(gde->time_entry), 88, -1);
879 gtk_box_pack_start (GTK_BOX (gde), gde->time_entry, TRUE, TRUE, 0);
881 store = gtk_tree_store_new(1, G_TYPE_STRING);
882 gde->time_combo = GTK_WIDGET(gtk_combo_box_new_with_model(GTK_TREE_MODEL(store)));
883 g_object_unref(store);
885 cell = gtk_cell_renderer_text_new();
887 gtk_cell_layout_pack_start( GTK_CELL_LAYOUT( gde->time_combo ), cell, TRUE );
889 gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( gde->time_combo ), cell,
"text", 0, NULL );
891 g_signal_connect (G_OBJECT (gde->time_combo),
"changed",
892 G_CALLBACK (set_time), gde);
894 gtk_box_pack_start (GTK_BOX (gde), gde->time_combo, FALSE, FALSE, 0);
900 g_signal_connect (G_OBJECT (gde),
"realize",
901 G_CALLBACK (fill_time_combo), gde);
903 if (gde->flags & GNC_DATE_EDIT_SHOW_TIME)
905 gtk_widget_show (GTK_WIDGET(gde->time_entry));
906 gtk_widget_show (GTK_WIDGET(gde->time_combo));
909 gde->cal_popup = gtk_window_new (GTK_WINDOW_POPUP);
910 gtk_widget_set_name (gde->cal_popup,
"gnc-date-edit-popup-window");
912 gtk_window_set_type_hint (GTK_WINDOW (gde->cal_popup),
913 GDK_WINDOW_TYPE_HINT_COMBO);
915 gtk_widget_set_events (GTK_WIDGET(gde->cal_popup),
916 gtk_widget_get_events (GTK_WIDGET(gde->cal_popup)) |
919 g_signal_connect (gde->cal_popup,
"delete-event",
920 G_CALLBACK(delete_popup), gde);
921 g_signal_connect (gde->cal_popup,
"key-press-event",
922 G_CALLBACK(key_press_popup), gde);
923 g_signal_connect (gde->cal_popup,
"button-press-event",
924 G_CALLBACK(gnc_date_edit_button_pressed), gde);
925 g_signal_connect (gde->cal_popup,
"button-release-event",
926 G_CALLBACK(gnc_date_edit_button_released), gde);
927 gtk_window_set_resizable (GTK_WINDOW (gde->cal_popup), FALSE);
928 gtk_window_set_screen (GTK_WINDOW (gde->cal_popup),
929 gtk_widget_get_screen (GTK_WIDGET (gde)));
931 frame = gtk_frame_new (NULL);
932 gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_NONE);
933 gtk_container_add (GTK_CONTAINER (gde->cal_popup), frame);
934 gtk_widget_show (GTK_WIDGET(frame));
936 gde->calendar = gtk_calendar_new ();
937 gtk_calendar_set_display_options
938 (GTK_CALENDAR (gde->calendar),
939 (GTK_CALENDAR_SHOW_DAY_NAMES
940 | GTK_CALENDAR_SHOW_HEADING
941 | ((gde->flags & GNC_DATE_EDIT_WEEK_STARTS_ON_MONDAY)
942 ? GTK_CALENDAR_WEEK_START_MONDAY : 0)));
943 g_signal_connect (gde->calendar,
"button-release-event",
944 G_CALLBACK(gnc_date_edit_button_released), gde);
945 g_signal_connect (G_OBJECT (gde->calendar),
"day-selected",
946 G_CALLBACK (day_selected), gde);
947 g_signal_connect (G_OBJECT (gde->calendar),
948 "day-selected-double-click",
949 G_CALLBACK (day_selected_double_click), gde);
950 gtk_container_add (GTK_CONTAINER (frame), gde->calendar);
951 gtk_widget_show (GTK_WIDGET(gde->calendar));
966 gnc_date_edit_new (
time64 the_time,
int show_time,
int use_24_format)
968 return gnc_date_edit_new_flags
970 ((show_time ? GNC_DATE_EDIT_SHOW_TIME : 0)
971 | (use_24_format ? GNC_DATE_EDIT_24_HR : 0)));
975 gnc_date_edit_new_ts (
Timespec the_time,
int show_time,
int use_24_format)
977 return gnc_date_edit_new (the_time.tv_sec, show_time, use_24_format);
988 gnc_date_edit_new_glade (gchar *widget_name,
989 gchar *string1, gchar *string2,
990 gint int1, gint int2)
995 widget = gnc_date_edit_new(time(NULL), FALSE, FALSE);
996 gtk_widget_show(widget);
1011 gnc_date_edit_new_flags (
time64 the_time, GNCDateEditFlags flags)
1015 gde = g_object_new (GNC_TYPE_DATE_EDIT, NULL, NULL);
1018 gde->initial_time = -1;
1019 create_children (gde);
1020 gnc_date_edit_set_time (gde, the_time);
1022 return GTK_WIDGET (gde);
1026 gnc_date_edit_get_date_internal (
GNCDateEdit *gde)
1030 gchar *flags = NULL;
1031 gboolean date_was_valid;
1034 g_assert(gde != NULL);
1035 g_assert(GNC_IS_DATE_EDIT(gde));
1037 date_was_valid =
qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)),
1038 &tm.tm_mday, &tm.tm_mon, &tm.tm_year);
1040 if (!date_was_valid)
1053 if (gde->flags & GNC_DATE_EDIT_SHOW_TIME)
1058 str = g_strdup (gtk_entry_get_text
1059 (GTK_ENTRY (gde->time_entry)));
1060 temp = gnc_strtok_r (str,
": ", &tokp);
1063 tm.tm_hour = atoi (temp);
1064 temp = gnc_strtok_r (NULL,
": ", &tokp);
1067 if (isdigit (*temp))
1069 tm.tm_min = atoi (temp);
1070 flags = gnc_strtok_r (NULL,
": ",
1072 if (flags && isdigit (*flags))
1074 tm.tm_sec = atoi (flags);
1075 flags = gnc_strtok_r (NULL,
1085 if (flags && (strcasecmp (flags,
"PM") == 0))
1087 if (tm.tm_hour < 12)
1094 gnc_tm_set_day_start(&tm);
1114 g_return_val_if_fail (gde != NULL, 0);
1115 g_return_val_if_fail (GNC_IS_DATE_EDIT (gde), 0);
1117 tm = gnc_date_edit_get_date_internal (gde);
1123 gnc_date_edit_get_gdate (
GNCDateEdit *gde, GDate *date)
1127 g_return_if_fail (gde && date);
1128 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
1130 t = gnc_date_edit_get_date(gde);
1131 g_date_clear (date, 1);
1140 ts.tv_sec = gnc_date_edit_get_date (gde);
1157 g_return_val_if_fail (gde != NULL, 0);
1158 g_return_val_if_fail (GNC_IS_DATE_EDIT (gde), 0);
1160 tm = gnc_date_edit_get_date_internal (gde);
1161 gnc_tm_set_day_end(&tm);
1171 ts.tv_sec = gnc_date_edit_get_date_end (gde);
1184 gnc_date_edit_set_flags (
GNCDateEdit *gde, GNCDateEditFlags flags)
1186 GNCDateEditFlags old_flags;
1188 g_return_if_fail (gde != NULL);
1189 g_return_if_fail (GNC_IS_DATE_EDIT (gde));
1191 old_flags = gde->flags;
1194 if ((flags & GNC_DATE_EDIT_SHOW_TIME) !=
1195 (old_flags & GNC_DATE_EDIT_SHOW_TIME))
1197 if (flags & GNC_DATE_EDIT_SHOW_TIME)
1199 gtk_widget_show (gde->cal_label);
1200 gtk_widget_show (gde->time_entry);
1201 gtk_widget_show (gde->time_combo);
1205 gtk_widget_hide (gde->cal_label);
1206 gtk_widget_hide (gde->time_entry);
1207 gtk_widget_hide (gde->time_combo);
1211 if ((flags & GNC_DATE_EDIT_24_HR) != (old_flags & GNC_DATE_EDIT_24_HR))
1213 fill_time_combo (NULL, gde);
1215 if ((flags & GNC_DATE_EDIT_WEEK_STARTS_ON_MONDAY)
1216 != (old_flags & GNC_DATE_EDIT_WEEK_STARTS_ON_MONDAY))
1218 if (flags & GNC_DATE_EDIT_WEEK_STARTS_ON_MONDAY)
1219 gtk_calendar_set_display_options
1220 (GTK_CALENDAR (gde->calendar),
1221 (GTK_CALENDAR (gde->calendar)->display_flags
1222 | GTK_CALENDAR_WEEK_START_MONDAY));
1224 gtk_calendar_set_display_options
1225 (GTK_CALENDAR (gde->calendar),
1226 (GTK_CALENDAR (gde->calendar)->display_flags
1227 & ~GTK_CALENDAR_WEEK_START_MONDAY));
1242 g_return_val_if_fail (gde != NULL, 0);
1243 g_return_val_if_fail (GNC_IS_DATE_EDIT (gde), 0);
1258 gnc_date_activates_default (
GNCDateEdit *gde, gboolean state)
1263 gtk_entry_set_activates_default(GTK_ENTRY(gde->date_entry), state);
1279 gtk_widget_grab_focus (gde->date_entry);
1289 gnc_date_make_mnemonic_target (
GNCDateEdit *gde, GtkWidget *label)
1294 gtk_label_set_mnemonic_widget (GTK_LABEL(label), gde->date_entry);
Date and Time handling routines.
Use a 64-bit unsigned int timespec.
Timespec gnc_dmy2timespec(gint day, gint month, gint year)
#define ENTER(format, args...)
struct tm * gnc_localtime_r(const time64 *secs, struct tm *time)
fill out a time struct from a 64-bit time value adjusted for the current time zone.
void gnc_tm_free(struct tm *time)
free a struct tm* created with gnc_localtime() or gnc_gmtime()
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
gsize qof_strftime(gchar *buf, gsize max, const gchar *format, const struct tm *tm)
struct tm * gnc_localtime(const time64 *secs)
fill out a time struct from a 64-bit time value.
All type declarations for the whole Gnucash engine.
void gnc_tm_get_today_start(struct tm *tm)
size_t qof_print_date_dmy_buff(gchar *buff, size_t buflen, int day, int month, int year)
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)
#define LEAVE(format, args...)
time64 gnc_time(time64 *tbuf)
get the current local time
const gchar * QofLogModule
void gnc_gdate_set_time64(GDate *gd, time64 time)