Changeset 199 for trunk/src/helpers/winh.c
- Timestamp:
- Aug 10, 2002, 1:11:22 PM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/winh.c
r196 r199 338 338 MPFROM2SHORT(usItemID, fSearchSubmenus), 339 339 (MPARAM)pmi)); 340 } 341 342 /* 343 *@@ winhQuerySubmenu: 344 * tests whether sID specifies a submenu in 345 * hMenu and returns the submenu window handle 346 * if so. 347 * 348 *@@added V0.9.20 (2002-08-10) [umoeller] 349 */ 350 351 HWND winhQuerySubmenu(HWND hMenu, 352 SHORT sID) 353 { 354 MENUITEM mi = {0}; 355 if ( (WinSendMsg(hMenu, 356 MM_QUERYITEM, 357 MPFROM2SHORT(sID, 358 FALSE), 359 (MPARAM)&mi)) 360 && (mi.afStyle & MIS_SUBMENU) 361 ) 362 return mi.hwndSubMenu; 363 364 return NULLHANDLE; 340 365 } 341 366 … … 503 528 * 504 529 *@@added V0.9.12 (2001-05-22) [umoeller] 530 *@@changed V0.9.20 (2002-08-10) [umoeller]: now supporting calling this more than once 505 531 */ 506 532 … … 508 534 LONG lDefaultItem) // in: item ID of new default item 509 535 { 510 // stolen from the Warp Toolkit WPS Guide 511 ULONG ulStyle = WinQueryWindowULong(hwndMenu, QWL_STYLE); 512 ulStyle |= MS_CONDITIONALCASCADE; 513 WinSetWindowULong(hwndMenu, QWL_STYLE, ulStyle); 536 BOOL brc; 537 ULONG ulStyle = WinQueryWindowULong(hwndMenu, QWL_STYLE); 538 LONG lOldDefault = -1; 539 540 if (ulStyle & MS_CONDITIONALCASCADE) 541 { 542 // menu is already conditional cascade: 543 lOldDefault = (LONG)WinSendMsg(hwndMenu, 544 MM_QUERYDEFAULTITEMID, 545 0, 546 0); 547 _PmpfF(("lOldDefault is %d", lOldDefault)); 548 } 549 else 550 { 551 ulStyle |= MS_CONDITIONALCASCADE; 552 WinSetWindowULong(hwndMenu, QWL_STYLE, ulStyle); 553 } 514 554 515 555 // make the first item in the subfolder 516 // the default of cascading submenu */ 517 return (BOOL)(WinSendMsg(hwndMenu, 518 MM_SETDEFAULTITEMID, 519 (MPARAM)lDefaultItem, 520 0)); 556 // the default of cascading submenu 557 brc = (BOOL)WinSendMsg(hwndMenu, 558 MM_SETDEFAULTITEMID, 559 (MPARAM)lDefaultItem, 560 0); 561 562 if ( (lOldDefault != -1) 563 && (lOldDefault != lDefaultItem) 564 ) 565 { 566 // unset the "checked" attribute of the old one 567 // or we'll have two in the menu 568 WinSendMsg(hwndMenu, 569 MM_SETITEMATTR, 570 MPFROM2SHORT(lOldDefault, 571 FALSE), 572 MPFROM2SHORT(MIA_CHECKED, 0)); 573 } 574 575 return brc; 521 576 } 522 577 … … 548 603 549 604 /* 550 *@@ winhCopyMenuItem :605 *@@ winhCopyMenuItem2: 551 606 * copies a menu item from hmenuSource to hmenuTarget. 552 607 * … … 554 609 * a submenu, the entire submenu is copied as well 555 610 * (this will then recurse). 611 * 612 * fl can be any combination of: 613 * 614 * -- COPYFL_STRIPTABS: strip off \t and everything 615 * that follows, if present. 556 616 * 557 617 * NOTE: Copying submenus will work only if each item … … 562 622 * 563 623 *@@added V0.9.9 (2001-03-09) [umoeller] 564 */ 565 566 BOOL winhCopyMenuItem(HWND hmenuTarget, 567 HWND hmenuSource, 568 USHORT usID, 569 SHORT sTargetPosition) // in: position to insert at or MIT_END 624 *@@changed V0.9.20 (2002-08-10) [umoeller]: renamed, added fl 625 */ 626 627 BOOL winhCopyMenuItem2(HWND hmenuTarget, 628 HWND hmenuSource, 629 USHORT usID, 630 SHORT sTargetPosition, // in: position to insert at or MIT_END 631 ULONG fl) // in: COPYFL_* flags 570 632 { 571 633 BOOL brc = FALSE; … … 587 649 // no separator: 588 650 // get item text 589 PSZ pszSource = winhQueryMenuItemText(hmenuSource,590 usID);591 if (pszSource)651 PSZ pszSource; 652 if (pszSource = winhQueryMenuItemText(hmenuSource, 653 usID)) 592 654 { 655 PSZ p; 656 // remove the hotkey description 657 // V0.9.20 (2002-08-10) [umoeller] 658 if ( (fl & COPYFL_STRIPTABS) 659 && (p = strchr(pszSource, '\t')) 660 ) 661 *p = '\0'; 662 593 663 if ( (mi.afStyle & MIS_SUBMENU) 594 664 && (mi.hwndSubMenu) … … 596 666 { 597 667 // this is the top of a submenu: 598 HWND hwndSubMenu = winhInsertSubmenu(hmenuTarget,599 sTargetPosition,600 mi.id,601 pszSource,602 mi.afStyle,603 0,604 NULL,605 0,606 0);607 if (hwndSubMenu)668 HWND hwndSubMenu; 669 if (hwndSubMenu = winhInsertSubmenu(hmenuTarget, 670 sTargetPosition, 671 mi.id, 672 pszSource, 673 mi.afStyle, 674 0, 675 NULL, 676 0, 677 0)) 608 678 { 609 679 // now copy all the items in the submenu 610 680 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, 611 MM_QUERYITEMCOUNT, 612 0, 0)); 681 MM_QUERYITEMCOUNT, 682 0, 683 0)); 613 684 // loop through all entries in the original submenu 614 685 ULONG i; … … 617 688 i++) 618 689 { 619 // CHAR szItemText[100];620 690 SHORT id = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, 621 691 MM_ITEMIDFROMPOSITION, … … 623 693 0)); 624 694 // recurse 625 winhCopyMenuItem (hwndSubMenu,695 winhCopyMenuItem2(hwndSubMenu, 626 696 mi.hwndSubMenu, 627 697 id, 628 MIT_END); 698 MIT_END, 699 fl); 629 700 } 630 701 … … 638 709 // get the original default item 639 710 SHORT sDefID = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu, 640 MM_QUERYDEFAULTITEMID, 641 0, 0)); 711 MM_QUERYDEFAULTITEMID, 712 0, 713 0)); 642 714 // set "conditional cascade style" on target too 643 WinSetWindowBits(hwndSubMenu, 644 QWL_STYLE, 645 MS_CONDITIONALCASCADE, 646 MS_CONDITIONALCASCADE); 647 // and set default item id 648 WinSendMsg(hwndSubMenu, 649 MM_SETDEFAULTITEMID, 650 (MPARAM)sDefID, 651 0); 715 winhSetMenuCondCascade(hwndSubMenu, sDefID); 652 716 } 653 717 } // end if (hwndSubmenu) … … 660 724 mi.iPosition = sTargetPosition; 661 725 s = SHORT1FROMMR(WinSendMsg(hmenuTarget, 662 MM_INSERTITEM, 663 MPFROMP(&mi), 664 MPFROMP(pszSource))); 665 if (s != MIT_MEMERROR && s != MIT_ERROR) 726 MM_INSERTITEM, 727 MPFROMP(&mi), 728 MPFROMP(pszSource))); 729 if ( (s != MIT_MEMERROR) 730 && (s != MIT_ERROR) 731 ) 666 732 brc = TRUE; 667 733 } 668 734 669 735 free(pszSource); 736 670 737 } // end if (pszSource) 671 738 } // end else if (mi.afStyle & MIS_SEPARATOR) … … 673 740 674 741 return brc; 742 } 743 744 /* 745 *@@ winhCopyMenuItem: 746 * wrapper for winhCopyMenuItem2 because it was 747 * exported. 748 * 749 *@@added V0.9.20 (2002-08-10) [umoeller] 750 */ 751 752 BOOL winhCopyMenuItem(HWND hmenuTarget, 753 HWND hmenuSource, 754 USHORT usID, 755 SHORT sTargetPosition) // in: position to insert at or MIT_END 756 { 757 return winhCopyMenuItem2(hmenuTarget, hmenuSource, usID, sTargetPosition, 0); 675 758 } 676 759 … … 696 779 HWND winhMergeIntoSubMenu(HWND hmenuTarget, // in: menu where to create submenu 697 780 SHORT sTargetPosition, // in: position to insert at or MIT_END 698 const char *pcszTitle, // in: title of new submenu 781 const char *pcszTitle, // in: title of new submenu or NULL 699 782 SHORT sID, // in: ID of new submenu 700 783 HWND hmenuSource) // in: menu to merge 701 784 { 702 HWND hwndNewSubmenu = WinCreateMenu(hmenuTarget, NULL);703 if (hwndNewSubmenu )704 { 705 MENUITEM mi = {0};706 SHORT src = 0;785 HWND hwndNewSubmenu; 786 if (hwndNewSubmenu = WinCreateMenu(hmenuTarget, NULL)) 787 { 788 MENUITEM mi = {0}; 789 SHORT src = 0; 707 790 // SHORT s = 0; 708 791 mi.iPosition = MIT_END; … … 724 807 int i; 725 808 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource, 726 MM_QUERYITEMCOUNT,727 0, 0));809 MM_QUERYITEMCOUNT, 810 0, 0)); 728 811 729 812 // loop through all entries in the original menu … … 731 814 { 732 815 SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource, 733 MM_ITEMIDFROMPOSITION,734 MPFROMSHORT(i),735 0));816 MM_ITEMIDFROMPOSITION, 817 MPFROMSHORT(i), 818 0)); 736 819 winhCopyMenuItem(hwndNewSubmenu, 737 820 hmenuSource, … … 752 835 753 836 /* 837 *@@ winhMergeIntoSubMenu: 838 * copies all items from hmenuSource into hmenuTarget, 839 * starting at the given position. 840 * 841 * Returns the no. of items that were copied. 842 * 843 * NOTE: Copying submenus will work only if each item 844 * in the submenu has a unique menu ID. This is due 845 * to the dumb implementation of menus in PM where 846 * it is impossible to query menu items without 847 * knowing their ID. 848 * 849 *@@added V0.9.20 (2002-08-10) [umoeller] 850 */ 851 852 ULONG winhMergeMenus(HWND hmenuTarget, // in: menu to copy items to 853 SHORT sTargetPosition, // in: position to insert at or MIT_END 854 HWND hmenuSource, // in: menu to merge 855 ULONG fl) // in: COPYFL_* flags for winhCopyMenuItem2 856 { 857 SHORT sTarget = MIT_END; 858 859 int i; 860 SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource, 861 MM_QUERYITEMCOUNT, 862 0, 0)); 863 864 // loop through all entries in the original menu 865 for (i = 0; i < cMenuItems; i++) 866 { 867 SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource, 868 MM_ITEMIDFROMPOSITION, 869 MPFROMSHORT(i), 870 0)); 871 winhCopyMenuItem2(hmenuTarget, 872 hmenuSource, 873 id, 874 MIT_END, 875 fl); 876 } 877 878 return i; 879 } 880 881 /* 754 882 *@@ winhQueryMenuItemText: 755 883 * this returns a menu item text as a PSZ … … 774 902 PSZ prc = NULL; 775 903 776 SHORT sLength = SHORT1FROMMR(WinSendMsg(hwndMenu,777 MM_QUERYITEMTEXTLENGTH,778 (MPARAM)(ULONG)usItemID,779 (MPARAM)NULL));780 if (sLength)904 SHORT sLength; 905 if (sLength = SHORT1FROMMR(WinSendMsg(hwndMenu, 906 MM_QUERYITEMTEXTLENGTH, 907 (MPARAM)(ULONG)usItemID, 908 (MPARAM)NULL))) 781 909 { 782 910 prc = (PSZ)malloc(sLength + 1);
Note:
See TracChangeset
for help on using the changeset viewer.