After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 117297 - dnd support for GtkCalendar
dnd support for GtkCalendar
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.2.x
Other other
: Normal enhancement
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2003-07-12 23:04 UTC by Matthias Clasen
Modified: 2004-12-22 21:47 UTC
See Also:
GNOME target: ---
GNOME version: Unversioned Enhancement


Attachments
calendar dnd (7.98 KB, patch)
2003-07-12 23:05 UTC, Matthias Clasen
none Details | Review
new patch (12.05 KB, patch)
2003-07-23 00:21 UTC, Matthias Clasen
none Details | Review

Description Matthias Clasen 2003-07-12 23:04:30 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.
Comment 1 Matthias Clasen 2003-07-12 23:05:09 UTC
Created attachment 18247 [details] [review]
calendar dnd
Comment 2 Owen Taylor 2003-07-18 21:40:12 UTC
===
   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()
Comment 3 Havoc Pennington 2003-07-18 21:58:36 UTC
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.
Comment 4 Matthias Clasen 2003-07-18 22:03:43 UTC
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.
Comment 5 Matthias Clasen 2003-07-23 00:21:45 UTC
Created attachment 18529 [details] [review]
new patch
Comment 6 Matthias Clasen 2003-07-23 00:25:15 UTC
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...
Comment 7 Matthias Clasen 2003-08-08 23:02:18 UTC
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.