]> git.saurik.com Git - wxWidgets.git/commitdiff
wxDragImage fixes and cleanup
authorRobin Dunn <robin@alldunn.com>
Fri, 18 May 2001 23:46:30 +0000 (23:46 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 18 May 2001 23:46:30 +0000 (23:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10224 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

wxPython/CHANGES.txt
wxPython/demo/OOR.py
wxPython/demo/wxDragImage.py
wxPython/src/misc2.i
wxPython/src/msw/misc2.cpp
wxPython/src/msw/misc2.py
wxPython/src/windows.i

index 23a8157999f80ff23c4a5b035896f52d6e10dd92..1c9ce2137ef98e5791855db1dcccc4514aeba32a 100644 (file)
@@ -107,7 +107,7 @@ specific.  It could have been added long ago but OOR required it.
 Finally added wxPyLineShape.GetLineControlPoints, which has been on my
 list for a while.  The above OOR modification made this easier.
 
-Fixed the __cmp__ methods for wxPoiunt and others.
+Fixed the __cmp__ methods for wxPoint and others.
 
 Added wxWave.
 
index 0ece4652d02c724e7d5aa9ad8f59ed25d19c39cb..e7afc3b7854f0f16d2489344c86a83259f9b77b1 100644 (file)
@@ -27,7 +27,7 @@ class TestPanel(wxPanel):
         btns.Add(self.btn2)
         btns.Add(50, -1, 1, wxEXPAND)
 
-        sizer.Add(btns, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 25)
+        sizer.Add(btns, 0, wxEXPAND|wxALL, 15)
 
         self.SetSizer(sizer)
         self.SetAutoLayout(true)
index a74a072699f6e61277abd500eef3ca577ff440a4..d4124ae7fd8a519bb92be9c84b18b3a8475c4ff9 100644 (file)
@@ -47,6 +47,7 @@ class DragCanvas(wxScrolledWindow):
         self.shapes = []
         self.dragImage = None
         self.dragShape = None
+        self.hiliteShape = None
 
         self.SetCursor(wxStockCursor(wxCURSOR_ARROW))
         self.bg_bmp = images.getBackgroundBitmap()
@@ -55,8 +56,6 @@ class DragCanvas(wxScrolledWindow):
         # Make a shape from an image and mask.  This one will demo
         # dragging outside the window
         bmp = images.getTestStarBitmap()
-        #mask = wxMaskColour(bmp, wxWHITE)
-        #bmp.SetMask(mask)
         shape = DragShape(bmp)
         shape.pos = wxPoint(5, 5)
         shape.fullscreen = true
@@ -174,13 +173,13 @@ class DragCanvas(wxScrolledWindow):
         self.dragImage.EndDrag()
         self.dragImage = None
 
-        # reposition and draw the shape
-        pt = evt.GetPosition()
-        newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
-                         self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
-
         dc = wxClientDC(self)
-        self.dragShape.pos = newPos
+        if self.hiliteShape:
+            self.hiliteShape.Draw(dc)
+            self.hiliteShape = None
+
+        # reposition and draw the shape
+        self.dragShape.pos = self.dragShape.pos + evt.GetPosition() - self.dragStartPos
         self.dragShape.shown = true
         self.dragShape.Draw(dc)
         self.dragShape = None
@@ -194,13 +193,19 @@ class DragCanvas(wxScrolledWindow):
         if self.dragShape and not self.dragImage:
 
             # only start the drag after having moved a couple pixels
-            tolerance = 4
+            tolerance = 2
             pt = evt.GetPosition()
             dx = abs(pt.x - self.dragStartPos.x)
             dy = abs(pt.y - self.dragStartPos.y)
             if dx <= tolerance and dy <= tolerance:
                 return
 
+            # erase the shape since it will be drawn independently now
+            dc = wxClientDC(self)
+            self.dragShape.shown = false
+            self.EraseShape(self.dragShape, dc)
+
+
             if self.dragShape.text:
                 self.dragImage = wxDragString(self.dragShape.text,
                                               wxStockCursor(wxCURSOR_HAND))
@@ -208,34 +213,45 @@ class DragCanvas(wxScrolledWindow):
                 self.dragImage = wxDragImage(self.dragShape.bmp,
                                              wxStockCursor(wxCURSOR_HAND))
 
-            newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
-                             self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
+            hotspot = self.dragStartPos - self.dragShape.pos
+            self.dragImage.BeginDrag(hotspot, self, self.dragShape.fullscreen)
 
-            if self.dragShape.fullscreen:
-                newPos = self.ClientToScreen(newPos)
-                self.dragImage.BeginDrag((0,0), self, true)
-            else:
-                self.dragImage.BeginDrag((0,0), self)
-
-
-            # erase the shape since it will be drawn independently now
-            dc = wxClientDC(self)
-            self.dragShape.shown = false
-            self.EraseShape(self.dragShape, dc)
-
-            self.dragImage.Move(newPos)
+            self.dragImage.Move(pt)
             self.dragImage.Show()
 
 
-        # if we have shape and image then move it.
+        # if we have shape and image then move it, posibly highlighting another shape.
         elif self.dragShape and self.dragImage:
-            pt = evt.GetPosition()
-            newPos = wxPoint(self.dragShape.pos.x + (pt.x - self.dragStartPos.x),
-                             self.dragShape.pos.y + (pt.y - self.dragStartPos.y))
-            if self.dragShape.fullscreen:
-                newPos = self.ClientToScreen(newPos)
-
-            self.dragImage.Move(newPos)
+            onShape = self.FindShape(evt.GetPosition())
+            unhiliteOld = false
+            hiliteNew = false
+
+            # figure out what to hilite and what to unhilite
+            if self.hiliteShape:
+                if onShape is None or self.hiliteShape is not onShape:
+                    unhiliteOld = true
+
+            if onShape and onShape is not self.hiliteShape and onShape.shown:
+                hiliteNew = TRUE
+
+            # if needed, hide the drag image so we can update the window
+            if unhiliteOld or hiliteNew:
+                self.dragImage.Hide()
+
+            if unhiliteOld:
+                dc = wxClientDC(self)
+                self.hiliteShape.Draw(dc)
+                self.hiliteShape = None
+
+            if hiliteNew:
+                dc = wxClientDC(self)
+                self.hiliteShape = onShape
+                self.hiliteShape.Draw(dc, wxINVERT)
+
+            # now move it and show it again if needed
+            self.dragImage.Move(evt.GetPosition())
+            if unhiliteOld or hiliteNew:
+                self.dragImage.Show()
 
 
 #----------------------------------------------------------------------
index 81d212afdde41f5742a908d7e8ce18a6069bb88d..08d074c5c5a6fc836d4ce7beba2e5c71a0d524f3 100644 (file)
@@ -469,7 +469,6 @@ bool wxShowTip(wxWindow *parent, wxTipProvider *tipProvider, bool showAtStartup
 
 %{
 #include <wx/generic/dragimgg.h>
-static wxPoint wxPyNullPoint;
 %}
 
 %name (wxDragImage) class wxGenericDragImage : public wxObject
@@ -477,10 +476,10 @@ static wxPoint wxPyNullPoint;
 public:
 
     wxGenericDragImage(const wxBitmap& image,
-                       const wxCursor& cursor = wxNullCursor,
-                       const wxPoint& hotspot = wxPyNullPoint);
+                       const wxCursor& cursor = wxNullCursor);
     ~wxGenericDragImage();
 
+    void SetBackingBitmap(wxBitmap* bitmap);
     bool BeginDrag(const wxPoint& hotspot, wxWindow* window,
                    bool fullScreen = FALSE, wxRect* rect = NULL);
 
@@ -500,12 +499,10 @@ public:
 
 // Alternate Constructors
 %new wxGenericDragImage* wxDragIcon(const wxIcon& image,
-                                   const wxCursor& cursor = wxNullCursor,
-                                   const wxPoint& hotspot = wxPyNullPoint);
+                                   const wxCursor& cursor = wxNullCursor);
 
 %new wxGenericDragImage* wxDragString(const wxString& str,
-                                      const wxCursor& cursor = wxNullCursor,
-                                      const wxPoint& hotspot = wxPyNullPoint);
+                                      const wxCursor& cursor = wxNullCursor);
 
 %new wxGenericDragImage* wxDragTreeItem(const wxTreeCtrl& treeCtrl, wxTreeItemId& id);
 
@@ -515,15 +512,13 @@ public:
 %{
 
 wxGenericDragImage* wxDragIcon(const wxIcon& image,
-                               const wxCursor& cursor,
-                               const wxPoint& hotspot) {
-    return new wxGenericDragImage(image, cursor, hotspot);
+                               const wxCursor& cursor) {
+    return new wxGenericDragImage(image, cursor);
 }
 
 wxGenericDragImage* wxDragString(const wxString& str,
-                                 const wxCursor& cursor,
-                                 const wxPoint& hotspot) {
-    return new wxGenericDragImage(str, cursor, hotspot);
+                                 const wxCursor& cursor) {
+    return new wxGenericDragImage(str, cursor);
 }
 
 wxGenericDragImage* wxDragTreeItem(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) {
index 904b76a6a4063c7c835460f48789e06fc3f2f6c7..9d9893effbc6fe775e1072331cda2e299fb388b4 100644 (file)
@@ -168,19 +168,16 @@ IMP_PYCALLBACK_STRING__pure( wxPyTipProvider, wxTipProvider, GetTip);
 
 
 #include <wx/generic/dragimgg.h>
-static wxPoint wxPyNullPoint;
 
 
 wxGenericDragImage* wxDragIcon(const wxIcon& image,
-                               const wxCursor& cursor,
-                               const wxPoint& hotspot) {
-    return new wxGenericDragImage(image, cursor, hotspot);
+                               const wxCursor& cursor) {
+    return new wxGenericDragImage(image, cursor);
 }
 
 wxGenericDragImage* wxDragString(const wxString& str,
-                                 const wxCursor& cursor,
-                                 const wxPoint& hotspot) {
-    return new wxGenericDragImage(str, cursor, hotspot);
+                                 const wxCursor& cursor) {
+    return new wxGenericDragImage(str, cursor);
 }
 
 wxGenericDragImage* wxDragTreeItem(const wxTreeCtrl& treeCtrl, wxTreeItemId& id) {
@@ -1990,16 +1987,13 @@ static PyObject *_wrap_wxDragIcon(PyObject *self, PyObject *args, PyObject *kwar
     wxGenericDragImage * _result;
     wxIcon * _arg0;
     wxCursor * _arg1 = (wxCursor *) &wxNullCursor;
-    wxPoint * _arg2 = (wxPoint *) &wxPyNullPoint;
     PyObject * _argo0 = 0;
     PyObject * _argo1 = 0;
-    wxPoint  temp;
-    PyObject * _obj2 = 0;
-    char *_kwnames[] = { "image","cursor","hotspot", NULL };
+    char *_kwnames[] = { "image","cursor", NULL };
     char _ptemp[128];
 
     self = self;
-    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|OO:wxDragIcon",_kwnames,&_argo0,&_argo1,&_obj2)) 
+    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|O:wxDragIcon",_kwnames,&_argo0,&_argo1)) 
         return NULL;
     if (_argo0) {
         if (_argo0 == Py_None) { _arg0 = NULL; }
@@ -2015,15 +2009,9 @@ static PyObject *_wrap_wxDragIcon(PyObject *self, PyObject *args, PyObject *kwar
         return NULL;
         }
     }
-    if (_obj2)
-{
-    _arg2 = &temp;
-    if (! wxPoint_helper(_obj2, &_arg2))
-        return NULL;
-}
 {
     wxPy_BEGIN_ALLOW_THREADS;
-        _result = (wxGenericDragImage *)wxDragIcon(*_arg0,*_arg1,*_arg2);
+        _result = (wxGenericDragImage *)wxDragIcon(*_arg0,*_arg1);
 
     wxPy_END_ALLOW_THREADS;
 }    if (_result) {
@@ -2041,16 +2029,13 @@ static PyObject *_wrap_wxDragString(PyObject *self, PyObject *args, PyObject *kw
     wxGenericDragImage * _result;
     wxString * _arg0;
     wxCursor * _arg1 = (wxCursor *) &wxNullCursor;
-    wxPoint * _arg2 = (wxPoint *) &wxPyNullPoint;
     PyObject * _obj0 = 0;
     PyObject * _argo1 = 0;
-    wxPoint  temp;
-    PyObject * _obj2 = 0;
-    char *_kwnames[] = { "str","cursor","hotspot", NULL };
+    char *_kwnames[] = { "str","cursor", NULL };
     char _ptemp[128];
 
     self = self;
-    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|OO:wxDragString",_kwnames,&_obj0,&_argo1,&_obj2)) 
+    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|O:wxDragString",_kwnames,&_obj0,&_argo1)) 
         return NULL;
 {
 #if PYTHON_API_VERSION >= 1009
@@ -2077,15 +2062,9 @@ static PyObject *_wrap_wxDragString(PyObject *self, PyObject *args, PyObject *kw
         return NULL;
         }
     }
-    if (_obj2)
-{
-    _arg2 = &temp;
-    if (! wxPoint_helper(_obj2, &_arg2))
-        return NULL;
-}
 {
     wxPy_BEGIN_ALLOW_THREADS;
-        _result = (wxGenericDragImage *)wxDragString(*_arg0,*_arg1,*_arg2);
+        _result = (wxGenericDragImage *)wxDragString(*_arg0,*_arg1);
 
     wxPy_END_ALLOW_THREADS;
 }    if (_result) {
@@ -3655,22 +3634,19 @@ static void *SwigwxGenericDragImageTowxObject(void *ptr) {
     return (void *) dest;
 }
 
-#define new_wxDragImage(_swigarg0,_swigarg1,_swigarg2) (new wxGenericDragImage(_swigarg0,_swigarg1,_swigarg2))
+#define new_wxDragImage(_swigarg0,_swigarg1) (new wxGenericDragImage(_swigarg0,_swigarg1))
 static PyObject *_wrap_new_wxDragImage(PyObject *self, PyObject *args, PyObject *kwargs) {
     PyObject * _resultobj;
     wxGenericDragImage * _result;
     wxBitmap * _arg0;
     wxCursor * _arg1 = (wxCursor *) &wxNullCursor;
-    wxPoint * _arg2 = (wxPoint *) &wxPyNullPoint;
     PyObject * _argo0 = 0;
     PyObject * _argo1 = 0;
-    wxPoint  temp;
-    PyObject * _obj2 = 0;
-    char *_kwnames[] = { "image","cursor","hotspot", NULL };
+    char *_kwnames[] = { "image","cursor", NULL };
     char _ptemp[128];
 
     self = self;
-    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|OO:new_wxDragImage",_kwnames,&_argo0,&_argo1,&_obj2)) 
+    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"O|O:new_wxDragImage",_kwnames,&_argo0,&_argo1)) 
         return NULL;
     if (_argo0) {
         if (_argo0 == Py_None) { _arg0 = NULL; }
@@ -3686,15 +3662,9 @@ static PyObject *_wrap_new_wxDragImage(PyObject *self, PyObject *args, PyObject
         return NULL;
         }
     }
-    if (_obj2)
-{
-    _arg2 = &temp;
-    if (! wxPoint_helper(_obj2, &_arg2))
-        return NULL;
-}
 {
     wxPy_BEGIN_ALLOW_THREADS;
-        _result = (wxGenericDragImage *)new_wxDragImage(*_arg0,*_arg1,*_arg2);
+        _result = (wxGenericDragImage *)new_wxDragImage(*_arg0,*_arg1);
 
     wxPy_END_ALLOW_THREADS;
 }    if (_result) {
@@ -3734,6 +3704,42 @@ static PyObject *_wrap_delete_wxDragImage(PyObject *self, PyObject *args, PyObje
     return _resultobj;
 }
 
+#define wxDragImage_SetBackingBitmap(_swigobj,_swigarg0)  (_swigobj->SetBackingBitmap(_swigarg0))
+static PyObject *_wrap_wxDragImage_SetBackingBitmap(PyObject *self, PyObject *args, PyObject *kwargs) {
+    PyObject * _resultobj;
+    wxGenericDragImage * _arg0;
+    wxBitmap * _arg1;
+    PyObject * _argo0 = 0;
+    PyObject * _argo1 = 0;
+    char *_kwnames[] = { "self","bitmap", NULL };
+
+    self = self;
+    if(!PyArg_ParseTupleAndKeywords(args,kwargs,"OO:wxDragImage_SetBackingBitmap",_kwnames,&_argo0,&_argo1)) 
+        return NULL;
+    if (_argo0) {
+        if (_argo0 == Py_None) { _arg0 = NULL; }
+        else if (SWIG_GetPtrObj(_argo0,(void **) &_arg0,"_wxGenericDragImage_p")) {
+            PyErr_SetString(PyExc_TypeError,"Type error in argument 1 of wxDragImage_SetBackingBitmap. Expected _wxGenericDragImage_p.");
+        return NULL;
+        }
+    }
+    if (_argo1) {
+        if (_argo1 == Py_None) { _arg1 = NULL; }
+        else if (SWIG_GetPtrObj(_argo1,(void **) &_arg1,"_wxBitmap_p")) {
+            PyErr_SetString(PyExc_TypeError,"Type error in argument 2 of wxDragImage_SetBackingBitmap. Expected _wxBitmap_p.");
+        return NULL;
+        }
+    }
+{
+    wxPy_BEGIN_ALLOW_THREADS;
+        wxDragImage_SetBackingBitmap(_arg0,_arg1);
+
+    wxPy_END_ALLOW_THREADS;
+}    Py_INCREF(Py_None);
+    _resultobj = Py_None;
+    return _resultobj;
+}
+
 #define wxDragImage_BeginDrag(_swigobj,_swigarg0,_swigarg1,_swigarg2,_swigarg3)  (_swigobj->BeginDrag(_swigarg0,_swigarg1,_swigarg2,_swigarg3))
 static PyObject *_wrap_wxDragImage_BeginDrag(PyObject *self, PyObject *args, PyObject *kwargs) {
     PyObject * _resultobj;
@@ -7119,6 +7125,7 @@ static PyMethodDef misc2cMethods[] = {
         { "wxDragImage_EndDrag", (PyCFunction) _wrap_wxDragImage_EndDrag, METH_VARARGS | METH_KEYWORDS },
         { "wxDragImage_BeginDrag2", (PyCFunction) _wrap_wxDragImage_BeginDrag2, METH_VARARGS | METH_KEYWORDS },
         { "wxDragImage_BeginDrag", (PyCFunction) _wrap_wxDragImage_BeginDrag, METH_VARARGS | METH_KEYWORDS },
+        { "wxDragImage_SetBackingBitmap", (PyCFunction) _wrap_wxDragImage_SetBackingBitmap, METH_VARARGS | METH_KEYWORDS },
         { "delete_wxDragImage", (PyCFunction) _wrap_delete_wxDragImage, METH_VARARGS | METH_KEYWORDS },
         { "new_wxDragImage", (PyCFunction) _wrap_new_wxDragImage, METH_VARARGS | METH_KEYWORDS },
         { "new_wxPyTipProvider", (PyCFunction) _wrap_new_wxPyTipProvider, METH_VARARGS | METH_KEYWORDS },
index ce94c3ef92b6e11f960cb954fce9da3e0015d02f..76e68dc44ec4a89c94b2892bf4dc76ba486684d1 100644 (file)
@@ -220,6 +220,9 @@ class wxDragImagePtr(wxObjectPtr):
     def __del__(self,misc2c=misc2c):
         if self.thisown == 1 :
             misc2c.delete_wxDragImage(self)
+    def SetBackingBitmap(self, *_args, **_kwargs):
+        val = apply(misc2c.wxDragImage_SetBackingBitmap,(self,) + _args, _kwargs)
+        return val
     def BeginDrag(self, *_args, **_kwargs):
         val = apply(misc2c.wxDragImage_BeginDrag,(self,) + _args, _kwargs)
         return val
index 8bd88ab478cc75fa438649ee1a8cb2b1c07fbffd..ddbf6b644a812b5d596a5275d32b5eb6ce4be7b8 100644 (file)
@@ -213,6 +213,7 @@ public:
     bool Close(int force = FALSE);
     bool Destroy();
     void DestroyChildren();
+    bool IsBeingDeleted();
 #ifdef __WXMSW__
     void DragAcceptFiles(bool accept);
 #endif