home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
contro.zip
/
SHADOWX.C
< prev
next >
Wrap
Text File
|
1994-12-26
|
7KB
|
238 lines
#define INCL_WIN
#define INCL_GPI
#define INCL_DOS
/* Presentation Manager include file */
#include <os2.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <math.h>
/*
* Include C GPF User Control API header file
*/
#include "GpfUC.h"
/* application specific header file */
#include "shadowx.h"
/* function prototypes of everything in this file */
PUCC APIENTRY RegisterShadowx( VOID );
MRESULT EXPENTRY fnwpShadowx(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/*************************************************/
PUCC APIENTRY RegisterShadowx( VOID )
{
HAB hab;
static UCC Ucc;
hab = WinInitialize(0);
/**********************************************/
/* Register the window class "Shadowx". */
/**********************************************/
WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
"SHADOWX", /* Window class name (Upper)*/
fnwpShadowx, /* Address window procedure */
CS_SAVEBITS | /* Class style */
CS_HITTEST | /* Class style */
CS_SIZEREDRAW | /* Class style */
CS_SYNCPAINT, /* Class style */
EXTRAWORDS /* Extra window words, instance-specific */
);
Ucc.Capability = GPF_CAPS_TEXT | GPF_CAPS_PRESPARAMS | GPF_CAPS_EXTENDED;
Ucc.WsStyle = WS_VISIBLE | WS_SYNCPAINT | WS_SAVEBITS;
/* set some arbitrary default size, used by the TRACKRECT */
Ucc.Cx = 120;
Ucc.Cy = 32;
/* return this structure to Gpf so it can start control placement and */
/* open the default dialog. The default dialog will return the text. */
return (&Ucc);
}
/******************************************************/
MRESULT EXPENTRY fnwpShadowx(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
HPS hps; /* Presentation Space handle */
RECTL rcl; /* Window rectangle */
ULONG Color;
PCREATESTRUCT pCrst; /* data type(s) defined by OS/2 PM */
PUCPARAMS pUC, pUcExt; /* typedef'd in shadowx.h */
/**********************************************/
/* Initialize Control */
/**********************************************/
pUC = (PVOID) WinQueryWindowULong(hwnd,EXTRA_SHADOW);
/* this will be a NULL pointer until WM_CREATE is processed */
if (!pUC)
{
if (msg != WM_CREATE)
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
switch(msg)
{
/*
* Query Dialog Code
*/
case WM_QUERYDLGCODE:
return( (MRESULT) DLGC_STATIC ); /* Static item */
break;
/*
* HitTest
*/
case WM_HITTEST:
return( (MRESULT) HT_TRANSPARENT);
break;
/*
* Let frame control erase background for us
*/
case WM_ERASEBACKGROUND:
/* The client window is cleared to SYSCLR_WINDOW. */
return (MRESULT)(FALSE); /* No background windows. */
/*
* The window needs painting
*/
case WM_PAINT:
if(pUC->fOverride == FALSE){
/* Set Default BackGroundColor and ForeGroundColor */
pUC->BgColor = CLR_PALEGRAY;
if (WinQueryPresParam(hwnd,
PP_BACKGROUNDCOLOR,0,
0,4L,&Color,0))
pUC->BgColor = Color;
if (WinQueryPresParam(hwnd,0,
PP_BACKGROUNDCOLORINDEX,
0,4L,&Color,QPF_ID1COLORINDEX))
pUC->BgColor = Color;
pUC->FgColor = CLR_PALEGRAY;
if (WinQueryPresParam(hwnd,
PP_FOREGROUNDCOLOR,0,
0,4L,&Color,0))
pUC->FgColor = Color;
if (WinQueryPresParam(hwnd,0,
PP_FOREGROUNDCOLORINDEX,
0,4L,&Color,QPF_ID1COLORINDEX))
pUC->FgColor = Color;
}
hps = WinBeginPaint( hwnd, (HPS)0, (PRECTL)&rcl );
Paint(hwnd,hps, pUC); /* do detailed painting */
WinEndPaint( hps ); /* Release cache PS */
break;
/*
* The application has asked for the control to be created.
*/
case WM_CREATE:
pCrst= (PCREATESTRUCT) mp2;
pUcExt= (PUCPARAMS) mp1; /* pCrst->pCtlData; */
pUC = (PUCPARAMS)malloc(sizeof(UCPARAMS)+8);
if(pUcExt != NULL){
memcpy(pUC,pUcExt, sizeof(UCPARAMS));
}
else{
pUC->LeftColor= CLR_WHITE;
pUC->RightColor= CLR_BLACK;
}
strncpy(pUC->chText, pCrst->pszText, MAX_SHADOW_TEXT);
*(pUC->chText+MAX_SHADOW_TEXT-1)= 0; /* defensive programming, make PSZ */
WinSetWindowPtr(hwnd,EXTRA_SHADOW,pUC);
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
/*
* The application has asked for the control to be destroyed.
*/
case WM_DESTROY:
WinSetWindowULong(hwnd,EXTRA_SHADOW,(ULONG)0);
free(pUC); /* release pointer/mem */
break;
/*
* All other messages are passed to the default procedure.
*/
default:
/* Pass all other messages to the default window procedure */
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return ((MRESULT) FALSE);
}
/* End of window procedure - WinProc: fnwpShadowx */
/***********************************************************/
VOID Paint(HWND hwnd, HPS hps, PUCPARAMS pUc) {
HAB hab;
RECTL rect;
SIZEF sizef;
SHORT usLen, usCharWidth;
POINTL ptl;
DOUBLE tangent;
static FATTRS Font = {
sizeof(FATTRS),0,0L,
"Tms Rmn",0,0,0L,0L,0,FATTR_FONTUSE_NOMIX};
hab= WinQueryAnchorBlock(hwnd);
DosBeep(400,100);
DosBeep(800,100);
DosBeep(1600,100);
WinQueryWindowRect(hwnd, &rect );
WinFillRect(hps, &rect, pUc->BgColor);
WinInflateRect(hab,&rect,-1,-1);
GpiSetCharMode(hps,CM_MODE2);
tangent= tan(((DOUBLE)pUc->sAngle*3.1416)/180.0);
ptl.y=200;
ptl.x= 200 * tangent;
GpiSetCharShear(hps,&ptl);
usLen= max(1,strlen(pUc->chText)); /* make sure this is never zero */
/* the character width will probably be too small (based on "W") */
usCharWidth= (rect.xRight - rect.xLeft)/usLen;
/* so we will guess at using ~150% of the min value */
sizef.cx = MAKEFIXED(11*usCharWidth/6,0);
/* make character height as tall as box sized by user */
/* if no descenders are used, text will float above box bottom */
sizef.cy = MAKEFIXED((rect.yTop-rect.yBottom),0);
GpiSetCharBox ( hps, &sizef ); /* set the 'cell' width */
/* we will always load, then unload, the required font */
GpiCreateLogFont(hps,(PSTR8)"EmptyName",MY_FONT_ID,&Font);
GpiSetCharSet(hps,MY_FONT_ID);
/* now draw text in three different places, slightly offset from */
/* each other and vary the foreground color. Slick. */
WinOffsetRect(hab,&rect,-1,+1);
/* first, shadow on left (sunny) side */
WinDrawText(hps,usLen,pUc->chText,&rect,pUc->LeftColor,pUc->BgColor,
DT_CENTER | DT_BOTTOM);
WinOffsetRect(hab,&rect,+2,-2);
/* next, dark shadow on right side */
WinDrawText(hps,usLen,pUc->chText,&rect,pUc->RightColor,pUc->BgColor,
DT_CENTER | DT_BOTTOM);
WinOffsetRect(hab,&rect,-1,+1);
/* superimpose the character bodies */
WinDrawText(hps,usLen,pUc->chText,&rect,pUc->FgColor,pUc->BgColor,
DT_CENTER | DT_BOTTOM);
GpiSetCharSet(hps,0L);
GpiDeleteSetId(hps, MY_FONT_ID);
}