|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* img_view.c - routines for handling the View menu functions
* Created 1989, 1990 IBM, Microsoft Corp.
*--------------------------------------------------------------*
*
* This module contains the code for handling the functions
* offered on the View submenu. These functions are called
* from the MainCommand() routine.
*
*--------------------------------------------------------------*
*
* This source file contains the following functions:
*
* ViewSwitchMode()
* ViewChangeColor()
* ViewSavePosition()
* ViewRestorePosition()
*
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs *
\*--------------------------------------------------------------*/
#define INCL_WINSCROLLBARS
#define INCL_WINFRAMEMGR
#define INCL_GPIPRIMITIVES
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs *
\*--------------------------------------------------------------*/
#include <os2.h>
#include <stdlib.h>
#include "img_main.h"
#include "img_xtrn.h"
#include "img_dlg.h"
/*--------------------------------------------------------------*\
* Static variables *
\*--------------------------------------------------------------*/
/* foreground/background color choices */
LONG lColorArray[COLOR_COUNT] = {CLR_BLACK,
CLR_WHITE,
CLR_BLUE,
CLR_GREEN,
CLR_YELLOW,
CLR_RED};
/****************************************************************\
* Switch Modes (Non-Detail <-> Detail) procedure
*--------------------------------------------------------------
*
* Name: ViewSwitchMode()
*
* Purpose: Toggles the mode of the application from Non-Detail
* to Detail mode and visa versa
*
* Usage: Routine is called whenever a WM_COMMAND message
* is posted to the main window in response to
* the user (de)selecting the Detail item
* from the View submenu
*
* Method: Since Non-Detail mode is the opposite to Detail mode
* toggle the menu settings, and ownership of the
* scrollbars, and redraw. If entering Detail mode
* it is necessary to size the main window aswell.
*
* Returns:
*
\****************************************************************/
VOID ViewSwitchMode()
{
vfDetail = !vfDetail;
/*
* detach/attach scrollbars to main window accordingly
*/
WinSetParent(vhwndVScroll,
vfDetail ? vhwndFrame : HWND_OBJECT,
FALSE);
WinSetParent(vhwndHScroll,
vfDetail ? vhwndFrame : HWND_OBJECT,
FALSE);
WinSendMsg(vhwndFrame,
WM_UPDATEFRAME,
MPFROMLONG(FCF_VERTSCROLL | FCF_HORZSCROLL),
0L);
/* resize main window if in 'Detail' mode */
if (vfDetail)
SizeMainWindow();
WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
} /* ViewSwitchMode() */
/****************************************************************\
* Change Color Routine
*--------------------------------------------------------------
*
* Name: ViewChangeColor()
*
* Purpose: To change the foreground/background colors of the
* selected image
*
* Usage: Routine is called whenever a WM_COMMAND message
* is posted to the main window in response to
* the user selecting a Color item from either the
* 'Foreground'/'Background' Color items on the View submenu
*
* Method:
*
* Returns:
*
\****************************************************************/
VOID ViewChangeColor(idColor)
USHORT idColor;
{
LONG lForeClr, lBackClr;
BOOL fSameClr;
USHORT idItem;
/*
* change either the foreground/background color and save
* previous settings so that the appropriate menuitem can
* be reset
*/
if (idColor < IDM_VIEWBACKCOLORBLACK) {
lForeClr = lColorArray[idColor - COLOR_BASE];
fSameClr = (lForeClr == vlBackClr);
idItem = MenuGetColorItemId(IDM_VIEWFORECOLORBLACK);
} else {
lBackClr = lColorArray[idColor - COLOR_BASE - COLOR_COUNT];
fSameClr = (lBackClr == vlForeClr);
idItem = MenuGetColorItemId(IDM_VIEWBACKCOLORBLACK);
}
/*
* if background color is the same as the foreground color
* - ensure this is correct and get out if not
*/
if (fSameClr) {
if (MessageBox(vhwndFrame,
IDMSG_BACKEQFORE, IDMSG_WARNING,
MB_APPLMODAL | MB_YESNO | MB_CUAWARNING,
TRUE) == MBID_NO)
return;
}
/* cancel previously checked item & save new values */
if (idColor < IDM_VIEWBACKCOLORBLACK) {
MenuCheckItem(vhwndViewForeClr, idItem, FALSE);
vlForeClr = lForeClr;
} else {
MenuCheckItem(vhwndViewBackClr, idItem, FALSE);
vlBackClr = lBackClr;
}
/*
* set colors appropriately and force redraw
*/
GpiSetBackColor(vhps, vlBackClr);
GpiSetColor(vhps, vlForeClr);
GpiSetBackMix(vhps, BM_OVERPAINT);
WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
} /* ViewChangeColor() */
/****************************************************************\
* Restore Image Position Routine
*--------------------------------------------------------------
*
* Name: ViewRestorePosition()
*
* Purpose: To restore the saved position of the image
*
* Usage: Routine is called whenever a WM_COMMAND message
* is posted to the main window in response to
* the user selecting the Restore Position item or the
* from the View submenu
*
* Method:
*
* Returns:
*
\****************************************************************/
VOID ViewRestorePosition()
{
RECTL rcl;
/* only valid if image is loaded & in Detail mode */
if (vfImgLoaded && vfDetail) {
WinQueryWindowRect(vhwndClient, &rcl);
GpiSetCurrentPosition(vhps, &vptlSave);
WinSendMsg(vhwndVScroll,
SBM_SETPOS,
MPFROMLONG(vptlSave.y - rcl.yTop),
0L);
WinSendMsg(vhwndHScroll,
SBM_SETPOS,
MPFROMLONG(labs(vptlSave.x)),
0L);
WinInvalidateRect(vhwndClient, (PRECTL)NULL, FALSE);
}
} /* ViewRestorePosition() */
/****************************************************************\
* Save Image Position Routine
*--------------------------------------------------------------
*
* Name: ViewSavePosition()
*
* Purpose: To save the current position of the image
*
* Usage: Routine is called whenever a WM_COMMAND message
* is posted to the main window in response to
* the user selecting the Save Position item or the
* from the View submenu
*
* Method:
*
* Returns:
*
\****************************************************************/
VOID ViewSavePosition()
{
if (vfImgLoaded && vfDetail)
GpiQueryCurrentPosition(vhps, &vptlSave);
} /* ViewSavePosition() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.