Minor fixups

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6246 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 2000-03-10 07:48:29 +00:00
parent bd75f0f185
commit 7b00766409
4 changed files with 311 additions and 289 deletions

View file

@ -1,3 +1,11 @@
Fri Mar 10 06:46:00 2000 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Source/NSView.m: Added ([_removeSubview:]) and make all subview
removals use it. Modify addition of subviews to invalidate the
subview coordinates.
* Source/NSScrollView.m: Use _removeSubview
* Source/AppKit/NSView.h: tidyup and add new method.
Fri Mar 10 02:12:34 2000 Nicola Pero <n.pero@mi.flashnet.it> Fri Mar 10 02:12:34 2000 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSSplitView.m ([-mouseDown:]): Better management of the * Source/NSSplitView.m ([-mouseDown:]): Better management of the

View file

@ -51,15 +51,22 @@
typedef int NSTrackingRectTag; typedef int NSTrackingRectTag;
typedef enum _NSBorderType { // constants representing the /*
NSNoBorder, // four types of borders that * constants representing the four types of borders that
NSLineBorder, // can appear around an NSView * can appear around an NSView
*/
typedef enum _NSBorderType {
NSNoBorder,
NSLineBorder,
NSBezelBorder, NSBezelBorder,
NSGrooveBorder NSGrooveBorder
} NSBorderType; } NSBorderType;
// autoresize constants which NSView uses in
// determining the parts of a view which are /*
// resized when the view's superview is resized * autoresize constants which NSView uses in
* determining the parts of a view which are
* resized when the view's superview is resized
*/
enum { enum {
NSViewNotSizable = 0, // view does not resize with its superview NSViewNotSizable = 0, // view does not resize with its superview
NSViewMinXMargin = 1, // left margin between views can stretch NSViewMinXMargin = 1, // left margin between views can stretch
@ -102,14 +109,14 @@ enum {
NSView *_previousKeyView; NSView *_previousKeyView;
} }
// /*
//Initializing NSView Objects * Initializing NSView Objects
// */
- (id) initWithFrame: (NSRect)frameRect; - (id) initWithFrame: (NSRect)frameRect;
// /*
// Managing the NSView Hierarchy * Managing the NSView Hierarchy
// */
- (void) addSubview: (NSView*)aView; - (void) addSubview: (NSView*)aView;
- (void) addSubview: (NSView*)aView - (void) addSubview: (NSView*)aView
positioned: (NSWindowOrderingMode)place positioned: (NSWindowOrderingMode)place
@ -129,9 +136,9 @@ enum {
- (void) viewWillMoveToSuperview: (NSView*)newSuper; - (void) viewWillMoveToSuperview: (NSView*)newSuper;
- (void) viewWillMoveToWindow: (NSWindow*)newWindow; - (void) viewWillMoveToWindow: (NSWindow*)newWindow;
// /*
// Modifying the Frame Rectangle * Modifying the Frame Rectangle
// */
- (float) frameRotation; - (float) frameRotation;
- (NSRect) frame; - (NSRect) frame;
- (void) rotateByAngle: (float)angle; - (void) rotateByAngle: (float)angle;
@ -140,10 +147,9 @@ enum {
- (void) setFrameRotation: (float)angle; - (void) setFrameRotation: (float)angle;
- (void) setFrameSize: (NSSize)newSize; - (void) setFrameSize: (NSSize)newSize;
// /*
// Modifying the Coordinate System * Modifying the Coordinate System
// */
- (float) boundsRotation; - (float) boundsRotation;
- (NSRect) bounds; - (NSRect) bounds;
- (BOOL) isFlipped; - (BOOL) isFlipped;
@ -156,9 +162,9 @@ enum {
- (void) setBoundsSize: (NSSize)newSize; - (void) setBoundsSize: (NSSize)newSize;
- (void) translateOriginToPoint: (NSPoint)point; - (void) translateOriginToPoint: (NSPoint)point;
// /*
// Converting Coordinates * Converting Coordinates
// */
- (NSRect) centerScanRect: (NSRect)aRect; - (NSRect) centerScanRect: (NSRect)aRect;
- (NSPoint) convertPoint: (NSPoint)aPoint - (NSPoint) convertPoint: (NSPoint)aPoint
fromView: (NSView*)aView; fromView: (NSView*)aView;
@ -173,17 +179,17 @@ enum {
- (NSSize) convertSize: (NSSize)aSize - (NSSize) convertSize: (NSSize)aSize
toView: (NSView*)aView; toView: (NSView*)aView;
// /*
// Notifying Ancestor Views * Notifying Ancestor Views
// */
- (void) setPostsFrameChangedNotifications: (BOOL)flag; - (void) setPostsFrameChangedNotifications: (BOOL)flag;
- (BOOL) postsFrameChangedNotifications; - (BOOL) postsFrameChangedNotifications;
- (void) setPostsBoundsChangedNotifications: (BOOL)flag; - (void) setPostsBoundsChangedNotifications: (BOOL)flag;
- (BOOL) postsBoundsChangedNotifications; - (BOOL) postsBoundsChangedNotifications;
// /*
// Resizing Subviews * Resizing Subviews
// */
- (void) resizeSubviewsWithOldSize: (NSSize)oldSize; - (void) resizeSubviewsWithOldSize: (NSSize)oldSize;
- (void) setAutoresizesSubviews: (BOOL)flag; - (void) setAutoresizesSubviews: (BOOL)flag;
- (BOOL) autoresizesSubviews; - (BOOL) autoresizesSubviews;
@ -191,25 +197,25 @@ enum {
- (unsigned int) autoresizingMask; - (unsigned int) autoresizingMask;
- (void) resizeWithOldSuperviewSize: (NSSize)oldSize; - (void) resizeWithOldSuperviewSize: (NSSize)oldSize;
// /*
// Graphics State Objects * Graphics State Objects
// */
- (void) allocateGState; - (void) allocateGState;
- (void) releaseGState; - (void) releaseGState;
- (int) gState; - (int) gState;
- (void) renewGState; - (void) renewGState;
- (void) setUpGState; - (void) setUpGState;
// /*
// Focusing * Focusing
// */
+ (NSView*) focusView; + (NSView*) focusView;
- (void) lockFocus; - (void) lockFocus;
- (void) unlockFocus; - (void) unlockFocus;
// /*
// Displaying * Displaying
// */
- (BOOL) canDraw; - (BOOL) canDraw;
- (void) display; - (void) display;
- (void) displayIfNeeded; - (void) displayIfNeeded;
@ -226,9 +232,9 @@ enum {
- (void) setNeedsDisplayInRect: (NSRect)invalidRect; - (void) setNeedsDisplayInRect: (NSRect)invalidRect;
- (BOOL) shouldDrawColor; - (BOOL) shouldDrawColor;
// /*
// Scrolling * Scrolling
// */
- (NSRect) adjustScroll: (NSRect)newVisible; - (NSRect) adjustScroll: (NSRect)newVisible;
- (BOOL) autoscroll: (NSEvent*)theEvent; - (BOOL) autoscroll: (NSEvent*)theEvent;
- (NSScrollView*) enclosingScrollView; - (NSScrollView*) enclosingScrollView;
@ -240,9 +246,9 @@ enum {
by: (NSSize)delta; by: (NSSize)delta;
- (BOOL) scrollRectToVisible: (NSRect)aRect; - (BOOL) scrollRectToVisible: (NSRect)aRect;
// /*
// Managing the Cursor * Managing the Cursor
// */
- (void) addCursorRect: (NSRect)aRect - (void) addCursorRect: (NSRect)aRect
cursor: (NSCursor*)anObject; cursor: (NSCursor*)anObject;
- (void) discardCursorRects; - (void) discardCursorRects;
@ -250,15 +256,15 @@ enum {
cursor: (NSCursor*)anObject; cursor: (NSCursor*)anObject;
- (void) resetCursorRects; - (void) resetCursorRects;
// /*
// Assigning a Tag * Assigning a Tag
// */
- (int) tag; - (int) tag;
- (id) viewWithTag: (int)aTag; - (id) viewWithTag: (int)aTag;
// /*
// Aiding Event Handling * Aiding Event Handling
// */
- (BOOL) acceptsFirstMouse: (NSEvent*)theEvent; - (BOOL) acceptsFirstMouse: (NSEvent*)theEvent;
- (NSView*) hitTest: (NSPoint)aPoint; - (NSView*) hitTest: (NSPoint)aPoint;
- (BOOL) mouse: (NSPoint)aPoint - (BOOL) mouse: (NSPoint)aPoint
@ -277,9 +283,9 @@ enum {
- (NSView*) previousKeyView; - (NSView*) previousKeyView;
- (NSView*) previousValidKeyView; - (NSView*) previousValidKeyView;
// /*
// Dragging * Dragging
// */
- (BOOL) dragFile: (NSString*)filename - (BOOL) dragFile: (NSString*)filename
fromRect: (NSRect)rect fromRect: (NSRect)rect
slideBack: (BOOL)slideFlag slideBack: (BOOL)slideFlag
@ -294,18 +300,18 @@ enum {
- (void) registerForDraggedTypes: (NSArray*)newTypes; - (void) registerForDraggedTypes: (NSArray*)newTypes;
- (void) unregisterDraggedTypes; - (void) unregisterDraggedTypes;
// /*
// Printing * Printing
// */
- (NSData*) dataWithEPSInsideRect: (NSRect)aRect; - (NSData*) dataWithEPSInsideRect: (NSRect)aRect;
- (void) fax: (id)sender; - (void) fax: (id)sender;
- (void) print: (id)sender; - (void) print: (id)sender;
- (void) writeEPSInsideRect: (NSRect)rect - (void) writeEPSInsideRect: (NSRect)rect
toPasteboard: (NSPasteboard*)pasteboard; toPasteboard: (NSPasteboard*)pasteboard;
// /*
// Pagination * Pagination
// */
- (void) adjustPageHeightNew: (float*)newBottom - (void) adjustPageHeightNew: (float*)newBottom
top: (float)oldTop top: (float)oldTop
bottom: (float)oldBottom bottom: (float)oldBottom
@ -321,12 +327,12 @@ enum {
- (NSRect) rectForPage: (int)page; - (NSRect) rectForPage: (int)page;
- (float) widthAdjustLimit; - (float) widthAdjustLimit;
// /*
// Writing Conforming PostScript * Writing Conforming PostScript
// */
- (void) addToPageSetup; - (void) addToPageSetup;
- (void) beginPage: (int)ordinalNum - (void) beginPage: (int)ordinalNum
label:(NSString *)aString abel: (NSString*)aString
bBox: (NSRect)pageRect bBox: (NSRect)pageRect
fonts: (NSString*)fontNames; fonts: (NSString*)fontNames;
- (void) beginPageSetupRect: (NSRect)aRect - (void) beginPageSetupRect: (NSRect)aRect
@ -349,30 +355,24 @@ enum {
- (void) endPage; - (void) endPage;
- (void) endTrailer; - (void) endTrailer;
// /*
// NSCoding protocol * NSCoding protocol
// */
- (void)encodeWithCoder:aCoder; - (void) encodeWithCoder: (NSCoder*)aCoder;
- initWithCoder:aDecoder; - (id) initWithCoder: (NSCoder*)aDecoder;
@end @end
@class NSAffineTransform; @class NSAffineTransform;
// /*
// GNUstep extensions * GNUstep extensions
// Methods whose names begin with an underscore must NOT be overridden. * Methods whose names begin with an underscore must NOT be overridden.
// */
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP
@interface NSView (PrivateMethods) @interface NSView (PrivateMethods)
/*
* If the view is rotated, [-_boundingRectFor:] returns the bounding box
* of the rect in the "normal" coordinates
*/
- (NSRect) _boundingRectFor: (NSRect)rect;
/* /*
* The [-_invalidateCoordinates] method marks the cached visible rectangles * The [-_invalidateCoordinates] method marks the cached visible rectangles
* of the view and it's subview as being invalid. NSViews methods call this * of the view and it's subview as being invalid. NSViews methods call this
@ -384,6 +384,8 @@ enum {
- (NSAffineTransform*) _matrixToWindow; - (NSAffineTransform*) _matrixToWindow;
- (NSAffineTransform*) _matrixFromWindow; - (NSAffineTransform*) _matrixFromWindow;
- (void) _removeSubview: (NSView*)aSubview;
@end @end
#endif #endif

View file

@ -207,6 +207,22 @@ static Class rulerViewClass = nil;
[self tile]; [self tile];
} }
- (void) _removeSubview: (NSView*)aView
{
if (aView == _contentView)
{
RETAIN(aView);
_contentView = nil;
[super _removeSubview: aView];
RELEASE(aView);
[self tile];
}
else
{
[super _removeSubview: aView];
}
}
- (void) setHorizontalScroller: (NSScroller*)aScroller - (void) setHorizontalScroller: (NSScroller*)aScroller
{ {
[_horizScroller removeFromSuperview]; [_horizScroller removeFromSuperview];

View file

@ -265,6 +265,10 @@ GSSetDragTypes(NSView* obj, NSArray *types)
RETAIN(aView); RETAIN(aView);
[aView removeFromSuperview]; [aView removeFromSuperview];
if (aView->_coordinates_valid)
{
(*invalidateImp)(aView, invalidateSel);
}
[aView viewWillMoveToWindow: _window]; [aView viewWillMoveToWindow: _window];
[aView viewWillMoveToSuperview: self]; [aView viewWillMoveToSuperview: self];
[aView setNextResponder: self]; [aView setNextResponder: self];
@ -301,6 +305,10 @@ GSSetDragTypes(NSView* obj, NSArray *types)
} }
RETAIN(aView); RETAIN(aView);
[aView removeFromSuperview]; [aView removeFromSuperview];
if (aView->_coordinates_valid)
{
(*invalidateImp)(aView, invalidateSel);
}
[aView viewWillMoveToWindow: _window]; [aView viewWillMoveToWindow: _window];
[aView viewWillMoveToSuperview: self]; [aView viewWillMoveToSuperview: self];
[aView setNextResponder: self]; [aView setNextResponder: self];
@ -372,67 +380,19 @@ GSSetDragTypes(NSView* obj, NSArray *types)
- (void) removeFromSuperviewWithoutNeedingDisplay - (void) removeFromSuperviewWithoutNeedingDisplay
{ {
/* This must be first because it invokes -resignFirstResponder:, if (_super_view != nil)
which assumes the view is still in the view hierarchy */
if ([_window firstResponder] == self)
[_window makeFirstResponder: _window];
/*
* We MUST make sure that coordinates are invalidated even if we have
* no superview - cos they may have been rebuilt since we lost the
* superview and the fact that this method has been invoked probably
* means we are about to be placed in a new view where the coordinate
* system will be different.
*/
if (_coordinates_valid)
{ {
(*invalidateImp)(self, invalidateSel); [_super_view _removeSubview: self];
} }
if (!_super_view)
{
return;
}
RETAIN(self);
[_super_view->_sub_views removeObjectIdenticalTo: self];
if ([_super_view->_sub_views count] == 0)
{
_super_view->_rFlags.has_subviews = 0;
}
_super_view = nil;
[self viewWillMoveToWindow: nil];
RELEASE(self);
} }
- (void) removeFromSuperview - (void) removeFromSuperview
{ {
/* This must be first because it invokes -resignFirstResponder:, if (_super_view != nil)
which assumes the view is still in the view hierarchy */
if ([_window firstResponder] == self)
[_window makeFirstResponder: _window];
/*
* We MUST make sure that coordinates are invalidated even if we have
* no superview - cos they may have been rebuilt since we lost the
* superview and the fact that this method has been invoked probably
* means we are about to be placed in a new view where the coordinate
* system will be different.
*/
if (_coordinates_valid)
{ {
(*invalidateImp)(self, invalidateSel);
}
if (!_super_view)
{
return;
}
[_super_view setNeedsDisplayInRect: _frame]; [_super_view setNeedsDisplayInRect: _frame];
RETAIN(self); [_super_view _removeSubview: self];
[_super_view->_sub_views removeObjectIdenticalTo: self];
if ([_super_view->_sub_views count] == 0)
{
_super_view->_rFlags.has_subviews = 0;
} }
_super_view = nil;
[self viewWillMoveToWindow: nil];
RELEASE(self);
} }
- (void) replaceSubview: (NSView*)oldView with: (NSView*)newView - (void) replaceSubview: (NSView*)oldView with: (NSView*)newView
@ -454,6 +414,10 @@ GSSetDragTypes(NSView* obj, NSArray *types)
*/ */
RETAIN(newView); RETAIN(newView);
[newView removeFromSuperview]; [newView removeFromSuperview];
if (newView->_coordinates_valid)
{
(*invalidateImp)(newView, invalidateSel);
}
[newView viewWillMoveToWindow: _window]; [newView viewWillMoveToWindow: _window];
[newView viewWillMoveToSuperview: self]; [newView viewWillMoveToSuperview: self];
[newView setNextResponder: self]; [newView setNextResponder: self];
@ -486,6 +450,10 @@ GSSetDragTypes(NSView* obj, NSArray *types)
*/ */
RETAIN(newView); RETAIN(newView);
[newView removeFromSuperview]; [newView removeFromSuperview];
if (newView->_coordinates_valid)
{
(*invalidateImp)(newView, invalidateSel);
}
index = [_sub_views indexOfObjectIdenticalTo: oldView]; index = [_sub_views indexOfObjectIdenticalTo: oldView];
[oldView removeFromSuperview]; [oldView removeFromSuperview];
[newView viewWillMoveToWindow: _window]; [newView viewWillMoveToWindow: _window];
@ -2766,5 +2734,33 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level)
} }
} }
- (void) _removeSubview: (NSView*)aSubview
{
/*
* This must be first because it invokes -resignFirstResponder:,
* which assumes the view is still in the view hierarchy
*/
if ([_window firstResponder] == aSubview)
{
[_window makeFirstResponder: _window];
}
/*
* We make sure that the coordinates are invalidated even though the
* code to add this view to another view will also invalidate them.
* This is for consistency so that when a view is not in the view
* hierarchy, its coordinates should not be valid.
*/
if (aSubview->_coordinates_valid)
{
(*invalidateImp)(aSubview, invalidateSel);
}
aSubview->_super_view = nil;
[aSubview viewWillMoveToWindow: nil];
[_sub_views removeObjectIdenticalTo: aSubview];
if ([_sub_views count] == 0)
{
_rFlags.has_subviews = 0;
}
}
@end @end