wxTextCtrl (drag&drop)
Posted: Wed Jan 07, 2009 8:48 pm
есть ли у кого нибудь простой пример реализации перетаскивания файлов(из проводника) в wxTextCtrl?
Official forum for the wxWidgets Cross-Platform GUI Toolkit
https://forums.wxwidgets.org/
Code: Select all
#include <wx/app.h>
#include <wx/frame.h>
#include <wx/textctrl.h>
#include <wx/dnd.h>
#include <wx/filename.h>
#define MAIN_WINDOW_ID 1000
class DnDFile : public wxFileDropTarget{
private:
wxTextCtrl *TargetTextCtrl;
public:
DnDFile(wxTextCtrl *target) {TargetTextCtrl = target; }
virtual bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString &filenames);
};
bool DnDFile::OnDropFiles(wxCoord, wxCoord, const wxArrayString &filenames)
{
wxFileName file(filenames[0]);
if(file.GetExt() == "txt") TargetTextCtrl->LoadFile(filenames[0]);
return true;
}
//---------------------------------------
class MainWindow : public wxFrame{
private:
wxTextCtrl *text_ctrl;
public:
MainWindow(wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size, long style, const wxString &name);
virtual ~MainWindow();
};
MainWindow::MainWindow(wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &pos, const wxSize &size, long style, const wxString &name)
: wxFrame(parent,id, title, pos, size, style, name)
{
text_ctrl = new wxTextCtrl(this, wxID_ANY,wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
text_ctrl->SetDropTarget(new DnDFile(text_ctrl));
}
//---------------------------------------
MainWindow::~MainWindow()
{
}
//---------------------------------------
class Application : public wxApp{
public:
bool OnInit();
};
IMPLEMENT_APP(Application)
bool Application::OnInit()
{
MainWindow *main_window = new MainWindow(NULL,MAIN_WINDOW_ID, wxT("test"),
wxPoint(100,100), wxSize(640,480),
wxDEFAULT_FRAME_STYLE, "test");
main_window->Show();
return true;
}
Code: Select all
virtual void GetAllFormats( wxDataFormat *formats, Direction dir = Get) const
Это понятно, но есть ещё такая вещь как сигнатура... Но к текстовым файлам это конечно не относится)Ну так вообще-то любой файл - бинарный.
A MIME type may have one or more associated extensions: "text/plain" will typically correspond to the extension ".txt", but may as well be associated with ".ini" or ".conf".