Is it possible to reject drag/dropped files based on filetype?

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
wonkey_monkey
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sun May 26, 2019 8:10 pm

Is it possible to reject drag/dropped files based on filetype?

Post by wonkey_monkey »

Years ago I remember finding out how to reject (by changing the cursor to a denial cursor) a drag/dropped file based on its filetype in a basic WINAPI program. Is it possible to do something similar in wxWidgets?

I have a class derived from wxWindow. I can DragAcceptFiles() easily enough, but it doesn't seem to allow me any way to discriminate before the file is dropped.

My grasp of inheritance, and in fact OOP in general, can be a little shaky. I've tried inherting from both wxWindow and wxFileDropTarget, which has an OnEnter() member for when a dragged file enters it, but my override of it, and wxFileDropTarget's OnDropFiles(), doesn't seem to get called.

avsPanel.h:

Code: Select all

class avsPanel : public wxWindow, public wxFileDropTarget {
public:
	avsPanel(wxWindow* parent);
	void set_other_panel(avsPanel* a);
	wxDragResult OnEnter(wxCoord x, wxCoord y, wxDragResult defResult);
	bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& st);

private:
	...
avsPanel.cpp:

Code: Select all

avsPanel::avsPanel(wxWindow* parent) : wxWindow(parent, wxID_ANY), wxFileDropTarget() {
	this->DragAcceptFiles(true);
}

#define SB ((wxFrame*)this->GetParent())->GetStatusBar()

wxDragResult avsPanel::OnEnter(wxCoord x, wxCoord y, wxDragResult defResult) {
	SB->SetStatusText("OnEnter", 0); // this code changes the status bar text of the main frame (definitely works)
	return defResult;
}

bool avsPanel::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& st) {
	SB->SetStatusText("OnDropFiles", 0); // this code changes the status bar text of the main frame (definitely works)
	return false;
}
Am I barking up completely the wrong tree with this?
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible to reject drag/dropped files based on filetype?

Post by doublemax »

The place to do it would be wxDropTarget::OnDragOver(). But unfortunately there is no way to get the list of files from there.

See this related discussion on wx-users:
https://groups.google.com/forum/#!msg/w ... XYoYwpK_YJ
Use the source, Luke!
wonkey_monkey
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sun May 26, 2019 8:10 pm

Re: Is it possible to reject drag/dropped files based on filetype?

Post by wonkey_monkey »

Ah okay, so it sounds like something that isn't implemented and so can't be done purely in wxWidgets. I'll look into doing it natively.

Out of interest, was I going about the multiple inheritance thing the right way? I'm still not sure why OnDropFiles() and OnEnter() weren't being called.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Is it possible to reject drag/dropped files based on filetype?

Post by doublemax »

I don't really see the point in that class, usually just deriving from wx[File]DropTarget should be enough.

Maybe there's just a call to SetDropTarget(this) missing?
Use the source, Luke!
wonkey_monkey
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sun May 26, 2019 8:10 pm

Re: Is it possible to reject drag/dropped files based on filetype?

Post by wonkey_monkey »

Yes, that was it, thanks.
Post Reply