4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
11 /* #define DEBUG_CARET */
36 static CARET Caret
= { 0, 0, FALSE
, 0, 0, 2, 12, 0, 500, 0 };
39 /*****************************************************************
42 HWND32
CARET_GetHwnd()
47 /*****************************************************************
50 static void CARET_DisplayCaret( DISPLAY_CARET status
)
55 if (Caret
.on
&& (status
== CARET_ON
)) return;
56 if (!Caret
.on
&& (status
== CARET_OFF
)) return;
58 /* So now it's always a toggle */
61 if (!(hdc
= GetDCEx32( Caret
.hwnd
, 0, DCX_USESTYLE
| DCX_CACHE
))) return;
62 hPrevBrush
= SelectObject32( hdc
, Caret
.hBrush
);
63 PatBlt32( hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, PATINVERT
);
64 SelectObject32( hdc
, hPrevBrush
);
65 ReleaseDC32( Caret
.hwnd
, hdc
);
69 /*****************************************************************
72 static VOID
CARET_Callback( HWND32 hwnd
, UINT32 msg
, UINT32 id
, DWORD ctime
)
74 dprintf_caret(stddeb
,"CARET_Callback: hwnd=%04x, timerid=%d, caret=%d\n",
76 CARET_DisplayCaret(CARET_TOGGLE
);
80 /*****************************************************************
83 static void CARET_SetTimer(void)
85 if (Caret
.timerid
) KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
86 Caret
.timerid
= SetSystemTimer32( (HWND32
)0, 0, Caret
.timeout
,
91 /*****************************************************************
94 static void CARET_ResetTimer(void)
98 KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
99 Caret
.timerid
= SetSystemTimer32( (HWND32
)0, 0, Caret
.timeout
,
105 /*****************************************************************
108 static void CARET_KillTimer(void)
112 KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
118 /*****************************************************************
119 * CreateCaret (USER.163) (USER32.65)
121 BOOL16
CreateCaret( HWND32 hwnd
, HBITMAP32 bitmap
, INT32 width
, INT32 height
)
123 dprintf_caret(stddeb
,"CreateCaret: hwnd=%04x\n", hwnd
);
125 if (!hwnd
) return FALSE
;
127 /* if cursor already exists, destroy it */
128 if (Caret
.hwnd
) DestroyCaret();
130 if (bitmap
&& (bitmap
!= 1))
133 if (!GetObject16( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
134 Caret
.width
= bmp
.bmWidth
;
135 Caret
.height
= bmp
.bmHeight
;
136 /* FIXME: we should make a copy of the bitmap instead of a brush */
137 Caret
.hBrush
= CreatePatternBrush32( bitmap
);
141 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
142 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
143 Caret
.hBrush
= CreateSolidBrush32(bitmap
? GetSysColor(COLOR_GRAYTEXT
):
144 GetSysColor(COLOR_WINDOW
) );
153 Caret
.timeout
= GetProfileInt32A( "windows", "CursorBlinkRate", 500 );
158 /*****************************************************************
159 * DestroyCaret (USER.164) (USER32.130)
161 BOOL16
DestroyCaret(void)
163 if (!Caret
.hwnd
) return FALSE
;
165 dprintf_caret(stddeb
,"DestroyCaret: hwnd=%04x, timerid=%d\n",
166 Caret
.hwnd
, Caret
.timerid
);
168 DeleteObject32( Caret
.hBrush
);
170 CARET_DisplayCaret(CARET_OFF
);
176 /*****************************************************************
177 * SetCaretPos (USER.165) (USER32.465)
179 BOOL16
SetCaretPos( INT32 x
, INT32 y
)
181 if (!Caret
.hwnd
) return FALSE
;
182 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
184 dprintf_caret(stddeb
,"SetCaretPos: x=%d, y=%d\n", x
, y
);
187 CARET_DisplayCaret(CARET_OFF
);
192 CARET_DisplayCaret(CARET_ON
);
199 /*****************************************************************
200 * HideCaret (USER.166) (USER32.316)
202 BOOL16
HideCaret( HWND32 hwnd
)
204 if (!Caret
.hwnd
) return FALSE
;
205 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
207 dprintf_caret(stddeb
,"HideCaret: hwnd=%04x, hidden=%d\n",
211 CARET_DisplayCaret(CARET_OFF
);
217 /*****************************************************************
218 * ShowCaret (USER.167) (USER32.528)
220 BOOL16
ShowCaret( HWND32 hwnd
)
222 if (!Caret
.hwnd
) return FALSE
;
223 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
225 dprintf_caret(stddeb
,"ShowCaret: hwnd=%04x, hidden=%d\n",
233 CARET_DisplayCaret(CARET_ON
);
241 /*****************************************************************
242 * SetCaretBlinkTime (USER.168) (USER32.464)
244 BOOL16
SetCaretBlinkTime( UINT32 msecs
)
246 if (!Caret
.hwnd
) return FALSE
;
248 dprintf_caret(stddeb
,"SetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
251 Caret
.timeout
= msecs
;
257 /*****************************************************************
258 * GetCaretBlinkTime16 (USER.169)
260 UINT16
GetCaretBlinkTime16(void)
262 return (UINT16
)GetCaretBlinkTime32();
266 /*****************************************************************
267 * GetCaretBlinkTime32 (USER32.208)
269 UINT32
GetCaretBlinkTime32(void)
271 return Caret
.timeout
;
275 /*****************************************************************
276 * GetCaretPos16 (USER.183)
278 VOID
GetCaretPos16( LPPOINT16 pt
)
280 if (!Caret
.hwnd
|| !pt
) return;
282 dprintf_caret(stddeb
,"GetCaretPos: hwnd=%04x, pt=%p, x=%d, y=%d\n",
283 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
284 pt
->x
= (INT16
)Caret
.x
;
285 pt
->y
= (INT16
)Caret
.y
;
289 /*****************************************************************
290 * GetCaretPos32 (USER32.209)
292 BOOL32
GetCaretPos32( LPPOINT32 pt
)
294 if (!Caret
.hwnd
|| !pt
) return FALSE
;