2007-03-22 10:30:00 -07:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is nsCursors.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Andrew Thompson.
|
|
|
|
* Portions created by the Andrew Thompson are Copyright (C) 2004
|
|
|
|
* Andrew Thompson. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Josh Aas <josh@mozilla.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsCursorManager.h"
|
2008-02-19 12:58:01 -08:00
|
|
|
#include "nsObjCExceptions.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
static nsCursorManager *gInstance;
|
|
|
|
|
|
|
|
/*! @category nsCursorManager(PrivateMethods)
|
|
|
|
Private methods for the cursor manager class.
|
|
|
|
*/
|
|
|
|
@interface nsCursorManager(PrivateMethods)
|
|
|
|
/*! @method getCursor:
|
|
|
|
@abstract Get a reference to the native Mac representation of a cursor.
|
|
|
|
@discussion Gets a reference to the Mac native implementation of a cursor.
|
|
|
|
If the cursor has been requested before, it is retreived from the cursor cache,
|
|
|
|
otherwise it is created and cached.
|
|
|
|
@param aCursor the cursor to get
|
|
|
|
@result the Mac native implementation of the cursor
|
|
|
|
*/
|
|
|
|
- (nsMacCursor *) getCursor: (nsCursor) aCursor;
|
|
|
|
|
|
|
|
/*! @method createCursor:
|
|
|
|
@abstract Create a Mac native representation of a cursor.
|
|
|
|
@discussion Creates a version of the Mac native representation of this cursor
|
|
|
|
@param aCursor the cursor to create
|
|
|
|
@result the Mac native implementation of the cursor
|
|
|
|
*/
|
|
|
|
+ (nsMacCursor *) createCursor: (enum nsCursor) aCursor;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation nsCursorManager
|
|
|
|
|
|
|
|
+ (nsCursorManager *) sharedInstance
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!gInstance) {
|
|
|
|
gInstance = [[nsCursorManager alloc] init];
|
|
|
|
}
|
|
|
|
return gInstance;
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) dispose
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
[gInstance release];
|
|
|
|
gInstance = nil;
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
+ (nsMacCursor *) createCursor: (enum nsCursor) aCursor
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
switch(aCursor)
|
|
|
|
{
|
|
|
|
case eCursor_standard:
|
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor arrowCursor]];
|
|
|
|
case eCursor_wait:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemeWatchCursor];
|
2008-11-28 14:43:29 -08:00
|
|
|
case eCursor_select:
|
2007-03-22 10:30:00 -07:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor IBeamCursor]];
|
|
|
|
case eCursor_hyperlink:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor pointingHandCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_crosshair:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor crosshairCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_move:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor openHandCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_help:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithImageNamed: @"help" hotSpot: NSMakePoint(1,1)];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_copy:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemeCopyArrowCursor];
|
|
|
|
case eCursor_alias:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemeAliasArrowCursor];
|
|
|
|
case eCursor_context_menu:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemeContextualMenuArrowCursor];
|
|
|
|
|
|
|
|
case eCursor_cell:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemePlusCursor];
|
|
|
|
case eCursor_grab:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor openHandCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_grabbing:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor closedHandCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_spinning:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithResources: 200 lastFrame: 203]; // better than kThemeSpinningCursor
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_zoom_in:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"zoomIn" hotSpot: NSMakePoint(6,6)];
|
|
|
|
case eCursor_zoom_out:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"zoomOut" hotSpot: NSMakePoint(6,6)];
|
|
|
|
case eCursor_vertical_text:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"vtIBeam" hotSpot: NSMakePoint(7,8)];
|
|
|
|
case eCursor_all_scroll:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor openHandCursor]];;
|
2007-03-22 10:30:00 -07:00
|
|
|
case eCursor_not_allowed:
|
|
|
|
case eCursor_no_drop:
|
|
|
|
return [nsMacCursor cursorWithThemeCursor: kThemeNotAllowedCursor];
|
|
|
|
|
|
|
|
// Resize Cursors:
|
|
|
|
//North
|
|
|
|
case eCursor_n_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeUpCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//North East
|
|
|
|
case eCursor_ne_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeNE" hotSpot: NSMakePoint(8,7)];
|
|
|
|
//East
|
|
|
|
case eCursor_e_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeRightCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//South East
|
|
|
|
case eCursor_se_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeSE" hotSpot: NSMakePoint(8,8)];
|
|
|
|
//South
|
|
|
|
case eCursor_s_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeDownCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//South West
|
|
|
|
case eCursor_sw_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeSW" hotSpot: NSMakePoint(6,8)];
|
|
|
|
//West
|
|
|
|
case eCursor_w_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeLeftCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//North West
|
|
|
|
case eCursor_nw_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeNW" hotSpot: NSMakePoint(7,7)];
|
|
|
|
//North & South
|
|
|
|
case eCursor_ns_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeUpDownCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//East & West
|
|
|
|
case eCursor_ew_resize:
|
2008-11-28 14:43:29 -08:00
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor resizeLeftRightCursor]];
|
2007-03-22 10:30:00 -07:00
|
|
|
//North East & South West
|
|
|
|
case eCursor_nesw_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeNESW" hotSpot: NSMakePoint(8,8)];
|
|
|
|
//North West & South East
|
|
|
|
case eCursor_nwse_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"sizeNWSE" hotSpot: NSMakePoint(8,8)];
|
|
|
|
//Column Resize
|
|
|
|
case eCursor_col_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"colResize" hotSpot: NSMakePoint(8,8)];
|
|
|
|
//Row Resize
|
|
|
|
case eCursor_row_resize:
|
|
|
|
return [nsMacCursor cursorWithImageNamed: @"rowResize" hotSpot: NSMakePoint(8,8)];
|
|
|
|
default:
|
|
|
|
return [nsMacCursor cursorWithCursor: [NSCursor arrowCursor]];
|
|
|
|
}
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) init
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if ((self = [super init])) {
|
2008-02-19 12:58:01 -08:00
|
|
|
mCursors = [[NSMutableDictionary alloc] initWithCapacity:25];
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return self;
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setCursor: (enum nsCursor) aCursor
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aCursor != mCurrentCursor) {
|
|
|
|
[[self getCursor: mCurrentCursor] unset];
|
|
|
|
[[self getCursor: aCursor] set];
|
2008-01-18 10:39:49 -08:00
|
|
|
|
|
|
|
if (aCursor == eCursor_none) {
|
|
|
|
[NSCursor hide];
|
|
|
|
} else if (mCurrentCursor == eCursor_none) {
|
|
|
|
[NSCursor unhide];
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
mCurrentCursor = aCursor;
|
|
|
|
}
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (nsMacCursor *) getCursor: (enum nsCursor) aCursor
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK_NIL;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsMacCursor * result = [mCursors objectForKey: [NSNumber numberWithInt: aCursor]];
|
|
|
|
if (!result) {
|
|
|
|
result = [nsCursorManager createCursor: aCursor];
|
|
|
|
[mCursors setObject: result forKey: [NSNumber numberWithInt: aCursor]];
|
|
|
|
}
|
|
|
|
return result;
|
2008-02-19 12:58:01 -08:00
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK_NIL;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) dealloc
|
|
|
|
{
|
2008-02-19 12:58:01 -08:00
|
|
|
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
[[self getCursor: mCurrentCursor] unset];
|
|
|
|
[mCursors release];
|
2008-02-19 12:58:01 -08:00
|
|
|
[super dealloc];
|
|
|
|
|
|
|
|
NS_OBJC_END_TRY_ABORT_BLOCK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|