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/wxexpr.h>
49 // Control point types
50 // Rectangle and most other shapes
51 #define CONTROL_POINT_VERTICAL 1
52 #define CONTROL_POINT_HORIZONTAL 2
53 #define CONTROL_POINT_DIAGONAL 3
56 #define CONTROL_POINT_ENDPOINT_TO 4
57 #define CONTROL_POINT_ENDPOINT_FROM 5
58 #define CONTROL_POINT_LINE 6
60 IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine
, wxObject
)
61 IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint
, wxObject
)
63 wxShapeTextLine::wxShapeTextLine(double the_x
, double the_y
, const wxString
& the_line
)
65 m_x
= the_x
; m_y
= the_y
; m_line
= the_line
;
68 wxShapeTextLine::~wxShapeTextLine()
72 IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler
, wxObject
)
74 wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler
*prev
, wxShape
*shape
)
76 m_previousHandler
= prev
;
77 m_handlerShape
= shape
;
80 wxShapeEvtHandler::~wxShapeEvtHandler()
84 // Creates a copy of this event handler.
85 wxShapeEvtHandler
* wxShapeEvtHandler::CreateNewCopy()
87 wxShapeEvtHandler
* newObject
= (wxShapeEvtHandler
*) GetClassInfo()->CreateObject();
89 wxASSERT( (newObject
!= NULL
) );
90 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShapeEvtHandler
))) );
92 newObject
->m_previousHandler
= newObject
;
100 void wxShapeEvtHandler::OnDelete()
102 if (this != GetShape())
106 void wxShapeEvtHandler::OnDraw(wxDC
& dc
)
108 if (m_previousHandler
)
109 m_previousHandler
->OnDraw(dc
);
112 void wxShapeEvtHandler::OnMoveLinks(wxDC
& dc
)
114 if (m_previousHandler
)
115 m_previousHandler
->OnMoveLinks(dc
);
118 void wxShapeEvtHandler::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
120 if (m_previousHandler
)
121 m_previousHandler
->OnMoveLink(dc
, moveControlPoints
);
124 void wxShapeEvtHandler::OnDrawContents(wxDC
& dc
)
126 if (m_previousHandler
)
127 m_previousHandler
->OnDrawContents(dc
);
130 void wxShapeEvtHandler::OnDrawBranches(wxDC
& dc
, bool erase
)
132 if (m_previousHandler
)
133 m_previousHandler
->OnDrawBranches(dc
, erase
);
136 void wxShapeEvtHandler::OnSize(double x
, double y
)
138 if (m_previousHandler
)
139 m_previousHandler
->OnSize(x
, y
);
142 bool wxShapeEvtHandler::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
144 if (m_previousHandler
)
145 return m_previousHandler
->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
);
150 void wxShapeEvtHandler::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
152 if (m_previousHandler
)
153 m_previousHandler
->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
156 void wxShapeEvtHandler::OnErase(wxDC
& dc
)
158 if (m_previousHandler
)
159 m_previousHandler
->OnErase(dc
);
162 void wxShapeEvtHandler::OnEraseContents(wxDC
& dc
)
164 if (m_previousHandler
)
165 m_previousHandler
->OnEraseContents(dc
);
168 void wxShapeEvtHandler::OnHighlight(wxDC
& dc
)
170 if (m_previousHandler
)
171 m_previousHandler
->OnHighlight(dc
);
174 void wxShapeEvtHandler::OnLeftClick(double x
, double y
, int keys
, int attachment
)
176 if (m_previousHandler
)
177 m_previousHandler
->OnLeftClick(x
, y
, keys
, attachment
);
180 void wxShapeEvtHandler::OnLeftDoubleClick(double x
, double y
, int keys
, int attachment
)
182 if (m_previousHandler
)
183 m_previousHandler
->OnLeftDoubleClick(x
, y
, keys
, attachment
);
186 void wxShapeEvtHandler::OnRightClick(double x
, double y
, int keys
, int attachment
)
188 if (m_previousHandler
)
189 m_previousHandler
->OnRightClick(x
, y
, keys
, attachment
);
192 void wxShapeEvtHandler::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
194 if (m_previousHandler
)
195 m_previousHandler
->OnDragLeft(draw
, x
, y
, keys
, attachment
);
198 void wxShapeEvtHandler::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
200 if (m_previousHandler
)
201 m_previousHandler
->OnBeginDragLeft(x
, y
, keys
, attachment
);
204 void wxShapeEvtHandler::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
206 if (m_previousHandler
)
207 m_previousHandler
->OnEndDragLeft(x
, y
, keys
, attachment
);
210 void wxShapeEvtHandler::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
212 if (m_previousHandler
)
213 m_previousHandler
->OnDragRight(draw
, x
, y
, keys
, attachment
);
216 void wxShapeEvtHandler::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
218 if (m_previousHandler
)
219 m_previousHandler
->OnBeginDragRight(x
, y
, keys
, attachment
);
222 void wxShapeEvtHandler::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
224 if (m_previousHandler
)
225 m_previousHandler
->OnEndDragRight(x
, y
, keys
, attachment
);
228 // Control points ('handles') redirect control to the actual shape, to make it easier
229 // to override sizing behaviour.
230 void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
232 if (m_previousHandler
)
233 m_previousHandler
->OnSizingDragLeft(pt
, draw
, x
, y
, keys
, attachment
);
236 void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
238 if (m_previousHandler
)
239 m_previousHandler
->OnSizingBeginDragLeft(pt
, x
, y
, keys
, attachment
);
242 void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
244 if (m_previousHandler
)
245 m_previousHandler
->OnSizingEndDragLeft(pt
, x
, y
, keys
, attachment
);
248 void wxShapeEvtHandler::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
250 if (m_previousHandler
)
251 m_previousHandler
->OnDrawOutline(dc
, x
, y
, w
, h
);
254 void wxShapeEvtHandler::OnDrawControlPoints(wxDC
& dc
)
256 if (m_previousHandler
)
257 m_previousHandler
->OnDrawControlPoints(dc
);
260 void wxShapeEvtHandler::OnEraseControlPoints(wxDC
& dc
)
262 if (m_previousHandler
)
263 m_previousHandler
->OnEraseControlPoints(dc
);
266 // Can override this to prevent or intercept line reordering.
267 void wxShapeEvtHandler::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
269 if (m_previousHandler
)
270 m_previousHandler
->OnChangeAttachment(attachment
, line
, ordering
);
273 IMPLEMENT_ABSTRACT_CLASS(wxShape
, wxShapeEvtHandler
)
275 wxShape::wxShape(wxShapeCanvas
*can
)
277 m_eventHandler
= this;
282 m_xpos
= 0.0; m_ypos
= 0.0;
283 m_pen
= g_oglBlackPen
;
284 m_brush
= wxWHITE_BRUSH
;
285 m_font
= g_oglNormalFont
;
286 m_textColour
= wxBLACK
;
287 m_textColourName
= "BLACK";
291 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
292 m_spaceAttachments
= TRUE
;
293 m_disableLabel
= FALSE
;
294 m_fixedWidth
= FALSE
;
295 m_fixedHeight
= FALSE
;
296 m_drawHandles
= TRUE
;
297 m_sensitivity
= OP_ALL
;
300 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
301 m_shadowMode
= SHADOW_NONE
;
302 m_shadowOffsetX
= 6.0;
303 m_shadowOffsetY
= 6.0;
304 m_shadowBrush
= wxBLACK_BRUSH
;
308 m_centreResize
= TRUE
;
309 m_maintainAspectRatio
= FALSE
;
310 m_highlighted
= FALSE
;
312 m_branchNeckLength
= 10;
313 m_branchStemLength
= 10;
314 m_branchSpacing
= 10;
315 m_branchStyle
= BRANCHING_ATTACHMENT_NORMAL
;
317 // Set up a default region. Much of the above will be put into
318 // the region eventually (the duplication is for compatibility)
319 wxShapeRegion
*region
= new wxShapeRegion
;
320 m_regions
.Append(region
);
321 region
->SetName("0");
322 region
->SetFont(g_oglNormalFont
);
323 region
->SetFormatMode(FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
);
324 region
->SetColour("BLACK");
330 m_parent
->GetChildren().DeleteObject(this);
337 m_canvas
->RemoveShape(this);
339 GetEventHandler()->OnDelete();
342 void wxShape::SetHighlight(bool hi
, bool recurse
)
347 wxNode
*node
= m_children
.First();
350 wxShape
*child
= (wxShape
*)node
->Data();
351 child
->SetHighlight(hi
, recurse
);
357 void wxShape::SetSensitivityFilter(int sens
, bool recursive
)
359 if (sens
& OP_DRAG_LEFT
)
364 m_sensitivity
= sens
;
367 wxNode
*node
= m_children
.First();
370 wxShape
*obj
= (wxShape
*)node
->Data();
371 obj
->SetSensitivityFilter(sens
, TRUE
);
377 void wxShape::SetDraggable(bool drag
, bool recursive
)
381 m_sensitivity
|= OP_DRAG_LEFT
;
383 if (m_sensitivity
& OP_DRAG_LEFT
)
384 m_sensitivity
= m_sensitivity
- OP_DRAG_LEFT
;
388 wxNode
*node
= m_children
.First();
391 wxShape
*obj
= (wxShape
*)node
->Data();
392 obj
->SetDraggable(drag
, TRUE
);
398 void wxShape::SetDrawHandles(bool drawH
)
400 m_drawHandles
= drawH
;
401 wxNode
*node
= m_children
.First();
404 wxShape
*obj
= (wxShape
*)node
->Data();
405 obj
->SetDrawHandles(drawH
);
410 void wxShape::SetShadowMode(int mode
, bool redraw
)
412 if (redraw
&& GetCanvas())
414 wxClientDC
dc(GetCanvas());
415 GetCanvas()->PrepareDC(dc
);
428 void wxShape::SetCanvas(wxShapeCanvas
*theCanvas
)
430 m_canvas
= theCanvas
;
431 wxNode
*node
= m_children
.First();
434 wxShape
*child
= (wxShape
*)node
->Data();
435 child
->SetCanvas(theCanvas
);
440 void wxShape::AddToCanvas(wxShapeCanvas
*theCanvas
, wxShape
*addAfter
)
442 theCanvas
->AddShape(this, addAfter
);
443 wxNode
*node
= m_children
.First();
444 wxShape
*lastImage
= this;
447 wxShape
*object
= (wxShape
*)node
->Data();
448 object
->AddToCanvas(theCanvas
, lastImage
);
455 // Insert at front of canvas
456 void wxShape::InsertInCanvas(wxShapeCanvas
*theCanvas
)
458 theCanvas
->InsertShape(this);
459 wxNode
*node
= m_children
.First();
460 wxShape
*lastImage
= this;
463 wxShape
*object
= (wxShape
*)node
->Data();
464 object
->AddToCanvas(theCanvas
, lastImage
);
471 void wxShape::RemoveFromCanvas(wxShapeCanvas
*theCanvas
)
475 theCanvas
->RemoveShape(this);
476 wxNode
*node
= m_children
.First();
479 wxShape
*object
= (wxShape
*)node
->Data();
480 object
->RemoveFromCanvas(theCanvas
);
486 void wxShape::ClearAttachments()
488 wxNode
*node
= m_attachmentPoints
.First();
491 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
495 m_attachmentPoints
.Clear();
498 void wxShape::ClearText(int regionId
)
502 m_text
.DeleteContents(TRUE
);
504 m_text
.DeleteContents(FALSE
);
506 wxNode
*node
= m_regions
.Nth(regionId
);
509 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
513 void wxShape::ClearRegions()
515 wxNode
*node
= m_regions
.First();
518 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
519 wxNode
*next
= node
->Next();
526 void wxShape::AddRegion(wxShapeRegion
*region
)
528 m_regions
.Append(region
);
531 void wxShape::SetDefaultRegionSize()
533 wxNode
*node
= m_regions
.First();
535 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
537 GetBoundingBoxMin(&w
, &h
);
538 region
->SetSize(w
, h
);
541 bool wxShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
546 double width
= 0.0, height
= 0.0;
547 GetBoundingBoxMin(&width
, &height
);
548 if (fabs(width
) < 4.0) width
= 4.0;
549 if (fabs(height
) < 4.0) height
= 4.0;
551 width
+= (double)4.0; height
+= (double)4.0; // Allowance for inaccurate mousing
553 double left
= (double)(m_xpos
- (width
/2.0));
554 double top
= (double)(m_ypos
- (height
/2.0));
555 double right
= (double)(m_xpos
+ (width
/2.0));
556 double bottom
= (double)(m_ypos
+ (height
/2.0));
558 int nearest_attachment
= 0;
560 // If within the bounding box, check the attachment points
561 // within the object.
563 if (x
>= left
&& x
<= right
&& y
>= top
&& y
<= bottom
)
565 int n
= GetNumberOfAttachments();
566 double nearest
= 999999.0;
568 // GetAttachmentPosition[Edge] takes a logical attachment position,
569 // i.e. if it's rotated through 90%, position 0 is East-facing.
571 for (int i
= 0; i
< n
; i
++)
574 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
576 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
577 ((yp
- y
) * (yp
- y
)));
582 nearest_attachment
= i
;
586 *attachment
= nearest_attachment
;
593 // Format a text string according to the region size, adding
594 // strings with positions to region text list
596 static bool GraphicsInSizeToContents
= FALSE
; // Infinite recursion elimination
597 void wxShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
602 if (m_regions
.Number() < 1)
604 wxNode
*node
= m_regions
.Nth(i
);
608 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
610 dc
.SetFont(region
->GetFont());
612 region
->GetSize(&w
, &h
);
614 wxStringList
*stringList
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
615 node
= stringList
->First();
618 char *s
= (char *)node
->Data();
619 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
620 region
->GetFormattedText().Append((wxObject
*)line
);
626 // Don't try to resize an object with more than one image (this case should be dealt
627 // with by overriden handlers)
628 if ((region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
) &&
629 (region
->GetFormattedText().Number() > 0) &&
630 (m_regions
.Number() == 1) && !GraphicsInSizeToContents
)
632 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
633 if ((actualW
+m_textMarginX
!= w
) || (actualH
+m_textMarginY
!= h
))
635 // If we are a descendant of a composite, must make sure the composite gets
637 wxShape
*topAncestor
= GetTopAncestor();
639 if (topAncestor
!= this)
641 // Make sure we don't recurse infinitely
642 GraphicsInSizeToContents
= TRUE
;
644 wxCompositeShape
*composite
= (wxCompositeShape
*)topAncestor
;
645 composite
->Erase(dc
);
646 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
647 Move(dc
, m_xpos
, m_ypos
);
648 composite
->CalculateSize();
649 if (composite
->Selected())
651 composite
->DeleteControlPoints(& dc
);
652 composite
->MakeControlPoints();
653 composite
->MakeMandatoryControlPoints();
655 // Where infinite recursion might happen if we didn't stop it
658 GraphicsInSizeToContents
= FALSE
;
663 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
664 Move(dc
, m_xpos
, m_ypos
);
666 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
667 Move(dc
, m_xpos
, m_ypos
);
671 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
675 void wxShape::Recentre(wxDC
& dc
)
678 GetBoundingBoxMin(&w
, &h
);
680 int noRegions
= m_regions
.Number();
681 for (int i
= 0; i
< noRegions
; i
++)
683 wxNode
*node
= m_regions
.Nth(i
);
686 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
687 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, region
->GetFormatMode());
692 bool wxShape::GetPerimeterPoint(double x1
, double y1
,
693 double x2
, double y2
,
694 double *x3
, double *y3
)
699 void wxShape::SetPen(wxPen
*the_pen
)
704 void wxShape::SetBrush(wxBrush
*the_brush
)
709 // Get the top-most (non-division) ancestor, or self
710 wxShape
*wxShape::GetTopAncestor()
715 if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape
)))
717 else return GetParent()->GetTopAncestor();
724 void wxShape::SetFont(wxFont
*the_font
, int regionId
)
727 wxNode
*node
= m_regions
.Nth(regionId
);
730 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
731 region
->SetFont(the_font
);
734 wxFont
*wxShape::GetFont(int n
) const
736 wxNode
*node
= m_regions
.Nth(n
);
739 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
740 return region
->GetFont();
743 void wxShape::SetFormatMode(int mode
, int regionId
)
745 wxNode
*node
= m_regions
.Nth(regionId
);
748 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
749 region
->SetFormatMode(mode
);
752 int wxShape::GetFormatMode(int regionId
) const
754 wxNode
*node
= m_regions
.Nth(regionId
);
757 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
758 return region
->GetFormatMode();
761 void wxShape::SetTextColour(const wxString
& the_colour
, int regionId
)
763 wxColour
*wxcolour
= wxTheColourDatabase
->FindColour(the_colour
);
764 m_textColour
= wxcolour
;
765 m_textColourName
= the_colour
;
767 wxNode
*node
= m_regions
.Nth(regionId
);
770 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
771 region
->SetColour(the_colour
);
774 wxString
wxShape::GetTextColour(int regionId
) const
776 wxNode
*node
= m_regions
.Nth(regionId
);
779 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
780 return region
->GetColour();
783 void wxShape::SetRegionName(const wxString
& name
, int regionId
)
785 wxNode
*node
= m_regions
.Nth(regionId
);
788 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
789 region
->SetName(name
);
792 wxString
wxShape::GetRegionName(int regionId
)
794 wxNode
*node
= m_regions
.Nth(regionId
);
797 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
798 return region
->GetName();
801 int wxShape::GetRegionId(const wxString
& name
)
803 wxNode
*node
= m_regions
.First();
807 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
808 if (region
->GetName() == name
)
816 // Name all m_regions in all subimages recursively.
817 void wxShape::NameRegions(const wxString
& parentName
)
819 int n
= GetNumberOfTextRegions();
821 for (int i
= 0; i
< n
; i
++)
823 if (parentName
.Length() > 0)
824 sprintf(buf
, "%s.%d", (const char*) parentName
, i
);
826 sprintf(buf
, "%d", i
);
827 SetRegionName(buf
, i
);
829 wxNode
*node
= m_children
.First();
833 wxShape
*child
= (wxShape
*)node
->Data();
834 if (parentName
.Length() > 0)
835 sprintf(buf
, "%s.%d", (const char*) parentName
, j
);
837 sprintf(buf
, "%d", j
);
838 child
->NameRegions(buf
);
844 // Get a region by name, possibly looking recursively into composites.
845 wxShape
*wxShape::FindRegion(const wxString
& name
, int *regionId
)
847 int id
= GetRegionId(name
);
854 wxNode
*node
= m_children
.First();
857 wxShape
*child
= (wxShape
*)node
->Data();
858 wxShape
*actualImage
= child
->FindRegion(name
, regionId
);
866 // Finds all region names for this image (composite or simple).
867 // Supply empty string list.
868 void wxShape::FindRegionNames(wxStringList
& list
)
870 int n
= GetNumberOfTextRegions();
871 for (int i
= 0; i
< n
; i
++)
873 wxString
name(GetRegionName(i
));
874 list
.Add((const char*) name
);
877 wxNode
*node
= m_children
.First();
880 wxShape
*child
= (wxShape
*)node
->Data();
881 child
->FindRegionNames(list
);
886 void wxShape::AssignNewIds()
890 wxNode
*node
= m_children
.First();
893 wxShape
*child
= (wxShape
*)node
->Data();
894 child
->AssignNewIds();
899 void wxShape::OnDraw(wxDC
& dc
)
903 void wxShape::OnMoveLinks(wxDC
& dc
)
905 // Want to set the ends of all attached links
906 // to point to/from this object
908 wxNode
*current
= m_lines
.First();
911 wxLineShape
*line
= (wxLineShape
*)current
->Data();
912 line
->GetEventHandler()->OnMoveLink(dc
);
913 current
= current
->Next();
918 void wxShape::OnDrawContents(wxDC
& dc
)
920 double bound_x
, bound_y
;
921 GetBoundingBoxMin(&bound_x
, &bound_y
);
922 if (m_regions
.Number() < 1) return;
924 if (m_pen
) dc
.SetPen(m_pen
);
926 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.First()->Data();
927 if (region
->GetFont()) dc
.SetFont(region
->GetFont());
929 dc
.SetTextForeground(* (region
->GetActualColourObject()));
930 dc
.SetBackgroundMode(wxTRANSPARENT
);
933 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
936 if (!GetDisableLabel())
938 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
942 void wxShape::DrawContents(wxDC
& dc
)
944 GetEventHandler()->OnDrawContents(dc
);
947 void wxShape::OnSize(double x
, double y
)
951 bool wxShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
956 void wxShape::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
960 void wxShape::OnErase(wxDC
& dc
)
966 wxNode
*current
= m_lines
.First();
969 wxLineShape
*line
= (wxLineShape
*)current
->Data();
970 line
->GetEventHandler()->OnErase(dc
);
971 current
= current
->Next();
973 GetEventHandler()->OnEraseContents(dc
);
976 void wxShape::OnEraseContents(wxDC
& dc
)
981 double maxX
, maxY
, minX
, minY
;
984 GetBoundingBoxMin(&minX
, &minY
);
985 GetBoundingBoxMax(&maxX
, &maxY
);
986 double topLeftX
= (double)(xp
- (maxX
/ 2.0) - 2.0);
987 double topLeftY
= (double)(yp
- (maxY
/ 2.0) - 2.0);
991 penWidth
= m_pen
->GetWidth();
993 dc
.SetPen(g_oglWhiteBackgroundPen
);
994 dc
.SetBrush(g_oglWhiteBackgroundBrush
);
995 dc
.DrawRectangle(WXROUND(topLeftX
- penWidth
), WXROUND(topLeftY
- penWidth
),
996 WXROUND(maxX
+ penWidth
*2.0 + 4.0), WXROUND(maxY
+ penWidth
*2.0 + 4.0));
999 void wxShape::EraseLinks(wxDC
& dc
, int attachment
, bool recurse
)
1004 wxNode
*current
= m_lines
.First();
1007 wxLineShape
*line
= (wxLineShape
*)current
->Data();
1008 if (attachment
== -1 || ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1009 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
)))
1010 line
->GetEventHandler()->OnErase(dc
);
1011 current
= current
->Next();
1015 wxNode
*node
= m_children
.First();
1018 wxShape
*child
= (wxShape
*)node
->Data();
1019 child
->EraseLinks(dc
, attachment
, recurse
);
1020 node
= node
->Next();
1025 void wxShape::DrawLinks(wxDC
& dc
, int attachment
, bool recurse
)
1030 wxNode
*current
= m_lines
.First();
1033 wxLineShape
*line
= (wxLineShape
*)current
->Data();
1034 if (attachment
== -1 ||
1035 (line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1036 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1038 current
= current
->Next();
1042 wxNode
*node
= m_children
.First();
1045 wxShape
*child
= (wxShape
*)node
->Data();
1046 child
->DrawLinks(dc
, attachment
, recurse
);
1047 node
= node
->Next();
1052 // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
1053 // edge of the shape.
1054 // attachmentPoint is the attachment point (= side) in question.
1056 // This is the default, rectangular implementation.
1057 bool wxShape::AttachmentSortTest(int attachmentPoint
, const wxRealPoint
& pt1
, const wxRealPoint
& pt2
)
1059 int physicalAttachment
= LogicalToPhysicalAttachment(attachmentPoint
);
1060 switch (physicalAttachment
)
1065 return (pt1
.x
<= pt2
.x
) ;
1071 return (pt1
.y
<= pt2
.y
) ;
1079 bool wxShape::MoveLineToNewAttachment(wxDC
& dc
, wxLineShape
*to_move
,
1082 if (GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1085 int newAttachment
, oldAttachment
;
1088 // Is (x, y) on this object? If so, find the new attachment point
1089 // the user has moved the point to
1090 bool hit
= HitTest(x
, y
, &newAttachment
, &distance
);
1096 if (to_move
->GetTo() == this)
1097 oldAttachment
= to_move
->GetAttachmentTo();
1099 oldAttachment
= to_move
->GetAttachmentFrom();
1101 // The links in a new ordering.
1104 // First, add all links to the new list.
1105 wxNode
*node
= m_lines
.First();
1108 newOrdering
.Append(node
->Data());
1109 node
= node
->Next();
1112 // Delete the line object from the list of links; we're going to move
1113 // it to another position in the list
1114 newOrdering
.DeleteObject(to_move
);
1116 double old_x
= (double) -99999.9;
1117 double old_y
= (double) -99999.9;
1119 node
= newOrdering
.First();
1122 while (!found
&& node
)
1124 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1125 if ((line
->GetTo() == this && oldAttachment
== line
->GetAttachmentTo()) ||
1126 (line
->GetFrom() == this && oldAttachment
== line
->GetAttachmentFrom()))
1128 double startX
, startY
, endX
, endY
;
1130 line
->GetEnds(&startX
, &startY
, &endX
, &endY
);
1131 if (line
->GetTo() == this)
1141 wxRealPoint
thisPoint(xp
, yp
);
1142 wxRealPoint
lastPoint(old_x
, old_y
);
1143 wxRealPoint
newPoint(x
, y
);
1145 if (AttachmentSortTest(newAttachment
, newPoint
, thisPoint
) && AttachmentSortTest(newAttachment
, lastPoint
, newPoint
))
1148 newOrdering
.Insert(node
, to_move
);
1154 node
= node
->Next();
1158 newOrdering
.Append(to_move
);
1160 GetEventHandler()->OnChangeAttachment(newAttachment
, to_move
, newOrdering
);
1165 void wxShape::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
1167 if (line
->GetTo() == this)
1168 line
->SetAttachmentTo(attachment
);
1170 line
->SetAttachmentFrom(attachment
);
1172 ApplyAttachmentOrdering(ordering
);
1174 wxClientDC
dc(GetCanvas());
1175 GetCanvas()->PrepareDC(dc
);
1179 if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc
);
1182 // Reorders the lines according to the given list.
1183 void wxShape::ApplyAttachmentOrdering(wxList
& linesToSort
)
1185 // This is a temporary store of all the lines.
1188 wxNode
*node
= m_lines
.First();
1191 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1192 linesStore
.Append(line
);
1193 node
= node
->Next();;
1198 node
= linesToSort
.First();
1201 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1202 if (linesStore
.Member(line
))
1205 linesStore
.DeleteObject(line
);
1206 m_lines
.Append(line
);
1208 node
= node
->Next();
1211 // Now add any lines that haven't been listed in linesToSort.
1212 node
= linesStore
.First();
1215 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1216 m_lines
.Append(line
);
1217 node
= node
->Next();
1221 // Reorders the lines coming into the node image at this attachment
1222 // position, in the order in which they appear in linesToSort.
1223 // Any remaining lines not in the list will be added to the end.
1224 void wxShape::SortLines(int attachment
, wxList
& linesToSort
)
1226 // This is a temporary store of all the lines at this attachment
1227 // point. We'll tick them off as we've processed them.
1228 wxList linesAtThisAttachment
;
1230 wxNode
*node
= m_lines
.First();
1233 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1234 wxNode
*next
= node
->Next();
1235 if ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1236 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1238 linesAtThisAttachment
.Append(line
);
1242 else node
= node
->Next();
1245 node
= linesToSort
.First();
1248 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1249 if (linesAtThisAttachment
.Member(line
))
1252 linesAtThisAttachment
.DeleteObject(line
);
1253 m_lines
.Append(line
);
1255 node
= node
->Next();
1258 // Now add any lines that haven't been listed in linesToSort.
1259 node
= linesAtThisAttachment
.First();
1262 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1263 m_lines
.Append(line
);
1264 node
= node
->Next();
1268 void wxShape::OnHighlight(wxDC
& dc
)
1272 void wxShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
1274 if ((m_sensitivity
& OP_CLICK_LEFT
) != OP_CLICK_LEFT
)
1280 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1281 m_parent
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
1287 void wxShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
1289 if ((m_sensitivity
& OP_CLICK_RIGHT
) != OP_CLICK_RIGHT
)
1295 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1296 m_parent
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);
1302 double DragOffsetX
= 0.0;
1303 double DragOffsetY
= 0.0;
1305 void wxShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1307 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1313 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1314 m_parent
->GetEventHandler()->OnDragLeft(draw
, x
, y
, keys
, attachment
);
1319 wxClientDC
dc(GetCanvas());
1320 GetCanvas()->PrepareDC(dc
);
1322 dc
.SetLogicalFunction(wxXOR
);
1324 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1325 dc
.SetPen(dottedPen
);
1326 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1329 xx
= x
+ DragOffsetX
;
1330 yy
= y
+ DragOffsetY
;
1332 m_canvas
->Snap(&xx
, &yy
);
1333 // m_xpos = xx; m_ypos = yy;
1335 GetBoundingBoxMax(&w
, &h
);
1336 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1339 void wxShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1341 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1347 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1348 m_parent
->GetEventHandler()->OnBeginDragLeft(x
, y
, keys
, attachment
);
1353 DragOffsetX
= m_xpos
- x
;
1354 DragOffsetY
= m_ypos
- y
;
1356 wxClientDC
dc(GetCanvas());
1357 GetCanvas()->PrepareDC(dc
);
1359 // New policy: don't erase shape until end of drag.
1363 xx
= x
+ DragOffsetX
;
1364 yy
= y
+ DragOffsetY
;
1365 m_canvas
->Snap(&xx
, &yy
);
1366 // m_xpos = xx; m_ypos = yy;
1367 dc
.SetLogicalFunction(wxXOR
);
1369 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1370 dc
.SetPen(dottedPen
);
1371 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1374 GetBoundingBoxMax(&w
, &h
);
1375 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1376 m_canvas
->CaptureMouse();
1379 void wxShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1381 m_canvas
->ReleaseMouse();
1382 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1388 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1389 m_parent
->GetEventHandler()->OnEndDragLeft(x
, y
, keys
, attachment
);
1394 wxClientDC
dc(GetCanvas());
1395 GetCanvas()->PrepareDC(dc
);
1397 dc
.SetLogicalFunction(wxCOPY
);
1399 double xx
= x
+ DragOffsetX
;
1400 double yy
= y
+ DragOffsetY
;
1401 m_canvas
->Snap(&xx
, &yy
);
1402 // canvas->Snap(&m_xpos, &m_ypos);
1404 // New policy: erase shape at end of drag.
1408 if (m_canvas
&& !m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1411 void wxShape::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1413 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1419 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1420 m_parent
->GetEventHandler()->OnDragRight(draw
, x
, y
, keys
, attachment
);
1426 void wxShape::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1428 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1434 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1435 m_parent
->GetEventHandler()->OnBeginDragRight(x
, y
, keys
, attachment
);
1441 void wxShape::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1443 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1449 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1450 m_parent
->GetEventHandler()->OnEndDragRight(x
, y
, keys
, attachment
);
1456 void wxShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
1458 double top_left_x
= (double)(x
- w
/2.0);
1459 double top_left_y
= (double)(y
- h
/2.0);
1460 double top_right_x
= (double)(top_left_x
+ w
);
1461 double top_right_y
= (double)top_left_y
;
1462 double bottom_left_x
= (double)top_left_x
;
1463 double bottom_left_y
= (double)(top_left_y
+ h
);
1464 double bottom_right_x
= (double)top_right_x
;
1465 double bottom_right_y
= (double)bottom_left_y
;
1468 points
[0].x
= WXROUND(top_left_x
); points
[0].y
= WXROUND(top_left_y
);
1469 points
[1].x
= WXROUND(top_right_x
); points
[1].y
= WXROUND(top_right_y
);
1470 points
[2].x
= WXROUND(bottom_right_x
); points
[2].y
= WXROUND(bottom_right_y
);
1471 points
[3].x
= WXROUND(bottom_left_x
); points
[3].y
= WXROUND(bottom_left_y
);
1472 points
[4].x
= WXROUND(top_left_x
); points
[4].y
= WXROUND(top_left_y
);
1474 dc
.DrawLines(5, points
);
1477 void wxShape::Attach(wxShapeCanvas
*can
)
1482 void wxShape::Detach()
1487 void wxShape::Move(wxDC
& dc
, double x
, double y
, bool display
)
1489 double old_x
= m_xpos
;
1490 double old_y
= m_ypos
;
1492 if (!GetEventHandler()->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
))
1499 m_xpos
= x
; m_ypos
= y
;
1501 ResetControlPoints();
1508 GetEventHandler()->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
1511 void wxShape::MoveLinks(wxDC
& dc
)
1513 GetEventHandler()->OnMoveLinks(dc
);
1517 void wxShape::Draw(wxDC
& dc
)
1521 GetEventHandler()->OnDraw(dc
);
1522 GetEventHandler()->OnDrawContents(dc
);
1523 GetEventHandler()->OnDrawControlPoints(dc
);
1524 GetEventHandler()->OnDrawBranches(dc
);
1528 void wxShape::Flash()
1532 wxClientDC
dc(GetCanvas());
1533 GetCanvas()->PrepareDC(dc
);
1535 dc
.SetLogicalFunction(wxXOR
);
1537 dc
.SetLogicalFunction(wxCOPY
);
1542 void wxShape::Show(bool show
)
1545 wxNode
*node
= m_children
.First();
1548 wxShape
*image
= (wxShape
*)node
->Data();
1550 node
= node
->Next();
1554 void wxShape::Erase(wxDC
& dc
)
1556 GetEventHandler()->OnErase(dc
);
1557 GetEventHandler()->OnEraseControlPoints(dc
);
1558 GetEventHandler()->OnDrawBranches(dc
, TRUE
);
1561 void wxShape::EraseContents(wxDC
& dc
)
1563 GetEventHandler()->OnEraseContents(dc
);
1566 void wxShape::AddText(const wxString
& string
)
1568 wxNode
*node
= m_regions
.First();
1571 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1572 region
->ClearText();
1573 wxShapeTextLine
*new_line
=
1574 new wxShapeTextLine(0.0, 0.0, string
);
1575 region
->GetFormattedText().Append(new_line
);
1577 m_formatted
= FALSE
;
1580 void wxShape::SetSize(double x
, double y
, bool recursive
)
1582 SetAttachmentSize(x
, y
);
1583 SetDefaultRegionSize();
1586 void wxShape::SetAttachmentSize(double w
, double h
)
1590 double width
, height
;
1591 GetBoundingBoxMin(&width
, &height
);
1594 else scaleX
= w
/width
;
1597 else scaleY
= h
/height
;
1599 wxNode
*node
= m_attachmentPoints
.First();
1602 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
1603 point
->m_x
= (double)(point
->m_x
* scaleX
);
1604 point
->m_y
= (double)(point
->m_y
* scaleY
);
1605 node
= node
->Next();
1609 // Add line FROM this object
1610 void wxShape::AddLine(wxLineShape
*line
, wxShape
*other
,
1611 int attachFrom
, int attachTo
,
1612 // The line ordering
1613 int positionFrom
, int positionTo
)
1615 if (positionFrom
== -1)
1617 if (!m_lines
.Member(line
))
1618 m_lines
.Append(line
);
1622 // Don't preserve old ordering if we have new ordering instructions
1623 m_lines
.DeleteObject(line
);
1624 if (positionFrom
< m_lines
.Number())
1626 wxNode
* node
= m_lines
.Nth(positionFrom
);
1627 m_lines
.Insert(node
, line
);
1630 m_lines
.Append(line
);
1633 if (positionTo
== -1)
1635 if (!other
->m_lines
.Member(line
))
1636 other
->m_lines
.Append(line
);
1640 // Don't preserve old ordering if we have new ordering instructions
1641 other
->m_lines
.DeleteObject(line
);
1642 if (positionTo
< other
->m_lines
.Number())
1644 wxNode
* node
= other
->m_lines
.Nth(positionTo
);
1645 other
->m_lines
.Insert(node
, line
);
1648 other
->m_lines
.Append(line
);
1651 // Wrong: doesn't preserve ordering of shape already linked
1652 m_lines
.DeleteObject(line
);
1653 other
->m_lines
.DeleteObject(line
);
1655 if (positionFrom
== -1)
1656 m_lines
.Append(line
);
1659 if (positionFrom
< m_lines
.Number())
1661 wxNode
* node
= m_lines
.Nth(positionFrom
);
1662 m_lines
.Insert(node
, line
);
1665 m_lines
.Append(line
);
1668 if (positionTo
== -1)
1669 other
->m_lines
.Append(line
);
1672 if (positionTo
< other
->m_lines
.Number())
1674 wxNode
* node
= other
->m_lines
.Nth(positionTo
);
1675 other
->m_lines
.Insert(node
, line
);
1678 other
->m_lines
.Append(line
);
1682 line
->SetFrom(this);
1684 line
->SetAttachments(attachFrom
, attachTo
);
1687 void wxShape::RemoveLine(wxLineShape
*line
)
1689 if (line
->GetFrom() == this)
1690 line
->GetTo()->m_lines
.DeleteObject(line
);
1692 line
->GetFrom()->m_lines
.DeleteObject(line
);
1694 m_lines
.DeleteObject(line
);
1698 void wxShape::WriteAttributes(wxExpr
*clause
)
1700 clause
->AddAttributeValueString("type", GetClassInfo()->GetClassName());
1701 clause
->AddAttributeValue("id", m_id
);
1705 int penWidth
= m_pen
->GetWidth();
1706 int penStyle
= m_pen
->GetStyle();
1708 clause
->AddAttributeValue("pen_width", (long)penWidth
);
1709 if (penStyle
!= wxSOLID
)
1710 clause
->AddAttributeValue("pen_style", (long)penStyle
);
1712 wxString penColour
= wxTheColourDatabase
->FindName(m_pen
->GetColour());
1713 if (penColour
== "")
1715 wxString
hex(oglColourToHex(m_pen
->GetColour()));
1716 hex
= wxString("#") + hex
;
1717 clause
->AddAttributeValueString("pen_colour", hex
);
1719 else if (penColour
!= "BLACK")
1720 clause
->AddAttributeValueString("pen_colour", penColour
);
1725 wxString brushColour
= wxTheColourDatabase
->FindName(m_brush
->GetColour());
1727 if (brushColour
== "")
1729 wxString
hex(oglColourToHex(m_brush
->GetColour()));
1730 hex
= wxString("#") + hex
;
1731 clause
->AddAttributeValueString("brush_colour", hex
);
1733 else if (brushColour
!= "WHITE")
1734 clause
->AddAttributeValueString("brush_colour", brushColour
);
1736 if (m_brush
->GetStyle() != wxSOLID
)
1737 clause
->AddAttributeValue("brush_style", (long)m_brush
->GetStyle());
1742 int n_lines
= m_lines
.Number();
1745 wxExpr
*list
= new wxExpr(wxExprList
);
1746 wxNode
*node
= m_lines
.First();
1749 wxShape
*line
= (wxShape
*)node
->Data();
1750 wxExpr
*id_expr
= new wxExpr(line
->GetId());
1751 list
->Append(id_expr
);
1752 node
= node
->Next();
1754 clause
->AddAttributeValue("arcs", list
);
1757 // Miscellaneous members
1758 if (m_attachmentMode
!= 0)
1759 clause
->AddAttributeValue("use_attachments", (long)m_attachmentMode
);
1760 if (m_sensitivity
!= OP_ALL
)
1761 clause
->AddAttributeValue("sensitivity", (long)m_sensitivity
);
1762 if (!m_spaceAttachments
)
1763 clause
->AddAttributeValue("space_attachments", (long)m_spaceAttachments
);
1765 clause
->AddAttributeValue("fixed_width", (long)m_fixedWidth
);
1767 clause
->AddAttributeValue("fixed_height", (long)m_fixedHeight
);
1768 if (m_shadowMode
!= SHADOW_NONE
)
1769 clause
->AddAttributeValue("shadow_mode", (long)m_shadowMode
);
1770 if (m_centreResize
!= TRUE
)
1771 clause
->AddAttributeValue("centre_resize", (long)0);
1772 clause
->AddAttributeValue("maintain_aspect_ratio", (long) m_maintainAspectRatio
);
1773 if (m_highlighted
!= FALSE
)
1774 clause
->AddAttributeValue("hilite", (long)m_highlighted
);
1776 if (m_parent
) // For composite objects
1777 clause
->AddAttributeValue("parent", (long)m_parent
->GetId());
1779 if (m_rotation
!= 0.0)
1780 clause
->AddAttributeValue("rotation", m_rotation
);
1782 if (!this->IsKindOf(CLASSINFO(wxLineShape
)))
1784 clause
->AddAttributeValue("neck_length", (long) m_branchNeckLength
);
1785 clause
->AddAttributeValue("stem_length", (long) m_branchStemLength
);
1786 clause
->AddAttributeValue("branch_spacing", (long) m_branchSpacing
);
1787 clause
->AddAttributeValue("branch_style", (long) m_branchStyle
);
1790 // Write user-defined attachment points, if any
1791 if (m_attachmentPoints
.Number() > 0)
1793 wxExpr
*attachmentList
= new wxExpr(wxExprList
);
1794 wxNode
*node
= m_attachmentPoints
.First();
1797 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
1798 wxExpr
*pointExpr
= new wxExpr(wxExprList
);
1799 pointExpr
->Append(new wxExpr((long)point
->m_id
));
1800 pointExpr
->Append(new wxExpr(point
->m_x
));
1801 pointExpr
->Append(new wxExpr(point
->m_y
));
1802 attachmentList
->Append(pointExpr
);
1803 node
= node
->Next();
1805 clause
->AddAttributeValue("user_attachments", attachmentList
);
1808 // Write text regions
1809 WriteRegions(clause
);
1812 void wxShape::WriteRegions(wxExpr
*clause
)
1814 // Output regions as region1 = (...), region2 = (...), etc
1815 // and formatted text as text1 = (...), text2 = (...) etc.
1817 char regionNameBuf
[20];
1818 char textNameBuf
[20];
1819 wxNode
*node
= m_regions
.First();
1822 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1823 sprintf(regionNameBuf
, "region%d", regionNo
);
1824 sprintf(textNameBuf
, "text%d", regionNo
);
1826 // Original text and region attributes:
1827 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
1828 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
1829 wxExpr
*regionExpr
= new wxExpr(wxExprList
);
1830 regionExpr
->Append(new wxExpr(wxExprString
, (region
->m_regionName
? region
->m_regionName
: "")));
1831 regionExpr
->Append(new wxExpr(wxExprString
, (region
->m_regionText
? region
->m_regionText
: "")));
1833 regionExpr
->Append(new wxExpr(region
->m_x
));
1834 regionExpr
->Append(new wxExpr(region
->m_y
));
1835 regionExpr
->Append(new wxExpr(region
->GetWidth()));
1836 regionExpr
->Append(new wxExpr(region
->GetHeight()));
1838 regionExpr
->Append(new wxExpr(region
->m_minWidth
));
1839 regionExpr
->Append(new wxExpr(region
->m_minHeight
));
1840 regionExpr
->Append(new wxExpr(region
->m_regionProportionX
));
1841 regionExpr
->Append(new wxExpr(region
->m_regionProportionY
));
1843 regionExpr
->Append(new wxExpr((long)region
->m_formatMode
));
1845 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetPointSize() : 10)));
1846 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetFamily() : wxDEFAULT
)));
1847 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetStyle() : wxDEFAULT
)));
1848 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetWeight() : wxNORMAL
)));
1849 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_textColour
? region
->m_textColour
: "BLACK"));
1851 // New members for pen colour/style
1852 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_penColour
? region
->m_penColour
: "BLACK"));
1853 regionExpr
->Append(new wxExpr((long)region
->m_penStyle
));
1856 // text1 = ((x y string) (x y string) ...)
1857 wxExpr
*textExpr
= new wxExpr(wxExprList
);
1859 wxNode
*textNode
= region
->m_formattedText
.First();
1862 wxShapeTextLine
*line
= (wxShapeTextLine
*)textNode
->Data();
1863 wxExpr
*list2
= new wxExpr(wxExprList
);
1864 list2
->Append(new wxExpr(line
->GetX()));
1865 list2
->Append(new wxExpr(line
->GetY()));
1866 list2
->Append(new wxExpr(wxExprString
, line
->GetText()));
1867 textExpr
->Append(list2
);
1868 textNode
= textNode
->Next();
1871 // Now add both attributes to the clause
1872 clause
->AddAttributeValue(regionNameBuf
, regionExpr
);
1873 clause
->AddAttributeValue(textNameBuf
, textExpr
);
1875 node
= node
->Next();
1880 void wxShape::ReadAttributes(wxExpr
*clause
)
1882 clause
->GetAttributeValue("id", m_id
);
1885 clause
->GetAttributeValue("x", m_xpos
);
1886 clause
->GetAttributeValue("y", m_ypos
);
1888 // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
1890 wxExpr
*strings
= clause
->AttributeValue("text");
1891 if (strings
&& strings
->Type() == wxExprList
)
1893 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
1894 wxExpr
*node
= strings
->value
.first
;
1897 wxExpr
*string_expr
= node
;
1900 wxString
the_string("");
1902 // string_expr can either be a string, or a list of
1903 // 3 elements: x, y, and string.
1904 if (string_expr
->Type() == wxExprString
)
1906 the_string
= string_expr
->StringValue();
1907 m_formatted
= FALSE
;
1909 else if (string_expr
->Type() == wxExprList
)
1911 wxExpr
*first
= string_expr
->value
.first
;
1912 wxExpr
*second
= first
? first
->next
: NULL
;
1913 wxExpr
*third
= second
? second
->next
: NULL
;
1915 if (first
&& second
&& third
&&
1916 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
1917 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
1918 third
->Type() == wxExprString
)
1920 if (first
->Type() == wxExprReal
)
1921 the_x
= first
->RealValue();
1922 else the_x
= (double)first
->IntegerValue();
1924 if (second
->Type() == wxExprReal
)
1925 the_y
= second
->RealValue();
1926 else the_y
= (double)second
->IntegerValue();
1928 the_string
= third
->StringValue();
1931 wxShapeTextLine
*line
=
1932 new wxShapeTextLine(the_x
, the_y
, (char*) (const char*) the_string
);
1933 m_text
.Append(line
);
1939 wxString pen_string
= "";
1940 wxString brush_string
= "";
1942 int pen_style
= wxSOLID
;
1943 int brush_style
= wxSOLID
;
1944 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
1946 clause
->GetAttributeValue("pen_colour", pen_string
);
1947 clause
->GetAttributeValue("text_colour", m_textColourName
);
1949 SetTextColour(m_textColourName
);
1951 clause
->GetAttributeValue("region_name", m_regionName
);
1953 clause
->GetAttributeValue("brush_colour", brush_string
);
1954 clause
->GetAttributeValue("pen_width", pen_width
);
1955 clause
->GetAttributeValue("pen_style", pen_style
);
1956 clause
->GetAttributeValue("brush_style", brush_style
);
1958 int iVal
= (int) m_attachmentMode
;
1959 clause
->GetAttributeValue("use_attachments", iVal
);
1960 m_attachmentMode
= iVal
;
1962 clause
->GetAttributeValue("sensitivity", m_sensitivity
);
1964 iVal
= (int) m_spaceAttachments
;
1965 clause
->GetAttributeValue("space_attachments", iVal
);
1966 m_spaceAttachments
= (iVal
!= 0);
1968 iVal
= (int) m_fixedWidth
;
1969 clause
->GetAttributeValue("fixed_width", iVal
);
1970 m_fixedWidth
= (iVal
!= 0);
1972 iVal
= (int) m_fixedHeight
;
1973 clause
->GetAttributeValue("fixed_height", iVal
);
1974 m_fixedHeight
= (iVal
!= 0);
1976 clause
->GetAttributeValue("format_mode", m_formatMode
);
1977 clause
->GetAttributeValue("shadow_mode", m_shadowMode
);
1979 iVal
= m_branchNeckLength
;
1980 clause
->GetAttributeValue("neck_length", iVal
);
1981 m_branchNeckLength
= iVal
;
1983 iVal
= m_branchStemLength
;
1984 clause
->GetAttributeValue("stem_length", iVal
);
1985 m_branchStemLength
= iVal
;
1987 iVal
= m_branchSpacing
;
1988 clause
->GetAttributeValue("branch_spacing", iVal
);
1989 m_branchSpacing
= iVal
;
1991 clause
->GetAttributeValue("branch_style", m_branchStyle
);
1993 iVal
= (int) m_centreResize
;
1994 clause
->GetAttributeValue("centre_resize", iVal
);
1995 m_centreResize
= (iVal
!= 0);
1997 iVal
= (int) m_maintainAspectRatio
;
1998 clause
->GetAttributeValue("maintain_aspect_ratio", iVal
);
1999 m_maintainAspectRatio
= (iVal
!= 0);
2001 iVal
= (int) m_highlighted
;
2002 clause
->GetAttributeValue("hilite", iVal
);
2003 m_highlighted
= (iVal
!= 0);
2005 clause
->GetAttributeValue("rotation", m_rotation
);
2007 if (pen_string
== "")
2008 pen_string
= "BLACK";
2009 if (brush_string
== "")
2010 brush_string
= "WHITE";
2012 if (pen_string
[0] == '#')
2014 wxColour
col(oglHexToColour(pen_string
.After('#')));
2015 m_pen
= wxThePenList
->FindOrCreatePen(col
, pen_width
, pen_style
);
2018 m_pen
= wxThePenList
->FindOrCreatePen(pen_string
, pen_width
, pen_style
);
2021 m_pen
= wxBLACK_PEN
;
2023 if (brush_string
[0] == '#')
2025 wxColour
col(oglHexToColour(brush_string
.After('#')));
2026 m_brush
= wxTheBrushList
->FindOrCreateBrush(col
, brush_style
);
2029 m_brush
= wxTheBrushList
->FindOrCreateBrush(brush_string
, brush_style
);
2032 m_brush
= wxWHITE_BRUSH
;
2034 int point_size
= 10;
2035 clause
->GetAttributeValue("point_size", point_size
);
2036 SetFont(oglMatchFont(point_size
));
2038 // Read user-defined attachment points, if any
2039 wxExpr
*attachmentList
= clause
->AttributeValue("user_attachments");
2042 wxExpr
*pointExpr
= attachmentList
->GetFirst();
2045 wxExpr
*idExpr
= pointExpr
->Nth(0);
2046 wxExpr
*xExpr
= pointExpr
->Nth(1);
2047 wxExpr
*yExpr
= pointExpr
->Nth(2);
2048 if (idExpr
&& xExpr
&& yExpr
)
2050 wxAttachmentPoint
*point
= new wxAttachmentPoint
;
2051 point
->m_id
= (int)idExpr
->IntegerValue();
2052 point
->m_x
= xExpr
->RealValue();
2053 point
->m_y
= yExpr
->RealValue();
2054 m_attachmentPoints
.Append((wxObject
*)point
);
2056 pointExpr
= pointExpr
->GetNext();
2060 // Read text regions
2061 ReadRegions(clause
);
2064 void wxShape::ReadRegions(wxExpr
*clause
)
2068 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
2069 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
2071 char regionNameBuf
[20];
2072 char textNameBuf
[20];
2074 wxExpr
*regionExpr
= NULL
;
2075 wxExpr
*textExpr
= NULL
;
2076 sprintf(regionNameBuf
, "region%d", regionNo
);
2077 sprintf(textNameBuf
, "text%d", regionNo
);
2079 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
2081 while (regionExpr
= clause
->AttributeValue(regionNameBuf
))
2084 * Get the region information
2088 wxString
regionName("");
2089 wxString
regionText("");
2093 double height
= 0.0;
2094 double minWidth
= 5.0;
2095 double minHeight
= 5.0;
2096 double m_regionProportionX
= -1.0;
2097 double m_regionProportionY
= -1.0;
2098 int formatMode
= FORMAT_NONE
;
2100 int fontFamily
= wxSWISS
;
2101 int fontStyle
= wxNORMAL
;
2102 int fontWeight
= wxNORMAL
;
2103 wxString
regionTextColour("");
2104 wxString
penColour("");
2105 int penStyle
= wxSOLID
;
2107 if (regionExpr
->Type() == wxExprList
)
2109 wxExpr
*nameExpr
= regionExpr
->Nth(0);
2110 wxExpr
*textExpr
= regionExpr
->Nth(1);
2111 wxExpr
*xExpr
= regionExpr
->Nth(2);
2112 wxExpr
*yExpr
= regionExpr
->Nth(3);
2113 wxExpr
*widthExpr
= regionExpr
->Nth(4);
2114 wxExpr
*heightExpr
= regionExpr
->Nth(5);
2115 wxExpr
*minWidthExpr
= regionExpr
->Nth(6);
2116 wxExpr
*minHeightExpr
= regionExpr
->Nth(7);
2117 wxExpr
*propXExpr
= regionExpr
->Nth(8);
2118 wxExpr
*propYExpr
= regionExpr
->Nth(9);
2119 wxExpr
*formatExpr
= regionExpr
->Nth(10);
2120 wxExpr
*sizeExpr
= regionExpr
->Nth(11);
2121 wxExpr
*familyExpr
= regionExpr
->Nth(12);
2122 wxExpr
*styleExpr
= regionExpr
->Nth(13);
2123 wxExpr
*weightExpr
= regionExpr
->Nth(14);
2124 wxExpr
*colourExpr
= regionExpr
->Nth(15);
2125 wxExpr
*penColourExpr
= regionExpr
->Nth(16);
2126 wxExpr
*penStyleExpr
= regionExpr
->Nth(17);
2128 regionName
= nameExpr
->StringValue();
2129 regionText
= textExpr
->StringValue();
2131 x
= xExpr
->RealValue();
2132 y
= yExpr
->RealValue();
2134 width
= widthExpr
->RealValue();
2135 height
= heightExpr
->RealValue();
2137 minWidth
= minWidthExpr
->RealValue();
2138 minHeight
= minHeightExpr
->RealValue();
2140 m_regionProportionX
= propXExpr
->RealValue();
2141 m_regionProportionY
= propYExpr
->RealValue();
2143 formatMode
= (int) formatExpr
->IntegerValue();
2144 fontSize
= (int)sizeExpr
->IntegerValue();
2145 fontFamily
= (int)familyExpr
->IntegerValue();
2146 fontStyle
= (int)styleExpr
->IntegerValue();
2147 fontWeight
= (int)weightExpr
->IntegerValue();
2151 regionTextColour
= colourExpr
->StringValue();
2154 regionTextColour
= "BLACK";
2157 penColour
= penColourExpr
->StringValue();
2159 penStyle
= (int)penStyleExpr
->IntegerValue();
2161 wxFont
*font
= wxTheFontList
->FindOrCreateFont(fontSize
, fontFamily
, fontStyle
, fontWeight
);
2163 wxShapeRegion
*region
= new wxShapeRegion
;
2164 region
->SetProportions(m_regionProportionX
, m_regionProportionY
);
2165 region
->SetFont(font
);
2166 region
->SetSize(width
, height
);
2167 region
->SetPosition(x
, y
);
2168 region
->SetMinSize(minWidth
, minHeight
);
2169 region
->SetFormatMode(formatMode
);
2170 region
->SetPenStyle(penStyle
);
2171 if (penColour
!= "")
2172 region
->SetPenColour(penColour
);
2174 region
->m_textColour
= regionTextColour
;
2175 region
->m_regionText
= regionText
;
2176 region
->m_regionName
= regionName
;
2178 m_regions
.Append(region
);
2181 * Get the formatted text strings
2184 textExpr
= clause
->AttributeValue(textNameBuf
);
2185 if (textExpr
&& (textExpr
->Type() == wxExprList
))
2187 wxExpr
*node
= textExpr
->value
.first
;
2190 wxExpr
*string_expr
= node
;
2193 wxString
the_string("");
2195 // string_expr can either be a string, or a list of
2196 // 3 elements: x, y, and string.
2197 if (string_expr
->Type() == wxExprString
)
2199 the_string
= string_expr
->StringValue();
2200 m_formatted
= FALSE
;
2202 else if (string_expr
->Type() == wxExprList
)
2204 wxExpr
*first
= string_expr
->value
.first
;
2205 wxExpr
*second
= first
? first
->next
: NULL
;
2206 wxExpr
*third
= second
? second
->next
: NULL
;
2208 if (first
&& second
&& third
&&
2209 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
2210 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
2211 third
->Type() == wxExprString
)
2213 if (first
->Type() == wxExprReal
)
2214 the_x
= first
->RealValue();
2215 else the_x
= (double)first
->IntegerValue();
2217 if (second
->Type() == wxExprReal
)
2218 the_y
= second
->RealValue();
2219 else the_y
= (double)second
->IntegerValue();
2221 the_string
= third
->StringValue();
2226 wxShapeTextLine
*line
=
2227 new wxShapeTextLine(the_x
, the_y
, (char*) (const char*) the_string
);
2228 region
->m_formattedText
.Append(line
);
2235 sprintf(regionNameBuf
, "region%d", regionNo
);
2236 sprintf(textNameBuf
, "text%d", regionNo
);
2239 // Compatibility: check for no regions (old file).
2240 // Lines and divided rectangles must deal with this compatibility
2241 // theirselves. Composites _may_ not have any regions anyway.
2242 if ((m_regions
.Number() == 0) &&
2243 !this->IsKindOf(CLASSINFO(wxLineShape
)) && !this->IsKindOf(CLASSINFO(wxDividedShape
)) &&
2244 !this->IsKindOf(CLASSINFO(wxCompositeShape
)))
2246 wxShapeRegion
*newRegion
= new wxShapeRegion
;
2247 newRegion
->SetName("0");
2248 m_regions
.Append((wxObject
*)newRegion
);
2249 if (m_text
.Number() > 0)
2251 newRegion
->ClearText();
2252 wxNode
*node
= m_text
.First();
2255 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->Data();
2256 wxNode
*next
= node
->Next();
2257 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
2267 void wxShape::Copy(wxShape
& copy
)
2270 copy
.m_xpos
= m_xpos
;
2271 copy
.m_ypos
= m_ypos
;
2273 copy
.m_brush
= m_brush
;
2274 copy
.m_textColour
= m_textColour
;
2275 copy
.m_centreResize
= m_centreResize
;
2276 copy
.m_maintainAspectRatio
= m_maintainAspectRatio
;
2277 copy
.m_attachmentMode
= m_attachmentMode
;
2278 copy
.m_spaceAttachments
= m_spaceAttachments
;
2279 copy
.m_highlighted
= m_highlighted
;
2280 copy
.m_rotation
= m_rotation
;
2281 copy
.m_textColourName
= m_textColourName
;
2282 copy
.m_regionName
= m_regionName
;
2284 copy
.m_sensitivity
= m_sensitivity
;
2285 copy
.m_draggable
= m_draggable
;
2286 copy
.m_fixedWidth
= m_fixedWidth
;
2287 copy
.m_fixedHeight
= m_fixedHeight
;
2288 copy
.m_formatMode
= m_formatMode
;
2289 copy
.m_drawHandles
= m_drawHandles
;
2291 copy
.m_visible
= m_visible
;
2292 copy
.m_shadowMode
= m_shadowMode
;
2293 copy
.m_shadowOffsetX
= m_shadowOffsetX
;
2294 copy
.m_shadowOffsetY
= m_shadowOffsetY
;
2295 copy
.m_shadowBrush
= m_shadowBrush
;
2297 copy
.m_branchNeckLength
= m_branchNeckLength
;
2298 copy
.m_branchStemLength
= m_branchStemLength
;
2299 copy
.m_branchSpacing
= m_branchSpacing
;
2301 // Copy text regions
2302 copy
.ClearRegions();
2303 wxNode
*node
= m_regions
.First();
2306 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
2307 wxShapeRegion
*newRegion
= new wxShapeRegion(*region
);
2308 copy
.m_regions
.Append(newRegion
);
2309 node
= node
->Next();
2313 copy
.ClearAttachments();
2314 node
= m_attachmentPoints
.First();
2317 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2318 wxAttachmentPoint
*newPoint
= new wxAttachmentPoint
;
2319 newPoint
->m_id
= point
->m_id
;
2320 newPoint
->m_x
= point
->m_x
;
2321 newPoint
->m_y
= point
->m_y
;
2322 copy
.m_attachmentPoints
.Append((wxObject
*)newPoint
);
2323 node
= node
->Next();
2327 copy
.m_lines
.Clear();
2328 node
= m_lines
.First();
2331 wxLineShape
* line
= (wxLineShape
*) node
->Data();
2332 copy
.m_lines
.Append(line
);
2333 node
= node
->Next();
2337 // Create and return a new, fully copied object.
2338 wxShape
*wxShape::CreateNewCopy(bool resetMapping
, bool recompute
)
2341 oglObjectCopyMapping
.Clear();
2343 wxShape
* newObject
= (wxShape
*) GetClassInfo()->CreateObject();
2345 wxASSERT( (newObject
!= NULL
) );
2346 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShape
))) );
2350 if (GetEventHandler() != this)
2352 wxShapeEvtHandler
* newHandler
= GetEventHandler()->CreateNewCopy();
2353 newObject
->SetEventHandler(newHandler
);
2354 newObject
->SetPreviousHandler(NULL
);
2355 newHandler
->SetPreviousHandler(newObject
);
2356 newHandler
->SetShape(newObject
);
2360 newObject
->Recompute();
2364 // Does the copying for this object, including copying event
2365 // handler data if any. Calls the virtual Copy function.
2366 void wxShape::CopyWithHandler(wxShape
& copy
)
2370 if (GetEventHandler() != this)
2372 wxASSERT( copy
.GetEventHandler() != NULL
);
2373 wxASSERT( copy
.GetEventHandler() != (©
) );
2374 wxASSERT( GetEventHandler()->GetClassInfo() == copy
.GetEventHandler()->GetClassInfo() );
2375 GetEventHandler()->CopyData(* (copy
.GetEventHandler()));
2380 // Default - make 6 control points
2381 void wxShape::MakeControlPoints()
2383 double maxX
, maxY
, minX
, minY
;
2385 GetBoundingBoxMax(&maxX
, &maxY
);
2386 GetBoundingBoxMin(&minX
, &minY
);
2388 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2389 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2391 // Offsets from main object
2392 double top
= (double)(- (heightMin
/ 2.0));
2393 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2394 double left
= (double)(- (widthMin
/ 2.0));
2395 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2397 wxControlPoint
*control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, top
,
2398 CONTROL_POINT_DIAGONAL
);
2399 m_canvas
->AddShape(control
);
2400 m_controlPoints
.Append(control
);
2402 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, top
,
2403 CONTROL_POINT_VERTICAL
);
2404 m_canvas
->AddShape(control
);
2405 m_controlPoints
.Append(control
);
2407 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, top
,
2408 CONTROL_POINT_DIAGONAL
);
2409 m_canvas
->AddShape(control
);
2410 m_controlPoints
.Append(control
);
2412 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, 0,
2413 CONTROL_POINT_HORIZONTAL
);
2414 m_canvas
->AddShape(control
);
2415 m_controlPoints
.Append(control
);
2417 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, bottom
,
2418 CONTROL_POINT_DIAGONAL
);
2419 m_canvas
->AddShape(control
);
2420 m_controlPoints
.Append(control
);
2422 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, bottom
,
2423 CONTROL_POINT_VERTICAL
);
2424 m_canvas
->AddShape(control
);
2425 m_controlPoints
.Append(control
);
2427 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, bottom
,
2428 CONTROL_POINT_DIAGONAL
);
2429 m_canvas
->AddShape(control
);
2430 m_controlPoints
.Append(control
);
2432 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, 0,
2433 CONTROL_POINT_HORIZONTAL
);
2434 m_canvas
->AddShape(control
);
2435 m_controlPoints
.Append(control
);
2439 void wxShape::MakeMandatoryControlPoints()
2441 wxNode
*node
= m_children
.First();
2444 wxShape
*child
= (wxShape
*)node
->Data();
2445 child
->MakeMandatoryControlPoints();
2446 node
= node
->Next();
2450 void wxShape::ResetMandatoryControlPoints()
2452 wxNode
*node
= m_children
.First();
2455 wxShape
*child
= (wxShape
*)node
->Data();
2456 child
->ResetMandatoryControlPoints();
2457 node
= node
->Next();
2461 void wxShape::ResetControlPoints()
2463 ResetMandatoryControlPoints();
2465 if (m_controlPoints
.Number() < 1)
2468 double maxX
, maxY
, minX
, minY
;
2470 GetBoundingBoxMax(&maxX
, &maxY
);
2471 GetBoundingBoxMin(&minX
, &minY
);
2473 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2474 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2476 // Offsets from main object
2477 double top
= (double)(- (heightMin
/ 2.0));
2478 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2479 double left
= (double)(- (widthMin
/ 2.0));
2480 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2482 wxNode
*node
= m_controlPoints
.First();
2483 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2484 control
->m_xoffset
= left
; control
->m_yoffset
= top
;
2486 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2487 control
->m_xoffset
= 0; control
->m_yoffset
= top
;
2489 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2490 control
->m_xoffset
= right
; control
->m_yoffset
= top
;
2492 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2493 control
->m_xoffset
= right
; control
->m_yoffset
= 0;
2495 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2496 control
->m_xoffset
= right
; control
->m_yoffset
= bottom
;
2498 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2499 control
->m_xoffset
= 0; control
->m_yoffset
= bottom
;
2501 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2502 control
->m_xoffset
= left
; control
->m_yoffset
= bottom
;
2504 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2505 control
->m_xoffset
= left
; control
->m_yoffset
= 0;
2508 void wxShape::DeleteControlPoints(wxDC
*dc
)
2510 wxNode
*node
= m_controlPoints
.First();
2513 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2515 control
->GetEventHandler()->OnErase(*dc
);
2516 m_canvas
->RemoveShape(control
);
2519 node
= m_controlPoints
.First();
2521 // Children of divisions are contained objects,
2523 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2525 node
= m_children
.First();
2528 wxShape
*child
= (wxShape
*)node
->Data();
2529 child
->DeleteControlPoints(dc
);
2530 node
= node
->Next();
2535 void wxShape::OnDrawControlPoints(wxDC
& dc
)
2540 dc
.SetBrush(wxBLACK_BRUSH
);
2541 dc
.SetPen(wxBLACK_PEN
);
2543 wxNode
*node
= m_controlPoints
.First();
2546 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2548 node
= node
->Next();
2550 // Children of divisions are contained objects,
2552 // This test bypasses the type facility for speed
2553 // (critical when drawing)
2554 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2556 node
= m_children
.First();
2559 wxShape
*child
= (wxShape
*)node
->Data();
2560 child
->GetEventHandler()->OnDrawControlPoints(dc
);
2561 node
= node
->Next();
2566 void wxShape::OnEraseControlPoints(wxDC
& dc
)
2568 wxNode
*node
= m_controlPoints
.First();
2571 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2573 node
= node
->Next();
2575 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2577 node
= m_children
.First();
2580 wxShape
*child
= (wxShape
*)node
->Data();
2581 child
->GetEventHandler()->OnEraseControlPoints(dc
);
2582 node
= node
->Next();
2587 void wxShape::Select(bool select
, wxDC
* dc
)
2589 m_selected
= select
;
2592 MakeControlPoints();
2593 // Children of divisions are contained objects,
2595 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2597 wxNode
*node
= m_children
.First();
2600 wxShape
*child
= (wxShape
*)node
->Data();
2601 child
->MakeMandatoryControlPoints();
2602 node
= node
->Next();
2606 GetEventHandler()->OnDrawControlPoints(*dc
);
2610 DeleteControlPoints(dc
);
2611 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2613 wxNode
*node
= m_children
.First();
2616 wxShape
*child
= (wxShape
*)node
->Data();
2617 child
->DeleteControlPoints(dc
);
2618 node
= node
->Next();
2624 bool wxShape::Selected() const
2629 bool wxShape::AncestorSelected() const
2631 if (m_selected
) return TRUE
;
2635 return GetParent()->AncestorSelected();
2638 int wxShape::GetNumberOfAttachments() const
2640 // Should return the MAXIMUM attachment point id here,
2641 // so higher-level functions can iterate through all attachments,
2642 // even if they're not contiguous.
2643 if (m_attachmentPoints
.Number() == 0)
2648 wxNode
*node
= m_attachmentPoints
.First();
2651 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2652 if (point
->m_id
> maxN
)
2654 node
= node
->Next();
2660 bool wxShape::AttachmentIsValid(int attachment
) const
2662 if (m_attachmentPoints
.Number() == 0)
2664 return ((attachment
>= 0) && (attachment
< 4)) ;
2667 wxNode
*node
= m_attachmentPoints
.First();
2670 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2671 if (point
->m_id
== attachment
)
2673 node
= node
->Next();
2678 bool wxShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
2679 int nth
, int no_arcs
, wxLineShape
*line
)
2681 if (m_attachmentMode
== ATTACHMENT_MODE_NONE
)
2683 *x
= m_xpos
; *y
= m_ypos
;
2686 else if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
2688 wxRealPoint pt
, stemPt
;
2689 GetBranchingAttachmentPoint(attachment
, nth
, pt
, stemPt
);
2694 else if (m_attachmentMode
== ATTACHMENT_MODE_EDGE
)
2696 if (m_attachmentPoints
.Number() > 0)
2698 wxNode
*node
= m_attachmentPoints
.First();
2701 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2702 if (point
->m_id
== attachment
)
2704 *x
= (double)(m_xpos
+ point
->m_x
);
2705 *y
= (double)(m_ypos
+ point
->m_y
);
2708 node
= node
->Next();
2710 *x
= m_xpos
; *y
= m_ypos
;
2715 // Assume is rectangular
2717 GetBoundingBoxMax(&w
, &h
);
2718 double top
= (double)(m_ypos
+ h
/2.0);
2719 double bottom
= (double)(m_ypos
- h
/2.0);
2720 double left
= (double)(m_xpos
- w
/2.0);
2721 double right
= (double)(m_xpos
+ w
/2.0);
2723 bool isEnd
= (line
&& line
->IsEnd(this));
2725 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2728 switch (physicalAttachment
)
2732 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(right
, bottom
),
2733 nth
, no_arcs
, line
);
2735 *x
= pt
.x
; *y
= pt
.y
;
2740 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(right
, bottom
), wxRealPoint(right
, top
),
2741 nth
, no_arcs
, line
);
2743 *x
= pt
.x
; *y
= pt
.y
;
2748 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, top
), wxRealPoint(right
, top
),
2749 nth
, no_arcs
, line
);
2751 *x
= pt
.x
; *y
= pt
.y
;
2756 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(left
, top
),
2757 nth
, no_arcs
, line
);
2759 *x
= pt
.x
; *y
= pt
.y
;
2774 void wxShape::GetBoundingBoxMax(double *w
, double *h
)
2777 GetBoundingBoxMin(&ww
, &hh
);
2778 if (m_shadowMode
!= SHADOW_NONE
)
2780 ww
+= m_shadowOffsetX
;
2781 hh
+= m_shadowOffsetY
;
2787 // Returns TRUE if image is a descendant of this composite
2788 bool wxShape::HasDescendant(wxShape
*image
)
2792 wxNode
*node
= m_children
.First();
2795 wxShape
*child
= (wxShape
*)node
->Data();
2796 bool ans
= child
->HasDescendant(image
);
2799 node
= node
->Next();
2804 // Clears points from a list of wxRealPoints, and clears list
2805 void wxShape::ClearPointList(wxList
& list
)
2807 wxNode
* node
= list
.First();
2810 wxRealPoint
* pt
= (wxRealPoint
*) node
->Data();
2813 node
= node
->Next();
2818 // Assuming the attachment lies along a vertical or horizontal line,
2819 // calculate the position on that point.
2820 wxRealPoint
wxShape::CalcSimpleAttachment(const wxRealPoint
& pt1
, const wxRealPoint
& pt2
,
2821 int nth
, int noArcs
, wxLineShape
* line
)
2823 bool isEnd
= (line
&& line
->IsEnd(this));
2825 // Are we horizontal or vertical?
2826 bool isHorizontal
= (oglRoughlyEqual(pt1
.y
, pt2
.y
) == TRUE
);
2832 wxRealPoint firstPoint
, secondPoint
;
2844 if (m_spaceAttachments
)
2846 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2848 // Align line according to the next handle along
2849 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2850 if (point
->x
< firstPoint
.x
)
2852 else if (point
->x
> secondPoint
.x
)
2858 x
= firstPoint
.x
+ (nth
+ 1)*(secondPoint
.x
- firstPoint
.x
)/(noArcs
+ 1);
2860 else x
= (secondPoint
.x
- firstPoint
.x
)/2.0; // Midpoint
2866 wxASSERT( oglRoughlyEqual(pt1
.x
, pt2
.x
) == TRUE
);
2868 wxRealPoint firstPoint
, secondPoint
;
2880 if (m_spaceAttachments
)
2882 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2884 // Align line according to the next handle along
2885 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2886 if (point
->y
< firstPoint
.y
)
2888 else if (point
->y
> secondPoint
.y
)
2894 y
= firstPoint
.y
+ (nth
+ 1)*(secondPoint
.y
- firstPoint
.y
)/(noArcs
+ 1);
2896 else y
= (secondPoint
.y
- firstPoint
.y
)/2.0; // Midpoint
2901 return wxRealPoint(x
, y
);
2904 // Return the zero-based position in m_lines of line.
2905 int wxShape::GetLinePosition(wxLineShape
* line
)
2908 for (i
= 0; i
< m_lines
.Number(); i
++)
2909 if ((wxLineShape
*) (m_lines
.Nth(i
)->Data()) == line
)
2919 // shoulder1 ->---------<- shoulder2
2921 // <- branching attachment point N-1
2923 // This function gets information about where branching connections go.
2924 // Returns FALSE if there are no lines at this attachment.
2925 bool wxShape::GetBranchingAttachmentInfo(int attachment
, wxRealPoint
& root
, wxRealPoint
& neck
,
2926 wxRealPoint
& shoulder1
, wxRealPoint
& shoulder2
)
2928 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2930 // Number of lines at this attachment.
2931 int lineCount
= GetAttachmentLineCount(attachment
);
2936 int totalBranchLength
= m_branchSpacing
* (lineCount
- 1);
2938 root
= GetBranchingAttachmentRoot(attachment
);
2940 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
2941 switch (physicalAttachment
)
2946 neck
.y
= root
.y
- m_branchNeckLength
;
2948 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2949 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2951 shoulder1
.y
= neck
.y
;
2952 shoulder2
.y
= neck
.y
;
2957 neck
.x
= root
.x
+ m_branchNeckLength
;
2960 shoulder1
.x
= neck
.x
;
2961 shoulder2
.x
= neck
.x
;
2963 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2964 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2970 neck
.y
= root
.y
+ m_branchNeckLength
;
2972 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2973 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2975 shoulder1
.y
= neck
.y
;
2976 shoulder2
.y
= neck
.y
;
2981 neck
.x
= root
.x
- m_branchNeckLength
;
2984 shoulder1
.x
= neck
.x
;
2985 shoulder2
.x
= neck
.x
;
2987 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2988 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2993 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentInfo." );
3000 // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
3001 // at this attachment point.
3002 // Get the attachment point where the arc joins the stem, and also the point where the
3003 // the stem meets the shoulder.
3004 bool wxShape::GetBranchingAttachmentPoint(int attachment
, int n
, wxRealPoint
& pt
, wxRealPoint
& stemPt
)
3006 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3008 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3009 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3011 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3012 switch (physicalAttachment
)
3016 pt
.y
= neck
.y
- m_branchStemLength
;
3017 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3025 pt
.y
= neck
.y
+ m_branchStemLength
;
3026 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3034 pt
.x
= neck
.x
+ m_branchStemLength
;
3035 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3043 pt
.x
= neck
.x
- m_branchStemLength
;
3044 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3052 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentPoint." );
3060 // Get the number of lines at this attachment position.
3061 int wxShape::GetAttachmentLineCount(int attachment
) const
3064 wxNode
* node
= m_lines
.First();
3067 wxLineShape
* lineShape
= (wxLineShape
*) node
->Data();
3068 if ((lineShape
->GetFrom() == this) && (lineShape
->GetAttachmentFrom() == attachment
))
3070 else if ((lineShape
->GetTo() == this) && (lineShape
->GetAttachmentTo() == attachment
))
3073 node
= node
->Next();
3078 // This function gets the root point at the given attachment.
3079 wxRealPoint
wxShape::GetBranchingAttachmentRoot(int attachment
)
3081 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3085 double width
, height
;
3086 GetBoundingBoxMax(& width
, & height
);
3088 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3089 switch (physicalAttachment
)
3094 root
.y
= GetY() - height
/2.0;
3099 root
.x
= GetX() + width
/2.0;
3106 root
.y
= GetY() + height
/2.0;
3111 root
.x
= GetX() - width
/2.0;
3117 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentRoot." );
3124 // Draw or erase the branches (not the actual arcs though)
3125 void wxShape::OnDrawBranches(wxDC
& dc
, int attachment
, bool erase
)
3127 int count
= GetAttachmentLineCount(attachment
);
3131 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3132 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3136 dc
.SetPen(*wxWHITE_PEN
);
3137 dc
.SetBrush(*wxWHITE_BRUSH
);
3141 dc
.SetPen(*wxBLACK_PEN
);
3142 dc
.SetBrush(*wxBLACK_BRUSH
);
3146 dc
.DrawLine((long) root
.x
, (long) root
.y
, (long) neck
.x
, (long) neck
.y
);
3150 // Draw shoulder-to-shoulder line
3151 dc
.DrawLine((long) shoulder1
.x
, (long) shoulder1
.y
, (long) shoulder2
.x
, (long) shoulder2
.y
);
3153 // Draw all the little branches
3155 for (i
= 0; i
< count
; i
++)
3157 wxRealPoint pt
, stemPt
;
3158 GetBranchingAttachmentPoint(attachment
, i
, pt
, stemPt
);
3159 dc
.DrawLine((long) stemPt
.x
, (long) stemPt
.y
, (long) pt
.x
, (long) pt
.y
);
3161 if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB
) && (count
> 1))
3164 // dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
3165 dc
.DrawEllipse((long) (stemPt
.x
- (blobSize
/2.0)), (long) (stemPt
.y
- (blobSize
/2.0)), blobSize
, blobSize
);
3170 // Draw or erase the branches (not the actual arcs though)
3171 void wxShape::OnDrawBranches(wxDC
& dc
, bool erase
)
3173 if (m_attachmentMode
!= ATTACHMENT_MODE_BRANCHING
)
3176 int count
= GetNumberOfAttachments();
3178 for (i
= 0; i
< count
; i
++)
3179 OnDrawBranches(dc
, i
, erase
);
3182 // Only get the attachment position at the _edge_ of the shape, ignoring
3183 // branching mode. This is used e.g. to indicate the edge of interest, not the point
3184 // on the attachment branch.
3185 bool wxShape::GetAttachmentPositionEdge(int attachment
, double *x
, double *y
,
3186 int nth
, int no_arcs
, wxLineShape
*line
)
3188 int oldMode
= m_attachmentMode
;
3190 // Calculate as if to edge, not branch
3191 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
3192 m_attachmentMode
= ATTACHMENT_MODE_EDGE
;
3193 bool success
= GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
3194 m_attachmentMode
= oldMode
;
3199 // Rotate the standard attachment point from physical (0 is always North)
3200 // to logical (0 -> 1 if rotated by 90 degrees)
3201 int wxShape::PhysicalToLogicalAttachment(int physicalAttachment
) const
3203 const double pi
= 3.1415926535897932384626433832795 ;
3205 if (oglRoughlyEqual(GetRotation(), 0.0))
3207 i
= physicalAttachment
;
3209 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3211 i
= physicalAttachment
- 1;
3213 else if (oglRoughlyEqual(GetRotation(), pi
))
3215 i
= physicalAttachment
- 2;
3217 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3219 i
= physicalAttachment
- 3;
3222 // Can't handle -- assume the same.
3223 return physicalAttachment
;
3231 // Rotate the standard attachment point from logical
3232 // to physical (0 is always North)
3233 int wxShape::LogicalToPhysicalAttachment(int logicalAttachment
) const
3235 const double pi
= 3.1415926535897932384626433832795 ;
3237 if (oglRoughlyEqual(GetRotation(), 0.0))
3239 i
= logicalAttachment
;
3241 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3243 i
= logicalAttachment
+ 1;
3245 else if (oglRoughlyEqual(GetRotation(), pi
))
3247 i
= logicalAttachment
+ 2;
3249 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3251 i
= logicalAttachment
+ 3;
3254 // Can't handle -- assume the same.
3255 return logicalAttachment
;
3263 void wxShape::Rotate(double WXUNUSED(x
), double WXUNUSED(y
), double theta
)
3265 const double pi
= 3.1415926535897932384626433832795 ;
3267 if (m_rotation
< 0.0)
3271 else if (m_rotation
> 2*pi
)