drag and drop

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Post Reply
jdratlif
Knows some wx things
Knows some wx things
Posts: 25
Joined: Mon Oct 11, 2004 2:12 pm
Location: in a small padded white room.
Contact:

drag and drop

Post by jdratlif » Mon Oct 11, 2004 3:07 pm

I am writing an application which decodes a binary record file to plain text.

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);
}
That printf() line is never reached, and the text control still tries to open the file (which is bad).

Any suggestions?
Find save states, game genie codes, and other misc emulation related goodies at emuWorks.

http://games.technoplaza.net

geon
I live to help wx-kind
I live to help wx-kind
Posts: 189
Joined: Tue Sep 07, 2004 4:10 pm
Location: Sweden, Uppsala

Post by geon » Mon Oct 11, 2004 9:54 pm

I think you need this line at the bottom of your class:

DECLARE_EVENT_TABLE()

... and in the .cpp file, there should be something like this:

BEGIN_EVENT_TABLE(CHTTextControl : public wxTextCtrl)
EVT_blablabla_EVENTS(CHTTextControl :: OnDropFiles)
END_EVENT_TABLE()

jdratlif
Knows some wx things
Knows some wx things
Posts: 25
Joined: Mon Oct 11, 2004 2:12 pm
Location: in a small padded white room.
Contact:

Post by jdratlif » Tue Oct 12, 2004 3:01 pm

geon wrote:I think you need this line at the bottom of your class:

DECLARE_EVENT_TABLE()

... and in the .cpp file, there should be something like this:

BEGIN_EVENT_TABLE(CHTTextControl : public wxTextCtrl)
EVT_blablabla_EVENTS(CHTTextControl :: OnDropFiles)
END_EVENT_TABLE()
I want to try this, but what kind of event would it be? Apologies. I'm new to wxWidgets.

I have seen EVT_MENU_EVENTS. But none of the EVT macros are in the windows compiled help (chm) file in the alphabetical functions and macros list. I'm pretty sure it's not a menu event.

I am also looking into the wxDropTarget which seems similar to the Java DnD API. I might be able to use that.
Find save states, game genie codes, and other misc emulation related goodies at emuWorks.

http://games.technoplaza.net

Lall
Earned a small fee
Earned a small fee
Posts: 13
Joined: Thu Sep 16, 2004 12:35 pm
Location: Belgium
Contact:

Post by Lall » Wed Oct 13, 2004 7:19 am

The event macro you're searching for is: EVT_DROP_FILES

BEGIN_EVENT_TABLE(CHTTextControl : public wxTextCtrl)
EVT_DROP_FILES(CHTTextControl :: OnDropFiles)
END_EVENT_TABLE()


I've actually never tried that method, I'm using the wxTextDropTarget class and SetDropTarget function of wxWindows class but that's for another application anyway... :)

Last thing, the method I'm using is successfully working under Win32 and Linux; I'm sure it must also work on other platforms ...
-----------------------------------
Lall

http://www.axoris.be
Axoris - Sound makes music
-----------------------------------

jdratlif
Knows some wx things
Knows some wx things
Posts: 25
Joined: Mon Oct 11, 2004 2:12 pm
Location: in a small padded white room.
Contact:

Post by jdratlif » Wed Oct 13, 2004 2:19 pm

Lall wrote:The event macro you're searching for is: EVT_DROP_FILES

BEGIN_EVENT_TABLE(CHTTextControl : public wxTextCtrl)
EVT_DROP_FILES(CHTTextControl :: OnDropFiles)
END_EVENT_TABLE()


I've actually never tried that method, I'm using the wxTextDropTarget class and SetDropTarget function of wxWindows class but that's for another application anyway... :)

Last thing, the method I'm using is successfully working under Win32 and Linux; I'm sure it must also work on other platforms ...
I should have looked more carefully. I saw the OnDropFiles thing and thought it was an easy way to add DragNDrop. Then it says it windows only. I hadn't thought they would make a win32 only method that for all intents and purposes isn't very useful.

Later I saw the wxDropTarget and looked at the example and I have it working now. But OnDropFiles is only implemented in Windows. I have working DragNDrop in Windows and Linux now for my app.

Thanks.
Find save states, game genie codes, and other misc emulation related goodies at emuWorks.

http://games.technoplaza.net

Post Reply