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

1.1     ! root        1: /*==============================================================*\
        !             2:  *  img_view.c - routines for handling the View menu functions
        !             3:  *      Created 1989, 1990 IBM, Microsoft Corp.
        !             4:  *--------------------------------------------------------------*
        !             5:  *
        !             6:  *  This module contains the code for handling the functions
        !             7:  *  offered on the View submenu. These functions are called
        !             8:  *  from the MainCommand() routine.
        !             9:  *
        !            10:  *--------------------------------------------------------------*
        !            11:  *
        !            12:  *  This source file contains the following functions:
        !            13:  *
        !            14:  *      ViewSwitchMode()
        !            15:  *      ViewChangeColor()
        !            16:  *      ViewSavePosition()
        !            17:  *      ViewRestorePosition()
        !            18:  *
        !            19: \*==============================================================*/
        !            20: /*--------------------------------------------------------------*\
        !            21:  *  Include files, macros, defined constants, and externs       *
        !            22: \*--------------------------------------------------------------*/
        !            23: #define INCL_WINSCROLLBARS
        !            24: #define INCL_WINFRAMEMGR
        !            25: #define INCL_GPIPRIMITIVES
        !            26: 
        !            27: /*--------------------------------------------------------------*\
        !            28:  *  Include files, macros, defined constants, and externs       *
        !            29: \*--------------------------------------------------------------*/
        !            30: #include <os2.h>
        !            31: #include <stdlib.h>
        !            32: #include "img_main.h"
        !            33: #include "img_xtrn.h"
        !            34: #include "img_dlg.h"
        !            35: 
        !            36: /*--------------------------------------------------------------*\
        !            37:  *  Static variables                                            *
        !            38: \*--------------------------------------------------------------*/
        !            39: /* foreground/background color choices */
        !            40: LONG  lColorArray[COLOR_COUNT] = {CLR_BLACK,
        !            41:                                   CLR_WHITE,
        !            42:                                   CLR_BLUE,
        !            43:                                   CLR_GREEN,
        !            44:                                   CLR_YELLOW,
        !            45:                                   CLR_RED};
        !            46: 
        !            47: /****************************************************************\
        !            48:  *  Switch Modes (Non-Detail <-> Detail) procedure
        !            49:  *--------------------------------------------------------------
        !            50:  *
        !            51:  *  Name:   ViewSwitchMode()
        !            52:  *
        !            53:  *  Purpose: Toggles the mode of the application from Non-Detail
        !            54:  *           to Detail mode and visa versa
        !            55:  *
        !            56:  *  Usage:  Routine is called whenever a WM_COMMAND message
        !            57:  *          is posted to the main window in response to
        !            58:  *          the user (de)selecting the Detail item
        !            59:  *          from the View submenu
        !            60:  *
        !            61:  *  Method: Since Non-Detail mode is the opposite to Detail mode
        !            62:  *          toggle the menu settings, and ownership of the
        !            63:  *          scrollbars, and redraw. If entering Detail mode
        !            64:  *          it is necessary to size the main window aswell.
        !            65:  *
        !            66:  *  Returns:
        !            67:  *
        !            68: \****************************************************************/
        !            69: VOID ViewSwitchMode()
        !            70: {
        !            71: 
        !            72:     vfDetail = !vfDetail;
        !            73: 
        !            74:    /*
        !            75:     * detach/attach scrollbars to main window accordingly
        !            76:     */
        !            77:     WinSetParent(vhwndVScroll,
        !            78:                  vfDetail ? vhwndFrame : HWND_OBJECT,
        !            79:                  FALSE);
        !            80:     WinSetParent(vhwndHScroll,
        !            81:                  vfDetail ? vhwndFrame : HWND_OBJECT,
        !            82:                  FALSE);
        !            83: 
        !            84:     WinSendMsg(vhwndFrame,
        !            85:                WM_UPDATEFRAME,
        !            86:                MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL),
        !            87:                0L);
        !            88: 
        !            89:     /* resize main window if in 'Detail' mode */
        !            90:     if (vfDetail)
        !            91:         SizeMainWindow();
        !            92: 
        !            93:     WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
        !            94: 
        !            95: }   /* ViewSwitchMode() */
        !            96: 
        !            97: /****************************************************************\
        !            98:  *  Change Color Routine
        !            99:  *--------------------------------------------------------------
        !           100:  *
        !           101:  *  Name:   ViewChangeColor()
        !           102:  *
        !           103:  *  Purpose: To change the foreground/background colors of the
        !           104:  *           selected image
        !           105:  *
        !           106:  *  Usage:  Routine is called whenever a WM_COMMAND message
        !           107:  *          is posted to the main window in response to
        !           108:  *          the user selecting a Color item from either the
        !           109:  *          'Foreground'/'Background' Color items on the View submenu
        !           110:  *
        !           111:  *  Method:
        !           112:  *
        !           113:  *  Returns:
        !           114:  *
        !           115: \****************************************************************/
        !           116: VOID ViewChangeColor(idColor)
        !           117: USHORT idColor;
        !           118: {
        !           119:     LONG lForeClr, lBackClr;
        !           120:     BOOL fSameClr;
        !           121:     USHORT idItem;
        !           122: 
        !           123:    /*
        !           124:     * change either the foreground/background color and save
        !           125:     * previous settings so that the appropriate menuitem can
        !           126:     * be reset
        !           127:     */
        !           128:     if (idColor < IDM_VIEWBACKCOLORBLACK) {
        !           129:         lForeClr = lColorArray[idColor - COLOR_BASE];
        !           130:         fSameClr = (lForeClr == vlBackClr);
        !           131:         idItem = MenuGetColorItemId(IDM_VIEWFORECOLORBLACK);
        !           132:     } else {
        !           133:         lBackClr = lColorArray[idColor - COLOR_BASE - COLOR_COUNT];
        !           134:         fSameClr = (lBackClr == vlForeClr);
        !           135:         idItem = MenuGetColorItemId(IDM_VIEWBACKCOLORBLACK);
        !           136:     }
        !           137:    /*
        !           138:     * if background color is the same as the foreground color
        !           139:     * - ensure this is correct and get out if not
        !           140:     */
        !           141:     if (fSameClr) {
        !           142:         if (MessageBox(vhwndFrame,
        !           143:                        IDMSG_BACKEQFORE, IDMSG_WARNING,
        !           144:                        MB_APPLMODAL | MB_YESNO | MB_CUAWARNING,
        !           145:                        TRUE) == MBID_NO)
        !           146:             return;
        !           147:     }
        !           148: 
        !           149:     /* cancel previously checked item  & save new values */
        !           150:     if (idColor < IDM_VIEWBACKCOLORBLACK) {
        !           151:         MenuCheckItem(vhwndViewForeClr, idItem, FALSE);
        !           152:         vlForeClr = lForeClr;
        !           153:     } else {
        !           154:         MenuCheckItem(vhwndViewBackClr, idItem, FALSE);
        !           155:         vlBackClr = lBackClr;
        !           156:     }
        !           157: 
        !           158:    /*
        !           159:     * set colors appropriately and force redraw
        !           160:     */
        !           161:     GpiSetBackColor(vhps, vlBackClr);
        !           162:     GpiSetColor(vhps, vlForeClr);
        !           163:     GpiSetBackMix(vhps, BM_OVERPAINT);
        !           164:     WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
        !           165: 
        !           166: }   /* ViewChangeColor() */
        !           167: 
        !           168: /****************************************************************\
        !           169:  *  Restore Image Position Routine
        !           170:  *--------------------------------------------------------------
        !           171:  *
        !           172:  *  Name:   ViewRestorePosition()
        !           173:  *
        !           174:  *  Purpose: To restore the saved position of the image
        !           175:  *
        !           176:  *  Usage:  Routine is called whenever a WM_COMMAND message
        !           177:  *          is posted to the main window in response to
        !           178:  *          the user selecting the Restore Position item or the
        !           179:  *          from the View submenu
        !           180:  *
        !           181:  *  Method:
        !           182:  *
        !           183:  *  Returns:
        !           184:  *
        !           185: \****************************************************************/
        !           186: VOID ViewRestorePosition()
        !           187: {
        !           188:     RECTL rcl;
        !           189: 
        !           190:     /* only valid if image is loaded & in Detail mode */
        !           191:     if (vfImgLoaded && vfDetail) {
        !           192:         WinQueryWindowRect(vhwndClient, &rcl);
        !           193:         GpiSetCurrentPosition(vhps, &vptlSave);
        !           194:         WinSendMsg(vhwndVScroll,
        !           195:                    SBM_SETPOS,
        !           196:                    MPFROMLONG(vptlSave.y - rcl.yTop),
        !           197:                    0L);
        !           198:         WinSendMsg(vhwndHScroll,
        !           199:                    SBM_SETPOS,
        !           200:                    MPFROMLONG(labs(vptlSave.x)),
        !           201:                    0L);
        !           202:         WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
        !           203:     }
        !           204: 
        !           205: }   /* ViewRestorePosition() */
        !           206: 
        !           207: /****************************************************************\
        !           208:  *  Save Image Position Routine
        !           209:  *--------------------------------------------------------------
        !           210:  *
        !           211:  *  Name:   ViewSavePosition()
        !           212:  *
        !           213:  *  Purpose: To save the current position of the image
        !           214:  *
        !           215:  *  Usage:  Routine is called whenever a WM_COMMAND message
        !           216:  *          is posted to the main window in response to
        !           217:  *          the user selecting the Save Position item or the
        !           218:  *          from the View submenu
        !           219:  *
        !           220:  *  Method:
        !           221:  *
        !           222:  *  Returns:
        !           223:  *
        !           224: \****************************************************************/
        !           225: VOID ViewSavePosition()
        !           226: {
        !           227:     if (vfImgLoaded && vfDetail)
        !           228:         GpiQueryCurrentPosition(vhps, &vptlSave);
        !           229: 
        !           230: }   /* ViewSavePosition() */

unix.superglobalmegacorp.com

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