gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSTableView verticalMotionCanBeginDrag stuff


From: Matt Rice
Subject: Re: NSTableView verticalMotionCanBeginDrag stuff
Date: Fri, 3 Nov 2006 03:47:48 -0800 (PST)

--- Matt Rice <address@hidden> wrote:

> 
> 
> --- Matt Rice <address@hidden> wrote:
> <snip>
> > 
> > as currently implemented it is impossible to
> > select
> > multiple rows through dragging
> > 
> > it selects the current row, and drags it when
> > mouseDragged on an unselected row, (the same
> > behaviour
> > as horizontal drag motion currently).
> > 
> > should i change this to only start vertical drags
> on
> > already selected rows so vertical motion on
> > unselected
> > rows allows you to select multiple rows?
> <snip>
> 
> this actually seems to me to be a bad behaviour
> (selecting a row when starting a drag event on an
> unselected row)
> 
> the main problem being that the modifier keys for
> selecting rows can affect both the drag operation
> and the selection mode
> 
> so i guess i'm proposing only beginning a drag
> operation when dragging from a selected row
> 
> and otherwise selecting rows
> 
> the other option,
> 
> dragging the selected rows no matter the current
> rows
> selection status, i don't really like, it would make
> selection in allowsMultipleSelection
> verticalMotionCanBeginDrag rather annoying.
> (iirc this is the apple behaviour)
> though it would surely simplify the code a bit
> 

ok, heres a patch which disables dragging from
unselected rows and implements verticalMotion...

i forgot to mention, not knowing anything about key
value encoding i implemented it, not sure if its in a
way which is compatible or how that is supposed to work...


 
____________________________________________________________________________________
Everyone is raving about the all-new Yahoo! Mail 
(http://advision.webevents.yahoo.com/mailbeta/)
Index: Source/NSTableView.m
===================================================================
--- Source/NSTableView.m        (revision 24019)
+++ Source/NSTableView.m        (working copy)
@@ -64,7 +64,7 @@
 #include <math.h>
 static NSNotificationCenter *nc = nil;
 
-static const int currentVersion = 3;
+static const int currentVersion = 4;
 
 static NSRect oldDraggingRect;
 static int oldDropRow;
@@ -88,15 +88,17 @@
   unsigned int emptySelection:1;
   unsigned int multipleSelection:1;
   unsigned int columnSelection:1;
-  unsigned int __unused:26;
+  unsigned int verticalMotionDrag:1;
+  unsigned int __unused:25;
 #else
-  unsigned int __unused:26;
+  unsigned int __unused:25;
   unsigned int columnSelection:1;
   unsigned int multipleSelection:1;
   unsigned int emptySelection:1;
   unsigned int drawsGrid:1;
   unsigned int columnResizing:1;
   unsigned int columnOrdering:1;
+  unsigned int verticalMotionDrag:1;
 #endif
 } GSTableViewFlags;
 
@@ -3639,31 +3641,16 @@
 
              if (draggingPossible == YES)
                {
-                 if (mouseLocationWin.y - initialLocation.y > 2
-                     || mouseLocationWin.y - initialLocation.y < -2)
+                 if ([_selectedRows containsIndex:_clickedRow] == NO
+                     || (_verticalMotionDrag == NO
+                         && fabs(mouseLocationWin.y - initialLocation.y) > 2))
                    {
                      draggingPossible = NO;
                    }
-                 else if (fabs(mouseLocationWin.x - initialLocation.x) >= 4)
+                 else if ((fabs(mouseLocationWin.x - initialLocation.x) >= 4)
+                          || (_verticalMotionDrag
+                              && fabs(mouseLocationWin.y - initialLocation.y) 
>= 4))
                    {
-                     mouseLocationView.x = _bounds.origin.x;
-                     oldRow = currentRow;
-                     currentRow = [self rowAtPoint: mouseLocationView];
-                     
-                     if (![_selectedRows containsIndex: currentRow])
-                       {
-                         /* Mouse drag in a row that wasn't selected.
-                            select the new row before dragging */
-                         computeNewSelection(self,
-                                             oldSelectedRows, 
-                                             _selectedRows,
-                                             originalRow,
-                                             oldRow,
-                                             currentRow,
-                                             &_selectedRow,
-                                             selectionMode);
-                       }
-
                      if ([self _startDragOperationWithEvent:theEvent])
                        {
                          return;
@@ -5183,17 +5170,12 @@
 
 - (void) setVerticalMotionCanBeginDrag: (BOOL)flag
 {
-  // TODO
-  NSLog(@"Method %s is not implemented for class %s",
-       "setVerticalMotionCanBeginDrag:", "NSTableView");
+  _verticalMotionDrag = flag;
 }
 
 - (BOOL) verticalMotionCanBeginDrag
 {
-  // TODO
-  NSLog(@"Method %s is not implemented for class %s",
-       "verticalMotionCanBeginDrag", "NSTableView");
-  return NO;
+  return _verticalMotionDrag;
 }
 
 /*
@@ -5250,6 +5232,7 @@
       tableViewFlags.drawsGrid = [self drawsGrid]; 
       tableViewFlags.columnResizing = [self allowsColumnResizing];
       tableViewFlags.columnOrdering = [self allowsColumnReordering];
+      tableViewFlags.verticalMotionDrag = [self verticalMotionCanBeginDrag];
       
       memcpy((void *)&vFlags,(void *)&tableViewFlags,sizeof(unsigned long));
 
@@ -5282,6 +5265,7 @@
       [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_allowsColumnResizing];
       [aCoder encodeValueOfObjCType: @encode(BOOL) at: 
&_allowsColumnReordering];
       [aCoder encodeValueOfObjCType: @encode(BOOL) at: 
&_autoresizesAllColumnsToFit];
+      [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_verticalMotionDrag];
     }
 }
 
@@ -5404,6 +5388,7 @@
          [self setDrawsGrid: tableViewFlags.drawsGrid];
          [self setAllowsColumnResizing: tableViewFlags.columnResizing];        
  
          [self setAllowsColumnReordering: tableViewFlags.columnOrdering];
+         [self setVerticalMotionCanBeginDrag: 
tableViewFlags.verticalMotionDrag];
        }
       
       _numberOfColumns = [columns count];
@@ -5420,6 +5405,7 @@
       int version = [aDecoder versionForClassName: 
                                  @"NSTableView"];
       id aDelegate;
+      _verticalMotionDrag = NO;
 
       _dataSource      = [aDecoder decodeObject];
       _tableColumns    = RETAIN([aDecoder decodeObject]);
@@ -5446,7 +5432,7 @@
       [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_allowsEmptySelection];
       [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_allowsColumnSelection];
       [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_allowsColumnResizing];
-      if (version == currentVersion)
+      if (version >= 3)
         {
          [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_allowsColumnReordering];
        }
@@ -5454,7 +5440,12 @@
         {
          [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_autoresizesAllColumnsToFit];
        } 
-      
+     
+      if (version >= 4)
+        {
+          [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_verticalMotionDrag];
+        }
+
       ASSIGN (_selectedColumns, [NSMutableIndexSet indexSet]);
       ASSIGN (_selectedRows, [NSMutableIndexSet indexSet]);
       if (_numberOfColumns)
Index: Headers/AppKit/NSTableView.h
===================================================================
--- Headers/AppKit/NSTableView.h        (revision 24018)
+++ Headers/AppKit/NSTableView.h        (working copy)
@@ -90,6 +90,7 @@
   NSCell            *_editedCell;
   BOOL               _autosaveTableColumns;
   NSString          *_autosaveName;
+  BOOL              _verticalMotionDrag;
 
   /*
    * Ivars Acting as Cache 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]