Annotation of os232sdk/toolkt20/c/samples/image/img_menu.c, revision 1.1

1.1     ! root        1: /*==============================================================*\
        !             2:  *  img_menu.c - routines for menu handling
        !             3:  *      Created 1989, 1990 IBM, Microsoft Corp.
        !             4:  *--------------------------------------------------------------*
        !             5:  *
        !             6:  *  This module contains the code for initializing menus as a
        !             7:  *  result of a WM_INITMENU message, and also code for disabling/
        !             8:  *  enabling single menu items.
        !             9:  *
        !            10:  *--------------------------------------------------------------*
        !            11:  *
        !            12:  *  This source file contains the following functions:
        !            13:  *
        !            14:  *      MenuInit()
        !            15:  *      MenuEnableItem(hwndMenu, idItem, fEnabled)
        !            16:  *
        !            17: \*==============================================================*/
        !            18: /*--------------------------------------------------------------*\
        !            19:  *  Include files, macros, defined constants, and externs       *
        !            20: \*--------------------------------------------------------------*/
        !            21: #define INCL_WINMENUS
        !            22: #define INCL_WINFRAMEMGR
        !            23: #include <os2.h>
        !            24: #include "img_main.h"
        !            25: #include "img_xtrn.h"
        !            26: 
        !            27: /*--------------------------------------------------------------*\
        !            28:  *  Entry point declarations                                    *
        !            29: \*--------------------------------------------------------------*/
        !            30: VOID MenuEnableItem(HWND hwndMenu, SHORT idItem, BOOL fEnable);
        !            31: 
        !            32: /****************************************************************\
        !            33:  *  Menu item intialization routine
        !            34:  *--------------------------------------------------------------
        !            35:  *
        !            36:  *  Name:   MenuInit(mp1, mp2)
        !            37:  *
        !            38:  *  Purpose: Processes the WM_INITMENU message for the main window,
        !            39:  *              disabling any menus that are not active
        !            40:  *
        !            41:  *  Usage:  Routine is called each time a menu is dropped
        !            42:  *
        !            43:  *  Method: A switch statement branches control based upon
        !            44:  *          the id of the menu which is being displayed
        !            45:  *
        !            46:  *  Returns:
        !            47: \****************************************************************/
        !            48: VOID MenuInit(mp1, mp2)
        !            49: MPARAM mp1;     /* first message parameter */
        !            50: MPARAM mp2;     /* second message parameter */
        !            51: {
        !            52: 
        !            53:     switch(SHORT1FROMMP(mp1))  {
        !            54:        case IDM_FILE:
        !            55: 
        !            56:            /*
        !            57:             * set the items on the File sub-menu appropriately
        !            58:             */
        !            59:             MenuEnableItem(HWNDFROMMP(mp2), IDM_FILEOPEN, (BOOL)!vfMaximized);
        !            60:             break;
        !            61: 
        !            62:         case IDM_VIEW:
        !            63: 
        !            64:            /*
        !            65:             * set the items on the View sub-menu appropriately
        !            66:             */
        !            67:             if (!vfImgLoaded)
        !            68:                 MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, FALSE);
        !            69:             else {
        !            70:                 MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, TRUE);
        !            71:                 MenuCheckItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, vfDetail);
        !            72:             }
        !            73: 
        !            74:             MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWFOREGROUNDCOLOR,
        !            75:                            vfImgLoaded);
        !            76: 
        !            77:             MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWBACKGROUNDCOLOR,
        !            78:                            vfImgLoaded);
        !            79: 
        !            80:             MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWSAVEPOSITION,
        !            81:                            (BOOL)(vfImgLoaded && vfDetail));
        !            82: 
        !            83:             MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWRESTOREPOSITION,
        !            84:                            (BOOL)(vfImgLoaded && vfDetail));
        !            85: 
        !            86:             break;
        !            87: 
        !            88:        /*
        !            89:         * check the currently selected foreground color &
        !            90:         * set global variable if previously not set
        !            91:         */
        !            92:         case IDM_VIEWFOREGROUNDCOLOR:
        !            93:             MenuCheckItem(HWNDFROMMP(mp2),
        !            94:                           MenuGetColorItemId(IDM_VIEWFORECOLORBLACK), TRUE);
        !            95: 
        !            96:             if (!vhwndViewForeClr)
        !            97:                 vhwndViewForeClr = HWNDFROMMP(mp2);
        !            98:             break;
        !            99: 
        !           100:        /*
        !           101:         * check the currently selected background color &
        !           102:         * set global variable if previously not set
        !           103:         */
        !           104:         case IDM_VIEWBACKGROUNDCOLOR:
        !           105:             MenuCheckItem(HWNDFROMMP(mp2),
        !           106:                           MenuGetColorItemId(IDM_VIEWBACKCOLORBLACK), TRUE);
        !           107: 
        !           108:             if (!vhwndViewBackClr)
        !           109:                 vhwndViewBackClr = HWNDFROMMP(mp2);
        !           110:             break;
        !           111: 
        !           112:         case IDM_HELP:
        !           113:             /*
        !           114:              * Enable or disable the Help menu depending upon whether the
        !           115:              * help manager has been enabled
        !           116:              */
        !           117:             MenuEnableItem(HWNDFROMMP(mp2),
        !           118:                           IDM_HELPHELPFORHELP, vfHelpEnabled);
        !           119: 
        !           120:             MenuEnableItem(HWNDFROMMP(mp2),
        !           121:                           IDM_HELPEXTENDED, vfHelpEnabled);
        !           122: 
        !           123:             MenuEnableItem(HWNDFROMMP(mp2),
        !           124:                           IDM_HELPKEYS, vfHelpEnabled);
        !           125: 
        !           126:             MenuEnableItem(HWNDFROMMP(mp2),
        !           127:                           IDM_HELPINDEX, vfHelpEnabled);
        !           128: 
        !           129:             /** REMEMBER: add a case for IDM_HELPTUTORIAL if you include
        !           130:                 the menu item   **/
        !           131: 
        !           132:             break;
        !           133:     }
        !           134: 
        !           135: }   /* MenuInit() */
        !           136: 
        !           137: /****************************************************************\
        !           138:  *  Get color menu item id
        !           139:  *--------------------------------------------------------------
        !           140:  *
        !           141:  *  Name:   MenuGetColorItemId(idBase)
        !           142:  *
        !           143:  *  Purpose: Returns ID for the currently selected foreground/
        !           144:  *           background color value
        !           145:  *
        !           146:  *  Usage:  Called whenever either the foreground/background
        !           147:  *          floating color menu is to be displayed.
        !           148:  *
        !           149:  *  Method:
        !           150:  *
        !           151:  *  Returns:
        !           152:  *
        !           153: \****************************************************************/
        !           154: SHORT MenuGetColorItemId(idBase)
        !           155: SHORT idBase; /* Id of the base color for foregrnd/backgrnd color menu */
        !           156: {
        !           157:     LONG lColor;
        !           158: 
        !           159:     if (idBase == IDM_VIEWFORECOLORBLACK)
        !           160:         lColor = vlForeClr;
        !           161:     else
        !           162:         lColor = vlBackClr;
        !           163: 
        !           164:    /*
        !           165:     * calculate menu item id based on current color value
        !           166:     */
        !           167:     switch ((SHORT)lColor) {
        !           168:         case CLR_BLACK:
        !           169:             return idBase;
        !           170:             break;
        !           171:         case CLR_WHITE:
        !           172:             return idBase + 1;
        !           173:             break;
        !           174:         case CLR_BLUE:
        !           175:             return idBase + 2;
        !           176:             break;
        !           177:         case CLR_GREEN:
        !           178:             return idBase + 3;
        !           179:             break;
        !           180:         case CLR_YELLOW:
        !           181:             return idBase + 4;
        !           182:             break;
        !           183:         case CLR_RED:
        !           184:             return idBase + 5;
        !           185:             break;
        !           186:     }
        !           187: }   /* MenuGetColorItemId() */
        !           188: 
        !           189: /****************************************************************\
        !           190:  *  Enables/Disables the menu item of the given menu
        !           191:  *--------------------------------------------------------------
        !           192:  *
        !           193:  *  Name:   MenuEnableItem(hwndMenu, idItem, fEnable)
        !           194:  *
        !           195:  *  Purpose: Enables or disables the menu item
        !           196:  *
        !           197:  *  Usage:  Called whenever a menu item is to enabled or
        !           198:  *          disabled
        !           199:  *
        !           200:  *  Method: Sends a MM_SETITEMATTR to the menu with the
        !           201:  *          given item id.  Sets the MIA_DISABLED attribute
        !           202:  *          flag if the item is to be disabled, clears the flag
        !           203:  *          if enabling
        !           204:  *
        !           205:  *  Returns:
        !           206:  *
        !           207: \****************************************************************/
        !           208: VOID MenuEnableItem(hwndMenu, idItem, fEnable)
        !           209: HWND hwndMenu;      /* Handle to the menu */
        !           210: SHORT idItem;       /* Id of the menu item to be enabled/disabled */
        !           211: BOOL fEnable;       /* flag to set enable or disable bit */
        !           212: {
        !           213:     WinSendMsg(hwndMenu,
        !           214:                MM_SETITEMATTR,
        !           215:                MPFROM2SHORT(idItem, TRUE),
        !           216:                MPFROM2SHORT(MIA_DISABLED,
        !           217:                             (fEnable ? 0 : MIA_DISABLED)));
        !           218: 
        !           219: }   /* MenuEnableItem() */
        !           220: 
        !           221: 
        !           222: /****************************************************************\
        !           223:  *  Check the menu item of the given menu
        !           224:  *--------------------------------------------------------------
        !           225:  *
        !           226:  *  Name:   MenuCheckItem(hwndMenu, idItem)
        !           227:  *
        !           228:  *  Purpose: Checks menu item
        !           229:  *
        !           230:  *  Usage:  Called whenever a menu item is to checked
        !           231:  *
        !           232:  *  Method: Sends a MM_SETITEMATTR to the menu with the
        !           233:  *          given item id.  Sets the MIA_CHECKED attribute
        !           234:  *          flag if the item is to be checked
        !           235:  *
        !           236:  *  Returns:
        !           237:  *
        !           238: \****************************************************************/
        !           239: VOID MenuCheckItem(hwndMenu, idItem, fCheck)
        !           240: HWND hwndMenu;      /* Handle to the menu */
        !           241: SHORT idItem;       /* Id of the menu item to be enabled/disabled */
        !           242: BOOL fCheck;        /* Check/uncheck item */
        !           243: {
        !           244:     WinSendMsg(hwndMenu,
        !           245:                MM_SETITEMATTR,
        !           246:                MPFROM2SHORT(idItem, TRUE),
        !           247:                MPFROM2SHORT(MIA_CHECKED,
        !           248:                             (fCheck ? MIA_CHECKED : ~MIA_CHECKED)));
        !           249: 
        !           250: }   /* MenuCheckItem() */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.