4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
10 #include "wine/wingdi16.h"
11 #include "wine/winuser16.h"
15 #include "debugtools.h"
17 DEFAULT_DEBUG_CHANNEL(caret
)
40 static CARET Caret
= { 0, 0, FALSE
, 0, 0, 2, 12, 0, 500, 0 };
42 /*****************************************************************
45 HWND
CARET_GetHwnd(void)
50 /*****************************************************************
53 void CARET_GetRect(LPRECT lprc
)
55 lprc
->right
= (lprc
->left
= Caret
.x
) + Caret
.width
- 1;
56 lprc
->bottom
= (lprc
->top
= Caret
.y
) + Caret
.height
- 1;
59 /*****************************************************************
62 static void CARET_DisplayCaret( DISPLAY_CARET status
)
67 if (Caret
.on
&& (status
== CARET_ON
)) return;
68 if (!Caret
.on
&& (status
== CARET_OFF
)) return;
70 /* So now it's always a toggle */
73 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
74 if (!(hdc
= GetDCEx( Caret
.hwnd
, 0, DCX_USESTYLE
/*| DCX_CACHE*/ ))) return;
75 hPrevBrush
= SelectObject( hdc
, Caret
.hBrush
);
76 PatBlt( hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, PATINVERT
);
77 SelectObject( hdc
, hPrevBrush
);
78 ReleaseDC( Caret
.hwnd
, hdc
);
82 /*****************************************************************
85 static VOID CALLBACK
CARET_Callback( HWND hwnd
, UINT msg
, UINT id
, DWORD ctime
)
87 TRACE("hwnd=%04x, timerid=%d, caret=%d\n",
89 CARET_DisplayCaret(CARET_TOGGLE
);
93 /*****************************************************************
96 static void CARET_SetTimer(void)
98 if (Caret
.timerid
) KillSystemTimer( (HWND
)0, Caret
.timerid
);
99 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
104 /*****************************************************************
107 static void CARET_ResetTimer(void)
111 KillSystemTimer( (HWND
)0, Caret
.timerid
);
112 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
118 /*****************************************************************
121 static void CARET_KillTimer(void)
125 KillSystemTimer( (HWND
)0, Caret
.timerid
);
131 /*****************************************************************
132 * CreateCaret16 (USER.163)
134 void WINAPI
CreateCaret16( HWND16 hwnd
, HBITMAP16 bitmap
,
135 INT16 width
, INT16 height
)
137 CreateCaret( hwnd
, bitmap
, width
, height
);
140 /*****************************************************************
141 * CreateCaret (USER32.66)
143 BOOL WINAPI
CreateCaret( HWND hwnd
, HBITMAP bitmap
,
144 INT width
, INT height
)
146 TRACE("hwnd=%04x\n", hwnd
);
148 if (!hwnd
) return FALSE
;
150 /* if cursor already exists, destroy it */
151 if (Caret
.hwnd
) DestroyCaret();
153 if (bitmap
&& (bitmap
!= 1))
156 if (!GetObject16( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
157 Caret
.width
= bmp
.bmWidth
;
158 Caret
.height
= bmp
.bmHeight
;
159 /* FIXME: we should make a copy of the bitmap instead of a brush */
160 Caret
.hBrush
= CreatePatternBrush( bitmap
);
164 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
165 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
166 Caret
.hBrush
= CreateSolidBrush(bitmap
?
167 GetSysColor(COLOR_GRAYTEXT
) :
168 GetSysColor(COLOR_WINDOW
) );
177 Caret
.timeout
= GetProfileIntA( "windows", "CursorBlinkRate", 500 );
182 /*****************************************************************
183 * DestroyCaret16 (USER.164)
185 void WINAPI
DestroyCaret16(void)
191 /*****************************************************************
192 * DestroyCaret (USER32.131)
194 BOOL WINAPI
DestroyCaret(void)
196 if (!Caret
.hwnd
) return FALSE
;
198 TRACE("hwnd=%04x, timerid=%d\n",
199 Caret
.hwnd
, Caret
.timerid
);
202 CARET_DisplayCaret(CARET_OFF
);
203 DeleteObject( Caret
.hBrush
);
209 /*****************************************************************
210 * SetCaretPos16 (USER.165)
212 void WINAPI
SetCaretPos16( INT16 x
, INT16 y
)
218 /*****************************************************************
219 * SetCaretPos (USER32.466)
221 BOOL WINAPI
SetCaretPos( INT x
, INT y
)
223 if (!Caret
.hwnd
) return FALSE
;
224 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
226 TRACE("x=%d, y=%d\n", x
, y
);
229 CARET_DisplayCaret(CARET_OFF
);
234 CARET_DisplayCaret(CARET_ON
);
241 /*****************************************************************
242 * HideCaret16 (USER.166)
244 void WINAPI
HideCaret16( HWND16 hwnd
)
250 /*****************************************************************
251 * HideCaret (USER32.317)
253 BOOL WINAPI
HideCaret( HWND hwnd
)
255 if (!Caret
.hwnd
) return FALSE
;
256 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
258 TRACE("hwnd=%04x, hidden=%d\n",
262 CARET_DisplayCaret(CARET_OFF
);
268 /*****************************************************************
269 * ShowCaret16 (USER.167)
271 void WINAPI
ShowCaret16( HWND16 hwnd
)
277 /*****************************************************************
278 * ShowCaret (USER32.529)
280 BOOL WINAPI
ShowCaret( HWND hwnd
)
282 if (!Caret
.hwnd
) return FALSE
;
283 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
285 TRACE("hwnd=%04x, hidden=%d\n",
293 CARET_DisplayCaret(CARET_ON
);
301 /*****************************************************************
302 * SetCaretBlinkTime16 (USER.168)
304 void WINAPI
SetCaretBlinkTime16( UINT16 msecs
)
306 SetCaretBlinkTime( msecs
);
309 /*****************************************************************
310 * SetCaretBlinkTime (USER32.465)
312 BOOL WINAPI
SetCaretBlinkTime( UINT msecs
)
314 if (!Caret
.hwnd
) return FALSE
;
316 TRACE("hwnd=%04x, msecs=%d\n",
319 Caret
.timeout
= msecs
;
325 /*****************************************************************
326 * GetCaretBlinkTime16 (USER.169)
328 UINT16 WINAPI
GetCaretBlinkTime16(void)
330 return (UINT16
)GetCaretBlinkTime();
334 /*****************************************************************
335 * GetCaretBlinkTime (USER32.209)
337 UINT WINAPI
GetCaretBlinkTime(void)
339 return Caret
.timeout
;
343 /*****************************************************************
344 * GetCaretPos16 (USER.183)
346 VOID WINAPI
GetCaretPos16( LPPOINT16 pt
)
348 if (!Caret
.hwnd
|| !pt
) return;
350 TRACE("hwnd=%04x, pt=%p, x=%d, y=%d\n",
351 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
352 pt
->x
= (INT16
)Caret
.x
;
353 pt
->y
= (INT16
)Caret
.y
;
357 /*****************************************************************
358 * GetCaretPos (USER32.210)
360 BOOL WINAPI
GetCaretPos( LPPOINT pt
)
362 if (!Caret
.hwnd
|| !pt
) return FALSE
;