4 * Copyright 1993 David Metcalfe
7 static char Copyright
[] = "Copyright David Metcalfe, 1993";
11 /* #define DEBUG_CARET /* */
12 /* #undef DEBUG_CARET /* */
32 static BOOL LockCaret
;
34 static WORD
CARET_Callback(HWND hwnd
, WORD msg
, WORD timerid
, LONG ctime
);
35 static void CARET_HideCaret();
38 /*****************************************************************
42 static WORD
CARET_Callback(HWND hwnd
, WORD msg
, WORD timerid
, LONG ctime
)
48 dprintf_caret(stddeb
,"CARET_Callback: id=%d: LockCaret=%d, hidden=%d, on=%d\n",
49 timerid
, LockCaret
, Caret
.hidden
, Caret
.on
);
50 if (!LockCaret
&& (!Caret
.hidden
|| Caret
.on
))
52 Caret
.on
= (Caret
.on
? FALSE
: TRUE
);
53 hdc
= GetDC(Caret
.hwnd
);
54 if (Caret
.bitmap
== 0 || Caret
.bitmap
== 1)
55 hBrush
= CreateSolidBrush(Caret
.color
);
57 hBrush
= CreatePatternBrush(Caret
.bitmap
);
58 SelectObject(hdc
, (HANDLE
)hBrush
);
59 SetROP2(hdc
, R2_XORPEN
);
60 rgn
= CreateRectRgn(Caret
.x
, Caret
.y
,
61 Caret
.x
+ Caret
.width
,
62 Caret
.y
+ Caret
.height
);
63 FillRgn(hdc
, rgn
, hBrush
);
64 DeleteObject((HANDLE
)rgn
);
65 DeleteObject((HANDLE
)hBrush
);
66 ReleaseDC(Caret
.hwnd
, hdc
);
72 /*****************************************************************
76 static void CARET_HideCaret()
83 hdc
= GetDC(Caret
.hwnd
);
84 if (Caret
.bitmap
== 0 || Caret
.bitmap
== 1)
85 hBrush
= CreateSolidBrush(Caret
.color
);
87 hBrush
= CreatePatternBrush(Caret
.bitmap
);
88 SelectObject(hdc
, (HANDLE
)hBrush
);
89 SetROP2(hdc
, R2_XORPEN
);
90 rgn
= CreateRectRgn(Caret
.x
, Caret
.y
,
91 Caret
.x
+ Caret
.width
,
92 Caret
.y
+ Caret
.height
);
93 FillRgn(hdc
, rgn
, hBrush
);
94 DeleteObject((HANDLE
)rgn
);
95 DeleteObject((HANDLE
)hBrush
);
96 ReleaseDC(Caret
.hwnd
, hdc
);
100 /*****************************************************************
101 * CreateCaret (USER.163)
104 void CreateCaret(HWND hwnd
, HBITMAP bitmap
, short width
, short height
)
109 /* if cursor already exists, destroy it */
113 if (bitmap
&& bitmap
!= 1)
114 Caret
.bitmap
= bitmap
;
119 Caret
.width
= GetSystemMetrics(SM_CXBORDER
);
122 Caret
.height
= height
;
124 Caret
.height
= GetSystemMetrics(SM_CYBORDER
);
132 Caret
.color
= GetSysColor(COLOR_GRAYTEXT
);
134 Caret
.color
= GetSysColor(COLOR_WINDOWTEXT
);
138 Caret
.timerid
= SetSystemTimer(NULL
, 0, Caret
.timeout
, CARET_Callback
);
140 dprintf_caret(stddeb
,"CreateCaret: hwnd=%d, timerid=%d\n",
141 hwnd
, Caret
.timerid
);
145 /*****************************************************************
146 * DestroyCaret (USER.164)
151 /* if (!Caret.hwnd) return;
153 dprintf_caret(stddeb
,"DestroyCaret: timerid=%d\n", Caret
.timerid
);
155 KillSystemTimer(NULL
, Caret
.timerid
);
160 Caret
.hwnd
= 0; /* cursor marked as not existing */
164 /*****************************************************************
165 * SetCaretPos (USER.165)
168 void SetCaretPos(short x
, short y
)
174 if (!Caret
.hwnd
) return;
176 dprintf_caret(stddeb
,"SetCaretPos: x=%d, y=%d\n", x
, y
);
187 /*****************************************************************
188 * HideCaret (USER.166)
191 void HideCaret(HWND hwnd
)
193 if (!Caret
.hwnd
) return;
194 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return;
205 /*****************************************************************
206 * ShowCaret (USER.167)
209 void ShowCaret(HWND hwnd
)
211 if (!Caret
.hwnd
) return;
212 if (hwnd
&& (Caret
.hwnd
!= hwnd
)) return;
214 dprintf_caret(stddeb
,"ShowCaret: hidden=%d\n", Caret
.hidden
);
220 /*****************************************************************
221 * SetCaretBlinkTime (USER.168)
224 void SetCaretBlinkTime(WORD msecs
)
226 if (!Caret
.hwnd
) return;
228 KillSystemTimer(NULL
, Caret
.timerid
);
229 Caret
.timeout
= msecs
;
230 Caret
.timerid
= SetSystemTimer(NULL
, 0, Caret
.timeout
, CARET_Callback
);
234 /*****************************************************************
235 * GetCaretBlinkTime (USER.169)
238 WORD
GetCaretBlinkTime()
240 if (!Caret
.hwnd
) return;
242 return Caret
.timeout
;
246 /*****************************************************************
247 * GetCaretPos (USER.183)
250 void GetCaretPos(LPPOINT pt
)
252 if (!Caret
.hwnd
|| !pt
) return;