0

I have a wxTextCtrl-derived class that overrides OnDropFiles. However, dragging something over the control does nothing. (The cursor changes to the 'not allowed' cursor.) I tried DragAcceptFiles(true) but that only enabled the built-in drop handler. (Which just loads the file into the control.) How can I get my own handler to be invoked?

I also tried SetDropTarget, but that never got invoked either. It worked in a wxFrame, though.

Any ideas?

Esko
  • 29,022
  • 11
  • 55
  • 82
Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

2 Answers2

1

This is a stripped down version of what I have in one of my projects:

My form code

wxTextCtrl* textctrl = new wxTextCtrl(...);
textctrl->SetDropTarget(new DropFiles(textctrl));

The dropfiles class

class DropFiles: public wxFileDropTarget{
public:
    DropFiles(wxTextCtrl *text): m_Text(text){}
    bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& arrFilenames);

private:
    wxTextCtrl *m_Text;
};

bool DropFiles::OnDropFiles(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y), const wxArrayString& arrFilenames){
    //Just take the first filename
    m_Text->SetValue(arrFilenames.Item(0));
    return true;
}

Hope that helps!

SteveL
  • 1,811
  • 1
  • 13
  • 23
  • Thanks for trying but that still didn't work - OnDropFiles never gets called. I did find a solution, though. See my answer. – Nathan Osman Jan 11 '10 at 01:47
  • Odd, I certainly don't handle it, I guess it is because you are deriving from wxTextCtrl perhaps? – SteveL Jan 14 '10 at 18:26
0

You have to handle the EVT_DROP_FILES event. Any other attempt to get notified will fail :(

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361