From 45382ff618faa002e28ed42c5f2f0def9f028ea5 Mon Sep 17 00:00:00 2001 From: FredKiefer Date: Mon, 28 Jun 2004 12:21:36 +0000 Subject: [PATCH] Added MacOSX standard cursors and improved mouse hidding. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@19638 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 11 ++++ Headers/AppKit/NSCursor.h | 30 +++++++++- Source/NSApplication.m | 2 +- Source/NSCursor.m | 118 ++++++++++++++++++++++++++++++-------- 4 files changed, 134 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 349f3a14d..bd8355e7e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2004-06-28 Fred Kiefer + + * Headers/AppKit/NSCursor.h: Added more MacOSX methods for standard + cursors. + * Source/NSCursor.m: Implemented new standard cursors methods. + (+setHiddenUntilMouseMoves:) added implementation. + (+initialize) set isHiddenUntilMouseMoves to NO (was YES). + * Source/NSApplication.m: (-nextEventMatchingMask:...dequeue:) when + cursor is hidden until mouse move, call [NSCursor + setHiddenUntilMouseMoves: NO] instead of [NSCursor unhide]. + 2004-06-27 23:10 Alexander Malmberg * Source/GSNibTemplates.m: Replace calls to diff --git a/Headers/AppKit/NSCursor.h b/Headers/AppKit/NSCursor.h index a12c663e6..b0d5d741f 100644 --- a/Headers/AppKit/NSCursor.h +++ b/Headers/AppKit/NSCursor.h @@ -64,9 +64,10 @@ backgroundColorHint:(NSColor *)bg */ - (NSPoint) hotSpot; - (NSImage*) image; -// This methods are defined in OpenStep, but not in MacOSX +#ifndef STRICT_MACOS_X - (void) setHotSpot: (NSPoint)spot; - (void) setImage: (NSImage *)newImage; +#endif /* * Setting the Cursor @@ -97,12 +98,37 @@ backgroundColorHint:(NSColor *)bg + (NSCursor*) greenArrowCursor; #endif +#ifndef STRICT_OPENSTEP ++ (NSCursor*) closedHandCursor; ++ (NSCursor*) crosshairCursor; ++ (NSCursor*) disappearingItemCursor; ++ (NSCursor*) openHandCursor; ++ (NSCursor*) pointingHandCursor; ++ (NSCursor*) resizeDownCursor; ++ (NSCursor*) resizeLeftCursor; ++ (NSCursor*) resizeLeftRightCursor; ++ (NSCursor*) resizeRightCursor; ++ (NSCursor*) resizeUpCursor; ++ (NSCursor*) resizeUpDownCursor; +#endif + @end /* Cursor types */ typedef enum { GSArrowCursor, - GSIBeamCursor + GSIBeamCursor, + GSClosedHandCursor, + GSCrosshairCursor, + GSDisappearingItemCursor, + GSOpenHandCursor, + GSPointingHandCursor, + GSResizeDownCursor, + GSResizeLeftCursor, + GSResizeLeftRightCursor, + GSResizeRightCursor, + GSResizeUpCursor, + GSResizeUpDownCursor, } GSCursorTypes; #endif /* _GNUstep_H_NSCursor */ diff --git a/Source/NSApplication.m b/Source/NSApplication.m index 8fe341bd5..feadbb647 100644 --- a/Source/NSApplication.m +++ b/Source/NSApplication.m @@ -1579,7 +1579,7 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException)); || (type == NSRightMouseDown) || (type == NSRightMouseUp) || (type == NSMouseMoved)) { - [NSCursor unhide]; + [NSCursor setHiddenUntilMouseMoves: NO]; } } } diff --git a/Source/NSCursor.m b/Source/NSCursor.m index f097b88fa..a6e1b3dfb 100644 --- a/Source/NSCursor.m +++ b/Source/NSCursor.m @@ -62,7 +62,7 @@ static NSMutableDictionary *cursorDict = nil; // Initialize class variables NSCursor_class = self; gnustep_gui_cursor_stack = [[NSMutableArray alloc] initWithCapacity: 2]; - gnustep_gui_hidden_until_move = YES; + gnustep_gui_hidden_until_move = NO; cursorDict = [NSMutableDictionary new]; [[self arrowCursor] push]; } @@ -89,8 +89,21 @@ static NSMutableDictionary *cursorDict = nil; return; } +/* + We should rather convert the image to a bitmap representation here via + the following code, but this is currently not supported by the libart backend + +{ + NSSize size = [_cursor_image size]; + + [_cursor_image lockFocus]; + rep = [[NSBitmapImageRep alloc] initWithFocusedViewRect: + NSMakeRect(0, 0, size.width, size.height)]; + AUTORELEASE(rep); + [_cursor_image unlockFocus]; +} + */ rep = (NSBitmapImageRep *)[_cursor_image bestRepresentationForDevice: nil]; - /* FIXME: Handle cached image reps also */ if (!rep || ![rep respondsToSelector: @selector(samplesPerPixel)]) { NSLog(@"NSCursor can only handle NSBitmapImageReps for now"); @@ -133,6 +146,14 @@ static NSMutableDictionary *cursorDict = nil; + (void) setHiddenUntilMouseMoves: (BOOL)flag { + if (flag) + { + [self hide]; + } + else + { + [self unhide]; + } gnustep_gui_hidden_until_move = flag; } @@ -149,16 +170,17 @@ static NSMutableDictionary *cursorDict = nil; /* * Getting the Cursor */ -+ (NSCursor*) arrowCursor +inline +NSCursor* _getStandardCursor(NSString *name, int style) { - NSString *name = @"GSArrowCursor"; NSCursor *cursor = [cursorDict objectForKey: name]; + if (cursor == nil) { void *c; cursor = [[NSCursor_class alloc] initWithImage: nil]; - [GSCurrentServer() standardcursor: GSArrowCursor : &c]; + [GSCurrentServer() standardcursor: style : &c]; [cursor _setCid: c]; [cursorDict setObject: cursor forKey: name]; RELEASE(cursor); @@ -166,28 +188,76 @@ static NSMutableDictionary *cursorDict = nil; return cursor; } ++ (NSCursor*) arrowCursor +{ + return _getStandardCursor(@"GSArrowCursor", GSArrowCursor); +} + ++ (NSCursor*) IBeamCursor +{ + return _getStandardCursor(@"GSIBeamCursor", GSIBeamCursor); +} + ++ (NSCursor*) closedHandCursor +{ + return _getStandardCursor(@"GSClosedHandCursor", GSClosedHandCursor); +} + ++ (NSCursor*) crosshairCursor +{ + return _getStandardCursor(@"GSCrosshairCursor", GSCrosshairCursor); +} + ++ (NSCursor*) disappearingItemCursor +{ + return _getStandardCursor(@"GSDisappearingItemCursor", GSDisappearingItemCursor); +} + ++ (NSCursor*) openHandCursor +{ + return _getStandardCursor(@"GSOpenHandCursor", GSOpenHandCursor); +} + ++ (NSCursor*) pointingHandCursor +{ + return _getStandardCursor(@"GSPointingHandCursor", GSPointingHandCursor); +} + ++ (NSCursor*) resizeDownCursor +{ + return _getStandardCursor(@"GSResizeDownCursor", GSResizeDownCursor); +} + ++ (NSCursor*) resizeLeftCursor +{ + return _getStandardCursor(@"GSResizeLeftCursor", GSResizeLeftCursor); +} + ++ (NSCursor*) resizeLeftRightCursor +{ + return _getStandardCursor(@"GSResizeLeftRightCursor", GSResizeLeftRightCursor); +} + ++ (NSCursor*) resizeRightCursor +{ + return _getStandardCursor(@"GSResizeRightCursor", GSResizeRightCursor); +} + ++ (NSCursor*) resizeUpCursor +{ + return _getStandardCursor(@"GSResizeUpCursor", GSResizeUpCursor); +} + ++ (NSCursor*) resizeUpDownCursor +{ + return _getStandardCursor(@"GSResizeUpDownCursor", GSResizeUpDownCursor); +} + + (NSCursor*) currentCursor { return gnustep_gui_current_cursor; } -+ (NSCursor*) IBeamCursor -{ - NSString *name = @"GSIBeamCursor"; - NSCursor *cursor = [cursorDict objectForKey: name]; - if (cursor == nil) - { - void *c; - - cursor = [[NSCursor_class alloc] initWithImage: nil]; - [GSCurrentServer() standardcursor: GSIBeamCursor : &c]; - [cursor _setCid: c]; - [cursorDict setObject: cursor forKey: name]; - RELEASE(cursor); - } - return cursor; -} - + (NSCursor*) greenArrowCursor { NSString *name = @"GSGreenArrowCursor"; @@ -259,13 +329,13 @@ backgroundColorHint:(NSColor *)bg */ - (NSPoint) hotSpot { - // FIXME: This wont work for the two standard cursor + // FIXME: This wont work for the standard cursor return _hot_spot; } - (NSImage*) image { - // FIXME: This wont work for the two standard cursor + // FIXME: This wont work for the standard cursor return _cursor_image; }