home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vos2-121.zip / v / draw / vdrwdlg.cpp < prev    next >
C/C++ Source or Header  |  1998-07-07  |  14KB  |  453 lines

  1. //=======================================================================
  2. //  vdrwdlg.cxx - Source file for vDrawDialog class
  3. //  Copyright (C) 1995,1996  Bruce E. Wampler
  4. //
  5. //  This program is part of the V C++ GUI Framework example programs.
  6. //
  7. //  This program is free software; you can redistribute it and/or modify
  8. //  it under the terms of the GNU General Public License as published by
  9. //  the Free Software Foundation; either version 2 of the License, or
  10. //  (at your option) any later version.
  11. //
  12. //  This program is distributed in the hope that it will be useful,
  13. //  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. //  GNU General Public License for more details.
  16. //
  17. //  You should have received a copy of the GNU General Public License
  18. //  (see COPYING) along with this program; if not, write to the Free
  19. //  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. //=======================================================================
  21.  
  22. #include "vdrwdlg.h"
  23. #include "vdrwcmdw.h"
  24. #include <v/vcolor.h>
  25. #include <v/vapp.h>
  26. #include <v/vwindow.h>
  27. #include <v/vicon.h>
  28.  
  29. #include "rect.xbm"
  30. #include "rdrect.xbm"
  31. #include "ellipse.xbm"
  32. #include "line.xbm"
  33. #include "point.xbm"
  34. #include "polygon.xbm"
  35.  
  36.     static vIcon rect(&rect_bits[0], rect_height, rect_width);
  37.  //    = {BitMap, rect_height, rect_width, 1, &rect_bits[0]};
  38.  
  39.     static vIcon rdrect(&rdrect_bits[0], rdrect_height, rdrect_width);
  40.  //    = {BitMap, rdrect_height, rdrect_width, 1, &rdrect_bits[0]};
  41.  
  42.     static vIcon ellipse(&ellipse_bits[0], ellipse_height, ellipse_width);
  43.  //    = {BitMap, ellipse_height, ellipse_width, 1, &ellipse_bits[0]};
  44.  
  45.     static vIcon line(&line_bits[0], line_height, line_width);
  46.   //   = {BitMap, line_height, line_width, 1, &line_bits[0]};
  47.  
  48.     static vIcon point(&point_bits[0], point_height, point_width);
  49.   //   = {BitMap, point_height, point_width, 1, &point_bits[0]};
  50.  
  51.     static vIcon polygon(&polygon_bits[0], polygon_height, polygon_width);
  52.  //    = {BitMap, polygon_height, polygon_width, 1, &polygon_bits[0]};
  53.  
  54. const int drawPoint = 0;    // same order as drawShap/drawVal in vdrwcmdw.cxx
  55. const int drawLine = 1;
  56. const int drawRect = 2;
  57. const int drawRdRect = 3;
  58. const int drawEllipse = 4;
  59. const int drawPoly = 5;
  60.  
  61.  
  62. const ItemVal lbL1 = 999;
  63. const ItemVal lbL2 = 998;
  64.  
  65. const ItemVal frShapeBox = 104;
  66. const ItemVal frShape = 105;
  67. const ItemVal icPoint = 110;
  68. const ItemVal icLine = 111;
  69. const ItemVal icRect = 112;
  70. const ItemVal icRdRect = 113;
  71. const ItemVal icEllipse = 114;
  72. const ItemVal icPolygon = 115;
  73.  
  74. const ItemVal frColors = 150;
  75. const ItemVal frWhich = 151;
  76. const ItemVal cbtPen = 152;
  77. const ItemVal rbPen = 153;
  78. const ItemVal cbPen = 154;
  79. const ItemVal cbtBrush = 155;
  80. const ItemVal rbBrush = 156;
  81. const ItemVal cbBrush = 157;
  82. const ItemVal cbtBG = 158;
  83. const ItemVal rbBG = 159;
  84.  
  85. const ItemVal btClose = 200;
  86. const ItemVal btApply = 201;
  87.  
  88.  
  89.     static vColor clrPen(0,0,0);
  90.     static vColor clrBrush(0,0,0);
  91.     static vColor clrBG(255,255,255);
  92.  
  93.     static char *penStyles[] =
  94.       {
  95.     "Solid", "Transparent", "Dash", "Dot", "DashDot", 0
  96.       };
  97.  
  98.     static ItemVal penMap[] =
  99.       {
  100.     m_PenSolid, m_PenTransparent, m_PenDash, m_PenDot, m_PenDashDot, 0
  101.       };
  102.  
  103.     static char *brushStyles[] =
  104.       {
  105.     "Solid", "Transparent", "Horizontal", "Vertical",
  106.     "Left Diag", "Right Diag", "Cross", "Diag Cross", 0
  107.       };
  108.  
  109.     static ItemVal brushMap[] =
  110.       {
  111.     m_BrushSolid, m_BrushTransparent, m_BrushHoriz,  m_BrushVert,
  112.     m_BrushLeft, m_BrushRight, m_BrushCross, m_BrushDiagCross, 0
  113.       };
  114.  
  115.     static CommandObject DefaultCmds[] =
  116.       {
  117.     {C_Label, lbL1, 0,"                           ",NoList,CA_MainMsg,isSens,NoFrame, 0, 0},
  118.     
  119.     //----------- The set color frame ---------------------------------
  120.     {C_Frame, frColors, 0, "", NoList, CA_None, isSens, NoFrame, 0, lbL1},
  121.     {C_Frame, frWhich, 0, "", NoList, CA_NoSpace | CA_NoBorder, isSens,
  122.         frColors, 0, 0},
  123.     {C_ColorButton, cbtPen, 0," ",(void*)&clrPen,CA_None,isSens,
  124.         frWhich, 0, 0},
  125.     {C_RadioButton, rbPen, 1, "Pen  ", NoList, CA_None, isSens,
  126.         frWhich, cbtPen, 0},
  127.     {C_ComboBox, cbPen,0,"",(void*)penStyles, CA_None, isSens,
  128.         frWhich, rbPen, 0},
  129.     {C_ColorButton, cbtBrush, 0," ",(void*)&clrBrush,CA_None,isSens,
  130.         frWhich, 0, cbPen},
  131.     {C_RadioButton, rbBrush, 0, "Brush", NoList, CA_None, isSens,
  132.         frWhich, cbtBrush, cbPen},
  133.     {C_ComboBox, cbBrush,0,"",(void*)brushStyles, CA_None, isSens,
  134.         frWhich, rbBrush, cbPen},
  135.     {C_ColorButton, cbtBG, 0," ",(void*)&clrBG,CA_None,isSens,
  136.         frWhich, 0, cbBrush},
  137.     {C_RadioButton, rbBG, 0, "Background", NoList, CA_None, isSens,
  138.         frWhich, cbtBG, cbBrush},
  139. #define vC_Size 12
  140. #define vC_Frame frColors
  141. #define vC_Below frWhich
  142. #include <v/vcb2x8.h>
  143.  
  144.     //----------- The shape frame ---------------------------------
  145. //    {C_Frame, frShape, 0, "", NoList, CA_NoSpace | CA_NoBorder, isSens,
  146.     {C_Frame, frShape, 0, "", NoList, CA_NoBorder, isSens,
  147.         frColors, 0, M_ColorFrame},
  148.  
  149.     {C_ToggleIconButton, icPoint, 0, "", (void*)&point, CA_None, isSens, frShape, 0, 0},
  150.     {C_ToggleIconButton, icLine, 0, "", (void*)&line, CA_None, isSens, frShape, 0,
  151.         icPoint},
  152.  
  153.     {C_ToggleIconButton, icRect, 1, "", (void*)&rect, CA_None, isSens, frShape,
  154.         icPoint, 0},
  155.     {C_ToggleIconButton, icRdRect, 0, "", (void*)&rdrect, CA_None, isSens, frShape,
  156.         icPoint, icRect},
  157.  
  158.     {C_ToggleIconButton, icEllipse, 0, "", (void*)&ellipse, CA_None, isSens, frShape,
  159.         icRect, 0},
  160.     {C_ToggleIconButton, icPolygon, 0, "", (void*)&polygon, CA_None, isSens, frShape,
  161.         icRect, icEllipse},
  162.     
  163.     {C_Button, btClose, 0, "Close",NoList, CA_None, isSens, NoFrame,
  164.         0, frColors},
  165.     {C_Button, btApply, 0, "Apply",NoList, CA_None, isSens, NoFrame,
  166.         btClose, frColors},
  167.  
  168.     {C_EndOfList,0,0,0,0,CA_None,0,0,0}
  169.       };
  170.  
  171.     static ItemVal curDrawType = icRect;
  172.  
  173. //==========================>>> SetCmdObjAttr <<<==============================
  174.   void SetCmdObjAttr(CommandObject* cList, ItemVal id, CmdAttribute newAttr)
  175.   {
  176.     // This is called to change the attrs field of the item with given id
  177.  
  178.     // scan the entire list
  179.  
  180.     int ix;
  181.     for (ix = 0 ; cList && (cList[ix].cmdType != C_EndOfList) ; ++ix)
  182.       {
  183.     if (cList[ix].cmdId == id)        // the one we want!
  184.       {
  185.         cList[ix].attrs = newAttr;        // change
  186.         break;
  187.       }
  188.       }
  189.    }
  190.  
  191. //==========================>>> SetCmdObjCmdType <<<===========================
  192.   void SetCmdObjCmdType(CommandObject* cList, ItemVal id, CmdType ct)
  193.   {
  194.     // This is called to change the attrs field of the item with given id
  195.  
  196.     // scan the entire list
  197.  
  198.     int ix;
  199.     for (ix = 0 ; cList && (cList[ix].cmdType != C_EndOfList) ; ++ix)
  200.       {
  201.     if (cList[ix].cmdId == id)        // the one we want!
  202.       {
  203.         cList[ix].cmdType = ct;        // change
  204.         break;
  205.       }
  206.       }                                          // special case - changing last
  207.     if (cList[ix].cmdId == id)
  208.     cList[ix].cmdType = ct;
  209.    }
  210.  
  211. //=========================>>> vDrawDialog::vDrawDialog <<<====================
  212.  vDrawDialog::vDrawDialog(vBaseWindow* bw, int All) :
  213.     vDialog(bw, 0, "Quick Pick")
  214.   {
  215.     UserDebug(Constructor,"vDrawDialog::vDrawDialog(basewindow)\n")
  216.     toAll = All;
  217.     pWin = (vWindow*) bw;
  218.     init();
  219.   }
  220.  
  221. //=========================>>> vDrawDialog::vDrawDialog <<<====================
  222.  vDrawDialog::vDrawDialog(vApp* aw) :
  223.     vDialog(aw, 0, "Global Quick Pick")
  224.   {
  225.     UserDebug(Constructor,"vDrawDialog::vDrawDialog(vapp)\n")
  226.     toAll = 1;
  227.     pWin = (vWindow*) NULL;
  228.     init();
  229.   }
  230.  
  231. //=========================>>> vDrawDialog::vDrawDialog <<<====================
  232.  void vDrawDialog::init()
  233.   {
  234.  
  235.     if (!toAll)            // State of Close and Apply depend on parent
  236.       {
  237.     SetCmdObjCmdType(DefaultCmds, btClose, C_EndOfList);
  238.       }
  239.     else
  240.       {
  241.     SetCmdObjCmdType(DefaultCmds, btClose, C_Button);
  242.       }
  243.  
  244.     AddDialogCmds(DefaultCmds);        // add the predefined commands
  245.  
  246.     setWhatColor = setPen;
  247.     drawWhatShape = drawLine;
  248.     penColorMsg = M_Black;        // message id of current color
  249.     brushColorMsg = M_Black;        // for pen, brush, and bg
  250.     bgColorMsg = M_White;
  251.     penColorVal = vC_Black;        // message id of current color
  252.     brushColorVal = vC_Black;        // for pen, brush, and bg
  253.     bgColorVal = vC_White;
  254.     penStyleMsg = m_PenSolid;        // solid pen
  255.     brushStyleMsg = m_BrushSolid;    // solid brush
  256.   }
  257.  
  258. //========================>>> vDrawDialog::~vDrawDialog <<<====================
  259.   vDrawDialog::~vDrawDialog()
  260.   {
  261.     UserDebug(Destructor,"vDrawDialog::~vDrawDialog() destructor\n")
  262.   }
  263.  
  264. //====================>>> vDrawDialog::DialogCommand <<<=======================
  265.   void vDrawDialog::DialogCommand(ItemVal id, ItemVal val, CmdType ctype)
  266.   {
  267.     // After the user has selected a command from the dialog,
  268.     // this routine is called with the value.  This code would be generated
  269.     // by Vigr.
  270.  
  271.     UserDebug2(CmdEvents,"vDrawDialog::DialogCommand(id:%d, val:%d)\n",id, val)
  272.  
  273.     switch (id)        // We will do some things depending on value
  274.       {
  275.     // Draw Shape Radio Buttons
  276.     case icPoint:
  277.         SetValue(curDrawType,0,Value);
  278.         curDrawType = id;
  279.         SetValue(curDrawType,1,Value);
  280.         drawWhatShape = drawPoint;
  281.         break;
  282.     case icLine:
  283.         SetValue(curDrawType,0,Value);
  284.         curDrawType = id;
  285.         SetValue(curDrawType,1,Value);
  286.         drawWhatShape = drawLine;
  287.         break;
  288.     case icRect:
  289.         SetValue(curDrawType,0,Value);
  290.         curDrawType = id;
  291.         SetValue(curDrawType,1,Value);
  292.         drawWhatShape = drawRect;
  293.         break;
  294.  
  295.     case icRdRect:
  296.         SetValue(curDrawType,0,Value);
  297.         curDrawType = id;
  298.         SetValue(curDrawType,1,Value);
  299.         drawWhatShape = drawRdRect;
  300.         break;
  301.  
  302.     case icEllipse:
  303.         SetValue(curDrawType,0,Value);
  304.         curDrawType = id;
  305.         SetValue(curDrawType,1,Value);
  306.         drawWhatShape = drawEllipse;
  307.         break;
  308.  
  309.     case icPolygon:
  310.         SetValue(curDrawType,0,Value);
  311.         curDrawType = id;
  312.         SetValue(curDrawType,1,Value);
  313.         drawWhatShape = drawPoly;
  314.         break;
  315.  
  316.     // Pen/Brush/BG Radio Buttons
  317.     case rbPen:
  318.         if (val)
  319.           {
  320.         setWhatColor = setPen;
  321.           }
  322.         break;
  323.     case rbBrush:
  324.         if (val)
  325.           {
  326.         setWhatColor = setBrush;
  327.           }
  328.         break;
  329.     case rbBG:
  330.         if (val)
  331.           {
  332.         setWhatColor = setBG;
  333.           }
  334.         break;
  335.  
  336.     case btClose:        // Close the dialog
  337.       {
  338.         CloseDialog();
  339.         break;
  340.       }
  341.  
  342.     case cbPen:
  343.       {
  344.         penStyleMsg = penMap[val];    // map to correct command
  345.         break;
  346.       }
  347.  
  348.     case cbBrush:
  349.       {
  350.         brushStyleMsg = brushMap[val];
  351.         break;
  352.       }
  353.  
  354.     case btApply:        // Apply settings to all windows
  355.       {
  356.         if (!toAll)
  357.         break;
  358.  
  359.         // Implementing this command requires close coordination
  360.         // with the vDrawCommandWindow class so messages can be
  361.         // handled appropriately.
  362.  
  363.         // First, set the color of the pen, brush, and background.
  364.         // Change window to set each one, then send the color
  365.         theApp->SendWindowCommandAll(m_PenBrushCombo, setPen, C_ComboBox);
  366.         theApp->SendWindowCommandAll(penColorMsg, penColorVal, C_ColorButton);
  367.         theApp->SendWindowCommandAll(m_PenBrushCombo, setBrush, C_ComboBox);
  368.         theApp->SendWindowCommandAll(brushColorMsg, brushColorVal, C_ColorButton);
  369.         theApp->SendWindowCommandAll(m_PenBrushCombo, setBG, C_ComboBox);
  370.         theApp->SendWindowCommandAll(bgColorMsg, bgColorVal, C_ColorButton);
  371.         theApp->SendWindowCommandAll(penStyleMsg, 1, C_Button);
  372.         theApp->SendWindowCommandAll(brushStyleMsg, 1, C_Button);
  373.  
  374.  
  375.         // And finally set the set mode to whatever ours is, both to
  376.         // the WindowCommand method, and to the combo box
  377.         theApp->SendWindowCommandAll(m_PenBrushCombo, setWhatColor, C_ComboBox);
  378.         theApp->SetValueAll(m_PenBrushCombo, setWhatColor, Value);
  379.  
  380.         // Next, set the shape
  381.         theApp->SendWindowCommandAll(m_DrawCombo,drawWhatShape,C_ComboBox);
  382.         theApp->SetValueAll(m_DrawCombo,drawWhatShape,Value);
  383.  
  384.         break;
  385.       }
  386.  
  387.     default:        // set a color...
  388.  
  389.         if (id >= M_Black && id <= M_White)  // color button
  390.           {
  391.         if (setWhatColor == setPen)
  392.           {
  393.             penColorMsg = id;
  394.             penColorVal = val;
  395.             clrPen.Set(vStdColors[val]);
  396.             SetValue(cbtPen,(ItemVal)clrPen.r(),Red);
  397.             SetValue(cbtPen,(ItemVal)clrPen.g(),Green);
  398.             SetValue(cbtPen,(ItemVal)clrPen.b(),Blue);
  399.           }
  400.         else if (setWhatColor == setBrush)
  401.           {
  402.             brushColorMsg = id;
  403.             brushColorVal = val;
  404.             clrBrush.Set( vStdColors[val]);
  405.             SetValue(cbtBrush,(ItemVal)clrBrush.r(),Red);
  406.             SetValue(cbtBrush,(ItemVal)clrBrush.g(),Green);
  407.             SetValue(cbtBrush,(ItemVal)clrBrush.b(),Blue);
  408.           }
  409.         else
  410.           {
  411.             bgColorMsg = id;
  412.             bgColorVal = val;
  413.             clrBG.Set(vStdColors[val]);
  414.             SetValue(cbtBG,(ItemVal)clrBG.r(),Red);
  415.             SetValue(cbtBG,(ItemVal)clrBG.g(),Green);
  416.             SetValue(cbtBG,(ItemVal)clrBG.b(),Blue);
  417.           }
  418.         break;
  419.           }
  420.       }
  421.  
  422.     if (!toAll && pWin)        // update what we did
  423.       {
  424.  
  425.     // Implementing this command requires close coordination
  426.     // with the vDrawCommandWindow class so messages can be
  427.     // handled appropriately.
  428.  
  429.     // First, set the color of the pen, brush, and background.
  430.     // Change window to set each one, then send the color
  431.     pWin->WindowCommand(m_PenBrushCombo, setPen, C_ComboBox);
  432.     pWin->WindowCommand(penColorMsg, penColorVal, C_ColorButton);
  433.     pWin->WindowCommand(m_PenBrushCombo, setBrush, C_ComboBox);
  434.     pWin->WindowCommand(brushColorMsg, brushColorVal, C_ColorButton);
  435.     pWin->WindowCommand(m_PenBrushCombo, setBG, C_ComboBox);
  436.     pWin->WindowCommand(bgColorMsg, bgColorVal, C_ColorButton);
  437.     pWin->WindowCommand(penStyleMsg, 1, C_Button);
  438.     pWin->WindowCommand(brushStyleMsg, 1, C_Button);
  439.  
  440.     // And finally set the set mode to whatever ours is, both to
  441.     // the WindowCommand method, and to the combo box
  442.     pWin->WindowCommand(m_PenBrushCombo, setWhatColor, C_ComboBox);
  443.     pWin->SetValue(m_PenBrushCombo, setWhatColor, Value);
  444.  
  445.     // Next, set the shape
  446.     pWin->WindowCommand(m_DrawCombo,drawWhatShape,C_ComboBox);
  447.     pWin->SetValue(m_DrawCombo,drawWhatShape,Value);
  448.       }
  449.  
  450.     // All commands should also route through the parent handler
  451.     vDialog::DialogCommand(id,val,ctype);
  452.   }
  453.