Author: mlytwyn
Date: Wed Mar  8 20:51:16 2017
New Revision: 40374

URL: http://svn.gna.org/viewcvs/gnustep?rev=40374&view=rev
Log:
Finish/cleanup visible column table view drawing/resizing

Modified:
    libs/gui/branches/gnustep_testplant_branch/Source/GSThemeDrawing.m
    libs/gui/branches/gnustep_testplant_branch/Source/NSTableColumn.m
    libs/gui/branches/gnustep_testplant_branch/Source/NSTableView.m

Modified: libs/gui/branches/gnustep_testplant_branch/Source/GSThemeDrawing.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/GSThemeDrawing.m?rev=40374&r1=40373&r2=40374&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/GSThemeDrawing.m  
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/GSThemeDrawing.m  Wed Mar 
 8 20:51:16 2017
@@ -28,8 +28,10 @@
 
 #import "GSThemePrivate.h"
 
+#import "Foundation/NSDebug.h"
+#import "Foundation/NSIndexSet.h"
+#import "Foundation/NSPredicate.h"
 #import "Foundation/NSUserDefaults.h"
-#import "Foundation/NSIndexSet.h"
 
 #import "AppKit/NSAttributedString.h"
 #import "AppKit/NSBezierPath.h"
@@ -97,6 +99,12 @@
 {
   return _selectedColumns;
 }
+@end
+
+@interface NSTableView (ColumnHelper)
+- (NSArray*) _visibleColumns;
+- (NSArray*) _resizableColumns;
+- (NSArray*) _hiddenColumns;
 @end
 
 @interface NSCell (GNUstepPrivate)
@@ -2924,74 +2932,58 @@
   NSTableView *tableView = [tableHeaderView tableView];
   NSArray *columns;
   int firstColumnToDraw;
-  int lastColumnToDraw;
   NSRect drawingRect;
   NSTableColumn *column;
   NSTableColumn *highlightedTableColumn;
   float width;
-  int i;
   NSCell *cell;
 
   if (tableView == nil)
     return;
-
-  firstColumnToDraw = [tableHeaderView columnAtPoint: NSMakePoint 
(aRect.origin.x,
-                                                        aRect.origin.y)];
-  if (firstColumnToDraw == -1)
-    firstColumnToDraw = 0;
-
-  lastColumnToDraw = [tableHeaderView columnAtPoint: NSMakePoint (NSMaxX 
(aRect),
-                                                       aRect.origin.y)];
-  if (lastColumnToDraw == -1)
-    lastColumnToDraw = [tableView numberOfColumns] - 1;
-
+  
+  // Draw only visible columns based on hidden setting...
+  columns = [tableView _visibleColumns];
+  
+  // If no visible columns then return...
+  if ([columns count] == 0)
+    return;
+  
+  firstColumnToDraw = [[tableView tableColumns] indexOfObject: [columns 
firstObject]];
   drawingRect = [tableHeaderView headerRectOfColumn: firstColumnToDraw];
-  
-  columns = [tableView tableColumns];
   highlightedTableColumn = [tableView highlightedTableColumn];
-  
-  for (i = firstColumnToDraw; i <= lastColumnToDraw; i++)
-    {
-      column = [columns objectAtIndex: i];
+
+  NSEnumerator *iter = [columns objectEnumerator];
+  while ((column = [iter nextObject]))
+    {
+      NSInteger index = [[tableView tableColumns] indexOfObject: column];
       width = [column width];
       drawingRect.size.width = width;
       cell = [column headerCell];
-      if ((column == highlightedTableColumn) ||
-          [tableView isColumnSelected: i])
-        {
-          [cell setHighlighted: YES];
-        }
+      if ((column == highlightedTableColumn) || [tableView isColumnSelected: 
index])
+      {
+        [cell setHighlighted: YES];
+      }
       else
-        {
-          [cell setHighlighted: NO];
-        }
-      [cell drawWithFrame: drawingRect
-                   inView: tableHeaderView];
+      {
+        [cell setHighlighted: NO];
+      }
+      [cell drawWithFrame: drawingRect inView: tableHeaderView];
       drawingRect.origin.x += width;
     }
   
   // Fill out table header to end if needed...
-  //if ([[[GSTheme theme] name] isEqualToString: @"GSTheme"] == NO)
-    {
-      if (lastColumnToDraw == [tableView numberOfColumns] - 1)
-        {
-          // This is really here to handle extending the table headers using 
the
-          // WinUXTheme (or one equivalent to) that writes directly to the MS 
windows
-          // device contexts...
-          NSRect clipFrame = [(NSClipView*)[tableView superview] 
documentVisibleRect];
-          CGFloat maxWidth = NSMaxX(clipFrame);
-          if (drawingRect.origin.x < maxWidth)
-          {
-            drawingRect.size.width = maxWidth - drawingRect.origin.x;
-            column = [columns objectAtIndex: lastColumnToDraw];
-            cell = AUTORELEASE([[NSTableHeaderCell alloc] initTextCell:@""]);
-            [cell setHighlighted: NO];
-#if 0
-            NSLog(@"%s:---> i: %d drawRect: %@", __PRETTY_FUNCTION__, -2, 
NSStringFromRect(drawingRect));
-#endif
-            [cell drawWithFrame: drawingRect inView: tableHeaderView];
-          }
-        }
+  // This is really here to handle extending the table headers using the
+  // WinUXTheme (or one equivalent to) that writes directly to the MS windows
+  // device contexts...
+  NSRect clipFrame = [(NSClipView*)[tableView superview] documentVisibleRect];
+  CGFloat maxWidth = NSMaxX(clipFrame);
+  if (drawingRect.origin.x < maxWidth)
+    {
+      drawingRect.size.width = maxWidth - drawingRect.origin.x;
+      column = [columns lastObject];
+      cell = AUTORELEASE([[NSTableHeaderCell alloc] initTextCell:@""]);
+      [cell setHighlighted: NO];
+      [cell drawWithFrame: drawingRect inView: tableHeaderView];
     }
 }
 
@@ -3062,8 +3054,6 @@
 
   NSInteger startingRow = [tableView rowAtPoint: NSMakePoint(minX, minY)];
   NSInteger endingRow = [tableView rowAtPoint: NSMakePoint(minX, maxY)];
-  NSInteger startingColumn = [tableView columnAtPoint: NSMakePoint(minX, 
minY)];
-  NSInteger endingColumn = [tableView columnAtPoint: NSMakePoint(maxX, minY)];
 
   NSGraphicsContext *ctxt = GSCurrentContext ();
   NSColor *gridColor = [tableView gridColor];
@@ -3074,12 +3064,6 @@
   if (endingRow == -1)
     endingRow = numberOfRows - 1;
 
-  if (startingColumn == -1)
-    startingColumn = 0;
-  if (endingColumn == -1)
-    endingColumn = numberOfColumns - 1;
-
-
   DPSgsave (ctxt);
   [gridColor set];
 
@@ -3088,25 +3072,33 @@
     {
       NSInteger i;
       for (i = startingRow; i <= endingRow; i++)
-       {
-         NSRect rowRect = [tableView rectOfRow: i];
-         rowRect.origin.y += rowRect.size.height - 1;
-         rowRect.size.height = 1;
-         NSRectFill(rowRect);
-       }
+        {
+          NSRect rowRect = [tableView rectOfRow: i];
+          rowRect.origin.y += rowRect.size.height - 1;
+          rowRect.size.height = 1;
+          NSRectFill(rowRect);
+        }
     }
   
   // Draw vertical lines
   if (numberOfColumns > 0)
     {
       NSInteger i;
-      for (i = startingColumn; i <= endingColumn; i++)
-       {
-         NSRect colRect = [tableView rectOfColumn: i];
-         colRect.origin.x += colRect.size.width - 1;
-         colRect.size.width = 1;
-         NSRectFill(colRect);
-       }
+      CGFloat lastX = 0;
+      CGFloat maxX = NSMaxX([[tableView superview] bounds])-1;
+      NSTableColumn *column = nil;
+      NSArray *columns = [tableView _visibleColumns];
+      NSEnumerator *iter = [columns objectEnumerator];
+      
+      while ((column = [iter nextObject]) && (lastX < maxX))
+        {
+          i = [[tableView tableColumns] indexOfObject: column];
+          NSRect colRect = [tableView rectOfColumn: i];
+          colRect.origin.x += colRect.size.width - 1;
+          colRect.size.width = 1;
+          NSRectFill(colRect);
+          lastX = colRect.origin.x;
+        }
     }
 
   DPSgrestore (ctxt);
@@ -3237,16 +3229,11 @@
           row = [selectedRows indexGreaterThanIndex: row];
         }        
     }
-  else // Selecting columns
-    {
-      NSUInteger selectedColumnsCount;
+  else if ([selectedColumns count] > 0) // Selecting columns
+    {
+      NSUInteger selectedColumnsCount = [selectedColumns count];
       NSUInteger column;
       NSInteger  startingColumn, endingColumn;
-      
-      selectedColumnsCount = [selectedColumns count];
-      
-      if (selectedColumnsCount == 0)
-        return;
       
       /* highlight selected columns */
       startingColumn = [tableView columnAtPoint: NSMakePoint(NSMinX(clipRect), 
0)];
@@ -3272,19 +3259,13 @@
                    inView: (NSView *)view
 {
   NSTableView *tableView = (NSTableView *)view;
-  // int numberOfRows = [tableView numberOfRows];
   int numberOfColumns = [tableView numberOfColumns];
-  // NSIndexSet *selectedRows = [tableView _selectedRowIndexes];
-  // NSColor *backgroundColor = [tableView backgroundColor];
   id dataSource = [tableView dataSource];
   CGFloat *columnOrigins = [tableView _columnOrigins];
   int editedRow = [tableView editedRow];
   int editedColumn = [tableView editedColumn];
-  int startingColumn;
-  int endingColumn;
   NSRect drawingRect;
   NSCell *cell;
-  int i;
   CGFloat x_pos;
 
   if (dataSource == nil)
@@ -3326,34 +3307,14 @@
     {
       /* Using columnAtPoint: here would make it called twice per row per drawn
        rect - so we avoid it and do it natively */
+      NSArray       *columns = [tableView _visibleColumns];
+      NSTableColumn *column  = nil;
+      NSEnumerator  *iter    = [columns objectEnumerator];
       
-      /* Determine starting column as fast as possible */
-      x_pos = NSMinX (clipRect);
-      i = 0;
-      while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
+      /* Draw the rows  */
+      while ((column = [iter nextObject]))
         {
-          i++;
-        }
-      startingColumn = (i - 1);
-      
-      if (startingColumn == -1)
-        startingColumn = 0;
-      
-      /* Determine ending column as fast as possible */
-      x_pos = NSMaxX (clipRect);
-      // Nota Bene: we do *not* reset i
-      while ((i < numberOfColumns) && (x_pos > columnOrigins[i]))
-        {
-          i++;
-        }
-      endingColumn = (i - 1);
-      
-      if (endingColumn == -1)
-        endingColumn = numberOfColumns - 1;
-
-      /* Draw the row between startingColumn and endingColumn */
-      for (i = startingColumn; i <= endingColumn; i++)
-        {
+          NSInteger i = [[tableView tableColumns] indexOfObject: column];
           cell = [tableView preparedCellAtColumn: i row:rowIndex];
           if (i == editedColumn && rowIndex == editedRow)
             {

Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSTableColumn.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSTableColumn.m?rev=40374&r1=40373&r2=40374&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSTableColumn.m   
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSTableColumn.m   Wed Mar 
 8 20:51:16 2017
@@ -73,6 +73,10 @@
 #import "AppKit/NSTableView.h"
 #import "GSBindingHelpers.h"
 
+@interface NSTableView (GNUstepPrivate)
+- (void) _tableColumnDidChangeState: (NSTableColumn*)column;
+@end
+
 /**
   <p>
   NSTableColumn objects represent columns in NSTableViews.  
@@ -351,7 +355,13 @@
 Set whether the column is invisible or not. */
 - (void) setHidden: (BOOL)hidden
 {
-  _is_hidden = hidden;
+  // If the flag is changing...
+  if (_is_hidden != hidden)
+  {
+    // Save and notify the table to resize columns based on hidden ones...
+    _is_hidden = hidden;
+    [[self tableView] _tableColumnDidChangeState: self];
+  }
 }
 
 /**

Modified: libs/gui/branches/gnustep_testplant_branch/Source/NSTableView.m
URL: 
http://svn.gna.org/viewcvs/gnustep/libs/gui/branches/gnustep_testplant_branch/Source/NSTableView.m?rev=40374&r1=40373&r2=40374&view=diff
==============================================================================
--- libs/gui/branches/gnustep_testplant_branch/Source/NSTableView.m     
(original)
+++ libs/gui/branches/gnustep_testplant_branch/Source/NSTableView.m     Wed Mar 
 8 20:51:16 2017
@@ -142,6 +142,8 @@
 - (NSArray*) _visibleColumns;
 - (NSArray*) _resizableColumns;
 - (NSArray*) _hiddenColumns;
+- (CGFloat) _columnOriginForColumn: (NSTableColumn*)column;
+- (CGFloat) _columnOriginForColumnAtIndex: (NSInteger) columnIndex;
 - (CGFloat) _currentColumnWidth: (NSArray*)columns remainingWidth: 
(CGFloat*)remainingWidth;
 @end
 
@@ -2125,7 +2127,6 @@
     {
       _columnOrigins = NSZoneMalloc (NSDefaultMallocZone (), sizeof (CGFloat));
     }
-
   _lastRemainingWidth = 0;
   [self _resizeTableView];
   [self tile];
@@ -2167,7 +2168,6 @@
     {
       NSZoneFree (NSDefaultMallocZone (), _columnOrigins);
     }
-
   _lastRemainingWidth = 0;
   [self _resizeTableView];
   [self tile];
@@ -4490,6 +4490,10 @@
       return NSZeroRect;
     }
 
+  // If not visible...
+  if ([[_tableColumns objectAtIndex: columnIndex] isHidden])
+    return NSZeroRect;
+  
   rect.origin.x = _columnOrigins[columnIndex];
   rect.origin.y = _bounds.origin.y;
   rect.size.width = [[_tableColumns objectAtIndex: columnIndex] width];
@@ -4583,13 +4587,18 @@
     }
   else
     {
-      NSInteger i = 0;
+      NSInteger i = 1;
+      NSInteger index = 1;
       
-      while ((i < _numberOfColumns) && (aPoint.x >= _columnOrigins[i]))
-        {
-          i++;
-        }
-      return i - 1;
+      for (i = 1; i < _numberOfColumns; ++i)
+        {
+          if ([[_tableColumns objectAtIndex: i] isHidden])
+            continue;
+          if (aPoint.x <= _columnOrigins[i])
+            break;
+          index++;
+        }
+      return index - 1;
     }
 }
 
@@ -4732,26 +4741,8 @@
 
 - (void) _tableColumnDidChangeState: (NSTableColumn*)column
 {
-  if ([column isHidden])
-  {
-    if ([_tableColumns indexOfObject: column] == NSNotFound)
-    {
-      NSWarnMLog(@"column not found in visible list: %@", [column identifier]);
-    }
-    else
-    {
-    }
-  }
-  else
-  {
-    if ([_tableColumnsHidden indexOfObject: column] == NSNotFound)
-    {
-      NSWarnMLog(@"column not found in hidden list: %@", [column identifier]);
-    }
-    else
-    {
-    }
-  }
+  _lastRemainingWidth = 0;
+  [self _resizeTableView];
 }
 
 - (void) _resizeTableView
@@ -5064,7 +5055,6 @@
       tb = [columns objectAtIndex: i];
       remainingWidth -= [[columns objectAtIndex: i] width];
     }
-  //remainingWidth -= _lastRemainingWidth;
   
   // Avoid hidden/unresizable columns for resizing...
   columns = AUTORELEASE([[self _resizableColumns] mutableCopy]);
@@ -5100,7 +5090,6 @@
           percents[ counter ] = [tb maxWidth] - width;
         }
         totalPrecents += percents[ counter ];
-        
         ++counter;
       }
       [columns removeObjectsInArray: removeCols];
@@ -5256,23 +5245,38 @@
   if (_tilingDisabled == YES)
     return;
 
-  if (_numberOfColumns > 0)
-    {
-      NSInteger i;
-      CGFloat width;
+  // Tile only VISIBLE columns, setting in hidden ones to zero...
+  NSArray *columns = [self tableColumns];
   
-      _columnOrigins[0] = _bounds.origin.x;
-      width = [[_tableColumns objectAtIndex: 0] width];
-      table_width += width;
-      for (i = 1; i < _numberOfColumns; i++)
-        {
-          _columnOrigins[i] = _columnOrigins[i - 1] + width;
-          width = [[_tableColumns objectAtIndex: i] width];
-          table_width += width;
+  if ([columns count] > 0)
+    {
+      NSInteger i = 0;
+  
+      while ([[_tableColumns objectAtIndex: i] isHidden])
+        {
+          _columnOrigins[i++] = 0;
+        }
+      if (i < [columns count])
+        {
+          CGFloat lastOrigin = _bounds.origin.x;
+          CGFloat lastWidth  = 0;
+          for ( ; i < [columns count]; i++)
+            {
+              if ([[columns objectAtIndex: i] isHidden])
+              {
+                _columnOrigins[i] = 0;
+                continue;
+              }
+              _columnOrigins[i] = lastOrigin + lastWidth;
+              lastWidth = [[columns objectAtIndex: i] width];
+              table_width += lastWidth;
+              lastOrigin = _columnOrigins[i];
+            }
         }
     }
   /* + 1 for the last grid line */
   table_height = (_numberOfRows * _rowHeight) + 1;
+  table_width  = fmax(table_width, [_super_view bounds].size.width);
   [self setFrameSize: NSMakeSize (table_width, table_height)];
   [self setNeedsDisplay: YES];
 
@@ -5323,7 +5327,7 @@
 
 - (void) drawBackgroundInClipRect: (NSRect)clipRect
 {
-  [[GSTheme theme] drawTableViewBackgroundInClipRect: clipRect
+  [[GSTheme theme] drawTableViewBackgroundInClipRect: [_super_view bounds]
                                               inView: self
                                  withBackgroundColor: _backgroundColor];
 }
@@ -6171,8 +6175,11 @@
 - (void) _userResizedTableColumn: (NSInteger)index
                            width: (CGFloat)width
 {
-  _lastRemainingWidth -= (width - [[_tableColumns objectAtIndex: index] 
width]);
+  CGFloat lastWidth = [[_tableColumns objectAtIndex: index] width];
   [[_tableColumns objectAtIndex: index] setWidth: width];
+  
+  // Resize the table columns...
+  //_lastRemainingWidth -= (width - [[_tableColumns objectAtIndex: index] 
width]);
   [self _resizeTableView];
 }
 
@@ -6429,8 +6436,7 @@
       NSString           *tableKey;
 
       defaults  = [NSUserDefaults standardUserDefaults];
-      tableKey = [NSString stringWithFormat: @"NSTableView Columns %@", 
-                          _autosaveName];
+      tableKey = [NSString stringWithFormat: @"NSTableView Columns %@", 
_autosaveName];
       config = [defaults objectForKey: tableKey];
       if (config != nil) 
         {
@@ -7439,6 +7445,26 @@
   return [_tableColumns filteredArrayUsingPredicate: predicate];
 }
 
+- (CGFloat) _columnOriginForColumn: (NSTableColumn*)column;
+{
+  if ([column isHidden])
+    return 0;
+  return [self _columnOriginForColumnAtIndex: [_tableColumns indexOfObject: 
column]];
+}
+
+- (CGFloat) _columnOriginForColumnAtIndex: (NSInteger) columnIndex
+{
+  if (columnIndex == NSNotFound)
+    return 0;
+  if ((columnIndex < 0) || (columnIndex >= _numberOfColumns))
+    return 0;
+  NSTableColumn *column = [_tableColumns objectAtIndex: columnIndex];
+  if ([column isHidden])
+    return 0;
+  
+  return _columnOrigins[ columnIndex ];
+}
+
 - (CGFloat) _currentColumnWidth: (NSArray*)columns remainingWidth: 
(CGFloat*)remainingWidth
 {
   NSInteger i             = 0;
@@ -7456,7 +7482,6 @@
   }
   if (remainingWidth)
     *remainingWidth = remWidth;
-
   return currentWidth;
 }
 


_______________________________________________
Gnustep-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/gnustep-cvs

Reply via email to