home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / wxos2233.zip / wxOS2-2_3_3.zip / wxWindows-2.3.3 / contrib / include / wx / ogl / basic.h next >
C/C++ Source or Header  |  2002-09-08  |  30KB  |  745 lines

  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name:        basic.h
  3. // Purpose:     Basic OGL classes and definitions
  4. // Author:      Julian Smart
  5. // Modified by:
  6. // Created:     12/07/98
  7. // RCS-ID:      $Id: basic.h,v 1.5 2002/09/07 12:10:20 GD Exp $
  8. // Copyright:   (c) Julian Smart
  9. // Licence:       wxWindows licence
  10. /////////////////////////////////////////////////////////////////////////////
  11.  
  12. #ifndef _OGL_BASIC_H_
  13. #define _OGL_BASIC_H_
  14.  
  15. #if defined(__GNUG__) && !defined(__APPLE__)
  16. #pragma interface "basic.h"
  17. #endif
  18.  
  19. #define OGL_VERSION     2.0
  20.  
  21. #ifndef DEFAULT_MOUSE_TOLERANCE
  22. #define DEFAULT_MOUSE_TOLERANCE 3
  23. #endif
  24.  
  25. // Edit these lines if you positively don't want PROLOGIO support
  26. #ifndef PROLOGIO
  27. #define PROLOGIO
  28. #endif
  29.  
  30. // Key identifiers
  31. #define KEY_SHIFT 1
  32. #define KEY_CTRL  2
  33.  
  34. // Arrow styles
  35.  
  36. #define ARROW_NONE         0
  37. #define ARROW_END          1
  38. #define ARROW_BOTH         2
  39. #define ARROW_MIDDLE       3
  40. #define ARROW_START        4
  41.  
  42. // Control point types
  43. // Rectangle and most other shapes
  44. #define CONTROL_POINT_VERTICAL   1
  45. #define CONTROL_POINT_HORIZONTAL 2
  46. #define CONTROL_POINT_DIAGONAL   3
  47.  
  48. // Line
  49. #define CONTROL_POINT_ENDPOINT_TO 4
  50. #define CONTROL_POINT_ENDPOINT_FROM 5
  51. #define CONTROL_POINT_LINE       6
  52.  
  53. // Types of formatting: can be combined in a bit list
  54. #define FORMAT_NONE           0
  55.                                 // Left justification
  56. #define FORMAT_CENTRE_HORIZ   1
  57.                                 // Centre horizontally
  58. #define FORMAT_CENTRE_VERT    2
  59.                                 // Centre vertically
  60. #define FORMAT_SIZE_TO_CONTENTS 4
  61.                                 // Resize shape to contents
  62.  
  63. // Shadow mode
  64. #define SHADOW_NONE           0
  65. #define SHADOW_LEFT           1
  66. #define SHADOW_RIGHT          2
  67.  
  68. /*
  69.  * Declare types
  70.  *
  71.  */
  72.  
  73. #define SHAPE_BASIC           wxTYPE_USER + 1
  74. #define SHAPE_RECTANGLE       wxTYPE_USER + 2
  75. #define SHAPE_ELLIPSE         wxTYPE_USER + 3
  76. #define SHAPE_POLYGON         wxTYPE_USER + 4
  77. #define SHAPE_CIRCLE          wxTYPE_USER + 5
  78. #define SHAPE_LINE            wxTYPE_USER + 6
  79. #define SHAPE_DIVIDED_RECTANGLE wxTYPE_USER + 8
  80. #define SHAPE_COMPOSITE       wxTYPE_USER + 9
  81. #define SHAPE_CONTROL_POINT   wxTYPE_USER + 10
  82. #define SHAPE_DRAWN           wxTYPE_USER + 11
  83. #define SHAPE_DIVISION        wxTYPE_USER + 12
  84. #define SHAPE_LABEL_OBJECT    wxTYPE_USER + 13
  85. #define SHAPE_BITMAP          wxTYPE_USER + 14
  86. #define SHAPE_DIVIDED_OBJECT_CONTROL_POINT   wxTYPE_USER + 15
  87.  
  88. #define OBJECT_REGION         wxTYPE_USER + 20
  89.  
  90. #define OP_CLICK_LEFT  1
  91. #define OP_CLICK_RIGHT 2
  92. #define OP_DRAG_LEFT 4
  93. #define OP_DRAG_RIGHT 8
  94.  
  95. #define OP_ALL (OP_CLICK_LEFT | OP_CLICK_RIGHT | OP_DRAG_LEFT | OP_DRAG_RIGHT)
  96.  
  97. // Attachment modes
  98. #define ATTACHMENT_MODE_NONE        0
  99. #define ATTACHMENT_MODE_EDGE        1
  100. #define ATTACHMENT_MODE_BRANCHING   2
  101.  
  102. // Sub-modes for branching attachment mode
  103. #define BRANCHING_ATTACHMENT_NORMAL 1
  104. #define BRANCHING_ATTACHMENT_BLOB   2
  105.  
  106. class wxShapeTextLine;
  107. class wxShapeCanvas;
  108. class wxLineShape;
  109. class wxControlPoint;
  110. class wxShapeRegion;
  111. class wxShape;
  112.  
  113. #ifdef PROLOGIO
  114. class WXDLLEXPORT wxExpr;
  115. class WXDLLEXPORT wxExprDatabase;
  116. #endif
  117.  
  118. // Round up
  119. #define WXROUND(x) ( (long) (x + 0.5) )
  120.  
  121.  
  122. // logical function to use when drawing rubberband boxes, etc.
  123. #define OGLRBLF         wxINVERT
  124.  
  125.  
  126.  
  127. class wxShapeEvtHandler: public wxObject, public wxClientDataContainer
  128. {
  129.  DECLARE_DYNAMIC_CLASS(wxShapeEvtHandler)
  130.  
  131.  public:
  132.   wxShapeEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL);
  133.   virtual ~wxShapeEvtHandler();
  134.  
  135.   inline void SetShape(wxShape *sh) { m_handlerShape = sh; }
  136.   inline wxShape *GetShape() const { return m_handlerShape; }
  137.  
  138.   inline void SetPreviousHandler(wxShapeEvtHandler* handler) { m_previousHandler = handler; }
  139.   inline wxShapeEvtHandler* GetPreviousHandler() const { return m_previousHandler; }
  140.  
  141.   // This is called when the _shape_ is deleted.
  142.   virtual void OnDelete();
  143.   virtual void OnDraw(wxDC& dc);
  144.   virtual void OnDrawContents(wxDC& dc);
  145.   virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
  146.   virtual void OnMoveLinks(wxDC& dc);
  147.   virtual void OnErase(wxDC& dc);
  148.   virtual void OnEraseContents(wxDC& dc);
  149.   virtual void OnHighlight(wxDC& dc);
  150.   virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
  151.   virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0);
  152.   virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
  153.   virtual void OnSize(double x, double y);
  154.   virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
  155.   virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
  156.  
  157.   virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  158.   virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
  159.   virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
  160.   virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  161.   virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0);
  162.   virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0);
  163.   virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
  164.   virtual void OnDrawControlPoints(wxDC& dc);
  165.   virtual void OnEraseControlPoints(wxDC& dc);
  166.   virtual void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE);
  167.  
  168.   // Control points ('handles') redirect control to the actual shape, to make it easier
  169.   // to override sizing behaviour.
  170.   virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  171.   virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  172.   virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  173.  
  174.   virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { }
  175.   virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { }
  176.  
  177.   // Can override this to prevent or intercept line reordering.
  178.   virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
  179.  
  180.   // Creates a copy of this event handler.
  181.   wxShapeEvtHandler *CreateNewCopy();
  182.  
  183.   // Does the copy - override for new event handlers which might store
  184.   // app-specific data.
  185.   virtual void CopyData(wxShapeEvtHandler& copy) {};
  186.  
  187.  private:
  188.   wxShapeEvtHandler*    m_previousHandler;
  189.   wxShape*              m_handlerShape;
  190. };
  191.  
  192. class wxShape: public wxShapeEvtHandler
  193. {
  194.  DECLARE_ABSTRACT_CLASS(wxShape)
  195.  
  196.  public:
  197.  
  198.   wxShape(wxShapeCanvas *can = NULL);
  199.   virtual ~wxShape();
  200.   virtual void GetBoundingBoxMax(double *width, double *height);
  201.   virtual void GetBoundingBoxMin(double *width, double *height) = 0;
  202.   virtual bool GetPerimeterPoint(double x1, double y1,
  203.                                  double x2, double y2,
  204.                                  double *x3, double *y3);
  205.   inline wxShapeCanvas *GetCanvas() { return m_canvas; }
  206.   void SetCanvas(wxShapeCanvas *the_canvas);
  207.   virtual void AddToCanvas(wxShapeCanvas *the_canvas, wxShape *addAfter = NULL);
  208.   virtual void InsertInCanvas(wxShapeCanvas *the_canvas);
  209.  
  210.   virtual void RemoveFromCanvas(wxShapeCanvas *the_canvas);
  211.   inline double GetX() const { return m_xpos; }
  212.   inline double GetY() const { return m_ypos; }
  213.   inline void SetX(double x) { m_xpos = x; }
  214.   inline void SetY(double y) { m_ypos = y; }
  215.  
  216.   inline wxShape *GetParent() const { return m_parent; }
  217.   inline void SetParent(wxShape *p) { m_parent = p; }
  218.   wxShape *GetTopAncestor();
  219.   inline wxList& GetChildren() { return m_children; }
  220.  
  221.   virtual void OnDraw(wxDC& dc);
  222.   virtual void OnDrawContents(wxDC& dc);
  223.   virtual void OnMoveLinks(wxDC& dc);
  224.   virtual void Unlink() { };
  225.   void SetDrawHandles(bool drawH);
  226.   inline bool GetDrawHandles() { return m_drawHandles; }
  227.   virtual void OnErase(wxDC& dc);
  228.   virtual void OnEraseContents(wxDC& dc);
  229.   virtual void OnHighlight(wxDC& dc);
  230.   virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
  231.   virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0) {}
  232.   virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
  233.   virtual void OnSize(double x, double y);
  234.   virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
  235.   virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
  236.  
  237.   virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  238.   virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
  239.   virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
  240.   virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  241.   virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0);
  242.   virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0);
  243.   virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
  244.   virtual void OnDrawControlPoints(wxDC& dc);
  245.   virtual void OnEraseControlPoints(wxDC& dc);
  246.  
  247.   virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { }
  248.   virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { }
  249.  
  250.   // Control points ('handles') redirect control to the actual shape, to make it easier
  251.   // to override sizing behaviour.
  252.   virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
  253.   virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  254.   virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  255.  
  256.   virtual void MakeControlPoints();
  257.   virtual void DeleteControlPoints(wxDC *dc = NULL);
  258.   virtual void ResetControlPoints();
  259.  
  260.   inline wxShapeEvtHandler *GetEventHandler() { return m_eventHandler; }
  261.   inline void SetEventHandler(wxShapeEvtHandler *handler) { m_eventHandler = handler; }
  262.  
  263.   // Mandatory control points, e.g. the divided line moving handles
  264.   // should appear even if a child of the 'selected' image
  265.   virtual void MakeMandatoryControlPoints();
  266.   virtual void ResetMandatoryControlPoints();
  267.  
  268.   inline virtual bool Recompute() { return TRUE; };
  269.   // Calculate size recursively, if size changes. Size might depend on children.
  270.   inline virtual void CalculateSize() { };
  271.   virtual void Select(bool select = TRUE, wxDC* dc = NULL);
  272.   virtual void SetHighlight(bool hi = TRUE, bool recurse = FALSE);
  273.   inline virtual bool IsHighlighted() const { return m_highlighted; };
  274.   virtual bool Selected() const;
  275.   virtual bool AncestorSelected() const;
  276.   void SetSensitivityFilter(int sens = OP_ALL, bool recursive = FALSE);
  277.   int GetSensitivityFilter() const { return m_sensitivity; }
  278.   void SetDraggable(bool drag, bool recursive = FALSE);
  279.   inline  void SetFixedSize(bool x, bool y) { m_fixedWidth = x; m_fixedHeight = y; };
  280.   inline  void GetFixedSize(bool *x, bool *y) const { *x = m_fixedWidth; *y = m_fixedHeight; };
  281.   inline  bool GetFixedWidth() const { return m_fixedWidth; }
  282.   inline  bool GetFixedHeight() const { return m_fixedHeight; }
  283.   inline  void SetSpaceAttachments(bool sp) { m_spaceAttachments = sp; };
  284.   inline  bool GetSpaceAttachments() const { return m_spaceAttachments; };
  285.   void SetShadowMode(int mode, bool redraw = FALSE);
  286.   inline int GetShadowMode() const { return m_shadowMode; }
  287.   virtual bool HitTest(double x, double y, int *attachment, double *distance);
  288.   inline void SetCentreResize(bool cr) { m_centreResize = cr; }
  289.   inline bool GetCentreResize() const { return m_centreResize; }
  290.   inline void SetMaintainAspectRatio(bool ar) { m_maintainAspectRatio = ar; }
  291.   inline bool GetMaintainAspectRatio() const { return m_maintainAspectRatio; }
  292.   inline wxList& GetLines() const { return (wxList&) m_lines; }
  293.   inline void SetDisableLabel(bool flag) { m_disableLabel = flag; }
  294.   inline bool GetDisableLabel() const { return m_disableLabel; }
  295.   inline void SetAttachmentMode(int mode) { m_attachmentMode = mode; }
  296.   inline int GetAttachmentMode() const { return m_attachmentMode; }
  297.   inline void SetId(long i) { m_id = i; }
  298.   inline long GetId() const { return m_id; }
  299.  
  300.   void SetPen(wxPen *pen);
  301.   void SetBrush(wxBrush *brush);
  302.  
  303.   virtual void Show(bool show);
  304.   virtual bool IsShown() const { return m_visible; }
  305.   virtual void Move(wxDC& dc, double x1, double y1, bool display = TRUE);
  306.   virtual void Erase(wxDC& dc);
  307.   virtual void EraseContents(wxDC& dc);
  308.   virtual void Draw(wxDC& dc);
  309.   virtual void Flash();
  310.   virtual void MoveLinks(wxDC& dc);
  311.   virtual void DrawContents(wxDC& dc);  // E.g. for drawing text label
  312.   virtual void SetSize(double x, double y, bool recursive = TRUE);
  313.   virtual void SetAttachmentSize(double x, double y);
  314.   void Attach(wxShapeCanvas *can);
  315.   void Detach();
  316.  
  317.   inline virtual bool Constrain() { return FALSE; } ;
  318.  
  319.   void AddLine(wxLineShape *line, wxShape *other,
  320.                int attachFrom = 0, int attachTo = 0,
  321.                // The line ordering
  322.                int positionFrom = -1, int positionTo = -1);
  323.  
  324.   // Return the zero-based position in m_lines of line.
  325.   int GetLinePosition(wxLineShape* line);
  326.  
  327.   void AddText(const wxString& string);
  328.  
  329.   inline wxPen *GetPen() const { return m_pen; }
  330.   inline wxBrush *GetBrush() const { return m_brush; }
  331.  
  332.   /*
  333.    * Region-specific functions (defaults to the default region
  334.    * for simple objects
  335.    */
  336.  
  337.   // Set the default, single region size to be consistent
  338.   // with the object size
  339.   void SetDefaultRegionSize();
  340.   virtual void FormatText(wxDC& dc, const wxString& s, int regionId = 0);
  341.   virtual void SetFormatMode(int mode, int regionId = 0);
  342.   virtual int GetFormatMode(int regionId = 0) const;
  343.   virtual void SetFont(wxFont *font, int regionId = 0);
  344.   virtual wxFont *GetFont(int regionId = 0) const;
  345.   virtual void SetTextColour(const wxString& colour, int regionId = 0);
  346.   virtual wxString GetTextColour(int regionId = 0) const;
  347.   virtual inline int GetNumberOfTextRegions() const { return m_regions.Number(); }
  348.   virtual void SetRegionName(const wxString& name, int regionId = 0);
  349.  
  350.   // Get the name representing the region for this image alone.
  351.   // I.e. this image's region ids go from 0 to N-1.
  352.   // But the names might be "0.2.0", "0.2.1" etc. depending on position in composite.
  353.   // So the last digit represents the region Id, the others represent positions
  354.   // in composites.
  355.   virtual wxString GetRegionName(int regionId);
  356.  
  357.   // Gets the region corresponding to the name, or -1 if not found.
  358.   virtual int GetRegionId(const wxString& name);
  359.  
  360.   // Construct names for regions, unique even for children of a composite.
  361.   virtual void NameRegions(const wxString& parentName = "");
  362.  
  363.   // Get list of regions
  364.   inline wxList& GetRegions() const { return (wxList&) m_regions; }
  365.  
  366.   virtual void AddRegion(wxShapeRegion *region);
  367.  
  368.   virtual void ClearRegions();
  369.  
  370.   // Assign new ids to this image and children (if composite)
  371.   void AssignNewIds();
  372.  
  373.   // Returns actual image (same as 'this' if non-composite) and region id
  374.   // for given region name.
  375.   virtual wxShape *FindRegion(const wxString& regionName, int *regionId);
  376.  
  377.   // Finds all region names for this image (composite or simple).
  378.   // Supply empty string list.
  379.   virtual void FindRegionNames(wxStringList& list);
  380.  
  381.   virtual void ClearText(int regionId = 0);
  382.   void RemoveLine(wxLineShape *line);
  383.  
  384. #ifdef PROLOGIO
  385.   // I/O
  386.   virtual void WriteAttributes(wxExpr *clause);
  387.   virtual void ReadAttributes(wxExpr *clause);
  388.  
  389.   // In case the object has constraints it needs to read in in a different pass
  390.   inline virtual void ReadConstraints(wxExpr *WXUNUSED(clause), wxExprDatabase *WXUNUSED(database)) { };
  391.   virtual void WriteRegions(wxExpr *clause);
  392.   virtual void ReadRegions(wxExpr *clause);
  393. #endif
  394.  
  395.   // Attachment code
  396.   virtual bool GetAttachmentPosition(int attachment, double *x, double *y,
  397.                                      int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
  398.   virtual int GetNumberOfAttachments() const;
  399.   virtual bool AttachmentIsValid(int attachment) const;
  400.  
  401.   // Only get the attachment position at the _edge_ of the shape, ignoring
  402.   // branching mode. This is used e.g. to indicate the edge of interest, not the point
  403.   // on the attachment branch.
  404.   virtual bool GetAttachmentPositionEdge(int attachment, double *x, double *y,
  405.                                      int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
  406.  
  407.   // Assuming the attachment lies along a vertical or horizontal line,
  408.   // calculate the position on that point.
  409.   virtual wxRealPoint CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2,
  410.     int nth, int noArcs, wxLineShape* line);
  411.  
  412.   // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
  413.   // edge of the shape.
  414.   // attachmentPoint is the attachment point (= side) in question.
  415.   virtual bool AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2);
  416.  
  417.   virtual void EraseLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE);
  418.   virtual void DrawLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE);
  419.  
  420.   virtual bool MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
  421.                                        double x, double y);
  422.  
  423.   // Reorders the lines coming into the node image at this attachment
  424.   // position, in the order in which they appear in linesToSort.
  425.   virtual void SortLines(int attachment, wxList& linesToSort);
  426.  
  427.   // Apply an attachment ordering change
  428.   void ApplyAttachmentOrdering(wxList& ordering);
  429.  
  430.   // Can override this to prevent or intercept line reordering.
  431.   virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
  432.  
  433.   //// New banching attachment code, 24/9/98
  434.  
  435.   //
  436.   //             |________|
  437.   //                 | <- root
  438.   //                 | <- neck
  439.   // shoulder1 ->---------<- shoulder2
  440.   //             | | | | |<- stem
  441.   //                      <- branching attachment point N-1
  442.  
  443.   // This function gets the root point at the given attachment.
  444.   virtual wxRealPoint GetBranchingAttachmentRoot(int attachment);
  445.  
  446.   // This function gets information about where branching connections go (calls GetBranchingAttachmentRoot)
  447.   virtual bool GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
  448.     wxRealPoint& shoulder1, wxRealPoint& shoulder2);
  449.  
  450.   // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
  451.   // at this attachment point.
  452.   // attachmentPoint is where the arc meets the stem, and stemPoint is where the stem meets the
  453.   // shoulder.
  454.   virtual bool GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& attachmentPoint,
  455.     wxRealPoint& stemPoint);
  456.  
  457.   // Get the number of lines at this attachment position.
  458.   virtual int GetAttachmentLineCount(int attachment) const;
  459.  
  460.   // Draw the branches (not the actual arcs though)
  461.   virtual void OnDrawBranches(wxDC& dc, int attachment, bool erase = FALSE);
  462.   virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
  463.  
  464.   // Branching attachment settings
  465.   inline void SetBranchNeckLength(int len) { m_branchNeckLength = len; }
  466.   inline int GetBranchNeckLength() const { return m_branchNeckLength; }
  467.  
  468.   inline void SetBranchStemLength(int len) { m_branchStemLength = len; }
  469.   inline int GetBranchStemLength() const { return m_branchStemLength; }
  470.  
  471.   inline void SetBranchSpacing(int len) { m_branchSpacing = len; }
  472.   inline int GetBranchSpacing() const { return m_branchSpacing; }
  473.  
  474.   // Further detail on branching style, e.g. blobs on interconnections
  475.   inline void SetBranchStyle(long style) { m_branchStyle = style; }
  476.   inline long GetBranchStyle() const { return m_branchStyle; }
  477.  
  478.   // Rotate the standard attachment point from physical (0 is always North)
  479.   // to logical (0 -> 1 if rotated by 90 degrees)
  480.   virtual int PhysicalToLogicalAttachment(int physicalAttachment) const;
  481.  
  482.   // Rotate the standard attachment point from logical
  483.   // to physical (0 is always North)
  484.   virtual int LogicalToPhysicalAttachment(int logicalAttachment) const;
  485.  
  486.   // This is really to distinguish between lines and other images.
  487.   // For lines, want to pass drag to canvas, since lines tend to prevent
  488.   // dragging on a canvas (they get in the way.)
  489.   virtual bool Draggable() const { return TRUE; }
  490.  
  491.   // Returns TRUE if image is a descendant of this image
  492.   bool HasDescendant(wxShape *image);
  493.  
  494.   // Creates a copy of this shape.
  495.   wxShape *CreateNewCopy(bool resetMapping = TRUE, bool recompute = TRUE);
  496.  
  497.   // Does the copying for this object
  498.   virtual void Copy(wxShape& copy);
  499.  
  500.   // Does the copying for this object, including copying event
  501.   // handler data if any. Calls the virtual Copy function.
  502.   void CopyWithHandler(wxShape& copy);
  503.  
  504.   // Rotate about the given axis by the given amount in radians.
  505.   virtual void Rotate(double x, double y, double theta);
  506.   virtual inline double GetRotation() const { return m_rotation; }
  507.  
  508.   void ClearAttachments();
  509.  
  510.   // Recentres all the text regions for this object
  511.   void Recentre(wxDC& dc);
  512.  
  513.   // Clears points from a list of wxRealPoints
  514.   void ClearPointList(wxList& list);
  515.  
  516.   // Return pen or brush of the right colour for the background
  517.   wxPen GetBackgroundPen();
  518.   wxBrush GetBackgroundBrush();
  519.  
  520.  
  521.  protected:
  522.   wxShapeEvtHandler*    m_eventHandler;
  523.   bool                  m_formatted;
  524.   double                m_xpos, m_ypos;
  525.   wxPen*                m_pen;
  526.   wxBrush*              m_brush;
  527.   wxFont*               m_font;
  528.   wxColour*             m_textColour;
  529.   wxString              m_textColourName;
  530.   wxShapeCanvas*        m_canvas;
  531.   wxList                m_lines;
  532.   wxList                m_text;
  533.   wxList                m_controlPoints;
  534.   wxList                m_regions;
  535.   wxList                m_attachmentPoints;
  536.   bool                  m_visible;
  537.   bool                  m_disableLabel;
  538.   long                  m_id;
  539.   bool                  m_selected;
  540.   bool                  m_highlighted;      // Different from selected: user-defined highlighting,
  541.                                             // e.g. thick border.
  542.   double                m_rotation;
  543.   int                   m_sensitivity;
  544.   bool                  m_draggable;
  545.   int                   m_attachmentMode;   // 0 for no attachments, 1 if using normal attachments,
  546.                                             // 2 for branching attachments
  547.   bool                  m_spaceAttachments; // TRUE if lines at one side should be spaced
  548.   bool                  m_fixedWidth;
  549.   bool                  m_fixedHeight;
  550.   bool                  m_centreResize;    // Default is to resize keeping the centre constant (TRUE)
  551.   bool                  m_drawHandles;     // Don't draw handles if FALSE, usually TRUE
  552.   wxList                m_children;      // In case it's composite
  553.   wxShape*              m_parent;      // In case it's a child
  554.   int                   m_formatMode;
  555.   int                   m_shadowMode;
  556.   wxBrush*              m_shadowBrush;
  557.   int                   m_shadowOffsetX;
  558.   int                   m_shadowOffsetY;
  559.   int                   m_textMarginX;    // Gap between text and border
  560.   int                   m_textMarginY;
  561.   wxString              m_regionName;
  562.   bool                  m_maintainAspectRatio;
  563.   int                   m_branchNeckLength;
  564.   int                   m_branchStemLength;
  565.   int                   m_branchSpacing;
  566.   long                  m_branchStyle;
  567. };
  568.  
  569. class wxPolygonShape: public wxShape
  570. {
  571.  DECLARE_DYNAMIC_CLASS(wxPolygonShape)
  572.  public:
  573.   wxPolygonShape();
  574.   ~wxPolygonShape();
  575.  
  576.   // Takes a list of wxRealPoints; each point is an OFFSET from the centre.
  577.   // Deletes user's points in destructor.
  578.   virtual void Create(wxList *points);
  579.   virtual void ClearPoints();
  580.  
  581.   void GetBoundingBoxMin(double *w, double *h);
  582.   void CalculateBoundingBox();
  583.   bool GetPerimeterPoint(double x1, double y1,
  584.                                  double x2, double y2,
  585.                                  double *x3, double *y3);
  586.   bool HitTest(double x, double y, int *attachment, double *distance);
  587.   void SetSize(double x, double y, bool recursive = TRUE);
  588.   void OnDraw(wxDC& dc);
  589.   void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
  590.  
  591.   // Control points ('handles') redirect control to the actual shape, to make it easier
  592.   // to override sizing behaviour.
  593.   virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0);
  594.   virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  595.   virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
  596.  
  597.   // A polygon should have a control point at each vertex,
  598.   // with the option of moving the control points individually
  599.   // to change the shape.
  600.   void MakeControlPoints();
  601.   void ResetControlPoints();
  602.  
  603.   // If we've changed the shape, must make the original
  604.   // points match the working points
  605.   void UpdateOriginalPoints();
  606.  
  607.   // Add a control point after the given point
  608.   virtual void AddPolygonPoint(int pos = 0);
  609.  
  610.   // Delete a control point
  611.   virtual void DeletePolygonPoint(int pos = 0);
  612.  
  613.   // Recalculates the centre of the polygon
  614.   virtual void CalculatePolygonCentre();
  615.  
  616. #ifdef PROLOGIO
  617.   void WriteAttributes(wxExpr *clause);
  618.   void ReadAttributes(wxExpr *clause);
  619. #endif
  620.  
  621.   int GetNumberOfAttachments() const;
  622.   bool GetAttachmentPosition(int attachment, double *x, double *y,
  623.                                      int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
  624.   bool AttachmentIsValid(int attachment);
  625.   // Does the copying for this object
  626.   void Copy(wxShape& copy);
  627.  
  628.   inline wxList *GetPoints() { return m_points; }
  629.  
  630.   // Rotate about the given axis by the given amount in radians
  631.   virtual void Rotate(double x, double y, double theta);
  632.  
  633.  private:
  634.   wxList*       m_points;
  635.   wxList*       m_originalPoints;
  636.   double        m_boundWidth;
  637.   double        m_boundHeight;
  638.   double        m_originalWidth;
  639.   double        m_originalHeight;
  640. };
  641.  
  642. class wxRectangleShape: public wxShape
  643. {
  644.  DECLARE_DYNAMIC_CLASS(wxRectangleShape)
  645.  public:
  646.   wxRectangleShape(double w = 0.0, double h = 0.0);
  647.   void GetBoundingBoxMin(double *w, double *h);
  648.   bool GetPerimeterPoint(double x1, double y1,
  649.                                  double x2, double y2,
  650.                                  double *x3, double *y3);
  651.   void OnDraw(wxDC& dc);
  652.   void SetSize(double x, double y, bool recursive = TRUE);
  653.   void SetCornerRadius(double rad); // If > 0, rounded corners
  654.  
  655. #ifdef PROLOGIO
  656.   void WriteAttributes(wxExpr *clause);
  657.   void ReadAttributes(wxExpr *clause);
  658. #endif
  659.  
  660.   int GetNumberOfAttachments() const;
  661.   bool GetAttachmentPosition(int attachment, double *x, double *y,
  662.                                      int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
  663.   // Does the copying for this object
  664.   void Copy(wxShape& copy);
  665.  
  666.   inline double GetWidth() const { return m_width; }
  667.   inline double GetHeight() const { return m_height; }
  668.   inline void SetWidth(double w) { m_width = w; }
  669.   inline void SetHeight(double h) { m_height = h; }
  670.  
  671. protected:
  672.   double m_width;
  673.   double m_height;
  674.   double m_cornerRadius;
  675. };
  676.  
  677. class wxTextShape: public wxRectangleShape
  678. {
  679.  DECLARE_DYNAMIC_CLASS(wxTextShape)
  680.  public:
  681.   wxTextShape(double width = 0.0, double height = 0.0);
  682.  
  683.   void OnDraw(wxDC& dc);
  684.  
  685. #ifdef PROLOGIO
  686.   void WriteAttributes(wxExpr *clause);
  687. #endif
  688.  
  689.   // Does the copying for this object
  690.   void Copy(wxShape& copy);
  691. };
  692.  
  693. class wxEllipseShape: public wxShape
  694. {
  695.  DECLARE_DYNAMIC_CLASS(wxEllipseShape)
  696.  public:
  697.   wxEllipseShape(double w = 0.0, double h = 0.0);
  698.  
  699.   void GetBoundingBoxMin(double *w, double *h);
  700.   bool GetPerimeterPoint(double x1, double y1,
  701.                                  double x2, double y2,
  702.                                  double *x3, double *y3);
  703.  
  704.   void OnDraw(wxDC& dc);
  705.   void SetSize(double x, double y, bool recursive = TRUE);
  706.  
  707. #ifdef PROLOGIO
  708.   void WriteAttributes(wxExpr *clause);
  709.   void ReadAttributes(wxExpr *clause);
  710. #endif
  711.  
  712.   int GetNumberOfAttachments() const;
  713.   bool GetAttachmentPosition(int attachment, double *x, double *y,
  714.                                      int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
  715.  
  716.   // Does the copying for this object
  717.   void Copy(wxShape& copy);
  718.  
  719.   inline double GetWidth() const { return m_width; }
  720.   inline double GetHeight() const { return m_height; }
  721.  
  722.   inline void SetWidth(double w) { m_width = w; }
  723.   inline void SetHeight(double h) { m_height = h; }
  724.  
  725. protected:
  726.   double m_width;
  727.   double m_height;
  728. };
  729.  
  730. class wxCircleShape: public wxEllipseShape
  731. {
  732.  DECLARE_DYNAMIC_CLASS(wxCircleShape)
  733.  public:
  734.   wxCircleShape(double w = 0.0);
  735.  
  736.   bool GetPerimeterPoint(double x1, double y1,
  737.                                  double x2, double y2,
  738.                                  double *x3, double *y3);
  739.   // Does the copying for this object
  740.   void Copy(wxShape& copy);
  741. };
  742.  
  743. #endif
  744.  // _OGL_BASIC_H_
  745.