home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wpobj.zip / CLRPALET.C < prev    next >
C/C++ Source or Header  |  1993-10-28  |  20KB  |  700 lines

  1. /*****************************************************************************
  2.  * MODULE NAME: ClrPalet.C
  3.  *
  4.  * DESCRIPTION:
  5.  *     Source code for ColorPalette object class.
  6. \****************************************************************************/
  7. /* OBJECT CLASS: ColorPalette
  8.  *
  9.  * CLASS HIERARCHY:
  10.  *
  11.  *     SOMObject
  12.  *       └── WPObject
  13.  *             └── WPAbstract
  14.  *                   └── WPPalette
  15.  *                         └──  WPColorPalette
  16.  *                                  └──  ColorPalette
  17.  *
  18.  * DESCRIPTION:
  19.  *     This object class can act as a stand-alone object class that creates
  20.  *     a palette of named colors that can be dragged and dropped much like the
  21.  *     system color palette. It can also be used as a replacement object class
  22.  *     for the WPColorPalette class - thus replacing the color palette object
  23.  *     in the System Setup folder and any other color palettes that the user
  24.  *   may have already created.
  25.  *
  26.  *     Each element of the named color palette contains a sample swatch of the
  27.  *     color and the name of that color. Editing a color in the named color
  28.  *     palette invokes the Color Wheel control.
  29.  *
  30.  *     The purpose of this class is to illustrate how the system provided
  31.  *     WPPalette object class works, and how the programmer can create his own
  32.  *   customized palette of icons, menus, or any other sort of attribute that
  33.  *   can be applied using drag and drop.
  34.  */
  35. #define SOMLINK    _System
  36. #define ColorPalette_Class_Source
  37. #define M_ColorPalette_Class_Source
  38. #include "clrpalet.ih"              /* implementation header emitted from ColorPalette.csc */
  39. #include "clrsampl.h"
  40.  
  41. /* Er, hum. This is a non-documented method that we had to override to
  42.  * allow the color sample control to work nicely...
  43.  */
  44. SOM_Scope BOOL SOMLINK clrp_wpSelectCell(
  45.     ColorPalette     *somSelf,
  46.     HWND            hwndPalette,
  47.     PCELL             pCell);
  48.  
  49. typedef BOOL (SOMLINK FNSELECTCELL)(ColorPalette *,HWND,PCELL);
  50.  
  51. typedef FNSELECTCELL *PFNSELECTCELL;
  52.  
  53. /********************* INSTANCE METHODS SECTION *****************************\
  54.  *        Do not put any code in this section unless it is really an        *
  55.  *      object INSTANCE method: otherwise parent method resolution will        *
  56.  *                   not work correctly for that method                        *
  57. \****************************************************************************/
  58. #undef SOM_CurrentClass
  59. #define SOM_CurrentClass SOMInstance
  60.  
  61. /*
  62.  * NEW METHOD: SetEditDlgHandle
  63.  *
  64.  * DESCRIPTION:
  65.  *   Store the handle of the color picking dialog window.
  66.  */
  67. SOM_Scope BOOL SOMLINK clrp_SetEditDlgHandle(
  68.     ColorPalette     *somSelf,
  69.     HWND            hwndEditDlg)
  70. {
  71.     ColorPaletteData *somThis    = ColorPaletteGetData(somSelf);
  72.  
  73.     _hwndEditDlg    = hwndEditDlg;
  74.     return TRUE;
  75. }
  76.  
  77. /*
  78.  * NEW METHOD: QueryEditDlgHandle
  79.  *
  80.  * DESCRIPTION:
  81.  *   Retrieve the handle of the color picking dialog window. Return NULL
  82.  *   if the dialog has not yet been created.
  83.  */
  84. SOM_Scope HWND SOMLINK clrp_QueryEditDlgHandle(
  85.     ColorPalette    *somSelf)
  86. {
  87.     ColorPaletteData *somThis    = ColorPaletteGetData(somSelf);
  88.  
  89.     return _hwndEditDlg;
  90. }
  91.  
  92. /*
  93.  * NEW METHOD: QuerySampleShape
  94.  *
  95.  * DESCRIPTION:
  96.  *   Describes the shape to be drawn for each color swatch. The pcPoints
  97.  *   variable must always be filled out, to indicate how many points are
  98.  *   contained in the pPoints array. pPoints either contains an array of
  99.  *   POINTL structures that this method should fill out or it can be NULL
  100.  *   to indicate that cPoints is being queried.
  101.  *
  102.  *   The point coordinates are specified in percentage coordinates.
  103.  */
  104. SOM_Scope BOOL   SOMLINK clrp_QuerySampleShape(
  105.     ColorPalette *somSelf,
  106.     PPOINTL      pPoints,
  107.     PULONG          pcPoints)
  108. {
  109.     #define         DEFAULT_CPOINTS                5
  110.     ColorPaletteData *somThis                  = ColorPaletteGetData(somSelf);
  111.     static POINTL    ptlShape[DEFAULT_CPOINTS] = { {   0,   0 },
  112.                                                   { 100,   0 },
  113.                                                   { 100, 100 },
  114.                                                   {   0, 100 },
  115.                                                   {   0,   0 }
  116.                                                 };
  117.  
  118.     /* Return the default color swatch shape, a rectangle.
  119.      */
  120.     if (pPoints)
  121.         memcpy(pPoints,ptlShape,DEFAULT_CPOINTS*sizeof(POINTL));
  122.     if (pcPoints)
  123.         *pcPoints    = DEFAULT_CPOINTS;
  124.     return TRUE;
  125. }
  126.  
  127. /*
  128.  * METHOD OVERRIDE: wpPaintCell
  129.  *
  130.  * DESCRIPTION:
  131.  *   Override the wpPaintCell method so that we can display different shape
  132.  *   color swatches in the palette view. The shape of the color swatch is as
  133.  *   defined by the QuerySampleShape method.
  134.  */
  135. SOM_Scope VOID SOMLINK clrp_wpPaintCell(
  136.     ColorPalette     *somSelf,
  137.     PCELL            pCell,
  138.     HPS             hps,
  139.     PRECTL             prcl,
  140.     BOOL            fHilite)
  141. {    
  142.     PPAINTPOT    pPaintPot    = (PVOID)pCell;
  143.     POINTL        *pPoints;
  144.     ULONG        cPoints, i;
  145.     LONG        xOrigin, yOrigin, xWidth, yHeight;
  146.  
  147.     /* Guarantee that the presentation space is currently in RGB mode
  148.      */
  149.     GpiCreateLogColorTable(hps,0,LCOLF_RGB,0,0,0 );
  150.  
  151.     /* Query the number of points in the palette shape to be drawn
  152.      */
  153.     _QuerySampleShape(somSelf,NULL,&cPoints);
  154.     if (cPoints)
  155.     {
  156.         /* Allocate an array of points to hold the shape
  157.          */
  158.         pPoints    = malloc(cPoints * sizeof(POINTL));
  159.         if (pPoints)
  160.         {
  161.             /* Scale the array of points so that they fit in the cell
  162.              * rectangle for this item
  163.              */
  164.             _QuerySampleShape(somSelf,pPoints,&cPoints);
  165.             xOrigin        = prcl->xLeft;
  166.             yOrigin        = prcl->yBottom;
  167.             xWidth        = prcl->xRight - xOrigin - 1; /* why the -1 ??? */
  168.             yHeight        = prcl->yTop   - yOrigin;
  169.             for (i    = 0; i < cPoints; i++)
  170.             {
  171.                 pPoints[i].x    = (pPoints[i].x * xWidth / 100) + xOrigin;
  172.                 pPoints[i].y    = (pPoints[i].y * yHeight / 100) + yOrigin;
  173.             }
  174.  
  175.             /* Create a path that contains the shape to be drawn
  176.              */
  177.             GpiBeginPath(hps,1);
  178.             GpiMove(hps,pPoints);
  179.             GpiPolyLine(hps,cPoints - 1,pPoints + 1);
  180.             GpiEndPath(hps);
  181.  
  182.             /* Fill the shape in the appropriate color for this cell
  183.              */
  184.             GpiSetColor(hps,pPaintPot->ulRGB);
  185.             GpiFillPath(hps,1,FPATH_ALTERNATE);
  186.  
  187.             /* Free the point array
  188.              */
  189.             free(pPoints);
  190.         }
  191.     }
  192. }
  193.  
  194. /*
  195.  * METHOD OVERRIDE: wpEditCell
  196.  *
  197.  * DESCRIPTION:
  198.  *   Override the wpEditCell method in order to display our own dialog
  199.  *   to perform color editing instead of the standard system provided color
  200.  *   selection dialog.
  201.  */
  202. SOM_Scope BOOL SOMLINK clrp_wpEditCell(
  203.     ColorPalette     *somSelf,
  204.     PCELL             pCell,
  205.     HWND             hwndPal)
  206. {
  207.     HWND        hwndDlg;
  208.  
  209.     /* If our dialog window isn't around at the moment we should load it.
  210.      * Note that the editing dialog is NOT modal, so that the user can quickly
  211.      * edit more than one color in the palette very quickly.
  212.      */
  213.     if (!_QueryEditDlgHandle(somSelf))
  214.         WinLoadDlg(HWND_DESKTOP,
  215.                    hwndPal,
  216.                    ColorPickingDialog,
  217.                    vhmodClrPalet,
  218.                    IDDLG_COLORPICKINGDIALOG,
  219.                    somSelf);
  220.  
  221.     /* Tell the editing dialog which cell's value it should currently
  222.      * be modifying, and then force it to the top of the Z-order and
  223.      * show it.
  224.      */
  225.     hwndDlg        =    _QueryEditDlgHandle(somSelf);
  226.     if (hwndDlg)
  227.     {
  228.         /* Pass the PAINTPOT cell that is to be edited on to the dialog...
  229.          */
  230.         WinSendMsg(hwndDlg,
  231.                    MSG_EDITCELL,
  232.                    MPFROMP(pCell),
  233.                    0);
  234.         WinSetWindowPos(hwndDlg,
  235.                         HWND_TOP,
  236.                         0, 0, 0, 0,
  237.                         SWP_ACTIVATE | SWP_ZORDER | SWP_SHOW);
  238.     }
  239. }
  240.  
  241. /*
  242.  * (NON-DOCUMENTED) METHOD OVERRIDE: wpSelectCell
  243.  *
  244.  * DESCRIPTION:
  245.  *   Override the wpSelectCell method in order that we can tell the
  246.  *   color sample control that we are buddies with what its new color should
  247.  *   be. Alright, so it is naughty to override a private method - but this one
  248.  *   should have been public anyway, it is perfectly harmless !
  249.  */
  250. SOM_Scope BOOL SOMLINK clrp_wpSelectCell(
  251.     ColorPalette     *somSelf,
  252.     HWND            hwndPalette,
  253.     PCELL             pCell)
  254. {
  255.     ColorPaletteData *somThis                  = ColorPaletteGetData(somSelf);
  256.     PFNSELECTCELL     parent_wpSelectCell    = NULL;
  257.     BOOL             rc                        = FALSE;
  258.     SOMClass           *Class, *ParentClass;
  259.  
  260.     /* If we are currently storing the handle of a color sample control,
  261.      * tell it about the newly selected color ...
  262.      */
  263.     if (_hwndColorSample)
  264.         WinSendMsg(_hwndColorSample,
  265.                    CSM_SETRGBCOLOR,
  266.                    MPFROMLONG(((PPAINTPOT)pCell)->ulRGB),
  267.                    0);
  268.  
  269.     /* Remember who the seleceted cell currently is
  270.      */
  271.     _pSelectedCell    = pCell;
  272.  
  273.     /* Call our parent method indirectly, since this isn't a public method!
  274.      */
  275.     Class    = _somGetClass(somSelf);
  276.     if (Class)
  277.     {
  278.         ParentClass    = _somGetParent(_ColorPalette);
  279.         if (ParentClass)
  280.         {
  281.             _somFindMethod(ParentClass,
  282.                            SOM_IdFromString("wpSelectCell"),
  283.                            (somMethodProc **)&parent_wpSelectCell);
  284.             if (parent_wpSelectCell)                
  285.                 rc    = (*parent_wpSelectCell)(somSelf,hwndPalette,pCell);
  286.         }
  287.     }
  288.     return    rc;
  289. }
  290.  
  291. /*
  292.  * METHOD OVERRIDE: wpRedrawCell
  293.  *
  294.  * DESCRIPTION:
  295.  *   Override the wpRedrawCell method in order that we can tell the
  296.  *   color sample control that opened us what its new color should be.
  297.  */
  298. SOM_Scope BOOL SOMLINK clrp_wpRedrawCell(
  299.     ColorPalette     *somSelf,
  300.     PCELL             pCell)
  301. {
  302.     ColorPaletteData *somThis                  = ColorPaletteGetData(somSelf);
  303.  
  304.     /* If we are currently storing the handle of a color sample control,
  305.      * tell it about the newly selected color ...
  306.      */
  307.     if (_hwndColorSample && (pCell == _pSelectedCell))
  308.         WinSendMsg(_hwndColorSample,
  309.                    CSM_SETRGBCOLOR,
  310.                    MPFROMLONG( ((PPAINTPOT)pCell)->ulRGB ),
  311.                    0);
  312.     return parent_wpRedrawCell(somSelf,pCell);
  313. }
  314.  
  315. /*
  316.  * METHOD OVERRIDE: wpSetup
  317.  *
  318.  * DESCRIPTION:
  319.  *   Look for our special setup string parameter "CTRLHDL=xxxxxxxx" coming
  320.  *   through to us from a color sample control window.
  321.  */
  322. SOM_Scope BOOL SOMLINK clrp_wpSetup(
  323.     ColorPalette    *somSelf,
  324.     PSZ             pszSetupString)
  325. {
  326.     ColorPaletteData *somThis                  = ColorPaletteGetData(somSelf);
  327.     CHAR             szHandle[20];
  328.     ULONG             cbszHandle;
  329.     HAB                 hab;
  330.     HWND             hwndColorSample;
  331.     HWND             hwndDlg;
  332.  
  333.     /* Scan the setup string for the "CTRLHDL=xxxxxxxx" parameter so that
  334.      * we can extract the window handle of the color sample control that
  335.      * wishes to communicate with us.
  336.      */
  337.     cbszHandle    = sizeof(szHandle);
  338.     hab            = WinQueryAnchorBlock(HWND_DESKTOP);
  339.     if (  _wpScanSetupString(somSelf,
  340.                              pszSetupString,
  341.                              "CTRLHDL",
  342.                              szHandle,
  343.                              &cbszHandle)
  344.        && cbszHandle
  345.        )
  346.     {
  347.         /* Only accept the specified handle value for us to communicate
  348.          * with if it is a valid window handle.
  349.          */
  350.         sscanf(szHandle,"%lx",&hwndColorSample);
  351.         if (hwndColorSample && WinIsWindow(hab,hwndColorSample))
  352.         {
  353.             _hwndColorSample    = hwndColorSample;
  354.  
  355.             /* Destroy the color picking dialog if it is visible
  356.              */
  357.             hwndDlg    = _QueryEditDlgHandle(somSelf);
  358.             if (hwndDlg)
  359.                 WinDestroyWindow(hwndDlg);
  360.         }
  361.     }
  362.  
  363.     /* Call our parent method so that all other setup parameters are
  364.      * processed correctly
  365.      */
  366.     return parent_wpSetup(somSelf,pszSetupString);
  367. }
  368.  
  369. /*********************** CLASS METHODS SECTION ******************************\
  370.  *        Do not put any code in this section unless it is really an        *
  371.  *       object CLASS method: otherwise parent method resolution will        *
  372.  *                      not work correctly for that method                     *
  373. \****************************************************************************/
  374. #undef SOM_CurrentClass
  375. #define SOM_CurrentClass SOMMeta
  376.  
  377. /*
  378.  * METACLASS METHOD OVERRIDE: wpclsInitData
  379.  *
  380.  * DESCRIPTION:
  381.  *   Override this method in order to perform one-time initialization when
  382.  *   an object class is instantiated.
  383.  */
  384. SOM_Scope void SOMLINK clrpM_wpclsInitData(
  385.     M_ColorPalette *somSelf)
  386. {
  387.     /* Register the color wheel control on the Workplace Shell process. We
  388.      * only have to do this once, so using the metaclass initialization
  389.      * method is an ideal place to do it ....
  390.      */
  391.     WinRegisterClass(NULLHANDLE,
  392.                      COLOR_WHEEL_CLASS,
  393.                      ClrWheelWndProc,
  394.                      CS_SYNCPAINT | CS_SIZEREDRAW,
  395.                      USER_RESERVED
  396.                     );
  397.  
  398.     /* Override the wpSelectCell private method
  399.      */
  400.     _somOverrideSMethod(somSelf,
  401.                         SOM_IdFromString("wpSelectCell"),
  402.                         (somMethodProc *)clrp_wpSelectCell);
  403.  
  404.     parent_wpclsInitData(somSelf);
  405. }
  406.  
  407. /*
  408.  * METACLASS METHOD OVERRIDE: wpclsQueryIconData
  409.  *
  410.  * DESCRIPTION:
  411.  *   Override this method in order to provide a unique icon for the
  412.  *   ColorPalette object class.
  413.  */
  414. SOM_Scope ULONG SOMLINK clrpM_wpclsQueryIconData(
  415.     M_ColorPalette *somSelf,
  416.     PICONINFO        pIconInfo)
  417. {
  418.     /* Tell the system that we have our own special default class icon
  419.      * stored as a resource within our dll module.
  420.      */
  421.     if (pIconInfo)
  422.     {
  423.         pIconInfo->cb        = sizeof(ICONINFO);
  424.         pIconInfo->fFormat    = ICON_RESOURCE;
  425.         pIconInfo->hmod        = vhmodClrPalet; /* Module handle of our dll */
  426.         pIconInfo->resid    = ID_CLRPALET;     /* Icon resource id */
  427.     }
  428.     return sizeof(ICONINFO);
  429. }
  430.  
  431. /*
  432.  * METACLASS METHOD OVERRIDE: wpclsQueryStyle
  433.  *
  434.  * DESCRIPTION:
  435.  *   Override this method to modify class styles for the ColorPalette object
  436.  *   class.
  437.  */
  438. SOM_Scope ULONG SOMLINK clrpM_wpclsQueryStyle(
  439.     M_ColorPalette *somSelf)
  440. {
  441.     ULONG    ulStyle;
  442.  
  443.     /* Tell the system that we don't want to have a template created
  444.      * in the templates folder automatically. We don't really need one
  445.      * because we are a replacement for the existing color palette class.
  446.      */
  447.     ulStyle    = parent_wpclsQueryStyle(somSelf);
  448.  
  449.     return ulStyle & ~CLSSTYLE_NEVERTEMPLATE;
  450. }
  451.  
  452. /**************************** ORDINARY CODE *********************************\
  453.  *           Put any code here that isn't a method of the object class        *
  454. \****************************************************************************/
  455. #undef SOM_CurrentClass
  456.  
  457. /*
  458.  * DIALOG PROCEDURE: ColorPickingDialog
  459.  *
  460.  * DESCRIPTION:
  461.  *   This code manages the color picking dialog, allowing the user to modify
  462.  *   the color value of a given cell within the color palette.
  463.  */
  464. MRESULT EXPENTRY ColorPickingDialog(
  465.     HWND    hwnd,
  466.     ULONG    msg,
  467.     MPARAM    mp1,
  468.     MPARAM    mp2)
  469. {
  470.     COLORPICKDATA    *pPickData    = WinQueryWindowPtr(hwnd,QWL_USER);
  471.     MRESULT            mr            = 0;
  472.     RGB2            *pRGB, rgb;
  473.     CLRWHLCDATA        cwcd;
  474.     ULONG            Value;
  475.  
  476.     switch (msg)
  477.     {
  478.         /* Initialize our dialog
  479.          */
  480.         case WM_INITDLG:
  481.             /* Allocate a structure to store our palette object pointer
  482.              * and the cell that is currently being edited.
  483.              */
  484.             pPickData    = malloc(sizeof(COLORPICKDATA));
  485.             if (pPickData)
  486.             {
  487.                 /* Store away the object pointer to the palette that we
  488.                  * are operating on.
  489.                  */
  490.                 WinSetWindowPtr(hwnd,QWL_USER,pPickData);
  491.                 pPickData->Palette        = PVOIDFROMMP(mp2);
  492.                 pPickData->pCell        = NULL;
  493.                 pPickData->fSpinSet        = TRUE;
  494.  
  495.                 /* Set the ranges on each of our spinbuttons
  496.                  */
  497.                 WinSendDlgItemMsg(hwnd,DID_SPINR,        
  498.                                   SPBM_SETLIMITS,
  499.                                   MPFROMLONG(255),
  500.                                   MPFROMLONG(0));
  501.                 WinSendDlgItemMsg(hwnd,DID_SPINB,        
  502.                                   SPBM_SETLIMITS,
  503.                                   MPFROMLONG(255),
  504.                                   MPFROMLONG(0));
  505.                 WinSendDlgItemMsg(hwnd,DID_SPING,        
  506.                                   SPBM_SETLIMITS,
  507.                                   MPFROMLONG(255),
  508.                                   MPFROMLONG(0));
  509.                 pPickData->fSpinSet        = FALSE;
  510.             }
  511.  
  512.             /* Store our handle away in the palette object so that it
  513.              * knows that we are loaded.
  514.              */
  515.             _SetEditDlgHandle(pPickData->Palette,hwnd);
  516.             break;
  517.  
  518.         /* Cleanup when our dialog is destroyed
  519.          */
  520.         case WM_DESTROY:
  521.             mr    = WinDefDlgProc(hwnd,msg,mp1,mp2);
  522.  
  523.             /* Let the palette object know that this dialog is no longer
  524.              * loaded and then free up our data structure
  525.              */
  526.             _SetEditDlgHandle(pPickData->Palette,NULLHANDLE);
  527.             if (pPickData)
  528.                 free(pPickData);
  529.             break;
  530.  
  531.         /* Change the color of the color swatch in the palette view when
  532.          * the user picks a new color from either the spin buttons or
  533.          * the color wheel control.
  534.          */
  535.         case WM_CONTROL:
  536.             switch (SHORT2FROMMP(mp1))
  537.             {
  538.                 case CWN_RGBCLRSELECTED:
  539.                     if (pPickData && pPickData->pCell)
  540.                     {
  541.                         /* The new color to be used is passed to us in MP2                    
  542.                          */
  543.                         ((PPAINTPOT)pPickData->pCell)->ulRGB
  544.                             = LONGFROMMP(mp2);
  545.  
  546.                         /* Redraw the cell and reset the spin buttons
  547.                          */
  548.                         _wpRedrawCell(pPickData->Palette,                        
  549.                                       pPickData->pCell);
  550.                         WinSendMsg(hwnd,
  551.                                    MSG_SETRGBSPINBTNS,
  552.                                    MPFROMP(&((PPAINTPOT)pPickData->pCell)->ulRGB),
  553.                                    0);
  554.                     }
  555.                     break;
  556.                     
  557.                 case SPBN_CHANGE:
  558.                     if (pPickData && !pPickData->fSpinSet && pPickData->pCell)
  559.                     {
  560.                         /* Figure out the new color to be used by reading
  561.                          * the values of each spin button in turn...
  562.                          */
  563.                         WinSendDlgItemMsg(hwnd,DID_SPINR,
  564.                                             SPBM_QUERYVALUE,
  565.                                           MPFROMP(&Value),
  566.                                           0);
  567.                         rgb.bRed        = Value;
  568.                         WinSendDlgItemMsg(hwnd,DID_SPING,
  569.                                             SPBM_QUERYVALUE,
  570.                                           MPFROMP(&Value),
  571.                                           0);
  572.                         rgb.bGreen        = Value;
  573.                         WinSendDlgItemMsg(hwnd,DID_SPINB,
  574.                                             SPBM_QUERYVALUE,
  575.                                           MPFROMP(&Value),
  576.                                           0);
  577.                         rgb.bBlue        = Value;
  578.                         rgb.fcOptions    = 0;
  579.                         ((PPAINTPOT)pPickData->pCell)->ulRGB
  580.                             = *((PULONG)&rgb);
  581.  
  582.                         /* Redraw the cell and reset the color wheel
  583.                          */
  584.                         _wpRedrawCell(pPickData->Palette,                        
  585.                                       pPickData->pCell);
  586.                         WinSendDlgItemMsg(hwnd,DID_COLORWHEEL,
  587.                                           CWM_SETRGBCLR,
  588.                                           MPFROMP(&((PPAINTPOT)pPickData->pCell)->ulRGB),
  589.                                           0);
  590.                     }
  591.                     break;
  592.             }
  593.             break;        
  594.  
  595.         /* Handle the UNDO and HELP pushbuttons
  596.          */
  597.         case WM_COMMAND:
  598.             switch(SHORT1FROMMP(mp1))
  599.             {
  600.                 case DID_UNDO:
  601.                     /* Set the color of the color swatch being edited back                
  602.                      * to its original value, and reset the position of
  603.                      * the crosshairs.
  604.                      */
  605.                     if (pPickData && pPickData->pCell)
  606.                     {
  607.                         ((PPAINTPOT)pPickData->pCell)->ulRGB
  608.                             = pPickData->ulRGBOriginal;
  609.                         _wpRedrawCell(pPickData->Palette,                        
  610.                                       pPickData->pCell);
  611.                         WinSendDlgItemMsg(hwnd,DID_COLORWHEEL,
  612.                                           CWM_SETRGBCLR,
  613.                                           MPFROMP(&pPickData->ulRGBOriginal),
  614.                                           0);
  615.                         WinSendMsg(hwnd,
  616.                                    MSG_SETRGBSPINBTNS,
  617.                                    MPFROMP(&pPickData->ulRGBOriginal),
  618.                                    0);
  619.                     }
  620.                     break;
  621.             }
  622.             break;
  623.  
  624.         /* Adjust the color crosshairs when the user asks to edit a
  625.          * different cell.
  626.          */
  627.         case MSG_EDITCELL:
  628.             if (pPickData)        
  629.             {
  630.                 /* Store away the new cell that is being edited and the
  631.                  * original color that was contained in this paintpot.
  632.                  */
  633.                 pPickData->pCell     = PVOIDFROMMP(mp1);
  634.                 if (pPickData->pCell)
  635.                 {
  636.                     pPickData->ulRGBOriginal = ((PPAINTPOT)mp1)->ulRGB;
  637.                     WinSendDlgItemMsg(hwnd,DID_COLORWHEEL,
  638.                                       CWM_SETRGBCLR,
  639.                                       MPFROMP(&((PPAINTPOT)mp1)->ulRGB),
  640.                                       0);
  641.                     WinSendMsg(hwnd,
  642.                                MSG_SETRGBSPINBTNS,
  643.                                MPFROMP(&((PPAINTPOT)mp1)->ulRGB),
  644.                                0);
  645.                 }
  646.             }
  647.             break;
  648.  
  649.         /* Set the current values in the R,G and B spinbuttons
  650.          */
  651.         case MSG_SETRGBSPINBTNS:
  652.             if (pPickData)
  653.             {
  654.                 pPickData->fSpinSet    = TRUE;
  655.                 pRGB                = PVOIDFROMMP(mp1);
  656.                 WinSendDlgItemMsg(hwnd,DID_SPINR,        
  657.                                   SPBM_SETCURRENTVALUE,
  658.                                   MPFROMSHORT(pRGB->bRed),
  659.                                   0);
  660.                 WinSendDlgItemMsg(hwnd,DID_SPINB,        
  661.                                   SPBM_SETCURRENTVALUE,
  662.                                   MPFROMSHORT(pRGB->bBlue),
  663.                                   0);
  664.                 WinSendDlgItemMsg(hwnd,DID_SPING,        
  665.                                   SPBM_SETCURRENTVALUE,
  666.                                   MPFROMSHORT(pRGB->bGreen),
  667.                                   0);
  668.                 pPickData->fSpinSet    = FALSE;
  669.             }
  670.             break;
  671.  
  672.         default:
  673.             return WinDefDlgProc(hwnd,msg,mp1,mp2);
  674.     }
  675.     return mr;
  676. }
  677.  
  678. /*
  679.  * FUNCTION: _DLL_InitTerm
  680.  *
  681.  * DESCRIPTION:
  682.  *   This function merely stores away our module handle when we get loaded
  683.  *   so that we can use it later for loading icons, dialogs and so on from
  684.  *   the resources within our dll.
  685.  */
  686. ULONG APIENTRY _DLL_InitTerm (
  687.     ULONG hmodule,    
  688.     ULONG ulFlag)        
  689. {
  690.     switch (ulFlag)
  691.     {
  692.         case 0:    /* A zero flag means called at DLL initialization */
  693.             if (_CRT_init () == -1)
  694.                 return (ULONG)0;
  695.             vhmodClrPalet    = hmodule; /* Store our mod handle in a global */
  696.             break;
  697.     }
  698.     return 1;
  699. }
  700.