home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / except1.zip / 3DLine.C next >
C/C++ Source or Header  |  1994-08-23  |  12KB  |  345 lines

  1. #pragma    title("Prominare Development System Support DLL  --  Version 3.0 -- (3DLine.C)")
  2. #pragma    subtitle("  3D Line Control DLL - Interface Definitions")
  3.  
  4. #define    INCL_GPI           /* Include OS/2 PM GPI Interface    */
  5. #define    INCL_WIN           /* Include OS/2 PM Windows Interface    */
  6.  
  7. #include <os2.h>
  8. #include <string.h>
  9.  
  10. #include <ccls32.h>
  11. #include <heapmem.h>
  12.  
  13. #include "appdefs.h"
  14. #include "except.h"
  15.  
  16. /* This    module contains    an example installable control that can    be used    */
  17. /* by Prominare    Designer to include within applications    where        */
  18. /* additional facilities are provided that are not found within    the    */
  19. /* default controls of OS/2 Presentation Manager.            */
  20. /*                                    */
  21. /* For complete    details    regarding the Custom Control Library        */
  22. /* Specification (CCLS), Version 2.1c, consult Section 2 in the        */
  23. /* Prominare Development System    Programming Guide.            */
  24. /*                                    */
  25. /* The DLL is created using the    following options in Prominare Builder:    */
  26. /*                                    */
  27. /* Option           Value                        */
  28. /* ------           -----                        */
  29. /* Op Sys           OS/2 PM Static DLL                */
  30. /* Optimization           Maximize                        */
  31. /* Compile Type           Subsystem                    */
  32. /* CPU               80486                        */
  33. /* Warning Level       3                        */
  34. /*                                    */
  35. /* Equivalent command line invocation:                    */
  36. /*                                    */
  37. /*     Icc -C -G4e -O+ -Rn -W3 3DLine.C                    */
  38.  
  39. /* Filename:   3DLine.C                            */
  40.  
  41. /*  Version:   3.0                            */
  42. /*  Created:   1994-08-23                        */
  43. /*  Revised:   1994-08-23                        */
  44.  
  45. /* Routines:   LONG lGetPresParam(HWND hWnd, ULONG ulID1, ULONG    ulID2,    */
  46. /*                  LONG lDefault);            */
  47. /*           static VOID CalcSize(PRECTL prcl, PLINEFIELD plf);    */
  48. /*           MRESULT EXPENTRY    Line3DWndProc(HWND hWnd, ULONG msg,    */
  49. /*                          MPARAM mp1, MPARAM mp2);    */
  50.  
  51.  
  52. /* Copyright ╕ 1987-1994  Prominare Inc.  All Rights Reserved.        */
  53.  
  54. /* --------------------------------------------------------------------    */
  55.  
  56. typedef    struct _LINEFIELD       /* lf */
  57.    {
  58.    POINTL aptl[4];           /* Entry Field Outline Points    */
  59.    ULONG  flStyle;           /* Line Style            */
  60.    LONG      lClrShadow;           /* Shadow Colour            */
  61.    BOOL      fDraw;           /* Draw Flag                */
  62.    } LINEFIELD ;
  63.  
  64. typedef    LINEFIELD *PLINEFIELD;
  65.  
  66. extern HHEAPMEM    hHeap;           /* Heap Handle            */
  67.  
  68. static VOID CalcSize(PRECTL prcl, PLINEFIELD plf);
  69.  
  70. static INTERNALADDRESSLIST aial[ ] = { { (PFNINTADD)lGetPresParam, "lGetPresParam" },
  71.                        { (PFNINTADD)CalcSize,       "CalcSize"       },
  72.                        { (PFNINTADD)Line3DWndProc, "Line3DWndProc" },
  73.                        { NULL, NULL } };
  74.  
  75. INTERNALADDRESS    intadd3DLine =    { __FILE__, 0, aial };
  76.  
  77. #pragma    subtitle("   Traffic Manager - Presentation Parameter Retrieve Procedure")
  78. #pragma    page( )
  79.  
  80. /* --- lGetPresParam ----------------------------------    [ Private } ---    */
  81. /*                                    */
  82. /*     This function is    used to    retrieve a presentation    parameter    */
  83. /*     that may    be present.  If    the presentation parameter is not,    */
  84. /*     the default colour passed to the    function will be used.    All    */
  85. /*     colours queried for are RGB or their RGB    equivalents.        */
  86. /*                                    */
  87. /*     Upon Entry:                            */
  88. /*                                    */
  89. /*     HWND  hWnd;     = Window    Handle                    */
  90. /*     ULONG ulID1;    = Presentation Parameter    1 ID (RGB)        */
  91. /*     ULONG ulID2;    = Presentation Parameter    2 ID (Index)        */
  92. /*     LONG  lDefault; = Default Colour                    */
  93. /*                                    */
  94. /*     Upon Exit:                            */
  95. /*                                    */
  96. /*     lGetPresParam = Colour to Use (RGB)                */
  97. /*                                    */
  98. /* --------------------------------------------------------------------    */
  99.  
  100. LONG lGetPresParam(HWND    hWnd, ULONG ulID1, ULONG ulID2,    LONG lDefault)
  101.  
  102. {
  103. HPS   hPS;               /* Presentation Space Handle        */
  104. LONG  lClr;               /* Presentation Parameter Colour    */
  105. ULONG ulID;               /* Presentation Parameter ID        */
  106.  
  107.                /* First    try to determine if any    presentation    */
  108.                /* parameters are set for the area requested.    */
  109.                /* The first ID is RGB index and    the second ID    */
  110.                /* is colour index.                */
  111.  
  112. if ( WinQueryPresParam(hWnd, ulID1, ulID2, &ulID, sizeof(LONG),    (PVOID)&lClr,
  113.                QPF_NOINHERIT | QPF_ID2COLORINDEX) )
  114.  
  115.                /* Presentation parameter set for the area,    */
  116.                /* return the RGB colour                */
  117.    return(lClr);
  118. else
  119.                /* No presentation parameters set, check    to see    */
  120.                /* if the default is a system colour in which    */
  121.                /* only need to query the index for the RGB    */
  122.                /* value                        */
  123.  
  124.    if (    (lDefault >= SYSCLR_SHADOWHILITEBGND) &&
  125.     (lDefault <= SYSCLR_HELPHILITE)    )
  126.        return(WinQuerySysColor(HWND_DESKTOP, lDefault, 0L));
  127.    else
  128.                /* Standard colour index, get the RGB equivalent    */
  129.                /* for the index                    */
  130.  
  131.        if ( (hPS = WinGetPS(hWnd)) != (HPS)NULL    )
  132.        if (    (lClr =    GpiQueryRGBColor(hPS, LCOLOPT_REALIZED,    lDefault)) == GPI_ALTERROR )
  133.            {
  134.                /* Colour was not found,    return white as    colour    */
  135.  
  136.            WinReleasePS(hPS);
  137.            return(RGB_WHITE);
  138.            }
  139.        else
  140.            {
  141.                /* Colour found,    return the RGB value        */
  142.  
  143.            WinReleasePS(hPS);
  144.            return(lClr);
  145.            }
  146.        else
  147.        return(RGB_WHITE);
  148. }
  149. #pragma    subtitle("   Shadowed Group Box DLL - Control Window Procedure")
  150. #pragma    page ( )
  151.  
  152. /* --- CalcSize    ---------------------------------------    [ Private ] ---    */
  153. /*                                    */
  154. /*     This function is    used to    calculate the sizes and    positions    */
  155. /*     of the various elements that are    used to    make up    a 3D text    */
  156. /*     field.                                */
  157. /*                                    */
  158. /*     Upon Entry:                            */
  159. /*                                    */
  160. /*     PRECTL      prcl;    = Control Rectangle Pointer            */
  161. /*     PLINEFIELD ptf;    = Text Field Information Pointer        */
  162. /*                                    */
  163. /*     Upon Exit:                            */
  164. /*                                    */
  165. /*     Nothing                                */
  166. /*                                    */
  167. /* --------------------------------------------------------------------    */
  168.  
  169. static VOID CalcSize(PRECTL prcl, PLINEFIELD plf)
  170.  
  171. {
  172.  
  173. if ( (prcl->xRight <= prcl->xLeft) ||
  174.      (prcl->yTop <= prcl->yBottom) )
  175.    plf->fDraw =    FALSE;
  176. else
  177.    {
  178.    plf->fDraw =    TRUE;
  179.  
  180.            /*  Line    display    points                    */
  181.            /*                            */
  182.            /*      0                  1            */
  183.            /*       ===========================            */
  184.            /*      2                  3            */
  185.  
  186.    if (    plf->flStyle & LNS_VERTICAL )
  187.        {
  188.        plf->aptl[0].x =    plf->aptl[1].x = (prcl->xRight - prcl->xLeft) /    2L +
  189.                       prcl->xLeft;
  190.        plf->aptl[2].x =    plf->aptl[3].x = plf->aptl[0].x    + 1L;
  191.        plf->aptl[0].y =    plf->aptl[2].y = prcl->yBottom;
  192.        plf->aptl[1].y =    plf->aptl[3].y = prcl->yTop   -    1L;
  193.        }
  194.    else
  195.        {
  196.        plf->aptl[0].x =    plf->aptl[2].x = prcl->xLeft;
  197.        plf->aptl[1].x =    plf->aptl[3].x = prcl->xRight;
  198.        plf->aptl[0].y =    plf->aptl[1].y = (prcl->yTop - prcl->yBottom) /    2L +
  199.                       prcl->yBottom;
  200.        plf->aptl[2].y =    plf->aptl[3].y = plf->aptl[0].y    - 1L;
  201.        }
  202.    }
  203. }
  204. #pragma    subtitle("   3D Line Control DLL - Control Window Procedure")
  205. #pragma    page ( )
  206.  
  207. /* --- Line3DWndProc ----------------------------------    [ Private ] ---    */
  208. /*                                    */
  209. /*     This function is    used to    handle the messages sent to the        */
  210. /*     installed control.  The window procedure    is designed to        */
  211. /*     allow for multiple instances and    to be totally re-entrant.    */
  212. /*                                    */
  213. /*     Upon Entry:                            */
  214. /*                                    */
  215. /*     HWND   hWnd; = Window Handle                    */
  216. /*     ULONG  msg;  = PM Message                    */
  217. /*     MPARAM mp1;  = Message Parameter    1                */
  218. /*     MPARAM mp2;  = Message Parameter    2                */
  219. /*                                    */
  220. /*     Upon Exit:                            */
  221. /*                                    */
  222. /*     Line3DWndProc = Message Handling    Result                */
  223. /*                                    */
  224. /* --------------------------------------------------------------------    */
  225.  
  226. MRESULT    EXPENTRY Line3DWndProc(HWND hWnd, ULONG    msg, MPARAM mp1, MPARAM    mp2)
  227.  
  228. {
  229. HPS          hPS;           /* Presentation Space Handle        */
  230. PCREATESTRUCT pcrst;           /* Create Structure Pointer        */
  231. PLINEFIELD    plf;           /* Text Field Structure Pointer    */
  232. RECTL          rcl;           /* Rectangle    Holder            */
  233. ULONG          flStyle;           /* Style Flag            */
  234.  
  235. switch ( msg )
  236.    {
  237.                /* Perform control initialization when the    */
  238.                /* control is created                */
  239.    case    WM_CREATE :
  240.                /* Save the address of the text string pointer    */
  241.                /* in the control's reserved memory to allow it  */
  242.                /* to be    referenced as required by the control    */
  243.  
  244.        WinSetWindowPtr(hWnd, QWW_CDATA,
  245.                (PVOID)(plf = (PLINEFIELD)HeapMalloc(hHeap, sizeof(LINEFIELD))));
  246.  
  247.                /* Get the control's creation structure address  */
  248.                /* to copy the default text of the control to    */
  249.                /* the memory in    the heap            */
  250.  
  251.        pcrst = (PCREATESTRUCT)PVOIDFROMMP(mp2);
  252.  
  253.        plf->flStyle   =    pcrst->flStyle;
  254.  
  255.        plf->lClrShadow = WinQuerySysColor(HWND_DESKTOP,    SYSCLR_SHADOW, 0L);
  256.        if ( ((rcl.xRight = pcrst->cx) >    0L) && ((rcl.yTop = pcrst->cy) > 0L) )
  257.        {
  258.        rcl.xLeft = rcl.yBottom = 0L;
  259.        CalcSize(&rcl, plf);
  260.        }
  261.        break;
  262.                /* Size of control changing, reset the display    */
  263.                /* points of the    line                */
  264.    case    WM_SIZE    :
  265.        if ( ((LONG)(SHORT)SHORT1FROMMP(mp2) > 0L) && ((LONG)(SHORT)SHORT2FROMMP(mp2) > 0L) )
  266.        {
  267.        WinQueryWindowRect(hWnd, &rcl);
  268.        CalcSize(&rcl, (PLINEFIELD)WinQueryWindowPtr(hWnd, QWW_CDATA));
  269.        }
  270.        else
  271.        {
  272.        plf = (PLINEFIELD)WinQueryWindowPtr(hWnd, QWW_CDATA);
  273.        plf->fDraw =    FALSE;
  274.        }
  275.        break;
  276.                /* Mouse    being passed over the control, imply    */
  277.                /* that the control is transparent to the    */
  278.                /* system                    */
  279.    case    WM_HITTEST :
  280.        return(MRFROMLONG(HT_TRANSPARENT));
  281.  
  282.                /* Erase    control    background            */
  283.  
  284.    case    WM_ERASEBACKGROUND :
  285.        return(MRFROMLONG(TRUE));
  286.  
  287.                /* Paint    the Control                */
  288.    case    WM_PAINT :
  289.                /* Get the address of the text from the        */
  290.                /* control's reserved memory                     */
  291.  
  292.        plf = (PLINEFIELD)WinQueryWindowPtr(hWnd, QWW_CDATA);
  293.        if ( ((flStyle =    WinQueryWindowULong(hWnd, QWL_STYLE)) &    LNS_VERTICAL) &&
  294.         (plf->flStyle & LNS_HORIZONTAL) )
  295.        {
  296.        plf->flStyle    &= (ULONG)~LNS_HORIZONTAL;
  297.        plf->flStyle    |= LNS_VERTICAL;
  298.        WinQueryWindowRect(hWnd, &rcl);
  299.        CalcSize(&rcl, plf);
  300.        }
  301.        else
  302.        if (    (flStyle & LNS_HORIZONTAL) && (plf->flStyle & LNS_VERTICAL) )
  303.            {
  304.            plf->flStyle &= (ULONG)~LNS_VERTICAL;
  305.            plf->flStyle |= LNS_HORIZONTAL;
  306.            WinQueryWindowRect(hWnd,    &rcl);
  307.            CalcSize(&rcl, plf);
  308.            }
  309.  
  310.        if ( plf->fDraw )
  311.        {
  312.                /* Get the presentation space for the control    */
  313.                /* and set the colour table to RGB mode        */
  314.  
  315.        GpiCreateLogColorTable(hPS =    WinBeginPaint(hWnd, (HPS)NULL, (PRECTL)NULL),
  316.                   0L, LCOLF_RGB, 0L, 0L, (PLONG)NULL);
  317.        GpiSetColor(hPS, plf->lClrShadow);
  318.  
  319.        GpiMove(hPS,    plf->aptl);
  320.        GpiLine(hPS,    &plf->aptl[1]);
  321.  
  322.        GpiSetColor(hPS, RGB_WHITE);
  323.  
  324.        GpiMove(hPS,    &plf->aptl[2]);
  325.        GpiLine(hPS,    &plf->aptl[3]);
  326.  
  327.        WinEndPaint(hPS);
  328.        }
  329.        break;
  330.                /* Control being    destroyed            */
  331.    case    WM_DESTROY :
  332.                /* Get the address of the text from the        */
  333.                /* control's reserved memory and release the     */
  334.                /* heap allocated for use by the    control        */
  335.  
  336.        HeapFree(hHeap, (PVOID)WinQueryWindowPtr(hWnd, QWW_CDATA));
  337.        break;
  338.                /* Default message processing            */
  339.    default :
  340.        return(WinDefWindowProc(hWnd, msg, mp1, mp2));
  341.    }
  342.  
  343. return(0L);
  344. }
  345.