Anyone can explain me drag&drop with wxDataObject ? Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Sickboy
Experienced Solver
Experienced Solver
Posts: 91
Joined: Wed Mar 16, 2005 10:30 pm
Location: Germany

Anyone can explain me drag&drop with wxDataObject ?

Post by Sickboy »

I try to drag&drop an object of my class for a while, but stuck here:
http://forums.wxwidgets.org/viewtopic.p ... highlight=

I've tried to simplify my problem using a wxString to drag&drop with a wxDataObject but again without success :(

this is the code:

Code: Select all

ReactionDnDObject::ReactionDnDObject(void* buf, size_t len)
{
		this->m_Reaction   = new wxString( (*(wxString*)buf) );
		this->m_ObjLen     = sizeof(*this->m_Reaction);
		wxLogDebug(wxT("Constructor buf: %s"),*m_Reaction);
}

bool         ReactionDnDObject::SetData( const wxDataFormat& format, size_t len, const void *buf )
{
      		 wxLogDebug(wxT("Set Data buf: %s"),*((wxString*)buf));   // here i can't access buf
                if (this->m_Reaction)
      		 delete this->m_Reaction;
                 m_Reaction = new wxString( (*(wxString*)buf) );
                 this->m_ObjLen     = len;
}

bool         ReactionDnDObject::GetDataHere(const wxDataFormat& format, void *buf )const
{
	 buf = (void*)(new wxString(*this->m_Reaction));
         wxLogDebug(wxT("GetDataHere buf:%s"),*((wxString*)buf));
         return true;
}

size_t       ReactionDnDObject::GetDataSize(const wxDataFormat& format )const
{
        return  m_ObjLen;
};
anyone see what is wrong ?

thx
ssigala
Earned some good credits
Earned some good credits
Posts: 109
Joined: Fri Sep 03, 2004 9:30 am
Location: Brescia, Italy

Re: Anyone can explain me drag&drop with wxDataObject ?

Post by ssigala »

Code: Select all

// this cannot work:
      		 wxLogDebug(wxT("Set Data buf: %s"),*((wxString*)buf));   // here i can't access buf
// you cannot pass a wxString when a (char *) is expected:
      		 wxLogDebug(wxT("Set Data buf: %s"),((wxString*)buf)->c_str());   // *should* work
// ...

         wxLogDebug(wxT("GetDataHere buf:%s"),*((wxString*)buf)); // same here
Sandro Sigala - Kynosoft, Brescia
Post Reply