Added RtlUnwind in ntdll, and made kernel32 spec entry a forward to
[wine/multimedia.git] / windows / caret.c
blob35b1245101875501017447904f26e8e07545ca33
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
6 */
8 #include "winuser.h"
9 #include "module.h"
10 #include "debug.h"
11 #include "wine/wingdi16.h"
13 DEFAULT_DEBUG_CHANNEL(caret)
15 typedef struct
17 HWND hwnd;
18 UINT hidden;
19 BOOL on;
20 INT x;
21 INT y;
22 INT width;
23 INT height;
24 HBRUSH16 hBrush;
25 UINT timeout;
26 UINT timerid;
27 } CARET;
29 typedef enum
31 CARET_OFF = 0,
32 CARET_ON,
33 CARET_TOGGLE
34 } DISPLAY_CARET;
36 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
38 /*****************************************************************
39 * CARET_GetHwnd
41 HWND CARET_GetHwnd(void)
43 return Caret.hwnd;
46 /*****************************************************************
47 * CARET_GetRect
49 void CARET_GetRect(LPRECT lprc)
51 lprc->right = (lprc->left = Caret.x) + Caret.width - 1;
52 lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1;
55 /*****************************************************************
56 * CARET_DisplayCaret
58 static void CARET_DisplayCaret( DISPLAY_CARET status )
60 HDC hdc;
61 HBRUSH16 hPrevBrush;
63 if (Caret.on && (status == CARET_ON)) return;
64 if (!Caret.on && (status == CARET_OFF)) return;
66 /* So now it's always a toggle */
68 Caret.on = !Caret.on;
69 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
70 if (!(hdc = GetDCEx( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return;
71 hPrevBrush = SelectObject( hdc, Caret.hBrush );
72 PatBlt( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
73 SelectObject( hdc, hPrevBrush );
74 ReleaseDC( Caret.hwnd, hdc );
78 /*****************************************************************
79 * CARET_Callback
81 static VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime)
83 TRACE(caret,"hwnd=%04x, timerid=%d, caret=%d\n",
84 hwnd, id, Caret.on);
85 CARET_DisplayCaret(CARET_TOGGLE);
89 /*****************************************************************
90 * CARET_SetTimer
92 static void CARET_SetTimer(void)
94 if (Caret.timerid) KillSystemTimer( (HWND)0, Caret.timerid );
95 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
96 CARET_Callback );
100 /*****************************************************************
101 * CARET_ResetTimer
103 static void CARET_ResetTimer(void)
105 if (Caret.timerid)
107 KillSystemTimer( (HWND)0, Caret.timerid );
108 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
109 CARET_Callback );
114 /*****************************************************************
115 * CARET_KillTimer
117 static void CARET_KillTimer(void)
119 if (Caret.timerid)
121 KillSystemTimer( (HWND)0, Caret.timerid );
122 Caret.timerid = 0;
127 /*****************************************************************
128 * CreateCaret16 (USER.163)
130 void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap,
131 INT16 width, INT16 height )
133 CreateCaret( hwnd, bitmap, width, height );
136 /*****************************************************************
137 * CreateCaret32 (USER32.66)
139 BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap,
140 INT width, INT height )
142 TRACE(caret,"hwnd=%04x\n", hwnd);
144 if (!hwnd) return FALSE;
146 /* if cursor already exists, destroy it */
147 if (Caret.hwnd) DestroyCaret();
149 if (bitmap && (bitmap != 1))
151 BITMAP16 bmp;
152 if (!GetObject16( bitmap, sizeof(bmp), &bmp )) return FALSE;
153 Caret.width = bmp.bmWidth;
154 Caret.height = bmp.bmHeight;
155 /* FIXME: we should make a copy of the bitmap instead of a brush */
156 Caret.hBrush = CreatePatternBrush( bitmap );
158 else
160 Caret.width = width ? width : GetSystemMetrics(SM_CXBORDER);
161 Caret.height = height ? height : GetSystemMetrics(SM_CYBORDER);
162 Caret.hBrush = CreateSolidBrush(bitmap ?
163 GetSysColor(COLOR_GRAYTEXT) :
164 GetSysColor(COLOR_WINDOW) );
167 Caret.hwnd = hwnd;
168 Caret.hidden = 1;
169 Caret.on = FALSE;
170 Caret.x = 0;
171 Caret.y = 0;
173 Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
174 return TRUE;
178 /*****************************************************************
179 * DestroyCaret16 (USER.164)
181 void WINAPI DestroyCaret16(void)
183 DestroyCaret();
187 /*****************************************************************
188 * DestroyCaret32 (USER32.131)
190 BOOL WINAPI DestroyCaret(void)
192 if (!Caret.hwnd) return FALSE;
194 TRACE(caret,"hwnd=%04x, timerid=%d\n",
195 Caret.hwnd, Caret.timerid);
197 CARET_KillTimer();
198 CARET_DisplayCaret(CARET_OFF);
199 DeleteObject( Caret.hBrush );
200 Caret.hwnd = 0;
201 return TRUE;
205 /*****************************************************************
206 * SetCaretPos16 (USER.165)
208 void WINAPI SetCaretPos16( INT16 x, INT16 y )
210 SetCaretPos( x, y );
214 /*****************************************************************
215 * SetCaretPos32 (USER32.466)
217 BOOL WINAPI SetCaretPos( INT x, INT y)
219 if (!Caret.hwnd) return FALSE;
220 if ((x == Caret.x) && (y == Caret.y)) return TRUE;
222 TRACE(caret,"x=%d, y=%d\n", x, y);
224 CARET_KillTimer();
225 CARET_DisplayCaret(CARET_OFF);
226 Caret.x = x;
227 Caret.y = y;
228 if (!Caret.hidden)
230 CARET_DisplayCaret(CARET_ON);
231 CARET_SetTimer();
233 return TRUE;
237 /*****************************************************************
238 * HideCaret16 (USER.166)
240 void WINAPI HideCaret16( HWND16 hwnd )
242 HideCaret( hwnd );
246 /*****************************************************************
247 * HideCaret32 (USER32.317)
249 BOOL WINAPI HideCaret( HWND hwnd )
251 if (!Caret.hwnd) return FALSE;
252 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
254 TRACE(caret,"hwnd=%04x, hidden=%d\n",
255 hwnd, Caret.hidden);
257 CARET_KillTimer();
258 CARET_DisplayCaret(CARET_OFF);
259 Caret.hidden++;
260 return TRUE;
264 /*****************************************************************
265 * ShowCaret16 (USER.167)
267 void WINAPI ShowCaret16( HWND16 hwnd )
269 ShowCaret( hwnd );
273 /*****************************************************************
274 * ShowCaret32 (USER32.529)
276 BOOL WINAPI ShowCaret( HWND hwnd )
278 if (!Caret.hwnd) return FALSE;
279 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
281 TRACE(caret,"hwnd=%04x, hidden=%d\n",
282 hwnd, Caret.hidden);
284 if (Caret.hidden)
286 Caret.hidden--;
287 if (!Caret.hidden)
289 CARET_DisplayCaret(CARET_ON);
290 CARET_SetTimer();
293 return TRUE;
297 /*****************************************************************
298 * SetCaretBlinkTime16 (USER.168)
300 void WINAPI SetCaretBlinkTime16( UINT16 msecs )
302 SetCaretBlinkTime( msecs );
305 /*****************************************************************
306 * SetCaretBlinkTime32 (USER32.465)
308 BOOL WINAPI SetCaretBlinkTime( UINT msecs )
310 if (!Caret.hwnd) return FALSE;
312 TRACE(caret,"hwnd=%04x, msecs=%d\n",
313 Caret.hwnd, msecs);
315 Caret.timeout = msecs;
316 CARET_ResetTimer();
317 return TRUE;
321 /*****************************************************************
322 * GetCaretBlinkTime16 (USER.169)
324 UINT16 WINAPI GetCaretBlinkTime16(void)
326 return (UINT16)GetCaretBlinkTime();
330 /*****************************************************************
331 * GetCaretBlinkTime32 (USER32.209)
333 UINT WINAPI GetCaretBlinkTime(void)
335 return Caret.timeout;
339 /*****************************************************************
340 * GetCaretPos16 (USER.183)
342 VOID WINAPI GetCaretPos16( LPPOINT16 pt )
344 if (!Caret.hwnd || !pt) return;
346 TRACE(caret,"hwnd=%04x, pt=%p, x=%d, y=%d\n",
347 Caret.hwnd, pt, Caret.x, Caret.y);
348 pt->x = (INT16)Caret.x;
349 pt->y = (INT16)Caret.y;
353 /*****************************************************************
354 * GetCaretPos32 (USER32.210)
356 BOOL WINAPI GetCaretPos( LPPOINT pt )
358 if (!Caret.hwnd || !pt) return FALSE;
359 pt->x = Caret.x;
360 pt->y = Caret.y;
361 return TRUE;