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 Bitmap DefineStdCursorBitmap (StdCursor id) {
37 return new Bitmap (16, 16);
39 internal static IntPtr DefineCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
40 CarbonCursor cc = new CarbonCursor (bitmap, mask, cursor_pixel, mask_pixel, xHotSpot, yHotSpot);
42 return (IntPtr) GCHandle.Alloc (cc);
44 internal static IntPtr DefineStdCursor (StdCursor id) {
45 CarbonCursor cc = new CarbonCursor (id);
47 return (IntPtr) GCHandle.Alloc (cc);
49 internal static void SetCursor (IntPtr cursor) {
50 if (cursor == IntPtr.Zero)
53 CarbonCursor cc = (CarbonCursor) ((GCHandle) cursor).Target;
59 internal struct CarbonCursor {
62 private Color cursor_color;
63 private Color mask_color;
67 private bool standard;
69 public CarbonCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
70 this.id = StdCursor.Default;
73 this.cursor_color = cursor_pixel;
74 this.mask_color = mask_pixel;
75 this.hot_x = xHotSpot;
76 this.hot_y = yHotSpot;
80 public CarbonCursor (StdCursor id) {
84 this.cursor_color = Color.Black;
85 this.mask_color = Color.Black;
91 public StdCursor StdCursor {
97 public Bitmap Bitmap {
109 public Color CursorColor {
115 public Color MaskColor {
121 public int HotSpotX {
127 public int HotSpotY {
133 public void SetCursor () {
135 SetStandardCursor ();
140 public void SetCustomCursor () {
141 throw new NotImplementedException ("We dont support custom cursors yet");
144 public void SetStandardCursor () {
146 case StdCursor.AppStarting:
147 SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
149 case StdCursor.Arrow:
150 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
152 case StdCursor.Cross:
153 SetThemeCursor (ThemeCursor.kThemeCrossCursor);
155 case StdCursor.Default:
156 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
159 SetThemeCursor (ThemeCursor.kThemeOpenHandCursor);
162 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
164 case StdCursor.HSplit:
165 SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
167 case StdCursor.IBeam:
168 SetThemeCursor (ThemeCursor.kThemeIBeamCursor);
171 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
173 case StdCursor.NoMove2D:
174 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
176 case StdCursor.NoMoveHoriz:
177 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
179 case StdCursor.NoMoveVert:
180 SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
182 case StdCursor.PanEast:
183 SetThemeCursor (ThemeCursor.kThemeResizeRightCursor);
185 case StdCursor.PanNE:
186 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
188 case StdCursor.PanNorth:
189 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
191 case StdCursor.PanNW:
192 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
194 case StdCursor.PanSE:
195 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
197 case StdCursor.PanSouth:
198 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
200 case StdCursor.PanSW:
201 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
203 case StdCursor.PanWest:
204 SetThemeCursor (ThemeCursor.kThemeResizeLeftCursor);
206 case StdCursor.SizeAll:
207 SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
209 case StdCursor.SizeNESW:
210 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
212 case StdCursor.SizeNS:
213 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
215 case StdCursor.SizeNWSE:
216 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
218 case StdCursor.SizeWE:
219 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
221 case StdCursor.UpArrow:
222 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
224 case StdCursor.VSplit:
225 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
227 case StdCursor.WaitCursor:
228 SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
231 SetThemeCursor (ThemeCursor.kThemeArrowCursor);
237 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
238 static extern int SetThemeCursor (ThemeCursor cursor);