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
This commit is contained in:
Fred Kiefer 2004-06-28 12:21:36 +00:00
parent 533700c724
commit d6f5403307
4 changed files with 134 additions and 27 deletions

View file

@ -1,3 +1,14 @@
2004-06-28 Fred Kiefer <FredKiefer@gmx.de>
* 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 <alexander@malmberg.org>
* Source/GSNibTemplates.m: Replace calls to

View file

@ -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 */

View file

@ -1579,7 +1579,7 @@ IF_NO_GC(NSAssert([event retainCount] > 0, NSInternalInconsistencyException));
|| (type == NSRightMouseDown) || (type == NSRightMouseUp)
|| (type == NSMouseMoved))
{
[NSCursor unhide];
[NSCursor setHiddenUntilMouseMoves: NO];
}
}
}

View file

@ -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;
}