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>
27 #include <wx/wxexpr.h>
39 #include <wx/ogl/basic.h>
40 #include <wx/ogl/basicp.h>
41 #include <wx/ogl/composit.h>
42 #include <wx/ogl/lines.h>
43 #include <wx/ogl/canvas.h>
44 #include <wx/ogl/divided.h>
45 #include <wx/ogl/misc.h>
47 // Control point types
48 // Rectangle and most other shapes
49 #define CONTROL_POINT_VERTICAL 1
50 #define CONTROL_POINT_HORIZONTAL 2
51 #define CONTROL_POINT_DIAGONAL 3
54 #define CONTROL_POINT_ENDPOINT_TO 4
55 #define CONTROL_POINT_ENDPOINT_FROM 5
56 #define CONTROL_POINT_LINE 6
58 IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine
, wxObject
)
59 IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint
, wxObject
)
61 wxShapeTextLine::wxShapeTextLine(double the_x
, double the_y
, const wxString
& the_line
)
63 m_x
= the_x
; m_y
= the_y
; m_line
= the_line
;
66 wxShapeTextLine::~wxShapeTextLine()
70 IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler
, wxObject
)
72 wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler
*prev
, wxShape
*shape
)
74 m_previousHandler
= prev
;
75 m_handlerShape
= shape
;
78 wxShapeEvtHandler::~wxShapeEvtHandler()
82 // Creates a copy of this event handler.
83 wxShapeEvtHandler
* wxShapeEvtHandler::CreateNewCopy()
85 wxShapeEvtHandler
* newObject
= (wxShapeEvtHandler
*) GetClassInfo()->CreateObject();
87 wxASSERT( (newObject
!= NULL
) );
88 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShapeEvtHandler
))) );
90 newObject
->m_previousHandler
= newObject
;
98 void wxShapeEvtHandler::OnDelete()
100 if (this != GetShape())
104 void wxShapeEvtHandler::OnDraw(wxDC
& dc
)
106 if (m_previousHandler
)
107 m_previousHandler
->OnDraw(dc
);
110 void wxShapeEvtHandler::OnMoveLinks(wxDC
& dc
)
112 if (m_previousHandler
)
113 m_previousHandler
->OnMoveLinks(dc
);
116 void wxShapeEvtHandler::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
118 if (m_previousHandler
)
119 m_previousHandler
->OnMoveLink(dc
, moveControlPoints
);
122 void wxShapeEvtHandler::OnDrawContents(wxDC
& dc
)
124 if (m_previousHandler
)
125 m_previousHandler
->OnDrawContents(dc
);
128 void wxShapeEvtHandler::OnDrawBranches(wxDC
& dc
, bool erase
)
130 if (m_previousHandler
)
131 m_previousHandler
->OnDrawBranches(dc
, erase
);
134 void wxShapeEvtHandler::OnSize(double x
, double y
)
136 if (m_previousHandler
)
137 m_previousHandler
->OnSize(x
, y
);
140 bool wxShapeEvtHandler::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
142 if (m_previousHandler
)
143 return m_previousHandler
->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
);
148 void wxShapeEvtHandler::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
150 if (m_previousHandler
)
151 m_previousHandler
->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
154 void wxShapeEvtHandler::OnErase(wxDC
& dc
)
156 if (m_previousHandler
)
157 m_previousHandler
->OnErase(dc
);
160 void wxShapeEvtHandler::OnEraseContents(wxDC
& dc
)
162 if (m_previousHandler
)
163 m_previousHandler
->OnEraseContents(dc
);
166 void wxShapeEvtHandler::OnHighlight(wxDC
& dc
)
168 if (m_previousHandler
)
169 m_previousHandler
->OnHighlight(dc
);
172 void wxShapeEvtHandler::OnLeftClick(double x
, double y
, int keys
, int attachment
)
174 if (m_previousHandler
)
175 m_previousHandler
->OnLeftClick(x
, y
, keys
, attachment
);
178 void wxShapeEvtHandler::OnLeftDoubleClick(double x
, double y
, int keys
, int attachment
)
180 if (m_previousHandler
)
181 m_previousHandler
->OnLeftDoubleClick(x
, y
, keys
, attachment
);
184 void wxShapeEvtHandler::OnRightClick(double x
, double y
, int keys
, int attachment
)
186 if (m_previousHandler
)
187 m_previousHandler
->OnRightClick(x
, y
, keys
, attachment
);
190 void wxShapeEvtHandler::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
192 if (m_previousHandler
)
193 m_previousHandler
->OnDragLeft(draw
, x
, y
, keys
, attachment
);
196 void wxShapeEvtHandler::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
198 if (m_previousHandler
)
199 m_previousHandler
->OnBeginDragLeft(x
, y
, keys
, attachment
);
202 void wxShapeEvtHandler::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
204 if (m_previousHandler
)
205 m_previousHandler
->OnEndDragLeft(x
, y
, keys
, attachment
);
208 void wxShapeEvtHandler::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
210 if (m_previousHandler
)
211 m_previousHandler
->OnDragRight(draw
, x
, y
, keys
, attachment
);
214 void wxShapeEvtHandler::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
216 if (m_previousHandler
)
217 m_previousHandler
->OnBeginDragRight(x
, y
, keys
, attachment
);
220 void wxShapeEvtHandler::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
222 if (m_previousHandler
)
223 m_previousHandler
->OnEndDragRight(x
, y
, keys
, attachment
);
226 // Control points ('handles') redirect control to the actual shape, to make it easier
227 // to override sizing behaviour.
228 void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
230 if (m_previousHandler
)
231 m_previousHandler
->OnSizingDragLeft(pt
, draw
, x
, y
, keys
, attachment
);
234 void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
236 if (m_previousHandler
)
237 m_previousHandler
->OnSizingBeginDragLeft(pt
, x
, y
, keys
, attachment
);
240 void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
242 if (m_previousHandler
)
243 m_previousHandler
->OnSizingEndDragLeft(pt
, x
, y
, keys
, attachment
);
246 void wxShapeEvtHandler::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
248 if (m_previousHandler
)
249 m_previousHandler
->OnDrawOutline(dc
, x
, y
, w
, h
);
252 void wxShapeEvtHandler::OnDrawControlPoints(wxDC
& dc
)
254 if (m_previousHandler
)
255 m_previousHandler
->OnDrawControlPoints(dc
);
258 void wxShapeEvtHandler::OnEraseControlPoints(wxDC
& dc
)
260 if (m_previousHandler
)
261 m_previousHandler
->OnEraseControlPoints(dc
);
264 // Can override this to prevent or intercept line reordering.
265 void wxShapeEvtHandler::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
267 if (m_previousHandler
)
268 m_previousHandler
->OnChangeAttachment(attachment
, line
, ordering
);
271 IMPLEMENT_ABSTRACT_CLASS(wxShape
, wxShapeEvtHandler
)
273 wxShape::wxShape(wxShapeCanvas
*can
)
275 m_eventHandler
= this;
280 m_xpos
= 0.0; m_ypos
= 0.0;
281 m_pen
= g_oglBlackPen
;
282 m_brush
= wxWHITE_BRUSH
;
283 m_font
= g_oglNormalFont
;
284 m_textColour
= wxBLACK
;
285 m_textColourName
= "BLACK";
289 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
290 m_spaceAttachments
= TRUE
;
291 m_disableLabel
= FALSE
;
292 m_fixedWidth
= FALSE
;
293 m_fixedHeight
= FALSE
;
294 m_drawHandles
= TRUE
;
295 m_sensitivity
= OP_ALL
;
298 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
299 m_shadowMode
= SHADOW_NONE
;
302 m_shadowBrush
= wxBLACK_BRUSH
;
306 m_centreResize
= TRUE
;
307 m_maintainAspectRatio
= FALSE
;
308 m_highlighted
= FALSE
;
310 m_branchNeckLength
= 10;
311 m_branchStemLength
= 10;
312 m_branchSpacing
= 10;
313 m_branchStyle
= BRANCHING_ATTACHMENT_NORMAL
;
315 // Set up a default region. Much of the above will be put into
316 // the region eventually (the duplication is for compatibility)
317 wxShapeRegion
*region
= new wxShapeRegion
;
318 m_regions
.Append(region
);
319 region
->SetName("0");
320 region
->SetFont(g_oglNormalFont
);
321 region
->SetFormatMode(FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
);
322 region
->SetColour("BLACK");
328 m_parent
->GetChildren().DeleteObject(this);
335 m_canvas
->RemoveShape(this);
337 GetEventHandler()->OnDelete();
340 void wxShape::SetHighlight(bool hi
, bool recurse
)
345 wxNode
*node
= m_children
.First();
348 wxShape
*child
= (wxShape
*)node
->Data();
349 child
->SetHighlight(hi
, recurse
);
355 void wxShape::SetSensitivityFilter(int sens
, bool recursive
)
357 if (sens
& OP_DRAG_LEFT
)
362 m_sensitivity
= sens
;
365 wxNode
*node
= m_children
.First();
368 wxShape
*obj
= (wxShape
*)node
->Data();
369 obj
->SetSensitivityFilter(sens
, TRUE
);
375 void wxShape::SetDraggable(bool drag
, bool recursive
)
379 m_sensitivity
|= OP_DRAG_LEFT
;
381 if (m_sensitivity
& OP_DRAG_LEFT
)
382 m_sensitivity
= m_sensitivity
- OP_DRAG_LEFT
;
386 wxNode
*node
= m_children
.First();
389 wxShape
*obj
= (wxShape
*)node
->Data();
390 obj
->SetDraggable(drag
, TRUE
);
396 void wxShape::SetDrawHandles(bool drawH
)
398 m_drawHandles
= drawH
;
399 wxNode
*node
= m_children
.First();
402 wxShape
*obj
= (wxShape
*)node
->Data();
403 obj
->SetDrawHandles(drawH
);
408 void wxShape::SetShadowMode(int mode
, bool redraw
)
410 if (redraw
&& GetCanvas())
412 wxClientDC
dc(GetCanvas());
413 GetCanvas()->PrepareDC(dc
);
426 void wxShape::SetCanvas(wxShapeCanvas
*theCanvas
)
428 m_canvas
= theCanvas
;
429 wxNode
*node
= m_children
.First();
432 wxShape
*child
= (wxShape
*)node
->Data();
433 child
->SetCanvas(theCanvas
);
438 void wxShape::AddToCanvas(wxShapeCanvas
*theCanvas
, wxShape
*addAfter
)
440 theCanvas
->AddShape(this, addAfter
);
441 wxNode
*node
= m_children
.First();
442 wxShape
*lastImage
= this;
445 wxShape
*object
= (wxShape
*)node
->Data();
446 object
->AddToCanvas(theCanvas
, lastImage
);
453 // Insert at front of canvas
454 void wxShape::InsertInCanvas(wxShapeCanvas
*theCanvas
)
456 theCanvas
->InsertShape(this);
457 wxNode
*node
= m_children
.First();
458 wxShape
*lastImage
= this;
461 wxShape
*object
= (wxShape
*)node
->Data();
462 object
->AddToCanvas(theCanvas
, lastImage
);
469 void wxShape::RemoveFromCanvas(wxShapeCanvas
*theCanvas
)
473 theCanvas
->RemoveShape(this);
474 wxNode
*node
= m_children
.First();
477 wxShape
*object
= (wxShape
*)node
->Data();
478 object
->RemoveFromCanvas(theCanvas
);
484 void wxShape::ClearAttachments()
486 wxNode
*node
= m_attachmentPoints
.First();
489 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
493 m_attachmentPoints
.Clear();
496 void wxShape::ClearText(int regionId
)
500 m_text
.DeleteContents(TRUE
);
502 m_text
.DeleteContents(FALSE
);
504 wxNode
*node
= m_regions
.Nth(regionId
);
507 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
511 void wxShape::ClearRegions()
513 wxNode
*node
= m_regions
.First();
516 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
517 wxNode
*next
= node
->Next();
524 void wxShape::AddRegion(wxShapeRegion
*region
)
526 m_regions
.Append(region
);
529 void wxShape::SetDefaultRegionSize()
531 wxNode
*node
= m_regions
.First();
533 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
535 GetBoundingBoxMin(&w
, &h
);
536 region
->SetSize(w
, h
);
539 bool wxShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
544 double width
= 0.0, height
= 0.0;
545 GetBoundingBoxMin(&width
, &height
);
546 if (fabs(width
) < 4.0) width
= 4.0;
547 if (fabs(height
) < 4.0) height
= 4.0;
549 width
+= (double)4.0; height
+= (double)4.0; // Allowance for inaccurate mousing
551 double left
= (double)(m_xpos
- (width
/2.0));
552 double top
= (double)(m_ypos
- (height
/2.0));
553 double right
= (double)(m_xpos
+ (width
/2.0));
554 double bottom
= (double)(m_ypos
+ (height
/2.0));
556 int nearest_attachment
= 0;
558 // If within the bounding box, check the attachment points
559 // within the object.
561 if (x
>= left
&& x
<= right
&& y
>= top
&& y
<= bottom
)
563 int n
= GetNumberOfAttachments();
564 double nearest
= 999999.0;
566 // GetAttachmentPosition[Edge] takes a logical attachment position,
567 // i.e. if it's rotated through 90%, position 0 is East-facing.
569 for (int i
= 0; i
< n
; i
++)
572 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
574 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
575 ((yp
- y
) * (yp
- y
)));
580 nearest_attachment
= i
;
584 *attachment
= nearest_attachment
;
591 // Format a text string according to the region size, adding
592 // strings with positions to region text list
594 static bool GraphicsInSizeToContents
= FALSE
; // Infinite recursion elimination
595 void wxShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
600 if (m_regions
.Number() < 1)
602 wxNode
*node
= m_regions
.Nth(i
);
606 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
608 dc
.SetFont(* region
->GetFont());
610 region
->GetSize(&w
, &h
);
612 wxStringList
*stringList
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
613 node
= stringList
->First();
616 char *s
= (char *)node
->Data();
617 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
618 region
->GetFormattedText().Append((wxObject
*)line
);
624 // Don't try to resize an object with more than one image (this case should be dealt
625 // with by overriden handlers)
626 if ((region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
) &&
627 (region
->GetFormattedText().Number() > 0) &&
628 (m_regions
.Number() == 1) && !GraphicsInSizeToContents
)
630 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
631 if ((actualW
+m_textMarginX
!= w
) || (actualH
+m_textMarginY
!= h
))
633 // If we are a descendant of a composite, must make sure the composite gets
635 wxShape
*topAncestor
= GetTopAncestor();
637 if (topAncestor
!= this)
639 // Make sure we don't recurse infinitely
640 GraphicsInSizeToContents
= TRUE
;
642 wxCompositeShape
*composite
= (wxCompositeShape
*)topAncestor
;
643 composite
->Erase(dc
);
644 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
645 Move(dc
, m_xpos
, m_ypos
);
646 composite
->CalculateSize();
647 if (composite
->Selected())
649 composite
->DeleteControlPoints(& dc
);
650 composite
->MakeControlPoints();
651 composite
->MakeMandatoryControlPoints();
653 // Where infinite recursion might happen if we didn't stop it
656 GraphicsInSizeToContents
= FALSE
;
661 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
662 Move(dc
, m_xpos
, m_ypos
);
664 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
665 Move(dc
, m_xpos
, m_ypos
);
669 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
673 void wxShape::Recentre(wxDC
& dc
)
676 GetBoundingBoxMin(&w
, &h
);
678 int noRegions
= m_regions
.Number();
679 for (int i
= 0; i
< noRegions
; i
++)
681 wxNode
*node
= m_regions
.Nth(i
);
684 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
685 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, region
->GetFormatMode());
690 bool wxShape::GetPerimeterPoint(double x1
, double y1
,
691 double x2
, double y2
,
692 double *x3
, double *y3
)
697 void wxShape::SetPen(wxPen
*the_pen
)
702 void wxShape::SetBrush(wxBrush
*the_brush
)
707 // Get the top-most (non-division) ancestor, or self
708 wxShape
*wxShape::GetTopAncestor()
713 if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape
)))
715 else return GetParent()->GetTopAncestor();
722 void wxShape::SetFont(wxFont
*the_font
, int regionId
)
725 wxNode
*node
= m_regions
.Nth(regionId
);
728 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
729 region
->SetFont(the_font
);
732 wxFont
*wxShape::GetFont(int n
) const
734 wxNode
*node
= m_regions
.Nth(n
);
737 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
738 return region
->GetFont();
741 void wxShape::SetFormatMode(int mode
, int regionId
)
743 wxNode
*node
= m_regions
.Nth(regionId
);
746 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
747 region
->SetFormatMode(mode
);
750 int wxShape::GetFormatMode(int regionId
) const
752 wxNode
*node
= m_regions
.Nth(regionId
);
755 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
756 return region
->GetFormatMode();
759 void wxShape::SetTextColour(const wxString
& the_colour
, int regionId
)
761 wxColour
*wxcolour
= wxTheColourDatabase
->FindColour(the_colour
);
762 m_textColour
= wxcolour
;
763 m_textColourName
= the_colour
;
765 wxNode
*node
= m_regions
.Nth(regionId
);
768 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
769 region
->SetColour(the_colour
);
772 wxString
wxShape::GetTextColour(int regionId
) const
774 wxNode
*node
= m_regions
.Nth(regionId
);
777 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
778 return region
->GetColour();
781 void wxShape::SetRegionName(const wxString
& name
, int regionId
)
783 wxNode
*node
= m_regions
.Nth(regionId
);
786 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
787 region
->SetName(name
);
790 wxString
wxShape::GetRegionName(int regionId
)
792 wxNode
*node
= m_regions
.Nth(regionId
);
795 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
796 return region
->GetName();
799 int wxShape::GetRegionId(const wxString
& name
)
801 wxNode
*node
= m_regions
.First();
805 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
806 if (region
->GetName() == name
)
814 // Name all m_regions in all subimages recursively.
815 void wxShape::NameRegions(const wxString
& parentName
)
817 int n
= GetNumberOfTextRegions();
819 for (int i
= 0; i
< n
; i
++)
821 if (parentName
.Length() > 0)
822 sprintf(buf
, "%s.%d", (const char*) parentName
, i
);
824 sprintf(buf
, "%d", i
);
825 SetRegionName(buf
, i
);
827 wxNode
*node
= m_children
.First();
831 wxShape
*child
= (wxShape
*)node
->Data();
832 if (parentName
.Length() > 0)
833 sprintf(buf
, "%s.%d", (const char*) parentName
, j
);
835 sprintf(buf
, "%d", j
);
836 child
->NameRegions(buf
);
842 // Get a region by name, possibly looking recursively into composites.
843 wxShape
*wxShape::FindRegion(const wxString
& name
, int *regionId
)
845 int id
= GetRegionId(name
);
852 wxNode
*node
= m_children
.First();
855 wxShape
*child
= (wxShape
*)node
->Data();
856 wxShape
*actualImage
= child
->FindRegion(name
, regionId
);
864 // Finds all region names for this image (composite or simple).
865 // Supply empty string list.
866 void wxShape::FindRegionNames(wxStringList
& list
)
868 int n
= GetNumberOfTextRegions();
869 for (int i
= 0; i
< n
; i
++)
871 wxString
name(GetRegionName(i
));
872 list
.Add((const char*) name
);
875 wxNode
*node
= m_children
.First();
878 wxShape
*child
= (wxShape
*)node
->Data();
879 child
->FindRegionNames(list
);
884 void wxShape::AssignNewIds()
888 wxNode
*node
= m_children
.First();
891 wxShape
*child
= (wxShape
*)node
->Data();
892 child
->AssignNewIds();
897 void wxShape::OnDraw(wxDC
& dc
)
901 void wxShape::OnMoveLinks(wxDC
& dc
)
903 // Want to set the ends of all attached links
904 // to point to/from this object
906 wxNode
*current
= m_lines
.First();
909 wxLineShape
*line
= (wxLineShape
*)current
->Data();
910 line
->GetEventHandler()->OnMoveLink(dc
);
911 current
= current
->Next();
916 void wxShape::OnDrawContents(wxDC
& dc
)
918 double bound_x
, bound_y
;
919 GetBoundingBoxMin(&bound_x
, &bound_y
);
920 if (m_regions
.Number() < 1) return;
922 if (m_pen
) dc
.SetPen(* m_pen
);
924 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.First()->Data();
925 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
927 dc
.SetTextForeground(* (region
->GetActualColourObject()));
928 dc
.SetBackgroundMode(wxTRANSPARENT
);
931 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
934 if (!GetDisableLabel())
936 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
940 void wxShape::DrawContents(wxDC
& dc
)
942 GetEventHandler()->OnDrawContents(dc
);
945 void wxShape::OnSize(double x
, double y
)
949 bool wxShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
954 void wxShape::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
958 void wxShape::OnErase(wxDC
& dc
)
964 wxNode
*current
= m_lines
.First();
967 wxLineShape
*line
= (wxLineShape
*)current
->Data();
968 line
->GetEventHandler()->OnErase(dc
);
969 current
= current
->Next();
971 GetEventHandler()->OnEraseContents(dc
);
974 void wxShape::OnEraseContents(wxDC
& dc
)
979 double maxX
, maxY
, minX
, minY
;
982 GetBoundingBoxMin(&minX
, &minY
);
983 GetBoundingBoxMax(&maxX
, &maxY
);
984 double topLeftX
= (double)(xp
- (maxX
/ 2.0) - 2.0);
985 double topLeftY
= (double)(yp
- (maxY
/ 2.0) - 2.0);
989 penWidth
= m_pen
->GetWidth();
991 dc
.SetPen(* g_oglWhiteBackgroundPen
);
992 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
993 dc
.DrawRectangle(WXROUND(topLeftX
- penWidth
), WXROUND(topLeftY
- penWidth
),
994 WXROUND(maxX
+ penWidth
*2.0 + 4.0), WXROUND(maxY
+ penWidth
*2.0 + 4.0));
997 void wxShape::EraseLinks(wxDC
& dc
, int attachment
, bool recurse
)
1002 wxNode
*current
= m_lines
.First();
1005 wxLineShape
*line
= (wxLineShape
*)current
->Data();
1006 if (attachment
== -1 || ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1007 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
)))
1008 line
->GetEventHandler()->OnErase(dc
);
1009 current
= current
->Next();
1013 wxNode
*node
= m_children
.First();
1016 wxShape
*child
= (wxShape
*)node
->Data();
1017 child
->EraseLinks(dc
, attachment
, recurse
);
1018 node
= node
->Next();
1023 void wxShape::DrawLinks(wxDC
& dc
, int attachment
, bool recurse
)
1028 wxNode
*current
= m_lines
.First();
1031 wxLineShape
*line
= (wxLineShape
*)current
->Data();
1032 if (attachment
== -1 ||
1033 (line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1034 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1036 current
= current
->Next();
1040 wxNode
*node
= m_children
.First();
1043 wxShape
*child
= (wxShape
*)node
->Data();
1044 child
->DrawLinks(dc
, attachment
, recurse
);
1045 node
= node
->Next();
1050 // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
1051 // edge of the shape.
1052 // attachmentPoint is the attachment point (= side) in question.
1054 // This is the default, rectangular implementation.
1055 bool wxShape::AttachmentSortTest(int attachmentPoint
, const wxRealPoint
& pt1
, const wxRealPoint
& pt2
)
1057 int physicalAttachment
= LogicalToPhysicalAttachment(attachmentPoint
);
1058 switch (physicalAttachment
)
1063 return (pt1
.x
<= pt2
.x
) ;
1069 return (pt1
.y
<= pt2
.y
) ;
1077 bool wxShape::MoveLineToNewAttachment(wxDC
& dc
, wxLineShape
*to_move
,
1080 if (GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1083 int newAttachment
, oldAttachment
;
1086 // Is (x, y) on this object? If so, find the new attachment point
1087 // the user has moved the point to
1088 bool hit
= HitTest(x
, y
, &newAttachment
, &distance
);
1094 if (to_move
->GetTo() == this)
1095 oldAttachment
= to_move
->GetAttachmentTo();
1097 oldAttachment
= to_move
->GetAttachmentFrom();
1099 // The links in a new ordering.
1102 // First, add all links to the new list.
1103 wxNode
*node
= m_lines
.First();
1106 newOrdering
.Append(node
->Data());
1107 node
= node
->Next();
1110 // Delete the line object from the list of links; we're going to move
1111 // it to another position in the list
1112 newOrdering
.DeleteObject(to_move
);
1114 double old_x
= (double) -99999.9;
1115 double old_y
= (double) -99999.9;
1117 node
= newOrdering
.First();
1120 while (!found
&& node
)
1122 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1123 if ((line
->GetTo() == this && oldAttachment
== line
->GetAttachmentTo()) ||
1124 (line
->GetFrom() == this && oldAttachment
== line
->GetAttachmentFrom()))
1126 double startX
, startY
, endX
, endY
;
1128 line
->GetEnds(&startX
, &startY
, &endX
, &endY
);
1129 if (line
->GetTo() == this)
1139 wxRealPoint
thisPoint(xp
, yp
);
1140 wxRealPoint
lastPoint(old_x
, old_y
);
1141 wxRealPoint
newPoint(x
, y
);
1143 if (AttachmentSortTest(newAttachment
, newPoint
, thisPoint
) && AttachmentSortTest(newAttachment
, lastPoint
, newPoint
))
1146 newOrdering
.Insert(node
, to_move
);
1152 node
= node
->Next();
1156 newOrdering
.Append(to_move
);
1158 GetEventHandler()->OnChangeAttachment(newAttachment
, to_move
, newOrdering
);
1163 void wxShape::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
1165 if (line
->GetTo() == this)
1166 line
->SetAttachmentTo(attachment
);
1168 line
->SetAttachmentFrom(attachment
);
1170 ApplyAttachmentOrdering(ordering
);
1172 wxClientDC
dc(GetCanvas());
1173 GetCanvas()->PrepareDC(dc
);
1177 if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc
);
1180 // Reorders the lines according to the given list.
1181 void wxShape::ApplyAttachmentOrdering(wxList
& linesToSort
)
1183 // This is a temporary store of all the lines.
1186 wxNode
*node
= m_lines
.First();
1189 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1190 linesStore
.Append(line
);
1191 node
= node
->Next();;
1196 node
= linesToSort
.First();
1199 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1200 if (linesStore
.Member(line
))
1203 linesStore
.DeleteObject(line
);
1204 m_lines
.Append(line
);
1206 node
= node
->Next();
1209 // Now add any lines that haven't been listed in linesToSort.
1210 node
= linesStore
.First();
1213 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1214 m_lines
.Append(line
);
1215 node
= node
->Next();
1219 // Reorders the lines coming into the node image at this attachment
1220 // position, in the order in which they appear in linesToSort.
1221 // Any remaining lines not in the list will be added to the end.
1222 void wxShape::SortLines(int attachment
, wxList
& linesToSort
)
1224 // This is a temporary store of all the lines at this attachment
1225 // point. We'll tick them off as we've processed them.
1226 wxList linesAtThisAttachment
;
1228 wxNode
*node
= m_lines
.First();
1231 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1232 wxNode
*next
= node
->Next();
1233 if ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1234 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1236 linesAtThisAttachment
.Append(line
);
1240 else node
= node
->Next();
1243 node
= linesToSort
.First();
1246 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1247 if (linesAtThisAttachment
.Member(line
))
1250 linesAtThisAttachment
.DeleteObject(line
);
1251 m_lines
.Append(line
);
1253 node
= node
->Next();
1256 // Now add any lines that haven't been listed in linesToSort.
1257 node
= linesAtThisAttachment
.First();
1260 wxLineShape
*line
= (wxLineShape
*)node
->Data();
1261 m_lines
.Append(line
);
1262 node
= node
->Next();
1266 void wxShape::OnHighlight(wxDC
& dc
)
1270 void wxShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
1272 if ((m_sensitivity
& OP_CLICK_LEFT
) != OP_CLICK_LEFT
)
1278 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1279 m_parent
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
1285 void wxShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
1287 if ((m_sensitivity
& OP_CLICK_RIGHT
) != OP_CLICK_RIGHT
)
1293 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1294 m_parent
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);
1300 double DragOffsetX
= 0.0;
1301 double DragOffsetY
= 0.0;
1303 void wxShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1305 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1311 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1312 m_parent
->GetEventHandler()->OnDragLeft(draw
, x
, y
, keys
, attachment
);
1317 wxClientDC
dc(GetCanvas());
1318 GetCanvas()->PrepareDC(dc
);
1320 dc
.SetLogicalFunction(OGLRBLF
);
1322 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1323 dc
.SetPen(dottedPen
);
1324 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1327 xx
= x
+ DragOffsetX
;
1328 yy
= y
+ DragOffsetY
;
1330 m_canvas
->Snap(&xx
, &yy
);
1331 // m_xpos = xx; m_ypos = yy;
1333 GetBoundingBoxMax(&w
, &h
);
1334 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1337 void wxShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1339 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1345 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1346 m_parent
->GetEventHandler()->OnBeginDragLeft(x
, y
, keys
, attachment
);
1351 DragOffsetX
= m_xpos
- x
;
1352 DragOffsetY
= m_ypos
- y
;
1354 wxClientDC
dc(GetCanvas());
1355 GetCanvas()->PrepareDC(dc
);
1357 // New policy: don't erase shape until end of drag.
1361 xx
= x
+ DragOffsetX
;
1362 yy
= y
+ DragOffsetY
;
1363 m_canvas
->Snap(&xx
, &yy
);
1364 // m_xpos = xx; m_ypos = yy;
1365 dc
.SetLogicalFunction(OGLRBLF
);
1367 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1368 dc
.SetPen(dottedPen
);
1369 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1372 GetBoundingBoxMax(&w
, &h
);
1373 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1374 m_canvas
->CaptureMouse();
1377 void wxShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1379 m_canvas
->ReleaseMouse();
1380 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1386 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1387 m_parent
->GetEventHandler()->OnEndDragLeft(x
, y
, keys
, attachment
);
1392 wxClientDC
dc(GetCanvas());
1393 GetCanvas()->PrepareDC(dc
);
1395 dc
.SetLogicalFunction(wxCOPY
);
1397 double xx
= x
+ DragOffsetX
;
1398 double yy
= y
+ DragOffsetY
;
1399 m_canvas
->Snap(&xx
, &yy
);
1400 // canvas->Snap(&m_xpos, &m_ypos);
1402 // New policy: erase shape at end of drag.
1406 if (m_canvas
&& !m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1409 void wxShape::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1411 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1417 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1418 m_parent
->GetEventHandler()->OnDragRight(draw
, x
, y
, keys
, attachment
);
1424 void wxShape::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1426 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1432 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1433 m_parent
->GetEventHandler()->OnBeginDragRight(x
, y
, keys
, attachment
);
1439 void wxShape::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1441 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1447 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1448 m_parent
->GetEventHandler()->OnEndDragRight(x
, y
, keys
, attachment
);
1454 void wxShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
1456 double top_left_x
= (double)(x
- w
/2.0);
1457 double top_left_y
= (double)(y
- h
/2.0);
1458 double top_right_x
= (double)(top_left_x
+ w
);
1459 double top_right_y
= (double)top_left_y
;
1460 double bottom_left_x
= (double)top_left_x
;
1461 double bottom_left_y
= (double)(top_left_y
+ h
);
1462 double bottom_right_x
= (double)top_right_x
;
1463 double bottom_right_y
= (double)bottom_left_y
;
1466 points
[0].x
= WXROUND(top_left_x
); points
[0].y
= WXROUND(top_left_y
);
1467 points
[1].x
= WXROUND(top_right_x
); points
[1].y
= WXROUND(top_right_y
);
1468 points
[2].x
= WXROUND(bottom_right_x
); points
[2].y
= WXROUND(bottom_right_y
);
1469 points
[3].x
= WXROUND(bottom_left_x
); points
[3].y
= WXROUND(bottom_left_y
);
1470 points
[4].x
= WXROUND(top_left_x
); points
[4].y
= WXROUND(top_left_y
);
1472 dc
.DrawLines(5, points
);
1475 void wxShape::Attach(wxShapeCanvas
*can
)
1480 void wxShape::Detach()
1485 void wxShape::Move(wxDC
& dc
, double x
, double y
, bool display
)
1487 double old_x
= m_xpos
;
1488 double old_y
= m_ypos
;
1490 if (!GetEventHandler()->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
))
1497 m_xpos
= x
; m_ypos
= y
;
1499 ResetControlPoints();
1506 GetEventHandler()->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
1509 void wxShape::MoveLinks(wxDC
& dc
)
1511 GetEventHandler()->OnMoveLinks(dc
);
1515 void wxShape::Draw(wxDC
& dc
)
1519 GetEventHandler()->OnDraw(dc
);
1520 GetEventHandler()->OnDrawContents(dc
);
1521 GetEventHandler()->OnDrawControlPoints(dc
);
1522 GetEventHandler()->OnDrawBranches(dc
);
1526 void wxShape::Flash()
1530 wxClientDC
dc(GetCanvas());
1531 GetCanvas()->PrepareDC(dc
);
1533 dc
.SetLogicalFunction(OGLRBLF
);
1535 dc
.SetLogicalFunction(wxCOPY
);
1540 void wxShape::Show(bool show
)
1543 wxNode
*node
= m_children
.First();
1546 wxShape
*image
= (wxShape
*)node
->Data();
1548 node
= node
->Next();
1552 void wxShape::Erase(wxDC
& dc
)
1554 GetEventHandler()->OnErase(dc
);
1555 GetEventHandler()->OnEraseControlPoints(dc
);
1556 GetEventHandler()->OnDrawBranches(dc
, TRUE
);
1559 void wxShape::EraseContents(wxDC
& dc
)
1561 GetEventHandler()->OnEraseContents(dc
);
1564 void wxShape::AddText(const wxString
& string
)
1566 wxNode
*node
= m_regions
.First();
1569 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1570 region
->ClearText();
1571 wxShapeTextLine
*new_line
=
1572 new wxShapeTextLine(0.0, 0.0, string
);
1573 region
->GetFormattedText().Append(new_line
);
1575 m_formatted
= FALSE
;
1578 void wxShape::SetSize(double x
, double y
, bool recursive
)
1580 SetAttachmentSize(x
, y
);
1581 SetDefaultRegionSize();
1584 void wxShape::SetAttachmentSize(double w
, double h
)
1588 double width
, height
;
1589 GetBoundingBoxMin(&width
, &height
);
1592 else scaleX
= w
/width
;
1595 else scaleY
= h
/height
;
1597 wxNode
*node
= m_attachmentPoints
.First();
1600 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
1601 point
->m_x
= (double)(point
->m_x
* scaleX
);
1602 point
->m_y
= (double)(point
->m_y
* scaleY
);
1603 node
= node
->Next();
1607 // Add line FROM this object
1608 void wxShape::AddLine(wxLineShape
*line
, wxShape
*other
,
1609 int attachFrom
, int attachTo
,
1610 // The line ordering
1611 int positionFrom
, int positionTo
)
1613 if (positionFrom
== -1)
1615 if (!m_lines
.Member(line
))
1616 m_lines
.Append(line
);
1620 // Don't preserve old ordering if we have new ordering instructions
1621 m_lines
.DeleteObject(line
);
1622 if (positionFrom
< m_lines
.Number())
1624 wxNode
* node
= m_lines
.Nth(positionFrom
);
1625 m_lines
.Insert(node
, line
);
1628 m_lines
.Append(line
);
1631 if (positionTo
== -1)
1633 if (!other
->m_lines
.Member(line
))
1634 other
->m_lines
.Append(line
);
1638 // Don't preserve old ordering if we have new ordering instructions
1639 other
->m_lines
.DeleteObject(line
);
1640 if (positionTo
< other
->m_lines
.Number())
1642 wxNode
* node
= other
->m_lines
.Nth(positionTo
);
1643 other
->m_lines
.Insert(node
, line
);
1646 other
->m_lines
.Append(line
);
1649 // Wrong: doesn't preserve ordering of shape already linked
1650 m_lines
.DeleteObject(line
);
1651 other
->m_lines
.DeleteObject(line
);
1653 if (positionFrom
== -1)
1654 m_lines
.Append(line
);
1657 if (positionFrom
< m_lines
.Number())
1659 wxNode
* node
= m_lines
.Nth(positionFrom
);
1660 m_lines
.Insert(node
, line
);
1663 m_lines
.Append(line
);
1666 if (positionTo
== -1)
1667 other
->m_lines
.Append(line
);
1670 if (positionTo
< other
->m_lines
.Number())
1672 wxNode
* node
= other
->m_lines
.Nth(positionTo
);
1673 other
->m_lines
.Insert(node
, line
);
1676 other
->m_lines
.Append(line
);
1680 line
->SetFrom(this);
1682 line
->SetAttachments(attachFrom
, attachTo
);
1685 void wxShape::RemoveLine(wxLineShape
*line
)
1687 if (line
->GetFrom() == this)
1688 line
->GetTo()->m_lines
.DeleteObject(line
);
1690 line
->GetFrom()->m_lines
.DeleteObject(line
);
1692 m_lines
.DeleteObject(line
);
1696 void wxShape::WriteAttributes(wxExpr
*clause
)
1698 clause
->AddAttributeValueString("type", GetClassInfo()->GetClassName());
1699 clause
->AddAttributeValue("id", m_id
);
1703 int penWidth
= m_pen
->GetWidth();
1704 int penStyle
= m_pen
->GetStyle();
1706 clause
->AddAttributeValue("pen_width", (long)penWidth
);
1707 if (penStyle
!= wxSOLID
)
1708 clause
->AddAttributeValue("pen_style", (long)penStyle
);
1710 wxString penColour
= wxTheColourDatabase
->FindName(m_pen
->GetColour());
1711 if (penColour
== "")
1713 wxString
hex(oglColourToHex(m_pen
->GetColour()));
1714 hex
= wxString("#") + hex
;
1715 clause
->AddAttributeValueString("pen_colour", hex
);
1717 else if (penColour
!= "BLACK")
1718 clause
->AddAttributeValueString("pen_colour", penColour
);
1723 wxString brushColour
= wxTheColourDatabase
->FindName(m_brush
->GetColour());
1725 if (brushColour
== "")
1727 wxString
hex(oglColourToHex(m_brush
->GetColour()));
1728 hex
= wxString("#") + hex
;
1729 clause
->AddAttributeValueString("brush_colour", hex
);
1731 else if (brushColour
!= "WHITE")
1732 clause
->AddAttributeValueString("brush_colour", brushColour
);
1734 if (m_brush
->GetStyle() != wxSOLID
)
1735 clause
->AddAttributeValue("brush_style", (long)m_brush
->GetStyle());
1740 int n_lines
= m_lines
.Number();
1743 wxExpr
*list
= new wxExpr(wxExprList
);
1744 wxNode
*node
= m_lines
.First();
1747 wxShape
*line
= (wxShape
*)node
->Data();
1748 wxExpr
*id_expr
= new wxExpr(line
->GetId());
1749 list
->Append(id_expr
);
1750 node
= node
->Next();
1752 clause
->AddAttributeValue("arcs", list
);
1755 // Miscellaneous members
1756 if (m_attachmentMode
!= 0)
1757 clause
->AddAttributeValue("use_attachments", (long)m_attachmentMode
);
1758 if (m_sensitivity
!= OP_ALL
)
1759 clause
->AddAttributeValue("sensitivity", (long)m_sensitivity
);
1760 if (!m_spaceAttachments
)
1761 clause
->AddAttributeValue("space_attachments", (long)m_spaceAttachments
);
1763 clause
->AddAttributeValue("fixed_width", (long)m_fixedWidth
);
1765 clause
->AddAttributeValue("fixed_height", (long)m_fixedHeight
);
1766 if (m_shadowMode
!= SHADOW_NONE
)
1767 clause
->AddAttributeValue("shadow_mode", (long)m_shadowMode
);
1768 if (m_centreResize
!= TRUE
)
1769 clause
->AddAttributeValue("centre_resize", (long)0);
1770 clause
->AddAttributeValue("maintain_aspect_ratio", (long) m_maintainAspectRatio
);
1771 if (m_highlighted
!= FALSE
)
1772 clause
->AddAttributeValue("hilite", (long)m_highlighted
);
1774 if (m_parent
) // For composite objects
1775 clause
->AddAttributeValue("parent", (long)m_parent
->GetId());
1777 if (m_rotation
!= 0.0)
1778 clause
->AddAttributeValue("rotation", m_rotation
);
1780 if (!this->IsKindOf(CLASSINFO(wxLineShape
)))
1782 clause
->AddAttributeValue("neck_length", (long) m_branchNeckLength
);
1783 clause
->AddAttributeValue("stem_length", (long) m_branchStemLength
);
1784 clause
->AddAttributeValue("branch_spacing", (long) m_branchSpacing
);
1785 clause
->AddAttributeValue("branch_style", (long) m_branchStyle
);
1788 // Write user-defined attachment points, if any
1789 if (m_attachmentPoints
.Number() > 0)
1791 wxExpr
*attachmentList
= new wxExpr(wxExprList
);
1792 wxNode
*node
= m_attachmentPoints
.First();
1795 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
1796 wxExpr
*pointExpr
= new wxExpr(wxExprList
);
1797 pointExpr
->Append(new wxExpr((long)point
->m_id
));
1798 pointExpr
->Append(new wxExpr(point
->m_x
));
1799 pointExpr
->Append(new wxExpr(point
->m_y
));
1800 attachmentList
->Append(pointExpr
);
1801 node
= node
->Next();
1803 clause
->AddAttributeValue("user_attachments", attachmentList
);
1806 // Write text regions
1807 WriteRegions(clause
);
1810 void wxShape::WriteRegions(wxExpr
*clause
)
1812 // Output regions as region1 = (...), region2 = (...), etc
1813 // and formatted text as text1 = (...), text2 = (...) etc.
1815 char regionNameBuf
[20];
1816 char textNameBuf
[20];
1817 wxNode
*node
= m_regions
.First();
1820 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1821 sprintf(regionNameBuf
, "region%d", regionNo
);
1822 sprintf(textNameBuf
, "text%d", regionNo
);
1824 // Original text and region attributes:
1825 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
1826 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
1827 wxExpr
*regionExpr
= new wxExpr(wxExprList
);
1828 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionName
));
1829 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionText
));
1831 regionExpr
->Append(new wxExpr(region
->m_x
));
1832 regionExpr
->Append(new wxExpr(region
->m_y
));
1833 regionExpr
->Append(new wxExpr(region
->GetWidth()));
1834 regionExpr
->Append(new wxExpr(region
->GetHeight()));
1836 regionExpr
->Append(new wxExpr(region
->m_minWidth
));
1837 regionExpr
->Append(new wxExpr(region
->m_minHeight
));
1838 regionExpr
->Append(new wxExpr(region
->m_regionProportionX
));
1839 regionExpr
->Append(new wxExpr(region
->m_regionProportionY
));
1841 regionExpr
->Append(new wxExpr((long)region
->m_formatMode
));
1843 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetPointSize() : 10)));
1844 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetFamily() : wxDEFAULT
)));
1845 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetStyle() : wxDEFAULT
)));
1846 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetWeight() : wxNORMAL
)));
1847 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_textColour
));
1849 // New members for pen colour/style
1850 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_penColour
));
1851 regionExpr
->Append(new wxExpr((long)region
->m_penStyle
));
1854 // text1 = ((x y string) (x y string) ...)
1855 wxExpr
*textExpr
= new wxExpr(wxExprList
);
1857 wxNode
*textNode
= region
->m_formattedText
.First();
1860 wxShapeTextLine
*line
= (wxShapeTextLine
*)textNode
->Data();
1861 wxExpr
*list2
= new wxExpr(wxExprList
);
1862 list2
->Append(new wxExpr(line
->GetX()));
1863 list2
->Append(new wxExpr(line
->GetY()));
1864 list2
->Append(new wxExpr(wxExprString
, line
->GetText()));
1865 textExpr
->Append(list2
);
1866 textNode
= textNode
->Next();
1869 // Now add both attributes to the clause
1870 clause
->AddAttributeValue(regionNameBuf
, regionExpr
);
1871 clause
->AddAttributeValue(textNameBuf
, textExpr
);
1873 node
= node
->Next();
1878 void wxShape::ReadAttributes(wxExpr
*clause
)
1880 clause
->GetAttributeValue("id", m_id
);
1883 clause
->GetAttributeValue("x", m_xpos
);
1884 clause
->GetAttributeValue("y", m_ypos
);
1886 // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
1888 wxExpr
*strings
= clause
->AttributeValue("text");
1889 if (strings
&& strings
->Type() == wxExprList
)
1891 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
1892 wxExpr
*node
= strings
->value
.first
;
1895 wxExpr
*string_expr
= node
;
1898 wxString
the_string("");
1900 // string_expr can either be a string, or a list of
1901 // 3 elements: x, y, and string.
1902 if (string_expr
->Type() == wxExprString
)
1904 the_string
= string_expr
->StringValue();
1905 m_formatted
= FALSE
;
1907 else if (string_expr
->Type() == wxExprList
)
1909 wxExpr
*first
= string_expr
->value
.first
;
1910 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
1911 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
1913 if (first
&& second
&& third
&&
1914 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
1915 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
1916 third
->Type() == wxExprString
)
1918 if (first
->Type() == wxExprReal
)
1919 the_x
= first
->RealValue();
1920 else the_x
= (double)first
->IntegerValue();
1922 if (second
->Type() == wxExprReal
)
1923 the_y
= second
->RealValue();
1924 else the_y
= (double)second
->IntegerValue();
1926 the_string
= third
->StringValue();
1929 wxShapeTextLine
*line
=
1930 new wxShapeTextLine(the_x
, the_y
, (char*) (const char*) the_string
);
1931 m_text
.Append(line
);
1937 wxString pen_string
= "";
1938 wxString brush_string
= "";
1940 int pen_style
= wxSOLID
;
1941 int brush_style
= wxSOLID
;
1942 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
1944 clause
->GetAttributeValue("pen_colour", pen_string
);
1945 clause
->GetAttributeValue("text_colour", m_textColourName
);
1947 SetTextColour(m_textColourName
);
1949 clause
->GetAttributeValue("region_name", m_regionName
);
1951 clause
->GetAttributeValue("brush_colour", brush_string
);
1952 clause
->GetAttributeValue("pen_width", pen_width
);
1953 clause
->GetAttributeValue("pen_style", pen_style
);
1954 clause
->GetAttributeValue("brush_style", brush_style
);
1956 int iVal
= (int) m_attachmentMode
;
1957 clause
->GetAttributeValue("use_attachments", iVal
);
1958 m_attachmentMode
= iVal
;
1960 clause
->GetAttributeValue("sensitivity", m_sensitivity
);
1962 iVal
= (int) m_spaceAttachments
;
1963 clause
->GetAttributeValue("space_attachments", iVal
);
1964 m_spaceAttachments
= (iVal
!= 0);
1966 iVal
= (int) m_fixedWidth
;
1967 clause
->GetAttributeValue("fixed_width", iVal
);
1968 m_fixedWidth
= (iVal
!= 0);
1970 iVal
= (int) m_fixedHeight
;
1971 clause
->GetAttributeValue("fixed_height", iVal
);
1972 m_fixedHeight
= (iVal
!= 0);
1974 clause
->GetAttributeValue("format_mode", m_formatMode
);
1975 clause
->GetAttributeValue("shadow_mode", m_shadowMode
);
1977 iVal
= m_branchNeckLength
;
1978 clause
->GetAttributeValue("neck_length", iVal
);
1979 m_branchNeckLength
= iVal
;
1981 iVal
= m_branchStemLength
;
1982 clause
->GetAttributeValue("stem_length", iVal
);
1983 m_branchStemLength
= iVal
;
1985 iVal
= m_branchSpacing
;
1986 clause
->GetAttributeValue("branch_spacing", iVal
);
1987 m_branchSpacing
= iVal
;
1989 clause
->GetAttributeValue("branch_style", m_branchStyle
);
1991 iVal
= (int) m_centreResize
;
1992 clause
->GetAttributeValue("centre_resize", iVal
);
1993 m_centreResize
= (iVal
!= 0);
1995 iVal
= (int) m_maintainAspectRatio
;
1996 clause
->GetAttributeValue("maintain_aspect_ratio", iVal
);
1997 m_maintainAspectRatio
= (iVal
!= 0);
1999 iVal
= (int) m_highlighted
;
2000 clause
->GetAttributeValue("hilite", iVal
);
2001 m_highlighted
= (iVal
!= 0);
2003 clause
->GetAttributeValue("rotation", m_rotation
);
2005 if (pen_string
== "")
2006 pen_string
= "BLACK";
2007 if (brush_string
== "")
2008 brush_string
= "WHITE";
2010 if (pen_string
.GetChar(0) == '#')
2012 wxColour
col(oglHexToColour(pen_string
.After('#')));
2013 m_pen
= wxThePenList
->FindOrCreatePen(col
, pen_width
, pen_style
);
2016 m_pen
= wxThePenList
->FindOrCreatePen(pen_string
, pen_width
, pen_style
);
2019 m_pen
= wxBLACK_PEN
;
2021 if (brush_string
.GetChar(0) == '#')
2023 wxColour
col(oglHexToColour(brush_string
.After('#')));
2024 m_brush
= wxTheBrushList
->FindOrCreateBrush(col
, brush_style
);
2027 m_brush
= wxTheBrushList
->FindOrCreateBrush(brush_string
, brush_style
);
2030 m_brush
= wxWHITE_BRUSH
;
2032 int point_size
= 10;
2033 clause
->GetAttributeValue("point_size", point_size
);
2034 SetFont(oglMatchFont(point_size
));
2036 // Read user-defined attachment points, if any
2037 wxExpr
*attachmentList
= clause
->AttributeValue("user_attachments");
2040 wxExpr
*pointExpr
= attachmentList
->GetFirst();
2043 wxExpr
*idExpr
= pointExpr
->Nth(0);
2044 wxExpr
*xExpr
= pointExpr
->Nth(1);
2045 wxExpr
*yExpr
= pointExpr
->Nth(2);
2046 if (idExpr
&& xExpr
&& yExpr
)
2048 wxAttachmentPoint
*point
= new wxAttachmentPoint
;
2049 point
->m_id
= (int)idExpr
->IntegerValue();
2050 point
->m_x
= xExpr
->RealValue();
2051 point
->m_y
= yExpr
->RealValue();
2052 m_attachmentPoints
.Append((wxObject
*)point
);
2054 pointExpr
= pointExpr
->GetNext();
2058 // Read text regions
2059 ReadRegions(clause
);
2062 void wxShape::ReadRegions(wxExpr
*clause
)
2066 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
2067 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
2069 char regionNameBuf
[20];
2070 char textNameBuf
[20];
2072 wxExpr
*regionExpr
= NULL
;
2073 wxExpr
*textExpr
= NULL
;
2074 sprintf(regionNameBuf
, "region%d", regionNo
);
2075 sprintf(textNameBuf
, "text%d", regionNo
);
2077 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
2079 while ((regionExpr
= clause
->AttributeValue(regionNameBuf
)))
2082 * Get the region information
2086 wxString
regionName("");
2087 wxString
regionText("");
2091 double height
= 0.0;
2092 double minWidth
= 5.0;
2093 double minHeight
= 5.0;
2094 double m_regionProportionX
= -1.0;
2095 double m_regionProportionY
= -1.0;
2096 int formatMode
= FORMAT_NONE
;
2098 int fontFamily
= wxSWISS
;
2099 int fontStyle
= wxNORMAL
;
2100 int fontWeight
= wxNORMAL
;
2101 wxString
regionTextColour("");
2102 wxString
penColour("");
2103 int penStyle
= wxSOLID
;
2105 if (regionExpr
->Type() == wxExprList
)
2107 wxExpr
*nameExpr
= regionExpr
->Nth(0);
2108 wxExpr
*textExpr
= regionExpr
->Nth(1);
2109 wxExpr
*xExpr
= regionExpr
->Nth(2);
2110 wxExpr
*yExpr
= regionExpr
->Nth(3);
2111 wxExpr
*widthExpr
= regionExpr
->Nth(4);
2112 wxExpr
*heightExpr
= regionExpr
->Nth(5);
2113 wxExpr
*minWidthExpr
= regionExpr
->Nth(6);
2114 wxExpr
*minHeightExpr
= regionExpr
->Nth(7);
2115 wxExpr
*propXExpr
= regionExpr
->Nth(8);
2116 wxExpr
*propYExpr
= regionExpr
->Nth(9);
2117 wxExpr
*formatExpr
= regionExpr
->Nth(10);
2118 wxExpr
*sizeExpr
= regionExpr
->Nth(11);
2119 wxExpr
*familyExpr
= regionExpr
->Nth(12);
2120 wxExpr
*styleExpr
= regionExpr
->Nth(13);
2121 wxExpr
*weightExpr
= regionExpr
->Nth(14);
2122 wxExpr
*colourExpr
= regionExpr
->Nth(15);
2123 wxExpr
*penColourExpr
= regionExpr
->Nth(16);
2124 wxExpr
*penStyleExpr
= regionExpr
->Nth(17);
2126 regionName
= nameExpr
->StringValue();
2127 regionText
= textExpr
->StringValue();
2129 x
= xExpr
->RealValue();
2130 y
= yExpr
->RealValue();
2132 width
= widthExpr
->RealValue();
2133 height
= heightExpr
->RealValue();
2135 minWidth
= minWidthExpr
->RealValue();
2136 minHeight
= minHeightExpr
->RealValue();
2138 m_regionProportionX
= propXExpr
->RealValue();
2139 m_regionProportionY
= propYExpr
->RealValue();
2141 formatMode
= (int) formatExpr
->IntegerValue();
2142 fontSize
= (int)sizeExpr
->IntegerValue();
2143 fontFamily
= (int)familyExpr
->IntegerValue();
2144 fontStyle
= (int)styleExpr
->IntegerValue();
2145 fontWeight
= (int)weightExpr
->IntegerValue();
2149 regionTextColour
= colourExpr
->StringValue();
2152 regionTextColour
= "BLACK";
2155 penColour
= penColourExpr
->StringValue();
2157 penStyle
= (int)penStyleExpr
->IntegerValue();
2159 wxFont
*font
= wxTheFontList
->FindOrCreateFont(fontSize
, fontFamily
, fontStyle
, fontWeight
);
2161 wxShapeRegion
*region
= new wxShapeRegion
;
2162 region
->SetProportions(m_regionProportionX
, m_regionProportionY
);
2163 region
->SetFont(font
);
2164 region
->SetSize(width
, height
);
2165 region
->SetPosition(x
, y
);
2166 region
->SetMinSize(minWidth
, minHeight
);
2167 region
->SetFormatMode(formatMode
);
2168 region
->SetPenStyle(penStyle
);
2169 if (penColour
!= "")
2170 region
->SetPenColour(penColour
);
2172 region
->m_textColour
= regionTextColour
;
2173 region
->m_regionText
= regionText
;
2174 region
->m_regionName
= regionName
;
2176 m_regions
.Append(region
);
2179 * Get the formatted text strings
2182 textExpr
= clause
->AttributeValue(textNameBuf
);
2183 if (textExpr
&& (textExpr
->Type() == wxExprList
))
2185 wxExpr
*node
= textExpr
->value
.first
;
2188 wxExpr
*string_expr
= node
;
2191 wxString
the_string("");
2193 // string_expr can either be a string, or a list of
2194 // 3 elements: x, y, and string.
2195 if (string_expr
->Type() == wxExprString
)
2197 the_string
= string_expr
->StringValue();
2198 m_formatted
= FALSE
;
2200 else if (string_expr
->Type() == wxExprList
)
2202 wxExpr
*first
= string_expr
->value
.first
;
2203 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
2204 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
2206 if (first
&& second
&& third
&&
2207 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
2208 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
2209 third
->Type() == wxExprString
)
2211 if (first
->Type() == wxExprReal
)
2212 the_x
= first
->RealValue();
2213 else the_x
= (double)first
->IntegerValue();
2215 if (second
->Type() == wxExprReal
)
2216 the_y
= second
->RealValue();
2217 else the_y
= (double)second
->IntegerValue();
2219 the_string
= third
->StringValue();
2224 wxShapeTextLine
*line
=
2225 new wxShapeTextLine(the_x
, the_y
, (char*) (const char*) the_string
);
2226 region
->m_formattedText
.Append(line
);
2233 sprintf(regionNameBuf
, "region%d", regionNo
);
2234 sprintf(textNameBuf
, "text%d", regionNo
);
2237 // Compatibility: check for no regions (old file).
2238 // Lines and divided rectangles must deal with this compatibility
2239 // theirselves. Composites _may_ not have any regions anyway.
2240 if ((m_regions
.Number() == 0) &&
2241 !this->IsKindOf(CLASSINFO(wxLineShape
)) && !this->IsKindOf(CLASSINFO(wxDividedShape
)) &&
2242 !this->IsKindOf(CLASSINFO(wxCompositeShape
)))
2244 wxShapeRegion
*newRegion
= new wxShapeRegion
;
2245 newRegion
->SetName("0");
2246 m_regions
.Append((wxObject
*)newRegion
);
2247 if (m_text
.Number() > 0)
2249 newRegion
->ClearText();
2250 wxNode
*node
= m_text
.First();
2253 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->Data();
2254 wxNode
*next
= node
->Next();
2255 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
2265 void wxShape::Copy(wxShape
& copy
)
2268 copy
.m_xpos
= m_xpos
;
2269 copy
.m_ypos
= m_ypos
;
2271 copy
.m_brush
= m_brush
;
2272 copy
.m_textColour
= m_textColour
;
2273 copy
.m_centreResize
= m_centreResize
;
2274 copy
.m_maintainAspectRatio
= m_maintainAspectRatio
;
2275 copy
.m_attachmentMode
= m_attachmentMode
;
2276 copy
.m_spaceAttachments
= m_spaceAttachments
;
2277 copy
.m_highlighted
= m_highlighted
;
2278 copy
.m_rotation
= m_rotation
;
2279 copy
.m_textColourName
= m_textColourName
;
2280 copy
.m_regionName
= m_regionName
;
2282 copy
.m_sensitivity
= m_sensitivity
;
2283 copy
.m_draggable
= m_draggable
;
2284 copy
.m_fixedWidth
= m_fixedWidth
;
2285 copy
.m_fixedHeight
= m_fixedHeight
;
2286 copy
.m_formatMode
= m_formatMode
;
2287 copy
.m_drawHandles
= m_drawHandles
;
2289 copy
.m_visible
= m_visible
;
2290 copy
.m_shadowMode
= m_shadowMode
;
2291 copy
.m_shadowOffsetX
= m_shadowOffsetX
;
2292 copy
.m_shadowOffsetY
= m_shadowOffsetY
;
2293 copy
.m_shadowBrush
= m_shadowBrush
;
2295 copy
.m_branchNeckLength
= m_branchNeckLength
;
2296 copy
.m_branchStemLength
= m_branchStemLength
;
2297 copy
.m_branchSpacing
= m_branchSpacing
;
2299 // Copy text regions
2300 copy
.ClearRegions();
2301 wxNode
*node
= m_regions
.First();
2304 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
2305 wxShapeRegion
*newRegion
= new wxShapeRegion(*region
);
2306 copy
.m_regions
.Append(newRegion
);
2307 node
= node
->Next();
2311 copy
.ClearAttachments();
2312 node
= m_attachmentPoints
.First();
2315 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2316 wxAttachmentPoint
*newPoint
= new wxAttachmentPoint
;
2317 newPoint
->m_id
= point
->m_id
;
2318 newPoint
->m_x
= point
->m_x
;
2319 newPoint
->m_y
= point
->m_y
;
2320 copy
.m_attachmentPoints
.Append((wxObject
*)newPoint
);
2321 node
= node
->Next();
2325 copy
.m_lines
.Clear();
2326 node
= m_lines
.First();
2329 wxLineShape
* line
= (wxLineShape
*) node
->Data();
2330 copy
.m_lines
.Append(line
);
2331 node
= node
->Next();
2335 // Create and return a new, fully copied object.
2336 wxShape
*wxShape::CreateNewCopy(bool resetMapping
, bool recompute
)
2339 oglObjectCopyMapping
.Clear();
2341 wxShape
* newObject
= (wxShape
*) GetClassInfo()->CreateObject();
2343 wxASSERT( (newObject
!= NULL
) );
2344 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShape
))) );
2348 if (GetEventHandler() != this)
2350 wxShapeEvtHandler
* newHandler
= GetEventHandler()->CreateNewCopy();
2351 newObject
->SetEventHandler(newHandler
);
2352 newObject
->SetPreviousHandler(NULL
);
2353 newHandler
->SetPreviousHandler(newObject
);
2354 newHandler
->SetShape(newObject
);
2358 newObject
->Recompute();
2362 // Does the copying for this object, including copying event
2363 // handler data if any. Calls the virtual Copy function.
2364 void wxShape::CopyWithHandler(wxShape
& copy
)
2368 if (GetEventHandler() != this)
2370 wxASSERT( copy
.GetEventHandler() != NULL
);
2371 wxASSERT( copy
.GetEventHandler() != (©
) );
2372 wxASSERT( GetEventHandler()->GetClassInfo() == copy
.GetEventHandler()->GetClassInfo() );
2373 GetEventHandler()->CopyData(* (copy
.GetEventHandler()));
2378 // Default - make 6 control points
2379 void wxShape::MakeControlPoints()
2381 double maxX
, maxY
, minX
, minY
;
2383 GetBoundingBoxMax(&maxX
, &maxY
);
2384 GetBoundingBoxMin(&minX
, &minY
);
2386 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2387 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2389 // Offsets from main object
2390 double top
= (double)(- (heightMin
/ 2.0));
2391 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2392 double left
= (double)(- (widthMin
/ 2.0));
2393 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2395 wxControlPoint
*control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, top
,
2396 CONTROL_POINT_DIAGONAL
);
2397 m_canvas
->AddShape(control
);
2398 m_controlPoints
.Append(control
);
2400 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, top
,
2401 CONTROL_POINT_VERTICAL
);
2402 m_canvas
->AddShape(control
);
2403 m_controlPoints
.Append(control
);
2405 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, top
,
2406 CONTROL_POINT_DIAGONAL
);
2407 m_canvas
->AddShape(control
);
2408 m_controlPoints
.Append(control
);
2410 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, 0,
2411 CONTROL_POINT_HORIZONTAL
);
2412 m_canvas
->AddShape(control
);
2413 m_controlPoints
.Append(control
);
2415 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, bottom
,
2416 CONTROL_POINT_DIAGONAL
);
2417 m_canvas
->AddShape(control
);
2418 m_controlPoints
.Append(control
);
2420 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, bottom
,
2421 CONTROL_POINT_VERTICAL
);
2422 m_canvas
->AddShape(control
);
2423 m_controlPoints
.Append(control
);
2425 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, bottom
,
2426 CONTROL_POINT_DIAGONAL
);
2427 m_canvas
->AddShape(control
);
2428 m_controlPoints
.Append(control
);
2430 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, 0,
2431 CONTROL_POINT_HORIZONTAL
);
2432 m_canvas
->AddShape(control
);
2433 m_controlPoints
.Append(control
);
2437 void wxShape::MakeMandatoryControlPoints()
2439 wxNode
*node
= m_children
.First();
2442 wxShape
*child
= (wxShape
*)node
->Data();
2443 child
->MakeMandatoryControlPoints();
2444 node
= node
->Next();
2448 void wxShape::ResetMandatoryControlPoints()
2450 wxNode
*node
= m_children
.First();
2453 wxShape
*child
= (wxShape
*)node
->Data();
2454 child
->ResetMandatoryControlPoints();
2455 node
= node
->Next();
2459 void wxShape::ResetControlPoints()
2461 ResetMandatoryControlPoints();
2463 if (m_controlPoints
.Number() < 1)
2466 double maxX
, maxY
, minX
, minY
;
2468 GetBoundingBoxMax(&maxX
, &maxY
);
2469 GetBoundingBoxMin(&minX
, &minY
);
2471 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2472 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2474 // Offsets from main object
2475 double top
= (double)(- (heightMin
/ 2.0));
2476 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2477 double left
= (double)(- (widthMin
/ 2.0));
2478 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2480 wxNode
*node
= m_controlPoints
.First();
2481 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2482 control
->m_xoffset
= left
; control
->m_yoffset
= top
;
2484 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2485 control
->m_xoffset
= 0; control
->m_yoffset
= top
;
2487 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2488 control
->m_xoffset
= right
; control
->m_yoffset
= top
;
2490 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2491 control
->m_xoffset
= right
; control
->m_yoffset
= 0;
2493 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2494 control
->m_xoffset
= right
; control
->m_yoffset
= bottom
;
2496 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2497 control
->m_xoffset
= 0; control
->m_yoffset
= bottom
;
2499 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2500 control
->m_xoffset
= left
; control
->m_yoffset
= bottom
;
2502 node
= node
->Next(); control
= (wxControlPoint
*)node
->Data();
2503 control
->m_xoffset
= left
; control
->m_yoffset
= 0;
2506 void wxShape::DeleteControlPoints(wxDC
*dc
)
2508 wxNode
*node
= m_controlPoints
.First();
2511 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2513 control
->GetEventHandler()->OnErase(*dc
);
2514 m_canvas
->RemoveShape(control
);
2517 node
= m_controlPoints
.First();
2519 // Children of divisions are contained objects,
2521 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2523 node
= m_children
.First();
2526 wxShape
*child
= (wxShape
*)node
->Data();
2527 child
->DeleteControlPoints(dc
);
2528 node
= node
->Next();
2533 void wxShape::OnDrawControlPoints(wxDC
& dc
)
2538 dc
.SetBrush(* wxBLACK_BRUSH
);
2539 dc
.SetPen(* wxBLACK_PEN
);
2541 wxNode
*node
= m_controlPoints
.First();
2544 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2546 node
= node
->Next();
2548 // Children of divisions are contained objects,
2550 // This test bypasses the type facility for speed
2551 // (critical when drawing)
2552 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2554 node
= m_children
.First();
2557 wxShape
*child
= (wxShape
*)node
->Data();
2558 child
->GetEventHandler()->OnDrawControlPoints(dc
);
2559 node
= node
->Next();
2564 void wxShape::OnEraseControlPoints(wxDC
& dc
)
2566 wxNode
*node
= m_controlPoints
.First();
2569 wxControlPoint
*control
= (wxControlPoint
*)node
->Data();
2571 node
= node
->Next();
2573 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2575 node
= m_children
.First();
2578 wxShape
*child
= (wxShape
*)node
->Data();
2579 child
->GetEventHandler()->OnEraseControlPoints(dc
);
2580 node
= node
->Next();
2585 void wxShape::Select(bool select
, wxDC
* dc
)
2587 m_selected
= select
;
2590 MakeControlPoints();
2591 // Children of divisions are contained objects,
2593 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2595 wxNode
*node
= m_children
.First();
2598 wxShape
*child
= (wxShape
*)node
->Data();
2599 child
->MakeMandatoryControlPoints();
2600 node
= node
->Next();
2604 GetEventHandler()->OnDrawControlPoints(*dc
);
2608 DeleteControlPoints(dc
);
2609 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2611 wxNode
*node
= m_children
.First();
2614 wxShape
*child
= (wxShape
*)node
->Data();
2615 child
->DeleteControlPoints(dc
);
2616 node
= node
->Next();
2622 bool wxShape::Selected() const
2627 bool wxShape::AncestorSelected() const
2629 if (m_selected
) return TRUE
;
2633 return GetParent()->AncestorSelected();
2636 int wxShape::GetNumberOfAttachments() const
2638 // Should return the MAXIMUM attachment point id here,
2639 // so higher-level functions can iterate through all attachments,
2640 // even if they're not contiguous.
2641 if (m_attachmentPoints
.Number() == 0)
2646 wxNode
*node
= m_attachmentPoints
.First();
2649 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2650 if (point
->m_id
> maxN
)
2652 node
= node
->Next();
2658 bool wxShape::AttachmentIsValid(int attachment
) const
2660 if (m_attachmentPoints
.Number() == 0)
2662 return ((attachment
>= 0) && (attachment
< 4)) ;
2665 wxNode
*node
= m_attachmentPoints
.First();
2668 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2669 if (point
->m_id
== attachment
)
2671 node
= node
->Next();
2676 bool wxShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
2677 int nth
, int no_arcs
, wxLineShape
*line
)
2679 if (m_attachmentMode
== ATTACHMENT_MODE_NONE
)
2681 *x
= m_xpos
; *y
= m_ypos
;
2684 else if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
2686 wxRealPoint pt
, stemPt
;
2687 GetBranchingAttachmentPoint(attachment
, nth
, pt
, stemPt
);
2692 else if (m_attachmentMode
== ATTACHMENT_MODE_EDGE
)
2694 if (m_attachmentPoints
.Number() > 0)
2696 wxNode
*node
= m_attachmentPoints
.First();
2699 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
2700 if (point
->m_id
== attachment
)
2702 *x
= (double)(m_xpos
+ point
->m_x
);
2703 *y
= (double)(m_ypos
+ point
->m_y
);
2706 node
= node
->Next();
2708 *x
= m_xpos
; *y
= m_ypos
;
2713 // Assume is rectangular
2715 GetBoundingBoxMax(&w
, &h
);
2716 double top
= (double)(m_ypos
+ h
/2.0);
2717 double bottom
= (double)(m_ypos
- h
/2.0);
2718 double left
= (double)(m_xpos
- w
/2.0);
2719 double right
= (double)(m_xpos
+ w
/2.0);
2721 bool isEnd
= (line
&& line
->IsEnd(this));
2723 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2726 switch (physicalAttachment
)
2730 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(right
, bottom
),
2731 nth
, no_arcs
, line
);
2733 *x
= pt
.x
; *y
= pt
.y
;
2738 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(right
, bottom
), wxRealPoint(right
, top
),
2739 nth
, no_arcs
, line
);
2741 *x
= pt
.x
; *y
= pt
.y
;
2746 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, top
), wxRealPoint(right
, top
),
2747 nth
, no_arcs
, line
);
2749 *x
= pt
.x
; *y
= pt
.y
;
2754 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(left
, top
),
2755 nth
, no_arcs
, line
);
2757 *x
= pt
.x
; *y
= pt
.y
;
2772 void wxShape::GetBoundingBoxMax(double *w
, double *h
)
2775 GetBoundingBoxMin(&ww
, &hh
);
2776 if (m_shadowMode
!= SHADOW_NONE
)
2778 ww
+= m_shadowOffsetX
;
2779 hh
+= m_shadowOffsetY
;
2785 // Returns TRUE if image is a descendant of this composite
2786 bool wxShape::HasDescendant(wxShape
*image
)
2790 wxNode
*node
= m_children
.First();
2793 wxShape
*child
= (wxShape
*)node
->Data();
2794 bool ans
= child
->HasDescendant(image
);
2797 node
= node
->Next();
2802 // Clears points from a list of wxRealPoints, and clears list
2803 void wxShape::ClearPointList(wxList
& list
)
2805 wxNode
* node
= list
.First();
2808 wxRealPoint
* pt
= (wxRealPoint
*) node
->Data();
2811 node
= node
->Next();
2816 // Assuming the attachment lies along a vertical or horizontal line,
2817 // calculate the position on that point.
2818 wxRealPoint
wxShape::CalcSimpleAttachment(const wxRealPoint
& pt1
, const wxRealPoint
& pt2
,
2819 int nth
, int noArcs
, wxLineShape
* line
)
2821 bool isEnd
= (line
&& line
->IsEnd(this));
2823 // Are we horizontal or vertical?
2824 bool isHorizontal
= (oglRoughlyEqual(pt1
.y
, pt2
.y
) == TRUE
);
2830 wxRealPoint firstPoint
, secondPoint
;
2842 if (m_spaceAttachments
)
2844 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2846 // Align line according to the next handle along
2847 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2848 if (point
->x
< firstPoint
.x
)
2850 else if (point
->x
> secondPoint
.x
)
2856 x
= firstPoint
.x
+ (nth
+ 1)*(secondPoint
.x
- firstPoint
.x
)/(noArcs
+ 1);
2858 else x
= (secondPoint
.x
- firstPoint
.x
)/2.0; // Midpoint
2864 wxASSERT( oglRoughlyEqual(pt1
.x
, pt2
.x
) == TRUE
);
2866 wxRealPoint firstPoint
, secondPoint
;
2878 if (m_spaceAttachments
)
2880 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2882 // Align line according to the next handle along
2883 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2884 if (point
->y
< firstPoint
.y
)
2886 else if (point
->y
> secondPoint
.y
)
2892 y
= firstPoint
.y
+ (nth
+ 1)*(secondPoint
.y
- firstPoint
.y
)/(noArcs
+ 1);
2894 else y
= (secondPoint
.y
- firstPoint
.y
)/2.0; // Midpoint
2899 return wxRealPoint(x
, y
);
2902 // Return the zero-based position in m_lines of line.
2903 int wxShape::GetLinePosition(wxLineShape
* line
)
2906 for (i
= 0; i
< m_lines
.Number(); i
++)
2907 if ((wxLineShape
*) (m_lines
.Nth(i
)->Data()) == line
)
2917 // shoulder1 ->---------<- shoulder2
2919 // <- branching attachment point N-1
2921 // This function gets information about where branching connections go.
2922 // Returns FALSE if there are no lines at this attachment.
2923 bool wxShape::GetBranchingAttachmentInfo(int attachment
, wxRealPoint
& root
, wxRealPoint
& neck
,
2924 wxRealPoint
& shoulder1
, wxRealPoint
& shoulder2
)
2926 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2928 // Number of lines at this attachment.
2929 int lineCount
= GetAttachmentLineCount(attachment
);
2934 int totalBranchLength
= m_branchSpacing
* (lineCount
- 1);
2936 root
= GetBranchingAttachmentRoot(attachment
);
2938 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
2939 switch (physicalAttachment
)
2944 neck
.y
= root
.y
- m_branchNeckLength
;
2946 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2947 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2949 shoulder1
.y
= neck
.y
;
2950 shoulder2
.y
= neck
.y
;
2955 neck
.x
= root
.x
+ m_branchNeckLength
;
2958 shoulder1
.x
= neck
.x
;
2959 shoulder2
.x
= neck
.x
;
2961 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2962 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2968 neck
.y
= root
.y
+ m_branchNeckLength
;
2970 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2971 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2973 shoulder1
.y
= neck
.y
;
2974 shoulder2
.y
= neck
.y
;
2979 neck
.x
= root
.x
- m_branchNeckLength
;
2982 shoulder1
.x
= neck
.x
;
2983 shoulder2
.x
= neck
.x
;
2985 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2986 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2991 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentInfo." );
2998 // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
2999 // at this attachment point.
3000 // Get the attachment point where the arc joins the stem, and also the point where the
3001 // the stem meets the shoulder.
3002 bool wxShape::GetBranchingAttachmentPoint(int attachment
, int n
, wxRealPoint
& pt
, wxRealPoint
& stemPt
)
3004 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3006 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3007 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3009 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3010 switch (physicalAttachment
)
3014 pt
.y
= neck
.y
- m_branchStemLength
;
3015 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3023 pt
.y
= neck
.y
+ m_branchStemLength
;
3024 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3032 pt
.x
= neck
.x
+ m_branchStemLength
;
3033 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3041 pt
.x
= neck
.x
- m_branchStemLength
;
3042 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3050 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentPoint." );
3058 // Get the number of lines at this attachment position.
3059 int wxShape::GetAttachmentLineCount(int attachment
) const
3062 wxNode
* node
= m_lines
.First();
3065 wxLineShape
* lineShape
= (wxLineShape
*) node
->Data();
3066 if ((lineShape
->GetFrom() == this) && (lineShape
->GetAttachmentFrom() == attachment
))
3068 else if ((lineShape
->GetTo() == this) && (lineShape
->GetAttachmentTo() == attachment
))
3071 node
= node
->Next();
3076 // This function gets the root point at the given attachment.
3077 wxRealPoint
wxShape::GetBranchingAttachmentRoot(int attachment
)
3079 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3083 double width
, height
;
3084 GetBoundingBoxMax(& width
, & height
);
3086 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3087 switch (physicalAttachment
)
3092 root
.y
= GetY() - height
/2.0;
3097 root
.x
= GetX() + width
/2.0;
3104 root
.y
= GetY() + height
/2.0;
3109 root
.x
= GetX() - width
/2.0;
3115 wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentRoot." );
3122 // Draw or erase the branches (not the actual arcs though)
3123 void wxShape::OnDrawBranches(wxDC
& dc
, int attachment
, bool erase
)
3125 int count
= GetAttachmentLineCount(attachment
);
3129 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3130 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3134 dc
.SetPen(*wxWHITE_PEN
);
3135 dc
.SetBrush(*wxWHITE_BRUSH
);
3139 dc
.SetPen(*wxBLACK_PEN
);
3140 dc
.SetBrush(*wxBLACK_BRUSH
);
3144 dc
.DrawLine((long) root
.x
, (long) root
.y
, (long) neck
.x
, (long) neck
.y
);
3148 // Draw shoulder-to-shoulder line
3149 dc
.DrawLine((long) shoulder1
.x
, (long) shoulder1
.y
, (long) shoulder2
.x
, (long) shoulder2
.y
);
3151 // Draw all the little branches
3153 for (i
= 0; i
< count
; i
++)
3155 wxRealPoint pt
, stemPt
;
3156 GetBranchingAttachmentPoint(attachment
, i
, pt
, stemPt
);
3157 dc
.DrawLine((long) stemPt
.x
, (long) stemPt
.y
, (long) pt
.x
, (long) pt
.y
);
3159 if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB
) && (count
> 1))
3162 // dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
3163 dc
.DrawEllipse((long) (stemPt
.x
- (blobSize
/2.0)), (long) (stemPt
.y
- (blobSize
/2.0)), blobSize
, blobSize
);
3168 // Draw or erase the branches (not the actual arcs though)
3169 void wxShape::OnDrawBranches(wxDC
& dc
, bool erase
)
3171 if (m_attachmentMode
!= ATTACHMENT_MODE_BRANCHING
)
3174 int count
= GetNumberOfAttachments();
3176 for (i
= 0; i
< count
; i
++)
3177 OnDrawBranches(dc
, i
, erase
);
3180 // Only get the attachment position at the _edge_ of the shape, ignoring
3181 // branching mode. This is used e.g. to indicate the edge of interest, not the point
3182 // on the attachment branch.
3183 bool wxShape::GetAttachmentPositionEdge(int attachment
, double *x
, double *y
,
3184 int nth
, int no_arcs
, wxLineShape
*line
)
3186 int oldMode
= m_attachmentMode
;
3188 // Calculate as if to edge, not branch
3189 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
3190 m_attachmentMode
= ATTACHMENT_MODE_EDGE
;
3191 bool success
= GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
3192 m_attachmentMode
= oldMode
;
3197 // Rotate the standard attachment point from physical (0 is always North)
3198 // to logical (0 -> 1 if rotated by 90 degrees)
3199 int wxShape::PhysicalToLogicalAttachment(int physicalAttachment
) const
3201 const double pi
= 3.1415926535897932384626433832795 ;
3203 if (oglRoughlyEqual(GetRotation(), 0.0))
3205 i
= physicalAttachment
;
3207 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3209 i
= physicalAttachment
- 1;
3211 else if (oglRoughlyEqual(GetRotation(), pi
))
3213 i
= physicalAttachment
- 2;
3215 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3217 i
= physicalAttachment
- 3;
3220 // Can't handle -- assume the same.
3221 return physicalAttachment
;
3229 // Rotate the standard attachment point from logical
3230 // to physical (0 is always North)
3231 int wxShape::LogicalToPhysicalAttachment(int logicalAttachment
) const
3233 const double pi
= 3.1415926535897932384626433832795 ;
3235 if (oglRoughlyEqual(GetRotation(), 0.0))
3237 i
= logicalAttachment
;
3239 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3241 i
= logicalAttachment
+ 1;
3243 else if (oglRoughlyEqual(GetRotation(), pi
))
3245 i
= logicalAttachment
+ 2;
3247 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3249 i
= logicalAttachment
+ 3;
3252 // Can't handle -- assume the same.
3253 return logicalAttachment
;
3261 void wxShape::Rotate(double WXUNUSED(x
), double WXUNUSED(y
), double theta
)
3263 const double pi
= 3.1415926535897932384626433832795 ;
3265 if (m_rotation
< 0.0)
3269 else if (m_rotation
> 2*pi
)