home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / visbuild / doodle / darea / darea.hpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-16  |  7.3 KB  |  199 lines

  1. #ifndef DAREA_HPP
  2. #define DAREA_HPP
  3. /******************************************************************************
  4. * .FILE:        darea.hpp                                                     *
  5. *                                                                             *
  6. * .DESCRIPTION: Header file for the class, DrawingArea                        *
  7. *                                                                             *
  8. * .CLASSES:     DrawingArea                                                   *
  9. *                                                                             *
  10. * .COPYRIGHT:                                                                 *
  11. *    Licensed Material - Program-Property of IBM                              *
  12. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  13. *                                                                             *
  14. * .DISCLAIMER:                                                                *
  15. *   The following [enclosed] code is sample code created by IBM               *
  16. *   Corporation.  This sample code is not part of any standard IBM product    *
  17. *   and is provided to you solely for the purpose of assisting you in the     *
  18. *   development of your applications.  The code is provided 'AS IS',          *
  19. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  20. *   arising out of your use of the sample code, even if they have been        *
  21. *   advised of the possibility of such damages.                               *
  22. *                                                                             *
  23. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  24. *                                                                             *
  25. ******************************************************************************/
  26.  
  27. #include <iframe.hpp>           //Include IFrameWindow Class Header
  28. #include <isizehdr.hpp>
  29. #include <icmdhdr.hpp>
  30. #include <igrafctx.hpp>
  31. #include <igbundle.hpp>
  32. #include <idrawcv.hpp>
  33. #include <imndihdr.hpp>
  34. #include <imndievt.hpp>
  35. #include <ireslib.hpp>
  36. #include <imoushdr.hpp>
  37. #include <imousevt.hpp>
  38. #include <ifont.hpp>
  39. #include <istring.hpp>
  40. #include <igrect.hpp>
  41. #include <iflyhhdr.hpp>
  42. #include "darea.h"
  43.  
  44. //**************************************************************************
  45. // Class:   DrawingArea                                                    *
  46. //                                                                         *
  47. // Purpose: Subclass of IDrawingCanvas.  Class contains the handlers       *
  48. //          necessary for interactive drawing of the graphic objects.      *
  49. //                                                                         *
  50. //**************************************************************************
  51. class DrawingArea : public IDrawingCanvas,
  52.                     public IMouseHandler
  53. {
  54. public:
  55.   DrawingArea  ( unsigned long id,
  56.                  IWindow* parent,
  57.                  IWindow* owner,
  58.                  const IRectangle& rect = IRectangle() );
  59. virtual
  60.   ~DrawingArea ( );
  61.  
  62. enum DrawState {
  63.   drawing,
  64.   waitingForInput,
  65.   notDrawing
  66.   };
  67.  
  68. DrawingArea
  69.   &setDrawState        ( const DrawState newState = drawing );
  70. DrawState
  71.   drawState            ( ) const { return dState; }
  72.  
  73. DrawingArea
  74.   &setBitmapFileName   ( const IString& bitmapFile )
  75.                          { currentBitmap = bitmapFile;
  76.                            return *this; }
  77. IString
  78.   bitmapFileName       ( ) const
  79.                          { return currentBitmap; }
  80.  
  81. enum DrawObject {
  82.   move = POINTER_MOVE,
  83.   line,
  84.   freehand,
  85.   rectangle,
  86.   ellipse,
  87.   polyline,
  88.   polygon,
  89.   arc,
  90.   pie,
  91.   chord,
  92.   text,
  93.   bitmap,
  94.   stylecan,
  95.   eraser
  96.   };
  97.  
  98. virtual DrawingArea
  99.   &setDrawObject       ( const DrawObject drawObject )
  100.                          { currentObj = drawObject;
  101.                            if (flyOverHandler)
  102.                              flyOverHandler->setHelpText( handle(),
  103.                                                           IResourceId(FLYOVERTEXT_BLANK),
  104.                                                           IResourceId(currentObj+LONG_OFFSET));
  105.                            return *this; }
  106. virtual DrawObject
  107.   drawObject           ( ) const {return currentObj;}
  108.  
  109. virtual IGraphicBundle
  110.   &graphicBundle       ( ) { return currentBundle; }
  111.  
  112. virtual DrawingArea
  113.   &setCurrentFont      ( const IFont& font );
  114. virtual IFont
  115.   currentFont          ( ) const;
  116.  
  117. virtual void
  118.    setColor            ( const IColor* color )
  119.                          { graphicBundle().setFillColor(*color); }
  120.  
  121. virtual void
  122.    setFlyOverHandler   ( IFlyOverHelpHandler* handler)
  123.                          { flyOverHandler = handler;
  124.                            if (flyOverHandler)
  125.                              flyOverHandler->setHelpText( handle(),
  126.                                                           IResourceId(FLYOVERTEXT_BLANK),
  127.                                                           IResourceId(currentObj+LONG_OFFSET));
  128.                          }
  129.  
  130. virtual void
  131.    setPenColor         ( const IColor* color )
  132.                          { graphicBundle().setPenColor(*color); }
  133. virtual void
  134.    setWidth            ( unsigned long width )
  135.                          { graphicBundle().setPenWidth(width); }
  136.  
  137. virtual void
  138.    setDrawStyle        ( short value = 0 )
  139.         { switch(value)
  140.           {
  141.             case -1:    // frame
  142.               graphicBundle().setDrawOperation(IGraphicBundle::frame);
  143.               break;
  144.             case 0:     // frame & fill
  145.               graphicBundle().setDrawOperation(IGraphicBundle::fillAndFrame);
  146.               break;
  147.             case 1:     // fill
  148.               graphicBundle().setDrawOperation(IGraphicBundle::fill);
  149.               break;
  150.           }
  151.         }
  152.  
  153. protected:
  154.  
  155. virtual Boolean
  156.   mouseMoved           ( IMouseEvent&        event ),
  157.   mouseClicked         ( IMouseClickEvent&   event ),
  158.   mousePointerChange   ( IMousePointerEvent& event );
  159.  
  160. virtual DrawingArea
  161.   &button1Down         ( const IPoint&       point ),
  162.   &button1Up           ( const IPoint&       point ),
  163.   &button1DoubleClick  ( const IPoint&       point ),
  164.   &button2Down         ( const IPoint&       point ),
  165.   &button2Up           ( const IPoint&       point );
  166.  
  167. private:
  168.   IGraphicContext    gc;
  169.   IFont              currentfont;
  170.   IGraphicBundle     currentBundle;
  171.   IString            currentBitmap;
  172.   DrawState          dState;
  173.   DrawObject         currentObj;
  174.   IGraphic*          iGraphic;
  175.   IGraphic*          moveGraphic;
  176.   IGRectangle        moveRect;
  177.   IPoint             startingPt;
  178.   IPoint             previousPt;
  179.   IPoint             tempPt;
  180.   unsigned long      pointCount;
  181.   IPointerHandle     ptrCurrent;
  182.   IPointerHandle     ptrLine;
  183.   IPointerHandle     ptrFreehand;
  184.   IPointerHandle     ptrRectangle;
  185.   IPointerHandle     ptrEllipse;
  186.   IPointerHandle     ptrPolyline;
  187.   IPointerHandle     ptrPolygon;
  188.   IPointerHandle     ptrArc;
  189.   IPointerHandle     ptrPie;
  190.   IPointerHandle     ptrChord;
  191.   IPointerHandle     ptrText;
  192.   IPointerHandle     ptrBitmap;
  193.   IPointerHandle     ptrStyleCan;
  194.   IPointerHandle     ptrEraser;
  195.   IFlyOverHelpHandler*  flyOverHandler;
  196. };
  197.  
  198. #endif
  199.