static void gtk_dateentry_popup_display (GtkDateEntry * dateentry) { const char *str; int month; //gint height, width, x, y; gint old_width, old_height; DB( g_print(" (dateentry) popup_display\n****\n\n") ); old_width = dateentry->popwin->allocation.width; old_height = dateentry->popwin->allocation.height; /* update */ str = gtk_entry_get_text (GTK_ENTRY (dateentry->entry)); g_date_set_parse (dateentry->date, str); if(g_date_valid(dateentry->date) == TRUE) { /* GtkCalendar expects month to be in 0-11 range (inclusive) */ month = g_date_get_month (dateentry->date) - 1; gtk_calendar_select_month (GTK_CALENDAR (dateentry->calendar), CLAMP (month, 0, 11), g_date_get_year (dateentry->date)); gtk_calendar_select_day (GTK_CALENDAR (dateentry->calendar), g_date_get_day (dateentry->date)); } position_popup(dateentry); gtk_widget_show (dateentry->popwin); gtk_grab_add (dateentry->popwin); // this close the popup */ gdk_pointer_grab (dateentry->popwin->window, TRUE, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK, NULL, NULL, GDK_CURRENT_TIME); }
static void gnc_date_edit_popup (GNCDateEdit *gde) { GtkWidget *toplevel; struct tm mtm; gboolean date_was_valid; GdkDevice *device, *keyboard, *pointer; g_return_if_fail (GNC_IS_DATE_EDIT (gde)); ENTER("gde %p", gde); device = gtk_get_current_event_device (); /* This code is pretty much just copied from gtk_date_edit_get_date */ date_was_valid = qof_scan_date (gtk_entry_get_text (GTK_ENTRY (gde->date_entry)), &mtm.tm_mday, &mtm.tm_mon, &mtm.tm_year); if (!date_was_valid) { /* No valid date. Hacky workaround: Instead of crashing we randomly choose today's date. */ gnc_tm_get_today_start(&mtm); } mtm.tm_mon--; /* Hope the user does not actually mean years early in the A.D. days... * This date widget will obviously not work for a history program :-) */ if (mtm.tm_year >= 1900) mtm.tm_year -= 1900; gnc_tm_set_day_start(&mtm); /* Set the calendar. */ gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), 1); gtk_calendar_select_month (GTK_CALENDAR (gde->calendar), mtm.tm_mon, 1900 + mtm.tm_year); gtk_calendar_select_day (GTK_CALENDAR (gde->calendar), mtm.tm_mday); /* Make sure we'll get notified of clicks outside the popup * window so we can properly pop down if that happens. */ toplevel = gtk_widget_get_toplevel (GTK_WIDGET (gde)); if (GTK_IS_WINDOW (toplevel)) { gtk_window_group_add_window ( gtk_window_get_group (GTK_WINDOW (toplevel)), GTK_WINDOW (gde->cal_popup)); gtk_window_set_transient_for (GTK_WINDOW (gde->cal_popup), GTK_WINDOW (toplevel)); } position_popup (gde); gtk_widget_show (gde->cal_popup); gtk_widget_grab_focus (gde->cal_popup); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (gde->date_button), TRUE); if (gdk_device_get_source (device) == GDK_SOURCE_KEYBOARD) { keyboard = device; pointer = gdk_device_get_associated_device (device); } else { pointer = device; keyboard = gdk_device_get_associated_device (device); } if (!gtk_widget_has_focus (gde->calendar)) gtk_widget_grab_focus (gde->calendar); if (!popup_grab_on_window (gtk_widget_get_window ((GTK_WIDGET(gde->cal_popup))), keyboard, pointer, GDK_CURRENT_TIME)) { gtk_widget_hide (gde->cal_popup); LEAVE("Failed to grab window"); return; } gtk_grab_add (gde->cal_popup); LEAVE(" "); }