4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
11 /* #define DEBUG_CARET */
35 static CARET Caret
= { 0, 0, FALSE
, 0, 0, 2, 12, 0, 500, 0 };
37 /*****************************************************************
40 HWND32
CARET_GetHwnd(void)
45 /*****************************************************************
48 void CARET_GetRect(LPRECT32 lprc
)
50 lprc
->right
= (lprc
->left
= Caret
.x
) + Caret
.width
- 1;
51 lprc
->bottom
= (lprc
->top
= Caret
.y
) + Caret
.height
- 1;
54 /*****************************************************************
57 static void CARET_DisplayCaret( DISPLAY_CARET status
)
62 if (Caret
.on
&& (status
== CARET_ON
)) return;
63 if (!Caret
.on
&& (status
== CARET_OFF
)) return;
65 /* So now it's always a toggle */
68 if (!(hdc
= GetDCEx32( Caret
.hwnd
, 0, DCX_USESTYLE
| DCX_CACHE
))) return;
69 hPrevBrush
= SelectObject32( hdc
, Caret
.hBrush
);
70 PatBlt32( hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, PATINVERT
);
71 SelectObject32( hdc
, hPrevBrush
);
72 ReleaseDC32( Caret
.hwnd
, hdc
);
76 /*****************************************************************
79 static VOID
CARET_Callback( HWND32 hwnd
, UINT32 msg
, UINT32 id
, DWORD ctime
)
81 dprintf_caret(stddeb
,"CARET_Callback: hwnd=%04x, timerid=%d, caret=%d\n",
83 CARET_DisplayCaret(CARET_TOGGLE
);
87 /*****************************************************************
90 static void CARET_SetTimer(void)
92 if (Caret
.timerid
) KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
93 Caret
.timerid
= SetSystemTimer32( (HWND32
)0, 0, Caret
.timeout
,
98 /*****************************************************************
101 static void CARET_ResetTimer(void)
105 KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
106 Caret
.timerid
= SetSystemTimer32( (HWND32
)0, 0, Caret
.timeout
,
112 /*****************************************************************
115 static void CARET_KillTimer(void)
119 KillSystemTimer32( (HWND32
)0, Caret
.timerid
);
125 /*****************************************************************
126 * CreateCaret (USER.163) (USER32.65)
128 BOOL16
CreateCaret( HWND32 hwnd
, HBITMAP32 bitmap
, INT32 width
, INT32 height
)
130 dprintf_caret(stddeb
,"CreateCaret: hwnd=%04x\n", hwnd
);
132 if (!hwnd
) return FALSE
;
134 /* if cursor already exists, destroy it */
135 if (Caret
.hwnd
) DestroyCaret();
137 if (bitmap
&& (bitmap
!= 1))
140 if (!GetObject16( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
141 Caret
.width
= bmp
.bmWidth
;
142 Caret
.height
= bmp
.bmHeight
;
143 /* FIXME: we should make a copy of the bitmap instead of a brush */
144 Caret
.hBrush
= CreatePatternBrush32( bitmap
);
148 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
149 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
150 Caret
.hBrush
= CreateSolidBrush32(bitmap
? GetSysColor(COLOR_GRAYTEXT
):
151 GetSysColor(COLOR_WINDOW
) );
160 Caret
.timeout
= GetProfileInt32A( "windows", "CursorBlinkRate", 500 );
165 /*****************************************************************
166 * DestroyCaret (USER.164) (USER32.130)
168 BOOL16
DestroyCaret(void)
170 if (!Caret
.hwnd
) return FALSE
;
172 dprintf_caret(stddeb
,"DestroyCaret: hwnd=%04x, timerid=%d\n",
173 Caret
.hwnd
, Caret
.timerid
);
176 CARET_DisplayCaret(CARET_OFF
);
177 DeleteObject32( Caret
.hBrush
);
183 /*****************************************************************
184 * SetCaretPos (USER.165) (USER32.465)
186 BOOL16
SetCaretPos( INT32 x
, INT32 y
)
188 if (!Caret
.hwnd
) return FALSE
;
189 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return TRUE
;
191 dprintf_caret(stddeb
,"SetCaretPos: x=%d, y=%d\n", x
, y
);
194 CARET_DisplayCaret(CARET_OFF
);
199 CARET_DisplayCaret(CARET_ON
);
206 /*****************************************************************
207 * HideCaret (USER.166) (USER32.316)
209 BOOL16
HideCaret( HWND32 hwnd
)
211 if (!Caret
.hwnd
) return FALSE
;
212 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
214 dprintf_caret(stddeb
,"HideCaret: hwnd=%04x, hidden=%d\n",
218 CARET_DisplayCaret(CARET_OFF
);
224 /*****************************************************************
225 * ShowCaret (USER.167) (USER32.528)
227 BOOL16
ShowCaret( HWND32 hwnd
)
229 if (!Caret
.hwnd
) return FALSE
;
230 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return FALSE
;
232 dprintf_caret(stddeb
,"ShowCaret: hwnd=%04x, hidden=%d\n",
240 CARET_DisplayCaret(CARET_ON
);
248 /*****************************************************************
249 * SetCaretBlinkTime (USER.168) (USER32.464)
251 BOOL16
SetCaretBlinkTime( UINT32 msecs
)
253 if (!Caret
.hwnd
) return FALSE
;
255 dprintf_caret(stddeb
,"SetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
258 Caret
.timeout
= msecs
;
264 /*****************************************************************
265 * GetCaretBlinkTime16 (USER.169)
267 UINT16
GetCaretBlinkTime16(void)
269 return (UINT16
)GetCaretBlinkTime32();
273 /*****************************************************************
274 * GetCaretBlinkTime32 (USER32.208)
276 UINT32
GetCaretBlinkTime32(void)
278 return Caret
.timeout
;
282 /*****************************************************************
283 * GetCaretPos16 (USER.183)
285 VOID
GetCaretPos16( LPPOINT16 pt
)
287 if (!Caret
.hwnd
|| !pt
) return;
289 dprintf_caret(stddeb
,"GetCaretPos: hwnd=%04x, pt=%p, x=%d, y=%d\n",
290 Caret
.hwnd
, pt
, Caret
.x
, Caret
.y
);
291 pt
->x
= (INT16
)Caret
.x
;
292 pt
->y
= (INT16
)Caret
.y
;
296 /*****************************************************************
297 * GetCaretPos32 (USER32.209)
299 BOOL32
GetCaretPos32( LPPOINT32 pt
)
301 if (!Caret
.hwnd
|| !pt
) return FALSE
;