Release 961222
[wine/gsoc-2012-control.git] / windows / caret.c
blobca11b7e5d59ec6cb1324b572c8e39fb5b103cde5
1 /*
2 * Caret functions
4 * Copyright 1993 David Metcalfe
5 * Copyright 1996 Frans van Dorsselaer
6 */
8 #include "windows.h"
9 #include "module.h"
10 #include "stddebug.h"
11 /* #define DEBUG_CARET */
12 #include "debug.h"
15 typedef struct
17 HWND32 hwnd;
18 UINT32 hidden;
19 BOOL32 on;
20 INT32 x;
21 INT32 y;
22 INT32 width;
23 INT32 height;
24 HBRUSH16 hBrush;
25 UINT32 timeout;
26 UINT32 timerid;
27 } CARET;
29 typedef enum
31 CARET_OFF = 0,
32 CARET_ON,
33 CARET_TOGGLE,
34 } DISPLAY_CARET;
36 static CARET Caret = { 0, 0, FALSE, 0, 0, 2, 12, 0, 500, 0 };
39 /*****************************************************************
40 * CARET_GetHwnd
42 HWND32 CARET_GetHwnd()
44 return Caret.hwnd;
47 /*****************************************************************
48 * CARET_DisplayCaret
50 static void CARET_DisplayCaret( DISPLAY_CARET status )
52 HDC32 hdc;
53 HBRUSH16 hPrevBrush;
55 if (Caret.on && (status == CARET_ON)) return;
56 if (!Caret.on && (status == CARET_OFF)) return;
58 /* So now it's always a toggle */
60 Caret.on = !Caret.on;
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 /*****************************************************************
70 * CARET_Callback
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",
75 hwnd, id, Caret.on);
76 CARET_DisplayCaret(CARET_TOGGLE);
80 /*****************************************************************
81 * CARET_SetTimer
83 static void CARET_SetTimer(void)
85 if (Caret.timerid) KillSystemTimer32( (HWND32)0, Caret.timerid );
86 Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
87 CARET_Callback );
91 /*****************************************************************
92 * CARET_ResetTimer
94 static void CARET_ResetTimer(void)
96 if (Caret.timerid)
98 KillSystemTimer32( (HWND32)0, Caret.timerid );
99 Caret.timerid = SetSystemTimer32( (HWND32)0, 0, Caret.timeout,
100 CARET_Callback );
105 /*****************************************************************
106 * CARET_KillTimer
108 static void CARET_KillTimer(void)
110 if (Caret.timerid)
112 KillSystemTimer32( (HWND32)0, Caret.timerid );
113 Caret.timerid = 0;
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))
132 BITMAP16 bmp;
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 );
139 else
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) );
147 Caret.hwnd = hwnd;
148 Caret.hidden = 1;
149 Caret.on = FALSE;
150 Caret.x = 0;
151 Caret.y = 0;
153 Caret.timeout = GetProfileInt32A( "windows", "CursorBlinkRate", 500 );
154 return TRUE;
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 );
169 CARET_KillTimer();
170 CARET_DisplayCaret(CARET_OFF);
171 Caret.hwnd = 0;
172 return TRUE;
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);
186 CARET_KillTimer();
187 CARET_DisplayCaret(CARET_OFF);
188 Caret.x = x;
189 Caret.y = y;
190 if (!Caret.hidden)
192 CARET_DisplayCaret(CARET_ON);
193 CARET_SetTimer();
195 return TRUE;
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",
208 hwnd, Caret.hidden);
210 CARET_KillTimer();
211 CARET_DisplayCaret(CARET_OFF);
212 Caret.hidden++;
213 return TRUE;
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",
226 hwnd, Caret.hidden);
228 if (Caret.hidden)
230 Caret.hidden--;
231 if (!Caret.hidden)
233 CARET_DisplayCaret(CARET_ON);
234 CARET_SetTimer();
237 return TRUE;
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",
249 Caret.hwnd, msecs);
251 Caret.timeout = msecs;
252 CARET_ResetTimer();
253 return TRUE;
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;
295 pt->x = Caret.x;
296 pt->y = Caret.y;
297 return TRUE;