home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / contro.zip / SHADOWX.C < prev    next >
Text File  |  1994-12-26  |  7KB  |  238 lines

  1.  
  2. #define INCL_WIN
  3. #define INCL_GPI
  4. #define INCL_DOS
  5.  
  6. /* Presentation Manager include file  */
  7. #include <os2.h>
  8.  
  9.  
  10. #include <stdlib.h>
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <memory.h>
  14. #include <math.h>
  15.  
  16. /*
  17.  * Include C GPF User Control API header file
  18.  */
  19.  
  20. #include "GpfUC.h"
  21.  
  22. /* application specific header file */
  23. #include "shadowx.h"
  24.  
  25. /* function prototypes of everything in this file */
  26. PUCC APIENTRY RegisterShadowx( VOID );
  27. MRESULT EXPENTRY fnwpShadowx(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
  28.  
  29. /*************************************************/
  30. PUCC APIENTRY RegisterShadowx( VOID )
  31. {
  32. HAB    hab;
  33. static UCC Ucc;
  34.  
  35.   hab = WinInitialize(0);
  36.   /**********************************************/
  37.   /*    Register the window class "Shadowx".     */
  38.   /**********************************************/
  39.   WinRegisterClass(        /* Register window class    */
  40.       hab,            /* Anchor block handle        */
  41.       "SHADOWX",        /* Window class name (Upper)*/
  42.       fnwpShadowx,        /* Address window procedure */
  43.       CS_SAVEBITS      |     /* Class style          */
  44.       CS_HITTEST      |     /* Class style          */
  45.       CS_SIZEREDRAW   |     /* Class style          */
  46.       CS_SYNCPAINT,     /* Class style      */
  47.       EXTRAWORDS        /* Extra window words, instance-specific */
  48.       );
  49.   Ucc.Capability = GPF_CAPS_TEXT | GPF_CAPS_PRESPARAMS | GPF_CAPS_EXTENDED;
  50.  
  51.   Ucc.WsStyle     = WS_VISIBLE | WS_SYNCPAINT | WS_SAVEBITS;
  52.   /* set some arbitrary default size, used by the TRACKRECT */
  53.   Ucc.Cx     = 120;
  54.   Ucc.Cy     = 32;
  55.  
  56.   /* return this structure to Gpf so it can start control placement and */
  57.   /* open the default dialog. The default dialog will return the text.  */
  58.   return (&Ucc);
  59.  }
  60.  
  61.  
  62. /******************************************************/
  63. MRESULT EXPENTRY fnwpShadowx(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  64. {
  65. HPS    hps;            /* Presentation Space handle     */
  66. RECTL    rcl;            /* Window rectangle          */
  67. ULONG    Color;
  68. PCREATESTRUCT pCrst;    /* data type(s) defined by OS/2 PM    */
  69. PUCPARAMS pUC, pUcExt; /* typedef'd in shadowx.h */
  70.  
  71.   /**********************************************/
  72.   /* Initialize Control                         */
  73.   /**********************************************/
  74.   pUC = (PVOID) WinQueryWindowULong(hwnd,EXTRA_SHADOW);
  75.   /* this will be a NULL pointer until WM_CREATE is processed */
  76.  
  77.   if (!pUC)
  78.       {
  79.        if (msg != WM_CREATE)
  80.       return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  81.       }
  82.  
  83.   switch(msg)
  84.   {
  85.     /*
  86.      * Query Dialog Code
  87.      */
  88.     case WM_QUERYDLGCODE:
  89.         return( (MRESULT) DLGC_STATIC ); /* Static item */
  90.     break;
  91.  
  92.     /*
  93.      * HitTest
  94.      */
  95.     case WM_HITTEST:
  96.         return( (MRESULT) HT_TRANSPARENT);
  97.     break;
  98.  
  99.     /*
  100.      * Let frame control erase background for us
  101.      */
  102.     case WM_ERASEBACKGROUND:
  103.         /* The client window is cleared to SYSCLR_WINDOW. */
  104.         return (MRESULT)(FALSE); /*  No background windows. */
  105.  
  106.     /*
  107.      * The window needs painting
  108.      */
  109.     case WM_PAINT:
  110.         if(pUC->fOverride == FALSE){
  111.             /* Set Default BackGroundColor and ForeGroundColor */
  112.             pUC->BgColor = CLR_PALEGRAY;
  113.             if (WinQueryPresParam(hwnd,
  114.                         PP_BACKGROUNDCOLOR,0,
  115.                         0,4L,&Color,0))
  116.                 pUC->BgColor = Color;
  117.             if (WinQueryPresParam(hwnd,0,
  118.                         PP_BACKGROUNDCOLORINDEX,
  119.                         0,4L,&Color,QPF_ID1COLORINDEX))
  120.                 pUC->BgColor = Color;
  121.  
  122.             pUC->FgColor = CLR_PALEGRAY;
  123.             if (WinQueryPresParam(hwnd,
  124.                         PP_FOREGROUNDCOLOR,0,
  125.                         0,4L,&Color,0))
  126.                 pUC->FgColor = Color;
  127.             if (WinQueryPresParam(hwnd,0,
  128.                         PP_FOREGROUNDCOLORINDEX,
  129.                         0,4L,&Color,QPF_ID1COLORINDEX))
  130.                 pUC->FgColor = Color;
  131.             }
  132.  
  133.  
  134.         hps = WinBeginPaint( hwnd, (HPS)0, (PRECTL)&rcl );
  135.         Paint(hwnd,hps, pUC);        /* do detailed painting */
  136.         WinEndPaint( hps );         /* Release cache PS   */
  137.         break;
  138.  
  139.     /*
  140.      * The application has asked for the control to be created.
  141.      */
  142.     case WM_CREATE:
  143.         pCrst= (PCREATESTRUCT) mp2;
  144.         pUcExt= (PUCPARAMS) mp1; /* pCrst->pCtlData; */
  145.         pUC = (PUCPARAMS)malloc(sizeof(UCPARAMS)+8);
  146.         if(pUcExt != NULL){
  147.             memcpy(pUC,pUcExt, sizeof(UCPARAMS));
  148.             }
  149.         else{
  150.             pUC->LeftColor= CLR_WHITE;
  151.             pUC->RightColor= CLR_BLACK;
  152.             }
  153.         strncpy(pUC->chText, pCrst->pszText, MAX_SHADOW_TEXT);
  154.         *(pUC->chText+MAX_SHADOW_TEXT-1)= 0; /* defensive programming, make PSZ */
  155.         WinSetWindowPtr(hwnd,EXTRA_SHADOW,pUC);
  156.         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  157.  
  158.     /*
  159.      * The application has asked for the control to be destroyed.
  160.      */
  161.     case WM_DESTROY:
  162.         WinSetWindowULong(hwnd,EXTRA_SHADOW,(ULONG)0);
  163.         free(pUC);         /* release pointer/mem  */
  164.         break;
  165.  
  166.  
  167.     /*
  168.      * All other messages are passed to the default procedure.
  169.      */
  170.     default:
  171.     /* Pass all other messages to the default window procedure */
  172.         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
  173.   }
  174.   return ((MRESULT) FALSE);
  175. }
  176. /* End of window procedure - WinProc: fnwpShadowx                  */
  177.  
  178.  
  179. /***********************************************************/
  180. VOID Paint(HWND hwnd, HPS hps, PUCPARAMS pUc) {
  181. HAB    hab;
  182. RECTL    rect;
  183. SIZEF    sizef;
  184. SHORT    usLen, usCharWidth;
  185. POINTL ptl;
  186. DOUBLE tangent;
  187. static FATTRS    Font = {
  188.         sizeof(FATTRS),0,0L,
  189.         "Tms Rmn",0,0,0L,0L,0,FATTR_FONTUSE_NOMIX};
  190.  
  191.     hab= WinQueryAnchorBlock(hwnd);
  192.     DosBeep(400,100);
  193.     DosBeep(800,100);
  194.     DosBeep(1600,100);
  195.  
  196.  
  197.     WinQueryWindowRect(hwnd, &rect );
  198.     WinFillRect(hps, &rect, pUc->BgColor);
  199.     WinInflateRect(hab,&rect,-1,-1);
  200.     GpiSetCharMode(hps,CM_MODE2);
  201.  
  202.     tangent= tan(((DOUBLE)pUc->sAngle*3.1416)/180.0);
  203.     ptl.y=200;
  204.     ptl.x= 200 * tangent;
  205.     GpiSetCharShear(hps,&ptl);
  206.  
  207.     usLen= max(1,strlen(pUc->chText));    /* make sure this is never zero  */
  208.     /* the character width will probably be too small (based on "W") */
  209.     usCharWidth= (rect.xRight - rect.xLeft)/usLen;
  210.     /* so we will guess at using ~150% of the min value */
  211.     sizef.cx = MAKEFIXED(11*usCharWidth/6,0);
  212.     /* make character height as tall as box sized by user */
  213.     /* if no descenders are used, text will float above box bottom */
  214.     sizef.cy = MAKEFIXED((rect.yTop-rect.yBottom),0);
  215.     GpiSetCharBox ( hps, &sizef );    /* set the 'cell' width */
  216.     /* we will always load, then unload, the required font */
  217.     GpiCreateLogFont(hps,(PSTR8)"EmptyName",MY_FONT_ID,&Font);
  218.     GpiSetCharSet(hps,MY_FONT_ID);
  219.     /* now draw text in three different places, slightly offset from */
  220.     /* each other and vary the foreground color. Slick. */
  221.     WinOffsetRect(hab,&rect,-1,+1);
  222.     /* first, shadow on left (sunny) side */
  223.     WinDrawText(hps,usLen,pUc->chText,&rect,pUc->LeftColor,pUc->BgColor,
  224.         DT_CENTER | DT_BOTTOM);
  225.     WinOffsetRect(hab,&rect,+2,-2);
  226.     /* next, dark shadow on right side */
  227.     WinDrawText(hps,usLen,pUc->chText,&rect,pUc->RightColor,pUc->BgColor,
  228.         DT_CENTER | DT_BOTTOM);
  229.     WinOffsetRect(hab,&rect,-1,+1);
  230.     /* superimpose the character bodies */
  231.     WinDrawText(hps,usLen,pUc->chText,&rect,pUc->FgColor,pUc->BgColor,
  232.         DT_CENTER | DT_BOTTOM);
  233.  
  234.     GpiSetCharSet(hps,0L);
  235.     GpiDeleteSetId(hps, MY_FONT_ID);
  236. }
  237.  
  238.