[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
GSTable doesn't handle frame changes
From: |
Alexander Malmberg |
Subject: |
GSTable doesn't handle frame changes |
Date: |
Tue, 12 Mar 2002 01:13:18 +0100 |
Hi,
Recently I've added a proper preferences panel to LuserNET; each 'tab'
there has a top-level view, a GSVbox or GSHbox, that gets added to an
NSBox when the tab is selected. Unfortunately, the boxes won't re-'tile'
themselves properly when they're added to the NSBox since they only
re-'tile' when they are resized.
I've attached a patch that moves the entire tiling process to a
_frameChanged: method, and ensures that this is called when the frame
changed (resizes, setFrame:, etc.) and this solved my problems. (It
loses some of the optimizations of the old version, but I don't think
that matters; the time spent re-tiling is probably negligible compared
to time spent actually redrawing everything.)
- Alexander Malmberg
Index: GSTable.m
===================================================================
RCS file: /cvsroot/gnustep/gnustep/core/gui/Source/GSTable.m,v
retrieving revision 1.5
diff -u -r1.5 GSTable.m
--- GSTable.m 26 Jan 2002 04:14:38 -0000 1.5
+++ GSTable.m 12 Mar 2002 00:07:36 -0000
@@ -27,6 +27,8 @@
#include <AppKit/GSTable.h>
+#include <Foundation/NSNotification.h>
+
// This is meant to make drawing invisible views a little faster
@interface GSTransparentView : NSView
@end
@@ -133,6 +135,12 @@
_expandingColumnNumber = columns;
_minimumSize = NSZeroSize;
+
+ [self setPostsFrameChangedNotifications: YES];
+ [[NSNotificationCenter defaultCenter] addObserver: self
+ selector: @selector(_frameChanged:)
+ name: NSViewFrameDidChangeNotification
+ object: self];
return self;
}
@@ -143,6 +151,7 @@
}
-(void) dealloc
{
+ [[NSNotificationCenter defaultCenter] removeObserver: self];
NSZoneFree (NSDefaultMallocZone (), _jails);
NSZoneFree (NSDefaultMallocZone (), _expandColumn);
NSZoneFree (NSDefaultMallocZone (), _expandRow);
@@ -489,90 +498,69 @@
NSSize newFrameSize;
[super resizeWithOldSuperviewSize: oldSize];
+
+ [self _frameChanged: nil];
+}
+
+
+-(void) _frameChanged: (NSNotification *)n
+{
+ float originShift;
+ float dimensionIncrement;
+ unsigned int i;
+ NSSize newFrameSize;
+
+
newFrameSize = [self frame].size;
//
// Width
//
- if (newFrameSize.width <= _minimumSize.width)
+ if (newFrameSize.width < _minimumSize.width)
{
- if (oldFrameSize.width > _minimumSize.width)
- {
- originShift = _minXBorder;
- for (i = 0; i < _numberOfColumns; i++)
- {
- _columnDimension[i] = _minColumnDimension[i];
- _columnXOrigin[i] = originShift;
- originShift += _minColumnDimension[i];
- }
- tableNeedUpdate = YES;
- }
+ newFrameSize.width = _minimumSize.width;
}
- else // newFrameSize.width > _minimumSize.width
- {
- if (oldFrameSize.width < _minimumSize.width)
- oldFrameSize.width = _minimumSize.width;
- if ((newFrameSize.width != oldFrameSize.width) && _expandingColumnNumber)
- {
- originShift = 0;
- dimensionIncrement = newFrameSize.width - oldFrameSize.width;
- dimensionIncrement = dimensionIncrement / _expandingColumnNumber;
- for (i = 0; i < _numberOfColumns; i++)
- {
- _columnXOrigin[i] += originShift;
- if (_expandColumn[i])
- {
- _columnDimension[i] += dimensionIncrement;
- originShift += dimensionIncrement;
- }
- }
- tableNeedUpdate = YES;
+ originShift = _minXBorder;
+ dimensionIncrement = (newFrameSize.width - _minimumSize.width) /
_expandingColumnNumber;
+ for (i = 0; i < _numberOfColumns; i++)
+ {
+ _columnXOrigin[i] = originShift;
+ _columnDimension[i] = _minColumnDimension[i];
+ originShift += _minColumnDimension[i];
+ if (_expandColumn[i])
+ {
+ _columnDimension[i] += dimensionIncrement;
+ originShift += dimensionIncrement;
}
}
+
//
// Height
//
- if (newFrameSize.height <= _minimumSize.height)
+ if (newFrameSize.height < _minimumSize.height)
{
- if (oldFrameSize.height > _minimumSize.height)
- {
- originShift = _minYBorder;
- for (i = 0; i < _numberOfRows; i++)
- {
- _rowDimension[i] = _minRowDimension[i];
- _rowYOrigin[i] = originShift;
- originShift += _minRowDimension[i];
- }
- tableNeedUpdate = YES;
- }
+ newFrameSize.height = _minimumSize.height;
}
- else // newFrameSize.height > _minimumSize.height
- {
- if (oldFrameSize.height < _minimumSize.height)
- oldFrameSize.height = _minimumSize.height;
- if ((newFrameSize.height != oldFrameSize.height) && _expandingRowNumber)
- {
- originShift = 0;
- dimensionIncrement = newFrameSize.height - oldFrameSize.height;
- dimensionIncrement = dimensionIncrement / _expandingRowNumber;
- for (i = 0; i < _numberOfRows; i++)
- {
- _rowYOrigin[i] += originShift;
- if (_expandRow[i])
- {
- _rowDimension[i] += dimensionIncrement;
- originShift += dimensionIncrement;
- }
- }
- tableNeedUpdate = YES;
+ originShift = _minYBorder;
+ dimensionIncrement = (newFrameSize.height - _minimumSize.height) /
_expandingRowNumber;
+ for (i = 0; i < _numberOfRows; i++)
+ {
+ _rowYOrigin[i] = originShift;
+ _rowDimension[i] = _minRowDimension[i];
+ originShift += _minRowDimension[i];
+ if (_expandRow[i])
+ {
+ _rowDimension[i] += dimensionIncrement;
+ originShift += dimensionIncrement;
}
}
- if (tableNeedUpdate)
- [self _updateWholeTable];
+ [self _updateWholeTable];
}
+
+
//
// Minimum Size
//
- GSTable doesn't handle frame changes,
Alexander Malmberg <=