4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
9 #include "wine/winuser16.h"
34 static CARET Caret
= { 0, 0, FALSE
, 0, 0, 2, 12, 0, 500, 0 };
36 /*****************************************************************
39 HWND
CARET_GetHwnd(void)
44 /*****************************************************************
47 void CARET_GetRect(LPRECT lprc
)
49 lprc
->right
= (lprc
->left
= Caret
.x
) + Caret
.width
- 1;
50 lprc
->bottom
= (lprc
->top
= Caret
.y
) + Caret
.height
- 1;
53 /*****************************************************************
56 static void CARET_DisplayCaret( DISPLAY_CARET status
)
61 if (Caret
.on
&& (status
== CARET_ON
)) return;
62 if (!Caret
.on
&& (status
== CARET_OFF
)) return;
64 /* So now it's always a toggle */
67 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
68 if (!(hdc
= GetDCEx( Caret
.hwnd
, 0, DCX_USESTYLE
/*| DCX_CACHE*/ ))) return;
69 hPrevBrush
= SelectObject( hdc
, Caret
.hBrush
);
70 PatBlt( hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, PATINVERT
);
71 SelectObject( hdc
, hPrevBrush
);
72 ReleaseDC( Caret
.hwnd
, hdc
);
76 /*****************************************************************
79 static VOID CALLBACK
CARET_Callback( HWND hwnd
, UINT msg
, UINT id
, DWORD ctime
)
81 TRACE(caret
,"hwnd=%04x, timerid=%d, caret=%d\n",
83 CARET_DisplayCaret(CARET_TOGGLE
);
87 /*****************************************************************
90 static void CARET_SetTimer(void)
92 if (Caret
.timerid
) KillSystemTimer( (HWND
)0, Caret
.timerid
);
93 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
98 /*****************************************************************
101 static void CARET_ResetTimer(void)
105 KillSystemTimer( (HWND
)0, Caret
.timerid
);
106 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
112 /*****************************************************************
115 static void CARET_KillTimer(void)
119 KillSystemTimer( (HWND
)0, Caret
.timerid
);
125 /*****************************************************************
126 * CreateCaret16 (USER.163)
128 void WINAPI
CreateCaret16( HWND16 hwnd
, HBITMAP16 bitmap
,
129 INT16 width
, INT16 height
)
131 CreateCaret( hwnd
, bitmap
, width
, height
);
134 /*****************************************************************
135 * CreateCaret32 (USER32.66)
137 BOOL WINAPI
CreateCaret( HWND hwnd
, HBITMAP bitmap
,
138 INT width
, INT height
)
140 TRACE(caret
,"hwnd=%04x\n", hwnd
);
142 if (!hwnd
) return FALSE
;
144 /* if cursor already exists, destroy it */
145 if (Caret
.hwnd
) DestroyCaret();
147 if (bitmap
&& (bitmap
!= 1))
150 if (!GetObject16( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
151 Caret
.width
= bmp
.bmWidth
;
152 Caret
.height
= bmp
.bmHeight
;
153 /* FIXME: we should make a copy of the bitmap instead of a brush */
154 Caret
.hBrush
= CreatePatternBrush( bitmap
);
158 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
159 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
160 Caret
.hBrush
= CreateSolidBrush(bitmap
?
161 GetSysColor(COLOR_GRAYTEXT
) :
162 GetSysColor(COLOR_WINDOW
) );
171 Caret
.timeout
= GetProfileIntA( "windows", "CursorBlinkRate", 500 );
176 /*****************************************************************
177 * DestroyCaret16 (USER.164)
179 void WINAPI
DestroyCaret16(void)
185 /*****************************************************************
186 * DestroyCaret32 (USER32.131)
188 BOOL WINAPI
DestroyCaret(void)
190 if (!Caret
.hwnd
) return FALSE
;
192 TRACE(caret
,"hwnd=%04x, timerid=%d\n",
193 Caret
.hwnd
, Caret
.timerid
);
196 CARET_DisplayCaret(CARET_OFF
);
197 DeleteObject( Caret
.hBrush
);
203 /*****************************************************************
204 * SetCaretPos16 (USER.165)
206 void WINAPI
SetCaretPos16( INT16 x
, INT16 y
)
212 /*****************************************************************
213 * SetCaretPos32 (USER32.466)
215 BOOL WINAPI
SetCaretPos( INT x
, INT y
)
217 if (!Caret
.hwnd
) return FALSE
;
218 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
220 TRACE(caret
,"x=%d, y=%d\n", x
, y
);
223 CARET_DisplayCaret(CARET_OFF
);
228 CARET_DisplayCaret(CARET_ON
);
235 /*****************************************************************
236 * HideCaret16 (USER.166)
238 void WINAPI
HideCaret16( HWND16 hwnd
)
244 /*****************************************************************
245 * HideCaret32 (USER32.317)
247 BOOL WINAPI
HideCaret( HWND hwnd
)
249 if (!Caret
.hwnd
) return FALSE
;
250 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
252 TRACE(caret
,"hwnd=%04x, hidden=%d\n",
256 CARET_DisplayCaret(CARET_OFF
);
262 /*****************************************************************
263 * ShowCaret16 (USER.167)
265 void WINAPI
ShowCaret16( HWND16 hwnd
)
271 /*****************************************************************
272 * ShowCaret32 (USER32.529)
274 BOOL WINAPI
ShowCaret( HWND hwnd
)
276 if (!Caret
.hwnd
) return FALSE
;
277 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
279 TRACE(caret
,"hwnd=%04x, hidden=%d\n",
287 CARET_DisplayCaret(CARET_ON
);
295 /*****************************************************************
296 * SetCaretBlinkTime16 (USER.168)
298 void WINAPI
SetCaretBlinkTime16( UINT16 msecs
)
300 SetCaretBlinkTime( msecs
);
303 /*****************************************************************
304 * SetCaretBlinkTime32 (USER32.465)
306 BOOL WINAPI
SetCaretBlinkTime( UINT msecs
)
308 if (!Caret
.hwnd
) return FALSE
;
310 TRACE(caret
,"hwnd=%04x, msecs=%d\n",
313 Caret
.timeout
= msecs
;
319 /*****************************************************************
320 * GetCaretBlinkTime16 (USER.169)
322 UINT16 WINAPI
GetCaretBlinkTime16(void)
324 return (UINT16
)GetCaretBlinkTime();
328 /*****************************************************************
329 * GetCaretBlinkTime32 (USER32.209)
331 UINT WINAPI
GetCaretBlinkTime(void)
333 return Caret
.timeout
;
337 /*****************************************************************
338 * GetCaretPos16 (USER.183)
340 VOID WINAPI
GetCaretPos16( LPPOINT16 pt
)
342 if (!Caret
.hwnd
|| !pt
) return;
344 TRACE(caret
,"hwnd=%04x, pt=%p, x=%d, y=%d\n",
345 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
346 pt
->x
= (INT16
)Caret
.x
;
347 pt
->y
= (INT16
)Caret
.y
;
351 /*****************************************************************
352 * GetCaretPos32 (USER32.210)
354 BOOL WINAPI
GetCaretPos( LPPOINT pt
)
356 if (!Caret
.hwnd
|| !pt
) return FALSE
;