From 61b91e6b5708e95537640a9539eb8906f3298053 Mon Sep 17 00:00:00 2001 From: Alexander Malmberg Date: Sat, 21 Sep 2002 23:33:37 +0000 Subject: [PATCH] Handle becomesKeyOnlyIfNeeded in NSPanel properly. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14508 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 8 +++++ Headers/gnustep/gui/NSView.h | 1 + Source/NSPanel.m | 67 ++++++++++++++++++++++++++++++++++-- Source/NSText.m | 5 +++ Source/NSTextField.m | 5 +++ Source/NSView.m | 6 ++++ Source/NSWindow.m | 5 ++- 7 files changed, 94 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1fa501df0..6952d065c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-09-22 01:23 Alexander Malmberg + + * Headers/gnustep/gui/NSView.h, Source/NSPanel.m, Source/NSText.m, + Source/NSTextField.m, Source/NSView.m, Source/NSWindow.m: Add + -needsPanelToBecomeKey method to NSView and override it to return + YES in NSText and NSTextField. Use it in NSPanel to handle + becomesKeyOnlyIfNeeded properly. + 2002-09-21 18:54 Gregory John Casamento * Source/NSOutlineView.m corrected preprocessor error messages. diff --git a/Headers/gnustep/gui/NSView.h b/Headers/gnustep/gui/NSView.h index aa59893ff..a0b548df6 100644 --- a/Headers/gnustep/gui/NSView.h +++ b/Headers/gnustep/gui/NSView.h @@ -339,6 +339,7 @@ enum { /* * Aiding Event Handling */ +-(BOOL) needsPanelToBecomeKey; - (void) setNextKeyView: (NSView*)aView; - (NSView*) nextKeyView; - (NSView*) nextValidKeyView; diff --git a/Source/NSPanel.m b/Source/NSPanel.m index baa7e6dfb..744fb1f4d 100644 --- a/Source/NSPanel.m +++ b/Source/NSPanel.m @@ -52,6 +52,8 @@ #include +#include + #ifdef ALERT_TITLE static NSString *defaultTitle = @"Alert"; #else @@ -94,8 +96,6 @@ static NSString *defaultTitle = @" "; - (BOOL) canBecomeKeyWindow { - if (_becomesKeyOnlyIfNeeded) - return NO; return YES; } @@ -191,6 +191,69 @@ static NSString *defaultTitle = @" "; return self; } + +- (void) sendEvent: (NSEvent*)theEvent +{ +/* +Code shared with [NSWindow -sendEvent:], remember to update both places. +*/ + NSView *v; + NSEventType type; + + type = [theEvent type]; + switch (type) + { + case NSLeftMouseDown: + { + BOOL wasKey = _f.is_key; + + if ([NSApp isActive] == NO && ((NSWindow *)self) != [NSApp iconWindow]) + { + [NSApp activateIgnoringOtherApps: YES]; + } + if (_f.has_closed == NO) + { + v = [_contentView hitTest: [theEvent locationInWindow]]; + if (_f.is_key == NO) + { + if (!_becomesKeyOnlyIfNeeded || [v needsPanelToBecomeKey]) + [self makeKeyAndOrderFront: self]; + } + if (_firstResponder != v) + { + [self makeFirstResponder: v]; + } + if (_lastDragView) + DESTROY(_lastDragView); + if (wasKey == YES || [v acceptsFirstMouse: theEvent] == YES) + { + if ([NSHelpManager isContextHelpModeActive]) + { + [v helpRequested: theEvent]; + } + else + { + /* Technically this should be just _lastView, + but I don't think it's a problem reusing this + ivar */ + ASSIGN(_lastDragView, v); + [v mouseDown: theEvent]; + } + } + else + { + [self mouseDown: theEvent]; + } + } + _lastPoint = [theEvent locationInWindow]; + break; + } + default: + [super sendEvent: theEvent]; + break; + } +} + @end /* NSPanel */ diff --git a/Source/NSText.m b/Source/NSText.m index f7ff17298..a65119e75 100644 --- a/Source/NSText.m +++ b/Source/NSText.m @@ -630,6 +630,11 @@ static Class concrete; * NSView */ +-(BOOL) needsPanelToBecomeKey +{ + return _tf.is_editable; +} + /* text lays out from top to bottom */ - (BOOL) isFlipped { diff --git a/Source/NSTextField.m b/Source/NSTextField.m index 6c3160b69..a8bff87c1 100644 --- a/Source/NSTextField.m +++ b/Source/NSTextField.m @@ -325,6 +325,11 @@ static Class textFieldCellClass; return [self isSelectable]; } +-(BOOL) needsPanelToBecomeKey +{ + return [self isEditable]; +} + - (BOOL) abortEditing { if (_text_object) diff --git a/Source/NSView.m b/Source/NSView.m index c43ce271f..1b7d42989 100644 --- a/Source/NSView.m +++ b/Source/NSView.m @@ -2430,6 +2430,11 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) return t; } +-(BOOL) needsPanelToBecomeKey +{ + return NO; +} + - (void) setNextKeyView: (NSView *)aView { if (!aView) @@ -3518,5 +3523,6 @@ static NSView* findByTag(NSView *view, int aTag, unsigned *level) } } } + @end diff --git a/Source/NSWindow.m b/Source/NSWindow.m index 04f9bc272..d87895868 100644 --- a/Source/NSWindow.m +++ b/Source/NSWindow.m @@ -2742,6 +2742,9 @@ resetCursorRectsForView(NSView *theView) switch (type) { case NSLeftMouseDown: +/* +Code shared with [NSPanel -sendEvent:], remember to update both places. +*/ { BOOL wasKey = _f.is_key; @@ -2751,11 +2754,11 @@ resetCursorRectsForView(NSView *theView) } if (_f.has_closed == NO) { + v = [_contentView hitTest: [theEvent locationInWindow]]; if (_f.is_key == NO) { [self makeKeyAndOrderFront: self]; } - v = [_contentView hitTest: [theEvent locationInWindow]]; if (_firstResponder != v) { [self makeFirstResponder: v];