#include "wx/dnd.h"
-#ifdef __WXGTK__
+#ifdef __WXMOTIF__
+#error Sorry, drag and drop is not yet implemented on wxMotif.
+#endif
+
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
#include "mondrian.xpm"
#endif
// Derive two simple classes which just put in the listbox the strings (text or
// file names) we drop on them
// ----------------------------------------------------------------------------
+
class DnDText : public wxTextDropTarget
{
public:
DnDText(wxListBox *pOwner) { m_pOwner = pOwner; }
- virtual bool OnDropText(long x, long y, const char *psz);
+ virtual bool OnDropText(long x, long y, const char *psz );
private:
wxListBox *m_pOwner;
DnDFile(wxListBox *pOwner) { m_pOwner = pOwner; }
virtual bool OnDropFiles(long x, long y,
- size_t nFiles, const char * const aszFiles[]);
+ size_t nFiles, const char * const aszFiles[] );
private:
wxListBox *m_pOwner;
// ----------------------------------------------------------------------------
// Define a new application type
// ----------------------------------------------------------------------------
+
class DnDApp : public wxApp
{
public:
// ----------------------------------------------------------------------------
// IDs for the menu commands
// ----------------------------------------------------------------------------
+
enum
{
Menu_Quit = 1,
m_strText("wxWindows drag & drop works :-)")
{
- SetBackgroundColour(* wxWHITE);
+// SetBackgroundColour(* wxWHITE);
// frame icon and status bar
SetIcon(wxICON(mondrian));
m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size,
wxTE_MULTILINE | wxTE_READONLY |
- wxSUNKEN_BORDER| wxHSCROLL);
+ wxSUNKEN_BORDER );
// redirect log messages to the text window (don't forget to delete it!)
m_pLog = new wxLogTextCtrl(m_ctrlLog);
// associate drop targets with 2 text controls
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
- m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
+ m_ctrlText->SetDropTarget( new DnDText(m_ctrlText) );
wxLayoutConstraints *c;
GetClientSize( &w, &h );
wxPaintDC dc(this);
- dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL ) );
- dc.DrawText( "Drag text from here!", 20, h-30 );
+ dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
+ dc.DrawText( "Drag text from here!", 20, h-22 );
}
void DnDFrame::OnDrag(wxCommandEvent& /* event */)
void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
{
- if ( !m_strText.IsEmpty() ) {
+ if ( !m_strText.IsEmpty() )
+ {
// start drag operation
-
- wxTextDataObject data(m_strText);
- wxDropSource dragSource(data, this);
+#ifdef __WXMSW__
+ wxTextDataObject textData(m_strText);
+ wxDropSource dragSource( textData, this );
+#else
+ wxDropSource dragSource( new wxTextDataObject (m_strText), this );
+#endif
const char *pc;
- switch ( dragSource.DoDragDrop(TRUE) ) {
+ switch ( dragSource.DoDragDrop(TRUE) )
+ {
case wxDragError: pc = "Error!"; break;
case wxDragNone: pc = "Nothing"; break;
case wxDragCopy: pc = "Copied"; break;