1
2
3
4
5
6 using System;
7 using System.Windows.API;
8
9 namespace System.Windows
10 {
11 public enum StandardCursorId : int
12 {
13 IDC_APPSTARTING = 32650,
14 IDC_ARROW = 32512,
15 IDC_CROSS = 32515,
16 IDC_HAND = 32649,
17 IDC_HELP = 32651,
18 IDC_IBEAM = 32513,
19 IDC_NO = 32648,
20 IDC_SIZEALL = 32646,
21 IDC_SIZENESW = 32643,
22 IDC_SIZENS = 32645,
23 IDC_SIZENWSE = 32642,
24 IDC_SIZEWE = 32644,
25 IDC_UPARROW = 32516,
26 IDC_WAIT = 32514
27 }
28
29 public class Cursor : Resource
30 {
31 public nothrow Cursor() : cursorHandle(null), standard(false)
32 {
33 }
34 public nothrow Cursor(void* cursorHandle_) : cursorHandle(cursorHandle_), standard(false)
35 {
36 }
37 public nothrow Cursor(void* cursorHandle_, bool standard_) : cursorHandle(cursorHandle_), standard(standard_)
38 {
39 }
40 public nothrow Cursor(Cursor&& that) : cursorHandle(that.cursorHandle), standard(that.standard)
41 {
42 that.cursorHandle = null;
43 that.standard = false;
44 }
45 public ~Cursor()
46 {
47 if (cursorHandle != null && !standard)
48 {
49 WinDestroyCursor(cursorHandle);
50 }
51 }
52 public default nothrow void operator=(Cursor&&);
53 suppress Cursor(const Cursor&);
54 suppress void operator=(const Cursor&);
55 public nothrow void* Handle() const
56 {
57 return cursorHandle;
58 }
59 public nothrow bool IsStandard() const
60 {
61 return standard;
62 }
63 public nothrow void SetStandard()
64 {
65 standard = true;
66 }
67 private void* cursorHandle;
68 private bool standard;
69 }
70
71 public Cursor LoadStandardCursor(StandardCursorId cursorId)
72 {
73 void* cursorHandle = WinLoadStandardCursor(cast<int>(cursorId));
74 if (cursorHandle == null)
75 {
76 throw WindowsAPIException(WinGetLastError());
77 }
78 return Cursor(cursorHandle, true);
79 }
80
81 public Cursor LoadCursor(const string& cursorName)
82 {
83 return Cursor(LoadCursor(cursorName.Chars()));
84 }
85
86 public Cursor GetCursor()
87 {
88 return Cursor(WinGetCursor(), true);
89 }
90
91 public void SetCursor(Cursor& cursor)
92 {
93 WinSetCursor(cursor.Handle());
94 }
95 }