home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / shape / os2plat.cpp < prev   
Text File  |  1997-04-02  |  15KB  |  480 lines

  1. /* @(#)Z 1.2 os2/src/samples/shape/os2plat.cpp, odshapepart, od96os2, odos29712d 97/03/21 17:47:40 (97/01/31 14:08:11) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odsamples
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  25. //   OR PERFORMANCE OF THIS SOFTWARE.
  26. //
  27. //====END_GENERATED_PROLOG========================================
  28.  
  29. #include <ODos2.h> 
  30. #include "iodshape.h"
  31.  
  32. extern "C" MRESULT EXPENTRY ColorProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 ); 
  33. extern "C" MRESULT EXPENTRY fnwpColorSample( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ); 
  34.  
  35. // Array of binary values for RGB value 
  36. SHORT RGBColors[3] = {0, 0, 0}; 
  37.  
  38. // Array of fill color for sliders 
  39. LONG RibbonColors[3] = {CLR_DARKRED, CLR_DARKGREEN, CLR_DARKBLUE}; 
  40. LONG ShaftColors[3]  = {CLR_RED,     CLR_GREEN,     CLR_BLUE    }; 
  41.  
  42. // Composite color value 
  43. LONG  Color = 0; 
  44.  
  45. const unsigned long ColorChoices = 9; 
  46. /* 
  47.  * Local method to display values of property in a modal window 
  48.  * returning a non-empty string if value selected.  Return value 
  49.  * is return value from WinDlgBox 
  50.  */ 
  51.  
  52. BOOL ColorWindow(HMODULE dllHandle, HWND ParentWindow, SHORT *BakColor) 
  53.  
  54.  
  55.     // take initial background color to start
  56.       RGBColors[RED]   = BakColor[RED];
  57.       RGBColors[GREEN] = BakColor[GREEN];
  58.       RGBColors[BLUE]  = BakColor[BLUE];
  59.  
  60.     // Register a window class to handle the user control 
  61.     WinRegisterClass(WinQueryAnchorBlock(ParentWindow), 
  62.                      "ColorMix", 
  63.                      fnwpColorSample, 
  64.                      0L, 
  65.                      0); 
  66.  
  67.     // Execute color dialog passing in the current color value 
  68.     ULONG rc = WinDlgBox(HWND_DESKTOP,
  69.                          ParentWindow,
  70.                          ColorProc,
  71.                          dllHandle,
  72.                          ID_COLORS,
  73.                          0); 
  74.  
  75.     // If user terminated with the OK button 
  76.     if (rc != DID_CANCEL) 
  77.     {
  78.      BakColor[RED] = RGBColors[RED];
  79.      BakColor[GREEN] = RGBColors[GREEN];
  80.      BakColor[BLUE] = RGBColors[BLUE]; 
  81.      return 0;
  82.     }
  83.  
  84.     // If canceled then don't change color
  85.     return 1; 
  86.  
  87.  
  88. MRESULT EXPENTRY ColorProc( HWND hwndDlg, ULONG msg, MPARAM mp1, MPARAM mp2 ) 
  89.  // This global variable prevents us from infinitely looping setting PM control 
  90.  // values.  The slider set the spin button and the spin button sets the 
  91.  // slider. 
  92.  static boolean Setting = FALSE; 
  93.  
  94.   // Switch on the PM message type 
  95.   switch (msg) 
  96.   { 
  97.     // case Initialize dialog 
  98.     case WM_INITDLG: 
  99.     { 
  100.       // We're setting values 
  101.       Setting = TRUE; 
  102.  
  103.       // For all three colors 
  104.       for (int Index = RED; 
  105.            Index <= BLUE; 
  106.            Index++) 
  107.       { 
  108.         // Set spin fields range from 0 to 255 
  109.         WinSendDlgItemMsg(hwndDlg, 
  110.                           ID_SPIN_RED + Index, 
  111.                           SPBM_SETLIMITS, 
  112.                           MPFROMLONG(255), 
  113.                           MPFROMLONG(0)); 
  114.  
  115.         // Initialize slider 
  116.         WinSendDlgItemMsg(hwndDlg, 
  117.                           ID_SLIDER_RED + Index, 
  118.                           SLM_SETSLIDERINFO, 
  119.                           MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  120.                                        SMA_INCREMENTVALUE), 
  121.                           MPFROMSHORT(RGBColors[Index])); 
  122.  
  123.         // Set spin field 
  124.         WinSendDlgItemMsg(hwndDlg, 
  125.                           ID_SPIN_RED + Index, 
  126.                           SPBM_SETCURRENTVALUE, 
  127.                           MPFROMLONG((long) RGBColors[Index]), 
  128.                           0); 
  129.       } 
  130.  
  131.       // Invalidate the mix window so it will repaint 
  132.       WinInvalidateRect(WinWindowFromID(hwndDlg, 
  133.                                         ID_MIX), 
  134.                         NULL, 
  135.                         FALSE); 
  136.  
  137.       // No longer setting values 
  138.       Setting = FALSE; 
  139.  
  140.       break; 
  141.     } 
  142.  
  143.     // Case draw item for owner drawn portion of sliders 
  144.     case WM_DRAWITEM: 
  145.     { 
  146.       // Get control identifier 
  147.       SHORT ID = SHORT1FROMMP(mp1); 
  148.  
  149.       // Switch on the control identifier 
  150.       switch (ID) 
  151.       { 
  152.         // case red, green or blue slider 
  153.         case ID_SLIDER_RED: 
  154.         case ID_SLIDER_GREEN: 
  155.         case ID_SLIDER_BLUE: 
  156.           { 
  157.             // Get owner item structure 
  158.             POWNERITEM POwnerItem = (POWNERITEM) PVOIDFROMMP(mp2); 
  159.  
  160.             // If drawing the ribbon strip 
  161.             if (POwnerItem->idItem == SDA_RIBBONSTRIP) 
  162.             { 
  163.               // Get color index 
  164.               int Index = ID - ID_SLIDER_RED; 
  165.  
  166.               // Fill in the ribbon strip with appropriate color 
  167.               WinFillRect(POwnerItem->hps, 
  168.                           &POwnerItem->rclItem, 
  169.                           RibbonColors[Index]); 
  170.  
  171.               // Return TRUE so the slider won't draw its own ribbon strip 
  172.               return (MRESULT) TRUE; 
  173.             } 
  174.             else 
  175.             { 
  176.               // If drawing the slider shaft 
  177.               if (POwnerItem->idItem == SDA_SLIDERSHAFT) 
  178.               { 
  179.                 // Get color index 
  180.                 int Index = ID - ID_SLIDER_RED; 
  181.  
  182.                 // Fill in the slider shaft with appropriate color 
  183.                 WinFillRect(POwnerItem->hps, 
  184.                             &POwnerItem->rclItem, 
  185.                             ShaftColors[Index]); 
  186.  
  187.                 // Return TRUE so the slider won't draw its own slider shaft 
  188.                 return (MRESULT) TRUE; 
  189.               } 
  190.             } 
  191.           } 
  192.  
  193.           break; 
  194.       } 
  195.  
  196.       break; 
  197.     } 
  198.  
  199.     // case Command 
  200.     case WM_COMMAND: 
  201.  
  202.       // switch on the dialog item 
  203.       switch (SHORT1FROMMP(mp1)) 
  204.       { 
  205.         // case OK 
  206.         // case Cancel 
  207.         case DID_OK: 
  208.         case DID_CANCEL: 
  209.  
  210.           // Dismiss the dialog 
  211.           WinDismissDlg(hwndDlg, (ULONG) SHORT1FROMMP(mp1)); 
  212.  
  213.           break; 
  214.  
  215.         // default case 
  216.         default: 
  217.  
  218.           // get PM's default procedure to handle the request 
  219.           return WinDefDlgProc(hwndDlg, 
  220.                                msg, 
  221.                                mp1, 
  222.                                mp2); 
  223.  
  224.           break; 
  225.       } 
  226.  
  227.       break; 
  228.  
  229.     // case Control 
  230.     case WM_CONTROL: 
  231.     { 
  232.       // Get control identifier 
  233.       SHORT ID = SHORT1FROMMP(mp1); 
  234.  
  235.       // switch on the dialog item 
  236.       switch (ID) 
  237.       { 
  238.         // case red, green or blue slider 
  239.         case ID_SLIDER_RED: 
  240.         case ID_SLIDER_GREEN: 
  241.         case ID_SLIDER_BLUE: 
  242.  
  243.           // switch on the PM action 
  244.           switch (SHORT2FROMMP(mp1)) 
  245.           { 
  246.             // case slider change 
  247.             case SLN_CHANGE: 
  248.             case SLN_SLIDERTRACK: 
  249.             { 
  250.               // If not already setting values 
  251.               if (Setting == FALSE) 
  252.               { 
  253.                 // Get index for red, green, blue 
  254.                 SHORT Index = ID - ID_SLIDER_RED; 
  255.  
  256.                 // get the new color value 
  257.                 RGBColors[Index] = SHORT1FROMMR(WinSendDlgItemMsg(hwndDlg, 
  258.                                                 ID, 
  259.                                                 SLM_QUERYSLIDERINFO, 
  260.                                                 MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  261.                                                              SMA_INCREMENTVALUE), 
  262.                                                 MPFROMLONG(0))); 
  263.  
  264.                 // We're setting values 
  265.                 Setting = TRUE; 
  266.  
  267.                 // Set corresponding spin button 
  268.                 WinSendDlgItemMsg(hwndDlg, 
  269.                                   ID_SPIN_RED + Index, 
  270.                                   SPBM_SETCURRENTVALUE, 
  271.                                   MPFROMLONG((long) RGBColors[Index]), 
  272.                                   0); 
  273.  
  274.                 // We're no longer setting values 
  275.                 Setting = FALSE; 
  276.  
  277.                 // invalidate the mix window so it will get redrawn 
  278.                 WinInvalidateRect(WinWindowFromID(hwndDlg, 
  279.                                                   ID_MIX), 
  280.                                   NULL, 
  281.                                   FALSE); 
  282.               } 
  283.  
  284.               break; 
  285.             } 
  286.  
  287.             // default case 
  288.             default: 
  289.  
  290.               // get PM's default procedure to handle the request 
  291.               return WinDefDlgProc(hwndDlg, 
  292.                                    msg, 
  293.                                    mp1, 
  294.                                    mp2); 
  295.  
  296.               break; 
  297.           } 
  298.           // endswitch - switch on the PM action 
  299.  
  300.           break; 
  301.  
  302.         // case red, green or blue spin button 
  303.         case ID_SPIN_RED: 
  304.         case ID_SPIN_GREEN: 
  305.         case ID_SPIN_BLUE: 
  306.  
  307.           // switch on the PM action 
  308.           switch (SHORT2FROMMP(mp1)) 
  309.           { 
  310.             // case value change 
  311.             case SPBN_CHANGE: 
  312.             { 
  313.               // If not already setting values 
  314.               if (Setting == FALSE) 
  315.               { 
  316.                 // Get index for red, green, blue 
  317.                 SHORT Index = ID - ID_SPIN_RED; 
  318.  
  319.                 // get the new color value 
  320.                 long NewValue; 
  321.                 WinSendDlgItemMsg(hwndDlg, 
  322.                                   ID, 
  323.                                   SPBM_QUERYVALUE, 
  324.                                   MRFROMP(&NewValue), 
  325.                                   MRFROM2SHORT(0, 
  326.                                                SPBQ_ALWAYSUPDATE)); 
  327.                 RGBColors[Index] = (SHORT) NewValue; 
  328.  
  329.                 // We're setting values 
  330.                 Setting = TRUE; 
  331.  
  332.                 // Set slider value 
  333.                 WinSendDlgItemMsg(hwndDlg, 
  334.                                   ID_SLIDER_RED + Index, 
  335.                                   SLM_SETSLIDERINFO, 
  336.                                   MPFROM2SHORT(SMA_SLIDERARMPOSITION, 
  337.                                                SMA_INCREMENTVALUE), 
  338.                                   MPFROMSHORT(RGBColors[Index])); 
  339.  
  340.                 // We're no longer setting values 
  341.                 Setting = FALSE; 
  342.  
  343.                 // invalidate the mix window so it will get redrawn 
  344.                 WinInvalidateRect(WinWindowFromID(hwndDlg, 
  345.                                                   ID_MIX), 
  346.                                   NULL, 
  347.                                   FALSE); 
  348.               } 
  349.               else 
  350.  
  351.               break; 
  352.             } 
  353.  
  354.             // default case 
  355.             default: 
  356.  
  357.               // get PM's default procedure to handle the request 
  358.               return WinDefDlgProc(hwndDlg, 
  359.                                    msg, 
  360.                                    mp1, 
  361.                                    mp2); 
  362.  
  363.               break; 
  364.           } 
  365.           // endswitch - switch on the PM action 
  366.  
  367.           break; 
  368.  
  369.         // default case 
  370.         default: 
  371.  
  372.           // get PM's default procedure to handle the request 
  373.           return WinDefDlgProc(hwndDlg, 
  374.                                msg, 
  375.                                mp1, 
  376.                                mp2); 
  377.  
  378.           break; 
  379.       } 
  380.       // endswitch - switch on the dialog item 
  381.       break; 
  382.     } 
  383.  
  384.     // default case 
  385.     default: 
  386.  
  387.       // get PM's default procedure to handle the request 
  388.       return WinDefDlgProc(hwndDlg, 
  389.                            msg, 
  390.                            mp1, 
  391.                            mp2); 
  392.  
  393.       break; 
  394.   } 
  395.  
  396.   return FALSE; 
  397.  
  398.  
  399. MRESULT EXPENTRY fnwpColorSample( HWND hwnd, ULONG msg, 
  400.                                   MPARAM mp1, MPARAM mp2 ) 
  401.   // If processing the paint message 
  402.   if (msg == WM_PAINT) 
  403.   { 
  404.     HPS    hps; 
  405.     RECTL  rcl,rcl1; 
  406.  
  407.     // Issue the begin paint 
  408.     hps = WinBeginPaint(hwnd, 
  409.                         NULL, 
  410.                         &rcl); 
  411.  
  412.     // Override the rectangle returned from WinBeginPaint with the 
  413.     // window's entire rectangle 
  414.     WinQueryWindowRect(hwnd, &rcl); 
  415.  
  416.     // Compose the color value needed by GpiCreateLogColorTable 
  417.     Color =                RGBColors[BLUE]   + 
  418.           (256L   * (LONG) RGBColors[GREEN]) + 
  419.           (65536L * (LONG) RGBColors[RED  ]); 
  420.  
  421.     // Create a color log table with one entry 
  422.     GpiCreateLogColorTable(hps, 
  423.                            LCOL_RESET, 
  424.                            LCOLF_RGB, 
  425.                            0L, 
  426.                            1L, 
  427.                            &Color); 
  428.  
  429.     // Issue four fills to outline the color in black 
  430.     rcl1.xLeft=rcl.xLeft; 
  431.     rcl1.xRight=rcl.xRight; 
  432.     rcl1.yTop=rcl.yTop; 
  433.     rcl1.yBottom=rcl.yTop - 4; 
  434.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  435.  
  436.     rcl1.xLeft=rcl.xLeft; 
  437.     rcl1.xRight=rcl.xRight; 
  438.     rcl1.yTop=rcl.yBottom + 4; 
  439.     rcl1.yBottom=rcl.yBottom; 
  440.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  441.  
  442.     rcl1.xLeft=rcl.xLeft; 
  443.     rcl1.xRight=rcl.xLeft + 4; 
  444.     rcl1.yTop=rcl.yTop - 4; 
  445.     rcl1.yBottom=rcl.yBottom + 4; 
  446.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  447.  
  448.     rcl1.xLeft=rcl.xRight - 4; 
  449.     rcl1.xRight=rcl.xRight; 
  450.     rcl1.yTop=rcl.yTop - 4; 
  451.     rcl1.yBottom=rcl.yBottom + 4; 
  452.     WinFillRect(hps, &rcl1, CLR_BLACK); 
  453.  
  454.     // Fill the rest of the rectangle with the current color 
  455.     rcl.xLeft += 5; 
  456.     rcl.yBottom += 5; 
  457.     rcl.xRight -= 5; 
  458.     rcl.yTop -= 5; 
  459.     WinFillRect(hps, &rcl, Color); 
  460.  
  461.     // Issue the end paint 
  462.     WinEndPaint( hps ); 
  463.  
  464.     // Return value is unimportant 
  465.     return FALSE; 
  466.   } 
  467.   else 
  468.   { 
  469.     // Pass all other messages to the default window procedure 
  470.     return WinDefWindowProc(hwnd, msg, mp1, mp2); 
  471.   } 
  472.  
  473.  
  474.