Fixed combo box bug introduced in June

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19870 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Quentin Mathe 2004-08-13 22:07:06 +00:00
parent dd69ef973d
commit a4c583b139
3 changed files with 88 additions and 40 deletions

View file

@ -1,3 +1,17 @@
2004-08-13 Quentin Mathe <qmathe@club-internet.fr>
* Source/NSComboBoxCell.m:
* Source/NSComboBox.m:
Fixed broken combo box behavior introduced June 17 with version 1.27,
which produced wrong tracking in the button cell and extra mouse down
call in the NSComboBox superclass. Now the rewritten version is also
documented.
Also now -[GSComboWindow deselectItemAtIndex:] still produces a
-[GSComboWindow tableViewSelectionDidChange:] call but the chain is
stopped in -[GSComboWindow validateSelection] by the _locationSelection
variable, then -[NSComboBoxCell selectItemAtIndex:] is not anymore
wrongly called.
2004-08-12 01:42 Alexander Malmberg <alexander@malmberg.org>
* Source/NSLayoutManager.m

View file

@ -455,14 +455,14 @@ static NSNotificationCenter *nc;
// Overridden
- (void) mouseDown: (NSEvent*)theEvent
{
BOOL clicked;
// clicked is set to the value YES when the click occurs in the text cell
// and to the value NO when it occurs in the button cell
BOOL buttonClicked;
// buttonClicked is set to the value YNO when the click occurs in the text cell
// and to the value YES when it occurs in the button cell
clicked = [_cell trackMouse: theEvent inRect: [self bounds]
buttonClicked = [_cell trackMouse: theEvent inRect: [self bounds]
ofView: self untilMouseUp: YES];
if (clicked)
if (!buttonClicked)
[super mouseDown: theEvent];
}

View file

@ -406,9 +406,7 @@ static GSComboWindow *gsWindow = nil;
[self makeFirstResponder: _tableView];
[self runLoopWithComboBoxCell: comboBoxCell];
[nc removeObserver: self];
[_tableView setDelegate: self];
// HACK: Need to reset the delegate to receive the next notifications
[nc removeObserver: self name: nil object: onWindow];
[self close];
@ -562,7 +560,9 @@ static GSComboWindow *gsWindow = nil;
{
if (!ForceBrowser)
{
_localSelection = YES;
[_tableView deselectAll: self];
_localSelection = NO;
}
else
{
@ -1431,16 +1431,26 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
}
}
/** Overrides NSCell <code>trackMouse:inRect:ofView:untilMouseUp:</code> method to establish a
* new method behavior.
* In the case <var>flag</var> is NO, returns NO when the mouse down occurs in the text
* cell part or when the mouse down occurs in the button cell part followed by a
* mouse up outside, otherwise returns YES (when both the mouse down and the
* mouse up occurs in the button cell part).
* In the case <var>flag</var> is YES, returns NO when the mouse occurs in the text
* cell part, otherwise returns YES (when the mouse down occurs in the button cell
* part).
*/
- (BOOL) trackMouse: (NSEvent *)theEvent
inRect: (NSRect)cellFrame
ofView: (NSView *)controlView
untilMouseUp: (BOOL)flag
{
NSWindow *cvWindow = [controlView window];
NSPoint point;
BOOL isFlipped = [controlView isFlipped];
BOOL clicked = NO;
NSRect buttonRect = buttonCellFrameFromRect(cellFrame);
NSRect textRect = textCellFrameFromRect(cellFrame);
BOOL result = NO;
// Should this be set by NSActionCell ?
if (_control_view != controlView)
@ -1451,38 +1461,62 @@ static inline NSRect buttonCellFrameFromRect(NSRect cellRect)
point = [controlView convertPoint: [theEvent locationInWindow]
fromView: nil];
if (!NSMouseInRect(point, cellFrame, isFlipped))
return NO;
else if ([theEvent type] == NSLeftMouseDown)
if (NSMouseInRect(point, textRect, isFlipped))
{
if (NSMouseInRect(point, textCellFrameFromRect(cellFrame), isFlipped))
{
return NO;
}
else if (NSMouseInRect(point, buttonRect, isFlipped))
{
[controlView lockFocus];
[_buttonCell highlight: YES withFrame: buttonRect inView: controlView];
[controlView unlockFocus];
[cvWindow flushWindow];
clicked = [_buttonCell trackMouse: theEvent
inRect: buttonRect
ofView: controlView
untilMouseUp: NO];
/* The click will be send by the target/action we have set for the button cell. */
[controlView lockFocus];
[_buttonCell highlight: NO withFrame: buttonRect inView: controlView];
[controlView unlockFocus];
[cvWindow flushWindow];
return clicked;
}
return NO;
}
return NO;
else if (NSMouseInRect(point, buttonRect, isFlipped))
{
NSEvent *e = theEvent;
BOOL isMouseUp = NO;
unsigned int eventMask = NSLeftMouseDownMask | NSLeftMouseUpMask
| NSMouseMovedMask | NSLeftMouseDraggedMask | NSOtherMouseDraggedMask
| NSRightMouseDraggedMask;
NSPoint location;
while (!isMouseUp) // Loop until mouse goes up
{
location = [controlView convertPoint: [e locationInWindow] fromView: nil];
// Ask the cell to track the mouse only when the mouse is within the cell
if (NSMouseInRect(location, buttonRect, isFlipped))
{
[_buttonCell setHighlighted: YES];
[controlView setNeedsDisplay: YES];
result = [_buttonCell trackMouse: e
inRect: buttonRect
ofView: controlView
untilMouseUp: [NSButtonCell prefersTrackingUntilMouseUp]];
isMouseUp = result;
[_buttonCell setHighlighted: NO];
[controlView setNeedsDisplay: YES];
}
if (!isMouseUp)
{
e = [NSApp nextEventMatchingMask: eventMask
untilDate: nil
inMode: NSEventTrackingRunLoopMode
dequeue: YES];
if ([e type] == NSLeftMouseUp)
isMouseUp = YES;
}
}
if (flag)
{
return YES;
}
else
{
return NO;
}
}
return NO; // Pathological case, normally never happen
}
- (void) resetCursorRect: (NSRect)cellFrame inView: (NSView *)controlView