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.
38 #include "debugtools.h"
40 DEFAULT_DEBUG_CHANNEL(updown)
42 /* Control configuration constants */
44 #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
45 #define REPEAT_DELAY 50 /* delay between auto-increments */
47 #define DEFAULT_WIDTH 14 /* default width of the ctrl */
48 #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
49 #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
50 #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
51 #define DEFAULT_BUDDYBORDER 2 /* Width/height of the buddy border */
56 #define FLAG_INCR 0x01
57 #define FLAG_DECR 0x02
58 #define FLAG_MOUSEIN 0x04
59 #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
63 #define BUDDY_UPDOWN_HWND "buddyUpDownHWND"
64 #define BUDDY_SUPERCLASS_WNDPROC "buddySupperClassWndProc"
66 static int accelIndex = -1;
68 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(\
69 "UpDown Ctrl: Unknown parameter(s) for message " #msg \
70 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
72 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))
74 static LRESULT CALLBACK
75 UPDOWN_Buddy_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
77 /***********************************************************************
79 * Tests if a given value 'val' is between the Min&Max limits
81 static BOOL UPDOWN_InBounds(HWND hwnd, int val)
83 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
85 if(infoPtr->MaxVal > infoPtr->MinVal)
86 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
88 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
91 /***********************************************************************
93 * Tests if we can change the current value by delta. If so, it changes
94 * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
96 static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
98 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
100 /* check if we can do the modification first */
101 if(!UPDOWN_InBounds (hwnd, infoPtr->CurVal+delta)){
102 if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_WRAP)
104 delta += (delta < 0 ? -1 : 1) *
105 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
106 (infoPtr->MinVal - infoPtr->MaxVal) +
107 (delta < 0 ? 1 : -1);
113 infoPtr->CurVal += delta;
117 /***********************************************************************
118 * UPDOWN_HasBuddyBorder [Internal]
120 * When we have a buddy set and that we are aligned on our buddy, we
121 * want to draw a sunken edge to make like we are part of that control.
123 static BOOL UPDOWN_HasBuddyBorder(HWND hwnd)
125 UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
126 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
128 return ( ((dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)) != 0) &&
129 (SendMessageA(hwnd, UDM_GETBUDDY, 0, 0) != 0) &&
130 (lstrcmpiA(infoPtr->szBuddyClass, "EDIT") == 0 ) );
133 /***********************************************************************
134 * UPDOWN_GetArrowRect
135 * wndPtr - pointer to the up-down wnd
136 * rect - will hold the rectangle
137 * incr - TRUE get the "increment" rect (up or right)
138 * FALSE get the "decrement" rect (down or left)
141 static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
143 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
144 int len; /* will hold the width or height */
146 GetClientRect (hwnd, rect);
149 * Make sure we calculate the rectangle to fit even if we draw the
152 if (UPDOWN_HasBuddyBorder(hwnd))
154 if (dwStyle & UDS_ALIGNLEFT)
155 rect->left+=DEFAULT_BUDDYBORDER;
157 rect->right-=DEFAULT_BUDDYBORDER;
159 InflateRect(rect, 0, -DEFAULT_BUDDYBORDER);
163 * We're calculating the midpoint to figure-out where the
164 * separation between the buttons will lay. We make sure that we
165 * round the uneven numbers by adding 1.
167 if (dwStyle & UDS_HORZ) {
168 len = rect->right - rect->left + 1; /* compute the width */
170 rect->left = rect->left + len/2;
172 rect->right = rect->left + len/2;
175 len = rect->bottom - rect->top + 1; /* compute the height */
177 rect->bottom = rect->top + len/2;
179 rect->top = rect->top + len/2;
183 /***********************************************************************
184 * UPDOWN_GetArrowFromPoint
185 * Returns the rectagle (for the up or down arrow) that contains pt.
186 * If it returns the up rect, it returns TRUE.
187 * If it returns the down rect, it returns FALSE.
190 UPDOWN_GetArrowFromPoint (HWND hwnd, RECT *rect, POINT pt)
192 UPDOWN_GetArrowRect (hwnd, rect, TRUE);
193 if(PtInRect(rect, pt))
196 UPDOWN_GetArrowRect (hwnd, rect, FALSE);
201 /***********************************************************************
202 * UPDOWN_GetThousandSep
203 * Returns the thousand sep. If an error occurs, it returns ','.
205 static char UPDOWN_GetThousandSep()
209 if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
210 sep, sizeof(sep)) != 1)
216 /***********************************************************************
218 * Tries to read the pos from the buddy window and if it succeeds,
219 * it stores it in the control's CurVal
221 * TRUE - if it read the integer from the buddy successfully
222 * FALSE - if an error occured
224 static BOOL UPDOWN_GetBuddyInt (HWND hwnd)
226 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
227 char txt[20], sep, *src, *dst;
230 if (!IsWindow(infoPtr->Buddy))
233 /*if the buddy is a list window, we must set curr index */
234 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
235 newVal = SendMessageA(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0);
240 /* we have a regular window, so will get the text */
241 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt)))
244 sep = UPDOWN_GetThousandSep();
246 /* now get rid of the separators */
247 for(src = dst = txt; *src; src++)
252 /* try to convert the number and validate it */
253 newVal = strtol(txt, &src, infoPtr->Base);
254 if(*src || !UPDOWN_InBounds (hwnd, newVal))
257 TRACE("new value(%d) read from buddy (old=%d)\n",
258 newVal, infoPtr->CurVal);
261 infoPtr->CurVal = newVal;
266 /***********************************************************************
268 * Tries to set the pos to the buddy window based on current pos
270 * TRUE - if it set the caption of the buddy successfully
271 * FALSE - if an error occured
273 static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
275 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
279 if (!IsWindow(infoPtr->Buddy))
282 TRACE("set new value(%d) to buddy.\n",
285 /*if the buddy is a list window, we must set curr index */
286 if(!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
287 SendMessageA(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0);
289 else{ /* Regular window, so set caption to the number */
290 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
292 sep = UPDOWN_GetThousandSep();
294 /* Do thousands seperation if necessary */
295 if (!(GetWindowLongA (hwnd, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
296 char txt2[20], *src = txt1, *dst = txt2;
298 lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
302 for(len=0; *src; len++){
307 *dst = 0; /* null terminate it */
308 strcpy(txt1, txt2); /* move it to the proper place */
310 SetWindowTextA(infoPtr->Buddy, txt1);
316 /***********************************************************************
317 * UPDOWN_DrawBuddyBorder [Internal]
319 * When we have a buddy set and that we are aligned on our buddy, we
320 * want to draw a sunken edge to make like we are part of that control.
322 static void UPDOWN_DrawBuddyBorder (HWND hwnd, HDC hdc)
324 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
327 GetClientRect(hwnd, &clientRect);
329 if (dwStyle & UDS_ALIGNLEFT)
330 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_LEFT | BF_TOP);
332 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_RIGHT | BF_TOP);
335 /***********************************************************************
336 * UPDOWN_Draw [Internal]
338 * Draw the arrows. The background need not be erased.
340 static void UPDOWN_Draw (HWND hwnd, HDC hdc)
342 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
343 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
348 * Draw the common border between ourselves and our buddy.
350 if (UPDOWN_HasBuddyBorder(hwnd))
351 UPDOWN_DrawBuddyBorder(hwnd, hdc);
353 /* Draw the incr button */
354 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
355 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
356 DrawFrameControl(hdc, &rect, DFC_SCROLL,
357 (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
358 (prssed ? DFCS_PUSHED : 0) |
359 (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
361 /* Draw the space between the buttons */
362 rect.top = rect.bottom; rect.bottom++;
363 DrawEdge(hdc, &rect, 0, BF_MIDDLE);
365 /* Draw the decr button */
366 UPDOWN_GetArrowRect(hwnd, &rect, FALSE);
367 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
368 DrawFrameControl(hdc, &rect, DFC_SCROLL,
369 (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
370 (prssed ? DFCS_PUSHED : 0) |
371 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
374 /***********************************************************************
375 * UPDOWN_Refresh [Internal]
377 * Synchronous drawing (must NOT be used in WM_PAINT).
380 static void UPDOWN_Refresh (HWND hwnd)
385 UPDOWN_Draw (hwnd, hdc);
386 ReleaseDC (hwnd, hdc);
390 /***********************************************************************
391 * UPDOWN_Paint [Internal]
393 * Asynchronous drawing (must ONLY be used in WM_PAINT).
396 static void UPDOWN_Paint (HWND hwnd, HDC passedDC)
402 hdc = BeginPaint (hwnd, &ps);
404 UPDOWN_Draw (hwnd, hdc);
407 EndPaint (hwnd, &ps);
410 /***********************************************************************
412 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
413 * Else, sets it as a new Buddy.
414 * Then, it should subclass the buddy
415 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
416 * process the UP/DOWN arrow keys.
417 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
418 * the size/pos of the buddy and the control are adjusted accordingly.
420 static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
422 UPDOWN_INFO* infoPtr = UPDOWN_GetInfoPtr (hwnd);
423 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
424 RECT budRect; /* new coord for the buddy */
425 int x,width; /* new x position and width for the up-down */
427 /* Is it a valid bud? */
428 if(!IsWindow(hwndBud))
431 /* there is already a body assigned */
432 if ( infoPtr->Buddy )
433 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
435 /* Store buddy window handle */
436 infoPtr->Buddy = hwndBud;
438 /* keep upDown ctrl hwnd in a buddy property */
439 SetPropA( hwndBud, BUDDY_UPDOWN_HWND, hwnd);
441 /* Store buddy window clas name */
442 memset(infoPtr->szBuddyClass, 0, UPDOWN_BUDDYCLASSNAMELEN);
443 GetClassNameA (hwndBud, infoPtr->szBuddyClass, UPDOWN_BUDDYCLASSNAMELEN-1);
445 if(dwStyle & UDS_ARROWKEYS){
446 /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
447 when we reset the upDown ctrl buddy to another buddy because it is not
448 good to break the window proc chain. */
450 /* keep buddy supperclass wndproc in prop instead of in ptr struct
451 to prevent accessing freed memory */
454 BUDDY_SUPERCLASS_WNDPROC,
455 (LONG)GetWindowLongA(hwndBud, GWL_WNDPROC) );
457 /* Assign the buddy wndproc to local wndproc in order to override
458 keyboard's up and down arrow */
462 (LONG)UPDOWN_Buddy_SubclassProc);
465 /* do we need to do any adjustments? */
466 if(!(dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
469 /* Get the rect of the buddy relative to its parent */
470 GetWindowRect(infoPtr->Buddy, &budRect);
471 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
472 (POINT *)(&budRect.left), 2);
474 /* now do the positioning */
475 if(dwStyle & UDS_ALIGNRIGHT){
476 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
477 x = budRect.right+DEFAULT_XSEP;
479 else{ /* UDS_ALIGNLEFT */
481 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
484 /* first adjust the buddy to accomodate the up/down */
485 SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
486 budRect.right - budRect.left, budRect.bottom - budRect.top,
487 SWP_NOACTIVATE|SWP_NOZORDER);
489 /* now position the up/down */
490 /* Since the UDS_ALIGN* flags were used, */
491 /* we will pick the position and size of the window. */
492 width = DEFAULT_WIDTH;
495 * If the updown has a buddy border, it has to overlap with the buddy
496 * to look as if it is integrated with the buddy control.
497 * We nudge the control or change it size to overlap.
499 if (UPDOWN_HasBuddyBorder(hwnd))
501 if(dwStyle & UDS_ALIGNRIGHT)
502 x-=DEFAULT_BUDDYBORDER;
504 width+=DEFAULT_BUDDYBORDER;
507 SetWindowPos (hwnd, infoPtr->Buddy,
508 x, budRect.top-DEFAULT_ADDTOP,
509 width, (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
515 /***********************************************************************
518 * This function increments/decrements the CurVal by the
519 * 'delta' amount according to the 'incr' flag
520 * It notifies the parent as required.
521 * It handles wraping and non-wraping correctly.
522 * It is assumed that delta>0
524 static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr)
526 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
527 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
528 int old_val = infoPtr->CurVal;
531 TRACE("%s by %d\n", incr ? "inc" : "dec", delta);
533 /* check if we can do the modification first */
534 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
535 if(!UPDOWN_OffsetVal (hwnd, delta))
538 /* so, if we can do the change, recompute delta and restore old value */
539 delta = infoPtr->CurVal - old_val;
540 infoPtr->CurVal = old_val;
542 /* We must notify parent now to obtain permission */
543 ni.iPos = infoPtr->CurVal;
545 ni.hdr.hwndFrom = hwnd;
546 ni.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
547 ni.hdr.code = UDN_DELTAPOS;
548 if (SendMessageA(GetParent (hwnd), WM_NOTIFY,
549 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))
550 return; /* we are not allowed to change */
552 /* Now adjust value with (maybe new) delta */
553 if (!UPDOWN_OffsetVal (hwnd, ni.iDelta))
556 /* Now take care about our buddy */
557 if(!IsWindow(infoPtr->Buddy))
558 return; /* Nothing else to do */
561 if (dwStyle & UDS_SETBUDDYINT)
562 UPDOWN_SetBuddyInt (hwnd);
564 /* Also, notify it */
565 /* FIXME: do we need to send the notification only if
566 we do not have the UDS_SETBUDDYINT style set? */
568 SendMessageA (GetParent (hwnd),
569 dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
570 MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
574 /***********************************************************************
577 * Returns TRUE if it is enabled as well as its buddy (if any)
580 static BOOL UPDOWN_IsEnabled (HWND hwnd)
582 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
584 if(GetWindowLongA (hwnd, GWL_STYLE) & WS_DISABLED)
586 return IsWindowEnabled(infoPtr->Buddy);
589 /***********************************************************************
592 * Deletes any timers, releases the mouse and does redraw if necessary.
593 * If the control is not in "capture" mode, it does nothing.
594 * If the control was not in cancel mode, it returns FALSE.
595 * If the control was in cancel mode, it returns TRUE.
597 static BOOL UPDOWN_CancelMode (HWND hwnd)
599 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
601 /* if not in 'capture' mode, do nothing */
602 if(!(infoPtr->Flags & FLAG_CLICKED))
605 KillTimer (hwnd, TIMERID1); /* kill all possible timers */
606 KillTimer (hwnd, TIMERID2);
608 if (GetCapture() == hwnd) /* let the mouse go */
609 ReleaseCapture(); /* if we still have it */
611 infoPtr->Flags = 0; /* get rid of any flags */
612 UPDOWN_Refresh (hwnd); /* redraw the control just in case */
617 /***********************************************************************
618 * UPDOWN_HandleMouseEvent
620 * Handle a mouse event for the updown.
621 * 'pt' is the location of the mouse event in client or
622 * windows coordinates.
624 static void UPDOWN_HandleMouseEvent (HWND hwnd, UINT msg, POINT pt)
626 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
627 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
633 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
634 /* If we are already in the 'clicked' mode, then nothing to do */
635 if(infoPtr->Flags & FLAG_CLICKED)
638 /* If the buddy is an edit, will set focus to it */
639 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
640 SetFocus(infoPtr->Buddy);
642 /* Now see which one is the 'active' arrow */
643 temp = UPDOWN_GetArrowFromPoint (hwnd, &rect, pt);
645 /* Update the CurVal if necessary */
646 if (dwStyle & UDS_SETBUDDYINT)
647 UPDOWN_GetBuddyInt (hwnd);
649 /* Before we proceed, see if we can spin... */
650 if(!(dwStyle & UDS_WRAP))
651 if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
652 (!temp && infoPtr->CurVal==infoPtr->MinVal))
655 /* Set up the correct flags */
657 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
658 infoPtr->Flags |= FLAG_MOUSEIN;
660 /* repaint the control */
661 UPDOWN_Refresh (hwnd);
663 /* process the click */
664 UPDOWN_DoAction (hwnd, 1, infoPtr->Flags & FLAG_INCR);
666 /* now capture all mouse messages */
669 /* and startup the first timer */
670 SetTimer(hwnd, TIMERID1, INITIAL_DELAY, 0);
674 /* If we are not in the 'clicked' mode, then nothing to do */
675 if(!(infoPtr->Flags & FLAG_CLICKED))
678 /* save the flags to see if any got modified */
679 temp = infoPtr->Flags;
681 /* Now get the 'active' arrow rectangle */
682 if (infoPtr->Flags & FLAG_INCR)
683 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
685 UPDOWN_GetArrowRect (hwnd, &rect, FALSE);
687 /* Update the flags if we are in/out */
688 if(PtInRect(&rect, pt))
689 infoPtr->Flags |= FLAG_MOUSEIN;
691 infoPtr->Flags &= ~FLAG_MOUSEIN;
692 if(accelIndex != -1) /* if we have accel info */
693 accelIndex = 0; /* reset it */
695 /* If state changed, redraw the control */
696 if(temp != infoPtr->Flags)
697 UPDOWN_Refresh (hwnd);
701 ERR("Impossible case!\n");
706 /***********************************************************************
709 static LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
712 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
713 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
719 /* get rid of border, if any */
720 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER);
724 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
725 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
727 /* initialize the info struct */
728 infoPtr->AccelCount=0; infoPtr->AccelVect=0;
729 infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
730 infoPtr->Base = 10; /* Default to base 10 */
731 infoPtr->Buddy = 0; /* No buddy window yet */
732 infoPtr->Flags = 0; /* And no flags */
734 /* Do we pick the buddy win ourselves? */
735 if (dwStyle & UDS_AUTOBUDDY)
736 UPDOWN_SetBuddy (hwnd, GetWindow (hwnd, GW_HWNDPREV));
738 TRACE("UpDown Ctrl creation, hwnd=%04x\n", hwnd);
742 if(infoPtr->AccelVect)
743 COMCTL32_Free (infoPtr->AccelVect);
745 if ( IsWindow(infoPtr->Buddy) ) /* Cleanup */
746 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
748 COMCTL32_Free (infoPtr);
750 TRACE("UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
754 if (dwStyle & WS_DISABLED)
755 UPDOWN_CancelMode (hwnd);
757 UPDOWN_Refresh (hwnd);
761 /* if initial timer, kill it and start the repeat timer */
762 if(wParam == TIMERID1){
763 KillTimer(hwnd, TIMERID1);
764 /* if no accel info given, used default timer */
765 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
770 accelIndex = 0; /* otherwise, use it */
771 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
773 SetTimer(hwnd, TIMERID2, temp, 0);
776 /* now, if the mouse is above us, do the thing...*/
777 if(infoPtr->Flags & FLAG_MOUSEIN){
778 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
779 UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR);
781 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
782 KillTimer(hwnd, TIMERID2);
783 accelIndex++; /* move to the next accel info */
784 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
785 /* make sure we have at least 1ms intervals */
786 SetTimer(hwnd, TIMERID2, temp, 0);
792 UPDOWN_CancelMode (hwnd);
796 if(!UPDOWN_CancelMode(hwnd))
798 /*If we released the mouse and our buddy is an edit */
799 /* we must select all text in it. */
800 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
801 SendMessageA(infoPtr->Buddy, EM_SETSEL, 0, MAKELONG(0, -1));
806 if(UPDOWN_IsEnabled(hwnd)){
808 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
809 UPDOWN_HandleMouseEvent (hwnd, message, pt );
814 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd)){
818 UPDOWN_GetBuddyInt (hwnd);
819 UPDOWN_DoAction (hwnd, 1, wParam==VK_UP);
826 UPDOWN_Paint (hwnd, (HDC)wParam);
830 if (wParam==0 && lParam==0) /*if both zero, */
831 return infoPtr->AccelCount; /*just return the accel count*/
832 if (wParam || lParam){
833 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
836 temp = MIN(infoPtr->AccelCount, wParam);
837 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
841 TRACE("UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
842 if(infoPtr->AccelVect){
843 COMCTL32_Free (infoPtr->AccelVect);
844 infoPtr->AccelCount = 0;
845 infoPtr->AccelVect = 0;
849 infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
850 if(infoPtr->AccelVect==0)
852 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
856 if (wParam || lParam)
857 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
858 return infoPtr->Base;
861 TRACE("UpDown Ctrl new base(%d), hwnd=%04x\n",
863 if ( !(wParam==10 || wParam==16) || lParam)
864 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
865 if (wParam==10 || wParam==16){
866 temp = infoPtr->Base;
867 infoPtr->Base = wParam;
868 return temp; /* return the prev base */
873 if (wParam || lParam)
874 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
875 return infoPtr->Buddy;
879 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
880 temp = infoPtr->Buddy;
881 UPDOWN_SetBuddy (hwnd, wParam);
882 TRACE("UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
883 infoPtr->Buddy, hwnd);
887 if (wParam || lParam)
888 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
889 temp = UPDOWN_GetBuddyInt (hwnd);
890 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
893 if (wParam || HIWORD(lParam))
894 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
895 temp = SLOWORD(lParam);
896 TRACE("UpDown Ctrl new value(%d), hwnd=%04x\n",
898 if(!UPDOWN_InBounds(hwnd, temp)){
899 if(temp < infoPtr->MinVal)
900 temp = infoPtr->MinVal;
901 if(temp > infoPtr->MaxVal)
902 temp = infoPtr->MaxVal;
904 wParam = infoPtr->CurVal; /* save prev value */
905 infoPtr->CurVal = temp; /* set the new value */
906 if(dwStyle & UDS_SETBUDDYINT)
907 UPDOWN_SetBuddyInt (hwnd);
908 return wParam; /* return prev value */
911 if (wParam || lParam)
912 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
913 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
917 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
918 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
919 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
920 /* |Max-Min| <= UD_MAXVAL */
921 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
922 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
927 *(LPINT)wParam = infoPtr->MinVal;
929 *(LPINT)lParam = infoPtr->MaxVal;
933 infoPtr->MinVal = (INT)wParam;
934 infoPtr->MaxVal = (INT)lParam;
935 if (infoPtr->MaxVal <= infoPtr->MinVal)
936 infoPtr->MaxVal = infoPtr->MinVal + 1;
937 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
938 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
942 if (message >= WM_USER)
943 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
944 message, wParam, lParam);
945 return DefWindowProcA (hwnd, message, wParam, lParam);
951 /***********************************************************************
952 * UPDOWN_Buddy_SubclassProc used to handle messages sent to the buddy
956 UPDOWN_Buddy_SubclassProc (
962 LONG superClassWndProc = GetPropA(hwnd, BUDDY_SUPERCLASS_WNDPROC);
963 TRACE("hwnd=%04x, wndProc=%d, uMsg=%04x, wParam=%d, lParam=%d\n",
964 hwnd, (INT)superClassWndProc, uMsg, wParam, (UINT)lParam);
970 if ( ((int)wParam == VK_UP ) || ((int)wParam == VK_DOWN ) )
972 HWND upDownHwnd = GetPropA(hwnd, BUDDY_UPDOWN_HWND);
973 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(upDownHwnd);
975 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox"))
977 /* if the buddy is a list window, we must update curr index */
978 INT oldVal = SendMessageA(hwnd, LB_GETCURSEL, 0, 0);
979 SendMessageA(hwnd, LB_SETCURSEL, oldVal+1, 0);
983 UPDOWN_GetBuddyInt(upDownHwnd);
984 UPDOWN_DoAction(upDownHwnd, 1, wParam==VK_UP);
989 /* else Fall Through */
993 return CallWindowProcA( (WNDPROC)superClassWndProc, hwnd, uMsg, wParam, lParam);
999 /***********************************************************************
1000 * UPDOWN_Register [Internal]
1002 * Registers the updown window class.
1006 UPDOWN_Register(void)
1010 if( GlobalFindAtomA( UPDOWN_CLASSA ) ) return;
1012 ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
1013 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
1014 wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
1015 wndClass.cbClsExtra = 0;
1016 wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
1017 wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
1018 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1019 wndClass.lpszClassName = UPDOWN_CLASSA;
1021 RegisterClassA( &wndClass );
1025 /***********************************************************************
1026 * UPDOWN_Unregister [Internal]
1028 * Unregisters the updown window class.
1032 UPDOWN_Unregister (void)
1034 if (GlobalFindAtomA (UPDOWN_CLASSA))
1035 UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);