4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
11 /* #define DEBUG_CARET */
36 static CARET Caret
= { 0, };
39 /*****************************************************************
47 /*****************************************************************
50 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
= GetDCEx( Caret
.hwnd
, 0, DCX_USESTYLE
| DCX_CACHE
))) return;
62 hPrevBrush
= SelectObject( hdc
, Caret
.hBrush
);
63 PatBlt( hdc
, Caret
.x
, Caret
.y
, Caret
.width
, Caret
.height
, PATINVERT
);
64 SelectObject( hdc
, hPrevBrush
);
65 ReleaseDC( Caret
.hwnd
, hdc
);
69 /*****************************************************************
72 WORD
CARET_Callback(HWND hwnd
, WORD msg
, WORD timerid
, LONG ctime
)
74 dprintf_caret(stddeb
,"CARET_Callback: hwnd=%04x, timerid=%d, caret=%d\n",
75 hwnd
, timerid
, Caret
.on
);
77 CARET_DisplayCaret(CARET_TOGGLE
);
82 /*****************************************************************
85 void CARET_SetTimer(void)
87 if (Caret
.timerid
) KillSystemTimer((HWND
)0, Caret
.timerid
);
88 Caret
.timerid
= SetSystemTimer((HWND
)0, 0, Caret
.timeout
,
89 MODULE_GetWndProcEntry16("CARET_Callback"));
93 /*****************************************************************
96 void CARET_ResetTimer(void)
100 KillSystemTimer((HWND
)0, Caret
.timerid
);
101 Caret
.timerid
= SetSystemTimer((HWND
)0, 0, Caret
.timeout
,
102 MODULE_GetWndProcEntry16("CARET_Callback"));
107 /*****************************************************************
110 void CARET_KillTimer(void)
114 KillSystemTimer((HWND
)0, Caret
.timerid
);
120 /*****************************************************************
121 * CreateCaret (USER.163)
123 BOOL
CreateCaret(HWND hwnd
, HBITMAP bitmap
, INT width
, INT height
)
125 dprintf_caret(stddeb
,"CreateCaret: hwnd=%04x\n", hwnd
);
127 if (!hwnd
) return FALSE
;
129 /* if cursor already exists, destroy it */
130 if (Caret
.hwnd
) DestroyCaret();
132 if (bitmap
&& (bitmap
!= 1))
135 if (!GetObject16( bitmap
, sizeof(bmp
), &bmp
)) return FALSE
;
136 Caret
.width
= bmp
.bmWidth
;
137 Caret
.height
= bmp
.bmHeight
;
138 /* FIXME: we should make a copy of the bitmap instead of a brush */
139 Caret
.hBrush
= CreatePatternBrush( bitmap
);
143 Caret
.width
= width
? width
: GetSystemMetrics(SM_CXBORDER
);
144 Caret
.height
= height
? height
: GetSystemMetrics(SM_CYBORDER
);
145 Caret
.hBrush
= CreateSolidBrush( bitmap
? GetSysColor(COLOR_GRAYTEXT
) :
146 GetSysColor(COLOR_WINDOW
) );
155 Caret
.timeout
= GetProfileInt( "windows", "CursorBlinkRate", 750 );
160 /*****************************************************************
161 * DestroyCaret (USER.164)
166 if (!Caret
.hwnd
) return FALSE
;
168 dprintf_caret(stddeb
,"DestroyCaret: hwnd=%04x, timerid=%d\n",
169 Caret
.hwnd
, Caret
.timerid
);
171 DeleteObject( Caret
.hBrush
);
173 CARET_DisplayCaret(CARET_OFF
);
180 /*****************************************************************
181 * SetCaretPos (USER.165)
184 void SetCaretPos(short x
, short y
)
186 if (!Caret
.hwnd
) return;
187 if ((x
== Caret
.x
) && (y
== Caret
.y
)) return;
189 dprintf_caret(stddeb
,"SetCaretPos: x=%d, y=%d\n", x
, y
);
192 CARET_DisplayCaret(CARET_OFF
);
197 CARET_DisplayCaret(CARET_ON
);
202 /*****************************************************************
203 * HideCaret (USER.166)
206 void HideCaret(HWND hwnd
)
208 if (!Caret
.hwnd
) return;
209 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return;
211 dprintf_caret(stddeb
,"HideCaret: hwnd=%04x, hidden=%d\n",
215 CARET_DisplayCaret(CARET_OFF
);
220 /*****************************************************************
221 * ShowCaret (USER.167)
224 void ShowCaret(HWND hwnd
)
226 if (!Caret
.hwnd
) return;
227 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return;
229 dprintf_caret(stddeb
,"ShowCaret: hwnd=%04x, hidden=%d\n",
237 CARET_DisplayCaret(CARET_ON
);
244 /*****************************************************************
245 * SetCaretBlinkTime (USER.168)
248 void SetCaretBlinkTime(WORD msecs
)
250 if (!Caret
.hwnd
) return;
252 dprintf_caret(stddeb
,"SetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
255 Caret
.timeout
= msecs
;
260 /*****************************************************************
261 * GetCaretBlinkTime (USER.169)
264 WORD
GetCaretBlinkTime()
266 if (!Caret
.hwnd
) return 0;
268 dprintf_caret(stddeb
,"GetCaretBlinkTime: hwnd=%04x, msecs=%d\n",
269 Caret
.hwnd
, Caret
.timeout
);
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
);
290 /*****************************************************************
291 * GetCaretPos32 (USER32.209)
293 void GetCaretPos32( LPPOINT32 pt
)
295 if (!Caret
.hwnd
|| !pt
) return;