|
|
Microsoft OS/2 SDK 2.0 05-30-1990
/*==============================================================*\
* Vmm_pnt.c - routines for the painting of the main window *
* Created 1990, Microsoft, IBM Corp. *
*--------------------------------------------------------------*
* *
* This module contains the code for the main client window *
* painting *
* *
*--------------------------------------------------------------*
* *
* This source file contains the following functions: *
* *
* MainPaint(hwnd) - main WM_PAINT processing routine *
* *
\*==============================================================*/
/*--------------------------------------------------------------*\
* Include files, macros, defined constants, and externs *
\*--------------------------------------------------------------*/
#define LINT_ARGS
#define INCL_WIN
#define INCL_GPI
#define INCL_DOSPROCESS
#include <os2.h>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "vmm_main.h"
#include "vmm_xtrn.h"
/* size and positioning of boxes in 0.1 millimeters (PU_LOMETRIC) */
#define BOX_WIDTH 450
#define BOX_HEIGHT 180
#define VERT_INDENT 30
#define HORZ_INDENT 30
#define SMALL_BOX_HEIGHT 90
#define HORZ_SPACING 50
#define VERT_SPACING 50
#define VERT_TEXT_POS 90 /* distance from top of window to display text info */
#define TOP_MARGIN 110
/*--------------------------------------------------------------*\
* Global variables *
\*--------------------------------------------------------------*/
ULONG clrForeground = CLR_NEUTRAL; /* color for window text */
ULONG clrBackground = CLR_BACKGROUND; /* color for window background */
CHAR szWindowText[MAXTEXTLEN] = "Sample"; /* text drawn in window */
extern ULONG ulFreePage; /* First free page entry in array */
extern PAGEENTRY apgentry[]; /* Application page table */
/*--------------------------------------------------------------*\
* Entry point declarations *
\*--------------------------------------------------------------*/
VOID DisplayPage(HPS hps, PPOINTL pptl, ULONG ulPageIndex)
{
POINTL ptl;
MATRIXLF matrix;
ULONG ulAccess;
ULONG ulRegionSize;
PVOID pMem;
char szBuffer[BUFF_SIZE];
pMem = apgentry[ulPageIndex].pvAddress;
/* We don't check the return code here since we assume that the array
contains good addresses since we verified them when we put them in
the array. */
DosQueryMem(pMem, &ulRegionSize, &ulAccess);
matrix.fxM11 = MAKEFIXED(1,0);
matrix.fxM12 = 0L;
matrix.lM13 = 0L;
matrix.fxM21 = 0L;
matrix.fxM22 = MAKEFIXED(1,0);
matrix.lM23 = 0L;
matrix.lM31 = pptl->x; /* x translation */
matrix.lM32 = pptl->y; /* y translation */
matrix.lM33 = 1L;
if (GpiSetDefaultViewMatrix(hps, 9L, &matrix,TRANSFORM_REPLACE) == GPI_ERROR)
{
/* We're in trouble here ??????????????????? */
}
ptl.x = 0L;
ptl.y = 0L;
GpiMove(hps, &ptl);
ptl.x = BOX_WIDTH;
ptl.y = BOX_HEIGHT;
/* set outline color to CLR_RED for uncommitted, CLR_GREEN for
committed */
if (ulAccess & PAG_COMMIT)
{
GpiSetColor(hps, CLR_GREEN);
}
else
{
GpiSetColor(hps, CLR_RED);
}
GpiBox(hps, DRO_OUTLINE, &ptl, 0L, 0L);
/* should query sys values in case the default is not black ? */
GpiSetColor(hps, CLR_BLACK);
szBuffer[0]='\000';
if (ulAccess & PAG_READ)
{
strcat(szBuffer, "R");
}
if (ulAccess & PAG_WRITE)
{
strcat(szBuffer, "W");
}
if (ulAccess & PAG_EXECUTE)
{
strcat(szBuffer, "E");
}
if (ulAccess & PAG_GUARD)
{
strcat(szBuffer, "G");
}
if (ulAccess & PAG_DEFAULT)
{
strcat(szBuffer, "Def");
}
if (ulAccess & PAG_BASE)
{
strcat(szBuffer, "Base");
}
ptl.x = HORZ_INDENT;
ptl.y = VERT_INDENT;
GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuffer), szBuffer);
ptl.x = 0;
ptl.y = SMALL_BOX_HEIGHT;
GpiMove(hps, &ptl);
ptl.x = BOX_WIDTH;
ptl.y = SMALL_BOX_HEIGHT;
GpiLine(hps, &ptl);
/* Get base address of current page */
sprintf(szBuffer, "0x%p", pMem);
ptl.x = HORZ_INDENT;
ptl.y = SMALL_BOX_HEIGHT+VERT_INDENT;
GpiCharStringAt(hps, &ptl, (LONG) strlen(szBuffer), szBuffer);
}
/****************************************************************\
* Main client painting routine *
*--------------------------------------------------------------*
* *
* Name: MainPaint(hwnd) *
* *
* Purpose: Paints the main client window. *
* *
* Usage: Routine is called whenver the client window *
* procedure receives a WM_PAINT message *
* *
* Method: *
* - begins painting by calling WinBeginPaint *
* and retriving the HPS for the window *
* *
* - paint page info boxes *
* *
* - ends painting by calling WinEndPaint *
* *
* Returns: *
* *
\****************************************************************/
VOID MainPaint(hwnd)
HWND hwnd; /* handle of the window to be painted */
{
HPS hps;
USHORT i;
POINTL ptl;
RECTL rect;
SIZEL sizl;
char szBuffer[BUFF_SIZE];
sizl.cx = 0L;
sizl.cy = 0L;
hps = WinBeginPaint(hwnd, NULL, NULL);
GpiSetPS(hps, &sizl, PU_LOMETRIC); /* set PS to a device
independent mapping mode */
WinQueryWindowRect(hwnd, &rect);
/* ?????????????????????????????????????????? */
WinFillRect(hps, &rect, CLR_BACKGROUND); /* This should be done by
properly handling the
WM_ERASEBACKGROUND message */
/* convert the coords of the window to world coords */
GpiConvert(hps, CVTC_DEVICE, CVTC_WORLD, 2L, (PPOINTL) &rect);
ptl.x = HORZ_INDENT;
ptl.y = rect.yTop-VERT_TEXT_POS;
strcpy(szBuffer,"Border color: Green=Committed page,"
" Red=Non-committed page");
GpiCharStringAt(hps, &ptl, strlen(szBuffer), szBuffer);
ptl.x = HORZ_INDENT;
ptl.y = rect.yTop-BOX_HEIGHT-TOP_MARGIN;
for (i=0; i<ulFreePage; i++)
{
DisplayPage(hps, &ptl, i);
ptl.x += BOX_WIDTH+HORZ_SPACING;
/* If the next page is a base page, display it on a new line
for clarity */
if (apgentry[i+1].fBaseAddr)
{
ptl.x = HORZ_INDENT;
ptl.y -= (BOX_HEIGHT+VERT_SPACING);
}
}
WinEndPaint(hps);
} /* MainPaint() */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.