home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / status.zip / UFSTAT.C < prev    next >
Text File  |  1995-04-20  |  15KB  |  528 lines

  1. #define INCL_PM
  2. #define INCL_GPI
  3.  
  4. #include <os2.h>
  5.  
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9.  
  10. #include "status.ext"
  11. #include "status.ids"
  12. #include "status.h"
  13.  
  14. #include "clr_bits.h"
  15.  
  16. PFNWP    OldFrameProc;
  17.  
  18. STATPARMS stparms={
  19.     26, 3, TRUE, TRUE, TRUE, CLR_PALEGRAY, CLR_BLUE,
  20.     CLR_BLACK, CLR_DARKGRAY, CLR_WHITE, DT_CENTER, "Hi"};
  21.  
  22. VOID PaintFancy(HWND, HPS, PSTATPARMS);
  23.  
  24. /**************************************************************/
  25. /* this window proc is for a window created during UfMainCreate */
  26. /* It has a pre-defined global handle 'hwndStatus' in status.h */
  27. MRESULT EXPENTRY StatusProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  28. {
  29. PSTATPARMS pStat= NULL;
  30.  
  31.     /* avoid getting a NULL pointer. OS/2 doesn't like them! */
  32.     if(msg != WM_CREATE)
  33.         pStat=(PSTATPARMS)WinQueryWindowULong(hwnd,QWL_USER);
  34.     else
  35.         pStat= &stparms;
  36.     if(!pStat)
  37.         pStat= &stparms;
  38.  
  39.     switch(msg){
  40.         case WM_USER_SETVAL:
  41.             switch((SHORT)mp1){
  42.                 case ST_SIZESHADOW:
  43.                     pStat->usShadow= (SHORT)mp2;
  44.                     pStat->height=
  45.                         pStat->usTextAreaHeight + 2*pStat->usShadow;
  46.                     WinSendMsg(
  47.                         WinQueryWindow(hwnd, QW_PARENT),
  48.                         WM_UPDATEFRAME,0L,0L);
  49.                     break;
  50.                 case ST_BORDER:
  51.                     pStat->fBorder= (BOOL)mp2;
  52.                     break;
  53.                 case ST_INOUT:
  54.                     pStat->f3DOut= (BOOL)mp2;
  55.                     break;
  56.                 case ST_TEXTCOLOR:
  57.                     pStat->TextColor= (LONG)mp2;
  58.                     break;
  59.                 case ST_BORDERCOLOR:
  60.                     pStat->BorderColor= (LONG)mp2;
  61.                     break;
  62.                 case ST_BACKCOLOR:
  63.                     pStat->BackColor= (LONG)mp2;
  64.                     break;
  65.                 case ST_SHADOWDARKCOLOR:
  66.                     pStat->ShadowDark= (LONG)mp2;
  67.                     break;
  68.                 case ST_SHADOWLIGHTCOLOR:
  69.                     pStat->ShadowLight= (LONG)mp2;
  70.                     break;
  71.                 case ST_TEXTALIGN:
  72.                     pStat->usAlign= (USHORT)mp2;
  73.                     break;
  74.                 case ST_POSITION:
  75.                     pStat->fTop= (BOOL)mp2;
  76.                     WinSendMsg(
  77.                         WinQueryWindow(hwnd, QW_PARENT),
  78.                         WM_UPDATEFRAME,0L,0L);
  79.                     break;
  80.                 }
  81.             WinInvalidateRect(hwnd, NULL, FALSE);
  82.             break;
  83.         case WM_USER_SETTEXT:
  84.             {
  85.             HPS hps;
  86.             RECTL rcl;
  87.             if( strlen((PSZ)mp1) >= STAT_TEXT_LEN )
  88.                 *(((PSZ)mp1)+STAT_TEXT_LEN -1) = 0;
  89.             strcpy(pStat->achText, (PSZ)mp1);
  90.             WinQueryWindowRect(hwnd, &rcl);
  91.             /* shrink 'rcl' so as not to paint the shadow/border */
  92.             rcl.yBottom += pStat->usShadow;
  93.             rcl.yTop -= pStat->usShadow;
  94.             rcl.xLeft += (pStat->usShadow+5);
  95.             rcl.xRight -= (pStat->usShadow+5);
  96.             hps= WinGetPS(hwnd);
  97.             WinDrawText(
  98.                 hps, -1, pStat->achText, &rcl,pStat->TextColor,
  99.                 pStat->BackColor,pStat->usAlign | DT_VCENTER | DT_ERASERECT);
  100.             WinReleasePS(hps);
  101.             }
  102.             break;
  103.         case WM_CONTEXTMENU:
  104.             ShowStatParms((PVOID)NULL);
  105.             break;
  106.         case WM_PAINT:
  107.             {
  108.             RECTL    rcl;
  109.             HPS     hps;
  110.             WinQueryWindowRect(hwnd, &rcl);
  111.             /* shrink 'rcl' so as not to paint the shadow/border */
  112.             rcl.yBottom += pStat->usShadow;
  113.             rcl.yTop -= pStat->usShadow;
  114.             /* keep the text away from the edges */
  115.             rcl.xLeft += (pStat->usShadow+5);
  116.             rcl.xRight -= (pStat->usShadow+5);
  117.             hps= WinBeginPaint(hwnd, NULLHANDLE, NULL);
  118.             GpiErase(hps);
  119.             PaintFancy(hwnd,hps,pStat);
  120.             WinDrawText(
  121.                 hps, -1, pStat->achText, &rcl,pStat->TextColor,CLR_NEUTRAL,
  122.                 pStat->usAlign | DT_VCENTER );
  123.             WinEndPaint(hps);
  124.             }
  125.             break;
  126.         case WM_SETWINDOWPARAMS:
  127.         {PWNDPARAMS pwp;
  128.             pwp= (PWNDPARAMS)mp1;
  129.             if(pwp->fsStatus != WPM_TEXT)
  130.                 break;
  131.             if(pwp->cchText >= STAT_TEXT_LEN)
  132.                 return (MRESULT) 2;
  133.             strcpy(pStat->achText, pwp->pszText);
  134.             WinInvalidateRect(hwnd, NULL, FALSE);
  135.         }
  136.             break;
  137.         case WM_ERASEBACKGROUND:
  138.             return (MRESULT) TRUE;
  139.         default:
  140.             return WinDefWindowProc(hwnd,msg,mp1,mp2);
  141.         }
  142.  
  143.     return (MRESULT) FALSE;
  144. }
  145.  
  146. /**************************************************************/
  147. MRESULT EXPENTRY NewFrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
  148. {
  149.     switch(msg){
  150.         case WM_QUERYFRAMECTLCOUNT:
  151.             return (MRESULT)((LONG)(OldFrameProc(hwnd,msg,mp1,mp2))+1);
  152.  
  153.         case WM_FORMATFRAME:{
  154.             PSWP    aswp;
  155.             SWP     swp;
  156.             LONG    clSwps;
  157.             PSTATPARMS pStat;
  158.  
  159.             pStat=(PSTATPARMS)WinQueryWindowULong(hwndStatus,QWL_USER);
  160.             clSwps= (LONG)OldFrameProc(hwnd,msg,mp1,mp2);
  161.             aswp= mp1;
  162.             clSwps--;    /* index to FID_CLIENT, always last in list */
  163.             swp= aswp[clSwps];    /* make copy of CLIENT data */
  164.             aswp[clSwps].fl= SWP_MOVE | SWP_SIZE | SWP_SHOW;
  165.             aswp[clSwps].cx= swp.cx;
  166.             aswp[clSwps].cy= pStat->height;
  167.             aswp[clSwps].x= swp.x;
  168.             switch(pStat->fTop){
  169.                 case FALSE:
  170.                     aswp[clSwps].y= swp.y;
  171.                     swp.y += pStat->height; /* raise the CLIENT */
  172.                     break;
  173.                 default:
  174.                 case TRUE:
  175.                     aswp[clSwps].y= (swp.y+swp.cy) - pStat->height;
  176.                     break;
  177.                 /* may add other stuff, like on the left/right side? */
  178.                 }
  179.             aswp[clSwps].hwnd= hwndStatus;
  180.             aswp[clSwps].hwndInsertBehind= NULLHANDLE;
  181.             aswp[clSwps].ulReserved1= 0;
  182.             aswp[clSwps].ulReserved2= 0;
  183.  
  184.             clSwps++;
  185.             swp.cy -= pStat->height;    /* shrink the CLIENT area */
  186.             aswp[clSwps]= swp;    /* copy client to list end */
  187.             clSwps++;
  188.             return (MRESULT) clSwps;
  189.             }
  190.         default:
  191.             return OldFrameProc(hwnd,msg,mp1,mp2);
  192.         }
  193. }
  194.  
  195. /**************************************************************/
  196. VOID UfMainCreate(PGPFPARMS pGpf)
  197. {
  198. HWND            hwndFrame;
  199. PSTATPARMS     pStat;
  200. FONTMETRICS    fm;
  201. HPS            hps;
  202.  
  203.     hwndFrame= GpfGetHwndFrame(pGpf->hwnd);
  204.  
  205.     WinRegisterClass(
  206.         habMainTask,
  207.         "StatusLine",
  208.         (PFNWP)StatusProc,
  209.         CS_SIZEREDRAW,
  210.         4);
  211.  
  212.     hwndStatus= WinCreateWindow(
  213.         hwndFrame,
  214.         "StatusLine",
  215.         NULL,
  216.         0L,
  217.         0,0,0,0,
  218.         hwndFrame,
  219.         HWND_BOTTOM,
  220.         STATUS_FID,
  221.         (PVOID)NULL,
  222.         (PVOID)NULL);
  223.  
  224.     pStat= (PSTATPARMS) malloc(LEN_STATPARMS);
  225.     *pStat= stparms;
  226.     hps= WinGetPS(hwndFrame);
  227.     GpiQueryFontMetrics(hps, (LONG)sizeof fm, &fm);
  228.     WinReleasePS(hps);
  229.     pStat->usTextAreaHeight= (4*fm.lMaxBaselineExt)/3;
  230.     pStat->height=    pStat->usTextAreaHeight + 2*pStat->usShadow;
  231.     strcpy(pStat->achText,"Default Message");
  232.     WinSetWindowULong(hwndStatus, QWL_USER, (ULONG)pStat);
  233.     OldFrameProc= WinSubclassWindow(hwndFrame, NewFrameProc);
  234. }
  235.  
  236.  
  237. /**************************************************************/
  238. /**************************************************************/
  239. VOID PaintFancy(HWND hwnd, HPS hps, PSTATPARMS pStat)
  240. {
  241. POINTL pt;
  242. RECTL    rcl;
  243. SHORT    i;
  244. SHORT    Pixel;
  245. LONG    TopLeftColor, BotRightColor;
  246. LONG    MarkHiColor, MarkLoColor;
  247. /*********************************************************************/
  248. /*  Set Default BackGroundColor and ForeGroundColor             */
  249. /*********************************************************************/
  250.  
  251.  
  252.     WinQueryWindowRect(hwnd, &rcl);
  253.     WinFillRect(hps,&rcl,pStat->BackColor);  /* Fill Rect         */
  254.  
  255.     GpiSetBackMix( hps, BM_LEAVEALONE);
  256.     GpiSetBackColor( hps, pStat->BackColor );
  257.     GpiSetLineType(hps,LINETYPE_DEFAULT);
  258.  
  259.     Pixel= pStat->usShadow;
  260.  
  261.     if (!pStat->f3DOut)
  262.        {
  263.         TopLeftColor = pStat->ShadowDark;
  264.         BotRightColor = pStat->ShadowLight;
  265.         MarkHiColor = CLR_BLACK;
  266.         MarkLoColor = CLR_DARKGRAY;
  267.  
  268.        }
  269.     else
  270.        {
  271.         TopLeftColor = pStat->ShadowLight;
  272.         BotRightColor = pStat->ShadowDark;
  273.         MarkHiColor = CLR_DARKGRAY;
  274.         MarkLoColor = CLR_BLACK;
  275.        }
  276.  
  277. /* Top */
  278.      GpiSetColor( hps, TopLeftColor );
  279.      for (i=0;i<Pixel;i++){
  280.         pt.x = rcl.xLeft;
  281.         pt.y = rcl.yTop-i-1;
  282.         GpiMove(hps,&pt);
  283.         pt.x = rcl.xRight-i-1;
  284.         GpiLine(hps,&pt);
  285.         }
  286. /* Bot */
  287.      GpiSetColor( hps, BotRightColor );
  288.      for (i=0;i<Pixel;i++){
  289.         pt.x = rcl.xLeft+i;
  290.         pt.y = rcl.yBottom+i;
  291.         GpiMove(hps,&pt);
  292.         pt.x = rcl.xRight;
  293.         GpiLine(hps,&pt);
  294.         }
  295. /* Left */
  296.      GpiSetColor( hps, TopLeftColor );
  297.      for (i=0;i<Pixel;i++){
  298.         pt.x = rcl.xLeft+i;
  299.         pt.y = rcl.yBottom+i;
  300.         GpiMove(hps,&pt);
  301.         pt.y = rcl.yTop;
  302.         GpiLine(hps,&pt);
  303.         }
  304. /* Right */
  305.      GpiSetColor( hps, BotRightColor );
  306.      for (i=0;i<Pixel;i++){
  307.         pt.x = rcl.xRight-i-1;
  308.         pt.y = rcl.yTop-i-1;
  309.         GpiMove(hps,&pt);
  310.         pt.y = rcl.xLeft;
  311.         GpiLine(hps,&pt);
  312.         }
  313.  
  314.      if (Pixel > 1){
  315.         /* Top */
  316.         GpiSetColor( hps, MarkHiColor );
  317.         pt.x = rcl.xLeft+1;
  318.         pt.y = rcl.yTop-2;
  319.         GpiMove(hps,&pt);
  320.         pt.x = rcl.xLeft+(Pixel-1);
  321.         pt.y = rcl.yTop-(Pixel);
  322.         GpiLine(hps,&pt);
  323.         /* Bot */
  324.         GpiSetColor( hps, MarkLoColor );
  325.         pt.x = rcl.xRight-2;
  326.         pt.y = rcl.yBottom+1;
  327.         GpiMove(hps,&pt);
  328.         pt.x = rcl.xRight-(Pixel);
  329.         pt.y = rcl.yBottom+(Pixel-1);
  330.         GpiLine(hps,&pt);
  331.         }
  332.  
  333. /* Border */
  334.     if (pStat->fBorder)
  335.         WinDrawBorder( hps,&rcl,1L,1L,
  336.             pStat->BorderColor,
  337.             pStat->BorderColor,
  338.             DB_STANDARD );
  339.  
  340. }
  341. /*********************************************************************/
  342. /*********************************************************************/
  343. VOID UfStatParmsEndSpin(PGPFPARMS pGpf)
  344. {
  345. ULONG ulTmp=0;
  346.  
  347.     WinSendDlgItemMsg(
  348.         pGpf->hwnd,ID_STAT_SB_SIZE,SPBM_QUERYVALUE,
  349.         MPFROMP(&ulTmp),MPFROM2SHORT(0,SPBQ_ALWAYSUPDATE));
  350.     WinSendMsg(
  351.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(ST_SIZESHADOW),MPFROMLONG(ulTmp));
  352.  
  353. }
  354. /*********************************************************************/
  355. /*********************************************************************/
  356. VOID UfStatParmsFonts(PGPFPARMS pGpf)
  357. {
  358. PFONTDLG    pfdlg;
  359. HWND    hwndFont;
  360. CHAR    szFontName[FACESIZE];
  361. PSTATPARMS pStat;
  362.  
  363.     pStat= (PSTATPARMS) WinQueryWindowULong(hwndStatus, QWL_USER);
  364.  
  365.     pfdlg= &pStat->fdlg;
  366.  
  367.     memset(pfdlg, 0, sizeof(FONTDLG));
  368.     pfdlg->cbSize= sizeof(FONTDLG);
  369.     pfdlg->hpsScreen= WinGetPS(pGpf->hwnd);
  370.     szFontName[0]=0;
  371.     pfdlg->pszFamilyname= szFontName;
  372.     pfdlg->usFamilyBufLen= FACESIZE;
  373.     pfdlg->fxPointSize= MAKEFIXED(10,0);
  374.     pfdlg->fl= FNTS_CENTER | FNTS_INITFROMFATTRS;
  375.     pfdlg->clrFore= CLR_BLACK;
  376.     pfdlg->clrBack= CLR_WHITE;
  377.     pfdlg->fAttrs.usCodePage= 437;
  378.     pfdlg->fAttrs.usRecordLength= sizeof(FATTRS);
  379.  
  380.     hwndFont= WinFontDlg(HWND_DESKTOP, pGpf->hwnd, pfdlg);
  381.  
  382.     if(hwndFont && (pfdlg->lReturn == DID_OK)){
  383.         DosBeep(3000,300);
  384.         }
  385.     WinReleasePS(pfdlg->hpsScreen);
  386. }
  387. /*********************************************************************/
  388. /*********************************************************************/
  389. VOID UfStatParmsCbx(PGPFPARMS pGpf)
  390. {
  391. SHORT    sVal;
  392. SHORT    sIndex;
  393. SHORT    sId;
  394. LONG    lColor;
  395.  
  396.     sId= SHORT1FROMMP(pGpf->mp1);
  397.  
  398.     switch( sId ){
  399.         case ID_STAT_CBX_TEXTCOLOR:
  400.             sVal= ST_TEXTCOLOR;
  401.             break;
  402.         case ID_STAT_CBX_BORDERCOLOR:
  403.             sVal= ST_BORDERCOLOR;
  404.             break;
  405.         case ID_STAT_CBX_BACKCOLOR:
  406.             sVal= ST_BACKCOLOR;
  407.             break;
  408.         case ID_STAT_CBX_DARKSHADOW:
  409.             sVal= ST_SHADOWDARKCOLOR;
  410.             break;
  411.         case ID_STAT_CBX_LITESHADOW:
  412.             sVal= ST_SHADOWLIGHTCOLOR;
  413.             break;
  414.         default:
  415.             return;
  416.         }
  417.     sIndex= (SHORT)WinSendDlgItemMsg(
  418.         hwndStatParms,sId,LM_QUERYSELECTION,MPFROMSHORT(0),0L);
  419.  
  420.     lColor= aSysClr[sIndex].lSysVal;
  421.  
  422.     WinSendMsg(
  423.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(sVal),MPFROMLONG(lColor));
  424. }
  425. /*********************************************************************/
  426. /*********************************************************************/
  427. VOID UfStatParmsInit(PGPFPARMS pGpf)
  428. {
  429. SHORT i=0;
  430.  
  431.     while( aSysClr[i].lSysVal != 0xfff0L){
  432.         WinSendDlgItemMsg(
  433.             pGpf->hwnd,ID_STAT_CBX_TEXTCOLOR,LM_INSERTITEM,
  434.             MPFROMSHORT(LIT_END), MPFROMP(aSysClr[i].pszSysVal));
  435.         WinSendDlgItemMsg(
  436.             pGpf->hwnd,ID_STAT_CBX_BORDERCOLOR,LM_INSERTITEM,
  437.             MPFROMSHORT(LIT_END), MPFROMP(aSysClr[i].pszSysVal));
  438.         WinSendDlgItemMsg(
  439.             pGpf->hwnd,ID_STAT_CBX_BACKCOLOR,LM_INSERTITEM,
  440.             MPFROMSHORT(LIT_END), MPFROMP(aSysClr[i].pszSysVal));
  441.         WinSendDlgItemMsg(
  442.             pGpf->hwnd,ID_STAT_CBX_DARKSHADOW,LM_INSERTITEM,
  443.             MPFROMSHORT(LIT_END), MPFROMP(aSysClr[i].pszSysVal));
  444.         WinSendDlgItemMsg(
  445.             pGpf->hwnd,ID_STAT_CBX_LITESHADOW,LM_INSERTITEM,
  446.             MPFROMSHORT(LIT_END), MPFROMP(aSysClr[i].pszSysVal));
  447.         i++;
  448.         }
  449.  
  450.     /* display default values in COMBO entry field */
  451.     WinSendDlgItemMsg(
  452.         pGpf->hwnd,ID_STAT_CBX_TEXTCOLOR,LM_SELECTITEM,
  453.         MPFROMSHORT(6), MPFROMSHORT(TRUE)); /* CLR_BLUE */
  454.     WinSendDlgItemMsg(
  455.         pGpf->hwnd,ID_STAT_CBX_BORDERCOLOR,LM_SELECTITEM,
  456.         MPFROMSHORT(4), MPFROMSHORT(TRUE)); /* CLR_BLACK */
  457.     WinSendDlgItemMsg(
  458.         pGpf->hwnd,ID_STAT_CBX_BACKCOLOR,LM_SELECTITEM,
  459.         MPFROMSHORT(20), MPFROMSHORT(TRUE));    /* CLR_PALEGRAY */
  460.     WinSendDlgItemMsg(
  461.         pGpf->hwnd,ID_STAT_CBX_DARKSHADOW,LM_SELECTITEM,
  462.         MPFROMSHORT(13), MPFROMSHORT(TRUE));    /* CLR_DARKGRAY */
  463.     WinSendDlgItemMsg(
  464.         pGpf->hwnd,ID_STAT_CBX_LITESHADOW,LM_SELECTITEM,
  465.         MPFROMSHORT(3), MPFROMSHORT(TRUE)); /* CLR_WHITE */
  466.  
  467.     WinSendDlgItemMsg(
  468.         pGpf->hwnd,ID_STAT_SB_SIZE,SPBM_SETLIMITS,
  469.         MPFROMLONG(10L),MPFROMLONG(0L));
  470.     WinSendDlgItemMsg(
  471.         pGpf->hwnd,ID_STAT_SB_SIZE,SPBM_SETCURRENTVALUE,
  472.         MPFROMLONG(3L),MPFROMLONG(0L));
  473. }
  474. /*********************************************************************/
  475. /*********************************************************************/
  476. VOID UfStatParmsPBOut(PGPFPARMS pGpf)
  477. {
  478.     pGpf= pGpf;
  479.     WinSendMsg(
  480.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(ST_INOUT),MPFROMSHORT(TRUE));
  481.  
  482. }
  483. /*********************************************************************/
  484. /*********************************************************************/
  485. VOID UfStatParmsPBIn(PGPFPARMS pGpf)
  486. {
  487.     pGpf= pGpf;
  488.     WinSendMsg(
  489.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(ST_INOUT),MPFROMSHORT(FALSE));
  490.  
  491. }
  492. /*********************************************************************/
  493. /*********************************************************************/
  494. VOID UfStatParmsCBBorder(PGPFPARMS pGpf)
  495. {
  496.     WinSendMsg(
  497.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(ST_BORDER),
  498.         (MPARAM)WinQueryButtonCheckstate(pGpf->hwnd,ID_STAT_CB_BORDER));
  499. }
  500.  
  501. /*********************************************************************/
  502. /*********************************************************************/
  503. VOID UfStatParmsCBTop(PGPFPARMS pGpf)
  504. {
  505.     WinSendMsg(
  506.         hwndStatus,WM_USER_SETVAL,MPFROMSHORT(ST_POSITION),
  507.         (MPARAM)WinQueryButtonCheckstate(pGpf->hwnd,ID_STAT_CB_TOP));
  508. }
  509.  
  510. /*********************************************************************/
  511. /*********************************************************************/
  512. VOID UfStatTextAlign(USHORT AlignFlag)
  513. {
  514.     WinSendMsg(
  515.         hwndStatus,WM_USER_SETVAL,
  516.         MPFROMSHORT(ST_TEXTALIGN),MPFROMSHORT(AlignFlag));
  517. }
  518. /*********************************************************************/
  519. /*********************************************************************/
  520. VOID UfStatPBSend(PGPFPARMS pGpf)
  521. {
  522. CHAR    achTemp[STAT_TEXT_LEN];
  523.  
  524.     WinQueryDlgItemText(pGpf->hwnd,ID_MAIN_EF_MSG,STAT_TEXT_LEN,achTemp);
  525.     WinSetWindowText(hwndStatus, achTemp);
  526.  
  527. }
  528.