GNOME Bugzilla – Bug 117297
dnd support for GtkCalendar
Last modified: 2004-12-22 21:47:04 UTC
I think it would be nice if GtkCalendar supported dnd. Here is a patch which lets GtkCalendar work as a drag source with targets application/x-date (format 16, DMY representation of date) and TEXT (strftime %F) and accept application/x-date when dropping on the calendar.
Created attachment 18247 [details] [review] calendar dnd
=== if (event->button == 1) stop_spinning (widget); + if (private_data->in_drag) + private_data->in_drag = 0; === Consider "press 1, release 2, release 2" - I don't think you should unset in_drag until button 1 is released. === g_signal_emit (calendar, gtk_calendar_signals[DAY_SELECTED_DOUBLE_CLICK_SIGNAL], 0); + private_data->in_drag = 0; === I'd unset in_drag before calling out to user code ... think about the user code putting up a modal dialog or setting the calendar insensitive. (Actuall,y stop_spinning probably should unset in_drag, but still, it's best to make state modifications prior to calling user code) === +static const GtkTargetEntry target_table[] = { + { "application/x-date", 0, 0 }, + { "TEXT", 0, 0 }, +}; === - The info field is meant to be set to an enum, so you don't have to do: if (selection_data->target == gdk_atom_intern ("application/x-date", FALSE)) You just 'switch (info) {}' - You shouldn't just provide "TEXT" here, but also STRING/UTF8_STRING. (Also text/plain in theory, but see 55117 for what needs to be fixed first.) - You should ask on xdg-list for examples anybody knows of date DND so we don't create yet another case of incompatible DND that should be compatible. === + gsize len = g_date_strftime (str, 127, "%F", date); + gtk_selection_data_set_text (selection_data, str, len); ==== Would '%x' be better than '%F'? The ISO 2003-07-18 dates, though nice, would seem exotic for most US users certainly, not what they would expect to get if they wanted a printed representation of a date. Another question: Would it be a good idea to accept DND of strings and use g_date_set_parse() to parse it? You can even get the data during the drag and show the appropriate feedback. Unfortunately, g_date_set_parse() is sort of hard to use here, since it doesn't give indication of success failure ... so you'd have to set the date to something artificial then check if it changed after g_date_set_parse()
g_date_set_parse() has some official way of checking failure, I think it's in the docs. You g_date_init() then parse then check g_date_is_valid() or something like that.
I've actually searched for examples of date dnd but couldn't find any. I'll ask on xdg-list just to be sure. You're probably right that %x is better than %F, but maybe this needs to be configurable (Thinking of the calendar panel applet, one would probably expect dnd to use the same format as the one used to display the date on the panel). I'll look into accepting text drops if they are parseable as a date.
Created attachment 18529 [details] [review] new patch
The new patch should incorporate all your comments. It uses %x and accepts TEXT drops if they are g_date_set_parse()-parseable. I had some fun figuring out how to indicate that a drop isn't accepted if the data isn't parseable. I'll try to squeeze some dnd api docs out of that experience...
This has been committed now, without support for the application/x-data format. It can be added later, when sufficient agreement on a suitable data format has been reached.