4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
11 #include "wine/wingdi16.h"
13 DEFAULT_DEBUG_CHANNEL(caret)
36 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
38 /*****************************************************************
41 HWND CARET_GetHwnd(void)
46 /*****************************************************************
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 /*****************************************************************
58 static void CARET_DisplayCaret( DISPLAY_CARET status )
63 if (Caret.on && (status == CARET_ON)) return;
64 if (!Caret.on && (status == CARET_OFF)) return;
66 /* So now it's always a toggle */
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 /*****************************************************************
81 static VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime)
83 TRACE(caret,"hwnd=%04x, timerid=%d, caret=%d\n",
85 CARET_DisplayCaret(CARET_TOGGLE);
89 /*****************************************************************
92 static void CARET_SetTimer(void)
94 if (Caret.timerid) KillSystemTimer( (HWND)0, Caret.timerid );
95 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
100 /*****************************************************************
103 static void CARET_ResetTimer(void)
107 KillSystemTimer( (HWND)0, Caret.timerid );
108 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
114 /*****************************************************************
117 static void CARET_KillTimer(void)
121 KillSystemTimer( (HWND)0, Caret.timerid );
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))
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 );
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) );
173 Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
178 /*****************************************************************
179 * DestroyCaret16 (USER.164)
181 void WINAPI DestroyCaret16(void)
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);
198 CARET_DisplayCaret(CARET_OFF);
199 DeleteObject( Caret.hBrush );
205 /*****************************************************************
206 * SetCaretPos16 (USER.165)
208 void WINAPI SetCaretPos16( INT16 x, INT16 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);
225 CARET_DisplayCaret(CARET_OFF);
230 CARET_DisplayCaret(CARET_ON);
237 /*****************************************************************
238 * HideCaret16 (USER.166)
240 void WINAPI HideCaret16( HWND16 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",
258 CARET_DisplayCaret(CARET_OFF);
264 /*****************************************************************
265 * ShowCaret16 (USER.167)
267 void WINAPI ShowCaret16( HWND16 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",
289 CARET_DisplayCaret(CARET_ON);
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",
315 Caret.timeout = msecs;
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;