]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/wx/lib/gridmovers.py
some tweaks
[wxWidgets.git] / wxPython / wx / lib / gridmovers.py
index 40c5156d5597062eb9f47440065027419a1f919a..866fee364e46d9ecea0175807c8b7ce78b79c646 100644 (file)
 #
 # o 2.5 Compatability changes
 #
+# 12/18/2003 - Jeff Grimmett (grimmtooth@softhome.net)
+#
+# o wxGridColMoveEvent -> GridColMoveEvent
+# o wxGridRowMoveEvent -> GridRowMoveEvent
+# o wxGridColMover -> GridColMover
+# o wxGridRowMover -> GridRowMover
+#
+
 
 import  wx
 import  wx.grid
@@ -31,7 +39,7 @@ EVT_GRID_ROW_MOVE = wx.PyEventBinder(wxEVT_COMMAND_GRID_ROW_MOVE, 1)
 
 #----------------------------------------------------------------------------
 
-class wxGridColMoveEvent(wx.PyCommandEvent):
+class GridColMoveEvent(wx.PyCommandEvent):
     def __init__(self, id, dCol, bCol):
         wx.PyCommandEvent.__init__(self, id = id)
         self.SetEventType(wxEVT_COMMAND_GRID_COL_MOVE)
@@ -45,7 +53,7 @@ class wxGridColMoveEvent(wx.PyCommandEvent):
         return self.beforeColumn
 
 
-class wxGridRowMoveEvent(wx.PyCommandEvent):
+class GridRowMoveEvent(wx.PyCommandEvent):
     def __init__(self, id, dRow, bRow):
         wx.PyCommandEvent.__init__(self,id = id)
         self.SetEventType(wxEVT_COMMAND_GRID_ROW_MOVE)
@@ -66,7 +74,7 @@ def _ColToRect(self,col):
     if self.GetNumberRows() > 0:
         rect = self.CellToRect(0,col)
     else:
-        rect = wxRect()
+        rect = wx.Rect()
         rect.height = self.GetColLabelSize()
         rect.width = self.GetColSize(col)
 
@@ -83,7 +91,7 @@ def _RowToRect(self,row):
     if self.GetNumberCols() > 0:
         rect = self.CellToRect(row,0)
     else:
-        rect = wxRect()
+        rect = wx.Rect()
         rect.width = self.GetRowLabelSize()
         rect.height = self.GetRowSize(row)
 
@@ -121,7 +129,7 @@ class ColDragWindow(wx.Window):
     def _GetInsertionInfo(self):
         parent = self.GetParent()
         sx = parent.GetViewStart()[0] * self.ux
-        sx -= parent._rlSize
+        sx -= parent.GetRowLabelSize()
         x = self.GetPosition()[0]
         w = self.GetSize()[0]
         sCol = parent.XToCol(x + sx)
@@ -151,12 +159,12 @@ class ColDragWindow(wx.Window):
     def OnPaint(self,evt):
         dc = wx.PaintDC(self)
         w,h = self.GetSize()
-        dc.DrawBitmap(self.image, (0,0))
+        dc.DrawBitmap(self.image, 0,0)
         dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
-        dc.DrawRectangle((0,0), (w,h))
+        dc.DrawRectangle(0,0, w,h)
         iPos = self.GetInsertionPos()
-        dc.DrawLine((iPos,h - 10), (iPos,h))
+        dc.DrawLine(iPos,h - 10, iPos,h)
 
 
 
@@ -184,7 +192,7 @@ class RowDragWindow(wx.Window):
     def _GetInsertionInfo(self):
         parent = self.GetParent()
         sy = parent.GetViewStart()[1] * self.uy
-        sy -= parent._clSize
+        sy -= parent.GetColLabelSize()
         y = self.GetPosition()[1]
         h = self.GetSize()[1]
         sRow = parent.YToRow(y + sy)
@@ -214,21 +222,20 @@ class RowDragWindow(wx.Window):
     def OnPaint(self,evt):
         dc = wx.PaintDC(self)
         w,h = self.GetSize()
-        dc.DrawBitmap(self.image, (0,0))
+        dc.DrawBitmap(self.image, 0,0)
         dc.SetPen(wx.Pen(wx.BLACK,1,wx.SOLID))
         dc.SetBrush(wx.TRANSPARENT_BRUSH)
-        dc.DrawRectangle((0,0), (w,h))
+        dc.DrawRectangle(0,0, w,h)
         iPos = self.GetInsertionPos()
-        dc.DrawLine((w - 10,iPos), (w,iPos))
+        dc.DrawLine(w - 10,iPos, w,iPos)
 
 #----------------------------------------------------------------------------
 
-class wxGridColMover(wx.EvtHandler):
+class GridColMover(wx.EvtHandler):
     def __init__(self,grid):
         wx.EvtHandler.__init__(self)
 
         self.grid = grid
-        self.grid._rlSize = self.grid.GetRowLabelSize()
         self.lwin = grid.GetGridColLabelWindow()
         self.lwin.PushEventHandler(self)
         self.colWin = None
@@ -244,7 +251,10 @@ class wxGridColMover(wx.EvtHandler):
 
     def OnMouseMove(self,evt):
         if self.isDragging:
-            if abs(self.startX - evt.m_x) >= 3:
+            _rlSize = self.grid.GetRowLabelSize()
+            if abs(self.startX - evt.m_x) >= 3 \
+                   and abs(evt.m_x - self.lastX) >= 3:
+                self.lastX = evt.m_x 
                 self.didMove = True
                 sx,y = self.grid.GetViewStart()
                 w,h = self.lwin.GetClientSize()
@@ -272,20 +282,20 @@ class wxGridColMover(wx.EvtHandler):
 
                 px = x - self.cellX
 
-                if px < 0 + self.grid._rlSize: px = 0 + self.grid._rlSize
+                if px < 0 + _rlSize: px = 0 + _rlSize
 
-                if px > w - self.colWin.GetSize()[0] + self.grid._rlSize:
-                    px = w - self.colWin.GetSize()[0] + self.grid._rlSize
+                if px > w - self.colWin.GetSize()[0] + _rlSize:
+                    px = w - self.colWin.GetSize()[0] + _rlSize
 
                 self.colWin.DisplayAt(px,y)
                 return
 
-        evt.Skip()
 
     def OnPress(self,evt):
-        self.startX = evt.m_x
+        self.startX = self.lastX = evt.m_x
+        _rlSize = self.grid.GetRowLabelSize()
         sx = self.grid.GetViewStart()[0] * self.ux
-        sx -= self.grid._rlSize
+        sx -= _rlSize
         px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
         px,py = self.grid.ScreenToClientXY(px,py)
 
@@ -300,12 +310,13 @@ class wxGridColMover(wx.EvtHandler):
         self.cellX = px + sx - rect.x
         size = self.lwin.GetSize()
         rect.y = 0
-        rect.x -= sx + self.grid._rlSize
+        rect.x -= sx + _rlSize
         rect.height = size[1]
         colImg = self._CaptureImage(rect)
         self.colWin = ColDragWindow(self.grid,colImg,col)
         self.colWin.Show(False)
         self.lwin.CaptureMouse()
+        evt.Skip()
 
     def OnRelease(self,evt):
         if self.isDragging:
@@ -317,7 +328,7 @@ class wxGridColMover(wx.EvtHandler):
                 px = self.lwin.ClientToScreenXY(self.startX,0)[0]
                 px = self.grid.ScreenToClientXY(px,0)[0]
                 sx = self.grid.GetViewStart()[0] * self.ux
-                sx -= self.grid._rlSize
+                sx -= self.grid.GetRowLabelSize()
                 col = self.grid.XToCol(px+sx)
 
                 if col != wx.NOT_FOUND:
@@ -328,7 +339,7 @@ class wxGridColMover(wx.EvtHandler):
                 bCol = self.colWin.GetInsertionColumn()
                 dCol = self.colWin.GetMoveColumn()
                 wx.PostEvent(self,
-                             wxGridColMoveEvent(self.grid.GetId(), dCol, bCol))
+                             GridColMoveEvent(self.grid.GetId(), dCol, bCol))
 
             self.colWin.Destroy()
         evt.Skip()
@@ -338,17 +349,16 @@ class wxGridColMover(wx.EvtHandler):
         memdc = wx.MemoryDC()
         memdc.SelectObject(bmp)
         dc = wx.WindowDC(self.lwin)
-        memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
+        memdc.Blit(0,0, rect.width, rect.height, dc, rect.x, rect.y)
         memdc.SelectObject(wx.NullBitmap)
         return bmp
 
 
-class wxGridRowMover(wx.EvtHandler):
+class GridRowMover(wx.EvtHandler):
     def __init__(self,grid):
         wx.EvtHandler.__init__(self)
 
         self.grid = grid
-        self.grid._clSize = self.grid.GetColLabelSize()
         self.lwin = grid.GetGridRowLabelWindow()
         self.lwin.PushEventHandler(self)
         self.rowWin = None
@@ -364,7 +374,10 @@ class wxGridRowMover(wx.EvtHandler):
 
     def OnMouseMove(self,evt):
         if self.isDragging:
-            if abs(self.startY - evt.m_y) >= 3:
+            _clSize = self.grid.GetColLabelSize()
+            if abs(self.startY - evt.m_y) >= 3 \
+                   and abs(evt.m_y - self.lastY) >= 3:
+                self.lastY = evt.m_y
                 self.didMove = True
                 x,sy = self.grid.GetViewStart()
                 w,h = self.lwin.GetClientSizeTuple()
@@ -394,21 +407,21 @@ class wxGridRowMover(wx.EvtHandler):
 
                 py = y - self.cellY
 
-                if py < 0 + self.grid._clSize: 
-                    py = 0 + self.grid._clSize
+                if py < 0 + _clSize: 
+                    py = 0 + _clSize
 
-                if py > h - self.rowWin.GetSize()[1] + self.grid._clSize:
-                    py = h - self.rowWin.GetSize()[1] + self.grid._clSize
+                if py > h - self.rowWin.GetSize()[1] + _clSize:
+                    py = h - self.rowWin.GetSize()[1] + _clSize
 
                 self.rowWin.DisplayAt(x,py)
                 return
 
-        evt.Skip()
 
     def OnPress(self,evt):
-        self.startY = evt.m_y
+        self.startY = self.lastY = evt.m_y
+        _clSize = self.grid.GetColLabelSize()
         sy = self.grid.GetViewStart()[1] * self.uy
-        sy -= self.grid._clSize
+        sy -= _clSize
         px,py = self.lwin.ClientToScreenXY(evt.m_x,evt.m_y)
         px,py = self.grid.ScreenToClientXY(px,py)
 
@@ -423,12 +436,13 @@ class wxGridRowMover(wx.EvtHandler):
         self.cellY = py + sy - rect.y
         size = self.lwin.GetSize()
         rect.x = 0
-        rect.y -= sy + self.grid._clSize
+        rect.y -= sy + _clSize
         rect.width = size[0]
         rowImg = self._CaptureImage(rect)
         self.rowWin = RowDragWindow(self.grid,rowImg,row)
         self.rowWin.Show(False)
         self.lwin.CaptureMouse()
+        evt.Skip()
 
     def OnRelease(self,evt):
         if self.isDragging:
@@ -440,7 +454,7 @@ class wxGridRowMover(wx.EvtHandler):
                 py = self.lwin.ClientToScreenXY(0,self.startY)[1]
                 py = self.grid.ScreenToClientXY(0,py)[1]
                 sy = self.grid.GetViewStart()[1] * self.uy
-                sy -= self.grid._clSize
+                sy -= self.grid.GetColLabelSize()
                 row = self.grid.YToRow(py + sy)
 
                 if row != wx.NOT_FOUND:
@@ -451,7 +465,7 @@ class wxGridRowMover(wx.EvtHandler):
                 dRow = self.rowWin.GetMoveRow()
 
                 wx.PostEvent(self,
-                             wxGridRowMoveEvent(self.grid.GetId(), dRow, bRow))
+                             GridRowMoveEvent(self.grid.GetId(), dRow, bRow))
 
             self.rowWin.Destroy()
         evt.Skip()
@@ -461,7 +475,7 @@ class wxGridRowMover(wx.EvtHandler):
         memdc = wx.MemoryDC()
         memdc.SelectObject(bmp)
         dc = wx.WindowDC(self.lwin)
-        memdc.Blit((0,0), rect.GetSize(), dc, rect.GetPosition())
+        memdc.Blit(0,0, rect.width, rect.height, dc, rect.x, rect.y)
         memdc.SelectObject(wx.NullBitmap)
         return bmp