Move mouse location code to graphics context.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@4381 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
richard 1999-06-09 08:54:08 +00:00
parent 6bbd8536b1
commit e3c716678d
7 changed files with 61 additions and 35 deletions

View file

@ -1,5 +1,11 @@
Wed Jun 9 8:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk> Wed Jun 9 8:35:00 1999 Richard Frith-Macdonald <richard@brainstorm.co.uk>
* Headers/AppKit/DPSOperators.h: Add DPSmouselocation()
* Headers/AppKit/PSOperators.h: Add PSmouselocation()
* Headers/AppKit/NSGraphicsContext.h: Add ([-DPSmouselocation::])
* Headers/AppKit/GSMethodTable.h: Add ([-DPSmouselocation::])
* Source/NSWindow.m: Use DPSmouselocation()
* Source/NSGraphicsContext.m: Add ([-DPSmouselocation::])
* Source/NSApplication.m: Fix retain/release problems introduced by * Source/NSApplication.m: Fix retain/release problems introduced by
event system changes. event system changes.

View file

@ -1931,4 +1931,11 @@ DPSPostEvent(GSCTXT *ctxt, NSEvent* anEvent, BOOL atStart)
(ctxt, @selector(DPSPostEvent:atStart:), anEvent, atStart); (ctxt, @selector(DPSPostEvent:atStart:), anEvent, atStart);
} }
static inline void
DPSmouselocation(GSCTXT *ctxt, float *x, float *y)
{
(ctxt->methods->DPSmouselocation__)
(ctxt, @selector(DPSmouselocation::), x, y);
}
#endif #endif

View file

@ -405,6 +405,8 @@ typedef struct {
(NSGraphicsContext*, SEL, unsigned, NSEvent*); (NSGraphicsContext*, SEL, unsigned, NSEvent*);
void (*DPSPostEvent_atStart_) void (*DPSPostEvent_atStart_)
(NSGraphicsContext*, SEL, NSEvent*, BOOL); (NSGraphicsContext*, SEL, NSEvent*, BOOL);
void (*DPSmouselocation__)
(NSGraphicsContext*, SEL, float*, float*);
} gsMethodTable; } gsMethodTable;

View file

@ -356,6 +356,7 @@ NSGraphicsContext *GSCurrentContext();
- (void) DPSDiscardEventsMatchingMask: (unsigned)mask - (void) DPSDiscardEventsMatchingMask: (unsigned)mask
beforeEvent: (NSEvent*)limit; beforeEvent: (NSEvent*)limit;
- (void) DPSPostEvent: (NSEvent*)anEvent atStart: (BOOL)flag; - (void) DPSPostEvent: (NSEvent*)anEvent atStart: (BOOL)flag;
- (void) DPSmouselocation: (float*)x : (float*)y;
@end @end
#endif /* _NSGraphicsContext_h_INCLUDE */ #endif /* _NSGraphicsContext_h_INCLUDE */

View file

@ -1767,4 +1767,10 @@ PSPostEvent(NSEvent* anEvent, BOOL atStart)
DPSPostEvent(DEFCTXT, anEvent, atStart); DPSPostEvent(DEFCTXT, anEvent, atStart);
} }
static inline void
PSmouselocation(float *x, float *y)
{
DPSmouselocation(DEFCTXT, x, y);
}
#endif #endif

View file

@ -657,6 +657,8 @@ struct NSWindow_struct
GET_IMP(@selector(DPSDiscardEventsMatchingMask:beforeEvent:)); GET_IMP(@selector(DPSDiscardEventsMatchingMask:beforeEvent:));
methodTable.DPSPostEvent_atStart_ = methodTable.DPSPostEvent_atStart_ =
GET_IMP(@selector(DPSPostEvent:atStart:)); GET_IMP(@selector(DPSPostEvent:atStart:));
methodTable.DPSmouselocation__ =
GET_IMP(@selector(DPSmouselocation::));
mptr = NSZoneMalloc(_globalGSZone, sizeof(gsMethodTable)); mptr = NSZoneMalloc(_globalGSZone, sizeof(gsMethodTable));
memcpy(mptr, &methodTable, sizeof(gsMethodTable)); memcpy(mptr, &methodTable, sizeof(gsMethodTable));
@ -1825,4 +1827,8 @@ struct NSWindow_struct
[event_queue addObject: anEvent]; [event_queue addObject: anEvent];
} }
- (void) DPSmouselocation: (float*)x : (float*)y
{
[self subclassResponsibility: _cmd];
}
@end @end

View file

@ -50,6 +50,7 @@
#include <AppKit/NSScreen.h> #include <AppKit/NSScreen.h>
#include <AppKit/NSView.h> #include <AppKit/NSView.h>
#include <AppKit/NSCursor.h> #include <AppKit/NSCursor.h>
#include <AppKit/PSOperators.h>
@interface GSWindowView : NSView @interface GSWindowView : NSView
@ -207,12 +208,11 @@ static Class responderClass;
defer: (BOOL)flag defer: (BOOL)flag
screen: (NSScreen*)aScreen screen: (NSScreen*)aScreen
{ {
NSApplication *theApp = [NSApplication sharedApplication];
NSRect r = [[NSScreen mainScreen] frame]; NSRect r = [[NSScreen mainScreen] frame];
NSRect cframe; NSRect cframe;
NSDebugLog(@"NSWindow default initializer\n"); NSDebugLog(@"NSWindow default initializer\n");
if (!theApp) if (!NSApp)
NSLog(@"No application!\n"); NSLog(@"No application!\n");
NSDebugLog(@"NSWindow start of init\n"); NSDebugLog(@"NSWindow start of init\n");
@ -226,7 +226,7 @@ static Class responderClass;
minimum_size = NSZeroSize; minimum_size = NSZeroSize;
maximum_size = r.size; maximum_size = r.size;
// Next responder is the // Next responder is the
[self setNextResponder: theApp]; // application [self setNextResponder: NSApp]; // application
cursor_rects_enabled = YES; // Cursor management cursor_rects_enabled = YES; // Cursor management
cursor_rects_valid = NO; cursor_rects_valid = NO;
@ -311,7 +311,7 @@ static Class responderClass;
&& ((represented_filename != nil && old == nil) && ((represented_filename != nil && old == nil)
|| (represented_filename == nil && old != nil))) || (represented_filename == nil && old != nil)))
{ {
[[NSApplication sharedApplication] updateWindowsItem: self]; [NSApp updateWindowsItem: self];
} }
} }
@ -403,9 +403,9 @@ static Class responderClass;
if ([title isEqual: represented_filename]) if ([title isEqual: represented_filename])
isDoc = YES; isDoc = YES;
if (menu_exclude == NO) if (menu_exclude == NO)
[[NSApplication sharedApplication] changeWindowsItem: self [NSApp changeWindowsItem: self
title: title title: title
filename: isDoc]; filename: isDoc];
} }
// //
@ -508,22 +508,18 @@ static Class responderClass;
- (void) makeKeyWindow - (void) makeKeyWindow
{ {
NSApplication *theApp = [NSApplication sharedApplication];
if (![self canBecomeKeyWindow]) if (![self canBecomeKeyWindow])
return; return;
[[theApp keyWindow] resignKeyWindow]; [[NSApp keyWindow] resignKeyWindow];
[self becomeKeyWindow]; [self becomeKeyWindow];
} }
- (void) makeMainWindow - (void) makeMainWindow
{ {
NSApplication *theApp = [NSApplication sharedApplication];
if (![self canBecomeMainWindow]) if (![self canBecomeMainWindow])
return; return;
[[theApp mainWindow] resignMainWindow]; [[NSApp mainWindow] resignMainWindow];
[self becomeMainWindow]; [self becomeMainWindow];
} }
@ -761,7 +757,7 @@ static Class responderClass;
- (void) setViewsNeedDisplay: (BOOL)flag - (void) setViewsNeedDisplay: (BOOL)flag
{ {
needs_display = flag; needs_display = flag;
[[NSApplication sharedApplication] setWindowsNeedUpdate: YES]; [NSApp setWindowsNeedUpdate: YES];
} }
- (BOOL) viewsNeedDisplay - (BOOL) viewsNeedDisplay
@ -896,7 +892,6 @@ static Class responderClass;
- (void) close - (void) close
{ {
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSApplication *theApp = [NSApplication sharedApplication];
/* /*
* If 'is_released_when_closed' then the window will be removed from the * If 'is_released_when_closed' then the window will be removed from the
@ -908,7 +903,7 @@ static Class responderClass;
RETAIN(self); RETAIN(self);
[nc postNotificationName: NSWindowWillCloseNotification object: self]; [nc postNotificationName: NSWindowWillCloseNotification object: self];
[theApp removeWindowsItem: self]; [NSApp removeWindowsItem: self];
[self orderOut: self]; [self orderOut: self];
if (is_released_when_closed) if (is_released_when_closed)
@ -1009,7 +1004,7 @@ static Class responderClass;
is_edited = flag; is_edited = flag;
if (menu_exclude == NO) if (menu_exclude == NO)
{ {
[[NSApplication sharedApplication] updateWindowsItem: self]; [NSApp updateWindowsItem: self];
} }
} }
} }
@ -1029,15 +1024,13 @@ static Class responderClass;
- (NSEvent *) currentEvent - (NSEvent *) currentEvent
{ {
return [[NSApplication sharedApplication] currentEvent]; return [NSApp currentEvent];
} }
- (void) discardEventsMatchingMask: (unsigned int)mask - (void) discardEventsMatchingMask: (unsigned int)mask
beforeEvent: (NSEvent *)lastEvent beforeEvent: (NSEvent *)lastEvent
{ {
NSApplication *theApp = [NSApplication sharedApplication]; [NSApp discardEventsMatchingMask: mask beforeEvent: lastEvent];
[theApp discardEventsMatchingMask: mask beforeEvent: lastEvent];
} }
- (NSResponder*) firstResponder - (NSResponder*) firstResponder
@ -1072,18 +1065,24 @@ static Class responderClass;
} }
/* Return mouse location in reciever's base coord system, ignores event /* Return mouse location in reciever's base coord system, ignores event
* loop status (backend) */ * loop status */
- (NSPoint) mouseLocationOutsideOfEventStream - (NSPoint) mouseLocationOutsideOfEventStream
{ {
return NSZeroPoint; float x;
float y;
DPSmouselocation(GSCurrentContext(), &x, &y);
x -= frame.origin.x;
y -= frame.origin.y;
return NSMakePoint(x, y);
} }
- (NSEvent *) nextEventMatchingMask: (unsigned int)mask - (NSEvent *) nextEventMatchingMask: (unsigned int)mask
{ {
return [[NSApplication sharedApplication] nextEventMatchingMask: mask return [NSApp nextEventMatchingMask: mask
untilDate: nil untilDate: nil
inMode: NSEventTrackingRunLoopMode inMode: NSEventTrackingRunLoopMode
dequeue: YES]; dequeue: YES];
} }
- (NSEvent *) nextEventMatchingMask: (unsigned int)mask - (NSEvent *) nextEventMatchingMask: (unsigned int)mask
@ -1091,15 +1090,15 @@ static Class responderClass;
inMode: (NSString *)mode inMode: (NSString *)mode
dequeue: (BOOL)deqFlag dequeue: (BOOL)deqFlag
{ {
return [[NSApplication sharedApplication] nextEventMatchingMask: mask return [NSApp nextEventMatchingMask: mask
untilDate: expiration untilDate: expiration
inMode: mode inMode: mode
dequeue: deqFlag]; dequeue: deqFlag];
} }
- (void) postEvent: (NSEvent *)event atStart: (BOOL)flag - (void) postEvent: (NSEvent *)event atStart: (BOOL)flag
{ {
[[NSApplication sharedApplication] postEvent: event atStart: flag]; [NSApp postEvent: event atStart: flag];
} }
- (void) setAcceptsMouseMovedEvents: (BOOL)flag - (void) setAcceptsMouseMovedEvents: (BOOL)flag
@ -1486,9 +1485,8 @@ static Class responderClass;
returnType: returnType]; returnType: returnType];
if (result == nil) if (result == nil)
result = [[NSApplication sharedApplication] result = [NSApp validRequestorForSendType: sendType
validRequestorForSendType: sendType returnType: returnType];
returnType: returnType];
return result; return result;
} }