* System.Windows.Forms/WebBrowser.cs: Add missing attributes, missing
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms.CarbonInternal / Cursor.cs
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:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
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.
19 //
20 // Copyright (c) 2008 Novell, Inc.
21 //
22 // Authors:
23 //      Geoff Norton (gnorton@novell.com)
24 //
25 //
26
27
28 using System;
29 using System.Drawing;
30 using System.Windows.Forms;
31 using System.Runtime.InteropServices;
32
33 namespace System.Windows.Forms.CarbonInternal {
34         internal class Cursor {
35                 internal static Bitmap DefineStdCursorBitmap (StdCursor id) {
36                         // FIXME
37                         return new Bitmap (16, 16);
38                 }
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);
41
42                         return (IntPtr) GCHandle.Alloc (cc);
43                 }
44                 internal static IntPtr DefineStdCursor (StdCursor id) {
45                         CarbonCursor cc = new CarbonCursor (id);
46                 
47                         return (IntPtr) GCHandle.Alloc (cc);
48                 }
49                 internal static void SetCursor (IntPtr cursor) {
50                         if (cursor == IntPtr.Zero)
51                                 return;
52
53                         CarbonCursor cc = (CarbonCursor) ((GCHandle) cursor).Target;
54
55                         cc.SetCursor ();
56                 }
57         }
58
59         internal struct CarbonCursor {
60                 private Bitmap bmp;
61                 private Bitmap mask;
62                 private Color cursor_color;
63                 private Color mask_color;
64                 private int hot_x;
65                 private int hot_y;
66                 private StdCursor id;
67                 private bool standard;
68
69                 public CarbonCursor (Bitmap bitmap, Bitmap mask, Color cursor_pixel, Color mask_pixel, int xHotSpot, int yHotSpot) {
70                         this.id = StdCursor.Default;
71                         this.bmp = bitmap;
72                         this.mask = mask;
73                         this.cursor_color = cursor_pixel;
74                         this.mask_color = mask_pixel;
75                         this.hot_x = xHotSpot;
76                         this.hot_y = yHotSpot;
77                         standard = true;
78                 }
79
80                 public CarbonCursor (StdCursor id) {
81                         this.id = id;
82                         this.bmp = null;
83                         this.mask = null;
84                         this.cursor_color = Color.Black;
85                         this.mask_color = Color.Black;
86                         this.hot_x = 0;
87                         this.hot_y = 0;
88                         standard = true;
89                 }
90
91                 public StdCursor StdCursor {
92                         get {
93                                 return id;
94                         }
95                 }
96
97                 public Bitmap Bitmap {
98                         get { 
99                                 return bmp;
100                         }
101                 }
102
103                 public Bitmap Mask {
104                         get { 
105                                 return mask;
106                         }
107                 }
108
109                 public Color CursorColor {
110                         get {
111                                 return cursor_color;
112                         }
113                 }
114
115                 public Color MaskColor {
116                         get {
117                                 return mask_color;
118                         }
119                 }
120
121                 public int HotSpotX {
122                         get { 
123                                 return hot_x;
124                         }
125                 }
126
127                 public int HotSpotY {
128                         get { 
129                                 return hot_y;
130                         }
131                 }
132
133                 public void SetCursor () {
134                         if (standard)
135                                 SetStandardCursor ();
136                         else    
137                                 SetCustomCursor ();
138                 }
139
140                 public void SetCustomCursor () {
141                         throw new NotImplementedException ("We dont support custom cursors yet");
142                 }
143
144                 public void SetStandardCursor () {
145                         switch (id) {
146                                 case StdCursor.AppStarting:
147                                         SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
148                                         break;
149                                 case StdCursor.Arrow:
150                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
151                                         break;
152                                 case StdCursor.Cross:
153                                         SetThemeCursor (ThemeCursor.kThemeCrossCursor);
154                                         break;
155                                 case StdCursor.Default:
156                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
157                                         break;
158                                 case StdCursor.Hand:
159                                         SetThemeCursor (ThemeCursor.kThemeOpenHandCursor);
160                                         break;
161                                 case StdCursor.Help:
162                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
163                                         break;
164                                 case StdCursor.HSplit:
165                                         SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
166                                         break;
167                                 case StdCursor.IBeam:
168                                         SetThemeCursor (ThemeCursor.kThemeIBeamCursor);
169                                         break;
170                                 case StdCursor.No:
171                                         SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
172                                         break;
173                                 case StdCursor.NoMove2D:
174                                         SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
175                                         break;
176                                 case StdCursor.NoMoveHoriz:
177                                         SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
178                                         break;
179                                 case StdCursor.NoMoveVert:
180                                         SetThemeCursor (ThemeCursor.kThemeNotAllowedCursor);
181                                         break;
182                                 case StdCursor.PanEast:
183                                         SetThemeCursor (ThemeCursor.kThemeResizeRightCursor);
184                                         break;
185                                 case StdCursor.PanNE:
186                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
187                                         break;
188                                 case StdCursor.PanNorth:
189                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
190                                         break;
191                                 case StdCursor.PanNW:
192                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
193                                         break;
194                                 case StdCursor.PanSE:
195                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
196                                         break;
197                                 case StdCursor.PanSouth:
198                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
199                                         break;
200                                 case StdCursor.PanSW:
201                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
202                                         break;
203                                 case StdCursor.PanWest:
204                                         SetThemeCursor (ThemeCursor.kThemeResizeLeftCursor);
205                                         break;
206                                 case StdCursor.SizeAll:
207                                         SetThemeCursor (ThemeCursor.kThemeResizeLeftRightCursor);
208                                         break;
209                                 case StdCursor.SizeNESW:
210                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
211                                         break;
212                                 case StdCursor.SizeNS:
213                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
214                                         break;
215                                 case StdCursor.SizeNWSE:
216                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
217                                         break;
218                                 case StdCursor.SizeWE:
219                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
220                                         break;
221                                 case StdCursor.UpArrow:
222                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
223                                         break;
224                                 case StdCursor.VSplit:
225                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
226                                         break;
227                                 case StdCursor.WaitCursor:
228                                         SetThemeCursor (ThemeCursor.kThemeSpinningCursor);
229                                         break;
230                                 default:
231                                         SetThemeCursor (ThemeCursor.kThemeArrowCursor);
232                                         break;
233                         }
234                         return;
235                 }
236
237                 [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
238                 static extern int SetThemeCursor (ThemeCursor cursor);
239
240         }
241 }