4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
6 * Copyright 2001 Eric Pouech
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/wingdi16.h"
28 #include "wine/winuser16.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(caret
);
55 static CARET Caret
= { 0, 0, FALSE
, 0, 0, 2, 12, 0, 500, 0 };
57 /*****************************************************************
60 HWND
CARET_GetHwnd(void)
65 /*****************************************************************
68 void CARET_GetRect(LPRECT lprc
)
70 lprc
->right
= (lprc
->left
= Caret
.x
) + Caret
.width
- 1;
71 lprc
->bottom
= (lprc
->top
= Caret
.y
) + Caret
.height
- 1;
74 /*****************************************************************
77 static void CARET_DisplayCaret( DISPLAY_CARET status
)
82 if (Caret
.on
&& (status
== CARET_ON
)) return;
83 if (!Caret
.on
&& (status
== CARET_OFF
)) return;
85 /* So now it's always a toggle */
88 /* do not use DCX_CACHE here, for x,y,width,height are in logical units */
89 if (!(hdc
= GetDCEx( Caret
.hwnd
, 0, DCX_USESTYLE
/*| DCX_CACHE*/ ))) return;
90 hCompDC
= CreateCompatibleDC(hdc
);
95 hPrevBmp
= SelectObject(hCompDC
, Caret
.hBmp
);
96 BitBlt(hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, hCompDC
, 0, 0, SRCINVERT
);
97 SelectObject(hCompDC
, hPrevBmp
);
100 ReleaseDC( Caret
.hwnd
, hdc
);
104 /*****************************************************************
107 static VOID CALLBACK
CARET_Callback( HWND hwnd
, UINT msg
, UINT id
, DWORD ctime
)
109 TRACE("hwnd=%04x, timerid=%d, caret=%d\n",
111 CARET_DisplayCaret(CARET_TOGGLE
);
115 /*****************************************************************
118 static void CARET_SetTimer(void)
120 if (Caret
.timerid
) KillSystemTimer( (HWND
)0, Caret
.timerid
);
121 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
126 /*****************************************************************
129 static void CARET_ResetTimer(void)
133 KillSystemTimer( (HWND
)0, Caret
.timerid
);
134 Caret
.timerid
= SetSystemTimer( (HWND
)0, 0, Caret
.timeout
,
140 /*****************************************************************
143 static void CARET_KillTimer(void)
147 KillSystemTimer( (HWND
)0, Caret
.timerid
);
153 /*****************************************************************
154 * CreateCaret (USER32.@)
156 BOOL WINAPI
CreateCaret( HWND hwnd
, HBITMAP bitmap
,
157 INT width
, INT height
)
159 TRACE("hwnd=%04x\n", hwnd
);
161 if (!hwnd
) return FALSE
;
163 /* if cursor already exists, destroy it */
164 if (Caret
.hwnd
) DestroyCaret();
166 if (bitmap
&& (bitmap
!= 1))
169 if (!GetObjectA( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
170 Caret
.width
= bmp
.bmWidth
;
171 Caret
.height
= bmp
.bmHeight
;
173 Caret
.hBmp
= CreateBitmapIndirect(&bmp
);
177 /* copy the bitmap */
178 LPBYTE buf
= HeapAlloc(GetProcessHeap(), 0, bmp
.bmWidthBytes
* bmp
.bmHeight
);
179 GetBitmapBits(bitmap
, bmp
.bmWidthBytes
* bmp
.bmHeight
, buf
);
180 SetBitmapBits(Caret
.hBmp
, bmp
.bmWidthBytes
* bmp
.bmHeight
, buf
);
181 HeapFree(GetProcessHeap(), 0, buf
);
188 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
189 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
192 /* create the uniform bitmap on the fly */
196 HDC hMemDC
= CreateCompatibleDC(hdc
);
202 r
.right
= Caret
.width
;
203 r
.bottom
= Caret
.height
;
205 if ((Caret
.hBmp
= CreateCompatibleBitmap(hMemDC
, Caret
.width
, Caret
.height
)))
207 HBITMAP hPrevBmp
= SelectObject(hMemDC
, Caret
.hBmp
);
208 FillRect(hMemDC
, &r
, (bitmap
? COLOR_GRAYTEXT
: COLOR_WINDOW
) + 1);
209 SelectObject(hMemDC
, hPrevBmp
);
213 ReleaseDC(hwnd
, hdc
);
217 Caret
.hwnd
= WIN_GetFullHandle( hwnd
);
223 Caret
.timeout
= GetProfileIntA( "windows", "CursorBlinkRate", 500 );
228 /*****************************************************************
229 * DestroyCaret (USER.164)
231 void WINAPI
DestroyCaret16(void)
237 /*****************************************************************
238 * DestroyCaret (USER32.@)
240 BOOL WINAPI
DestroyCaret(void)
242 if (!Caret
.hwnd
) return FALSE
;
244 TRACE("hwnd=%04x, timerid=%d\n",
245 Caret
.hwnd
, Caret
.timerid
);
248 CARET_DisplayCaret(CARET_OFF
);
249 DeleteObject( Caret
.hBmp
);
255 /*****************************************************************
256 * SetCaretPos (USER.165)
258 void WINAPI
SetCaretPos16( INT16 x
, INT16 y
)
264 /*****************************************************************
265 * SetCaretPos (USER32.@)
267 BOOL WINAPI
SetCaretPos( INT x
, INT y
)
269 if (!Caret
.hwnd
) return FALSE
;
270 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
272 TRACE("x=%d, y=%d\n", x
, y
);
275 CARET_DisplayCaret(CARET_OFF
);
280 CARET_DisplayCaret(CARET_ON
);
287 /*****************************************************************
288 * HideCaret (USER32.@)
290 BOOL WINAPI
HideCaret( HWND hwnd
)
292 if (!Caret
.hwnd
) return FALSE
;
293 if (hwnd
&& (Caret
.hwnd
!= WIN_GetFullHandle(hwnd
))) return FALSE
;
295 TRACE("hwnd=%04x, hidden=%d\n",
299 CARET_DisplayCaret(CARET_OFF
);
305 /*****************************************************************
306 * ShowCaret (USER32.@)
308 BOOL WINAPI
ShowCaret( HWND hwnd
)
310 if (!Caret
.hwnd
) return FALSE
;
311 if (hwnd
&& (Caret
.hwnd
!= WIN_GetFullHandle(hwnd
))) return FALSE
;
313 TRACE("hwnd=%04x, hidden=%d\n",
321 CARET_DisplayCaret(CARET_ON
);
329 /*****************************************************************
330 * SetCaretBlinkTime (USER.168)
332 void WINAPI
SetCaretBlinkTime16( UINT16 msecs
)
334 SetCaretBlinkTime( msecs
);
337 /*****************************************************************
338 * SetCaretBlinkTime (USER32.@)
340 BOOL WINAPI
SetCaretBlinkTime( UINT msecs
)
342 if (!Caret
.hwnd
) return FALSE
;
344 TRACE("hwnd=%04x, msecs=%d\n",
347 Caret
.timeout
= msecs
;
353 /*****************************************************************
354 * GetCaretBlinkTime (USER.169)
356 UINT16 WINAPI
GetCaretBlinkTime16(void)
358 return (UINT16
)GetCaretBlinkTime();
362 /*****************************************************************
363 * GetCaretBlinkTime (USER32.@)
365 UINT WINAPI
GetCaretBlinkTime(void)
367 return Caret
.timeout
;
371 /*****************************************************************
372 * GetCaretPos (USER.183)
374 VOID WINAPI
GetCaretPos16( LPPOINT16 pt
)
376 if (!Caret
.hwnd
|| !pt
) return;
378 TRACE("hwnd=%04x, pt=%p, x=%d, y=%d\n",
379 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
380 pt
->x
= (INT16
)Caret
.x
;
381 pt
->y
= (INT16
)Caret
.y
;
385 /*****************************************************************
386 * GetCaretPos (USER32.@)
388 BOOL WINAPI
GetCaretPos( LPPOINT pt
)
390 if (!Caret
.hwnd
|| !pt
) return FALSE
;