Release 970305
[wine/multimedia.git] / windows / caret.c
blob00de7ff24f3ca0a32a0e15ae2d062bc41180c29e
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
6 */
8 #include "windows.h"
9 #include "module.h"
10 #include "stddebug.h"
11 /* #define DEBUG_CARET */
12 #include "debug.h"
14 typedef struct
16 HWND32 hwnd;
17 UINT32 hidden;
18 BOOL32 on;
19 INT32 x;
20 INT32 y;
21 INT32 width;
22 INT32 height;
23 HBRUSH16 hBrush;
24 UINT32 timeout;
25 UINT32 timerid;
26 } CARET;
28 typedef enum
30 CARET_OFF = 0,
31 CARET_ON,
32 CARET_TOGGLE,
33 } DISPLAY_CARET;
35 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
37 /*****************************************************************
38 * CARET_GetHwnd
40 HWND32 CARET_GetHwnd(void)
42 return Caret.hwnd;
45 /*****************************************************************
46 * CARET_GetRect
48 void CARET_GetRect(LPRECT32 lprc)
50 lprc->right = (lprc->left = Caret.x) + Caret.width - 1;
51 lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1;
54 /*****************************************************************
55 * CARET_DisplayCaret
57 static void CARET_DisplayCaret( DISPLAY_CARET status )
59 HDC32 hdc;
60 HBRUSH16 hPrevBrush;
62 if (Caret.on && (status == CARET_ON)) return;
63 if (!Caret.on && (status == CARET_OFF)) return;
65 /* So now it's always a toggle */
67 Caret.on = !Caret.on;
68 if (!(hdc = GetDCEx32( Caret.hwnd, 0, DCX_USESTYLE | DCX_CACHE ))) return;
69 hPrevBrush = SelectObject32( hdc, Caret.hBrush );
70 PatBlt32( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
71 SelectObject32( hdc, hPrevBrush );
72 ReleaseDC32( Caret.hwnd, hdc );
76 /*****************************************************************
77 * CARET_Callback
79 static VOID CARET_Callback( HWND32 hwnd, UINT32 msg, UINT32 id, DWORD ctime)
81 dprintf_caret(stddeb,"CARET_Callback: 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) KillSystemTimer32( (HWND32)0, Caret.timerid );
93 Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
94 CARET_Callback );
98 /*****************************************************************
99 * CARET_ResetTimer
101 static void CARET_ResetTimer(void)
103 if (Caret.timerid)
105 KillSystemTimer32( (HWND32)0, Caret.timerid );
106 Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
107 CARET_Callback );
112 /*****************************************************************
113 * CARET_KillTimer
115 static void CARET_KillTimer(void)
117 if (Caret.timerid)
119 KillSystemTimer32( (HWND32)0, Caret.timerid );
120 Caret.timerid = 0;
125 /*****************************************************************
126 * CreateCaret16 (USER.163)
128 void CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap, INT16 width, INT16 height )
130 CreateCaret32( hwnd, bitmap, width, height );
133 /*****************************************************************
134 * CreateCaret32 (USER32.65)
136 BOOL32 CreateCaret32( HWND32 hwnd, HBITMAP32 bitmap,
137 INT32 width, INT32 height )
139 dprintf_caret(stddeb,"CreateCaret: hwnd=%04x\n", hwnd);
141 if (!hwnd) return FALSE;
143 /* if cursor already exists, destroy it */
144 if (Caret.hwnd) DestroyCaret32();
146 if (bitmap && (bitmap != 1))
148 BITMAP16 bmp;
149 if (!GetObject16( bitmap, sizeof(bmp), &bmp )) return FALSE;
150 Caret.width = bmp.bmWidth;
151 Caret.height = bmp.bmHeight;
152 /* FIXME: we should make a copy of the bitmap instead of a brush */
153 Caret.hBrush = CreatePatternBrush32( bitmap );
155 else
157 Caret.width = width ? width : GetSystemMetrics32(SM_CXBORDER);
158 Caret.height = height ? height : GetSystemMetrics32(SM_CYBORDER);
159 Caret.hBrush = CreateSolidBrush32(bitmap ?
160 GetSysColor32(COLOR_GRAYTEXT) :
161 GetSysColor32(COLOR_WINDOW) );
164 Caret.hwnd = hwnd;
165 Caret.hidden = 1;
166 Caret.on = FALSE;
167 Caret.x = 0;
168 Caret.y = 0;
170 Caret.timeout = GetProfileInt32A( "windows", "CursorBlinkRate", 500 );
171 return TRUE;
175 /*****************************************************************
176 * DestroyCaret16 (USER.164)
178 void DestroyCaret16(void)
180 DestroyCaret32();
184 /*****************************************************************
185 * DestroyCaret32 (USER32.130)
187 BOOL32 DestroyCaret32(void)
189 if (!Caret.hwnd) return FALSE;
191 dprintf_caret(stddeb,"DestroyCaret: hwnd=%04x, timerid=%d\n",
192 Caret.hwnd, Caret.timerid);
194 CARET_KillTimer();
195 CARET_DisplayCaret(CARET_OFF);
196 DeleteObject32( Caret.hBrush );
197 Caret.hwnd = 0;
198 return TRUE;
202 /*****************************************************************
203 * SetCaretPos16 (USER.165)
205 void SetCaretPos16( INT16 x, INT16 y )
207 SetCaretPos32( x, y );
211 /*****************************************************************
212 * SetCaretPos32 (USER32.465)
214 BOOL32 SetCaretPos32( INT32 x, INT32 y)
216 if (!Caret.hwnd) return FALSE;
217 if ((x == Caret.x) && (y == Caret.y)) return TRUE;
219 dprintf_caret(stddeb,"SetCaretPos: x=%d, y=%d\n", x, y);
221 CARET_KillTimer();
222 CARET_DisplayCaret(CARET_OFF);
223 Caret.x = x;
224 Caret.y = y;
225 if (!Caret.hidden)
227 CARET_DisplayCaret(CARET_ON);
228 CARET_SetTimer();
230 return TRUE;
234 /*****************************************************************
235 * HideCaret16 (USER.166)
237 void HideCaret16( HWND16 hwnd )
239 HideCaret32( hwnd );
243 /*****************************************************************
244 * HideCaret32 (USER32.316)
246 BOOL32 HideCaret32( HWND32 hwnd )
248 if (!Caret.hwnd) return FALSE;
249 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
251 dprintf_caret(stddeb,"HideCaret: hwnd=%04x, hidden=%d\n",
252 hwnd, Caret.hidden);
254 CARET_KillTimer();
255 CARET_DisplayCaret(CARET_OFF);
256 Caret.hidden++;
257 return TRUE;
261 /*****************************************************************
262 * ShowCaret16 (USER.167)
264 void ShowCaret16( HWND16 hwnd )
266 ShowCaret32( hwnd );
270 /*****************************************************************
271 * ShowCaret32 (USER32.528)
273 BOOL32 ShowCaret32( HWND32 hwnd )
275 if (!Caret.hwnd) return FALSE;
276 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
278 dprintf_caret(stddeb,"ShowCaret: hwnd=%04x, hidden=%d\n",
279 hwnd, Caret.hidden);
281 if (Caret.hidden)
283 Caret.hidden--;
284 if (!Caret.hidden)
286 CARET_DisplayCaret(CARET_ON);
287 CARET_SetTimer();
290 return TRUE;
294 /*****************************************************************
295 * SetCaretBlinkTime16 (USER.168)
297 void SetCaretBlinkTime16( UINT16 msecs )
299 SetCaretBlinkTime32( msecs );
302 /*****************************************************************
303 * SetCaretBlinkTime32 (USER32.464)
305 BOOL32 SetCaretBlinkTime32( UINT32 msecs )
307 if (!Caret.hwnd) return FALSE;
309 dprintf_caret(stddeb,"SetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
310 Caret.hwnd, msecs);
312 Caret.timeout = msecs;
313 CARET_ResetTimer();
314 return TRUE;
318 /*****************************************************************
319 * GetCaretBlinkTime16 (USER.169)
321 UINT16 GetCaretBlinkTime16(void)
323 return (UINT16)GetCaretBlinkTime32();
327 /*****************************************************************
328 * GetCaretBlinkTime32 (USER32.208)
330 UINT32 GetCaretBlinkTime32(void)
332 return Caret.timeout;
336 /*****************************************************************
337 * GetCaretPos16 (USER.183)
339 VOID GetCaretPos16( LPPOINT16 pt )
341 if (!Caret.hwnd || !pt) return;
343 dprintf_caret(stddeb,"GetCaretPos: hwnd=%04x, pt=%p, x=%d, y=%d\n",
344 Caret.hwnd, pt, Caret.x, Caret.y);
345 pt->x = (INT16)Caret.x;
346 pt->y = (INT16)Caret.y;
350 /*****************************************************************
351 * GetCaretPos32 (USER32.209)
353 BOOL32 GetCaretPos32( LPPOINT32 pt )
355 if (!Caret.hwnd || !pt) return FALSE;
356 pt->x = Caret.x;
357 pt->y = Caret.y;
358 return TRUE;