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

Last change on this file since 91 was 60, checked in by achimha, 26 years ago

* empty log message *

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