4 * Copyright 1997 Dimitrie O. Paun
7 * - subclass the buddy window (in UPDOWN_SetBuddy) to process the
9 * - I am not sure about the default values for the Min, Max, Pos
10 * (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
11 * - I think I do not handle correctly the WS_BORDER style.
12 * (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
15 * Not much. The following have not been tested at all:
17 * - listbox as buddy window
20 * - UDS_ALIGNLEFT, ~UDS_WRAP
21 * (tested - they work)
22 * - integers with thousand separators.
23 * (fixed bugs. <noel@macadamian.com>)
25 * Even though the above list seems rather large, the control seems to
26 * behave very well so I am confident it does work in most (all) of the
29 * I do not like the arrows yet, I'll work more on them later on.
40 #include "debugtools.h"
42 DEFAULT_DEBUG_CHANNEL(updown)
44 /* Control configuration constants */
46 #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
47 #define REPEAT_DELAY 50 /* delay between auto-increments */
49 #define DEFAULT_WIDTH 14 /* default width of the ctrl */
50 #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
51 #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
52 #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
57 #define FLAG_INCR 0x01
58 #define FLAG_DECR 0x02
59 #define FLAG_MOUSEIN 0x04
60 #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
65 static int accelIndex = -1;
67 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(\
68 "UpDown Ctrl: Unknown parameter(s) for message " #msg \
69 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
71 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))
74 /***********************************************************************
76 * Tests if a given value 'val' is between the Min&Max limits
78 static BOOL UPDOWN_InBounds(HWND hwnd, int val)
80 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
82 if(infoPtr->MaxVal > infoPtr->MinVal)
83 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
85 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
88 /***********************************************************************
90 * Tests if we can change the current value by delta. If so, it changes
91 * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
93 static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
95 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
97 /* check if we can do the modification first */
98 if(!UPDOWN_InBounds (hwnd, infoPtr->CurVal+delta)){
99 if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_WRAP)
101 delta += (delta < 0 ? -1 : 1) *
102 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
103 (infoPtr->MinVal - infoPtr->MaxVal) +
104 (delta < 0 ? 1 : -1);
110 infoPtr->CurVal += delta;
114 /***********************************************************************
115 * UPDOWN_GetArrowRect
116 * wndPtr - pointer to the up-down wnd
117 * rect - will hold the rectangle
118 * incr - TRUE get the "increment" rect (up or right)
119 * FALSE get the "decrement" rect (down or left)
122 static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
124 int len; /* will hold the width or height */
126 GetClientRect (hwnd, rect);
128 if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_HORZ) {
129 len = rect->right - rect->left; /* compute the width */
131 rect->left = len/2+1;
136 len = rect->bottom - rect->top; /* compute the height */
138 rect->bottom = len/2;
144 /***********************************************************************
145 * UPDOWN_GetArrowFromPoint
146 * Returns the rectagle (for the up or down arrow) that contains pt.
147 * If it returns the up rect, it returns TRUE.
148 * If it returns the down rect, it returns FALSE.
151 UPDOWN_GetArrowFromPoint (HWND hwnd, RECT *rect, POINT pt)
153 UPDOWN_GetArrowRect (hwnd, rect, TRUE);
154 if(PtInRect(rect, pt))
157 UPDOWN_GetArrowRect (hwnd, rect, FALSE);
162 /***********************************************************************
163 * UPDOWN_GetThousandSep
164 * Returns the thousand sep. If an error occurs, it returns ','.
166 static char UPDOWN_GetThousandSep()
170 if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
171 sep, sizeof(sep)) != 1)
177 /***********************************************************************
179 * Tries to read the pos from the buddy window and if it succeeds,
180 * it stores it in the control's CurVal
182 * TRUE - if it read the integer from the buddy successfully
183 * FALSE - if an error occured
185 static BOOL UPDOWN_GetBuddyInt (HWND hwnd)
187 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
188 char txt[20], sep, *src, *dst;
191 if (!IsWindow(infoPtr->Buddy))
194 /*if the buddy is a list window, we must set curr index */
195 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
196 newVal = SendMessageA(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0);
201 /* we have a regular window, so will get the text */
202 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt)))
205 sep = UPDOWN_GetThousandSep();
207 /* now get rid of the separators */
208 for(src = dst = txt; *src; src++)
213 /* try to convert the number and validate it */
214 newVal = strtol(txt, &src, infoPtr->Base);
215 if(*src || !UPDOWN_InBounds (hwnd, newVal))
218 TRACE("new value(%d) read from buddy (old=%d)\n",
219 newVal, infoPtr->CurVal);
222 infoPtr->CurVal = newVal;
227 /***********************************************************************
229 * Tries to set the pos to the buddy window based on current pos
231 * TRUE - if it set the caption of the buddy successfully
232 * FALSE - if an error occured
234 static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
236 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
240 if (!IsWindow(infoPtr->Buddy))
243 TRACE("set new value(%d) to buddy.\n",
246 /*if the buddy is a list window, we must set curr index */
247 if(!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
248 SendMessageA(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0);
250 else{ /* Regular window, so set caption to the number */
251 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
253 sep = UPDOWN_GetThousandSep();
255 /* Do thousands seperation if necessary */
256 if (!(GetWindowLongA (hwnd, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
257 char txt2[20], *src = txt1, *dst = txt2;
259 lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
263 for(len=0; *src; len++){
268 *dst = 0; /* null terminate it */
269 strcpy(txt1, txt2); /* move it to the proper place */
271 SetWindowTextA(infoPtr->Buddy, txt1);
277 /***********************************************************************
278 * UPDOWN_Draw [Internal]
280 * Draw the arrows. The background need not be erased.
282 static void UPDOWN_Draw (HWND hwnd, HDC hdc)
284 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
285 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
289 /* Draw the incr button */
290 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
291 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
292 DrawFrameControl(hdc, &rect, DFC_SCROLL,
293 (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
294 (prssed ? DFCS_PUSHED : 0) |
295 (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
297 /* Draw the space between the buttons */
298 rect.top = rect.bottom; rect.bottom++;
299 DrawEdge(hdc, &rect, 0, BF_MIDDLE);
301 /* Draw the decr button */
302 UPDOWN_GetArrowRect(hwnd, &rect, FALSE);
303 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
304 DrawFrameControl(hdc, &rect, DFC_SCROLL,
305 (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
306 (prssed ? DFCS_PUSHED : 0) |
307 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
310 /***********************************************************************
311 * UPDOWN_Refresh [Internal]
313 * Synchronous drawing (must NOT be used in WM_PAINT).
316 static void UPDOWN_Refresh (HWND hwnd)
321 UPDOWN_Draw (hwnd, hdc);
322 ReleaseDC (hwnd, hdc);
326 /***********************************************************************
327 * UPDOWN_Paint [Internal]
329 * Asynchronous drawing (must ONLY be used in WM_PAINT).
332 static void UPDOWN_Paint (HWND hwnd)
337 hdc = BeginPaint (hwnd, &ps);
338 UPDOWN_Draw (hwnd, hdc);
339 EndPaint (hwnd, &ps);
342 /***********************************************************************
344 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
345 * Else, sets it as a new Buddy.
346 * Then, it should subclass the buddy
347 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
348 * process the UP/DOWN arrow keys.
349 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
350 * the size/pos of the buddy and the control are adjusted accordingly.
352 static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
354 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
355 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
356 RECT budRect; /* new coord for the buddy */
357 int x; /* new x position and width for the up-down */
359 *infoPtr->szBuddyClass = '\0';
361 /* Is is a valid bud? */
362 if(!IsWindow(hwndBud))
365 /* Store buddy window handle */
366 infoPtr->Buddy = hwndBud;
368 /* Store buddy window clas name */
369 GetClassNameA (hwndBud, infoPtr->szBuddyClass, 40);
371 if(dwStyle & UDS_ARROWKEYS){
372 FIXME("we need to subclass the buddy to process the arrow keys.\n");
375 /* do we need to do any adjustments? */
376 if(!(dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
379 infoPtr->Buddy = hwndBud;
381 /* Get the rect of the buddy relative to its parent */
382 GetWindowRect(infoPtr->Buddy, &budRect);
383 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
384 (POINT *)(&budRect.left), 2);
386 /* now do the positioning */
387 if(dwStyle & UDS_ALIGNRIGHT){
388 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
389 x = budRect.right+DEFAULT_XSEP;
391 else{ /* UDS_ALIGNLEFT */
393 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
396 /* first adjust the buddy to accomodate the up/down */
397 SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
398 budRect.right - budRect.left, budRect.bottom - budRect.top,
399 SWP_NOACTIVATE|SWP_NOZORDER);
401 /* now position the up/down */
402 /* Since the UDS_ALIGN* flags were used, */
403 /* we will pick the position and size of the window. */
405 SetWindowPos (hwnd, 0, x, budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
406 (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
407 SWP_NOACTIVATE|SWP_NOZORDER);
412 /***********************************************************************
415 * This function increments/decrements the CurVal by the
416 * 'delta' amount according to the 'incr' flag
417 * It notifies the parent as required.
418 * It handles wraping and non-wraping correctly.
419 * It is assumed that delta>0
421 static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr)
423 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
424 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
425 int old_val = infoPtr->CurVal;
428 TRACE("%s by %d\n", incr ? "inc" : "dec", delta);
430 /* check if we can do the modification first */
431 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
432 if(!UPDOWN_OffsetVal (hwnd, delta))
435 /* so, if we can do the change, recompute delta and restore old value */
436 delta = infoPtr->CurVal - old_val;
437 infoPtr->CurVal = old_val;
439 /* We must notify parent now to obtain permission */
440 ni.iPos = infoPtr->CurVal;
442 ni.hdr.hwndFrom = hwnd;
443 ni.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
444 ni.hdr.code = UDN_DELTAPOS;
445 if (SendMessageA(GetParent (hwnd), WM_NOTIFY,
446 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))
447 return; /* we are not allowed to change */
449 /* Now adjust value with (maybe new) delta */
450 if (!UPDOWN_OffsetVal (hwnd, ni.iDelta))
453 /* Now take care about our buddy */
454 if(!IsWindow(infoPtr->Buddy))
455 return; /* Nothing else to do */
458 if (dwStyle & UDS_SETBUDDYINT)
459 UPDOWN_SetBuddyInt (hwnd);
461 /* Also, notify it */
462 /* FIXME: do we need to send the notification only if
463 we do not have the UDS_SETBUDDYINT style set? */
465 SendMessageA (GetParent (hwnd),
466 dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
467 MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
471 /***********************************************************************
474 * Returns TRUE if it is enabled as well as its buddy (if any)
477 static BOOL UPDOWN_IsEnabled (HWND hwnd)
479 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
481 if(GetWindowLongA (hwnd, GWL_STYLE) & WS_DISABLED)
483 return IsWindowEnabled(infoPtr->Buddy);
486 /***********************************************************************
489 * Deletes any timers, releases the mouse and does redraw if necessary.
490 * If the control is not in "capture" mode, it does nothing.
491 * If the control was not in cancel mode, it returns FALSE.
492 * If the control was in cancel mode, it returns TRUE.
494 static BOOL UPDOWN_CancelMode (HWND hwnd)
496 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
498 /* if not in 'capture' mode, do nothing */
499 if(!(infoPtr->Flags & FLAG_CLICKED))
502 KillTimer (hwnd, TIMERID1); /* kill all possible timers */
503 KillTimer (hwnd, TIMERID2);
505 if (GetCapture() == hwnd) /* let the mouse go */
506 ReleaseCapture(); /* if we still have it */
508 infoPtr->Flags = 0; /* get rid of any flags */
509 UPDOWN_Refresh (hwnd); /* redraw the control just in case */
514 /***********************************************************************
515 * UPDOWN_HandleMouseEvent
517 * Handle a mouse event for the updown.
518 * 'pt' is the location of the mouse event in client or
519 * windows coordinates.
521 static void UPDOWN_HandleMouseEvent (HWND hwnd, UINT msg, POINT pt)
523 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
524 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
530 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
531 /* If we are already in the 'clicked' mode, then nothing to do */
532 if(infoPtr->Flags & FLAG_CLICKED)
535 /* If the buddy is an edit, will set focus to it */
536 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
537 SetFocus(infoPtr->Buddy);
539 /* Now see which one is the 'active' arrow */
540 temp = UPDOWN_GetArrowFromPoint (hwnd, &rect, pt);
542 /* Update the CurVal if necessary */
543 if (dwStyle & UDS_SETBUDDYINT)
544 UPDOWN_GetBuddyInt (hwnd);
546 /* Before we proceed, see if we can spin... */
547 if(!(dwStyle & UDS_WRAP))
548 if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
549 (!temp && infoPtr->CurVal==infoPtr->MinVal))
552 /* Set up the correct flags */
554 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
555 infoPtr->Flags |= FLAG_MOUSEIN;
557 /* repaint the control */
558 UPDOWN_Refresh (hwnd);
560 /* process the click */
561 UPDOWN_DoAction (hwnd, 1, infoPtr->Flags & FLAG_INCR);
563 /* now capture all mouse messages */
566 /* and startup the first timer */
567 SetTimer(hwnd, TIMERID1, INITIAL_DELAY, 0);
571 /* If we are not in the 'clicked' mode, then nothing to do */
572 if(!(infoPtr->Flags & FLAG_CLICKED))
575 /* save the flags to see if any got modified */
576 temp = infoPtr->Flags;
578 /* Now get the 'active' arrow rectangle */
579 if (infoPtr->Flags & FLAG_INCR)
580 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
582 UPDOWN_GetArrowRect (hwnd, &rect, FALSE);
584 /* Update the flags if we are in/out */
585 if(PtInRect(&rect, pt))
586 infoPtr->Flags |= FLAG_MOUSEIN;
588 infoPtr->Flags &= ~FLAG_MOUSEIN;
589 if(accelIndex != -1) /* if we have accel info */
590 accelIndex = 0; /* reset it */
592 /* If state changed, redraw the control */
593 if(temp != infoPtr->Flags)
594 UPDOWN_Refresh (hwnd);
598 ERR("Impossible case!\n");
603 /***********************************************************************
606 LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
609 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
610 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
616 /* get rid of border, if any */
617 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER);
621 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
622 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
624 /* initialize the info struct */
625 infoPtr->AccelCount=0; infoPtr->AccelVect=0;
626 infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
627 infoPtr->Base = 10; /* Default to base 10 */
628 infoPtr->Buddy = 0; /* No buddy window yet */
629 infoPtr->Flags = 0; /* And no flags */
631 /* Do we pick the buddy win ourselves? */
632 if (dwStyle & UDS_AUTOBUDDY)
633 UPDOWN_SetBuddy (hwnd, GetWindow (hwnd, GW_HWNDPREV));
635 TRACE("UpDown Ctrl creation, hwnd=%04x\n", hwnd);
639 if(infoPtr->AccelVect)
640 COMCTL32_Free (infoPtr->AccelVect);
642 COMCTL32_Free (infoPtr);
644 TRACE("UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
648 if (dwStyle & WS_DISABLED)
649 UPDOWN_CancelMode (hwnd);
654 /* if initial timer, kill it and start the repeat timer */
655 if(wParam == TIMERID1){
656 KillTimer(hwnd, TIMERID1);
657 /* if no accel info given, used default timer */
658 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
663 accelIndex = 0; /* otherwise, use it */
664 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
666 SetTimer(hwnd, TIMERID2, temp, 0);
669 /* now, if the mouse is above us, do the thing...*/
670 if(infoPtr->Flags & FLAG_MOUSEIN){
671 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
672 UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR);
674 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
675 KillTimer(hwnd, TIMERID2);
676 accelIndex++; /* move to the next accel info */
677 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
678 /* make sure we have at least 1ms intervals */
679 SetTimer(hwnd, TIMERID2, temp, 0);
685 UPDOWN_CancelMode (hwnd);
689 if(!UPDOWN_CancelMode(hwnd))
691 /*If we released the mouse and our buddy is an edit */
692 /* we must select all text in it. */
693 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
694 SendMessageA(infoPtr->Buddy, EM_SETSEL, 0, MAKELONG(0, -1));
699 if(UPDOWN_IsEnabled(hwnd)){
701 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
702 UPDOWN_HandleMouseEvent (hwnd, message, pt );
707 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd)){
711 UPDOWN_GetBuddyInt (hwnd);
712 UPDOWN_DoAction (hwnd, 1, wParam==VK_UP);
723 if (wParam==0 && lParam==0) /*if both zero, */
724 return infoPtr->AccelCount; /*just return the accel count*/
725 if (wParam || lParam){
726 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
729 temp = MIN(infoPtr->AccelCount, wParam);
730 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
734 TRACE("UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
735 if(infoPtr->AccelVect){
736 COMCTL32_Free (infoPtr->AccelVect);
737 infoPtr->AccelCount = 0;
738 infoPtr->AccelVect = 0;
742 infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
743 if(infoPtr->AccelVect==0)
745 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
749 if (wParam || lParam)
750 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
751 return infoPtr->Base;
754 TRACE("UpDown Ctrl new base(%d), hwnd=%04x\n",
756 if ( !(wParam==10 || wParam==16) || lParam)
757 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
758 if (wParam==10 || wParam==16){
759 temp = infoPtr->Base;
760 infoPtr->Base = wParam;
761 return temp; /* return the prev base */
766 if (wParam || lParam)
767 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
768 return infoPtr->Buddy;
772 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
773 temp = infoPtr->Buddy;
774 infoPtr->Buddy = wParam;
775 UPDOWN_SetBuddy (hwnd, wParam);
776 TRACE("UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
777 infoPtr->Buddy, hwnd);
781 if (wParam || lParam)
782 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
783 temp = UPDOWN_GetBuddyInt (hwnd);
784 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
787 if (wParam || HIWORD(lParam))
788 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
789 temp = SLOWORD(lParam);
790 TRACE("UpDown Ctrl new value(%d), hwnd=%04x\n",
792 if(!UPDOWN_InBounds(hwnd, temp)){
793 if(temp < infoPtr->MinVal)
794 temp = infoPtr->MinVal;
795 if(temp > infoPtr->MaxVal)
796 temp = infoPtr->MaxVal;
798 wParam = infoPtr->CurVal; /* save prev value */
799 infoPtr->CurVal = temp; /* set the new value */
800 if(dwStyle & UDS_SETBUDDYINT)
801 UPDOWN_SetBuddyInt (hwnd);
802 return wParam; /* return prev value */
805 if (wParam || lParam)
806 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
807 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
811 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
812 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
813 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
814 /* |Max-Min| <= UD_MAXVAL */
815 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
816 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
821 *(LPINT)wParam = infoPtr->MinVal;
823 *(LPINT)lParam = infoPtr->MaxVal;
827 infoPtr->MinVal = (INT)wParam;
828 infoPtr->MaxVal = (INT)lParam;
829 if (infoPtr->MaxVal <= infoPtr->MinVal)
830 infoPtr->MaxVal = infoPtr->MinVal + 1;
831 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
832 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
836 if (message >= WM_USER)
837 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
838 message, wParam, lParam);
839 return DefWindowProcA (hwnd, message, wParam, lParam);
846 /***********************************************************************
847 * UPDOWN_Register [Internal]
849 * Registers the updown window class.
853 UPDOWN_Register(void)
857 if( GlobalFindAtomA( UPDOWN_CLASSA ) ) return;
859 ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
860 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
861 wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
862 wndClass.cbClsExtra = 0;
863 wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
864 wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
865 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
866 wndClass.lpszClassName = UPDOWN_CLASSA;
868 RegisterClassA( &wndClass );
872 /***********************************************************************
873 * UPDOWN_Unregister [Internal]
875 * Unregisters the updown window class.
879 UPDOWN_Unregister (void)
881 if (GlobalFindAtomA (UPDOWN_CLASSA))
882 UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);