Re: passing non-string data in drag and drop



    WAN Hing Wah> How?would u mind giving me an example source code?  from the
    WAN Hing Wah> GtkSelectionData structure seen in gtkdnd.h the data field
    WAN Hing Wah> is of type guchar * looking the source code of
    WAN Hing Wah> gtk_selection_set_data..  it will try to duplicate the
    WAN Hing Wah> string and store in the structure..instead of using the
    WAN Hing Wah> original pointer....in that way,I can't pass a pointer to
    WAN Hing Wah> the structure..moreover,even I use "data->data=widget"
    WAN Hing Wah> manually...  after the drag and drop event have ended.the
    WAN Hing Wah> data->data will be freed..so the gtkwidget structure will be
    WAN Hing Wah> freed and lead to serious error..  Can u give me example
    WAN Hing Wah> source code to handle it?

Wan Hing Wah, it is generally not a good idea to store a pointer to the
selection because another window for a program running on another machine
can get the selection and assume it is a valid pointer on this other machine.

You usually just want to create a buffer of bytes, write your data structure
out in a particular order to the buffer, what I refer to as 'encoding' your
data, and then call gtk_selection_data_set().  The application that gets the
contents of the selection needs to know how to 'decode' the data.  I have some
example code from one of my applications that I can send you directly if you
want (it is too big to include in this message).

But, if you really do need to store the pointer, do the following:

  GtkSelectionData *sd;
  GdkAtom type;
  gint format;
  sometype_t *p;

  ......

  gtk_selection_data_set(sd, type, format, (const guchar *) &p, sizeof(p));

This will store what you want.
-----------------------------------------------------------------------------
Mark Leisher
Computing Research Lab            Once you fully apprehend the vacuity of a
New Mexico State University       life without struggle, you are equipped
Box 30001, Dept. 3CRL             with the basic means of salvation.
Las Cruces, NM  88003                            -- Tennessee Williams




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]