Stubs for CloseDesktop and CloseWindowStation.
[wine/wine-kai.git] / windows / caret.c
blobb0f04d3bb00260d5505693cd91eb8d5cbb947baa
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
6 */
8 #include "winuser.h"
9 #include "wine/winuser16.h"
10 #include "module.h"
11 #include "debug.h"
13 typedef struct
15 HWND hwnd;
16 UINT hidden;
17 BOOL on;
18 INT x;
19 INT y;
20 INT width;
21 INT height;
22 HBRUSH16 hBrush;
23 UINT timeout;
24 UINT timerid;
25 } CARET;
27 typedef enum
29 CARET_OFF = 0,
30 CARET_ON,
31 CARET_TOGGLE,
32 } DISPLAY_CARET;
34 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
36 /*****************************************************************
37 * CARET_GetHwnd
39 HWND CARET_GetHwnd(void)
41 return Caret.hwnd;
44 /*****************************************************************
45 * CARET_GetRect
47 void CARET_GetRect(LPRECT lprc)
49 lprc->right = (lprc->left = Caret.x) + Caret.width - 1;
50 lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1;
53 /*****************************************************************
54 * CARET_DisplayCaret
56 static void CARET_DisplayCaret( DISPLAY_CARET status )
58 HDC hdc;
59 HBRUSH16 hPrevBrush;
61 if (Caret.on && (status == CARET_ON)) return;
62 if (!Caret.on && (status == CARET_OFF)) return;
64 /* So now it's always a toggle */
66 Caret.on = !Caret.on;
67 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
68 if (!(hdc = GetDCEx( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return;
69 hPrevBrush = SelectObject( hdc, Caret.hBrush );
70 PatBlt( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
71 SelectObject( hdc, hPrevBrush );
72 ReleaseDC( Caret.hwnd, hdc );
76 /*****************************************************************
77 * CARET_Callback
79 static VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime)
81 TRACE(caret,"hwnd=%04x, timerid=%d, caret=%d\n",
82 hwnd, id, Caret.on);
83 CARET_DisplayCaret(CARET_TOGGLE);
87 /*****************************************************************
88 * CARET_SetTimer
90 static void CARET_SetTimer(void)
92 if (Caret.timerid) KillSystemTimer( (HWND)0, Caret.timerid );
93 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
94 CARET_Callback );
98 /*****************************************************************
99 * CARET_ResetTimer
101 static void CARET_ResetTimer(void)
103 if (Caret.timerid)
105 KillSystemTimer( (HWND)0, Caret.timerid );
106 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
107 CARET_Callback );
112 /*****************************************************************
113 * CARET_KillTimer
115 static void CARET_KillTimer(void)
117 if (Caret.timerid)
119 KillSystemTimer( (HWND)0, Caret.timerid );
120 Caret.timerid = 0;
125 /*****************************************************************
126 * CreateCaret16 (USER.163)
128 void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap,
129 INT16 width, INT16 height )
131 CreateCaret( hwnd, bitmap, width, height );
134 /*****************************************************************
135 * CreateCaret32 (USER32.66)
137 BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap,
138 INT width, INT height )
140 TRACE(caret,"hwnd=%04x\n", hwnd);
142 if (!hwnd) return FALSE;
144 /* if cursor already exists, destroy it */
145 if (Caret.hwnd) DestroyCaret();
147 if (bitmap && (bitmap != 1))
149 BITMAP16 bmp;
150 if (!GetObject16( bitmap, sizeof(bmp), &bmp )) return FALSE;
151 Caret.width = bmp.bmWidth;
152 Caret.height = bmp.bmHeight;
153 /* FIXME: we should make a copy of the bitmap instead of a brush */
154 Caret.hBrush = CreatePatternBrush( bitmap );
156 else
158 Caret.width = width ? width : GetSystemMetrics(SM_CXBORDER);
159 Caret.height = height ? height : GetSystemMetrics(SM_CYBORDER);
160 Caret.hBrush = CreateSolidBrush(bitmap ?
161 GetSysColor(COLOR_GRAYTEXT) :
162 GetSysColor(COLOR_WINDOW) );
165 Caret.hwnd = hwnd;
166 Caret.hidden = 1;
167 Caret.on = FALSE;
168 Caret.x = 0;
169 Caret.y = 0;
171 Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
172 return TRUE;
176 /*****************************************************************
177 * DestroyCaret16 (USER.164)
179 void WINAPI DestroyCaret16(void)
181 DestroyCaret();
185 /*****************************************************************
186 * DestroyCaret32 (USER32.131)
188 BOOL WINAPI DestroyCaret(void)
190 if (!Caret.hwnd) return FALSE;
192 TRACE(caret,"hwnd=%04x, timerid=%d\n",
193 Caret.hwnd, Caret.timerid);
195 CARET_KillTimer();
196 CARET_DisplayCaret(CARET_OFF);
197 DeleteObject( Caret.hBrush );
198 Caret.hwnd = 0;
199 return TRUE;
203 /*****************************************************************
204 * SetCaretPos16 (USER.165)
206 void WINAPI SetCaretPos16( INT16 x, INT16 y )
208 SetCaretPos( x, y );
212 /*****************************************************************
213 * SetCaretPos32 (USER32.466)
215 BOOL WINAPI SetCaretPos( INT x, INT y)
217 if (!Caret.hwnd) return FALSE;
218 if ((x == Caret.x) && (y == Caret.y)) return TRUE;
220 TRACE(caret,"x=%d, y=%d\n", x, y);
222 CARET_KillTimer();
223 CARET_DisplayCaret(CARET_OFF);
224 Caret.x = x;
225 Caret.y = y;
226 if (!Caret.hidden)
228 CARET_DisplayCaret(CARET_ON);
229 CARET_SetTimer();
231 return TRUE;
235 /*****************************************************************
236 * HideCaret16 (USER.166)
238 void WINAPI HideCaret16( HWND16 hwnd )
240 HideCaret( hwnd );
244 /*****************************************************************
245 * HideCaret32 (USER32.317)
247 BOOL WINAPI HideCaret( HWND hwnd )
249 if (!Caret.hwnd) return FALSE;
250 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
252 TRACE(caret,"hwnd=%04x, hidden=%d\n",
253 hwnd, Caret.hidden);
255 CARET_KillTimer();
256 CARET_DisplayCaret(CARET_OFF);
257 Caret.hidden++;
258 return TRUE;
262 /*****************************************************************
263 * ShowCaret16 (USER.167)
265 void WINAPI ShowCaret16( HWND16 hwnd )
267 ShowCaret( hwnd );
271 /*****************************************************************
272 * ShowCaret32 (USER32.529)
274 BOOL WINAPI ShowCaret( HWND hwnd )
276 if (!Caret.hwnd) return FALSE;
277 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
279 TRACE(caret,"hwnd=%04x, hidden=%d\n",
280 hwnd, Caret.hidden);
282 if (Caret.hidden)
284 Caret.hidden--;
285 if (!Caret.hidden)
287 CARET_DisplayCaret(CARET_ON);
288 CARET_SetTimer();
291 return TRUE;
295 /*****************************************************************
296 * SetCaretBlinkTime16 (USER.168)
298 void WINAPI SetCaretBlinkTime16( UINT16 msecs )
300 SetCaretBlinkTime( msecs );
303 /*****************************************************************
304 * SetCaretBlinkTime32 (USER32.465)
306 BOOL WINAPI SetCaretBlinkTime( UINT msecs )
308 if (!Caret.hwnd) return FALSE;
310 TRACE(caret,"hwnd=%04x, msecs=%d\n",
311 Caret.hwnd, msecs);
313 Caret.timeout = msecs;
314 CARET_ResetTimer();
315 return TRUE;
319 /*****************************************************************
320 * GetCaretBlinkTime16 (USER.169)
322 UINT16 WINAPI GetCaretBlinkTime16(void)
324 return (UINT16)GetCaretBlinkTime();
328 /*****************************************************************
329 * GetCaretBlinkTime32 (USER32.209)
331 UINT WINAPI GetCaretBlinkTime(void)
333 return Caret.timeout;
337 /*****************************************************************
338 * GetCaretPos16 (USER.183)
340 VOID WINAPI GetCaretPos16( LPPOINT16 pt )
342 if (!Caret.hwnd || !pt) return;
344 TRACE(caret,"hwnd=%04x, pt=%p, x=%d, y=%d\n",
345 Caret.hwnd, pt, Caret.x, Caret.y);
346 pt->x = (INT16)Caret.x;
347 pt->y = (INT16)Caret.y;
351 /*****************************************************************
352 * GetCaretPos32 (USER32.210)
354 BOOL WINAPI GetCaretPos( LPPOINT pt )
356 if (!Caret.hwnd || !pt) return FALSE;
357 pt->x = Caret.x;
358 pt->y = Caret.y;
359 return TRUE;