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

  1. #define INCL_DOS
  2. #define INCL_WIN
  3. #define INCL_GPI
  4.  
  5. /* Presentation Manager include file  */
  6. #include <os2.h>
  7.  
  8. /*
  9.  * Include C library routine header files
  10.  */
  11.  
  12. #include <stdlib.h>    /* Miscellaneous function declarations      */
  13. #include <stdio.h>     /* Declarations for standard I/O routines */
  14. #include <string.h>    /* String function declarations       */
  15. #include <memory.h>    /* Declarations for memory manipulation   */
  16.  
  17. /*
  18.  * Include C GPF API User Control header files
  19.  */
  20. #include "GpfUC.h"
  21.  
  22. #include "shadext.h"
  23. #include "shadowx.h"
  24.  
  25. /* prototypes */
  26. MRESULT EXPENTRY fnwpExtShadowx(HWND, ULONG, MPARAM, MPARAM);
  27.  
  28. struct{
  29.     ULONG    Color;
  30.     PSZ     Text;
  31.     } Colors[]={
  32.         CLR_WHITE,        "WHITE",
  33.         CLR_BLACK,        "BLACK",
  34.         CLR_RED,        "RED",
  35.         CLR_BLUE,        "BLUE",
  36.         CLR_GREEN,        "GREEN",
  37.         CLR_CYAN,        "CYAN",
  38.         CLR_YELLOW,     "YELLOW",
  39.         CLR_PALEGRAY,    "PALEGRAY",
  40.         CLR_PINK,        "PINK",
  41.         CLR_DARKGRAY,    "DARK GRAY",
  42.         CLR_DARKRED,    "DARK RED",
  43.         CLR_DARKBLUE,    "DARK BLUE",
  44.         CLR_DARKGREEN,    "DARK GREEN",
  45.         CLR_DARKCYAN,    "DARK CYAN",
  46.         CLR_BROWN,        "BROWN",
  47.         CLR_DARKPINK,    "DARK PINK",
  48.         0xffff,         ""};
  49.  
  50. static USHORT ComboID[]=
  51.     {ID_CBX_LEFT,ID_CBX_RIGHT,ID_CBX_FORE,ID_CBX_BACK,0};
  52.  
  53. /************************************************************/
  54. LONG APIENTRY ExtendedShadowx(LONG WsStyle, PVOID pCtlData)
  55. {
  56. HWND    hwndActive, hwndDlg;
  57. HMODULE hmod;
  58. UCHAR    tmp[256];
  59. APIRET rc;
  60.  
  61.  
  62.     hwndActive= WinQueryActiveWindow(HWND_DESKTOP);
  63.     rc= DosLoadModule(tmp, sizeof(tmp), "SHADOWX", (HMODULE *)&hmod);
  64.  
  65.     hwndDlg= WinDlgBox(
  66.         HWND_DESKTOP,    /* Parent             */
  67.         hwndActive,     /* Owner             */
  68.         fnwpExtShadowx, /* Address of dialog proc     */
  69.         hmod,            /* Module handle     */
  70.         ID_SHADEXT,     /* ID of dialog in resource  */
  71.         pCtlData);        /* Initialization data     */
  72.  
  73.  
  74.     return WsStyle;
  75.  
  76. }
  77.  
  78. /************************************************************/
  79. MRESULT EXPENTRY fnwpExtShadowx(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
  80. {
  81. LONG lSpinVal;
  82. SHORT i, j;
  83. USHORT Notify,Index,fAngle;
  84. static BOOL fCreate;
  85. static PUCPARAMS pUC;
  86. static HWND hwndSample;
  87. HPS hps;
  88. CHAR chSave;
  89.  
  90. switch (msg){
  91.     case WM_INITDLG:
  92.         fCreate= TRUE;
  93.         hwndSample= WinWindowFromID(hwnd,ID_SAMPLE);
  94.  
  95.         pUC= (PUCPARAMS) mp2;
  96.         if(pUC->cBytes != sizeof(UCPARAMS)){    /* has it been initialized? */
  97.             pUC->cBytes= sizeof(UCPARAMS);
  98.             pUC->BgIndex= 7;    /* CLR_PALEGRAY offset into struct "Colors" */
  99.             pUC->FgIndex= 7;
  100.             pUC->LeftIndex= 0;
  101.             pUC->LeftColor= CLR_WHITE;
  102.             pUC->RightIndex= 1;
  103.             pUC->RightColor= CLR_BLACK;
  104.             pUC->sAngle= 0;
  105.             pUC->fOverride= FALSE;
  106.             DosBeep(3000,500);
  107.             DosBeep(1500,500);
  108.             }
  109.  
  110.         if(!*pUC->chText)
  111.             strcpy(pUC->chText,"t");
  112.  
  113.         WinCheckButton(hwnd,ID_CB_OVERRIDE,pUC->fOverride);
  114.  
  115.         /* INIT SPIN BUTTONS */
  116.         WinSendDlgItemMsg(
  117.             hwnd,
  118.             ID_SB_ANGLE,
  119.             SPBM_SETLIMITS,
  120.             MPFROMLONG(30L),
  121.             MPFROMLONG(-30L));
  122.         WinSendDlgItemMsg(
  123.             hwnd,
  124.             ID_SB_ANGLE,
  125.             SPBM_SETCURRENTVALUE,
  126.             MPFROMLONG((LONG)pUC->sAngle),
  127.             0L);
  128.  
  129.         /* INIT COMBO BOXES */
  130.         for(i=0; i<4; i++)
  131.             WinSendDlgItemMsg(
  132.                 hwnd,
  133.                 ComboID[i],
  134.                 LM_DELETEALL,
  135.                 0L,0L);
  136.         for(i=0; Colors[i].Color != 0xffff; i++)
  137.             for(j=0; j<4; j++)
  138.                 WinSendDlgItemMsg(
  139.                     hwnd,
  140.                     ComboID[j],
  141.                     LM_INSERTITEM,
  142.                     MPFROMSHORT(LIT_END),
  143.                     MPFROMP(Colors[i].Text));
  144.  
  145.         WinSendDlgItemMsg(
  146.             hwnd,
  147.             ID_CBX_LEFT,
  148.             LM_SELECTITEM,
  149.             MPFROMSHORT(pUC->LeftIndex),
  150.             MPFROMSHORT(TRUE));
  151.         WinSendDlgItemMsg(
  152.             hwnd,
  153.             ID_CBX_RIGHT,
  154.             LM_SELECTITEM,
  155.             MPFROMSHORT(pUC->RightIndex),
  156.             MPFROMSHORT(TRUE));
  157.         WinSendDlgItemMsg(
  158.             hwnd,
  159.             ID_CBX_FORE,
  160.             LM_SELECTITEM,
  161.             MPFROMSHORT(pUC->FgIndex),
  162.             MPFROMSHORT(TRUE));
  163.         WinSendDlgItemMsg(
  164.             hwnd,
  165.             ID_CBX_BACK,
  166.             LM_SELECTITEM,
  167.             MPFROMSHORT(pUC->BgIndex),
  168.             MPFROMSHORT(TRUE));
  169.  
  170.         WinEnableWindow(WinWindowFromID(hwnd,ID_CBX_FORE),pUC->fOverride);
  171.         WinEnableWindow(WinWindowFromID(hwnd,ID_CBX_BACK),pUC->fOverride);
  172.  
  173.         fCreate= FALSE;
  174.         break;
  175.  
  176.     case WM_CONTROL:
  177.     case WM_COMMAND:
  178.         Notify= SHORT2FROMMP( mp1 );
  179.         switch( SHORT1FROMMP( mp1 ) ){
  180.             case ID_SB_ANGLE:
  181.                 if(Notify == SPBN_ENDSPIN){
  182.                     WinSendDlgItemMsg(
  183.                         hwnd,
  184.                         ID_SB_ANGLE,
  185.                         SPBM_QUERYVALUE,
  186.                         MPFROMP(&lSpinVal),
  187.                         MPFROM2SHORT(0,SPBQ_ALWAYSUPDATE));
  188.                     pUC->sAngle= (SHORT)lSpinVal;
  189.                     }
  190.                 else
  191.                     return FALSE;
  192.                 break;
  193.  
  194.             case ID_CB_OVERRIDE:
  195.                 pUC->fOverride=
  196.                     (BOOL)WinSendDlgItemMsg(
  197.                         hwnd,
  198.                         SHORT1FROMMP(mp1),
  199.                         BM_QUERYCHECK,
  200.                         0L,0L);
  201.                 WinEnableWindow(
  202.                     WinWindowFromID(hwnd,ID_CBX_FORE),
  203.                     pUC->fOverride);
  204.                 WinEnableWindow(
  205.                     WinWindowFromID(hwnd,ID_CBX_BACK),
  206.                     pUC->fOverride);
  207.                 break;
  208.  
  209.             case ID_CBX_LEFT:
  210.                 switch(Notify){
  211.                     case CBN_ENTER:
  212.                     case CBN_LBSELECT:
  213.                         Index=
  214.                         (SHORT)WinSendDlgItemMsg(
  215.                             hwnd,
  216.                             ID_CBX_LEFT,
  217.                             LM_QUERYSELECTION,
  218.                             MPFROMSHORT(0),
  219.                             0L);
  220.                         if(Index == LIT_NONE)
  221.                             return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  222.                         pUC->LeftIndex= Index;
  223.                         pUC->LeftColor= Colors[Index].Color;
  224.                         break;
  225.                     default:
  226.                         return FALSE;
  227.                     }
  228.                 break;
  229.             case ID_CBX_RIGHT:
  230.                 switch(Notify){
  231.                     case CBN_ENTER:
  232.                     case CBN_LBSELECT:
  233.                         Index=
  234.                         (SHORT)WinSendDlgItemMsg(
  235.                             hwnd,
  236.                             ID_CBX_RIGHT,
  237.                             LM_QUERYSELECTION,
  238.                             MPFROMSHORT(0),
  239.                             0L);
  240.                         if(Index == LIT_NONE)
  241.                             return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  242.                         pUC->RightIndex= Index;
  243.                         pUC->RightColor= Colors[Index].Color;
  244.                         break;
  245.                     default:
  246.                         return FALSE;
  247.                     }
  248.                 break;
  249.             case ID_CBX_FORE:
  250.                 switch(Notify){
  251.                     case CBN_ENTER:
  252.                     case CBN_LBSELECT:
  253.                         Index=
  254.                         (SHORT)WinSendDlgItemMsg(
  255.                             hwnd,
  256.                             ID_CBX_FORE,
  257.                             LM_QUERYSELECTION,
  258.                             MPFROMSHORT(0),
  259.                             0L);
  260.                         if(Index == LIT_NONE)
  261.                             return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  262.                         pUC->FgIndex= Index;
  263.                         pUC->FgColor= Colors[Index].Color;
  264.                         break;
  265.                     default:
  266.                         return FALSE;
  267.                     }
  268.                 break;
  269.             case ID_CBX_BACK:
  270.                 switch(Notify){
  271.                     case CBN_ENTER:
  272.                     case CBN_LBSELECT:
  273.                         Index=
  274.                         (SHORT)WinSendDlgItemMsg(
  275.                             hwnd,
  276.                             ID_CBX_BACK,
  277.                             LM_QUERYSELECTION,
  278.                             MPFROMSHORT(0),
  279.                             0L);
  280.                         if(Index == LIT_NONE)
  281.                             return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  282.                         pUC->BgIndex= Index;
  283.                         pUC->BgColor= Colors[Index].Color;
  284.                         break;
  285.                     default:
  286.                         return FALSE;
  287.                     }
  288.                 break;
  289.  
  290.             case ID_PB_OK:
  291.             case DID_OK:
  292.                 WinDismissDlg( hwnd, TRUE );
  293.                 return FALSE;
  294.  
  295.             default:
  296.                 return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  297.             }
  298.         break;
  299.  
  300.     default:
  301.         return WinDefDlgProc( hwnd, msg, mp1, mp2 );
  302.     }
  303.  
  304.  
  305.     /* draw a local sample of the text style and color(s) */
  306.     if(!fCreate){
  307.         hps= WinGetPS(hwndSample);
  308.         /* temporarily NULL-terminate after 1st character */
  309.         chSave=*(pUC->chText +1);
  310.         *(pUC->chText +1)= 0;
  311.         Paint(hwndSample, hps, pUC);
  312.         *(pUC->chText +1)= chSave;
  313.         WinReleasePS(hps);
  314.         }
  315.  
  316.  
  317.     return FALSE;
  318.  
  319. }
  320.  
  321.