[Commits] (alecf) fix most of bug 2645 - highlight a half-hour when the user clicks between events, and bring back create-on-drag

commits at osafoundation.org commits at osafoundation.org
Thu Apr 7 17:27:40 PDT 2005


Commit by: alecf
Modified files:
chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py 1.30 1.31
chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py 1.56 1.57

Log message:
fix most of bug 2645 - highlight a half-hour when the user clicks between events, and bring back create-on-drag


Bugzilla links:
http://bugzilla.osafoundation.org/show_bug.cgi?id=2645

ViewCVS links:
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py.diff?r1=text&tr1=1.30&r2=text&tr2=1.31
http://cvs.osafoundation.org/index.cgi/chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py.diff?r1=text&tr1=1.56&r2=text&tr2=1.57

Index: chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py
diff -u chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py:1.30 chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py:1.31
--- chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py:1.30	Thu Apr  7 10:33:13 2005
+++ chandler/parcels/osaf/framework/blocks/calendar/CollectionCanvas.py	Thu Apr  7 17:27:39 2005
@@ -1,8 +1,8 @@
 """ Canvas block for displaying item collections
 """
 
-__version__ = "$Revision: 1.30 $"
-__date__ = "$Date: 2005/04/07 17:33:13 $"
+__version__ = "$Revision: 1.31 $"
+__date__ = "$Date: 2005/04/08 00:27:39 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -293,6 +293,7 @@
 
         self._isDraggingItem = False
         self._isResizingItem = False
+        self._isDraggingNone = False
         self._dragStart = None
         self._originalDragBox = None
         self._currentDragBox = None
@@ -369,13 +370,13 @@
             self._isResizingItem = True
             self.OnBeginResizeItem()
             self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
-            self.CaptureMouse()
 
         else: 
             # start dragging
             self._isDraggingItem = True
             self.OnBeginDragItem()
-            self.CaptureMouse()
+            
+        self.CaptureMouse()
 
     def _initiateDragWithoutSelection(self):
         """
@@ -384,18 +385,23 @@
             OnCreateItem()
             OnBeginResizeItem()
         """
+        # start keeping _dragCurrentUnscrolled up to date
+        self._dragCurrentUnscrolled = self._dragStartUnscrolled
+
         itemBox = self.OnCreateItem(self._dragStartUnscrolled, True)
         if itemBox: # if we have one, start resizing this item
             self.SetDragBox(itemBox)
             self._isResizingItem = True
             self.OnBeginResizeItem()
             self.SetCursor(wx.StockCursor(wx.CURSOR_SIZENS))
-            self.CaptureMouse()
-        else: # clear out the drag info, avoid creating more items
-            # actually, shouldn't DragBox already be none?
-            self.SetDragBox(None)
-            # this is a way to prevent this method from being called again
-            self._setDragStart(None)
+        else: 
+            # indicate that we're dragging nothing
+            self._isDraggingNone = True
+            self.OnBeginDragNone()
+
+        self.CaptureMouse()
+        
+
         
     def _handleNormalDrag(self, dragInProgress, unscrolledPosition):
         """
@@ -435,6 +441,19 @@
             self._setDragStart(None)
             self.ReleaseMouse()
 
+    def _handleNoneDrag(self, dragInProgress, unscrolledPosition):
+        
+        if dragInProgress:
+            self._dragCurrentUnscrolled = unscrolledPosition
+            self.OnDraggingNone(unscrolledPosition)
+            
+        else: # end the drag
+            self._isDraggingNone = False
+            self._dragCurrentUnscrolled = None
+            self.OnEndDragNone()
+            self._setDragStart(None)
+            self.ReleaseMouse()
+            
     def _updateCursor(self, unscrolledPosition):
         """
         Show the resize cursor if we're over a resize area,
@@ -513,6 +532,7 @@
         if (event.Entering() or event.Leaving()):
             return
 
+        # checks if the event iself is from dragging the mouse
         dragInProgress = event.Dragging() and event.LeftIsDown()
         
         # handle events-in-progress such as resizes or drags
@@ -522,6 +542,9 @@
         # handle resizing
         elif self._isResizingItem:
             self._handleResizeDrag(dragInProgress, unscrolledPosition)
+            
+        elif self._isDraggingNone:
+            self._handleNoneDrag(dragInProgress, unscrolledPosition)
                 
         else: 
             # just handle normal mouse events
@@ -537,7 +560,7 @@
             # look for the beginning of a drag
             # _dragStart seems to be used as a way to allow someone to
             # cancel/ignore a drag in progress - see _initiateDragWithoutSelection
-            elif (dragInProgress and self._dragStart):
+            elif (dragInProgress):
                 
                 if (self._shouldBeginDrag(position)):
                     if self._originalDragBox: 
@@ -639,9 +662,6 @@
     def OnPaint(self, event):
         """
         """
-        # @@@ we currently have a bug where the update regions don't 
-        # always match the virtual size, creating a small black band 
-        # at the bottom of the virtual window
 
         # double buffered drawing
         dc = wx.PaintDC(self)
@@ -718,6 +738,21 @@
         self.blockItem.selection = item
         self.blockItem.postSelectItemBroadcast()
         self.wxSynchronizeWidget()
+        
+    def OnSelectNone(self, unscrolledPosition):
+        """
+           Called when the user clicks on an area that isn't an item
+        """
+        self.OnSelectItem(None)
+    
+    def OnBeginDragNone(self):
+        pass
+        
+    def OnDraggingNone(self, unscrolledPosition):
+        pass
+        
+    def OnEndDragNone(self):
+        pass
 
     # DropReceiveWidget
     

Index: chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py
diff -u chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.56 chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.57
--- chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py:1.56	Thu Apr  7 10:33:13 2005
+++ chandler/parcels/osaf/framework/blocks/calendar/CalendarCanvas.py	Thu Apr  7 17:27:39 2005
@@ -1,8 +1,8 @@
 """ Canvas for calendaring blocks
 """
 
-__version__ = "$Revision: 1.56 $"
-__date__ = "$Date: 2005/04/07 17:33:13 $"
+__version__ = "$Revision: 1.57 $"
+__date__ = "$Date: 2005/04/08 00:27:39 $"
 __copyright__ = "Copyright (c) 2004 Open Source Applications Foundation"
 __license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
 
@@ -209,12 +209,22 @@
         @rtype: string or None
         """
         
+        if hasattr(self, '_forceResizeMode'):
+            return self._forceResizeMode
+            
         if self._resizeTopBounds.Inside(point):
             return self.RESIZE_MODE_START
         if self._resizeLowBounds.Inside(point):
             return self.RESIZE_MODE_END
         return None
         
+    def SetResizeMode(self, mode):
+        self._forceResizeMode = mode
+        
+    def ResetResizeMode(self):
+        if hasattr(self, '_forceResizeMode'):
+            del self._forceResizeMode
+    
     def GenerateBoundsRects(self, calendarCanvas):
         """
         Generate a bounds rectangle for each day period. For example, an event
@@ -556,10 +566,6 @@
         self.parent.blockItem.postSelectItemBroadcast()
         self.parent.wxSynchronizeWidget()
     
-    def OnSelectNone(self, unscrolledPosition):
-        # quick hack to allow deselection
-        self.OnSelectItem(None)
-
     def GrabFocusHack(self):
         self.editor.SaveItem()
         self.editor.Hide()
@@ -919,10 +925,16 @@
         super (wxWeekColumnCanvas, self).OnInit()
         
         # @@@ rationalize drawing calculations...
+        self.hourHeight = 40
+        
         self._scrollYRate = 10
-        self.SetVirtualSize((self.GetVirtualSize().width, 40*24))
+        
+        self._bgSelectionStartTime = None
+        self._bgSelectionEndTime = None
+        
+        self.SetVirtualSize((self.GetVirtualSize().width, self.hourHeight*24))
         self.SetScrollRate(0, self._scrollYRate)
-        self.Scroll(0, (40*7)/self._scrollYRate)
+        self.Scroll(0, (self.hourHeight*7)/self._scrollYRate)
 
     def ScaledScroll(self, dx, dy):
         (scrollX, scrollY) = self.CalcUnscrolledPosition(0,0)
@@ -942,7 +954,6 @@
         # @@@ magic numbers
         self.size = self.GetVirtualSize()
         self.xOffset = self.size.width / 8
-        self.hourHeight = 40
         if self.parent.blockItem.dayMode:
             self.parent.columns = 1
         else:
@@ -970,8 +981,13 @@
         topCoordinate = self.CalcUnscrolledPosition((0,0))
         topTime = self.getDateTimeFromPosition(wx.Point(topCoordinate[0],
                                                         topCoordinate[1]))
+        
+        #bottomCoordinate = self.CalcUnscrolledPosition((
+        #bottomTime = self.getDateTimeFromPosition(wx.Point(bottomCoordinate[0],
+        #                                                   bottomCoordinate[1]))
 
         # Draw the lines separating hours
+        halfHourHeight = self.hourHeight/2
         for hour in range(24):
             
             # Draw the hour legend
@@ -1005,9 +1021,9 @@
             # Draw the line between half hours
             dc.SetPen(self.minorLinePen)
             dc.DrawLine(self.xOffset,
-                         hour * self.hourHeight + (self.hourHeight/2),
+                         hour * self.hourHeight + halfHourHeight,
                         self.size.width,
-                         hour * self.hourHeight + (self.hourHeight/2))
+                         hour * self.hourHeight + halfHourHeight)
 
         # Draw lines between days
         for day in range(self.parent.columns):
@@ -1017,6 +1033,21 @@
                 dc.SetPen(self.minorLinePen)
             dc.DrawLine(self.xOffset + (self.dayWidth * day), 0,
                         self.xOffset + (self.dayWidth * day), self.size.height)
+                        
+        # draw selection stuff
+        if (self._bgSelectionStartTime):
+            dc.SetPen(self.majorLinePen)
+            dc.SetBrush(self.selectionBrush)
+            
+            tlPos = self.getPositionFromDateTime(self._bgSelectionStartTime)
+            brPos = \
+               (self.getPositionFromDateTime(self._bgSelectionEndTime))
+            brPos.x += self.dayWidth
+            brPos.y += halfHourHeight
+            
+            selectionRect = wx.RectPP(tlPos, brPos)
+            dc.DrawRectangleRect(selectionRect)
+                    
 
     def sortByStartTime(self, item1, item2):
         """
@@ -1107,7 +1138,19 @@
 
             
     # handle mouse related actions: move, resize, create, select
-
+    
+    def OnSelectItem(self, item):
+        if item:
+            # clear background selection
+            self._bgSelectionStartTime = self._bgSelectionEndTime = None
+        
+        super(wxWeekColumnCanvas, self).OnSelectItem(item)
+        
+    def OnSelectNone(self, unscrolledPosition):
+        self._bgSelectionStartTime = self.getDateTimeFromPosition(unscrolledPosition)
+        self._bgSelectionEndTime = self._bgSelectionStartTime
+        super(wxWeekColumnCanvas, self).OnSelectNone(unscrolledPosition)
+        
     def OnEditItem(self, box):
         position = self.CalcScrolledPosition(box.GetEditorPosition())
         size = box.GetMaxEditorSize()
@@ -1118,29 +1161,33 @@
         self.editor.SetItem(box.GetItem(), textPos, textSize, self.smallFont.GetPointSize()) 
 
     def OnCreateItem(self, unscrolledPosition, createOnDrag):
+        # @@@ this code might want to live somewhere else, refactored
+        view = self.parent.blockItem.itsView
+        event = Calendar.CalendarEvent(view=view)
+        newTime = self.getDateTimeFromPosition(unscrolledPosition)
+        event.InitOutgoingAttributes()
+        event.ChangeStart(newTime)
+
+        # ugh, this is a hack to work around the whole ItemCollection stuff
+        # see bug 2749 for some background
+        self.parent.blockItem.contents.source.add(event)
+        
         if createOnDrag:
-            # @@@ disable until we work out repository issues
-            # event.duration = DateTime.DateTimeDelta(0, 0, 60)
-            #     x, y = self.getPositionFromDateTime(newTime)
-            #     eventRect = wx.Rect(x, y,
-            #          self.dayWidth - 1,
-            #          int(event.duration.hours * self.hourHeight) - 1)
-            pass
+            self._bgSelectionStartTime = self.bgSelectionEndTime = None
         else:
-            # @@@ this code might want to live somewhere else, refactored
-            view = self.parent.blockItem.itsView
-            newTime = self.getDateTimeFromPosition(unscrolledPosition)
-            event = Calendar.CalendarEvent(view=view)
-            event.InitOutgoingAttributes()
-            event.ChangeStart(newTime)
 
-            self.parent.blockItem.contents.source.add(event)
             self.OnSelectItem(event)
 
             # @@@ Bug#1854 currently this is too slow,
             # and the event causes flicker
-            view.commit()
-        return None
+            #view.commit()
+        canvasItem = ColumnarCanvasItem(event, self)
+        
+        # only problem here is that we haven't checked for conflicts
+        canvasItem.UpdateDrawingRects()
+        canvasItem.SetResizeMode(canvasItem.RESIZE_MODE_END)
+        return canvasItem
+        
     
     def OnBeginResizeItem(self):
         self._lastUnscrolledPosition = self._dragStartUnscrolled
@@ -1149,6 +1196,7 @@
         
     def OnEndResizeItem(self):
         self.StopDragTimer()
+        self._originalDragBox.ResetResizeMode()
         pass
         
     def OnResizingItem(self, unscrolledPosition):
@@ -1189,6 +1237,15 @@
         self.StopDragTimer()
         pass
         
+    def OnDraggingNone(self, unscrolledPosition):
+        self._bgSelectionEndTime = self.getDateTimeFromPosition(unscrolledPosition)
+        if (self._bgSelectionEndTime < self._bgSelectionStartTime):
+            # swap values
+            (self._bgSelectionStartTime, self._bgSelectionEndTime) = \
+                (self._bgSelectionEndTime, self._bgSelectionStartTime)
+        self.Refresh()
+            
+        
     def OnDraggingItem(self, unscrolledPosition):
         # at the start of the drag, the mouse was somewhere inside the
         # dragbox, but not necessarily exactly at x,y



More information about the Commits mailing list