home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
contro.zip
/
SHADOW.C
< prev
next >
Wrap
Text File
|
1994-12-18
|
7KB
|
221 lines
#define INCL_WIN
#define INCL_GPI
/* Presentation Manager include file */
#include <os2.h>
/*
* Include C library routine header files
*/
#include <stdlib.h> /* Miscellaneous function declarations */
#include <stdio.h> /* Declarations for standard I/O routines */
#include <string.h> /* String function declarations */
#include <memory.h> /* Declarations for memory manipulation */
/*
* Include C GPF API User Control header files
*/
#include "GpfUC.h"
/* function prototypes of everything in this file */
PUCC APIENTRY RegisterShadow( VOID );
MRESULT EXPENTRY fnwpShadow(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
VOID Paint(HWND, HPS, PSZ);
#define EXTRAWORDS (4 * sizeof(PVOID))
/*************************************************/
PUCC APIENTRY RegisterShadow( VOID )
{
HAB hab;
static UCC Ucc;
hab = WinInitialize(0);
/**********************************************/
/* Register the window class "Shadow". */
/**********************************************/
WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
"SHADOW", /* Window class name (Upper)*/
fnwpShadow, /* 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;
Ucc.WsStyle = WS_VISIBLE;
/* set some arbitrary default size, used by the TRACKRECT */
Ucc.Cx = 120;
Ucc.Cy = 32;
/* return this structure to Gpf so it can start placement and */
/* open the default dialog. The default dialog will return the text. */
return (&Ucc);
}
#define EXTRA_SHADOW 8
/******************************************************/
MRESULT EXPENTRY fnwpShadow(
HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
HPS hps; /* Presentation Space handle */
RECTL rcl; /* Window rectangle */
ULONG BorderColor,Color;
ULONG BackGroundColor;
PSZ pShadow; /* we will allocate memory for this */
PCREATESTRUCT pCrst; /* data type(s) defined by OS/2 PM */
/**********************************************/
/* Initialize Control Parameters */
/**********************************************/
pShadow = (PVOID) WinQueryWindowULong(hwnd,0);
if (!pShadow)
{
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:
/* Set Default BackGroundColor and ForeGroundColor */ BackGroundColor = CLR_PALEGRAY;
/* Query and Save Presentation Parameters BackGroundColor */
if (WinQueryPresParam(hwnd,
PP_BACKGROUNDCOLOR,0,
0,4L,&Color,0))
BackGroundColor = Color;
/* Query and Save Presentation Parameters BG Color Index */
if (WinQueryPresParam(hwnd,0,
PP_BACKGROUNDCOLORINDEX,
0,4L,&Color,QPF_ID1COLORINDEX))
BackGroundColor = Color;
/* Set Default BorderColor */
/* BorderColor = BackGroundColor; */
BorderColor = CLR_BLACK;
/* Query and Save Presentation Parameters BackGroundColor */
if (WinQueryPresParam(hwnd,
PP_BORDERCOLOR,0,
0,4L,&Color,0))
BorderColor = Color;
/* Query and Save Presentation Parameters BG Color Index */
if (WinQueryPresParam(
hwnd,0,
PP_BORDERCOLORINDEX,
0,4L,&Color,QPF_ID1COLORINDEX))
BorderColor = Color;
hps = WinBeginPaint( hwnd, (HPS)0, (PRECTL)&rcl );
WinFillRect(hps,&rcl,BackGroundColor);
Paint(hwnd,hps, pShadow); /* 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;
pShadow = (PSZ)malloc(64); /* Set Pointer */
strncpy(pShadow, pCrst->pszText, 63);
*(pShadow+63)= 0; /* defensive programming, make PSZ */
WinSetWindowPtr(hwnd,0,pShadow);
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(pShadow); /* 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: fnwpShadow */
#define MY_FONT_ID 10 /* any old number will do */
/***********************************************************/
VOID Paint(HWND hwnd, HPS hps, PSZ psz) {
HAB hab;
RECTL rect;
SIZEF sizef;
SHORT usLen, usCharWidth;
static FATTRS Font = {
sizeof(FATTRS),0,0L,
"Tms Rmn",0,0,0L,0L,0,FATTR_FONTUSE_NOMIX};
hab= WinQueryAnchorBlock(hwnd);
WinQueryWindowRect(hwnd, &rect );
WinFillRect(hps, &rect, CLR_PALEGRAY);
WinInflateRect(hab,&rect,-1,-1);
GpiSetCharMode(hps,CM_MODE2);
usLen= max(1,strlen(psz)); /* 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,psz,&rect,CLR_WHITE,CLR_PALEGRAY,
DT_CENTER | DT_BOTTOM);
WinOffsetRect(hab,&rect,+2,-2);
/* next, dark shadow on right side */
WinDrawText(hps,usLen,psz,&rect,CLR_BLACK,CLR_PALEGRAY,
DT_CENTER | DT_BOTTOM);
WinOffsetRect(hab,&rect,-1,+1);
/* superimpose the character bodies */
WinDrawText(hps,usLen,psz,&rect,CLR_PALEGRAY,CLR_PALEGRAY,
DT_CENTER | DT_BOTTOM);
GpiSetCharSet(hps,0L);
GpiDeleteSetId(hps, MY_FONT_ID);
}