I had previously created a Java version, but became interested in wxWidgets and decided to rewrite it for a learning project.
Questions:
a) is DnD only in the win32 port? Are there any plans to extend it to other Ports?
b) How can I change the default behavior of a DnD component?
Example: I have a wxTextCtrl. I call DragAcceptFiles(true) on it. When a file is dragged to it, it opens the file. However, since this file is binary, that's no good. I want to change the behavior.
The docs say the default behavior is in OnDropFiles. So I subclassed wxTextCtrl and added the OnDropFiles method with the same signature as in the manual. This method is never called, and the default behavior doesn't go away.
I'm not a great C++ programmer. I've never written a real application in C++. I know C, and Java very well, but am just learning C++. But a lot of concepts still aren't 100% clear to me.
I tried making the method virtual, but this didn't help.
Code: Select all
#ifndef _CHTTEXTCONTROL_H
#define _CHTTEXTCONTROL_H
#include <wx/textctrl.h>
#include <wx/window.h>
#include <wx/event.h>
class CHTTextControl : public wxTextCtrl {
public:
CHTTextControl(wxWindow *);
void OnDropFiles(wxDropFilesEvent &);
};
#endif
CHTTextControl::CHTTextControl(wxWindow *parent) :
wxTextCtrl(parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxTE_MULTILINE | wxTE_READONLY | wxTE_RICH,
wxDefaultValidator, wxTextCtrlNameStr) {
DragAcceptFiles(true);
SetFont(wxFont(12, wxMODERN, wxNORMAL, wxNORMAL));
}
void CHTTextControl::OnDropFiles(wxDropFilesEvent &event) {
// just testing if we removed the default behavior
printf("CHTTextControl::OnDropFiles was called...\n");
fflush(stdout);
}
Any suggestions?