Drag&Drop changes?

Christian Buhtz exsudat at gmx.de
Wed Aug 15 05:40:39 PDT 2007


Vadim Zeitlin schrieb:
> Where does the "filenames" parameter (the one containing incorrect data)
> comes from?

Ok, there is a wxPanel derived class BFDirCtrl. It contains a 
'wxGenericDirCtrl* pDirCtrl_' as attribute.

In the ctor of BFDirCtrl I set the begin-drag-event-handler
     // install handlers
     pDirCtrl_->GetTreeCtrl()->Connect
     (
         wxID_ANY,
         wxEVT_COMMAND_TREE_BEGIN_DRAG,
         wxTreeEventHandler (BFDirCtrl::OnBeginDrag),
         NULL,
         this
     );


The handler looks like this
void BFDirCtrl::OnBeginDrag (wxTreeEvent& event)
{
     wxFileDataObject    my_data;
     wxDropSource        dragSource  ( this );

     pDirCtrl_->GetTreeCtrl()->SelectItem(event.GetItem());
     my_data.AddFile(pDirCtrl_->GetPath());
     /* with the next line I see a MsgBox with the givin parameter
        the parameter is valid and ok */
     BFSystem::Info(pDirCtrl_->GetPath());
     dragSource.SetData(my_data);

     wxDragResult result = dragSource.DoDragDrop( TRUE );
}

GetPath() is declared as this
virtual wxString GetPath() const;

As I describe in the code, the return value of GetPath() is ok.

And after dragging and releasing the mouse button the OnDropFiles() 
handler is called.

There is a wxTreeCtrl derived class BFBackupTree with a private class 
BFBackupDropTarget in it. In the ctor of BFBackupTree I just set the 
drop-target with this line
SetDropTarget   ( new BFBackupDropTarget(this) );

And the handler looks like this

bool BFBackupTree::BFBackupDropTarget::OnDropFiles(wxCoord x, wxCoord y, 
const wxArrayString& filenames)
{
     BFSystem::Info(filenames[0]);
     return pBackupTree_->OnDropFiles(x, y, filenames);
}

With BFSystem::Info() I test the parameter again and here it is 
not-valid. There is just character-salad.





More information about the wx-dev mailing list