Lock focus fixes - get cells to lock focus before drawing themselves.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4924 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-09-21 05:10:54 +00:00
parent 0424173e96
commit 98a649c60a
13 changed files with 85 additions and 25 deletions

View file

@ -1,3 +1,40 @@
Tue Sep 15 1999 Nicola Pero <n.pero@mi.flashnet.it>
(NB. The above date reflects submission of the patch - sorry I didn't
commit it until 21st Sept - RFM)
* Source/NSButton.m ([-performClick:]): Removed lock/unlock focus,
now done automatically by the cell.
* Source/NSBrowserCell.m ([-drawInteriorWithFrame:inView:]): Lock
focus in the view during drawing.
* Source/NSButtonCell.m: ([-drawInteriorWithFrame:inView:]): Lock
focus in the view during drawing. ([-drawWithFrame:inView:]):
idem.
* Source/NSButtonCell.m ([-performClick:]): draw in its control_view,
if it has one, not in the currently focused view.
* Source/NSCell.m ([-performClick:]): idem.
* Source/NSCell.m: ([-drawInteriorWithFrame:inView:]): Lock focus
in the view during drawing. ([-drawWithFrame:inView:]): idem.
* Source/NSControl.m ([-initWithFrame:]): invoke +cellClass
when creating the new cell.
* Source/NSControl.m ([-drawCellInside:]): call the cell's
drawingRectForBounds: method to get the area to draw.
* Source/NSControl.m ([-mouseDown:]): Removed lock/unlock focus
now done automatically by the cell.
* Source/NSImageCell.m: ([-drawInteriorWithFrame:inView:]): Lock
focus in the view during drawing. ([-drawWithFrame:inView:]): idem.
* Source/NSMatrix.m ([-highlightCell:atRow:column:]): lock focus
during drawing of background.
* Source/NSMatrix.m ([-_mouseDownNonListMode:]): Removed lock
focus now done by the cells. ([-mouseDown:]): idem. ([-keyDown:]):
idem.
* Source/NSMenuItemCell.m ([-drawWithFrame:inView:]): Lock focus
in the view during drawing.
* Source/NSPopUpButtonCell.m ([-drawWithFrame:inView:]): idem.
* Source/NSSliderCell.m ([-drawInteriorWithFrame:inView:]): idem.
* Source/NSTableHeaderCell.m ([-drawInteriorWithFrame:inView:]):
idem.
* Source/NSTextFieldCell.m: ([-drawInteriorWithFrame:inView:]): idem.
Mon Sep 20 1999 Nicola Pero <n.pero@mi.flashnet.it> Mon Sep 20 1999 Nicola Pero <n.pero@mi.flashnet.it>
* Source/NSView.m ([-setFrameSize:]): use zero width or height if * Source/NSView.m ([-setFrameSize:]): use zero width or height if

View file

@ -275,6 +275,7 @@ static Class colorClass;
NSColor *backColor; NSColor *backColor;
control_view = controlView; // remember last view cell was drawn in control_view = controlView; // remember last view cell was drawn in
[controlView lockFocus];
if (cell_highlighted || cell_state) // temporary hack FAR FIX ME? if (cell_highlighted || cell_state) // temporary hack FAR FIX ME?
{ {
backColor = [colorClass selectedControlColor]; backColor = [colorClass selectedControlColor];
@ -327,6 +328,7 @@ static Class colorClass;
position.y += [image size].height; position.y += [image size].height;
[image compositeToPoint: position operation: NSCompositeCopy]; [image compositeToPoint: position operation: NSCompositeCopy];
} }
[controlView unlockFocus];
} }
/* /*

View file

@ -304,9 +304,7 @@ id _nsbuttonCellClass = nil;
- (void) performClick: (id)sender - (void) performClick: (id)sender
{ {
[self lockFocus];
[cell performClick: sender]; [cell performClick: sender];
[self unlockFocus];
} }
- (BOOL) performKeyEquivalent: (NSEvent *)anEvent - (BOOL) performKeyEquivalent: (NSEvent *)anEvent

View file

@ -185,7 +185,12 @@
- (void) performClick: (id)sender - (void) performClick: (id)sender
{ {
NSView *cv = [NSView focusView]; NSView *cv;
if (control_view)
cv = control_view;
else
cv = [NSView focusView];
[self highlight: YES withFrame: [cv frame] inView: cv]; [self highlight: YES withFrame: [cv frame] inView: cv];
if (action) if (action)
@ -397,6 +402,7 @@
// draw the border if needed // draw the border if needed
if ([self isBordered]) if ([self isBordered])
{ {
[controlView lockFocus];
if ([self isHighlighted] && ([self highlightsBy] & NSPushInCellMask)) if ([self isHighlighted] && ([self highlightsBy] & NSPushInCellMask))
{ {
NSDrawGrayBezel(cellFrame, NSZeroRect); NSDrawGrayBezel(cellFrame, NSZeroRect);
@ -405,6 +411,7 @@
{ {
NSDrawButton(cellFrame, NSZeroRect); NSDrawButton(cellFrame, NSZeroRect);
} }
[controlView unlockFocus];
} }
[self drawInteriorWithFrame: cellFrame inView: controlView]; [self drawInteriorWithFrame: cellFrame inView: controlView];
@ -426,6 +433,7 @@
return; return;
cellFrame = [self drawingRectForBounds: cellFrame]; cellFrame = [self drawingRectForBounds: cellFrame];
[controlView lockFocus];
// pushed in buttons contents are displaced to the bottom right 1px // pushed in buttons contents are displaced to the bottom right 1px
if ([self isBordered] && [self isHighlighted] if ([self isBordered] && [self isHighlighted]
@ -562,6 +570,7 @@
{ {
[self _drawText: titleToDisplay inFrame: titleRect]; [self _drawText: titleToDisplay inFrame: titleRect];
} }
[controlView unlockFocus];
} }
- (NSSize) cellSize - (NSSize) cellSize

View file

@ -684,7 +684,8 @@ static Class cellClass;
- (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawInteriorWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
{ {
cellFrame = [self drawingRectForBounds: cellFrame]; cellFrame = [self drawingRectForBounds: cellFrame];
[controlView lockFocus];
// Clear the cell frame // Clear the cell frame
if ([self isOpaque]) if ([self isOpaque])
{ {
@ -730,6 +731,7 @@ static Class cellClass;
case NSNullCellType: case NSNullCellType:
break; break;
} }
[controlView unlockFocus];
} }
- (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView - (void) drawWithFrame: (NSRect)cellFrame inView: (NSView*)controlView
@ -743,6 +745,7 @@ static Class cellClass;
if (NSIsEmptyRect(cellFrame)) if (NSIsEmptyRect(cellFrame))
return; return;
[controlView lockFocus];
// draw the border if needed // draw the border if needed
if ([self isBordered]) if ([self isBordered])
{ {
@ -754,6 +757,7 @@ static Class cellClass;
NSDrawWhiteBezel(cellFrame, NSZeroRect); NSDrawWhiteBezel(cellFrame, NSZeroRect);
} }
[controlView unlockFocus];
[self drawInteriorWithFrame: cellFrame inView: controlView]; [self drawInteriorWithFrame: cellFrame inView: controlView];
} }
@ -820,7 +824,12 @@ static Class cellClass;
- (void) performClick: (id)sender - (void) performClick: (id)sender
{ {
NSView *cv = [NSView focusView]; NSView *cv;
if (control_view)
cv = control_view;
else
cv = [NSView focusView];
NSLog(@"performClick:"); NSLog(@"performClick:");

View file

@ -77,7 +77,7 @@ static Class cellClass;
- (id) initWithFrame: (NSRect)frameRect - (id) initWithFrame: (NSRect)frameRect
{ {
[super initWithFrame: frameRect]; [super initWithFrame: frameRect];
[self setCell: AUTORELEASE([cellClass new])]; [self setCell: AUTORELEASE([[[self class] cellClass] new])];
tag = 0; tag = 0;
return self; return self;
@ -319,7 +319,8 @@ static Class cellClass;
{ {
if (cell == aCell) if (cell == aCell)
{ {
[cell drawInteriorWithFrame: bounds inView: self]; [cell drawInteriorWithFrame: [cell drawingRectForBounds: bounds]
inView: self];
} }
} }
@ -413,7 +414,6 @@ static Class cellClass;
unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask | unsigned int event_mask = NSLeftMouseDownMask | NSLeftMouseUpMask |
NSMouseMovedMask | NSLeftMouseDraggedMask | NSMouseMovedMask | NSLeftMouseDraggedMask |
NSRightMouseDraggedMask; NSRightMouseDraggedMask;
NSDebugLog(@"NSControl mouseDown\n"); NSDebugLog(@"NSControl mouseDown\n");
if (![self isEnabled]) if (![self isEnabled])
@ -426,8 +426,6 @@ static Class cellClass;
[window _captureMouse: self]; [window _captureMouse: self];
[self lockFocus];
e = theEvent; e = theEvent;
while (!done) // loop until mouse goes up while (!done) // loop until mouse goes up
{ {
@ -472,7 +470,7 @@ static Class cellClass;
[cell highlight: NO withFrame: bounds inView: self]; [cell highlight: NO withFrame: bounds inView: self];
[window flushWindow]; [window flushWindow];
} }
[self unlockFocus];
[cell sendActionOn: oldActionMask]; [cell sendActionOn: oldActionMask];
if (mouseUp) if (mouseUp)

View file

@ -122,7 +122,8 @@
// do nothing if cell's frame rect is zero // do nothing if cell's frame rect is zero
if( NSIsEmptyRect(cellFrame) ) if( NSIsEmptyRect(cellFrame) )
return; return;
[controlView lockFocus];
// draw the border if needed // draw the border if needed
switch( [self imageFrameStyle] ) switch( [self imageFrameStyle] )
{ {
@ -144,6 +145,7 @@
} }
[self drawInteriorWithFrame: cellFrame inView: controlView]; [self drawInteriorWithFrame: cellFrame inView: controlView];
[controlView unlockFocus];
} }
static inline float xLeftInRect(NSSize innerSize, NSRect outerRect) static inline float xLeftInRect(NSSize innerSize, NSRect outerRect)
@ -210,6 +212,7 @@ static inline NSSize scaleProportionally(NSSize imageSize, NSRect canvasRect)
// leave room for the frame // leave room for the frame
cellFrame = [self drawingRectForBounds: cellFrame]; cellFrame = [self drawingRectForBounds: cellFrame];
[controlView lockFocus];
switch( [self imageScaling] ) switch( [self imageScaling] )
{ {
@ -287,6 +290,7 @@ static inline NSSize scaleProportionally(NSSize imageSize, NSRect canvasRect)
// draw! // draw!
[image compositeToPoint: position operation: NSCompositeCopy]; [image compositeToPoint: position operation: NSCompositeCopy];
[controlView unlockFocus];
} }
- (NSSize) cellSize - (NSSize) cellSize

View file

@ -1289,8 +1289,10 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
if (drawsCellBackground) if (drawsCellBackground)
{ {
[self lockFocus];
[cellBackgroundColor set]; [cellBackgroundColor set];
NSRectFill(cellFrame); NSRectFill(cellFrame);
[self unlockFocus];
} }
[aCell highlight: flag [aCell highlight: flag
withFrame: cellFrame withFrame: cellFrame
@ -1386,8 +1388,6 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask unsigned eventMask = NSLeftMouseUpMask | NSLeftMouseDownMask
| NSMouseMovedMask | NSLeftMouseDraggedMask; | NSMouseMovedMask | NSLeftMouseDraggedMask;
[self lockFocus];
if ((mode == NSRadioModeMatrix) && selectedCell) if ((mode == NSRadioModeMatrix) && selectedCell)
{ {
[selectedCell setState: NSOffState]; [selectedCell setState: NSOffState];
@ -1499,8 +1499,6 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
column: highlightedColumn]; column: highlightedColumn];
[window flushWindow]; [window flushWindow];
} }
[self unlockFocus];
} }
@ -1533,7 +1531,6 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05]; [NSEvent startPeriodicEventsAfterDelay: 0.05 withPeriod: 0.05];
ASSIGN(lastEvent, theEvent); ASSIGN(lastEvent, theEvent);
[self lockFocus];
// selection involves two steps, first // selection involves two steps, first
// a loop that continues until the left mouse goes up; then a series of // a loop that continues until the left mouse goes up; then a series of
// steps which send actions and display the cell as it should appear after // steps which send actions and display the cell as it should appear after
@ -1743,8 +1740,6 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
if (target && doubleAction && ([lastEvent clickCount] > 1)) if (target && doubleAction && ([lastEvent clickCount] > 1))
[target performSelector: doubleAction withObject: self]; [target performSelector: doubleAction withObject: self];
[self unlockFocus];
if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix)) if ((mode != NSTrackModeMatrix) && (mode != NSHighlightModeMatrix))
[NSEvent stopPeriodicEvents]; [NSEvent stopPeriodicEvents];
@ -2051,14 +2046,11 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
if (![selectedCell isEditable]) if (![selectedCell isEditable])
return; return;
[self lockFocus];
// If RETURN key then make the next text the first responder // If RETURN key then make the next text the first responder
if (key_code == 0x0d) if (key_code == 0x0d)
{ {
[selectedCell endEditing: nil]; [selectedCell endEditing: nil];
[selectedCell drawInteriorWithFrame: rect inView: self]; [selectedCell drawInteriorWithFrame: rect inView: self];
[self unlockFocus];
return; return;
} }
@ -2067,7 +2059,6 @@ fprintf(stderr, " NSMatrix: selectTextAtRow --- ");
[selectedCell _handleKeyEvent: theEvent]; [selectedCell _handleKeyEvent: theEvent];
[selectedCell drawInteriorWithFrame: rect inView: self]; [selectedCell drawInteriorWithFrame: rect inView: self];
[self unlockFocus];
} }
- (BOOL) acceptsFirstResponder - (BOOL) acceptsFirstResponder

View file

@ -252,11 +252,13 @@ static BOOL usesUserKeyEquivalents = YES;
- (void) drawWithFrame: (NSRect)cellFrame - (void) drawWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView inView: (NSView *)controlView
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt;
NSRect floodRect = cellFrame; NSRect floodRect = cellFrame;
NSString *keyQ = nil; NSString *keyQ = nil;
NSColor *backColor; NSColor *backColor;
[controlView lockFocus];
ctxt = GSCurrentContext();
NSDrawButton(cellFrame, cellFrame); NSDrawButton(cellFrame, cellFrame);
floodRect.origin.x += 1; floodRect.origin.x += 1;
@ -326,5 +328,6 @@ static BOOL usesUserKeyEquivalents = YES;
[self _drawText:keyQ inFrame:floodRect]; [self _drawText:keyQ inFrame:floodRect];
} }
[controlView unlockFocus];
} }
@end @end

View file

@ -59,13 +59,15 @@
- (void) drawWithFrame: (NSRect)cellFrame - (void) drawWithFrame: (NSRect)cellFrame
inView: (NSView*)view inView: (NSView*)view
{ {
NSGraphicsContext *ctxt = GSCurrentContext(); NSGraphicsContext *ctxt;
NSColor *backColor; NSColor *backColor;
NSImage *toDraw = nil; NSImage *toDraw = nil;
NSRect rect = cellFrame; NSRect rect = cellFrame;
NSRect arect = cellFrame; NSRect arect = cellFrame;
NSPoint point; NSPoint point;
[view lockFocus];
ctxt = GSCurrentContext();
NSDrawButton(cellFrame, cellFrame); NSDrawButton(cellFrame, cellFrame);
arect.size.width -= 3; arect.size.width -= 3;
@ -188,5 +190,6 @@
position.y += size.height; position.y += size.height;
[toDraw compositeToPoint: position operation: NSCompositeCopy]; [toDraw compositeToPoint: position operation: NSCompositeCopy];
} }
[view unlockFocus];
} }
@end @end

View file

@ -125,6 +125,7 @@
NSImage* image; NSImage* image;
NSSize size; NSSize size;
[controlView lockFocus];
if (vertical != _isVertical) { if (vertical != _isVertical) {
if (vertical) { if (vertical) {
image = [NSImage imageNamed: @"common_SliderVert"]; image = [NSImage imageNamed: @"common_SliderVert"];
@ -148,6 +149,7 @@
[self drawBarInside: cellFrame flipped: [controlView isFlipped]]; [self drawBarInside: cellFrame flipped: [controlView isFlipped]];
[self drawKnob]; [self drawKnob];
[controlView unlockFocus];
} }
- (float) knobThickness - (float) knobThickness

View file

@ -5,8 +5,10 @@
- (void) drawInteriorWithFrame: (NSRect)cellFrame - (void) drawInteriorWithFrame: (NSRect)cellFrame
inView: (NSView *)controlView inView: (NSView *)controlView
{ {
[controlView lockFocus];
[[NSColor controlShadowColor] set]; [[NSColor controlShadowColor] set];
NSRectFill(cellFrame); NSRectFill(cellFrame);
[super drawInteriorWithFrame: cellFrame inView: controlView]; [super drawInteriorWithFrame: cellFrame inView: controlView];
[controlView unlockFocus];
} }
@end @end

View file

@ -195,8 +195,10 @@
{ {
if (draw_background) if (draw_background)
{ {
[controlView lockFocus];
[background_color set]; [background_color set];
NSRectFill ([self drawingRectForBounds: cellFrame]); NSRectFill ([self drawingRectForBounds: cellFrame]);
[controlView unlockFocus];
} }
[super drawInteriorWithFrame: cellFrame inView: controlView]; [super drawInteriorWithFrame: cellFrame inView: controlView];
} }