1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2008 Novell, Inc.
23 // Geoff Norton (gnorton@novell.com)
30 using System.Windows.Forms;
31 using System.Runtime.InteropServices;
33 namespace System.Windows.Forms.CarbonInternal {
34 internal class Cursor {
35 internal static CarbonCursor defcur = new CarbonCursor (StdCursor.Default);
37 internal static Bitmap DefineStdCursorBitmap (StdCursor id) {
39 return new Bitmap (16, 16);
41 internal static IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
42 CarbonCursor cc = new CarbonCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
44 return (IntPtr) GCHandle.Alloc (cc);
46 internal static IntPtr DefineStdCursor (StdCursor id) {
47 CarbonCursor cc = new CarbonCursor (id);
49 return (IntPtr) GCHandle.Alloc (cc);
51 internal static void SetCursor (IntPtr cursor) {
52 if (cursor == IntPtr.Zero) {
57 CarbonCursor cc = (CarbonCursor) ((GCHandle) cursor).Target;
63 internal struct CarbonCursor {
66 private Color cursor_color;
67 private Color mask_color;
71 private bool standard;
73 public CarbonCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
74 this.id = StdCursor.Default;
77 this.cursor_color = cursor_pixel;
78 this.mask_color = mask_pixel;
79 this.hot_x = xHotSpot;
80 this.hot_y = yHotSpot;
84 public CarbonCursor (StdCursor id) {
88 this.cursor_color = Color.Black;
89 this.mask_color = Color.Black;
95 public StdCursor StdCursor {
101 public Bitmap Bitmap {
113 public Color CursorColor {
119 public Color MaskColor {
125 public int HotSpotX {
131 public int HotSpotY {
137 public void SetCursor () {
139 SetStandardCursor ();
144 public void SetCustomCursor () {
145 throw new NotImplementedException ("We dont support custom cursors yet");
148 public void SetStandardCursor () {
150 case StdCursor.AppStarting:
151 SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
153 case StdCursor.Arrow:
154 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
156 case StdCursor.Cross:
157 SetThemeCursor (ThemeCursor.kThemeCrossCursor);
159 case StdCursor.Default:
160 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
163 SetThemeCursor (ThemeCursor.kThemeOpenHandCursor);
166 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
168 case StdCursor.HSplit:
169 SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
171 case StdCursor.IBeam:
172 SetThemeCursor (ThemeCursor.kThemeIBeamCursor);
175 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
177 case StdCursor.NoMove2D:
178 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
180 case StdCursor.NoMoveHoriz:
181 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
183 case StdCursor.NoMoveVert:
184 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
186 case StdCursor.PanEast:
187 SetThemeCursor (ThemeCursor.kThemeResizeRightCursor);
189 case StdCursor.PanNE:
190 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
192 case StdCursor.PanNorth:
193 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
195 case StdCursor.PanNW:
196 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
198 case StdCursor.PanSE:
199 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
201 case StdCursor.PanSouth:
202 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
204 case StdCursor.PanSW:
205 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
207 case StdCursor.PanWest:
208 SetThemeCursor (ThemeCursor.kThemeResizeLeftCursor);
210 case StdCursor.SizeAll:
211 SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
213 case StdCursor.SizeNESW:
214 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
216 case StdCursor.SizeNS:
217 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
219 case StdCursor.SizeNWSE:
220 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
222 case StdCursor.SizeWE:
223 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
225 case StdCursor.UpArrow:
226 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
228 case StdCursor.VSplit:
229 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
231 case StdCursor.WaitCursor:
232 SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
235 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
241 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
242 static extern int SetThemeCursor (ThemeCursor cursor);