1 | /* $Id: updown.c,v 1.5 1999-06-24 16:37:46 cbratschi Exp $ */
|
---|
2 | /*
|
---|
3 | * Updown control
|
---|
4 | *
|
---|
5 | * Copyright 1997 Dimitrie O. Paun
|
---|
6 | * Copyright 1999 Achim Hasenmueller
|
---|
7 | * Copyright 1999 Christoph Bratschi
|
---|
8 | *
|
---|
9 | * TODO:
|
---|
10 | * - subclass the buddy window (in UPDOWN_SetBuddyHandle) to process the
|
---|
11 | * arrow keys
|
---|
12 | * - I am not sure about the default values for the Min, Max, Pos
|
---|
13 | * (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
|
---|
14 | * - I think I do not handle correctly the WS_BORDER style.
|
---|
15 | * (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
|
---|
16 | *
|
---|
17 | * Testing:
|
---|
18 | * Not much. The following have not been tested at all:
|
---|
19 | * - horizontal arrows
|
---|
20 | * - listbox as buddy window
|
---|
21 | * - acceleration
|
---|
22 | * - base 16
|
---|
23 | * - UDS_ALIGNLEFT, ~UDS_WRAP
|
---|
24 | * (tested - they work)
|
---|
25 | * - integers with thousand separators.
|
---|
26 | * (fixed bugs. <noel@macadamian.com>)
|
---|
27 | *
|
---|
28 | * Even though the above list seems rather large, the control seems to
|
---|
29 | * behave very well so I am confident it does work in most (all) of the
|
---|
30 | * untested cases.
|
---|
31 | * Problems:
|
---|
32 | * I do not like the arrows yet, I'll work more on them later on.
|
---|
33 | */
|
---|
34 |
|
---|
35 | /* CB: Odin32 problems
|
---|
36 | - Open32 doesn't look for CS_DBLCLKS -> double clicks always sent
|
---|
37 | */
|
---|
38 |
|
---|
39 | #include <stdlib.h>
|
---|
40 | #include <stdio.h>
|
---|
41 | #include <string.h>
|
---|
42 |
|
---|
43 | #include "winbase.h"
|
---|
44 | #include "winuser.h"
|
---|
45 | #include "commctrl.h"
|
---|
46 | #include "winnls.h"
|
---|
47 | #include "updown.h"
|
---|
48 |
|
---|
49 | /* Control configuration constants */
|
---|
50 |
|
---|
51 | #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
|
---|
52 | #define REPEAT_DELAY 50 /* delay between auto-increments */
|
---|
53 |
|
---|
54 | #define DEFAULT_WIDTH 14 /* default width of the ctrl */
|
---|
55 | #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
|
---|
56 | #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
|
---|
57 | #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
|
---|
58 |
|
---|
59 |
|
---|
60 | /* Work constants */
|
---|
61 |
|
---|
62 | #define FLAG_INCR 0x01
|
---|
63 | #define FLAG_DECR 0x02
|
---|
64 | #define FLAG_MOUSEIN 0x04
|
---|
65 | #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
|
---|
66 |
|
---|
67 | #define TIMERID1 1
|
---|
68 | #define TIMERID2 2
|
---|
69 |
|
---|
70 | static int accelIndex = -1;
|
---|
71 |
|
---|
72 | //#define UNKNOWN_PARAM(msg, wParam, lParam) WARN(updown, \
|
---|
73 | // "UpDown Ctrl: Unknown parameter(s) for message " #msg \
|
---|
74 | // "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
|
---|
75 | #define UNKNOWN_PARAM(msg, wParam, lParam)
|
---|
76 |
|
---|
77 | #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA(hwnd,0))
|
---|
78 |
|
---|
79 |
|
---|
80 | /***********************************************************************
|
---|
81 | * UPDOWN_InBounds
|
---|
82 | * Tests if a given value 'val' is between the Min&Max limits
|
---|
83 | */
|
---|
84 | static BOOL UPDOWN_InBounds(HWND hwnd, int val)
|
---|
85 | {
|
---|
86 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
87 |
|
---|
88 | if(infoPtr->MaxVal > infoPtr->MinVal)
|
---|
89 | return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
|
---|
90 | else
|
---|
91 | return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
|
---|
92 | }
|
---|
93 |
|
---|
94 | /***********************************************************************
|
---|
95 | * UPDOWN_OffsetVal
|
---|
96 | * Tests if we can change the current value by delta. If so, it changes
|
---|
97 | * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
|
---|
98 | */
|
---|
99 | static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
|
---|
100 | {
|
---|
101 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
102 |
|
---|
103 | /* check if we can do the modification first */
|
---|
104 | if(!UPDOWN_InBounds (hwnd, infoPtr->CurVal+delta)){
|
---|
105 | if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_WRAP)
|
---|
106 | {
|
---|
107 | delta += (delta < 0 ? -1 : 1) *
|
---|
108 | (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
|
---|
109 | (infoPtr->MinVal - infoPtr->MaxVal) +
|
---|
110 | (delta < 0 ? 1 : -1);
|
---|
111 | }
|
---|
112 | else
|
---|
113 | return FALSE;
|
---|
114 | }
|
---|
115 |
|
---|
116 | infoPtr->CurVal += delta;
|
---|
117 | return TRUE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | /***********************************************************************
|
---|
121 | * UPDOWN_GetArrowRect
|
---|
122 | * wndPtr - pointer to the up-down wnd
|
---|
123 | * rect - will hold the rectangle
|
---|
124 | * incr - TRUE get the "increment" rect (up or right)
|
---|
125 | * FALSE get the "decrement" rect (down or left)
|
---|
126 | *
|
---|
127 | */
|
---|
128 | static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
|
---|
129 | {
|
---|
130 | int len; /* will hold the width or height */
|
---|
131 |
|
---|
132 | GetClientRect (hwnd, rect);
|
---|
133 |
|
---|
134 | if (GetWindowLongA(hwnd, GWL_STYLE) & UDS_HORZ)
|
---|
135 | {
|
---|
136 | len = rect->right-rect->left; /* compute the width */
|
---|
137 | if (incr) rect->left = len/2+1;
|
---|
138 | else rect->right = len/2;
|
---|
139 | } else
|
---|
140 | {
|
---|
141 | len = rect->bottom-rect->top; /* compute the height */
|
---|
142 | if (incr) rect->bottom = len/2;
|
---|
143 | else rect->top = len/2+1;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | /***********************************************************************
|
---|
148 | * UPDOWN_GetArrowFromPoint
|
---|
149 | * Returns the rectagle (for the up or down arrow) that contains pt.
|
---|
150 | * If it returns the up rect, it returns TRUE.
|
---|
151 | * If it returns the down rect, it returns FALSE.
|
---|
152 | */
|
---|
153 | static BOOL
|
---|
154 | UPDOWN_GetArrowFromPoint (HWND hwnd, RECT *rect, POINT pt)
|
---|
155 | {
|
---|
156 | UPDOWN_GetArrowRect (hwnd, rect, TRUE);
|
---|
157 | if(PtInRect(rect, pt))
|
---|
158 | return TRUE;
|
---|
159 |
|
---|
160 | UPDOWN_GetArrowRect (hwnd, rect, FALSE);
|
---|
161 | return FALSE;
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | /***********************************************************************
|
---|
166 | * UPDOWN_GetThousandSep
|
---|
167 | * Returns the thousand sep. If an error occurs, it returns ','.
|
---|
168 | */
|
---|
169 | static char UPDOWN_GetThousandSep()
|
---|
170 | {
|
---|
171 | char sep[2];
|
---|
172 |
|
---|
173 | if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
|
---|
174 | sep, sizeof(sep)) != 1)
|
---|
175 | return ',';
|
---|
176 |
|
---|
177 | return sep[0];
|
---|
178 | }
|
---|
179 |
|
---|
180 | /***********************************************************************
|
---|
181 | * UPDOWN_GetBuddyInt
|
---|
182 | * Tries to read the pos from the buddy window and if it succeeds,
|
---|
183 | * it stores it in the control's CurVal
|
---|
184 | * returns:
|
---|
185 | * TRUE - if it read the integer from the buddy successfully
|
---|
186 | * FALSE - if an error occured
|
---|
187 | */
|
---|
188 | static BOOL UPDOWN_GetBuddyInt (HWND hwnd)
|
---|
189 | {
|
---|
190 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
191 | char txt[20], sep, *src, *dst;
|
---|
192 | int newVal;
|
---|
193 |
|
---|
194 | if (!IsWindow(infoPtr->Buddy)) return FALSE;
|
---|
195 |
|
---|
196 | /*if the buddy is a list window, we must set curr index */
|
---|
197 | if (!lstrcmpA(infoPtr->szBuddyClass,"ListBox"))
|
---|
198 | {
|
---|
199 | newVal = SendMessageA(infoPtr->Buddy,LB_GETCARETINDEX,0,0);
|
---|
200 | if(newVal < 0) return FALSE;
|
---|
201 | } else
|
---|
202 | {
|
---|
203 | /* we have a regular window, so will get the text */
|
---|
204 | if (!GetWindowTextA(infoPtr->Buddy,txt,sizeof(txt))) return FALSE;
|
---|
205 |
|
---|
206 | sep = UPDOWN_GetThousandSep();
|
---|
207 |
|
---|
208 | /* now get rid of the separators */
|
---|
209 | for(src = dst = txt;*src;src++)
|
---|
210 | if (*src != sep)
|
---|
211 | *dst++ = *src;
|
---|
212 | *dst = 0;
|
---|
213 |
|
---|
214 | /* try to convert the number and validate it */
|
---|
215 | newVal = strtol(txt,&src,infoPtr->Base);
|
---|
216 | if (*src || !UPDOWN_InBounds(hwnd,newVal)) return FALSE;
|
---|
217 |
|
---|
218 | // TRACE(updown, "new value(%d) read from buddy (old=%d)\n",
|
---|
219 | // newVal, infoPtr->CurVal);
|
---|
220 | }
|
---|
221 |
|
---|
222 | infoPtr->CurVal = newVal;
|
---|
223 |
|
---|
224 | return TRUE;
|
---|
225 | }
|
---|
226 |
|
---|
227 |
|
---|
228 | /***********************************************************************
|
---|
229 | * UPDOWN_SetBuddyInt
|
---|
230 | * Tries to set the pos to the buddy window based on current pos
|
---|
231 | * returns:
|
---|
232 | * TRUE - if it set the caption of the buddy successfully
|
---|
233 | * FALSE - if an error occured
|
---|
234 | */
|
---|
235 | static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
|
---|
236 | {
|
---|
237 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
238 | char txt1[20],sep;
|
---|
239 | int len;
|
---|
240 |
|
---|
241 | if (!IsWindow(infoPtr->Buddy)) return FALSE;
|
---|
242 |
|
---|
243 | // TRACE(updown, "set new value(%d) to buddy.\n",
|
---|
244 | // infoPtr->CurVal);
|
---|
245 |
|
---|
246 | /*if the buddy is a list window, we must set curr index */
|
---|
247 | if(!lstrcmpA(infoPtr->szBuddyClass, "ListBox"))
|
---|
248 | {
|
---|
249 | SendMessageA(infoPtr->Buddy,LB_SETCURSEL,infoPtr->CurVal,0);
|
---|
250 | } else
|
---|
251 | { /* Regular window, so set caption to the number */
|
---|
252 | len = sprintf(txt1,(infoPtr->Base == 16) ? "%X" : "%d",infoPtr->CurVal);
|
---|
253 |
|
---|
254 | sep = UPDOWN_GetThousandSep();
|
---|
255 |
|
---|
256 | /* Do thousands seperation if necessary */
|
---|
257 | if (!(GetWindowLongA (hwnd, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
|
---|
258 | char txt2[20], *src = txt1, *dst = txt2;
|
---|
259 | if(len%3 > 0){
|
---|
260 | lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
|
---|
261 | dst += len%3;
|
---|
262 | src += len%3;
|
---|
263 | }
|
---|
264 | for(len=0; *src; len++){
|
---|
265 | if(len%3==0)
|
---|
266 | *dst++ = sep;
|
---|
267 | *dst++ = *src++;
|
---|
268 | }
|
---|
269 | *dst = 0; /* null terminate it */
|
---|
270 | strcpy(txt1, txt2); /* move it to the proper place */
|
---|
271 | }
|
---|
272 | SetWindowTextA(infoPtr->Buddy, txt1);
|
---|
273 | }
|
---|
274 |
|
---|
275 | return TRUE;
|
---|
276 | }
|
---|
277 |
|
---|
278 | /***********************************************************************
|
---|
279 | * UPDOWN_Draw [Internal]
|
---|
280 | *
|
---|
281 | * Draw the arrows. The background need not be erased.
|
---|
282 | */
|
---|
283 | static void UPDOWN_Draw(HWND hwnd,HDC hdc)
|
---|
284 | {
|
---|
285 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
286 | DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
|
---|
287 | BOOL prssed;
|
---|
288 | RECT rect;
|
---|
289 |
|
---|
290 | /* Draw the incr button */
|
---|
291 | UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
|
---|
292 | prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
|
---|
293 | DrawFrameControl(hdc, &rect, DFC_SCROLL,
|
---|
294 | (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
|
---|
295 | (prssed ? DFCS_PUSHED : 0) |
|
---|
296 | (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
|
---|
297 |
|
---|
298 | /* Draw the space between the buttons */
|
---|
299 | rect.top = rect.bottom;
|
---|
300 | rect.bottom++;
|
---|
301 | DrawEdge(hdc, &rect, 0, BF_MIDDLE);
|
---|
302 |
|
---|
303 | /* Draw the decr button */
|
---|
304 | UPDOWN_GetArrowRect(hwnd, &rect, FALSE);
|
---|
305 | prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
|
---|
306 | DrawFrameControl(hdc, &rect, DFC_SCROLL,
|
---|
307 | (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
|
---|
308 | (prssed ? DFCS_PUSHED : 0) |
|
---|
309 | (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
|
---|
310 | }
|
---|
311 |
|
---|
312 | /***********************************************************************
|
---|
313 | * UPDOWN_Refresh [Internal]
|
---|
314 | *
|
---|
315 | * Synchronous drawing (must NOT be used in WM_PAINT).
|
---|
316 | * Calls UPDOWN_Draw.
|
---|
317 | */
|
---|
318 | static void UPDOWN_Refresh (HWND hwnd)
|
---|
319 | {
|
---|
320 | HDC hdc;
|
---|
321 |
|
---|
322 | hdc = GetDC (hwnd);
|
---|
323 | UPDOWN_Draw (hwnd, hdc);
|
---|
324 | ReleaseDC (hwnd, hdc);
|
---|
325 | }
|
---|
326 |
|
---|
327 |
|
---|
328 | /***********************************************************************
|
---|
329 | * UPDOWN_Paint [Internal]
|
---|
330 | *
|
---|
331 | * Asynchronous drawing (must ONLY be used in WM_PAINT).
|
---|
332 | * Calls UPDOWN_Draw.
|
---|
333 | */
|
---|
334 | static void UPDOWN_Paint (HWND hwnd)
|
---|
335 | {
|
---|
336 | PAINTSTRUCT ps;
|
---|
337 | HDC hdc;
|
---|
338 |
|
---|
339 | hdc = BeginPaint (hwnd, &ps);
|
---|
340 | UPDOWN_Draw (hwnd, hdc);
|
---|
341 | EndPaint (hwnd, &ps);
|
---|
342 | }
|
---|
343 |
|
---|
344 | /***********************************************************************
|
---|
345 | * UPDOWN_SetBuddyHandle
|
---|
346 | * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
|
---|
347 | * Else, sets it as a new Buddy.
|
---|
348 | * Then, it should subclass the buddy
|
---|
349 | * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
|
---|
350 | * process the UP/DOWN arrow keys.
|
---|
351 | * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
|
---|
352 | * the size/pos of the buddy and the control are adjusted accordingly.
|
---|
353 | */
|
---|
354 | static BOOL UPDOWN_SetBuddyHandle (HWND hwnd, HWND hwndBud)
|
---|
355 | {
|
---|
356 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
357 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
358 | RECT budRect; /* new coord for the buddy */
|
---|
359 | int x; /* new x position and width for the up-down */
|
---|
360 |
|
---|
361 | *infoPtr->szBuddyClass = '\0';
|
---|
362 |
|
---|
363 | /* Is is a valid bud? */
|
---|
364 | if(!IsWindow(hwndBud))
|
---|
365 | return FALSE;
|
---|
366 |
|
---|
367 | /* Store buddy window clas name */
|
---|
368 | GetClassNameA (hwndBud, infoPtr->szBuddyClass, 40);
|
---|
369 |
|
---|
370 | if(dwStyle & UDS_ARROWKEYS){
|
---|
371 | // FIXME(updown, "we need to subclass the buddy to process the arrow keys.\n");
|
---|
372 | }
|
---|
373 |
|
---|
374 | /* do we need to do any adjustments? */
|
---|
375 | if(!(dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
|
---|
376 | return TRUE;
|
---|
377 |
|
---|
378 | infoPtr->Buddy = hwndBud;
|
---|
379 |
|
---|
380 | /* Get the rect of the buddy relative to its parent */
|
---|
381 | GetWindowRect(infoPtr->Buddy, &budRect);
|
---|
382 | MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
|
---|
383 | (POINT *)(&budRect.left), 2);
|
---|
384 |
|
---|
385 | /* now do the positioning */
|
---|
386 | if(dwStyle & UDS_ALIGNRIGHT){
|
---|
387 | budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
|
---|
388 | x = budRect.right+DEFAULT_XSEP;
|
---|
389 | }
|
---|
390 | else{ /* UDS_ALIGNLEFT */
|
---|
391 | x = budRect.left;
|
---|
392 | budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
|
---|
393 | }
|
---|
394 |
|
---|
395 | /* first adjust the buddy to accomodate the up/down */
|
---|
396 | SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
|
---|
397 | budRect.right - budRect.left, budRect.bottom - budRect.top,
|
---|
398 | SWP_NOACTIVATE|SWP_NOZORDER);
|
---|
399 |
|
---|
400 | /* now position the up/down */
|
---|
401 | /* Since the UDS_ALIGN* flags were used, */
|
---|
402 | /* we will pick the position and size of the window. */
|
---|
403 |
|
---|
404 | SetWindowPos (hwnd, 0, x, budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
|
---|
405 | (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
|
---|
406 | SWP_NOACTIVATE|SWP_NOZORDER);
|
---|
407 |
|
---|
408 | return TRUE;
|
---|
409 | }
|
---|
410 |
|
---|
411 | /***********************************************************************
|
---|
412 | * UPDOWN_DoAction
|
---|
413 | *
|
---|
414 | * This function increments/decrements the CurVal by the
|
---|
415 | * 'delta' amount according to the 'incr' flag
|
---|
416 | * It notifies the parent as required.
|
---|
417 | * It handles wraping and non-wraping correctly.
|
---|
418 | * It is assumed that delta>0
|
---|
419 | */
|
---|
420 | static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr)
|
---|
421 | {
|
---|
422 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
423 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
424 | int old_val = infoPtr->CurVal;
|
---|
425 | NM_UPDOWN ni;
|
---|
426 |
|
---|
427 | // TRACE(updown, "%s by %d\n", incr ? "inc" : "dec", delta);
|
---|
428 |
|
---|
429 | /* check if we can do the modification first */
|
---|
430 | delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
|
---|
431 | if(!UPDOWN_OffsetVal(hwnd,delta)) return;
|
---|
432 |
|
---|
433 | /* so, if we can do the change, recompute delta and restore old value */
|
---|
434 | delta = infoPtr->CurVal-old_val;
|
---|
435 | infoPtr->CurVal = old_val;
|
---|
436 |
|
---|
437 | /* We must notify parent now to obtain permission */
|
---|
438 | ni.iPos = infoPtr->CurVal;
|
---|
439 | ni.iDelta = delta;
|
---|
440 | ni.hdr.hwndFrom = hwnd;
|
---|
441 | ni.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID);
|
---|
442 | ni.hdr.code = UDN_DELTAPOS;
|
---|
443 | if (SendMessageA(GetParent(hwnd),WM_NOTIFY,
|
---|
444 | (WPARAM)ni.hdr.idFrom,(LPARAM)&ni))
|
---|
445 | return; /* we are not allowed to change */
|
---|
446 |
|
---|
447 | /* Now adjust value with (maybe new) delta */
|
---|
448 | if (!UPDOWN_OffsetVal (hwnd,ni.iDelta)) return;
|
---|
449 |
|
---|
450 | /* Now take care about our buddy */
|
---|
451 | if(!IsWindow(infoPtr->Buddy))
|
---|
452 | return; /* Nothing else to do */
|
---|
453 |
|
---|
454 |
|
---|
455 | if (dwStyle & UDS_SETBUDDYINT) UPDOWN_SetBuddyInt(hwnd);
|
---|
456 |
|
---|
457 | /* Also, notify it */
|
---|
458 | /* FIXME: do we need to send the notification only if
|
---|
459 | we do not have the UDS_SETBUDDYINT style set? */
|
---|
460 |
|
---|
461 | SendMessageA (GetParent (hwnd),
|
---|
462 | dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
|
---|
463 | MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
|
---|
464 | hwnd);
|
---|
465 | }
|
---|
466 |
|
---|
467 | /***********************************************************************
|
---|
468 | * UPDOWN_IsEnabled
|
---|
469 | *
|
---|
470 | * Returns TRUE if it is enabled as well as its buddy (if any)
|
---|
471 | * FALSE otherwise
|
---|
472 | */
|
---|
473 | static BOOL UPDOWN_IsEnabled (HWND hwnd)
|
---|
474 | {
|
---|
475 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
476 |
|
---|
477 | if(GetWindowLongA (hwnd, GWL_STYLE) & WS_DISABLED)
|
---|
478 | return FALSE;
|
---|
479 | return IsWindowEnabled(infoPtr->Buddy);
|
---|
480 | }
|
---|
481 |
|
---|
482 | /***********************************************************************
|
---|
483 | * UPDOWN_CancelMode
|
---|
484 | *
|
---|
485 | * Deletes any timers, releases the mouse and does redraw if necessary.
|
---|
486 | * If the control is not in "capture" mode, it does nothing.
|
---|
487 | * If the control was not in cancel mode, it returns FALSE.
|
---|
488 | * If the control was in cancel mode, it returns TRUE.
|
---|
489 | */
|
---|
490 | static BOOL UPDOWN_CancelMode (HWND hwnd)
|
---|
491 | {
|
---|
492 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
493 |
|
---|
494 | /* if not in 'capture' mode, do nothing */
|
---|
495 | if(!(infoPtr->Flags & FLAG_CLICKED))
|
---|
496 | return FALSE;
|
---|
497 |
|
---|
498 | KillTimer (hwnd, TIMERID1); /* kill all possible timers */
|
---|
499 | KillTimer (hwnd, TIMERID2);
|
---|
500 |
|
---|
501 | if (GetCapture() == hwnd) /* let the mouse go */
|
---|
502 | ReleaseCapture(); /* if we still have it */
|
---|
503 |
|
---|
504 | infoPtr->Flags = 0; /* get rid of any flags */
|
---|
505 | UPDOWN_Refresh (hwnd); /* redraw the control just in case */
|
---|
506 |
|
---|
507 | return TRUE;
|
---|
508 | }
|
---|
509 |
|
---|
510 | /***********************************************************************
|
---|
511 | * UPDOWN_HandleMouseEvent
|
---|
512 | *
|
---|
513 | * Handle a mouse event for the updown.
|
---|
514 | * 'pt' is the location of the mouse event in client or
|
---|
515 | * windows coordinates.
|
---|
516 | */
|
---|
517 | static void UPDOWN_HandleMouseEvent (HWND hwnd, UINT msg, POINT pt)
|
---|
518 | {
|
---|
519 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
|
---|
520 | DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
|
---|
521 | RECT rect;
|
---|
522 | int temp;
|
---|
523 |
|
---|
524 | switch(msg)
|
---|
525 | {
|
---|
526 | case WM_LBUTTONDOWN: /* Initialise mouse tracking */
|
---|
527 | /* If we are already in the 'clicked' mode, then nothing to do */
|
---|
528 | if (infoPtr->Flags & FLAG_CLICKED) return;
|
---|
529 |
|
---|
530 | /* If the buddy is an edit, will set focus to it */
|
---|
531 | if (!lstrcmpA(infoPtr->szBuddyClass,"Edit")) SetFocus(infoPtr->Buddy);
|
---|
532 |
|
---|
533 | /* Now see which one is the 'active' arrow */
|
---|
534 | temp = UPDOWN_GetArrowFromPoint(hwnd,&rect,pt);
|
---|
535 |
|
---|
536 | /* Update the CurVal if necessary */
|
---|
537 | if (dwStyle & UDS_SETBUDDYINT) UPDOWN_GetBuddyInt(hwnd);
|
---|
538 |
|
---|
539 | /* Before we proceed, see if we can spin... */
|
---|
540 | if (!(dwStyle & UDS_WRAP))
|
---|
541 | if ((temp && infoPtr->CurVal == infoPtr->MaxVal) ||
|
---|
542 | (!temp && infoPtr->CurVal == infoPtr->MinVal))
|
---|
543 | return;
|
---|
544 |
|
---|
545 | /* Set up the correct flags */
|
---|
546 | infoPtr->Flags = 0;
|
---|
547 | infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
|
---|
548 | infoPtr->Flags |= FLAG_MOUSEIN;
|
---|
549 |
|
---|
550 | /* repaint the control */
|
---|
551 | UPDOWN_Refresh (hwnd);
|
---|
552 |
|
---|
553 | /* process the click */
|
---|
554 | UPDOWN_DoAction (hwnd,1,infoPtr->Flags & FLAG_INCR);
|
---|
555 |
|
---|
556 | /* now capture all mouse messages */
|
---|
557 | SetCapture (hwnd);
|
---|
558 |
|
---|
559 | /* and startup the first timer */
|
---|
560 | SetTimer(hwnd,TIMERID1,INITIAL_DELAY,0);
|
---|
561 | break;
|
---|
562 |
|
---|
563 | case WM_MOUSEMOVE:
|
---|
564 | /* If we are not in the 'clicked' mode, then nothing to do */
|
---|
565 | if (!(infoPtr->Flags & FLAG_CLICKED)) return;
|
---|
566 |
|
---|
567 | /* save the flags to see if any got modified */
|
---|
568 | temp = infoPtr->Flags;
|
---|
569 |
|
---|
570 | /* Now get the 'active' arrow rectangle */
|
---|
571 | if (infoPtr->Flags & FLAG_INCR)
|
---|
572 | UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
|
---|
573 | else
|
---|
574 | UPDOWN_GetArrowRect (hwnd, &rect, FALSE);
|
---|
575 |
|
---|
576 | /* Update the flags if we are in/out */
|
---|
577 | if(PtInRect(&rect, pt))
|
---|
578 | infoPtr->Flags |= FLAG_MOUSEIN;
|
---|
579 | else{
|
---|
580 | infoPtr->Flags &= ~FLAG_MOUSEIN;
|
---|
581 | if(accelIndex != -1) /* if we have accel info */
|
---|
582 | accelIndex = 0; /* reset it */
|
---|
583 | }
|
---|
584 | /* If state changed, redraw the control */
|
---|
585 | if(temp != infoPtr->Flags)
|
---|
586 | UPDOWN_Refresh (hwnd);
|
---|
587 | break;
|
---|
588 |
|
---|
589 | default:
|
---|
590 | // ERR(updown, "Impossible case!\n");
|
---|
591 | break;
|
---|
592 | }
|
---|
593 |
|
---|
594 | }
|
---|
595 |
|
---|
596 | //Message handling
|
---|
597 |
|
---|
598 | static LRESULT UPDOWN_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
599 | {
|
---|
600 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
601 |
|
---|
602 | /* get rid of border, if any */
|
---|
603 | SetWindowLongA(hwnd,GWL_STYLE,dwStyle & ~WS_BORDER);
|
---|
604 | return TRUE;
|
---|
605 | }
|
---|
606 |
|
---|
607 | static LRESULT UPDOWN_Create(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
608 | {
|
---|
609 | UPDOWN_INFO *infoPtr;
|
---|
610 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
611 |
|
---|
612 | infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc(sizeof(UPDOWN_INFO));
|
---|
613 | SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
|
---|
614 |
|
---|
615 | /* initialize the info struct */
|
---|
616 | infoPtr->AccelCount = 0;
|
---|
617 | infoPtr->AccelVect = 0;
|
---|
618 | infoPtr->CurVal = 0;
|
---|
619 | infoPtr->MinVal = 0;
|
---|
620 | infoPtr->MaxVal = 100; /*FIXME*/
|
---|
621 | infoPtr->Base = 10; /* Default to base 10 */
|
---|
622 | infoPtr->Buddy = 0; /* No buddy window yet */
|
---|
623 | infoPtr->Flags = 0; /* And no flags */
|
---|
624 |
|
---|
625 | /* Do we pick the buddy win ourselves? */
|
---|
626 | if (dwStyle & UDS_AUTOBUDDY) UPDOWN_SetBuddyHandle(hwnd,GetWindow(hwnd,GW_HWNDPREV));
|
---|
627 |
|
---|
628 | // TRACE(updown, "UpDown Ctrl creation, hwnd=%04x\n", hwnd);
|
---|
629 |
|
---|
630 | return 0;
|
---|
631 | }
|
---|
632 |
|
---|
633 | static LRESULT UPDOWN_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
634 | {
|
---|
635 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
636 |
|
---|
637 | if(infoPtr->AccelVect) COMCTL32_Free(infoPtr->AccelVect);
|
---|
638 |
|
---|
639 | COMCTL32_Free (infoPtr);
|
---|
640 |
|
---|
641 | // TRACE(updown, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
|
---|
642 |
|
---|
643 | return 0;
|
---|
644 | }
|
---|
645 |
|
---|
646 | static LRESULT UPDOWN_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
647 | {
|
---|
648 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
649 |
|
---|
650 | if (dwStyle & WS_DISABLED) UPDOWN_CancelMode(hwnd);
|
---|
651 | UPDOWN_Paint(hwnd);
|
---|
652 |
|
---|
653 | return 0;
|
---|
654 | }
|
---|
655 |
|
---|
656 | static LRESULT UPDOWN_Timer(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
657 | {
|
---|
658 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
659 | int temp;
|
---|
660 |
|
---|
661 | /* if initial timer, kill it and start the repeat timer */
|
---|
662 | if(wParam == TIMERID1)
|
---|
663 | {
|
---|
664 | KillTimer(hwnd, TIMERID1);
|
---|
665 | /* if no accel info given, used default timer */
|
---|
666 | if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0)
|
---|
667 | {
|
---|
668 | accelIndex = -1;
|
---|
669 | temp = REPEAT_DELAY;
|
---|
670 | } else
|
---|
671 | {
|
---|
672 | accelIndex = 0; /* otherwise, use it */
|
---|
673 | temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
|
---|
674 | }
|
---|
675 | SetTimer(hwnd, TIMERID2, temp, 0);
|
---|
676 | }
|
---|
677 |
|
---|
678 | /* now, if the mouse is above us, do the thing...*/
|
---|
679 | if(infoPtr->Flags & FLAG_MOUSEIN)
|
---|
680 | {
|
---|
681 | temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
|
---|
682 | UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR);
|
---|
683 |
|
---|
684 | if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1)
|
---|
685 | {
|
---|
686 | KillTimer(hwnd, TIMERID2);
|
---|
687 | accelIndex++; /* move to the next accel info */
|
---|
688 | temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
|
---|
689 | /* make sure we have at least 1ms intervals */
|
---|
690 | SetTimer(hwnd, TIMERID2, temp, 0);
|
---|
691 | }
|
---|
692 | }
|
---|
693 |
|
---|
694 | return 0;
|
---|
695 | }
|
---|
696 |
|
---|
697 | static LRESULT UPDOWN_LButtonUp(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
698 | {
|
---|
699 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
700 |
|
---|
701 | if (!UPDOWN_CancelMode(hwnd)) return 0;
|
---|
702 | /*If we released the mouse and our buddy is an edit */
|
---|
703 | /* we must select all text in it. */
|
---|
704 | if (!lstrcmpA(infoPtr->szBuddyClass,"Edit"))
|
---|
705 | SendMessageA(infoPtr->Buddy,EM_SETSEL,0,MAKELONG(0,-1));
|
---|
706 |
|
---|
707 | return 0;
|
---|
708 | }
|
---|
709 |
|
---|
710 | static LRESULT UPDOWN_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
711 | {
|
---|
712 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
713 |
|
---|
714 | if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd))
|
---|
715 | {
|
---|
716 | switch(wParam)
|
---|
717 | {
|
---|
718 | case VK_UP:
|
---|
719 | case VK_DOWN:
|
---|
720 | UPDOWN_GetBuddyInt (hwnd);
|
---|
721 | UPDOWN_DoAction (hwnd, 1, wParam==VK_UP);
|
---|
722 | break;
|
---|
723 | }
|
---|
724 | }
|
---|
725 |
|
---|
726 | return 0;
|
---|
727 | }
|
---|
728 |
|
---|
729 | static LRESULT UPDOWN_GetAccel(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
730 | {
|
---|
731 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
732 | INT temp;
|
---|
733 |
|
---|
734 | if (wParam == 0 && lParam == 0) /*if both zero, */
|
---|
735 | return infoPtr->AccelCount; /*just return the accel count*/
|
---|
736 | if (wParam || lParam)
|
---|
737 | {
|
---|
738 | UNKNOWN_PARAM(UDM_GETACCEL,wParam,lParam);
|
---|
739 | return 0;
|
---|
740 | }
|
---|
741 | temp = MIN(infoPtr->AccelCount,wParam);
|
---|
742 | memcpy((void *)lParam,infoPtr->AccelVect,temp*sizeof(UDACCEL));
|
---|
743 |
|
---|
744 | return temp;
|
---|
745 | }
|
---|
746 |
|
---|
747 | static LRESULT UPDOWN_SetAccel(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
748 | {
|
---|
749 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
750 |
|
---|
751 | // TRACE(updown, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
|
---|
752 | if(infoPtr->AccelVect)
|
---|
753 | {
|
---|
754 | COMCTL32_Free(infoPtr->AccelVect);
|
---|
755 | infoPtr->AccelCount = 0;
|
---|
756 | infoPtr->AccelVect = 0;
|
---|
757 | }
|
---|
758 | if(wParam == 0) return TRUE;
|
---|
759 | infoPtr->AccelVect = COMCTL32_Alloc(wParam*sizeof(UDACCEL));
|
---|
760 | if(infoPtr->AccelVect == 0) return FALSE;
|
---|
761 | memcpy(infoPtr->AccelVect,(void*)lParam,wParam*sizeof(UDACCEL));
|
---|
762 |
|
---|
763 | return TRUE;
|
---|
764 | }
|
---|
765 |
|
---|
766 | static LRESULT UPDOWN_GetBase(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
767 | {
|
---|
768 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
769 |
|
---|
770 | if (wParam || lParam) UNKNOWN_PARAM(UDM_GETBASE,wParam,lParam);
|
---|
771 |
|
---|
772 | return infoPtr->Base;
|
---|
773 | }
|
---|
774 |
|
---|
775 | static LRESULT UPDOWN_SetBase(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
776 | {
|
---|
777 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
778 | INT temp;
|
---|
779 |
|
---|
780 | // TRACE(updown, "UpDown Ctrl new base(%d), hwnd=%04x\n",
|
---|
781 | // wParam, hwnd);
|
---|
782 | if (!(wParam==10 || wParam==16) || lParam) UNKNOWN_PARAM(UDM_SETBASE,wParam,lParam);
|
---|
783 | if (wParam==10 || wParam==16)
|
---|
784 | {
|
---|
785 | temp = infoPtr->Base;
|
---|
786 | infoPtr->Base = wParam;
|
---|
787 | return temp; /* return the prev base */
|
---|
788 | }
|
---|
789 |
|
---|
790 | return 0;
|
---|
791 | }
|
---|
792 |
|
---|
793 | static LRESULT UPDOWN_GetBuddy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
794 | {
|
---|
795 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
796 |
|
---|
797 | if (wParam || lParam) UNKNOWN_PARAM(UDM_GETBUDDY,wParam,lParam);
|
---|
798 |
|
---|
799 | return infoPtr->Buddy;
|
---|
800 | }
|
---|
801 |
|
---|
802 |
|
---|
803 | static LRESULT UPDOWN_SetBuddy(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
804 | {
|
---|
805 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
806 | INT temp;
|
---|
807 |
|
---|
808 | if (lParam) UNKNOWN_PARAM(UDM_SETBUDDY,wParam,lParam);
|
---|
809 | temp = infoPtr->Buddy;
|
---|
810 | infoPtr->Buddy = wParam;
|
---|
811 | UPDOWN_SetBuddyHandle(hwnd,wParam);
|
---|
812 | // TRACE(updown, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
|
---|
813 | // infoPtr->Buddy, hwnd);
|
---|
814 |
|
---|
815 | return temp;
|
---|
816 | }
|
---|
817 |
|
---|
818 | static LRESULT UPDOWN_GetPos(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
819 | {
|
---|
820 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
821 | INT temp;
|
---|
822 |
|
---|
823 | if (wParam || lParam) UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
|
---|
824 | temp = UPDOWN_GetBuddyInt(hwnd);
|
---|
825 |
|
---|
826 | return MAKELONG(infoPtr->CurVal,temp ? 0:1);
|
---|
827 | }
|
---|
828 |
|
---|
829 | static LRESULT UPDOWN_SetPos(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
830 | {
|
---|
831 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
832 | DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE);
|
---|
833 | INT temp;
|
---|
834 |
|
---|
835 | if (wParam || HIWORD(lParam)) UNKNOWN_PARAM(UDM_GETPOS,wParam,lParam);
|
---|
836 | temp = SLOWORD(lParam);
|
---|
837 | // TRACE(updown, "UpDown Ctrl new value(%d), hwnd=%04x\n",
|
---|
838 | // temp, hwnd);
|
---|
839 | if (!UPDOWN_InBounds(hwnd, temp))
|
---|
840 | {
|
---|
841 | if (temp < infoPtr->MinVal) temp = infoPtr->MinVal;
|
---|
842 | if (temp > infoPtr->MaxVal) temp = infoPtr->MaxVal;
|
---|
843 | }
|
---|
844 | wParam = infoPtr->CurVal; /* save prev value */
|
---|
845 | infoPtr->CurVal = temp; /* set the new value */
|
---|
846 | if (dwStyle & UDS_SETBUDDYINT) UPDOWN_SetBuddyInt (hwnd);
|
---|
847 |
|
---|
848 | return wParam; /* return prev value */
|
---|
849 | }
|
---|
850 |
|
---|
851 | static LRESULT UPDOWN_GetRange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
852 | {
|
---|
853 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
854 |
|
---|
855 | if (wParam || lParam) UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
|
---|
856 |
|
---|
857 | return MAKELONG(infoPtr->MaxVal,infoPtr->MinVal);
|
---|
858 | }
|
---|
859 |
|
---|
860 | static LRESULT UPDOWN_SetRange(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
861 | {
|
---|
862 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
863 |
|
---|
864 | if (wParam) UNKNOWN_PARAM(UDM_SETRANGE,wParam,lParam); /* we must have: */
|
---|
865 | infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
|
---|
866 | infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
|
---|
867 | /* |Max-Min| <= UD_MAXVAL */
|
---|
868 | // TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
|
---|
869 | // infoPtr->MinVal, infoPtr->MaxVal, hwnd);
|
---|
870 |
|
---|
871 | return 0;
|
---|
872 | }
|
---|
873 |
|
---|
874 | static LRESULT UPDOWN_GetRange32(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
875 | {
|
---|
876 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
877 |
|
---|
878 | if (wParam) *(LPINT)wParam = infoPtr->MinVal;
|
---|
879 | if (lParam) *(LPINT)lParam = infoPtr->MaxVal;
|
---|
880 |
|
---|
881 | return 0;
|
---|
882 | }
|
---|
883 |
|
---|
884 | static LRESULT UPDOWN_SetRange32(HWND hwnd,WPARAM wParam,LPARAM lParam)
|
---|
885 | {
|
---|
886 | UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd);
|
---|
887 |
|
---|
888 | infoPtr->MinVal = (INT)wParam;
|
---|
889 | infoPtr->MaxVal = (INT)lParam;
|
---|
890 | if (infoPtr->MaxVal <= infoPtr->MinVal) infoPtr->MaxVal = infoPtr->MinVal+1;
|
---|
891 | // TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
|
---|
892 | // infoPtr->MinVal, infoPtr->MaxVal, hwnd);
|
---|
893 |
|
---|
894 | return 0;
|
---|
895 | }
|
---|
896 |
|
---|
897 | /***********************************************************************
|
---|
898 | * UpDownWndProc
|
---|
899 | */
|
---|
900 | LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
|
---|
901 | LPARAM lParam)
|
---|
902 | {
|
---|
903 | switch(message)
|
---|
904 | {
|
---|
905 | case WM_NCCREATE:
|
---|
906 | return UPDOWN_NCCreate(hwnd,wParam,lParam);
|
---|
907 |
|
---|
908 | case WM_CREATE:
|
---|
909 | return UPDOWN_Create(hwnd,wParam,lParam);
|
---|
910 |
|
---|
911 | case WM_DESTROY:
|
---|
912 | return UPDOWN_Destroy(hwnd,wParam,lParam);
|
---|
913 |
|
---|
914 | case WM_ENABLE:
|
---|
915 | return UPDOWN_Enable(hwnd,wParam,lParam);
|
---|
916 |
|
---|
917 | case WM_TIMER:
|
---|
918 | return UPDOWN_Timer(hwnd,wParam,lParam);
|
---|
919 |
|
---|
920 | case WM_CANCELMODE:
|
---|
921 | UPDOWN_CancelMode(hwnd);
|
---|
922 | break;
|
---|
923 |
|
---|
924 | case WM_LBUTTONUP:
|
---|
925 | return UPDOWN_LButtonUp(hwnd,wParam,lParam);
|
---|
926 |
|
---|
927 | case WM_LBUTTONDOWN:
|
---|
928 | case WM_MOUSEMOVE:
|
---|
929 | if(UPDOWN_IsEnabled(hwnd))
|
---|
930 | {
|
---|
931 | POINT pt;
|
---|
932 | CONV_POINT16TO32((POINT16 *)&lParam,&pt);
|
---|
933 | UPDOWN_HandleMouseEvent(hwnd,message,pt);
|
---|
934 | }
|
---|
935 | break;
|
---|
936 |
|
---|
937 | case WM_KEYDOWN:
|
---|
938 | return UPDOWN_KeyDown(hwnd,wParam,lParam);
|
---|
939 |
|
---|
940 | case WM_PAINT:
|
---|
941 | UPDOWN_Paint(hwnd);
|
---|
942 | break;
|
---|
943 |
|
---|
944 | case UDM_GETACCEL:
|
---|
945 | return UPDOWN_GetAccel(hwnd,wParam,lParam);
|
---|
946 |
|
---|
947 | case UDM_SETACCEL:
|
---|
948 | return UPDOWN_SetAccel(hwnd,wParam,lParam);
|
---|
949 |
|
---|
950 | case UDM_GETBASE:
|
---|
951 | return UPDOWN_GetBase(hwnd,wParam,lParam);
|
---|
952 |
|
---|
953 | case UDM_SETBASE:
|
---|
954 | return UPDOWN_SetBase(hwnd,wParam,lParam);
|
---|
955 |
|
---|
956 | case UDM_GETBUDDY:
|
---|
957 | return UPDOWN_GetBuddy(hwnd,wParam,lParam);
|
---|
958 |
|
---|
959 | case UDM_SETBUDDY:
|
---|
960 | return UPDOWN_SetBuddy(hwnd,wParam,lParam);
|
---|
961 |
|
---|
962 | case UDM_GETPOS:
|
---|
963 | return UPDOWN_GetPos(hwnd,wParam,lParam);
|
---|
964 |
|
---|
965 | case UDM_SETPOS:
|
---|
966 | return UPDOWN_SetPos(hwnd,wParam,lParam);
|
---|
967 |
|
---|
968 | case UDM_GETRANGE:
|
---|
969 | return UPDOWN_GetRange(hwnd,wParam,lParam);
|
---|
970 |
|
---|
971 | case UDM_SETRANGE:
|
---|
972 | return UPDOWN_SetRange(hwnd,wParam,lParam);
|
---|
973 |
|
---|
974 | case UDM_GETRANGE32:
|
---|
975 | return UPDOWN_GetRange32(hwnd,wParam,lParam);
|
---|
976 |
|
---|
977 | case UDM_SETRANGE32:
|
---|
978 | return UPDOWN_SetRange32(hwnd,wParam,lParam);
|
---|
979 |
|
---|
980 | default:
|
---|
981 | // if (message >= WM_USER)
|
---|
982 | // ERR (updown, "unknown msg %04x wp=%04x lp=%08lx\n",
|
---|
983 | // message, wParam, lParam);
|
---|
984 | return DefWindowProcA(hwnd,message,wParam,lParam);
|
---|
985 | }
|
---|
986 |
|
---|
987 | return 0;
|
---|
988 | }
|
---|
989 |
|
---|
990 |
|
---|
991 | /***********************************************************************
|
---|
992 | * UPDOWN_Register [Internal]
|
---|
993 | *
|
---|
994 | * Registers the updown window class.
|
---|
995 | */
|
---|
996 |
|
---|
997 | VOID
|
---|
998 | UPDOWN_Register(void)
|
---|
999 | {
|
---|
1000 | WNDCLASSA wndClass;
|
---|
1001 |
|
---|
1002 | if( GlobalFindAtomA( UPDOWN_CLASSA ) ) return;
|
---|
1003 |
|
---|
1004 | ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
|
---|
1005 | wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
|
---|
1006 | wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
|
---|
1007 | wndClass.cbClsExtra = 0;
|
---|
1008 | wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
|
---|
1009 | wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
|
---|
1010 | wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
|
---|
1011 | wndClass.lpszClassName = UPDOWN_CLASSA;
|
---|
1012 |
|
---|
1013 | RegisterClassA( &wndClass );
|
---|
1014 | }
|
---|
1015 |
|
---|
1016 |
|
---|
1017 | /***********************************************************************
|
---|
1018 | * UPDOWN_Unregister [Internal]
|
---|
1019 | *
|
---|
1020 | * Unregisters the updown window class.
|
---|
1021 | */
|
---|
1022 |
|
---|
1023 | VOID
|
---|
1024 | UPDOWN_Unregister (VOID)
|
---|
1025 | {
|
---|
1026 | if (GlobalFindAtomA (UPDOWN_CLASSA))
|
---|
1027 | UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);
|
---|
1028 | }
|
---|
1029 |
|
---|