]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dnd/dnd.cpp
fix for bug in wxEditableListBox in connection with new wxListCtrl
[wxWidgets.git] / samples / dnd / dnd.cpp
index 39b58f179e5f767d80e5fcb5667d6cace544c7c8..4f5f76d60e970869f1e59b6e5ec8210676a34d1c 100644 (file)
 
 #if defined(__WXGTK__) || defined(__WXMOTIF__)
     #include "mondrian.xpm"
 
 #if defined(__WXGTK__) || defined(__WXMOTIF__)
     #include "mondrian.xpm"
+
+    #include "dnd_copy.xpm"
+    #include "dnd_move.xpm"
+    #include "dnd_none.xpm"
 #endif
 
 // ----------------------------------------------------------------------------
 #endif
 
 // ----------------------------------------------------------------------------
@@ -76,6 +80,39 @@ private:
     wxListBox *m_pOwner;
 };
 
     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
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // 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);
 
     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_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
     m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
+    m_ctrlLog->SetDropTarget(new URLDropTarget);
 
     wxLayoutConstraints *c;
 
 
     wxLayoutConstraints *c;
 
@@ -1065,14 +1103,10 @@ void DnDFrame::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
         textData.AddFile( "/file1.txt" );
         textData.AddFile( "/file2.txt" );
 */
         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;
 
 
         const char *pc;
 
@@ -1511,19 +1545,19 @@ DnDShapeFrame::DnDShapeFrame(wxFrame *parent)
     SetDropTarget(new DnDShapeDropTarget(this));
 
     m_shape = NULL;
     SetDropTarget(new DnDShapeDropTarget(this));
 
     m_shape = NULL;
-    
+
     SetBackgroundColour(*wxWHITE);
 }
 
 DnDShapeFrame::~DnDShapeFrame()
 {
     SetBackgroundColour(*wxWHITE);
 }
 
 DnDShapeFrame::~DnDShapeFrame()
 {
-    if (m_shape) 
+    if (m_shape)
         delete m_shape;
 }
 
 void DnDShapeFrame::SetShape(DnDShape *shape)
 {
         delete m_shape;
 }
 
 void DnDShapeFrame::SetShape(DnDShape *shape)
 {
-    if (m_shape) 
+    if (m_shape)
         delete m_shape;
     m_shape = shape;
     Refresh();
         delete m_shape;
     m_shape = shape;
     Refresh();
@@ -1772,7 +1806,7 @@ static void ShowBitmap(const wxBitmap& bitmap)
     frame->SetStatusText(wxString::Format(_T("%dx%d"), w, h));
 
     frame->SetClientSize(w > 100 ? 100 : w, h > 100 ? 100 : h);
     frame->SetStatusText(wxString::Format(_T("%dx%d"), w, h));
 
     frame->SetClientSize(w > 100 ? 100 : w, h > 100 ? 100 : h);
-    frame->Show();
+    frame->Show(TRUE);
 }
 
 #ifdef USE_METAFILES
 }
 
 #ifdef USE_METAFILES