4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
12 DEFAULT_DEBUG_CHANNEL(caret)
35 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
37 /*****************************************************************
40 HWND CARET_GetHwnd(void)
45 /*****************************************************************
48 void CARET_GetRect(LPRECT lprc)
50 lprc->right = (lprc->left = Caret.x) + Caret.width - 1;
51 lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1;
54 /*****************************************************************
57 static void CARET_DisplayCaret( DISPLAY_CARET status )
62 if (Caret.on && (status == CARET_ON)) return;
63 if (!Caret.on && (status == CARET_OFF)) return;
65 /* So now it's always a toggle */
68 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
69 if (!(hdc = GetDCEx( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return;
70 hPrevBrush = SelectObject( hdc, Caret.hBrush );
71 PatBlt( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
72 SelectObject( hdc, hPrevBrush );
73 ReleaseDC( Caret.hwnd, hdc );
77 /*****************************************************************
80 static VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime)
82 TRACE(caret,"hwnd=%04x, timerid=%d, caret=%d\n",
84 CARET_DisplayCaret(CARET_TOGGLE);
88 /*****************************************************************
91 static void CARET_SetTimer(void)
93 if (Caret.timerid) KillSystemTimer( (HWND)0, Caret.timerid );
94 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
99 /*****************************************************************
102 static void CARET_ResetTimer(void)
106 KillSystemTimer( (HWND)0, Caret.timerid );
107 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
113 /*****************************************************************
116 static void CARET_KillTimer(void)
120 KillSystemTimer( (HWND)0, Caret.timerid );
126 /*****************************************************************
127 * CreateCaret16 (USER.163)
129 void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap,
130 INT16 width, INT16 height )
132 CreateCaret( hwnd, bitmap, width, height );
135 /*****************************************************************
136 * CreateCaret32 (USER32.66)
138 BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap,
139 INT width, INT height )
141 TRACE(caret,"hwnd=%04x\n", hwnd);
143 if (!hwnd) return FALSE;
145 /* if cursor already exists, destroy it */
146 if (Caret.hwnd) DestroyCaret();
148 if (bitmap && (bitmap != 1))
151 if (!GetObject16( bitmap, sizeof(bmp), &bmp )) return FALSE;
152 Caret.width = bmp.bmWidth;
153 Caret.height = bmp.bmHeight;
154 /* FIXME: we should make a copy of the bitmap instead of a brush */
155 Caret.hBrush = CreatePatternBrush( bitmap );
159 Caret.width = width ? width : GetSystemMetrics(SM_CXBORDER);
160 Caret.height = height ? height : GetSystemMetrics(SM_CYBORDER);
161 Caret.hBrush = CreateSolidBrush(bitmap ?
162 GetSysColor(COLOR_GRAYTEXT) :
163 GetSysColor(COLOR_WINDOW) );
172 Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
177 /*****************************************************************
178 * DestroyCaret16 (USER.164)
180 void WINAPI DestroyCaret16(void)
186 /*****************************************************************
187 * DestroyCaret32 (USER32.131)
189 BOOL WINAPI DestroyCaret(void)
191 if (!Caret.hwnd) return FALSE;
193 TRACE(caret,"hwnd=%04x, timerid=%d\n",
194 Caret.hwnd, Caret.timerid);
197 CARET_DisplayCaret(CARET_OFF);
198 DeleteObject( Caret.hBrush );
204 /*****************************************************************
205 * SetCaretPos16 (USER.165)
207 void WINAPI SetCaretPos16( INT16 x, INT16 y )
213 /*****************************************************************
214 * SetCaretPos32 (USER32.466)
216 BOOL WINAPI SetCaretPos( INT x, INT y)
218 if (!Caret.hwnd) return FALSE;
219 if ((x == Caret.x) && (y == Caret.y)) return TRUE;
221 TRACE(caret,"x=%d, y=%d\n", x, y);
224 CARET_DisplayCaret(CARET_OFF);
229 CARET_DisplayCaret(CARET_ON);
236 /*****************************************************************
237 * HideCaret16 (USER.166)
239 void WINAPI HideCaret16( HWND16 hwnd )
245 /*****************************************************************
246 * HideCaret32 (USER32.317)
248 BOOL WINAPI HideCaret( HWND hwnd )
250 if (!Caret.hwnd) return FALSE;
251 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
253 TRACE(caret,"hwnd=%04x, hidden=%d\n",
257 CARET_DisplayCaret(CARET_OFF);
263 /*****************************************************************
264 * ShowCaret16 (USER.167)
266 void WINAPI ShowCaret16( HWND16 hwnd )
272 /*****************************************************************
273 * ShowCaret32 (USER32.529)
275 BOOL WINAPI ShowCaret( HWND hwnd )
277 if (!Caret.hwnd) return FALSE;
278 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
280 TRACE(caret,"hwnd=%04x, hidden=%d\n",
288 CARET_DisplayCaret(CARET_ON);
296 /*****************************************************************
297 * SetCaretBlinkTime16 (USER.168)
299 void WINAPI SetCaretBlinkTime16( UINT16 msecs )
301 SetCaretBlinkTime( msecs );
304 /*****************************************************************
305 * SetCaretBlinkTime32 (USER32.465)
307 BOOL WINAPI SetCaretBlinkTime( UINT msecs )
309 if (!Caret.hwnd) return FALSE;
311 TRACE(caret,"hwnd=%04x, msecs=%d\n",
314 Caret.timeout = msecs;
320 /*****************************************************************
321 * GetCaretBlinkTime16 (USER.169)
323 UINT16 WINAPI GetCaretBlinkTime16(void)
325 return (UINT16)GetCaretBlinkTime();
329 /*****************************************************************
330 * GetCaretBlinkTime32 (USER32.209)
332 UINT WINAPI GetCaretBlinkTime(void)
334 return Caret.timeout;
338 /*****************************************************************
339 * GetCaretPos16 (USER.183)
341 VOID WINAPI GetCaretPos16( LPPOINT16 pt )
343 if (!Caret.hwnd || !pt) return;
345 TRACE(caret,"hwnd=%04x, pt=%p, x=%d, y=%d\n",
346 Caret.hwnd, pt, Caret.x, Caret.y);
347 pt->x = (INT16)Caret.x;
348 pt->y = (INT16)Caret.y;
352 /*****************************************************************
353 * GetCaretPos32 (USER32.210)
355 BOOL WINAPI GetCaretPos( LPPOINT pt )
357 if (!Caret.hwnd || !pt) return FALSE;