#include "wx/dnd.h"
+#ifdef __WXGTK__
+#include "mondrian.xpm"
+#endif
+
// ----------------------------------------------------------------------------
// Derive 2 simple classes which just put in the listbox the strings (text or
// file names) we drop on them
void OnHelp (wxCommandEvent& event);
void OnLogClear(wxCommandEvent& event);
- void OnMouseBtnDown(wxMouseEvent& event);
+ void OnLeftDown(wxMouseEvent& event);
+ void OnRightDown(wxMouseEvent& event);
bool OnClose();
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
-
- EVT_LEFT_DOWN(OnMouseBtnDown)
- EVT_RIGHT_DOWN(OnMouseBtnDown)
- EVT_MIDDLE_DOWN(OnMouseBtnDown)
+ EVT_LEFT_DOWN(OnLeftDown)
+ EVT_RIGHT_DOWN(OnRightDown)
END_EVENT_TABLE()
// `Main program' equivalent, creating windows and returning main app frame
bool DnDApp::OnInit(void)
{
// create the main frame window
- DnDFrame *frame = new DnDFrame(NULL, "Drag & Drop wxWindows App",
+ DnDFrame *frame = new DnDFrame((wxFrame *) NULL, "Drag & Drop wxWindows App",
50, 50, 450, 340);
// activate it
m_strText("wxWindows drag & drop works :-)")
{
+
+#ifdef __WXMSW__
// frame icon and status bar
SetIcon(wxIcon("mondrian"));
+#else
+ SetIcon(wxIcon(mondrian_xpm));
+#endif
+
const int widths[] = { -1 };
CreateStatusBar();
m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL);
m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL);
+
m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size,
wxTE_MULTILINE | wxTE_READONLY |
wxSUNKEN_BORDER| wxHSCROLL);
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
// associate drop targets with 2 text controls
+#ifdef __WXMSW__ // it's not supported (yet) on other platforms
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
- m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
+#endif //MSW
+ m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
wxLayoutConstraints *c;
void DnDFrame::OnHelp(wxCommandEvent& /* event */)
{
wxMessageDialog dialog(this,
-"This small program demonstrates drag & drop support in wxWindows. "
-"The program window consists of 3 parts: the bottom pane is for "
-"debug messages, so that you can see what's going on inside. "
-"The top part is split into 2 listboxes, the left one accepts "
-"files and the right one accepts text."
-"\n\n"
-"To test wxDropTarget: open wordpad (write.exe), select some text in "
-"it and drag it to the right listbox (you'll notice the usual visual "
-"feedback, i.e. the cursor will change). Also, try dragging some "
-"files (you can select several at once) from Windows Explorer (or "
-"File Manager) to the left pane. Hold down Ctrl/Shift keys when "
-"you drop text (doesn't work with files) and see what changes. "
-"\n\n"
-"To test wxDropSource: just press any mouse button on the empty zone of "
-"the window and drag it to wordpad or any other droptarget accepting "
-"text (and of course you can just drag it to the right pane). Due to "
-"a lot of trace messages, the cursor might take some time to change, "
-"don't release the mouse button until it does. You can change the "
-"string being dragged in in \"File|Test drag...\" dialog."
-"\n\n"
-"Please send all questions/bug reports/suggestions &c to "
+"This small program demonstrates drag & drop support in wxWindows. The program window\n"
+"consists of 3 parts: the bottom pane is for debug messages, so that you can see what's\n"
+"going on inside. The top part is split into 2 listboxes, the left one accepts files\n"
+"and the right one accepts text.\n"
+"\n"
+"To test wxDropTarget: open wordpad (write.exe), select some text in it and drag it to\n"
+"the right listbox (you'll notice the usual visual feedback, i.e. the cursor will change).\n"
+"Also, try dragging some files (you can select several at once) from Windows Explorer (or \n"
+"File Manager) to the left pane. Hold down Ctrl/Shift keys when you drop text (doesn't \n"
+"work with files) and see what changes.\n"
+"\n"
+"To test wxDropSource: just press any mouse button on the empty zone of the window and drag\n"
+"it to wordpad or any other droptarget accepting text (and of course you can just drag it\n"
+"to the right pane). Due to a lot of trace messages, the cursor might take some time to \n"
+"change, don't release the mouse button until it does. You can change the string being\n"
+"dragged in in \"File|Test drag...\" dialog.\n"
+"\n"
+"\n"
+"Please send all questions/bug reports/suggestions &c to \n"
"Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>",
"wxDnD Help");
dialog.ShowModal();
}
-void DnDFrame::OnLogClear(wxCommandEvent& event)
+void DnDFrame::OnLogClear(wxCommandEvent& /* event */ )
{
m_ctrlLog->Clear();
}
return TRUE;
}
-void DnDFrame::OnMouseBtnDown(wxMouseEvent& event)
+void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
if ( !m_strText.IsEmpty() ) {
// start drag operation
+
wxTextDataObject data(m_strText);
- wxDropSource dragSource(data);
+ wxDropSource dragSource(data, this);
const char *pc;
switch ( dragSource.DoDragDrop(TRUE) ) {
}
}
+void DnDFrame::OnRightDown(wxMouseEvent &event )
+{
+ wxMenu *menu = new wxMenu;
+
+ menu->Append(Menu_Drag, "&Test drag...");
+ menu->Append(Menu_About, "&About");
+ menu->Append(Menu_Quit, "E&xit");
+
+ PopupMenu( menu, event.GetX(), event.GetY() );
+}
+
DnDFrame::~DnDFrame()
{
if ( m_pLog != NULL ) {