]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dnd/dnd.cpp
New module definition file to keep .dll build compilable.
[wxWidgets.git] / samples / dnd / dnd.cpp
index 6ba0420bb368e4d9388d57368110e7821cf1a987..4f5f76d60e970869f1e59b6e5ec8210676a34d1c 100644 (file)
 
 #if defined(__WXGTK__) || defined(__WXMOTIF__)
     #include "mondrian.xpm"
+
+    #include "dnd_copy.xpm"
+    #include "dnd_move.xpm"
+    #include "dnd_none.xpm"
 #endif
 
 // ----------------------------------------------------------------------------
@@ -76,6 +80,39 @@ private:
     wxListBox *m_pOwner;
 };
 
+// ----------------------------------------------------------------------------
+// Define a custom dtop target accepting URLs
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT URLDropTarget : public wxDropTarget
+{
+public:
+    URLDropTarget() { SetDataObject(new wxURLDataObject); }
+
+    void OnDropURL(wxCoord x, wxCoord y, const wxString& text)
+    {
+        // of course, a real program would do something more useful here...
+        wxMessageBox(text, _T("wxDnD sample: got URL"),
+                     wxICON_INFORMATION | wxOK);
+    }
+
+    // URLs can't be moved, only copied
+    virtual wxDragResult OnDragOver(wxCoord WXUNUSED(x), wxCoord WXUNUSED(y),
+                                    wxDragResult def)
+        { return def == wxDragMove ? wxDragCopy : def; }
+
+    // translate this to calls to OnDropURL() just for convenience
+    virtual wxDragResult OnData(wxCoord x, wxCoord y, wxDragResult def)
+    {
+        if ( !GetData() )
+            return wxDragNone;
+
+        OnDropURL(x, y, ((wxURLDataObject *)m_dataObject)->GetURL());
+
+        return def;
+    }
+};
+
 // ----------------------------------------------------------------------------
 // Define a new application type
 // ----------------------------------------------------------------------------
@@ -917,9 +954,10 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
     m_pLog = new wxLogTextCtrl(m_ctrlLog);
     m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
 
-    // associate drop targets with 2 text controls
+    // associate drop targets with the controls
     m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
     m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
+    m_ctrlLog->SetDropTarget(new URLDropTarget);
 
     wxLayoutConstraints *c;
 
@@ -1065,14 +1103,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
         textData.AddFile( "/file1.txt" );
         textData.AddFile( "/file2.txt" );
 */
-        wxDropSource source(textData, this
-
-#ifdef __WXMSW__
-                            ,wxCURSOR_PENCIL,           // for copy
-                            wxCURSOR_SPRAYCAN,          // for move
-                            wxCURSOR_QUESTION_ARROW     // for nothing
-#endif
-                            );
+        wxDropSource source(textData, this,
+                            wxDROP_ICON(dnd_copy),
+                            wxDROP_ICON(dnd_move),
+                            wxDROP_ICON(dnd_none));
 
         const char *pc;
 
@@ -1511,19 +1545,19 @@ DnDShapeFrame::DnDShapeFrame(wxFrame *parent)
     SetDropTarget(new DnDShapeDropTarget(this));
 
     m_shape = NULL;
-    
+
     SetBackgroundColour(*wxWHITE);
 }
 
 DnDShapeFrame::~DnDShapeFrame()
 {
-    if (m_shape) 
+    if (m_shape)
         delete m_shape;
 }
 
 void DnDShapeFrame::SetShape(DnDShape *shape)
 {
-    if (m_shape) 
+    if (m_shape)
         delete m_shape;
     m_shape = shape;
     Refresh();