home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / gpiimage.zip / IMG_MENU.C < prev    next >
C/C++ Source or Header  |  1998-04-20  |  9KB  |  271 lines

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