|
|
Microsoft OS/2 SDK PM 08-08-1988
/****************************** Module Header ******************************\
* Module Name: FONTTEST.C
*
* Example of a simple OS/2 Presentation Manager application
*
* Created by Microsoft Corp., 1988
*
\***************************************************************************/
#define INCL_GPI
#define INCL_WIN
#define INCL_WINCOMMON
#define INCL_WINMESSAGEMGR
#include <os2.h>
#include <pmfont.h>
#include "fonttest.h"
#define LINT_ARGS
#include "string.h"
typedef BOOL FAR * LPBOOL;
HAB vhab;
HWND vhwndFTClient;
HWND vhwndFTFrame;
SHORT vcch;
FATTRS vfat;
FONTMETRICS vfm;
CHAR szAlphabet[CCHMAX];
CHAR szAppName[8];
typedef struct _FONTDATA {
LONG xShear;
LONG yShear;
LONG xAngle;
LONG yAngle;
} FONTDATA;
FATTRS DisplayList[MAXLINES];
FONTDATA DisplayData[MAXLINES];
SHORT BottomLine = 0;
SHORT TopLine = 0;
SHORT FontDesired = 0;
SHORT FontInUse = 0;
LONG FontsAvail = FONTSAVAIL;
FONTMETRICS fm[FONTSAVAIL];
/***************************** Public Function ****************************\
*
* Font Test Main procedure
*
* Effects: Set globals - vhab Handle to Application Anchor Block
*
* Warnings: None
*
\***************************************************************************/
int cdecl main( )
{
QMSG qmsg;
HMQ hmq;
CHAR szTitle[21];
HPS hps;
ULONG ctldata;
vhab = WinInitialize(NULL);
hmq = WinCreateMsgQueue( vhab, 0 );
WinLoadString( vhab, NULL, IDS_NAME, sizeof(szAppName), szAppName );
/* Register Application Window Class. Extra longword is used to
specify whether any string should be displayed and whether the
window should be redrawn. */
if ( !WinRegisterClass( vhab, szAppName, FonttestWndProc,
0L, sizeof(ULONG)) )
return( FALSE );
/* Create a window instance of class "FontTest" */
WinLoadString( vhab, NULL, IDS_TITLE, sizeof(szTitle), szTitle );
hps = WinGetPS(HWND_DESKTOP);
GpiQueryFontMetrics( hps, (LONG)sizeof(FONTMETRICS), &vfm );
WinReleasePS(hps);
vfat.usRecordLength = sizeof(FATTRS);
vfat.fsSelection = vfm.fsSelection;
vfat.lMatch = 0L;
vfat.fsType = vfm.fsType;
strcpy(vfat.szFaceName, vfm.szFacename);
vfat.idRegistry = 0;
vfat.usCodePage = vfm.usCodePage;
vfat.lMaxBaselineExt = vfm.lMaxBaselineExt;
vfat.lAveCharWidth = vfm.lAveCharWidth;
vfat.sQuality = FATTR_QUALITY_DEFAULT;
ctldata = FCF_STANDARD;
vhwndFTFrame = WinCreateStdWindow(
HWND_DESKTOP, /* specify desktop as parent window */
/* window styles */
WS_VISIBLE | FS_ICON | FS_ACCELTABLE,
&ctldata, /* frame creation flags */
szAppName, /* window class name */
szTitle, /* name appearing in window caption */
0L, /* client styles */
NULL, /* use current executable module id */
ID_FONTTEST, /* resource id */
&vhwndFTClient /* window handle */
);
vcch = WinLoadString( vhab, NULL, IDS_ALPHABET, CCHMAX, szAlphabet);
while( WinGetMsg( vhab, &qmsg, NULL, 0, 0 ) )
WinDispatchMsg( vhab, &qmsg );
WinDestroyWindow( vhwndFTFrame );
WinDestroyMsgQueue( hmq );
WinTerminate( vhab );
}
/***************************** Public Function ****************************\
*
* MRESULT EXPENTRY fnAboutDlg( hwndDlg, message, mp1, mp2 )
* HWND hwndDlg;
* USHORT message;
* ULONG mp1;
* ULONG mp2;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
MRESULT EXPENTRY fnAboutDlg( hwndDlg, message, mp1, mp2 )
HWND hwndDlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
switch( message )
{
case WM_COMMAND:
switch( SHORT1FROMMP( mp1 ) )
{
case DID_OK:
case DID_CANCEL:
WinDismissDlg( hwndDlg, TRUE );
break;
default:
return( (MRESULT)FALSE );
}
default:
return( WinDefDlgProc( hwndDlg, message, mp1, mp2 ) );
}
return( 0L );
}
/***************************** Private Function ****************************\
*
* VOID PASCAL RedrawScreen( hwnd, hps )
* HWND hwnd;
* HPS hps;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
VOID PASCAL RedrawScreen ( hwnd, hps )
HWND hwnd;
HPS hps;
{
POINTL ptl;
SHORT x;
CHARBUNDLE cb;
RECTL rcl;
SIZEF sizef;
POINTL pointl;
GRADIENTL gradientl;
cb.lColor = SYSCLR_WINDOWTEXT;
GpiSetAttrs(hps, PRIM_CHAR, CBB_COLOR, 0L, (PBUNDLE)&cb );
WinSetWindowULong ( hwnd, QWL_USER,
WinQueryWindowULong ( hwnd, QWL_USER ) &
(ULONG) ~ID_REDRAW );
/* Special case for initial state. */
if ( (TopLine == BottomLine) &&
(WinQueryWindowULong (hwnd, QWL_USER) & ID_SHOW) )
{
ShowSampleString ( hwnd, hps );
return;
}
ptl.x = 0L;
x = TopLine;
while ( x != BottomLine )
{
x = (x + MAXLINES - 1) % MAXLINES;
sizef.cx = DisplayList[x].lAveCharWidth * 65536;
sizef.cy = DisplayList[x].lMaxBaselineExt * 65536;
GpiSetCharBox ( hps, &sizef );
gradientl.x = DisplayData[x].xAngle;
gradientl.y = DisplayData[x].yAngle;
GpiSetCharAngle ( hps, &gradientl );
pointl.x = DisplayData[x].xShear;
pointl.y = DisplayData[x].yShear;
GpiSetCharShear ( hps, &pointl );
GpiCreateLogFont( hps, (PSTR8)szAppName, (LONG)ID_LCID, &DisplayList[x]);
GpiSetCharSet( hps, (LONG) ID_LCID );
GpiQueryFontMetrics( hps, (LONG)sizeof(FONTMETRICS), &vfm );
WinScrollWindow (hwnd, 0, (SHORT) vfm.lMaxBaselineExt, NULL, NULL, NULL,
&rcl, 0);
WinFillRect (hps, &rcl, SYSCLR_WINDOW);
ptl.y = vfm.lMaxDescender + 1;
GpiCharStringAt( hps, &ptl, (long)vcch, szAlphabet );
GpiSetCharSet ( hps, 0L );
GpiDeleteSetId ( hps, (LONG) ID_LCID );
}
}
/***************************** Private Function ****************************\
*
* VOID PASCAL ShowSampleString( hwnd, hps )
* HWND hwnd;
* HPS hps;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
VOID PASCAL ShowSampleString( hwnd, hps )
HWND hwnd;
HPS hps;
{
POINTL ptl;
CHARBUNDLE cb;
RECTL rcl;
SIZEF sizef;
GRADIENTL gradientl;
POINTL pointl;
GpiLoadFonts( vhab, (PSZ) "fonts" );
GpiQueryFonts ( hps, (ULONG) QUERY_PUBLIC_FONTS | QUERY_PRIVATE_FONTS,
NULL, &FontsAvail, (LONG) sizeof(FONTMETRICS), fm);
cb.lColor = SYSCLR_WINDOWTEXT;
GpiSetAttrs(hps, PRIM_CHAR, CBB_COLOR, 0L, (PBUNDLE)&cb );
if ( (0 <= FontDesired) && (FontDesired < (SHORT) FontsAvail) )
{
vfat.lMatch = fm[FontDesired].lMatch;
FontInUse = FontDesired;
}
else
vfat.lMatch = fm[FontInUse].lMatch;
sizef.cx = vfat.lAveCharWidth * 65536;
sizef.cy = vfat.lMaxBaselineExt * 65536;
GpiSetCharBox ( hps, &sizef );
gradientl.x = DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].xAngle;
gradientl.y = DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].yAngle;
GpiSetCharAngle ( hps, &gradientl );
pointl.x = DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].xShear;
pointl.y = DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].yShear;
GpiSetCharShear ( hps, &pointl );
GpiCreateLogFont( hps, (PSTR8) szAppName, (LONG) ID_LCID, &vfat );
BottomLine = (BottomLine + MAXLINES - 1) % MAXLINES;
/* Store the font attributes for the current line in the display list. */
DisplayList[BottomLine].usRecordLength = vfat.usRecordLength;
DisplayList[BottomLine].fsSelection = vfat.fsSelection;
DisplayList[BottomLine].lMatch = vfat.lMatch;
DisplayList[BottomLine].fsType = vfat.fsType;
DisplayList[BottomLine].idRegistry = vfat.idRegistry;
DisplayList[BottomLine].usCodePage = vfat.usCodePage;
DisplayList[BottomLine].lMaxBaselineExt = vfat.lMaxBaselineExt;
DisplayList[BottomLine].lAveCharWidth = vfat.lAveCharWidth;
DisplayList[BottomLine].sQuality = vfat.sQuality;
DisplayList[BottomLine].fsFontUse = vfat.fsFontUse;
strcpy ( DisplayList[BottomLine].szFaceName, vfat.szFaceName );
if ( TopLine == BottomLine )
TopLine = (TopLine + MAXLINES - 1) % MAXLINES;
GpiSetCharSet( hps, (LONG) ID_LCID );
GpiQueryFontMetrics( hps, (LONG)sizeof(FONTMETRICS), &vfm );
WinScrollWindow (hwnd, 0, (SHORT) vfm.lMaxBaselineExt, NULL, NULL, NULL,
&rcl, 0);
WinFillRect (hps, &rcl, SYSCLR_WINDOW);
ptl.y = vfm.lMaxDescender + 1;
ptl.x = 0L;
GpiCharStringAt( hps, &ptl, (long)vcch, szAlphabet );
GpiSetCharSet ( hps, 0L );
GpiDeleteSetId ( hps, (LONG) ID_LCID );
}
/***************************** Private Function ****************************\
*
* VOID PASCAL InitDlg( hps, hwndDlg )
* HPS hps;
* HWND hwndDlg;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
VOID PASCAL InitDlg( hdlg )
HWND hdlg;
{
if (vfat.fsSelection & FATTR_SEL_UNDERSCORE)
WinSendDlgItemMsg( hdlg, IDUNDERLINE, BM_SETCHECK,
MPFROM2SHORT(TRUE, 0), 0L );
if (vfat.fsSelection & FATTR_SEL_STRIKEOUT)
WinSendDlgItemMsg( hdlg, IDSTRIKEOUT, BM_SETCHECK,
MPFROM2SHORT(TRUE, 0), 0L );
if (vfat.fsSelection & FATTR_SEL_ITALIC)
WinSendDlgItemMsg( hdlg, IDITALIC, BM_SETCHECK,
MPFROM2SHORT(TRUE, 0), 0L );
if (vfat.fsType & FATTR_TYPE_FIXED)
WinSendDlgItemMsg( hdlg, IDPITCH, BM_SETCHECK,
MPFROM2SHORT(TRUE, 0), 0L );
WinSetDlgItemShort(hdlg, IDXSHEAR, 0, TRUE);
WinSetDlgItemShort(hdlg, IDYSHEAR, 1, TRUE);
WinSetDlgItemShort(hdlg, IDXANGLE, 1, TRUE);
WinSetDlgItemShort(hdlg, IDYANGLE, 0, TRUE);
WinSetDlgItemShort(hdlg, IDHEIGHT, (int)vfat.lMaxBaselineExt, TRUE);
WinSetDlgItemShort(hdlg, IDFMHEIGHT, (int)vfm.lEmHeight, TRUE);
WinSetDlgItemShort(hdlg, IDWIDTH, (int)vfat.lAveCharWidth, TRUE);
WinSetDlgItemShort(hdlg, IDFMWIDTH, (int)vfm.lAveCharWidth, TRUE);
WinSetDlgItemShort(hdlg, IDFMWEIGHT, (int)vfm.usWeightClass, TRUE);
WinSetDlgItemShort(hdlg, IDAVCHARWIDTH, (int)vfm.lAveCharWidth, TRUE);
WinSetDlgItemShort(hdlg, IDMAXCHARINC, (int)vfm.lMaxCharInc, TRUE);
WinSetDlgItemShort(hdlg, IDCODEPAGE, (int)vfat.usCodePage, TRUE);
WinSetDlgItemShort(hdlg, IDFMCODEPAGE, (int)vfm.usCodePage, TRUE);
WinSetDlgItemShort(hdlg, IDFONTDESIRED, FontDesired, TRUE);
WinSetDlgItemShort(hdlg, IDFONTINUSE, FontInUse, TRUE);
}
/***************************** Private Function ****************************\
*
* VOID PASCAL DlgCommand( hdlg, mp1 )
* HWND hdlg;
* ULONG mp1;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
VOID PASCAL DlgCommand( hdlg, mp1 )
HWND hdlg;
MPARAM mp1;
{
SHORT sTmp;
switch ( SHORT1FROMMP(mp1) )
{
case DID_OK:
if (WinSendDlgItemMsg( hdlg, IDITALIC, BM_QUERYCHECK, 0L, 0L))
vfat.fsSelection |= FATTR_SEL_ITALIC;
else
vfat.fsSelection &= ~FATTR_SEL_ITALIC;
if (WinSendDlgItemMsg( hdlg, IDUNDERLINE, BM_QUERYCHECK, 0L, 0L))
vfat.fsSelection |= FATTR_SEL_UNDERSCORE;
else
vfat.fsSelection &= ~FATTR_SEL_UNDERSCORE;
if (WinSendDlgItemMsg( hdlg, IDSTRIKEOUT, BM_QUERYCHECK, 0L, 0L))
vfat.fsSelection |= FATTR_SEL_STRIKEOUT;
else
vfat.fsSelection &= ~FATTR_SEL_STRIKEOUT;
WinQueryDlgItemShort(hdlg, IDWIDTH, &sTmp, TRUE);
vfat.lAveCharWidth = sTmp;
WinQueryDlgItemShort(hdlg, IDHEIGHT, &sTmp, TRUE);
vfat.lMaxBaselineExt = sTmp;
WinQueryDlgItemShort(hdlg, IDXSHEAR, &sTmp, TRUE);
DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].xShear = (LONG) sTmp;
WinQueryDlgItemShort(hdlg, IDYSHEAR, &sTmp, TRUE);
DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].yShear = (LONG) sTmp;
WinQueryDlgItemShort(hdlg, IDXANGLE, &sTmp, TRUE);
DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].xAngle = (LONG) sTmp;
WinQueryDlgItemShort(hdlg, IDYANGLE, &sTmp, TRUE);
DisplayData[(BottomLine+MAXLINES-1)%MAXLINES].yAngle = (LONG) sTmp;
if (WinSendDlgItemMsg( hdlg, IDPITCH, BM_QUERYCHECK, 0L, 0L))
vfat.fsType = FATTR_TYPE_FIXED;
else
vfat.fsType = 0;
WinQueryDlgItemShort(hdlg, IDCODEPAGE, &sTmp, TRUE);
vfat.usCodePage = sTmp;
WinQueryDlgItemShort(hdlg, IDFONTDESIRED, &sTmp, TRUE);
FontDesired = sTmp;
WinDismissDlg( hdlg, TRUE );
break;
case DID_CANCEL:
WinDismissDlg( hdlg, TRUE );
break;
default:
break;
}
}
/***************************** Public Function ****************************\
*
* MRESULT EXPENTRY fnOptionsDlg( hdlg, message, mp1, mp2 )
* HWND hdlg;
* USHORT message;
* ULONG mp1;
* ULONG mp2;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
MRESULT EXPENTRY fnOptionsDlg( hdlg, message, mp1, mp2 )
HWND hdlg;
USHORT message;
MPARAM mp1;
MPARAM mp2;
{
switch (message)
{
case WM_COMMAND:
DlgCommand( hdlg, mp1 );
break;
case WM_INITDLG:
InitDlg( hdlg );
break;
default:
return( WinDefDlgProc( hdlg, message, mp1, mp2 ) );
}
return( 0L );
}
/***************************** Private Function ****************************\
*
* VOID PASCAL FonttestCommand( hwnd, id )
* HWND hwnd;
* USHORT id;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
VOID PASCAL FonttestCommand( hwnd, id )
HWND hwnd;
USHORT id;
{
switch (id)
{
case IDM_SAMPLE:
/* Specify that the sample string should be displayed. */
WinSetWindowULong ( hwnd, QWL_USER, (ULONG) ID_SHOW);
WinInvalidateRect( hwnd, (PWRECT)NULL, TRUE );
WinUpdateWindow( hwnd );
break;
case IDM_CLEAR:
/* Specify that the sample string should not be displayed. */
WinSetWindowULong ( hwnd, QWL_USER, (ULONG) ID_NOSHOW);
WinInvalidateRect( hwnd, (PWRECT)NULL, TRUE );
WinUpdateWindow( hwnd );
break;
case IDM_OPTIONS:
WinDlgBox(HWND_DESKTOP, hwnd, fnOptionsDlg, NULL, IDD_OPTIONS, NULL);
break;
case IDM_ABOUT:
WinDlgBox( HWND_DESKTOP, hwnd, fnAboutDlg, NULL, IDD_ABOUT, NULL );
break;
default:
break;
}
}
/***************************** Public Function ****************************\
*
* MRESULT EXPENTRY FonttestWndProc( hwnd, msg, mp1, mp2 )
* HWND hwnd;
* USHORT msg;
* ULONG mp1;
* ULONG mp2;
*
* Effects: None
*
* Warnings: None
*
\***************************************************************************/
MRESULT EXPENTRY FonttestWndProc( hwnd, msg, mp1, mp2 )
HWND hwnd;
USHORT msg;
MPARAM mp1;
MPARAM mp2;
{
HPS hps;
RECTL rcl;
switch (msg)
{
case WM_CREATE:
/* Specify that the sample string should be displayed. */
WinSetWindowULong ( hwnd, QWL_USER, (ULONG) ID_SHOW);
break;
case WM_PAINT:
hps = WinBeginPaint( hwnd, NULL, &rcl );
if ( WinQueryWindowULong ( hwnd, QWL_USER ) & (ULONG) ID_REDRAW )
RedrawScreen ( hwnd, hps );
else
if ( WinQueryWindowULong (hwnd, QWL_USER) & (ULONG) ID_SHOW )
ShowSampleString( hwnd, hps );
else
{
TopLine = BottomLine;
WinFillRect (hps, &rcl, SYSCLR_WINDOW);
}
WinEndPaint( hps );
break;
case WM_CLOSE:
WinPostMsg( hwnd, WM_QUIT, 0L, 0L );;
break;
case WM_COMMAND:
FonttestCommand( hwnd, SHORT1FROMMP(mp1) );
break;
case WM_ERASEBACKGROUND:
WinSetWindowULong ( hwnd, QWL_USER,
WinQueryWindowULong( hwnd, QWL_USER ) | ID_REDRAW );
return (TRUE); /* Let frame control erase background. */
break;
default:
return (WinDefWindowProc( hwnd, msg, mp1, mp2 ) );
break;
}
return 0L;
}
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.