1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Basic OGL classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "basic.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include <wx/deprecated/wxexpr.h>
39 #include "wx/ogl/ogl.h"
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
49 #define CONTROL_POINT_ENDPOINT_TO 4
50 #define CONTROL_POINT_ENDPOINT_FROM 5
51 #define CONTROL_POINT_LINE 6
53 IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine
, wxObject
)
54 IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint
, wxObject
)
56 wxShapeTextLine::wxShapeTextLine(double the_x
, double the_y
, const wxString
& the_line
)
58 m_x
= the_x
; m_y
= the_y
; m_line
= the_line
;
61 wxShapeTextLine::~wxShapeTextLine()
65 IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler
, wxObject
)
67 wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler
*prev
, wxShape
*shape
)
69 m_previousHandler
= prev
;
70 m_handlerShape
= shape
;
73 wxShapeEvtHandler::~wxShapeEvtHandler()
77 // Creates a copy of this event handler.
78 wxShapeEvtHandler
* wxShapeEvtHandler::CreateNewCopy()
80 wxShapeEvtHandler
* newObject
= (wxShapeEvtHandler
*) GetClassInfo()->CreateObject();
82 wxASSERT( (newObject
!= NULL
) );
83 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShapeEvtHandler
))) );
85 newObject
->m_previousHandler
= newObject
;
93 void wxShapeEvtHandler::OnDelete()
95 if (this != GetShape())
99 void wxShapeEvtHandler::OnDraw(wxDC
& dc
)
101 if (m_previousHandler
)
102 m_previousHandler
->OnDraw(dc
);
105 void wxShapeEvtHandler::OnMoveLinks(wxDC
& dc
)
107 if (m_previousHandler
)
108 m_previousHandler
->OnMoveLinks(dc
);
111 void wxShapeEvtHandler::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
113 if (m_previousHandler
)
114 m_previousHandler
->OnMoveLink(dc
, moveControlPoints
);
117 void wxShapeEvtHandler::OnDrawContents(wxDC
& dc
)
119 if (m_previousHandler
)
120 m_previousHandler
->OnDrawContents(dc
);
123 void wxShapeEvtHandler::OnDrawBranches(wxDC
& dc
, bool erase
)
125 if (m_previousHandler
)
126 m_previousHandler
->OnDrawBranches(dc
, erase
);
129 void wxShapeEvtHandler::OnSize(double x
, double y
)
131 if (m_previousHandler
)
132 m_previousHandler
->OnSize(x
, y
);
135 bool wxShapeEvtHandler::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
137 if (m_previousHandler
)
138 return m_previousHandler
->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
);
143 void wxShapeEvtHandler::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
145 if (m_previousHandler
)
146 m_previousHandler
->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
149 void wxShapeEvtHandler::OnErase(wxDC
& dc
)
151 if (m_previousHandler
)
152 m_previousHandler
->OnErase(dc
);
155 void wxShapeEvtHandler::OnEraseContents(wxDC
& dc
)
157 if (m_previousHandler
)
158 m_previousHandler
->OnEraseContents(dc
);
161 void wxShapeEvtHandler::OnHighlight(wxDC
& dc
)
163 if (m_previousHandler
)
164 m_previousHandler
->OnHighlight(dc
);
167 void wxShapeEvtHandler::OnLeftClick(double x
, double y
, int keys
, int attachment
)
169 if (m_previousHandler
)
170 m_previousHandler
->OnLeftClick(x
, y
, keys
, attachment
);
173 void wxShapeEvtHandler::OnLeftDoubleClick(double x
, double y
, int keys
, int attachment
)
175 if (m_previousHandler
)
176 m_previousHandler
->OnLeftDoubleClick(x
, y
, keys
, attachment
);
179 void wxShapeEvtHandler::OnRightClick(double x
, double y
, int keys
, int attachment
)
181 if (m_previousHandler
)
182 m_previousHandler
->OnRightClick(x
, y
, keys
, attachment
);
185 void wxShapeEvtHandler::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
187 if (m_previousHandler
)
188 m_previousHandler
->OnDragLeft(draw
, x
, y
, keys
, attachment
);
191 void wxShapeEvtHandler::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
193 if (m_previousHandler
)
194 m_previousHandler
->OnBeginDragLeft(x
, y
, keys
, attachment
);
197 void wxShapeEvtHandler::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
199 if (m_previousHandler
)
200 m_previousHandler
->OnEndDragLeft(x
, y
, keys
, attachment
);
203 void wxShapeEvtHandler::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
205 if (m_previousHandler
)
206 m_previousHandler
->OnDragRight(draw
, x
, y
, keys
, attachment
);
209 void wxShapeEvtHandler::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
211 if (m_previousHandler
)
212 m_previousHandler
->OnBeginDragRight(x
, y
, keys
, attachment
);
215 void wxShapeEvtHandler::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
217 if (m_previousHandler
)
218 m_previousHandler
->OnEndDragRight(x
, y
, keys
, attachment
);
221 // Control points ('handles') redirect control to the actual shape, to make it easier
222 // to override sizing behaviour.
223 void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
225 if (m_previousHandler
)
226 m_previousHandler
->OnSizingDragLeft(pt
, draw
, x
, y
, keys
, attachment
);
229 void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
231 if (m_previousHandler
)
232 m_previousHandler
->OnSizingBeginDragLeft(pt
, x
, y
, keys
, attachment
);
235 void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
237 if (m_previousHandler
)
238 m_previousHandler
->OnSizingEndDragLeft(pt
, x
, y
, keys
, attachment
);
241 void wxShapeEvtHandler::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
243 if (m_previousHandler
)
244 m_previousHandler
->OnDrawOutline(dc
, x
, y
, w
, h
);
247 void wxShapeEvtHandler::OnDrawControlPoints(wxDC
& dc
)
249 if (m_previousHandler
)
250 m_previousHandler
->OnDrawControlPoints(dc
);
253 void wxShapeEvtHandler::OnEraseControlPoints(wxDC
& dc
)
255 if (m_previousHandler
)
256 m_previousHandler
->OnEraseControlPoints(dc
);
259 // Can override this to prevent or intercept line reordering.
260 void wxShapeEvtHandler::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
262 if (m_previousHandler
)
263 m_previousHandler
->OnChangeAttachment(attachment
, line
, ordering
);
266 IMPLEMENT_ABSTRACT_CLASS(wxShape
, wxShapeEvtHandler
)
268 wxShape::wxShape(wxShapeCanvas
*can
)
270 m_eventHandler
= this;
275 m_xpos
= 0.0; m_ypos
= 0.0;
276 m_pen
= g_oglBlackPen
;
277 m_brush
= wxWHITE_BRUSH
;
278 m_font
= g_oglNormalFont
;
279 m_textColour
= wxT("BLACK");
280 m_textColourName
= wxT("BLACK");
283 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
284 m_spaceAttachments
= TRUE
;
285 m_disableLabel
= FALSE
;
286 m_fixedWidth
= FALSE
;
287 m_fixedHeight
= FALSE
;
288 m_drawHandles
= TRUE
;
289 m_sensitivity
= OP_ALL
;
292 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
293 m_shadowMode
= SHADOW_NONE
;
296 m_shadowBrush
= wxBLACK_BRUSH
;
299 m_regionName
= wxT("0");
300 m_centreResize
= TRUE
;
301 m_maintainAspectRatio
= FALSE
;
302 m_highlighted
= FALSE
;
304 m_branchNeckLength
= 10;
305 m_branchStemLength
= 10;
306 m_branchSpacing
= 10;
307 m_branchStyle
= BRANCHING_ATTACHMENT_NORMAL
;
309 // Set up a default region. Much of the above will be put into
310 // the region eventually (the duplication is for compatibility)
311 wxShapeRegion
*region
= new wxShapeRegion
;
312 m_regions
.Append(region
);
313 region
->SetName(wxT("0"));
314 region
->SetFont(g_oglNormalFont
);
315 region
->SetFormatMode(FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
);
316 region
->SetColour(wxT("BLACK"));
322 m_parent
->GetChildren().DeleteObject(this);
329 m_canvas
->RemoveShape(this);
331 GetEventHandler()->OnDelete();
334 void wxShape::SetHighlight(bool hi
, bool recurse
)
339 wxNode
*node
= m_children
.GetFirst();
342 wxShape
*child
= (wxShape
*)node
->GetData();
343 child
->SetHighlight(hi
, recurse
);
344 node
= node
->GetNext();
349 void wxShape::SetSensitivityFilter(int sens
, bool recursive
)
351 if (sens
& OP_DRAG_LEFT
)
356 m_sensitivity
= sens
;
359 wxNode
*node
= m_children
.GetFirst();
362 wxShape
*obj
= (wxShape
*)node
->GetData();
363 obj
->SetSensitivityFilter(sens
, TRUE
);
364 node
= node
->GetNext();
369 void wxShape::SetDraggable(bool drag
, bool recursive
)
373 m_sensitivity
|= OP_DRAG_LEFT
;
375 if (m_sensitivity
& OP_DRAG_LEFT
)
376 m_sensitivity
= m_sensitivity
- OP_DRAG_LEFT
;
380 wxNode
*node
= m_children
.GetFirst();
383 wxShape
*obj
= (wxShape
*)node
->GetData();
384 obj
->SetDraggable(drag
, TRUE
);
385 node
= node
->GetNext();
390 void wxShape::SetDrawHandles(bool drawH
)
392 m_drawHandles
= drawH
;
393 wxNode
*node
= m_children
.GetFirst();
396 wxShape
*obj
= (wxShape
*)node
->GetData();
397 obj
->SetDrawHandles(drawH
);
398 node
= node
->GetNext();
402 void wxShape::SetShadowMode(int mode
, bool redraw
)
404 if (redraw
&& GetCanvas())
406 wxClientDC
dc(GetCanvas());
407 GetCanvas()->PrepareDC(dc
);
420 void wxShape::SetCanvas(wxShapeCanvas
*theCanvas
)
422 m_canvas
= theCanvas
;
423 wxNode
*node
= m_children
.GetFirst();
426 wxShape
*child
= (wxShape
*)node
->GetData();
427 child
->SetCanvas(theCanvas
);
428 node
= node
->GetNext();
432 void wxShape::AddToCanvas(wxShapeCanvas
*theCanvas
, wxShape
*addAfter
)
434 theCanvas
->AddShape(this, addAfter
);
435 wxNode
*node
= m_children
.GetFirst();
436 wxShape
*lastImage
= this;
439 wxShape
*object
= (wxShape
*)node
->GetData();
440 object
->AddToCanvas(theCanvas
, lastImage
);
443 node
= node
->GetNext();
447 // Insert at front of canvas
448 void wxShape::InsertInCanvas(wxShapeCanvas
*theCanvas
)
450 theCanvas
->InsertShape(this);
451 wxNode
*node
= m_children
.GetFirst();
452 wxShape
*lastImage
= this;
455 wxShape
*object
= (wxShape
*)node
->GetData();
456 object
->AddToCanvas(theCanvas
, lastImage
);
459 node
= node
->GetNext();
463 void wxShape::RemoveFromCanvas(wxShapeCanvas
*theCanvas
)
467 theCanvas
->RemoveShape(this);
468 wxNode
*node
= m_children
.GetFirst();
471 wxShape
*object
= (wxShape
*)node
->GetData();
472 object
->RemoveFromCanvas(theCanvas
);
474 node
= node
->GetNext();
478 void wxShape::ClearAttachments()
480 wxNode
*node
= m_attachmentPoints
.GetFirst();
483 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
485 node
= node
->GetNext();
487 m_attachmentPoints
.Clear();
490 void wxShape::ClearText(int regionId
)
494 m_text
.DeleteContents(TRUE
);
496 m_text
.DeleteContents(FALSE
);
498 wxNode
*node
= m_regions
.Item(regionId
);
501 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
505 void wxShape::ClearRegions()
507 wxNode
*node
= m_regions
.GetFirst();
510 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
511 wxNode
*next
= node
->GetNext();
518 void wxShape::AddRegion(wxShapeRegion
*region
)
520 m_regions
.Append(region
);
523 void wxShape::SetDefaultRegionSize()
525 wxNode
*node
= m_regions
.GetFirst();
527 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
529 GetBoundingBoxMin(&w
, &h
);
530 region
->SetSize(w
, h
);
533 bool wxShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
538 double width
= 0.0, height
= 0.0;
539 GetBoundingBoxMin(&width
, &height
);
540 if (fabs(width
) < 4.0) width
= 4.0;
541 if (fabs(height
) < 4.0) height
= 4.0;
543 width
+= (double)4.0; height
+= (double)4.0; // Allowance for inaccurate mousing
545 double left
= (double)(m_xpos
- (width
/2.0));
546 double top
= (double)(m_ypos
- (height
/2.0));
547 double right
= (double)(m_xpos
+ (width
/2.0));
548 double bottom
= (double)(m_ypos
+ (height
/2.0));
550 int nearest_attachment
= 0;
552 // If within the bounding box, check the attachment points
553 // within the object.
555 if (x
>= left
&& x
<= right
&& y
>= top
&& y
<= bottom
)
557 int n
= GetNumberOfAttachments();
558 double nearest
= 999999.0;
560 // GetAttachmentPosition[Edge] takes a logical attachment position,
561 // i.e. if it's rotated through 90%, position 0 is East-facing.
563 for (int i
= 0; i
< n
; i
++)
566 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
568 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
569 ((yp
- y
) * (yp
- y
)));
574 nearest_attachment
= i
;
578 *attachment
= nearest_attachment
;
585 // Format a text string according to the region size, adding
586 // strings with positions to region text list
588 static bool GraphicsInSizeToContents
= FALSE
; // Infinite recursion elimination
589 void wxShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
594 if (m_regions
.GetCount() < 1)
596 wxNode
*node
= m_regions
.Item(i
);
600 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
601 // region->SetText(s); // don't set the formatted text yet, it will be done below
602 region
->m_regionText
= s
;
603 dc
.SetFont(* region
->GetFont());
605 region
->GetSize(&w
, &h
);
607 wxStringList
*stringList
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
608 node
= (wxNode
*)stringList
->GetFirst();
611 wxChar
*s
= (wxChar
*)node
->GetData();
612 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
613 region
->GetFormattedText().Append((wxObject
*)line
);
614 node
= node
->GetNext();
619 // Don't try to resize an object with more than one image (this case should be dealt
620 // with by overriden handlers)
621 if ((region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
) &&
622 (region
->GetFormattedText().GetCount() > 0) &&
623 (m_regions
.GetCount() == 1) && !GraphicsInSizeToContents
)
625 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
626 if ((actualW
+m_textMarginX
!= w
) || (actualH
+m_textMarginY
!= h
))
628 // If we are a descendant of a composite, must make sure the composite gets
630 wxShape
*topAncestor
= GetTopAncestor();
632 if (topAncestor
!= this)
634 // Make sure we don't recurse infinitely
635 GraphicsInSizeToContents
= TRUE
;
637 wxCompositeShape
*composite
= (wxCompositeShape
*)topAncestor
;
638 composite
->Erase(dc
);
639 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
640 Move(dc
, m_xpos
, m_ypos
);
641 composite
->CalculateSize();
642 if (composite
->Selected())
644 composite
->DeleteControlPoints(& dc
);
645 composite
->MakeControlPoints();
646 composite
->MakeMandatoryControlPoints();
648 // Where infinite recursion might happen if we didn't stop it
651 GraphicsInSizeToContents
= FALSE
;
656 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
657 Move(dc
, m_xpos
, m_ypos
);
659 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
660 Move(dc
, m_xpos
, m_ypos
);
664 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
668 void wxShape::Recentre(wxDC
& dc
)
671 GetBoundingBoxMin(&w
, &h
);
673 int noRegions
= m_regions
.GetCount();
674 for (int i
= 0; i
< noRegions
; i
++)
676 wxNode
*node
= m_regions
.Item(i
);
679 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
680 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, region
->GetFormatMode());
685 bool wxShape::GetPerimeterPoint(double WXUNUSED(x1
), double WXUNUSED(y1
),
686 double WXUNUSED(x2
), double WXUNUSED(y2
),
687 double *WXUNUSED(x3
), double *WXUNUSED(y3
))
692 void wxShape::SetPen(wxPen
*the_pen
)
697 void wxShape::SetBrush(wxBrush
*the_brush
)
702 // Get the top-most (non-division) ancestor, or self
703 wxShape
*wxShape::GetTopAncestor()
708 if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape
)))
710 else return GetParent()->GetTopAncestor();
717 void wxShape::SetFont(wxFont
*the_font
, int regionId
)
720 wxNode
*node
= m_regions
.Item(regionId
);
723 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
724 region
->SetFont(the_font
);
727 wxFont
*wxShape::GetFont(int n
) const
729 wxNode
*node
= m_regions
.Item(n
);
732 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
733 return region
->GetFont();
736 void wxShape::SetFormatMode(int mode
, int regionId
)
738 wxNode
*node
= m_regions
.Item(regionId
);
741 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
742 region
->SetFormatMode(mode
);
745 int wxShape::GetFormatMode(int regionId
) const
747 wxNode
*node
= m_regions
.Item(regionId
);
750 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
751 return region
->GetFormatMode();
754 void wxShape::SetTextColour(const wxString
& the_colour
, int regionId
)
756 m_textColour
= wxTheColourDatabase
->Find(the_colour
);
757 m_textColourName
= the_colour
;
759 wxNode
*node
= m_regions
.Item(regionId
);
762 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
763 region
->SetColour(the_colour
);
766 wxString
wxShape::GetTextColour(int regionId
) const
768 wxNode
*node
= m_regions
.Item(regionId
);
770 return wxEmptyString
;
771 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
772 return region
->GetColour();
775 void wxShape::SetRegionName(const wxString
& name
, int regionId
)
777 wxNode
*node
= m_regions
.Item(regionId
);
780 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
781 region
->SetName(name
);
784 wxString
wxShape::GetRegionName(int regionId
)
786 wxNode
*node
= m_regions
.Item(regionId
);
788 return wxEmptyString
;
789 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
790 return region
->GetName();
793 int wxShape::GetRegionId(const wxString
& name
)
795 wxNode
*node
= m_regions
.GetFirst();
799 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
800 if (region
->GetName() == name
)
802 node
= node
->GetNext();
808 // Name all m_regions in all subimages recursively.
809 void wxShape::NameRegions(const wxString
& parentName
)
811 int n
= GetNumberOfTextRegions();
813 for (int i
= 0; i
< n
; i
++)
815 if (parentName
.Length() > 0)
816 buff
<< parentName
<< wxT(".") << i
;
819 SetRegionName(buff
, i
);
821 wxNode
*node
= m_children
.GetFirst();
826 wxShape
*child
= (wxShape
*)node
->GetData();
827 if (parentName
.Length() > 0)
828 buff
<< parentName
<< wxT(".") << j
;
831 child
->NameRegions(buff
);
832 node
= node
->GetNext();
837 // Get a region by name, possibly looking recursively into composites.
838 wxShape
*wxShape::FindRegion(const wxString
& name
, int *regionId
)
840 int id
= GetRegionId(name
);
847 wxNode
*node
= m_children
.GetFirst();
850 wxShape
*child
= (wxShape
*)node
->GetData();
851 wxShape
*actualImage
= child
->FindRegion(name
, regionId
);
854 node
= node
->GetNext();
859 // Finds all region names for this image (composite or simple).
860 // Supply empty string list.
861 void wxShape::FindRegionNames(wxStringList
& list
)
863 int n
= GetNumberOfTextRegions();
864 for (int i
= 0; i
< n
; i
++)
866 wxString
name(GetRegionName(i
));
870 wxNode
*node
= m_children
.GetFirst();
873 wxShape
*child
= (wxShape
*)node
->GetData();
874 child
->FindRegionNames(list
);
875 node
= node
->GetNext();
879 void wxShape::AssignNewIds()
883 wxNode
*node
= m_children
.GetFirst();
886 wxShape
*child
= (wxShape
*)node
->GetData();
887 child
->AssignNewIds();
888 node
= node
->GetNext();
892 void wxShape::OnDraw(wxDC
& WXUNUSED(dc
))
896 void wxShape::OnMoveLinks(wxDC
& dc
)
898 // Want to set the ends of all attached links
899 // to point to/from this object
901 wxNode
*current
= m_lines
.GetFirst();
904 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
905 line
->GetEventHandler()->OnMoveLink(dc
);
906 current
= current
->GetNext();
911 void wxShape::OnDrawContents(wxDC
& dc
)
913 double bound_x
, bound_y
;
914 GetBoundingBoxMin(&bound_x
, &bound_y
);
915 if (m_regions
.GetCount() < 1) return;
917 if (m_pen
) dc
.SetPen(* m_pen
);
919 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.GetFirst()->GetData();
920 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
922 dc
.SetTextForeground(region
->GetActualColourObject());
923 dc
.SetBackgroundMode(wxTRANSPARENT
);
926 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
929 if (!GetDisableLabel())
931 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
935 void wxShape::DrawContents(wxDC
& dc
)
937 GetEventHandler()->OnDrawContents(dc
);
940 void wxShape::OnSize(double WXUNUSED(x
), double WXUNUSED(y
))
944 bool wxShape::OnMovePre(wxDC
& WXUNUSED(dc
), double WXUNUSED(x
), double WXUNUSED(y
), double WXUNUSED(old_x
), double WXUNUSED(old_y
), bool WXUNUSED(display
))
949 void wxShape::OnMovePost(wxDC
& WXUNUSED(dc
), double WXUNUSED(x
), double WXUNUSED(y
), double WXUNUSED(old_x
), double WXUNUSED(old_y
), bool WXUNUSED(display
))
953 void wxShape::OnErase(wxDC
& dc
)
959 wxNode
*current
= m_lines
.GetFirst();
962 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
963 line
->GetEventHandler()->OnErase(dc
);
964 current
= current
->GetNext();
966 GetEventHandler()->OnEraseContents(dc
);
969 void wxShape::OnEraseContents(wxDC
& dc
)
974 double maxX
, maxY
, minX
, minY
;
977 GetBoundingBoxMin(&minX
, &minY
);
978 GetBoundingBoxMax(&maxX
, &maxY
);
979 double topLeftX
= (double)(xp
- (maxX
/ 2.0) - 2.0);
980 double topLeftY
= (double)(yp
- (maxY
/ 2.0) - 2.0);
984 penWidth
= m_pen
->GetWidth();
986 dc
.SetPen(GetBackgroundPen());
987 dc
.SetBrush(GetBackgroundBrush());
989 dc
.DrawRectangle(WXROUND(topLeftX
- penWidth
), WXROUND(topLeftY
- penWidth
),
990 WXROUND(maxX
+ penWidth
*2.0 + 4.0), WXROUND(maxY
+ penWidth
*2.0 + 4.0));
993 void wxShape::EraseLinks(wxDC
& dc
, int attachment
, bool recurse
)
998 wxNode
*current
= m_lines
.GetFirst();
1001 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1002 if (attachment
== -1 || ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1003 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
)))
1004 line
->GetEventHandler()->OnErase(dc
);
1005 current
= current
->GetNext();
1009 wxNode
*node
= m_children
.GetFirst();
1012 wxShape
*child
= (wxShape
*)node
->GetData();
1013 child
->EraseLinks(dc
, attachment
, recurse
);
1014 node
= node
->GetNext();
1019 void wxShape::DrawLinks(wxDC
& dc
, int attachment
, bool recurse
)
1024 wxNode
*current
= m_lines
.GetFirst();
1027 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1028 if (attachment
== -1 ||
1029 (line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1030 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1032 current
= current
->GetNext();
1036 wxNode
*node
= m_children
.GetFirst();
1039 wxShape
*child
= (wxShape
*)node
->GetData();
1040 child
->DrawLinks(dc
, attachment
, recurse
);
1041 node
= node
->GetNext();
1046 // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
1047 // edge of the shape.
1048 // attachmentPoint is the attachment point (= side) in question.
1050 // This is the default, rectangular implementation.
1051 bool wxShape::AttachmentSortTest(int attachmentPoint
, const wxRealPoint
& pt1
, const wxRealPoint
& pt2
)
1053 int physicalAttachment
= LogicalToPhysicalAttachment(attachmentPoint
);
1054 switch (physicalAttachment
)
1059 return (pt1
.x
<= pt2
.x
) ;
1064 return (pt1
.y
<= pt2
.y
) ;
1071 bool wxShape::MoveLineToNewAttachment(wxDC
& dc
, wxLineShape
*to_move
,
1074 if (GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1077 int newAttachment
, oldAttachment
;
1080 // Is (x, y) on this object? If so, find the new attachment point
1081 // the user has moved the point to
1082 bool hit
= HitTest(x
, y
, &newAttachment
, &distance
);
1088 if (to_move
->GetTo() == this)
1089 oldAttachment
= to_move
->GetAttachmentTo();
1091 oldAttachment
= to_move
->GetAttachmentFrom();
1093 // The links in a new ordering.
1096 // First, add all links to the new list.
1097 wxNode
*node
= m_lines
.GetFirst();
1100 newOrdering
.Append(node
->GetData());
1101 node
= node
->GetNext();
1104 // Delete the line object from the list of links; we're going to move
1105 // it to another position in the list
1106 newOrdering
.DeleteObject(to_move
);
1108 double old_x
= (double) -99999.9;
1109 double old_y
= (double) -99999.9;
1111 node
= newOrdering
.GetFirst();
1114 while (!found
&& node
)
1116 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1117 if ((line
->GetTo() == this && oldAttachment
== line
->GetAttachmentTo()) ||
1118 (line
->GetFrom() == this && oldAttachment
== line
->GetAttachmentFrom()))
1120 double startX
, startY
, endX
, endY
;
1122 line
->GetEnds(&startX
, &startY
, &endX
, &endY
);
1123 if (line
->GetTo() == this)
1133 wxRealPoint
thisPoint(xp
, yp
);
1134 wxRealPoint
lastPoint(old_x
, old_y
);
1135 wxRealPoint
newPoint(x
, y
);
1137 if (AttachmentSortTest(newAttachment
, newPoint
, thisPoint
) && AttachmentSortTest(newAttachment
, lastPoint
, newPoint
))
1140 newOrdering
.Insert(node
, to_move
);
1146 node
= node
->GetNext();
1150 newOrdering
.Append(to_move
);
1152 GetEventHandler()->OnChangeAttachment(newAttachment
, to_move
, newOrdering
);
1157 void wxShape::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
1159 if (line
->GetTo() == this)
1160 line
->SetAttachmentTo(attachment
);
1162 line
->SetAttachmentFrom(attachment
);
1164 ApplyAttachmentOrdering(ordering
);
1166 wxClientDC
dc(GetCanvas());
1167 GetCanvas()->PrepareDC(dc
);
1171 if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc
);
1174 // Reorders the lines according to the given list.
1175 void wxShape::ApplyAttachmentOrdering(wxList
& linesToSort
)
1177 // This is a temporary store of all the lines.
1180 wxNode
*node
= m_lines
.GetFirst();
1183 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1184 linesStore
.Append(line
);
1185 node
= node
->GetNext();;
1190 node
= linesToSort
.GetFirst();
1193 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1194 if (linesStore
.Member(line
))
1197 linesStore
.DeleteObject(line
);
1198 m_lines
.Append(line
);
1200 node
= node
->GetNext();
1203 // Now add any lines that haven't been listed in linesToSort.
1204 node
= linesStore
.GetFirst();
1207 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1208 m_lines
.Append(line
);
1209 node
= node
->GetNext();
1213 // Reorders the lines coming into the node image at this attachment
1214 // position, in the order in which they appear in linesToSort.
1215 // Any remaining lines not in the list will be added to the end.
1216 void wxShape::SortLines(int attachment
, wxList
& linesToSort
)
1218 // This is a temporary store of all the lines at this attachment
1219 // point. We'll tick them off as we've processed them.
1220 wxList linesAtThisAttachment
;
1222 wxNode
*node
= m_lines
.GetFirst();
1225 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1226 wxNode
*next
= node
->GetNext();
1227 if ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1228 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1230 linesAtThisAttachment
.Append(line
);
1234 else node
= node
->GetNext();
1237 node
= linesToSort
.GetFirst();
1240 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1241 if (linesAtThisAttachment
.Member(line
))
1244 linesAtThisAttachment
.DeleteObject(line
);
1245 m_lines
.Append(line
);
1247 node
= node
->GetNext();
1250 // Now add any lines that haven't been listed in linesToSort.
1251 node
= linesAtThisAttachment
.GetFirst();
1254 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1255 m_lines
.Append(line
);
1256 node
= node
->GetNext();
1260 void wxShape::OnHighlight(wxDC
& WXUNUSED(dc
))
1264 void wxShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
1266 if ((m_sensitivity
& OP_CLICK_LEFT
) != OP_CLICK_LEFT
)
1272 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1273 m_parent
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
1279 void wxShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
1281 if ((m_sensitivity
& OP_CLICK_RIGHT
) != OP_CLICK_RIGHT
)
1287 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1288 m_parent
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);
1294 double DragOffsetX
= 0.0;
1295 double DragOffsetY
= 0.0;
1297 void wxShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1299 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1305 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1306 m_parent
->GetEventHandler()->OnDragLeft(draw
, x
, y
, keys
, attachment
);
1311 wxClientDC
dc(GetCanvas());
1312 GetCanvas()->PrepareDC(dc
);
1314 dc
.SetLogicalFunction(OGLRBLF
);
1316 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1317 dc
.SetPen(dottedPen
);
1318 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1321 xx
= x
+ DragOffsetX
;
1322 yy
= y
+ DragOffsetY
;
1324 m_canvas
->Snap(&xx
, &yy
);
1325 // m_xpos = xx; m_ypos = yy;
1327 GetBoundingBoxMax(&w
, &h
);
1328 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1331 void wxShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1333 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1339 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1340 m_parent
->GetEventHandler()->OnBeginDragLeft(x
, y
, keys
, attachment
);
1345 DragOffsetX
= m_xpos
- x
;
1346 DragOffsetY
= m_ypos
- y
;
1348 wxClientDC
dc(GetCanvas());
1349 GetCanvas()->PrepareDC(dc
);
1351 // New policy: don't erase shape until end of drag.
1355 xx
= x
+ DragOffsetX
;
1356 yy
= y
+ DragOffsetY
;
1357 m_canvas
->Snap(&xx
, &yy
);
1358 // m_xpos = xx; m_ypos = yy;
1359 dc
.SetLogicalFunction(OGLRBLF
);
1361 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1362 dc
.SetPen(dottedPen
);
1363 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1366 GetBoundingBoxMax(&w
, &h
);
1367 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1368 m_canvas
->CaptureMouse();
1371 void wxShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1373 m_canvas
->ReleaseMouse();
1374 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1380 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1381 m_parent
->GetEventHandler()->OnEndDragLeft(x
, y
, keys
, attachment
);
1386 wxClientDC
dc(GetCanvas());
1387 GetCanvas()->PrepareDC(dc
);
1389 dc
.SetLogicalFunction(wxCOPY
);
1391 double xx
= x
+ DragOffsetX
;
1392 double yy
= y
+ DragOffsetY
;
1393 m_canvas
->Snap(&xx
, &yy
);
1394 // canvas->Snap(&m_xpos, &m_ypos);
1396 // New policy: erase shape at end of drag.
1400 if (m_canvas
&& !m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1403 void wxShape::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1405 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1411 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1412 m_parent
->GetEventHandler()->OnDragRight(draw
, x
, y
, keys
, attachment
);
1418 void wxShape::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1420 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1426 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1427 m_parent
->GetEventHandler()->OnBeginDragRight(x
, y
, keys
, attachment
);
1433 void wxShape::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1435 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1441 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1442 m_parent
->GetEventHandler()->OnEndDragRight(x
, y
, keys
, attachment
);
1448 void wxShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
1450 double top_left_x
= (double)(x
- w
/2.0);
1451 double top_left_y
= (double)(y
- h
/2.0);
1452 double top_right_x
= (double)(top_left_x
+ w
);
1453 double top_right_y
= (double)top_left_y
;
1454 double bottom_left_x
= (double)top_left_x
;
1455 double bottom_left_y
= (double)(top_left_y
+ h
);
1456 double bottom_right_x
= (double)top_right_x
;
1457 double bottom_right_y
= (double)bottom_left_y
;
1460 points
[0].x
= WXROUND(top_left_x
); points
[0].y
= WXROUND(top_left_y
);
1461 points
[1].x
= WXROUND(top_right_x
); points
[1].y
= WXROUND(top_right_y
);
1462 points
[2].x
= WXROUND(bottom_right_x
); points
[2].y
= WXROUND(bottom_right_y
);
1463 points
[3].x
= WXROUND(bottom_left_x
); points
[3].y
= WXROUND(bottom_left_y
);
1464 points
[4].x
= WXROUND(top_left_x
); points
[4].y
= WXROUND(top_left_y
);
1466 dc
.DrawLines(5, points
);
1469 void wxShape::Attach(wxShapeCanvas
*can
)
1474 void wxShape::Detach()
1479 void wxShape::Move(wxDC
& dc
, double x
, double y
, bool display
)
1481 double old_x
= m_xpos
;
1482 double old_y
= m_ypos
;
1484 if (!GetEventHandler()->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
))
1491 m_xpos
= x
; m_ypos
= y
;
1493 ResetControlPoints();
1500 GetEventHandler()->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
1503 void wxShape::MoveLinks(wxDC
& dc
)
1505 GetEventHandler()->OnMoveLinks(dc
);
1509 void wxShape::Draw(wxDC
& dc
)
1513 GetEventHandler()->OnDraw(dc
);
1514 GetEventHandler()->OnDrawContents(dc
);
1515 GetEventHandler()->OnDrawControlPoints(dc
);
1516 GetEventHandler()->OnDrawBranches(dc
);
1520 void wxShape::Flash()
1524 wxClientDC
dc(GetCanvas());
1525 GetCanvas()->PrepareDC(dc
);
1527 dc
.SetLogicalFunction(OGLRBLF
);
1529 dc
.SetLogicalFunction(wxCOPY
);
1534 void wxShape::Show(bool show
)
1537 wxNode
*node
= m_children
.GetFirst();
1540 wxShape
*image
= (wxShape
*)node
->GetData();
1542 node
= node
->GetNext();
1546 void wxShape::Erase(wxDC
& dc
)
1548 GetEventHandler()->OnErase(dc
);
1549 GetEventHandler()->OnEraseControlPoints(dc
);
1550 GetEventHandler()->OnDrawBranches(dc
, TRUE
);
1553 void wxShape::EraseContents(wxDC
& dc
)
1555 GetEventHandler()->OnEraseContents(dc
);
1558 void wxShape::AddText(const wxString
& string
)
1560 wxNode
*node
= m_regions
.GetFirst();
1563 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1564 region
->ClearText();
1565 wxShapeTextLine
*new_line
=
1566 new wxShapeTextLine(0.0, 0.0, string
);
1567 region
->GetFormattedText().Append(new_line
);
1569 m_formatted
= FALSE
;
1572 void wxShape::SetSize(double x
, double y
, bool WXUNUSED(recursive
))
1574 SetAttachmentSize(x
, y
);
1575 SetDefaultRegionSize();
1578 void wxShape::SetAttachmentSize(double w
, double h
)
1582 double width
, height
;
1583 GetBoundingBoxMin(&width
, &height
);
1586 else scaleX
= w
/width
;
1589 else scaleY
= h
/height
;
1591 wxNode
*node
= m_attachmentPoints
.GetFirst();
1594 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1595 point
->m_x
= (double)(point
->m_x
* scaleX
);
1596 point
->m_y
= (double)(point
->m_y
* scaleY
);
1597 node
= node
->GetNext();
1601 // Add line FROM this object
1602 void wxShape::AddLine(wxLineShape
*line
, wxShape
*other
,
1603 int attachFrom
, int attachTo
,
1604 // The line ordering
1605 int positionFrom
, int positionTo
)
1607 if (positionFrom
== -1)
1609 if (!m_lines
.Member(line
))
1610 m_lines
.Append(line
);
1614 // Don't preserve old ordering if we have new ordering instructions
1615 m_lines
.DeleteObject(line
);
1616 if (positionFrom
< (int) m_lines
.GetCount())
1618 wxNode
* node
= m_lines
.Item(positionFrom
);
1619 m_lines
.Insert(node
, line
);
1622 m_lines
.Append(line
);
1625 if (positionTo
== -1)
1627 if (!other
->m_lines
.Member(line
))
1628 other
->m_lines
.Append(line
);
1632 // Don't preserve old ordering if we have new ordering instructions
1633 other
->m_lines
.DeleteObject(line
);
1634 if (positionTo
< (int) other
->m_lines
.GetCount())
1636 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1637 other
->m_lines
.Insert(node
, line
);
1640 other
->m_lines
.Append(line
);
1643 // Wrong: doesn't preserve ordering of shape already linked
1644 m_lines
.DeleteObject(line
);
1645 other
->m_lines
.DeleteObject(line
);
1647 if (positionFrom
== -1)
1648 m_lines
.Append(line
);
1651 if (positionFrom
< m_lines
.GetCount())
1653 wxNode
* node
= m_lines
.Item(positionFrom
);
1654 m_lines
.Insert(node
, line
);
1657 m_lines
.Append(line
);
1660 if (positionTo
== -1)
1661 other
->m_lines
.Append(line
);
1664 if (positionTo
< other
->m_lines
.GetCount())
1666 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1667 other
->m_lines
.Insert(node
, line
);
1670 other
->m_lines
.Append(line
);
1674 line
->SetFrom(this);
1676 line
->SetAttachments(attachFrom
, attachTo
);
1679 void wxShape::RemoveLine(wxLineShape
*line
)
1681 if (line
->GetFrom() == this)
1682 line
->GetTo()->m_lines
.DeleteObject(line
);
1684 line
->GetFrom()->m_lines
.DeleteObject(line
);
1686 m_lines
.DeleteObject(line
);
1690 void wxShape::WriteAttributes(wxExpr
*clause
)
1692 clause
->AddAttributeValueString(_T("type"), GetClassInfo()->GetClassName());
1693 clause
->AddAttributeValue(_T("id"), m_id
);
1697 int penWidth
= m_pen
->GetWidth();
1698 int penStyle
= m_pen
->GetStyle();
1700 clause
->AddAttributeValue(_T("pen_width"), (long)penWidth
);
1701 if (penStyle
!= wxSOLID
)
1702 clause
->AddAttributeValue(_T("pen_style"), (long)penStyle
);
1704 wxString penColour
= wxTheColourDatabase
->FindName(m_pen
->GetColour());
1705 if (penColour
== wxEmptyString
)
1707 wxString
hex(oglColourToHex(m_pen
->GetColour()));
1708 hex
= wxString(_T("#")) + hex
;
1709 clause
->AddAttributeValueString(_T("pen_colour"), hex
);
1711 else if (penColour
!= _T("BLACK"))
1712 clause
->AddAttributeValueString(_T("pen_colour"), penColour
);
1717 wxString brushColour
= wxTheColourDatabase
->FindName(m_brush
->GetColour());
1719 if (brushColour
== wxEmptyString
)
1721 wxString
hex(oglColourToHex(m_brush
->GetColour()));
1722 hex
= wxString(_T("#")) + hex
;
1723 clause
->AddAttributeValueString(_T("brush_colour"), hex
);
1725 else if (brushColour
!= _T("WHITE"))
1726 clause
->AddAttributeValueString(_T("brush_colour"), brushColour
);
1728 if (m_brush
->GetStyle() != wxSOLID
)
1729 clause
->AddAttributeValue(_T("brush_style"), (long)m_brush
->GetStyle());
1734 int n_lines
= m_lines
.GetCount();
1737 wxExpr
*list
= new wxExpr(wxExprList
);
1738 wxNode
*node
= m_lines
.GetFirst();
1741 wxShape
*line
= (wxShape
*)node
->GetData();
1742 wxExpr
*id_expr
= new wxExpr(line
->GetId());
1743 list
->Append(id_expr
);
1744 node
= node
->GetNext();
1746 clause
->AddAttributeValue(_T("arcs"), list
);
1749 // Miscellaneous members
1750 if (m_attachmentMode
!= 0)
1751 clause
->AddAttributeValue(_T("use_attachments"), (long)m_attachmentMode
);
1752 if (m_sensitivity
!= OP_ALL
)
1753 clause
->AddAttributeValue(_T("sensitivity"), (long)m_sensitivity
);
1754 if (!m_spaceAttachments
)
1755 clause
->AddAttributeValue(_T("space_attachments"), (long)m_spaceAttachments
);
1757 clause
->AddAttributeValue(_T("fixed_width"), (long)m_fixedWidth
);
1759 clause
->AddAttributeValue(_T("fixed_height"), (long)m_fixedHeight
);
1760 if (m_shadowMode
!= SHADOW_NONE
)
1761 clause
->AddAttributeValue(_T("shadow_mode"), (long)m_shadowMode
);
1762 if (m_centreResize
!= TRUE
)
1763 clause
->AddAttributeValue(_T("centre_resize"), (long)0);
1764 clause
->AddAttributeValue(_T("maintain_aspect_ratio"), (long) m_maintainAspectRatio
);
1765 if (m_highlighted
!= FALSE
)
1766 clause
->AddAttributeValue(_T("hilite"), (long)m_highlighted
);
1768 if (m_parent
) // For composite objects
1769 clause
->AddAttributeValue(_T("parent"), (long)m_parent
->GetId());
1771 if (m_rotation
!= 0.0)
1772 clause
->AddAttributeValue(_T("rotation"), m_rotation
);
1774 if (!this->IsKindOf(CLASSINFO(wxLineShape
)))
1776 clause
->AddAttributeValue(_T("neck_length"), (long) m_branchNeckLength
);
1777 clause
->AddAttributeValue(_T("stem_length"), (long) m_branchStemLength
);
1778 clause
->AddAttributeValue(_T("branch_spacing"), (long) m_branchSpacing
);
1779 clause
->AddAttributeValue(_T("branch_style"), (long) m_branchStyle
);
1782 // Write user-defined attachment points, if any
1783 if (m_attachmentPoints
.GetCount() > 0)
1785 wxExpr
*attachmentList
= new wxExpr(wxExprList
);
1786 wxNode
*node
= m_attachmentPoints
.GetFirst();
1789 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1790 wxExpr
*pointExpr
= new wxExpr(wxExprList
);
1791 pointExpr
->Append(new wxExpr((long)point
->m_id
));
1792 pointExpr
->Append(new wxExpr(point
->m_x
));
1793 pointExpr
->Append(new wxExpr(point
->m_y
));
1794 attachmentList
->Append(pointExpr
);
1795 node
= node
->GetNext();
1797 clause
->AddAttributeValue(_T("user_attachments"), attachmentList
);
1800 // Write text regions
1801 WriteRegions(clause
);
1804 void wxShape::WriteRegions(wxExpr
*clause
)
1806 // Output regions as region1 = (...), region2 = (...), etc
1807 // and formatted text as text1 = (...), text2 = (...) etc.
1809 wxChar regionNameBuf
[20];
1810 wxChar textNameBuf
[20];
1811 wxNode
*node
= m_regions
.GetFirst();
1814 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1815 wxSprintf(regionNameBuf
, _T("region%d"), regionNo
);
1816 wxSprintf(textNameBuf
, _T("text%d"), regionNo
);
1818 // Original text and region attributes:
1819 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
1820 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
1821 wxExpr
*regionExpr
= new wxExpr(wxExprList
);
1822 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionName
));
1823 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionText
));
1825 regionExpr
->Append(new wxExpr(region
->m_x
));
1826 regionExpr
->Append(new wxExpr(region
->m_y
));
1827 regionExpr
->Append(new wxExpr(region
->GetWidth()));
1828 regionExpr
->Append(new wxExpr(region
->GetHeight()));
1830 regionExpr
->Append(new wxExpr(region
->m_minWidth
));
1831 regionExpr
->Append(new wxExpr(region
->m_minHeight
));
1832 regionExpr
->Append(new wxExpr(region
->m_regionProportionX
));
1833 regionExpr
->Append(new wxExpr(region
->m_regionProportionY
));
1835 regionExpr
->Append(new wxExpr((long)region
->m_formatMode
));
1837 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetPointSize() : 10)));
1838 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetFamily() : wxDEFAULT
)));
1839 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetStyle() : wxDEFAULT
)));
1840 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetWeight() : wxNORMAL
)));
1841 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_textColour
));
1843 // New members for pen colour/style
1844 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_penColour
));
1845 regionExpr
->Append(new wxExpr((long)region
->m_penStyle
));
1848 // text1 = ((x y string) (x y string) ...)
1849 wxExpr
*textExpr
= new wxExpr(wxExprList
);
1851 wxNode
*textNode
= region
->m_formattedText
.GetFirst();
1854 wxShapeTextLine
*line
= (wxShapeTextLine
*)textNode
->GetData();
1855 wxExpr
*list2
= new wxExpr(wxExprList
);
1856 list2
->Append(new wxExpr(line
->GetX()));
1857 list2
->Append(new wxExpr(line
->GetY()));
1858 list2
->Append(new wxExpr(wxExprString
, line
->GetText()));
1859 textExpr
->Append(list2
);
1860 textNode
= textNode
->GetNext();
1863 // Now add both attributes to the clause
1864 clause
->AddAttributeValue(regionNameBuf
, regionExpr
);
1865 clause
->AddAttributeValue(textNameBuf
, textExpr
);
1867 node
= node
->GetNext();
1872 void wxShape::ReadAttributes(wxExpr
*clause
)
1874 clause
->GetAttributeValue(_T("id"), m_id
);
1877 clause
->GetAttributeValue(_T("x"), m_xpos
);
1878 clause
->GetAttributeValue(_T("y"), m_ypos
);
1880 // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
1882 wxExpr
*strings
= clause
->AttributeValue(_T("text"));
1883 if (strings
&& strings
->Type() == wxExprList
)
1885 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
1886 wxExpr
*node
= strings
->value
.first
;
1889 wxExpr
*string_expr
= node
;
1892 wxString the_string
= wxEmptyString
;
1894 // string_expr can either be a string, or a list of
1895 // 3 elements: x, y, and string.
1896 if (string_expr
->Type() == wxExprString
)
1898 the_string
= string_expr
->StringValue();
1899 m_formatted
= FALSE
;
1901 else if (string_expr
->Type() == wxExprList
)
1903 wxExpr
*first
= string_expr
->value
.first
;
1904 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
1905 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
1907 if (first
&& second
&& third
&&
1908 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
1909 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
1910 third
->Type() == wxExprString
)
1912 if (first
->Type() == wxExprReal
)
1913 the_x
= first
->RealValue();
1914 else the_x
= (double)first
->IntegerValue();
1916 if (second
->Type() == wxExprReal
)
1917 the_y
= second
->RealValue();
1918 else the_y
= (double)second
->IntegerValue();
1920 the_string
= third
->StringValue();
1923 wxShapeTextLine
*line
=
1924 new wxShapeTextLine(the_x
, the_y
, the_string
);
1925 m_text
.Append(line
);
1931 wxString pen_string
= wxEmptyString
;
1932 wxString brush_string
= wxEmptyString
;
1934 int pen_style
= wxSOLID
;
1935 int brush_style
= wxSOLID
;
1936 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
1938 clause
->GetAttributeValue(_T("pen_colour"), pen_string
);
1939 clause
->GetAttributeValue(_T("text_colour"), m_textColourName
);
1941 SetTextColour(m_textColourName
);
1943 clause
->GetAttributeValue(_T("region_name"), m_regionName
);
1945 clause
->GetAttributeValue(_T("brush_colour"), brush_string
);
1946 clause
->GetAttributeValue(_T("pen_width"), pen_width
);
1947 clause
->GetAttributeValue(_T("pen_style"), pen_style
);
1948 clause
->GetAttributeValue(_T("brush_style"), brush_style
);
1950 int iVal
= (int) m_attachmentMode
;
1951 clause
->GetAttributeValue(_T("use_attachments"), iVal
);
1952 m_attachmentMode
= iVal
;
1954 clause
->GetAttributeValue(_T("sensitivity"), m_sensitivity
);
1956 iVal
= (int) m_spaceAttachments
;
1957 clause
->GetAttributeValue(_T("space_attachments"), iVal
);
1958 m_spaceAttachments
= (iVal
!= 0);
1960 iVal
= (int) m_fixedWidth
;
1961 clause
->GetAttributeValue(_T("fixed_width"), iVal
);
1962 m_fixedWidth
= (iVal
!= 0);
1964 iVal
= (int) m_fixedHeight
;
1965 clause
->GetAttributeValue(_T("fixed_height"), iVal
);
1966 m_fixedHeight
= (iVal
!= 0);
1968 clause
->GetAttributeValue(_T("format_mode"), m_formatMode
);
1969 clause
->GetAttributeValue(_T("shadow_mode"), m_shadowMode
);
1971 iVal
= m_branchNeckLength
;
1972 clause
->GetAttributeValue(_T("neck_length"), iVal
);
1973 m_branchNeckLength
= iVal
;
1975 iVal
= m_branchStemLength
;
1976 clause
->GetAttributeValue(_T("stem_length"), iVal
);
1977 m_branchStemLength
= iVal
;
1979 iVal
= m_branchSpacing
;
1980 clause
->GetAttributeValue(_T("branch_spacing"), iVal
);
1981 m_branchSpacing
= iVal
;
1983 clause
->GetAttributeValue(_T("branch_style"), m_branchStyle
);
1985 iVal
= (int) m_centreResize
;
1986 clause
->GetAttributeValue(_T("centre_resize"), iVal
);
1987 m_centreResize
= (iVal
!= 0);
1989 iVal
= (int) m_maintainAspectRatio
;
1990 clause
->GetAttributeValue(_T("maintain_aspect_ratio"), iVal
);
1991 m_maintainAspectRatio
= (iVal
!= 0);
1993 iVal
= (int) m_highlighted
;
1994 clause
->GetAttributeValue(_T("hilite"), iVal
);
1995 m_highlighted
= (iVal
!= 0);
1997 clause
->GetAttributeValue(_T("rotation"), m_rotation
);
1999 if (pen_string
== wxEmptyString
)
2000 pen_string
= _T("BLACK");
2001 if (brush_string
== wxEmptyString
)
2002 brush_string
= _T("WHITE");
2004 if (pen_string
.GetChar(0) == '#')
2006 wxColour
col(oglHexToColour(pen_string
.After('#')));
2007 m_pen
= wxThePenList
->FindOrCreatePen(col
, pen_width
, pen_style
);
2010 m_pen
= wxThePenList
->FindOrCreatePen(pen_string
, pen_width
, pen_style
);
2013 m_pen
= wxBLACK_PEN
;
2015 if (brush_string
.GetChar(0) == '#')
2017 wxColour
col(oglHexToColour(brush_string
.After('#')));
2018 m_brush
= wxTheBrushList
->FindOrCreateBrush(col
, brush_style
);
2021 m_brush
= wxTheBrushList
->FindOrCreateBrush(brush_string
, brush_style
);
2024 m_brush
= wxWHITE_BRUSH
;
2026 int point_size
= 10;
2027 clause
->GetAttributeValue(_T("point_size"), point_size
);
2028 SetFont(oglMatchFont(point_size
));
2030 // Read user-defined attachment points, if any
2031 wxExpr
*attachmentList
= clause
->AttributeValue(_T("user_attachments"));
2034 wxExpr
*pointExpr
= attachmentList
->GetFirst();
2037 wxExpr
*idExpr
= pointExpr
->Nth(0);
2038 wxExpr
*xExpr
= pointExpr
->Nth(1);
2039 wxExpr
*yExpr
= pointExpr
->Nth(2);
2040 if (idExpr
&& xExpr
&& yExpr
)
2042 wxAttachmentPoint
*point
= new wxAttachmentPoint
;
2043 point
->m_id
= (int)idExpr
->IntegerValue();
2044 point
->m_x
= xExpr
->RealValue();
2045 point
->m_y
= yExpr
->RealValue();
2046 m_attachmentPoints
.Append((wxObject
*)point
);
2048 pointExpr
= pointExpr
->GetNext();
2052 // Read text regions
2053 ReadRegions(clause
);
2056 void wxShape::ReadRegions(wxExpr
*clause
)
2060 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
2061 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
2063 wxChar regionNameBuf
[20];
2064 wxChar textNameBuf
[20];
2067 wxExpr
*textExpr
= NULL
;
2068 wxSprintf(regionNameBuf
, _T("region%d"), regionNo
);
2069 wxSprintf(textNameBuf
, _T("text%d"), regionNo
);
2071 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
2073 while ((regionExpr
= clause
->AttributeValue(regionNameBuf
)) != NULL
)
2076 * Get the region information
2080 wxString regionName
= wxEmptyString
;
2081 wxString regionText
= wxEmptyString
;
2085 double height
= 0.0;
2086 double minWidth
= 5.0;
2087 double minHeight
= 5.0;
2088 double m_regionProportionX
= -1.0;
2089 double m_regionProportionY
= -1.0;
2090 int formatMode
= FORMAT_NONE
;
2092 int fontFamily
= wxSWISS
;
2093 int fontStyle
= wxNORMAL
;
2094 int fontWeight
= wxNORMAL
;
2095 wxString regionTextColour
= wxEmptyString
;
2096 wxString penColour
= wxEmptyString
;
2097 int penStyle
= wxSOLID
;
2099 if (regionExpr
->Type() == wxExprList
)
2101 wxExpr
*nameExpr
= regionExpr
->Nth(0);
2102 wxExpr
*textExpr
= regionExpr
->Nth(1);
2103 wxExpr
*xExpr
= regionExpr
->Nth(2);
2104 wxExpr
*yExpr
= regionExpr
->Nth(3);
2105 wxExpr
*widthExpr
= regionExpr
->Nth(4);
2106 wxExpr
*heightExpr
= regionExpr
->Nth(5);
2107 wxExpr
*minWidthExpr
= regionExpr
->Nth(6);
2108 wxExpr
*minHeightExpr
= regionExpr
->Nth(7);
2109 wxExpr
*propXExpr
= regionExpr
->Nth(8);
2110 wxExpr
*propYExpr
= regionExpr
->Nth(9);
2111 wxExpr
*formatExpr
= regionExpr
->Nth(10);
2112 wxExpr
*sizeExpr
= regionExpr
->Nth(11);
2113 wxExpr
*familyExpr
= regionExpr
->Nth(12);
2114 wxExpr
*styleExpr
= regionExpr
->Nth(13);
2115 wxExpr
*weightExpr
= regionExpr
->Nth(14);
2116 wxExpr
*colourExpr
= regionExpr
->Nth(15);
2117 wxExpr
*penColourExpr
= regionExpr
->Nth(16);
2118 wxExpr
*penStyleExpr
= regionExpr
->Nth(17);
2120 regionName
= nameExpr
->StringValue();
2121 regionText
= textExpr
->StringValue();
2123 x
= xExpr
->RealValue();
2124 y
= yExpr
->RealValue();
2126 width
= widthExpr
->RealValue();
2127 height
= heightExpr
->RealValue();
2129 minWidth
= minWidthExpr
->RealValue();
2130 minHeight
= minHeightExpr
->RealValue();
2132 m_regionProportionX
= propXExpr
->RealValue();
2133 m_regionProportionY
= propYExpr
->RealValue();
2135 formatMode
= (int) formatExpr
->IntegerValue();
2136 fontSize
= (int)sizeExpr
->IntegerValue();
2137 fontFamily
= (int)familyExpr
->IntegerValue();
2138 fontStyle
= (int)styleExpr
->IntegerValue();
2139 fontWeight
= (int)weightExpr
->IntegerValue();
2143 regionTextColour
= colourExpr
->StringValue();
2146 regionTextColour
= _T("BLACK");
2149 penColour
= penColourExpr
->StringValue();
2151 penStyle
= (int)penStyleExpr
->IntegerValue();
2153 wxFont
*font
= wxTheFontList
->FindOrCreateFont(fontSize
, fontFamily
, fontStyle
, fontWeight
);
2155 wxShapeRegion
*region
= new wxShapeRegion
;
2156 region
->SetProportions(m_regionProportionX
, m_regionProportionY
);
2157 region
->SetFont(font
);
2158 region
->SetSize(width
, height
);
2159 region
->SetPosition(x
, y
);
2160 region
->SetMinSize(minWidth
, minHeight
);
2161 region
->SetFormatMode(formatMode
);
2162 region
->SetPenStyle(penStyle
);
2163 if (penColour
!= wxEmptyString
)
2164 region
->SetPenColour(penColour
);
2166 region
->m_textColour
= regionTextColour
;
2167 region
->m_regionText
= regionText
;
2168 region
->m_regionName
= regionName
;
2170 m_regions
.Append(region
);
2173 * Get the formatted text strings
2176 textExpr
= clause
->AttributeValue(textNameBuf
);
2177 if (textExpr
&& (textExpr
->Type() == wxExprList
))
2179 wxExpr
*node
= textExpr
->value
.first
;
2182 wxExpr
*string_expr
= node
;
2185 wxString the_string
= wxEmptyString
;
2187 // string_expr can either be a string, or a list of
2188 // 3 elements: x, y, and string.
2189 if (string_expr
->Type() == wxExprString
)
2191 the_string
= string_expr
->StringValue();
2192 m_formatted
= FALSE
;
2194 else if (string_expr
->Type() == wxExprList
)
2196 wxExpr
*first
= string_expr
->value
.first
;
2197 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
2198 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
2200 if (first
&& second
&& third
&&
2201 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
2202 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
2203 third
->Type() == wxExprString
)
2205 if (first
->Type() == wxExprReal
)
2206 the_x
= first
->RealValue();
2207 else the_x
= (double)first
->IntegerValue();
2209 if (second
->Type() == wxExprReal
)
2210 the_y
= second
->RealValue();
2211 else the_y
= (double)second
->IntegerValue();
2213 the_string
= third
->StringValue();
2218 wxShapeTextLine
*line
=
2219 new wxShapeTextLine(the_x
, the_y
, the_string
);
2220 region
->m_formattedText
.Append(line
);
2227 wxSprintf(regionNameBuf
, _T("region%d"), regionNo
);
2228 wxSprintf(textNameBuf
, _T("text%d"), regionNo
);
2231 // Compatibility: check for no regions (old file).
2232 // Lines and divided rectangles must deal with this compatibility
2233 // theirselves. Composites _may_ not have any regions anyway.
2234 if ((m_regions
.GetCount() == 0) &&
2235 !this->IsKindOf(CLASSINFO(wxLineShape
)) && !this->IsKindOf(CLASSINFO(wxDividedShape
)) &&
2236 !this->IsKindOf(CLASSINFO(wxCompositeShape
)))
2238 wxShapeRegion
*newRegion
= new wxShapeRegion
;
2239 newRegion
->SetName(_T("0"));
2240 m_regions
.Append((wxObject
*)newRegion
);
2241 if (m_text
.GetCount() > 0)
2243 newRegion
->ClearText();
2244 wxNode
*node
= m_text
.GetFirst();
2247 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->GetData();
2248 wxNode
*next
= node
->GetNext();
2249 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
2259 void wxShape::Copy(wxShape
& copy
)
2262 copy
.m_xpos
= m_xpos
;
2263 copy
.m_ypos
= m_ypos
;
2265 copy
.m_brush
= m_brush
;
2266 copy
.m_textColour
= m_textColour
;
2267 copy
.m_centreResize
= m_centreResize
;
2268 copy
.m_maintainAspectRatio
= m_maintainAspectRatio
;
2269 copy
.m_attachmentMode
= m_attachmentMode
;
2270 copy
.m_spaceAttachments
= m_spaceAttachments
;
2271 copy
.m_highlighted
= m_highlighted
;
2272 copy
.m_rotation
= m_rotation
;
2273 copy
.m_textColourName
= m_textColourName
;
2274 copy
.m_regionName
= m_regionName
;
2276 copy
.m_sensitivity
= m_sensitivity
;
2277 copy
.m_draggable
= m_draggable
;
2278 copy
.m_fixedWidth
= m_fixedWidth
;
2279 copy
.m_fixedHeight
= m_fixedHeight
;
2280 copy
.m_formatMode
= m_formatMode
;
2281 copy
.m_drawHandles
= m_drawHandles
;
2283 copy
.m_visible
= m_visible
;
2284 copy
.m_shadowMode
= m_shadowMode
;
2285 copy
.m_shadowOffsetX
= m_shadowOffsetX
;
2286 copy
.m_shadowOffsetY
= m_shadowOffsetY
;
2287 copy
.m_shadowBrush
= m_shadowBrush
;
2289 copy
.m_branchNeckLength
= m_branchNeckLength
;
2290 copy
.m_branchStemLength
= m_branchStemLength
;
2291 copy
.m_branchSpacing
= m_branchSpacing
;
2293 // Copy text regions
2294 copy
.ClearRegions();
2295 wxNode
*node
= m_regions
.GetFirst();
2298 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
2299 wxShapeRegion
*newRegion
= new wxShapeRegion(*region
);
2300 copy
.m_regions
.Append(newRegion
);
2301 node
= node
->GetNext();
2305 copy
.ClearAttachments();
2306 node
= m_attachmentPoints
.GetFirst();
2309 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2310 wxAttachmentPoint
*newPoint
= new wxAttachmentPoint
;
2311 newPoint
->m_id
= point
->m_id
;
2312 newPoint
->m_x
= point
->m_x
;
2313 newPoint
->m_y
= point
->m_y
;
2314 copy
.m_attachmentPoints
.Append((wxObject
*)newPoint
);
2315 node
= node
->GetNext();
2319 copy
.m_lines
.Clear();
2320 node
= m_lines
.GetFirst();
2323 wxLineShape
* line
= (wxLineShape
*) node
->GetData();
2324 copy
.m_lines
.Append(line
);
2325 node
= node
->GetNext();
2329 // Create and return a new, fully copied object.
2330 wxShape
*wxShape::CreateNewCopy(bool resetMapping
, bool recompute
)
2333 oglObjectCopyMapping
.Clear();
2335 wxShape
* newObject
= (wxShape
*) GetClassInfo()->CreateObject();
2337 wxASSERT( (newObject
!= NULL
) );
2338 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShape
))) );
2342 if (GetEventHandler() != this)
2344 wxShapeEvtHandler
* newHandler
= GetEventHandler()->CreateNewCopy();
2345 newObject
->SetEventHandler(newHandler
);
2346 newObject
->SetPreviousHandler(NULL
);
2347 newHandler
->SetPreviousHandler(newObject
);
2348 newHandler
->SetShape(newObject
);
2352 newObject
->Recompute();
2356 // Does the copying for this object, including copying event
2357 // handler data if any. Calls the virtual Copy function.
2358 void wxShape::CopyWithHandler(wxShape
& copy
)
2362 if (GetEventHandler() != this)
2364 wxASSERT( copy
.GetEventHandler() != NULL
);
2365 wxASSERT( copy
.GetEventHandler() != (©
) );
2366 wxASSERT( GetEventHandler()->GetClassInfo() == copy
.GetEventHandler()->GetClassInfo() );
2367 GetEventHandler()->CopyData(* (copy
.GetEventHandler()));
2372 // Default - make 6 control points
2373 void wxShape::MakeControlPoints()
2375 double maxX
, maxY
, minX
, minY
;
2377 GetBoundingBoxMax(&maxX
, &maxY
);
2378 GetBoundingBoxMin(&minX
, &minY
);
2380 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2381 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2383 // Offsets from main object
2384 double top
= (double)(- (heightMin
/ 2.0));
2385 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2386 double left
= (double)(- (widthMin
/ 2.0));
2387 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2389 wxControlPoint
*control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, top
,
2390 CONTROL_POINT_DIAGONAL
);
2391 m_canvas
->AddShape(control
);
2392 m_controlPoints
.Append(control
);
2394 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, top
,
2395 CONTROL_POINT_VERTICAL
);
2396 m_canvas
->AddShape(control
);
2397 m_controlPoints
.Append(control
);
2399 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, top
,
2400 CONTROL_POINT_DIAGONAL
);
2401 m_canvas
->AddShape(control
);
2402 m_controlPoints
.Append(control
);
2404 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, 0,
2405 CONTROL_POINT_HORIZONTAL
);
2406 m_canvas
->AddShape(control
);
2407 m_controlPoints
.Append(control
);
2409 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, bottom
,
2410 CONTROL_POINT_DIAGONAL
);
2411 m_canvas
->AddShape(control
);
2412 m_controlPoints
.Append(control
);
2414 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, bottom
,
2415 CONTROL_POINT_VERTICAL
);
2416 m_canvas
->AddShape(control
);
2417 m_controlPoints
.Append(control
);
2419 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, bottom
,
2420 CONTROL_POINT_DIAGONAL
);
2421 m_canvas
->AddShape(control
);
2422 m_controlPoints
.Append(control
);
2424 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, 0,
2425 CONTROL_POINT_HORIZONTAL
);
2426 m_canvas
->AddShape(control
);
2427 m_controlPoints
.Append(control
);
2431 void wxShape::MakeMandatoryControlPoints()
2433 wxNode
*node
= m_children
.GetFirst();
2436 wxShape
*child
= (wxShape
*)node
->GetData();
2437 child
->MakeMandatoryControlPoints();
2438 node
= node
->GetNext();
2442 void wxShape::ResetMandatoryControlPoints()
2444 wxNode
*node
= m_children
.GetFirst();
2447 wxShape
*child
= (wxShape
*)node
->GetData();
2448 child
->ResetMandatoryControlPoints();
2449 node
= node
->GetNext();
2453 void wxShape::ResetControlPoints()
2455 ResetMandatoryControlPoints();
2457 if (m_controlPoints
.GetCount() < 1)
2460 double maxX
, maxY
, minX
, minY
;
2462 GetBoundingBoxMax(&maxX
, &maxY
);
2463 GetBoundingBoxMin(&minX
, &minY
);
2465 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2466 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2468 // Offsets from main object
2469 double top
= (double)(- (heightMin
/ 2.0));
2470 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2471 double left
= (double)(- (widthMin
/ 2.0));
2472 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2474 wxNode
*node
= m_controlPoints
.GetFirst();
2475 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2476 control
->m_xoffset
= left
; control
->m_yoffset
= top
;
2478 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2479 control
->m_xoffset
= 0; control
->m_yoffset
= top
;
2481 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2482 control
->m_xoffset
= right
; control
->m_yoffset
= top
;
2484 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2485 control
->m_xoffset
= right
; control
->m_yoffset
= 0;
2487 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2488 control
->m_xoffset
= right
; control
->m_yoffset
= bottom
;
2490 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2491 control
->m_xoffset
= 0; control
->m_yoffset
= bottom
;
2493 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2494 control
->m_xoffset
= left
; control
->m_yoffset
= bottom
;
2496 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2497 control
->m_xoffset
= left
; control
->m_yoffset
= 0;
2500 void wxShape::DeleteControlPoints(wxDC
*dc
)
2502 wxNode
*node
= m_controlPoints
.GetFirst();
2505 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2507 control
->GetEventHandler()->OnErase(*dc
);
2508 m_canvas
->RemoveShape(control
);
2511 node
= m_controlPoints
.GetFirst();
2513 // Children of divisions are contained objects,
2515 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2517 node
= m_children
.GetFirst();
2520 wxShape
*child
= (wxShape
*)node
->GetData();
2521 child
->DeleteControlPoints(dc
);
2522 node
= node
->GetNext();
2527 void wxShape::OnDrawControlPoints(wxDC
& dc
)
2532 dc
.SetBrush(* wxBLACK_BRUSH
);
2533 dc
.SetPen(* wxBLACK_PEN
);
2535 wxNode
*node
= m_controlPoints
.GetFirst();
2538 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2540 node
= node
->GetNext();
2542 // Children of divisions are contained objects,
2544 // This test bypasses the type facility for speed
2545 // (critical when drawing)
2546 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2548 node
= m_children
.GetFirst();
2551 wxShape
*child
= (wxShape
*)node
->GetData();
2552 child
->GetEventHandler()->OnDrawControlPoints(dc
);
2553 node
= node
->GetNext();
2558 void wxShape::OnEraseControlPoints(wxDC
& dc
)
2560 wxNode
*node
= m_controlPoints
.GetFirst();
2563 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2565 node
= node
->GetNext();
2567 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2569 node
= m_children
.GetFirst();
2572 wxShape
*child
= (wxShape
*)node
->GetData();
2573 child
->GetEventHandler()->OnEraseControlPoints(dc
);
2574 node
= node
->GetNext();
2579 void wxShape::Select(bool select
, wxDC
* dc
)
2581 m_selected
= select
;
2584 MakeControlPoints();
2585 // Children of divisions are contained objects,
2587 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2589 wxNode
*node
= m_children
.GetFirst();
2592 wxShape
*child
= (wxShape
*)node
->GetData();
2593 child
->MakeMandatoryControlPoints();
2594 node
= node
->GetNext();
2598 GetEventHandler()->OnDrawControlPoints(*dc
);
2602 DeleteControlPoints(dc
);
2603 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2605 wxNode
*node
= m_children
.GetFirst();
2608 wxShape
*child
= (wxShape
*)node
->GetData();
2609 child
->DeleteControlPoints(dc
);
2610 node
= node
->GetNext();
2616 bool wxShape::Selected() const
2621 bool wxShape::AncestorSelected() const
2623 if (m_selected
) return TRUE
;
2627 return GetParent()->AncestorSelected();
2630 int wxShape::GetNumberOfAttachments() const
2632 // Should return the MAXIMUM attachment point id here,
2633 // so higher-level functions can iterate through all attachments,
2634 // even if they're not contiguous.
2635 if (m_attachmentPoints
.GetCount() == 0)
2640 wxNode
*node
= m_attachmentPoints
.GetFirst();
2643 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2644 if (point
->m_id
> maxN
)
2646 node
= node
->GetNext();
2652 bool wxShape::AttachmentIsValid(int attachment
) const
2654 if (m_attachmentPoints
.GetCount() == 0)
2656 return ((attachment
>= 0) && (attachment
< 4)) ;
2659 wxNode
*node
= m_attachmentPoints
.GetFirst();
2662 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2663 if (point
->m_id
== attachment
)
2665 node
= node
->GetNext();
2670 bool wxShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
2671 int nth
, int no_arcs
, wxLineShape
*line
)
2673 if (m_attachmentMode
== ATTACHMENT_MODE_NONE
)
2675 *x
= m_xpos
; *y
= m_ypos
;
2678 else if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
2680 wxRealPoint pt
, stemPt
;
2681 GetBranchingAttachmentPoint(attachment
, nth
, pt
, stemPt
);
2686 else if (m_attachmentMode
== ATTACHMENT_MODE_EDGE
)
2688 if (m_attachmentPoints
.GetCount() > 0)
2690 wxNode
*node
= m_attachmentPoints
.GetFirst();
2693 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2694 if (point
->m_id
== attachment
)
2696 *x
= (double)(m_xpos
+ point
->m_x
);
2697 *y
= (double)(m_ypos
+ point
->m_y
);
2700 node
= node
->GetNext();
2702 *x
= m_xpos
; *y
= m_ypos
;
2707 // Assume is rectangular
2709 GetBoundingBoxMax(&w
, &h
);
2710 double top
= (double)(m_ypos
+ h
/2.0);
2711 double bottom
= (double)(m_ypos
- h
/2.0);
2712 double left
= (double)(m_xpos
- w
/2.0);
2713 double right
= (double)(m_xpos
+ w
/2.0);
2715 /* bool isEnd = */ (line
&& line
->IsEnd(this));
2717 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2720 switch (physicalAttachment
)
2724 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(right
, bottom
),
2725 nth
, no_arcs
, line
);
2727 *x
= pt
.x
; *y
= pt
.y
;
2732 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(right
, bottom
), wxRealPoint(right
, top
),
2733 nth
, no_arcs
, line
);
2735 *x
= pt
.x
; *y
= pt
.y
;
2740 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, top
), wxRealPoint(right
, top
),
2741 nth
, no_arcs
, line
);
2743 *x
= pt
.x
; *y
= pt
.y
;
2748 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(left
, top
),
2749 nth
, no_arcs
, line
);
2751 *x
= pt
.x
; *y
= pt
.y
;
2765 void wxShape::GetBoundingBoxMax(double *w
, double *h
)
2768 GetBoundingBoxMin(&ww
, &hh
);
2769 if (m_shadowMode
!= SHADOW_NONE
)
2771 ww
+= m_shadowOffsetX
;
2772 hh
+= m_shadowOffsetY
;
2778 // Returns TRUE if image is a descendant of this composite
2779 bool wxShape::HasDescendant(wxShape
*image
)
2783 wxNode
*node
= m_children
.GetFirst();
2786 wxShape
*child
= (wxShape
*)node
->GetData();
2787 bool ans
= child
->HasDescendant(image
);
2790 node
= node
->GetNext();
2795 // Clears points from a list of wxRealPoints, and clears list
2796 void wxShape::ClearPointList(wxList
& list
)
2798 wxNode
* node
= list
.GetFirst();
2801 wxRealPoint
* pt
= (wxRealPoint
*) node
->GetData();
2804 node
= node
->GetNext();
2809 // Assuming the attachment lies along a vertical or horizontal line,
2810 // calculate the position on that point.
2811 wxRealPoint
wxShape::CalcSimpleAttachment(const wxRealPoint
& pt1
, const wxRealPoint
& pt2
,
2812 int nth
, int noArcs
, wxLineShape
* line
)
2814 bool isEnd
= (line
&& line
->IsEnd(this));
2816 // Are we horizontal or vertical?
2817 bool isHorizontal
= (oglRoughlyEqual(pt1
.y
, pt2
.y
) == TRUE
);
2823 wxRealPoint firstPoint
, secondPoint
;
2835 if (m_spaceAttachments
)
2837 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2839 // Align line according to the next handle along
2840 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2841 if (point
->x
< firstPoint
.x
)
2843 else if (point
->x
> secondPoint
.x
)
2849 x
= firstPoint
.x
+ (nth
+ 1)*(secondPoint
.x
- firstPoint
.x
)/(noArcs
+ 1);
2851 else x
= (secondPoint
.x
- firstPoint
.x
)/2.0; // Midpoint
2857 wxASSERT( oglRoughlyEqual(pt1
.x
, pt2
.x
) == TRUE
);
2859 wxRealPoint firstPoint
, secondPoint
;
2871 if (m_spaceAttachments
)
2873 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2875 // Align line according to the next handle along
2876 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2877 if (point
->y
< firstPoint
.y
)
2879 else if (point
->y
> secondPoint
.y
)
2885 y
= firstPoint
.y
+ (nth
+ 1)*(secondPoint
.y
- firstPoint
.y
)/(noArcs
+ 1);
2887 else y
= (secondPoint
.y
- firstPoint
.y
)/2.0; // Midpoint
2892 return wxRealPoint(x
, y
);
2895 // Return the zero-based position in m_lines of line.
2896 int wxShape::GetLinePosition(wxLineShape
* line
)
2898 for (size_t i
= 0; i
< m_lines
.GetCount(); i
++)
2899 if ((wxLineShape
*) (m_lines
.Item(i
)->GetData()) == line
)
2909 // shoulder1 ->---------<- shoulder2
2911 // <- branching attachment point N-1
2913 // This function gets information about where branching connections go.
2914 // Returns FALSE if there are no lines at this attachment.
2915 bool wxShape::GetBranchingAttachmentInfo(int attachment
, wxRealPoint
& root
, wxRealPoint
& neck
,
2916 wxRealPoint
& shoulder1
, wxRealPoint
& shoulder2
)
2918 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2920 // Number of lines at this attachment.
2921 int lineCount
= GetAttachmentLineCount(attachment
);
2926 int totalBranchLength
= m_branchSpacing
* (lineCount
- 1);
2928 root
= GetBranchingAttachmentRoot(attachment
);
2930 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
2931 switch (physicalAttachment
)
2936 neck
.y
= root
.y
- m_branchNeckLength
;
2938 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2939 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2941 shoulder1
.y
= neck
.y
;
2942 shoulder2
.y
= neck
.y
;
2947 neck
.x
= root
.x
+ m_branchNeckLength
;
2950 shoulder1
.x
= neck
.x
;
2951 shoulder2
.x
= neck
.x
;
2953 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2954 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2960 neck
.y
= root
.y
+ m_branchNeckLength
;
2962 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2963 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2965 shoulder1
.y
= neck
.y
;
2966 shoulder2
.y
= neck
.y
;
2971 neck
.x
= root
.x
- m_branchNeckLength
;
2974 shoulder1
.x
= neck
.x
;
2975 shoulder2
.x
= neck
.x
;
2977 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2978 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2983 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentInfo.") );
2990 // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
2991 // at this attachment point.
2992 // Get the attachment point where the arc joins the stem, and also the point where the
2993 // the stem meets the shoulder.
2994 bool wxShape::GetBranchingAttachmentPoint(int attachment
, int n
, wxRealPoint
& pt
, wxRealPoint
& stemPt
)
2996 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2998 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
2999 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3001 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3002 switch (physicalAttachment
)
3006 pt
.y
= neck
.y
- m_branchStemLength
;
3007 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3015 pt
.y
= neck
.y
+ m_branchStemLength
;
3016 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3024 pt
.x
= neck
.x
+ m_branchStemLength
;
3025 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3033 pt
.x
= neck
.x
- m_branchStemLength
;
3034 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3042 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentPoint.") );
3050 // Get the number of lines at this attachment position.
3051 int wxShape::GetAttachmentLineCount(int attachment
) const
3054 wxNode
* node
= m_lines
.GetFirst();
3057 wxLineShape
* lineShape
= (wxLineShape
*) node
->GetData();
3058 if ((lineShape
->GetFrom() == this) && (lineShape
->GetAttachmentFrom() == attachment
))
3060 else if ((lineShape
->GetTo() == this) && (lineShape
->GetAttachmentTo() == attachment
))
3063 node
= node
->GetNext();
3068 // This function gets the root point at the given attachment.
3069 wxRealPoint
wxShape::GetBranchingAttachmentRoot(int attachment
)
3071 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3075 double width
, height
;
3076 GetBoundingBoxMax(& width
, & height
);
3078 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3079 switch (physicalAttachment
)
3084 root
.y
= GetY() - height
/2.0;
3089 root
.x
= GetX() + width
/2.0;
3096 root
.y
= GetY() + height
/2.0;
3101 root
.x
= GetX() - width
/2.0;
3107 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentRoot.") );
3114 // Draw or erase the branches (not the actual arcs though)
3115 void wxShape::OnDrawBranches(wxDC
& dc
, int attachment
, bool erase
)
3117 int count
= GetAttachmentLineCount(attachment
);
3121 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3122 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3126 dc
.SetPen(*wxWHITE_PEN
);
3127 dc
.SetBrush(*wxWHITE_BRUSH
);
3131 dc
.SetPen(*wxBLACK_PEN
);
3132 dc
.SetBrush(*wxBLACK_BRUSH
);
3136 dc
.DrawLine((long) root
.x
, (long) root
.y
, (long) neck
.x
, (long) neck
.y
);
3140 // Draw shoulder-to-shoulder line
3141 dc
.DrawLine((long) shoulder1
.x
, (long) shoulder1
.y
, (long) shoulder2
.x
, (long) shoulder2
.y
);
3143 // Draw all the little branches
3145 for (i
= 0; i
< count
; i
++)
3147 wxRealPoint pt
, stemPt
;
3148 GetBranchingAttachmentPoint(attachment
, i
, pt
, stemPt
);
3149 dc
.DrawLine((long) stemPt
.x
, (long) stemPt
.y
, (long) pt
.x
, (long) pt
.y
);
3151 if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB
) && (count
> 1))
3154 // dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
3155 dc
.DrawEllipse((long) (stemPt
.x
- (blobSize
/2.0)), (long) (stemPt
.y
- (blobSize
/2.0)), blobSize
, blobSize
);
3160 // Draw or erase the branches (not the actual arcs though)
3161 void wxShape::OnDrawBranches(wxDC
& dc
, bool erase
)
3163 if (m_attachmentMode
!= ATTACHMENT_MODE_BRANCHING
)
3166 int count
= GetNumberOfAttachments();
3168 for (i
= 0; i
< count
; i
++)
3169 OnDrawBranches(dc
, i
, erase
);
3172 // Only get the attachment position at the _edge_ of the shape, ignoring
3173 // branching mode. This is used e.g. to indicate the edge of interest, not the point
3174 // on the attachment branch.
3175 bool wxShape::GetAttachmentPositionEdge(int attachment
, double *x
, double *y
,
3176 int nth
, int no_arcs
, wxLineShape
*line
)
3178 int oldMode
= m_attachmentMode
;
3180 // Calculate as if to edge, not branch
3181 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
3182 m_attachmentMode
= ATTACHMENT_MODE_EDGE
;
3183 bool success
= GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
3184 m_attachmentMode
= oldMode
;
3189 // Rotate the standard attachment point from physical (0 is always North)
3190 // to logical (0 -> 1 if rotated by 90 degrees)
3191 int wxShape::PhysicalToLogicalAttachment(int physicalAttachment
) const
3193 const double pi
= 3.1415926535897932384626433832795 ;
3195 if (oglRoughlyEqual(GetRotation(), 0.0))
3197 i
= physicalAttachment
;
3199 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3201 i
= physicalAttachment
- 1;
3203 else if (oglRoughlyEqual(GetRotation(), pi
))
3205 i
= physicalAttachment
- 2;
3207 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3209 i
= physicalAttachment
- 3;
3212 // Can't handle -- assume the same.
3213 return physicalAttachment
;
3221 // Rotate the standard attachment point from logical
3222 // to physical (0 is always North)
3223 int wxShape::LogicalToPhysicalAttachment(int logicalAttachment
) const
3225 const double pi
= 3.1415926535897932384626433832795 ;
3227 if (oglRoughlyEqual(GetRotation(), 0.0))
3229 i
= logicalAttachment
;
3231 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3233 i
= logicalAttachment
+ 1;
3235 else if (oglRoughlyEqual(GetRotation(), pi
))
3237 i
= logicalAttachment
+ 2;
3239 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3241 i
= logicalAttachment
+ 3;
3244 // Can't handle -- assume the same.
3245 return logicalAttachment
;
3253 void wxShape::Rotate(double WXUNUSED(x
), double WXUNUSED(y
), double theta
)
3255 const double pi
= 3.1415926535897932384626433832795 ;
3257 if (m_rotation
< 0.0)
3261 else if (m_rotation
> 2*pi
)
3268 wxPen
wxShape::GetBackgroundPen()
3272 wxColour c
= GetCanvas()->GetBackgroundColour();
3273 return wxPen(c
, 1, wxSOLID
);
3275 return * g_oglWhiteBackgroundPen
;
3279 wxBrush
wxShape::GetBackgroundBrush()
3283 wxColour c
= GetCanvas()->GetBackgroundColour();
3284 return wxBrush(c
, wxSOLID
);
3286 return * g_oglWhiteBackgroundBrush
;