Changeset 180 for trunk/src/comctl32/updown.c
- Timestamp:
- Jun 24, 1999, 6:37:46 PM (26 years ago)
- File:
-
- 1 edited
-
trunk/src/comctl32/updown.c (modified) (23 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/comctl32/updown.c
r110 r180 1 /* $Id: updown.c,v 1. 4 1999-06-16 20:25:45cbratschi Exp $ */1 /* $Id: updown.c,v 1.5 1999-06-24 16:37:46 cbratschi Exp $ */ 2 2 /* 3 3 * Updown control … … 8 8 * 9 9 * TODO: 10 * - subclass the buddy window (in UPDOWN_SetBuddy ) to process the10 * - subclass the buddy window (in UPDOWN_SetBuddyHandle) to process the 11 11 * arrow keys 12 12 * - I am not sure about the default values for the Min, Max, Pos … … 33 33 */ 34 34 35 /* CB: Odin32 problems 36 - Open32 doesn't look for CS_DBLCLKS -> double clicks always sent 37 */ 38 35 39 #include <stdlib.h> 36 40 #include <stdio.h> … … 71 75 #define UNKNOWN_PARAM(msg, wParam, lParam) 72 76 73 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA (hwnd,0))77 #define UPDOWN_GetInfoPtr(hwnd) ((UPDOWN_INFO *)GetWindowLongA(hwnd,0)) 74 78 75 79 … … 128 132 GetClientRect (hwnd, rect); 129 133 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; 134 if (GetWindowLongA(hwnd, GWL_STYLE) & UDS_HORZ) 135 { 136 len = rect->right-rect->left; /* compute the width */ 137 if (incr) rect->left = len/2+1; 138 else rect->right = len/2; 139 } else 140 { 141 len = rect->bottom-rect->top; /* compute the height */ 142 if (incr) rect->bottom = len/2; 143 else rect->top = len/2+1; 143 144 } 144 145 } … … 191 192 int newVal; 192 193 193 if (!IsWindow(infoPtr->Buddy)) 194 return FALSE; 194 if (!IsWindow(infoPtr->Buddy)) return FALSE; 195 195 196 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{197 if (!lstrcmpA(infoPtr->szBuddyClass,"ListBox")) 198 { 199 newVal = SendMessageA(infoPtr->Buddy,LB_GETCARETINDEX,0,0); 200 if(newVal < 0) return FALSE; 201 } else 202 { 203 203 /* we have a regular window, so will get the text */ 204 if (!GetWindowTextA(infoPtr->Buddy, txt, sizeof(txt))) 205 return FALSE; 204 if (!GetWindowTextA(infoPtr->Buddy,txt,sizeof(txt))) return FALSE; 206 205 207 206 sep = UPDOWN_GetThousandSep(); 208 207 209 208 /* now get rid of the separators */ 210 for(src = dst = txt; *src;src++)211 if (*src != sep)209 for(src = dst = txt;*src;src++) 210 if (*src != sep) 212 211 *dst++ = *src; 213 212 *dst = 0; 214 213 215 214 /* 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; 215 newVal = strtol(txt,&src,infoPtr->Base); 216 if (*src || !UPDOWN_InBounds(hwnd,newVal)) return FALSE; 219 217 220 218 // TRACE(updown, "new value(%d) read from buddy (old=%d)\n", … … 223 221 224 222 infoPtr->CurVal = newVal; 223 225 224 return TRUE; 226 225 } … … 236 235 static BOOL UPDOWN_SetBuddyInt (HWND hwnd) 237 236 { 238 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);239 char txt1[20], sep;237 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 238 char txt1[20],sep; 240 239 int len; 241 240 242 if (!IsWindow(infoPtr->Buddy)) 243 return FALSE; 241 if (!IsWindow(infoPtr->Buddy)) return FALSE; 244 242 245 243 // TRACE(updown, "set new value(%d) to buddy.\n", … … 247 245 248 246 /*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); 247 if(!lstrcmpA(infoPtr->szBuddyClass, "ListBox")) 248 { 249 SendMessageA(infoPtr->Buddy,LB_SETCURSEL,infoPtr->CurVal,0); 250 } else 251 { /* Regular window, so set caption to the number */ 252 len = sprintf(txt1,(infoPtr->Base == 16) ? "%X" : "%d",infoPtr->CurVal); 254 253 255 254 sep = UPDOWN_GetThousandSep(); … … 282 281 * Draw the arrows. The background need not be erased. 283 282 */ 284 static void UPDOWN_Draw (HWND hwnd,HDC hdc)285 { 286 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);287 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);283 static void UPDOWN_Draw(HWND hwnd,HDC hdc) 284 { 285 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 286 DWORD dwStyle = GetWindowLongA(hwnd, GWL_STYLE); 288 287 BOOL prssed; 289 288 RECT rect; … … 298 297 299 298 /* Draw the space between the buttons */ 300 rect.top = rect.bottom; rect.bottom++; 299 rect.top = rect.bottom; 300 rect.bottom++; 301 301 DrawEdge(hdc, &rect, 0, BF_MIDDLE); 302 302 … … 343 343 344 344 /*********************************************************************** 345 * UPDOWN_SetBuddy 345 * UPDOWN_SetBuddyHandle 346 346 * Tests if 'hwndBud' is a valid window handle. If not, returns FALSE. 347 347 * Else, sets it as a new Buddy. … … 352 352 * the size/pos of the buddy and the control are adjusted accordingly. 353 353 */ 354 static BOOL UPDOWN_SetBuddy (HWND hwnd, HWND hwndBud)354 static BOOL UPDOWN_SetBuddyHandle (HWND hwnd, HWND hwndBud) 355 355 { 356 356 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd); … … 420 420 static void UPDOWN_DoAction (HWND hwnd, int delta, BOOL incr) 421 421 { 422 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);423 DWORD dwStyle = GetWindowLongA (hwnd,GWL_STYLE);422 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 423 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 424 424 int old_val = infoPtr->CurVal; 425 425 NM_UPDOWN ni; … … 429 429 /* check if we can do the modification first */ 430 430 delta *= (incr ? 1 : -1) * (infoPtr->MaxVal < infoPtr->MinVal ? -1 : 1); 431 if(!UPDOWN_OffsetVal (hwnd, delta)) 432 return; 431 if(!UPDOWN_OffsetVal(hwnd,delta)) return; 433 432 434 433 /* so, if we can do the change, recompute delta and restore old value */ 435 delta = infoPtr->CurVal -old_val;434 delta = infoPtr->CurVal-old_val; 436 435 infoPtr->CurVal = old_val; 437 436 … … 440 439 ni.iDelta = delta; 441 440 ni.hdr.hwndFrom = hwnd; 442 ni.hdr.idFrom = GetWindowLongA (hwnd,GWL_ID);441 ni.hdr.idFrom = GetWindowLongA(hwnd,GWL_ID); 443 442 ni.hdr.code = UDN_DELTAPOS; 444 if (SendMessageA(GetParent (hwnd),WM_NOTIFY,445 (WPARAM)ni.hdr.idFrom, (LPARAM)&ni))443 if (SendMessageA(GetParent(hwnd),WM_NOTIFY, 444 (WPARAM)ni.hdr.idFrom,(LPARAM)&ni)) 446 445 return; /* we are not allowed to change */ 447 446 448 447 /* Now adjust value with (maybe new) delta */ 449 if (!UPDOWN_OffsetVal (hwnd, ni.iDelta)) 450 return; 448 if (!UPDOWN_OffsetVal (hwnd,ni.iDelta)) return; 451 449 452 450 /* Now take care about our buddy */ … … 455 453 456 454 457 if (dwStyle & UDS_SETBUDDYINT) 458 UPDOWN_SetBuddyInt (hwnd); 455 if (dwStyle & UDS_SETBUDDYINT) UPDOWN_SetBuddyInt(hwnd); 459 456 460 457 /* Also, notify it */ … … 529 526 case WM_LBUTTONDOWN: /* Initialise mouse tracking */ 530 527 /* If we are already in the 'clicked' mode, then nothing to do */ 531 if(infoPtr->Flags & FLAG_CLICKED) 532 return; 528 if (infoPtr->Flags & FLAG_CLICKED) return; 533 529 534 530 /* If the buddy is an edit, will set focus to it */ 535 if (!lstrcmpA (infoPtr->szBuddyClass, "Edit")) 536 SetFocus(infoPtr->Buddy); 531 if (!lstrcmpA(infoPtr->szBuddyClass,"Edit")) SetFocus(infoPtr->Buddy); 537 532 538 533 /* Now see which one is the 'active' arrow */ 539 temp = UPDOWN_GetArrowFromPoint (hwnd, &rect,pt);534 temp = UPDOWN_GetArrowFromPoint(hwnd,&rect,pt); 540 535 541 536 /* Update the CurVal if necessary */ 542 if (dwStyle & UDS_SETBUDDYINT) 543 UPDOWN_GetBuddyInt (hwnd); 537 if (dwStyle & UDS_SETBUDDYINT) UPDOWN_GetBuddyInt(hwnd); 544 538 545 539 /* 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))540 if (!(dwStyle & UDS_WRAP)) 541 if ((temp && infoPtr->CurVal == infoPtr->MaxVal) || 542 (!temp && infoPtr->CurVal == infoPtr->MinVal)) 549 543 return; 550 544 … … 558 552 559 553 /* process the click */ 560 UPDOWN_DoAction (hwnd, 1,infoPtr->Flags & FLAG_INCR);554 UPDOWN_DoAction (hwnd,1,infoPtr->Flags & FLAG_INCR); 561 555 562 556 /* now capture all mouse messages */ … … 564 558 565 559 /* and startup the first timer */ 566 SetTimer(hwnd, TIMERID1, INITIAL_DELAY,0);560 SetTimer(hwnd,TIMERID1,INITIAL_DELAY,0); 567 561 break; 568 562 569 563 case WM_MOUSEMOVE: 570 564 /* If we are not in the 'clicked' mode, then nothing to do */ 571 if(!(infoPtr->Flags & FLAG_CLICKED)) 572 return; 565 if (!(infoPtr->Flags & FLAG_CLICKED)) return; 573 566 574 567 /* save the flags to see if any got modified */ … … 601 594 } 602 595 596 //Message handling 597 598 static LRESULT UPDOWN_NCCreate(HWND hwnd,WPARAM wParam,LPARAM lParam) 599 { 600 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 601 602 /* get rid of border, if any */ 603 SetWindowLongA(hwnd,GWL_STYLE,dwStyle & ~WS_BORDER); 604 return TRUE; 605 } 606 607 static LRESULT UPDOWN_Create(HWND hwnd,WPARAM wParam,LPARAM lParam) 608 { 609 UPDOWN_INFO *infoPtr; 610 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 611 612 infoPtr = (UPDOWN_INFO*)COMCTL32_Alloc(sizeof(UPDOWN_INFO)); 613 SetWindowLongA (hwnd, 0, (DWORD)infoPtr); 614 615 /* initialize the info struct */ 616 infoPtr->AccelCount = 0; 617 infoPtr->AccelVect = 0; 618 infoPtr->CurVal = 0; 619 infoPtr->MinVal = 0; 620 infoPtr->MaxVal = 100; /*FIXME*/ 621 infoPtr->Base = 10; /* Default to base 10 */ 622 infoPtr->Buddy = 0; /* No buddy window yet */ 623 infoPtr->Flags = 0; /* And no flags */ 624 625 /* Do we pick the buddy win ourselves? */ 626 if (dwStyle & UDS_AUTOBUDDY) UPDOWN_SetBuddyHandle(hwnd,GetWindow(hwnd,GW_HWNDPREV)); 627 628 // TRACE(updown, "UpDown Ctrl creation, hwnd=%04x\n", hwnd); 629 630 return 0; 631 } 632 633 static LRESULT UPDOWN_Destroy(HWND hwnd,WPARAM wParam,LPARAM lParam) 634 { 635 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 636 637 if(infoPtr->AccelVect) COMCTL32_Free(infoPtr->AccelVect); 638 639 COMCTL32_Free (infoPtr); 640 641 // TRACE(updown, "UpDown Ctrl destruction, hwnd=%04x\n", hwnd); 642 643 return 0; 644 } 645 646 static LRESULT UPDOWN_Enable(HWND hwnd,WPARAM wParam,LPARAM lParam) 647 { 648 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 649 650 if (dwStyle & WS_DISABLED) UPDOWN_CancelMode(hwnd); 651 UPDOWN_Paint(hwnd); 652 653 return 0; 654 } 655 656 static LRESULT UPDOWN_Timer(HWND hwnd,WPARAM wParam,LPARAM lParam) 657 { 658 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 659 int temp; 660 661 /* if initial timer, kill it and start the repeat timer */ 662 if(wParam == TIMERID1) 663 { 664 KillTimer(hwnd, TIMERID1); 665 /* if no accel info given, used default timer */ 666 if(infoPtr->AccelCount==0 || infoPtr->AccelVect==0) 667 { 668 accelIndex = -1; 669 temp = REPEAT_DELAY; 670 } else 671 { 672 accelIndex = 0; /* otherwise, use it */ 673 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1; 674 } 675 SetTimer(hwnd, TIMERID2, temp, 0); 676 } 677 678 /* now, if the mouse is above us, do the thing...*/ 679 if(infoPtr->Flags & FLAG_MOUSEIN) 680 { 681 temp = accelIndex==-1 ? 1 : infoPtr->AccelVect[accelIndex].nInc; 682 UPDOWN_DoAction(hwnd, temp, infoPtr->Flags & FLAG_INCR); 683 684 if(accelIndex!=-1 && accelIndex < infoPtr->AccelCount-1) 685 { 686 KillTimer(hwnd, TIMERID2); 687 accelIndex++; /* move to the next accel info */ 688 temp = infoPtr->AccelVect[accelIndex].nSec * 1000 + 1; 689 /* make sure we have at least 1ms intervals */ 690 SetTimer(hwnd, TIMERID2, temp, 0); 691 } 692 } 693 694 return 0; 695 } 696 697 static LRESULT UPDOWN_LButtonUp(HWND hwnd,WPARAM wParam,LPARAM lParam) 698 { 699 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 700 701 if (!UPDOWN_CancelMode(hwnd)) return 0; 702 /*If we released the mouse and our buddy is an edit */ 703 /* we must select all text in it. */ 704 if (!lstrcmpA(infoPtr->szBuddyClass,"Edit")) 705 SendMessageA(infoPtr->Buddy,EM_SETSEL,0,MAKELONG(0,-1)); 706 707 return 0; 708 } 709 710 static LRESULT UPDOWN_KeyDown(HWND hwnd,WPARAM wParam,LPARAM lParam) 711 { 712 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 713 714 if((dwStyle & UDS_ARROWKEYS) && UPDOWN_IsEnabled(hwnd)) 715 { 716 switch(wParam) 717 { 718 case VK_UP: 719 case VK_DOWN: 720 UPDOWN_GetBuddyInt (hwnd); 721 UPDOWN_DoAction (hwnd, 1, wParam==VK_UP); 722 break; 723 } 724 } 725 726 return 0; 727 } 728 729 static LRESULT UPDOWN_GetAccel(HWND hwnd,WPARAM wParam,LPARAM lParam) 730 { 731 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 732 INT temp; 733 734 if (wParam == 0 && lParam == 0) /*if both zero, */ 735 return infoPtr->AccelCount; /*just return the accel count*/ 736 if (wParam || lParam) 737 { 738 UNKNOWN_PARAM(UDM_GETACCEL,wParam,lParam); 739 return 0; 740 } 741 temp = MIN(infoPtr->AccelCount,wParam); 742 memcpy((void *)lParam,infoPtr->AccelVect,temp*sizeof(UDACCEL)); 743 744 return temp; 745 } 746 747 static LRESULT UPDOWN_SetAccel(HWND hwnd,WPARAM wParam,LPARAM lParam) 748 { 749 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 750 751 // TRACE(updown, "UpDown Ctrl new accel info, hwnd=%04x\n", hwnd); 752 if(infoPtr->AccelVect) 753 { 754 COMCTL32_Free(infoPtr->AccelVect); 755 infoPtr->AccelCount = 0; 756 infoPtr->AccelVect = 0; 757 } 758 if(wParam == 0) return TRUE; 759 infoPtr->AccelVect = COMCTL32_Alloc(wParam*sizeof(UDACCEL)); 760 if(infoPtr->AccelVect == 0) return FALSE; 761 memcpy(infoPtr->AccelVect,(void*)lParam,wParam*sizeof(UDACCEL)); 762 763 return TRUE; 764 } 765 766 static LRESULT UPDOWN_GetBase(HWND hwnd,WPARAM wParam,LPARAM lParam) 767 { 768 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 769 770 if (wParam || lParam) UNKNOWN_PARAM(UDM_GETBASE,wParam,lParam); 771 772 return infoPtr->Base; 773 } 774 775 static LRESULT UPDOWN_SetBase(HWND hwnd,WPARAM wParam,LPARAM lParam) 776 { 777 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 778 INT temp; 779 780 // TRACE(updown, "UpDown Ctrl new base(%d), hwnd=%04x\n", 781 // wParam, hwnd); 782 if (!(wParam==10 || wParam==16) || lParam) UNKNOWN_PARAM(UDM_SETBASE,wParam,lParam); 783 if (wParam==10 || wParam==16) 784 { 785 temp = infoPtr->Base; 786 infoPtr->Base = wParam; 787 return temp; /* return the prev base */ 788 } 789 790 return 0; 791 } 792 793 static LRESULT UPDOWN_GetBuddy(HWND hwnd,WPARAM wParam,LPARAM lParam) 794 { 795 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 796 797 if (wParam || lParam) UNKNOWN_PARAM(UDM_GETBUDDY,wParam,lParam); 798 799 return infoPtr->Buddy; 800 } 801 802 803 static LRESULT UPDOWN_SetBuddy(HWND hwnd,WPARAM wParam,LPARAM lParam) 804 { 805 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 806 INT temp; 807 808 if (lParam) UNKNOWN_PARAM(UDM_SETBUDDY,wParam,lParam); 809 temp = infoPtr->Buddy; 810 infoPtr->Buddy = wParam; 811 UPDOWN_SetBuddyHandle(hwnd,wParam); 812 // TRACE(updown, "UpDown Ctrl new buddy(%04x), hwnd=%04x\n", 813 // infoPtr->Buddy, hwnd); 814 815 return temp; 816 } 817 818 static LRESULT UPDOWN_GetPos(HWND hwnd,WPARAM wParam,LPARAM lParam) 819 { 820 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 821 INT temp; 822 823 if (wParam || lParam) UNKNOWN_PARAM(UDM_GETPOS, wParam, lParam); 824 temp = UPDOWN_GetBuddyInt(hwnd); 825 826 return MAKELONG(infoPtr->CurVal,temp ? 0:1); 827 } 828 829 static LRESULT UPDOWN_SetPos(HWND hwnd,WPARAM wParam,LPARAM lParam) 830 { 831 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 832 DWORD dwStyle = GetWindowLongA(hwnd,GWL_STYLE); 833 INT temp; 834 835 if (wParam || HIWORD(lParam)) UNKNOWN_PARAM(UDM_GETPOS,wParam,lParam); 836 temp = SLOWORD(lParam); 837 // TRACE(updown, "UpDown Ctrl new value(%d), hwnd=%04x\n", 838 // temp, hwnd); 839 if (!UPDOWN_InBounds(hwnd, temp)) 840 { 841 if (temp < infoPtr->MinVal) temp = infoPtr->MinVal; 842 if (temp > infoPtr->MaxVal) temp = infoPtr->MaxVal; 843 } 844 wParam = infoPtr->CurVal; /* save prev value */ 845 infoPtr->CurVal = temp; /* set the new value */ 846 if (dwStyle & UDS_SETBUDDYINT) UPDOWN_SetBuddyInt (hwnd); 847 848 return wParam; /* return prev value */ 849 } 850 851 static LRESULT UPDOWN_GetRange(HWND hwnd,WPARAM wParam,LPARAM lParam) 852 { 853 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 854 855 if (wParam || lParam) UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam); 856 857 return MAKELONG(infoPtr->MaxVal,infoPtr->MinVal); 858 } 859 860 static LRESULT UPDOWN_SetRange(HWND hwnd,WPARAM wParam,LPARAM lParam) 861 { 862 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 863 864 if (wParam) UNKNOWN_PARAM(UDM_SETRANGE,wParam,lParam); /* we must have: */ 865 infoPtr->MaxVal = SLOWORD(lParam); /* UD_MINVAL <= Max <= UD_MAXVAL */ 866 infoPtr->MinVal = SHIWORD(lParam); /* UD_MINVAL <= Min <= UD_MAXVAL */ 867 /* |Max-Min| <= UD_MAXVAL */ 868 // TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n", 869 // infoPtr->MinVal, infoPtr->MaxVal, hwnd); 870 871 return 0; 872 } 873 874 static LRESULT UPDOWN_GetRange32(HWND hwnd,WPARAM wParam,LPARAM lParam) 875 { 876 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 877 878 if (wParam) *(LPINT)wParam = infoPtr->MinVal; 879 if (lParam) *(LPINT)lParam = infoPtr->MaxVal; 880 881 return 0; 882 } 883 884 static LRESULT UPDOWN_SetRange32(HWND hwnd,WPARAM wParam,LPARAM lParam) 885 { 886 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr(hwnd); 887 888 infoPtr->MinVal = (INT)wParam; 889 infoPtr->MaxVal = (INT)lParam; 890 if (infoPtr->MaxVal <= infoPtr->MinVal) infoPtr->MaxVal = infoPtr->MinVal+1; 891 // TRACE(updown, "UpDown Ctrl new range(%d to %d), hwnd=%04x\n", 892 // infoPtr->MinVal, infoPtr->MaxVal, hwnd); 893 894 return 0; 895 } 896 603 897 /*********************************************************************** 604 898 * UpDownWndProc … … 607 901 LPARAM lParam) 608 902 { 609 UPDOWN_INFO *infoPtr = UPDOWN_GetInfoPtr (hwnd);610 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);611 int temp;612 613 903 switch(message) 614 904 { 615 905 case WM_NCCREATE: 616 /* get rid of border, if any */ 617 SetWindowLongA (hwnd, GWL_STYLE, dwStyle & ~WS_BORDER); 618 return TRUE; 906 return UPDOWN_NCCreate(hwnd,wParam,lParam); 619 907 620 908 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); 909 return UPDOWN_Create(hwnd,wParam,lParam); 910 911 case WM_DESTROY: 912 return UPDOWN_Destroy(hwnd,wParam,lParam); 913 914 case WM_ENABLE: 915 return UPDOWN_Enable(hwnd,wParam,lParam); 916 917 case WM_TIMER: 918 return UPDOWN_Timer(hwnd,wParam,lParam); 919 920 case WM_CANCELMODE: 921 UPDOWN_CancelMode(hwnd); 636 922 break; 637 923 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 } 924 case WM_LBUTTONUP: 925 return UPDOWN_LButtonUp(hwnd,wParam,lParam); 926 927 case WM_LBUTTONDOWN: 928 case WM_MOUSEMOVE: 929 if(UPDOWN_IsEnabled(hwnd)) 930 { 931 POINT pt; 932 CONV_POINT16TO32((POINT16 *)&lParam,&pt); 933 UPDOWN_HandleMouseEvent(hwnd,message,pt); 681 934 } 682 935 break; 683 936 684 case WM_CANCELMODE: 685 UPDOWN_CancelMode (hwnd); 937 case WM_KEYDOWN: 938 return UPDOWN_KeyDown(hwnd,wParam,lParam); 939 940 case WM_PAINT: 941 UPDOWN_Paint(hwnd); 686 942 break; 687 943 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 944 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; 945 return UPDOWN_GetAccel(hwnd,wParam,lParam); 732 946 733 947 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; 948 return UPDOWN_SetAccel(hwnd,wParam,lParam); 747 949 748 950 case UDM_GETBASE: 749 if (wParam || lParam) 750 UNKNOWN_PARAM(UDM_GETBASE, wParam, lParam); 751 return infoPtr->Base; 951 return UPDOWN_GetBase(hwnd,wParam,lParam); 752 952 753 953 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; 954 return UPDOWN_SetBase(hwnd,wParam,lParam); 764 955 765 956 case UDM_GETBUDDY: 766 if (wParam || lParam) 767 UNKNOWN_PARAM(UDM_GETBUDDY, wParam, lParam); 768 return infoPtr->Buddy; 957 return UPDOWN_GetBuddy(hwnd,wParam,lParam); 769 958 770 959 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; 960 return UPDOWN_SetBuddy(hwnd,wParam,lParam); 779 961 780 962 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); 963 return UPDOWN_GetPos(hwnd,wParam,lParam); 785 964 786 965 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 */ 966 return UPDOWN_SetPos(hwnd,wParam,lParam); 803 967 804 968 case UDM_GETRANGE: 805 if (wParam || lParam) 806 UNKNOWN_PARAM(UDM_GETRANGE, wParam, lParam); 807 return MAKELONG(infoPtr->MaxVal, infoPtr->MinVal); 969 return UPDOWN_GetRange(hwnd,wParam,lParam); 808 970 809 971 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; 972 return UPDOWN_SetRange(hwnd,wParam,lParam); 818 973 819 974 case UDM_GETRANGE32: 820 if (wParam) 821 *(LPINT)wParam = infoPtr->MinVal; 822 if (lParam) 823 *(LPINT)lParam = infoPtr->MaxVal; 824 break; 975 return UPDOWN_GetRange32(hwnd,wParam,lParam); 825 976 826 977 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; 978 return UPDOWN_SetRange32(hwnd,wParam,lParam); 834 979 835 980 default: … … 837 982 // ERR (updown, "unknown msg %04x wp=%04x lp=%08lx\n", 838 983 // message, wParam, lParam); 839 return DefWindowProcA (hwnd, message, wParam,lParam);984 return DefWindowProcA(hwnd,message,wParam,lParam); 840 985 } 841 986
Note:
See TracChangeset
for help on using the changeset viewer.
