Release 960218
[wine.git] / windows / caret.c
blob12e9e000bfc10c4aedd91b38b7385bda74d44e52
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 */
7 #include "windows.h"
8 #include "selectors.h"
9 #include "alias.h"
10 #include "relay32.h"
11 #include "stddebug.h"
12 /* #define DEBUG_CARET */
13 #include "debug.h"
16 typedef struct
18 HWND hwnd;
19 short hidden;
20 BOOL on;
21 short x;
22 short y;
23 short width;
24 short height;
25 COLORREF color;
26 HBITMAP bitmap;
27 WORD timeout;
28 WORD timerid;
29 } CARET;
31 static CARET Caret;
32 static BOOL LockCaret;
34 static void CARET_HideCaret();
37 /*****************************************************************
38 * CARET_Callback
40 WORD CARET_Callback(HWND hwnd, WORD msg, WORD timerid, LONG ctime)
42 HDC hdc;
43 HBRUSH hBrush;
44 HRGN rgn;
46 dprintf_caret(stddeb,"CARET_Callback: id=%d: LockCaret=%d, hidden=%d, on=%d\n",
47 timerid, LockCaret, Caret.hidden, Caret.on);
48 if (!LockCaret && (!Caret.hidden || Caret.on))
50 Caret.on = (Caret.on ? FALSE : TRUE);
51 hdc = GetDC(Caret.hwnd);
52 if (Caret.bitmap == (HBITMAP)0 || Caret.bitmap == (HBITMAP)1)
53 hBrush = CreateSolidBrush(Caret.color);
54 else
55 hBrush = CreatePatternBrush(Caret.bitmap);
56 SelectObject(hdc, (HANDLE)hBrush);
57 SetROP2(hdc, R2_NOTXORPEN);
58 rgn = CreateRectRgn(Caret.x, Caret.y,
59 Caret.x + Caret.width,
60 Caret.y + Caret.height);
61 FillRgn(hdc, rgn, hBrush);
62 DeleteObject((HANDLE)rgn);
63 DeleteObject((HANDLE)hBrush);
64 ReleaseDC(Caret.hwnd, hdc);
66 return 0;
70 /*****************************************************************
71 * CARET_HideCaret
74 static void CARET_HideCaret()
76 HDC hdc;
77 HBRUSH hBrush;
78 HRGN rgn;
80 Caret.on = FALSE;
81 hdc = GetDC(Caret.hwnd);
82 if (Caret.bitmap == (HBITMAP)0 || Caret.bitmap == (HBITMAP)1)
83 hBrush = CreateSolidBrush(Caret.color);
84 else
85 hBrush = CreatePatternBrush(Caret.bitmap);
86 SelectObject(hdc, (HANDLE)hBrush);
87 SetROP2(hdc, R2_NOTXORPEN);
88 rgn = CreateRectRgn(Caret.x, Caret.y,
89 Caret.x + Caret.width,
90 Caret.y + Caret.height);
91 FillRgn(hdc, rgn, hBrush);
92 DeleteObject((HANDLE)rgn);
93 DeleteObject((HANDLE)hBrush);
94 ReleaseDC(Caret.hwnd, hdc);
97 /*****************************************************************
98 * CARET_Initialize
100 static void CARET_Initialize()
102 DWORD WineProc,Win16Proc,Win32Proc;
103 static int initialized=0;
104 if(!initialized)
106 WineProc=(DWORD)CARET_Callback;
107 Win16Proc=(DWORD)GetWndProcEntry16("CARET_Callback");
108 Win32Proc=(DWORD)RELAY32_GetEntryPoint(
109 RELAY32_GetBuiltinDLL("WINPROCS32"),"CARET_Callback",0);
110 ALIAS_RegisterAlias(WineProc,Win16Proc,Win32Proc);
111 initialized=1;
116 /*****************************************************************
117 * CreateCaret (USER.163)
120 BOOL CreateCaret(HWND hwnd, HBITMAP bitmap, INT width, INT height)
122 if (!hwnd) return FALSE;
125 /* if cursor already exists, destroy it */
126 /* if (Caret.hwnd)
127 DestroyCaret();
129 if (bitmap && bitmap != (HBITMAP)1)
130 Caret.bitmap = bitmap;
132 if (width)
133 Caret.width = width;
134 else
135 Caret.width = GetSystemMetrics(SM_CXBORDER);
137 if (height)
138 Caret.height = height;
139 else
140 Caret.height = GetSystemMetrics(SM_CYBORDER);
142 Caret.hwnd = hwnd;
143 Caret.hidden = 1;
144 Caret.on = FALSE;
145 Caret.x = 0;
146 Caret.y = 0;
147 if (bitmap == (HBITMAP)1)
148 Caret.color = GetSysColor(COLOR_GRAYTEXT);
149 else
150 Caret.color = GetSysColor(COLOR_WINDOWTEXT);
151 Caret.timeout = 750;
152 LockCaret = FALSE;
154 CARET_Initialize();
156 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
157 (FARPROC)GetWndProcEntry16("CARET_Callback"));
159 dprintf_caret(stddeb,"CreateCaret: hwnd="NPFMT", timerid=%d\n",
160 hwnd, Caret.timerid);
161 return TRUE;
165 /*****************************************************************
166 * DestroyCaret (USER.164)
169 BOOL DestroyCaret()
171 /* if (!Caret.hwnd) return;
173 dprintf_caret(stddeb,"DestroyCaret: timerid=%d\n", Caret.timerid);
175 KillSystemTimer( (HWND)0, Caret.timerid);
177 if (Caret.on)
178 CARET_HideCaret();
180 Caret.hwnd = 0; /* cursor marked as not existing */
181 return TRUE;
185 /*****************************************************************
186 * SetCaretPos (USER.165)
189 void SetCaretPos(short x, short y)
191 if (!Caret.hwnd) return;
193 dprintf_caret(stddeb,"SetCaretPos: x=%d, y=%d\n", x, y);
195 LockCaret = TRUE;
196 if (Caret.on)
197 CARET_HideCaret();
199 Caret.x = x;
200 Caret.y = y;
201 LockCaret = FALSE;
204 /*****************************************************************
205 * HideCaret (USER.166)
208 void HideCaret(HWND hwnd)
210 if (!Caret.hwnd) return;
211 if (hwnd && (Caret.hwnd != hwnd)) return;
213 LockCaret = TRUE;
214 if (Caret.on)
215 CARET_HideCaret();
217 ++Caret.hidden;
218 LockCaret = FALSE;
222 /*****************************************************************
223 * ShowCaret (USER.167)
226 void ShowCaret(HWND hwnd)
228 if (!Caret.hwnd) return;
229 if (hwnd && (Caret.hwnd != hwnd)) return;
231 dprintf_caret(stddeb,"ShowCaret: hidden=%d\n", Caret.hidden);
232 if (Caret.hidden)
233 --Caret.hidden;
237 /*****************************************************************
238 * SetCaretBlinkTime (USER.168)
241 void SetCaretBlinkTime(WORD msecs)
243 if (!Caret.hwnd) return;
245 CARET_Initialize();
247 KillSystemTimer( (HWND)0, Caret.timerid);
248 Caret.timeout = msecs;
249 Caret.timerid = SetSystemTimer( (HWND)0, 0, Caret.timeout,
250 (FARPROC)GetWndProcEntry16("CARET_Callback"));
254 /*****************************************************************
255 * GetCaretBlinkTime (USER.169)
258 WORD GetCaretBlinkTime()
260 if (!Caret.hwnd) return 0;
261 return Caret.timeout;
265 /*****************************************************************
266 * GetCaretPos (USER.183)
269 void GetCaretPos(LPPOINT pt)
271 if (!Caret.hwnd || !pt) return;
273 pt->x = Caret.x;
274 pt->y = Caret.y;