home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / listpm7.zip / pallet.cpp < prev    next >
C/C++ Source or Header  |  1999-07-12  |  64KB  |  2,493 lines

  1. /*
  2. -------------------------------------------------------------------------------
  3. Copyright (c) IBM Corporation 1996, 1997.
  4. All Rights Reserved.
  5.  
  6. Permission is granted to copy, use, modify, and merge this software into your
  7. applications and to permit others to do any of the foregoing. You must include
  8. this permission and copyright notice in all copies and modified versions of
  9. this software. THIS SOFTWARE IS PROVIDED IN ITS 'AS IS' CONDITION.
  10. IBM DISCLAIMS ANY LIABILITY OF ANY KIND FOR DAMAGES WHATSOEVER RESULTING
  11. FROM THE USE OF THIS SOFTWARE.
  12. -------------------------------------------------------------------------------
  13. */
  14.  
  15. #include "pallet.hpp"
  16. //#include "2dpglbl.h"
  17. #include <iiconctl.hpp>
  18. #include <ifontdlg.hpp>
  19. #include <iostream.h>
  20. #include <stdlib.h>
  21.  
  22. #ifndef _ISTRMMOD_
  23. #include <istrmmod.hpp>
  24. #endif
  25.  
  26. IStreamModule gSampleStreamModule("PrintTestStreamModule");
  27.  
  28.  
  29.  
  30. // global color pallet
  31. IBaseColor *colorTable[PALLETCANVAS_SQUARE][PALLETCANVAS_SQUARE];
  32.  
  33. const  GCoordinate kMMPerInch = 25.4;
  34. const  GCoordinate dpiAlbert = 72.0;
  35.  
  36. //*************************************************************************
  37. // Class IColorSelector: method definitions                               *
  38. //*************************************************************************
  39.  
  40. /*
  41.  * Function: IColorSelector::IColorSelector
  42.  *
  43.  * Parameters:
  44.  *   id     : the window's id
  45.  *   parent : a pointer to the parent window
  46.  *   owner  : a pointer to the owner window
  47.  *   t      : specifies type (Red_type, Green_type, Blue_type
  48.  *   h      : specifies horizontal (true) or vertical (false) orientation
  49.  *
  50.  * Return value: NONE
  51.  *
  52.  * Purpose: constructor for IColorSelector
  53.  *
  54. */
  55.  
  56. IColorSelector::IColorSelector(long id, IWindow* parent, IWindow* owner,
  57.                                IColorSelector::ColorType t, bool h)
  58.   : ICanvas(id, parent, owner, IRectangle(), ICanvas::defaultStyle() |
  59.                                              IWindow::clipSiblings),
  60.     win(owner),
  61.     value(0),
  62.     type(t),
  63.     capturing(false),
  64.     horizontal(h)
  65. {
  66.   // start up the event handlers
  67.   IMouseHandler::handleEventsFor(this);
  68.   IPaintHandler::handleEventsFor(this);
  69.  
  70.   // size with respect to orientation
  71.   if(horizontal)
  72.      sizeTo(ISize(IGPoint2D(COLORSELECTOR_WIDTH,COLORSELECTOR_HEIGHT).fX,
  73.                   IGPoint2D(COLORSELECTOR_WIDTH,COLORSELECTOR_HEIGHT).fY));
  74.  
  75.   else
  76.      sizeTo(ISize(IGPoint2D(COLORSELECTOR_WIDTH,COLORSELECTOR_HEIGHT).fY,
  77.                   IGPoint2D(COLORSELECTOR_WIDTH,COLORSELECTOR_HEIGHT).fX));
  78.  
  79.   managedPresSpacePtr = new IManagedPresSpaceHandle(this);
  80.  
  81. }
  82.  
  83. /*
  84.  * Function: IColorSelector::~IColorSelector
  85.  *
  86.  * Parameters: NONE
  87.  *
  88.  * Return Value: NONE
  89.  *
  90.  * Purpose: destructor for IColorSelector
  91.  *
  92. */
  93.  
  94. IColorSelector::~IColorSelector()
  95. {
  96.   // shut down the event handlers
  97.   IMouseHandler::stopHandlingEventsFor(this);
  98.   IPaintHandler::stopHandlingEventsFor(this);
  99.  
  100.   delete managedPresSpacePtr;
  101.  
  102. }
  103.  
  104. /*
  105.  * Function: IColorSelector::GetValue
  106.  *
  107.  * Parameters: NONE
  108.  *
  109.  * Return Value: the current color value selected
  110.  *
  111.  * Purpose: returns the current color value (between 0 and 1) selected
  112.  *
  113. */
  114.  
  115. CharIntensity IColorSelector::GetValue()
  116. {
  117.   return value;
  118.  
  119. }
  120.  
  121. /*
  122.  * Function: IColorSelector::SetValue
  123.  *
  124.  * Parameters:
  125.  *   val : the new value to be selected/set range 0-255
  126.  *
  127.  * Return value: returns the previous selection value
  128.  *
  129.  * Purpose: changes the current value of the selection and
  130.  *          repositions the selection indicator
  131.  *
  132. */
  133.  
  134. CharIntensity IColorSelector::SetValue(CharIntensity val)
  135. {
  136.   // create the rendering devices
  137.   IBaseRootGrafPort myDisplayPort(this->presSpace());
  138.  
  139.   CharIntensity oldVal = value;    // the current selection
  140.   CharIntensity valPos = value / (255/COLORSELECTOR_COLORS);
  141.  
  142.   // erase the old selection indicator
  143.   if(horizontal) {
  144.  
  145.      for(CharIntensity i = valPos-1; (i < valPos+2) && (i <= COLORSELECTOR_COLORS); i++) {
  146.  
  147.       IGLine2D line(IGPoint2D(i,0),IGPoint2D(i,COLORSELECTOR_HEIGHT));
  148.       CharIntensity j = i*(255/COLORSELECTOR_COLORS);
  149.       if(j < 0) j = 0;
  150.  
  151.       switch(type) {
  152.  
  153.         case Red_type:
  154.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j,0,0),2));
  155.           break;
  156.  
  157.         case Green_type:
  158.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,j,0),2));
  159.           break;
  160.  
  161.         case Blue_type:
  162.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,0,j),2));
  163.           break;
  164.  
  165.         case Gray_type:
  166.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j),2));
  167.           break;
  168.  
  169.       }
  170.  
  171.     }
  172.  
  173.     // render the new selection indicator
  174.     valPos = val / (255/COLORSELECTOR_COLORS);
  175.     IGRect2D selection(IGPoint2D(valPos-1,0),IGPoint2D(valPos+1,COLORSELECTOR_HEIGHT));
  176.     myDisplayPort.draw(selection,IFrameBundle(IBaseColor(IBaseColor::kWhite)));
  177.  
  178.   }
  179.  
  180.   else {  // vertical
  181.  
  182.      for(CharIntensity i = valPos-1; (i < valPos+2) && (i <= COLORSELECTOR_COLORS); i++) {
  183.  
  184.       IGLine2D line(IGPoint2D(0,i),IGPoint2D(COLORSELECTOR_HEIGHT,i));
  185.       CharIntensity j = i*(255/COLORSELECTOR_COLORS);
  186.       if(j < 0) j = 0;
  187.  
  188.       switch(type) {
  189.  
  190.         case Red_type:
  191.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j,0,0),2));
  192.           break;
  193.  
  194.         case Green_type:
  195.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,j,0),2));
  196.           break;
  197.  
  198.         case Blue_type:
  199.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,0,j),2));
  200.           break;
  201.  
  202.         case Gray_type:
  203.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j),2));
  204.           break;
  205.  
  206.       }
  207.  
  208.     }
  209.  
  210.     // render the new selection indicator
  211.     valPos = val / (255/COLORSELECTOR_COLORS);
  212.     IGRect2D selection(IGPoint2D(0,valPos-1),IGPoint2D(COLORSELECTOR_HEIGHT,valPos+1));
  213.     myDisplayPort.draw(selection,IFrameBundle(IBaseColor(IBaseColor::kWhite)));
  214.  
  215.   }
  216.  
  217.   value = val;
  218.   return oldVal;
  219.  
  220. }
  221.  
  222. /*
  223.  * Function: IColorSelector::paintWindow
  224.  *
  225.  * Parameter:
  226.  *   event: the type of paint event to be handled - ignored in this method
  227.  *
  228.  * Return value: returns true if painting is done - in this case; always true
  229.  *
  230.  * Purpose: renders the control to the screen when update required
  231.  *
  232. */
  233.  
  234. bool IColorSelector::paintWindow(IPaintEvent &event)
  235. {
  236.   // create the rendering devices
  237.   IBaseRootGrafPort myDisplayPort(this->presSpace());
  238.  
  239.   CharIntensity valPos;     // the indicator position
  240.  
  241.   // render the gradient field
  242.   if(horizontal) {
  243.  
  244.      for(CharIntensity i = 0; i <= COLORSELECTOR_COLORS; i++) {
  245.  
  246.       IGLine2D line(IGPoint2D(i,0),IGPoint2D(i,COLORSELECTOR_HEIGHT-1));
  247.  
  248.       CharIntensity j = i * (255/COLORSELECTOR_COLORS);
  249.           if (j < 0) j = 0;
  250.  
  251.       switch(type) {
  252.  
  253.         case Red_type:
  254.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j,0,0),2));
  255.           break;
  256.  
  257.         case Green_type:
  258.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,j,0),2));
  259.           break;
  260.  
  261.         case Blue_type:
  262.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,0,j),2));
  263.           break;
  264.  
  265.         case Gray_type:
  266.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j),2));
  267.           break;
  268.  
  269.       }
  270.  
  271.     }
  272.  
  273.     // render the selection indicator
  274.     valPos = value / (255/COLORSELECTOR_COLORS);
  275.     IGRect2D selection(IGPoint2D(valPos-1,0),IGPoint2D(valPos+1,COLORSELECTOR_HEIGHT-1));
  276.     myDisplayPort.draw(selection,IFrameBundle(IBaseColor(IBaseColor::kWhite)));
  277. }
  278.  
  279.   else {  // vertical
  280.  
  281.      for(CharIntensity i = 0; i <= COLORSELECTOR_COLORS; i++) {
  282.  
  283.       IGLine2D line(IGPoint2D(0,i),IGPoint2D(COLORSELECTOR_HEIGHT-1,i));
  284.  
  285.       CharIntensity j = i * (255/COLORSELECTOR_COLORS);
  286.           if (j < 0) j = 0;
  287.  
  288.       switch(type) {
  289.  
  290.         case Red_type:
  291.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j,0,0),2));
  292.           break;
  293.  
  294.         case Green_type:
  295.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,j,0),2));
  296.           break;
  297.  
  298.         case Blue_type:
  299.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(0,0,j),2));
  300.           break;
  301.  
  302.         case Gray_type:
  303.           myDisplayPort.draw(line,IFrameBundle(IBaseColor(j),2));
  304.           break;
  305.  
  306.       }
  307.  
  308.     }
  309.  
  310.     // render the selection indicator
  311.     valPos = value / (255/COLORSELECTOR_COLORS);
  312.     IGRect2D selection(0,valPos-1,COLORSELECTOR_HEIGHT-5,valPos+1);
  313.     myDisplayPort.draw(selection,IFrameBundle(IBaseColor(IBaseColor::kWhite)));
  314.  
  315.   }
  316.  
  317.   return true;
  318.  
  319. }
  320.  
  321. /*
  322.  * Function: IColorSelector::mouseClicked
  323.  *
  324.  * Parameters:
  325.  *   event: used to describe the type of the mouse click event
  326.  *
  327.  * Return value: returns true if the event was processed
  328.  *
  329.  * Purpose: handles mouse clicks for updating the current selection
  330.  *
  331. */
  332.  
  333. bool IColorSelector::mouseClicked(IMouseClickEvent &event)
  334. {
  335.   bool result = false;     // the return result
  336.  
  337.   if ( event.mouseButton() == IMouseClickEvent::button1 &&
  338.        event.mouseAction() == IMouseClickEvent::down ) {
  339.  
  340.     CharIntensity val;     // the value of the current selection
  341.  
  342.     // capture the mouse pointer to allow dragging of the indicator
  343.     capturing = true;
  344.     capturePointer();
  345.  
  346.     // create the rendering devices
  347.     IBaseRootGrafPort myDisplayPort(this->presSpace());
  348.  
  349.     // Get the mouse position in world space
  350.     IGPoint2D talPoint;
  351.     IPoint point(event.mousePosition());
  352.     talPoint = myDisplayPort.pixelToPointSize().transformPoint(IGPoint2D(point));
  353.  
  354.     // calculate the value selection from the mouse position
  355.     if(horizontal)
  356.       val = (CharIntensity)(talPoint.fX * (255/COLORSELECTOR_COLORS));
  357.  
  358.     else
  359.       val = (CharIntensity)(talPoint.fY * (255/COLORSELECTOR_COLORS));
  360.  
  361.     // do some range checking/adjustment
  362.     if(val > 255) val = 255;
  363.  
  364.     else if(val < 0) val = 0;
  365.  
  366.     // set the new selection and do nescessary paint updates
  367.     SetValue(val);
  368.     ((IPalletDialog*)win)->SetValue(value,type);
  369.  
  370.     result = true;
  371.  
  372.   }
  373.  
  374.   else if( event.mouseButton() == IMouseClickEvent::button1 &&
  375.            event.mouseAction() == IMouseClickEvent::up ) {
  376.  
  377.     // disable mouse pointer capturing when the mouse is released
  378.     capturePointer(false);
  379.     capturing = false;
  380.     result = true;
  381.  
  382.   }
  383.  
  384.   return result;
  385.  
  386. }
  387.  
  388. /*
  389.  * Function: IColorSelector::mouseMoved
  390.  *
  391.  * Parameteres:
  392.  *   event: contains the mouse position
  393.  *
  394.  * Return value: returns true when the event is processed
  395.  *
  396.  * Purpose: handles dragging of the selection indicator
  397.  *
  398. */
  399.  
  400. bool IColorSelector::mouseMoved(IMouseEvent &event)
  401. {
  402.   bool result = false;     // the return result
  403.  
  404.   if(capturing) {  // if the mouse is down...
  405.  
  406.     CharIntensity val;
  407.  
  408.     // create rendering devices
  409.     IBaseRootGrafPort myDisplayPort(this->presSpace());
  410.  
  411.     // get the mouse position in world space
  412.     IPoint point(event.mousePosition());
  413.     IGPoint2D talPoint;
  414.     talPoint = myDisplayPort.pixelToPointSize().transformPoint(IGPoint2D(point));
  415.  
  416.     // get the value with respect to the mouse position
  417.     if(horizontal)
  418.       val = (CharIntensity)(talPoint.fX * (255/COLORSELECTOR_COLORS));
  419.  
  420.     else
  421.       val = (CharIntensity)(talPoint.fY * (255/COLORSELECTOR_COLORS));
  422.  
  423.     // do some range checking/adjustment
  424.     if(val > 255) val = 255;
  425.  
  426.     else if(val < 0) val = 0;
  427.  
  428.     // set the value and do paint updates where necessary
  429.     SetValue(val);
  430.     ((IPalletDialog*)win)->SetValue(value,type);
  431.  
  432.     result = true;
  433.  
  434.   }
  435.  
  436.   return result;
  437.  
  438. }
  439.  
  440. //*************************************************************************
  441. // Class IColorSquare: method definitions                                 *
  442. //*************************************************************************
  443.  
  444. /*
  445.  * Function: IColorSquare::IColorSquare
  446.  *
  447.  * Parameters:
  448.  *   id    : the windows id
  449.  *   parent: pointer to the parent window
  450.  *   owner : pointer to the owner window
  451.  *
  452.  * Return value: NONE
  453.  *
  454.  * Purpose: constructor for IColorSquare
  455.  *
  456. */
  457.  
  458. IColorSquare::IColorSquare(const unsigned long id, IWindow* parent, IWindow* owner)
  459.   : ICanvas(id,parent,owner),
  460.   win(parent->parent())
  461. {
  462.   // start up the event handlers
  463.   IPaintHandler::handleEventsFor(this);
  464.  
  465.   managedPresSpacePtr = new IManagedPresSpaceHandle(this);
  466.   sizeTo(ISize(IGPoint2D(COLORSQUARE_WIDTH,COLORSQUARE_WIDTH).fX,
  467.                IGPoint2D(COLORSQUARE_WIDTH,COLORSQUARE_WIDTH).fY));
  468.  
  469.   moveTo(IPoint(IGPoint2D(PALLETCANVAS_SIZE+2*PALLETDIALOG_SPACER,PALLETDIALOG_SPACER)));
  470. }
  471.  
  472. /*
  473.  * Function: IColorSquare::~IColorSquare
  474.  *
  475.  * Parameters: NONE
  476.  *
  477.  * Return value: NONE
  478.  *
  479.  * Purpose: destructor for IColorSquare
  480.  *
  481. */
  482.  
  483. IColorSquare::~IColorSquare()
  484. {
  485.   // shut down the event handlers
  486.   IPaintHandler::stopHandlingEventsFor(this);
  487.  
  488.   delete managedPresSpacePtr;
  489. }
  490.  
  491. /*
  492.  * Function: IColorSquare::paintWindow
  493.  *
  494.  * Parameters:
  495.  *   event: the type of paint event to be handled - ignored in this method
  496.  *
  497.  * Return value: returns true if painting is done - always true in this case
  498.  *
  499.  * Purpose: renders the control to the screen when update is required
  500.  *
  501. */
  502.  
  503. bool IColorSquare::paintWindow(IPaintEvent& event)
  504. {
  505.   // create the rendering devices
  506.   IBaseRootGrafPort myDisplayPort(this->presSpace());
  507.  
  508.   IGPoint2D talPoint;
  509.   talPoint = myDisplayPort.pixelToPointSize().transformPoint(IGPoint2D(COLORSQUARE_WIDTH-1,COLORSQUARE_WIDTH-1));
  510.   IGRect2D theRect(IGPoint2D(0,0),talPoint);
  511.  
  512.   myDisplayPort.draw(theRect,IFillAndFrameBundle(((IPalletDialog*)win)->color(),
  513.                 IBaseColor(IBaseColor::kBlack)));
  514.  
  515.   return true;
  516.  
  517. }
  518.  
  519.  
  520. /*
  521.  * Function: IPalletCanvas::IPalletCanvas
  522.  *
  523.  * Parameters:
  524.  *   id    : the window's id
  525.  *   parent: a pointer to the parent window
  526.  *   owner : a pointer to the owner window
  527.  *
  528.  * Return value: NONE
  529.  *
  530.  * Purpose: constructor for IPalletCanvas
  531.  *
  532. */
  533.  
  534. IPalletCanvas::IPalletCanvas(const unsigned long id, IWindow* parent, IWindow* owner, int& pX, int& pY)
  535.   : ICanvas(id,parent,owner,
  536.     IGRect2D((IGPoint2D(0,0)),
  537.               IGPoint2D(PALLETCANVAS_SIZE,PALLETCANVAS_SIZE))),
  538.     win(parent->parent())
  539. {
  540.   // start up the event handlers
  541.   IMouseHandler::handleEventsFor(this);
  542.   IPaintHandler::handleEventsFor(this);
  543.  
  544.   // do some initial range checking/adjustments
  545.   if(pX > (PALLETCANVAS_SQUARE-1)) pX = (PALLETCANVAS_SQUARE-1);
  546.   if(pX < 0) pX = 0;
  547.   if(pY > (PALLETCANVAS_SQUARE-1)) pY = (PALLETCANVAS_SQUARE-1);
  548.   if(pY < 0) pY = 0;
  549.  
  550.   // hold on to the referenced indexes
  551.   posX = &pX;
  552.   posY = &pY;
  553.  
  554.   // initialize
  555.   InitTables();
  556.   paintAllFlag = 1;
  557.  
  558.   managedPresSpacePtr = new IManagedPresSpaceHandle(this);
  559. }
  560.  
  561. /*
  562.  * Function: IPalletCanvas::~IPalletCanvas
  563.  *
  564.  * Parameters: NONE
  565.  *
  566.  * Return valu: NONE
  567.  *
  568.  * Purpose: destructor for IPalletCanvas
  569.  *
  570. */
  571.  
  572. IPalletCanvas::~IPalletCanvas()
  573. {
  574.   IMouseHandler::stopHandlingEventsFor(this);
  575.   IPaintHandler::stopHandlingEventsFor(this);
  576.  
  577.   for(int i = 0;i < PALLETCANVAS_SQUARE;i++) {
  578.  
  579.     for(int j = 0;j< PALLETCANVAS_SQUARE; j++) {
  580.  
  581.       delete squareTable[i][j];
  582.  
  583.     }
  584.  
  585.   }
  586.  
  587.   delete managedPresSpacePtr;
  588.  
  589. }
  590.  
  591. /*
  592.  * Function: IPalletCanvas::color
  593.  *
  594.  * Parameters: NONE
  595.  *
  596.  * Return value: the currently selected color from a global color table
  597.  *
  598.  * Purpose: returns the currently selected color from the color table
  599.  *
  600. */
  601.  
  602. IBaseColor IPalletCanvas::color()
  603. {
  604.   return *colorTable[*posX][*posY];
  605.  
  606. }
  607.  
  608. /*
  609.  * Function: IPalletCanvas::setColor
  610.  *
  611.  * Parameters: NONE
  612.  *
  613.  * Return value: NONE
  614.  *
  615.  * Purpose: called to update the pallet as the slider indicators are moved
  616.  *
  617. */
  618.  
  619. void IPalletCanvas::SetColor()
  620. {
  621.   // create the rendering devices
  622.    IBaseRootGrafPort myDisplayPort(this->presSpace());
  623.  
  624.   // create the attribute bundle with the appropriate color
  625.   IFillAndFrameBundle bundle(*colorTable[*posX][*posY],IBaseColor(IBaseColor::kBlack));
  626.  
  627.   // render the affected portion of the pallet to the screen
  628.   myDisplayPort.draw(*squareTable[*posX][*posY],bundle);
  629. }
  630.  
  631. /*
  632.  * Function: IPalletCanvas::paintWindow
  633.  *
  634.  * Parameters:
  635.  *   event: gives detail on the type of paint event that occured
  636.  *
  637.  * Return value: returns true when painting is handled - always true here
  638.  *
  639.  * Purpose: repaints the pallet when the need arises
  640.  *
  641. */
  642.  
  643. bool IPalletCanvas::paintWindow(IPaintEvent& event)
  644. {
  645.   if(paintAllFlag) {  // if painting required...
  646.  
  647.     // create the rendering devices
  648.     IBaseRootGrafPort myDisplayPort(this->presSpace());
  649.  
  650.     // draw the table
  651.    for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  652.  
  653.       for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  654.  
  655.         IFillAndFrameBundle bundle(*colorTable[i][j],IBaseColor(IBaseColor::kBlack));
  656.         myDisplayPort.draw(*squareTable[i][j],bundle);
  657.  
  658.       }
  659.  
  660.     }
  661.  
  662.   }
  663.  
  664.   paintAllFlag = 1;
  665.   return true;
  666.  
  667. }
  668.  
  669. /*
  670.  * Function: IPalletCanvas::mouseClicked
  671.  *
  672.  * Parameters:
  673.  *   event: gives detail on what type of mouse click occurred
  674.  *
  675.  * Return value: returns true when the event is processed
  676.  *
  677.  * Purpose: used to change the currently selected color from the table
  678.  *
  679. */
  680.  
  681. bool IPalletCanvas::mouseClicked(IMouseClickEvent& event)
  682. {
  683.   bool result = false;     // the return result
  684.  
  685.   if ( event.mouseButton() == IMouseClickEvent::button1 &&
  686.        event.mouseAction() == IMouseClickEvent::down ) {
  687.  
  688.     // create the rendering devices
  689.     IBaseRootGrafPort myDisplayPort(this->presSpace());
  690.  
  691.     // get the mouse position in world space
  692.     IGPoint2D talPoint;
  693.     IPoint point(event.mousePosition());
  694.     talPoint = IGPoint2D(point);
  695.  
  696.     // calculate the table entry clicked on
  697.     *posX = ((int)(talPoint.fX))/PALLETCANVAS_SQUAREWIDTH;
  698.     *posY = ((int)(talPoint.fY))/PALLETCANVAS_SQUAREWIDTH;
  699.  
  700.     // do some range checking/adjustments
  701.     if(*posX > (PALLETCANVAS_SQUARE-1)) *posX = (PALLETCANVAS_SQUARE-1);
  702.     if(*posY > (PALLETCANVAS_SQUARE-1)) *posY = (PALLETCANVAS_SQUARE-1);
  703.  
  704.     // update the values for the dialog and do necessary painting; rgb and equivalent greyscale
  705.     ((IPalletDialog*)win)->SetValues(colorTable[*posX][*posY]->redMix(),colorTable[*posX][*posY]->greenMix(),colorTable[*posX][*posY]->blueMix(),
  706.                                      0.3*(colorTable[*posX][*posY]->redMix())+0.59*(colorTable[*posX][*posY]->greenMix())+0.11*(colorTable[*posX][*posY]->blueMix()));
  707.     ((IPalletDialog*)win)->SetColor(*colorTable[*posX][*posY]);
  708.  
  709.     result = true;
  710.  
  711.     paintAllFlag = 0;
  712.  
  713.   }
  714.  
  715.   return result;
  716.  
  717. }
  718.  
  719. /*
  720.  * Function: IPalletCanvas::InitTables
  721.  *
  722.  * Parameters: NONE
  723.  *
  724.  * Return value: NONE
  725.  *
  726.  * Purpose: initailizes the square table consisting of 64 rectangles
  727.  *
  728. */
  729.  
  730. void IPalletCanvas::InitTables()
  731. {
  732.   IBaseRootGrafPort myDisplayPort(this->presSpace());
  733.   for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  734.  
  735.     for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  736.  
  737.       IGPoint2D p1 = myDisplayPort.pixelToPointSize().transformPoint(IGPoint2D( 0+i*PALLETCANVAS_SQUAREWIDTH, 0+j*PALLETCANVAS_SQUAREWIDTH));
  738.       IGPoint2D p2 = myDisplayPort.pixelToPointSize().transformPoint(IGPoint2D(PALLETCANVAS_SQUAREWIDTH+i*PALLETCANVAS_SQUAREWIDTH,
  739.                                PALLETCANVAS_SQUAREWIDTH+j*PALLETCANVAS_SQUAREWIDTH));
  740.       squareTable[i][j] = new IGRect2D(p1,p2);
  741.  
  742.     }
  743.  
  744.   }
  745.  
  746. }
  747.  
  748. //*************************************************************************
  749. // Class IControlCanvas: method definitions                               *
  750. //*************************************************************************
  751.  
  752. /*
  753.  * Function: IControlCanvas::command
  754.  *
  755.  * Parameters:
  756.  *   event: contains the id of the command event
  757.  *
  758.  * Return value: returns true if the command event if handled
  759.  *
  760.  * Purpose: used for dismissal of the dialog
  761.  *
  762. */
  763.  
  764. bool IControlCanvas::command(ICommandEvent& event)
  765. {
  766.   bool result = false;
  767.  
  768.   switch(event.commandId()) {
  769.  
  770.     case ID_RESET:
  771.     case ID_OK: {  // Ok button pressed
  772.  
  773.        ((IFrameWindow*)parent())->dismiss( event.commandId() );
  774.       result = true;
  775.       break;
  776.     }
  777.  
  778.    default:
  779.     case ID_CANCEL: {  // Cancel button pressed
  780.  
  781.       ((IFrameWindow*)parent())->dismiss(0);
  782.       result = true;
  783.       break;
  784.     }
  785.  
  786.   }
  787.  
  788.   return result;
  789.  
  790. }
  791.  
  792. //*************************************************************************
  793. // Class IPalletDialog: method definitions                                *
  794. //*************************************************************************
  795.  
  796. /*
  797.  * Function: IPalletDialog::IPalletDialog
  798.  *
  799.  * Parameters:
  800.  *   title: the windows title
  801.  *   pX   : the horizontal index of the initial color to be selected
  802.  *   pY   : the vertical index of the initial color to be selected
  803.  *
  804.  * Return value: NONE
  805.  *
  806.  * Purpose: constructor for IPalletCanvas
  807.  *
  808. */
  809.  
  810. IPalletDialog::IPalletDialog(const char* title, int& pX, int &pY, IWindow * ownerWnd)
  811.   : IFrameWindow(IResourceId(WND_PALLET),
  812.                   IWindow::desktopWindow(),
  813.                   ownerWnd,
  814.       IRectangle(),
  815.       IFrameWindow::classDefaultStyle &
  816.       ~IFrameWindow::minimizeButton &
  817.       ~IFrameWindow::maximizeButton &
  818.       ~IFrameWindow::sizingBorder |
  819.       IFrameWindow::titleBar |
  820.       IFrameWindow::shellPosition  |
  821.       IFrameWindow::dialogBackground |
  822.       IFrameWindow::dialogBorder),
  823.     controlCanvas(ID_CONTROL,this,this),
  824.     palletCanvas(ID_PALLET,&controlCanvas,&controlCanvas,pX,pY),
  825.     colorSquare(ID_COLORSQUARE,&controlCanvas,&controlCanvas),
  826.     OkBut(ID_OK,&controlCanvas,&controlCanvas),
  827.     CancelBut(ID_CANCEL,&controlCanvas,&controlCanvas),
  828.     ResetBut(ID_RESET,&controlCanvas,&controlCanvas),
  829.     rSelector(ID_RSELECTOR,&controlCanvas,this,IColorSelector::Red_type,true),
  830.     gSelector(ID_GSELECTOR,&controlCanvas,this,IColorSelector::Green_type,true),
  831.     bSelector(ID_BSELECTOR,&controlCanvas,this,IColorSelector::Blue_type,true),
  832.     grSelector(ID_GRSELECTOR,&controlCanvas,this,IColorSelector::Gray_type,false),
  833.     grayColor(false),
  834.     dialogTitle(this)
  835. {
  836.   setClient(&controlCanvas);
  837.  
  838.   OkBut.setText( STR_OK );
  839.   CancelBut.setText( STR_CANCEL );
  840.   ResetBut.setText( STR_RESET );
  841.  
  842.   dialogTitle.setText(title);
  843.  
  844.   controlCanvas.setLayoutDistorted(IWindow::immediateUpdate,0);
  845.  
  846.   // size the controls (in world space)
  847.   controlCanvas.sizeTo(ISize(IPoint(IGPoint2D(300,270+60))));
  848.   sizeTo(ISize(IPoint(IGPoint2D(300,270+60))));
  849.   OkBut.sizeTo(ISize(IPoint(IGPoint2D(45,40))));
  850.   CancelBut.sizeTo(ISize(IPoint(IGPoint2D(75,40))));
  851.   ResetBut.sizeTo(ISize(IPoint(IGPoint2D(75,40))));
  852.  
  853.   // position the controls (in world space)
  854.   OkBut.moveTo(IPoint(IGPoint2D(32,200)));
  855.   CancelBut.moveTo(IPoint(IGPoint2D(82,200)));
  856.   ResetBut.moveTo(IPoint(IGPoint2D(57,200+50)));
  857.   palletCanvas.moveTo(IPoint(IGPoint2D(PALLETDIALOG_SPACER,PALLETDIALOG_SPACER)));
  858.   rSelector.moveTo(IPoint(IGPoint2D(PALLETCANVAS_SIZE+2*PALLETDIALOG_SPACER,
  859.                                     COLORSQUARE_WIDTH+2*PALLETDIALOG_SPACER)));
  860.   gSelector.moveTo(IPoint(IGPoint2D(PALLETCANVAS_SIZE+2*PALLETDIALOG_SPACER,
  861.                                     COLORSQUARE_WIDTH+3*PALLETDIALOG_SPACER+COLORSELECTOR_HEIGHT)));
  862.   bSelector.moveTo(IPoint(IGPoint2D(PALLETCANVAS_SIZE+2*PALLETDIALOG_SPACER,
  863.                                     COLORSQUARE_WIDTH+4*PALLETDIALOG_SPACER+2*COLORSELECTOR_HEIGHT)));
  864.   grSelector.moveTo(IPoint(IGPoint2D(PALLETCANVAS_SIZE+3*PALLETDIALOG_SPACER+COLORSELECTOR_WIDTH,
  865.                                      COLORSQUARE_WIDTH+2*PALLETDIALOG_SPACER)));
  866.  
  867.   // set the initial values
  868.   fColor = IBaseColor(*colorTable[pX][pY]);
  869.   SetValues(colorTable[pX][pY]->redMix(),
  870.             colorTable[pX][pY]->greenMix(),
  871.             colorTable[pX][pY]->blueMix(),0);
  872.  
  873.   // draw!
  874.   refresh();
  875.   setFocus();
  876.  
  877. }
  878.  
  879. /*
  880.  * Function: IPalletDialog::~IPalletDialog
  881.  *
  882.  * Parameters: NONE
  883.  *
  884.  * Return value: NONE
  885.  *
  886.  * Purpose: destructor for IPalletDialog
  887.  *
  888. */
  889.  
  890. IPalletDialog::~IPalletDialog()
  891. {
  892.  
  893. }
  894.  
  895. /*
  896.  * Function: IPalletDialog::color
  897.  *
  898.  * Parameters: NONE
  899.  *
  900.  * Return value: the paint constructed from the currently selected color
  901.  *
  902.  * Purpose: returns the paint constructed from the currently selected color
  903.  *
  904. */
  905.  
  906. IBaseColor IPalletDialog::color()
  907. {
  908.  
  909.   return fColor;
  910.  
  911. }
  912.  
  913. /*
  914.  * Function: IPalletDialog::SetValues
  915.  *
  916.  * Parameters:
  917.  *   rV : the red value to be set
  918.  *   gV : the green value to be set
  919.  *   bV : the blue value to be set
  920.  *   grV: the gray value to be set
  921.  *
  922.  * Return value: NONE
  923.  *
  924.  * Purpose: updates the dialog to reflect the indicated values
  925.  *
  926. */
  927.  
  928. void IPalletDialog::SetValues(CharIntensity rV, CharIntensity gV, CharIntensity bV, CharIntensity grV)
  929. {
  930.   char value[5];
  931.  
  932.   // set the selector values
  933.   rSelector.SetValue(rV);
  934.   gSelector.SetValue(gV);
  935.   bSelector.SetValue(bV);
  936.   grSelector.SetValue(grV);
  937.  
  938.   // set the values for the dialog
  939.   rVal = rV;
  940.   gVal = gV;
  941.   bVal = bV;
  942.   grVal = grV;
  943.  
  944.   // construct the paint from the appropriate color type
  945.   if(grayColor) fColor = IBaseColor(grVal);
  946.  
  947.   else fColor = IBaseColor(rVal,gVal,bVal);
  948.  
  949.   // do the necessary painting, and do it now!
  950.   colorSquare.refresh(IWindow::paintAllImmediate);
  951.  
  952. }
  953.  
  954. /*
  955.  * Function: IPalletDialog::SetValue
  956.  *
  957.  * Parameters:
  958.  *   val: the value to be set
  959.  *   t  : the type of value being set (Red_type, Green_type, Blue_type, Gray_type)
  960.  *
  961.  * Return value: NONE
  962.  *
  963.  * Purpose: set the value of the specifed type ( t )
  964.  *
  965. */
  966.  
  967. void IPalletDialog::SetValue(CharIntensity val, IColorSelector::ColorType t)
  968. {
  969.   int pX, pY;
  970.   char value[5];
  971.  
  972.   // set the value with respect to the type
  973.   switch(t) {
  974.  
  975.     case IColorSelector::Red_type: {
  976.  
  977.       rVal = val;
  978.       break;
  979.  
  980.     }
  981.  
  982.     case IColorSelector::Green_type: {
  983.  
  984.       gVal = val;
  985.       break;
  986.  
  987.     }
  988.  
  989.     case IColorSelector::Blue_type: {
  990.  
  991.       bVal = val;
  992.       break;
  993.  
  994.     }
  995.  
  996.     case IColorSelector::Gray_type: {
  997.  
  998.       grVal = val;
  999.       if(!grayColor) {
  1000.  
  1001.         grayColor = true;
  1002.  
  1003.       }
  1004.  
  1005.       SetValues(grVal,grVal,grVal,grVal);
  1006.  
  1007.       // set the paint
  1008.       fColor = IBaseColor(grVal);
  1009.       colorSquare.refresh(IWindow::paintAllImmediate);
  1010.  
  1011.       return;
  1012.  
  1013.     }
  1014.  
  1015.   }
  1016.  
  1017.   if(grayColor) {  // if the gray color has changed...
  1018.  
  1019.     grayColor = false;
  1020.     SetValues(rVal,gVal,bVal,0);     // update all indicators
  1021.  
  1022.   }
  1023.  
  1024.   // set the paint
  1025.   fColor = IBaseColor(rVal,gVal,bVal);
  1026.  
  1027.   // update the indices
  1028.   pX = palletCanvas.GetPosX();
  1029.   pY = palletCanvas.GetPosY();
  1030.  
  1031.   // reflect the change int the color table
  1032.   delete colorTable[pX][pY];
  1033.   colorTable[pX][pY] = new IBaseColor(rVal,gVal,bVal);
  1034.  
  1035.   // reflect the change in the palletCanvas
  1036.   palletCanvas.SetColor();
  1037.  
  1038.   // reflect the change in the colorSquare
  1039.   colorSquare.refresh(IWindow::paintAllImmediate);
  1040.  
  1041. }
  1042.  
  1043. /*
  1044.  * Function: IPalletDialog::setColor
  1045.  *
  1046.  * Parameters:
  1047.  *   color: the new color (in paint form) to be set
  1048.  *
  1049.  * Return value: NONE
  1050.  *
  1051.  * Purpose: to set the currently selected color (in paint form)
  1052.  *
  1053. */
  1054.  
  1055. void IPalletDialog::SetColor(IBaseColor color)
  1056. {
  1057.   fColor = color;
  1058.  
  1059. };
  1060.  
  1061. class InitThisModule
  1062. {
  1063.    public:
  1064.       InitThisModule()
  1065.       {
  1066.          InitPallet();
  1067.       };
  1068.       ~InitThisModule()
  1069.       {
  1070.          ClearPallet();
  1071.       };
  1072.       void InitPallet();
  1073.       void ClearPallet();
  1074.    private:
  1075.       // disable, declare but no definition
  1076.       InitThisModule( const InitThisModule& );
  1077.       InitThisModule & operator= ( const InitThisModule& );
  1078. };
  1079. static InitThisModule INIT;
  1080. /*
  1081.  * Function: InitThisModule::InitPallet
  1082.  *
  1083.  * Parameters: NONE
  1084.  *
  1085.  * Return value: NONE
  1086.  *
  1087.  * Purpose: initializes the global color pallet
  1088.  *
  1089. */
  1090.  
  1091. void InitThisModule::InitPallet()
  1092. {
  1093.   // set up the table - no pattern here!
  1094.   IBaseColor table[8][8] = {
  1095.     {IBaseColor(170,255,0), IBaseColor(128,128,0),
  1096.     IBaseColor(170,85,0),IBaseColor(128,0,0),IBaseColor(0,255,0),
  1097.     IBaseColor(0,146,0),IBaseColor(0,85,0),IBaseColor(0,0,0)},
  1098.  
  1099.     {IBaseColor(170,1,85),IBaseColor(170,170,85),
  1100.     IBaseColor(170,85,85),IBaseColor(170,0,85),
  1101.     IBaseColor(0,255,85),IBaseColor(0,170,85),IBaseColor(0,85,85),
  1102.     IBaseColor(0,0,85)},
  1103.  
  1104.     {IBaseColor(170,1,170),
  1105.     IBaseColor(204,204,204),IBaseColor(170,85,170),
  1106.     IBaseColor(128,128,128),IBaseColor(0,255,170),
  1107.     IBaseColor(0,146,170),IBaseColor(0,85,170),
  1108.     IBaseColor(0,0,170)},
  1109.  
  1110.     {IBaseColor(170,255,255),
  1111.     IBaseColor(170,170,255),IBaseColor(170,85,255),
  1112.     IBaseColor(170,0,255),IBaseColor(0,255,255),
  1113.     IBaseColor(0,170,255),IBaseColor(0,85,255),
  1114.     IBaseColor(0,0,255)},
  1115.  
  1116.     {IBaseColor(255,255,0),
  1117.     IBaseColor(255,170,0),IBaseColor(255,85,0),
  1118.     IBaseColor(255,0,0),IBaseColor(85,255,0),
  1119.     IBaseColor(85,170,0),IBaseColor(85,85,0),
  1120.     IBaseColor(85,0,0)},
  1121.  
  1122.     {IBaseColor(255,255,85),
  1123.     IBaseColor(255,170,85),IBaseColor(255,85,85),
  1124.     IBaseColor(255,0,85),IBaseColor(85,255,85),
  1125.     IBaseColor(85,170,85),IBaseColor(131,131,131),
  1126.     IBaseColor(85,0,85)},
  1127.  
  1128.     {IBaseColor(255,255,170),
  1129.     IBaseColor(255,170,170),IBaseColor(255,85,170),
  1130.     IBaseColor(255,0,170),IBaseColor(85,255,170),
  1131.     IBaseColor(85,170,170),IBaseColor(85,85,170),
  1132.     IBaseColor(85,0,170)},
  1133.  
  1134.     {IBaseColor(255,255,255),
  1135.     IBaseColor(255,170,255),IBaseColor(255,85,255),
  1136.     IBaseColor(255,0,255),IBaseColor(85,255,255),
  1137.     IBaseColor(85,170,255),IBaseColor(85,85,255),
  1138.     IBaseColor(85,0,255)}
  1139.   };
  1140.  
  1141.   // initialize the global table
  1142.   for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  1143.  
  1144.     for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  1145.  
  1146.       colorTable[i][j] = new IBaseColor(table[i][j]);
  1147.  
  1148.     }
  1149.  
  1150.   }
  1151.  
  1152. }
  1153.  
  1154. /*
  1155.  * Function: InitThisModule::ClearPallet
  1156.  *
  1157.  * Parameters: NONE
  1158.  *
  1159.  * Return value: NONE
  1160.  *
  1161.  * Purpose: clears the global color pallet
  1162.  *
  1163. */
  1164.  
  1165. void InitThisModule::ClearPallet()
  1166. {
  1167.   for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  1168.  
  1169.     for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  1170.  
  1171.       delete colorTable[i][j];
  1172.  
  1173.     }
  1174.  
  1175.   }
  1176.  
  1177. }
  1178.  
  1179. #if 0
  1180. //*************************************************************************
  1181. // Class ITextDialog: method definitions                                  *
  1182. //*************************************************************************
  1183.  
  1184. /*
  1185.  * Function: ITextDialog::ITextDialog
  1186.  *
  1187.  * Parameters:
  1188.  *   title: the window's title
  1189.  *
  1190.  * Return value: none
  1191.  *
  1192.  * Purpose: constructor for ITextDialog
  1193.  *
  1194. */
  1195.  
  1196. ITextDialog::ITextDialog(const char* title, IWindow * ownerWnd)
  1197.   : IFrameWindow(IResourceId(WND_TEXT),
  1198.                   IWindow::desktopWindow(),
  1199.                   ownerWnd,
  1200.       IRectangle(),
  1201.       IFrameWindow::classDefaultStyle &
  1202.       ~IFrameWindow::minimizeButton &
  1203.       ~IFrameWindow::maximizeButton &
  1204.       ~IFrameWindow::sizingBorder |
  1205.       IFrameWindow::titleBar |
  1206.       IFrameWindow::dialogBackground |
  1207.       IFrameWindow::dialogBorder),
  1208.     controlCanvas(0x8008,this,this),
  1209.     entryField(0x8009,&controlCanvas,&controlCanvas),
  1210.     OkBut(ID_OK,&controlCanvas,&controlCanvas),
  1211.     dialogTitle(this)
  1212. {
  1213.   // start the event handler
  1214.   handleEventsFor(this);
  1215.  
  1216.   setClient(&controlCanvas);
  1217.  
  1218.   // initialize the text controls
  1219.   OkBut.setText("Ok");
  1220.   dialogTitle.setText(title);
  1221.  
  1222.   sizeTo(ISize(360,120));
  1223.  
  1224.   // position the entry field
  1225.   controlCanvas.addToCell(&entryField,2,2,6,2);
  1226.  
  1227.   // position/size/set the Ok button
  1228.   OkBut.sizeTo(ISize(45,40));
  1229.   OkBut.moveTo(IPoint(155,50));
  1230.   OkBut.enableDefault();
  1231.  
  1232.   entryField.setFocus();
  1233.  
  1234. }
  1235.  
  1236. /*
  1237.  * Function: ITextDialog::command
  1238.  *
  1239.  * Parameters:
  1240.  *   event: contains the command event id
  1241.  *
  1242.  * Return value: returns true
  1243.  *
  1244.  * Purpose: used to dismiss the dialog
  1245.  *
  1246. */
  1247.  
  1248. bool ITextDialog::command(ICommandEvent& event)
  1249. {
  1250.    bool result = false;
  1251.  
  1252.    switch(event.commandId()) {
  1253.  
  1254.      case ID_OK: {  // Ok button pressed
  1255.  
  1256.     dismiss(ID_OK);
  1257.        result = true;
  1258.        break;
  1259.      }
  1260.      default: {
  1261.  
  1262.        dismiss(0);
  1263.        result = true;
  1264.        break;
  1265.   }
  1266.  
  1267.    }
  1268.  
  1269.    return result;
  1270.  
  1271. }
  1272.  
  1273. //*************************************************************************
  1274. // Class DrawingArea: method definitions                                  *
  1275. //*************************************************************************
  1276.  
  1277. /*
  1278.  * Function: DrawingArea::DrawingArea
  1279.  *
  1280.  * Parameters:
  1281.  *   windowId: the window's id
  1282.  *   parent  : a pointer to the window's parent
  1283.  *   owner   : a pointer to the window's owner
  1284.  *   initial : the window's intial sizing rectangle
  1285.  *
  1286.  * Return value: NONE
  1287.  *
  1288.  * Purpose: constructor for DrawingArea
  1289.  *
  1290. */
  1291.  
  1292. DrawingArea::DrawingArea( unsigned long windowId, IWindow* parent,
  1293.                           IWindow* owner, const IRectangle& initial )
  1294.   : dState( notDrawing ),
  1295.     currentObj( attribStyle ),
  1296.     clipping(false),
  1297.     drawingBundle(IBaseColor(IBaseColor::kBlack), IAttributeState::kFrame),
  1298.     currentBundle(IBaseColor(IBaseColor::kGreen),IBaseColor(IBaseColor::kBlue), IAttributeState::kFillAndFrame)
  1299.     , myDisplayPort(0)
  1300.     , paintedLastResize(false)
  1301. {
  1302.  
  1303.   ICanvas::initialize( windowId, parent, owner, initial,
  1304.         ICanvas::convertToGUIStyle(ICanvas::defaultStyle()), 0);
  1305.   // start up the event handlers
  1306.   IMouseHandler::handleEventsFor(this);
  1307.   IPaintHandler::handleEventsFor(this);
  1308.   IResizeHandler::handleEventsFor(this);
  1309.  
  1310. #ifndef IC_MOTIF
  1311.   // Load the mouse pointers
  1312.   IResourceLibrary reslib;
  1313.  
  1314.   for(unsigned long i = 0; i < kNumberOfPointers; i++) {
  1315.  
  1316.     ptrArray[i] = reslib.loadPointer( i+POINTER_OFFSET );
  1317.  
  1318.   }
  1319. #endif
  1320.  
  1321.   moveGraphic = NULL;
  1322.   parentPort = NULL;
  1323.   clickCount = 0;
  1324.  
  1325.   fGraphicGroup = new IGraphicGroup();
  1326.  
  1327.   clickCount = 0;
  1328.  
  1329. }
  1330.  
  1331. /*
  1332.  * Function: DrawingArea::~DrawingArea
  1333.  *
  1334.  * Parameters: NONE
  1335.  *
  1336.  * Return value: NONE
  1337.  *
  1338.  * Purpose: destructor for DrawingArea
  1339.  *
  1340. */
  1341.  
  1342. DrawingArea::~DrawingArea( )
  1343. {
  1344.  
  1345.   // shut down the event handlers
  1346.   IMouseHandler::stopHandlingEventsFor(this);
  1347.   IPaintHandler::stopHandlingEventsFor(this);
  1348.  
  1349.   // clean up the pointers
  1350.   if(fGraphicGroup) delete fGraphicGroup;
  1351.   if(currentGraphic) delete currentGraphic;
  1352.   if(myDisplayPort) delete myDisplayPort;
  1353.  
  1354. }
  1355.  
  1356. /*
  1357.  * Function: DrawingArea::SetInfoText
  1358.  *
  1359.  * Parameters:
  1360.  *   text: the text to be displayed in the information area
  1361.  *
  1362.  * Return value: NONE
  1363.  *
  1364.  * Purpose: calls MainWindow to set the text in the information area
  1365.  *
  1366. */
  1367.  
  1368. void DrawingArea::SetInfoText(IString text)
  1369. {
  1370.   ((MainWindow*)parent())->SetInfoText(text);
  1371.  
  1372. }
  1373.  
  1374. /*
  1375.  * Function: DrawingArea::SetInfoText
  1376.  *
  1377.  * Parameters:
  1378.  *   id: the resource id of the text to be displayed in the information area
  1379.  *
  1380.  * Return value: NONE
  1381.  *
  1382.  * Purpose: calls MainWindow to set the text in the information area
  1383.  *
  1384. */
  1385.  
  1386. void DrawingArea::SetInfoText(unsigned long id)
  1387. {
  1388.   ((MainWindow*)parent())->SetInfoText(id);
  1389.  
  1390. }
  1391.  
  1392. //*************************************************************************
  1393. // Class MainWindow: method definitions                                   *
  1394. //*************************************************************************
  1395.  
  1396. /*
  1397.  * Function: MainWindow::MainWindow
  1398.  *
  1399.  * Parameters:
  1400.  *   windowId: the window's id
  1401.  *
  1402.  * Return value: NONE
  1403.  *
  1404.  * Purpose: constructor for MainWindow
  1405.  *
  1406. */
  1407.  
  1408. MainWindow::MainWindow(unsigned long windowId)
  1409.   : IFrameWindow (                      //Call IFrameWindow constructor
  1410.     IFrameWindow::defaultStyle()        //  Use default plus
  1411.     | IFrameWindow::animated,           //  Set to show with "animation"
  1412.     windowId),                          //  Main Window ID
  1413.     drawingArea( WND_DRAW, this, this ),
  1414.     toolBar1( WND_TOOLBAR1,this, IToolBar::aboveClient),
  1415.     menuBar( WND_MAIN, this),
  1416.     infoText( WND_TEXT, this, this, IRectangle(), IStaticText::defaultStyle()
  1417.                                                 | IStaticText::top
  1418.                                                 | IStaticText::left
  1419.                                                 | IStaticText::wordBreak ),
  1420.     lastDrawOperationId(ID_FILLANDFRAME),
  1421.     lastPenWidthId(ID_PENWIDTH_1),
  1422.     lastPenTypeId(ID_PENTYPE_SOLID)
  1423. {
  1424.    ICoordinateSystem::setApplicationOrientation(ICoordinateSystem::originUpperLeft);
  1425.  
  1426.   // start up the event handlers
  1427.   ICommandHandler::handleEventsFor(this);
  1428.   IResizeHandler::handleEventsFor(this);
  1429.  
  1430.   setClient(&drawingArea);
  1431.  
  1432.  
  1433.   // Flow Toolbar
  1434.   toolBar1.alignDecksByGroup();
  1435.  
  1436.   // initialize the tool bar button array
  1437.   for(unsigned long i = 0; i < kNumberOfButtons; i++) {
  1438.  
  1439.         try {
  1440.     buttonArray[i] = new IToolBarButton(i+BUTTON_OFFSET, &toolBar1, &toolBar1);
  1441.     buttonArray[i]->setStandardBitmapSize(ISize(22,19)); // used as an offset here
  1442.     buttonArray[i]->setBitmap( i+BUTTON_OFFSET );
  1443.     toolBar1.addAsLast(buttonArray[i]);
  1444.         }
  1445.         catch (IException& e)
  1446.         {
  1447.                 cout << "Caught Exception: " << e.name() << ": " << e.text() << endl;
  1448.                 buttonArray[i] = new IToolBarButton(i+BUTTON_OFFSET, &toolBar1, &toolBar1);
  1449.                 buttonArray[i]->setStandardBitmapSize(ISize(22,19));
  1450.                 buttonArray[i]->setBitmap(i+BUTTON_OFFSET);
  1451.                 toolBar1.addAsLast(buttonArray[i]);
  1452.         }
  1453.  
  1454.   }
  1455.  
  1456.   groupButtIndex = kNumberOfButtons;
  1457.   buttonArray[0]->latch();
  1458.   lastButton = buttonArray[0];
  1459.  
  1460.   // setup the information area
  1461.   addExtension( &infoText,
  1462.     IFrameWindow::belowClient,
  1463.     (unsigned long)(2 * 24),
  1464.     IFrameWindow::thickLine );
  1465.  
  1466.   // check the default menu selections
  1467.   menuBar.checkItem(lastDrawOperationId);
  1468.   menuBar.checkItem(lastPenWidthId);
  1469.   menuBar.checkItem(lastPenTypeId);
  1470.   menuBar.checkItem(ID_SC_FRAME_TMODE);
  1471.   menuBar.checkItem(ID_SC_FILL_TMODE);
  1472.   menuBar.checkItem(ID_PATTERN_SOLID);
  1473.   menuBar.checkItem(ID_FPATTERN_SOLID);
  1474.  
  1475.   setFocus();
  1476.   maximize();
  1477.   show();
  1478.  
  1479.   // initialize the color table indices
  1480.   fillX = bframeX = bfillX = 0;         // set default color settings
  1481.   frameX = 3;
  1482.   frameY = bframeY = bfillY = 7;
  1483.   fillY = 4;
  1484.   canvasX = 7; canvasY = 0;
  1485.  
  1486.   drawingArea.Init();
  1487.  
  1488.   refresh();
  1489.  
  1490.   // allocate the color table
  1491.   InitPallet();
  1492.  
  1493. }
  1494.  
  1495. /*
  1496.  * Function: MainWindow::~MainWindow
  1497.  *
  1498.  * Parameters: NONE
  1499.  *
  1500.  * Return value: NONE
  1501.  *
  1502.  * Purpose: destructor for MainWindow
  1503.  *
  1504. */
  1505.  
  1506. MainWindow::~MainWindow()
  1507. {
  1508.  
  1509.   // delete the button array
  1510.   for(unsigned long i = 0; i < kNumberOfButtons; i++) {
  1511.  
  1512.     delete buttonArray[i];
  1513.  
  1514.   }
  1515.  
  1516.   // delete the color table
  1517.   ClearPallet();
  1518.  
  1519. }
  1520.  
  1521. /*
  1522.  * Function: MainWindow::SetInfoText
  1523.  *
  1524.  * Parameters:
  1525.  *   text: the text to be displayed in the information area
  1526.  *
  1527.  * Return value: NONE
  1528.  *
  1529.  * Purpose: sets the text in the information area
  1530.  *
  1531. */
  1532.  
  1533. void MainWindow::SetInfoText(IString text)
  1534. {
  1535.   infoText.setText(text);
  1536.  
  1537. }
  1538.  
  1539. /*
  1540.  * Function: MainWindow::SetInfoText
  1541.  *
  1542.  * Parameters:
  1543.  *   id: the resource id of the text to be displayed in the information area
  1544.  *
  1545.  * Return value: NONE
  1546.  *
  1547.  * Purpose: sets the text in the information area
  1548.  *
  1549. */
  1550.  
  1551. void MainWindow::SetInfoText(unsigned long id)
  1552. {
  1553.   infoText.setText(id);
  1554.  
  1555. }
  1556.  
  1557. /*
  1558.  * Function: MainWindow::InitPallet
  1559.  *
  1560.  * Parameters: NONE
  1561.  *
  1562.  * Return value: NONE
  1563.  *
  1564.  * Purpose: initializes the global color pallet
  1565.  *
  1566. */
  1567.  
  1568. void MainWindow::InitPallet()
  1569. {
  1570.   // set up the table - no pattern here!
  1571.   IBaseColor table[8][8] = {
  1572.     {IBaseColor(170,255,0), IBaseColor(128,128,0),
  1573.     IBaseColor(170,85,0),IBaseColor(128,0,0),IBaseColor(0,255,0),
  1574.     IBaseColor(0,146,0),IBaseColor(0,85,0),IBaseColor(0,0,0)},
  1575.  
  1576.     {IBaseColor(170,1,85),IBaseColor(170,170,85),
  1577.     IBaseColor(170,85,85),IBaseColor(170,0,85),
  1578.     IBaseColor(0,255,85),IBaseColor(0,170,85),IBaseColor(0,85,85),
  1579.     IBaseColor(0,0,85)},
  1580.  
  1581.     {IBaseColor(170,1,170),
  1582.     IBaseColor(204,204,204),IBaseColor(170,85,170),
  1583.     IBaseColor(128,128,128),IBaseColor(0,255,170),
  1584.     IBaseColor(0,146,170),IBaseColor(0,85,170),
  1585.     IBaseColor(0,0,170)},
  1586.  
  1587.     {IBaseColor(170,255,255),
  1588.     IBaseColor(170,170,255),IBaseColor(170,85,255),
  1589.     IBaseColor(170,0,255),IBaseColor(0,255,255),
  1590.     IBaseColor(0,170,255),IBaseColor(0,85,255),
  1591.     IBaseColor(0,0,255)},
  1592.  
  1593.     {IBaseColor(255,255,0),
  1594.     IBaseColor(255,170,0),IBaseColor(255,85,0),
  1595.     IBaseColor(255,0,0),IBaseColor(85,255,0),
  1596.     IBaseColor(85,170,0),IBaseColor(85,85,0),
  1597.     IBaseColor(85,0,0)},
  1598.  
  1599.     {IBaseColor(255,255,85),
  1600.     IBaseColor(255,170,85),IBaseColor(255,85,85),
  1601.     IBaseColor(255,0,85),IBaseColor(85,255,85),
  1602.     IBaseColor(85,170,85),IBaseColor(131,131,131),
  1603.     IBaseColor(85,0,85)},
  1604.  
  1605.     {IBaseColor(255,255,170),
  1606.     IBaseColor(255,170,170),IBaseColor(255,85,170),
  1607.     IBaseColor(255,0,170),IBaseColor(85,255,170),
  1608.     IBaseColor(85,170,170),IBaseColor(85,85,170),
  1609.     IBaseColor(85,0,170)},
  1610.  
  1611.     {IBaseColor(255,255,255),
  1612.     IBaseColor(255,170,255),IBaseColor(255,85,255),
  1613.     IBaseColor(255,0,255),IBaseColor(85,255,255),
  1614.     IBaseColor(85,170,255),IBaseColor(85,85,255),
  1615.     IBaseColor(85,0,255)}
  1616.   };
  1617.  
  1618.   // initialize the global table
  1619.   for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  1620.  
  1621.     for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  1622.  
  1623.       colorTable[i][j] = new IBaseColor(table[i][j]);
  1624.  
  1625.     }
  1626.  
  1627.   }
  1628.  
  1629. }
  1630.  
  1631. /*
  1632.  * Function: MainWindow::ClearPallet
  1633.  *
  1634.  * Parameters: NONE
  1635.  *
  1636.  * Return value: NONE
  1637.  *
  1638.  * Purpose: clears the global color pallet
  1639.  *
  1640. */
  1641.  
  1642. void MainWindow::ClearPallet()
  1643. {
  1644.   for(int i = 0; i < PALLETCANVAS_SQUARE; i++) {
  1645.  
  1646.     for(int j = 0; j < PALLETCANVAS_SQUARE; j++) {
  1647.  
  1648.       delete colorTable[i][j];
  1649.  
  1650.     }
  1651.  
  1652.   }
  1653.  
  1654. }
  1655.  
  1656. /*
  1657.  * Function: MainWindow::command
  1658.  *
  1659.  * Parameters:
  1660.  *   event: contains the command id of the event to be handled
  1661.  *
  1662.  * Return value: returns true when the event is processed
  1663.  *
  1664.  * Purpose: handles selections from the menu bar, tool bar, and pop-up menus
  1665.  *
  1666. */
  1667.  
  1668. bool MainWindow::command( ICommandEvent& event )
  1669. {
  1670.   bool fProcessed = false;
  1671.  
  1672.   char title[20];
  1673.  
  1674.   switch (event.commandId()) {
  1675.  
  1676.     // handle the toolbar events
  1677.     case PALLET_NORM: {
  1678.  
  1679.       currentPointer = POINTER_NONE;
  1680.  
  1681.       if(lastButton != buttonArray[PALLET_NORM - BUTTON_OFFSET]) lastButton->unlatch();
  1682.  
  1683.       lastButton = buttonArray[PALLET_NORM - BUTTON_OFFSET];
  1684.  
  1685.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1686.       SetInfoText(event.commandId()+LONG_OFFSET);
  1687.  
  1688.       fProcessed = true;
  1689.       break;
  1690.  
  1691.     }
  1692.  
  1693.     case PALLET_LINE: {
  1694.  
  1695.       currentPointer = POINTER_LINE;
  1696.  
  1697.       if(lastButton != buttonArray[PALLET_LINE - BUTTON_OFFSET]) lastButton->unlatch();
  1698.  
  1699.       lastButton = buttonArray[PALLET_LINE - BUTTON_OFFSET];
  1700.  
  1701.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1702.       SetInfoText(event.commandId()+LONG_OFFSET);
  1703.  
  1704.       fProcessed = true;
  1705.       break;
  1706.  
  1707.     }
  1708.  
  1709.     case PALLET_DRAW: {
  1710.  
  1711.       currentPointer = POINTER_DRAW;
  1712.  
  1713.       if(lastButton != buttonArray[PALLET_DRAW - BUTTON_OFFSET]) lastButton->unlatch();
  1714.  
  1715.       lastButton=  buttonArray[PALLET_DRAW - BUTTON_OFFSET];
  1716.  
  1717.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1718.       SetInfoText(event.commandId()+LONG_OFFSET);
  1719.  
  1720.       fProcessed = true;
  1721.       break;
  1722.  
  1723.     }
  1724.  
  1725.     case PALLET_RECTANGLE: {
  1726.  
  1727.       currentPointer = POINTER_RECTANGLE;
  1728.  
  1729.       if(lastButton != buttonArray[PALLET_RECTANGLE - BUTTON_OFFSET]) lastButton->unlatch();
  1730.  
  1731.       lastButton = buttonArray[PALLET_RECTANGLE - BUTTON_OFFSET];
  1732.  
  1733.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1734.       SetInfoText(event.commandId()+LONG_OFFSET);
  1735.  
  1736.       fProcessed = true;
  1737.       break;
  1738.  
  1739.     }
  1740.  
  1741.     case PALLET_ELLIPSE: {
  1742.  
  1743.       currentPointer = POINTER_ELLIPSE;
  1744.  
  1745.       if(lastButton != buttonArray[PALLET_ELLIPSE - BUTTON_OFFSET]) lastButton->unlatch();
  1746.  
  1747.       lastButton = buttonArray[PALLET_ELLIPSE - BUTTON_OFFSET];
  1748.  
  1749.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1750.       SetInfoText(event.commandId()+LONG_OFFSET);
  1751.  
  1752.       fProcessed = true;
  1753.       break;
  1754.  
  1755.     }
  1756.  
  1757.     case PALLET_POLYLINE: {
  1758.  
  1759.       currentPointer = POINTER_POLYLINE;
  1760.  
  1761.       if(lastButton != buttonArray[PALLET_POLYLINE - BUTTON_OFFSET]) lastButton->unlatch();
  1762.  
  1763.       lastButton = buttonArray[PALLET_POLYLINE - BUTTON_OFFSET];
  1764.  
  1765.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1766.       SetInfoText(event.commandId()+LONG_OFFSET);
  1767.  
  1768.       fProcessed = true;
  1769.       break;
  1770.  
  1771.     }
  1772.  
  1773.     case PALLET_POLYGON: {
  1774.  
  1775.       currentPointer = POINTER_POLYGON;
  1776.  
  1777.       if(lastButton != buttonArray[PALLET_POLYGON - BUTTON_OFFSET]) lastButton->unlatch();
  1778.  
  1779.       lastButton = buttonArray[PALLET_POLYGON - BUTTON_OFFSET];
  1780.  
  1781.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1782.       SetInfoText(event.commandId()+LONG_OFFSET);
  1783.  
  1784.       fProcessed = true;
  1785.       break;
  1786.  
  1787.     }
  1788.  
  1789.     case PALLET_CURVE: {
  1790.  
  1791.       currentPointer = POINTER_NONE;
  1792.  
  1793.       buttonArray[PALLET_CURVE - BUTTON_OFFSET]->unlatch();
  1794.       lastButton->latch();
  1795.  
  1796.       IPopUpMenu *curvePopUp = new IPopUpMenu(this,ID_POPUP_MENU);
  1797.       curvePopUp->addText(PALLET_ARC, "3 Point Arc");
  1798.       curvePopUp->addText(PALLET_CBEZIER, "Bezier Curve");
  1799.       curvePopUp->addText(PALLET_ACURVE, "Abstract Curve");
  1800. #ifndef IC_MOTIF
  1801.       (*curvePopUp).show(buttonArray[PALLET_CURVE - BUTTON_OFFSET]->position());
  1802. #else
  1803.       (*curvePopUp).show(IPoint(0,0));
  1804. #endif
  1805.       (*curvePopUp).setAutoDeleteObject();
  1806.  
  1807.       fProcessed = true;
  1808.       break;
  1809.  
  1810.     }
  1811.  
  1812.     case PALLET_LOOP: {
  1813.  
  1814.       currentPointer = POINTER_NONE;
  1815.  
  1816.       buttonArray[PALLET_LOOP - BUTTON_OFFSET]->unlatch();
  1817.       lastButton->latch();
  1818.  
  1819.       IPopUpMenu *loopPopUp = new IPopUpMenu(this,ID_POPUP_MENU);
  1820.       loopPopUp->addText(PALLET_CHORD, "Chord");
  1821.       loopPopUp->addText(PALLET_PIE, "Pie");
  1822.       loopPopUp->addText(PALLET_LBEZIER, "Bezier Loop");
  1823.       loopPopUp->addText(PALLET_ALOOP, "Abstract Loop");
  1824. #ifndef IC_MOTIF
  1825.       (*loopPopUp).show(buttonArray[PALLET_LOOP - BUTTON_OFFSET]->position());
  1826. #else
  1827.       (*loopPopUp).show(IPoint(0,0));
  1828. #endif
  1829.       (*loopPopUp).setAutoDeleteObject();
  1830.  
  1831.       fProcessed = true;
  1832.       break;
  1833.  
  1834.     }
  1835.  
  1836.     case PALLET_AREA: {
  1837.  
  1838.       currentPointer = POINTER_NONE;
  1839.  
  1840.       buttonArray[PALLET_AREA - BUTTON_OFFSET]->unlatch();
  1841.       lastButton->latch();
  1842.  
  1843.       IPopUpMenu *areaPopUp = new IPopUpMenu(this,ID_POPUP_MENU);
  1844.       areaPopUp->addText(PALLET_ADD, "Add");
  1845.       areaPopUp->addText(PALLET_SUBTRACT, "Subtract");
  1846.       areaPopUp->addText(PALLET_MULTIPLY, "Intersect");
  1847.       areaPopUp->addText(PALLET_XOR, "Exclusive Or");
  1848. #ifndef IC_MOTIF
  1849.       (*areaPopUp).show(buttonArray[PALLET_AREA - BUTTON_OFFSET]->position());
  1850. #else
  1851.       (*areaPopUp).show(IPoint(0,0));
  1852. #endif
  1853.       (*areaPopUp).setAutoDeleteObject();
  1854.  
  1855.       fProcessed = true;
  1856.       break;
  1857.  
  1858.     }
  1859.  
  1860.     case PALLET_TEXT: {
  1861.  
  1862.       currentPointer = POINTER_TEXT;
  1863.  
  1864.       if(lastButton != buttonArray[PALLET_TEXT - BUTTON_OFFSET]) lastButton->unlatch();
  1865.  
  1866.       lastButton = buttonArray[PALLET_TEXT - BUTTON_OFFSET];
  1867.  
  1868.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1869.       SetInfoText(event.commandId()+LONG_OFFSET);
  1870.  
  1871.       ITextDialog textDialog("Set Graphic Text", this);
  1872.  
  1873.       // bring up the dialog and get the text when the user has finished
  1874.       textDialog.showModally();
  1875.       if (textDialog.result() == ID_OK)
  1876.         drawingArea.SetGraphicText(IText(textDialog.getText()));
  1877.       else
  1878.         drawingArea.SetGraphicText(IText(""));
  1879.  
  1880.       fProcessed = true;
  1881.       break;
  1882.  
  1883.     }
  1884.  
  1885.     case PALLET_BITMAP: {
  1886.  
  1887.       currentPointer = POINTER_BITMAP;
  1888.  
  1889.       if(lastButton != buttonArray[PALLET_BITMAP - BUTTON_OFFSET]) lastButton->unlatch();
  1890.  
  1891.       lastButton = buttonArray[PALLET_BITMAP - BUTTON_OFFSET];
  1892.  
  1893.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1894.  
  1895.       fProcessed = true;
  1896.       break;
  1897.  
  1898.     }
  1899.  
  1900.  
  1901.     case PALLET_ROTATE: {
  1902.  
  1903.       currentPointer = POINTER_ROTATE;
  1904.  
  1905.       if(lastButton != buttonArray[PALLET_ROTATE - BUTTON_OFFSET]) lastButton->unlatch();
  1906.  
  1907.       lastButton = buttonArray[PALLET_ROTATE - BUTTON_OFFSET];
  1908.  
  1909.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1910.       SetInfoText(event.commandId()+LONG_OFFSET);
  1911.  
  1912.       fProcessed = true;
  1913.       break;
  1914.  
  1915.     }
  1916.  
  1917.     case PALLET_SCALE: {
  1918.  
  1919.       currentPointer = POINTER_SCALE;
  1920.  
  1921.       if(lastButton != buttonArray[PALLET_SCALE - BUTTON_OFFSET]) lastButton->unlatch();
  1922.  
  1923.       lastButton = buttonArray[PALLET_SCALE - BUTTON_OFFSET];
  1924.  
  1925.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1926.       SetInfoText(event.commandId()+LONG_OFFSET);
  1927.  
  1928.       fProcessed = true;
  1929.       break;
  1930.     }
  1931.  
  1932.     case PALLET_CLIP: {
  1933.  
  1934.       currentPointer = POINTER_CLIP;
  1935.  
  1936.       if(lastButton != buttonArray[PALLET_CLIP - BUTTON_OFFSET]) lastButton->unlatch();
  1937.  
  1938.       lastButton = buttonArray[PALLET_CLIP - BUTTON_OFFSET];
  1939.  
  1940.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1941.       SetInfoText(event.commandId()+LONG_OFFSET);
  1942.  
  1943.       fProcessed = true;
  1944.       break;
  1945.  
  1946.     }
  1947.  
  1948.     case PALLET_STYLE: {
  1949.  
  1950.       currentPointer = POINTER_NONE;
  1951.  
  1952.       if(lastButton != buttonArray[PALLET_STYLE - BUTTON_OFFSET]) lastButton->unlatch();
  1953.  
  1954.       lastButton = buttonArray[PALLET_STYLE - BUTTON_OFFSET];
  1955.  
  1956.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1957.       SetInfoText(event.commandId()+LONG_OFFSET);
  1958.  
  1959.       fProcessed = true;
  1960.       break;
  1961.  
  1962.     }
  1963.  
  1964.     // handle the curve popup menu selections
  1965.     case PALLET_ARC: {
  1966.  
  1967.       currentPointer = POINTER_ARC;
  1968.  
  1969.       if(lastButton != buttonArray[PALLET_CURVE - BUTTON_OFFSET]) lastButton->unlatch();
  1970.  
  1971.       lastButton = buttonArray[PALLET_CURVE - BUTTON_OFFSET];
  1972.       lastButton->latch();
  1973.  
  1974.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1975.       SetInfoText(event.commandId()+LONG_OFFSET);
  1976.  
  1977.       fProcessed = true;
  1978.       break;
  1979.  
  1980.     }
  1981.  
  1982.     case PALLET_CBEZIER: {
  1983.  
  1984.       currentPointer = POINTER_NONE;
  1985.  
  1986.       if(lastButton != buttonArray[PALLET_CURVE - BUTTON_OFFSET]) lastButton->unlatch();
  1987.  
  1988.       lastButton = buttonArray[PALLET_CURVE - BUTTON_OFFSET];
  1989.       lastButton->latch();
  1990.  
  1991.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  1992.       SetInfoText(event.commandId()+LONG_OFFSET);
  1993.  
  1994.       fProcessed = true;
  1995.       break;
  1996.  
  1997.     }
  1998.  
  1999.     case PALLET_ACURVE: {
  2000.  
  2001.       currentPointer = POINTER_NONE;
  2002.  
  2003.       if(lastButton != buttonArray[PALLET_CURVE - BUTTON_OFFSET]) lastButton->unlatch();
  2004.  
  2005.       lastButton = buttonArray[PALLET_CURVE - BUTTON_OFFSET];
  2006.       lastButton->latch();
  2007.  
  2008.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2009.       SetInfoText(event.commandId()+LONG_OFFSET);
  2010.  
  2011.       fProcessed = true;
  2012.       break;
  2013.  
  2014.     }
  2015.  
  2016.     // handle the loop popup menu selections
  2017.     case PALLET_ALOOP: {
  2018.  
  2019.       currentPointer = POINTER_NONE;
  2020.  
  2021.       if(lastButton != buttonArray[PALLET_LOOP - BUTTON_OFFSET]) lastButton->unlatch();
  2022.  
  2023.       lastButton = buttonArray[PALLET_LOOP - BUTTON_OFFSET];
  2024.       lastButton->latch();
  2025.  
  2026.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2027.       SetInfoText(event.commandId()+LONG_OFFSET);
  2028.  
  2029.       fProcessed = true;
  2030.       break;
  2031.  
  2032.     }
  2033.  
  2034.     case PALLET_LBEZIER: {
  2035.  
  2036.       currentPointer = POINTER_NONE;
  2037.  
  2038.       if(lastButton != buttonArray[PALLET_LOOP - BUTTON_OFFSET]) lastButton->unlatch();
  2039.  
  2040.       lastButton = buttonArray[PALLET_LOOP - BUTTON_OFFSET];
  2041.       lastButton->latch();
  2042.  
  2043.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2044.       SetInfoText(event.commandId()+LONG_OFFSET);
  2045.  
  2046.       fProcessed = true;
  2047.       break;
  2048.  
  2049.     }
  2050.  
  2051.     case PALLET_CHORD: {
  2052.  
  2053.       currentPointer = POINTER_CHORD;
  2054.  
  2055.       if(lastButton != buttonArray[PALLET_LOOP - BUTTON_OFFSET]) lastButton->unlatch();
  2056.  
  2057.       lastButton = buttonArray[PALLET_LOOP - BUTTON_OFFSET];
  2058.       lastButton->latch();
  2059.  
  2060.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2061.       SetInfoText(event.commandId()+LONG_OFFSET);
  2062.  
  2063.       fProcessed = true;
  2064.       break;
  2065.  
  2066.     }
  2067.  
  2068.     case PALLET_PIE: {
  2069.  
  2070.       currentPointer = POINTER_PIE;
  2071.  
  2072.       if(lastButton != buttonArray[PALLET_LOOP - BUTTON_OFFSET]) lastButton->unlatch();
  2073.  
  2074.       lastButton = buttonArray[PALLET_LOOP - BUTTON_OFFSET];
  2075.       lastButton->latch();
  2076.  
  2077.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2078.       SetInfoText(event.commandId()+LONG_OFFSET);
  2079.  
  2080.       fProcessed = true;
  2081.       break;
  2082.  
  2083.     }
  2084.  
  2085.     // handle the area popup menu selections
  2086.     case PALLET_ADD: {
  2087.  
  2088.       currentPointer = POINTER_NONE;
  2089.  
  2090.       if(lastButton != buttonArray[PALLET_AREA - BUTTON_OFFSET]) lastButton->unlatch();
  2091.  
  2092.       lastButton = buttonArray[PALLET_AREA - BUTTON_OFFSET];
  2093.       lastButton->latch();
  2094.  
  2095.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2096.       SetInfoText(event.commandId()+LONG_OFFSET);
  2097.  
  2098.       fProcessed = true;
  2099.       break;
  2100.  
  2101.     }
  2102.  
  2103.     case PALLET_SUBTRACT: {
  2104.  
  2105.       currentPointer = POINTER_NONE;
  2106.  
  2107.       if(lastButton != buttonArray[PALLET_AREA - BUTTON_OFFSET]) lastButton->unlatch();
  2108.  
  2109.       lastButton = buttonArray[PALLET_AREA - BUTTON_OFFSET];
  2110.       lastButton->latch();
  2111.  
  2112.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2113.       SetInfoText(event.commandId()+LONG_OFFSET);
  2114.  
  2115.       fProcessed = true;
  2116.       break;
  2117.  
  2118.     }
  2119.  
  2120.     case PALLET_MULTIPLY: {
  2121.  
  2122.       currentPointer = POINTER_NONE;
  2123.  
  2124.       if(lastButton != buttonArray[PALLET_AREA - BUTTON_OFFSET]) lastButton->unlatch();
  2125.  
  2126.       lastButton = buttonArray[PALLET_AREA - BUTTON_OFFSET];
  2127.       lastButton->latch();
  2128.  
  2129.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2130.       SetInfoText(event.commandId()+LONG_OFFSET);
  2131.  
  2132.       fProcessed = true;
  2133.       break;
  2134.  
  2135.     }
  2136.  
  2137.     case PALLET_XOR: {
  2138.  
  2139.       currentPointer = POINTER_NONE;
  2140.  
  2141.       if(lastButton != buttonArray[PALLET_AREA - BUTTON_OFFSET]) lastButton->unlatch();
  2142.  
  2143.       lastButton = buttonArray[PALLET_AREA - BUTTON_OFFSET];
  2144.       lastButton->latch();
  2145.  
  2146.       drawingArea.SetDrawObject((DrawingArea::DrawObject)event.commandId());
  2147.       SetInfoText(event.commandId()+LONG_OFFSET);
  2148.  
  2149.       fProcessed = true;
  2150.       break;
  2151.  
  2152.     }
  2153.  
  2154.     // handle pen width selections
  2155.     case ID_PENWIDTH_1:
  2156.     case ID_PENWIDTH_2:
  2157.     case ID_PENWIDTH_3:
  2158.     case ID_PENWIDTH_4:
  2159.     case ID_PENWIDTH_5:
  2160.     case ID_PENWIDTH_6:
  2161.     case ID_PENWIDTH_7:
  2162.     case ID_PENWIDTH_8:
  2163.     case ID_PENWIDTH_9:
  2164.     case ID_PENWIDTH_10: {
  2165.  
  2166.       menuBar.uncheckItem(lastPenWidthId)
  2167.                .checkItem(lastPenWidthId = event.commandId());
  2168.  
  2169.       drawingArea.SetPenWidth(event.commandId() - ID_CORRECTION);
  2170.  
  2171.       fProcessed = true;
  2172.       break;
  2173.  
  2174.     }
  2175.  
  2176.     // handle pen color selection
  2177.     case ID_COLORS: {
  2178.  
  2179.       IPalletDialog colorDialog("Set Pen Color",frameX,frameY, this);
  2180.       colorDialog.showModally();
  2181.       if (colorDialog.result() == ID_OK)
  2182.         drawingArea.SetPenColor(colorDialog.color());
  2183.       fProcessed = true;
  2184.       break;
  2185.  
  2186.     }
  2187.  
  2188.     // handle fill color selection
  2189.     case ID_FLCOLORS: {
  2190.  
  2191.       IPalletDialog colorDialog("Set Fill Color",fillX,fillY,this);
  2192.       colorDialog.showModally();
  2193.       if (colorDialog.result() == ID_OK)
  2194.         drawingArea.SetFillColor(colorDialog.color());
  2195.  
  2196.       fProcessed = true;
  2197.       break;
  2198.  
  2199.     }
  2200.  
  2201.     // handle fill color selection
  2202.     case ID_CCOLORS: {
  2203.  
  2204.       IPalletDialog colorDialog("Set Canvas Color",canvasX,canvasY,this);
  2205.  
  2206.       fProcessed = true;
  2207.       break;
  2208.  
  2209.     }
  2210.  
  2211.     // handle pen style selections
  2212.     case ID_PENTYPE_HAIRLINE:
  2213.     case ID_PENTYPE_SOLID :
  2214.     case ID_PENTYPE_INVISIBLE :
  2215.     case ID_PENTYPE_DASHDOT :
  2216.     case ID_PENTYPE_SHORTDASH :
  2217.     case ID_PENTYPE_DOT :
  2218.     case ID_PENTYPE_DASHDOUBLEDOT: {
  2219.  
  2220.       menuBar.uncheckItem(lastPenTypeId);
  2221.       menuBar.checkItem(lastPenTypeId = event.commandId());
  2222.  
  2223.       drawingArea.setPenType(event.commandId());
  2224.  
  2225.       fProcessed = true;
  2226.       break;
  2227.  
  2228.     }
  2229.  
  2230.     // handle drawing operation selections
  2231.     case ID_FILL: {
  2232.  
  2233.       menuBar.uncheckItem(lastDrawOperationId)
  2234.              .checkItem(lastDrawOperationId = event.commandId());
  2235.  
  2236.       drawingArea.SetDrawingOp(IAttributeState::kFill);
  2237.  
  2238.       fProcessed = true;
  2239.       break;
  2240.  
  2241.     }
  2242.  
  2243.     case ID_FRAME: {
  2244.  
  2245.       menuBar.uncheckItem(lastDrawOperationId)
  2246.              .checkItem(lastDrawOperationId = event.commandId());
  2247.  
  2248.       drawingArea.SetDrawingOp(IAttributeState::kFrame);
  2249.  
  2250.       fProcessed = true;
  2251.       break;
  2252.  
  2253.     }
  2254.  
  2255.     case ID_FILLANDFRAME: {
  2256.  
  2257.       menuBar.uncheckItem(lastDrawOperationId)
  2258.              .checkItem(lastDrawOperationId = event.commandId());
  2259.  
  2260.       drawingArea.SetDrawingOp(IAttributeState::kFillAndFrame);
  2261.  
  2262.       fProcessed = true;
  2263.       break;
  2264.  
  2265.     }
  2266.  
  2267.     // handle clear background selection
  2268.     case ID_CLEAR: {
  2269.  
  2270.       drawingArea.Clear();
  2271.  
  2272.       fProcessed = true;
  2273.       break;
  2274.  
  2275.     }
  2276.  
  2277.     // handle reset color pallete selection
  2278.     case ID_RESET: {
  2279.  
  2280.       ClearPallet();
  2281.       InitPallet();
  2282.  
  2283.       fProcessed = true;
  2284.       break;
  2285.  
  2286.     }
  2287.  
  2288.     // handle frame transfer mode selections
  2289.     case ID_SC_FRAME_TMODE:
  2290.     case ID_IS_FRAME_TMODE:
  2291.     case ID_DC_FRAME_TMODE:
  2292.     case ID_ID_FRAME_TMODE:
  2293.     case ID_SORD_FRAME_TMODE:
  2294.     case ID_SANDD_FRAME_TMODE:
  2295.     case ID_SXORD_FRAME_TMODE:
  2296.     case ID_ISANDD_FRAME_TMODE:
  2297.     case ID_ISORD_FRAME_TMODE:
  2298.     case ID_SANDID_FRAME_TMODE:
  2299.     case ID_SORID_FRAME_TMODE:
  2300.     case ID_IRSANDD_FRAME_TMODE:
  2301.     case ID_IRSORD_FRAME_TMODE:
  2302.     case ID_IRSXORD_FRAME_TMODE:
  2303.     case ID_ONE_FRAME_TMODE:
  2304.     case ID_ZERO_FRAME_TMODE: {
  2305.  
  2306.       menuBar.uncheckItem(frameTransferMode)
  2307.              .checkItem(event.commandId());
  2308.  
  2309.       drawingArea.SetFrameTransferMode(event.commandId());
  2310.  
  2311.       fProcessed = true;
  2312.       break;
  2313.  
  2314.     }
  2315.  
  2316.     // handle fill transfer mode selections
  2317.     case ID_SC_FILL_TMODE:
  2318.     case ID_IS_FILL_TMODE:
  2319.     case ID_DC_FILL_TMODE:
  2320.     case ID_ID_FILL_TMODE:
  2321.     case ID_SORD_FILL_TMODE:
  2322.     case ID_SANDD_FILL_TMODE:
  2323.     case ID_SXORD_FILL_TMODE:
  2324.     case ID_ISANDD_FILL_TMODE:
  2325.     case ID_ISORD_FILL_TMODE:
  2326.     case ID_SANDID_FILL_TMODE:
  2327.     case ID_SORID_FILL_TMODE:
  2328.     case ID_IRSANDD_FILL_TMODE:
  2329.     case ID_IRSORD_FILL_TMODE:
  2330.     case ID_IRSXORD_FILL_TMODE:
  2331.     case ID_ONE_FILL_TMODE:
  2332.     case ID_ZERO_FILL_TMODE: {
  2333.  
  2334.       menuBar.uncheckItem(fillTransferMode)
  2335.              .checkItem(event.commandId());
  2336.  
  2337.       drawingArea.SetFillTransferMode(event.commandId());
  2338.  
  2339.       fProcessed = true;
  2340.       break;
  2341.  
  2342.     }
  2343.  
  2344.     // handle fill pattern selections
  2345.     case ID_PATTERN_SOLID:
  2346.     case ID_PATTERN_BDIAGONAL:
  2347.     case ID_PATTERN_FDIAGONAL:
  2348.     case ID_PATTERN_CROSS:
  2349.     case ID_PATTERN_DIAGONALCROSS:
  2350.     case ID_PATTERN_HORIZONTAL:
  2351.     case ID_PATTERN_VERTICAL:
  2352.     case ID_PATTERN_EAGLE:
  2353.     case ID_PATTERN_TAJMAHAL: {
  2354.  
  2355.       menuBar.uncheckItem(framePattern)
  2356.              .checkItem(event.commandId());
  2357.  
  2358.       drawingArea.SetFramePattern(event.commandId());
  2359.       fProcessed = true;
  2360.  
  2361.       break;
  2362.  
  2363.     }
  2364.  
  2365.     // handle fill pattern selections
  2366.     case ID_FPATTERN_SOLID:
  2367.     case ID_FPATTERN_BDIAGONAL:
  2368.     case ID_FPATTERN_FDIAGONAL:
  2369.     case ID_FPATTERN_CROSS:
  2370.     case ID_FPATTERN_DIAGONALCROSS:
  2371.     case ID_FPATTERN_HORIZONTAL:
  2372.     case ID_FPATTERN_VERTICAL:
  2373.     case ID_FPATTERN_EAGLE:
  2374.     case ID_FPATTERN_TAJMAHAL: {
  2375.  
  2376.       menuBar.uncheckItem(fillPattern)
  2377.              .checkItem(event.commandId());
  2378.  
  2379.       drawingArea.SetFillPattern(event.commandId());
  2380.  
  2381.       fProcessed = true;
  2382.       break;
  2383.  
  2384.     }
  2385.  
  2386.     case MI_PREVIEWER:
  2387.     case MI_DIALOG:
  2388.         {
  2389. #ifndef FVT_NOPRINT
  2390.                 SetInfoText("Handling Print");
  2391.  
  2392.                 // Create a simple butler (good old Ned) and use a simple page iterator
  2393.                 IPrintButler butler;
  2394.                 IStandardPageDescription page(IString("US Letter"), IPageDescription::kUSLetter);
  2395.                 IGenericClientJobDescription *clientJob = (IGenericClientJobDescription*)
  2396.                 butler.printJobDescription()->clientJobDescription();
  2397.                 clientJob->setFileName("c:\\temp\\ptfwin.txt");
  2398.                 IGraphicGroup *group = drawingArea.GetGraphicGroup();
  2399.  
  2400.                 try {
  2401.                         switch (event.commandId())
  2402.                         {
  2403.                                 case MI_PREVIEWER:
  2404.                                         butler.printWithPreview(*this, page, *group);
  2405.                                         break;
  2406.                                 case MI_DIALOG:
  2407.                                         butler.printWithDialog(*this, page, *group);
  2408.                                         break;
  2409.                         } // end switch on the print request
  2410.                 }
  2411.                 catch (IException& e)
  2412.                 {
  2413.                         IText error("Caught Exception: ");
  2414.                         error.append(e.name());
  2415.                         error.append(": ");
  2416.                         error.append(e.text());
  2417.                         SetInfoText(error);
  2418.                 }
  2419. #endif
  2420.                 fProcessed = true;
  2421.                 break;
  2422.         }
  2423.  
  2424.     break;
  2425.  
  2426.   } /* endswitch */
  2427.  
  2428.   return fProcessed;
  2429.  
  2430. }
  2431.  
  2432. /*
  2433.  * Function: MainWindow::windowResize
  2434.  *
  2435.  * Parameters:
  2436.  *   event: describes the type of resize event to be processed
  2437.  *
  2438.  * Return value: returns true when the event it processed - always true here
  2439.  *
  2440.  * Purpose: Handles the positioning of the buttons of the toolbar as the
  2441.  *          window size changes
  2442.  *
  2443. */
  2444.  
  2445. bool MainWindow::windowResize(IResizeEvent& event)
  2446. {
  2447.   // if the window size hasn't changed there is nothing to do
  2448.   if(event.newSize() == event.oldSize()) return true;
  2449.  
  2450.   // if the width of the button is zero, do nothing
  2451.   if(buttonArray[0]->size().width() == 0) return true;
  2452.  
  2453.   // calculate the number of buttons that can fit in one row
  2454.   int newInd = event.newSize().width()/buttonArray[0]->size().width();
  2455.  
  2456.   // do some range checking/adjustment
  2457.   if(newInd > kNumberOfButtons) newInd = kNumberOfButtons;
  2458.  
  2459.   // if the same amount of buttons can fit there is nothing to do
  2460.   if((newInd == groupButtIndex) || (newInd == 0)) return true;
  2461.  
  2462.   // remove the buttons from the toolbar
  2463.   for(unsigned long i = 0; i < kNumberOfButtons; i++) {
  2464.  
  2465.     toolBar1.remove( buttonArray[i] );
  2466.  
  2467.   }
  2468.  
  2469.   // add the buttons in the new orientation
  2470.   for(unsigned long j = kNumberOfButtons-1; j > 0; j--) {
  2471.  
  2472.     if(!((j+1)%newInd)) {  // if we are at a break point...
  2473.  
  2474.       toolBar1.addAsFirst( buttonArray[j], true ); // start another row
  2475.  
  2476.     }
  2477.  
  2478.     else { // else add to the same row
  2479.  
  2480.       toolBar1.addAsFirst( buttonArray[j] );
  2481.  
  2482.     }
  2483.  
  2484.   }
  2485.  
  2486.   toolBar1.addAsFirst( buttonArray[0] );
  2487.   groupButtIndex = newInd;
  2488.  
  2489.   return true;
  2490.  
  2491. }
  2492. #endif
  2493.