RE: [gtkmm] Passing a pointer to a class using D&D



Thanks Vlad and Timothy,

Here's my conclusion, in case it helps anyone out.  The point about
different address spaces makes good since from a design point of view
for the D&D design.  My target types were all planned to be internal
except for a string of a file path, but I see why it wouldn't make sense
to support passing an address.  The idea of just using a temporary
global object is a good work around I think and I'll look into it.  The
problem with that is that the entire application is not my own, so
getting global objects or methods to get access to the main window (as
Vlad did in the code below) is a bit of a pain.  For now, I passed the
address as a string rather than an integer and then cast it back into a
pointer on the other end.  This seems to work.  Dangerous, but a simple
enough hack until I can get a temporary object worked in.  Thanks for
the help.

~Ryan

> -----Original Message-----
> From: Vladislav Grinchenko [mailto:3rdshift comcast net] 
> Sent: Thursday, August 05, 2004 10:29 PM
> To: Miller, Ryan D
> Cc: Gtkmm list
> Subject: Re: [gtkmm] Passing a pointer to a class using D&D
> 
> 
> Ryan,
> 
> why bother - if you dnd in the same application, you can keep 
> all info you want in a temp object visible to both source and 
> target. I tried it all a couple of weeks ago and discovered 
> that passing casted pointers to anything is clearly 
> dangerous. String are fine but that's about it.
> 
> Here's what I ended up with -
> source - 
> http://cvs.sourceforge.net/viewcvs.py/granule/granule/src/Deck
> List.cpp?rev=1.10&view=auto
> (on_drag_begin(), on_drag_data_get())
> 
> target - 
> http://cvs.sourceforge.net/viewcvs.py/granule/granule/src/Card
> Box.cpp?rev=1.35&view=auto
> (on_deck_dropped_cb())
> 
> hope this helps,
> -Vlad
> 
> 
> On Thu, 2004-08-05 at 09:12, Miller, Ryan D wrote:
> > Greetings everyone,
> > 
> > Another question for the great readers of gtkmm list.  I need to 
> > access several fields of information from a class after a user 
> > performs a drag from that class onto another one.  (Both 
> classes are 
> > derived from EventBoxes).  I figured out how to pass a 
> single value, 
> > such as a string, based on the examples by casting the 
> string into a 
> > guchar* and then using get_data_as_string on the receiving end.  In 
> > order to pass more than one thing, I was hoping to pass the 
> address of 
> > the passing and then create a pointer to the passing class on the 
> > receiving end and use that to access what I need.  Is this 
> a feasible 
> > way to do this?  In a more concise manner: I would like to pass a 
> > pointer to "this" using D&D. The code I have right now is 
> below, but I 
> > end up with different values for the addresses on both ends.  Does 
> > anyone know how to do this?
> > 
> > In drag_data_get(..) in my passing class:
> > 
> >   Selection_data.set( selection_data.get_target(), 8, (const guint8 
> > *)this, sizeof(this));
> > 
> > In drag_data_received(..) in my receiving class (templateBoxTarget):
> > 
> >   templateBoxTarget *t = (templateBoxTarget *) 
> > selection_data.get_data();
> > 
> > And I have also tried something like this as a shot in the 
> dark, but 
> > got the same results:
> >   void *pVoid = (void *)selection_data.get_data();
> >   templateBoxTarget *t = static_cast<templateBoxTarget *> (pVoid);
> > 
> > Thanks!,
> > Ryan
> > _______________________________________________
> > gtkmm-list mailing list
> > gtkmm-list gnome org 
> http://mail.gnome.org/mailman/listinfo/gtkmm-> list
> -- 
> 
> 
> _____________________________________________________________
> Vladislav Grinchenko       http://home.comcast.net/~3rdshift/
>                                  e-mail: 3rdshift comcast net
>                                                    
>       Focus on quality, and productivity will follow. 
> _____________________________________________________________
> 
> 



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