Mouse handling fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3973 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-03-24 11:31:06 +00:00
parent c444b09026
commit bceff2165a
6 changed files with 148 additions and 106 deletions

View file

@ -40,6 +40,7 @@
#include <AppKit/NSScrollView.h> #include <AppKit/NSScrollView.h>
#include <AppKit/NSMatrix.h> #include <AppKit/NSMatrix.h>
#include <AppKit/NSTextFieldCell.h> #include <AppKit/NSTextFieldCell.h>
#include <AppKit/PSOperators.h>
#define COLUMN_SEP 6 #define COLUMN_SEP 6
@ -1296,6 +1297,7 @@
{ {
int i; int i;
NSRectClip(rect);
// Load the first column if not already done // Load the first column if not already done
if (!_isLoaded) if (!_isLoaded)
{ {

View file

@ -1,4 +1,4 @@
/* /*
NSButton.m NSButton.m
The button class The button class
@ -8,14 +8,14 @@
Author: Scott Christley <scottc@net-community.com> Author: Scott Christley <scottc@net-community.com>
Ovidiu Predescu <ovidiu@net-community.com> Ovidiu Predescu <ovidiu@net-community.com>
Date: 1996 Date: 1996
This file is part of the GNUstep GUI Library. This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version. version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
@ -25,7 +25,7 @@
License along with this library; see the file COPYING.LIB. License along with this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation, If not, write to the Free Software Foundation,
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <gnustep/gui/config.h> #include <gnustep/gui/config.h>
@ -47,24 +47,24 @@ id _nsbuttonCellClass = nil;
// //
// Class methods // Class methods
// //
+ (void)initialize + (void) initialize
{ {
if (self == [NSButton class]) if (self == [NSButton class])
{ {
[self setVersion:1]; [self setVersion: 1];
[self setCellClass:[NSButtonCell class]]; [self setCellClass: [NSButtonCell class]];
} }
} }
// //
// Initializing the NSButton Factory // Initializing the NSButton Factory
// //
+ (Class)cellClass + (Class) cellClass
{ {
return _nsbuttonCellClass; return _nsbuttonCellClass;
} }
+ (void)setCellClass:(Class)classId + (void) setCellClass: (Class)classId
{ {
_nsbuttonCellClass = classId; _nsbuttonCellClass = classId;
} }
@ -77,191 +77,196 @@ id _nsbuttonCellClass = nil;
// //
- init - init
{ {
return [self initWithFrame:NSZeroRect]; return [self initWithFrame: NSZeroRect];
} }
- initWithFrame:(NSRect)frameRect - initWithFrame: (NSRect)frameRect
{ {
[super initWithFrame:frameRect]; [super initWithFrame: frameRect];
// set our cell // set our cell
[self setCell:[[_nsbuttonCellClass new] autorelease]]; [self setCell: [[_nsbuttonCellClass new] autorelease]];
return self; return self;
} }
// - (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
// Setting the Button Type
//
- (void)setButtonType:(NSButtonType)aType
{ {
[cell setButtonType:aType]; return YES;
}
//
// Setting the Button Type
//
- (void) setButtonType: (NSButtonType)aType
{
[cell setButtonType: aType];
[self display]; [self display];
} }
// //
// Identifying the Selected Cell // Identifying the Selected Cell
// //
- (id)selectedCell - (id) selectedCell
{ {
return cell; return cell;
} }
// //
// Setting the State // Setting the State
// //
- (void)setIntValue:(int)anInt - (void) setIntValue: (int)anInt
{ {
[self setState:(anInt != 0)]; [self setState: (anInt != 0)];
} }
- (void)setFloatValue:(float)aFloat - (void) setFloatValue: (float)aFloat
{ {
[self setState:(aFloat != 0)]; [self setState: (aFloat != 0)];
} }
- (void)setDoubleValue:(double)aDouble - (void) setDoubleValue: (double)aDouble
{ {
[self setState:(aDouble != 0)]; [self setState: (aDouble != 0)];
} }
- (void)setState:(int)value - (void) setState: (int)value
{ {
[cell setState:value]; [cell setState: value];
[self display]; [self display];
} }
- (int)state - (int) state
{ {
return [cell state]; return [cell state];
} }
// //
// Setting the Repeat Interval // Setting the Repeat Interval
// //
- (void)getPeriodicDelay:(float *)delay - (void) getPeriodicDelay: (float *)delay
interval:(float *)interval interval: (float *)interval
{ {
[cell getPeriodicDelay:delay interval:interval]; [cell getPeriodicDelay: delay interval: interval];
} }
- (void)setPeriodicDelay:(float)delay - (void) setPeriodicDelay: (float)delay
interval:(float)interval interval: (float)interval
{ {
[cell setPeriodicDelay:delay interval:interval]; [cell setPeriodicDelay: delay interval: interval];
} }
// //
// Setting the Titles // Setting the Titles
// //
- (NSString *)alternateTitle - (NSString *) alternateTitle
{ {
return [cell alternateTitle]; return [cell alternateTitle];
} }
- (void)setAlternateTitle:(NSString *)aString - (void) setAlternateTitle: (NSString *)aString
{ {
[cell setAlternateTitle:aString]; [cell setAlternateTitle: aString];
[self display]; [self display];
} }
- (void)setTitle:(NSString *)aString - (void) setTitle: (NSString *)aString
{ {
[cell setTitle:aString]; [cell setTitle: aString];
[self display]; [self display];
} }
- (NSString *)title - (NSString *) title
{ {
return [cell title]; return [cell title];
} }
// //
// Setting the Images // Setting the Images
// //
- (NSImage *)alternateImage - (NSImage *) alternateImage
{ {
return [cell alternateImage]; return [cell alternateImage];
} }
- (NSImage *)image - (NSImage *) image
{ {
return [cell image]; return [cell image];
} }
- (NSCellImagePosition)imagePosition - (NSCellImagePosition) imagePosition
{ {
return [cell imagePosition]; return [cell imagePosition];
} }
- (void)setAlternateImage:(NSImage *)anImage - (void) setAlternateImage: (NSImage *)anImage
{ {
[cell setAlternateImage:anImage]; [cell setAlternateImage: anImage];
[self display]; [self display];
} }
- (void)setImage:(NSImage *)anImage - (void) setImage: (NSImage *)anImage
{ {
[cell setImage:anImage]; [cell setImage: anImage];
[self display]; [self display];
} }
- (void)setImagePosition:(NSCellImagePosition)aPosition - (void) setImagePosition: (NSCellImagePosition)aPosition
{ {
[cell setImagePosition:aPosition]; [cell setImagePosition: aPosition];
[self display]; [self display];
} }
- (void)setAlignment:(NSTextAlignment)mode - (void) setAlignment: (NSTextAlignment)mode
{ {
[cell setAlignment:mode]; [cell setAlignment: mode];
} }
- (NSTextAlignment)alignment - (NSTextAlignment) alignment
{ {
return [cell alignment]; return [cell alignment];
} }
// //
// Modifying Graphic Attributes // Modifying Graphic Attributes
// //
- (BOOL)isBordered - (BOOL) isBordered
{ {
return [cell isBordered]; return [cell isBordered];
} }
- (BOOL)isTransparent - (BOOL) isTransparent
{ {
return [cell isTransparent]; return [cell isTransparent];
} }
- (void)setBordered:(BOOL)flag - (void) setBordered: (BOOL)flag
{ {
[cell setBordered:flag]; [cell setBordered: flag];
[self display]; [self display];
} }
- (void)setTransparent:(BOOL)flag - (void) setTransparent: (BOOL)flag
{ {
[cell setTransparent:flag]; [cell setTransparent: flag];
[self display]; [self display];
} }
// //
// Displaying // Displaying
// //
- (void)drawRect:(NSRect)rect - (void) drawRect: (NSRect)rect
{ {
[cell drawWithFrame:rect inView:self]; [cell drawWithFrame: rect inView: self];
} }
- (void)highlight:(BOOL)flag - (void) highlight: (BOOL)flag
{ {
[cell highlight: flag withFrame: bounds inView: self]; [cell highlight: flag withFrame: bounds inView: self];
} }
// //
// Setting the Key Equivalent // Setting the Key Equivalent
// //
- (NSString*) keyEquivalent - (NSString*) keyEquivalent
{ {
@ -286,10 +291,10 @@ id _nsbuttonCellClass = nil;
// //
// Determining the first responder // Determining the first responder
// //
- (BOOL)acceptsFirstResponder - (BOOL) acceptsFirstResponder
{ {
return [cell acceptsFirstResponder] || ([self keyEquivalent] != nil); return [cell acceptsFirstResponder] || ([self keyEquivalent] != nil);
} }
- (void) keyDown: (NSEvent*)theEvent - (void) keyDown: (NSEvent*)theEvent
{ {
@ -298,7 +303,7 @@ id _nsbuttonCellClass = nil;
} }
// //
// Handling Events and Action Messages // Handling Events and Action Messages
// //
- (void) performClick: (id)sender - (void) performClick: (id)sender

View file

@ -68,6 +68,11 @@
// Class variables // Class variables
static NSFont* menuFont = nil; static NSFont* menuFont = nil;
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
{
return YES;
}
- (id) initWithFrame: (NSRect)rect - (id) initWithFrame: (NSRect)rect
{ {
[super initWithFrame: rect]; [super initWithFrame: rect];

View file

@ -88,6 +88,11 @@ static BOOL preCalcValues = NO;
return YES; return YES;
} }
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
{
return YES;
}
- (NSScrollArrowPosition) arrowsPosition - (NSScrollArrowPosition) arrowsPosition
{ {
return _arrowsPosition; return _arrowsPosition;

View file

@ -45,6 +45,11 @@
// //
// Instance methods // Instance methods
// //
- (BOOL) acceptsFirstMouse: (NSEvent *)theEvent
{
return YES;
}
- (void) mouseDown: (NSEvent*)theEvent - (void) mouseDown: (NSEvent*)theEvent
{ {
NSApplication *app = [NSApplication sharedApplication]; NSApplication *app = [NSApplication sharedApplication];

View file

@ -1141,7 +1141,8 @@
- (void) sendEvent: (NSEvent *)theEvent - (void) sendEvent: (NSEvent *)theEvent
{ {
NSView *v; NSView *v;
NSEventType type;
if (!cursor_rects_valid) // If the cursor rects are invalid if (!cursor_rects_valid) // If the cursor rects are invalid
{ // Then discard and reset { // Then discard and reset
@ -1149,15 +1150,19 @@
[self resetCursorRects]; [self resetCursorRects];
} }
switch ([theEvent type]) type = [theEvent type];
switch (type)
{ {
case NSLeftMouseDown: // Left mouse down case NSLeftMouseDown: // Left mouse down
v = [content_view hitTest: [theEvent locationInWindow]]; v = [content_view hitTest: [theEvent locationInWindow]];
NSDebugLog([v description]); if (first_responder != v)
NSDebugLog(@"\n"); {
if (first_responder != v) // if hit view is not first [self makeFirstResponder: v];
[self makeFirstResponder: v]; // responder ask it to be if ([v acceptsFirstMouse: theEvent] == YES)
[v mouseDown: theEvent]; [v mouseDown: theEvent];
}
else
[v mouseDown: theEvent];
last_point = [theEvent locationInWindow]; last_point = [theEvent locationInWindow];
break; break;
@ -1179,31 +1184,46 @@
last_point = [theEvent locationInWindow]; last_point = [theEvent locationInWindow];
break; break;
case NSMouseMoved: // Mouse moved case NSLeftMouseDragged: // Left mouse dragged
v = [content_view hitTest: [theEvent locationInWindow]]; case NSRightMouseDragged: // Right mouse dragged
[v mouseMoved: theEvent]; // First send the NSMouseMoved event case NSMouseMoved: // Mouse moved
// We need to go through all of the views, and any with switch (type)
// a tracking rectangle then we need to determine if we {
// should send a NSMouseEntered or NSMouseExited event case NSLeftMouseDragged:
v = [content_view hitTest: [theEvent locationInWindow]];
[v mouseDragged: theEvent];
break;
case NSRightMouseDragged:
v = [content_view hitTest: [theEvent locationInWindow]];
[v rightMouseDragged: theEvent];
break;
default:
if (accepts_mouse_moved)
{
// If the window is set to accept mouse movements, we need to
// forward the mouse movement to the correct view.
v = [content_view hitTest: [theEvent locationInWindow]];
[v mouseMoved: theEvent];
}
break;
}
// We need to go through all of the views, and if there is any with
// a tracking rectangle then we need to determine if we should send
// a NSMouseEntered or NSMouseExited event.
[self checkTrackingRectangles: content_view forEvent: theEvent]; [self checkTrackingRectangles: content_view forEvent: theEvent];
// We need to go through all of the views, and any with
// a cursor rectangle then we need to determine if we
// should send a cursor update event
// We only do this if we are the key window
if (is_key) if (is_key)
[self checkCursorRectangles: content_view forEvent: theEvent]; {
// We need to go through all of the views, and if there is any with
// a cursor rectangle then we need to determine if we should send a
// cursor update event.
[self checkCursorRectangles: content_view forEvent: theEvent];
}
last_point = [theEvent locationInWindow]; last_point = [theEvent locationInWindow];
break; break;
case NSLeftMouseDragged: // Left mouse dragged
last_point = [theEvent locationInWindow];
break;
case NSRightMouseDragged: // Right mouse dragged
last_point = [theEvent locationInWindow];
break;
case NSMouseEntered: // Mouse entered case NSMouseEntered: // Mouse entered
case NSMouseExited: // Mouse exited case NSMouseExited: // Mouse exited
break; break;
@ -1219,7 +1239,7 @@
case NSKeyUp: // Key up case NSKeyUp: // Key up
if (original_responder) // send message to the if (original_responder) // send message to the
[original_responder keyUp: theEvent]; // object that got the [original_responder keyUp: theEvent]; // object that got the
break; // key down break; // key down
case NSFlagsChanged: // Flags changed case NSFlagsChanged: // Flags changed
@ -1642,7 +1662,7 @@
disable_flush_window = NO; disable_flush_window = NO;
menu_exclude = NO; menu_exclude = NO;
hides_on_deactivate = NO; hides_on_deactivate = NO;
accepts_mouse_moved = YES; accepts_mouse_moved = NO;
} }
- (id) cleanInit - (id) cleanInit