Release 980315
[wine/multimedia.git] / controls / updown.c
blobe3b95cb12903b6b8e808a4cc2c4cc6b56aeeee1b
1 /*
2 * Updown control
4 * Copyright 1997 Dimitrie O. Paun
6 * TODO:
7 * - subclass the buddy window (in UPDOWN_SetBuddy) to process the
8 * arrow keys
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 * Testing:
13 * Not much. The following have not been tested at all:
14 * - horizontal arrows
15 * - listbox as buddy window
16 * - acceleration
17 * - base 16
18 * - UDS_ALIGNLEFT, ~UDS_WRAP
19 * - integers with thousand separators.
20 * Even though the above list seems rather large, the control seems to
21 * behave very well so I am confident it does work in most (all) of the
22 * untested cases.
23 * Problems:
24 * I do not like the arrows yet, I'll work more on them later on.
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <assert.h>
30 #include <string.h>
31 #include "windows.h"
32 #include "winnls.h"
33 #include "sysmetrics.h"
34 #include "updown.h"
35 #include "graphics.h"
36 #include "heap.h"
37 #include "win.h"
38 #include "debug.h"
40 /* Control configuration constants */
42 #define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
43 #define REPEAT_DELAY 50 /* delay between auto-increments */
45 #define DEFAULT_WIDTH 14 /* default width of the ctrl */
46 #define DEFAULT_XSEP 0 /* default separation between buddy and crtl */
47 #define DEFAULT_ADDTOP 0 /* amount to extend above the buddy window */
48 #define DEFAULT_ADDBOT 0 /* amount to extend below the buddy window */
51 /* Work constants */
53 #define FLAG_INCR 0x01
54 #define FLAG_DECR 0x02
55 #define FLAG_MOUSEIN 0x04
56 #define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
58 #define TIMERID1 1
59 #define TIMERID2 2
61 static int accelIndex = -1;
63 #define UNKNOWN_PARAM(msg, wParam, lParam) WARN(updown, \
64 "UpDown Ctrl: Unknown parameter(s) for message " #msg \
65 "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
67 #define UPDOWN_GetInfoPtr(wndPtr) ((UPDOWN_INFO *)wndPtr->wExtra)
69 /***********************************************************************
70 * UPDOWN_InBounds
71 * Tests if a given value 'val' is between the Min&Max limits
73 static BOOL32 UPDOWN_InBounds(WND *wndPtr, int val)
75 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
77 if(infoPtr->MaxVal > infoPtr->MinVal)
78 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
79 else
80 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
83 /***********************************************************************
84 * UPDOWN_OffsetVal
85 * Tests if we can change the current value by delta. If so, it changes
86 * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
88 static BOOL32 UPDOWN_OffsetVal(WND *wndPtr, int delta)
90 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
92 /* check if we can do the modification first */
93 if(!UPDOWN_InBounds(wndPtr, infoPtr->CurVal+delta)){
94 if(wndPtr->dwStyle & UDS_WRAP)
95 delta += (delta < 0 ? -1 : 1) *
96 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
97 (infoPtr->MinVal - infoPtr->MaxVal) +
98 (delta < 0 ? 1 : -1);
99 else
100 return FALSE;
103 infoPtr->CurVal += delta;
104 return TRUE;
107 /***********************************************************************
108 * UPDOWN_GetArrawRect
109 * wndPtr - pointer to the up-down wnd
110 * rect - will hold the rectangle
111 * incr - TRUE get the "increment" rect (up or right)
112 * FALSE get the "decrement" rect (down or left)
115 static void UPDOWN_GetArrowRect(WND *wndPtr, RECT32 *rect, BOOL32 incr)
117 int len; /* will hold the width or height */
119 GetClientRect32(wndPtr->hwndSelf, rect);
121 if (wndPtr->dwStyle & UDS_HORZ) {
122 len = rect->right - rect->left; /* compute the width */
123 if (incr)
124 rect->left = len/2+1;
125 else
126 rect->right = len/2;
128 else {
129 len = rect->bottom - rect->top; /* compute the height */
130 if (incr)
131 rect->bottom = len/2;
132 else
133 rect->top = len/2+1;
137 /***********************************************************************
138 * UPDOWN_GetArrowFromPoint
139 * Returns the rectagle (for the up or down arrow) that contains pt.
140 * If it returns the up rect, it returns TRUE.
141 * If it returns the down rect, it returns FALSE.
143 static int UPDOWN_GetArrowFromPoint(WND *wndPtr, RECT32 *rect, POINT32 pt)
145 UPDOWN_GetArrowRect(wndPtr, rect, TRUE);
146 if(PtInRect32(rect, pt))
147 return TRUE;
149 UPDOWN_GetArrowRect(wndPtr, rect, FALSE);
150 return FALSE;
154 /***********************************************************************
155 * UPDOWN_GetThousandSep
156 * Returns the thousand sep. If an error occurs, it returns ','.
158 static char UPDOWN_GetThousandSep()
160 char sep[2];
162 if(GetLocaleInfo32A(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
163 sep, sizeof(sep)) != 1)
164 return ',';
166 return sep[0];
169 /***********************************************************************
170 * UPDOWN_GetBuddyInt
171 * Tries to read the pos from the buddy window and if it succeeds,
172 * it stores it in the control's CurVal
173 * returns:
174 * TRUE - if it read the integer from the buddy successfully
175 * FALSE - if an error occured
177 static BOOL32 UPDOWN_GetBuddyInt(WND *wndPtr)
179 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
180 char txt[20], sep, *src, *dst;
181 int newVal;
183 if (!IsWindow32(infoPtr->Buddy))
184 return FALSE;
186 /*if the buddy is a list window, we must set curr index */
187 if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
188 newVal = SendMessage32A(infoPtr->Buddy, LB_GETCARETINDEX32, 0, 0);
189 if(newVal < 0)
190 return FALSE;
192 else{
193 /* we have a regural window, so will get the text */
194 if (!GetWindowText32A(infoPtr->Buddy, txt, sizeof(txt)))
195 return FALSE;
197 sep = UPDOWN_GetThousandSep();
199 /* now get rid of the separators */
200 for(src = dst = txt; *src; src++)
201 if(*src != sep)
202 *dst++ = *src;
203 *dst = 0;
205 /* try to convert the number and validate it */
206 newVal = strtol(txt, &src, infoPtr->Base);
207 if(*src || !UPDOWN_InBounds(wndPtr, newVal))
208 return FALSE;
210 TRACE(updown, "new value(%d) read from buddy (old=%d)\n",
211 newVal, infoPtr->CurVal);
214 infoPtr->CurVal = newVal;
215 return TRUE;
219 /***********************************************************************
220 * UPDOWN_SetBuddyInt
221 * Tries to set the pos to the buddy window based on current pos
222 * returns:
223 * TRUE - if it set the caption of the buddy successfully
224 * FALSE - if an error occured
226 static BOOL32 UPDOWN_SetBuddyInt(WND *wndPtr)
228 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
229 char txt1[20], sep;
230 int len;
232 if (!IsWindow32(infoPtr->Buddy))
233 return FALSE;
235 TRACE(updown, "set new value(%d) to buddy.\n",
236 infoPtr->CurVal);
238 /*if the buddy is a list window, we must set curr index */
239 if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_LISTBOX)){
240 SendMessage32A(infoPtr->Buddy, LB_SETCURSEL32, infoPtr->CurVal, 0);
242 else{ /* Regural window, so set caption to the number */
243 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
245 sep = UPDOWN_GetThousandSep();
247 if (!(wndPtr->dwStyle & UDS_NOTHOUSANDS)) {
248 char txt2[20], *src = txt1, *dst = txt2;
249 if(len%3 > 0){
250 strncpy(dst, src, len%3);
251 dst += len%3;
252 src += len%3;
254 for(len=0; *src; len++,src++){
255 if(len%3==0)
256 *dst++ = sep;
257 *dst++ = *src++;
259 *dst = 0; /* null terminate it */
260 strcpy(txt1, txt2); /* move it to the proper place */
262 SetWindowText32A(infoPtr->Buddy, txt1);
265 return TRUE;
268 /***********************************************************************
269 * UPDOWN_Paint
270 * Draw the arrows. The background need not be erased.
272 static void UPDOWN_Paint(WND *wndPtr)
274 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
275 PAINTSTRUCT32 ps;
276 BOOL32 prssed;
277 RECT32 rect;
278 HDC32 hdc;
280 /* start painting the button */
281 hdc = BeginPaint32( wndPtr->hwndSelf, &ps );
283 /* Draw the incr button */
284 UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
285 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
286 DrawFrameControl32(hdc, &rect, DFC_SCROLL,
287 (wndPtr->dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
288 (prssed ? DFCS_PUSHED : 0) |
289 (wndPtr->dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
291 /* Draw the space between the buttons */
292 rect.top = rect.bottom; rect.bottom++;
293 DrawEdge32(hdc, &rect, 0, BF_MIDDLE);
295 /* Draw the decr button */
296 UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
297 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
298 DrawFrameControl32(hdc, &rect, DFC_SCROLL,
299 (wndPtr->dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
300 (prssed ? DFCS_PUSHED : 0) |
301 (wndPtr->dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
304 /* clean-up */
305 EndPaint32( wndPtr->hwndSelf, &ps );
308 /***********************************************************************
309 * UPDOWN_SetBuddy
310 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
311 * Else, sets it as a new Buddy.
312 * Then, it should subclass the buddy
313 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
314 * process the UP/DOWN arrow keys.
315 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
316 * the size/pos of the buddy and the control are adjusted accordingly.
318 static BOOL32 UPDOWN_SetBuddy(WND *wndPtr, HWND32 hwndBud)
320 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
321 RECT32 budRect; /* new coord for the buddy */
322 int x; /* new x position and width for the up-down */
324 /* Is is a valid bud? */
325 if(!IsWindow32(hwndBud))
326 return FALSE;
328 if(wndPtr->dwStyle & UDS_ARROWKEYS){
329 FIXME(updown, "we need to subclass the buddy to process the arrow keys.\n");
332 /* do we need to do any adjustments? */
333 if(!(wndPtr->dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
334 return TRUE;
336 /* Get the rect of the buddy relative to its parent */
337 GetWindowRect32(infoPtr->Buddy, &budRect);
338 MapWindowPoints32(HWND_DESKTOP, GetParent32(infoPtr->Buddy),
339 (POINT32 *)(&budRect.left), 2);
341 /* now do the positioning */
342 if(wndPtr->dwStyle & UDS_ALIGNRIGHT){
343 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
344 x = budRect.right+DEFAULT_XSEP;
346 else{ /* UDS_ALIGNLEFT */
347 x = budRect.left;
348 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
351 /* first adjust the buddy to accomodate the up/down */
352 SetWindowPos32(infoPtr->Buddy, 0, budRect.left, budRect.top,
353 budRect.right - budRect.left, budRect.bottom - budRect.top,
354 SWP_NOACTIVATE|SWP_NOZORDER);
356 /* now position the up/down */
357 /* Since the UDS_ALIGN* flags were used, */
358 /* we will pick the position and size of the window. */
359 SetWindowPos32(wndPtr->hwndSelf,0,x,budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
360 (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
361 SWP_NOACTIVATE|SWP_NOZORDER);
363 return TRUE;
366 /***********************************************************************
367 * UPDOWN_DoAction
369 * This function increments/decrements the CurVal by the
370 * 'delta' amount according to the 'incr' flag
371 * It notifies the parent as required.
372 * It handles wraping and non-wraping correctly.
373 * It is assumed that delta>0
375 static void UPDOWN_DoAction(WND *wndPtr, int delta, BOOL32 incr)
377 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
378 int old_val = infoPtr->CurVal;
379 NM_UPDOWN ni;
381 TRACE(updown, "%s by %d\n", incr ? "inc" : "dec", delta);
383 /* check if we can do the modification first */
384 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
385 if(!UPDOWN_OffsetVal(wndPtr, delta))
386 return;
388 /* so, if we can do the change, recompute delta and restore old value */
389 delta = infoPtr->CurVal - old_val;
390 infoPtr->CurVal = old_val;
392 /* We must notify parent now to obtain permission */
393 ni.iPos = infoPtr->CurVal;
394 ni.iDelta = delta;
395 ni.hdr.hwndFrom = wndPtr->hwndSelf;
396 ni.hdr.idFrom = wndPtr->wIDmenu;
397 ni.hdr.code = UDN_DELTAPOS;
398 if(SendMessage32A(wndPtr->parent->hwndSelf,
399 WM_NOTIFY, wndPtr->wIDmenu, (LPARAM)&ni))
400 return; /* we are not allowed to change */
402 /* Now adjust value with (maybe new) delta */
403 if(!UPDOWN_OffsetVal(wndPtr, ni.iDelta))
404 return;
406 /* Now take care about our buddy */
407 if(!IsWindow32(infoPtr->Buddy))
408 return; /* Nothing else to do */
411 if(wndPtr->dwStyle & UDS_SETBUDDYINT)
412 UPDOWN_SetBuddyInt(wndPtr);
414 /* Also, notify it */
415 /* FIXME: do we need to send the notification only if
416 we do not have the UDS_SETBUDDYINT style set? */
417 SendMessage32A(infoPtr->Buddy,
418 wndPtr->dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
419 MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
420 wndPtr->hwndSelf);
423 /***********************************************************************
424 * UPDOWN_IsEnabled
426 * Returns TRUE if it is enabled as well as its buddy (if any)
427 * FALSE otherwise
429 static BOOL32 UPDOWN_IsEnabled(WND *wndPtr)
431 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
433 if(wndPtr->dwStyle & WS_DISABLED)
434 return FALSE;
435 return IsWindowEnabled32(infoPtr->Buddy);
438 /***********************************************************************
439 * UPDOWN_CancelMode
441 * Deletes any timers, releases the mouse and does redraw if necessary.
442 * If the control is not in "capture" mode, it does nothing.
443 * If the control was not in cancel mode, it returns FALSE.
444 * If the control was in cancel mode, it returns TRUE.
446 static BOOL32 UPDOWN_CancelMode(WND *wndPtr)
448 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
450 /* if not in 'capture' mode, do nothing */
451 if(!(infoPtr->Flags & FLAG_CLICKED))
452 return FALSE;
454 KillTimer32(wndPtr->hwndSelf, TIMERID1); /* kill all possible timers */
455 KillTimer32(wndPtr->hwndSelf, TIMERID2);
457 if(GetCapture32() == wndPtr->hwndSelf) /* let the mouse go */
458 ReleaseCapture(); /* if we still have it */
460 infoPtr->Flags = 0; /* get rid of any flags */
461 UPDOWN_Paint(wndPtr); /* redraw the control just in case */
463 return TRUE;
466 /***********************************************************************
467 * UPDOWN_HandleMouseEvent
469 * Handle a mouse event for the updown.
470 * 'pt' is the location of the mouse event in client or
471 * windows coordinates.
473 static void UPDOWN_HandleMouseEvent(WND *wndPtr, UINT32 msg, POINT32 pt)
475 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
476 RECT32 rect;
477 int temp;
479 switch(msg)
481 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
482 /* If we are already in the 'clicked' mode, then nothing to do */
483 if(infoPtr->Flags & FLAG_CLICKED)
484 return;
486 /* If the buddy is an edit, will set focus to it */
487 if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
488 SetFocus32(infoPtr->Buddy);
490 /* Now see which one is the 'active' arrow */
491 temp = UPDOWN_GetArrowFromPoint(wndPtr, &rect, pt);
493 /* Update the CurVal if necessary */
494 if(wndPtr->dwStyle & UDS_SETBUDDYINT)
495 UPDOWN_GetBuddyInt(wndPtr);
497 /* Before we proceed, see if we can spin... */
498 if(!(wndPtr->dwStyle & UDS_WRAP))
499 if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
500 (!temp && infoPtr->CurVal==infoPtr->MinVal))
501 return;
503 /* Set up the correct flags */
504 infoPtr->Flags = 0;
505 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
506 infoPtr->Flags |= FLAG_MOUSEIN;
508 /* repaint the control */
509 UPDOWN_Paint(wndPtr);
511 /* process the click */
512 UPDOWN_DoAction(wndPtr, 1, infoPtr->Flags & FLAG_INCR);
514 /* now capture all mouse messages */
515 SetCapture32(wndPtr->hwndSelf);
517 /* and startup the first timer */
518 SetTimer32(wndPtr->hwndSelf, TIMERID1, INITIAL_DELAY, 0);
519 break;
521 case WM_MOUSEMOVE:
522 /* If we are not in the 'clicked' mode, then nothing to do */
523 if(!(infoPtr->Flags & FLAG_CLICKED))
524 return;
526 /* save the flags to see if any got modified */
527 temp = infoPtr->Flags;
529 /* Now get the 'active' arrow rectangle */
530 if (infoPtr->Flags & FLAG_INCR)
531 UPDOWN_GetArrowRect(wndPtr, &rect, TRUE);
532 else
533 UPDOWN_GetArrowRect(wndPtr, &rect, FALSE);
535 /* Update the flags if we are in/out */
536 if(PtInRect32(&rect, pt))
537 infoPtr->Flags |= FLAG_MOUSEIN;
538 else{
539 infoPtr->Flags &= ~FLAG_MOUSEIN;
540 if(accelIndex != -1) /* if we have accel info */
541 accelIndex = 0; /* reset it */
543 /* If state changed, redraw the control */
544 if(temp != infoPtr->Flags)
545 UPDOWN_Paint(wndPtr);
546 break;
548 default:
549 ERR(updown, "Impossible case!\n");
554 /***********************************************************************
555 * UpDownWndProc
557 LRESULT WINAPI UpDownWindowProc(HWND32 hwnd, UINT32 message, WPARAM32 wParam,
558 LPARAM lParam)
560 WND *wndPtr = WIN_FindWndPtr(hwnd);
561 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(wndPtr);
562 int temp;
564 switch(message)
566 case WM_CREATE:
567 /* get rid of border, if any */
568 wndPtr->dwStyle &= ~WS_BORDER;
570 /* initialize the info struct */
571 infoPtr->AccelCount=0; infoPtr->AccelVect=0;
572 infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
573 infoPtr->Base = 10; /* Default to base 10 */
574 infoPtr->Buddy = 0; /* No buddy window yet */
575 infoPtr->Flags = 0; /* And no flags */
577 /* Do we pick the buddy win ourselves? */
578 if(wndPtr->dwStyle & UDS_AUTOBUDDY)
579 UPDOWN_SetBuddy(wndPtr, GetWindow32(wndPtr->hwndSelf, GW_HWNDPREV));
581 TRACE(updown, "UpDown Ctrl creation, hwnd=%04x\n", hwnd);
582 break;
584 case WM_DESTROY:
585 if(infoPtr->AccelVect)
586 free(infoPtr->AccelVect);
587 TRACE(updown, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
588 break;
590 case WM_ENABLE:
591 if(wndPtr->dwStyle & WS_DISABLED)
592 UPDOWN_CancelMode(wndPtr);
593 UPDOWN_Paint(wndPtr);
594 break;
596 case WM_TIMER:
597 /* if initial timer, kill it and start the repeat timer */
598 if(wParam == TIMERID1){
599 KillTimer32(hwnd, TIMERID1);
600 /* if no accel info given, used default timer */
601 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
602 accelIndex = -1;
603 temp = REPEAT_DELAY;
605 else{
606 accelIndex = 0; /* otherwise, use it */
607 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
609 SetTimer32(hwnd, TIMERID2, temp, 0);
612 /* now, if the mouse is above us, do the thing...*/
613 if(infoPtr->Flags & FLAG_MOUSEIN){
614 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
615 UPDOWN_DoAction(wndPtr, temp, infoPtr->Flags & FLAG_INCR);
617 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
618 KillTimer32(hwnd, TIMERID2);
619 accelIndex++; /* move to the next accel info */
620 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
621 /* make sure we have at least 1ms intervals */
622 SetTimer32(hwnd, TIMERID2, temp, 0);
625 break;
627 case WM_CANCELMODE:
628 UPDOWN_CancelMode(wndPtr);
629 break;
631 case WM_LBUTTONUP:
632 if(!UPDOWN_CancelMode(wndPtr))
633 break;
634 /*If we released the mouse and our buddy is an edit */
635 /* we must select all text in it. */
636 if(WIDGETS_IsControl32(WIN_FindWndPtr(infoPtr->Buddy), BIC32_EDIT))
637 SendMessage32A(infoPtr->Buddy, EM_SETSEL32, 0, MAKELONG(0, -1));
638 break;
640 case WM_LBUTTONDOWN:
641 case WM_MOUSEMOVE:
642 if(UPDOWN_IsEnabled(wndPtr)){
643 POINT32 pt;
644 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
645 UPDOWN_HandleMouseEvent( wndPtr, message, pt );
647 break;
649 case WM_KEYDOWN:
650 if((wndPtr->dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(wndPtr)){
651 switch(wParam){
652 case VK_UP:
653 case VK_DOWN:
654 UPDOWN_GetBuddyInt(wndPtr);
655 UPDOWN_DoAction(wndPtr, 1, wParam==VK_UP);
656 break;
659 break;
661 case WM_PAINT:
662 UPDOWN_Paint(wndPtr);
663 break;
665 case UDM_GETACCEL:
666 if (wParam==0 && lParam==0) /*if both zero, */
667 return infoPtr->AccelCount; /*just return the accel count*/
668 if (wParam || lParam){
669 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
670 return 0;
672 temp = MIN(infoPtr->AccelCount, wParam);
673 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
674 return temp;
676 case UDM_SETACCEL:
677 TRACE(updown, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
678 if(infoPtr->AccelVect){
679 free(infoPtr->AccelVect);
680 infoPtr->AccelCount = 0;
681 infoPtr->AccelVect = 0;
683 if(wParam==0)
684 return TRUE;
685 infoPtr->AccelVect = malloc(wParam*sizeof(UDACCEL));
686 if(infoPtr->AccelVect==0)
687 return FALSE;
688 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
689 return TRUE;
691 case UDM_GETBASE:
692 if (wParam || lParam)
693 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
694 return infoPtr->Base;
696 case UDM_SETBASE:
697 TRACE(updown, "UpDown Ctrl new base(%d), hwnd=%04x\n",
698 wParam, hwnd);
699 if ( !(wParam==10 || wParam==16) || lParam)
700 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
701 if (wParam==10 || wParam==16){
702 temp = infoPtr->Base;
703 infoPtr->Base = wParam;
704 return temp; /* return the prev base */
706 break;
708 case UDM_GETBUDDY:
709 if (wParam || lParam)
710 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
711 return infoPtr->Buddy;
713 case UDM_SETBUDDY:
714 if (lParam)
715 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
716 temp = infoPtr->Buddy;
717 infoPtr->Buddy = wParam;
718 UPDOWN_SetBuddy(wndPtr, wParam);
719 TRACE(updown, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
720 infoPtr->Buddy, hwnd);
721 return temp;
723 case UDM_GETPOS:
724 if (wParam || lParam)
725 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
726 temp = UPDOWN_GetBuddyInt(wndPtr);
727 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
729 case UDM_SETPOS:
730 if (wParam || HIWORD(lParam))
731 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
732 temp = SLOWORD(lParam);
733 TRACE(updown, "UpDown Ctrl new value(%d), hwnd=%04x\n",
734 temp, hwnd);
735 if(!UPDOWN_InBounds(wndPtr, temp)){
736 if(temp < infoPtr->MinVal)
737 temp = infoPtr->MinVal;
738 if(temp > infoPtr->MaxVal)
739 temp = infoPtr->MaxVal;
741 wParam = infoPtr->CurVal; /* save prev value */
742 infoPtr->CurVal = temp; /* set the new value */
743 if(wndPtr->dwStyle & UDS_SETBUDDYINT)
744 UPDOWN_SetBuddyInt(wndPtr);
745 return wParam; /* return prev value */
747 case UDM_GETRANGE:
748 if (wParam || lParam)
749 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
750 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
752 case UDM_SETRANGE:
753 if (wParam)
754 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
755 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
756 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
757 /* |Max-Min| <= UD_MAXVAL */
758 TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
759 infoPtr->MinVal, infoPtr->MaxVal, hwnd);
760 break;
762 default:
763 if (message >= WM_USER)
764 WARN(updown, "unknown msg %04x wp=%04x lp=%08lx\n",
765 message, wParam, lParam );
766 return DefWindowProc32A( hwnd, message, wParam, lParam );
769 return 0;