4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
12 #include "wine/wingdi16.h"
13 #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 * CreateCaret (USER32.@)
134 BOOL WINAPI
CreateCaret( HWND hwnd
, HBITMAP bitmap
,
135 INT width
, INT height
)
137 TRACE("hwnd=%04x\n", hwnd
);
139 if (!hwnd
) return FALSE
;
141 /* if cursor already exists, destroy it */
142 if (Caret
.hwnd
) DestroyCaret();
144 if (bitmap
&& (bitmap
!= 1))
147 if (!GetObjectA( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
148 Caret
.width
= bmp
.bmWidth
;
149 Caret
.height
= bmp
.bmHeight
;
150 /* FIXME: we should make a copy of the bitmap instead of a brush */
151 Caret
.hBrush
= CreatePatternBrush( bitmap
);
155 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
156 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
157 Caret
.hBrush
= CreateSolidBrush(bitmap
?
158 GetSysColor(COLOR_GRAYTEXT
) :
159 GetSysColor(COLOR_WINDOW
) );
162 Caret
.hwnd
= WIN_GetFullHandle( hwnd
);
168 Caret
.timeout
= GetProfileIntA( "windows", "CursorBlinkRate", 500 );
173 /*****************************************************************
174 * DestroyCaret (USER.164)
176 void WINAPI
DestroyCaret16(void)
182 /*****************************************************************
183 * DestroyCaret (USER32.@)
185 BOOL WINAPI
DestroyCaret(void)
187 if (!Caret
.hwnd
) return FALSE
;
189 TRACE("hwnd=%04x, timerid=%d\n",
190 Caret
.hwnd
, Caret
.timerid
);
193 CARET_DisplayCaret(CARET_OFF
);
194 DeleteObject( Caret
.hBrush
);
200 /*****************************************************************
201 * SetCaretPos (USER.165)
203 void WINAPI
SetCaretPos16( INT16 x
, INT16 y
)
209 /*****************************************************************
210 * SetCaretPos (USER32.@)
212 BOOL WINAPI
SetCaretPos( INT x
, INT y
)
214 if (!Caret
.hwnd
) return FALSE
;
215 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
217 TRACE("x=%d, y=%d\n", x
, y
);
220 CARET_DisplayCaret(CARET_OFF
);
225 CARET_DisplayCaret(CARET_ON
);
232 /*****************************************************************
233 * HideCaret (USER32.@)
235 BOOL WINAPI
HideCaret( HWND hwnd
)
237 if (!Caret
.hwnd
) return FALSE
;
238 if (hwnd
&& (Caret
.hwnd
!= WIN_GetFullHandle(hwnd
))) return FALSE
;
240 TRACE("hwnd=%04x, hidden=%d\n",
244 CARET_DisplayCaret(CARET_OFF
);
250 /*****************************************************************
251 * ShowCaret (USER32.@)
253 BOOL WINAPI
ShowCaret( HWND hwnd
)
255 if (!Caret
.hwnd
) return FALSE
;
256 if (hwnd
&& (Caret
.hwnd
!= WIN_GetFullHandle(hwnd
))) return FALSE
;
258 TRACE("hwnd=%04x, hidden=%d\n",
266 CARET_DisplayCaret(CARET_ON
);
274 /*****************************************************************
275 * SetCaretBlinkTime (USER.168)
277 void WINAPI
SetCaretBlinkTime16( UINT16 msecs
)
279 SetCaretBlinkTime( msecs
);
282 /*****************************************************************
283 * SetCaretBlinkTime (USER32.@)
285 BOOL WINAPI
SetCaretBlinkTime( UINT msecs
)
287 if (!Caret
.hwnd
) return FALSE
;
289 TRACE("hwnd=%04x, msecs=%d\n",
292 Caret
.timeout
= msecs
;
298 /*****************************************************************
299 * GetCaretBlinkTime (USER.169)
301 UINT16 WINAPI
GetCaretBlinkTime16(void)
303 return (UINT16
)GetCaretBlinkTime();
307 /*****************************************************************
308 * GetCaretBlinkTime (USER32.@)
310 UINT WINAPI
GetCaretBlinkTime(void)
312 return Caret
.timeout
;
316 /*****************************************************************
317 * GetCaretPos (USER.183)
319 VOID WINAPI
GetCaretPos16( LPPOINT16 pt
)
321 if (!Caret
.hwnd
|| !pt
) return;
323 TRACE("hwnd=%04x, pt=%p, x=%d, y=%d\n",
324 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
325 pt
->x
= (INT16
)Caret
.x
;
326 pt
->y
= (INT16
)Caret
.y
;
330 /*****************************************************************
331 * GetCaretPos (USER32.@)
333 BOOL WINAPI
GetCaretPos( LPPOINT pt
)
335 if (!Caret
.hwnd
|| !pt
) return FALSE
;