source: trunk/src/comctl32/updown.c@ 110

Last change on this file since 110 was 110, checked in by cbratschi, 26 years ago

comctl32 wine conversion bugs fixed
trackbar: TRACKBAR_Draw prototype

File size: 26.3 KB
Line 
1/* $Id: updown.c,v 1.4 1999-06-16 20:25:45 cbratschi Exp $ */
2/*
3 * Updown control
4 *
5 * Copyright 1997 Dimitrie O. Paun
6 * Copyright 1999 Achim Hasenmueller
7 * Copyright 1999 Christoph Bratschi
8 *
9 * TODO:
10 * - subclass the buddy window (in UPDOWN_SetBuddy) to process the
11 * arrow keys
12 * - I am not sure about the default values for the Min, Max, Pos
13 * (in the UPDOWN_INFO the fields: MinVal, MaxVal, CurVal)
14 * - I think I do not handle correctly the WS_BORDER style.
15 * (Should be fixed. <ekohl@abo.rhein-zeitung.de>)
16 *
17 * Testing:
18 * Not much. The following have not been tested at all:
19 * - horizontal arrows
20 * - listbox as buddy window
21 * - acceleration
22 * - base 16
23 * - UDS_ALIGNLEFT, ~UDS_WRAP
24 * (tested - they work)
25 * - integers with thousand separators.
26 * (fixed bugs. <noel@macadamian.com>)
27 *
28 * Even though the above list seems rather large, the control seems to
29 * behave very well so I am confident it does work in most (all) of the
30 * untested cases.
31 * Problems:
32 * I do not like the arrows yet, I'll work more on them later on.
33 */
34
35#include <stdlib.h>
36#include <stdio.h>
37#include <string.h>
38
39#include "winbase.h"
40#include "winuser.h"
41#include "commctrl.h"
42#include "winnls.h"
43#include "updown.h"
44
45/* Control configuration constants */
46
47#define INITIAL_DELAY 500 /* initial timer until auto-increment kicks in */
48#define REPEAT_DELAY 50 /* delay between auto-increments */
49
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
55
56/* Work constants */
57
58#define FLAG_INCR 0x01
59#define FLAG_DECR 0x02
60#define FLAG_MOUSEIN 0x04
61#define FLAG_CLICKED (FLAG_INCR | FLAG_DECR)
62
63#define TIMERID1 1
64#define TIMERID2 2
65
66static int accelIndex = -1;
67
68//#define UNKNOWN_PARAM(msg, wParam, lParam) WARN(updown, \
69// "UpDown Ctrl: Unknown parameter(s) for message " #msg \
70// "(%04x): wp=%04x lp=%08lx\n", msg, wParam, lParam);
71#define UNKNOWN_PARAM(msg, wParam, lParam)
72
73#define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))
74
75
76/***********************************************************************
77 * UPDOWN_InBounds
78 * Tests if a given value 'val' is between the Min&Max limits
79 */
80static BOOL UPDOWN_InBounds(HWND hwnd, int val)
81{
82 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
83
84 if(infoPtr->MaxVal > infoPtr->MinVal)
85 return (infoPtr->MinVal <= val) && (val <= infoPtr->MaxVal);
86 else
87 return (infoPtr->MaxVal <= val) && (val <= infoPtr->MinVal);
88}
89
90/***********************************************************************
91 * UPDOWN_OffsetVal
92 * Tests if we can change the current value by delta. If so, it changes
93 * it and returns TRUE. Else, it leaves it unchanged and returns FALSE.
94 */
95static BOOL UPDOWN_OffsetVal(HWND hwnd, int delta)
96{
97 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
98
99 /* check if we can do the modification first */
100 if(!UPDOWN_InBounds (hwnd, infoPtr->CurVal+delta)){
101 if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_WRAP)
102 {
103 delta += (delta < 0 ? -1 : 1) *
104 (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1) *
105 (infoPtr->MinVal - infoPtr->MaxVal) +
106 (delta < 0 ? 1 : -1);
107 }
108 else
109 return FALSE;
110 }
111
112 infoPtr->CurVal += delta;
113 return TRUE;
114}
115
116/***********************************************************************
117 * UPDOWN_GetArrowRect
118 * wndPtr - pointer to the up-down wnd
119 * rect - will hold the rectangle
120 * incr - TRUE get the "increment" rect (up or right)
121 * FALSE get the "decrement" rect (down or left)
122 *
123 */
124static void UPDOWN_GetArrowRect (HWND hwnd, RECT *rect, BOOL incr)
125{
126 int len; /* will hold the width or height */
127
128 GetClientRect (hwnd, rect);
129
130 if (GetWindowLongA (hwnd, GWL_STYLE) & UDS_HORZ) {
131 len = rect->right - rect->left; /* compute the width */
132 if (incr)
133 rect->left = len/2+1;
134 else
135 rect->right = len/2;
136 }
137 else {
138 len = rect->bottom - rect->top; /* compute the height */
139 if (incr)
140 rect->bottom = len/2;
141 else
142 rect->top = len/2+1;
143 }
144}
145
146/***********************************************************************
147 * UPDOWN_GetArrowFromPoint
148 * Returns the rectagle (for the up or down arrow) that contains pt.
149 * If it returns the up rect, it returns TRUE.
150 * If it returns the down rect, it returns FALSE.
151 */
152static BOOL
153UPDOWN_GetArrowFromPoint (HWND hwnd, RECT *rect, POINT pt)
154{
155 UPDOWN_GetArrowRect (hwnd, rect, TRUE);
156 if(PtInRect(rect, pt))
157 return TRUE;
158
159 UPDOWN_GetArrowRect (hwnd, rect, FALSE);
160 return FALSE;
161}
162
163
164/***********************************************************************
165 * UPDOWN_GetThousandSep
166 * Returns the thousand sep. If an error occurs, it returns ','.
167 */
168static char UPDOWN_GetThousandSep()
169{
170 char sep[2];
171
172 if(GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_STHOUSAND,
173 sep, sizeof(sep)) != 1)
174 return ',';
175
176 return sep[0];
177}
178
179/***********************************************************************
180 * UPDOWN_GetBuddyInt
181 * Tries to read the pos from the buddy window and if it succeeds,
182 * it stores it in the control's CurVal
183 * returns:
184 * TRUE - if it read the integer from the buddy successfully
185 * FALSE - if an error occured
186 */
187static BOOL UPDOWN_GetBuddyInt (HWND hwnd)
188{
189 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
190 char txt[20], sep, *src, *dst;
191 int newVal;
192
193 if (!IsWindow(infoPtr->Buddy))
194 return FALSE;
195
196 /*if the buddy is a list window, we must set curr index */
197 if (!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
198 newVal = SendMessageA(infoPtr->Buddy, LB_GETCARETINDEX, 0, 0);
199 if(newVal < 0)
200 return FALSE;
201 }
202 else{
203 /* we have a regular window, so will get the text */
204 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt)))
205 return FALSE;
206
207 sep = UPDOWN_GetThousandSep();
208
209 /* now get rid of the separators */
210 for(src = dst = txt; *src; src++)
211 if(*src != sep)
212 *dst++ = *src;
213 *dst = 0;
214
215 /* try to convert the number and validate it */
216 newVal = strtol(txt, &src, infoPtr->Base);
217 if(*src || !UPDOWN_InBounds (hwnd, newVal))
218 return FALSE;
219
220// TRACE(updown, "new value(%d) read from buddy (old=%d)\n",
221// newVal, infoPtr->CurVal);
222 }
223
224 infoPtr->CurVal = newVal;
225 return TRUE;
226}
227
228
229/***********************************************************************
230 * UPDOWN_SetBuddyInt
231 * Tries to set the pos to the buddy window based on current pos
232 * returns:
233 * TRUE - if it set the caption of the buddy successfully
234 * FALSE - if an error occured
235 */
236static BOOL UPDOWN_SetBuddyInt (HWND hwnd)
237{
238 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
239 char txt1[20], sep;
240 int len;
241
242 if (!IsWindow(infoPtr->Buddy))
243 return FALSE;
244
245// TRACE(updown, "set new value(%d) to buddy.\n",
246// infoPtr->CurVal);
247
248 /*if the buddy is a list window, we must set curr index */
249 if(!lstrcmpA (infoPtr->szBuddyClass, "ListBox")){
250 SendMessageA(infoPtr->Buddy, LB_SETCURSEL, infoPtr->CurVal, 0);
251 }
252 else{ /* Regular window, so set caption to the number */
253 len = sprintf(txt1, (infoPtr->Base==16) ? "%X" : "%d", infoPtr->CurVal);
254
255 sep = UPDOWN_GetThousandSep();
256
257 /* Do thousands seperation if necessary */
258 if (!(GetWindowLongA (hwnd, GWL_STYLE) & UDS_NOTHOUSANDS) && (len > 3)) {
259 char txt2[20], *src = txt1, *dst = txt2;
260 if(len%3 > 0){
261 lstrcpynA (dst, src, len%3 + 1); /* need to include the null */
262 dst += len%3;
263 src += len%3;
264 }
265 for(len=0; *src; len++){
266 if(len%3==0)
267 *dst++ = sep;
268 *dst++ = *src++;
269 }
270 *dst = 0; /* null terminate it */
271 strcpy(txt1, txt2); /* move it to the proper place */
272 }
273 SetWindowTextA(infoPtr->Buddy, txt1);
274 }
275
276 return TRUE;
277}
278
279/***********************************************************************
280 * UPDOWN_Draw [Internal]
281 *
282 * Draw the arrows. The background need not be erased.
283 */
284static void UPDOWN_Draw (HWND hwnd, HDC hdc)
285{
286 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
287 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
288 BOOL prssed;
289 RECT rect;
290
291 /* Draw the incr button */
292 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
293 prssed = (infoPtr->Flags & FLAG_INCR) && (infoPtr->Flags & FLAG_MOUSEIN);
294 DrawFrameControl(hdc, &rect, DFC_SCROLL,
295 (dwStyle & UDS_HORZ ? DFCS_SCROLLLEFT : DFCS_SCROLLUP) |
296 (prssed ? DFCS_PUSHED : 0) |
297 (dwStyle&WS_DISABLED ? DFCS_INACTIVE : 0) );
298
299 /* Draw the space between the buttons */
300 rect.top = rect.bottom; rect.bottom++;
301 DrawEdge(hdc, &rect, 0, BF_MIDDLE);
302
303 /* Draw the decr button */
304 UPDOWN_GetArrowRect(hwnd, &rect, FALSE);
305 prssed = (infoPtr->Flags & FLAG_DECR) && (infoPtr->Flags & FLAG_MOUSEIN);
306 DrawFrameControl(hdc, &rect, DFC_SCROLL,
307 (dwStyle & UDS_HORZ ? DFCS_SCROLLRIGHT : DFCS_SCROLLDOWN) |
308 (prssed ? DFCS_PUSHED : 0) |
309 (dwStyle & WS_DISABLED ? DFCS_INACTIVE : 0) );
310}
311
312/***********************************************************************
313 * UPDOWN_Refresh [Internal]
314 *
315 * Synchronous drawing (must NOT be used in WM_PAINT).
316 * Calls UPDOWN_Draw.
317 */
318static void UPDOWN_Refresh (HWND hwnd)
319{
320 HDC hdc;
321
322 hdc = GetDC (hwnd);
323 UPDOWN_Draw (hwnd, hdc);
324 ReleaseDC (hwnd, hdc);
325}
326
327
328/***********************************************************************
329 * UPDOWN_Paint [Internal]
330 *
331 * Asynchronous drawing (must ONLY be used in WM_PAINT).
332 * Calls UPDOWN_Draw.
333 */
334static void UPDOWN_Paint (HWND hwnd)
335{
336 PAINTSTRUCT ps;
337 HDC hdc;
338
339 hdc = BeginPaint (hwnd, &ps);
340 UPDOWN_Draw (hwnd, hdc);
341 EndPaint (hwnd, &ps);
342}
343
344/***********************************************************************
345 * UPDOWN_SetBuddy
346 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE.
347 * Else, sets it as a new Buddy.
348 * Then, it should subclass the buddy
349 * If window has the UDS_ARROWKEYS, it subcalsses the buddy window to
350 * process the UP/DOWN arrow keys.
351 * If window has the UDS_ALIGNLEFT or UDS_ALIGNRIGHT style
352 * the size/pos of the buddy and the control are adjusted accordingly.
353 */
354static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)
355{
356 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
357 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
358 RECT budRect; /* new coord for the buddy */
359 int x; /* new x position and width for the up-down */
360
361 *infoPtr->szBuddyClass = '\0';
362
363 /* Is is a valid bud? */
364 if(!IsWindow(hwndBud))
365 return FALSE;
366
367 /* Store buddy window clas name */
368 GetClassNameA (hwndBud, infoPtr->szBuddyClass, 40);
369
370 if(dwStyle & UDS_ARROWKEYS){
371// FIXME(updown, "we need to subclass the buddy to process the arrow keys.\n");
372 }
373
374 /* do we need to do any adjustments? */
375 if(!(dwStyle & (UDS_ALIGNLEFT | UDS_ALIGNRIGHT)))
376 return TRUE;
377
378 infoPtr->Buddy = hwndBud;
379
380 /* Get the rect of the buddy relative to its parent */
381 GetWindowRect(infoPtr->Buddy, &budRect);
382 MapWindowPoints(HWND_DESKTOP, GetParent(infoPtr->Buddy),
383 (POINT *)(&budRect.left), 2);
384
385 /* now do the positioning */
386 if(dwStyle & UDS_ALIGNRIGHT){
387 budRect.right -= DEFAULT_WIDTH+DEFAULT_XSEP;
388 x = budRect.right+DEFAULT_XSEP;
389 }
390 else{ /* UDS_ALIGNLEFT */
391 x = budRect.left;
392 budRect.left += DEFAULT_WIDTH+DEFAULT_XSEP;
393 }
394
395 /* first adjust the buddy to accomodate the up/down */
396 SetWindowPos(infoPtr->Buddy, 0, budRect.left, budRect.top,
397 budRect.right - budRect.left, budRect.bottom - budRect.top,
398 SWP_NOACTIVATE|SWP_NOZORDER);
399
400 /* now position the up/down */
401 /* Since the UDS_ALIGN* flags were used, */
402 /* we will pick the position and size of the window. */
403
404 SetWindowPos (hwnd, 0, x, budRect.top-DEFAULT_ADDTOP,DEFAULT_WIDTH,
405 (budRect.bottom-budRect.top)+DEFAULT_ADDTOP+DEFAULT_ADDBOT,
406 SWP_NOACTIVATE|SWP_NOZORDER);
407
408 return TRUE;
409}
410
411/***********************************************************************
412 * UPDOWN_DoAction
413 *
414 * This function increments/decrements the CurVal by the
415 * 'delta' amount according to the 'incr' flag
416 * It notifies the parent as required.
417 * It handles wraping and non-wraping correctly.
418 * It is assumed that delta>0
419 */
420static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr)
421{
422 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
423 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
424 int old_val = infoPtr->CurVal;
425 NM_UPDOWN ni;
426
427// TRACE(updown, "%s by %d\n", incr ? "inc" : "dec", delta);
428
429 /* check if we can do the modification first */
430 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1);
431 if(!UPDOWN_OffsetVal (hwnd, delta))
432 return;
433
434 /* so, if we can do the change, recompute delta and restore old value */
435 delta = infoPtr->CurVal - old_val;
436 infoPtr->CurVal = old_val;
437
438 /* We must notify parent now to obtain permission */
439 ni.iPos = infoPtr->CurVal;
440 ni.iDelta = delta;
441 ni.hdr.hwndFrom = hwnd;
442 ni.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
443 ni.hdr.code = UDN_DELTAPOS;
444 if (SendMessageA(GetParent (hwnd), WM_NOTIFY,
445 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))
446 return; /* we are not allowed to change */
447
448 /* Now adjust value with (maybe new) delta */
449 if (!UPDOWN_OffsetVal (hwnd, ni.iDelta))
450 return;
451
452 /* Now take care about our buddy */
453 if(!IsWindow(infoPtr->Buddy))
454 return; /* Nothing else to do */
455
456
457 if (dwStyle & UDS_SETBUDDYINT)
458 UPDOWN_SetBuddyInt (hwnd);
459
460 /* Also, notify it */
461 /* FIXME: do we need to send the notification only if
462 we do not have the UDS_SETBUDDYINT style set? */
463
464 SendMessageA (GetParent (hwnd),
465 dwStyle & UDS_HORZ ? WM_HSCROLL : WM_VSCROLL,
466 MAKELONG(incr ? SB_LINEUP : SB_LINEDOWN, infoPtr->CurVal),
467 hwnd);
468}
469
470/***********************************************************************
471 * UPDOWN_IsEnabled
472 *
473 * Returns TRUE if it is enabled as well as its buddy (if any)
474 * FALSE otherwise
475 */
476static BOOL UPDOWN_IsEnabled (HWND hwnd)
477{
478 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
479
480 if(GetWindowLongA (hwnd, GWL_STYLE) & WS_DISABLED)
481 return FALSE;
482 return IsWindowEnabled(infoPtr->Buddy);
483}
484
485/***********************************************************************
486 * UPDOWN_CancelMode
487 *
488 * Deletes any timers, releases the mouse and does redraw if necessary.
489 * If the control is not in "capture" mode, it does nothing.
490 * If the control was not in cancel mode, it returns FALSE.
491 * If the control was in cancel mode, it returns TRUE.
492 */
493static BOOL UPDOWN_CancelMode (HWND hwnd)
494{
495 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
496
497 /* if not in 'capture' mode, do nothing */
498 if(!(infoPtr->Flags & FLAG_CLICKED))
499 return FALSE;
500
501 KillTimer (hwnd, TIMERID1); /* kill all possible timers */
502 KillTimer (hwnd, TIMERID2);
503
504 if (GetCapture() == hwnd) /* let the mouse go */
505 ReleaseCapture(); /* if we still have it */
506
507 infoPtr->Flags = 0; /* get rid of any flags */
508 UPDOWN_Refresh (hwnd); /* redraw the control just in case */
509
510 return TRUE;
511}
512
513/***********************************************************************
514 * UPDOWN_HandleMouseEvent
515 *
516 * Handle a mouse event for the updown.
517 * 'pt' is the location of the mouse event in client or
518 * windows coordinates.
519 */
520static void UPDOWN_HandleMouseEvent (HWND hwnd, UINT msg, POINT pt)
521{
522 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
523 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
524 RECT rect;
525 int temp;
526
527 switch(msg)
528 {
529 case WM_LBUTTONDOWN: /* Initialise mouse tracking */
530 /* If we are already in the 'clicked' mode, then nothing to do */
531 if(infoPtr->Flags & FLAG_CLICKED)
532 return;
533
534 /* If the buddy is an edit, will set focus to it */
535 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
536 SetFocus(infoPtr->Buddy);
537
538 /* Now see which one is the 'active' arrow */
539 temp = UPDOWN_GetArrowFromPoint (hwnd, &rect, pt);
540
541 /* Update the CurVal if necessary */
542 if (dwStyle & UDS_SETBUDDYINT)
543 UPDOWN_GetBuddyInt (hwnd);
544
545 /* Before we proceed, see if we can spin... */
546 if(!(dwStyle & UDS_WRAP))
547 if(( temp && infoPtr->CurVal==infoPtr->MaxVal) ||
548 (!temp && infoPtr->CurVal==infoPtr->MinVal))
549 return;
550
551 /* Set up the correct flags */
552 infoPtr->Flags = 0;
553 infoPtr->Flags |= temp ? FLAG_INCR : FLAG_DECR;
554 infoPtr->Flags |= FLAG_MOUSEIN;
555
556 /* repaint the control */
557 UPDOWN_Refresh (hwnd);
558
559 /* process the click */
560 UPDOWN_DoAction (hwnd, 1, infoPtr->Flags & FLAG_INCR);
561
562 /* now capture all mouse messages */
563 SetCapture (hwnd);
564
565 /* and startup the first timer */
566 SetTimer(hwnd, TIMERID1, INITIAL_DELAY, 0);
567 break;
568
569 case WM_MOUSEMOVE:
570 /* If we are not in the 'clicked' mode, then nothing to do */
571 if(!(infoPtr->Flags & FLAG_CLICKED))
572 return;
573
574 /* save the flags to see if any got modified */
575 temp = infoPtr->Flags;
576
577 /* Now get the 'active' arrow rectangle */
578 if (infoPtr->Flags & FLAG_INCR)
579 UPDOWN_GetArrowRect (hwnd, &rect, TRUE);
580 else
581 UPDOWN_GetArrowRect (hwnd, &rect, FALSE);
582
583 /* Update the flags if we are in/out */
584 if(PtInRect(&rect, pt))
585 infoPtr->Flags |= FLAG_MOUSEIN;
586 else{
587 infoPtr->Flags &= ~FLAG_MOUSEIN;
588 if(accelIndex != -1) /* if we have accel info */
589 accelIndex = 0; /* reset it */
590 }
591 /* If state changed, redraw the control */
592 if(temp != infoPtr->Flags)
593 UPDOWN_Refresh (hwnd);
594 break;
595
596 default:
597// ERR(updown, "Impossible case!\n");
598 break;
599 }
600
601}
602
603/***********************************************************************
604 * UpDownWndProc
605 */
606LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam,
607 LPARAM lParam)
608{
609 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);
610 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
611 int temp;
612
613 switch(message)
614 {
615 case WM_NCCREATE:
616 /* get rid of border, if any */
617 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER);
618 return TRUE;
619
620 case WM_CREATE:
621 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc (sizeof(UPDOWN_INFO));
622 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
623
624 /* initialize the info struct */
625 infoPtr->AccelCount=0; infoPtr->AccelVect=0;
626 infoPtr->CurVal=0; infoPtr->MinVal=0; infoPtr->MaxVal=100; /*FIXME*/
627 infoPtr->Base = 10; /* Default to base 10 */
628 infoPtr->Buddy = 0; /* No buddy window yet */
629 infoPtr->Flags = 0; /* And no flags */
630
631 /* Do we pick the buddy win ourselves? */
632 if (dwStyle & UDS_AUTOBUDDY)
633 UPDOWN_SetBuddy (hwnd, GetWindow (hwnd, GW_HWNDPREV));
634
635// TRACE(updown, "UpDown Ctrl creation, hwnd=%04x\n", hwnd);
636 break;
637
638 case WM_DESTROY:
639 if(infoPtr->AccelVect)
640 COMCTL32_Free (infoPtr->AccelVect);
641
642 COMCTL32_Free (infoPtr);
643
644// TRACE(updown, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd);
645 break;
646
647 case WM_ENABLE:
648 if (dwStyle & WS_DISABLED)
649 UPDOWN_CancelMode (hwnd);
650 UPDOWN_Paint (hwnd);
651 break;
652
653 case WM_TIMER:
654 /* if initial timer, kill it and start the repeat timer */
655 if(wParam == TIMERID1){
656 KillTimer(hwnd, TIMERID1);
657 /* if no accel info given, used default timer */
658 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0){
659 accelIndex = -1;
660 temp = REPEAT_DELAY;
661 }
662 else{
663 accelIndex = 0; /* otherwise, use it */
664 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
665 }
666 SetTimer(hwnd, TIMERID2, temp, 0);
667 }
668
669 /* now, if the mouse is above us, do the thing...*/
670 if(infoPtr->Flags & FLAG_MOUSEIN){
671 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc;
672 UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR);
673
674 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1){
675 KillTimer(hwnd, TIMERID2);
676 accelIndex++; /* move to the next accel info */
677 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1;
678 /* make sure we have at least 1ms intervals */
679 SetTimer(hwnd, TIMERID2, temp, 0);
680 }
681 }
682 break;
683
684 case WM_CANCELMODE:
685 UPDOWN_CancelMode (hwnd);
686 break;
687
688 case WM_LBUTTONUP:
689 if(!UPDOWN_CancelMode(hwnd))
690 break;
691 /*If we released the mouse and our buddy is an edit */
692 /* we must select all text in it. */
693 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit"))
694 SendMessageA(infoPtr->Buddy, EM_SETSEL, 0, MAKELONG(0, -1));
695 break;
696
697 case WM_LBUTTONDOWN:
698 case WM_MOUSEMOVE:
699 if(UPDOWN_IsEnabled(hwnd)){
700 POINT pt;
701 CONV_POINT16TO32( (POINT16 *)&lParam, &pt );
702 UPDOWN_HandleMouseEvent (hwnd, message, pt );
703 }
704 break;
705
706 case WM_KEYDOWN:
707 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd)){
708 switch(wParam){
709 case VK_UP:
710 case VK_DOWN:
711 UPDOWN_GetBuddyInt (hwnd);
712 UPDOWN_DoAction (hwnd, 1, wParam==VK_UP);
713 break;
714 }
715 }
716 break;
717
718 case WM_PAINT:
719 UPDOWN_Paint (hwnd);
720 break;
721
722 case UDM_GETACCEL:
723 if (wParam==0 && lParam==0) /*if both zero, */
724 return infoPtr->AccelCount; /*just return the accel count*/
725 if (wParam || lParam){
726 UNKNOWN_PARAM(UDM_GETACCEL, wParam, lParam);
727 return 0;
728 }
729 temp = MIN(infoPtr->AccelCount, wParam);
730 memcpy((void *)lParam, infoPtr->AccelVect, temp*sizeof(UDACCEL));
731 return temp;
732
733 case UDM_SETACCEL:
734// TRACE(updown, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd);
735 if(infoPtr->AccelVect){
736 COMCTL32_Free (infoPtr->AccelVect);
737 infoPtr->AccelCount = 0;
738 infoPtr->AccelVect = 0;
739 }
740 if(wParam==0)
741 return TRUE;
742 infoPtr->AccelVect = COMCTL32_Alloc (wParam*sizeof(UDACCEL));
743 if(infoPtr->AccelVect==0)
744 return FALSE;
745 memcpy(infoPtr->AccelVect, (void*)lParam, wParam*sizeof(UDACCEL));
746 return TRUE;
747
748 case UDM_GETBASE:
749 if (wParam || lParam)
750 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam);
751 return infoPtr->Base;
752
753 case UDM_SETBASE:
754// TRACE(updown, "UpDown Ctrl new base(%d), hwnd=%04x\n",
755// wParam, hwnd);
756 if ( !(wParam==10 || wParam==16) || lParam)
757 UNKNOWN_PARAM(UDM_SETBASE, wParam, lParam);
758 if (wParam==10 || wParam==16){
759 temp = infoPtr->Base;
760 infoPtr->Base = wParam;
761 return temp; /* return the prev base */
762 }
763 break;
764
765 case UDM_GETBUDDY:
766 if (wParam || lParam)
767 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam);
768 return infoPtr->Buddy;
769
770 case UDM_SETBUDDY:
771 if (lParam)
772 UNKNOWN_PARAM(UDM_SETBUDDY, wParam, lParam);
773 temp = infoPtr->Buddy;
774 infoPtr->Buddy = wParam;
775 UPDOWN_SetBuddy (hwnd, wParam);
776// TRACE(updown, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n",
777// infoPtr->Buddy, hwnd);
778 return temp;
779
780 case UDM_GETPOS:
781 if (wParam || lParam)
782 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
783 temp = UPDOWN_GetBuddyInt (hwnd);
784 return MAKELONG(infoPtr->CurVal, temp ? 0 : 1);
785
786 case UDM_SETPOS:
787 if (wParam || HIWORD(lParam))
788 UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam);
789 temp = SLOWORD(lParam);
790// TRACE(updown, "UpDown Ctrl new value(%d), hwnd=%04x\n",
791// temp, hwnd);
792 if(!UPDOWN_InBounds(hwnd, temp)){
793 if(temp < infoPtr->MinVal)
794 temp = infoPtr->MinVal;
795 if(temp > infoPtr->MaxVal)
796 temp = infoPtr->MaxVal;
797 }
798 wParam = infoPtr->CurVal; /* save prev value */
799 infoPtr->CurVal = temp; /* set the new value */
800 if(dwStyle & UDS_SETBUDDYINT)
801 UPDOWN_SetBuddyInt (hwnd);
802 return wParam; /* return prev value */
803
804 case UDM_GETRANGE:
805 if (wParam || lParam)
806 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam);
807 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal);
808
809 case UDM_SETRANGE:
810 if (wParam)
811 UNKNOWN_PARAM(UDM_SETRANGE, wParam, lParam); /* we must have: */
812 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */
813 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */
814 /* |Max-Min| <= UD_MAXVAL */
815// TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
816// infoPtr->MinVal, infoPtr->MaxVal, hwnd);
817 break;
818
819 case UDM_GETRANGE32:
820 if (wParam)
821 *(LPINT)wParam = infoPtr->MinVal;
822 if (lParam)
823 *(LPINT)lParam = infoPtr->MaxVal;
824 break;
825
826 case UDM_SETRANGE32:
827 infoPtr->MinVal = (INT)wParam;
828 infoPtr->MaxVal = (INT)lParam;
829 if (infoPtr->MaxVal <= infoPtr->MinVal)
830 infoPtr->MaxVal = infoPtr->MinVal + 1;
831// TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n",
832// infoPtr->MinVal, infoPtr->MaxVal, hwnd);
833 break;
834
835 default:
836// if (message >= WM_USER)
837// ERR (updown, "unknown msg %04x wp=%04x lp=%08lx\n",
838// message, wParam, lParam);
839 return DefWindowProcA (hwnd, message, wParam, lParam);
840 }
841
842 return 0;
843}
844
845
846/***********************************************************************
847 * UPDOWN_Register [Internal]
848 *
849 * Registers the updown window class.
850 */
851
852VOID
853UPDOWN_Register(void)
854{
855 WNDCLASSA wndClass;
856
857 if( GlobalFindAtomA( UPDOWN_CLASSA ) ) return;
858
859 ZeroMemory( &wndClass, sizeof( WNDCLASSA ) );
860 wndClass.style = CS_GLOBALCLASS | CS_VREDRAW;
861 wndClass.lpfnWndProc = (WNDPROC)UpDownWindowProc;
862 wndClass.cbClsExtra = 0;
863 wndClass.cbWndExtra = sizeof(UPDOWN_INFO*);
864 wndClass.hCursor = LoadCursorA( 0, IDC_ARROWA );
865 wndClass.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
866 wndClass.lpszClassName = UPDOWN_CLASSA;
867
868 RegisterClassA( &wndClass );
869}
870
871
872/***********************************************************************
873 * UPDOWN_Unregister [Internal]
874 *
875 * Unregisters the updown window class.
876 */
877
878VOID
879UPDOWN_Unregister (VOID)
880{
881 if (GlobalFindAtomA (UPDOWN_CLASSA))
882 UnregisterClassA (UPDOWN_CLASSA, (HINSTANCE)NULL);
883}
884
Note: See TracBrowser for help on using the repository browser.