Changeset 199 for trunk


Ignore:
Timestamp:
Aug 10, 2002, 1:11:22 PM (23 years ago)
Author:
umoeller
Message:

Menu fixes.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/helpers/winh.h

    r195 r199  
    191191    #endif
    192192
     193    HWND XWPENTRY winhQuerySubmenu(HWND hMenu, SHORT sID);
     194
    193195    /*
    194196     * winhCreateEmptyMenu:
     
    274276                                           SHORT sId);
    275277
     278    #define COPYFL_STRIPTABS            0x0001
     279
     280    BOOL XWPENTRY winhCopyMenuItem2(HWND hmenuTarget,
     281                                    HWND hmenuSource,
     282                                    USHORT usID,
     283                                    SHORT sTargetPosition,
     284                                    ULONG fl);
     285
    276286    BOOL XWPENTRY winhCopyMenuItem(HWND hmenuTarget,
    277287                                   HWND hmenuSource,
     
    295305                                       HWND hmenuSource);
    296306    typedef WINHMERGEINTOSUBMENU *PWINHMERGEINTOSUBMENU;
     307
     308    ULONG XWPENTRY winhMergeMenus(HWND hmenuTarget,
     309                                  SHORT sTargetPosition,
     310                                  HWND hmenuSource,
     311                                  ULONG fl);
     312    typedef ULONG XWPENTRY WINHMERGEMENUS(HWND hmenuTarget,
     313                                          SHORT sTargetPosition,
     314                                          HWND hmenuSource,
     315                                          ULONG fl);
     316    typedef WINHMERGEMENUS *PWINHMERGEMENUS;
    297317
    298318    PSZ XWPENTRY winhQueryMenuItemText(HWND hwndMenu,
  • trunk/src/helpers/dialog.c

    r197 r199  
    27972797 *@@changed V0.9.19 (2002-04-24) [umoeller]: added pfnHelp
    27982798 *@@changed V0.9.20 (2002-07-12) [umoeller]: made icon spacing wider
     2799 *@@changed V0.9.20 (2002-08-10) [umoeller]: fixed missing close button
    27992800 */
    28002801
     
    29652966            if (!(arc = dlghCreateDlg(phwndDlg,
    29662967                                      hwndOwner,
    2967                                       FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN,
     2968                                      FCF_TITLEBAR | FCF_SYSMENU | FCF_DLGBORDER | FCF_NOBYTEALIGN
     2969                                            | FCF_CLOSEBUTTON,      // was missing V0.9.20 (2002-08-10) [umoeller]
    29682970                                      fnwpMessageBox,
    29692971                                      pcszTitle,
  • trunk/src/helpers/winh.c

    r196 r199  
    338338                             MPFROM2SHORT(usItemID, fSearchSubmenus),
    339339                             (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
     351HWND 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;
    340365}
    341366
     
    503528 *
    504529 *@@added V0.9.12 (2001-05-22) [umoeller]
     530 *@@changed V0.9.20 (2002-08-10) [umoeller]: now supporting calling this more than once
    505531 */
    506532
     
    508534                            LONG lDefaultItem)      // in: item ID of new default item
    509535{
    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    }
    514554
    515555    // 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;
    521576}
    522577
     
    548603
    549604/*
    550  *@@ winhCopyMenuItem:
     605 *@@ winhCopyMenuItem2:
    551606 *      copies a menu item from hmenuSource to hmenuTarget.
    552607 *
     
    554609 *      a submenu, the entire submenu is copied as well
    555610 *      (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.
    556616 *
    557617 *      NOTE: Copying submenus will work only if each item
     
    562622 *
    563623 *@@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
     627BOOL 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
    570632{
    571633    BOOL brc = FALSE;
     
    587649            // no separator:
    588650            // get item text
    589             PSZ pszSource = winhQueryMenuItemText(hmenuSource,
    590                                                   usID);
    591             if (pszSource)
     651            PSZ pszSource;
     652            if (pszSource = winhQueryMenuItemText(hmenuSource,
     653                                                  usID))
    592654            {
     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
    593663                if (    (mi.afStyle & MIS_SUBMENU)
    594664                     && (mi.hwndSubMenu)
     
    596666                {
    597667                    // 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))
    608678                    {
    609679                        // now copy all the items in the submenu
    610680                        SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
    611                                                              MM_QUERYITEMCOUNT,
    612                                                              0, 0));
     681                                                                   MM_QUERYITEMCOUNT,
     682                                                                   0,
     683                                                                   0));
    613684                        // loop through all entries in the original submenu
    614685                        ULONG i;
     
    617688                             i++)
    618689                        {
    619                             // CHAR szItemText[100];
    620690                            SHORT id = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
    621691                                                         MM_ITEMIDFROMPOSITION,
     
    623693                                                         0));
    624694                            // recurse
    625                             winhCopyMenuItem(hwndSubMenu,
     695                            winhCopyMenuItem2(hwndSubMenu,
    626696                                             mi.hwndSubMenu,
    627697                                             id,
    628                                              MIT_END);
     698                                             MIT_END,
     699                                             fl);
    629700                        }
    630701
     
    638709                            // get the original default item
    639710                            SHORT sDefID = SHORT1FROMMR(WinSendMsg(mi.hwndSubMenu,
    640                                                              MM_QUERYDEFAULTITEMID,
    641                                                              0, 0));
     711                                                                   MM_QUERYDEFAULTITEMID,
     712                                                                   0,
     713                                                                   0));
    642714                            // 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);
    652716                        }
    653717                    } // end if (hwndSubmenu)
     
    660724                    mi.iPosition = sTargetPosition;
    661725                    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                       )
    666732                        brc = TRUE;
    667733                }
    668734
    669735                free(pszSource);
     736
    670737            } // end if (pszSource)
    671738        } // end else if (mi.afStyle & MIS_SEPARATOR)
     
    673740
    674741    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
     752BOOL 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);
    675758}
    676759
     
    696779HWND winhMergeIntoSubMenu(HWND hmenuTarget,         // in: menu where to create submenu
    697780                          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
    699782                          SHORT sID,                // in: ID of new submenu
    700783                          HWND hmenuSource)         // in: menu to merge
    701784{
    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;
    707790        // SHORT s = 0;
    708791        mi.iPosition = MIT_END;
     
    724807            int i;
    725808            SHORT cMenuItems = SHORT1FROMMR(WinSendMsg(hmenuSource,
    726                                                  MM_QUERYITEMCOUNT,
    727                                                  0, 0));
     809                                                       MM_QUERYITEMCOUNT,
     810                                                       0, 0));
    728811
    729812            // loop through all entries in the original menu
     
    731814            {
    732815                SHORT id = SHORT1FROMMR(WinSendMsg(hmenuSource,
    733                                              MM_ITEMIDFROMPOSITION,
    734                                              MPFROMSHORT(i),
    735                                              0));
     816                                                   MM_ITEMIDFROMPOSITION,
     817                                                   MPFROMSHORT(i),
     818                                                   0));
    736819                winhCopyMenuItem(hwndNewSubmenu,
    737820                                 hmenuSource,
     
    752835
    753836/*
     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
     852ULONG 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/*
    754882 *@@ winhQueryMenuItemText:
    755883 *      this returns a menu item text as a PSZ
     
    774902    PSZ     prc = NULL;
    775903
    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)))
    781909    {
    782910        prc = (PSZ)malloc(sLength + 1);
Note: See TracChangeset for help on using the changeset viewer.