Page 1 of 1

Anyone can explain me drag&drop with wxDataObject ?

Posted: Mon Sep 12, 2005 11:52 am
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

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

Posted: Tue Sep 13, 2005 1:13 pm
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