File:  [OS/2 SDKs] / os232sdk / toolkt20 / c / samples / image / img_menu.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:31 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1990, HEAD
Microsoft OS/2 SDK 2.0 05-30-1990

/*==============================================================*\
 *  img_menu.c - routines for menu handling
 *      Created 1989, 1990 IBM, Microsoft Corp.
 *--------------------------------------------------------------*
 *
 *  This module contains the code for initializing menus as a
 *  result of a WM_INITMENU message, and also code for disabling/
 *  enabling single menu items.
 *
 *--------------------------------------------------------------*
 *
 *  This source file contains the following functions:
 *
 *      MenuInit()
 *      MenuEnableItem(hwndMenu, idItem, fEnabled)
 *
\*==============================================================*/
/*--------------------------------------------------------------*\
 *  Include files, macros, defined constants, and externs       *
\*--------------------------------------------------------------*/
#define INCL_WINMENUS
#define INCL_WINFRAMEMGR
#include <os2.h>
#include "img_main.h"
#include "img_xtrn.h"

/*--------------------------------------------------------------*\
 *  Entry point declarations                                    *
\*--------------------------------------------------------------*/
VOID MenuEnableItem(HWND hwndMenu, SHORT idItem, BOOL fEnable);

/****************************************************************\
 *  Menu item intialization routine
 *--------------------------------------------------------------
 *
 *  Name:   MenuInit(mp1, mp2)
 *
 *  Purpose: Processes the WM_INITMENU message for the main window,
 *              disabling any menus that are not active
 *
 *  Usage:  Routine is called each time a menu is dropped
 *
 *  Method: A switch statement branches control based upon
 *          the id of the menu which is being displayed
 *
 *  Returns:
\****************************************************************/
VOID MenuInit(mp1, mp2)
MPARAM mp1;     /* first message parameter */
MPARAM mp2;     /* second message parameter */
{

    switch(SHORT1FROMMP(mp1))  {
       case IDM_FILE:

           /*
            * set the items on the File sub-menu appropriately
            */
            MenuEnableItem(HWNDFROMMP(mp2), IDM_FILEOPEN, (BOOL)!vfMaximized);
            break;

        case IDM_VIEW:

           /*
            * set the items on the View sub-menu appropriately
            */
            if (!vfImgLoaded)
                MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, FALSE);
            else {
                MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, TRUE);
                MenuCheckItem(HWNDFROMMP(mp2), IDM_VIEWDETAIL, vfDetail);
            }

            MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWFOREGROUNDCOLOR,
                           vfImgLoaded);

            MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWBACKGROUNDCOLOR,
                           vfImgLoaded);

            MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWSAVEPOSITION,
                           (BOOL)(vfImgLoaded && vfDetail));

            MenuEnableItem(HWNDFROMMP(mp2), IDM_VIEWRESTOREPOSITION,
                           (BOOL)(vfImgLoaded && vfDetail));

            break;

       /*
        * check the currently selected foreground color &
        * set global variable if previously not set
        */
        case IDM_VIEWFOREGROUNDCOLOR:
            MenuCheckItem(HWNDFROMMP(mp2),
                          MenuGetColorItemId(IDM_VIEWFORECOLORBLACK), TRUE);

            if (!vhwndViewForeClr)
                vhwndViewForeClr = HWNDFROMMP(mp2);
            break;

       /*
        * check the currently selected background color &
        * set global variable if previously not set
        */
        case IDM_VIEWBACKGROUNDCOLOR:
            MenuCheckItem(HWNDFROMMP(mp2),
                          MenuGetColorItemId(IDM_VIEWBACKCOLORBLACK), TRUE);

            if (!vhwndViewBackClr)
                vhwndViewBackClr = HWNDFROMMP(mp2);
            break;

        case IDM_HELP:
            /*
             * Enable or disable the Help menu depending upon whether the
             * help manager has been enabled
             */
            MenuEnableItem(HWNDFROMMP(mp2),
                          IDM_HELPHELPFORHELP, vfHelpEnabled);

            MenuEnableItem(HWNDFROMMP(mp2),
                          IDM_HELPEXTENDED, vfHelpEnabled);

            MenuEnableItem(HWNDFROMMP(mp2),
                          IDM_HELPKEYS, vfHelpEnabled);

            MenuEnableItem(HWNDFROMMP(mp2),
                          IDM_HELPINDEX, vfHelpEnabled);

            /** REMEMBER: add a case for IDM_HELPTUTORIAL if you include
                the menu item   **/

            break;
    }

}   /* MenuInit() */

/****************************************************************\
 *  Get color menu item id
 *--------------------------------------------------------------
 *
 *  Name:   MenuGetColorItemId(idBase)
 *
 *  Purpose: Returns ID for the currently selected foreground/
 *           background color value
 *
 *  Usage:  Called whenever either the foreground/background
 *          floating color menu is to be displayed.
 *
 *  Method:
 *
 *  Returns:
 *
\****************************************************************/
SHORT MenuGetColorItemId(idBase)
SHORT idBase; /* Id of the base color for foregrnd/backgrnd color menu */
{
    LONG lColor;

    if (idBase == IDM_VIEWFORECOLORBLACK)
        lColor = vlForeClr;
    else
        lColor = vlBackClr;

   /*
    * calculate menu item id based on current color value
    */
    switch ((SHORT)lColor) {
        case CLR_BLACK:
            return idBase;
            break;
        case CLR_WHITE:
            return idBase + 1;
            break;
        case CLR_BLUE:
            return idBase + 2;
            break;
        case CLR_GREEN:
            return idBase + 3;
            break;
        case CLR_YELLOW:
            return idBase + 4;
            break;
        case CLR_RED:
            return idBase + 5;
            break;
    }
}   /* MenuGetColorItemId() */

/****************************************************************\
 *  Enables/Disables the menu item of the given menu
 *--------------------------------------------------------------
 *
 *  Name:   MenuEnableItem(hwndMenu, idItem, fEnable)
 *
 *  Purpose: Enables or disables the menu item
 *
 *  Usage:  Called whenever a menu item is to enabled or
 *          disabled
 *
 *  Method: Sends a MM_SETITEMATTR to the menu with the
 *          given item id.  Sets the MIA_DISABLED attribute
 *          flag if the item is to be disabled, clears the flag
 *          if enabling
 *
 *  Returns:
 *
\****************************************************************/
VOID MenuEnableItem(hwndMenu, idItem, fEnable)
HWND hwndMenu;      /* Handle to the menu */
SHORT idItem;       /* Id of the menu item to be enabled/disabled */
BOOL fEnable;       /* flag to set enable or disable bit */
{
    WinSendMsg(hwndMenu,
               MM_SETITEMATTR,
               MPFROM2SHORT(idItem, TRUE),
               MPFROM2SHORT(MIA_DISABLED,
                            (fEnable ? 0 : MIA_DISABLED)));

}   /* MenuEnableItem() */


/****************************************************************\
 *  Check the menu item of the given menu
 *--------------------------------------------------------------
 *
 *  Name:   MenuCheckItem(hwndMenu, idItem)
 *
 *  Purpose: Checks menu item
 *
 *  Usage:  Called whenever a menu item is to checked
 *
 *  Method: Sends a MM_SETITEMATTR to the menu with the
 *          given item id.  Sets the MIA_CHECKED attribute
 *          flag if the item is to be checked
 *
 *  Returns:
 *
\****************************************************************/
VOID MenuCheckItem(hwndMenu, idItem, fCheck)
HWND hwndMenu;      /* Handle to the menu */
SHORT idItem;       /* Id of the menu item to be enabled/disabled */
BOOL fCheck;        /* Check/uncheck item */
{
    WinSendMsg(hwndMenu,
               MM_SETITEMATTR,
               MPFROM2SHORT(idItem, TRUE),
               MPFROM2SHORT(MIA_CHECKED,
                            (fCheck ? MIA_CHECKED : ~MIA_CHECKED)));

}   /* MenuCheckItem() */

unix.superglobalmegacorp.com

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