0
|
1 // Written in the D programming language
|
|
2 // www.digitalmars.com/d/
|
|
3
|
|
4 /*
|
|
5 * The contents of this file are subject to the Mozilla Public License Version
|
|
6 * 1.1 (the "License"); you may not use this file except in compliance with
|
|
7 * the License. You may obtain a copy of the License at
|
|
8 * http://www.mozilla.org/MPL/
|
|
9 *
|
|
10 * Software distributed under the License is distributed on an "AS IS" basis,
|
|
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
12 * for the specific language governing rights and limitations under the
|
|
13 * License.
|
|
14 *
|
|
15 * The Original Code is the Dynamin library.
|
|
16 *
|
|
17 * The Initial Developer of the Original Code is Jordan Miner.
|
|
18 * Portions created by the Initial Developer are Copyright (C) 2007-2009
|
|
19 * the Initial Developer. All Rights Reserved.
|
|
20 *
|
|
21 * Contributor(s):
|
|
22 * Jordan Miner <jminer7@gmail.com>
|
|
23 *
|
|
24 */
|
|
25
|
|
26 module dynamin.gui.windows_cursor;
|
|
27
|
|
28 public import dynamin.c.windows;
|
|
29 public import tango.io.Stdout;
|
|
30 public import dynamin.gui.control;
|
|
31
|
|
32 // TODO: use import("AeroMouseDrag.png"), import("MouseDrag.png"), etc.
|
|
33 // to embed png into executable. Then, use lodepng to decode it and use
|
|
34 // CreateIconIndirect to create a cusor from them if possible.
|
|
35
|
|
36 template CursorBackend() {
|
|
37 HCURSOR _handle;
|
|
38 bool isBuiltin = false;
|
|
39 this(HCURSOR h) {
|
|
40 _handle = h;
|
|
41 isBuiltin = true;
|
|
42 }
|
|
43 static:
|
|
44 void backend_SetCurrent(Control c, Cursor cur) {
|
|
45 assert(cur.isBuiltin); // TODO: allow custom cursors
|
|
46 SetCursor(cur._handle);
|
|
47 }
|
|
48 Cursor none = null;
|
|
49 Cursor arrow = null;
|
|
50 Cursor waitArrow = null;
|
|
51 Cursor wait = null;
|
|
52 Cursor text = null;
|
|
53 Cursor hand = null;
|
|
54 Cursor move = null;
|
|
55 Cursor resizeHoriz = null;
|
|
56 Cursor resizeVert = null;
|
|
57 Cursor resizeBackslash = null;
|
|
58 Cursor resizeSlash = null;
|
|
59 Cursor drag = null; // from resource
|
|
60 Cursor invalidDrag = null;
|
|
61 Cursor reversedArrow = null; // from resource
|
|
62 Cursor crosshair = null;
|
|
63
|
|
64 Cursor backend_maybeLoad(Cursor* cache, int curRes) {
|
|
65 if(*cache is null) {
|
|
66 HCURSOR hcur = LoadImage(null, MAKEINTRESOURCE(curRes),
|
|
67 IMAGE_CURSOR, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
|
|
68 if(hcur is null)
|
|
69 Stdout.format("LoadImage() failed loading cursor {}", curRes).newline;
|
|
70 else
|
|
71 *cache = new Cursor(hcur);
|
|
72 }
|
|
73 return *cache;
|
|
74 }
|
|
75 Cursor backend_maybeLoad(Cursor* cache, wchar[] name) {
|
|
76 if(*cache is null) {
|
|
77 HCURSOR hcur = LoadImage(GetModuleHandle(null), name.ptr,
|
|
78 IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE);
|
|
79 if(hcur is null)
|
|
80 Stdout.format("LoadImage() failed loading cursor {}", name).newline;
|
|
81 else
|
|
82 *cache = new Cursor(hcur);
|
|
83 }
|
|
84 return *cache;
|
|
85 }
|
|
86 Cursor backend_None() {
|
|
87 if(none is null)
|
|
88 none = new Cursor(cast(HCURSOR)null);
|
|
89 return none;
|
|
90 }
|
|
91 Cursor backend_Arrow() {
|
|
92 return backend_maybeLoad(&arrow, OCR_NORMAL);
|
|
93 }
|
|
94 Cursor backend_WaitArrow() {
|
|
95 return backend_maybeLoad(&waitArrow, OCR_APPSTARTING);
|
|
96 }
|
|
97 Cursor backend_Wait() {
|
|
98 return backend_maybeLoad(&wait, OCR_WAIT);
|
|
99 }
|
|
100 Cursor backend_Text() {
|
|
101 return backend_maybeLoad(&text, OCR_IBEAM);
|
|
102 }
|
|
103 Cursor backend_Hand() {
|
|
104 return backend_maybeLoad(&hand, OCR_HAND); // Windows 98 & newer
|
|
105 }
|
|
106 Cursor backend_Move() {
|
|
107 return backend_maybeLoad(&move, OCR_SIZEALL);
|
|
108 }
|
|
109 Cursor backend_ResizeHoriz() {
|
|
110 return backend_maybeLoad(&resizeHoriz, OCR_SIZEWE);
|
|
111 }
|
|
112 Cursor backend_ResizeVert() {
|
|
113 return backend_maybeLoad(&resizeVert, OCR_SIZENS);
|
|
114 }
|
|
115 Cursor backend_ResizeBackslash() {
|
|
116 return backend_maybeLoad(&resizeBackslash, OCR_SIZENWSE);
|
|
117 }
|
|
118 Cursor backend_ResizeSlash() {
|
|
119 return backend_maybeLoad(&resizeSlash, OCR_SIZENESW);
|
|
120 }
|
|
121 Cursor backend_Drag() {
|
|
122 if(checkWindowsVersion(WindowsVersion.WindowsVista))
|
|
123 return backend_maybeLoad(&drag, "AeroDragCur");
|
|
124 else
|
|
125 return backend_maybeLoad(&drag, "DragCur");
|
|
126 }
|
|
127 Cursor backend_InvalidDrag() {
|
|
128 return backend_maybeLoad(&invalidDrag, OCR_NO);
|
|
129 }
|
|
130 Cursor backend_ReversedArrow() {
|
|
131 if(checkWindowsVersion(WindowsVersion.WindowsVista))
|
|
132 return backend_maybeLoad(&drag, "AeroReversedArrowCur");
|
|
133 else
|
|
134 return backend_maybeLoad(&drag, "ReversedArrowCur");
|
|
135 }
|
|
136 Cursor backend_Crosshair() {
|
|
137 return backend_maybeLoad(&crosshair, OCR_CROSS);
|
|
138 }
|
|
139 }
|
|
140
|