32 #include <glib/gi18n.h>
33 #include <gdk/gdkkeysyms.h>
36 #include "gnc-cell-renderer-popup-entry.h"
37 #include "dialog-utils.h"
42 static void gpw_cell_editable_init (GtkCellEditableIface *iface);
43 static gboolean gpw_key_press_event (GtkWidget *box,
44 GdkEventKey *key_event);
58 static GtkEventBoxClass *parent_class;
59 static guint signals[LAST_SIGNAL];
62 gnc_popup_entry_get_type (
void)
64 static GtkType widget_type = 0;
68 static const GTypeInfo widget_info =
73 (GClassInitFunc) gnc_popup_entry_class_init,
78 (GInstanceInitFunc) gnc_popup_entry_init,
81 static const GInterfaceInfo cell_editable_info =
83 (GInterfaceInitFunc) gpw_cell_editable_init,
88 widget_type = g_type_register_static (GTK_TYPE_EVENT_BOX,
93 g_type_add_interface_static (widget_type,
94 GTK_TYPE_CELL_EDITABLE,
106 widget->hbox = gtk_hbox_new (FALSE, 0);
107 gtk_widget_show (widget->hbox);
109 widget->entry = g_object_new (GTK_TYPE_ENTRY,
"has_frame", FALSE, NULL);
110 GTK_ENTRY (widget->entry)->is_cell_renderer = TRUE;
111 gtk_widget_show (widget->entry);
113 widget->button = gtk_button_new ();
114 gtk_widget_show (widget->button);
116 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
117 gtk_widget_show (arrow);
119 gtk_container_add (GTK_CONTAINER (widget->button), arrow);
121 gtk_box_pack_start (GTK_BOX (widget->hbox), widget->entry, TRUE, TRUE, 0);
122 gtk_box_pack_start (GTK_BOX (widget->hbox), widget->button, FALSE, TRUE, 0);
124 gtk_container_add (GTK_CONTAINER (widget), widget->hbox);
126 GTK_WIDGET_SET_FLAGS (widget, GTK_CAN_FOCUS);
127 gtk_widget_add_events (GTK_WIDGET (widget), GDK_KEY_PRESS_MASK);
128 gtk_widget_add_events (GTK_WIDGET (widget), GDK_KEY_RELEASE_MASK);
134 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
136 widget_class->key_press_event = gpw_key_press_event;
138 gtk_object_add_arg_type (
"GncPopupEntry::editing-canceled", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_EDITING_CANCELED);
140 parent_class = GTK_EVENT_BOX_CLASS (g_type_class_peek_parent (klass));
142 signals[ARROW_CLICKED] = g_signal_new
144 G_TYPE_FROM_CLASS (klass),
148 g_cclosure_marshal_VOID__VOID,
156 g_signal_emit (widget, signals[ARROW_CLICKED], 0);
162 gtk_cell_editable_entry_activated (GtkEntry *entry,
GncPopupEntry *widget)
164 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
165 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
169 gtk_cell_editable_key_press_event (GtkEntry *entry,
170 GdkEventKey *key_event,
173 const char *date_string;
174 gint year = 0, month = 0, day = 0;
177 if (key_event->keyval == GDK_Escape)
179 widget->editing_canceled = TRUE;
181 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
182 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
187 date_string = gtk_entry_get_text (entry);
189 memset (&when, 0,
sizeof (when));
193 when.tm_year = year - 1900;
194 when.tm_mon = month - 1 ;
197 if (!gnc_handle_date_accelerator (key_event, &when, date_string))
201 gtk_widget_grab_focus (GTK_WIDGET (entry));
208 gpw_key_press_event (GtkWidget *box,
209 GdkEventKey *key_event)
214 gtk_widget_grab_focus (widget->entry);
216 if (key_event->keyval == GDK_Escape)
218 widget->editing_canceled = TRUE;
220 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (widget));
221 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (widget));
226 if (key_event->keyval == GDK_Left)
228 gtk_editable_set_position (GTK_EDITABLE (widget->entry), 0);
232 if (key_event->keyval == GDK_Right)
234 gtk_editable_set_position (GTK_EDITABLE (widget->entry), -1);
239 memcpy (&tmp_event, key_event,
sizeof (GdkEventKey));
241 tmp_event.key.window = widget->entry->window;
242 tmp_event.key.send_event = TRUE;
244 gtk_widget_event (widget->entry, &tmp_event);
246 return GTK_WIDGET_CLASS (parent_class)->key_press_event (GTK_WIDGET (widget),
251 gpw_start_editing (GtkCellEditable *cell_editable,
256 gtk_editable_select_region (GTK_EDITABLE (widget->entry), 0, -1);
258 g_signal_connect (G_OBJECT (widget->entry),
260 G_CALLBACK (gtk_cell_editable_entry_activated),
262 g_signal_connect (G_OBJECT (widget->entry),
264 G_CALLBACK (gtk_cell_editable_key_press_event),
266 g_signal_connect (G_OBJECT (widget->button),
268 (GCallback) gpw_arrow_clicked,
273 gpw_cell_editable_init (GtkCellEditableIface *iface)
275 iface->start_editing = gpw_start_editing;
279 gnc_popup_entry_set_text (
GncPopupEntry *popup,
const gchar *text)
281 g_return_if_fail (GNC_IS_POPUP_ENTRY (popup));
283 gtk_entry_set_text (GTK_ENTRY (popup->entry), text ? text :
"");
289 g_return_val_if_fail (GNC_IS_POPUP_ENTRY (popup), NULL);
291 return gtk_entry_get_text (GTK_ENTRY (popup->entry));
295 gnc_popup_get_button_width (
void)
297 GtkWidget *window, *button, *arrow;
302 window = gtk_window_new (GTK_WINDOW_POPUP);
304 button = gtk_button_new ();
305 gtk_widget_show (button);
306 gtk_container_add (GTK_CONTAINER (window), button);
308 arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_OUT);
309 gtk_widget_show (arrow);
310 gtk_container_add (GTK_CONTAINER (button), arrow);
312 gtk_window_move (GTK_WINDOW (window), -500, -500);
313 gtk_widget_show (window);
315 gtk_widget_size_request (window, &req);
319 gtk_widget_destroy (window);
Date and Time handling routines.
char * qof_print_date(time64 secs)
time64 gnc_mktime(struct tm *time)
calculate seconds from the epoch given a time struct
gboolean qof_scan_date(const char *buff, int *day, int *month, int *year)