4 * Copyright 1997 Dimitrie O. Paun
7 * - I am not sure about the default values for the Min, Max, Pos
8 * (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
9 * - I think I do not handle correctly the WS_BORDER style.
10 * (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
13 * Not much. The following have not been tested at all:
15 * - listbox as buddy window
18 * - UDS_ALIGNLEFT, ~UDS_WRAP
19 * (tested - they work)
20 * - integers with thousand separators.
21 * (fixed bugs. <noel@macadamian.com>)
23 * Even though the above list seems rather large, the control seems to
24 * behave very well so I am confident it does work in most (all) of the
27 * I do not like the arrows yet, I'll work more on them later on.
41 #include "debugtools.h"
43 DEFAULT_DEBUG_CHANNEL(updown);
45 /* Control configuration constants */
47 #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
48 #define REPEAT_DELAY 50 /* delay between auto-increments */
50 #define DEFAULT_WIDTH 14 /* default width of the ctrl */
51 #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
52 #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
53 #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
54 #define DEFAULT_BUDDYBORDER 2 /* Width/height of the buddy border */
59 #define FLAG_INCR 0x01
60 #define FLAG_DECR 0x02
61 #define FLAG_MOUSEIN 0x04
62 #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
66 #define BUDDY_UPDOWN_HWND "buddyUpDownHWND"
67 #define BUDDY_SUPERCLASS_WNDPROC "buddySupperClassWndProc"
69 static int accelIndex = -1;
71 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(\
72 "UpDown Ctrl: Unknown parameter(s) for message " #msg \
73 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
75 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))
77 static LRESULT CALLBACK
78 UPDOWN_Buddy_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
80 /***********************************************************************
82 * Tests if a given value 'val' is between the Min&Max limits
84 static BOOL UPDOWN_InBounds(HWND hwnd, int val)
86 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
88 if(infoPtr->MaxVal > infoPtr->MinVal)
89 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
91 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
94 /***********************************************************************
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.
99 static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
101 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
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)
107 delta += (delta < 0 ? -1 : 1) *
108 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
109 (infoPtr->MinVal - infoPtr->MaxVal) +
110 (delta < 0 ? 1 : -1);
116 infoPtr->CurVal += delta;
120 /***********************************************************************
121 * UPDOWN_HasBuddyBorder [Internal]
123 * When we have a buddy set and that we are aligned on our buddy, we
124 * want to draw a sunken edge to make like we are part of that control.
126 static BOOL UPDOWN_HasBuddyBorder(HWND hwnd)
128 UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
129 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
131 return ( ((dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)) != 0) &&
132 (SendMessageA(hwnd, UDM_GETBUDDY, 0, 0) != 0) &&
133 (lstrcmpiA(infoPtr->szBuddyClass, "EDIT") == 0 ) );
136 /***********************************************************************
137 * UPDOWN_GetArrowRect
138 * wndPtr - pointer to the up-down wnd
139 * rect - will hold the rectangle
140 * incr - TRUE get the "increment" rect (up or right)
141 * FALSE get the "decrement" rect (down or left)
144 static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
146 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
147 int len; /* will hold the width or height */
149 GetClientRect (hwnd, rect);
152 * Make sure we calculate the rectangle to fit even if we draw the
155 if (UPDOWN_HasBuddyBorder(hwnd))
157 if (dwStyle & UDS_ALIGNLEFT)
158 rect->left+=DEFAULT_BUDDYBORDER;
160 rect->right-=DEFAULT_BUDDYBORDER;
162 InflateRect(rect, 0, -DEFAULT_BUDDYBORDER);
166 * We're calculating the midpoint to figure-out where the
167 * separation between the buttons will lay. We make sure that we
168 * round the uneven numbers by adding 1.
170 if (dwStyle & UDS_HORZ) {
171 len = rect->right - rect->left + 1; /* compute the width */
173 rect->left = rect->left + len/2;
175 rect->right = rect->left + len/2;
178 len = rect->bottom - rect->top + 1; /* compute the height */
180 rect->bottom = rect->top + len/2;
182 rect->top = rect->top + len/2;
186 /***********************************************************************
187 * UPDOWN_GetArrowFromPoint
188 * Returns the rectagle (for the up or down arrow) that contains pt.
189 * If it returns the up rect, it returns TRUE.
190 * If it returns the down rect, it returns FALSE.
193 UPDOWN_GetArrowFromPoint (HWND hwnd, RECT *rect, POINT pt)
195 UPDOWN_GetArrowRect (hwnd, rect, TRUE);
196 if(PtInRect(rect, pt))
199 UPDOWN_GetArrowRect (hwnd, rect, FALSE);
204 /***********************************************************************
205 * UPDOWN_GetThousandSep
206 * Returns the thousand sep. If an error occurs, it returns ','.
208 static char UPDOWN_GetThousandSep()
212 if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
213 sep, sizeof(sep)) != 1)
219 /***********************************************************************
221 * Tries to read the pos from the buddy window and if it succeeds,
222 * it stores it in the control's CurVal
224 * TRUE - if it read the integer from the buddy successfully
225 * FALSE - if an error occured
227 static BOOL UPDOWN_GetBuddyInt (HWND hwnd)
229 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
230 char txt[20], sep, *src, *dst;
233 if (!IsWindow(infoPtr->Buddy))
236 /*if the buddy is a list window, we must set curr index */
237 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
238 newVal = SendMessageA(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0);
243 /* we have a regular window, so will get the text */
244 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt)))
247 sep = UPDOWN_GetThousandSep();
249 /* now get rid of the separators */
250 for(src = dst = txt; *src; src++)
255 /* try to convert the number and validate it */
256 newVal = strtol(txt, &src, infoPtr->Base);
257 if(*src || !UPDOWN_InBounds (hwnd, newVal))
260 TRACE("new value(%d) read from buddy (old=%d)\n",
261 newVal, infoPtr->CurVal);
264 infoPtr->CurVal = newVal;
269 /***********************************************************************
271 * Tries to set the pos to the buddy window based on current pos
273 * TRUE - if it set the caption of the buddy successfully
274 * FALSE - if an error occured
276 static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
278 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
282 if (!IsWindow(infoPtr->Buddy))
285 TRACE("set new value(%d) to buddy.\n",
288 /*if the buddy is a list window, we must set curr index */
289 if(!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
290 SendMessageA(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0);
292 else{ /* Regular window, so set caption to the number */
293 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
295 sep = UPDOWN_GetThousandSep();
297 /* Do thousands seperation if necessary */
298 if (!(GetWindowLongA (hwnd, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
299 char txt2[20], *src = txt1, *dst = txt2;
301 lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
305 for(len=0; *src; len++){
310 *dst = 0; /* null terminate it */
311 strcpy(txt1, txt2); /* move it to the proper place */
313 SetWindowTextA(infoPtr->Buddy, txt1);
319 /***********************************************************************
320 * UPDOWN_DrawBuddyBorder [Internal]
322 * When we have a buddy set and that we are aligned on our buddy, we
323 * want to draw a sunken edge to make like we are part of that control.
325 static void UPDOWN_DrawBuddyBorder (HWND hwnd, HDC hdc)
327 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
330 GetClientRect(hwnd, &clientRect);
332 if (dwStyle & UDS_ALIGNLEFT)
333 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_LEFT | BF_TOP);
335 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_RIGHT | BF_TOP);
338 /***********************************************************************
339 * UPDOWN_Draw [Internal]
341 * Draw the arrows. The background need not be erased.
343 static void UPDOWN_Draw (HWND hwnd, HDC hdc)
345 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
346 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
351 * Draw the common border between ourselves and our buddy.
353 if (UPDOWN_HasBuddyBorder(hwnd))
354 UPDOWN_DrawBuddyBorder(hwnd, hdc);
356 /* Draw the incr button */
357 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
358 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
359 DrawFrameControl(hdc, &rect, DFC_SCROLL,
360 (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLUP) |
361 (prssed ? DFCS_PUSHED : 0) |
362 (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
364 /* Draw the space between the buttons */
365 rect.top = rect.bottom; rect.bottom++;
366 DrawEdge(hdc, &rect, 0, BF_MIDDLE);
368 /* Draw the decr button */
369 UPDOWN_GetArrowRect(hwnd, &rect, FALSE);
370 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
371 DrawFrameControl(hdc, &rect, DFC_SCROLL,
372 (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLDOWN) |
373 (prssed ? DFCS_PUSHED : 0) |
374 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
377 /***********************************************************************
378 * UPDOWN_Refresh [Internal]
380 * Synchronous drawing (must NOT be used in WM_PAINT).
383 static void UPDOWN_Refresh (HWND hwnd)
388 UPDOWN_Draw (hwnd, hdc);
389 ReleaseDC (hwnd, hdc);
393 /***********************************************************************
394 * UPDOWN_Paint [Internal]
396 * Asynchronous drawing (must ONLY be used in WM_PAINT).
399 static void UPDOWN_Paint (HWND hwnd, HDC passedDC)
405 hdc = BeginPaint (hwnd, &ps);
407 UPDOWN_Draw (hwnd, hdc);
410 EndPaint (hwnd, &ps);
413 /***********************************************************************
415 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
416 * Else, sets it as a new Buddy.
417 * Then, it should subclass the buddy
418 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
419 * process the UP/DOWN arrow keys.
420 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
421 * the size/pos of the buddy and the control are adjusted accordingly.
423 static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
425 UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
426 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
427 RECT budRect; /* new coord for the buddy */
428 int x,width; /* new x position and width for the up-down */
429 WNDPROC baseWndProc, currWndProc;
431 /* Is it a valid bud? */
432 if(!IsWindow(hwndBud))
435 /* there is already a body assigned */
436 if ( infoPtr->Buddy )
437 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
439 /* Store buddy window handle */
440 infoPtr->Buddy = hwndBud;
442 /* keep upDown ctrl hwnd in a buddy property */
443 SetPropA( hwndBud, BUDDY_UPDOWN_HWND, hwnd);
445 /* Store buddy window clas name */
446 memset(infoPtr->szBuddyClass, 0, UPDOWN_BUDDYCLASSNAMELEN);
447 GetClassNameA (hwndBud, infoPtr->szBuddyClass, UPDOWN_BUDDYCLASSNAMELEN-1);
449 if(dwStyle & UDS_ARROWKEYS){
450 /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
451 when we reset the upDown ctrl buddy to another buddy because it is not
452 good to break the window proc chain. */
454 currWndProc = (WNDPROC) GetWindowLongA(hwndBud, GWL_WNDPROC);
455 if (currWndProc != UPDOWN_Buddy_SubclassProc)
457 // replace the buddy's WndProc with ours
458 baseWndProc = (WNDPROC)SetWindowLongA(hwndBud, GWL_WNDPROC,
459 (LPARAM)UPDOWN_Buddy_SubclassProc);
460 // and save the base class' WndProc
461 SetPropA(hwndBud, BUDDY_SUPERCLASS_WNDPROC, (HANDLE)baseWndProc);
464 // its already been subclassed, don't overwrite BUDDY_SUPERCLASS_WNDPROC
467 /* do we need to do any adjustments? */
468 if(!(dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
471 /* Get the rect of the buddy relative to its parent */
472 GetWindowRect(infoPtr->Buddy, &budRect);
473 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
474 (POINT *)(&budRect.left), 2);
476 /* now do the positioning */
477 if(dwStyle & UDS_ALIGNRIGHT){
478 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
479 x = budRect.right+DEFAULT_XSEP;
481 else{ /* UDS_ALIGNLEFT */
483 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
486 /* first adjust the buddy to accomodate the up/down */
487 SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
488 budRect.right - budRect.left, budRect.bottom - budRect.top,
489 SWP_NOACTIVATE|SWP_NOZORDER);
491 /* now position the up/down */
492 /* Since the UDS_ALIGN* flags were used, */
493 /* we will pick the position and size of the window. */
494 width = DEFAULT_WIDTH;
497 * If the updown has a buddy border, it has to overlap with the buddy
498 * to look as if it is integrated with the buddy control.
499 * We nudge the control or change it size to overlap.
501 if (UPDOWN_HasBuddyBorder(hwnd))
503 if(dwStyle & UDS_ALIGNRIGHT)
504 x-=DEFAULT_BUDDYBORDER;
506 width+=DEFAULT_BUDDYBORDER;
509 SetWindowPos (hwnd, infoPtr->Buddy,
510 x, budRect.top-DEFAULT_ADDTOP,
511 width, (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
517 /***********************************************************************
520 * This function increments/decrements the CurVal by the
521 * 'delta' amount according to the 'incr' flag
522 * It notifies the parent as required.
523 * It handles wraping and non-wraping correctly.
524 * It is assumed that delta>0
526 static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr)
528 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
529 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
532 TRACE("%s by %d\n", incr ? "inc" : "dec", delta);
534 /* check if we can do the modification first */
535 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
537 /* We must notify parent now to obtain permission */
538 ni.iPos = infoPtr->CurVal;
540 ni.hdr.hwndFrom = hwnd;
541 ni.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
542 ni.hdr.code = UDN_DELTAPOS;
543 if (!SendMessageA(GetParent (hwnd), WM_NOTIFY,
544 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))
546 /* Parent said: OK to adjust */
548 /* Now adjust value with (maybe new) delta */
549 if (UPDOWN_OffsetVal (hwnd, ni.iDelta))
551 /* Now take care about our buddy */
552 if(infoPtr->Buddy && IsWindow(infoPtr->Buddy)
553 && (dwStyle & UDS_SETBUDDYINT) )
554 UPDOWN_SetBuddyInt (hwnd);
558 /* Also, notify it. This message is sent in any case. */
559 SendMessageA (GetParent (hwnd),
560 dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
561 MAKELONG(SB_THUMBPOSITION, infoPtr->CurVal), hwnd);
564 /***********************************************************************
567 * Returns TRUE if it is enabled as well as its buddy (if any)
570 static BOOL UPDOWN_IsEnabled (HWND hwnd)
572 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
574 if(GetWindowLongA (hwnd, GWL_STYLE) & WS_DISABLED)
577 return IsWindowEnabled(infoPtr->Buddy);
581 /***********************************************************************
584 * Deletes any timers, releases the mouse and does redraw if necessary.
585 * If the control is not in "capture" mode, it does nothing.
586 * If the control was not in cancel mode, it returns FALSE.
587 * If the control was in cancel mode, it returns TRUE.
589 static BOOL UPDOWN_CancelMode (HWND hwnd)
591 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
593 /* if not in 'capture' mode, do nothing */
594 if(!(infoPtr->Flags & FLAG_CLICKED))
597 KillTimer (hwnd, TIMERID1); /* kill all possible timers */
598 KillTimer (hwnd, TIMERID2);
600 if (GetCapture() == hwnd) /* let the mouse go */
601 ReleaseCapture(); /* if we still have it */
603 infoPtr->Flags = 0; /* get rid of any flags */
604 UPDOWN_Refresh (hwnd); /* redraw the control just in case */
609 /***********************************************************************
610 * UPDOWN_HandleMouseEvent
612 * Handle a mouse event for the updown.
613 * 'pt' is the location of the mouse event in client or
614 * windows coordinates.
616 static void UPDOWN_HandleMouseEvent (HWND hwnd, UINT msg, POINT pt)
618 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
619 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
625 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
626 /* If we are already in the 'clicked' mode, then nothing to do */
627 if(infoPtr->Flags & FLAG_CLICKED)
630 /* If the buddy is an edit, will set focus to it */
631 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
632 SetFocus(infoPtr->Buddy);
634 /* Now see which one is the 'active' arrow */
635 temp = UPDOWN_GetArrowFromPoint (hwnd, &rect, pt);
637 /* Update the CurVal if necessary */
638 if (dwStyle & UDS_SETBUDDYINT)
639 UPDOWN_GetBuddyInt (hwnd);
641 /* Set up the correct flags */
643 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
644 infoPtr->Flags |= FLAG_MOUSEIN;
646 /* repaint the control */
647 UPDOWN_Refresh (hwnd);
649 /* process the click */
650 UPDOWN_DoAction (hwnd, 1, infoPtr->Flags & FLAG_INCR);
652 /* now capture all mouse messages */
655 /* and startup the first timer */
656 SetTimer(hwnd, TIMERID1, INITIAL_DELAY, 0);
660 /* If we are not in the 'clicked' mode, then nothing to do */
661 if(!(infoPtr->Flags & FLAG_CLICKED))
664 /* save the flags to see if any got modified */
665 temp = infoPtr->Flags;
667 /* Now get the 'active' arrow rectangle */
668 if (infoPtr->Flags & FLAG_INCR)
669 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
671 UPDOWN_GetArrowRect (hwnd, &rect, FALSE);
673 /* Update the flags if we are in/out */
674 if(PtInRect(&rect, pt))
675 infoPtr->Flags |= FLAG_MOUSEIN;
677 infoPtr->Flags &= ~FLAG_MOUSEIN;
678 if(accelIndex != -1) /* if we have accel info */
679 accelIndex = 0; /* reset it */
681 /* If state changed, redraw the control */
682 if(temp != infoPtr->Flags)
683 UPDOWN_Refresh (hwnd);
687 ERR("Impossible case!\n");
692 /***********************************************************************
695 static LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
698 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
699 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
701 if (!infoPtr && (message != WM_CREATE) && (message != WM_NCCREATE))
702 return DefWindowProcA (hwnd, message, wParam, lParam);
706 /* get rid of border, if any */
707 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER);
711 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
712 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
714 /* initialize the info struct */
715 infoPtr->AccelCount=0; infoPtr->AccelVect=0;
716 infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
717 infoPtr->Base = 10; /* Default to base 10 */
718 infoPtr->Buddy = 0; /* No buddy window yet */
719 infoPtr->Flags = 0; /* And no flags */
721 /* Do we pick the buddy win ourselves? */
722 if (dwStyle & UDS_AUTOBUDDY)
723 UPDOWN_SetBuddy (hwnd, GetWindow (hwnd, GW_HWNDPREV));
725 TRACE("UpDown Ctrl creation, hwnd=%04x\n", hwnd);
729 if(infoPtr->AccelVect)
730 COMCTL32_Free (infoPtr->AccelVect);
732 if ( IsWindow(infoPtr->Buddy) ) /* Cleanup */
733 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
735 COMCTL32_Free (infoPtr);
736 SetWindowLongA (hwnd, 0, 0);
737 TRACE("UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
741 if (dwStyle & WS_DISABLED)
742 UPDOWN_CancelMode (hwnd);
744 UPDOWN_Refresh (hwnd);
748 /* if initial timer, kill it and start the repeat timer */
749 if(wParam == TIMERID1){
750 KillTimer(hwnd, TIMERID1);
751 /* if no accel info given, used default timer */
752 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
757 accelIndex = 0; /* otherwise, use it */
758 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
760 SetTimer(hwnd, TIMERID2, temp, 0);
763 /* now, if the mouse is above us, do the thing...*/
764 if(infoPtr->Flags & FLAG_MOUSEIN){
765 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
766 UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR);
768 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
769 KillTimer(hwnd, TIMERID2);
770 accelIndex++; /* move to the next accel info */
771 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
772 /* make sure we have at least 1ms intervals */
773 SetTimer(hwnd, TIMERID2, temp, 0);
779 UPDOWN_CancelMode (hwnd);
783 if(!UPDOWN_CancelMode(hwnd))
786 SendMessageA(GetParent(hwnd), dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
787 MAKELONG(SB_ENDSCROLL, infoPtr->CurVal), hwnd);
789 /*If we released the mouse and our buddy is an edit */
790 /* we must select all text in it. */
791 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
792 SendMessageA(infoPtr->Buddy, EM_SETSEL, 0, MAKELONG(0, -1));
797 if(UPDOWN_IsEnabled(hwnd)){
799 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
800 UPDOWN_HandleMouseEvent (hwnd, message, pt );
805 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd)){
809 UPDOWN_GetBuddyInt (hwnd);
810 UPDOWN_DoAction (hwnd, 1, wParam==VK_UP);
817 UPDOWN_Paint (hwnd, (HDC)wParam);
821 if (wParam==0 && lParam==0) /*if both zero, */
822 return infoPtr->AccelCount; /*just return the accel count*/
823 if (wParam || lParam){
824 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
827 temp = min(infoPtr->AccelCount, wParam);
828 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
832 TRACE("UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
833 if(infoPtr->AccelVect){
834 COMCTL32_Free (infoPtr->AccelVect);
835 infoPtr->AccelCount = 0;
836 infoPtr->AccelVect = 0;
840 infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
841 if(infoPtr->AccelVect==0)
843 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
847 if (wParam || lParam)
848 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
849 return infoPtr->Base;
852 TRACE("UpDown Ctrl new base(%d), hwnd=%04x\n",
854 if ( !(wParam==10 || wParam==16) || lParam)
855 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
856 if (wParam==10 || wParam==16){
857 temp = infoPtr->Base;
858 infoPtr->Base = wParam;
859 return temp; /* return the prev base */
864 if (wParam || lParam)
865 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
866 return infoPtr->Buddy;
870 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
871 temp = infoPtr->Buddy;
872 UPDOWN_SetBuddy (hwnd, wParam);
873 TRACE("UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
874 infoPtr->Buddy, hwnd);
878 if (wParam || lParam)
879 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
880 temp = UPDOWN_GetBuddyInt (hwnd);
881 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
884 if (wParam || HIWORD(lParam))
885 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
886 temp = SLOWORD(lParam);
887 TRACE("UpDown Ctrl new value(%d), hwnd=%04x\n",
889 if(!UPDOWN_InBounds(hwnd, temp)){
890 if(temp < infoPtr->MinVal)
891 temp = infoPtr->MinVal;
892 if(temp > infoPtr->MaxVal)
893 temp = infoPtr->MaxVal;
895 wParam = infoPtr->CurVal; /* save prev value */
896 infoPtr->CurVal = temp; /* set the new value */
897 if(dwStyle & UDS_SETBUDDYINT)
898 UPDOWN_SetBuddyInt (hwnd);
899 return wParam; /* return prev value */
902 if (wParam || lParam)
903 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
904 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
908 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
909 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
910 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
911 /* |Max-Min| <= UD_MAXVAL */
912 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
913 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
918 *(LPINT)wParam = infoPtr->MinVal;
920 *(LPINT)lParam = infoPtr->MaxVal;
924 infoPtr->MinVal = (INT)wParam;
925 infoPtr->MaxVal = (INT)lParam;
926 if (infoPtr->MaxVal <= infoPtr->MinVal)
927 infoPtr->MaxVal = infoPtr->MinVal + 1;
928 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
929 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
933 if (message >= WM_USER)
934 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
935 message, wParam, lParam);
936 return DefWindowProcA (hwnd, message, wParam, lParam);
942 /***********************************************************************
943 * UPDOWN_Buddy_SubclassProc used to handle messages sent to the buddy
947 UPDOWN_Buddy_SubclassProc (
953 WNDPROC superClassWndProc = (WNDPROC)GetPropA(hwnd, BUDDY_SUPERCLASS_WNDPROC);
954 TRACE("hwnd=%04x, wndProc=%d, uMsg=%04x, wParam=%d, lParam=%d\n",
955 hwnd, (INT)superClassWndProc, uMsg, wParam, (UINT)lParam);
961 if ( ((int)wParam == VK_UP ) || ((int)wParam == VK_DOWN ) )
963 HWND upDownHwnd = GetPropA(hwnd, BUDDY_UPDOWN_HWND);
964 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(upDownHwnd);
966 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox"))
968 /* if the buddy is a list window, we must update curr index */
969 INT oldVal = SendMessageA(hwnd, LB_GETCURSEL, 0, 0);
970 SendMessageA(hwnd, LB_SETCURSEL, oldVal+1, 0);
974 UPDOWN_GetBuddyInt(upDownHwnd);
975 UPDOWN_DoAction(upDownHwnd, 1, wParam==VK_UP);
980 /* else Fall Through */
983 return CallWindowProcA( superClassWndProc, hwnd, uMsg, wParam, lParam);
986 /***********************************************************************
987 * UPDOWN_Register [Internal]
989 * Registers the updown window class.
993 UPDOWN_Register(void)
997 ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
998 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
999 wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
1000 wndClass.cbClsExtra = 0;
1001 wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
1002 wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
1003 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1004 wndClass.lpszClassName = UPDOWN_CLASSA;
1006 RegisterClassA( &wndClass );
1010 /***********************************************************************
1011 * UPDOWN_Unregister [Internal]
1013 * Unregisters the updown window class.
1017 UPDOWN_Unregister (void)
1019 UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);