Release 941017
[wine/gsoc-2012-control.git] / windows / caret.c
blobae835b41eca723b3f6b6efd56f225a826160637c
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 */
7 static char Copyright[] = "Copyright David Metcalfe, 1993";
9 #include "windows.h"
10 #include "stddebug.h"
11 /* #define DEBUG_CARET /* */
12 /* #undef DEBUG_CARET /* */
13 #include "debug.h"
16 typedef struct
18 HWND hwnd;
19 short hidden;
20 BOOL on;
21 short x;
22 short y;
23 short width;
24 short height;
25 COLORREF color;
26 HBITMAP bitmap;
27 WORD timeout;
28 WORD timerid;
29 } CARET;
31 static CARET Caret;
32 static BOOL LockCaret;
34 static WORD CARET_Callback(HWND hwnd, WORD msg, WORD timerid, LONG ctime);
35 static void CARET_HideCaret();
38 /*****************************************************************
39 * CARET_Callback
42 static WORD CARET_Callback(HWND hwnd, WORD msg, WORD timerid, LONG ctime)
44 HDC hdc;
45 HBRUSH hBrush;
46 HRGN rgn;
48 dprintf_caret(stddeb,"CARET_Callback: id=%d: LockCaret=%d, hidden=%d, on=%d\n",
49 timerid, LockCaret, Caret.hidden, Caret.on);
50 if (!LockCaret && (!Caret.hidden || Caret.on))
52 Caret.on = (Caret.on ? FALSE : TRUE);
53 hdc = GetDC(Caret.hwnd);
54 if (Caret.bitmap == 0 || Caret.bitmap == 1)
55 hBrush = CreateSolidBrush(Caret.color);
56 else
57 hBrush = CreatePatternBrush(Caret.bitmap);
58 SelectObject(hdc, (HANDLE)hBrush);
59 SetROP2(hdc, R2_XORPEN);
60 rgn = CreateRectRgn(Caret.x, Caret.y,
61 Caret.x + Caret.width,
62 Caret.y + Caret.height);
63 FillRgn(hdc, rgn, hBrush);
64 DeleteObject((HANDLE)rgn);
65 DeleteObject((HANDLE)hBrush);
66 ReleaseDC(Caret.hwnd, hdc);
68 return 0;
72 /*****************************************************************
73 * CARET_HideCaret
76 static void CARET_HideCaret()
78 HDC hdc;
79 HBRUSH hBrush;
80 HRGN rgn;
82 Caret.on = FALSE;
83 hdc = GetDC(Caret.hwnd);
84 if (Caret.bitmap == 0 || Caret.bitmap == 1)
85 hBrush = CreateSolidBrush(Caret.color);
86 else
87 hBrush = CreatePatternBrush(Caret.bitmap);
88 SelectObject(hdc, (HANDLE)hBrush);
89 SetROP2(hdc, R2_XORPEN);
90 rgn = CreateRectRgn(Caret.x, Caret.y,
91 Caret.x + Caret.width,
92 Caret.y + Caret.height);
93 FillRgn(hdc, rgn, hBrush);
94 DeleteObject((HANDLE)rgn);
95 DeleteObject((HANDLE)hBrush);
96 ReleaseDC(Caret.hwnd, hdc);
100 /*****************************************************************
101 * CreateCaret (USER.163)
104 void CreateCaret(HWND hwnd, HBITMAP bitmap, short width, short height)
106 if (!hwnd) return;
109 /* if cursor already exists, destroy it */
110 /* if (Caret.hwnd)
111 DestroyCaret();
113 if (bitmap && bitmap != 1)
114 Caret.bitmap = bitmap;
116 if (width)
117 Caret.width = width;
118 else
119 Caret.width = GetSystemMetrics(SM_CXBORDER);
121 if (height)
122 Caret.height = height;
123 else
124 Caret.height = GetSystemMetrics(SM_CYBORDER);
126 Caret.hwnd = hwnd;
127 Caret.hidden = 1;
128 Caret.on = FALSE;
129 Caret.x = 0;
130 Caret.y = 0;
131 if (bitmap == 1)
132 Caret.color = GetSysColor(COLOR_GRAYTEXT);
133 else
134 Caret.color = GetSysColor(COLOR_WINDOWTEXT);
135 Caret.timeout = 750;
136 LockCaret = FALSE;
138 Caret.timerid = SetSystemTimer(NULL, 0, Caret.timeout, CARET_Callback);
140 dprintf_caret(stddeb,"CreateCaret: hwnd=%d, timerid=%d\n",
141 hwnd, Caret.timerid);
145 /*****************************************************************
146 * DestroyCaret (USER.164)
149 void DestroyCaret()
151 /* if (!Caret.hwnd) return;
153 dprintf_caret(stddeb,"DestroyCaret: timerid=%d\n", Caret.timerid);
155 KillSystemTimer(NULL, Caret.timerid);
157 if (Caret.on)
158 CARET_HideCaret();
160 Caret.hwnd = 0; /* cursor marked as not existing */
164 /*****************************************************************
165 * SetCaretPos (USER.165)
168 void SetCaretPos(short x, short y)
170 HDC hdc;
171 HBRUSH hBrush;
172 HRGN rgn;
174 if (!Caret.hwnd) return;
176 dprintf_caret(stddeb,"SetCaretPos: x=%d, y=%d\n", x, y);
178 LockCaret = TRUE;
179 if (Caret.on)
180 CARET_HideCaret();
182 Caret.x = x;
183 Caret.y = y;
184 LockCaret = FALSE;
187 /*****************************************************************
188 * HideCaret (USER.166)
191 void HideCaret(HWND hwnd)
193 if (!Caret.hwnd) return;
194 if (hwnd && (Caret.hwnd != hwnd)) return;
196 LockCaret = TRUE;
197 if (Caret.on)
198 CARET_HideCaret();
200 ++Caret.hidden;
201 LockCaret = FALSE;
205 /*****************************************************************
206 * ShowCaret (USER.167)
209 void ShowCaret(HWND hwnd)
211 if (!Caret.hwnd) return;
212 if (hwnd && (Caret.hwnd != hwnd)) return;
214 dprintf_caret(stddeb,"ShowCaret: hidden=%d\n", Caret.hidden);
215 if (Caret.hidden)
216 --Caret.hidden;
220 /*****************************************************************
221 * SetCaretBlinkTime (USER.168)
224 void SetCaretBlinkTime(WORD msecs)
226 if (!Caret.hwnd) return;
228 KillSystemTimer(NULL, Caret.timerid);
229 Caret.timeout = msecs;
230 Caret.timerid = SetSystemTimer(NULL, 0, Caret.timeout, CARET_Callback);
234 /*****************************************************************
235 * GetCaretBlinkTime (USER.169)
238 WORD GetCaretBlinkTime()
240 if (!Caret.hwnd) return;
242 return Caret.timeout;
246 /*****************************************************************
247 * GetCaretPos (USER.183)
250 void GetCaretPos(LPPOINT pt)
252 if (!Caret.hwnd || !pt) return;
254 pt->x = Caret.x;
255 pt->y = Caret.y;