Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Attributes | Private Attributes
nsThemeCursor Class Reference

Implementation of nsMacCursor that uses Carbon Appearance Manager cursors. More...

Inheritance diagram for nsThemeCursor:
Inheritance graph
[legend]
Collaboration diagram for nsThemeCursor:
Collaboration graph
[legend]

List of all members.

Public Member Functions

(id- initWithThemeCursor:
 initWithThemeCursor: Create a cursor by specifying a Carbon Apperance Manager ThemeCursor constant.
(void- setFrame: [implementation]
(int- numFrames [implementation]
(void- set
 set Set the cursor.
(void- unset
 unset Unset the cursor.
(BOOL- isAnimated
 isAnimated Tests whether this cursor is animated.
(int- getNextCursorFrame [implementation]
(void- createTimer [implementation]
(void- destroyTimer [implementation]
(void- spinCursor: [implementation]
(void- dealloc [implementation]

Static Public Member Functions

(nsMacCursor *) + cursorWithThemeCursor:
 cursorWithThemeCursor: Create a cursor by specifying a Carbon Apperance Manager ThemeCursor constant.
(nsMacCursor *) + cursorWithCursor:
 cursorWithCursor: Create a cursor by specifying a Cocoa NSCursor.
(nsMacCursor *) + cursorWithImageNamed:hotSpot:
 cursorWithImageNamed:hotSpot: Create a cursor by specifying the name of an image resource to use for the cursor and a hotspot.
(nsMacCursor *) + cursorWithFrames:
 cursorWithFrames: Create an animated cursor by specifying the frames to use for the animation.
(nsMacCursor *) + cursorWithResources:lastFrame:
 cursorWithResources:lastFrame: Create an animated cursor by specifying a range of CURS resources to load and animate.

Protected Attributes

int mFrameCounter

Private Attributes

ThemeCursor mCursor

Detailed Description

Implementation of nsMacCursor that uses Carbon Appearance Manager cursors.

Displays a static or animated ThemeCursor using Carbon Appearance Manager functions. Understands how many frames exist in each of the built-in ThemeCursors.

Definition at line 101 of file nsMacCursor.mm.


Member Function Documentation

- (void) createTimer [implementation]

Definition at line 248 of file nsMacCursor.mm.

{
  if ( mTimer == nil)
  {
    mTimer = [[NSTimer scheduledTimerWithTimeInterval: 0.25
                                               target: self
                                             selector: @selector(spinCursor:)
                                             userInfo: nil
                                              repeats: YES] retain];
  }
}

Here is the caller graph for this function:

+ (nsMacCursor *) cursorWithCursor: (NSCursor *)  aCursor

cursorWithCursor: Create a cursor by specifying a Cocoa NSCursor.

Creates a cursor representing the given Cocoa built-in cursor.

Parameters:
aCursorthe NSCursor to use
Returns:
an autoreleased instance of nsMacCursor representing the given NSCursor

Definition at line 198 of file nsMacCursor.mm.

                                  : (NSCursor *) aCursor
{
  return [[[nsCocoaCursor alloc] initWithCursor: aCursor] autorelease];
}

Here is the caller graph for this function:

+ (nsMacCursor *) cursorWithFrames: (NSArray *)  aCursorFrames

cursorWithFrames: Create an animated cursor by specifying the frames to use for the animation.

Creates a cursor that will animate by cycling through the given frames. Each element of the array must be an instance of NSCursor

Parameters:
aCursorFramesan array of NSCursor, representing the frames of an animated cursor, in the order they should be played.
Returns:
an autoreleased instance of nsMacCursor that will animate the given cursor frames

Definition at line 208 of file nsMacCursor.mm.

                                  : (NSArray *) aCursorFrames
{
  return [[[nsCocoaCursor alloc] initWithFrames: aCursorFrames] autorelease];
}
+ (nsMacCursor *) cursorWithImageNamed: (NSString *)  aCursorImage
hotSpot: (NSPoint)  aPoint 

cursorWithImageNamed:hotSpot: Create a cursor by specifying the name of an image resource to use for the cursor and a hotspot.

Creates a cursor by loading the named image using the +[NSImage imageNamed:] method.

The image must be compatible with any restrictions laid down by NSCursor. These vary by operating system version. eg, Jaguar has a smaller maximum size than Panther.

The hotspot precisely determines the point where the user clicks when using the cursor.

Parameters:
aCursorthe name of the image to use for the cursor
aPointthe point within the cursor to use as the hotspot
Returns:
an autoreleased instance of nsMacCursor that uses the given image and hotspot

Definition at line 203 of file nsMacCursor.mm.

                                      : (NSString *) aCursorImage hotSpot: (NSPoint) aPoint
{
  return [[[nsCocoaCursor alloc] initWithImageNamed: aCursorImage hotSpot: aPoint] autorelease];
}

Here is the caller graph for this function:

+ (nsMacCursor *) cursorWithResources: (int aFirstFrame
lastFrame: (int aLastFrame 

cursorWithResources:lastFrame: Create an animated cursor by specifying a range of CURS resources to load and animate.

Creates a cursor that will animate by cycling through the given range of cursor resource ids. Each resource in the range must be the next frame in the animation.

To create a static cursor, simply pass the same resource id for both parameters.

The frames are loaded from the compiled version of the resource file nsMacWidget.r.

Parameters:
aFirstFramethe resource id for the first frame of the animation. Must be 128 or greated
aLastFramethe resource id for the last frame of the animation. Must be 128 or greater, and greater than or equal to aFirstFrame
Returns:
an autoreleased instance of nsMacCursor that will animate the given cursor resources

Definition at line 193 of file nsMacCursor.mm.

                                     : (int) aFirstFrame lastFrame: (int) aLastFrame
{
  return [[[nsResourceCursor alloc] initWithFirstFrame: aFirstFrame lastFrame: aLastFrame] autorelease];
}

Here is the caller graph for this function:

+ (nsMacCursor *) cursorWithThemeCursor: (ThemeCursor)  aCursor

cursorWithThemeCursor: Create a cursor by specifying a Carbon Apperance Manager ThemeCursor constant.

Creates a cursor representing the given Appearance Manager built in cursor.

Parameters:
aCursorthe ThemeCursor to use
Returns:
an autoreleased instance of nsMacCursor representing the given ThemeCursor

Definition at line 188 of file nsMacCursor.mm.

                                       : (ThemeCursor) aCursor
{
  return [[[nsThemeCursor alloc] initWithThemeCursor: aCursor] autorelease];
}

Here is the caller graph for this function:

- (void) dealloc [implementation]

Reimplemented in nsCocoaCursor.

Definition at line 283 of file nsMacCursor.mm.

{
  [self destroyTimer];
  [super dealloc];    
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) destroyTimer [implementation]

Definition at line 260 of file nsMacCursor.mm.

{
  if ( mTimer != nil)
  {
      [mTimer invalidate];
      [mTimer release];
      mTimer = nil;
  }
}

Here is the caller graph for this function:

- (int) getNextCursorFrame [implementation]

Definition at line 242 of file nsMacCursor.mm.

Here is the call graph for this function:

Here is the caller graph for this function:

- (id) initWithThemeCursor: (ThemeCursor)  aCursor

initWithThemeCursor: Create a cursor by specifying a Carbon Apperance Manager ThemeCursor constant.

Creates a cursor representing the given Appearance Manager built in cursor.

Parameters:
aCursorthe ThemeCursor to use
Returns:
an instance of nsThemeCursor representing the given ThemeCursor

Definition at line 292 of file nsMacCursor.mm.

                          : (ThemeCursor) aCursor
{
  self = [super init];
  //Appearance Manager cursors all fall into the range 0..127. Custom application CURS resources begin at id 128.
  NS_ASSERTION(mCursor >= 0 && mCursor < 128, "Theme cursors must be in the range 0 <= num < 128");
  mCursor = aCursor;    
  return self;
}

isAnimated Tests whether this cursor is animated.

Use this method to determine whether a cursor is animated

Returns:
YES if the cursor is animated (has more than one frame), NO if it is a simple static cursor.

Definition at line 231 of file nsMacCursor.mm.

{
  return [self numFrames] > 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (int) numFrames [implementation]

Reimplemented from nsMacCursor.

Definition at line 319 of file nsMacCursor.mm.

{
  //These don't appear to be documented. Trial and Error...
  switch (mCursor)
  {
    case kThemeWatchCursor:
    case kThemeSpinningCursor:            
      return 8;
    default:
      return 1;
  }
}
- (void) set

set Set the cursor.

Makes this cursor the current cursor. If the cursor is animated, the animation is started.

Definition at line 213 of file nsMacCursor.mm.

{
  if ( [self isAnimated])
  {
    [self createTimer];
  }
  //if the cursor isn't animated or the timer creation fails for any reason...
  if (mTimer == nil)
  {
    [self setFrame: 0];
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

- (void) setFrame: (int aFrameIndex [implementation]

Reimplemented from nsMacCursor.

Definition at line 301 of file nsMacCursor.mm.

                 : (int) aFrameIndex
{
  if ( [self isAnimated] )
  {
    //if the cursor is animated try to draw the appropriate frame
    OSStatus err = ::SetAnimatedThemeCursor(mCursor, aFrameIndex);
    if ( err != noErr )
    {
      //in the event of any kind of problem, just try to show the first frame
      ::SetThemeCursor(mCursor);
    }
  }
  else
  {
    ::SetThemeCursor(mCursor);
  }
}

Here is the call graph for this function:

- (void) spinCursor: (NSTimer *)  aTimer [implementation]

Definition at line 270 of file nsMacCursor.mm.

                   : (NSTimer *) aTimer
{
  if ( [aTimer isValid] )
  {
    [self setFrame: [self getNextCursorFrame]];
  }
}

Here is the call graph for this function:

- (void) unset

unset Unset the cursor.

The cursor will return to the default (usually the arrow cursor). Unsets the cursor. If the cursor is animated, the animation is stopped.

Definition at line 226 of file nsMacCursor.mm.

{
  [self destroyTimer];    
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

- (ThemeCursor) mCursor [private]

Definition at line 104 of file nsMacCursor.mm.

- (int) mFrameCounter [protected, inherited]

Definition at line 50 of file nsMacCursor.h.


The documentation for this class was generated from the following file: