4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
8 #include "wine/wingdi16.h"
9 #include "wine/winuser16.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(caret)
38 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
40 /*****************************************************************
43 HWND CARET_GetHwnd(void)
48 /*****************************************************************
51 void CARET_GetRect(LPRECT lprc)
53 lprc->right = (lprc->left = Caret.x) + Caret.width - 1;
54 lprc->bottom = (lprc->top = Caret.y) + Caret.height - 1;
57 /*****************************************************************
60 static void CARET_DisplayCaret( DISPLAY_CARET status )
65 if (Caret.on && (status == CARET_ON)) return;
66 if (!Caret.on && (status == CARET_OFF)) return;
68 /* So now it's always a toggle */
71 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
72 if (!(hdc = GetDCEx( Caret.hwnd, 0, DCX_USESTYLE /*| DCX_CACHE*/ ))) return;
73 hPrevBrush = SelectObject( hdc, Caret.hBrush );
74 PatBlt( hdc, Caret.x, Caret.y, Caret.width, Caret.height, PATINVERT );
75 SelectObject( hdc, hPrevBrush );
76 ReleaseDC( Caret.hwnd, hdc );
80 /*****************************************************************
83 static VOID CALLBACK CARET_Callback( HWND hwnd, UINT msg, UINT id, DWORD ctime)
85 TRACE("hwnd=%04x, timerid=%d, caret=%d\n",
87 CARET_DisplayCaret(CARET_TOGGLE);
91 /*****************************************************************
94 static void CARET_SetTimer(void)
96 if (Caret.timerid) KillSystemTimer( (HWND)0, Caret.timerid );
97 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
102 /*****************************************************************
105 static void CARET_ResetTimer(void)
109 KillSystemTimer( (HWND)0, Caret.timerid );
110 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
116 /*****************************************************************
119 static void CARET_KillTimer(void)
123 KillSystemTimer( (HWND)0, Caret.timerid );
129 /*****************************************************************
130 * CreateCaret16 (USER.163)
132 void WINAPI CreateCaret16( HWND16 hwnd, HBITMAP16 bitmap,
133 INT16 width, INT16 height )
135 CreateCaret( hwnd, bitmap, width, height );
138 /*****************************************************************
139 * CreateCaret32 (USER32.66)
141 BOOL WINAPI CreateCaret( HWND hwnd, HBITMAP bitmap,
142 INT width, INT height )
144 TRACE("hwnd=%04x\n", hwnd);
146 if (!hwnd) return FALSE;
148 /* if cursor already exists, destroy it */
149 if (Caret.hwnd) DestroyCaret();
151 if (bitmap && (bitmap != 1))
154 if (!GetObject16( bitmap, sizeof(bmp), &bmp )) return FALSE;
155 Caret.width = bmp.bmWidth;
156 Caret.height = bmp.bmHeight;
157 /* FIXME: we should make a copy of the bitmap instead of a brush */
158 Caret.hBrush = CreatePatternBrush( bitmap );
162 Caret.width = width ? width : GetSystemMetrics(SM_CXBORDER);
163 Caret.height = height ? height : GetSystemMetrics(SM_CYBORDER);
164 Caret.hBrush = CreateSolidBrush(bitmap ?
165 GetSysColor(COLOR_GRAYTEXT) :
166 GetSysColor(COLOR_WINDOW) );
175 Caret.timeout = GetProfileIntA( "windows", "CursorBlinkRate", 500 );
180 /*****************************************************************
181 * DestroyCaret16 (USER.164)
183 void WINAPI DestroyCaret16(void)
189 /*****************************************************************
190 * DestroyCaret32 (USER32.131)
192 BOOL WINAPI DestroyCaret(void)
194 if (!Caret.hwnd) return FALSE;
196 TRACE("hwnd=%04x, timerid=%d\n",
197 Caret.hwnd, Caret.timerid);
200 CARET_DisplayCaret(CARET_OFF);
201 DeleteObject( Caret.hBrush );
207 /*****************************************************************
208 * SetCaretPos16 (USER.165)
210 void WINAPI SetCaretPos16( INT16 x, INT16 y )
216 /*****************************************************************
217 * SetCaretPos32 (USER32.466)
219 BOOL WINAPI SetCaretPos( INT x, INT y)
221 if (!Caret.hwnd) return FALSE;
222 if ((x == Caret.x) && (y == Caret.y)) return TRUE;
224 TRACE("x=%d, y=%d\n", x, y);
227 CARET_DisplayCaret(CARET_OFF);
232 CARET_DisplayCaret(CARET_ON);
239 /*****************************************************************
240 * HideCaret16 (USER.166)
242 void WINAPI HideCaret16( HWND16 hwnd )
248 /*****************************************************************
249 * HideCaret32 (USER32.317)
251 BOOL WINAPI HideCaret( HWND hwnd )
253 if (!Caret.hwnd) return FALSE;
254 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
256 TRACE("hwnd=%04x, hidden=%d\n",
260 CARET_DisplayCaret(CARET_OFF);
266 /*****************************************************************
267 * ShowCaret16 (USER.167)
269 void WINAPI ShowCaret16( HWND16 hwnd )
275 /*****************************************************************
276 * ShowCaret32 (USER32.529)
278 BOOL WINAPI ShowCaret( HWND hwnd )
280 if (!Caret.hwnd) return FALSE;
281 if (hwnd && (Caret.hwnd != hwnd)) return FALSE;
283 TRACE("hwnd=%04x, hidden=%d\n",
291 CARET_DisplayCaret(CARET_ON);
299 /*****************************************************************
300 * SetCaretBlinkTime16 (USER.168)
302 void WINAPI SetCaretBlinkTime16( UINT16 msecs )
304 SetCaretBlinkTime( msecs );
307 /*****************************************************************
308 * SetCaretBlinkTime32 (USER32.465)
310 BOOL WINAPI SetCaretBlinkTime( UINT msecs )
312 if (!Caret.hwnd) return FALSE;
314 TRACE("hwnd=%04x, msecs=%d\n",
317 Caret.timeout = msecs;
323 /*****************************************************************
324 * GetCaretBlinkTime16 (USER.169)
326 UINT16 WINAPI GetCaretBlinkTime16(void)
328 return (UINT16)GetCaretBlinkTime();
332 /*****************************************************************
333 * GetCaretBlinkTime32 (USER32.209)
335 UINT WINAPI GetCaretBlinkTime(void)
337 return Caret.timeout;
341 /*****************************************************************
342 * GetCaretPos16 (USER.183)
344 VOID WINAPI GetCaretPos16( LPPOINT16 pt )
346 if (!Caret.hwnd || !pt) return;
348 TRACE("hwnd=%04x, pt=%p, x=%d, y=%d\n",
349 Caret.hwnd, pt, Caret.x, Caret.y);
350 pt->x = (INT16)Caret.x;
351 pt->y = (INT16)Caret.y;
355 /*****************************************************************
356 * GetCaretPos32 (USER32.210)
358 BOOL WINAPI GetCaretPos( LPPOINT pt )
360 if (!Caret.hwnd || !pt) return FALSE;