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

  1. /**************************************************************************
  2.  *  File name  :  img_view.c
  3.  *
  4.  *  Description:  This module contains the code for handling the functions
  5.  *                offered on the View submenu. These functions are called
  6.  *                from the MainCommand() routine:
  7.  *
  8.  *                ViewSwitchMode()
  9.  *                ViewChangeColor()
  10.  *                ViewSavePosition()
  11.  *                ViewRestorePosition()
  12.  *
  13.  *  Concepts   :  display modes, image processing
  14.  *
  15.  *  API's      :  WinSetParent
  16.  *                WinSendMsg
  17.  *                WinInvalidateRect
  18.  *                GpiSetBackCol
  19.  *                GpiSetColor
  20.  *                GpiSetBackMix
  21.  *                WinQueryWindowRect
  22.  *                GpiSetCurrentPosition
  23.  *
  24.  *  Required
  25.  *    Files    :  OS2.H, STDLIB.H, IMG_MAIN.H, IMG_XTRN.H, IMG_DLG.H
  26.  *
  27.  *  Copyright (C) 1991 IBM Corporation
  28.  *
  29.  *      DISCLAIMER OF WARRANTIES.  The following [enclosed] code is
  30.  *      sample code created by IBM Corporation. This sample code is not
  31.  *      part of any standard or IBM product and is provided to you solely
  32.  *      for  the purpose of assisting you in the development of your
  33.  *      applications.  The code is provided "AS IS", without
  34.  *      warranty of any kind.  IBM shall not be liable for any damages
  35.  *      arising out of your use of the sample code, even if they have been
  36.  *      advised of the possibility of such damages.                                                    *
  37.  *************************************************************************/
  38. /*
  39.  *  Include files, macros, defined constants, and externs
  40.  */
  41. #define INCL_WINSCROLLBARS
  42. #define INCL_WINFRAMEMGR
  43. #define INCL_WINSTDFILE
  44. #define INCL_GPIPRIMITIVES
  45.  
  46. /*
  47.  *  Include files, macros, defined constants, and externs
  48.  */
  49. #include <os2.h>
  50. #include <stdlib.h>
  51.  
  52. #include "img_main.h"
  53. #include "img_xtrn.h"
  54. #include "img_dlg.h"
  55.  
  56. /*
  57.  *  Static variables
  58.  */
  59. /* foreground/background color choices */
  60. LONG  lColorArray[COLOR_COUNT] = {CLR_BLACK,
  61.                                   CLR_WHITE,
  62.                                   CLR_BLUE,
  63.                                   CLR_GREEN,
  64.                                   CLR_YELLOW,
  65.                                   CLR_RED};
  66.  
  67. /**************************************************************************
  68.  *
  69.  *  Name       : ViewSwitchMode()
  70.  *
  71.  *  Description: Toggles the mode of the application from Non-Detail
  72.  *               to Detail mode and visa versa
  73.  *
  74.  *  Concepts   : Routine is called whenever a WM_COMMAND message
  75.  *               is posted to the main window in response to
  76.  *               the user (de)selecting the Detail item
  77.  *               from the View submenu.
  78.  *
  79.  *               Since Non-Detail mode is the opposite to Detail mode,
  80.  *               toggle the menu settings, and ownership of the
  81.  *               scrollbars, and redraw. If entering Detail mode
  82.  *               it is necessary to size the main window as well.
  83.  *
  84.  *  API's      :  WinSetParent
  85.  *                WinSendMsg
  86.  *                WinInvalidateRect
  87.  *
  88.  *  Parameters :  [none]
  89.  *
  90.  *  Return     : [none]
  91.  *
  92.  *************************************************************************/
  93. VOID ViewSwitchMode()
  94. {
  95.    vfDetail = (BOOL)(!vfDetail);
  96.  
  97.    /*
  98.     * detach/attach scrollbars to main window accordingly
  99.     */
  100.    WinSetParent(vhwndVScroll,
  101.                  vfDetail ? vhwndFrame : HWND_OBJECT,
  102.                  FALSE);
  103.    WinSetParent(vhwndHScroll,
  104.                  vfDetail ? vhwndFrame : HWND_OBJECT,
  105.                  FALSE);
  106.  
  107.    WinSendMsg(vhwndFrame,
  108.                WM_UPDATEFRAME,
  109.                MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL),
  110.                (MPARAM)NULL);
  111.  
  112.     /* resize main window if in 'Detail' mode */
  113.    if (vfDetail)
  114.         SizeMainWindow();
  115.  
  116.    WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
  117.  
  118. }   /* End of ViewSwitchMode  */
  119.  
  120. /**************************************************************************
  121.  *
  122.  *  Name       : ViewChangeColor(idColor)
  123.  *
  124.  *  Description: Changes the foreground/background colors of the
  125.  *               selected image.
  126.  *
  127.  *  Concepts   : Routine is called whenever a WM_COMMAND message
  128.  *               is posted to the main window in response to
  129.  *               the user selecting a Color item from either the
  130.  *               'Foreground'/'Background' Color items on the View submenu
  131.  *
  132.  *  API's      :  GpiSetBackColor
  133.  *                GpiSetColor
  134.  *                GpiSetBackMix
  135.  *                WinInvalidateRect
  136.  *
  137.  *  Parameters :  idColor = identifier of the selected color
  138.  *
  139.  *  Return     : [none]
  140.  *
  141.  *************************************************************************/
  142. VOID ViewChangeColor(USHORT idColor)
  143. {
  144.    LONG lForeClr, lBackClr;
  145.    BOOL fSameClr;
  146.    USHORT idItem;
  147.  
  148.    /*
  149.     * change either the foreground/background color and save
  150.     * previous settings so that the appropriate menuitem can
  151.     * be reset
  152.     */
  153.    if (idColor < IDM_VIEWBACKCOLORBLACK)
  154.    {
  155.        lForeClr = lColorArray[idColor - COLOR_BASE];
  156.        fSameClr = (BOOL)(lForeClr == vlBackClr);
  157.        idItem = MenuGetColorItemId(IDM_VIEWFORECOLORBLACK);
  158.    }
  159.    else
  160.    {
  161.        lBackClr = lColorArray[idColor - COLOR_BASE - COLOR_COUNT];
  162.        fSameClr = (BOOL)(lBackClr == vlForeClr);
  163.        idItem = MenuGetColorItemId(IDM_VIEWBACKCOLORBLACK);
  164.    }
  165.    /*
  166.     * if background color is the same as the foreground color
  167.     * - ensure this is correct and get out if not
  168.     */
  169.    if (fSameClr)
  170.    {
  171.        if (MessageBox(vhwndFrame,
  172.                       IDMSG_BACKEQFORE, IDMSG_WARNING,
  173.                       MB_APPLMODAL | MB_YESNO | MB_CUAWARNING,
  174.                       TRUE) == MBID_NO)
  175.            return;
  176.    }
  177.  
  178.     /* cancel previously checked item  & save new values */
  179.    if (idColor < IDM_VIEWBACKCOLORBLACK)
  180.    {
  181.        MenuEnableItem(vhwndViewForeClr, idItem, TRUE);
  182.        vlForeClr = lForeClr;
  183.    }
  184.    else
  185.    {
  186.        MenuEnableItem(vhwndViewBackClr, idItem, TRUE);
  187.        vlBackClr = lBackClr;
  188.    }
  189.  
  190.    /*
  191.     * set colors appropriately and force redraw
  192.     */
  193.    GpiSetBackColor(vhps, vlBackClr);
  194.    GpiSetColor(vhps, vlForeClr);
  195.    GpiSetBackMix(vhps, BM_OVERPAINT);
  196.    WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
  197.  
  198. }   /* End of ViewChangeColor() */
  199.  
  200. /**************************************************************************
  201.  *
  202.  *  Name       : ViewRestorePosition()
  203.  *
  204.  *  Description: Restores the saved position of the image
  205.  *
  206.  *  Concepts   : Routine is called whenever a WM_COMMAND message
  207.  *               is posted to the main window in response to
  208.  *               the user selecting the Restore Position item
  209.  *
  210.  *  API's      : WinQueryWindowRect
  211.  *               GpiSetCurrentPosition
  212.  *               WinSendMsg
  213.  *               WinInvalidateRect
  214.  *
  215.  *  Parameters : [none]
  216.  *
  217.  *  Return     : [none]
  218.  *
  219.  *************************************************************************/
  220. VOID ViewRestorePosition(void)
  221. {
  222.    RECTL rcl;
  223.  
  224.     /* only valid if image is loaded & in Detail mode */
  225.    if (vfImgLoaded && vfDetail)
  226.    {
  227.        WinQueryWindowRect(vhwndClient, &rcl);
  228.        GpiSetCurrentPosition(vhps, &vptlSave);
  229.        WinSendMsg(vhwndVScroll,
  230.                   SBM_SETPOS,
  231.                   MPFROMLONG(vptlSave.y - rcl.yTop),
  232.                   (MPARAM)NULL);
  233.        WinSendMsg(vhwndHScroll,
  234.                   SBM_SETPOS,
  235.                   MPFROMLONG(labs(vptlSave.x)),
  236.                   (MPARAM)NULL);
  237.        WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
  238.    }
  239. }   /* End of ViewRestorePosition */
  240.  
  241. /**************************************************************************
  242.  *
  243.  *  Name       : ViewSavePosition()
  244.  *
  245.  *  Description: Saves the saved position of the image
  246.  *
  247.  *  Concepts   : Routine is called whenever a WM_COMMAND message
  248.  *               is posted to the main window in response to
  249.  *               the user selecting the Save Position item
  250.  *
  251.  *  API's      : GpiQueryCurrentPosition
  252.  *
  253.  *  Parameters : [none]
  254.  *
  255.  *  Return     : [none]
  256.  *
  257.  *************************************************************************/
  258. VOID ViewSavePosition(void)
  259. {
  260.    if (vfImgLoaded && vfDetail)
  261.        GpiQueryCurrentPosition(vhps, &vptlSave);
  262. }   /* ViewSavePosition() */
  263. /***************************  End of img_view.c  *************************/
  264.