4 * Copyright 1997 Dimitrie O. Paun
7 * - I think I do not handle correctly the WS_BORDER style.
8 * (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
11 * Not much. The following have not been tested at all:
13 * - listbox as buddy window
16 * - integers with thousand separators.
17 * (fixed bugs. <noel@macadamian.com>)
19 * Even though the above list seems rather large, the control seems to
20 * behave very well so I am confident it does work in most (all) of the
34 #include "debugtools.h"
36 DEFAULT_DEBUG_CHANNEL(updown);
38 #define UPDOWN_BUDDYCLASSNAMELEN 40
42 HWND Self; /* Handle to this up-down control */
43 UINT AccelCount; /* Number of elements in AccelVect */
44 UDACCEL* AccelVect; /* Vector containing AccelCount elements */
45 INT AccelIndex; /* Current accel index, -1 if not accelerating */
46 INT Base; /* Base to display nr in the buddy window */
47 INT CurVal; /* Current up-down value */
48 INT MinVal; /* Minimum up-down value */
49 INT MaxVal; /* Maximum up-down value */
50 HWND Buddy; /* Handle to the buddy window */
51 CHAR szBuddyClass[UPDOWN_BUDDYCLASSNAMELEN]; /* Buddy window class name */
52 INT Flags; /* Internal Flags FLAG_* */
55 /* Control configuration constants */
57 #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
58 #define REPEAT_DELAY 50 /* delay between auto-increments */
60 #define DEFAULT_WIDTH 14 /* default width of the ctrl */
61 #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
62 #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
63 #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
64 #define DEFAULT_BUDDYBORDER 2 /* Width/height of the buddy border */
69 #define FLAG_INCR 0x01
70 #define FLAG_DECR 0x02
71 #define FLAG_MOUSEIN 0x04
72 #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
76 #define BUDDY_UPDOWN_HWND "buddyUpDownHWND"
77 #define BUDDY_SUPERCLASS_WNDPROC "buddySupperClassWndProc"
79 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(\
80 "Unknown parameter(s) for message " #msg \
81 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
83 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))
85 static LRESULT CALLBACK
86 UPDOWN_Buddy_SubclassProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
88 /***********************************************************************
90 * Tests if a given value 'val' is between the Min&Max limits
92 static BOOL UPDOWN_InBounds(UPDOWN_INFO *infoPtr, int val)
94 if(infoPtr->MaxVal > infoPtr->MinVal)
95 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
97 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
100 /***********************************************************************
102 * Tests if we can change the current value by delta. If so, it changes
103 * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
105 static BOOL UPDOWN_OffsetVal(UPDOWN_INFO *infoPtr, int delta)
107 /* check if we can do the modification first */
108 if(!UPDOWN_InBounds (infoPtr, infoPtr->CurVal+delta)){
109 if (GetWindowLongW (infoPtr->Self, GWL_STYLE) & UDS_WRAP)
111 delta += (delta < 0 ? -1 : 1) *
112 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
113 (infoPtr->MinVal - infoPtr->MaxVal) +
114 (delta < 0 ? 1 : -1);
120 infoPtr->CurVal += delta;
124 /***********************************************************************
125 * UPDOWN_HasBuddyBorder [Internal]
127 * When we have a buddy set and that we are aligned on our buddy, we
128 * want to draw a sunken edge to make like we are part of that control.
130 static BOOL UPDOWN_HasBuddyBorder(UPDOWN_INFO* infoPtr)
132 DWORD dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
134 return ( ((dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)) != 0) &&
135 (SendMessageW(infoPtr->Self, UDM_GETBUDDY, 0, 0) != 0) &&
136 (lstrcmpiA(infoPtr->szBuddyClass, "EDIT") == 0 ) );
139 /***********************************************************************
140 * UPDOWN_GetArrowRect
141 * wndPtr - pointer to the up-down wnd
142 * rect - will hold the rectangle
143 * incr - TRUE get the "increment" rect (up or right)
144 * FALSE get the "decrement" rect (down or left)
146 static void UPDOWN_GetArrowRect (UPDOWN_INFO* infoPtr, RECT *rect, BOOL incr)
148 DWORD dwStyle = GetWindowLongW (infoPtr->Self, GWL_STYLE);
149 int len; /* will hold the width or height */
151 GetClientRect (infoPtr->Self, rect);
154 * Make sure we calculate the rectangle to fit even if we draw the
157 if (UPDOWN_HasBuddyBorder(infoPtr)) {
158 if (dwStyle & UDS_ALIGNLEFT)
159 rect->left += DEFAULT_BUDDYBORDER;
161 rect->right -= DEFAULT_BUDDYBORDER;
163 InflateRect(rect, 0, -DEFAULT_BUDDYBORDER);
167 * We're calculating the midpoint to figure-out where the
168 * separation between the buttons will lay. We make sure that we
169 * round the uneven numbers by adding 1.
171 if (dwStyle & UDS_HORZ) {
172 len = rect->right - rect->left + 1; /* compute the width */
174 rect->left = rect->left + len/2;
176 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.
192 static BOOL UPDOWN_GetArrowFromPoint (UPDOWN_INFO* infoPtr, RECT *rect, POINT pt)
194 UPDOWN_GetArrowRect (infoPtr, rect, TRUE);
195 if(PtInRect(rect, pt)) return TRUE;
197 UPDOWN_GetArrowRect (infoPtr, rect, FALSE);
202 /***********************************************************************
203 * UPDOWN_GetThousandSep
204 * Returns the thousand sep. If an error occurs, it returns ','.
206 static CHAR UPDOWN_GetThousandSep()
210 if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND, sep, 2) != 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 occurred
224 static BOOL UPDOWN_GetBuddyInt (UPDOWN_INFO *infoPtr)
226 char txt[20], sep, *src, *dst;
229 if (!IsWindow(infoPtr->Buddy))
232 /*if the buddy is a list window, we must set curr index */
233 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
234 newVal = SendMessageA(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0);
239 /* we have a regular window, so will get the text */
240 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt)))
243 sep = UPDOWN_GetThousandSep();
245 /* now get rid of the separators */
246 for(src = dst = txt; *src; src++)
247 if(*src != sep) *dst++ = *src;
250 /* try to convert the number and validate it */
251 newVal = strtol(txt, &src, infoPtr->Base);
252 if(*src || !UPDOWN_InBounds (infoPtr, newVal))
255 TRACE("new value(%d) from buddy (old=%d)\n", newVal, infoPtr->CurVal);
258 infoPtr->CurVal = newVal;
263 /***********************************************************************
265 * Tries to set the pos to the buddy window based on current pos
267 * TRUE - if it set the caption of the buddy successfully
268 * FALSE - if an error occurred
270 static BOOL UPDOWN_SetBuddyInt (UPDOWN_INFO *infoPtr)
275 if (!IsWindow(infoPtr->Buddy))
278 TRACE("set new value(%d) to buddy.\n", infoPtr->CurVal);
280 /*if the buddy is a list window, we must set curr index */
281 if(!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
282 SendMessageA(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0);
284 else{ /* Regular window, so set caption to the number */
285 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
287 sep = UPDOWN_GetThousandSep();
289 /* Do thousands seperation if necessary */
290 if (!(GetWindowLongA (infoPtr->Self, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
291 char txt2[20], *src = txt1, *dst = txt2;
293 lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
297 for(len=0; *src; len++) {
298 if(len%3==0) *dst++ = sep;
301 *dst = 0; /* null terminate it */
302 strcpy(txt1, txt2); /* move it to the proper place */
304 SetWindowTextA(infoPtr->Buddy, txt1);
310 /***********************************************************************
311 * UPDOWN_DrawBuddyBorder [Internal]
313 * When we have a buddy set and that we are aligned on our buddy, we
314 * want to draw a sunken edge to make like we are part of that control.
316 static void UPDOWN_DrawBuddyBorder (UPDOWN_INFO *infoPtr, HDC hdc)
318 DWORD dwStyle = GetWindowLongA (infoPtr->Self, GWL_STYLE);
321 GetClientRect(infoPtr->Self, &clientRect);
323 if (dwStyle & UDS_ALIGNLEFT)
324 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_LEFT | BF_TOP);
326 DrawEdge(hdc, &clientRect, EDGE_SUNKEN, BF_BOTTOM | BF_RIGHT | BF_TOP);
329 /***********************************************************************
330 * UPDOWN_Draw [Internal]
332 * Draw the arrows. The background need not be erased.
334 static void UPDOWN_Draw (UPDOWN_INFO *infoPtr, HDC hdc)
336 DWORD dwStyle = GetWindowLongA (infoPtr->Self, GWL_STYLE);
341 * Draw the common border between ourselves and our buddy.
343 if (UPDOWN_HasBuddyBorder(infoPtr))
344 UPDOWN_DrawBuddyBorder(infoPtr, hdc);
346 /* Draw the incr button */
347 UPDOWN_GetArrowRect (infoPtr, &rect, TRUE);
348 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
349 DrawFrameControl(hdc, &rect, DFC_SCROLL,
350 (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLUP) |
351 (prssed ? DFCS_PUSHED : 0) |
352 (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
354 /* Draw the space between the buttons */
355 rect.top = rect.bottom; rect.bottom++;
356 DrawEdge(hdc, &rect, 0, BF_MIDDLE);
358 /* Draw the decr button */
359 UPDOWN_GetArrowRect(infoPtr, &rect, FALSE);
360 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
361 DrawFrameControl(hdc, &rect, DFC_SCROLL,
362 (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLDOWN) |
363 (prssed ? DFCS_PUSHED : 0) |
364 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
367 /***********************************************************************
368 * UPDOWN_Refresh [Internal]
370 * Synchronous drawing (must NOT be used in WM_PAINT).
373 static void UPDOWN_Refresh (UPDOWN_INFO *infoPtr)
375 HDC hdc = GetDC (infoPtr->Self);
376 UPDOWN_Draw (infoPtr, hdc);
377 ReleaseDC (infoPtr->Self, hdc);
381 /***********************************************************************
382 * UPDOWN_Paint [Internal]
384 * Asynchronous drawing (must ONLY be used in WM_PAINT).
387 static void UPDOWN_Paint (UPDOWN_INFO *infoPtr, HDC hdc)
390 UPDOWN_Draw (infoPtr, hdc);
394 hdc = BeginPaint (infoPtr->Self, &ps);
395 UPDOWN_Draw (infoPtr, hdc);
396 EndPaint (infoPtr->Self, &ps);
400 /***********************************************************************
402 * Tests if 'bud' is a valid window handle. If not, returns FALSE.
403 * Else, sets it as a new Buddy.
404 * Then, it should subclass the buddy
405 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
406 * process the UP/DOWN arrow keys.
407 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
408 * the size/pos of the buddy and the control are adjusted accordingly.
410 static BOOL UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
412 DWORD dwStyle = GetWindowLongA (infoPtr->Self, GWL_STYLE);
413 RECT budRect; /* new coord for the buddy */
414 int x,width; /* new x position and width for the up-down */
415 WNDPROC baseWndProc, currWndProc;
417 /* Is it a valid bud? */
418 if(!IsWindow(bud)) return FALSE;
420 /* there is already a body assigned */
421 if ( infoPtr->Buddy )
422 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
424 /* Store buddy window handle */
425 infoPtr->Buddy = bud;
427 /* keep upDown ctrl hwnd in a buddy property */
428 SetPropA( bud, BUDDY_UPDOWN_HWND, infoPtr->Self);
430 /* Store buddy window clas name */
431 memset(infoPtr->szBuddyClass, 0, UPDOWN_BUDDYCLASSNAMELEN);
432 GetClassNameA (bud, infoPtr->szBuddyClass, UPDOWN_BUDDYCLASSNAMELEN-1);
434 if(dwStyle & UDS_ARROWKEYS){
435 /* Note that I don't clear the BUDDY_SUPERCLASS_WNDPROC property
436 when we reset the upDown ctrl buddy to another buddy because it is not
437 good to break the window proc chain. */
439 currWndProc = (WNDPROC) GetWindowLongA(bud, GWL_WNDPROC);
440 if (currWndProc != UPDOWN_Buddy_SubclassProc)
442 // replace the buddy's WndProc with ours
443 baseWndProc = (WNDPROC)SetWindowLongA(bud, GWL_WNDPROC,
444 (LPARAM)UPDOWN_Buddy_SubclassProc);
445 // and save the base class' WndProc
446 SetPropA(bud, BUDDY_SUPERCLASS_WNDPROC, (HANDLE)baseWndProc);
449 // its already been subclassed, don't overwrite BUDDY_SUPERCLASS_WNDPROC
452 /* Get the rect of the buddy relative to its parent */
453 GetWindowRect(infoPtr->Buddy, &budRect);
454 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
455 (POINT *)(&budRect.left), 2);
457 /* now do the positioning */
458 if (dwStyle & UDS_ALIGNLEFT) {
460 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
462 else if (dwStyle & UDS_ALIGNRIGHT){
463 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
464 x = budRect.right+DEFAULT_XSEP;
467 x = budRect.right+DEFAULT_XSEP;
470 /* first adjust the buddy to accomodate the up/down */
471 SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
472 budRect.right - budRect.left, budRect.bottom - budRect.top,
473 SWP_NOACTIVATE|SWP_NOZORDER);
475 /* now position the up/down */
476 /* Since the UDS_ALIGN* flags were used, */
477 /* we will pick the position and size of the window. */
478 width = DEFAULT_WIDTH;
481 * If the updown has a buddy border, it has to overlap with the buddy
482 * to look as if it is integrated with the buddy control.
483 * We nudge the control or change it size to overlap.
485 if (UPDOWN_HasBuddyBorder(infoPtr))
487 if(dwStyle & UDS_ALIGNLEFT)
488 width+=DEFAULT_BUDDYBORDER;
490 x-=DEFAULT_BUDDYBORDER;
493 SetWindowPos (infoPtr->Self, infoPtr->Buddy,
494 x, budRect.top-DEFAULT_ADDTOP,
495 width, (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
501 /***********************************************************************
504 * This function increments/decrements the CurVal by the
505 * 'delta' amount according to the 'incr' flag
506 * It notifies the parent as required.
507 * It handles wraping and non-wraping correctly.
508 * It is assumed that delta>0
510 static void UPDOWN_DoAction (UPDOWN_INFO *infoPtr, int delta, BOOL incr)
512 DWORD dwStyle = GetWindowLongA (infoPtr->Self, GWL_STYLE);
515 TRACE("%s by %d\n", incr ? "inc" : "dec", delta);
517 /* check if we can do the modification first */
518 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
520 /* We must notify parent now to obtain permission */
521 ni.iPos = infoPtr->CurVal;
523 ni.hdr.hwndFrom = infoPtr->Self;
524 ni.hdr.idFrom = GetWindowLongA (infoPtr->Self, GWL_ID);
525 ni.hdr.code = UDN_DELTAPOS;
526 if (!SendMessageA(GetParent (infoPtr->Self), WM_NOTIFY,
527 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))
529 /* Parent said: OK to adjust */
531 /* Now adjust value with (maybe new) delta */
532 if (UPDOWN_OffsetVal (infoPtr, ni.iDelta))
534 /* Now take care about our buddy */
535 if(infoPtr->Buddy && IsWindow(infoPtr->Buddy)
536 && (dwStyle & UDS_SETBUDDYINT) )
537 UPDOWN_SetBuddyInt (infoPtr);
541 /* Also, notify it. This message is sent in any case. */
542 SendMessageA (GetParent (infoPtr->Self),
543 dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
544 MAKELONG(SB_THUMBPOSITION, infoPtr->CurVal), infoPtr->Self);
547 /***********************************************************************
550 * Returns TRUE if it is enabled as well as its buddy (if any)
553 static BOOL UPDOWN_IsEnabled (UPDOWN_INFO *infoPtr)
555 if(GetWindowLongA (infoPtr->Self, GWL_STYLE) & WS_DISABLED)
558 return IsWindowEnabled(infoPtr->Buddy);
562 /***********************************************************************
565 * Deletes any timers, releases the mouse and does redraw if necessary.
566 * If the control is not in "capture" mode, it does nothing.
567 * If the control was not in cancel mode, it returns FALSE.
568 * If the control was in cancel mode, it returns TRUE.
570 static BOOL UPDOWN_CancelMode (UPDOWN_INFO *infoPtr)
572 /* if not in 'capture' mode, do nothing */
573 if(!(infoPtr->Flags & FLAG_CLICKED))
576 KillTimer (infoPtr->Self, TIMERID1); /* kill all possible timers */
577 KillTimer (infoPtr->Self, TIMERID2);
579 if (GetCapture() == infoPtr->Self) /* let the mouse go */
580 ReleaseCapture(); /* if we still have it */
582 infoPtr->Flags = 0; /* get rid of any flags */
583 UPDOWN_Refresh (infoPtr); /* redraw the control just in case */
588 /***********************************************************************
589 * UPDOWN_HandleMouseEvent
591 * Handle a mouse event for the updown.
592 * 'pt' is the location of the mouse event in client or
593 * windows coordinates.
595 static void UPDOWN_HandleMouseEvent (UPDOWN_INFO *infoPtr, UINT msg, POINT pt)
597 DWORD dwStyle = GetWindowLongA (infoPtr->Self, GWL_STYLE);
603 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
604 /* If we are already in the 'clicked' mode, then nothing to do */
605 if(infoPtr->Flags & FLAG_CLICKED)
608 /* If the buddy is an edit, will set focus to it */
609 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
610 SetFocus(infoPtr->Buddy);
612 /* Now see which one is the 'active' arrow */
613 temp = UPDOWN_GetArrowFromPoint (infoPtr, &rect, pt);
615 /* Update the CurVal if necessary */
616 if (dwStyle & UDS_SETBUDDYINT)
617 UPDOWN_GetBuddyInt (infoPtr);
619 /* Set up the correct flags */
621 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
622 infoPtr->Flags |= FLAG_MOUSEIN;
624 /* repaint the control */
625 UPDOWN_Refresh (infoPtr);
627 /* process the click */
628 UPDOWN_DoAction (infoPtr, 1, infoPtr->Flags & FLAG_INCR);
630 /* now capture all mouse messages */
631 SetCapture (infoPtr->Self);
633 /* and startup the first timer */
634 SetTimer(infoPtr->Self, TIMERID1, INITIAL_DELAY, 0);
638 /* If we are not in the 'clicked' mode, then nothing to do */
639 if(!(infoPtr->Flags & FLAG_CLICKED))
642 /* save the flags to see if any got modified */
643 temp = infoPtr->Flags;
645 /* Now get the 'active' arrow rectangle */
646 if (infoPtr->Flags & FLAG_INCR)
647 UPDOWN_GetArrowRect (infoPtr, &rect, TRUE);
649 UPDOWN_GetArrowRect (infoPtr, &rect, FALSE);
651 /* Update the flags if we are in/out */
652 if(PtInRect(&rect, pt))
653 infoPtr->Flags |= FLAG_MOUSEIN;
655 infoPtr->Flags &= ~FLAG_MOUSEIN;
656 if(infoPtr->AccelIndex != -1) /* if we have accel info */
657 infoPtr->AccelIndex = 0; /* reset it */
659 /* If state changed, redraw the control */
660 if(temp != infoPtr->Flags)
661 UPDOWN_Refresh (infoPtr);
665 ERR("Impossible case!\n");
670 /***********************************************************************
673 static LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
676 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
677 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
679 if (!infoPtr && (message != WM_CREATE) && (message != WM_NCCREATE))
680 return DefWindowProcA (hwnd, message, wParam, lParam);
684 /* get rid of border, if any */
685 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER);
689 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
690 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
692 /* initialize the info struct */
693 infoPtr->Self = hwnd;
694 infoPtr->AccelCount = 0;
695 infoPtr->AccelVect = 0;
696 infoPtr->AccelIndex = -1;
699 infoPtr->MaxVal = 9999;
700 infoPtr->Base = 10; /* Default to base 10 */
701 infoPtr->Buddy = 0; /* No buddy window yet */
702 infoPtr->Flags = 0; /* And no flags */
704 /* Do we pick the buddy win ourselves? */
705 if (dwStyle & UDS_AUTOBUDDY)
706 UPDOWN_SetBuddy (infoPtr, GetWindow (hwnd, GW_HWNDPREV));
708 TRACE("UpDown Ctrl creation, hwnd=%04x\n", hwnd);
712 if(infoPtr->AccelVect)
713 COMCTL32_Free (infoPtr->AccelVect);
715 if ( IsWindow(infoPtr->Buddy) ) /* Cleanup */
716 RemovePropA(infoPtr->Buddy, BUDDY_UPDOWN_HWND);
718 COMCTL32_Free (infoPtr);
719 SetWindowLongA (hwnd, 0, 0);
720 TRACE("UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
724 if (dwStyle & WS_DISABLED)
725 UPDOWN_CancelMode (infoPtr);
727 UPDOWN_Refresh (infoPtr);
731 /* if initial timer, kill it and start the repeat timer */
732 if(wParam == TIMERID1){
733 KillTimer(hwnd, TIMERID1);
734 /* if no accel info given, used default timer */
735 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
736 infoPtr->AccelIndex = -1;
740 infoPtr->AccelIndex = 0; /* otherwise, use it */
741 temp = infoPtr->AccelVect[infoPtr->AccelIndex].nSec * 1000 + 1;
743 SetTimer(hwnd, TIMERID2, temp, 0);
746 /* now, if the mouse is above us, do the thing...*/
747 if(infoPtr->Flags & FLAG_MOUSEIN){
748 temp = infoPtr->AccelIndex == -1 ? 1 : infoPtr->AccelVect[infoPtr->AccelIndex].nInc;
749 UPDOWN_DoAction(infoPtr, temp, infoPtr->Flags & FLAG_INCR);
751 if(infoPtr->AccelIndex != -1 && infoPtr->AccelIndex < infoPtr->AccelCount-1){
752 KillTimer(hwnd, TIMERID2);
753 infoPtr->AccelIndex++; /* move to the next accel info */
754 temp = infoPtr->AccelVect[infoPtr->AccelIndex].nSec * 1000 + 1;
755 /* make sure we have at least 1ms intervals */
756 SetTimer(hwnd, TIMERID2, temp, 0);
762 UPDOWN_CancelMode (infoPtr);
766 if(!UPDOWN_CancelMode(infoPtr))
769 SendMessageA(GetParent(hwnd), dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
770 MAKELONG(SB_ENDSCROLL, infoPtr->CurVal), hwnd);
772 /*If we released the mouse and our buddy is an edit */
773 /* we must select all text in it. */
774 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
775 SendMessageA(infoPtr->Buddy, EM_SETSEL, 0, MAKELONG(0, -1));
780 if(UPDOWN_IsEnabled(infoPtr)){
782 pt.x = SLOWORD(lParam);
783 pt.y = SHIWORD(lParam);
784 UPDOWN_HandleMouseEvent (infoPtr, message, pt );
789 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(infoPtr)){
793 UPDOWN_GetBuddyInt (infoPtr);
794 /* FIXME: Paint the according button pressed for some time, like win95 does*/
795 UPDOWN_DoAction (infoPtr, 1, wParam==VK_UP);
802 UPDOWN_Paint (infoPtr, (HDC)wParam);
806 if (wParam==0 && lParam==0) /*if both zero, */
807 return infoPtr->AccelCount; /*just return the accel count*/
808 if (wParam || lParam){
809 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
812 temp = min(infoPtr->AccelCount, wParam);
813 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
817 TRACE("UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
818 if(infoPtr->AccelVect){
819 COMCTL32_Free (infoPtr->AccelVect);
820 infoPtr->AccelCount = 0;
821 infoPtr->AccelVect = 0;
825 infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
826 if(infoPtr->AccelVect==0)
828 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
832 if (wParam || lParam)
833 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
834 return infoPtr->Base;
837 TRACE("UpDown Ctrl new base(%d), hwnd=%04x\n", wParam, hwnd);
838 if ( !(wParam==10 || wParam==16) || lParam)
839 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
840 if (wParam==10 || wParam==16){
841 temp = infoPtr->Base;
842 infoPtr->Base = wParam;
843 return temp; /* return the prev base */
848 if (wParam || lParam)
849 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
850 return infoPtr->Buddy;
854 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
855 temp = infoPtr->Buddy;
856 UPDOWN_SetBuddy (infoPtr, wParam);
857 TRACE("UpDown Ctrl new buddy(%04x), hwnd=%04x\n", infoPtr->Buddy, hwnd);
861 if (wParam || lParam)
862 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
863 temp = UPDOWN_GetBuddyInt (infoPtr);
864 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
867 if (wParam || HIWORD(lParam))
868 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
869 temp = SLOWORD(lParam);
870 TRACE("UpDown Ctrl new value(%d), hwnd=%04x\n", temp, hwnd);
871 if(!UPDOWN_InBounds(infoPtr, temp)){
872 if(temp < infoPtr->MinVal)
873 temp = infoPtr->MinVal;
874 if(temp > infoPtr->MaxVal)
875 temp = infoPtr->MaxVal;
877 wParam = infoPtr->CurVal; /* save prev value */
878 infoPtr->CurVal = temp; /* set the new value */
879 if(dwStyle & UDS_SETBUDDYINT)
880 UPDOWN_SetBuddyInt (infoPtr);
881 return wParam; /* return prev value */
884 if (wParam || lParam)
885 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
886 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
890 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
891 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
892 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
893 /* |Max-Min| <= UD_MAXVAL */
894 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
895 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
900 *(LPINT)wParam = infoPtr->MinVal;
902 *(LPINT)lParam = infoPtr->MaxVal;
906 infoPtr->MinVal = (INT)wParam;
907 infoPtr->MaxVal = (INT)lParam;
908 if (infoPtr->MaxVal <= infoPtr->MinVal)
909 infoPtr->MaxVal = infoPtr->MinVal + 1;
910 TRACE("UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
911 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
915 if ((LPBOOL)lParam != NULL)
916 *((LPBOOL)lParam) = TRUE;
917 return infoPtr->CurVal;
920 if(!UPDOWN_InBounds(infoPtr, (int)lParam)){
921 if((int)lParam < infoPtr->MinVal)
922 lParam = infoPtr->MinVal;
923 if((int)lParam > infoPtr->MaxVal)
924 lParam = infoPtr->MaxVal;
926 temp = infoPtr->CurVal; /* save prev value */
927 infoPtr->CurVal = (int)lParam; /* set the new value */
928 if(dwStyle & UDS_SETBUDDYINT)
929 UPDOWN_SetBuddyInt (infoPtr);
930 return temp; /* return prev value */
933 if (message >= WM_USER)
934 ERR("unknown msg %04x wp=%04x lp=%08lx\n", message, wParam, lParam);
935 return DefWindowProcA (hwnd, message, wParam, lParam);
941 /***********************************************************************
942 * UPDOWN_Buddy_SubclassProc used to handle messages sent to the buddy
946 UPDOWN_Buddy_SubclassProc (
952 WNDPROC superClassWndProc = (WNDPROC)GetPropA(hwnd, BUDDY_SUPERCLASS_WNDPROC);
953 TRACE("hwnd=%04x, wndProc=%d, uMsg=%04x, wParam=%d, lParam=%d\n",
954 hwnd, (INT)superClassWndProc, uMsg, wParam, (UINT)lParam);
960 if ( ((int)wParam == VK_UP ) || ((int)wParam == VK_DOWN ) )
962 HWND upDownHwnd = GetPropA(hwnd, BUDDY_UPDOWN_HWND);
963 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(upDownHwnd);
965 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox"))
967 /* if the buddy is a list window, we must update curr index */
968 INT oldVal = SendMessageA(hwnd, LB_GETCURSEL, 0, 0);
969 SendMessageA(hwnd, LB_SETCURSEL, oldVal+1, 0);
973 UPDOWN_GetBuddyInt(infoPtr);
974 UPDOWN_DoAction(infoPtr, 1, wParam==VK_UP);
979 /* else Fall Through */
982 return CallWindowProcA( superClassWndProc, hwnd, uMsg, wParam, lParam);
985 /***********************************************************************
986 * UPDOWN_Register [Internal]
988 * Registers the updown window class.
992 UPDOWN_Register(void)
996 ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
997 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
998 wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
999 wndClass.cbClsExtra = 0;
1000 wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
1001 wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
1002 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
1003 wndClass.lpszClassName = UPDOWN_CLASSA;
1005 RegisterClassA( &wndClass );
1009 /***********************************************************************
1010 * UPDOWN_Unregister [Internal]
1012 * Unregisters the updown window class.
1016 UPDOWN_Unregister (void)
1018 UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);