2001-12-17 16:51:51 +00:00
/ * * < title > NSCursor < / title >
1996-05-30 20:03:15 +00:00
2001-12-17 16:51:51 +00:00
< abstract > Holds an image to use as a cursor < / abstract >
1996-05-30 20:03:15 +00:00
2001-12-17 16:51:51 +00:00
Copyright ( C ) 1996 , 1999 , 2001 Free Software Foundation , Inc .
1996-05-30 20:03:15 +00:00
2001-12-17 16:51:51 +00:00
Author : Scott Christley < scottc @ net - community . com >
1996-05-30 20:03:15 +00:00
Date : 1996
2001-12-17 16:51:51 +00:00
Author : Adam Fedor < fedor @ gnu . org >
Date : Dec 2001
1996-05-30 20:03:15 +00:00
This file is part of the GNUstep GUI Library .
This library is free software ; you can redistribute it and / or
2007-10-29 21:16:17 +00:00
modify it under the terms of the GNU Lesser General Public
1996-05-30 20:03:15 +00:00
License as published by the Free Software Foundation ; either
2008-06-10 04:01:49 +00:00
version 2 of the License , or ( at your option ) any later version .
2007-10-29 21:16:17 +00:00
1996-05-30 20:03:15 +00:00
This library is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
2007-10-29 21:16:17 +00:00
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the GNU
Lesser General Public License for more details .
1996-05-30 20:03:15 +00:00
2007-10-29 21:16:17 +00:00
You should have received a copy of the GNU Lesser General Public
1996-10-18 17:14:13 +00:00
License along with this library ; see the file COPYING . LIB .
2007-10-29 21:16:17 +00:00
If not , see < http : // www . gnu . org / licenses / > or write to the
Free Software Foundation , 51 Franklin Street , Fifth Floor ,
Boston , MA 02110 -1301 , USA .
1996-05-30 20:03:15 +00:00
* /
2011-03-04 11:33:22 +00:00
# import < Foundation / NSArray . h >
# import < Foundation / NSDebug . h >
# import < Foundation / NSDictionary . h >
# import < Foundation / NSKeyedArchiver . h >
# import "AppKit/NSColor.h"
# import "AppKit/NSCursor.h"
# import "AppKit/NSGraphics.h"
# import "AppKit/NSImage.h"
# import "AppKit/NSBitmapImageRep.h"
# import "GNUstepGUI/GSDisplayServer.h"
1997-02-12 22:21:43 +00:00
2016-12-22 20:56:31 +00:00
@ interface NSImage ( Private )
+ ( NSDictionary * ) _XcodeImageMappings ;
+ ( NSArray * ) _XcodeImagePaths ;
@ end
1997-02-12 22:21:43 +00:00
// Class variables
1997-02-18 18:45:16 +00:00
static NSMutableArray * gnustep_gui _cursor _stack ;
1997-02-12 22:21:43 +00:00
static NSCursor * gnustep_gui _current _cursor ;
static BOOL gnustep_gui _hidden _until _move ;
2001-07-23 22:58:54 +00:00
static Class NSCursor_class ;
1996-05-30 20:03:15 +00:00
2001-12-13 04:13:42 +00:00
static NSMutableDictionary * cursorDict = nil ;
2001-12-03 21:17:12 +00:00
1996-05-30 20:03:15 +00:00
@ implementation NSCursor
1999-11-15 16:00:47 +00:00
/ *
* Class methods
* /
+ ( void ) initialize
1996-05-30 20:03:15 +00:00
{
if ( self = = [ NSCursor class ] )
{
// Initial version
2011-03-12 19:01:54 +00:00
[ self setVersion : 1 ] ;
1997-02-12 22:21:43 +00:00
// Initialize class variables
2001-07-23 22:58:54 +00:00
NSCursor_class = self ;
2012-10-19 22:51:20 +00:00
gnustep_gui _cursor _stack = [ [ NSMutableArray alloc ] initWithCapacity : 1 ] ;
2004-06-28 12:21:36 +00:00
gnustep_gui _hidden _until _move = NO ;
2003-07-22 15:23:12 +00:00
cursorDict = [ NSMutableDictionary new ] ;
2012-10-19 22:51:20 +00:00
[ [ self arrowCursor ] set ] ;
1996-05-30 20:03:15 +00:00
}
}
2015-06-26 19:19:59 +00:00
# ifdef WIN32
+ ( NSUInteger ) count
{
return [ gnustep_gui _cursor _stack count ] ;
}
# endif
// Testplant - MAL -2015 -06 -26 : Keeping testplant fixes . . .
2013-10-03 20:20:25 +00:00
+ ( NSMutableArray * ) stack
{
2013-10-21 17:59:13 +00:00
return gnustep_gui _cursor _stack ;
}
2015-06-26 19:19:59 +00:00
// Testplant - MAL -2015 -06 -26 : Keeping testplant fixes . . .
2013-10-21 17:59:13 +00:00
+ ( void ) resetStack
{
[ gnustep_gui _cursor _stack removeAllObjects ] ;
2013-10-03 20:20:25 +00:00
}
1999-11-15 16:00:47 +00:00
- ( void * ) _cid
1999-10-29 18:43:48 +00:00
{
2001-07-23 22:58:54 +00:00
return _cid ;
1999-10-29 18:43:48 +00:00
}
2001-05-04 03:19:32 +00:00
- ( void ) _setCid : ( void * ) val
1999-10-29 18:43:48 +00:00
{
2001-07-23 22:58:54 +00:00
_cid = val ;
}
- ( void ) _computeCid
{
void * c ;
if ( _cursor _image = = nil )
{
_cid = NULL ;
return ;
}
2011-03-07 19:45:04 +00:00
[ GSCurrentServer ( ) imagecursor : _hot _spot : _cursor _image : & c ] ;
2001-07-23 22:58:54 +00:00
_cid = c ;
1999-10-29 18:43:48 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Hides the current cursor . < / p >
1999-11-15 16:00:47 +00:00
* /
+ ( void ) hide
1997-02-12 22:21:43 +00:00
{
2002-03-28 03:53:18 +00:00
[ GSCurrentServer ( ) hidecursor ] ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Pops the cursor off the top of the stack and makes the previous one
as the current cursor . < / p >
* /
1999-11-15 16:00:47 +00:00
+ ( void ) pop
1997-02-12 22:21:43 +00:00
{
1999-11-15 16:00:47 +00:00
/ *
* The object we pop is the current cursor
* /
2012-10-19 22:51:20 +00:00
if ( [ gnustep_gui _cursor _stack count ] > 0 )
1999-11-15 16:00:47 +00:00
{
2012-10-19 22:51:20 +00:00
NSCursor * c = RETAIN ( [ gnustep_gui _cursor _stack lastObject ] ) ;
1999-11-15 16:00:47 +00:00
[ gnustep_gui _cursor _stack removeLastObject ] ;
2002-01-15 16:43:13 +00:00
NSDebugLLog ( @ "NSCursor" , @ "Cursor pop" ) ;
2012-10-19 22:51:20 +00:00
[ c set ] ;
RELEASE ( c ) ;
1999-11-15 16:00:47 +00:00
}
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Hides the cursor if < var > flag < / var > is YES . Unhides it if NO < / p >
* /
1999-11-15 16:00:47 +00:00
+ ( void ) setHiddenUntilMouseMoves : ( BOOL ) flag
1997-02-12 22:21:43 +00:00
{
2004-06-28 12:21:36 +00:00
if ( flag )
{
[ self hide ] ;
}
else
{
[ self unhide ] ;
}
1997-02-12 22:21:43 +00:00
gnustep_gui _hidden _until _move = flag ;
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns whther the cursor is hidden until mouse moves < / p >
* /
1999-11-15 16:00:47 +00:00
+ ( BOOL ) isHiddenUntilMouseMoves
1997-02-12 22:21:43 +00:00
{
return gnustep_gui _hidden _until _move ;
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Shows the NSCursor . < / p >
< p > See Also : + hide < / p >
* /
1999-11-15 16:00:47 +00:00
+ ( void ) unhide
1997-02-12 22:21:43 +00:00
{
2002-03-28 03:53:18 +00:00
[ GSCurrentServer ( ) showcursor ] ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
1999-11-15 16:00:47 +00:00
/ *
* Getting the Cursor
* /
2004-09-21 22:00:26 +00:00
static
NSCursor * getStandardCursor ( NSString * name , int style )
1996-05-30 20:03:15 +00:00
{
2001-12-13 04:13:42 +00:00
NSCursor * cursor = [ cursorDict objectForKey : name ] ;
2004-06-28 12:21:36 +00:00
2001-12-13 04:13:42 +00:00
if ( cursor = = nil )
2001-12-03 21:17:12 +00:00
{
2004-12-08 23:53:32 +00:00
void * c = NULL ;
2001-07-23 22:58:54 +00:00
2011-03-12 19:01:54 +00:00
cursor = [ [ NSCursor_class alloc ] initWithImage : nil
hotSpot : NSZeroPoint ] ;
if ( nil ! = cursor )
2004-12-08 23:53:32 +00:00
{
2011-03-12 19:01:54 +00:00
[ GSCurrentServer ( ) standardcursor : style : & c ] ;
if ( c = = NULL )
{
/ *
There is no standard cursor with this name defined in the
backend , so try an image with this name .
* /
[ cursor setImage : [ NSImage imageNamed : name ] ] ;
}
else
{
[ cursor _setCid : c ] ;
}
cursor -> _cursor _flags . type = style ;
[ cursorDict setObject : cursor forKey : name ] ;
RELEASE ( cursor ) ;
}
2001-12-03 21:17:12 +00:00
}
2001-12-13 04:13:42 +00:00
return cursor ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns an arrow cursor . < / p >
* /
2004-06-28 12:21:36 +00:00
+ ( NSCursor * ) arrowCursor
1996-05-30 20:03:15 +00:00
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSArrowCursor" , GSArrowCursor ) ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns an I - beam cursor . < / p >
* /
1999-11-15 16:00:47 +00:00
+ ( NSCursor * ) IBeamCursor
1996-05-30 20:03:15 +00:00
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSIBeamCursor" , GSIBeamCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) closedHandCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSClosedHandCursor" , GSClosedHandCursor ) ;
2004-06-28 12:21:36 +00:00
}
2011-03-12 19:01:54 +00:00
+ ( NSCursor * ) contextualMenuCursor
{
return getStandardCursor ( @ "GSContextualMenuCursor" , GSContextualMenuCursor ) ;
}
2004-06-28 12:21:36 +00:00
+ ( NSCursor * ) crosshairCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSCrosshairCursor" , GSCrosshairCursor ) ;
2004-06-28 12:21:36 +00:00
}
2011-03-12 19:01:54 +00:00
+ ( NSCursor * ) dragCopyCursor
{
return getStandardCursor ( @ "GSDragCopyCursor" , GSDragCopyCursor ) ;
}
+ ( NSCursor * ) dragLinkCursor
{
return getStandardCursor ( @ "GSDragLinkCursor" , GSDragLinkCursor ) ;
}
2004-06-28 12:21:36 +00:00
+ ( NSCursor * ) disappearingItemCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSDisappearingItemCursor" , GSDisappearingItemCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) openHandCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSOpenHandCursor" , GSOpenHandCursor ) ;
2004-06-28 12:21:36 +00:00
}
2011-03-12 19:01:54 +00:00
+ ( NSCursor * ) operationNotAllowedCursor
{
return getStandardCursor ( @ "GSOperationNotAllowedCursor" ,
GSOperationNotAllowedCursor ) ;
}
2004-06-28 12:21:36 +00:00
+ ( NSCursor * ) pointingHandCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSPointingHandCursor" , GSPointingHandCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeDownCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeDownCursor" , GSResizeDownCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeLeftCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeLeftCursor" , GSResizeLeftCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeLeftRightCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeLeftRightCursor" , GSResizeLeftRightCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeRightCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeRightCursor" , GSResizeRightCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeUpCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeUpCursor" , GSResizeUpCursor ) ;
2004-06-28 12:21:36 +00:00
}
+ ( NSCursor * ) resizeUpDownCursor
{
2004-09-21 22:00:26 +00:00
return getStandardCursor ( @ "GSResizeUpDownCursor" , GSResizeUpDownCursor ) ;
2004-06-28 12:21:36 +00:00
}
2015-06-26 19:19:59 +00:00
// Testplant - MAL -2015 -06 -26 : Keeping testplant fixes . . .
2013-08-23 16:09:17 +00:00
+ ( NSCursor * ) resizeNWSECursor
{
return getStandardCursor ( @ "GSResizeNWSECursor" , GSResizeNWSECursor ) ;
}
2013-08-23 16:31:38 +00:00
+ ( NSCursor * ) resizeNESWCursor
2013-08-23 16:09:17 +00:00
{
return getStandardCursor ( @ "GSResizeNESWCursor" , GSResizeNESWCursor ) ;
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns the current cursor . < / p >
* /
2004-06-28 12:21:36 +00:00
+ ( NSCursor * ) currentCursor
{
return gnustep_gui _current _cursor ;
2001-12-13 04:13:42 +00:00
}
2011-03-12 19:01:54 +00:00
+ ( NSCursor * ) currentSystemCursor
{
// FIXME
return nil ;
}
2001-12-13 04:13:42 +00:00
+ ( NSCursor * ) greenArrowCursor
{
NSString * name = @ "GSGreenArrowCursor" ;
NSCursor * cursor = [ cursorDict objectForKey : name ] ;
if ( cursor = = nil )
{
void * c ;
2011-03-12 19:01:54 +00:00
cursor = [ [ NSCursor_class alloc ] initWithImage : nil
hotSpot : NSZeroPoint ] ;
2002-03-28 03:53:18 +00:00
[ GSCurrentServer ( ) standardcursor : GSArrowCursor : & c ] ;
2011-02-15 22:54:23 +00:00
[ GSCurrentServer ( ) recolorcursor : [ NSColor greenColor ]
: [ NSColor blackColor ] : c ] ;
2001-12-13 04:13:42 +00:00
[ cursor _setCid : c ] ;
[ cursorDict setObject : cursor forKey : name ] ;
RELEASE ( cursor ) ;
}
return cursor ;
1996-05-30 20:03:15 +00:00
}
1999-11-15 16:00:47 +00:00
/ *
* Initializing a New NSCursor Object
* /
- ( id ) init
1997-02-12 22:21:43 +00:00
{
2011-03-12 19:01:54 +00:00
return [ self initWithImage : nil hotSpot : NSZeroPoint ] ;
1997-02-12 22:21:43 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Initializes and returns a new NSCursor with a NSImage < var > newImage < / var >
2007-11-29 11:34:41 +00:00
and a hot spot point with x = 0 and y = 0 ( top left corner ) . < / p >
2005-12-05 10:04:53 +00:00
< p > See Also : - initWithImage : hotSpot : < / p >
* /
1999-11-15 16:00:47 +00:00
- ( id ) initWithImage : ( NSImage * ) newImage
1996-05-30 20:03:15 +00:00
{
1999-11-15 16:00:47 +00:00
return [ self initWithImage : newImage
2007-11-29 11:34:41 +00:00
hotSpot : NSZeroPoint ] ;
1999-11-15 16:00:47 +00:00
}
1997-02-12 22:21:43 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Initializes and returns a new NSCursor with a NSImage < var > newImage < / var >
and the hot spot to < var > hotSpot < / var > . < / p >
2007-11-29 11:34:41 +00:00
< p > NB . The coordinate system of an NSCursor is flipped , so a hotSpot at
0 , 0 is in the top left corner of the cursor . < / p >
2005-12-05 10:04:53 +00:00
< p > See Also : - initWithImage : - setImage : < / p >
* /
2001-12-17 16:51:51 +00:00
- ( id ) initWithImage : ( NSImage * ) newImage hotSpot : ( NSPoint ) hotSpot
1999-11-15 16:00:47 +00:00
{
2011-03-12 19:01:54 +00:00
// _cursor _flags . is_set _on _mouse _entered = NO ;
// _cursor _flags . is_set _on _mouse _exited = NO ;
2001-12-17 16:51:51 +00:00
_hot _spot = hotSpot ;
2001-07-23 22:58:54 +00:00
[ self setImage : newImage ] ;
1997-02-12 22:21:43 +00:00
return self ;
1996-05-30 20:03:15 +00:00
}
2001-07-23 22:58:54 +00:00
- ( id ) initWithImage : ( NSImage * ) newImage
foregroundColorHint : ( NSColor * ) fg
backgroundColorHint : ( NSColor * ) bg
hotSpot : ( NSPoint ) hotSpot
{
2011-02-14 18:38:11 +00:00
self = [ self initWithImage : newImage hotSpot : hotSpot ] ;
if ( self = = nil )
return nil ;
2001-12-13 04:13:42 +00:00
if ( fg || bg )
{
if ( bg = = nil )
bg = [ NSColor whiteColor ] ;
if ( fg = = nil )
fg = [ NSColor blackColor ] ;
bg = [ bg colorUsingColorSpaceName : NSDeviceRGBColorSpace ] ;
fg = [ fg colorUsingColorSpaceName : NSDeviceRGBColorSpace ] ;
2011-02-15 22:54:23 +00:00
[ GSCurrentServer ( ) recolorcursor : fg : bg : _cid ] ;
2001-12-13 04:13:42 +00:00
}
2011-02-14 18:38:11 +00:00
return self ;
2001-07-23 22:58:54 +00:00
}
2011-03-12 19:01:54 +00:00
2006-10-02 08:42:04 +00:00
- ( void ) dealloc
2003-07-22 15:23:12 +00:00
{
2011-03-12 19:01:54 +00:00
RELEASE ( _cursor _image ) ;
2011-02-15 22:54:23 +00:00
if ( _cid )
{
[ GSCurrentServer ( ) freecursor : _cid ] ;
}
2003-07-22 15:23:12 +00:00
[ super dealloc ] ;
}
2005-12-05 10:04:53 +00:00
2007-11-29 11:34:41 +00:00
/ * * < p > Returns the hot spot point of the NSCursor . This is in the
* cursor ' s coordinate system which is a flipped on ( origin at the
* top left of the cursor ) . < / p >
1999-11-15 16:00:47 +00:00
* /
- ( NSPoint ) hotSpot
1996-05-30 20:03:15 +00:00
{
2004-06-28 12:21:36 +00:00
// FIXME : This wont work for the standard cursor
2001-07-23 22:58:54 +00:00
return _hot _spot ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns the image of the NSCursor < / p >
* /
1999-11-15 16:00:47 +00:00
- ( NSImage * ) image
1996-05-30 20:03:15 +00:00
{
2004-06-28 12:21:36 +00:00
// FIXME : This wont work for the standard cursor
2001-07-23 22:58:54 +00:00
return _cursor _image ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Sets the hot spot point of the NSCursor to < var > spot < / var > < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) setHotSpot : ( NSPoint ) spot
1997-02-12 22:21:43 +00:00
{
2001-07-23 22:58:54 +00:00
_hot _spot = spot ;
[ self _computeCid ] ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Sets < var > newImage < / var > the image of the NSCursor < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) setImage : ( NSImage * ) newImage
1997-02-12 22:21:43 +00:00
{
2001-07-23 22:58:54 +00:00
ASSIGN ( _cursor _image , newImage ) ;
[ self _computeCid ] ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Returns whether if the cursor is set on - mouseEntered : .
< / p > < p > See Also : - setOnMouseEntered : - mouseEntered : - set
- isSetOnMouseExited < / p >
1999-11-15 16:00:47 +00:00
* /
- ( BOOL ) isSetOnMouseEntered
1996-05-30 20:03:15 +00:00
{
2011-03-12 19:01:54 +00:00
return _cursor _flags . is_set _on _mouse _entered ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Returns whether if the cursor is push on - mouseExited : .
< / p > < p > See Also : - setOnMouseEntered : - mouseExited : - set
- isSetOnMouseEntered < / p >
* /
1999-11-15 16:00:47 +00:00
- ( BOOL ) isSetOnMouseExited
1996-05-30 20:03:15 +00:00
{
2011-03-12 19:01:54 +00:00
return _cursor _flags . is_set _on _mouse _exited ;
1996-05-30 20:03:15 +00:00
}
2005-12-05 10:04:53 +00:00
/ * * < p > Sets the cursor if - isSetOnMouseEntered is YES or pushs the cursor
if - isSetOnMouseExited is NO < / p >
< p > See Also : - isSetOnMouseEntered - isSetOnMouseExited < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) mouseEntered : ( NSEvent * ) theEvent
1997-02-12 22:21:43 +00:00
{
2015-06-26 19:19:59 +00:00
NSDebugLLog ( @ "NSCursor" , @ "Cursor mouseEntered:enter %d exit %d" ,
_cursor _flags . is_set _on _mouse _entered , _cursor _flags . is_set _on _mouse _exited ) ;
2011-03-12 19:01:54 +00:00
if ( _cursor _flags . is_set _on _mouse _entered = = YES )
1999-11-15 16:00:47 +00:00
{
[ self set ] ;
}
2011-03-12 19:01:54 +00:00
else if ( _cursor _flags . is_set _on _mouse _exited = = NO )
1999-11-15 16:00:47 +00:00
{
/ *
* Undocumented behavior - if a cursor is not set on exit or entry ,
* we assume a push - pop situation instead .
* /
[ self push ] ;
}
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Sets the cursor if - isSetOnMouseExited is YES or pops the cursor
if - isSetOnMouseEntered is NO < / p >
< p > See Also : - isSetOnMouseExited - isSetOnMouseEntered < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) mouseExited : ( NSEvent * ) theEvent
1997-02-12 22:21:43 +00:00
{
2015-06-26 19:19:59 +00:00
NSDebugLLog ( @ "NSCursor" , @ "Cursor mouseExited: enter %d exit %d" ,
_cursor _flags . is_set _on _mouse _entered , _cursor _flags . is_set _on _mouse _exited ) ;
2011-03-12 19:01:54 +00:00
if ( _cursor _flags . is_set _on _mouse _exited = = YES )
1999-11-15 16:00:47 +00:00
{
[ self set ] ;
}
2011-03-12 19:01:54 +00:00
else if ( _cursor _flags . is_set _on _mouse _entered = = NO )
1999-11-15 16:00:47 +00:00
{
/ *
* Undocumented behavior - if a cursor is not set on exit or entry ,
* we assume a push - pop situation instead .
* /
[ self pop ] ;
}
2006-05-27 21:54:29 +00:00
else
{
/ *
* The cursor was set on entry , we reset it to the default cursor on exit .
* Using push and pop all the time would seem to be a clearer way .
* /
[ [ NSCursor arrowCursor ] set ] ;
}
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Pops the cursor off the top of the stack and makes the previous
the current cursor . < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) pop
1997-02-12 22:21:43 +00:00
{
2001-07-23 22:58:54 +00:00
[ NSCursor_class pop ] ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Adds the NSCursor into the cursor stack and makes it the current
cursor . < / p > < p > See Also : - pop - set < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) push
1997-02-12 22:21:43 +00:00
{
2012-10-19 22:51:20 +00:00
[ gnustep_gui _cursor _stack addObject : gnustep_gui _current _cursor ] ;
2001-07-23 22:58:54 +00:00
[ self set ] ;
2002-01-15 16:43:13 +00:00
NSDebugLLog ( @ "NSCursor" , @ "Cursor push %p" , _cid ) ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Sets the NSCursor as the current cursor . < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) set
1997-02-12 22:21:43 +00:00
{
2012-10-19 22:51:20 +00:00
ASSIGN ( gnustep_gui _current _cursor , self ) ;
2001-07-23 22:58:54 +00:00
if ( _cid )
1999-11-15 16:00:47 +00:00
{
2011-02-15 22:54:23 +00:00
[ GSCurrentServer ( ) setcursor : _cid ] ;
1999-11-15 16:00:47 +00:00
}
2012-10-19 22:51:20 +00:00
else
{
/ *
* No image ? This is odd , so we set an standard
* cursor image ( GSArrowCursor ) .
* /
void * c = NULL ;
[ GSCurrentServer ( ) standardcursor : GSArrowCursor : & c ] ;
if ( c ! = NULL )
{
[ self _setCid : c ] ;
[ GSCurrentServer ( ) setcursor : _cid ] ;
}
}
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Sets whether if the cursor is set on - mouseEntered : .
< / p > < p > See Also : - isSetOnMouseEntered - mouseEntered : - set < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) setOnMouseEntered : ( BOOL ) flag
1997-02-12 22:21:43 +00:00
{
2011-03-12 19:01:54 +00:00
_cursor _flags . is_set _on _mouse _entered = flag ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
2005-12-05 10:04:53 +00:00
/ * * < p > Sets whether if the cursor is push on - mouseExited : .
< / p > < p > See Also : - isSetOnMouseExited - mouseExited : - set < / p >
* /
1999-11-15 16:00:47 +00:00
- ( void ) setOnMouseExited : ( BOOL ) flag
1997-02-12 22:21:43 +00:00
{
2011-03-12 19:01:54 +00:00
_cursor _flags . is_set _on _mouse _exited = flag ;
1997-02-12 22:21:43 +00:00
}
1996-05-30 20:03:15 +00:00
1999-11-15 16:00:47 +00:00
/ *
* NSCoding protocol
* /
1999-03-02 08:58:30 +00:00
- ( void ) encodeWithCoder : ( NSCoder * ) aCoder
1996-05-30 20:03:15 +00:00
{
2011-03-12 19:01:54 +00:00
if ( [ aCoder allowsKeyedCoding ] )
{
if ( nil ! = _cursor _image )
{
[ aCoder encodeObject : _cursor _image forKey : @ "NSImage" ] ;
}
else
{
int type = _cursor _flags . type ;
[ aCoder encodeInt : type forKey : @ "NSCursorType" ] ;
}
[ aCoder encodePoint : _hot _spot forKey : @ "NSHotSpot" ] ;
}
else
{
BOOL flag ;
// FIXME : This wont work for the standard cursor
flag = _cursor _flags . is_set _on _mouse _entered ;
[ aCoder encodeValueOfObjCType : @ encode ( BOOL ) at : & flag ] ;
flag = _cursor _flags . is_set _on _mouse _exited ;
[ aCoder encodeValueOfObjCType : @ encode ( BOOL ) at : & flag ] ;
[ aCoder encodeObject : _cursor _image ] ;
[ aCoder encodePoint : _hot _spot ] ;
}
1996-05-30 20:03:15 +00:00
}
1999-03-02 08:58:30 +00:00
- ( id ) initWithCoder : ( NSCoder * ) aDecoder
1996-05-30 20:03:15 +00:00
{
2004-01-30 19:49:00 +00:00
if ( [ aDecoder allowsKeyedCoding ] )
{
DESTROY ( self ) ;
2011-03-12 19:01:54 +00:00
if ( [ aDecoder containsValueForKey : @ "NSCursorType" ] )
2004-02-24 19:31:33 +00:00
{
2016-12-22 20:56:31 +00:00
int type = [ aDecoder decodeIntForKey : @ "NSCursorType" ] ;
2011-03-12 19:01:54 +00:00
switch ( type )
{
case 0 :
self = [ NSCursor arrowCursor ] ;
break ;
case 1 :
self = [ NSCursor IBeamCursor ] ;
break ;
case 2 :
self = [ NSCursor dragLinkCursor ] ;
break ;
case 3 :
self = [ NSCursor operationNotAllowedCursor ] ;
break ;
case 5 :
self = [ NSCursor dragCopyCursor ] ;
break ;
case 11 :
self = [ NSCursor closedHandCursor ] ;
break ;
case 12 :
self = [ NSCursor openHandCursor ] ;
break ;
case 13 :
self = [ NSCursor pointingHandCursor ] ;
break ;
case 17 :
self = [ NSCursor resizeLeftCursor ] ;
break ;
case 18 :
self = [ NSCursor resizeRightCursor ] ;
break ;
case 19 :
self = [ NSCursor resizeLeftRightCursor ] ;
break ;
case 20 :
self = [ NSCursor crosshairCursor ] ;
break ;
case 21 :
self = [ NSCursor resizeUpCursor ] ;
break ;
case 22 :
self = [ NSCursor resizeDownCursor ] ;
break ;
case 24 :
self = [ NSCursor contextualMenuCursor ] ;
break ;
case 25 :
self = [ NSCursor disappearingItemCursor ] ;
break ;
default :
// FIXME
self = [ NSCursor arrowCursor ] ;
break ;
}
RETAIN ( self ) ;
2016-12-22 20:56:31 +00:00
}
2011-03-12 19:01:54 +00:00
else
2004-01-30 19:49:00 +00:00
{
2011-03-12 19:01:54 +00:00
NSPoint hotSpot = NSMakePoint ( 0 , 0 ) ;
NSImage * image = nil ;
if ( [ aDecoder containsValueForKey : @ "NSHotSpot" ] )
{
hotSpot = [ aDecoder decodePointForKey : @ "NSHotSpot" ] ;
}
if ( [ aDecoder containsValueForKey : @ "NSImage" ] )
{
image = [ aDecoder decodeObjectForKey : @ "NSImage" ] ;
}
2015-06-26 19:19:59 +00:00
// Testplant - MAL -2015 -06 -26 : Keeping testplant fixes . . .
2016-12-22 20:56:31 +00:00
if ( [ [ NSImage _XcodeImagePaths ] containsObject : [ image name ] ] )
{
NSString * selectorName = [ [ NSImage _XcodeImageMappings ] objectForKey : [ image name ] ] ;
SEL selector = NSSelectorFromString ( selectorName ) ;
if ( selector = = NULL )
{
NSDebugLog ( @ "An NSCursor object was encoded with the image %@ which was not automatically substituted with NSCursor substitute due to missing selector: %@." , [ image name ] , selectorName ) ;
}
else
{
NSDebugLog ( @ "An NSCursor object was encoded with the image %@. This cursor was automatically substituted with NSCursor substitute (%@)." , [ image name ] , selectorName ) ;
self = RETAIN ( [ NSCursor performSelector : selector ] ) ;
[ image setName : nil ] ;
}
}
else if ( image = = nil )
{
NSLog ( @ "%s:NSCursor object was encoded with image which was not found" , __PRETTY _FUNCTION __ ) ;
}
else
{
self = [ [ NSCursor alloc ] initWithImage : image hotSpot : hotSpot ] ;
}
2011-03-12 19:01:54 +00:00
}
2004-01-30 19:49:00 +00:00
}
else
{
2011-03-12 19:01:54 +00:00
BOOL flag ;
2006-10-02 08:42:04 +00:00
[ aDecoder decodeValueOfObjCType : @ encode ( BOOL )
2011-03-12 19:01:54 +00:00
at : & flag ] ;
_cursor _flags . is_set _on _mouse _entered = flag ;
2006-10-02 08:42:04 +00:00
[ aDecoder decodeValueOfObjCType : @ encode ( BOOL )
2011-03-12 19:01:54 +00:00
at : & flag ] ;
_cursor _flags . is_set _on _mouse _exited = flag ;
2004-01-30 19:49:00 +00:00
_cursor _image = [ aDecoder decodeObject ] ;
_hot _spot = [ aDecoder decodePoint ] ;
[ self _computeCid ] ;
}
1996-05-30 20:03:15 +00:00
return self ;
}
@ end