--- /dev/null
+#
+
+top_srcdir = @top_srcdir@/..
+top_builddir = ../../..
+
+VPATH= $(top_srcdir)/utils/ogl/src
+
+LIBTARGET=$(top_builddir)/lib/libogl
+
+OBJECTS=basic.o bmpshape.o composit.o divided.o lines.o misc.o \
+ basic2.o canvas.o constrnt.o drawn.o mfutils.o ogldiag.o
+
+
+include $(top_builddir)/src/makelib.env
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: basic.cpp
+// Purpose: Basic OGL classes
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "basic.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+#include <math.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "composit.h"
+#include "lines.h"
+#include "canvas.h"
+#include "divided.h"
+#include "misc.h"
+
+// Control point types
+// Rectangle and most other shapes
+#define CONTROL_POINT_VERTICAL 1
+#define CONTROL_POINT_HORIZONTAL 2
+#define CONTROL_POINT_DIAGONAL 3
+
+// Line
+#define CONTROL_POINT_ENDPOINT_TO 4
+#define CONTROL_POINT_ENDPOINT_FROM 5
+#define CONTROL_POINT_LINE 6
+
+IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine, wxObject)
+IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint, wxObject)
+
+wxShapeTextLine::wxShapeTextLine(double the_x, double the_y, const wxString& the_line)
+{
+ m_x = the_x; m_y = the_y; m_line = the_line;
+}
+
+wxShapeTextLine::~wxShapeTextLine()
+{
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler, wxObject)
+
+wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler *prev, wxShape *shape)
+{
+ m_previousHandler = prev;
+ m_handlerShape = shape;
+}
+
+wxShapeEvtHandler::~wxShapeEvtHandler()
+{
+}
+
+// Creates a copy of this event handler.
+wxShapeEvtHandler* wxShapeEvtHandler::CreateNewCopy()
+{
+ wxShapeEvtHandler* newObject = (wxShapeEvtHandler*) GetClassInfo()->CreateObject();
+
+ wxASSERT( (newObject != NULL) );
+ wxASSERT( (newObject->IsKindOf(CLASSINFO(wxShapeEvtHandler))) );
+
+ newObject->m_previousHandler = newObject;
+
+ CopyData(*newObject);
+
+ return newObject;
+}
+
+
+void wxShapeEvtHandler::OnDelete()
+{
+ if (this != GetShape())
+ delete this;
+}
+
+void wxShapeEvtHandler::OnDraw(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDraw(dc);
+}
+
+void wxShapeEvtHandler::OnMoveLinks(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnMoveLinks(dc);
+}
+
+void wxShapeEvtHandler::OnMoveLink(wxDC& dc, bool moveControlPoints)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnMoveLink(dc, moveControlPoints);
+}
+
+void wxShapeEvtHandler::OnDrawContents(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDrawContents(dc);
+}
+
+void wxShapeEvtHandler::OnDrawBranches(wxDC& dc, bool erase)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDrawBranches(dc, erase);
+}
+
+void wxShapeEvtHandler::OnSize(double x, double y)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnSize(x, y);
+}
+
+bool wxShapeEvtHandler::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+ if (m_previousHandler)
+ return m_previousHandler->OnMovePre(dc, x, y, old_x, old_y, display);
+ else
+ return TRUE;
+}
+
+void wxShapeEvtHandler::OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnMovePost(dc, x, y, old_x, old_y, display);
+}
+
+void wxShapeEvtHandler::OnErase(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnErase(dc);
+}
+
+void wxShapeEvtHandler::OnEraseContents(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnEraseContents(dc);
+}
+
+void wxShapeEvtHandler::OnHighlight(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnHighlight(dc);
+}
+
+void wxShapeEvtHandler::OnLeftClick(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnLeftClick(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnLeftDoubleClick(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnLeftDoubleClick(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnRightClick(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnRightClick(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDragLeft(draw, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnBeginDragLeft(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnEndDragLeft(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnDragRight(bool draw, double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDragRight(draw, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnBeginDragRight(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnBeginDragRight(x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnEndDragRight(double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnEndDragRight(x, y, keys, attachment);
+}
+
+// Control points ('handles') redirect control to the actual shape, to make it easier
+// to override sizing behaviour.
+void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnSizingDragLeft(pt, draw, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnSizingBeginDragLeft(pt, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnSizingEndDragLeft(pt, x, y, keys, attachment);
+}
+
+void wxShapeEvtHandler::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDrawOutline(dc, x, y, w, h);
+}
+
+void wxShapeEvtHandler::OnDrawControlPoints(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnDrawControlPoints(dc);
+}
+
+void wxShapeEvtHandler::OnEraseControlPoints(wxDC& dc)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnEraseControlPoints(dc);
+}
+
+// Can override this to prevent or intercept line reordering.
+void wxShapeEvtHandler::OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering)
+{
+ if (m_previousHandler)
+ m_previousHandler->OnChangeAttachment(attachment, line, ordering);
+}
+
+IMPLEMENT_ABSTRACT_CLASS(wxShape, wxShapeEvtHandler)
+
+wxShape::wxShape(wxShapeCanvas *can)
+{
+ m_eventHandler = this;
+ SetShape(this);
+ m_id = 0;
+ m_formatted = FALSE;
+ m_canvas = can;
+ m_xpos = 0.0; m_ypos = 0.0;
+ m_pen = g_oglBlackPen;
+ m_brush = wxWHITE_BRUSH;
+ m_font = g_oglNormalFont;
+ m_textColour = wxBLACK;
+ m_textColourName = "BLACK";
+ m_visible = FALSE;
+ m_clientData = NULL;
+ m_selected = FALSE;
+ m_attachmentMode = ATTACHMENT_MODE_NONE;
+ m_spaceAttachments = TRUE;
+ m_disableLabel = FALSE;
+ m_fixedWidth = FALSE;
+ m_fixedHeight = FALSE;
+ m_drawHandles = TRUE;
+ m_sensitivity = OP_ALL;
+ m_draggable = TRUE;
+ m_parent = NULL;
+ m_formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT;
+ m_shadowMode = SHADOW_NONE;
+ m_shadowOffsetX = 6;
+ m_shadowOffsetY = 6;
+ m_shadowBrush = wxBLACK_BRUSH;
+ m_textMarginX = 5;
+ m_textMarginY = 5;
+ m_regionName = "0";
+ m_centreResize = TRUE;
+ m_maintainAspectRatio = FALSE;
+ m_highlighted = FALSE;
+ m_rotation = 0.0;
+ m_branchNeckLength = 10;
+ m_branchStemLength = 10;
+ m_branchSpacing = 10;
+ m_branchStyle = BRANCHING_ATTACHMENT_NORMAL;
+
+ // Set up a default region. Much of the above will be put into
+ // the region eventually (the duplication is for compatibility)
+ wxShapeRegion *region = new wxShapeRegion;
+ m_regions.Append(region);
+ region->SetName("0");
+ region->SetFont(g_oglNormalFont);
+ region->SetFormatMode(FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT);
+ region->SetColour("BLACK");
+}
+
+wxShape::~wxShape()
+{
+ if (m_parent)
+ m_parent->GetChildren().DeleteObject(this);
+
+ ClearText();
+ ClearRegions();
+ ClearAttachments();
+
+ if (m_canvas)
+ m_canvas->RemoveShape(this);
+
+ GetEventHandler()->OnDelete();
+}
+
+void wxShape::SetHighlight(bool hi, bool recurse)
+{
+ m_highlighted = hi;
+ if (recurse)
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->SetHighlight(hi, recurse);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::SetSensitivityFilter(int sens, bool recursive)
+{
+ if (sens & OP_DRAG_LEFT)
+ m_draggable = TRUE;
+ else
+ m_draggable = FALSE;
+
+ m_sensitivity = sens;
+ if (recursive)
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *obj = (wxShape *)node->Data();
+ obj->SetSensitivityFilter(sens, TRUE);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::SetDraggable(bool drag, bool recursive)
+{
+ m_draggable = drag;
+ if (m_draggable)
+ m_sensitivity |= OP_DRAG_LEFT;
+ else
+ if (m_sensitivity & OP_DRAG_LEFT)
+ m_sensitivity = m_sensitivity - OP_DRAG_LEFT;
+
+ if (recursive)
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *obj = (wxShape *)node->Data();
+ obj->SetDraggable(drag, TRUE);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::SetDrawHandles(bool drawH)
+{
+ m_drawHandles = drawH;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *obj = (wxShape *)node->Data();
+ obj->SetDrawHandles(drawH);
+ node = node->Next();
+ }
+}
+
+void wxShape::SetShadowMode(int mode, bool redraw)
+{
+ if (redraw && GetCanvas())
+ {
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+ Erase(dc);
+
+ m_shadowMode = mode;
+
+ Draw(dc);
+ }
+ else
+ {
+ m_shadowMode = mode;
+ }
+}
+
+void wxShape::SetCanvas(wxShapeCanvas *theCanvas)
+{
+ m_canvas = theCanvas;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->SetCanvas(theCanvas);
+ node = node->Next();
+ }
+}
+
+void wxShape::AddToCanvas(wxShapeCanvas *theCanvas, wxShape *addAfter)
+{
+ theCanvas->AddShape(this, addAfter);
+ wxNode *node = m_children.First();
+ wxShape *lastImage = this;
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->AddToCanvas(theCanvas, lastImage);
+ lastImage = object;
+
+ node = node->Next();
+ }
+}
+
+// Insert at front of canvas
+void wxShape::InsertInCanvas(wxShapeCanvas *theCanvas)
+{
+ theCanvas->InsertShape(this);
+ wxNode *node = m_children.First();
+ wxShape *lastImage = this;
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->AddToCanvas(theCanvas, lastImage);
+ lastImage = object;
+
+ node = node->Next();
+ }
+}
+
+void wxShape::RemoveFromCanvas(wxShapeCanvas *theCanvas)
+{
+ if (Selected())
+ Select(FALSE);
+ theCanvas->RemoveShape(this);
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->RemoveFromCanvas(theCanvas);
+
+ node = node->Next();
+ }
+}
+
+void wxShape::ClearAttachments()
+{
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ delete point;
+ node = node->Next();
+ }
+ m_attachmentPoints.Clear();
+}
+
+void wxShape::ClearText(int regionId)
+{
+ if (regionId == 0)
+ {
+ m_text.DeleteContents(TRUE);
+ m_text.Clear();
+ m_text.DeleteContents(FALSE);
+ }
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->ClearText();
+}
+
+void wxShape::ClearRegions()
+{
+ wxNode *node = m_regions.First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ wxNode *next = node->Next();
+ delete region;
+ delete node;
+ node = next;
+ }
+}
+
+void wxShape::AddRegion(wxShapeRegion *region)
+{
+ m_regions.Append(region);
+}
+
+void wxShape::SetDefaultRegionSize()
+{
+ wxNode *node = m_regions.First();
+ if (!node) return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ double w, h;
+ GetBoundingBoxMin(&w, &h);
+ region->SetSize(w, h);
+}
+
+bool wxShape::HitTest(double x, double y, int *attachment, double *distance)
+{
+// if (!sensitive)
+// return FALSE;
+
+ double width = 0.0, height = 0.0;
+ GetBoundingBoxMin(&width, &height);
+ if (fabs(width) < 4.0) width = 4.0;
+ if (fabs(height) < 4.0) height = 4.0;
+
+ width += (double)4.0; height += (double)4.0; // Allowance for inaccurate mousing
+
+ double left = (double)(m_xpos - (width/2.0));
+ double top = (double)(m_ypos - (height/2.0));
+ double right = (double)(m_xpos + (width/2.0));
+ double bottom = (double)(m_ypos + (height/2.0));
+
+ int nearest_attachment = 0;
+
+ // If within the bounding box, check the attachment points
+ // within the object.
+
+ if (x >= left && x <= right && y >= top && y <= bottom)
+ {
+ int n = GetNumberOfAttachments();
+ double nearest = 999999.0;
+
+ // GetAttachmentPosition[Edge] takes a logical attachment position,
+ // i.e. if it's rotated through 90%, position 0 is East-facing.
+
+ for (int i = 0; i < n; i++)
+ {
+ double xp, yp;
+ if (GetAttachmentPositionEdge(i, &xp, &yp))
+ {
+ double l = (double)sqrt(((xp - x) * (xp - x)) +
+ ((yp - y) * (yp - y)));
+
+ if (l < nearest)
+ {
+ nearest = l;
+ nearest_attachment = i;
+ }
+ }
+ }
+ *attachment = nearest_attachment;
+ *distance = nearest;
+ return TRUE;
+ }
+ else return FALSE;
+}
+
+// Format a text string according to the region size, adding
+// strings with positions to region text list
+
+static bool GraphicsInSizeToContents = FALSE; // Infinite recursion elimination
+void wxShape::FormatText(wxDC& dc, const wxString& s, int i)
+{
+ double w, h;
+ ClearText(i);
+
+ if (m_regions.Number() < 1)
+ return;
+ wxNode *node = m_regions.Nth(i);
+ if (!node)
+ return;
+
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetText(s);
+ dc.SetFont(* region->GetFont());
+
+ region->GetSize(&w, &h);
+
+ wxStringList *stringList = oglFormatText(dc, s, (w-5), (h-5), region->GetFormatMode());
+ node = stringList->First();
+ while (node)
+ {
+ char *s = (char *)node->Data();
+ wxShapeTextLine *line = new wxShapeTextLine(0.0, 0.0, s);
+ region->GetFormattedText().Append((wxObject *)line);
+ node = node->Next();
+ }
+ delete stringList;
+ double actualW = w;
+ double actualH = h;
+ // Don't try to resize an object with more than one image (this case should be dealt
+ // with by overriden handlers)
+ if ((region->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS) &&
+ (region->GetFormattedText().Number() > 0) &&
+ (m_regions.Number() == 1) && !GraphicsInSizeToContents)
+ {
+ oglGetCentredTextExtent(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, &actualW, &actualH);
+ if ((actualW+m_textMarginX != w ) || (actualH+m_textMarginY != h))
+ {
+ // If we are a descendant of a composite, must make sure the composite gets
+ // resized properly
+ wxShape *topAncestor = GetTopAncestor();
+
+ if (topAncestor != this)
+ {
+ // Make sure we don't recurse infinitely
+ GraphicsInSizeToContents = TRUE;
+
+ wxCompositeShape *composite = (wxCompositeShape *)topAncestor;
+ composite->Erase(dc);
+ SetSize(actualW+m_textMarginX, actualH+m_textMarginY);
+ Move(dc, m_xpos, m_ypos);
+ composite->CalculateSize();
+ if (composite->Selected())
+ {
+ composite->DeleteControlPoints(& dc);
+ composite->MakeControlPoints();
+ composite->MakeMandatoryControlPoints();
+ }
+ // Where infinite recursion might happen if we didn't stop it
+ composite->Draw(dc);
+
+ GraphicsInSizeToContents = FALSE;
+ }
+ else
+ {
+ Erase(dc);
+ SetSize(actualW+m_textMarginX, actualH+m_textMarginY);
+ Move(dc, m_xpos, m_ypos);
+ }
+ SetSize(actualW+m_textMarginX, actualH+m_textMarginY);
+ Move(dc, m_xpos, m_ypos);
+ EraseContents(dc);
+ }
+ }
+ oglCentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, actualW, actualH, region->GetFormatMode());
+ m_formatted = TRUE;
+}
+
+void wxShape::Recentre(wxDC& dc)
+{
+ double w, h;
+ GetBoundingBoxMin(&w, &h);
+
+ int noRegions = m_regions.Number();
+ for (int i = 0; i < noRegions; i++)
+ {
+ wxNode *node = m_regions.Nth(i);
+ if (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ oglCentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, region->GetFormatMode());
+ }
+ }
+}
+
+bool wxShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ return FALSE;
+}
+
+void wxShape::SetPen(wxPen *the_pen)
+{
+ m_pen = the_pen;
+}
+
+void wxShape::SetBrush(wxBrush *the_brush)
+{
+ m_brush = the_brush;
+}
+
+// Get the top-most (non-division) ancestor, or self
+wxShape *wxShape::GetTopAncestor()
+{
+ if (!GetParent())
+ return this;
+
+ if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape)))
+ return this;
+ else return GetParent()->GetTopAncestor();
+}
+
+/*
+ * Region functions
+ *
+ */
+void wxShape::SetFont(wxFont *the_font, int regionId)
+{
+ m_font = the_font;
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetFont(the_font);
+}
+
+wxFont *wxShape::GetFont(int n) const
+{
+ wxNode *node = m_regions.Nth(n);
+ if (!node)
+ return NULL;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ return region->GetFont();
+}
+
+void wxShape::SetFormatMode(int mode, int regionId)
+{
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetFormatMode(mode);
+}
+
+int wxShape::GetFormatMode(int regionId) const
+{
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return 0;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ return region->GetFormatMode();
+}
+
+void wxShape::SetTextColour(const wxString& the_colour, int regionId)
+{
+ wxColour *wxcolour = wxTheColourDatabase->FindColour(the_colour);
+ m_textColour = wxcolour;
+ m_textColourName = the_colour;
+
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetColour(the_colour);
+}
+
+wxString wxShape::GetTextColour(int regionId) const
+{
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return wxString("");
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ return region->GetColour();
+}
+
+void wxShape::SetRegionName(const wxString& name, int regionId)
+{
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetName(name);
+}
+
+wxString wxShape::GetRegionName(int regionId)
+{
+ wxNode *node = m_regions.Nth(regionId);
+ if (!node)
+ return wxString("");
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ return region->GetName();
+}
+
+int wxShape::GetRegionId(const wxString& name)
+{
+ wxNode *node = m_regions.First();
+ int i = 0;
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ if (region->GetName() == name)
+ return i;
+ node = node->Next();
+ i ++;
+ }
+ return -1;
+}
+
+// Name all m_regions in all subimages recursively.
+void wxShape::NameRegions(const wxString& parentName)
+{
+ int n = GetNumberOfTextRegions();
+ char buf[100];
+ for (int i = 0; i < n; i++)
+ {
+ if (parentName.Length() > 0)
+ sprintf(buf, "%s.%d", (const char*) parentName, i);
+ else
+ sprintf(buf, "%d", i);
+ SetRegionName(buf, i);
+ }
+ wxNode *node = m_children.First();
+ int j = 0;
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ if (parentName.Length() > 0)
+ sprintf(buf, "%s.%d", (const char*) parentName, j);
+ else
+ sprintf(buf, "%d", j);
+ child->NameRegions(buf);
+ node = node->Next();
+ j ++;
+ }
+}
+
+// Get a region by name, possibly looking recursively into composites.
+wxShape *wxShape::FindRegion(const wxString& name, int *regionId)
+{
+ int id = GetRegionId(name);
+ if (id > -1)
+ {
+ *regionId = id;
+ return this;
+ }
+
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ wxShape *actualImage = child->FindRegion(name, regionId);
+ if (actualImage)
+ return actualImage;
+ node = node->Next();
+ }
+ return NULL;
+}
+
+// Finds all region names for this image (composite or simple).
+// Supply empty string list.
+void wxShape::FindRegionNames(wxStringList& list)
+{
+ int n = GetNumberOfTextRegions();
+ for (int i = 0; i < n; i++)
+ {
+ wxString name(GetRegionName(i));
+ list.Add((const char*) name);
+ }
+
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->FindRegionNames(list);
+ node = node->Next();
+ }
+}
+
+void wxShape::AssignNewIds()
+{
+// if (m_id == 0)
+ m_id = wxNewId();
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->AssignNewIds();
+ node = node->Next();
+ }
+}
+
+void wxShape::OnDraw(wxDC& dc)
+{
+}
+
+void wxShape::OnMoveLinks(wxDC& dc)
+{
+ // Want to set the ends of all attached links
+ // to point to/from this object
+
+ wxNode *current = m_lines.First();
+ while (current)
+ {
+ wxLineShape *line = (wxLineShape *)current->Data();
+ line->GetEventHandler()->OnMoveLink(dc);
+ current = current->Next();
+ }
+}
+
+
+void wxShape::OnDrawContents(wxDC& dc)
+{
+ double bound_x, bound_y;
+ GetBoundingBoxMin(&bound_x, &bound_y);
+ if (m_regions.Number() < 1) return;
+
+ if (m_pen) dc.SetPen(* m_pen);
+
+ wxShapeRegion *region = (wxShapeRegion *)m_regions.First()->Data();
+ if (region->GetFont()) dc.SetFont(* region->GetFont());
+
+ dc.SetTextForeground(* (region->GetActualColourObject()));
+ dc.SetBackgroundMode(wxTRANSPARENT);
+ if (!m_formatted)
+ {
+ oglCentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, bound_x, bound_y, region->GetFormatMode());
+ m_formatted = TRUE;
+ }
+ if (!GetDisableLabel())
+ {
+ oglDrawFormattedText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, bound_x, bound_y, region->GetFormatMode());
+ }
+}
+
+void wxShape::DrawContents(wxDC& dc)
+{
+ GetEventHandler()->OnDrawContents(dc);
+}
+
+void wxShape::OnSize(double x, double y)
+{
+}
+
+bool wxShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+ return TRUE;
+}
+
+void wxShape::OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+}
+
+void wxShape::OnErase(wxDC& dc)
+{
+ if (!m_visible)
+ return;
+
+ // Erase links
+ wxNode *current = m_lines.First();
+ while (current)
+ {
+ wxLineShape *line = (wxLineShape *)current->Data();
+ line->GetEventHandler()->OnErase(dc);
+ current = current->Next();
+ }
+ GetEventHandler()->OnEraseContents(dc);
+}
+
+void wxShape::OnEraseContents(wxDC& dc)
+{
+ if (!m_visible)
+ return;
+
+ double maxX, maxY, minX, minY;
+ double xp = GetX();
+ double yp = GetY();
+ GetBoundingBoxMin(&minX, &minY);
+ GetBoundingBoxMax(&maxX, &maxY);
+ double topLeftX = (double)(xp - (maxX / 2.0) - 2.0);
+ double topLeftY = (double)(yp - (maxY / 2.0) - 2.0);
+
+ int penWidth = 0;
+ if (m_pen)
+ penWidth = m_pen->GetWidth();
+
+ dc.SetPen(* g_oglWhiteBackgroundPen);
+ dc.SetBrush(* g_oglWhiteBackgroundBrush);
+ dc.DrawRectangle(WXROUND(topLeftX - penWidth), WXROUND(topLeftY - penWidth),
+ WXROUND(maxX + penWidth*2.0 + 4.0), WXROUND(maxY + penWidth*2.0 + 4.0));
+}
+
+void wxShape::EraseLinks(wxDC& dc, int attachment, bool recurse)
+{
+ if (!m_visible)
+ return;
+
+ wxNode *current = m_lines.First();
+ while (current)
+ {
+ wxLineShape *line = (wxLineShape *)current->Data();
+ if (attachment == -1 || ((line->GetTo() == this && line->GetAttachmentTo() == attachment) ||
+ (line->GetFrom() == this && line->GetAttachmentFrom() == attachment)))
+ line->GetEventHandler()->OnErase(dc);
+ current = current->Next();
+ }
+ if (recurse)
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->EraseLinks(dc, attachment, recurse);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::DrawLinks(wxDC& dc, int attachment, bool recurse)
+{
+ if (!m_visible)
+ return;
+
+ wxNode *current = m_lines.First();
+ while (current)
+ {
+ wxLineShape *line = (wxLineShape *)current->Data();
+ if (attachment == -1 ||
+ (line->GetTo() == this && line->GetAttachmentTo() == attachment) ||
+ (line->GetFrom() == this && line->GetAttachmentFrom() == attachment))
+ line->Draw(dc);
+ current = current->Next();
+ }
+ if (recurse)
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->DrawLinks(dc, attachment, recurse);
+ node = node->Next();
+ }
+ }
+}
+
+// Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
+// edge of the shape.
+// attachmentPoint is the attachment point (= side) in question.
+
+// This is the default, rectangular implementation.
+bool wxShape::AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2)
+{
+ int physicalAttachment = LogicalToPhysicalAttachment(attachmentPoint);
+ switch (physicalAttachment)
+ {
+ case 0:
+ case 2:
+ {
+ return (pt1.x <= pt2.x) ;
+ break;
+ }
+ case 1:
+ case 3:
+ {
+ return (pt1.y <= pt2.y) ;
+ break;
+ }
+ }
+
+ return FALSE;
+}
+
+bool wxShape::MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
+ double x, double y)
+{
+ if (GetAttachmentMode() == ATTACHMENT_MODE_NONE)
+ return FALSE;
+
+ int newAttachment, oldAttachment;
+ double distance;
+
+ // Is (x, y) on this object? If so, find the new attachment point
+ // the user has moved the point to
+ bool hit = HitTest(x, y, &newAttachment, &distance);
+ if (!hit)
+ return FALSE;
+
+ EraseLinks(dc);
+
+ if (to_move->GetTo() == this)
+ oldAttachment = to_move->GetAttachmentTo();
+ else
+ oldAttachment = to_move->GetAttachmentFrom();
+
+ // The links in a new ordering.
+ wxList newOrdering;
+
+ // First, add all links to the new list.
+ wxNode *node = m_lines.First();
+ while (node)
+ {
+ newOrdering.Append(node->Data());
+ node = node->Next();
+ }
+
+ // Delete the line object from the list of links; we're going to move
+ // it to another position in the list
+ newOrdering.DeleteObject(to_move);
+
+ double old_x = (double) -99999.9;
+ double old_y = (double) -99999.9;
+
+ node = newOrdering.First();
+ bool found = FALSE;
+
+ while (!found && node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ if ((line->GetTo() == this && oldAttachment == line->GetAttachmentTo()) ||
+ (line->GetFrom() == this && oldAttachment == line->GetAttachmentFrom()))
+ {
+ double startX, startY, endX, endY;
+ double xp, yp;
+ line->GetEnds(&startX, &startY, &endX, &endY);
+ if (line->GetTo() == this)
+ {
+ xp = endX;
+ yp = endY;
+ } else
+ {
+ xp = startX;
+ yp = startY;
+ }
+
+ wxRealPoint thisPoint(xp, yp);
+ wxRealPoint lastPoint(old_x, old_y);
+ wxRealPoint newPoint(x, y);
+
+ if (AttachmentSortTest(newAttachment, newPoint, thisPoint) && AttachmentSortTest(newAttachment, lastPoint, newPoint))
+ {
+ found = TRUE;
+ newOrdering.Insert(node, to_move);
+ }
+
+ old_x = xp;
+ old_y = yp;
+ }
+ node = node->Next();
+ }
+
+ if (!found)
+ newOrdering.Append(to_move);
+
+ GetEventHandler()->OnChangeAttachment(newAttachment, to_move, newOrdering);
+
+ return TRUE;
+}
+
+void wxShape::OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering)
+{
+ if (line->GetTo() == this)
+ line->SetAttachmentTo(attachment);
+ else
+ line->SetAttachmentFrom(attachment);
+
+ ApplyAttachmentOrdering(ordering);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ MoveLinks(dc);
+
+ if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc);
+}
+
+// Reorders the lines according to the given list.
+void wxShape::ApplyAttachmentOrdering(wxList& linesToSort)
+{
+ // This is a temporary store of all the lines.
+ wxList linesStore;
+
+ wxNode *node = m_lines.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ linesStore.Append(line);
+ node = node->Next();;
+ }
+
+ m_lines.Clear();
+
+ node = linesToSort.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ if (linesStore.Member(line))
+ {
+ // Done this one
+ linesStore.DeleteObject(line);
+ m_lines.Append(line);
+ }
+ node = node->Next();
+ }
+
+ // Now add any lines that haven't been listed in linesToSort.
+ node = linesStore.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ m_lines.Append(line);
+ node = node->Next();
+ }
+}
+
+// Reorders the lines coming into the node image at this attachment
+// position, in the order in which they appear in linesToSort.
+// Any remaining lines not in the list will be added to the end.
+void wxShape::SortLines(int attachment, wxList& linesToSort)
+{
+ // This is a temporary store of all the lines at this attachment
+ // point. We'll tick them off as we've processed them.
+ wxList linesAtThisAttachment;
+
+ wxNode *node = m_lines.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ wxNode *next = node->Next();
+ if ((line->GetTo() == this && line->GetAttachmentTo() == attachment) ||
+ (line->GetFrom() == this && line->GetAttachmentFrom() == attachment))
+ {
+ linesAtThisAttachment.Append(line);
+ delete node;
+ node = next;
+ }
+ else node = node->Next();
+ }
+
+ node = linesToSort.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ if (linesAtThisAttachment.Member(line))
+ {
+ // Done this one
+ linesAtThisAttachment.DeleteObject(line);
+ m_lines.Append(line);
+ }
+ node = node->Next();
+ }
+
+ // Now add any lines that haven't been listed in linesToSort.
+ node = linesAtThisAttachment.First();
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+ m_lines.Append(line);
+ node = node->Next();
+ }
+}
+
+void wxShape::OnHighlight(wxDC& dc)
+{
+}
+
+void wxShape::OnLeftClick(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_CLICK_LEFT) != OP_CLICK_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnLeftClick(x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+void wxShape::OnRightClick(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_CLICK_RIGHT) != OP_CLICK_RIGHT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnRightClick(x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+double DragOffsetX = 0.0;
+double DragOffsetY = 0.0;
+
+void wxShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnDragLeft(draw, x, y, keys, attachment);
+ }
+ return;
+ }
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+
+ double xx, yy;
+ xx = x + DragOffsetX;
+ yy = y + DragOffsetY;
+
+ m_canvas->Snap(&xx, &yy);
+// m_xpos = xx; m_ypos = yy;
+ double w, h;
+ GetBoundingBoxMax(&w, &h);
+ GetEventHandler()->OnDrawOutline(dc, xx, yy, w, h);
+}
+
+void wxShape::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnBeginDragLeft(x, y, keys, attachment);
+ }
+ return;
+ }
+
+ DragOffsetX = m_xpos - x;
+ DragOffsetY = m_ypos - y;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ // New policy: don't erase shape until end of drag.
+// Erase(dc);
+
+ double xx, yy;
+ xx = x + DragOffsetX;
+ yy = y + DragOffsetY;
+ m_canvas->Snap(&xx, &yy);
+// m_xpos = xx; m_ypos = yy;
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ double w, h;
+ GetBoundingBoxMax(&w, &h);
+ GetEventHandler()->OnDrawOutline(dc, xx, yy, w, h);
+ m_canvas->CaptureMouse();
+}
+
+void wxShape::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ m_canvas->ReleaseMouse();
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnEndDragLeft(x, y, keys, attachment);
+ }
+ return;
+ }
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(wxCOPY);
+
+ double xx = x + DragOffsetX;
+ double yy = y + DragOffsetY;
+ m_canvas->Snap(&xx, &yy);
+// canvas->Snap(&m_xpos, &m_ypos);
+
+ // New policy: erase shape at end of drag.
+ Erase(dc);
+
+ Move(dc, xx, yy);
+ if (m_canvas && !m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);
+}
+
+void wxShape::OnDragRight(bool draw, double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_RIGHT) != OP_DRAG_RIGHT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnDragRight(draw, x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+void wxShape::OnBeginDragRight(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_RIGHT) != OP_DRAG_RIGHT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnBeginDragRight(x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+void wxShape::OnEndDragRight(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_RIGHT) != OP_DRAG_RIGHT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnEndDragRight(x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+void wxShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
+{
+ double top_left_x = (double)(x - w/2.0);
+ double top_left_y = (double)(y - h/2.0);
+ double top_right_x = (double)(top_left_x + w);
+ double top_right_y = (double)top_left_y;
+ double bottom_left_x = (double)top_left_x;
+ double bottom_left_y = (double)(top_left_y + h);
+ double bottom_right_x = (double)top_right_x;
+ double bottom_right_y = (double)bottom_left_y;
+
+ wxPoint points[5];
+ points[0].x = WXROUND(top_left_x); points[0].y = WXROUND(top_left_y);
+ points[1].x = WXROUND(top_right_x); points[1].y = WXROUND(top_right_y);
+ points[2].x = WXROUND(bottom_right_x); points[2].y = WXROUND(bottom_right_y);
+ points[3].x = WXROUND(bottom_left_x); points[3].y = WXROUND(bottom_left_y);
+ points[4].x = WXROUND(top_left_x); points[4].y = WXROUND(top_left_y);
+
+ dc.DrawLines(5, points);
+}
+
+void wxShape::Attach(wxShapeCanvas *can)
+{
+ m_canvas = can;
+}
+
+void wxShape::Detach()
+{
+ m_canvas = NULL;
+}
+
+void wxShape::Move(wxDC& dc, double x, double y, bool display)
+{
+ double old_x = m_xpos;
+ double old_y = m_ypos;
+
+ if (!GetEventHandler()->OnMovePre(dc, x, y, old_x, old_y, display))
+ {
+// m_xpos = old_x;
+// m_ypos = old_y;
+ return;
+ }
+
+ m_xpos = x; m_ypos = y;
+
+ ResetControlPoints();
+
+ if (display)
+ Draw(dc);
+
+ MoveLinks(dc);
+
+ GetEventHandler()->OnMovePost(dc, x, y, old_x, old_y, display);
+}
+
+void wxShape::MoveLinks(wxDC& dc)
+{
+ GetEventHandler()->OnMoveLinks(dc);
+}
+
+
+void wxShape::Draw(wxDC& dc)
+{
+ if (m_visible)
+ {
+ GetEventHandler()->OnDraw(dc);
+ GetEventHandler()->OnDrawContents(dc);
+ GetEventHandler()->OnDrawControlPoints(dc);
+ GetEventHandler()->OnDrawBranches(dc);
+ }
+}
+
+void wxShape::Flash()
+{
+ if (GetCanvas())
+ {
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+ Draw(dc);
+ dc.SetLogicalFunction(wxCOPY);
+ Draw(dc);
+ }
+}
+
+void wxShape::Show(bool show)
+{
+ m_visible = show;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *image = (wxShape *)node->Data();
+ image->Show(show);
+ node = node->Next();
+ }
+}
+
+void wxShape::Erase(wxDC& dc)
+{
+ GetEventHandler()->OnErase(dc);
+ GetEventHandler()->OnEraseControlPoints(dc);
+ GetEventHandler()->OnDrawBranches(dc, TRUE);
+}
+
+void wxShape::EraseContents(wxDC& dc)
+{
+ GetEventHandler()->OnEraseContents(dc);
+}
+
+void wxShape::AddText(const wxString& string)
+{
+ wxNode *node = m_regions.First();
+ if (!node)
+ return;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->ClearText();
+ wxShapeTextLine *new_line =
+ new wxShapeTextLine(0.0, 0.0, string);
+ region->GetFormattedText().Append(new_line);
+
+ m_formatted = FALSE;
+}
+
+void wxShape::SetSize(double x, double y, bool recursive)
+{
+ SetAttachmentSize(x, y);
+ SetDefaultRegionSize();
+}
+
+void wxShape::SetAttachmentSize(double w, double h)
+{
+ double scaleX;
+ double scaleY;
+ double width, height;
+ GetBoundingBoxMin(&width, &height);
+ if (width == 0.0)
+ scaleX = 1.0;
+ else scaleX = w/width;
+ if (height == 0.0)
+ scaleY = 1.0;
+ else scaleY = h/height;
+
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ point->m_x = (double)(point->m_x * scaleX);
+ point->m_y = (double)(point->m_y * scaleY);
+ node = node->Next();
+ }
+}
+
+// Add line FROM this object
+void wxShape::AddLine(wxLineShape *line, wxShape *other,
+ int attachFrom, int attachTo,
+ // The line ordering
+ int positionFrom, int positionTo)
+{
+ if (positionFrom == -1)
+ {
+ if (!m_lines.Member(line))
+ m_lines.Append(line);
+ }
+ else
+ {
+ // Don't preserve old ordering if we have new ordering instructions
+ m_lines.DeleteObject(line);
+ if (positionFrom < m_lines.Number())
+ {
+ wxNode* node = m_lines.Nth(positionFrom);
+ m_lines.Insert(node, line);
+ }
+ else
+ m_lines.Append(line);
+ }
+
+ if (positionTo == -1)
+ {
+ if (!other->m_lines.Member(line))
+ other->m_lines.Append(line);
+ }
+ else
+ {
+ // Don't preserve old ordering if we have new ordering instructions
+ other->m_lines.DeleteObject(line);
+ if (positionTo < other->m_lines.Number())
+ {
+ wxNode* node = other->m_lines.Nth(positionTo);
+ other->m_lines.Insert(node, line);
+ }
+ else
+ other->m_lines.Append(line);
+ }
+#if 0
+ // Wrong: doesn't preserve ordering of shape already linked
+ m_lines.DeleteObject(line);
+ other->m_lines.DeleteObject(line);
+
+ if (positionFrom == -1)
+ m_lines.Append(line);
+ else
+ {
+ if (positionFrom < m_lines.Number())
+ {
+ wxNode* node = m_lines.Nth(positionFrom);
+ m_lines.Insert(node, line);
+ }
+ else
+ m_lines.Append(line);
+ }
+
+ if (positionTo == -1)
+ other->m_lines.Append(line);
+ else
+ {
+ if (positionTo < other->m_lines.Number())
+ {
+ wxNode* node = other->m_lines.Nth(positionTo);
+ other->m_lines.Insert(node, line);
+ }
+ else
+ other->m_lines.Append(line);
+ }
+#endif
+
+ line->SetFrom(this);
+ line->SetTo(other);
+ line->SetAttachments(attachFrom, attachTo);
+}
+
+void wxShape::RemoveLine(wxLineShape *line)
+{
+ if (line->GetFrom() == this)
+ line->GetTo()->m_lines.DeleteObject(line);
+ else
+ line->GetFrom()->m_lines.DeleteObject(line);
+
+ m_lines.DeleteObject(line);
+}
+
+#ifdef PROLOGIO
+void wxShape::WriteAttributes(wxExpr *clause)
+{
+ clause->AddAttributeValueString("type", GetClassInfo()->GetClassName());
+ clause->AddAttributeValue("id", m_id);
+
+ if (m_pen)
+ {
+ int penWidth = m_pen->GetWidth();
+ int penStyle = m_pen->GetStyle();
+ if (penWidth != 1)
+ clause->AddAttributeValue("pen_width", (long)penWidth);
+ if (penStyle != wxSOLID)
+ clause->AddAttributeValue("pen_style", (long)penStyle);
+
+ wxString penColour = wxTheColourDatabase->FindName(m_pen->GetColour());
+ if (penColour == "")
+ {
+ wxString hex(oglColourToHex(m_pen->GetColour()));
+ hex = wxString("#") + hex;
+ clause->AddAttributeValueString("pen_colour", hex);
+ }
+ else if (penColour != "BLACK")
+ clause->AddAttributeValueString("pen_colour", penColour);
+ }
+
+ if (m_brush)
+ {
+ wxString brushColour = wxTheColourDatabase->FindName(m_brush->GetColour());
+
+ if (brushColour == "")
+ {
+ wxString hex(oglColourToHex(m_brush->GetColour()));
+ hex = wxString("#") + hex;
+ clause->AddAttributeValueString("brush_colour", hex);
+ }
+ else if (brushColour != "WHITE")
+ clause->AddAttributeValueString("brush_colour", brushColour);
+
+ if (m_brush->GetStyle() != wxSOLID)
+ clause->AddAttributeValue("brush_style", (long)m_brush->GetStyle());
+ }
+
+ // Output line ids
+
+ int n_lines = m_lines.Number();
+ if (n_lines > 0)
+ {
+ wxExpr *list = new wxExpr(wxExprList);
+ wxNode *node = m_lines.First();
+ while (node)
+ {
+ wxShape *line = (wxShape *)node->Data();
+ wxExpr *id_expr = new wxExpr(line->GetId());
+ list->Append(id_expr);
+ node = node->Next();
+ }
+ clause->AddAttributeValue("arcs", list);
+ }
+
+ // Miscellaneous members
+ if (m_attachmentMode != 0)
+ clause->AddAttributeValue("use_attachments", (long)m_attachmentMode);
+ if (m_sensitivity != OP_ALL)
+ clause->AddAttributeValue("sensitivity", (long)m_sensitivity);
+ if (!m_spaceAttachments)
+ clause->AddAttributeValue("space_attachments", (long)m_spaceAttachments);
+ if (m_fixedWidth)
+ clause->AddAttributeValue("fixed_width", (long)m_fixedWidth);
+ if (m_fixedHeight)
+ clause->AddAttributeValue("fixed_height", (long)m_fixedHeight);
+ if (m_shadowMode != SHADOW_NONE)
+ clause->AddAttributeValue("shadow_mode", (long)m_shadowMode);
+ if (m_centreResize != TRUE)
+ clause->AddAttributeValue("centre_resize", (long)0);
+ clause->AddAttributeValue("maintain_aspect_ratio", (long) m_maintainAspectRatio);
+ if (m_highlighted != FALSE)
+ clause->AddAttributeValue("hilite", (long)m_highlighted);
+
+ if (m_parent) // For composite objects
+ clause->AddAttributeValue("parent", (long)m_parent->GetId());
+
+ if (m_rotation != 0.0)
+ clause->AddAttributeValue("rotation", m_rotation);
+
+ if (!this->IsKindOf(CLASSINFO(wxLineShape)))
+ {
+ clause->AddAttributeValue("neck_length", (long) m_branchNeckLength);
+ clause->AddAttributeValue("stem_length", (long) m_branchStemLength);
+ clause->AddAttributeValue("branch_spacing", (long) m_branchSpacing);
+ clause->AddAttributeValue("branch_style", (long) m_branchStyle);
+ }
+
+ // Write user-defined attachment points, if any
+ if (m_attachmentPoints.Number() > 0)
+ {
+ wxExpr *attachmentList = new wxExpr(wxExprList);
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ wxExpr *pointExpr = new wxExpr(wxExprList);
+ pointExpr->Append(new wxExpr((long)point->m_id));
+ pointExpr->Append(new wxExpr(point->m_x));
+ pointExpr->Append(new wxExpr(point->m_y));
+ attachmentList->Append(pointExpr);
+ node = node->Next();
+ }
+ clause->AddAttributeValue("user_attachments", attachmentList);
+ }
+
+ // Write text regions
+ WriteRegions(clause);
+}
+
+void wxShape::WriteRegions(wxExpr *clause)
+{
+ // Output regions as region1 = (...), region2 = (...), etc
+ // and formatted text as text1 = (...), text2 = (...) etc.
+ int regionNo = 1;
+ char regionNameBuf[20];
+ char textNameBuf[20];
+ wxNode *node = m_regions.First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ sprintf(regionNameBuf, "region%d", regionNo);
+ sprintf(textNameBuf, "text%d", regionNo);
+
+ // Original text and region attributes:
+ // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
+ // formatMode fontSize fontFamily fontStyle fontWeight textColour)
+ wxExpr *regionExpr = new wxExpr(wxExprList);
+ regionExpr->Append(new wxExpr(wxExprString, region->m_regionName));
+ regionExpr->Append(new wxExpr(wxExprString, region->m_regionText));
+
+ regionExpr->Append(new wxExpr(region->m_x));
+ regionExpr->Append(new wxExpr(region->m_y));
+ regionExpr->Append(new wxExpr(region->GetWidth()));
+ regionExpr->Append(new wxExpr(region->GetHeight()));
+
+ regionExpr->Append(new wxExpr(region->m_minWidth));
+ regionExpr->Append(new wxExpr(region->m_minHeight));
+ regionExpr->Append(new wxExpr(region->m_regionProportionX));
+ regionExpr->Append(new wxExpr(region->m_regionProportionY));
+
+ regionExpr->Append(new wxExpr((long)region->m_formatMode));
+
+ regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetPointSize() : 10)));
+ regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetFamily() : wxDEFAULT)));
+ regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetStyle() : wxDEFAULT)));
+ regionExpr->Append(new wxExpr((long)(region->m_font ? region->m_font->GetWeight() : wxNORMAL)));
+ regionExpr->Append(new wxExpr(wxExprString, region->m_textColour));
+
+ // New members for pen colour/style
+ regionExpr->Append(new wxExpr(wxExprString, region->m_penColour));
+ regionExpr->Append(new wxExpr((long)region->m_penStyle));
+
+ // Formatted text:
+ // text1 = ((x y string) (x y string) ...)
+ wxExpr *textExpr = new wxExpr(wxExprList);
+
+ wxNode *textNode = region->m_formattedText.First();
+ while (textNode)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)textNode->Data();
+ wxExpr *list2 = new wxExpr(wxExprList);
+ list2->Append(new wxExpr(line->GetX()));
+ list2->Append(new wxExpr(line->GetY()));
+ list2->Append(new wxExpr(wxExprString, line->GetText()));
+ textExpr->Append(list2);
+ textNode = textNode->Next();
+ }
+
+ // Now add both attributes to the clause
+ clause->AddAttributeValue(regionNameBuf, regionExpr);
+ clause->AddAttributeValue(textNameBuf, textExpr);
+
+ node = node->Next();
+ regionNo ++;
+ }
+}
+
+void wxShape::ReadAttributes(wxExpr *clause)
+{
+ clause->GetAttributeValue("id", m_id);
+ wxRegisterId(m_id);
+
+ clause->GetAttributeValue("x", m_xpos);
+ clause->GetAttributeValue("y", m_ypos);
+
+ // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
+ ClearText();
+ wxExpr *strings = clause->AttributeValue("text");
+ if (strings && strings->Type() == wxExprList)
+ {
+ m_formatted = TRUE; // Assume text is formatted unless we prove otherwise
+ wxExpr *node = strings->value.first;
+ while (node)
+ {
+ wxExpr *string_expr = node;
+ double the_x = 0.0;
+ double the_y = 0.0;
+ wxString the_string("");
+
+ // string_expr can either be a string, or a list of
+ // 3 elements: x, y, and string.
+ if (string_expr->Type() == wxExprString)
+ {
+ the_string = string_expr->StringValue();
+ m_formatted = FALSE;
+ }
+ else if (string_expr->Type() == wxExprList)
+ {
+ wxExpr *first = string_expr->value.first;
+ wxExpr *second = first ? first->next : (wxExpr*) NULL;
+ wxExpr *third = second ? second->next : (wxExpr*) NULL;
+
+ if (first && second && third &&
+ (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
+ (second->Type() == wxExprReal || second->Type() == wxExprInteger) &&
+ third->Type() == wxExprString)
+ {
+ if (first->Type() == wxExprReal)
+ the_x = first->RealValue();
+ else the_x = (double)first->IntegerValue();
+
+ if (second->Type() == wxExprReal)
+ the_y = second->RealValue();
+ else the_y = (double)second->IntegerValue();
+
+ the_string = third->StringValue();
+ }
+ }
+ wxShapeTextLine *line =
+ new wxShapeTextLine(the_x, the_y, (char*) (const char*) the_string);
+ m_text.Append(line);
+
+ node = node->next;
+ }
+ }
+
+ wxString pen_string = "";
+ wxString brush_string = "";
+ int pen_width = 1;
+ int pen_style = wxSOLID;
+ int brush_style = wxSOLID;
+ m_attachmentMode = ATTACHMENT_MODE_NONE;
+
+ clause->GetAttributeValue("pen_colour", pen_string);
+ clause->GetAttributeValue("text_colour", m_textColourName);
+
+ SetTextColour(m_textColourName);
+
+ clause->GetAttributeValue("region_name", m_regionName);
+
+ clause->GetAttributeValue("brush_colour", brush_string);
+ clause->GetAttributeValue("pen_width", pen_width);
+ clause->GetAttributeValue("pen_style", pen_style);
+ clause->GetAttributeValue("brush_style", brush_style);
+
+ int iVal = (int) m_attachmentMode;
+ clause->GetAttributeValue("use_attachments", iVal);
+ m_attachmentMode = iVal;
+
+ clause->GetAttributeValue("sensitivity", m_sensitivity);
+
+ iVal = (int) m_spaceAttachments;
+ clause->GetAttributeValue("space_attachments", iVal);
+ m_spaceAttachments = (iVal != 0);
+
+ iVal = (int) m_fixedWidth;
+ clause->GetAttributeValue("fixed_width", iVal);
+ m_fixedWidth = (iVal != 0);
+
+ iVal = (int) m_fixedHeight;
+ clause->GetAttributeValue("fixed_height", iVal);
+ m_fixedHeight = (iVal != 0);
+
+ clause->GetAttributeValue("format_mode", m_formatMode);
+ clause->GetAttributeValue("shadow_mode", m_shadowMode);
+
+ iVal = m_branchNeckLength;
+ clause->GetAttributeValue("neck_length", iVal);
+ m_branchNeckLength = iVal;
+
+ iVal = m_branchStemLength;
+ clause->GetAttributeValue("stem_length", iVal);
+ m_branchStemLength = iVal;
+
+ iVal = m_branchSpacing;
+ clause->GetAttributeValue("branch_spacing", iVal);
+ m_branchSpacing = iVal;
+
+ clause->GetAttributeValue("branch_style", m_branchStyle);
+
+ iVal = (int) m_centreResize;
+ clause->GetAttributeValue("centre_resize", iVal);
+ m_centreResize = (iVal != 0);
+
+ iVal = (int) m_maintainAspectRatio;
+ clause->GetAttributeValue("maintain_aspect_ratio", iVal);
+ m_maintainAspectRatio = (iVal != 0);
+
+ iVal = (int) m_highlighted;
+ clause->GetAttributeValue("hilite", iVal);
+ m_highlighted = (iVal != 0);
+
+ clause->GetAttributeValue("rotation", m_rotation);
+
+ if (pen_string == "")
+ pen_string = "BLACK";
+ if (brush_string == "")
+ brush_string = "WHITE";
+
+ if (pen_string.GetChar(0) == '#')
+ {
+ wxColour col(oglHexToColour(pen_string.After('#')));
+ m_pen = wxThePenList->FindOrCreatePen(col, pen_width, pen_style);
+ }
+ else
+ m_pen = wxThePenList->FindOrCreatePen(pen_string, pen_width, pen_style);
+
+ if (!m_pen)
+ m_pen = wxBLACK_PEN;
+
+ if (brush_string.GetChar(0) == '#')
+ {
+ wxColour col(oglHexToColour(brush_string.After('#')));
+ m_brush = wxTheBrushList->FindOrCreateBrush(col, brush_style);
+ }
+ else
+ m_brush = wxTheBrushList->FindOrCreateBrush(brush_string, brush_style);
+
+ if (!m_brush)
+ m_brush = wxWHITE_BRUSH;
+
+ int point_size = 10;
+ clause->GetAttributeValue("point_size", point_size);
+ SetFont(oglMatchFont(point_size));
+
+ // Read user-defined attachment points, if any
+ wxExpr *attachmentList = clause->AttributeValue("user_attachments");
+ if (attachmentList)
+ {
+ wxExpr *pointExpr = attachmentList->GetFirst();
+ while (pointExpr)
+ {
+ wxExpr *idExpr = pointExpr->Nth(0);
+ wxExpr *xExpr = pointExpr->Nth(1);
+ wxExpr *yExpr = pointExpr->Nth(2);
+ if (idExpr && xExpr && yExpr)
+ {
+ wxAttachmentPoint *point = new wxAttachmentPoint;
+ point->m_id = (int)idExpr->IntegerValue();
+ point->m_x = xExpr->RealValue();
+ point->m_y = yExpr->RealValue();
+ m_attachmentPoints.Append((wxObject *)point);
+ }
+ pointExpr = pointExpr->GetNext();
+ }
+ }
+
+ // Read text regions
+ ReadRegions(clause);
+}
+
+void wxShape::ReadRegions(wxExpr *clause)
+{
+ ClearRegions();
+
+ // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
+ // formatMode fontSize fontFamily fontStyle fontWeight textColour)
+ int regionNo = 1;
+ char regionNameBuf[20];
+ char textNameBuf[20];
+
+ wxExpr *regionExpr = NULL;
+ wxExpr *textExpr = NULL;
+ sprintf(regionNameBuf, "region%d", regionNo);
+ sprintf(textNameBuf, "text%d", regionNo);
+
+ m_formatted = TRUE; // Assume text is formatted unless we prove otherwise
+
+ while ((regionExpr = clause->AttributeValue(regionNameBuf)))
+ {
+ /*
+ * Get the region information
+ *
+ */
+
+ wxString regionName("");
+ wxString regionText("");
+ double x = 0.0;
+ double y = 0.0;
+ double width = 0.0;
+ double height = 0.0;
+ double minWidth = 5.0;
+ double minHeight = 5.0;
+ double m_regionProportionX = -1.0;
+ double m_regionProportionY = -1.0;
+ int formatMode = FORMAT_NONE;
+ int fontSize = 10;
+ int fontFamily = wxSWISS;
+ int fontStyle = wxNORMAL;
+ int fontWeight = wxNORMAL;
+ wxString regionTextColour("");
+ wxString penColour("");
+ int penStyle = wxSOLID;
+
+ if (regionExpr->Type() == wxExprList)
+ {
+ wxExpr *nameExpr = regionExpr->Nth(0);
+ wxExpr *textExpr = regionExpr->Nth(1);
+ wxExpr *xExpr = regionExpr->Nth(2);
+ wxExpr *yExpr = regionExpr->Nth(3);
+ wxExpr *widthExpr = regionExpr->Nth(4);
+ wxExpr *heightExpr = regionExpr->Nth(5);
+ wxExpr *minWidthExpr = regionExpr->Nth(6);
+ wxExpr *minHeightExpr = regionExpr->Nth(7);
+ wxExpr *propXExpr = regionExpr->Nth(8);
+ wxExpr *propYExpr = regionExpr->Nth(9);
+ wxExpr *formatExpr = regionExpr->Nth(10);
+ wxExpr *sizeExpr = regionExpr->Nth(11);
+ wxExpr *familyExpr = regionExpr->Nth(12);
+ wxExpr *styleExpr = regionExpr->Nth(13);
+ wxExpr *weightExpr = regionExpr->Nth(14);
+ wxExpr *colourExpr = regionExpr->Nth(15);
+ wxExpr *penColourExpr = regionExpr->Nth(16);
+ wxExpr *penStyleExpr = regionExpr->Nth(17);
+
+ regionName = nameExpr->StringValue();
+ regionText = textExpr->StringValue();
+
+ x = xExpr->RealValue();
+ y = yExpr->RealValue();
+
+ width = widthExpr->RealValue();
+ height = heightExpr->RealValue();
+
+ minWidth = minWidthExpr->RealValue();
+ minHeight = minHeightExpr->RealValue();
+
+ m_regionProportionX = propXExpr->RealValue();
+ m_regionProportionY = propYExpr->RealValue();
+
+ formatMode = (int) formatExpr->IntegerValue();
+ fontSize = (int)sizeExpr->IntegerValue();
+ fontFamily = (int)familyExpr->IntegerValue();
+ fontStyle = (int)styleExpr->IntegerValue();
+ fontWeight = (int)weightExpr->IntegerValue();
+
+ if (colourExpr)
+ {
+ regionTextColour = colourExpr->StringValue();
+ }
+ else
+ regionTextColour = "BLACK";
+
+ if (penColourExpr)
+ penColour = penColourExpr->StringValue();
+ if (penStyleExpr)
+ penStyle = (int)penStyleExpr->IntegerValue();
+ }
+ wxFont *font = wxTheFontList->FindOrCreateFont(fontSize, fontFamily, fontStyle, fontWeight);
+
+ wxShapeRegion *region = new wxShapeRegion;
+ region->SetProportions(m_regionProportionX, m_regionProportionY);
+ region->SetFont(font);
+ region->SetSize(width, height);
+ region->SetPosition(x, y);
+ region->SetMinSize(minWidth, minHeight);
+ region->SetFormatMode(formatMode);
+ region->SetPenStyle(penStyle);
+ if (penColour != "")
+ region->SetPenColour(penColour);
+
+ region->m_textColour = regionTextColour;
+ region->m_regionText = regionText;
+ region->m_regionName = regionName;
+
+ m_regions.Append(region);
+
+ /*
+ * Get the formatted text strings
+ *
+ */
+ textExpr = clause->AttributeValue(textNameBuf);
+ if (textExpr && (textExpr->Type() == wxExprList))
+ {
+ wxExpr *node = textExpr->value.first;
+ while (node)
+ {
+ wxExpr *string_expr = node;
+ double the_x = 0.0;
+ double the_y = 0.0;
+ wxString the_string("");
+
+ // string_expr can either be a string, or a list of
+ // 3 elements: x, y, and string.
+ if (string_expr->Type() == wxExprString)
+ {
+ the_string = string_expr->StringValue();
+ m_formatted = FALSE;
+ }
+ else if (string_expr->Type() == wxExprList)
+ {
+ wxExpr *first = string_expr->value.first;
+ wxExpr *second = first ? first->next : (wxExpr*) NULL;
+ wxExpr *third = second ? second->next : (wxExpr*) NULL;
+
+ if (first && second && third &&
+ (first->Type() == wxExprReal || first->Type() == wxExprInteger) &&
+ (second->Type() == wxExprReal || second->Type() == wxExprInteger) &&
+ third->Type() == wxExprString)
+ {
+ if (first->Type() == wxExprReal)
+ the_x = first->RealValue();
+ else the_x = (double)first->IntegerValue();
+
+ if (second->Type() == wxExprReal)
+ the_y = second->RealValue();
+ else the_y = (double)second->IntegerValue();
+
+ the_string = third->StringValue();
+ }
+ }
+ if (the_string)
+ {
+ wxShapeTextLine *line =
+ new wxShapeTextLine(the_x, the_y, (char*) (const char*) the_string);
+ region->m_formattedText.Append(line);
+ }
+ node = node->next;
+ }
+ }
+
+ regionNo ++;
+ sprintf(regionNameBuf, "region%d", regionNo);
+ sprintf(textNameBuf, "text%d", regionNo);
+ }
+
+ // Compatibility: check for no regions (old file).
+ // Lines and divided rectangles must deal with this compatibility
+ // theirselves. Composites _may_ not have any regions anyway.
+ if ((m_regions.Number() == 0) &&
+ !this->IsKindOf(CLASSINFO(wxLineShape)) && !this->IsKindOf(CLASSINFO(wxDividedShape)) &&
+ !this->IsKindOf(CLASSINFO(wxCompositeShape)))
+ {
+ wxShapeRegion *newRegion = new wxShapeRegion;
+ newRegion->SetName("0");
+ m_regions.Append((wxObject *)newRegion);
+ if (m_text.Number() > 0)
+ {
+ newRegion->ClearText();
+ wxNode *node = m_text.First();
+ while (node)
+ {
+ wxShapeTextLine *textLine = (wxShapeTextLine *)node->Data();
+ wxNode *next = node->Next();
+ newRegion->GetFormattedText().Append((wxObject *)textLine);
+ delete node;
+ node = next;
+ }
+ }
+ }
+}
+
+#endif
+
+void wxShape::Copy(wxShape& copy)
+{
+ copy.m_id = m_id;
+ copy.m_xpos = m_xpos;
+ copy.m_ypos = m_ypos;
+ copy.m_pen = m_pen;
+ copy.m_brush = m_brush;
+ copy.m_textColour = m_textColour;
+ copy.m_centreResize = m_centreResize;
+ copy.m_maintainAspectRatio = m_maintainAspectRatio;
+ copy.m_attachmentMode = m_attachmentMode;
+ copy.m_spaceAttachments = m_spaceAttachments;
+ copy.m_highlighted = m_highlighted;
+ copy.m_rotation = m_rotation;
+ copy.m_textColourName = m_textColourName;
+ copy.m_regionName = m_regionName;
+
+ copy.m_sensitivity = m_sensitivity;
+ copy.m_draggable = m_draggable;
+ copy.m_fixedWidth = m_fixedWidth;
+ copy.m_fixedHeight = m_fixedHeight;
+ copy.m_formatMode = m_formatMode;
+ copy.m_drawHandles = m_drawHandles;
+
+ copy.m_visible = m_visible;
+ copy.m_shadowMode = m_shadowMode;
+ copy.m_shadowOffsetX = m_shadowOffsetX;
+ copy.m_shadowOffsetY = m_shadowOffsetY;
+ copy.m_shadowBrush = m_shadowBrush;
+
+ copy.m_branchNeckLength = m_branchNeckLength;
+ copy.m_branchStemLength = m_branchStemLength;
+ copy.m_branchSpacing = m_branchSpacing;
+
+ // Copy text regions
+ copy.ClearRegions();
+ wxNode *node = m_regions.First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ wxShapeRegion *newRegion = new wxShapeRegion(*region);
+ copy.m_regions.Append(newRegion);
+ node = node->Next();
+ }
+
+ // Copy attachments
+ copy.ClearAttachments();
+ node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ wxAttachmentPoint *newPoint = new wxAttachmentPoint;
+ newPoint->m_id = point->m_id;
+ newPoint->m_x = point->m_x;
+ newPoint->m_y = point->m_y;
+ copy.m_attachmentPoints.Append((wxObject *)newPoint);
+ node = node->Next();
+ }
+
+ // Copy lines
+ copy.m_lines.Clear();
+ node = m_lines.First();
+ while (node)
+ {
+ wxLineShape* line = (wxLineShape*) node->Data();
+ copy.m_lines.Append(line);
+ node = node->Next();
+ }
+}
+
+// Create and return a new, fully copied object.
+wxShape *wxShape::CreateNewCopy(bool resetMapping, bool recompute)
+{
+ if (resetMapping)
+ oglObjectCopyMapping.Clear();
+
+ wxShape* newObject = (wxShape*) GetClassInfo()->CreateObject();
+
+ wxASSERT( (newObject != NULL) );
+ wxASSERT( (newObject->IsKindOf(CLASSINFO(wxShape))) );
+
+ Copy(*newObject);
+
+ if (GetEventHandler() != this)
+ {
+ wxShapeEvtHandler* newHandler = GetEventHandler()->CreateNewCopy();
+ newObject->SetEventHandler(newHandler);
+ newObject->SetPreviousHandler(NULL);
+ newHandler->SetPreviousHandler(newObject);
+ newHandler->SetShape(newObject);
+ }
+
+ if (recompute)
+ newObject->Recompute();
+ return newObject;
+}
+
+// Does the copying for this object, including copying event
+// handler data if any. Calls the virtual Copy function.
+void wxShape::CopyWithHandler(wxShape& copy)
+{
+ Copy(copy);
+
+ if (GetEventHandler() != this)
+ {
+ wxASSERT( copy.GetEventHandler() != NULL );
+ wxASSERT( copy.GetEventHandler() != (©) );
+ wxASSERT( GetEventHandler()->GetClassInfo() == copy.GetEventHandler()->GetClassInfo() );
+ GetEventHandler()->CopyData(* (copy.GetEventHandler()));
+ }
+}
+
+
+// Default - make 6 control points
+void wxShape::MakeControlPoints()
+{
+ double maxX, maxY, minX, minY;
+
+ GetBoundingBoxMax(&maxX, &maxY);
+ GetBoundingBoxMin(&minX, &minY);
+
+ double widthMin = (double)(minX + CONTROL_POINT_SIZE + 2);
+ double heightMin = (double)(minY + CONTROL_POINT_SIZE + 2);
+
+ // Offsets from main object
+ double top = (double)(- (heightMin / 2.0));
+ double bottom = (double)(heightMin / 2.0 + (maxY - minY));
+ double left = (double)(- (widthMin / 2.0));
+ double right = (double)(widthMin / 2.0 + (maxX - minX));
+
+ wxControlPoint *control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, top,
+ CONTROL_POINT_DIAGONAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, 0, top,
+ CONTROL_POINT_VERTICAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, top,
+ CONTROL_POINT_DIAGONAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, 0,
+ CONTROL_POINT_HORIZONTAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, right, bottom,
+ CONTROL_POINT_DIAGONAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, 0, bottom,
+ CONTROL_POINT_VERTICAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, bottom,
+ CONTROL_POINT_DIAGONAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ control = new wxControlPoint(m_canvas, this, CONTROL_POINT_SIZE, left, 0,
+ CONTROL_POINT_HORIZONTAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+}
+
+void wxShape::MakeMandatoryControlPoints()
+{
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->MakeMandatoryControlPoints();
+ node = node->Next();
+ }
+}
+
+void wxShape::ResetMandatoryControlPoints()
+{
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->ResetMandatoryControlPoints();
+ node = node->Next();
+ }
+}
+
+void wxShape::ResetControlPoints()
+{
+ ResetMandatoryControlPoints();
+
+ if (m_controlPoints.Number() < 1)
+ return;
+
+ double maxX, maxY, minX, minY;
+
+ GetBoundingBoxMax(&maxX, &maxY);
+ GetBoundingBoxMin(&minX, &minY);
+
+ double widthMin = (double)(minX + CONTROL_POINT_SIZE + 2);
+ double heightMin = (double)(minY + CONTROL_POINT_SIZE + 2);
+
+ // Offsets from main object
+ double top = (double)(- (heightMin / 2.0));
+ double bottom = (double)(heightMin / 2.0 + (maxY - minY));
+ double left = (double)(- (widthMin / 2.0));
+ double right = (double)(widthMin / 2.0 + (maxX - minX));
+
+ wxNode *node = m_controlPoints.First();
+ wxControlPoint *control = (wxControlPoint *)node->Data();
+ control->m_xoffset = left; control->m_yoffset = top;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = 0; control->m_yoffset = top;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = right; control->m_yoffset = top;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = right; control->m_yoffset = 0;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = right; control->m_yoffset = bottom;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = 0; control->m_yoffset = bottom;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = left; control->m_yoffset = bottom;
+
+ node = node->Next(); control = (wxControlPoint *)node->Data();
+ control->m_xoffset = left; control->m_yoffset = 0;
+}
+
+void wxShape::DeleteControlPoints(wxDC *dc)
+{
+ wxNode *node = m_controlPoints.First();
+ while (node)
+ {
+ wxControlPoint *control = (wxControlPoint *)node->Data();
+ if (dc)
+ control->GetEventHandler()->OnErase(*dc);
+ m_canvas->RemoveShape(control);
+ delete control;
+ delete node;
+ node = m_controlPoints.First();
+ }
+ // Children of divisions are contained objects,
+ // so stop here
+ if (!IsKindOf(CLASSINFO(wxDivisionShape)))
+ {
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->DeleteControlPoints(dc);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::OnDrawControlPoints(wxDC& dc)
+{
+ if (!m_drawHandles)
+ return;
+
+ dc.SetBrush(* wxBLACK_BRUSH);
+ dc.SetPen(* wxBLACK_PEN);
+
+ wxNode *node = m_controlPoints.First();
+ while (node)
+ {
+ wxControlPoint *control = (wxControlPoint *)node->Data();
+ control->Draw(dc);
+ node = node->Next();
+ }
+ // Children of divisions are contained objects,
+ // so stop here.
+ // This test bypasses the type facility for speed
+ // (critical when drawing)
+ if (!IsKindOf(CLASSINFO(wxDivisionShape)))
+ {
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->GetEventHandler()->OnDrawControlPoints(dc);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::OnEraseControlPoints(wxDC& dc)
+{
+ wxNode *node = m_controlPoints.First();
+ while (node)
+ {
+ wxControlPoint *control = (wxControlPoint *)node->Data();
+ control->Erase(dc);
+ node = node->Next();
+ }
+ if (!IsKindOf(CLASSINFO(wxDivisionShape)))
+ {
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->GetEventHandler()->OnEraseControlPoints(dc);
+ node = node->Next();
+ }
+ }
+}
+
+void wxShape::Select(bool select, wxDC* dc)
+{
+ m_selected = select;
+ if (select)
+ {
+ MakeControlPoints();
+ // Children of divisions are contained objects,
+ // so stop here
+ if (!IsKindOf(CLASSINFO(wxDivisionShape)))
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->MakeMandatoryControlPoints();
+ node = node->Next();
+ }
+ }
+ if (dc)
+ GetEventHandler()->OnDrawControlPoints(*dc);
+ }
+ if (!select)
+ {
+ DeleteControlPoints(dc);
+ if (!IsKindOf(CLASSINFO(wxDivisionShape)))
+ {
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ child->DeleteControlPoints(dc);
+ node = node->Next();
+ }
+ }
+ }
+}
+
+bool wxShape::Selected() const
+{
+ return m_selected;
+}
+
+bool wxShape::AncestorSelected() const
+{
+ if (m_selected) return TRUE;
+ if (!GetParent())
+ return FALSE;
+ else
+ return GetParent()->AncestorSelected();
+}
+
+int wxShape::GetNumberOfAttachments() const
+{
+ // Should return the MAXIMUM attachment point id here,
+ // so higher-level functions can iterate through all attachments,
+ // even if they're not contiguous.
+ if (m_attachmentPoints.Number() == 0)
+ return 4;
+ else
+ {
+ int maxN = 3;
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id > maxN)
+ maxN = point->m_id;
+ node = node->Next();
+ }
+ return maxN+1;;
+ }
+}
+
+bool wxShape::AttachmentIsValid(int attachment) const
+{
+ if (m_attachmentPoints.Number() == 0)
+ {
+ return ((attachment >= 0) && (attachment < 4)) ;
+ }
+
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id == attachment)
+ return TRUE;
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+bool wxShape::GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ if (m_attachmentMode == ATTACHMENT_MODE_NONE)
+ {
+ *x = m_xpos; *y = m_ypos;
+ return TRUE;
+ }
+ else if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
+ {
+ wxRealPoint pt, stemPt;
+ GetBranchingAttachmentPoint(attachment, nth, pt, stemPt);
+ *x = pt.x;
+ *y = pt.y;
+ return TRUE;
+ }
+ else if (m_attachmentMode == ATTACHMENT_MODE_EDGE)
+ {
+ if (m_attachmentPoints.Number() > 0)
+ {
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id == attachment)
+ {
+ *x = (double)(m_xpos + point->m_x);
+ *y = (double)(m_ypos + point->m_y);
+ return TRUE;
+ }
+ node = node->Next();
+ }
+ *x = m_xpos; *y = m_ypos;
+ return FALSE;
+ }
+ else
+ {
+ // Assume is rectangular
+ double w, h;
+ GetBoundingBoxMax(&w, &h);
+ double top = (double)(m_ypos + h/2.0);
+ double bottom = (double)(m_ypos - h/2.0);
+ double left = (double)(m_xpos - w/2.0);
+ double right = (double)(m_xpos + w/2.0);
+
+ bool isEnd = (line && line->IsEnd(this));
+
+ int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+ // Simplified code
+ switch (physicalAttachment)
+ {
+ case 0:
+ {
+ wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, bottom), wxRealPoint(right, bottom),
+ nth, no_arcs, line);
+
+ *x = pt.x; *y = pt.y;
+ break;
+ }
+ case 1:
+ {
+ wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(right, bottom), wxRealPoint(right, top),
+ nth, no_arcs, line);
+
+ *x = pt.x; *y = pt.y;
+ break;
+ }
+ case 2:
+ {
+ wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, top), wxRealPoint(right, top),
+ nth, no_arcs, line);
+
+ *x = pt.x; *y = pt.y;
+ break;
+ }
+ case 3:
+ {
+ wxRealPoint pt = CalcSimpleAttachment(wxRealPoint(left, bottom), wxRealPoint(left, top),
+ nth, no_arcs, line);
+
+ *x = pt.x; *y = pt.y;
+ break;
+ }
+ default:
+ {
+ return FALSE;
+ break;
+ }
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+void wxShape::GetBoundingBoxMax(double *w, double *h)
+{
+ double ww, hh;
+ GetBoundingBoxMin(&ww, &hh);
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ ww += m_shadowOffsetX;
+ hh += m_shadowOffsetY;
+ }
+ *w = ww;
+ *h = hh;
+}
+
+// Returns TRUE if image is a descendant of this composite
+bool wxShape::HasDescendant(wxShape *image)
+{
+ if (image == this)
+ return TRUE;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ bool ans = child->HasDescendant(image);
+ if (ans)
+ return TRUE;
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+// Clears points from a list of wxRealPoints, and clears list
+void wxShape::ClearPointList(wxList& list)
+{
+ wxNode* node = list.First();
+ while (node)
+ {
+ wxRealPoint* pt = (wxRealPoint*) node->Data();
+ delete pt;
+
+ node = node->Next();
+ }
+ list.Clear();
+}
+
+// Assuming the attachment lies along a vertical or horizontal line,
+// calculate the position on that point.
+wxRealPoint wxShape::CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2,
+ int nth, int noArcs, wxLineShape* line)
+{
+ bool isEnd = (line && line->IsEnd(this));
+
+ // Are we horizontal or vertical?
+ bool isHorizontal = (oglRoughlyEqual(pt1.y, pt2.y) == TRUE);
+
+ double x, y;
+
+ if (isHorizontal)
+ {
+ wxRealPoint firstPoint, secondPoint;
+ if (pt1.x > pt2.x)
+ {
+ firstPoint = pt2;
+ secondPoint = pt1;
+ }
+ else
+ {
+ firstPoint = pt1;
+ secondPoint = pt2;
+ }
+
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->x < firstPoint.x)
+ x = firstPoint.x;
+ else if (point->x > secondPoint.x)
+ x = secondPoint.x;
+ else
+ x = point->x;
+ }
+ else
+ x = firstPoint.x + (nth + 1)*(secondPoint.x - firstPoint.x)/(noArcs + 1);
+ }
+ else x = (secondPoint.x - firstPoint.x)/2.0; // Midpoint
+
+ y = pt1.y;
+ }
+ else
+ {
+ wxASSERT( oglRoughlyEqual(pt1.x, pt2.x) == TRUE );
+
+ wxRealPoint firstPoint, secondPoint;
+ if (pt1.y > pt2.y)
+ {
+ firstPoint = pt2;
+ secondPoint = pt1;
+ }
+ else
+ {
+ firstPoint = pt1;
+ secondPoint = pt2;
+ }
+
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->y < firstPoint.y)
+ y = firstPoint.y;
+ else if (point->y > secondPoint.y)
+ y = secondPoint.y;
+ else
+ y = point->y;
+ }
+ else
+ y = firstPoint.y + (nth + 1)*(secondPoint.y - firstPoint.y)/(noArcs + 1);
+ }
+ else y = (secondPoint.y - firstPoint.y)/2.0; // Midpoint
+
+ x = pt1.x;
+ }
+
+ return wxRealPoint(x, y);
+}
+
+// Return the zero-based position in m_lines of line.
+int wxShape::GetLinePosition(wxLineShape* line)
+{
+ int i = 0;
+ for (i = 0; i < m_lines.Number(); i++)
+ if ((wxLineShape*) (m_lines.Nth(i)->Data()) == line)
+ return i;
+
+ return 0;
+}
+
+//
+// |________|
+// | <- root
+// | <- neck
+// shoulder1 ->---------<- shoulder2
+// | | | | |
+// <- branching attachment point N-1
+
+// This function gets information about where branching connections go.
+// Returns FALSE if there are no lines at this attachment.
+bool wxShape::GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
+ wxRealPoint& shoulder1, wxRealPoint& shoulder2)
+{
+ int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+ // Number of lines at this attachment.
+ int lineCount = GetAttachmentLineCount(attachment);
+
+ if (lineCount == 0)
+ return FALSE;
+
+ int totalBranchLength = m_branchSpacing * (lineCount - 1);
+
+ root = GetBranchingAttachmentRoot(attachment);
+
+ // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+ switch (physicalAttachment)
+ {
+ case 0:
+ {
+ neck.x = GetX();
+ neck.y = root.y - m_branchNeckLength;
+
+ shoulder1.x = root.x - (totalBranchLength/2.0) ;
+ shoulder2.x = root.x + (totalBranchLength/2.0) ;
+
+ shoulder1.y = neck.y;
+ shoulder2.y = neck.y;
+ break;
+ }
+ case 1:
+ {
+ neck.x = root.x + m_branchNeckLength;
+ neck.y = root.y;
+
+ shoulder1.x = neck.x ;
+ shoulder2.x = neck.x ;
+
+ shoulder1.y = neck.y - (totalBranchLength/2.0) ;
+ shoulder2.y = neck.y + (totalBranchLength/2.0) ;
+ break;
+ }
+ case 2:
+ {
+ neck.x = GetX();
+ neck.y = root.y + m_branchNeckLength;
+
+ shoulder1.x = root.x - (totalBranchLength/2.0) ;
+ shoulder2.x = root.x + (totalBranchLength/2.0) ;
+
+ shoulder1.y = neck.y;
+ shoulder2.y = neck.y;
+ break;
+ }
+ case 3:
+ {
+ neck.x = root.x - m_branchNeckLength;
+ neck.y = root.y ;
+
+ shoulder1.x = neck.x ;
+ shoulder2.x = neck.x ;
+
+ shoulder1.y = neck.y - (totalBranchLength/2.0) ;
+ shoulder2.y = neck.y + (totalBranchLength/2.0) ;
+ break;
+ }
+ default:
+ {
+ wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentInfo." );
+ break;
+ }
+ }
+ return TRUE;
+}
+
+// n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
+// at this attachment point.
+// Get the attachment point where the arc joins the stem, and also the point where the
+// the stem meets the shoulder.
+bool wxShape::GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& pt, wxRealPoint& stemPt)
+{
+ int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+ wxRealPoint root, neck, shoulder1, shoulder2;
+ GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
+
+ // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+ switch (physicalAttachment)
+ {
+ case 0:
+ {
+ pt.y = neck.y - m_branchStemLength;
+ pt.x = shoulder1.x + n*m_branchSpacing;
+
+ stemPt.x = pt.x;
+ stemPt.y = neck.y;
+ break;
+ }
+ case 2:
+ {
+ pt.y = neck.y + m_branchStemLength;
+ pt.x = shoulder1.x + n*m_branchSpacing;
+
+ stemPt.x = pt.x;
+ stemPt.y = neck.y;
+ break;
+ }
+ case 1:
+ {
+ pt.x = neck.x + m_branchStemLength;
+ pt.y = shoulder1.y + n*m_branchSpacing;
+
+ stemPt.x = neck.x;
+ stemPt.y = pt.y;
+ break;
+ }
+ case 3:
+ {
+ pt.x = neck.x - m_branchStemLength;
+ pt.y = shoulder1.y + n*m_branchSpacing;
+
+ stemPt.x = neck.x;
+ stemPt.y = pt.y;
+ break;
+ }
+ default:
+ {
+ wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentPoint." );
+ break;
+ }
+ }
+
+ return TRUE;
+}
+
+// Get the number of lines at this attachment position.
+int wxShape::GetAttachmentLineCount(int attachment) const
+{
+ int count = 0;
+ wxNode* node = m_lines.First();
+ while (node)
+ {
+ wxLineShape* lineShape = (wxLineShape*) node->Data();
+ if ((lineShape->GetFrom() == this) && (lineShape->GetAttachmentFrom() == attachment))
+ count ++;
+ else if ((lineShape->GetTo() == this) && (lineShape->GetAttachmentTo() == attachment))
+ count ++;
+
+ node = node->Next();
+ }
+ return count;
+}
+
+// This function gets the root point at the given attachment.
+wxRealPoint wxShape::GetBranchingAttachmentRoot(int attachment)
+{
+ int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+ wxRealPoint root;
+
+ double width, height;
+ GetBoundingBoxMax(& width, & height);
+
+ // Assume that we have attachment points 0 to 3: top, right, bottom, left.
+ switch (physicalAttachment)
+ {
+ case 0:
+ {
+ root.x = GetX() ;
+ root.y = GetY() - height/2.0;
+ break;
+ }
+ case 1:
+ {
+ root.x = GetX() + width/2.0;
+ root.y = GetY() ;
+ break;
+ }
+ case 2:
+ {
+ root.x = GetX() ;
+ root.y = GetY() + height/2.0;
+ break;
+ }
+ case 3:
+ {
+ root.x = GetX() - width/2.0;
+ root.y = GetY() ;
+ break;
+ }
+ default:
+ {
+ wxFAIL_MSG( "Unrecognised attachment point in GetBranchingAttachmentRoot." );
+ break;
+ }
+ }
+ return root;
+}
+
+// Draw or erase the branches (not the actual arcs though)
+void wxShape::OnDrawBranches(wxDC& dc, int attachment, bool erase)
+{
+ int count = GetAttachmentLineCount(attachment);
+ if (count == 0)
+ return;
+
+ wxRealPoint root, neck, shoulder1, shoulder2;
+ GetBranchingAttachmentInfo(attachment, root, neck, shoulder1, shoulder2);
+
+ if (erase)
+ {
+ dc.SetPen(*wxWHITE_PEN);
+ dc.SetBrush(*wxWHITE_BRUSH);
+ }
+ else
+ {
+ dc.SetPen(*wxBLACK_PEN);
+ dc.SetBrush(*wxBLACK_BRUSH);
+ }
+
+ // Draw neck
+ dc.DrawLine((long) root.x, (long) root.y, (long) neck.x, (long) neck.y);
+
+ if (count > 1)
+ {
+ // Draw shoulder-to-shoulder line
+ dc.DrawLine((long) shoulder1.x, (long) shoulder1.y, (long) shoulder2.x, (long) shoulder2.y);
+ }
+ // Draw all the little branches
+ int i;
+ for (i = 0; i < count; i++)
+ {
+ wxRealPoint pt, stemPt;
+ GetBranchingAttachmentPoint(attachment, i, pt, stemPt);
+ dc.DrawLine((long) stemPt.x, (long) stemPt.y, (long) pt.x, (long) pt.y);
+
+ if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB) && (count > 1))
+ {
+ long blobSize=6;
+// dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
+ dc.DrawEllipse((long) (stemPt.x - (blobSize/2.0)), (long) (stemPt.y - (blobSize/2.0)), blobSize, blobSize);
+ }
+ }
+}
+
+// Draw or erase the branches (not the actual arcs though)
+void wxShape::OnDrawBranches(wxDC& dc, bool erase)
+{
+ if (m_attachmentMode != ATTACHMENT_MODE_BRANCHING)
+ return;
+
+ int count = GetNumberOfAttachments();
+ int i;
+ for (i = 0; i < count; i++)
+ OnDrawBranches(dc, i, erase);
+}
+
+// Only get the attachment position at the _edge_ of the shape, ignoring
+// branching mode. This is used e.g. to indicate the edge of interest, not the point
+// on the attachment branch.
+bool wxShape::GetAttachmentPositionEdge(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ int oldMode = m_attachmentMode;
+
+ // Calculate as if to edge, not branch
+ if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
+ m_attachmentMode = ATTACHMENT_MODE_EDGE;
+ bool success = GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+ m_attachmentMode = oldMode;
+
+ return success;
+}
+
+// Rotate the standard attachment point from physical (0 is always North)
+// to logical (0 -> 1 if rotated by 90 degrees)
+int wxShape::PhysicalToLogicalAttachment(int physicalAttachment) const
+{
+ const double pi = 3.1415926535897932384626433832795 ;
+ int i;
+ if (oglRoughlyEqual(GetRotation(), 0.0))
+ {
+ i = physicalAttachment;
+ }
+ else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
+ {
+ i = physicalAttachment - 1;
+ }
+ else if (oglRoughlyEqual(GetRotation(), pi))
+ {
+ i = physicalAttachment - 2;
+ }
+ else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
+ {
+ i = physicalAttachment - 3;
+ }
+ else
+ // Can't handle -- assume the same.
+ return physicalAttachment;
+
+ if (i < 0)
+ i += 4;
+
+ return i;
+}
+
+// Rotate the standard attachment point from logical
+// to physical (0 is always North)
+int wxShape::LogicalToPhysicalAttachment(int logicalAttachment) const
+{
+ const double pi = 3.1415926535897932384626433832795 ;
+ int i;
+ if (oglRoughlyEqual(GetRotation(), 0.0))
+ {
+ i = logicalAttachment;
+ }
+ else if (oglRoughlyEqual(GetRotation(), (pi/2.0)))
+ {
+ i = logicalAttachment + 1;
+ }
+ else if (oglRoughlyEqual(GetRotation(), pi))
+ {
+ i = logicalAttachment + 2;
+ }
+ else if (oglRoughlyEqual(GetRotation(), (3.0*pi/2.0)))
+ {
+ i = logicalAttachment + 3;
+ }
+ else
+ // Can't handle -- assume the same.
+ return logicalAttachment;
+
+ if (i > 3)
+ i -= 4;
+
+ return i;
+}
+
+void wxShape::Rotate(double WXUNUSED(x), double WXUNUSED(y), double theta)
+{
+ const double pi = 3.1415926535897932384626433832795 ;
+ m_rotation = theta;
+ if (m_rotation < 0.0)
+ {
+ m_rotation += 2*pi;
+ }
+ else if (m_rotation > 2*pi)
+ {
+ m_rotation -= 2*pi;
+ }
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: basic.h
+// Purpose: Basic OGL classes and definitions
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_BASIC_H_
+#define _OGL_BASIC_H_
+
+#ifdef __GNUG__
+#pragma interface "basic.h"
+#endif
+
+#define OGL_VERSION 2.0
+
+#ifndef DEFAULT_MOUSE_TOLERANCE
+#define DEFAULT_MOUSE_TOLERANCE 3
+#endif
+
+// Edit these lines if you positively don't want PROLOGIO support
+#ifndef PROLOGIO
+#define PROLOGIO
+#endif
+
+// Key identifiers
+#define KEY_SHIFT 1
+#define KEY_CTRL 2
+
+// Arrow styles
+
+#define ARROW_NONE 0
+#define ARROW_END 1
+#define ARROW_BOTH 2
+#define ARROW_MIDDLE 3
+#define ARROW_START 4
+
+// Control point types
+// Rectangle and most other shapes
+#define CONTROL_POINT_VERTICAL 1
+#define CONTROL_POINT_HORIZONTAL 2
+#define CONTROL_POINT_DIAGONAL 3
+
+// Line
+#define CONTROL_POINT_ENDPOINT_TO 4
+#define CONTROL_POINT_ENDPOINT_FROM 5
+#define CONTROL_POINT_LINE 6
+
+// Types of formatting: can be combined in a bit list
+#define FORMAT_NONE 0
+ // Left justification
+#define FORMAT_CENTRE_HORIZ 1
+ // Centre horizontally
+#define FORMAT_CENTRE_VERT 2
+ // Centre vertically
+#define FORMAT_SIZE_TO_CONTENTS 4
+ // Resize shape to contents
+
+// Shadow mode
+#define SHADOW_NONE 0
+#define SHADOW_LEFT 1
+#define SHADOW_RIGHT 2
+
+/*
+ * Declare types
+ *
+ */
+
+#define SHAPE_BASIC wxTYPE_USER + 1
+#define SHAPE_RECTANGLE wxTYPE_USER + 2
+#define SHAPE_ELLIPSE wxTYPE_USER + 3
+#define SHAPE_POLYGON wxTYPE_USER + 4
+#define SHAPE_CIRCLE wxTYPE_USER + 5
+#define SHAPE_LINE wxTYPE_USER + 6
+#define SHAPE_DIVIDED_RECTANGLE wxTYPE_USER + 8
+#define SHAPE_COMPOSITE wxTYPE_USER + 9
+#define SHAPE_CONTROL_POINT wxTYPE_USER + 10
+#define SHAPE_DRAWN wxTYPE_USER + 11
+#define SHAPE_DIVISION wxTYPE_USER + 12
+#define SHAPE_LABEL_OBJECT wxTYPE_USER + 13
+#define SHAPE_BITMAP wxTYPE_USER + 14
+#define SHAPE_DIVIDED_OBJECT_CONTROL_POINT wxTYPE_USER + 15
+
+#define OBJECT_REGION wxTYPE_USER + 20
+
+#define OP_CLICK_LEFT 1
+#define OP_CLICK_RIGHT 2
+#define OP_DRAG_LEFT 4
+#define OP_DRAG_RIGHT 8
+
+#define OP_ALL (OP_CLICK_LEFT | OP_CLICK_RIGHT | OP_DRAG_LEFT | OP_DRAG_RIGHT)
+
+// Attachment modes
+#define ATTACHMENT_MODE_NONE 0
+#define ATTACHMENT_MODE_EDGE 1
+#define ATTACHMENT_MODE_BRANCHING 2
+
+// Sub-modes for branching attachment mode
+#define BRANCHING_ATTACHMENT_NORMAL 1
+#define BRANCHING_ATTACHMENT_BLOB 2
+
+class wxShapeTextLine;
+class wxShapeCanvas;
+class wxLineShape;
+class wxControlPoint;
+class wxShapeRegion;
+class wxShape;
+
+#ifdef PROLOGIO
+class WXDLLEXPORT wxExpr;
+class WXDLLEXPORT wxExprDatabase;
+#endif
+
+// Round up
+#define WXROUND(x) ( (long) (x + 0.5) )
+
+
+// logical function to use when drawing rubberband boxes, etc.
+#define OGLRBLF wxINVERT
+
+
+
+class wxShapeEvtHandler: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxShapeEvtHandler)
+
+ public:
+ wxShapeEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL);
+ virtual ~wxShapeEvtHandler();
+
+ inline void SetShape(wxShape *sh) { m_handlerShape = sh; }
+ inline wxShape *GetShape() const { return m_handlerShape; }
+
+ inline void SetPreviousHandler(wxShapeEvtHandler* handler) { m_previousHandler = handler; }
+ inline wxShapeEvtHandler* GetPreviousHandler() const { return m_previousHandler; }
+
+ // This is called when the _shape_ is deleted.
+ virtual void OnDelete();
+ virtual void OnDraw(wxDC& dc);
+ virtual void OnDrawContents(wxDC& dc);
+ virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
+ virtual void OnMoveLinks(wxDC& dc);
+ virtual void OnErase(wxDC& dc);
+ virtual void OnEraseContents(wxDC& dc);
+ virtual void OnHighlight(wxDC& dc);
+ virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
+ virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0);
+ virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
+ virtual void OnSize(double x, double y);
+ virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+ virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+
+ virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
+ virtual void OnDrawControlPoints(wxDC& dc);
+ virtual void OnEraseControlPoints(wxDC& dc);
+ virtual void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE);
+
+ // Control points ('handles') redirect control to the actual shape, to make it easier
+ // to override sizing behaviour.
+ virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+
+ virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { }
+ virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { }
+
+ // Can override this to prevent or intercept line reordering.
+ virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
+
+ // Creates a copy of this event handler.
+ wxShapeEvtHandler *CreateNewCopy();
+
+ // Does the copy - override for new event handlers which might store
+ // app-specific data.
+ virtual void CopyData(wxShapeEvtHandler& copy) {};
+
+ private:
+ wxShapeEvtHandler* m_previousHandler;
+ wxShape* m_handlerShape;
+};
+
+class wxShape: public wxShapeEvtHandler
+{
+ DECLARE_ABSTRACT_CLASS(wxShape)
+
+ public:
+
+ wxShape(wxShapeCanvas *can = NULL);
+ virtual ~wxShape();
+ virtual void GetBoundingBoxMax(double *width, double *height);
+ virtual void GetBoundingBoxMin(double *width, double *height) = 0;
+ virtual bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+ inline wxShapeCanvas *GetCanvas() { return m_canvas; }
+ void SetCanvas(wxShapeCanvas *the_canvas);
+ virtual void AddToCanvas(wxShapeCanvas *the_canvas, wxShape *addAfter = NULL);
+ virtual void InsertInCanvas(wxShapeCanvas *the_canvas);
+
+ virtual void RemoveFromCanvas(wxShapeCanvas *the_canvas);
+ inline double GetX() const { return m_xpos; }
+ inline double GetY() const { return m_ypos; }
+ inline void SetX(double x) { m_xpos = x; }
+ inline void SetY(double y) { m_ypos = y; }
+
+ inline wxShape *GetParent() const { return m_parent; }
+ inline void SetParent(wxShape *p) { m_parent = p; }
+ wxShape *GetTopAncestor();
+ inline wxList& GetChildren() { return m_children; }
+
+ virtual void OnDraw(wxDC& dc);
+ virtual void OnDrawContents(wxDC& dc);
+ virtual void OnMoveLinks(wxDC& dc);
+ virtual void Unlink() { };
+ void SetDrawHandles(bool drawH);
+ inline bool GetDrawHandles() { return m_drawHandles; }
+ virtual void OnErase(wxDC& dc);
+ virtual void OnEraseContents(wxDC& dc);
+ virtual void OnHighlight(wxDC& dc);
+ virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
+ virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0) {}
+ virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
+ virtual void OnSize(double x, double y);
+ virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+ virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+
+ virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0);
+ virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
+ virtual void OnDrawControlPoints(wxDC& dc);
+ virtual void OnEraseControlPoints(wxDC& dc);
+
+ virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { }
+ virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { }
+
+ // Control points ('handles') redirect control to the actual shape, to make it easier
+ // to override sizing behaviour.
+ virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false
+ virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+
+ virtual void MakeControlPoints();
+ virtual void DeleteControlPoints(wxDC *dc = NULL);
+ virtual void ResetControlPoints();
+
+ inline wxShapeEvtHandler *GetEventHandler() { return m_eventHandler; }
+ inline void SetEventHandler(wxShapeEvtHandler *handler) { m_eventHandler = handler; }
+
+ // Mandatory control points, e.g. the divided line moving handles
+ // should appear even if a child of the 'selected' image
+ virtual void MakeMandatoryControlPoints();
+ virtual void ResetMandatoryControlPoints();
+
+ inline virtual bool Recompute() { return TRUE; };
+ // Calculate size recursively, if size changes. Size might depend on children.
+ inline virtual void CalculateSize() { };
+ virtual void Select(bool select = TRUE, wxDC* dc = NULL);
+ virtual void SetHighlight(bool hi = TRUE, bool recurse = FALSE);
+ inline virtual bool IsHighlighted() const { return m_highlighted; };
+ virtual bool Selected() const;
+ virtual bool AncestorSelected() const;
+ void SetSensitivityFilter(int sens = OP_ALL, bool recursive = FALSE);
+ int GetSensitivityFilter() const { return m_sensitivity; }
+ void SetDraggable(bool drag, bool recursive = FALSE);
+ inline void SetFixedSize(bool x, bool y) { m_fixedWidth = x; m_fixedHeight = y; };
+ inline void GetFixedSize(bool *x, bool *y) const { *x = m_fixedWidth; *y = m_fixedHeight; };
+ inline bool GetFixedWidth() const { return m_fixedWidth; }
+ inline bool GetFixedHeight() const { return m_fixedHeight; }
+ inline void SetSpaceAttachments(bool sp) { m_spaceAttachments = sp; };
+ inline bool GetSpaceAttachments() const { return m_spaceAttachments; };
+ void SetShadowMode(int mode, bool redraw = FALSE);
+ inline int GetShadowMode() const { return m_shadowMode; }
+ virtual bool HitTest(double x, double y, int *attachment, double *distance);
+ inline void SetCentreResize(bool cr) { m_centreResize = cr; }
+ inline bool GetCentreResize() const { return m_centreResize; }
+ inline void SetMaintainAspectRatio(bool ar) { m_maintainAspectRatio = ar; }
+ inline bool GetMaintainAspectRatio() const { return m_maintainAspectRatio; }
+ inline wxList& GetLines() const { return (wxList&) m_lines; }
+ inline void SetDisableLabel(bool flag) { m_disableLabel = flag; }
+ inline bool GetDisableLabel() const { return m_disableLabel; }
+ inline void SetAttachmentMode(int mode) { m_attachmentMode = mode; }
+ inline int GetAttachmentMode() const { return m_attachmentMode; }
+ inline void SetId(long i) { m_id = i; }
+ inline long GetId() const { return m_id; }
+
+ void SetPen(wxPen *pen);
+ void SetBrush(wxBrush *brush);
+ inline void SetClientData(wxObject *client_data) { m_clientData = client_data; };
+ inline wxObject *GetClientData() const { return m_clientData; };
+
+ virtual void Show(bool show);
+ virtual bool IsShown() const { return m_visible; }
+ virtual void Move(wxDC& dc, double x1, double y1, bool display = TRUE);
+ virtual void Erase(wxDC& dc);
+ virtual void EraseContents(wxDC& dc);
+ virtual void Draw(wxDC& dc);
+ virtual void Flash();
+ virtual void MoveLinks(wxDC& dc);
+ virtual void DrawContents(wxDC& dc); // E.g. for drawing text label
+ virtual void SetSize(double x, double y, bool recursive = TRUE);
+ virtual void SetAttachmentSize(double x, double y);
+ void Attach(wxShapeCanvas *can);
+ void Detach();
+
+ inline virtual bool Constrain() { return FALSE; } ;
+
+ void AddLine(wxLineShape *line, wxShape *other,
+ int attachFrom = 0, int attachTo = 0,
+ // The line ordering
+ int positionFrom = -1, int positionTo = -1);
+
+ // Return the zero-based position in m_lines of line.
+ int GetLinePosition(wxLineShape* line);
+
+ void AddText(const wxString& string);
+
+ inline wxPen *GetPen() const { return m_pen; }
+ inline wxBrush *GetBrush() const { return m_brush; }
+
+ /*
+ * Region-specific functions (defaults to the default region
+ * for simple objects
+ */
+
+ // Set the default, single region size to be consistent
+ // with the object size
+ void SetDefaultRegionSize();
+ virtual void FormatText(wxDC& dc, const wxString& s, int regionId = 0);
+ virtual void SetFormatMode(int mode, int regionId = 0);
+ virtual int GetFormatMode(int regionId = 0) const;
+ virtual void SetFont(wxFont *font, int regionId = 0);
+ virtual wxFont *GetFont(int regionId = 0) const;
+ virtual void SetTextColour(const wxString& colour, int regionId = 0);
+ virtual wxString GetTextColour(int regionId = 0) const;
+ virtual inline int GetNumberOfTextRegions() const { return m_regions.Number(); }
+ virtual void SetRegionName(const wxString& name, int regionId = 0);
+
+ // Get the name representing the region for this image alone.
+ // I.e. this image's region ids go from 0 to N-1.
+ // But the names might be "0.2.0", "0.2.1" etc. depending on position in composite.
+ // So the last digit represents the region Id, the others represent positions
+ // in composites.
+ virtual wxString GetRegionName(int regionId);
+
+ // Gets the region corresponding to the name, or -1 if not found.
+ virtual int GetRegionId(const wxString& name);
+
+ // Construct names for regions, unique even for children of a composite.
+ virtual void NameRegions(const wxString& parentName = "");
+
+ // Get list of regions
+ inline wxList& GetRegions() const { return (wxList&) m_regions; }
+
+ virtual void AddRegion(wxShapeRegion *region);
+
+ virtual void ClearRegions();
+
+ // Assign new ids to this image and children (if composite)
+ void AssignNewIds();
+
+ // Returns actual image (same as 'this' if non-composite) and region id
+ // for given region name.
+ virtual wxShape *FindRegion(const wxString& regionName, int *regionId);
+
+ // Finds all region names for this image (composite or simple).
+ // Supply empty string list.
+ virtual void FindRegionNames(wxStringList& list);
+
+ virtual void ClearText(int regionId = 0);
+ void RemoveLine(wxLineShape *line);
+
+#ifdef PROLOGIO
+ // I/O
+ virtual void WriteAttributes(wxExpr *clause);
+ virtual void ReadAttributes(wxExpr *clause);
+
+ // In case the object has constraints it needs to read in in a different pass
+ inline virtual void ReadConstraints(wxExpr *WXUNUSED(clause), wxExprDatabase *WXUNUSED(database)) { };
+ virtual void WriteRegions(wxExpr *clause);
+ virtual void ReadRegions(wxExpr *clause);
+#endif
+
+ // Attachment code
+ virtual bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+ virtual int GetNumberOfAttachments() const;
+ virtual bool AttachmentIsValid(int attachment) const;
+
+ // Only get the attachment position at the _edge_ of the shape, ignoring
+ // branching mode. This is used e.g. to indicate the edge of interest, not the point
+ // on the attachment branch.
+ virtual bool GetAttachmentPositionEdge(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+
+ // Assuming the attachment lies along a vertical or horizontal line,
+ // calculate the position on that point.
+ virtual wxRealPoint CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2,
+ int nth, int noArcs, wxLineShape* line);
+
+ // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
+ // edge of the shape.
+ // attachmentPoint is the attachment point (= side) in question.
+ virtual bool AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2);
+
+ virtual void EraseLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE);
+ virtual void DrawLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE);
+
+ virtual bool MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move,
+ double x, double y);
+
+ // Reorders the lines coming into the node image at this attachment
+ // position, in the order in which they appear in linesToSort.
+ virtual void SortLines(int attachment, wxList& linesToSort);
+
+ // Apply an attachment ordering change
+ void ApplyAttachmentOrdering(wxList& ordering);
+
+ // Can override this to prevent or intercept line reordering.
+ virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
+
+ //// New banching attachment code, 24/9/98
+
+ //
+ // |________|
+ // | <- root
+ // | <- neck
+ // shoulder1 ->---------<- shoulder2
+ // | | | | |<- stem
+ // <- branching attachment point N-1
+
+ // This function gets the root point at the given attachment.
+ virtual wxRealPoint GetBranchingAttachmentRoot(int attachment);
+
+ // This function gets information about where branching connections go (calls GetBranchingAttachmentRoot)
+ virtual bool GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck,
+ wxRealPoint& shoulder1, wxRealPoint& shoulder2);
+
+ // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
+ // at this attachment point.
+ // attachmentPoint is where the arc meets the stem, and stemPoint is where the stem meets the
+ // shoulder.
+ virtual bool GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& attachmentPoint,
+ wxRealPoint& stemPoint);
+
+ // Get the number of lines at this attachment position.
+ virtual int GetAttachmentLineCount(int attachment) const;
+
+ // Draw the branches (not the actual arcs though)
+ virtual void OnDrawBranches(wxDC& dc, int attachment, bool erase = FALSE);
+ virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE);
+
+ // Branching attachment settings
+ inline void SetBranchNeckLength(int len) { m_branchNeckLength = len; }
+ inline int GetBranchNeckLength() const { return m_branchNeckLength; }
+
+ inline void SetBranchStemLength(int len) { m_branchStemLength = len; }
+ inline int GetBranchStemLength() const { return m_branchStemLength; }
+
+ inline void SetBranchSpacing(int len) { m_branchSpacing = len; }
+ inline int GetBranchSpacing() const { return m_branchSpacing; }
+
+ // Further detail on branching style, e.g. blobs on interconnections
+ inline void SetBranchStyle(long style) { m_branchStyle = style; }
+ inline long GetBranchStyle() const { return m_branchStyle; }
+
+ // Rotate the standard attachment point from physical (0 is always North)
+ // to logical (0 -> 1 if rotated by 90 degrees)
+ virtual int PhysicalToLogicalAttachment(int physicalAttachment) const;
+
+ // Rotate the standard attachment point from logical
+ // to physical (0 is always North)
+ virtual int LogicalToPhysicalAttachment(int logicalAttachment) const;
+
+ // This is really to distinguish between lines and other images.
+ // For lines, want to pass drag to canvas, since lines tend to prevent
+ // dragging on a canvas (they get in the way.)
+ virtual bool Draggable() const { return TRUE; }
+
+ // Returns TRUE if image is a descendant of this image
+ bool HasDescendant(wxShape *image);
+
+ // Creates a copy of this shape.
+ wxShape *CreateNewCopy(bool resetMapping = TRUE, bool recompute = TRUE);
+
+ // Does the copying for this object
+ virtual void Copy(wxShape& copy);
+
+ // Does the copying for this object, including copying event
+ // handler data if any. Calls the virtual Copy function.
+ void CopyWithHandler(wxShape& copy);
+
+ // Rotate about the given axis by the given amount in radians.
+ virtual void Rotate(double x, double y, double theta);
+ virtual inline double GetRotation() const { return m_rotation; }
+
+ void ClearAttachments();
+
+ // Recentres all the text regions for this object
+ void Recentre(wxDC& dc);
+
+ // Clears points from a list of wxRealPoints
+ void ClearPointList(wxList& list);
+
+ private:
+ wxObject* m_clientData;
+
+ protected:
+ wxShapeEvtHandler* m_eventHandler;
+ bool m_formatted;
+ double m_xpos, m_ypos;
+ wxPen* m_pen;
+ wxBrush* m_brush;
+ wxFont* m_font;
+ wxColour* m_textColour;
+ wxString m_textColourName;
+ wxShapeCanvas* m_canvas;
+ wxList m_lines;
+ wxList m_text;
+ wxList m_controlPoints;
+ wxList m_regions;
+ wxList m_attachmentPoints;
+ bool m_visible;
+ bool m_disableLabel;
+ long m_id;
+ bool m_selected;
+ bool m_highlighted; // Different from selected: user-defined highlighting,
+ // e.g. thick border.
+ double m_rotation;
+ int m_sensitivity;
+ bool m_draggable;
+ int m_attachmentMode; // 0 for no attachments, 1 if using normal attachments,
+ // 2 for branching attachments
+ bool m_spaceAttachments; // TRUE if lines at one side should be spaced
+ bool m_fixedWidth;
+ bool m_fixedHeight;
+ bool m_centreResize; // Default is to resize keeping the centre constant (TRUE)
+ bool m_drawHandles; // Don't draw handles if FALSE, usually TRUE
+ wxList m_children; // In case it's composite
+ wxShape* m_parent; // In case it's a child
+ int m_formatMode;
+ int m_shadowMode;
+ wxBrush* m_shadowBrush;
+ int m_shadowOffsetX;
+ int m_shadowOffsetY;
+ int m_textMarginX; // Gap between text and border
+ int m_textMarginY;
+ wxString m_regionName;
+ bool m_maintainAspectRatio;
+ int m_branchNeckLength;
+ int m_branchStemLength;
+ int m_branchSpacing;
+ long m_branchStyle;
+};
+
+class wxPolygonShape: public wxShape
+{
+ DECLARE_DYNAMIC_CLASS(wxPolygonShape)
+ public:
+ wxPolygonShape();
+ ~wxPolygonShape();
+
+ // Takes a list of wxRealPoints; each point is an OFFSET from the centre.
+ // Deletes user's points in destructor.
+ virtual void Create(wxList *points);
+ virtual void ClearPoints();
+
+ void GetBoundingBoxMin(double *w, double *h);
+ void CalculateBoundingBox();
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+ bool HitTest(double x, double y, int *attachment, double *distance);
+ void SetSize(double x, double y, bool recursive = TRUE);
+ void OnDraw(wxDC& dc);
+ void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
+
+ // Control points ('handles') redirect control to the actual shape, to make it easier
+ // to override sizing behaviour.
+ virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+
+ // A polygon should have a control point at each vertex,
+ // with the option of moving the control points individually
+ // to change the shape.
+ void MakeControlPoints();
+ void ResetControlPoints();
+
+ // If we've changed the shape, must make the original
+ // points match the working points
+ void UpdateOriginalPoints();
+
+ // Add a control point after the given point
+ virtual void AddPolygonPoint(int pos = 0);
+
+ // Delete a control point
+ virtual void DeletePolygonPoint(int pos = 0);
+
+ // Recalculates the centre of the polygon
+ virtual void CalculatePolygonCentre();
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ int GetNumberOfAttachments() const;
+ bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+ bool AttachmentIsValid(int attachment);
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ inline wxList *GetPoints() { return m_points; }
+
+ // Rotate about the given axis by the given amount in radians
+ virtual void Rotate(double x, double y, double theta);
+
+ private:
+ wxList* m_points;
+ wxList* m_originalPoints;
+ double m_boundWidth;
+ double m_boundHeight;
+ double m_originalWidth;
+ double m_originalHeight;
+};
+
+class wxRectangleShape: public wxShape
+{
+ DECLARE_DYNAMIC_CLASS(wxRectangleShape)
+ public:
+ wxRectangleShape(double w = 0.0, double h = 0.0);
+ void GetBoundingBoxMin(double *w, double *h);
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+ void OnDraw(wxDC& dc);
+ void SetSize(double x, double y, bool recursive = TRUE);
+ void SetCornerRadius(double rad); // If > 0, rounded corners
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ int GetNumberOfAttachments() const;
+ bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ inline double GetWidth() const { return m_width; }
+ inline double GetHeight() const { return m_height; }
+ inline void SetWidth(double w) { m_width = w; }
+ inline void SetHeight(double h) { m_height = h; }
+
+protected:
+ double m_width;
+ double m_height;
+ double m_cornerRadius;
+};
+
+class wxTextShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxTextShape)
+ public:
+ wxTextShape(double width = 0.0, double height = 0.0);
+
+ void OnDraw(wxDC& dc);
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+#endif
+
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+};
+
+class wxEllipseShape: public wxShape
+{
+ DECLARE_DYNAMIC_CLASS(wxEllipseShape)
+ public:
+ wxEllipseShape(double w = 0.0, double h = 0.0);
+
+ void GetBoundingBoxMin(double *w, double *h);
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+
+ void OnDraw(wxDC& dc);
+ void SetSize(double x, double y, bool recursive = TRUE);
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ int GetNumberOfAttachments() const;
+ bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ inline double GetWidth() const { return m_width; }
+ inline double GetHeight() const { return m_height; }
+
+ inline void SetWidth(double w) { m_width = w; }
+ inline void SetHeight(double h) { m_height = h; }
+
+protected:
+ double m_width;
+ double m_height;
+};
+
+class wxCircleShape: public wxEllipseShape
+{
+ DECLARE_DYNAMIC_CLASS(wxCircleShape)
+ public:
+ wxCircleShape(double w = 0.0);
+
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+};
+
+#endif
+ // _OGL_BASIC_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: basic2.cpp
+// Purpose: Basic OGL classes (2)
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "basicp.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+#include <math.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "composit.h"
+#include "lines.h"
+#include "canvas.h"
+#include "divided.h"
+#include "misc.h"
+
+// Control point types
+// Rectangle and most other shapes
+#define CONTROL_POINT_VERTICAL 1
+#define CONTROL_POINT_HORIZONTAL 2
+#define CONTROL_POINT_DIAGONAL 3
+
+// Line
+#define CONTROL_POINT_ENDPOINT_TO 4
+#define CONTROL_POINT_ENDPOINT_FROM 5
+#define CONTROL_POINT_LINE 6
+
+// Two stage construction: need to call Create
+IMPLEMENT_DYNAMIC_CLASS(wxPolygonShape, wxShape)
+
+wxPolygonShape::wxPolygonShape()
+{
+ m_points = NULL;
+ m_originalPoints = NULL;
+}
+
+void wxPolygonShape::Create(wxList *the_points)
+{
+ ClearPoints();
+
+ m_originalPoints = the_points;
+
+ // Duplicate the list of points
+ m_points = new wxList;
+
+ wxNode *node = the_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
+ m_points->Append((wxObject*) new_point);
+ node = node->Next();
+ }
+ CalculateBoundingBox();
+ m_originalWidth = m_boundWidth;
+ m_originalHeight = m_boundHeight;
+ SetDefaultRegionSize();
+}
+
+wxPolygonShape::~wxPolygonShape()
+{
+ ClearPoints();
+}
+
+void wxPolygonShape::ClearPoints()
+{
+ if (m_points)
+ {
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ delete point;
+ delete node;
+ node = m_points->First();
+ }
+ delete m_points;
+ m_points = NULL;
+ }
+ if (m_originalPoints)
+ {
+ wxNode *node = m_originalPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ delete point;
+ delete node;
+ node = m_originalPoints->First();
+ }
+ delete m_originalPoints;
+ m_originalPoints = NULL;
+ }
+}
+
+
+// Width and height. Centre of object is centre of box.
+void wxPolygonShape::GetBoundingBoxMin(double *width, double *height)
+{
+ *width = m_boundWidth;
+ *height = m_boundHeight;
+}
+
+void wxPolygonShape::CalculateBoundingBox()
+{
+ // Calculate bounding box at construction (and presumably resize) time
+ double left = 10000;
+ double right = -10000;
+ double top = 10000;
+ double bottom = -10000;
+
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ if (point->x < left) left = point->x;
+ if (point->x > right) right = point->x;
+
+ if (point->y < top) top = point->y;
+ if (point->y > bottom) bottom = point->y;
+
+ node = node->Next();
+ }
+ m_boundWidth = right - left;
+ m_boundHeight = bottom - top;
+}
+
+// Recalculates the centre of the polygon, and
+// readjusts the point offsets accordingly.
+// Necessary since the centre of the polygon
+// is expected to be the real centre of the bounding
+// box.
+void wxPolygonShape::CalculatePolygonCentre()
+{
+ double left = 10000;
+ double right = -10000;
+ double top = 10000;
+ double bottom = -10000;
+
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ if (point->x < left) left = point->x;
+ if (point->x > right) right = point->x;
+
+ if (point->y < top) top = point->y;
+ if (point->y > bottom) bottom = point->y;
+
+ node = node->Next();
+ }
+ double bwidth = right - left;
+ double bheight = bottom - top;
+
+ double newCentreX = (double)(left + (bwidth/2.0));
+ double newCentreY = (double)(top + (bheight/2.0));
+
+ node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ point->x -= newCentreX;
+ point->y -= newCentreY;
+ node = node->Next();
+ }
+ m_xpos += newCentreX;
+ m_ypos += newCentreY;
+}
+
+bool PolylineHitTest(double n, double xvec[], double yvec[],
+ double x1, double y1, double x2, double y2)
+{
+ bool isAHit = FALSE;
+ int i;
+ double lastx = xvec[0];
+ double lasty = yvec[0];
+
+ double min_ratio = 1.0;
+ double line_ratio;
+ double other_ratio;
+
+// char buf[300];
+ for (i = 1; i < n; i++)
+ {
+ oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[i], yvec[i],
+ &line_ratio, &other_ratio);
+ if (line_ratio != 1.0)
+ isAHit = TRUE;
+// sprintf(buf, "Line ratio = %.2f, other ratio = %.2f\n", line_ratio, other_ratio);
+// ClipsErrorFunction(buf);
+ lastx = xvec[i];
+ lasty = yvec[i];
+
+ if (line_ratio < min_ratio)
+ min_ratio = line_ratio;
+ }
+
+ // Do last (implicit) line if last and first doubles are not identical
+ if (!(xvec[0] == lastx && yvec[0] == lasty))
+ {
+ oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0],
+ &line_ratio, &other_ratio);
+ if (line_ratio != 1.0)
+ isAHit = TRUE;
+// sprintf(buf, "Line ratio = %.2f, other ratio = %.2f\n", line_ratio, other_ratio);
+// ClipsErrorFunction(buf);
+
+ if (line_ratio < min_ratio)
+ min_ratio = line_ratio;
+ }
+// ClipsErrorFunction("\n");
+ return isAHit;
+}
+
+bool wxPolygonShape::HitTest(double x, double y, int *attachment, double *distance)
+{
+ // Imagine four lines radiating from this point. If all of these lines hit the polygon,
+ // we're inside it, otherwise we're not. Obviously we'd need more radiating lines
+ // to be sure of correct results for very strange (concave) shapes.
+ double endPointsX[4];
+ double endPointsY[4];
+ // North
+ endPointsX[0] = x;
+ endPointsY[0] = (double)(y - 1000.0);
+ // East
+ endPointsX[1] = (double)(x + 1000.0);
+ endPointsY[1] = y;
+ // South
+ endPointsX[2] = x;
+ endPointsY[2] = (double)(y + 1000.0);
+ // West
+ endPointsX[3] = (double)(x - 1000.0);
+ endPointsY[3] = y;
+
+ // Store polygon points in an array
+ int np = m_points->Number();
+ double *xpoints = new double[np];
+ double *ypoints = new double[np];
+ wxNode *node = m_points->First();
+ int i = 0;
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ xpoints[i] = point->x + m_xpos;
+ ypoints[i] = point->y + m_ypos;
+ node = node->Next();
+ i ++;
+ }
+
+ // We assume it's inside the polygon UNLESS one or more
+ // lines don't hit the outline.
+ bool isContained = TRUE;
+
+ int noPoints = 4;
+ for (i = 0; i < noPoints; i++)
+ {
+ if (!PolylineHitTest(np, xpoints, ypoints, x, y, endPointsX[i], endPointsY[i]))
+ isContained = FALSE;
+ }
+/*
+ if (isContained)
+ ClipsErrorFunction("It's a hit!\n");
+ else
+ ClipsErrorFunction("No hit.\n");
+*/
+ delete[] xpoints;
+ delete[] ypoints;
+
+ if (!isContained)
+ return FALSE;
+
+ int nearest_attachment = 0;
+
+ // If a hit, check the attachment points within the object.
+ int n = GetNumberOfAttachments();
+ double nearest = 999999.0;
+
+ for (i = 0; i < n; i++)
+ {
+ double xp, yp;
+ if (GetAttachmentPositionEdge(i, &xp, &yp))
+ {
+ double l = (double)sqrt(((xp - x) * (xp - x)) +
+ ((yp - y) * (yp - y)));
+ if (l < nearest)
+ {
+ nearest = l;
+ nearest_attachment = i;
+ }
+ }
+ }
+ *attachment = nearest_attachment;
+ *distance = nearest;
+ return TRUE;
+}
+
+// Really need to be able to reset the shape! Otherwise, if the
+// points ever go to zero, we've lost it, and can't resize.
+void wxPolygonShape::SetSize(double new_width, double new_height, bool recursive)
+{
+ SetAttachmentSize(new_width, new_height);
+
+ // Multiply all points by proportion of new size to old size
+ double x_proportion = (double)(fabs(new_width/m_originalWidth));
+ double y_proportion = (double)(fabs(new_height/m_originalHeight));
+
+ wxNode *node = m_points->First();
+ wxNode *original_node = m_originalPoints->First();
+ while (node && original_node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *original_point = (wxRealPoint *)original_node->Data();
+
+ point->x = (original_point->x * x_proportion);
+ point->y = (original_point->y * y_proportion);
+
+ node = node->Next();
+ original_node = original_node->Next();
+ }
+
+// CalculateBoundingBox();
+ m_boundWidth = (double)fabs(new_width);
+ m_boundHeight = (double)fabs(new_height);
+ SetDefaultRegionSize();
+}
+
+// Make the original points the same as the working points
+void wxPolygonShape::UpdateOriginalPoints()
+{
+ if (!m_originalPoints) m_originalPoints = new wxList;
+ wxNode *original_node = m_originalPoints->First();
+ while (original_node)
+ {
+ wxNode *next_node = original_node->Next();
+ wxRealPoint *original_point = (wxRealPoint *)original_node->Data();
+ delete original_point;
+ delete original_node;
+
+ original_node = next_node;
+ }
+
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *original_point = new wxRealPoint(point->x, point->y);
+ m_originalPoints->Append((wxObject*) original_point);
+
+ node = node->Next();
+ }
+ CalculateBoundingBox();
+ m_originalWidth = m_boundWidth;
+ m_originalHeight = m_boundHeight;
+}
+
+void wxPolygonShape::AddPolygonPoint(int pos)
+{
+ wxNode *node = m_points->Nth(pos);
+ if (!node) node = m_points->First();
+ wxRealPoint *firstPoint = (wxRealPoint *)node->Data();
+
+ wxNode *node2 = m_points->Nth(pos + 1);
+ if (!node2) node2 = m_points->First();
+ wxRealPoint *secondPoint = (wxRealPoint *)node2->Data();
+
+ double x = (double)((secondPoint->x - firstPoint->x)/2.0 + firstPoint->x);
+ double y = (double)((secondPoint->y - firstPoint->y)/2.0 + firstPoint->y);
+ wxRealPoint *point = new wxRealPoint(x, y);
+
+ if (pos >= (m_points->Number() - 1))
+ m_points->Append((wxObject*) point);
+ else
+ m_points->Insert(node2, (wxObject*) point);
+
+ UpdateOriginalPoints();
+
+ if (m_selected)
+ {
+ DeleteControlPoints();
+ MakeControlPoints();
+ }
+}
+
+void wxPolygonShape::DeletePolygonPoint(int pos)
+{
+ wxNode *node = m_points->Nth(pos);
+ if (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ delete point;
+ delete node;
+ UpdateOriginalPoints();
+ if (m_selected)
+ {
+ DeleteControlPoints();
+ MakeControlPoints();
+ }
+ }
+}
+
+// Assume (x1, y1) is centre of box (most generally, line end at box)
+bool wxPolygonShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ int n = m_points->Number();
+
+ // First check for situation where the line is vertical,
+ // and we would want to connect to a point on that vertical --
+ // oglFindEndForPolyline can't cope with this (the arrow
+ // gets drawn to the wrong place).
+ if ((m_attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2))
+ {
+ // Look for the point we'd be connecting to. This is
+ // a heuristic...
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ if (point->x == 0.0)
+ {
+ if ((y2 > y1) && (point->y > 0.0))
+ {
+ *x3 = point->x + m_xpos;
+ *y3 = point->y + m_ypos;
+ return TRUE;
+ }
+ else if ((y2 < y1) && (point->y < 0.0))
+ {
+ *x3 = point->x + m_xpos;
+ *y3 = point->y + m_ypos;
+ return TRUE;
+ }
+ }
+ node = node->Next();
+ }
+ }
+
+ double *xpoints = new double[n];
+ double *ypoints = new double[n];
+
+ wxNode *node = m_points->First();
+ int i = 0;
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ xpoints[i] = point->x + m_xpos;
+ ypoints[i] = point->y + m_ypos;
+ node = node->Next();
+ i ++;
+ }
+
+ oglFindEndForPolyline(n, xpoints, ypoints,
+ x1, y1, x2, y2, x3, y3);
+
+ delete[] xpoints;
+ delete[] ypoints;
+
+ return TRUE;
+}
+
+void wxPolygonShape::OnDraw(wxDC& dc)
+{
+ int n = m_points->Number();
+ wxPoint *intPoints = new wxPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint* point = (wxRealPoint*) m_points->Nth(i)->Data();
+ intPoints[i].x = WXROUND(point->x);
+ intPoints[i].y = WXROUND(point->y);
+ }
+
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ if (m_shadowBrush)
+ dc.SetBrush(* m_shadowBrush);
+ dc.SetPen(* g_oglTransparentPen);
+
+ dc.DrawPolygon(n, intPoints, WXROUND(m_xpos + m_shadowOffsetX), WXROUND(m_ypos + m_shadowOffsetY));
+ }
+
+ if (m_pen)
+ {
+ if (m_pen->GetWidth() == 0)
+ dc.SetPen(* g_oglTransparentPen);
+ else
+ dc.SetPen(* m_pen);
+ }
+ if (m_brush)
+ dc.SetBrush(* m_brush);
+ dc.DrawPolygon(n, intPoints, WXROUND(m_xpos), WXROUND(m_ypos));
+
+ delete[] intPoints;
+}
+
+void wxPolygonShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
+{
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+ // Multiply all points by proportion of new size to old size
+ double x_proportion = (double)(fabs(w/m_originalWidth));
+ double y_proportion = (double)(fabs(h/m_originalHeight));
+
+ int n = m_originalPoints->Number();
+ wxPoint *intPoints = new wxPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint* point = (wxRealPoint*) m_originalPoints->Nth(i)->Data();
+ intPoints[i].x = WXROUND(x_proportion * point->x);
+ intPoints[i].y = WXROUND(y_proportion * point->y);
+ }
+ dc.DrawPolygon(n, intPoints, WXROUND(x), WXROUND(y));
+ delete[] intPoints;
+}
+
+// Make as many control points as there are vertices.
+void wxPolygonShape::MakeControlPoints()
+{
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxPolygonControlPoint *control = new wxPolygonControlPoint(m_canvas, this, CONTROL_POINT_SIZE,
+ point, point->x, point->y);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+ node = node->Next();
+ }
+}
+
+void wxPolygonShape::ResetControlPoints()
+{
+ wxNode *node = m_points->First();
+ wxNode *controlPointNode = m_controlPoints.First();
+ while (node && controlPointNode)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxPolygonControlPoint *controlPoint = (wxPolygonControlPoint *)controlPointNode->Data();
+
+ controlPoint->m_xoffset = point->x;
+ controlPoint->m_yoffset = point->y;
+ controlPoint->m_polygonVertex = point;
+
+ node = node->Next();
+ controlPointNode = controlPointNode->Next();
+ }
+}
+
+
+#ifdef PROLOGIO
+void wxPolygonShape::WriteAttributes(wxExpr *clause)
+{
+ wxShape::WriteAttributes(clause);
+
+ clause->AddAttributeValue("x", m_xpos);
+ clause->AddAttributeValue("y", m_ypos);
+
+ // Make a list of lists for the coordinates
+ wxExpr *list = new wxExpr(wxExprList);
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxExpr *point_list = new wxExpr(wxExprList);
+ wxExpr *x_expr = new wxExpr((double)point->x);
+ wxExpr *y_expr = new wxExpr((double)point->y);
+
+ point_list->Append(x_expr);
+ point_list->Append(y_expr);
+ list->Append(point_list);
+
+ node = node->Next();
+ }
+ clause->AddAttributeValue("points", list);
+
+ // Save the original (unscaled) points
+ list = new wxExpr(wxExprList);
+ node = m_originalPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxExpr *point_list = new wxExpr(wxExprList);
+ wxExpr *x_expr = new wxExpr((double) point->x);
+ wxExpr *y_expr = new wxExpr((double) point->y);
+ point_list->Append(x_expr);
+ point_list->Append(y_expr);
+ list->Append(point_list);
+
+ node = node->Next();
+ }
+ clause->AddAttributeValue("m_originalPoints", list);
+}
+
+void wxPolygonShape::ReadAttributes(wxExpr *clause)
+{
+ wxShape::ReadAttributes(clause);
+
+ // Read a list of lists
+ m_points = new wxList;
+ m_originalPoints = new wxList;
+
+ wxExpr *points_list = NULL;
+ clause->AssignAttributeValue("points", &points_list);
+
+ // If no points_list, don't crash!! Assume a diamond instead.
+ double the_height = 100.0;
+ double the_width = 100.0;
+ if (!points_list)
+ {
+ wxRealPoint *point = new wxRealPoint(0.0, (-the_height/2));
+ m_points->Append((wxObject*) point);
+
+ point = new wxRealPoint((the_width/2), 0.0);
+ m_points->Append((wxObject*) point);
+
+ point = new wxRealPoint(0.0, (the_height/2));
+ m_points->Append((wxObject*) point);
+
+ point = new wxRealPoint((-the_width/2), 0.0);
+ m_points->Append((wxObject*) point);
+
+ point = new wxRealPoint(0.0, (-the_height/2));
+ m_points->Append((wxObject*) point);
+ }
+ else
+ {
+ wxExpr *node = points_list->value.first;
+
+ while (node)
+ {
+ wxExpr *xexpr = node->value.first;
+ long x = xexpr->IntegerValue();
+
+ wxExpr *yexpr = xexpr->next;
+ long y = yexpr->IntegerValue();
+
+ wxRealPoint *point = new wxRealPoint((double)x, (double)y);
+ m_points->Append((wxObject*) point);
+
+ node = node->next;
+ }
+ }
+
+ points_list = NULL;
+ clause->AssignAttributeValue("m_originalPoints", &points_list);
+
+ // If no points_list, don't crash!! Assume a diamond instead.
+ if (!points_list)
+ {
+ wxRealPoint *point = new wxRealPoint(0.0, (-the_height/2));
+ m_originalPoints->Append((wxObject*) point);
+
+ point = new wxRealPoint((the_width/2), 0.0);
+ m_originalPoints->Append((wxObject*) point);
+
+ point = new wxRealPoint(0.0, (the_height/2));
+ m_originalPoints->Append((wxObject*) point);
+
+ point = new wxRealPoint((-the_width/2), 0.0);
+ m_originalPoints->Append((wxObject*) point);
+
+ point = new wxRealPoint(0.0, (-the_height/2));
+ m_originalPoints->Append((wxObject*) point);
+
+ m_originalWidth = the_width;
+ m_originalHeight = the_height;
+ }
+ else
+ {
+ wxExpr *node = points_list->value.first;
+ double min_x = 1000;
+ double min_y = 1000;
+ double max_x = -1000;
+ double max_y = -1000;
+ while (node)
+ {
+ wxExpr *xexpr = node->value.first;
+ long x = xexpr->IntegerValue();
+
+ wxExpr *yexpr = xexpr->next;
+ long y = yexpr->IntegerValue();
+
+ wxRealPoint *point = new wxRealPoint((double)x, (double)y);
+ m_originalPoints->Append((wxObject*) point);
+
+ if (x < min_x)
+ min_x = (double)x;
+ if (y < min_y)
+ min_y = (double)y;
+ if (x > max_x)
+ max_x = (double)x;
+ if (y > max_y)
+ max_y = (double)y;
+
+ node = node->next;
+ }
+ m_originalWidth = max_x - min_x;
+ m_originalHeight = max_y - min_y;
+ }
+
+ CalculateBoundingBox();
+}
+#endif
+
+void wxPolygonShape::Copy(wxShape& copy)
+{
+ wxShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxPolygonShape)) );
+
+ wxPolygonShape& polyCopy = (wxPolygonShape&) copy;
+
+ polyCopy.ClearPoints();
+
+ polyCopy.m_points = new wxList;
+ polyCopy.m_originalPoints = new wxList;
+
+ wxNode *node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
+ polyCopy.m_points->Append((wxObject*) new_point);
+ node = node->Next();
+ }
+ node = m_originalPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
+ polyCopy.m_originalPoints->Append((wxObject*) new_point);
+ node = node->Next();
+ }
+ polyCopy.m_boundWidth = m_boundWidth;
+ polyCopy.m_boundHeight = m_boundHeight;
+ polyCopy.m_originalWidth = m_originalWidth;
+ polyCopy.m_originalHeight = m_originalHeight;
+}
+
+int wxPolygonShape::GetNumberOfAttachments() const
+{
+ int maxN = (m_points ? (m_points->Number() - 1) : 0);
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id > maxN)
+ maxN = point->m_id;
+ node = node->Next();
+ }
+ return maxN+1;;
+}
+
+bool wxPolygonShape::GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ if ((m_attachmentMode == ATTACHMENT_MODE_EDGE) && m_points && attachment < m_points->Number())
+ {
+ wxRealPoint *point = (wxRealPoint *)m_points->Nth(attachment)->Data();
+ *x = point->x + m_xpos;
+ *y = point->y + m_ypos;
+ return TRUE;
+ }
+ else
+ { return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); }
+}
+
+bool wxPolygonShape::AttachmentIsValid(int attachment)
+{
+ if (!m_points)
+ return FALSE;
+
+ if ((attachment >= 0) && (attachment < m_points->Number()))
+ return TRUE;
+
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id == attachment)
+ return TRUE;
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+// Rotate about the given axis by the given amount in radians
+void wxPolygonShape::Rotate(double x, double y, double theta)
+{
+ double actualTheta = theta-m_rotation;
+
+ // Rotate attachment points
+ double sinTheta = (double)sin(actualTheta);
+ double cosTheta = (double)cos(actualTheta);
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ double x1 = point->m_x;
+ double y1 = point->m_y;
+ point->m_x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ point->m_y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ node = node->Next();
+ }
+
+ node = m_points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ double x1 = point->x;
+ double y1 = point->y;
+ point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ node = node->Next();
+ }
+ node = m_originalPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ double x1 = point->x;
+ double y1 = point->y;
+ point->x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ point->y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ node = node->Next();
+ }
+
+ m_rotation = theta;
+
+ CalculatePolygonCentre();
+ CalculateBoundingBox();
+ ResetControlPoints();
+}
+
+// Rectangle object
+
+IMPLEMENT_DYNAMIC_CLASS(wxRectangleShape, wxShape)
+
+wxRectangleShape::wxRectangleShape(double w, double h)
+{
+ m_width = w; m_height = h; m_cornerRadius = 0.0;
+ SetDefaultRegionSize();
+}
+
+void wxRectangleShape::OnDraw(wxDC& dc)
+{
+ double x1 = (double)(m_xpos - m_width/2.0);
+ double y1 = (double)(m_ypos - m_height/2.0);
+
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ if (m_shadowBrush)
+ dc.SetBrush(* m_shadowBrush);
+ dc.SetPen(* g_oglTransparentPen);
+
+ if (m_cornerRadius != 0.0)
+ dc.DrawRoundedRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY),
+ WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
+ else
+ dc.DrawRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), WXROUND(m_width), WXROUND(m_height));
+ }
+
+ if (m_pen)
+ {
+ if (m_pen->GetWidth() == 0)
+ dc.SetPen(* g_oglTransparentPen);
+ else
+ dc.SetPen(* m_pen);
+ }
+ if (m_brush)
+ dc.SetBrush(* m_brush);
+
+ if (m_cornerRadius != 0.0)
+ dc.DrawRoundedRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
+ else
+ dc.DrawRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height));
+}
+
+void wxRectangleShape::GetBoundingBoxMin(double *the_width, double *the_height)
+{
+ *the_width = m_width;
+ *the_height = m_height;
+}
+
+void wxRectangleShape::SetSize(double x, double y, bool recursive)
+{
+ SetAttachmentSize(x, y);
+ m_width = (double)wxMax(x, 1.0);
+ m_height = (double)wxMax(y, 1.0);
+ SetDefaultRegionSize();
+}
+
+void wxRectangleShape::SetCornerRadius(double rad)
+{
+ m_cornerRadius = rad;
+}
+
+// Assume (x1, y1) is centre of box (most generally, line end at box)
+bool wxRectangleShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ double bound_x, bound_y;
+ GetBoundingBoxMax(&bound_x, &bound_y);
+ oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3);
+
+ return TRUE;
+}
+
+#ifdef PROLOGIO
+void wxRectangleShape::WriteAttributes(wxExpr *clause)
+{
+ wxShape::WriteAttributes(clause);
+ clause->AddAttributeValue("x", m_xpos);
+ clause->AddAttributeValue("y", m_ypos);
+
+ clause->AddAttributeValue("width", m_width);
+ clause->AddAttributeValue("height", m_height);
+ if (m_cornerRadius != 0.0)
+ clause->AddAttributeValue("corner", m_cornerRadius);
+}
+
+void wxRectangleShape::ReadAttributes(wxExpr *clause)
+{
+ wxShape::ReadAttributes(clause);
+ clause->AssignAttributeValue("width", &m_width);
+ clause->AssignAttributeValue("height", &m_height);
+ clause->AssignAttributeValue("corner", &m_cornerRadius);
+
+ // In case we're reading an old file, set the region's size
+ if (m_regions.Number() == 1)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)m_regions.First()->Data();
+ region->SetSize(m_width, m_height);
+ }
+}
+#endif
+
+void wxRectangleShape::Copy(wxShape& copy)
+{
+ wxShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxRectangleShape)) );
+
+ wxRectangleShape& rectCopy = (wxRectangleShape&) copy;
+ rectCopy.m_width = m_width;
+ rectCopy.m_height = m_height;
+ rectCopy.m_cornerRadius = m_cornerRadius;
+}
+
+int wxRectangleShape::GetNumberOfAttachments() const
+{
+ return wxShape::GetNumberOfAttachments();
+}
+
+
+// There are 4 attachment points on a rectangle - 0 = top, 1 = right, 2 = bottom,
+// 3 = left.
+bool wxRectangleShape::GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+}
+
+// Text object (no box)
+
+IMPLEMENT_DYNAMIC_CLASS(wxTextShape, wxRectangleShape)
+
+wxTextShape::wxTextShape(double width, double height):
+ wxRectangleShape(width, height)
+{
+}
+
+void wxTextShape::OnDraw(wxDC& dc)
+{
+}
+
+void wxTextShape::Copy(wxShape& copy)
+{
+ wxRectangleShape::Copy(copy);
+}
+
+#ifdef PROLOGIO
+void wxTextShape::WriteAttributes(wxExpr *clause)
+{
+ wxRectangleShape::WriteAttributes(clause);
+}
+#endif
+
+// Ellipse object
+
+IMPLEMENT_DYNAMIC_CLASS(wxEllipseShape, wxShape)
+
+wxEllipseShape::wxEllipseShape(double w, double h)
+{
+ m_width = w; m_height = h;
+ SetDefaultRegionSize();
+}
+
+void wxEllipseShape::GetBoundingBoxMin(double *w, double *h)
+{
+ *w = m_width; *h = m_height;
+}
+
+bool wxEllipseShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ double bound_x, bound_y;
+ GetBoundingBoxMax(&bound_x, &bound_y);
+
+// oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3);
+ oglDrawArcToEllipse(m_xpos, m_ypos, bound_x, bound_y, x2, y2, x1, y1, x3, y3);
+
+ return TRUE;
+}
+
+void wxEllipseShape::OnDraw(wxDC& dc)
+{
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ if (m_shadowBrush)
+ dc.SetBrush(* m_shadowBrush);
+ dc.SetPen(* g_oglTransparentPen);
+ dc.DrawEllipse((long) ((m_xpos - GetWidth()/2) + m_shadowOffsetX),
+ (long) ((m_ypos - GetHeight()/2) + m_shadowOffsetY),
+ (long) GetWidth(), (long) GetHeight());
+ }
+
+ if (m_pen)
+ {
+ if (m_pen->GetWidth() == 0)
+ dc.SetPen(* g_oglTransparentPen);
+ else
+ dc.SetPen(* m_pen);
+ }
+ if (m_brush)
+ dc.SetBrush(* m_brush);
+ dc.DrawEllipse((long) (m_xpos - GetWidth()/2), (long) (m_ypos - GetHeight()/2), (long) GetWidth(), (long) GetHeight());
+}
+
+void wxEllipseShape::SetSize(double x, double y, bool recursive)
+{
+ SetAttachmentSize(x, y);
+ m_width = x;
+ m_height = y;
+ SetDefaultRegionSize();
+}
+
+#ifdef PROLOGIO
+void wxEllipseShape::WriteAttributes(wxExpr *clause)
+{
+ wxShape::WriteAttributes(clause);
+ clause->AddAttributeValue("x", m_xpos);
+ clause->AddAttributeValue("y", m_ypos);
+
+ clause->AddAttributeValue("width", m_width);
+ clause->AddAttributeValue("height", m_height);
+}
+
+void wxEllipseShape::ReadAttributes(wxExpr *clause)
+{
+ wxShape::ReadAttributes(clause);
+ clause->AssignAttributeValue("width", &m_width);
+ clause->AssignAttributeValue("height", &m_height);
+
+ // In case we're reading an old file, set the region's size
+ if (m_regions.Number() == 1)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)m_regions.First()->Data();
+ region->SetSize(m_width, m_height);
+ }
+}
+#endif
+
+void wxEllipseShape::Copy(wxShape& copy)
+{
+ wxShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxEllipseShape)) );
+
+ wxEllipseShape& ellipseCopy = (wxEllipseShape&) copy;
+
+ ellipseCopy.m_width = m_width;
+ ellipseCopy.m_height = m_height;
+}
+
+int wxEllipseShape::GetNumberOfAttachments() const
+{
+ return wxShape::GetNumberOfAttachments();
+}
+
+// There are 4 attachment points on an ellipse - 0 = top, 1 = right, 2 = bottom,
+// 3 = left.
+bool wxEllipseShape::GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ if (m_attachmentMode == ATTACHMENT_MODE_BRANCHING)
+ return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+
+ if (m_attachmentMode != ATTACHMENT_MODE_NONE)
+ {
+ double top = (double)(m_ypos + m_height/2.0);
+ double bottom = (double)(m_ypos - m_height/2.0);
+ double left = (double)(m_xpos - m_width/2.0);
+ double right = (double)(m_xpos + m_width/2.0);
+
+ int physicalAttachment = LogicalToPhysicalAttachment(attachment);
+
+ switch (physicalAttachment)
+ {
+ case 0:
+ {
+ if (m_spaceAttachments)
+ *x = left + (nth + 1)*m_width/(no_arcs + 1);
+ else *x = m_xpos;
+ *y = top;
+ // We now have the point on the bounding box: but get the point on the ellipse
+ // by imagining a vertical line from (*x, m_ypos - m_height- 500) to (*x, m_ypos) intersecting
+ // the ellipse.
+ oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos-m_height-500), *x, m_ypos, x, y);
+ break;
+ }
+ case 1:
+ {
+ *x = right;
+ if (m_spaceAttachments)
+ *y = bottom + (nth + 1)*m_height/(no_arcs + 1);
+ else *y = m_ypos;
+ oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos+m_width+500), *y, m_xpos, *y, x, y);
+ break;
+ }
+ case 2:
+ {
+ if (m_spaceAttachments)
+ *x = left + (nth + 1)*m_width/(no_arcs + 1);
+ else *x = m_xpos;
+ *y = bottom;
+ oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, *x, (double)(m_ypos+m_height+500), *x, m_ypos, x, y);
+ break;
+ }
+ case 3:
+ {
+ *x = left;
+ if (m_spaceAttachments)
+ *y = bottom + (nth + 1)*m_height/(no_arcs + 1);
+ else *y = m_ypos;
+ oglDrawArcToEllipse(m_xpos, m_ypos, m_width, m_height, (double)(m_xpos-m_width-500), *y, m_xpos, *y, x, y);
+ break;
+ }
+ default:
+ {
+ return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line);
+ break;
+ }
+ }
+ return TRUE;
+ }
+ else
+ { *x = m_xpos; *y = m_ypos; return TRUE; }
+}
+
+
+// Circle object
+IMPLEMENT_DYNAMIC_CLASS(wxCircleShape, wxEllipseShape)
+
+wxCircleShape::wxCircleShape(double diameter):wxEllipseShape(diameter, diameter)
+{
+ SetMaintainAspectRatio(TRUE);
+}
+
+void wxCircleShape::Copy(wxShape& copy)
+{
+ wxEllipseShape::Copy(copy);
+}
+
+bool wxCircleShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ oglFindEndForCircle(m_width/2,
+ m_xpos, m_ypos, // Centre of circle
+ x2, y2, // Other end of line
+ x3, y3);
+
+ return TRUE;
+}
+
+// Control points
+
+double wxControlPoint::sm_controlPointDragStartX = 0.0;
+double wxControlPoint::sm_controlPointDragStartY = 0.0;
+double wxControlPoint::sm_controlPointDragStartWidth = 0.0;
+double wxControlPoint::sm_controlPointDragStartHeight = 0.0;
+double wxControlPoint::sm_controlPointDragEndWidth = 0.0;
+double wxControlPoint::sm_controlPointDragEndHeight = 0.0;
+double wxControlPoint::sm_controlPointDragPosX = 0.0;
+double wxControlPoint::sm_controlPointDragPosY = 0.0;
+
+IMPLEMENT_DYNAMIC_CLASS(wxControlPoint, wxRectangleShape)
+
+wxControlPoint::wxControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type):wxRectangleShape(size, size)
+{
+ m_canvas = theCanvas;
+ m_shape = object;
+ m_xoffset = the_xoffset;
+ m_yoffset = the_yoffset;
+ m_type = the_type;
+ SetPen(g_oglBlackForegroundPen);
+ SetBrush(wxBLACK_BRUSH);
+ m_oldCursor = NULL;
+ m_visible = TRUE;
+ m_eraseObject = TRUE;
+}
+
+wxControlPoint::~wxControlPoint()
+{
+}
+
+// Don't even attempt to draw any text - waste of time!
+void wxControlPoint::OnDrawContents(wxDC& dc)
+{
+}
+
+void wxControlPoint::OnDraw(wxDC& dc)
+{
+ m_xpos = m_shape->GetX() + m_xoffset;
+ m_ypos = m_shape->GetY() + m_yoffset;
+ wxRectangleShape::OnDraw(dc);
+}
+
+void wxControlPoint::OnErase(wxDC& dc)
+{
+ wxRectangleShape::OnErase(dc);
+}
+
+// Implement resizing of canvas object
+void wxControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);
+}
+
+void wxControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);
+}
+
+void wxControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment);
+}
+
+int wxControlPoint::GetNumberOfAttachments() const
+{
+ return 1;
+}
+
+bool wxControlPoint::GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth, int no_arcs, wxLineShape *line)
+{
+ *x = m_xpos; *y = m_ypos;
+ return TRUE;
+}
+
+// Control points ('handles') redirect control to the actual shape, to make it easier
+// to override sizing behaviour.
+void wxShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment)
+{
+ double bound_x;
+ double bound_y;
+ this->GetBoundingBoxMin(&bound_x, &bound_y);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ if (this->GetCentreResize())
+ {
+ // Maintain the same centre point.
+ double new_width = (double)(2.0*fabs(x - this->GetX()));
+ double new_height = (double)(2.0*fabs(y - this->GetY()));
+
+ // Constrain sizing according to what control point you're dragging
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL)
+ {
+ if (GetMaintainAspectRatio())
+ {
+ new_height = bound_y*(new_width/bound_x);
+ }
+ else
+ new_height = bound_y;
+ }
+ else if (pt->m_type == CONTROL_POINT_VERTICAL)
+ {
+ if (GetMaintainAspectRatio())
+ {
+ new_width = bound_x*(new_height/bound_y);
+ }
+ else
+ new_width = bound_x;
+ }
+ else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT))
+ new_height = bound_y*(new_width/bound_x);
+
+ if (this->GetFixedWidth())
+ new_width = bound_x;
+
+ if (this->GetFixedHeight())
+ new_height = bound_y;
+
+ pt->sm_controlPointDragEndWidth = new_width;
+ pt->sm_controlPointDragEndHeight = new_height;
+
+ this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
+ new_width, new_height);
+ }
+ else
+ {
+ // Don't maintain the same centre point!
+ double newX1 = wxMin(pt->sm_controlPointDragStartX, x);
+ double newY1 = wxMin(pt->sm_controlPointDragStartY, y);
+ double newX2 = wxMax(pt->sm_controlPointDragStartX, x);
+ double newY2 = wxMax(pt->sm_controlPointDragStartY, y);
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL)
+ {
+ newY1 = pt->sm_controlPointDragStartY;
+ newY2 = newY1 + pt->sm_controlPointDragStartHeight;
+ }
+ else if (pt->m_type == CONTROL_POINT_VERTICAL)
+ {
+ newX1 = pt->sm_controlPointDragStartX;
+ newX2 = newX1 + pt->sm_controlPointDragStartWidth;
+ }
+ else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio()))
+ {
+ double newH = (double)((newX2 - newX1)*(pt->sm_controlPointDragStartHeight/pt->sm_controlPointDragStartWidth));
+ if (GetY() > pt->sm_controlPointDragStartY)
+ newY2 = (double)(newY1 + newH);
+ else
+ newY1 = (double)(newY2 - newH);
+ }
+ double newWidth = (double)(newX2 - newX1);
+ double newHeight = (double)(newY2 - newY1);
+
+ if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio())
+ {
+ newWidth = bound_x * (newHeight/bound_y) ;
+ }
+
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio())
+ {
+ newHeight = bound_y * (newWidth/bound_x) ;
+ }
+
+ pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth/2.0));
+ pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight/2.0));
+ if (this->GetFixedWidth())
+ newWidth = bound_x;
+
+ if (this->GetFixedHeight())
+ newHeight = bound_y;
+
+ pt->sm_controlPointDragEndWidth = newWidth;
+ pt->sm_controlPointDragEndHeight = newHeight;
+ this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight);
+ }
+}
+
+void wxShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ m_canvas->CaptureMouse();
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+/*
+ if (pt->m_eraseObject)
+ this->Erase(dc);
+*/
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ double bound_x;
+ double bound_y;
+ this->GetBoundingBoxMin(&bound_x, &bound_y);
+
+ // Choose the 'opposite corner' of the object as the stationary
+ // point in case this is non-centring resizing.
+ if (pt->GetX() < this->GetX())
+ pt->sm_controlPointDragStartX = (double)(this->GetX() + (bound_x/2.0));
+ else
+ pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0));
+
+ if (pt->GetY() < this->GetY())
+ pt->sm_controlPointDragStartY = (double)(this->GetY() + (bound_y/2.0));
+ else
+ pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0));
+
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL)
+ pt->sm_controlPointDragStartY = (double)(this->GetY() - (bound_y/2.0));
+ else if (pt->m_type == CONTROL_POINT_VERTICAL)
+ pt->sm_controlPointDragStartX = (double)(this->GetX() - (bound_x/2.0));
+
+ // We may require the old width and height.
+ pt->sm_controlPointDragStartWidth = bound_x;
+ pt->sm_controlPointDragStartHeight = bound_y;
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ if (this->GetCentreResize())
+ {
+ double new_width = (double)(2.0*fabs(x - this->GetX()));
+ double new_height = (double)(2.0*fabs(y - this->GetY()));
+
+ // Constrain sizing according to what control point you're dragging
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL)
+ {
+ if (GetMaintainAspectRatio())
+ {
+ new_height = bound_y*(new_width/bound_x);
+ }
+ else
+ new_height = bound_y;
+ }
+ else if (pt->m_type == CONTROL_POINT_VERTICAL)
+ {
+ if (GetMaintainAspectRatio())
+ {
+ new_width = bound_x*(new_height/bound_y);
+ }
+ else
+ new_width = bound_x;
+ }
+ else if (pt->m_type == CONTROL_POINT_DIAGONAL && (keys & KEY_SHIFT))
+ new_height = bound_y*(new_width/bound_x);
+
+ if (this->GetFixedWidth())
+ new_width = bound_x;
+
+ if (this->GetFixedHeight())
+ new_height = bound_y;
+
+ pt->sm_controlPointDragEndWidth = new_width;
+ pt->sm_controlPointDragEndHeight = new_height;
+ this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
+ new_width, new_height);
+ }
+ else
+ {
+ // Don't maintain the same centre point!
+ double newX1 = wxMin(pt->sm_controlPointDragStartX, x);
+ double newY1 = wxMin(pt->sm_controlPointDragStartY, y);
+ double newX2 = wxMax(pt->sm_controlPointDragStartX, x);
+ double newY2 = wxMax(pt->sm_controlPointDragStartY, y);
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL)
+ {
+ newY1 = pt->sm_controlPointDragStartY;
+ newY2 = newY1 + pt->sm_controlPointDragStartHeight;
+ }
+ else if (pt->m_type == CONTROL_POINT_VERTICAL)
+ {
+ newX1 = pt->sm_controlPointDragStartX;
+ newX2 = newX1 + pt->sm_controlPointDragStartWidth;
+ }
+ else if (pt->m_type == CONTROL_POINT_DIAGONAL && ((keys & KEY_SHIFT) || GetMaintainAspectRatio()))
+ {
+ double newH = (double)((newX2 - newX1)*(pt->sm_controlPointDragStartHeight/pt->sm_controlPointDragStartWidth));
+ if (pt->GetY() > pt->sm_controlPointDragStartY)
+ newY2 = (double)(newY1 + newH);
+ else
+ newY1 = (double)(newY2 - newH);
+ }
+ double newWidth = (double)(newX2 - newX1);
+ double newHeight = (double)(newY2 - newY1);
+
+ if (pt->m_type == CONTROL_POINT_VERTICAL && GetMaintainAspectRatio())
+ {
+ newWidth = bound_x * (newHeight/bound_y) ;
+ }
+
+ if (pt->m_type == CONTROL_POINT_HORIZONTAL && GetMaintainAspectRatio())
+ {
+ newHeight = bound_y * (newWidth/bound_x) ;
+ }
+
+ pt->sm_controlPointDragPosX = (double)(newX1 + (newWidth/2.0));
+ pt->sm_controlPointDragPosY = (double)(newY1 + (newHeight/2.0));
+ if (this->GetFixedWidth())
+ newWidth = bound_x;
+
+ if (this->GetFixedHeight())
+ newHeight = bound_y;
+
+ pt->sm_controlPointDragEndWidth = newWidth;
+ pt->sm_controlPointDragEndHeight = newHeight;
+ this->GetEventHandler()->OnDrawOutline(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY, newWidth, newHeight);
+ }
+}
+
+void wxShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ m_canvas->ReleaseMouse();
+ dc.SetLogicalFunction(wxCOPY);
+ this->Recompute();
+ this->ResetControlPoints();
+
+ this->Erase(dc);
+/*
+ if (!pt->m_eraseObject)
+ this->Show(FALSE);
+*/
+
+ this->SetSize(pt->sm_controlPointDragEndWidth, pt->sm_controlPointDragEndHeight);
+
+ // The next operation could destroy this control point (it does for label objects,
+ // via formatting the text), so save all values we're going to use, or
+ // we'll be accessing garbage.
+ wxShape *theObject = this;
+ wxShapeCanvas *theCanvas = m_canvas;
+ bool eraseIt = pt->m_eraseObject;
+
+ if (theObject->GetCentreResize())
+ theObject->Move(dc, theObject->GetX(), theObject->GetY());
+ else
+ theObject->Move(dc, pt->sm_controlPointDragPosX, pt->sm_controlPointDragPosY);
+
+/*
+ if (!eraseIt)
+ theObject->Show(TRUE);
+*/
+
+ // Recursively redraw links if we have a composite.
+ if (theObject->GetChildren().Number() > 0)
+ theObject->DrawLinks(dc, -1, TRUE);
+
+ double width, height;
+ theObject->GetBoundingBoxMax(&width, &height);
+ theObject->GetEventHandler()->OnEndSize(width, height);
+
+ if (!theCanvas->GetQuickEditMode() && eraseIt) theCanvas->Redraw(dc);
+}
+
+
+
+// Polygon control points
+
+IMPLEMENT_DYNAMIC_CLASS(wxPolygonControlPoint, wxControlPoint)
+
+wxPolygonControlPoint::wxPolygonControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size,
+ wxRealPoint *vertex, double the_xoffset, double the_yoffset):
+ wxControlPoint(theCanvas, object, size, the_xoffset, the_yoffset, 0)
+{
+ m_polygonVertex = vertex;
+ m_originalDistance = 0.0;
+}
+
+wxPolygonControlPoint::~wxPolygonControlPoint()
+{
+}
+
+// Calculate what new size would be, at end of resize
+void wxPolygonControlPoint::CalculateNewSize(double x, double y)
+{
+ double bound_x;
+ double bound_y;
+ GetShape()->GetBoundingBoxMin(&bound_x, &bound_y);
+
+ double dist = (double)sqrt((x - m_shape->GetX())*(x - m_shape->GetX()) +
+ (y - m_shape->GetY())*(y - m_shape->GetY()));
+
+ m_newSize.x = (double)(dist/this->m_originalDistance)*this->m_originalSize.x;
+ m_newSize.y = (double)(dist/this->m_originalDistance)*this->m_originalSize.y;
+}
+
+
+// Implement resizing polygon or moving the vertex.
+void wxPolygonControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);
+}
+
+void wxPolygonControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);
+}
+
+void wxPolygonControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment);
+}
+
+// Control points ('handles') redirect control to the actual shape, to make it easier
+// to override sizing behaviour.
+void wxPolygonShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment)
+{
+ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ if (0) // keys & KEY_CTRL)
+ {
+ // TODO: mend this code. Currently we rely on altering the
+ // actual points, but we should assume we're not, as per
+ // the normal sizing case.
+ m_canvas->Snap(&x, &y);
+
+ // Move point
+ ppt->m_polygonVertex->x = x - this->GetX();
+ ppt->m_polygonVertex->y = y - this->GetY();
+ ppt->SetX(x);
+ ppt->SetY(y);
+ ((wxPolygonShape *)this)->CalculateBoundingBox();
+ ((wxPolygonShape *)this)->CalculatePolygonCentre();
+ }
+ else
+ {
+ ppt->CalculateNewSize(x, y);
+ }
+
+ this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
+ ppt->GetNewSize().x, ppt->GetNewSize().y);
+}
+
+void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ this->Erase(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ double bound_x;
+ double bound_y;
+ this->GetBoundingBoxMin(&bound_x, &bound_y);
+
+ double dist = (double)sqrt((x - this->GetX())*(x - this->GetX()) +
+ (y - this->GetY())*(y - this->GetY()));
+ ppt->m_originalDistance = dist;
+ ppt->m_originalSize.x = bound_x;
+ ppt->m_originalSize.y = bound_y;
+
+ if (ppt->m_originalDistance == 0.0) ppt->m_originalDistance = (double) 0.0001;
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ if (0) // keys & KEY_CTRL)
+ {
+ // TODO: mend this code. Currently we rely on altering the
+ // actual points, but we should assume we're not, as per
+ // the normal sizing case.
+ m_canvas->Snap(&x, &y);
+
+ // Move point
+ ppt->m_polygonVertex->x = x - this->GetX();
+ ppt->m_polygonVertex->y = y - this->GetY();
+ ppt->SetX(x);
+ ppt->SetY(y);
+ ((wxPolygonShape *)this)->CalculateBoundingBox();
+ ((wxPolygonShape *)this)->CalculatePolygonCentre();
+ }
+ else
+ {
+ ppt->CalculateNewSize(x, y);
+ }
+
+ this->GetEventHandler()->OnDrawOutline(dc, this->GetX(), this->GetY(),
+ ppt->GetNewSize().x, ppt->GetNewSize().y);
+
+ m_canvas->CaptureMouse();
+}
+
+void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ wxPolygonControlPoint* ppt = (wxPolygonControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ m_canvas->ReleaseMouse();
+ dc.SetLogicalFunction(wxCOPY);
+
+ // If we're changing shape, must reset the original points
+ if (keys & KEY_CTRL)
+ {
+ ((wxPolygonShape *)this)->CalculateBoundingBox();
+ ((wxPolygonShape *)this)->UpdateOriginalPoints();
+ }
+ else
+ {
+ SetSize(ppt->GetNewSize().x, ppt->GetNewSize().y);
+ }
+
+ ((wxPolygonShape *)this)->CalculateBoundingBox();
+ ((wxPolygonShape *)this)->CalculatePolygonCentre();
+
+ this->Recompute();
+ this->ResetControlPoints();
+ this->Move(dc, this->GetX(), this->GetY());
+ if (!m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);
+}
+
+/*
+ * Object region
+ *
+ */
+IMPLEMENT_DYNAMIC_CLASS(wxShapeRegion, wxObject)
+
+wxShapeRegion::wxShapeRegion()
+{
+ m_regionText = "";
+ m_font = g_oglNormalFont;
+ m_minHeight = 5.0;
+ m_minWidth = 5.0;
+ m_width = 0.0;
+ m_height = 0.0;
+ m_x = 0.0;
+ m_y = 0.0;
+
+ m_regionProportionX = -1.0;
+ m_regionProportionY = -1.0;
+ m_formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT;
+ m_regionName = "";
+ m_textColour = "BLACK";
+ m_penColour = "BLACK";
+ m_penStyle = wxSOLID;
+ m_actualColourObject = NULL;
+ m_actualPenObject = NULL;
+}
+
+wxShapeRegion::wxShapeRegion(wxShapeRegion& region)
+{
+ m_regionText = region.m_regionText;
+ m_regionName = region.m_regionName;
+ m_textColour = region.m_textColour;
+
+ m_font = region.m_font;
+ m_minHeight = region.m_minHeight;
+ m_minWidth = region.m_minWidth;
+ m_width = region.m_width;
+ m_height = region.m_height;
+ m_x = region.m_x;
+ m_y = region.m_y;
+
+ m_regionProportionX = region.m_regionProportionX;
+ m_regionProportionY = region.m_regionProportionY;
+ m_formatMode = region.m_formatMode;
+ m_actualColourObject = NULL;
+ m_actualPenObject = NULL;
+ m_penStyle = region.m_penStyle;
+ m_penColour = region.m_penColour;
+
+ ClearText();
+ wxNode *node = region.m_formattedText.First();
+ while (node)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)node->Data();
+ wxShapeTextLine *new_line =
+ new wxShapeTextLine(line->GetX(), line->GetY(), line->GetText());
+ m_formattedText.Append(new_line);
+ node = node->Next();
+ }
+}
+
+wxShapeRegion::~wxShapeRegion()
+{
+ ClearText();
+}
+
+void wxShapeRegion::ClearText()
+{
+ wxNode *node = m_formattedText.First();
+ while (node)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)node->Data();
+ wxNode *next = node->Next();
+ delete line;
+ delete node;
+ node = next;
+ }
+}
+
+void wxShapeRegion::SetFont(wxFont *f)
+{
+ m_font = f;
+}
+
+void wxShapeRegion::SetMinSize(double w, double h)
+{
+ m_minWidth = w;
+ m_minHeight = h;
+}
+
+void wxShapeRegion::SetSize(double w, double h)
+{
+ m_width = w;
+ m_height = h;
+}
+
+void wxShapeRegion::SetPosition(double xp, double yp)
+{
+ m_x = xp;
+ m_y = yp;
+}
+
+void wxShapeRegion::SetProportions(double xp, double yp)
+{
+ m_regionProportionX = xp;
+ m_regionProportionY = yp;
+}
+
+void wxShapeRegion::SetFormatMode(int mode)
+{
+ m_formatMode = mode;
+}
+
+void wxShapeRegion::SetColour(const wxString& col)
+{
+ m_textColour = col;
+ m_actualColourObject = NULL;
+}
+
+wxColour *wxShapeRegion::GetActualColourObject()
+{
+ if (!m_actualColourObject)
+ m_actualColourObject = wxTheColourDatabase->FindColour(GetColour());
+ if (!m_actualColourObject)
+ m_actualColourObject = wxBLACK;
+ return m_actualColourObject;
+}
+
+void wxShapeRegion::SetPenColour(const wxString& col)
+{
+ m_penColour = col;
+ m_actualPenObject = NULL;
+}
+
+// Returns NULL if the pen is invisible
+// (different to pen being transparent; indicates that
+// region boundary should not be drawn.)
+wxPen *wxShapeRegion::GetActualPen()
+{
+ if (m_actualPenObject)
+ return m_actualPenObject;
+
+ if (!m_penColour) return NULL;
+ if (m_penColour == "Invisible")
+ return NULL;
+ m_actualPenObject = wxThePenList->FindOrCreatePen(m_penColour, 1, m_penStyle);
+ return m_actualPenObject;
+}
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: basicp.h
+// Purpose: Private OGL classes and definitions
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_BASICP_H_
+#define _OGL_BASICP_H_
+
+#ifdef __GNUG__
+#pragma interface "basicp.h"
+#endif
+
+#define CONTROL_POINT_SIZE 6
+
+class wxShapeTextLine: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxShapeTextLine)
+public:
+ wxShapeTextLine(double the_x = 0.0, double the_y = 0.0, const wxString& the_line = "");
+ ~wxShapeTextLine();
+
+ inline double GetX() const { return m_x; }
+ inline double GetY() const { return m_y; }
+
+ inline void SetX(double x) { m_x = x; }
+ inline void SetY(double y) { m_y = y; }
+
+ inline void SetText(const wxString& text) { m_line = text; }
+ inline wxString GetText() const { return m_line; }
+
+protected:
+ wxString m_line;
+ double m_x;
+ double m_y;
+};
+
+class wxShape;
+class wxControlPoint: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxControlPoint)
+
+ friend class wxShapeEvtHandler;
+ friend class wxShape;
+
+ public:
+ wxControlPoint(wxShapeCanvas *the_canvas = NULL, wxShape *object = NULL, double size = 0.0, double the_xoffset = 0.0,
+ double the_yoffset = 0.0, int the_type = 0);
+ ~wxControlPoint();
+
+ void OnDraw(wxDC& dc);
+ void OnErase(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+
+ bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+ int GetNumberOfAttachments() const;
+
+ inline void SetEraseObject(bool er) { m_eraseObject = er; }
+
+public:
+ int m_type;
+ double m_xoffset;
+ double m_yoffset;
+ wxShape* m_shape;
+ wxCursor* m_oldCursor;
+ bool m_eraseObject; // If TRUE, erases object before dragging handle.
+
+/*
+ * Store original top-left, bottom-right coordinates
+ * in case we're doing non-vertical resizing.
+ */
+ static double sm_controlPointDragStartX;
+ static double sm_controlPointDragStartY;
+ static double sm_controlPointDragStartWidth;
+ static double sm_controlPointDragStartHeight;
+ static double sm_controlPointDragEndWidth;
+ static double sm_controlPointDragEndHeight;
+ static double sm_controlPointDragPosX;
+ static double sm_controlPointDragPosY;
+};
+
+class wxPolygonShape;
+class wxPolygonControlPoint: public wxControlPoint
+{
+ DECLARE_DYNAMIC_CLASS(wxPolygonControlPoint)
+ friend class wxPolygonShape;
+ public:
+ wxPolygonControlPoint(wxShapeCanvas *the_canvas = NULL, wxShape *object = NULL, double size = 0.0, wxRealPoint *vertex = NULL,
+ double the_xoffset = 0.0, double the_yoffset = 0.0);
+ ~wxPolygonControlPoint();
+
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+
+ // Calculate what new size would be, at end of resize
+ virtual void CalculateNewSize(double x, double y);
+
+ // Get new size
+ inline wxRealPoint GetNewSize() const { return m_newSize; };
+
+public:
+ wxRealPoint* m_polygonVertex;
+ wxRealPoint m_originalSize;
+ double m_originalDistance;
+ wxRealPoint m_newSize;
+};
+
+/*
+ * Object regions.
+ * Every shape has one or more text regions with various
+ * properties. Not all of a region's properties will be used
+ * by a shape.
+ *
+ */
+
+class wxShapeRegion: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxShapeRegion)
+
+ public:
+ // Constructor
+ wxShapeRegion();
+ // Copy constructor
+ wxShapeRegion(wxShapeRegion& region);
+ // Destructor
+ ~wxShapeRegion();
+
+ // Accessors
+ inline void SetText(const wxString& s) { m_regionText = s; }
+ void SetFont(wxFont *f);
+ void SetMinSize(double w, double h);
+ void SetSize(double w, double h);
+ void SetPosition(double x, double y);
+ void SetProportions(double x, double y);
+ void SetFormatMode(int mode);
+ inline void SetName(const wxString& s) { m_regionName = s; };
+ void SetColour(const wxString& col); // Text colour
+
+ inline wxString GetText() const { return m_regionText; }
+ inline wxFont *GetFont() const { return m_font; }
+ inline void GetMinSize(double *x, double *y) const { *x = m_minWidth; *y = m_minHeight; }
+ inline void GetProportion(double *x, double *y) const { *x = m_regionProportionX; *y = m_regionProportionY; }
+ inline void GetSize(double *x, double *y) const { *x = m_width; *y = m_height; }
+ inline void GetPosition(double *xp, double *yp) const { *xp = m_x; *yp = m_y; }
+ inline int GetFormatMode() const { return m_formatMode; }
+ inline wxString GetName() const { return m_regionName; }
+ inline wxString GetColour() const { return m_textColour; }
+ wxColour *GetActualColourObject();
+ inline wxList& GetFormattedText() { return m_formattedText; }
+ inline wxString GetPenColour() const { return m_penColour; }
+ inline int GetPenStyle() const { return m_penStyle; }
+ inline void SetPenStyle(int style) { m_penStyle = style; m_actualPenObject = NULL; }
+ void SetPenColour(const wxString& col);
+ wxPen *GetActualPen();
+ inline double GetWidth() const { return m_width; }
+ inline double GetHeight() const { return m_height; }
+
+ void ClearText();
+
+public:
+ wxString m_regionText;
+ wxList m_formattedText; // List of wxShapeTextLines
+ wxFont* m_font;
+ double m_minHeight; // If zero, hide region.
+ double m_minWidth; // If zero, hide region.
+ double m_width;
+ double m_height;
+ double m_x;
+ double m_y;
+
+ double m_regionProportionX; // Proportion of total object size;
+ // -1.0 indicates equal proportion
+ double m_regionProportionY; // Proportion of total object size;
+ // -1.0 indicates equal proportion
+
+ int m_formatMode; // FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT | FORMAT_NONE
+ wxString m_regionName;
+ wxString m_textColour;
+ wxColour* m_actualColourObject; // For speed purposes
+
+ // New members for specifying divided rectangle division colour/style 30/6/94
+ wxString m_penColour;
+ int m_penStyle;
+ wxPen* m_actualPenObject;
+
+};
+
+/*
+ * User-defined attachment point
+ */
+
+class wxAttachmentPoint: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxAttachmentPoint)
+
+public:
+ inline wxAttachmentPoint()
+ {
+ m_id = 0; m_x = 0.0; m_y = 0.0;
+ }
+ inline wxAttachmentPoint(int id, double x, double y)
+ {
+ m_id = id; m_x = x; m_y = y;
+ }
+
+public:
+ int m_id; // Identifier
+ double m_x; // x offset from centre of object
+ double m_y; // y offset from centre of object
+};
+
+#endif
+ // _OGL_BASICP_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: bmpshape.cpp
+// Purpose: Bitmap shape class
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "bmpshape.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "canvas.h"
+#include "bmpshape.h"
+#include "misc.h"
+
+/*
+ * Bitmap object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxBitmapShape, wxShape)
+
+wxBitmapShape::wxBitmapShape():wxRectangleShape(100.0, 50.0)
+{
+ m_filename = "";
+}
+
+wxBitmapShape::~wxBitmapShape()
+{
+}
+
+void wxBitmapShape::OnDraw(wxDC& dc)
+{
+ if (!m_bitmap.Ok())
+ return;
+
+ wxMemoryDC tempDC;
+ tempDC.SelectObject(m_bitmap);
+ double x, y;
+ x = WXROUND(m_xpos - m_bitmap.GetWidth() / 2.0);
+ y = WXROUND(m_ypos - m_bitmap.GetHeight() / 2.0);
+ dc.Blit((long) x, (long) y, m_bitmap.GetWidth(), m_bitmap.GetHeight(), &tempDC, 0, 0);
+}
+
+void wxBitmapShape::SetSize(double w, double h, bool recursive)
+{
+ if (m_bitmap.Ok())
+ {
+ w = m_bitmap.GetWidth();
+ h = m_bitmap.GetHeight();
+ }
+
+ SetAttachmentSize(w, h);
+
+ m_width = w;
+ m_height = h;
+ SetDefaultRegionSize();
+}
+
+#ifdef PROLOGIO
+void wxBitmapShape::WriteAttributes(wxExpr *clause)
+{
+ // Can't really save the bitmap; so instantiate the bitmap
+ // at a higher level in the application, from a symbol library.
+ wxRectangleShape::WriteAttributes(clause);
+ clause->AddAttributeValueString("filename", m_filename);
+}
+
+void wxBitmapShape::ReadAttributes(wxExpr *clause)
+{
+ wxRectangleShape::ReadAttributes(clause);
+ clause->GetAttributeValue("filename", m_filename);
+}
+#endif
+
+// Does the copying for this object
+void wxBitmapShape::Copy(wxShape& copy)
+{
+ wxRectangleShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxBitmapShape)) ) ;
+
+ wxBitmapShape& bitmapCopy = (wxBitmapShape&) copy;
+
+ bitmapCopy.m_bitmap = m_bitmap;
+ bitmapCopy.SetFilename(m_filename);
+}
+
+void wxBitmapShape::SetBitmap(const wxBitmap& bm)
+{
+ m_bitmap = bm;
+ if (m_bitmap.Ok())
+ SetSize(m_bitmap.GetWidth(), m_bitmap.GetHeight());
+}
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: bmpshape.h
+// Purpose: wxBitmapShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_BITMAP_H_
+#define _OGL_BITMAP_H_
+
+#ifdef __GNUG__
+#pragma interface "bmpshape.h"
+#endif
+
+#include "basic.h"
+
+class wxBitmapShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxBitmapShape)
+ public:
+ wxBitmapShape();
+ ~wxBitmapShape();
+
+ void OnDraw(wxDC& dc);
+
+#ifdef PROLOGIO
+ // I/O
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ void SetSize(double w, double h, bool recursive = TRUE);
+ inline wxBitmap& GetBitmap() const { return (wxBitmap&) m_bitmap; }
+ void SetBitmap(const wxBitmap& bm);
+ inline void SetFilename(const wxString& f) { m_filename = f; };
+ inline wxString GetFilename() const { return m_filename; }
+
+private:
+ wxBitmap m_bitmap;
+ wxString m_filename;
+};
+
+#endif
+ // _OGL_BITMAP_H_
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: canvas.cpp
+// Purpose: Shape canvas class
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "canvas.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+
+#include <ctype.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "canvas.h"
+#include "ogldiag.h"
+#include "misc.h"
+#include "lines.h"
+#include "composit.h"
+
+#define CONTROL_POINT_SIZE 6
+
+// Control point types
+// Rectangle and most other shapes
+#define CONTROL_POINT_VERTICAL 1
+#define CONTROL_POINT_HORIZONTAL 2
+#define CONTROL_POINT_DIAGONAL 3
+
+// Line
+#define CONTROL_POINT_ENDPOINT_TO 4
+#define CONTROL_POINT_ENDPOINT_FROM 5
+#define CONTROL_POINT_LINE 6
+
+extern wxCursor *g_oglBullseyeCursor;
+
+IMPLEMENT_DYNAMIC_CLASS(wxShapeCanvas, wxScrolledWindow)
+
+BEGIN_EVENT_TABLE(wxShapeCanvas, wxScrolledWindow)
+ EVT_PAINT(wxShapeCanvas::OnPaint)
+ EVT_MOUSE_EVENTS(wxShapeCanvas::OnMouseEvent)
+END_EVENT_TABLE()
+
+// Object canvas
+wxShapeCanvas::wxShapeCanvas(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style):
+ wxScrolledWindow(parent, id, pos, size, style)
+{
+ m_shapeDiagram = NULL;
+ m_dragState = NoDragging;
+ m_draggedShape = NULL;
+ m_oldDragX = 0;
+ m_oldDragY = 0;
+ m_firstDragX = 0;
+ m_firstDragY = 0;
+ m_checkTolerance = TRUE;
+}
+
+wxShapeCanvas::~wxShapeCanvas()
+{
+}
+
+void wxShapeCanvas::OnPaint(wxPaintEvent& event)
+{
+ wxPaintDC dc(this);
+
+ PrepareDC(dc);
+
+ dc.Clear();
+
+ if (GetDiagram())
+ GetDiagram()->Redraw(dc);
+}
+
+void wxShapeCanvas::OnMouseEvent(wxMouseEvent& event)
+{
+ wxClientDC dc(this);
+ PrepareDC(dc);
+
+ wxPoint logPos(event.GetLogicalPosition(dc));
+
+ double x, y;
+ x = (double) logPos.x;
+ y = (double) logPos.y;
+
+ int keys = 0;
+ if (event.ShiftDown())
+ keys = keys | KEY_SHIFT;
+ if (event.ControlDown())
+ keys = keys | KEY_CTRL;
+
+ bool dragging = event.Dragging();
+
+ // Check if we're within the tolerance for mouse movements.
+ // If we're very close to the position we started dragging
+ // from, this may not be an intentional drag at all.
+ if (dragging)
+ {
+ int dx = abs(dc.LogicalToDeviceX((long) (x - m_firstDragX)));
+ int dy = abs(dc.LogicalToDeviceY((long) (y - m_firstDragY)));
+ if (m_checkTolerance && (dx <= GetDiagram()->GetMouseTolerance()) && (dy <= GetDiagram()->GetMouseTolerance()))
+ {
+ return;
+ }
+ else
+ // If we've ignored the tolerance once, then ALWAYS ignore
+ // tolerance in this drag, even if we come back within
+ // the tolerance range.
+ m_checkTolerance = FALSE;
+ }
+
+ // Dragging - note that the effect of dragging is left entirely up
+ // to the object, so no movement is done unless explicitly done by
+ // object.
+ if (dragging && m_draggedShape && m_dragState == StartDraggingLeft)
+ {
+ m_dragState = ContinueDraggingLeft;
+
+ // If the object isn't m_draggable, transfer message to canvas
+ if (m_draggedShape->Draggable())
+ m_draggedShape->GetEventHandler()->OnBeginDragLeft((double)x, (double)y, keys, m_draggedAttachment);
+ else
+ {
+ m_draggedShape = NULL;
+ OnBeginDragLeft((double)x, (double)y, keys);
+ }
+
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (dragging && m_draggedShape && m_dragState == ContinueDraggingLeft)
+ {
+ // Continue dragging
+ m_draggedShape->GetEventHandler()->OnDragLeft(FALSE, m_oldDragX, m_oldDragY, keys, m_draggedAttachment);
+ m_draggedShape->GetEventHandler()->OnDragLeft(TRUE, (double)x, (double)y, keys, m_draggedAttachment);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (event.LeftUp() && m_draggedShape && m_dragState == ContinueDraggingLeft)
+ {
+ m_dragState = NoDragging;
+ m_checkTolerance = TRUE;
+
+ m_draggedShape->GetEventHandler()->OnDragLeft(FALSE, m_oldDragX, m_oldDragY, keys, m_draggedAttachment);
+
+ m_draggedShape->GetEventHandler()->OnEndDragLeft((double)x, (double)y, keys, m_draggedAttachment);
+ m_draggedShape = NULL;
+ }
+ else if (dragging && m_draggedShape && m_dragState == StartDraggingRight)
+ {
+ m_dragState = ContinueDraggingRight;
+
+ if (m_draggedShape->Draggable())
+ m_draggedShape->GetEventHandler()->OnBeginDragRight((double)x, (double)y, keys, m_draggedAttachment);
+ else
+ {
+ m_draggedShape = NULL;
+ OnBeginDragRight((double)x, (double)y, keys);
+ }
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (dragging && m_draggedShape && m_dragState == ContinueDraggingRight)
+ {
+ // Continue dragging
+ m_draggedShape->GetEventHandler()->OnDragRight(FALSE, m_oldDragX, m_oldDragY, keys, m_draggedAttachment);
+ m_draggedShape->GetEventHandler()->OnDragRight(TRUE, (double)x, (double)y, keys, m_draggedAttachment);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (event.RightUp() && m_draggedShape && m_dragState == ContinueDraggingRight)
+ {
+ m_dragState = NoDragging;
+ m_checkTolerance = TRUE;
+
+ m_draggedShape->GetEventHandler()->OnDragRight(FALSE, m_oldDragX, m_oldDragY, keys, m_draggedAttachment);
+
+ m_draggedShape->GetEventHandler()->OnEndDragRight((double)x, (double)y, keys, m_draggedAttachment);
+ m_draggedShape = NULL;
+ }
+
+ // All following events sent to canvas, not object
+ else if (dragging && !m_draggedShape && m_dragState == StartDraggingLeft)
+ {
+ m_dragState = ContinueDraggingLeft;
+ OnBeginDragLeft((double)x, (double)y, keys);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (dragging && !m_draggedShape && m_dragState == ContinueDraggingLeft)
+ {
+ // Continue dragging
+ OnDragLeft(FALSE, m_oldDragX, m_oldDragY, keys);
+ OnDragLeft(TRUE, (double)x, (double)y, keys);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (event.LeftUp() && !m_draggedShape && m_dragState == ContinueDraggingLeft)
+ {
+ m_dragState = NoDragging;
+ m_checkTolerance = TRUE;
+
+ OnDragLeft(FALSE, m_oldDragX, m_oldDragY, keys);
+ OnEndDragLeft((double)x, (double)y, keys);
+ m_draggedShape = NULL;
+ }
+ else if (dragging && !m_draggedShape && m_dragState == StartDraggingRight)
+ {
+ m_dragState = ContinueDraggingRight;
+ OnBeginDragRight((double)x, (double)y, keys);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (dragging && !m_draggedShape && m_dragState == ContinueDraggingRight)
+ {
+ // Continue dragging
+ OnDragRight(FALSE, m_oldDragX, m_oldDragY, keys);
+ OnDragRight(TRUE, (double)x, (double)y, keys);
+ m_oldDragX = x; m_oldDragY = y;
+ }
+ else if (event.RightUp() && !m_draggedShape && m_dragState == ContinueDraggingRight)
+ {
+ m_dragState = NoDragging;
+ m_checkTolerance = TRUE;
+
+ OnDragRight(FALSE, m_oldDragX, m_oldDragY, keys);
+ OnEndDragRight((double)x, (double)y, keys);
+ m_draggedShape = NULL;
+ }
+
+ // Non-dragging events
+ else if (event.IsButton())
+ {
+ m_checkTolerance = TRUE;
+
+ // Find the nearest object
+ int attachment = 0;
+ wxShape *nearest_object = FindShape(x, y, &attachment);
+ if (nearest_object) // Object event
+ {
+ if (event.LeftDown())
+ {
+ m_draggedShape = nearest_object;
+ m_draggedAttachment = attachment;
+ m_dragState = StartDraggingLeft;
+ m_firstDragX = x;
+ m_firstDragY = y;
+ }
+ else if (event.LeftUp())
+ {
+ // N.B. Only register a click if the same object was
+ // identified for down *and* up.
+ if (nearest_object == m_draggedShape)
+ nearest_object->GetEventHandler()->OnLeftClick((double)x, (double)y, keys, attachment);
+
+ m_draggedShape = NULL;
+ m_dragState = NoDragging;
+ }
+ else if (event.LeftDClick())
+ {
+ nearest_object->GetEventHandler()->OnLeftDoubleClick((double)x, (double)y, keys, attachment);
+
+ m_draggedShape = NULL;
+ m_dragState = NoDragging;
+ }
+ else if (event.RightDown())
+ {
+ m_draggedShape = nearest_object;
+ m_draggedAttachment = attachment;
+ m_dragState = StartDraggingRight;
+ m_firstDragX = x;
+ m_firstDragY = y;
+ }
+ else if (event.RightUp())
+ {
+ if (nearest_object == m_draggedShape)
+ nearest_object->GetEventHandler()->OnRightClick((double)x, (double)y, keys, attachment);
+
+ m_draggedShape = NULL;
+ m_dragState = NoDragging;
+ }
+ }
+ else // Canvas event (no nearest object)
+ {
+ if (event.LeftDown())
+ {
+ m_draggedShape = NULL;
+ m_dragState = StartDraggingLeft;
+ m_firstDragX = x;
+ m_firstDragY = y;
+ }
+ else if (event.LeftUp())
+ {
+ OnLeftClick((double)x, (double)y, keys);
+
+ m_draggedShape = NULL;
+ m_dragState = NoDragging;
+ }
+ else if (event.RightDown())
+ {
+ m_draggedShape = NULL;
+ m_dragState = StartDraggingRight;
+ m_firstDragX = x;
+ m_firstDragY = y;
+ }
+ else if (event.RightUp())
+ {
+ OnRightClick((double)x, (double)y, keys);
+
+ m_draggedShape = NULL;
+ m_dragState = NoDragging;
+ }
+ }
+ }
+}
+
+/*
+ * Try to find a sensitive object, working up the hierarchy of composites.
+ *
+ */
+wxShape *wxShapeCanvas::FindFirstSensitiveShape(double x, double y, int *new_attachment, int op)
+{
+ wxShape *image = FindShape(x, y, new_attachment);
+ if (!image) return NULL;
+
+ wxShape *actualImage = FindFirstSensitiveShape1(image, op);
+ if (actualImage)
+ {
+ double dist;
+ // Find actual attachment
+ actualImage->HitTest(x, y, new_attachment, &dist);
+ }
+ return actualImage;
+}
+
+wxShape *wxShapeCanvas::FindFirstSensitiveShape1(wxShape *image, int op)
+{
+ if (image->GetSensitivityFilter() & op)
+ return image;
+ if (image->GetParent())
+ return FindFirstSensitiveShape1(image->GetParent(), op);
+ return NULL;
+}
+
+// Helper function: TRUE if 'contains' wholly contains 'contained'.
+static bool WhollyContains(wxShape *contains, wxShape *contained)
+{
+ double xp1, yp1, xp2, yp2;
+ double w1, h1, w2, h2;
+ double left1, top1, right1, bottom1, left2, top2, right2, bottom2;
+
+ xp1 = contains->GetX(); yp1 = contains->GetY(); xp2 = contained->GetX(); yp2 = contained->GetY();
+ contains->GetBoundingBoxMax(&w1, &h1);
+ contained->GetBoundingBoxMax(&w2, &h2);
+
+ left1 = (double)(xp1 - (w1 / 2.0));
+ top1 = (double)(yp1 - (h1 / 2.0));
+ right1 = (double)(xp1 + (w1 / 2.0));
+ bottom1 = (double)(yp1 + (h1 / 2.0));
+
+ left2 = (double)(xp2 - (w2 / 2.0));
+ top2 = (double)(yp2 - (h2 / 2.0));
+ right2 = (double)(xp2 + (w2 / 2.0));
+ bottom2 = (double)(yp2 + (h2 / 2.0));
+
+ return ((left1 <= left2) && (top1 <= top2) && (right1 >= right2) && (bottom1 >= bottom2));
+}
+
+wxShape *wxShapeCanvas::FindShape(double x, double y, int *attachment, wxClassInfo *info, wxShape *notObject)
+{
+ double nearest = 100000.0;
+ int nearest_attachment = 0;
+ wxShape *nearest_object = NULL;
+
+ // Go backward through the object list, since we want:
+ // (a) to have the control points drawn LAST to overlay
+ // the other objects
+ // (b) to find the control points FIRST if they exist
+
+ wxNode *current = GetDiagram()->GetShapeList()->Last();
+ while (current)
+ {
+ wxShape *object = (wxShape *)current->Data();
+
+ double dist;
+ int temp_attachment;
+
+ // First pass for lines, which might be inside a container, so we
+ // want lines to take priority over containers. This first loop
+ // could fail if we clickout side a line, so then we'll
+ // try other shapes.
+ if (object->IsShown() &&
+ object->IsKindOf(CLASSINFO(wxLineShape)) &&
+ object->HitTest(x, y, &temp_attachment, &dist) &&
+ ((info == NULL) || object->IsKindOf(info)) &&
+ (!notObject || !notObject->HasDescendant(object)))
+ {
+ // A line is trickier to spot than a normal object.
+ // For a line, since it's the diagonal of the box
+ // we use for the hit test, we may have several
+ // lines in the box and therefore we need to be able
+ // to specify the nearest point to the centre of the line
+ // as our hit criterion, to give the user some room for
+ // manouevre.
+ if (dist < nearest)
+ {
+ nearest = dist;
+ nearest_object = object;
+ nearest_attachment = temp_attachment;
+ }
+ }
+ if (current)
+ current = current->Previous();
+ }
+
+ current = GetDiagram()->GetShapeList()->Last();
+ while (current)
+ {
+ wxShape *object = (wxShape *)current->Data();
+ double dist;
+ int temp_attachment;
+
+ // On second pass, only ever consider non-composites or divisions. If children want to pass
+ // up control to the composite, that's up to them.
+ if (object->IsShown() && (object->IsKindOf(CLASSINFO(wxDivisionShape)) || !object->IsKindOf(CLASSINFO(wxCompositeShape)))
+ && object->HitTest(x, y, &temp_attachment, &dist) && ((info == NULL) || object->IsKindOf(info)) &&
+ (!notObject || !notObject->HasDescendant(object)))
+ {
+ if (!object->IsKindOf(CLASSINFO(wxLineShape)))
+ {
+ // If we've hit a container, and we have already found a line in the
+ // first pass, then ignore the container in case the line is in the container.
+ // Check for division in case line straddles divisions (i.e. is not wholly contained).
+ if (!nearest_object || !(object->IsKindOf(CLASSINFO(wxDivisionShape)) || WhollyContains(object, nearest_object)))
+ {
+ nearest = dist;
+ nearest_object = object;
+ nearest_attachment = temp_attachment;
+ current = NULL;
+ }
+ }
+ }
+ if (current)
+ current = current->Previous();
+ }
+
+ *attachment = nearest_attachment;
+ return nearest_object;
+}
+
+/*
+ * Higher-level events called by OnEvent
+ *
+ */
+
+void wxShapeCanvas::OnLeftClick(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnRightClick(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnDragLeft(bool draw, double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnBeginDragLeft(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnEndDragLeft(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnDragRight(bool draw, double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnBeginDragRight(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::OnEndDragRight(double x, double y, int keys)
+{
+}
+
+void wxShapeCanvas::AddShape(wxShape *object, wxShape *addAfter)
+ { GetDiagram()->AddShape(object, addAfter); }
+void wxShapeCanvas::InsertShape(wxShape *object)
+ { GetDiagram()->InsertShape(object); }
+void wxShapeCanvas::RemoveShape(wxShape *object)
+ { GetDiagram()->RemoveShape(object); }
+bool wxShapeCanvas::GetQuickEditMode()
+ { return GetDiagram()->GetQuickEditMode(); }
+void wxShapeCanvas::Redraw(wxDC& dc)
+ { GetDiagram()->Redraw(dc); }
+void wxShapeCanvas::Snap(double *x, double *y)
+ { GetDiagram()->Snap(x, y); }
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: canvas.h
+// Purpose: wxShapeCanvas
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_CANVAS_H_
+#define _OGL_CANVAS_H_
+
+#ifdef __GNUG__
+#pragma interface "canvas.h"
+#endif
+
+// Drag states
+#define NoDragging 0
+#define StartDraggingLeft 1
+#define ContinueDraggingLeft 2
+#define StartDraggingRight 3
+#define ContinueDraggingRight 4
+
+// When drag_count reaches 0, process drag message
+
+class wxDiagram;
+
+class wxShapeCanvas: public wxScrolledWindow
+{
+ DECLARE_DYNAMIC_CLASS(wxShapeCanvas)
+ public:
+ wxShapeCanvas(wxWindow *parent = NULL, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
+ long style = wxBORDER | wxRETAINED);
+ ~wxShapeCanvas();
+
+ inline void SetDiagram(wxDiagram *diag) { m_shapeDiagram = diag; }
+ inline wxDiagram *GetDiagram() const { return m_shapeDiagram; }
+
+ virtual void OnLeftClick(double x, double y, int keys = 0);
+ virtual void OnRightClick(double x, double y, int keys = 0);
+
+ virtual void OnDragLeft(bool draw, double x, double y, int keys=0); // Erase if draw false
+ virtual void OnBeginDragLeft(double x, double y, int keys=0);
+ virtual void OnEndDragLeft(double x, double y, int keys=0);
+
+ virtual void OnDragRight(bool draw, double x, double y, int keys=0); // Erase if draw false
+ virtual void OnBeginDragRight(double x, double y, int keys=0);
+ virtual void OnEndDragRight(double x, double y, int keys=0);
+
+ // Find object for mouse click, of given wxClassInfo (NULL for any type).
+ // If notImage is non-NULL, don't find an object that is equal to or a descendant of notImage
+ virtual wxShape *FindShape(double x, double y, int *attachment, wxClassInfo *info = NULL, wxShape *notImage = NULL);
+ wxShape *FindFirstSensitiveShape(double x, double y, int *new_attachment, int op);
+ wxShape *FindFirstSensitiveShape1(wxShape *image, int op);
+
+ // Redirect to wxDiagram object
+ virtual void AddShape(wxShape *object, wxShape *addAfter = NULL);
+ virtual void InsertShape(wxShape *object);
+ virtual void RemoveShape(wxShape *object);
+ virtual bool GetQuickEditMode();
+ virtual void Redraw(wxDC& dc);
+ void Snap(double *x, double *y);
+
+ // Events
+ void OnPaint(wxPaintEvent& event);
+ void OnMouseEvent(wxMouseEvent& event);
+
+ protected:
+ wxDiagram* m_shapeDiagram;
+ int m_dragState;
+ double m_oldDragX, m_oldDragY; // Previous drag coordinates
+ double m_firstDragX, m_firstDragY; // INITIAL drag coordinates
+ bool m_checkTolerance; // Whether to check drag tolerance
+ wxShape* m_draggedShape;
+ int m_draggedAttachment;
+
+DECLARE_EVENT_TABLE()
+};
+
+#endif
+ // _OGL_CANVAS_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: composit.cpp
+// Purpose: Composite OGL class
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "composit.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "constrnt.h"
+#include "composit.h"
+#include "misc.h"
+#include "canvas.h"
+
+// Sometimes, objects need to access the whole database to
+// construct themselves.
+wxExprDatabase *GlobalwxExprDatabase = NULL;
+
+
+/*
+ * Division control point
+ */
+
+class wxDivisionControlPoint: public wxControlPoint
+{
+ DECLARE_DYNAMIC_CLASS(wxDivisionControlPoint)
+ public:
+ wxDivisionControlPoint() {}
+ wxDivisionControlPoint(wxShapeCanvas *the_canvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type);
+ ~wxDivisionControlPoint();
+
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDivisionControlPoint, wxControlPoint)
+
+/*
+ * Composite object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxCompositeShape, wxRectangleShape)
+
+wxCompositeShape::wxCompositeShape(): wxRectangleShape(10.0, 10.0)
+{
+// selectable = FALSE;
+ m_oldX = m_xpos;
+ m_oldY = m_ypos;
+}
+
+wxCompositeShape::~wxCompositeShape()
+{
+ wxNode *node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ delete constraint;
+ node = node->Next();
+ }
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ wxNode *next = node->Next();
+ object->Unlink();
+ delete object;
+ node = next;
+ }
+}
+
+void wxCompositeShape::OnDraw(wxDC& dc)
+{
+ double x1 = (double)(m_xpos - m_width/2.0);
+ double y1 = (double)(m_ypos - m_height/2.0);
+
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ if (m_shadowBrush)
+ dc.SetBrush(* m_shadowBrush);
+ dc.SetPen(* g_oglTransparentPen);
+
+ if (m_cornerRadius != 0.0)
+ dc.DrawRoundedRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY),
+ WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
+ else
+ dc.DrawRectangle(WXROUND(x1 + m_shadowOffsetX), WXROUND(y1 + m_shadowOffsetY), WXROUND(m_width), WXROUND(m_height));
+ }
+}
+
+void wxCompositeShape::OnDrawContents(wxDC& dc)
+{
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->Draw(dc);
+ object->DrawLinks(dc);
+ node = node->Next();
+ }
+ wxShape::OnDrawContents(dc);
+}
+
+bool wxCompositeShape::OnMovePre(wxDC& dc, double x, double y, double oldx, double oldy, bool display)
+{
+ double diffX = x - oldx;
+ double diffY = y - oldy;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+
+ object->Erase(dc);
+ object->Move(dc, object->GetX() + diffX, object->GetY() + diffY, display);
+
+ node = node->Next();
+ }
+ return TRUE;
+}
+
+void wxCompositeShape::OnErase(wxDC& dc)
+{
+ wxRectangleShape::OnErase(dc);
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->Erase(dc);
+ node = node->Next();
+ }
+}
+
+static double objectStartX = 0.0;
+static double objectStartY = 0.0;
+
+void wxCompositeShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ double xx = x;
+ double yy = y;
+ m_canvas->Snap(&xx, &yy);
+ double offsetX = xx - objectStartX;
+ double offsetY = yy - objectStartY;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ GetEventHandler()->OnDrawOutline(dc, GetX() + offsetX, GetY() + offsetY, GetWidth(), GetHeight());
+// wxShape::OnDragLeft(draw, x, y, keys, attachment);
+}
+
+void wxCompositeShape::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ objectStartX = x;
+ objectStartY = y;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ Erase(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+ m_canvas->CaptureMouse();
+
+ double xx = x;
+ double yy = y;
+ m_canvas->Snap(&xx, &yy);
+ double offsetX = xx - objectStartX;
+ double offsetY = yy - objectStartY;
+
+ GetEventHandler()->OnDrawOutline(dc, GetX() + offsetX, GetY() + offsetY, GetWidth(), GetHeight());
+
+// wxShape::OnBeginDragLeft(x, y, keys, attachment);
+}
+
+void wxCompositeShape::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+// wxShape::OnEndDragLeft(x, y, keys, attachment);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ m_canvas->ReleaseMouse();
+
+ if (!m_draggable)
+ {
+ if (m_parent) m_parent->GetEventHandler()->OnEndDragLeft(x, y, keys, 0);
+ return;
+ }
+
+ dc.SetLogicalFunction(wxCOPY);
+ double xx = x;
+ double yy = y;
+ m_canvas->Snap(&xx, &yy);
+ double offsetX = xx - objectStartX;
+ double offsetY = yy - objectStartY;
+
+ Move(dc, GetX() + offsetX, GetY() + offsetY);
+
+ if (m_canvas && !m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);
+}
+
+void wxCompositeShape::OnRightClick(double x, double y, int keys, int attachment)
+{
+ // If we get a ctrl-right click, this means send the message to
+ // the division, so we can invoke a user interface for dealing with regions.
+ if (keys & KEY_CTRL)
+ {
+ wxNode *node = m_divisions.First();
+ while (node)
+ {
+ wxDivisionShape *division = (wxDivisionShape *)node->Data();
+ wxNode *next = node->Next();
+ int attach = 0;
+ double dist = 0.0;
+ if (division->HitTest(x, y, &attach, &dist))
+ {
+ division->GetEventHandler()->OnRightClick(x, y, keys, attach);
+ node = NULL;
+ }
+ if (node)
+ node = next;
+ }
+ }
+}
+
+void wxCompositeShape::SetSize(double w, double h, bool recursive)
+{
+ SetAttachmentSize(w, h);
+
+ double xScale = (double)(w/(wxMax(1.0, GetWidth())));
+ double yScale = (double)(h/(wxMax(1.0, GetHeight())));
+
+ m_width = w;
+ m_height = h;
+
+ if (!recursive) return;
+
+ wxNode *node = m_children.First();
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ double xBound, yBound;
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+
+ // Scale the position first
+ double newX = (double)(((object->GetX() - GetX())*xScale) + GetX());
+ double newY = (double)(((object->GetY() - GetY())*yScale) + GetY());
+ object->Show(FALSE);
+ object->Move(dc, newX, newY);
+ object->Show(TRUE);
+
+ // Now set the scaled size
+ object->GetBoundingBoxMin(&xBound, &yBound);
+ object->SetSize(object->GetFixedWidth() ? xBound : xScale*xBound,
+ object->GetFixedHeight() ? yBound : yScale*yBound);
+
+ node = node->Next();
+ }
+ SetDefaultRegionSize();
+}
+
+void wxCompositeShape::AddChild(wxShape *child, wxShape *addAfter)
+{
+ m_children.Append(child);
+ child->SetParent(this);
+ if (m_canvas)
+ {
+ // Ensure we add at the right position
+ if (addAfter)
+ child->RemoveFromCanvas(m_canvas);
+ child->AddToCanvas(m_canvas, addAfter);
+ }
+}
+
+void wxCompositeShape::RemoveChild(wxShape *child)
+{
+ m_children.DeleteObject(child);
+ m_divisions.DeleteObject(child);
+ RemoveChildFromConstraints(child);
+ child->SetParent(NULL);
+}
+
+void wxCompositeShape::DeleteConstraintsInvolvingChild(wxShape *child)
+{
+ wxNode *node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ wxNode *nextNode = node->Next();
+
+ if ((constraint->m_constrainingObject == child) ||
+ constraint->m_constrainedObjects.Member(child))
+ {
+ delete constraint;
+ delete node;
+ }
+ node = nextNode;
+ }
+}
+
+void wxCompositeShape::RemoveChildFromConstraints(wxShape *child)
+{
+ wxNode *node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ wxNode *nextNode = node->Next();
+
+ if (constraint->m_constrainedObjects.Member(child))
+ constraint->m_constrainedObjects.DeleteObject(child);
+ if (constraint->m_constrainingObject == child)
+ constraint->m_constrainingObject = NULL;
+
+ // Delete the constraint if no participants left
+ if (!constraint->m_constrainingObject)
+ {
+ delete constraint;
+ delete node;
+ }
+
+ node = nextNode;
+ }
+}
+
+void wxCompositeShape::Copy(wxShape& copy)
+{
+ wxRectangleShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxCompositeShape)) ) ;
+
+ wxCompositeShape& compositeCopy = (wxCompositeShape&) copy;
+
+ // Associate old and new copies for compositeCopying constraints and division geometry
+ oglObjectCopyMapping.Append((long)this, &compositeCopy);
+
+ // Copy the children
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ wxShape *newObject = object->CreateNewCopy(FALSE, FALSE);
+ if (newObject->GetId() == 0)
+ newObject->SetId(wxNewId());
+
+ newObject->SetParent(&compositeCopy);
+ compositeCopy.m_children.Append(newObject);
+
+ // Some m_children may be divisions
+ if (m_divisions.Member(object))
+ compositeCopy.m_divisions.Append(newObject);
+
+ oglObjectCopyMapping.Append((long)object, newObject);
+
+ node = node->Next();
+ }
+
+ // Copy the constraints
+ node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+
+ wxShape *newConstraining = (wxShape *)(oglObjectCopyMapping.Find((long)constraint->m_constrainingObject)->Data());
+
+ wxList newConstrainedList;
+ wxNode *node2 = constraint->m_constrainedObjects.First();
+ while (node2)
+ {
+ wxShape *constrainedObject = (wxShape *)node2->Data();
+ wxShape *newConstrained = (wxShape *)(oglObjectCopyMapping.Find((long)constrainedObject)->Data());
+ newConstrainedList.Append(newConstrained);
+ node2 = node2->Next();
+ }
+
+ wxOGLConstraint *newConstraint = new wxOGLConstraint(constraint->m_constraintType, newConstraining,
+ newConstrainedList);
+ newConstraint->m_constraintId = constraint->m_constraintId;
+ if (constraint->m_constraintName)
+ {
+ newConstraint->m_constraintName = constraint->m_constraintName;
+ }
+ newConstraint->SetSpacing(constraint->m_xSpacing, constraint->m_ySpacing);
+ compositeCopy.m_constraints.Append(newConstraint);
+
+ node = node->Next();
+ }
+
+ // Now compositeCopy the division geometry
+ node = m_divisions.First();
+ while (node)
+ {
+ wxDivisionShape *division = (wxDivisionShape *)node->Data();
+ wxNode *node1 = oglObjectCopyMapping.Find((long)division);
+ wxNode *leftNode = NULL;
+ wxNode *topNode = NULL;
+ wxNode *rightNode = NULL;
+ wxNode *bottomNode = NULL;
+ if (division->GetLeftSide())
+ leftNode = oglObjectCopyMapping.Find((long)division->GetLeftSide());
+ if (division->GetTopSide())
+ topNode = oglObjectCopyMapping.Find((long)division->GetTopSide());
+ if (division->GetRightSide())
+ rightNode = oglObjectCopyMapping.Find((long)division->GetRightSide());
+ if (division->GetBottomSide())
+ bottomNode = oglObjectCopyMapping.Find((long)division->GetBottomSide());
+ if (node1)
+ {
+ wxDivisionShape *newDivision = (wxDivisionShape *)node1->Data();
+ if (leftNode)
+ newDivision->SetLeftSide((wxDivisionShape *)leftNode->Data());
+ if (topNode)
+ newDivision->SetTopSide((wxDivisionShape *)topNode->Data());
+ if (rightNode)
+ newDivision->SetRightSide((wxDivisionShape *)rightNode->Data());
+ if (bottomNode)
+ newDivision->SetBottomSide((wxDivisionShape *)bottomNode->Data());
+ }
+ node = node->Next();
+ }
+}
+
+wxOGLConstraint *wxCompositeShape::AddConstraint(wxOGLConstraint *constraint)
+{
+ m_constraints.Append(constraint);
+ if (constraint->m_constraintId == 0)
+ constraint->m_constraintId = wxNewId();
+ return constraint;
+}
+
+wxOGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxList& constrained)
+{
+ wxOGLConstraint *constraint = new wxOGLConstraint(type, constraining, constrained);
+ if (constraint->m_constraintId == 0)
+ constraint->m_constraintId = wxNewId();
+ m_constraints.Append(constraint);
+ return constraint;
+}
+
+wxOGLConstraint *wxCompositeShape::AddConstraint(int type, wxShape *constraining, wxShape *constrained)
+{
+ wxList l;
+ l.Append(constrained);
+ wxOGLConstraint *constraint = new wxOGLConstraint(type, constraining, l);
+ if (constraint->m_constraintId == 0)
+ constraint->m_constraintId = wxNewId();
+ m_constraints.Append(constraint);
+ return constraint;
+}
+
+wxOGLConstraint *wxCompositeShape::FindConstraint(long cId, wxCompositeShape **actualComposite)
+{
+ wxNode *node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ if (constraint->m_constraintId == cId)
+ {
+ if (actualComposite)
+ *actualComposite = this;
+ return constraint;
+ }
+ node = node->Next();
+ }
+ // If not found, try children.
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ if (child->IsKindOf(CLASSINFO(wxCompositeShape)))
+ {
+ wxOGLConstraint *constraint = ((wxCompositeShape *)child)->FindConstraint(cId, actualComposite);
+ if (constraint)
+ {
+ if (actualComposite)
+ *actualComposite = (wxCompositeShape *)child;
+ return constraint;
+ }
+ }
+ node = node->Next();
+ }
+ return NULL;
+}
+
+void wxCompositeShape::DeleteConstraint(wxOGLConstraint *constraint)
+{
+ m_constraints.DeleteObject(constraint);
+ delete constraint;
+}
+
+void wxCompositeShape::CalculateSize()
+{
+ double maxX = (double) -999999.9;
+ double maxY = (double) -999999.9;
+ double minX = (double) 999999.9;
+ double minY = (double) 999999.9;
+
+ double w, h;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+
+ // Recalculate size of composite objects because may not conform
+ // to size it was set to - depends on the children.
+ object->CalculateSize();
+
+ object->GetBoundingBoxMax(&w, &h);
+ if ((object->GetX() + (w/2.0)) > maxX)
+ maxX = (double)(object->GetX() + (w/2.0));
+ if ((object->GetX() - (w/2.0)) < minX)
+ minX = (double)(object->GetX() - (w/2.0));
+ if ((object->GetY() + (h/2.0)) > maxY)
+ maxY = (double)(object->GetY() + (h/2.0));
+ if ((object->GetY() - (h/2.0)) < minY)
+ minY = (double)(object->GetY() - (h/2.0));
+
+ node = node->Next();
+ }
+ m_width = maxX - minX;
+ m_height = maxY - minY;
+ m_xpos = (double)(m_width/2.0 + minX);
+ m_ypos = (double)(m_height/2.0 + minY);
+}
+
+bool wxCompositeShape::Recompute()
+{
+ int noIterations = 0;
+ bool changed = TRUE;
+ while (changed && (noIterations < 500))
+ {
+ changed = Constrain();
+ noIterations ++;
+ }
+/*
+#ifdef wx_x
+ if (changed)
+ cerr << "Warning: constraint algorithm failed after 500 iterations.\n";
+#endif
+*/
+ return (!changed);
+}
+
+bool wxCompositeShape::Constrain()
+{
+ CalculateSize();
+
+ bool changed = FALSE;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ if (object->Constrain())
+ changed = TRUE;
+ node = node->Next();
+ }
+
+ node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ if (constraint->Evaluate()) changed = TRUE;
+ node = node->Next();
+ }
+ return changed;
+}
+
+#ifdef PROLOGIO
+void wxCompositeShape::WriteAttributes(wxExpr *clause)
+{
+ wxRectangleShape::WriteAttributes(clause);
+
+// clause->AddAttributeValue("selectable", (long)selectable);
+
+ // Output constraints as constraint1 = (...), constraint2 = (...), etc.
+ int constraintNo = 1;
+ char m_constraintNameBuf[20];
+ wxNode *node = m_constraints.First();
+ while (node)
+ {
+ wxOGLConstraint *constraint = (wxOGLConstraint *)node->Data();
+ sprintf(m_constraintNameBuf, "constraint%d", constraintNo);
+
+ // Each constraint is stored in the form
+ // (type name id xspacing yspacing m_constrainingObjectId constrainedObjectIdList)
+ wxExpr *constraintExpr = new wxExpr(wxExprList);
+ constraintExpr->Append(new wxExpr((long)constraint->m_constraintType));
+ constraintExpr->Append(new wxExpr(wxExprString, constraint->m_constraintName));
+ constraintExpr->Append(new wxExpr(constraint->m_constraintId));
+ constraintExpr->Append(new wxExpr(constraint->m_xSpacing));
+ constraintExpr->Append(new wxExpr(constraint->m_ySpacing));
+ constraintExpr->Append(new wxExpr(constraint->m_constrainingObject->GetId()));
+
+ wxExpr *objectList = new wxExpr(wxExprList);
+ wxNode *node1 = constraint->m_constrainedObjects.First();
+ while (node1)
+ {
+ wxShape *obj = (wxShape *)node1->Data();
+ objectList->Append(new wxExpr(obj->GetId()));
+ node1 = node1->Next();
+ }
+ constraintExpr->Append(objectList);
+
+ clause->AddAttributeValue(m_constraintNameBuf, constraintExpr);
+
+ node = node->Next();
+ constraintNo ++;
+ }
+
+ // Write the ids of all the child images
+ wxExpr *childrenExpr = new wxExpr(wxExprList);
+ node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ childrenExpr->Append(new wxExpr(child->GetId()));
+ node = node->Next();
+ }
+ clause->AddAttributeValue("children", childrenExpr);
+
+ // Write the ids of all the division images
+ if (m_divisions.Number() > 0)
+ {
+ wxExpr *divisionsExpr = new wxExpr(wxExprList);
+ node = m_divisions.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ divisionsExpr->Append(new wxExpr(child->GetId()));
+ node = node->Next();
+ }
+ clause->AddAttributeValue("divisions", divisionsExpr);
+ }
+}
+
+// Problem. Child images are always written AFTER the parent
+// so as to be able to link up to parent. So we may not be able
+// to find the constraint participants until we've read everything
+// in. Need to have another pass for composites.
+void wxCompositeShape::ReadAttributes(wxExpr *clause)
+{
+ wxRectangleShape::ReadAttributes(clause);
+
+// clause->GetAttributeValue("selectable", selectable);
+}
+
+void wxCompositeShape::ReadConstraints(wxExpr *clause, wxExprDatabase *database)
+{
+ // Constraints are output as constraint1 = (...), constraint2 = (...), etc.
+ int constraintNo = 1;
+ char m_constraintNameBuf[20];
+ bool haveConstraints = TRUE;
+
+ while (haveConstraints)
+ {
+ sprintf(m_constraintNameBuf, "constraint%d", constraintNo);
+ wxExpr *constraintExpr = NULL;
+ clause->GetAttributeValue(m_constraintNameBuf, &constraintExpr);
+ if (!constraintExpr)
+ {
+ haveConstraints = FALSE;
+ break;
+ }
+ int cType = 0;
+ double cXSpacing = 0.0;
+ double cYSpacing = 0.0;
+ wxString cName("");
+ long cId = 0;
+ wxShape *m_constrainingObject = NULL;
+ wxList m_constrainedObjects;
+
+ // Each constraint is stored in the form
+ // (type name id xspacing yspacing m_constrainingObjectId constrainedObjectIdList)
+
+ wxExpr *typeExpr = constraintExpr->Nth(0);
+ wxExpr *nameExpr = constraintExpr->Nth(1);
+ wxExpr *idExpr = constraintExpr->Nth(2);
+ wxExpr *xExpr = constraintExpr->Nth(3);
+ wxExpr *yExpr = constraintExpr->Nth(4);
+ wxExpr *constrainingExpr = constraintExpr->Nth(5);
+ wxExpr *constrainedExpr = constraintExpr->Nth(6);
+
+ cType = (int)typeExpr->IntegerValue();
+ cXSpacing = xExpr->RealValue();
+ cYSpacing = yExpr->RealValue();
+ cName = nameExpr->StringValue();
+ cId = idExpr->IntegerValue();
+
+ wxExpr *objExpr1 = database->HashFind("node_image", constrainingExpr->IntegerValue());
+ if (objExpr1 && objExpr1->GetClientData())
+ m_constrainingObject = (wxShape *)objExpr1->GetClientData();
+ else
+ wxFatalError("Couldn't find constraining image of composite.", "Object graphics error");
+
+ int i = 0;
+ wxExpr *currentIdExpr = constrainedExpr->Nth(i);
+ while (currentIdExpr)
+ {
+ long currentId = currentIdExpr->IntegerValue();
+ wxExpr *objExpr2 = database->HashFind("node_image", currentId);
+ if (objExpr2 && objExpr2->GetClientData())
+ {
+ m_constrainedObjects.Append((wxShape *)objExpr2->GetClientData());
+ }
+ else
+ {
+ wxFatalError("Couldn't find constrained image of composite.", "Object graphics error");
+ }
+
+ i ++;
+ currentIdExpr = constrainedExpr->Nth(i);
+ }
+ wxOGLConstraint *newConstraint = AddConstraint(cType, m_constrainingObject, m_constrainedObjects);
+ newConstraint->SetSpacing(cXSpacing, cYSpacing);
+ newConstraint->m_constraintId = cId;
+ newConstraint->m_constraintName = (const char*) cName;
+ constraintNo ++;
+ }
+}
+#endif
+
+// Make this composite into a container by creating one wxDivisionShape
+void wxCompositeShape::MakeContainer()
+{
+ wxDivisionShape *division = OnCreateDivision();
+ m_divisions.Append(division);
+ AddChild(division);
+
+ division->SetSize(m_width, m_height);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ division->Move(dc, GetX(), GetY());
+ Recompute();
+ division->Show(TRUE);
+}
+
+wxDivisionShape *wxCompositeShape::OnCreateDivision()
+{
+ return new wxDivisionShape;
+}
+
+wxShape *wxCompositeShape::FindContainerImage()
+{
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ if (!m_divisions.Member(child))
+ return child;
+ node = node->Next();
+ }
+ return NULL;
+}
+
+// Returns TRUE if division is a descendant of this container
+bool wxCompositeShape::ContainsDivision(wxDivisionShape *division)
+{
+ if (m_divisions.Member(division))
+ return TRUE;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *child = (wxShape *)node->Data();
+ if (child->IsKindOf(CLASSINFO(wxCompositeShape)))
+ {
+ bool ans = ((wxCompositeShape *)child)->ContainsDivision(division);
+ if (ans)
+ return TRUE;
+ }
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+/*
+ * Division object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxDivisionShape, wxCompositeShape)
+
+wxDivisionShape::wxDivisionShape()
+{
+ SetSensitivityFilter(OP_CLICK_LEFT | OP_CLICK_RIGHT | OP_DRAG_RIGHT);
+ SetCentreResize(FALSE);
+ SetAttachmentMode(TRUE);
+ m_leftSide = NULL;
+ m_rightSide = NULL;
+ m_topSide = NULL;
+ m_bottomSide = NULL;
+ m_handleSide = DIVISION_SIDE_NONE;
+ m_leftSidePen = wxBLACK_PEN;
+ m_topSidePen = wxBLACK_PEN;
+ m_leftSideColour = "BLACK";
+ m_topSideColour = "BLACK";
+ m_leftSideStyle = "Solid";
+ m_topSideStyle = "Solid";
+ ClearRegions();
+}
+
+wxDivisionShape::~wxDivisionShape()
+{
+}
+
+void wxDivisionShape::OnDraw(wxDC& dc)
+{
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+ dc.SetBackgroundMode(wxTRANSPARENT);
+
+ double x1 = (double)(GetX() - (GetWidth()/2.0));
+ double y1 = (double)(GetY() - (GetHeight()/2.0));
+ double x2 = (double)(GetX() + (GetWidth()/2.0));
+ double y2 = (double)(GetY() + (GetHeight()/2.0));
+
+ // Should subtract 1 pixel if drawing under Windows
+#ifdef __WXMSW__
+ y2 -= (double)1.0;
+#endif
+
+ if (m_leftSide)
+ {
+ dc.SetPen(* m_leftSidePen);
+ dc.DrawLine(WXROUND(x1), WXROUND(y2), WXROUND(x1), WXROUND(y1));
+ }
+ if (m_topSide)
+ {
+ dc.SetPen(* m_topSidePen);
+ dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y1));
+ }
+
+ // For testing purposes, draw a rectangle so we know
+ // how big the division is.
+// SetBrush(* wxCYAN_BRUSH);
+// wxRectangleShape::OnDraw(dc);
+}
+
+void wxDivisionShape::OnDrawContents(wxDC& dc)
+{
+ wxCompositeShape::OnDrawContents(dc);
+}
+
+bool wxDivisionShape::OnMovePre(wxDC& dc, double x, double y, double oldx, double oldy, bool display)
+{
+ double diffX = x - oldx;
+ double diffY = y - oldy;
+ wxNode *node = m_children.First();
+ while (node)
+ {
+ wxShape *object = (wxShape *)node->Data();
+ object->Erase(dc);
+ object->Move(dc, object->GetX() + diffX, object->GetY() + diffY, display);
+ node = node->Next();
+ }
+ return TRUE;
+}
+
+void wxDivisionShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnDragLeft(draw, x, y, keys, attachment);
+ }
+ return;
+ }
+ wxShape::OnDragLeft(draw, x, y, keys, attachment);
+}
+
+void wxDivisionShape::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnBeginDragLeft(x, y, keys, attachment);
+ }
+ return;
+ }
+
+ wxShape::OnBeginDragLeft(x, y, keys, attachment);
+}
+
+void wxDivisionShape::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ m_canvas->ReleaseMouse();
+ if ((m_sensitivity & OP_DRAG_LEFT) != OP_DRAG_LEFT)
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnEndDragLeft(x, y, keys, attachment);
+ }
+ return;
+ }
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(wxCOPY);
+
+ m_canvas->Snap(&m_xpos, &m_ypos);
+ GetEventHandler()->OnMovePre(dc, x, y, m_oldX, m_oldY);
+
+ ResetControlPoints();
+ Draw(dc);
+ MoveLinks(dc);
+ GetEventHandler()->OnDrawControlPoints(dc);
+
+ if (m_canvas && !m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);
+}
+
+void wxDivisionShape::SetSize(double w, double h, bool recursive)
+{
+ m_width = w;
+ m_height = h;
+ wxRectangleShape::SetSize(w, h, recursive);
+}
+
+void wxDivisionShape::CalculateSize()
+{
+}
+
+void wxDivisionShape::Copy(wxShape& copy)
+{
+ wxCompositeShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxDivisionShape)) ) ;
+
+ wxDivisionShape& divisionCopy = (wxDivisionShape&) copy;
+
+ divisionCopy.m_leftSideStyle = m_leftSideStyle;
+ divisionCopy.m_topSideStyle = m_topSideStyle;
+ divisionCopy.m_leftSideColour = m_leftSideColour;
+ divisionCopy.m_topSideColour = m_topSideColour;
+
+ divisionCopy.m_leftSidePen = m_leftSidePen;
+ divisionCopy.m_topSidePen = m_topSidePen;
+ divisionCopy.m_handleSide = m_handleSide;
+
+ // Division geometry copying is handled at the wxCompositeShape level.
+}
+
+#ifdef PROLOGIO
+void wxDivisionShape::WriteAttributes(wxExpr *clause)
+{
+ wxCompositeShape::WriteAttributes(clause);
+
+ if (m_leftSide)
+ clause->AddAttributeValue("left_side", (long)m_leftSide->GetId());
+ if (m_topSide)
+ clause->AddAttributeValue("top_side", (long)m_topSide->GetId());
+ if (m_rightSide)
+ clause->AddAttributeValue("right_side", (long)m_rightSide->GetId());
+ if (m_bottomSide)
+ clause->AddAttributeValue("bottom_side", (long)m_bottomSide->GetId());
+
+ clause->AddAttributeValue("handle_side", (long)m_handleSide);
+ clause->AddAttributeValueString("left_colour", m_leftSideColour);
+ clause->AddAttributeValueString("top_colour", m_topSideColour);
+ clause->AddAttributeValueString("left_style", m_leftSideStyle);
+ clause->AddAttributeValueString("top_style", m_topSideStyle);
+}
+
+void wxDivisionShape::ReadAttributes(wxExpr *clause)
+{
+ wxCompositeShape::ReadAttributes(clause);
+
+ clause->GetAttributeValue("handle_side", m_handleSide);
+ clause->GetAttributeValue("left_colour", m_leftSideColour);
+ clause->GetAttributeValue("top_colour", m_topSideColour);
+ clause->GetAttributeValue("left_style", m_leftSideStyle);
+ clause->GetAttributeValue("top_style", m_topSideStyle);
+}
+#endif
+
+// Experimental
+void wxDivisionShape::OnRightClick(double x, double y, int keys, int attachment)
+{
+ if (keys & KEY_CTRL)
+ {
+ PopupMenu(x, y);
+ }
+/*
+ else if (keys & KEY_SHIFT)
+ {
+ if (m_leftSide || m_topSide || m_rightSide || m_bottomSide)
+ {
+ if (Selected())
+ {
+ Select(FALSE);
+ GetParent()->Draw(dc);
+ }
+ else
+ Select(TRUE);
+ }
+ }
+*/
+ else
+ {
+ attachment = 0;
+ double dist;
+ if (m_parent)
+ {
+ m_parent->HitTest(x, y, &attachment, &dist);
+ m_parent->GetEventHandler()->OnRightClick(x, y, keys, attachment);
+ }
+ return;
+ }
+}
+
+
+// Divide wxHORIZONTALly or wxVERTICALly
+bool wxDivisionShape::Divide(int direction)
+{
+ // Calculate existing top-left, bottom-right
+ double x1 = (double)(GetX() - (GetWidth()/2.0));
+ double y1 = (double)(GetY() - (GetHeight()/2.0));
+ wxCompositeShape *compositeParent = (wxCompositeShape *)GetParent();
+ double oldWidth = GetWidth();
+ double oldHeight = GetHeight();
+ if (Selected())
+ Select(FALSE);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ if (direction == wxVERTICAL)
+ {
+ // Dividing vertically means notionally putting a horizontal line through it.
+ // Break existing piece into two.
+ double newXPos1 = GetX();
+ double newYPos1 = (double)(y1 + (GetHeight()/4.0));
+ double newXPos2 = GetX();
+ double newYPos2 = (double)(y1 + (3.0*GetHeight()/4.0));
+ wxDivisionShape *newDivision = compositeParent->OnCreateDivision();
+ newDivision->Show(TRUE);
+
+ Erase(dc);
+
+ // Anything adjoining the bottom of this division now adjoins the
+ // bottom of the new division.
+ wxNode *node = compositeParent->GetDivisions().First();
+ while (node)
+ {
+ wxDivisionShape *obj = (wxDivisionShape *)node->Data();
+ if (obj->GetTopSide() == this)
+ obj->SetTopSide(newDivision);
+ node = node->Next();
+ }
+ newDivision->SetTopSide(this);
+ newDivision->SetBottomSide(m_bottomSide);
+ newDivision->SetLeftSide(m_leftSide);
+ newDivision->SetRightSide(m_rightSide);
+ m_bottomSide = newDivision;
+
+ compositeParent->GetDivisions().Append(newDivision);
+
+ // CHANGE: Need to insert this division at start of divisions in the object
+ // list, because e.g.:
+ // 1) Add division
+ // 2) Add contained object
+ // 3) Add division
+ // Division is now receiving mouse events _before_ the contained object,
+ // because it was added last (on top of all others)
+
+ // Add after the image that visualizes the container
+ compositeParent->AddChild(newDivision, compositeParent->FindContainerImage());
+
+ m_handleSide = DIVISION_SIDE_BOTTOM;
+ newDivision->SetHandleSide(DIVISION_SIDE_TOP);
+
+ SetSize(oldWidth, (double)(oldHeight/2.0));
+ Move(dc, newXPos1, newYPos1);
+
+ newDivision->SetSize(oldWidth, (double)(oldHeight/2.0));
+ newDivision->Move(dc, newXPos2, newYPos2);
+ }
+ else
+ {
+ // Dividing horizontally means notionally putting a vertical line through it.
+ // Break existing piece into two.
+ double newXPos1 = (double)(x1 + (GetWidth()/4.0));
+ double newYPos1 = GetY();
+ double newXPos2 = (double)(x1 + (3.0*GetWidth()/4.0));
+ double newYPos2 = GetY();
+ wxDivisionShape *newDivision = compositeParent->OnCreateDivision();
+ newDivision->Show(TRUE);
+
+ Erase(dc);
+
+ // Anything adjoining the left of this division now adjoins the
+ // left of the new division.
+ wxNode *node = compositeParent->GetDivisions().First();
+ while (node)
+ {
+ wxDivisionShape *obj = (wxDivisionShape *)node->Data();
+ if (obj->GetLeftSide() == this)
+ obj->SetLeftSide(newDivision);
+ node = node->Next();
+ }
+ newDivision->SetTopSide(m_topSide);
+ newDivision->SetBottomSide(m_bottomSide);
+ newDivision->SetLeftSide(this);
+ newDivision->SetRightSide(m_rightSide);
+ m_rightSide = newDivision;
+
+ compositeParent->GetDivisions().Append(newDivision);
+ compositeParent->AddChild(newDivision, compositeParent->FindContainerImage());
+
+ m_handleSide = DIVISION_SIDE_RIGHT;
+ newDivision->SetHandleSide(DIVISION_SIDE_LEFT);
+
+ SetSize((double)(oldWidth/2.0), oldHeight);
+ Move(dc, newXPos1, newYPos1);
+
+ newDivision->SetSize((double)(oldWidth/2.0), oldHeight);
+ newDivision->Move(dc, newXPos2, newYPos2);
+ }
+ if (compositeParent->Selected())
+ {
+ compositeParent->DeleteControlPoints(& dc);
+ compositeParent->MakeControlPoints();
+ compositeParent->MakeMandatoryControlPoints();
+ }
+ compositeParent->Draw(dc);
+ return TRUE;
+}
+
+// Make one control point for every visible line
+void wxDivisionShape::MakeControlPoints()
+{
+ MakeMandatoryControlPoints();
+}
+
+void wxDivisionShape::MakeMandatoryControlPoints()
+{
+ double maxX, maxY;
+
+ GetBoundingBoxMax(&maxX, &maxY);
+ double x, y;
+ int direction;
+/*
+ if (m_leftSide)
+ {
+ x = (double)(-maxX/2.0);
+ y = 0.0;
+ wxDivisionControlPoint *control = new wxDivisionControlPoint(m_canvas, this, CONTROL_POINT_SIZE, x, y,
+ CONTROL_POINT_HORIZONTAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+ }
+ if (m_topSide)
+ {
+ x = 0.0;
+ y = (double)(-maxY/2.0);
+ wxDivisionControlPoint *control = new wxDivisionControlPoint(m_canvas, this, CONTROL_POINT_SIZE, x, y,
+ CONTROL_POINT_VERTICAL);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+ }
+*/
+ switch (m_handleSide)
+ {
+ case DIVISION_SIDE_LEFT:
+ {
+ x = (double)(-maxX/2.0);
+ y = 0.0;
+ direction = CONTROL_POINT_HORIZONTAL;
+ break;
+ }
+ case DIVISION_SIDE_TOP:
+ {
+ x = 0.0;
+ y = (double)(-maxY/2.0);
+ direction = CONTROL_POINT_VERTICAL;
+ break;
+ }
+ case DIVISION_SIDE_RIGHT:
+ {
+ x = (double)(maxX/2.0);
+ y = 0.0;
+ direction = CONTROL_POINT_HORIZONTAL;
+ break;
+ }
+ case DIVISION_SIDE_BOTTOM:
+ {
+ x = 0.0;
+ y = (double)(maxY/2.0);
+ direction = CONTROL_POINT_VERTICAL;
+ break;
+ }
+ default:
+ break;
+ }
+ if (m_handleSide != DIVISION_SIDE_NONE)
+ {
+ wxDivisionControlPoint *control = new wxDivisionControlPoint(m_canvas, this, CONTROL_POINT_SIZE, x, y,
+ direction);
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+ }
+}
+
+void wxDivisionShape::ResetControlPoints()
+{
+ ResetMandatoryControlPoints();
+}
+
+void wxDivisionShape::ResetMandatoryControlPoints()
+{
+ if (m_controlPoints.Number() < 1)
+ return;
+
+ double maxX, maxY;
+
+ GetBoundingBoxMax(&maxX, &maxY);
+/*
+ wxNode *node = m_controlPoints.First();
+ while (node)
+ {
+ wxDivisionControlPoint *control = (wxDivisionControlPoint *)node->Data();
+ if (control->type == CONTROL_POINT_HORIZONTAL)
+ {
+ control->xoffset = (double)(-maxX/2.0); control->m_yoffset = 0.0;
+ }
+ else if (control->type == CONTROL_POINT_VERTICAL)
+ {
+ control->xoffset = 0.0; control->m_yoffset = (double)(-maxY/2.0);
+ }
+ node = node->Next();
+ }
+*/
+ wxNode *node = m_controlPoints.First();
+ if ((m_handleSide == DIVISION_SIDE_LEFT) && node)
+ {
+ wxDivisionControlPoint *control = (wxDivisionControlPoint *)node->Data();
+ control->m_xoffset = (double)(-maxX/2.0); control->m_yoffset = 0.0;
+ }
+
+ if ((m_handleSide == DIVISION_SIDE_TOP) && node)
+ {
+ wxDivisionControlPoint *control = (wxDivisionControlPoint *)node->Data();
+ control->m_xoffset = 0.0; control->m_yoffset = (double)(-maxY/2.0);
+ }
+
+ if ((m_handleSide == DIVISION_SIDE_RIGHT) && node)
+ {
+ wxDivisionControlPoint *control = (wxDivisionControlPoint *)node->Data();
+ control->m_xoffset = (double)(maxX/2.0); control->m_yoffset = 0.0;
+ }
+
+ if ((m_handleSide == DIVISION_SIDE_BOTTOM) && node)
+ {
+ wxDivisionControlPoint *control = (wxDivisionControlPoint *)node->Data();
+ control->m_xoffset = 0.0; control->m_yoffset = (double)(maxY/2.0);
+ }
+}
+
+// Adjust a side, returning FALSE if it's not physically possible.
+bool wxDivisionShape::AdjustLeft(double left, bool test)
+{
+ double x2 = (double)(GetX() + (GetWidth()/2.0));
+
+ if (left >= x2)
+ return FALSE;
+ if (test)
+ return TRUE;
+
+ double newW = x2 - left;
+ double newX = (double)(left + newW/2.0);
+ SetSize(newW, GetHeight());
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ Move(dc, newX, GetY());
+
+ return TRUE;
+}
+
+bool wxDivisionShape::AdjustTop(double top, bool test)
+{
+ double y2 = (double)(GetY() + (GetHeight()/2.0));
+
+ if (top >= y2)
+ return FALSE;
+ if (test)
+ return TRUE;
+
+ double newH = y2 - top;
+ double newY = (double)(top + newH/2.0);
+ SetSize(GetWidth(), newH);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ Move(dc, GetX(), newY);
+
+ return TRUE;
+}
+
+bool wxDivisionShape::AdjustRight(double right, bool test)
+{
+ double x1 = (double)(GetX() - (GetWidth()/2.0));
+
+ if (right <= x1)
+ return FALSE;
+ if (test)
+ return TRUE;
+
+ double newW = right - x1;
+ double newX = (double)(x1 + newW/2.0);
+ SetSize(newW, GetHeight());
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ Move(dc, newX, GetY());
+
+ return TRUE;
+}
+
+bool wxDivisionShape::AdjustBottom(double bottom, bool test)
+{
+ double y1 = (double)(GetY() - (GetHeight()/2.0));
+
+ if (bottom <= y1)
+ return FALSE;
+ if (test)
+ return TRUE;
+
+ double newH = bottom - y1;
+ double newY = (double)(y1 + newH/2.0);
+ SetSize(GetWidth(), newH);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ Move(dc, GetX(), newY);
+
+ return TRUE;
+}
+
+wxDivisionControlPoint::wxDivisionControlPoint(wxShapeCanvas *the_canvas, wxShape *object, double size, double the_xoffset, double the_yoffset, int the_type):
+ wxControlPoint(the_canvas, object, size, the_xoffset, the_yoffset, the_type)
+{
+ SetEraseObject(FALSE);
+}
+
+wxDivisionControlPoint::~wxDivisionControlPoint()
+{
+}
+
+static double originalX = 0.0;
+static double originalY = 0.0;
+static double originalW = 0.0;
+static double originalH = 0.0;
+
+// Implement resizing of canvas object
+void wxDivisionControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ wxControlPoint::OnDragLeft(draw, x, y, keys, attachment);
+}
+
+void wxDivisionControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ wxDivisionShape *division = (wxDivisionShape *)m_shape;
+ originalX = division->GetX();
+ originalY = division->GetY();
+ originalW = division->GetWidth();
+ originalH = division->GetHeight();
+
+ wxControlPoint::OnBeginDragLeft(x, y, keys, attachment);
+}
+
+void wxDivisionControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ wxControlPoint::OnEndDragLeft(x, y, keys, attachment);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxDivisionShape *division = (wxDivisionShape *)m_shape;
+ wxCompositeShape *divisionParent = (wxCompositeShape *)division->GetParent();
+
+ // Need to check it's within the bounds of the parent composite.
+ double x1 = (double)(divisionParent->GetX() - (divisionParent->GetWidth()/2.0));
+ double y1 = (double)(divisionParent->GetY() - (divisionParent->GetHeight()/2.0));
+ double x2 = (double)(divisionParent->GetX() + (divisionParent->GetWidth()/2.0));
+ double y2 = (double)(divisionParent->GetY() + (divisionParent->GetHeight()/2.0));
+
+ // Need to check it has not made the division zero or negative width/height
+ double dx1 = (double)(division->GetX() - (division->GetWidth()/2.0));
+ double dy1 = (double)(division->GetY() - (division->GetHeight()/2.0));
+ double dx2 = (double)(division->GetX() + (division->GetWidth()/2.0));
+ double dy2 = (double)(division->GetY() + (division->GetHeight()/2.0));
+
+ bool success = TRUE;
+ switch (division->GetHandleSide())
+ {
+ case DIVISION_SIDE_LEFT:
+ {
+ if ((x <= x1) || (x >= x2) || (x >= dx2))
+ success = FALSE;
+ // Try it out first...
+ else if (!division->ResizeAdjoining(DIVISION_SIDE_LEFT, x, TRUE))
+ success = FALSE;
+ else
+ division->ResizeAdjoining(DIVISION_SIDE_LEFT, x, FALSE);
+
+ break;
+ }
+ case DIVISION_SIDE_TOP:
+ {
+ if ((y <= y1) || (y >= y2) || (y >= dy2))
+ success = FALSE;
+ else if (!division->ResizeAdjoining(DIVISION_SIDE_TOP, y, TRUE))
+ success = FALSE;
+ else
+ division->ResizeAdjoining(DIVISION_SIDE_TOP, y, FALSE);
+
+ break;
+ }
+ case DIVISION_SIDE_RIGHT:
+ {
+ if ((x <= x1) || (x >= x2) || (x <= dx1))
+ success = FALSE;
+ else if (!division->ResizeAdjoining(DIVISION_SIDE_RIGHT, x, TRUE))
+ success = FALSE;
+ else
+ division->ResizeAdjoining(DIVISION_SIDE_RIGHT, x, FALSE);
+
+ break;
+ }
+ case DIVISION_SIDE_BOTTOM:
+ {
+ if ((y <= y1) || (y >= y2) || (y <= dy1))
+ success = FALSE;
+ else if (!division->ResizeAdjoining(DIVISION_SIDE_BOTTOM, y, TRUE))
+ success = FALSE;
+ else
+ division->ResizeAdjoining(DIVISION_SIDE_BOTTOM, y, FALSE);
+
+ break;
+ }
+ }
+ if (!success)
+ {
+ division->SetSize(originalW, originalH);
+ division->Move(dc, originalX, originalY);
+ }
+ divisionParent->Draw(dc);
+ division->GetEventHandler()->OnDrawControlPoints(dc);
+}
+
+/* Resize adjoining divisions.
+ *
+ Behaviour should be as follows:
+ If right edge moves, find all objects whose left edge
+ adjoins this object, and move left edge accordingly.
+ If left..., move ... right.
+ If top..., move ... bottom.
+ If bottom..., move top.
+ If size goes to zero or end position is other side of start position,
+ resize to original size and return.
+ */
+bool wxDivisionShape::ResizeAdjoining(int side, double newPos, bool test)
+{
+ wxCompositeShape *divisionParent = (wxCompositeShape *)GetParent();
+ wxNode *node = divisionParent->GetDivisions().First();
+ while (node)
+ {
+ wxDivisionShape *division = (wxDivisionShape *)node->Data();
+ switch (side)
+ {
+ case DIVISION_SIDE_LEFT:
+ {
+ if (division->m_rightSide == this)
+ {
+ bool success = division->AdjustRight(newPos, test);
+ if (!success && test)
+ return FALSE;
+ }
+ break;
+ }
+ case DIVISION_SIDE_TOP:
+ {
+ if (division->m_bottomSide == this)
+ {
+ bool success = division->AdjustBottom(newPos, test);
+ if (!success && test)
+ return FALSE;
+ }
+ break;
+ }
+ case DIVISION_SIDE_RIGHT:
+ {
+ if (division->m_leftSide == this)
+ {
+ bool success = division->AdjustLeft(newPos, test);
+ if (!success && test)
+ return FALSE;
+ }
+ break;
+ }
+ case DIVISION_SIDE_BOTTOM:
+ {
+ if (division->m_topSide == this)
+ {
+ bool success = division->AdjustTop(newPos, test);
+ if (!success && test)
+ return FALSE;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ node = node->Next();
+ }
+
+ return TRUE;
+}
+
+/*
+ * Popup menu for editing divisions
+ *
+ */
+class OGLPopupDivisionMenu : public wxMenu {
+public:
+ OGLPopupDivisionMenu() : wxMenu() {
+ Append(DIVISION_MENU_SPLIT_HORIZONTALLY, "Split horizontally");
+ Append(DIVISION_MENU_SPLIT_VERTICALLY, "Split vertically");
+ AppendSeparator();
+ Append(DIVISION_MENU_EDIT_LEFT_EDGE, "Edit left edge");
+ Append(DIVISION_MENU_EDIT_TOP_EDGE, "Edit top edge");
+ }
+
+ void OnMenu(wxCommandEvent& event);
+
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(OGLPopupDivisionMenu, wxMenu)
+ EVT_CUSTOM_RANGE(wxEVT_COMMAND_MENU_SELECTED,
+ DIVISION_MENU_SPLIT_HORIZONTALLY,
+ DIVISION_MENU_EDIT_BOTTOM_EDGE,
+ OGLPopupDivisionMenu::OnMenu)
+END_EVENT_TABLE()
+
+
+void OGLPopupDivisionMenu::OnMenu(wxCommandEvent& event)
+{
+ wxDivisionShape *division = (wxDivisionShape *)GetClientData();
+ switch (event.GetInt())
+ {
+ case DIVISION_MENU_SPLIT_HORIZONTALLY:
+ {
+ division->Divide(wxHORIZONTAL);
+ break;
+ }
+ case DIVISION_MENU_SPLIT_VERTICALLY:
+ {
+ division->Divide(wxVERTICAL);
+ break;
+ }
+ case DIVISION_MENU_EDIT_LEFT_EDGE:
+ {
+ division->EditEdge(DIVISION_SIDE_LEFT);
+ break;
+ }
+ case DIVISION_MENU_EDIT_TOP_EDGE:
+ {
+ division->EditEdge(DIVISION_SIDE_TOP);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void wxDivisionShape::EditEdge(int side)
+{
+ wxMessageBox("EditEdge() not implemented", "OGL", wxOK);
+
+#if 0
+ wxBeginBusyCursor();
+
+ wxPen *currentPen = NULL;
+ char **pColour = NULL;
+ char **pStyle = NULL;
+ if (side == DIVISION_SIDE_LEFT)
+ {
+ currentPen = m_leftSidePen;
+ pColour = &m_leftSideColour;
+ pStyle = &m_leftSideStyle;
+ }
+ else
+ {
+ currentPen = m_topSidePen;
+ pColour = &m_topSideColour;
+ pStyle = &m_topSideStyle;
+ }
+
+ GraphicsForm *form = new GraphicsForm("Containers");
+ int lineWidth = currentPen->GetWidth();
+
+ form->Add(wxMakeFormShort("Width", &lineWidth, wxFORM_DEFAULT, NULL, NULL, wxVERTICAL,
+ 150));
+ form->Add(wxMakeFormString("Colour", pColour, wxFORM_CHOICE,
+ new wxList(wxMakeConstraintStrings(
+ "BLACK" ,
+ "BLUE" ,
+ "BROWN" ,
+ "CORAL" ,
+ "CYAN" ,
+ "DARK GREY" ,
+ "DARK GREEN" ,
+ "DIM GREY" ,
+ "GREY" ,
+ "GREEN" ,
+ "LIGHT BLUE" ,
+ "LIGHT GREY" ,
+ "MAGENTA" ,
+ "MAROON" ,
+ "NAVY" ,
+ "ORANGE" ,
+ "PURPLE" ,
+ "RED" ,
+ "TURQUOISE" ,
+ "VIOLET" ,
+ "WHITE" ,
+ "YELLOW" ,
+ NULL),
+ NULL), NULL, wxVERTICAL, 150));
+ form->Add(wxMakeFormString("Style", pStyle, wxFORM_CHOICE,
+ new wxList(wxMakeConstraintStrings(
+ "Solid" ,
+ "Short Dash" ,
+ "Long Dash" ,
+ "Dot" ,
+ "Dot Dash" ,
+ NULL),
+ NULL), NULL, wxVERTICAL, 100));
+
+ wxDialogBox *dialog = new wxDialogBox(m_canvas->GetParent(), "Division properties", 10, 10, 500, 500);
+ if (GraphicsLabelFont)
+ dialog->SetLabelFont(GraphicsLabelFont);
+ if (GraphicsButtonFont)
+ dialog->SetButtonFont(GraphicsButtonFont);
+
+ form->AssociatePanel(dialog);
+ form->dialog = dialog;
+
+ dialog->Fit();
+ dialog->Centre(wxBOTH);
+
+ wxEndBusyCursor();
+ dialog->Show(TRUE);
+
+ int lineStyle = wxSOLID;
+ if (*pStyle)
+ {
+ if (strcmp(*pStyle, "Solid") == 0)
+ lineStyle = wxSOLID;
+ else if (strcmp(*pStyle, "Dot") == 0)
+ lineStyle = wxDOT;
+ else if (strcmp(*pStyle, "Short Dash") == 0)
+ lineStyle = wxSHORT_DASH;
+ else if (strcmp(*pStyle, "Long Dash") == 0)
+ lineStyle = wxLONG_DASH;
+ else if (strcmp(*pStyle, "Dot Dash") == 0)
+ lineStyle = wxDOT_DASH;
+ }
+
+ wxPen *newPen = wxThePenList->FindOrCreatePen(*pColour, lineWidth, lineStyle);
+ if (!pen)
+ pen = wxBLACK_PEN;
+ if (side == DIVISION_SIDE_LEFT)
+ m_leftSidePen = newPen;
+ else
+ m_topSidePen = newPen;
+
+ // Need to draw whole image again
+ wxCompositeShape *compositeParent = (wxCompositeShape *)GetParent();
+ compositeParent->Draw(dc);
+#endif
+}
+
+// Popup menu
+void wxDivisionShape::PopupMenu(double x, double y)
+{
+ wxMenu* oglPopupDivisionMenu = new OGLPopupDivisionMenu;
+
+ oglPopupDivisionMenu->SetClientData((void *)this);
+ if (m_leftSide)
+ oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, TRUE);
+ else
+ oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_LEFT_EDGE, FALSE);
+ if (m_topSide)
+ oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, TRUE);
+ else
+ oglPopupDivisionMenu->Enable(DIVISION_MENU_EDIT_TOP_EDGE, FALSE);
+
+ int x1, y1;
+ m_canvas->ViewStart(&x1, &y1);
+
+ int unit_x, unit_y;
+ m_canvas->GetScrollPixelsPerUnit(&unit_x, &unit_y);
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ int mouse_x = (int)(dc.LogicalToDeviceX((long)(x - x1*unit_x)));
+ int mouse_y = (int)(dc.LogicalToDeviceY((long)(y - y1*unit_y)));
+
+ m_canvas->PopupMenu(oglPopupDivisionMenu, mouse_x, mouse_y);
+ delete oglPopupDivisionMenu;
+}
+
+void wxDivisionShape::SetLeftSideColour(const wxString& colour)
+{
+ m_leftSideColour = colour;
+}
+
+void wxDivisionShape::SetTopSideColour(const wxString& colour)
+{
+ m_topSideColour = colour;
+}
+
+void wxDivisionShape::SetLeftSideStyle(const wxString& style)
+{
+ m_leftSideStyle = style;
+}
+
+void wxDivisionShape::SetTopSideStyle(const wxString& style)
+{
+ m_topSideStyle = style;
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: composit.h
+// Purpose: wxCompositeShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_COMPOSIT_H_
+#define _OGL_COMPOSIT_H_
+
+#ifdef __GNUG__
+#pragma interface "composit.h"
+#endif
+
+class wxDivisionShape;
+class wxOGLConstraint;
+
+/*
+ * A composite object is an invisible rectangle surrounding all children
+ *
+ */
+
+class wxCompositeShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxCompositeShape)
+public:
+
+ wxCompositeShape();
+ ~wxCompositeShape();
+
+ void OnDraw(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+ void OnErase(wxDC& dc);
+ bool OnMovePre(wxDC& dc, double x, double y, double oldX, double oldY, bool display = TRUE);
+ void OnDragLeft(bool draw, double x, double y, int keys, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys, int attachment = 0);
+
+ void OnRightClick(double x, double y, int keys, int attachment = 0);
+
+ void SetSize(double w, double h, bool recursive = TRUE);
+
+ // Returns TRUE if it settled down
+ bool Recompute();
+
+ // New members
+ void AddChild(wxShape *child, wxShape *addAfter = NULL);
+ void RemoveChild(wxShape *child);
+
+ wxOGLConstraint *AddConstraint(wxOGLConstraint *constraint);
+ wxOGLConstraint *AddConstraint(int type, wxShape *constraining, wxList& constrained);
+ wxOGLConstraint *AddConstraint(int type, wxShape *constraining, wxShape *constrained);
+
+ void DeleteConstraint(wxOGLConstraint *constraint);
+
+ // Delete constraints that involve this child.
+ void DeleteConstraintsInvolvingChild(wxShape *child);
+
+ // Remove the image from any constraints involving it, but DON'T
+ // remove any constraints.
+ void RemoveChildFromConstraints(wxShape *child);
+
+ // Find constraint, also returning actual composite the constraint was in,
+ // in case it had to find it recursively.
+ wxOGLConstraint *FindConstraint(long id, wxCompositeShape **actualComposite = NULL);
+
+ // Returns TRUE if something changed
+ bool Constrain();
+
+ // Make this composite into a container by creating one wxDivisionShape
+ void MakeContainer();
+
+ // Calculates size and position of composite object based on children
+ void CalculateSize();
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+ // In case the object has constraints it needs to read in in a different pass
+ void ReadConstraints(wxExpr *clause, wxExprDatabase *database);
+#endif
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ virtual wxDivisionShape *OnCreateDivision();
+
+ // Finds the image used to visualize a container. This is any child
+ // of the composite that is not in the divisions list.
+ wxShape *FindContainerImage();
+
+ // Returns TRUE if division is a descendant of this container
+ bool ContainsDivision(wxDivisionShape *division);
+
+ inline wxList& GetDivisions() const { return (wxList&) m_divisions; }
+ inline wxList& GetConstraints() const { return (wxList&) m_constraints; }
+
+protected:
+ double m_oldX;
+ double m_oldY;
+ wxList m_constraints;
+ wxList m_divisions; // In case it's a container
+};
+
+/*
+ * A division object is a composite with special properties,
+ * to be used for containment. It's a subdivision of a container.
+ * A containing node image consists of a composite with a main child shape
+ * such as rounded rectangle, plus a list of division objects.
+ * It needs to be a composite because a division contains pieces
+ * of diagram.
+ * NOTE a container has at least one wxDivisionShape for consistency.
+ * This can be subdivided, so it turns into two objects, then each of
+ * these can be subdivided, etc.
+ */
+#define DIVISION_SIDE_NONE 0
+#define DIVISION_SIDE_LEFT 1
+#define DIVISION_SIDE_TOP 2
+#define DIVISION_SIDE_RIGHT 3
+#define DIVISION_SIDE_BOTTOM 4
+
+class wxDivisionShape: public wxCompositeShape
+{
+ DECLARE_DYNAMIC_CLASS(wxDivisionShape)
+ public:
+
+ wxDivisionShape();
+ ~wxDivisionShape();
+
+ void OnDraw(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+ bool OnMovePre(wxDC& dc, double x, double y, double oldX, double oldY, bool display = TRUE);
+ void OnDragLeft(bool draw, double x, double y, int keys, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys, int attachment = 0);
+
+ void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
+
+ // Don't want this kind of composite to resize its subdiagrams, so
+ // override composite's SetSize.
+ void SetSize(double w, double h, bool recursive = TRUE);
+
+ // Similarly for calculating size: it's fixed at whatever SetSize
+ // set it to, not in terms of children.
+ void CalculateSize();
+
+ void MakeControlPoints();
+ void ResetControlPoints();
+ void MakeMandatoryControlPoints();
+ void ResetMandatoryControlPoints();
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ // Divide horizontally (wxHORIZONTAL) or vertically (wxVERTICAL)
+ bool Divide(int direction);
+
+ // Resize adjoining divisions at the given side. If test is TRUE,
+ // just see whether it's possible for each adjoining region,
+ // returning FALSE if it's not.
+ bool ResizeAdjoining(int side, double newPos, bool test);
+
+ // Adjust a side, returning FALSE if it's not physically possible.
+ bool AdjustLeft(double left, bool test);
+ bool AdjustTop(double top, bool test);
+ bool AdjustRight(double right, bool test);
+ bool AdjustBottom(double bottom, bool test);
+
+ // Edit style of left or top side
+ void EditEdge(int side);
+
+ // Popup menu
+ void PopupMenu(double x, double y);
+
+ inline void SetLeftSide(wxDivisionShape *shape) { m_leftSide = shape; }
+ inline void SetTopSide(wxDivisionShape *shape) { m_topSide = shape; }
+ inline void SetRightSide(wxDivisionShape *shape) { m_rightSide = shape; }
+ inline void SetBottomSide(wxDivisionShape *shape) { m_bottomSide = shape; }
+ inline wxDivisionShape *GetLeftSide() const { return m_leftSide; }
+ inline wxDivisionShape *GetTopSide() const { return m_topSide; }
+ inline wxDivisionShape *GetRightSide() const { return m_rightSide; }
+ inline wxDivisionShape *GetBottomSide() const { return m_bottomSide; }
+
+ inline void SetHandleSide(int side) { m_handleSide = side; }
+ inline int GetHandleSide() const { return m_handleSide; }
+
+ inline void SetLeftSidePen(wxPen *pen) { m_leftSidePen = pen; }
+ inline wxPen *GetLeftSidePen() const { return m_leftSidePen; }
+ inline void SetTopSidePen(wxPen *pen) { m_topSidePen = pen; }
+ inline wxPen *GetTopSidePen() const { return m_topSidePen; }
+
+ void SetLeftSideColour(const wxString& colour);
+ void SetTopSideColour(const wxString& colour);
+ void SetLeftSideStyle(const wxString& style);
+ void SetTopSideStyle(const wxString& style);
+
+ inline wxString GetLeftSideColour() const { return m_leftSideColour; }
+ inline wxString GetTopSideColour() const { return m_topSideColour; }
+ inline wxString GetLeftSideStyle() const { return m_leftSideStyle; }
+ inline wxString GetTopSideStyle() const { return m_topSideStyle; }
+
+ protected:
+ // Adjoining divisions. NULL indicates edge
+ // of container, and that side shouldn't be
+ // drawn.
+ wxDivisionShape* m_leftSide;
+ wxDivisionShape* m_rightSide;
+ wxDivisionShape* m_topSide;
+ wxDivisionShape* m_bottomSide;
+
+ int m_handleSide; // Side at which handle is legal
+
+ wxPen* m_leftSidePen;
+ wxPen* m_topSidePen;
+ wxString m_leftSideColour;
+ wxString m_topSideColour;
+ wxString m_leftSideStyle;
+ wxString m_topSideStyle;
+};
+
+
+#define DIVISION_MENU_SPLIT_HORIZONTALLY 1
+#define DIVISION_MENU_SPLIT_VERTICALLY 2
+#define DIVISION_MENU_EDIT_LEFT_EDGE 3
+#define DIVISION_MENU_EDIT_TOP_EDGE 4
+#define DIVISION_MENU_EDIT_RIGHT_EDGE 5
+#define DIVISION_MENU_EDIT_BOTTOM_EDGE 6
+#define DIVISION_MENU_DELETE_ALL 7
+
+#endif
+ // _OGL_COMPOSIT_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: constrnt.cpp
+// Purpose: OGL Constraint classes
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "constrnt.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include "basic.h"
+#include "constrnt.h"
+#include "canvas.h"
+
+wxList *wxOGLConstraintTypes = NULL;
+
+/*
+ * Constraint type
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxOGLConstraintType, wxObject)
+
+wxOGLConstraintType::wxOGLConstraintType(int theType, const wxString& theName, const wxString& thePhrase)
+{
+ m_type = theType;
+ m_name = theName;
+ m_phrase = thePhrase;
+}
+
+wxOGLConstraintType::~wxOGLConstraintType()
+{
+}
+
+void OGLInitializeConstraintTypes()
+{
+ if (!wxOGLConstraintTypes)
+ return;
+
+ wxOGLConstraintTypes = new wxList(wxKEY_INTEGER);
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_VERTICALLY,
+ new wxOGLConstraintType(gyCONSTRAINT_CENTRED_VERTICALLY, "Centre vertically", "centred vertically w.r.t."));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_HORIZONTALLY,
+ new wxOGLConstraintType(gyCONSTRAINT_CENTRED_HORIZONTALLY, "Centre horizontally", "centred horizontally w.r.t."));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_CENTRED_BOTH,
+ new wxOGLConstraintType(gyCONSTRAINT_CENTRED_BOTH, "Centre", "centred w.r.t."));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_LEFT_OF,
+ new wxOGLConstraintType(gyCONSTRAINT_LEFT_OF, "Left of", "left of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_RIGHT_OF,
+ new wxOGLConstraintType(gyCONSTRAINT_RIGHT_OF, "Right of", "right of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_ABOVE,
+ new wxOGLConstraintType(gyCONSTRAINT_ABOVE, "Above", "above"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_BELOW,
+ new wxOGLConstraintType(gyCONSTRAINT_BELOW, "Below", "below"));
+
+ // Alignment
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_TOP,
+ new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_TOP, "Top-aligned", "aligned to the top of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_BOTTOM,
+ new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_BOTTOM, "Bottom-aligned", "aligned to the bottom of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_LEFT,
+ new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_LEFT, "Left-aligned", "aligned to the left of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_ALIGNED_RIGHT,
+ new wxOGLConstraintType(gyCONSTRAINT_ALIGNED_RIGHT, "Right-aligned", "aligned to the right of"));
+
+ // Mid-alignment
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_TOP,
+ new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_TOP, "Top-midaligned", "centred on the top of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_BOTTOM,
+ new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_BOTTOM, "Bottom-midaligned", "centred on the bottom of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_LEFT,
+ new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_LEFT, "Left-midaligned", "centred on the left of"));
+
+ wxOGLConstraintTypes->Append(gyCONSTRAINT_MIDALIGNED_RIGHT,
+ new wxOGLConstraintType(gyCONSTRAINT_MIDALIGNED_RIGHT, "Right-midaligned", "centred on the right of"));
+}
+
+void OGLCleanUpConstraintTypes()
+{
+ if (!wxOGLConstraintTypes)
+ return;
+
+ wxNode* node = wxOGLConstraintTypes->First();
+ while (node)
+ {
+ wxOGLConstraintType* ct = (wxOGLConstraintType*) node->Data();
+ delete ct;
+ node = node->Next();
+ }
+ delete wxOGLConstraintTypes;
+ wxOGLConstraintTypes = NULL;
+}
+
+/*
+ * Constraint Stuff
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxOGLConstraint, wxObject)
+
+wxOGLConstraint::wxOGLConstraint(int type, wxShape *constraining, wxList& constrained)
+{
+ m_xSpacing = 0.0;
+ m_ySpacing = 0.0;
+
+ m_constraintType = type;
+ m_constrainingObject = constraining;
+
+ m_constraintId = 0;
+ m_constraintName = "noname";
+
+ wxNode *node = constrained.First();
+ while (node)
+ {
+ m_constrainedObjects.Append(node->Data());
+ node = node->Next();
+ }
+}
+
+wxOGLConstraint::~wxOGLConstraint()
+{
+}
+
+bool wxOGLConstraint::Equals(double a, double b)
+{
+ double marg = 0.5;
+
+ bool eq = ((b <= a + marg) && (b >= a - marg));
+ return eq;
+}
+
+// Return TRUE if anything changed
+bool wxOGLConstraint::Evaluate()
+{
+ double maxWidth, maxHeight, minWidth, minHeight, x, y;
+ m_constrainingObject->GetBoundingBoxMax(&maxWidth, &maxHeight);
+ m_constrainingObject->GetBoundingBoxMin(&minWidth, &minHeight);
+ x = m_constrainingObject->GetX();
+ y = m_constrainingObject->GetY();
+
+ wxClientDC dc(m_constrainingObject->GetCanvas());
+ m_constrainingObject->GetCanvas()->PrepareDC(dc);
+
+ switch (m_constraintType)
+ {
+ case gyCONSTRAINT_CENTRED_VERTICALLY:
+ {
+ int n = m_constrainedObjects.Number();
+ double totalObjectHeight = 0.0;
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ totalObjectHeight += height2;
+ node = node->Next();
+ }
+ double startY;
+ double spacingY;
+ // Check if within the constraining object...
+ if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight)
+ {
+ spacingY = (double)((minHeight - totalObjectHeight)/(n + 1));
+ startY = (double)(y - (minHeight/2.0));
+ }
+ // Otherwise, use default spacing
+ else
+ {
+ spacingY = m_ySpacing;
+ startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0));
+ }
+
+ // Now position the objects
+ bool changed = FALSE;
+ node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ startY += (double)(spacingY + (height2/2.0));
+ if (!Equals(startY, constrainedObject->GetY()))
+ {
+ constrainedObject->Move(dc, constrainedObject->GetX(), startY, FALSE);
+ changed = TRUE;
+ }
+ startY += (double)(height2/2.0);
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_CENTRED_HORIZONTALLY:
+ {
+ int n = m_constrainedObjects.Number();
+ double totalObjectWidth = 0.0;
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ totalObjectWidth += width2;
+ node = node->Next();
+ }
+ double startX;
+ double spacingX;
+ // Check if within the constraining object...
+ if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth)
+ {
+ spacingX = (double)((minWidth - totalObjectWidth)/(n + 1));
+ startX = (double)(x - (minWidth/2.0));
+ }
+ // Otherwise, use default spacing
+ else
+ {
+ spacingX = m_xSpacing;
+ startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0));
+ }
+
+ // Now position the objects
+ bool changed = FALSE;
+ node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ startX += (double)(spacingX + (width2/2.0));
+ if (!Equals(startX, constrainedObject->GetX()))
+ {
+ constrainedObject->Move(dc, startX, constrainedObject->GetY(), FALSE);
+ changed = TRUE;
+ }
+ startX += (double)(width2/2.0);
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_CENTRED_BOTH:
+ {
+ int n = m_constrainedObjects.Number();
+ double totalObjectWidth = 0.0;
+ double totalObjectHeight = 0.0;
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ totalObjectWidth += width2;
+ totalObjectHeight += height2;
+ node = node->Next();
+ }
+ double startX;
+ double spacingX;
+ double startY;
+ double spacingY;
+
+ // Check if within the constraining object...
+ if ((totalObjectWidth + (n + 1)*m_xSpacing) <= minWidth)
+ {
+ spacingX = (double)((minWidth - totalObjectWidth)/(n + 1));
+ startX = (double)(x - (minWidth/2.0));
+ }
+ // Otherwise, use default spacing
+ else
+ {
+ spacingX = m_xSpacing;
+ startX = (double)(x - ((totalObjectWidth + (n+1)*spacingX)/2.0));
+ }
+
+ // Check if within the constraining object...
+ if ((totalObjectHeight + (n + 1)*m_ySpacing) <= minHeight)
+ {
+ spacingY = (double)((minHeight - totalObjectHeight)/(n + 1));
+ startY = (double)(y - (minHeight/2.0));
+ }
+ // Otherwise, use default spacing
+ else
+ {
+ spacingY = m_ySpacing;
+ startY = (double)(y - ((totalObjectHeight + (n+1)*spacingY)/2.0));
+ }
+
+ // Now position the objects
+ bool changed = FALSE;
+ node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+ startX += (double)(spacingX + (width2/2.0));
+ startY += (double)(spacingY + (height2/2.0));
+
+ if ((!Equals(startX, constrainedObject->GetX())) || (!Equals(startY, constrainedObject->GetY())))
+ {
+ constrainedObject->Move(dc, startX, startY, FALSE);
+ changed = TRUE;
+ }
+
+ startX += (double)(width2/2.0);
+ startY += (double)(height2/2.0);
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_LEFT_OF:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double x3 = (double)(x - (minWidth/2.0) - (width2/2.0) - m_xSpacing);
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_RIGHT_OF:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double x3 = (double)(x + (minWidth/2.0) + (width2/2.0) + m_xSpacing);
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+
+ return FALSE;
+ }
+ case gyCONSTRAINT_ABOVE:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double y3 = (double)(y - (minHeight/2.0) - (height2/2.0) - m_ySpacing);
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_BELOW:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double y3 = (double)(y + (minHeight/2.0) + (height2/2.0) + m_ySpacing);
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_ALIGNED_LEFT:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double x3 = (double)(x - (minWidth/2.0) + (width2/2.0) + m_xSpacing);
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_ALIGNED_RIGHT:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double x3 = (double)(x + (minWidth/2.0) - (width2/2.0) - m_xSpacing);
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+
+ return FALSE;
+ }
+ case gyCONSTRAINT_ALIGNED_TOP:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double y3 = (double)(y - (minHeight/2.0) + (height2/2.0) + m_ySpacing);
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_ALIGNED_BOTTOM:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double width2, height2;
+ constrainedObject->GetBoundingBoxMax(&width2, &height2);
+
+ double y3 = (double)(y + (minHeight/2.0) - (height2/2.0) - m_ySpacing);
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_MIDALIGNED_LEFT:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double x3 = (double)(x - (minWidth/2.0));
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_MIDALIGNED_RIGHT:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double x3 = (double)(x + (minWidth/2.0));
+ if (!Equals(x3, constrainedObject->GetX()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, x3, constrainedObject->GetY(), FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+
+ return FALSE;
+ }
+ case gyCONSTRAINT_MIDALIGNED_TOP:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double y3 = (double)(y - (minHeight/2.0));
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+ case gyCONSTRAINT_MIDALIGNED_BOTTOM:
+ {
+ bool changed = FALSE;
+
+ wxNode *node = m_constrainedObjects.First();
+ while (node)
+ {
+ wxShape *constrainedObject = (wxShape *)node->Data();
+
+ double y3 = (double)(y + (minHeight/2.0));
+ if (!Equals(y3, constrainedObject->GetY()))
+ {
+ changed = TRUE;
+ constrainedObject->Move(dc, constrainedObject->GetX(), y3, FALSE);
+ }
+
+ node = node->Next();
+ }
+ return changed;
+ }
+
+ default:
+ return FALSE;
+ }
+ return FALSE;
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: constrnt.h
+// Purpose: OGL constraint definitions
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_CONSTRNT_H_
+#define _OGL_CONSTRNT_H_
+
+#ifdef __GNUG__
+#pragma interface "constrnt.h"
+#endif
+
+/*
+ * OGL Constraints
+ *
+ */
+
+class wxOGLConstraintType: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxOGLConstraintType)
+public:
+ wxOGLConstraintType(int type = 0, const wxString& name = "", const wxString& phrase = "");
+ ~wxOGLConstraintType();
+
+public:
+ int m_type; // E.g. gyCONSTRAINT_CENTRED_VERTICALLY
+ wxString m_name; // E.g. "Centre vertically"
+ wxString m_phrase; // E.g. "centred vertically with respect to", "left of"
+
+};
+
+extern wxList* wxOGLConstraintTypes;
+
+#define gyCONSTRAINT_CENTRED_VERTICALLY 1
+#define gyCONSTRAINT_CENTRED_HORIZONTALLY 2
+#define gyCONSTRAINT_CENTRED_BOTH 3
+#define gyCONSTRAINT_LEFT_OF 4
+#define gyCONSTRAINT_RIGHT_OF 5
+#define gyCONSTRAINT_ABOVE 6
+#define gyCONSTRAINT_BELOW 7
+#define gyCONSTRAINT_ALIGNED_TOP 8
+#define gyCONSTRAINT_ALIGNED_BOTTOM 9
+#define gyCONSTRAINT_ALIGNED_LEFT 10
+#define gyCONSTRAINT_ALIGNED_RIGHT 11
+
+// Like aligned, but with the objects centred on the respective edge
+// of the reference object.
+#define gyCONSTRAINT_MIDALIGNED_TOP 12
+#define gyCONSTRAINT_MIDALIGNED_BOTTOM 13
+#define gyCONSTRAINT_MIDALIGNED_LEFT 14
+#define gyCONSTRAINT_MIDALIGNED_RIGHT 15
+
+class wxOGLConstraint: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxOGLConstraint)
+ public:
+ wxOGLConstraint() { m_xSpacing = 0.0; m_ySpacing = 0.0; m_constraintType = 0; m_constraintName = ""; m_constraintId = 0;
+ m_constrainingObject = NULL; }
+ wxOGLConstraint(int type, wxShape *constraining, wxList& constrained);
+ ~wxOGLConstraint();
+
+ // Returns TRUE if anything changed
+ bool Evaluate();
+ inline void SetSpacing(double x, double y) { m_xSpacing = x; m_ySpacing = y; };
+ bool Equals(double a, double b);
+
+ double m_xSpacing;
+ double m_ySpacing;
+ int m_constraintType;
+ wxString m_constraintName;
+ long m_constraintId;
+ wxShape* m_constrainingObject;
+ wxList m_constrainedObjects;
+
+};
+
+void OGLInitializeConstraintTypes();
+void OGLCleanUpConstraintTypes();
+
+#endif
+ // _OGL_CONSTRNT_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: divided.cpp
+// Purpose: wxDividedShape class
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "divided.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "canvas.h"
+#include "divided.h"
+#include "lines.h"
+#include "misc.h"
+
+class wxDividedShapeControlPoint: public wxControlPoint
+{
+ DECLARE_DYNAMIC_CLASS(wxDividedShapeControlPoint)
+ private:
+ int regionId;
+ public:
+ wxDividedShapeControlPoint() { regionId = 0; }
+ wxDividedShapeControlPoint(wxShapeCanvas *the_canvas, wxShape *object, int region,
+ double size, double the_xoffset, double the_yoffset, int the_type);
+ ~wxDividedShapeControlPoint();
+
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxDividedShapeControlPoint, wxControlPoint)
+
+/*
+ * Divided object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxDividedShape, wxRectangleShape)
+
+wxDividedShape::wxDividedShape(double w, double h): wxRectangleShape(w, h)
+{
+ ClearRegions();
+}
+
+wxDividedShape::~wxDividedShape()
+{
+}
+
+void wxDividedShape::OnDraw(wxDC& dc)
+{
+ wxRectangleShape::OnDraw(dc);
+}
+
+void wxDividedShape::OnDrawContents(wxDC& dc)
+{
+ double defaultProportion = (double)(GetRegions().Number() > 0 ? (1.0/((double)(GetRegions().Number()))) : 0.0);
+ double currentY = (double)(m_ypos - (m_height / 2.0));
+ double maxY = (double)(m_ypos + (m_height / 2.0));
+
+ double leftX = (double)(m_xpos - (m_width / 2.0));
+ double rightX = (double)(m_xpos + (m_width / 2.0));
+
+ if (m_pen) dc.SetPen(* m_pen);
+
+ if (m_textColour) dc.SetTextForeground(* m_textColour);
+
+#ifdef __WXMSW__
+ // For efficiency, don't do this under X - doesn't make
+ // any visible difference for our purposes.
+ if (m_brush)
+ dc.SetTextBackground(m_brush->GetColour());
+#endif
+/*
+ if (!formatted)
+ {
+ FormatRegionText();
+ formatted = TRUE;
+ }
+*/
+ if (GetDisableLabel()) return;
+
+ double xMargin = 2;
+ double yMargin = 2;
+ dc.SetBackgroundMode(wxTRANSPARENT);
+
+ wxNode *node = GetRegions().First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ dc.SetFont(* region->GetFont());
+ dc.SetTextForeground(* region->GetActualColourObject());
+
+ double proportion =
+ region->m_regionProportionY < 0.0 ? defaultProportion : region->m_regionProportionY;
+
+ double y = currentY + m_height*proportion;
+ double actualY = maxY < y ? maxY : y;
+
+ double centreX = m_xpos;
+ double centreY = (double)(currentY + (actualY - currentY)/2.0);
+
+ oglDrawFormattedText(dc, ®ion->m_formattedText,
+ (double)(centreX), (double)(centreY), (double)(m_width-2*xMargin), (double)(actualY - currentY - 2*yMargin),
+ region->m_formatMode);
+ if ((y <= maxY) && (node->Next()))
+ {
+ wxPen *regionPen = region->GetActualPen();
+ if (regionPen)
+ {
+ dc.SetPen(* regionPen);
+ dc.DrawLine(WXROUND(leftX), WXROUND(y), WXROUND(rightX), WXROUND(y));
+ }
+ }
+
+ currentY = actualY;
+
+ node = node->Next();
+ }
+}
+
+void wxDividedShape::SetSize(double w, double h, bool recursive)
+{
+ SetAttachmentSize(w, h);
+ m_width = w;
+ m_height = h;
+ SetRegionSizes();
+}
+
+void wxDividedShape::SetRegionSizes()
+{
+ if (GetRegions().Number() == 0)
+ return;
+
+ double defaultProportion = (double)(GetRegions().Number() > 0 ? (1.0/((double)(GetRegions().Number()))) : 0.0);
+ double currentY = (double)(m_ypos - (m_height / 2.0));
+ double maxY = (double)(m_ypos + (m_height / 2.0));
+
+// double leftX = (double)(m_xpos - (m_width / 2.0));
+// double rightX = (double)(m_xpos + (m_width / 2.0));
+
+ wxNode *node = GetRegions().First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ double proportion =
+ region->m_regionProportionY <= 0.0 ? defaultProportion : region->m_regionProportionY;
+
+ double sizeY = (double)proportion*m_height;
+ double y = currentY + sizeY;
+ double actualY = maxY < y ? maxY : y;
+
+ double centreY = (double)(currentY + (actualY - currentY)/2.0);
+
+ region->SetSize(m_width, sizeY);
+ region->SetPosition(0.0, (double)(centreY - m_ypos));
+ currentY = actualY;
+ node = node->Next();
+ }
+}
+
+// Attachment points correspond to regions in the divided box
+bool wxDividedShape::GetAttachmentPosition(int attachment, double *x, double *y, int nth, int no_arcs,
+ wxLineShape *line)
+{
+ int totalNumberAttachments = (GetRegions().Number() * 2) + 2;
+ if ((GetAttachmentMode() == ATTACHMENT_MODE_NONE) || (attachment >= totalNumberAttachments))
+ {
+ return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs);
+ }
+
+ int n = GetRegions().Number();
+ bool isEnd = (line && line->IsEnd(this));
+
+ double left = (double)(m_xpos - m_width/2.0);
+ double right = (double)(m_xpos + m_width/2.0);
+ double top = (double)(m_ypos - m_height/2.0);
+ double bottom = (double)(m_ypos + m_height/2.0);
+
+ // Zero is top, n+1 is bottom.
+ if (attachment == 0)
+ {
+ *y = top;
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->x < left)
+ *x = left;
+ else if (point->x > right)
+ *x = right;
+ else
+ *x = point->x;
+ }
+ else
+ *x = left + (nth + 1)*m_width/(no_arcs + 1);
+ }
+ else
+ *x = m_xpos;
+ }
+ else if (attachment == (n+1))
+ {
+ *y = bottom;
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->x < left)
+ *x = left;
+ else if (point->x > right)
+ *x = right;
+ else
+ *x = point->x;
+ }
+ else
+ *x = left + (nth + 1)*m_width/(no_arcs + 1);
+ }
+ else
+ *x = m_xpos;
+ }
+ // Left or right.
+ else
+ {
+ int i = 0;
+ bool isLeft = FALSE;
+ if (attachment < (n+1))
+ {
+ i = attachment-1;
+ isLeft = FALSE;
+ }
+ else
+ {
+ i = (totalNumberAttachments - attachment - 1);
+ isLeft = TRUE;
+ }
+ wxNode *node = GetRegions().Nth(i);
+ if (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+
+ if (isLeft)
+ *x = left;
+ else
+ *x = right;
+
+ // Calculate top and bottom of region
+ top = (double)((m_ypos + region->m_y) - (region->m_height/2.0));
+ bottom = (double)((m_ypos + region->m_y) + (region->m_height/2.0));
+
+ // Assuming we can trust the absolute size and
+ // position of these regions...
+ if (m_spaceAttachments)
+ {
+ if (line && (line->GetAlignmentType(isEnd) == LINE_ALIGNMENT_TO_NEXT_HANDLE))
+ {
+ // Align line according to the next handle along
+ wxRealPoint *point = line->GetNextControlPoint(this);
+ if (point->y < bottom)
+ *y = bottom;
+ else if (point->y > top)
+ *y = top;
+ else
+ *y = point->y;
+ }
+ else
+// *y = (double)(((m_ypos + region->m_y) - (region->m_height/2.0)) + (nth + 1)*region->m_height/(no_arcs+1));
+ *y = (double)(top + (nth + 1)*region->m_height/(no_arcs+1));
+ }
+ else
+ *y = (double)(m_ypos + region->m_y);
+ }
+ else
+ {
+ *x = m_xpos;
+ *y = m_ypos;
+ return FALSE;
+ }
+ }
+ return TRUE;
+}
+
+int wxDividedShape::GetNumberOfAttachments() const
+{
+ // There are two attachments for each region (left and right),
+ // plus one on the top and one on the bottom.
+ int n = (GetRegions().Number() * 2) + 2;
+
+ int maxN = n - 1;
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ if (point->m_id > maxN)
+ maxN = point->m_id;
+ node = node->Next();
+ }
+ return maxN + 1;
+}
+
+bool wxDividedShape::AttachmentIsValid(int attachment)
+{
+ int totalNumberAttachments = (GetRegions().Number() * 2) + 2;
+ if (attachment >= totalNumberAttachments)
+ {
+ return wxShape::AttachmentIsValid(attachment);
+ }
+ else if (attachment >= 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+void wxDividedShape::Copy(wxShape& copy)
+{
+ wxRectangleShape::Copy(copy);
+}
+
+// Region operations
+
+void wxDividedShape::MakeControlPoints()
+{
+ wxRectangleShape::MakeControlPoints();
+
+ MakeMandatoryControlPoints();
+}
+
+void wxDividedShape::MakeMandatoryControlPoints()
+{
+ double currentY = (double)(GetY() - (m_height / 2.0));
+ double maxY = (double)(GetY() + (m_height / 2.0));
+
+ wxNode *node = GetRegions().First();
+ int i = 0;
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+
+ double proportion = region->m_regionProportionY;
+
+ double y = currentY + m_height*proportion;
+ double actualY = (double)(maxY < y ? maxY : y);
+
+ if (node->Next())
+ {
+ wxDividedShapeControlPoint *controlPoint =
+ new wxDividedShapeControlPoint(m_canvas, this, i, CONTROL_POINT_SIZE, 0.0, (double)(actualY - GetY()), 0);
+ m_canvas->AddShape(controlPoint);
+ m_controlPoints.Append(controlPoint);
+ }
+ currentY = actualY;
+ i ++;
+ node = node->Next();
+ }
+}
+
+void wxDividedShape::ResetControlPoints()
+{
+ // May only have the region handles, (n - 1) of them.
+ if (m_controlPoints.Number() > (GetRegions().Number() - 1))
+ wxRectangleShape::ResetControlPoints();
+
+ ResetMandatoryControlPoints();
+}
+
+void wxDividedShape::ResetMandatoryControlPoints()
+{
+ double currentY = (double)(GetY() - (m_height / 2.0));
+ double maxY = (double)(GetY() + (m_height / 2.0));
+
+ wxNode *node = m_controlPoints.First();
+ int i = 0;
+ while (node)
+ {
+ wxControlPoint *controlPoint = (wxControlPoint *)node->Data();
+ if (controlPoint->IsKindOf(CLASSINFO(wxDividedShapeControlPoint)))
+ {
+ wxNode *node1 = GetRegions().Nth(i);
+ wxShapeRegion *region = (wxShapeRegion *)node1->Data();
+
+ double proportion = region->m_regionProportionY;
+
+ double y = currentY + m_height*proportion;
+ double actualY = (double)(maxY < y ? maxY : y);
+
+ controlPoint->m_xoffset = 0.0;
+ controlPoint->m_yoffset = (double)(actualY - GetY());
+ currentY = actualY;
+ i ++;
+ }
+ node = node->Next();
+ }
+}
+
+#ifdef PROLOGIO
+void wxDividedShape::WriteAttributes(wxExpr *clause)
+{
+ wxRectangleShape::WriteAttributes(clause);
+}
+
+void wxDividedShape::ReadAttributes(wxExpr *clause)
+{
+ wxRectangleShape::ReadAttributes(clause);
+}
+#endif
+
+/*
+ * Edit the division colour/style
+ *
+ */
+
+void wxDividedShape::EditRegions()
+{
+ wxMessageBox("EditRegions() is unimplemented.", "OGL", wxOK);
+
+ // TODO
+#if 0
+ if (GetRegions().Number() < 2)
+ return;
+
+ wxBeginBusyCursor();
+
+ GraphicsForm *form = new GraphicsForm("Divided nodes");
+ // Need an array to store all the style strings,
+ // since they need to be converted to integers
+ char **styleStrings = new char *[GetRegions().Number()];
+ for (int j = 0; j < GetRegions().Number(); j++)
+ styleStrings[j] = NULL;
+
+ int i = 0;
+ wxNode *node = GetRegions().First();
+ while (node && node->Next())
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ char buf[50];
+ sprintf(buf, "Region %d", (i+1));
+ form->Add(wxMakeFormMessage(buf));
+ form->Add(wxMakeFormNewLine());
+
+ form->Add(wxMakeFormString("Colour", ®ion->penColour, wxFORM_CHOICE,
+ new wxList(wxMakeConstraintStrings(
+ "Invisible" ,
+ "BLACK" ,
+ "BLUE" ,
+ "BROWN" ,
+ "CORAL" ,
+ "CYAN" ,
+ "DARK GREY" ,
+ "DARK GREEN" ,
+ "DIM GREY" ,
+ "GREY" ,
+ "GREEN" ,
+ "LIGHT BLUE" ,
+ "LIGHT GREY" ,
+ "MAGENTA" ,
+ "MAROON" ,
+ "NAVY" ,
+ "ORANGE" ,
+ "PURPLE" ,
+ "RED" ,
+ "TURQUOISE" ,
+ "VIOLET" ,
+ "WHITE" ,
+ "YELLOW" ,
+ NULL),
+ NULL), NULL, wxVERTICAL, 150));
+
+ char *styleString = NULL;
+ switch (region->penStyle)
+ {
+ case wxSHORT_DASH:
+ styleString = "Short Dash";
+ break;
+ case wxLONG_DASH:
+ styleString = "Long Dash";
+ break;
+ case wxDOT:
+ styleString = "Dot";
+ break;
+ case wxDOT_DASH:
+ styleString = "Dot Dash";
+ break;
+ case wxSOLID:
+ default:
+ styleString = "Solid";
+ break;
+ }
+ styleStrings[i] = copystring(styleString);
+ form->Add(wxMakeFormString("Style", &(styleStrings[i]), wxFORM_CHOICE,
+ new wxList(wxMakeConstraintStrings(
+ "Solid" ,
+ "Short Dash" ,
+ "Long Dash" ,
+ "Dot" ,
+ "Dot Dash" ,
+ NULL),
+ NULL), NULL, wxVERTICAL, 100));
+ node = node->Next();
+ i ++;
+ if (node && node->Next())
+ form->Add(wxMakeFormNewLine());
+ }
+ wxDialogBox *dialog = new wxDialogBox(m_canvas->GetParent(), "Divided object properties", 10, 10, 500, 500);
+ if (GraphicsLabelFont)
+ dialog->SetLabelFont(GraphicsLabelFont);
+ if (GraphicsButtonFont)
+ dialog->SetButtonFont(GraphicsButtonFont);
+ form->AssociatePanel(dialog);
+ form->dialog = dialog;
+
+ dialog->Fit();
+ dialog->Centre(wxBOTH);
+
+ wxEndBusyCursor();
+
+ dialog->Show(TRUE);
+
+ node = GetRegions().First();
+ i = 0;
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+
+ if (styleStrings[i])
+ {
+ if (strcmp(styleStrings[i], "Solid") == 0)
+ region->penStyle = wxSOLID;
+ else if (strcmp(styleStrings[i], "Dot") == 0)
+ region->penStyle = wxDOT;
+ else if (strcmp(styleStrings[i], "Short Dash") == 0)
+ region->penStyle = wxSHORT_DASH;
+ else if (strcmp(styleStrings[i], "Long Dash") == 0)
+ region->penStyle = wxLONG_DASH;
+ else if (strcmp(styleStrings[i], "Dot Dash") == 0)
+ region->penStyle = wxDOT_DASH;
+ delete[] styleStrings[i];
+ }
+ region->m_actualPenObject = NULL;
+ node = node->Next();
+ i ++;
+ }
+ delete[] styleStrings;
+ Draw(dc);
+#endif
+}
+
+void wxDividedShape::OnRightClick(double x, double y, int keys, int attachment)
+{
+ if (keys & KEY_CTRL)
+ {
+ EditRegions();
+ }
+ else
+ {
+ wxRectangleShape::OnRightClick(x, y, keys, attachment);
+ }
+}
+
+wxDividedShapeControlPoint::wxDividedShapeControlPoint(wxShapeCanvas *the_canvas, wxShape *object,
+ int region, double size, double the_m_xoffset, double the_m_yoffset, int the_type):
+ wxControlPoint(the_canvas, object, size, the_m_xoffset, the_m_yoffset, the_type)
+{
+ regionId = region;
+}
+
+wxDividedShapeControlPoint::~wxDividedShapeControlPoint()
+{
+}
+
+// Implement resizing of divided object division
+void wxDividedShapeControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
+ double x1 = (double)(dividedObject->GetX() - (dividedObject->GetWidth()/2.0));
+ double y1 = y;
+ double x2 = (double)(dividedObject->GetX() + (dividedObject->GetWidth()/2.0));
+ double y2 = y;
+ dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y2));
+}
+
+void wxDividedShapeControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
+ dc.SetLogicalFunction(OGLRBLF);
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ double x1 = (double)(dividedObject->GetX() - (dividedObject->GetWidth()/2.0));
+ double y1 = y;
+ double x2 = (double)(dividedObject->GetX() + (dividedObject->GetWidth()/2.0));
+ double y2 = y;
+ dc.DrawLine(WXROUND(x1), WXROUND(y1), WXROUND(x2), WXROUND(y2));
+ m_canvas->CaptureMouse();
+}
+
+void wxDividedShapeControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxDividedShape *dividedObject = (wxDividedShape *)m_shape;
+ wxNode *node = dividedObject->GetRegions().Nth(regionId);
+ if (!node)
+ return;
+
+ wxShapeRegion *thisRegion = (wxShapeRegion *)node->Data();
+ wxShapeRegion *nextRegion = NULL; // Region below this one
+
+ dc.SetLogicalFunction(wxCOPY);
+
+ m_canvas->ReleaseMouse();
+
+ // Find the old top and bottom of this region,
+ // and calculate the new proportion for this region
+ // if legal.
+
+ double currentY = (double)(dividedObject->GetY() - (dividedObject->GetHeight() / 2.0));
+ double maxY = (double)(dividedObject->GetY() + (dividedObject->GetHeight() / 2.0));
+
+ // Save values
+ double thisRegionTop = 0.0;
+ double thisRegionBottom = 0.0;
+ double nextRegionBottom = 0.0;
+
+ node = dividedObject->GetRegions().First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+
+ double proportion = region->m_regionProportionY;
+ double yy = currentY + (dividedObject->GetHeight()*proportion);
+ double actualY = (double)(maxY < yy ? maxY : yy);
+
+ if (region == thisRegion)
+ {
+ thisRegionTop = currentY;
+ thisRegionBottom = actualY;
+ if (node->Next())
+ nextRegion = (wxShapeRegion *)node->Next()->Data();
+ }
+ if (region == nextRegion)
+ {
+ nextRegionBottom = actualY;
+ }
+
+ currentY = actualY;
+ node = node->Next();
+ }
+ if (!nextRegion)
+ return;
+
+ // Check that we haven't gone above this region or below
+ // next region.
+ if ((y <= thisRegionTop) || (y >= nextRegionBottom))
+ return;
+
+ dividedObject->EraseLinks(dc);
+
+ // Now calculate the new proportions of this region and the next region.
+ double thisProportion = (double)((y - thisRegionTop)/dividedObject->GetHeight());
+ double nextProportion = (double)((nextRegionBottom - y)/dividedObject->GetHeight());
+ thisRegion->SetProportions(0.0, thisProportion);
+ nextRegion->SetProportions(0.0, nextProportion);
+ m_yoffset = (double)(y - dividedObject->GetY());
+
+ // Now reformat text
+ int i = 0;
+ node = dividedObject->GetRegions().First();
+ while (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ if (region->GetText())
+ {
+ char *s = copystring(region->GetText());
+ dividedObject->FormatText(dc, s, i);
+ delete[] s;
+ }
+ node = node->Next();
+ i++;
+ }
+ dividedObject->SetRegionSizes();
+ dividedObject->Draw(dc);
+ dividedObject->GetEventHandler()->OnMoveLinks(dc);
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: divided.h
+// Purpose: wxDividedShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_DIVIDED_H_
+#define _OGL_DIVIDED_H_
+
+#ifdef __GNUG__
+#pragma interface "basic.h"
+#endif
+
+/*
+ * Definition of a region
+ *
+ */
+
+/*
+ * Box divided into horizontal regions
+ *
+ */
+
+extern wxFont *g_oglNormalFont;
+class wxDividedShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxDividedShape)
+
+ public:
+ wxDividedShape(double w = 0.0, double h = 0.0);
+ ~wxDividedShape();
+
+ void OnDraw(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+
+ void SetSize(double w, double h, bool recursive = TRUE);
+
+ void MakeControlPoints();
+ void ResetControlPoints();
+
+ void MakeMandatoryControlPoints();
+ void ResetMandatoryControlPoints();
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ void Copy(wxShape ©);
+
+ // Set all region sizes according to proportions and
+ // this object total size
+ void SetRegionSizes();
+
+ // Edit region colours/styles
+ void EditRegions();
+
+ // Attachment points correspond to regions in the divided box
+ bool GetAttachmentPosition(int attachment, double *x, double *y,
+ int nth = 0, int no_arcs = 1, wxLineShape *line = NULL);
+ bool AttachmentIsValid(int attachment);
+ int GetNumberOfAttachments() const;
+
+ // Invoke editor on CTRL-right click
+ void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
+};
+
+#endif
+ // _OGL_DIVIDED_H_
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: drawn.cpp
+// Purpose: wxDrawnShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "drawn.h"
+#pragma implementation "drawnp.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "canvas.h"
+#include "mfutils.h"
+#include "drawn.h"
+#include "drawnp.h"
+#include "misc.h"
+
+static void IntToHex(unsigned int dec, char *buf);
+static unsigned long HexToInt(char *buf);
+extern char *oglBuffer;
+
+#define gyTYPE_PEN 40
+#define gyTYPE_BRUSH 41
+#define gyTYPE_FONT 42
+
+/*
+ * Drawn object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape, wxRectangleShape)
+
+wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
+{
+ m_saveToFile = TRUE;
+ m_currentAngle = oglDRAWN_ANGLE_0;
+}
+
+wxDrawnShape::~wxDrawnShape()
+{
+}
+
+void wxDrawnShape::OnDraw(wxDC& dc)
+{
+ // Pass pen and brush in case we have force outline
+ // and fill colours
+ if (m_shadowMode != SHADOW_NONE)
+ {
+ if (m_shadowBrush)
+ m_metafiles[m_currentAngle].m_fillBrush = m_shadowBrush;
+ m_metafiles[m_currentAngle].m_outlinePen = g_oglTransparentPen;
+ m_metafiles[m_currentAngle].Draw(dc, m_xpos + m_shadowOffsetX, m_ypos + m_shadowOffsetY);
+ }
+
+ m_metafiles[m_currentAngle].m_outlinePen = m_pen;
+ m_metafiles[m_currentAngle].m_fillBrush = m_brush;
+ m_metafiles[m_currentAngle].Draw(dc, m_xpos, m_ypos);
+}
+
+void wxDrawnShape::SetSize(double w, double h, bool recursive)
+{
+ SetAttachmentSize(w, h);
+
+ double scaleX;
+ double scaleY;
+ if (GetWidth() == 0.0)
+ scaleX = 1.0;
+ else scaleX = w/GetWidth();
+ if (GetHeight() == 0.0)
+ scaleY = 1.0;
+ else scaleY = h/GetHeight();
+
+ int i = 0;
+ for (i = 0; i < 4; i++)
+ {
+ if (m_metafiles[i].IsValid())
+ m_metafiles[i].Scale(scaleX, scaleY);
+ }
+ m_width = w;
+ m_height = h;
+ SetDefaultRegionSize();
+}
+
+void wxDrawnShape::Scale(double sx, double sy)
+{
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ if (m_metafiles[i].IsValid())
+ {
+ m_metafiles[i].Scale(sx, sy);
+ m_metafiles[i].CalculateSize(this);
+ }
+ }
+}
+
+void wxDrawnShape::Translate(double x, double y)
+{
+ int i;
+ for (i = 0; i < 4; i++)
+ {
+ if (m_metafiles[i].IsValid())
+ {
+ m_metafiles[i].Translate(x, y);
+ m_metafiles[i].CalculateSize(this);
+ }
+ }
+}
+
+// theta is absolute rotation from the zero position
+void wxDrawnShape::Rotate(double x, double y, double theta)
+{
+ m_currentAngle = DetermineMetaFile(theta);
+
+ if (m_currentAngle == 0)
+ {
+ // Rotate metafile
+ if (!m_metafiles[0].GetRotateable())
+ return;
+
+ m_metafiles[0].Rotate(x, y, theta);
+ }
+
+ double actualTheta = theta-m_rotation;
+
+ // Rotate attachment points
+ double sinTheta = (double)sin(actualTheta);
+ double cosTheta = (double)cos(actualTheta);
+ wxNode *node = m_attachmentPoints.First();
+ while (node)
+ {
+ wxAttachmentPoint *point = (wxAttachmentPoint *)node->Data();
+ double x1 = point->m_x;
+ double y1 = point->m_y;
+ point->m_x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ point->m_y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ node = node->Next();
+ }
+ m_rotation = theta;
+
+ m_metafiles[m_currentAngle].CalculateSize(this);
+}
+
+// Which metafile do we use now? Based on current rotation and validity
+// of metafiles.
+
+int wxDrawnShape::DetermineMetaFile(double rotation)
+{
+ double tolerance = 0.0001;
+ const double pi = 3.1415926535897932384626433832795 ;
+ double angle1 = 0.0;
+ double angle2 = pi/2.0;
+ double angle3 = pi;
+ double angle4 = 3.0*pi/2.0;
+
+ int whichMetafile = 0;
+
+ if (oglRoughlyEqual(rotation, angle1, tolerance))
+ {
+ whichMetafile = 0;
+ }
+ else if (oglRoughlyEqual(rotation, angle2, tolerance))
+ {
+ whichMetafile = 1;
+ }
+ else if (oglRoughlyEqual(rotation, angle3, tolerance))
+ {
+ whichMetafile = 2;
+ }
+ else if (oglRoughlyEqual(rotation, angle4, tolerance))
+ {
+ whichMetafile = 3;
+ }
+
+ if ((whichMetafile > 0) && !m_metafiles[whichMetafile].IsValid())
+ whichMetafile = 0;
+
+ return whichMetafile;
+}
+
+void wxDrawnShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
+{
+ if (m_metafiles[m_currentAngle].GetOutlineOp() != -1)
+ {
+ wxNode* node = m_metafiles[m_currentAngle].GetOps().Nth(m_metafiles[m_currentAngle].GetOutlineOp());
+ wxASSERT (node != NULL);
+ wxDrawOp* op = (wxDrawOp*) node->Data();
+
+ if (op->OnDrawOutline(dc, x, y, w, h, m_width, m_height))
+ return;
+ }
+
+ // Default... just use a rectangle
+ wxRectangleShape::OnDrawOutline(dc, x, y, w, h);
+}
+
+// Get the perimeter point using the special outline op, if there is one,
+// otherwise use default wxRectangleShape scheme
+bool wxDrawnShape::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3)
+{
+ if (m_metafiles[m_currentAngle].GetOutlineOp() != -1)
+ {
+ wxNode* node = m_metafiles[m_currentAngle].GetOps().Nth(m_metafiles[m_currentAngle].GetOutlineOp());
+ wxASSERT (node != NULL);
+ wxDrawOp* op = (wxDrawOp*) node->Data();
+
+ if (op->GetPerimeterPoint(x1, y1, x2, y2, x3, y3, GetX(), GetY(), GetAttachmentMode()))
+ return TRUE;
+ }
+
+ // Default... just use a rectangle
+ return wxRectangleShape::GetPerimeterPoint(x1, y1, x2, y2, x3, y3);
+}
+
+#ifdef PROLOGIO
+void wxDrawnShape::WriteAttributes(wxExpr *clause)
+{
+ wxRectangleShape::WriteAttributes(clause);
+
+ clause->AddAttributeValue("current_angle", (long)m_currentAngle);
+ clause->AddAttributeValue("save_metafile", (long)m_saveToFile);
+ if (m_saveToFile)
+ {
+ int i = 0;
+ for (i = 0; i < 4; i++)
+ {
+ if (m_metafiles[i].IsValid())
+ m_metafiles[i].WriteAttributes(clause, i);
+ }
+ }
+}
+
+void wxDrawnShape::ReadAttributes(wxExpr *clause)
+{
+ wxRectangleShape::ReadAttributes(clause);
+
+ int iVal = (int) m_saveToFile;
+ clause->GetAttributeValue("save_metafile", iVal);
+ clause->GetAttributeValue("current_angle", m_currentAngle);
+ m_saveToFile = (iVal != 0);
+
+ if (m_saveToFile)
+ {
+ int i = 0;
+ for (i = 0; i < 4; i++)
+ {
+ m_metafiles[i].ReadAttributes(clause, i);
+ }
+ }
+}
+#endif
+
+// Does the copying for this object
+void wxDrawnShape::Copy(wxShape& copy)
+{
+ wxRectangleShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxDrawnShape)) ) ;
+
+ wxDrawnShape& drawnCopy = (wxDrawnShape&) copy;
+
+ int i = 0;
+ for (i = 0; i < 4; i++)
+ {
+ m_metafiles[i].Copy(drawnCopy.m_metafiles[i]);
+ }
+ drawnCopy.m_saveToFile = m_saveToFile;
+ drawnCopy.m_currentAngle = m_currentAngle;
+}
+
+bool wxDrawnShape::LoadFromMetaFile(char *filename)
+{
+ return m_metafiles[0].LoadFromMetaFile(filename, &m_width, &m_height);
+}
+
+// Set of functions for drawing into a pseudo metafile.
+// They use integers, but doubles are used internally for accuracy
+// when scaling.
+
+void wxDrawnShape::DrawLine(const wxPoint& pt1, const wxPoint& pt2)
+{
+ m_metafiles[m_currentAngle].DrawLine(pt1, pt2);
+}
+
+void wxDrawnShape::DrawRectangle(const wxRect& rect)
+{
+ m_metafiles[m_currentAngle].DrawRectangle(rect);
+}
+
+void wxDrawnShape::DrawRoundedRectangle(const wxRect& rect, double radius)
+{
+ m_metafiles[m_currentAngle].DrawRoundedRectangle(rect, radius);
+}
+
+void wxDrawnShape::DrawEllipse(const wxRect& rect)
+{
+ m_metafiles[m_currentAngle].DrawEllipse(rect);
+}
+
+void wxDrawnShape::DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt)
+{
+ m_metafiles[m_currentAngle].DrawArc(centrePt, startPt, endPt);
+}
+
+void wxDrawnShape::DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle)
+{
+ m_metafiles[m_currentAngle].DrawEllipticArc(rect, startAngle, endAngle);
+}
+
+void wxDrawnShape::DrawPoint(const wxPoint& pt)
+{
+ m_metafiles[m_currentAngle].DrawPoint(pt);
+}
+
+void wxDrawnShape::DrawText(const wxString& text, const wxPoint& pt)
+{
+ m_metafiles[m_currentAngle].DrawText(text, pt);
+}
+
+void wxDrawnShape::DrawLines(int n, wxPoint pts[])
+{
+ m_metafiles[m_currentAngle].DrawLines(n, pts);
+}
+
+void wxDrawnShape::DrawPolygon(int n, wxPoint pts[], int flags)
+{
+ if (flags & oglMETAFLAGS_ATTACHMENTS)
+ {
+ ClearAttachments();
+ int i;
+ for (i = 0; i < n; i++)
+ m_attachmentPoints.Append(new wxAttachmentPoint(i, pts[i].x, pts[i].y));
+ }
+ m_metafiles[m_currentAngle].DrawPolygon(n, pts, flags);
+}
+
+void wxDrawnShape::DrawSpline(int n, wxPoint pts[])
+{
+ m_metafiles[m_currentAngle].DrawSpline(n, pts);
+}
+
+void wxDrawnShape::SetClippingRect(const wxRect& rect)
+{
+ m_metafiles[m_currentAngle].SetClippingRect(rect);
+}
+
+void wxDrawnShape::DestroyClippingRect()
+{
+ m_metafiles[m_currentAngle].DestroyClippingRect();
+}
+
+void wxDrawnShape::SetDrawnPen(wxPen* pen, bool isOutline)
+{
+ m_metafiles[m_currentAngle].SetPen(pen, isOutline);
+}
+
+void wxDrawnShape::SetDrawnBrush(wxBrush* brush, bool isFill)
+{
+ m_metafiles[m_currentAngle].SetBrush(brush, isFill);
+}
+
+void wxDrawnShape::SetDrawnFont(wxFont* font)
+{
+ m_metafiles[m_currentAngle].SetFont(font);
+}
+
+void wxDrawnShape::SetDrawnTextColour(const wxColour& colour)
+{
+ m_metafiles[m_currentAngle].SetTextColour(colour);
+}
+
+void wxDrawnShape::SetDrawnBackgroundColour(const wxColour& colour)
+{
+ m_metafiles[m_currentAngle].SetBackgroundColour(colour);
+}
+
+void wxDrawnShape::SetDrawnBackgroundMode(int mode)
+{
+ m_metafiles[m_currentAngle].SetBackgroundMode(mode);
+}
+
+
+/*
+ * Individual operations
+ *
+ */
+
+/*
+ * Set font, brush, text colour
+ *
+ */
+
+wxOpSetGDI::wxOpSetGDI(int theOp, wxPseudoMetaFile *theImage, int theGdiIndex, int theMode):
+ wxDrawOp(theOp)
+{
+ m_gdiIndex = theGdiIndex;
+ m_image = theImage;
+ m_mode = theMode;
+}
+
+void wxOpSetGDI::Do(wxDC& dc, double xoffset, double yoffset)
+{
+ switch (m_op)
+ {
+ case DRAWOP_SET_PEN:
+ {
+ // Check for overriding this operation for outline
+ // colour
+ if (m_image->m_outlineColours.Member((wxObject *)m_gdiIndex))
+ {
+ if (m_image->m_outlinePen)
+ dc.SetPen(* m_image->m_outlinePen);
+ }
+ else
+ {
+ wxNode *node = m_image->m_gdiObjects.Nth(m_gdiIndex);
+ if (node)
+ {
+ wxPen *pen = (wxPen *)node->Data();
+ if (pen)
+ dc.SetPen(* pen);
+ }
+ }
+ break;
+ }
+ case DRAWOP_SET_BRUSH:
+ {
+ // Check for overriding this operation for outline or fill
+ // colour
+ if (m_image->m_outlineColours.Member((wxObject *)m_gdiIndex))
+ {
+ // Need to construct a brush to match the outline pen's colour
+ if (m_image->m_outlinePen)
+ {
+ wxBrush *br = wxTheBrushList->FindOrCreateBrush(m_image->m_outlinePen->GetColour(), wxSOLID);
+ if (br)
+ dc.SetBrush(* br);
+ }
+ }
+ else if (m_image->m_fillColours.Member((wxObject *)m_gdiIndex))
+ {
+ if (m_image->m_fillBrush)
+ {
+ dc.SetBrush(* m_image->m_fillBrush);
+ }
+ }
+ else
+ {
+ wxNode *node = m_image->m_gdiObjects.Nth(m_gdiIndex);
+ if (node)
+ {
+ wxBrush *brush = (wxBrush *)node->Data();
+ if (brush)
+ dc.SetBrush(* brush);
+ }
+ }
+ break;
+ }
+ case DRAWOP_SET_FONT:
+ {
+ wxNode *node = m_image->m_gdiObjects.Nth(m_gdiIndex);
+ if (node)
+ {
+ wxFont *font = (wxFont *)node->Data();
+ if (font)
+ dc.SetFont(* font);
+ }
+ break;
+ }
+ case DRAWOP_SET_TEXT_COLOUR:
+ {
+ wxColour col(m_r,m_g,m_b);
+ dc.SetTextForeground(col);
+ break;
+ }
+ case DRAWOP_SET_BK_COLOUR:
+ {
+ wxColour col(m_r,m_g,m_b);
+ dc.SetTextBackground(col);
+ break;
+ }
+ case DRAWOP_SET_BK_MODE:
+ {
+ dc.SetBackgroundMode(m_mode);
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+wxDrawOp *wxOpSetGDI::Copy(wxPseudoMetaFile *newImage)
+{
+ wxOpSetGDI *newOp = new wxOpSetGDI(m_op, newImage, m_gdiIndex, m_mode);
+ newOp->m_r = m_r;
+ newOp->m_g = m_g;
+ newOp->m_b = m_b;
+ return newOp;
+}
+
+wxExpr *wxOpSetGDI::WriteExpr(wxPseudoMetaFile *image)
+{
+ wxExpr *expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)m_op));
+ switch (m_op)
+ {
+ case DRAWOP_SET_PEN:
+ case DRAWOP_SET_BRUSH:
+ case DRAWOP_SET_FONT:
+ {
+ expr->Append(new wxExpr((long)m_gdiIndex));
+ break;
+ }
+ case DRAWOP_SET_TEXT_COLOUR:
+ case DRAWOP_SET_BK_COLOUR:
+ {
+ expr->Append(new wxExpr((long)m_r));
+ expr->Append(new wxExpr((long)m_g));
+ expr->Append(new wxExpr((long)m_b));
+ break;
+ }
+ case DRAWOP_SET_BK_MODE:
+ {
+ expr->Append(new wxExpr((long)m_mode));
+ break;
+ }
+ default:
+ break;
+ }
+ return expr;
+}
+
+void wxOpSetGDI::ReadExpr(wxPseudoMetaFile *image, wxExpr *expr)
+{
+ switch (m_op)
+ {
+ case DRAWOP_SET_PEN:
+ case DRAWOP_SET_BRUSH:
+ case DRAWOP_SET_FONT:
+ {
+ m_gdiIndex = (int)expr->Nth(1)->IntegerValue();
+ break;
+ }
+ case DRAWOP_SET_TEXT_COLOUR:
+ case DRAWOP_SET_BK_COLOUR:
+ {
+ m_r = (unsigned char)expr->Nth(1)->IntegerValue();
+ m_g = (unsigned char)expr->Nth(2)->IntegerValue();
+ m_b = (unsigned char)expr->Nth(3)->IntegerValue();
+ break;
+ }
+ case DRAWOP_SET_BK_MODE:
+ {
+ m_mode = (int)expr->Nth(1)->IntegerValue();
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+/*
+ * Set/destroy clipping
+ *
+ */
+
+wxOpSetClipping::wxOpSetClipping(int theOp, double theX1, double theY1,
+ double theX2, double theY2):wxDrawOp(theOp)
+{
+ m_x1 = theX1;
+ m_y1 = theY1;
+ m_x2 = theX2;
+ m_y2 = theY2;
+}
+
+wxDrawOp *wxOpSetClipping::Copy(wxPseudoMetaFile *newImage)
+{
+ wxOpSetClipping *newOp = new wxOpSetClipping(m_op, m_x1, m_y1, m_x2, m_y2);
+ return newOp;
+}
+
+void wxOpSetClipping::Do(wxDC& dc, double xoffset, double yoffset)
+{
+ switch (m_op)
+ {
+ case DRAWOP_SET_CLIPPING_RECT:
+ {
+ dc.SetClippingRegion((long)(m_x1 + xoffset), (long)(m_y1 + yoffset), (long)(m_x2 + xoffset), (long)(m_y2 + yoffset));
+ break;
+ }
+ case DRAWOP_DESTROY_CLIPPING_RECT:
+ {
+ dc.DestroyClippingRegion();
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void wxOpSetClipping::Scale(double xScale, double yScale)
+{
+ m_x1 *= xScale;
+ m_y1 *= yScale;
+ m_x2 *= xScale;
+ m_y2 *= yScale;
+}
+
+void wxOpSetClipping::Translate(double x, double y)
+{
+ m_x1 += x;
+ m_y1 += y;
+}
+
+wxExpr *wxOpSetClipping::WriteExpr(wxPseudoMetaFile *image)
+{
+ wxExpr *expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)m_op));
+ switch (m_op)
+ {
+ case DRAWOP_SET_CLIPPING_RECT:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ expr->Append(new wxExpr(m_x2));
+ expr->Append(new wxExpr(m_y2));
+ break;
+ }
+ default:
+ break;
+ }
+ return expr;
+}
+
+void wxOpSetClipping::ReadExpr(wxPseudoMetaFile *image, wxExpr *expr)
+{
+ switch (m_op)
+ {
+ case DRAWOP_SET_CLIPPING_RECT:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ m_x2 = expr->Nth(3)->RealValue();
+ m_y2 = expr->Nth(4)->RealValue();
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+/*
+ * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
+ *
+ */
+
+wxOpDraw::wxOpDraw(int theOp, double theX1, double theY1, double theX2, double theY2,
+ double theRadius, char *s):wxDrawOp(theOp)
+{
+ m_x1 = theX1;
+ m_y1 = theY1;
+ m_x2 = theX2;
+ m_y2 = theY2;
+ m_x3 = 0.0;
+ m_y3 = 0.0;
+ m_radius = theRadius;
+ if (s) m_textString = copystring(s);
+ else m_textString = NULL;
+}
+
+wxOpDraw::~wxOpDraw()
+{
+ if (m_textString) delete[] m_textString;
+}
+
+wxDrawOp *wxOpDraw::Copy(wxPseudoMetaFile *newImage)
+{
+ wxOpDraw *newOp = new wxOpDraw(m_op, m_x1, m_y1, m_x2, m_y2, m_radius, m_textString);
+ newOp->m_x3 = m_x3;
+ newOp->m_y3 = m_y3;
+ return newOp;
+}
+
+void wxOpDraw::Do(wxDC& dc, double xoffset, double yoffset)
+{
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_LINE:
+ {
+ dc.DrawLine(WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset), WXROUND(m_x2+xoffset), WXROUND(m_y2+yoffset));
+ break;
+ }
+ case DRAWOP_DRAW_RECT:
+ {
+ dc.DrawRectangle(WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset), WXROUND(m_x2), WXROUND(m_y2));
+ break;
+ }
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ {
+ dc.DrawRoundedRectangle(WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset), WXROUND(m_x2), WXROUND(m_y2), m_radius);
+ break;
+ }
+ case DRAWOP_DRAW_ELLIPSE:
+ {
+ dc.DrawEllipse(WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset), WXROUND(m_x2), WXROUND(m_y2));
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ {
+ dc.DrawArc(WXROUND(m_x2+xoffset), WXROUND(m_y2+yoffset),
+ WXROUND(m_x3+xoffset), WXROUND(m_y3+yoffset),
+ WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset));
+ break;
+ }
+ case DRAWOP_DRAW_ELLIPTIC_ARC:
+ {
+ const double pi = 3.1415926535897932384626433832795 ;
+
+ // Convert back to degrees
+ dc.DrawEllipticArc(
+ WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset),
+ WXROUND(m_x2), WXROUND(m_y2),
+ WXROUND(m_x3*(360.0/(2.0*pi))), WXROUND(m_y3*(360.0/(2.0*pi))));
+ break;
+ }
+ case DRAWOP_DRAW_POINT:
+ {
+ dc.DrawPoint(WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset));
+ break;
+ }
+ case DRAWOP_DRAW_TEXT:
+ {
+ dc.DrawText(m_textString, WXROUND(m_x1+xoffset), WXROUND(m_y1+yoffset));
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void wxOpDraw::Scale(double scaleX, double scaleY)
+{
+ m_x1 *= scaleX;
+ m_y1 *= scaleY;
+ m_x2 *= scaleX;
+ m_y2 *= scaleY;
+
+ if (m_op != DRAWOP_DRAW_ELLIPTIC_ARC)
+ {
+ m_x3 *= scaleX;
+ m_y3 *= scaleY;
+ }
+
+ m_radius *= scaleX;
+}
+
+void wxOpDraw::Translate(double x, double y)
+{
+ m_x1 += x;
+ m_y1 += y;
+
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_LINE:
+ {
+ m_x2 += x;
+ m_y2 += y;
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ {
+ m_x2 += x;
+ m_y2 += y;
+ m_x3 += x;
+ m_y3 += y;
+ break;
+ }
+ case DRAWOP_DRAW_ELLIPTIC_ARC:
+ {
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void wxOpDraw::Rotate(double x, double y, double theta, double sinTheta, double cosTheta)
+{
+ double newX1 = m_x1*cosTheta - m_y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ double newY1 = m_x1*sinTheta + m_y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_LINE:
+ {
+ double newX2 = m_x2*cosTheta - m_y2*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ double newY2 = m_x2*sinTheta + m_y2*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+
+ m_x1 = newX1;
+ m_y1 = newY1;
+ m_x2 = newX2;
+ m_y2 = newY2;
+ break;
+ }
+ case DRAWOP_DRAW_RECT:
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ case DRAWOP_DRAW_ELLIPTIC_ARC:
+ {
+ // Assume only 0, 90, 180, 270 degree rotations.
+ // oldX1, oldY1 represents the top left corner. Find the
+ // bottom right, and rotate that. Then the width/height is the difference
+ // between x/y values.
+ double oldBottomRightX = m_x1 + m_x2;
+ double oldBottomRightY = m_y1 + m_y2;
+ double newBottomRightX = oldBottomRightX*cosTheta - oldBottomRightY*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ double newBottomRightY = oldBottomRightX*sinTheta + oldBottomRightY*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+
+ // Now find the new top-left, bottom-right coordinates.
+ double minX = wxMin(newX1, newBottomRightX);
+ double minY = wxMin(newY1, newBottomRightY);
+ double maxX = wxMax(newX1, newBottomRightX);
+ double maxY = wxMax(newY1, newBottomRightY);
+
+ m_x1 = minX;
+ m_y1 = minY;
+ m_x2 = maxX - minX; // width
+ m_y2 = maxY - minY; // height
+
+ if (m_op == DRAWOP_DRAW_ELLIPTIC_ARC)
+ {
+ // Add rotation to angles
+ m_x3 += theta;
+ m_y3 += theta;
+ }
+
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ {
+ double newX2 = m_x2*cosTheta - m_y2*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ double newY2 = m_x2*sinTheta + m_y2*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ double newX3 = m_x3*cosTheta - m_y3*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ double newY3 = m_x3*sinTheta + m_y3*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+
+ m_x1 = newX1;
+ m_y1 = newY1;
+ m_x2 = newX2;
+ m_y2 = newY2;
+ m_x3 = newX3;
+ m_y3 = newY3;
+
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+wxExpr *wxOpDraw::WriteExpr(wxPseudoMetaFile *image)
+{
+ wxExpr *expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)m_op));
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_LINE:
+ case DRAWOP_DRAW_RECT:
+ case DRAWOP_DRAW_ELLIPSE:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ expr->Append(new wxExpr(m_x2));
+ expr->Append(new wxExpr(m_y2));
+ break;
+ }
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ expr->Append(new wxExpr(m_x2));
+ expr->Append(new wxExpr(m_y2));
+ expr->Append(new wxExpr(m_radius));
+ break;
+ }
+ case DRAWOP_DRAW_POINT:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ break;
+ }
+ case DRAWOP_DRAW_TEXT:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ expr->Append(new wxExpr(wxExprString, m_textString));
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ case DRAWOP_DRAW_ELLIPTIC_ARC:
+ {
+ expr->Append(new wxExpr(m_x1));
+ expr->Append(new wxExpr(m_y1));
+ expr->Append(new wxExpr(m_x2));
+ expr->Append(new wxExpr(m_y2));
+ expr->Append(new wxExpr(m_x3));
+ expr->Append(new wxExpr(m_y3));
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ return expr;
+}
+
+void wxOpDraw::ReadExpr(wxPseudoMetaFile *image, wxExpr *expr)
+{
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_LINE:
+ case DRAWOP_DRAW_RECT:
+ case DRAWOP_DRAW_ELLIPSE:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ m_x2 = expr->Nth(3)->RealValue();
+ m_y2 = expr->Nth(4)->RealValue();
+ break;
+ }
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ m_x2 = expr->Nth(3)->RealValue();
+ m_y2 = expr->Nth(4)->RealValue();
+ m_radius = expr->Nth(5)->RealValue();
+ break;
+ }
+ case DRAWOP_DRAW_POINT:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ break;
+ }
+ case DRAWOP_DRAW_TEXT:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ wxString str(expr->Nth(3)->StringValue());
+ m_textString = copystring((const char*) str);
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ case DRAWOP_DRAW_ELLIPTIC_ARC:
+ {
+ m_x1 = expr->Nth(1)->RealValue();
+ m_y1 = expr->Nth(2)->RealValue();
+ m_x2 = expr->Nth(3)->RealValue();
+ m_y2 = expr->Nth(4)->RealValue();
+ m_x3 = expr->Nth(5)->RealValue();
+ m_y3 = expr->Nth(6)->RealValue();
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+}
+
+/*
+ * Draw polygon, polyline, spline
+ *
+ */
+
+wxOpPolyDraw::wxOpPolyDraw(int theOp, int n, wxRealPoint *thePoints):wxDrawOp(theOp)
+{
+ m_noPoints = n;
+ m_points = thePoints;
+}
+
+wxOpPolyDraw::~wxOpPolyDraw()
+{
+ delete[] m_points;
+}
+
+wxDrawOp *wxOpPolyDraw::Copy(wxPseudoMetaFile *newImage)
+{
+ wxRealPoint *newPoints = new wxRealPoint[m_noPoints];
+ for (int i = 0; i < m_noPoints; i++)
+ {
+ newPoints[i].x = m_points[i].x;
+ newPoints[i].y = m_points[i].y;
+ }
+ wxOpPolyDraw *newOp = new wxOpPolyDraw(m_op, m_noPoints, newPoints);
+ return newOp;
+}
+
+void wxOpPolyDraw::Do(wxDC& dc, double xoffset, double yoffset)
+{
+ switch (m_op)
+ {
+ case DRAWOP_DRAW_POLYLINE:
+ {
+ wxPoint *actualPoints = new wxPoint[m_noPoints];
+ int i;
+ for (i = 0; i < m_noPoints; i++)
+ {
+ actualPoints[i].x = WXROUND(m_points[i].x);
+ actualPoints[i].y = WXROUND(m_points[i].y);
+ }
+
+ dc.DrawLines(m_noPoints, actualPoints, WXROUND(xoffset), WXROUND(yoffset));
+
+ delete[] actualPoints;
+ break;
+ }
+ case DRAWOP_DRAW_POLYGON:
+ {
+ wxPoint *actualPoints = new wxPoint[m_noPoints];
+ int i;
+ for (i = 0; i < m_noPoints; i++)
+ {
+ actualPoints[i].x = WXROUND(m_points[i].x);
+ actualPoints[i].y = WXROUND(m_points[i].y);
+ }
+
+ dc.DrawPolygon(m_noPoints, actualPoints, WXROUND(xoffset), WXROUND(yoffset));
+
+ delete[] actualPoints;
+ break;
+ }
+ case DRAWOP_DRAW_SPLINE:
+ {
+ wxPoint *actualPoints = new wxPoint[m_noPoints];
+ int i;
+ for (i = 0; i < m_noPoints; i++)
+ {
+ actualPoints[i].x = WXROUND(m_points[i].x);
+ actualPoints[i].y = WXROUND(m_points[i].y);
+ }
+
+ dc.DrawSpline(m_noPoints, actualPoints); // no offsets in DrawSpline // , xoffset, yoffset);
+
+ delete[] actualPoints;
+ break;
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+void wxOpPolyDraw::Scale(double scaleX, double scaleY)
+{
+ for (int i = 0; i < m_noPoints; i++)
+ {
+ m_points[i].x *= scaleX;
+ m_points[i].y *= scaleY;
+ }
+}
+
+void wxOpPolyDraw::Translate(double x, double y)
+{
+ for (int i = 0; i < m_noPoints; i++)
+ {
+ m_points[i].x += x;
+ m_points[i].y += y;
+ }
+}
+
+void wxOpPolyDraw::Rotate(double x, double y, double theta, double sinTheta, double cosTheta)
+{
+ for (int i = 0; i < m_noPoints; i++)
+ {
+ double x1 = m_points[i].x;
+ double y1 = m_points[i].y;
+ m_points[i].x = x1*cosTheta - y1*sinTheta + x*(1.0 - cosTheta) + y*sinTheta;
+ m_points[i].y = x1*sinTheta + y1*cosTheta + y*(1.0 - cosTheta) + x*sinTheta;
+ }
+}
+
+wxExpr *wxOpPolyDraw::WriteExpr(wxPseudoMetaFile *image)
+{
+ wxExpr *expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)m_op));
+ expr->Append(new wxExpr((long)m_noPoints));
+
+// char buf1[9];
+ char buf2[5];
+ char buf3[5];
+
+ oglBuffer[0] = 0;
+
+ /*
+ * Store each coordinate pair in a hex string to save space.
+ * E.g. "1B9080CD". 4 hex digits per coordinate pair.
+ *
+ */
+
+ for (int i = 0; i < m_noPoints; i++)
+ {
+ long signedX = (long)(m_points[i].x*100.0);
+ long signedY = (long)(m_points[i].y*100.0);
+
+ // Scale to 0 -> 64K
+ long unSignedX = (long)(signedX + 32767.0);
+ long unSignedY = (long)(signedY + 32767.0);
+
+// IntToHex((unsigned int)signedX, buf2);
+// IntToHex((unsigned int)signedY, buf3);
+ IntToHex((int)unSignedX, buf2);
+ IntToHex((int)unSignedY, buf3);
+
+ // Don't overrun the buffer
+ if ((i*8) < 3000)
+ {
+ strcat(oglBuffer, buf2);
+ strcat(oglBuffer, buf3);
+ }
+ }
+ expr->Append(new wxExpr(wxExprString, oglBuffer));
+ return expr;
+}
+
+void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile *image, wxExpr *expr)
+{
+ m_noPoints = (int)expr->Nth(1)->IntegerValue();
+
+ char buf1[5];
+ char buf2[5];
+
+ m_points = new wxRealPoint[m_noPoints];
+ int i = 0;
+ int bufPtr = 0;
+ wxString hexString = expr->Nth(2)->StringValue();
+ while (i < m_noPoints)
+ {
+ buf1[0] = hexString[(size_t)bufPtr];
+ buf1[1] = hexString[(size_t)(bufPtr + 1)];
+ buf1[2] = hexString[(size_t)(bufPtr + 2)];
+ buf1[3] = hexString[(size_t)(bufPtr + 3)];
+ buf1[4] = 0;
+
+ buf2[0] = hexString[(size_t)(bufPtr + 4)];
+ buf2[1] = hexString[(size_t)(bufPtr + 5)];
+ buf2[2] = hexString[(size_t)(bufPtr + 6)];
+ buf2[3] = hexString[(size_t)(bufPtr + 7)];
+ buf2[4] = 0;
+
+ bufPtr += 8;
+
+// int signedX = (signed int)HexToInt(buf1);
+// int signedY = (signed int)HexToInt(buf2);
+ long unSignedX = HexToInt(buf1);
+ long unSignedY = HexToInt(buf2);
+ // Scale -32K -> +32K
+ long signedX = unSignedX - 32767;
+ long signedY = unSignedY - 32767;
+#ifdef __WXMSW__
+ int testX = (signed int)unSignedX;
+ int testY = (signed int)unSignedY;
+#endif
+
+ m_points[i].x = (double)(signedX / 100.0);
+ m_points[i].y = (double)(signedY / 100.0);
+
+ i ++;
+ }
+}
+
+// Draw an outline using the current operation.
+bool wxOpPolyDraw::OnDrawOutline(wxDC& dc, double x, double y, double w, double h, double oldW, double oldH)
+{
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+
+ // Multiply all points by proportion of new size to old size
+ double x_proportion = (double)(fabs(w/oldW));
+ double y_proportion = (double)(fabs(h/oldH));
+
+ int n = m_noPoints;
+ wxPoint *intPoints = new wxPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ intPoints[i].x = WXROUND (x_proportion * m_points[i].x);
+ intPoints[i].y = WXROUND (y_proportion * m_points[i].y);
+ }
+ dc.DrawPolygon(n, intPoints, (long) x, (long) y);
+ delete[] intPoints;
+ return TRUE;
+}
+
+// Assume (x1, y1) is centre of box (most generally, line end at box)
+bool wxOpPolyDraw::GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3,
+ double xOffset, double yOffset,
+ int attachmentMode)
+{
+ int n = m_noPoints;
+
+ // First check for situation where the line is vertical,
+ // and we would want to connect to a point on that vertical --
+ // oglFindEndForPolyline can't cope with this (the arrow
+ // gets drawn to the wrong place).
+ if ((attachmentMode == ATTACHMENT_MODE_NONE) && (x1 == x2))
+ {
+ // Look for the point we'd be connecting to. This is
+ // a heuristic...
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint *point = & (m_points[i]);
+ if (point->x == 0.0)
+ {
+ if ((y2 > y1) && (point->y > 0.0))
+ {
+ *x3 = point->x + xOffset;
+ *y3 = point->y + yOffset;
+ return TRUE;
+ }
+ else if ((y2 < y1) && (point->y < 0.0))
+ {
+ *x3 = point->x + xOffset;
+ *y3 = point->y + yOffset;
+ return TRUE;
+ }
+ }
+ }
+ }
+
+ double *xpoints = new double[n];
+ double *ypoints = new double[n];
+
+ int i = 0;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint *point = & (m_points[i]);
+ xpoints[i] = point->x + xOffset;
+ ypoints[i] = point->y + yOffset;
+ }
+
+ oglFindEndForPolyline(n, xpoints, ypoints,
+ x1, y1, x2, y2, x3, y3);
+
+ delete[] xpoints;
+ delete[] ypoints;
+
+ return TRUE;
+}
+
+
+/*
+ * Utilities
+ *
+ */
+
+static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F' };
+
+// Convert unsigned 16-bit integer to 4-character hex string
+static void IntToHex(unsigned int dec, char *buf)
+{
+ int digit1 = (int)(dec/4096);
+ int digit2 = (int)((dec - (digit1*4096))/256);
+ int digit3 = (int)((dec - (digit1*4096) - (digit2*256))/16);
+ int digit4 = dec - (digit1*4096 + digit2*256 + digit3*16);
+
+ buf[0] = hexArray[digit1];
+ buf[1] = hexArray[digit2];
+ buf[2] = hexArray[digit3];
+ buf[3] = hexArray[digit4];
+ buf[4] = 0;
+}
+
+// One hex digit to decimal number
+static int HexToInt1(char hex)
+{
+ switch (hex)
+ {
+ case '0':
+ return 0;
+ case '1':
+ return 1;
+ case '2':
+ return 2;
+ case '3':
+ return 3;
+ case '4':
+ return 4;
+ case '5':
+ return 5;
+ case '6':
+ return 6;
+ case '7':
+ return 7;
+ case '8':
+ return 8;
+ case '9':
+ return 9;
+ case 'A':
+ return 10;
+ case 'B':
+ return 11;
+ case 'C':
+ return 12;
+ case 'D':
+ return 13;
+ case 'E':
+ return 14;
+ case 'F':
+ return 15;
+ default:
+ return 0;
+ }
+ return 0;
+}
+
+// 4-digit hex string to unsigned integer
+static unsigned long HexToInt(char *buf)
+{
+ long d1 = (long)(HexToInt1(buf[0])*4096.0) ;
+ long d2 = (long)(HexToInt1(buf[1])*256.0) ;
+ long d3 = (long)(HexToInt1(buf[2])*16.0) ;
+ long d4 = (long)(HexToInt1(buf[3])) ;
+ unsigned long n = (long)(d1 + d2 + d3 + d4) ;
+ return n;
+}
+
+/*
+ * wxPseudo meta-file
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile, wxObject)
+
+wxPseudoMetaFile::wxPseudoMetaFile()
+{
+ m_currentRotation = 0;
+ m_rotateable = TRUE;
+ m_width = 0.0;
+ m_height = 0.0;
+ m_outlinePen = NULL;
+ m_fillBrush = NULL;
+ m_outlineOp = -1;
+}
+
+wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile& mf)
+{
+ mf.Copy(*this);
+}
+
+wxPseudoMetaFile::~wxPseudoMetaFile()
+{
+ Clear();
+}
+
+void wxPseudoMetaFile::Clear()
+{
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ delete op;
+ node = node->Next();
+ }
+ m_ops.Clear();
+ m_gdiObjects.Clear();
+ m_outlineColours.Clear();
+ m_fillColours.Clear();
+ m_outlineOp = -1;
+}
+
+void wxPseudoMetaFile::Draw(wxDC& dc, double xoffset, double yoffset)
+{
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ op->Do(dc, xoffset, yoffset);
+ node = node->Next();
+ }
+}
+
+void wxPseudoMetaFile::Scale(double sx, double sy)
+{
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ op->Scale(sx, sy);
+ node = node->Next();
+ }
+ m_width *= sx;
+ m_height *= sy;
+}
+
+void wxPseudoMetaFile::Translate(double x, double y)
+{
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ op->Translate(x, y);
+ node = node->Next();
+ }
+}
+
+void wxPseudoMetaFile::Rotate(double x, double y, double theta)
+{
+ double theta1 = theta-m_currentRotation;
+ if (theta1 == 0.0) return;
+ double cosTheta = (double)cos(theta1);
+ double sinTheta = (double)sin(theta1);
+
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ op->Rotate(x, y, theta, sinTheta, cosTheta);
+ node = node->Next();
+ }
+ m_currentRotation = theta;
+}
+
+#ifdef PROLOGIO
+void wxPseudoMetaFile::WriteAttributes(wxExpr *clause, int whichAngle)
+{
+ wxString widthStr;
+ widthStr.Printf("meta_width%d", whichAngle);
+
+ wxString heightStr;
+ heightStr.Printf("meta_height%d", whichAngle);
+
+ wxString outlineStr;
+ outlineStr.Printf("outline_op%d", whichAngle);
+
+ wxString rotateableStr;
+ rotateableStr.Printf("meta_rotateable%d", whichAngle);
+
+ // Write width and height
+ clause->AddAttributeValue(widthStr, m_width);
+ clause->AddAttributeValue(heightStr, m_height);
+ clause->AddAttributeValue(rotateableStr, (long)m_rotateable);
+ clause->AddAttributeValue(outlineStr, (long)m_outlineOp);
+
+ // Write GDI objects
+ char buf[50];
+ int i = 1;
+ wxNode *node = m_gdiObjects.First();
+ while (node)
+ {
+ sprintf(buf, "gdi%d_%d", whichAngle, i);
+ wxObject *obj = (wxObject *)node->Data();
+ wxExpr *expr = NULL;
+ if (obj)
+ {
+ if (obj->IsKindOf(CLASSINFO(wxPen)))
+ {
+ wxPen *thePen = (wxPen *)obj;
+ expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)gyTYPE_PEN));
+ expr->Append(new wxExpr((long)thePen->GetWidth()));
+ expr->Append(new wxExpr((long)thePen->GetStyle()));
+ expr->Append(new wxExpr((long)thePen->GetColour().Red()));
+ expr->Append(new wxExpr((long)thePen->GetColour().Green()));
+ expr->Append(new wxExpr((long)thePen->GetColour().Blue()));
+ }
+ else if (obj->IsKindOf(CLASSINFO(wxBrush)))
+ {
+ wxBrush *theBrush = (wxBrush *)obj;
+ expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)gyTYPE_BRUSH));
+ expr->Append(new wxExpr((long)theBrush->GetStyle()));
+ expr->Append(new wxExpr((long)theBrush->GetColour().Red()));
+ expr->Append(new wxExpr((long)theBrush->GetColour().Green()));
+ expr->Append(new wxExpr((long)theBrush->GetColour().Blue()));
+ }
+ else if (obj->IsKindOf(CLASSINFO(wxFont)))
+ {
+ wxFont *theFont = (wxFont *)obj;
+ expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)gyTYPE_FONT));
+ expr->Append(new wxExpr((long)theFont->GetPointSize()));
+ expr->Append(new wxExpr((long)theFont->GetFamily()));
+ expr->Append(new wxExpr((long)theFont->GetStyle()));
+ expr->Append(new wxExpr((long)theFont->GetWeight()));
+ expr->Append(new wxExpr((long)theFont->GetUnderlined()));
+ }
+ }
+ else
+ {
+ // If no recognised GDI object, append a place holder anyway.
+ expr = new wxExpr(wxExprList);
+ expr->Append(new wxExpr((long)0));
+ }
+
+ if (expr)
+ {
+ clause->AddAttributeValue(buf, expr);
+ i ++;
+ }
+ node = node->Next();
+ }
+
+ // Write drawing operations
+ i = 1;
+ node = m_ops.First();
+ while (node)
+ {
+ sprintf(buf, "op%d_%d", whichAngle, i);
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ wxExpr *expr = op->WriteExpr(this);
+ if (expr)
+ {
+ clause->AddAttributeValue(buf, expr);
+ i ++;
+ }
+ node = node->Next();
+ }
+
+ // Write outline and fill GDI op lists (if any)
+ if (m_outlineColours.Number() > 0)
+ {
+ wxExpr *outlineExpr = new wxExpr(wxExprList);
+ node = m_outlineColours.First();
+ while (node)
+ {
+ outlineExpr->Append(new wxExpr((long)node->Data()));
+ node = node->Next();
+ }
+ wxString outlineObjectsStr;
+ outlineObjectsStr.Printf("outline_objects%d", whichAngle);
+
+ clause->AddAttributeValue(outlineObjectsStr, outlineExpr);
+ }
+ if (m_fillColours.Number() > 0)
+ {
+ wxExpr *fillExpr = new wxExpr(wxExprList);
+ node = m_fillColours.First();
+ while (node)
+ {
+ fillExpr->Append(new wxExpr((long)node->Data()));
+ node = node->Next();
+ }
+ wxString fillObjectsStr;
+ fillObjectsStr.Printf("fill_objects%d", whichAngle);
+
+ clause->AddAttributeValue(fillObjectsStr, fillExpr);
+ }
+
+}
+
+void wxPseudoMetaFile::ReadAttributes(wxExpr *clause, int whichAngle)
+{
+ wxString widthStr;
+ widthStr.Printf("meta_width%d", whichAngle);
+
+ wxString heightStr;
+ heightStr.Printf("meta_height%d", whichAngle);
+
+ wxString outlineStr;
+ outlineStr.Printf("outline_op%d", whichAngle);
+
+ wxString rotateableStr;
+ rotateableStr.Printf("meta_rotateable%d", whichAngle);
+
+ clause->GetAttributeValue(widthStr, m_width);
+ clause->GetAttributeValue(heightStr, m_height);
+ clause->GetAttributeValue(outlineStr, m_outlineOp);
+
+ int iVal = (int) m_rotateable;
+ clause->GetAttributeValue(rotateableStr, iVal);
+ m_rotateable = (iVal != 0);
+
+ // Read GDI objects
+ char buf[50];
+ int i = 1;
+ bool keepGoing = TRUE;
+ while (keepGoing)
+ {
+ sprintf(buf, "gdi%d_%d", whichAngle, i);
+ wxExpr *expr = NULL;
+ clause->GetAttributeValue(buf, &expr);
+ if (!expr)
+ {
+ keepGoing = FALSE;
+ }
+ else
+ {
+ wxExpr *idExpr = expr->Nth(0);
+ switch (idExpr->IntegerValue())
+ {
+ case gyTYPE_PEN:
+ {
+ int penWidth = (int)expr->Nth(1)->IntegerValue();
+ int penStyle = (int)expr->Nth(2)->IntegerValue();
+ int penRed = (int)expr->Nth(3)->IntegerValue();
+ int penGreen = (int)expr->Nth(4)->IntegerValue();
+ int penBlue = (int)expr->Nth(5)->IntegerValue();
+ wxColour col(penRed, penGreen, penBlue);
+ wxPen *p = wxThePenList->FindOrCreatePen(col, penWidth, penStyle);
+ if (!p)
+ p = wxBLACK_PEN;
+ m_gdiObjects.Append(p);
+ break;
+ }
+ case gyTYPE_BRUSH:
+ {
+ int brushStyle = (int)expr->Nth(1)->IntegerValue();
+ int brushRed = (int)expr->Nth(2)->IntegerValue();
+ int brushGreen = (int)expr->Nth(3)->IntegerValue();
+ int brushBlue = (int)expr->Nth(4)->IntegerValue();
+ wxColour col(brushRed, brushGreen, brushBlue);
+ wxBrush *b = wxTheBrushList->FindOrCreateBrush(col, brushStyle);
+ if (!b)
+ b = wxWHITE_BRUSH;
+ m_gdiObjects.Append(b);
+ break;
+ }
+ case gyTYPE_FONT:
+ {
+ int fontPointSize = (int)expr->Nth(1)->IntegerValue();
+ int fontFamily = (int)expr->Nth(2)->IntegerValue();
+ int fontStyle = (int)expr->Nth(3)->IntegerValue();
+ int fontWeight = (int)expr->Nth(4)->IntegerValue();
+ int fontUnderlined = (int)expr->Nth(5)->IntegerValue();
+ m_gdiObjects.Append(wxTheFontList->FindOrCreateFont(fontPointSize,
+ fontFamily, fontStyle, fontWeight, (fontUnderlined != 0)));
+ break;
+ }
+ default:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ }
+ i ++;
+ }
+ }
+
+ // Now read in the operations
+ keepGoing = TRUE;
+ i = 1;
+ while (keepGoing)
+ {
+ sprintf(buf, "op%d_%d", whichAngle, i);
+ wxExpr *expr = NULL;
+ clause->GetAttributeValue(buf, &expr);
+ if (!expr)
+ {
+ keepGoing = FALSE;
+ }
+ else
+ {
+ wxExpr *idExpr = expr->Nth(0);
+ int opId = (int)idExpr->IntegerValue();
+ switch (opId)
+ {
+ case DRAWOP_SET_PEN:
+ case DRAWOP_SET_BRUSH:
+ case DRAWOP_SET_FONT:
+ case DRAWOP_SET_TEXT_COLOUR:
+ case DRAWOP_SET_BK_COLOUR:
+ case DRAWOP_SET_BK_MODE:
+ {
+ wxOpSetGDI *theOp = new wxOpSetGDI(opId, this, 0);
+ theOp->ReadExpr(this, expr);
+ m_ops.Append(theOp);
+ break;
+ }
+
+ case DRAWOP_SET_CLIPPING_RECT:
+ case DRAWOP_DESTROY_CLIPPING_RECT:
+ {
+ wxOpSetClipping *theOp = new wxOpSetClipping(opId, 0.0, 0.0, 0.0, 0.0);
+ theOp->ReadExpr(this, expr);
+ m_ops.Append(theOp);
+ break;
+ }
+
+ case DRAWOP_DRAW_LINE:
+ case DRAWOP_DRAW_RECT:
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ case DRAWOP_DRAW_ELLIPSE:
+ case DRAWOP_DRAW_POINT:
+ case DRAWOP_DRAW_ARC:
+ case DRAWOP_DRAW_TEXT:
+ {
+ wxOpDraw *theOp = new wxOpDraw(opId, 0.0, 0.0, 0.0, 0.0);
+ theOp->ReadExpr(this, expr);
+ m_ops.Append(theOp);
+ break;
+ }
+ case DRAWOP_DRAW_SPLINE:
+ case DRAWOP_DRAW_POLYLINE:
+ case DRAWOP_DRAW_POLYGON:
+ {
+ wxOpPolyDraw *theOp = new wxOpPolyDraw(opId, 0, NULL);
+ theOp->ReadExpr(this, expr);
+ m_ops.Append(theOp);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ i ++;
+ }
+
+ wxString outlineObjectsStr;
+ outlineObjectsStr.Printf("outline_objects%d", whichAngle);
+
+ // Now read in the list of outline and fill operations, if any
+ wxExpr *expr1 = clause->AttributeValue(outlineObjectsStr);
+ if (expr1)
+ {
+ wxExpr *eachExpr = expr1->GetFirst();
+ while (eachExpr)
+ {
+ m_outlineColours.Append((wxObject *)eachExpr->IntegerValue());
+ eachExpr = eachExpr->GetNext();
+ }
+ }
+
+ wxString fillObjectsStr;
+ fillObjectsStr.Printf("fill_objects%d", whichAngle);
+
+ expr1 = clause->AttributeValue(fillObjectsStr);
+ if (expr1)
+ {
+ wxExpr *eachExpr = expr1->GetFirst();
+ while (eachExpr)
+ {
+ m_fillColours.Append((wxObject *)eachExpr->IntegerValue());
+ eachExpr = eachExpr->GetNext();
+ }
+ }
+}
+#endif
+
+// Does the copying for this object
+void wxPseudoMetaFile::Copy(wxPseudoMetaFile& copy)
+{
+ copy.Clear();
+
+ copy.m_currentRotation = m_currentRotation;
+ copy.m_width = m_width;
+ copy.m_height = m_height;
+ copy.m_rotateable = m_rotateable;
+ copy.m_fillBrush = m_fillBrush;
+ copy.m_outlinePen = m_outlinePen;
+ copy.m_outlineOp = m_outlineOp;
+
+ // Copy the GDI objects
+ wxNode *node = m_gdiObjects.First();
+ while (node)
+ {
+ wxObject *obj = (wxObject *)node->Data();
+ copy.m_gdiObjects.Append(obj);
+ node = node->Next();
+ }
+
+ // Copy the operations
+ node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ copy.m_ops.Append(op->Copy(©));
+ node = node->Next();
+ }
+
+ // Copy the outline/fill operations
+ node = m_outlineColours.First();
+ while (node)
+ {
+ copy.m_outlineColours.Append((wxObject *)node->Data());
+ node = node->Next();
+ }
+ node = m_fillColours.First();
+ while (node)
+ {
+ copy.m_fillColours.Append((wxObject *)node->Data());
+ node = node->Next();
+ }
+}
+
+/*
+ * Pass size of existing image; scale height to
+ * fit width and return new width and height.
+ *
+ */
+
+bool wxPseudoMetaFile::LoadFromMetaFile(char *filename, double *rwidth, double *rheight)
+{
+ if (!FileExists(filename))
+ return NULL;
+
+ wxXMetaFile *metaFile = new wxXMetaFile;
+
+ if (!metaFile->ReadFile(filename))
+ {
+ delete metaFile;
+ return FALSE;
+ }
+
+ double lastX = 0.0;
+ double lastY = 0.0;
+
+ // Convert from metafile records to wxDrawnShape records
+ wxNode *node = metaFile->metaRecords.First();
+ while (node)
+ {
+ wxMetaRecord *record = (wxMetaRecord *)node->Data();
+ switch (record->metaFunction)
+ {
+ case META_SETBKCOLOR:
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BK_COLOUR, this, 0);
+ op->m_r = (unsigned char)record->param1;
+ op->m_g = (unsigned char)record->param2;
+ op->m_b = (unsigned char)record->param3;
+ m_ops.Append(op);
+ break;
+ }
+ case META_SETBKMODE:
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BK_MODE, this, 0, (int)record->param1);
+ m_ops.Append(op);
+ break;
+ }
+ case META_SETMAPMODE:
+ {
+ break;
+ }
+// case META_SETROP2:
+// case META_SETRELABS:
+// case META_SETPOLYFILLMODE:
+// case META_SETSTRETCHBLTMODE:
+// case META_SETTEXTCHAREXTRA:
+ case META_SETTEXTCOLOR:
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR, this, 0);
+ op->m_r = (unsigned char)record->param1;
+ op->m_g = (unsigned char)record->param2;
+ op->m_b = (unsigned char)record->param3;
+ m_ops.Append(op);
+ break;
+ }
+// case META_SETTEXTJUSTIFICATION:
+// case META_SETWINDOWORG:
+// case META_SETWINDOWEXT:
+// case META_SETVIEWPORTORG:
+// case META_SETVIEWPORTEXT:
+// case META_OFFSETWINDOWORG:
+// case META_SCALEWINDOWEXT:
+// case META_OFFSETVIEWPORTORG:
+// case META_SCALEVIEWPORTEXT:
+ case META_LINETO:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_LINE, (double)lastX, (double)lastY,
+ (double)record->param1, (double)record->param2);
+ m_ops.Append(op);
+ break;
+ }
+ case META_MOVETO:
+ {
+ lastX = (double)record->param1;
+ lastY = (double)record->param2;
+ break;
+ }
+ case META_EXCLUDECLIPRECT:
+ {
+/*
+ wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
+ rec->param4 = getshort(handle); // m_y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+*/
+ break;
+ }
+ case META_INTERSECTCLIPRECT:
+ {
+/*
+ rec->param4 = getshort(handle); // m_y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+*/
+ break;
+ }
+// case META_ARC: // DO!!!
+ case META_ELLIPSE:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_ELLIPSE,
+ (double)record->param1, (double)record->param2,
+ (double)(record->param3 - record->param1),
+ (double)(record->param4 - record->param2));
+ m_ops.Append(op);
+ break;
+ }
+// case META_FLOODFILL:
+// case META_PIE: // DO!!!
+ case META_RECTANGLE:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_RECT,
+ (double)record->param1, (double)record->param2,
+ (double)(record->param3 - record->param1),
+ (double)(record->param4 - record->param2));
+ m_ops.Append(op);
+ break;
+ }
+ case META_ROUNDRECT:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT,
+ (double)record->param1, (double)record->param2,
+ (double)(record->param3 - record->param1),
+ (double)(record->param4 - record->param2), (double)record->param5);
+ m_ops.Append(op);
+ break;
+ }
+// case META_PATBLT:
+// case META_SAVEDC:
+ case META_SETPIXEL:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_POINT,
+ (double)record->param1, (double)record->param2,
+ 0.0, 0.0);
+
+// SHOULD SET THE COLOUR - SET PEN?
+// rec->param3 = getint(handle); // COLORREF
+ m_ops.Append(op);
+ break;
+ }
+// case META_OFFSETCLIPRGN:
+ case META_TEXTOUT:
+ {
+ wxOpDraw *op = new wxOpDraw(DRAWOP_DRAW_TEXT,
+ (double)record->param1, (double)record->param2,
+ 0.0, 0.0, 0.0, record->stringParam);
+ m_ops.Append(op);
+ break;
+ }
+// case META_BITBLT:
+// case META_STRETCHBLT:
+ case META_POLYGON:
+ {
+ int n = (int)record->param1;
+ wxRealPoint *newPoints = new wxRealPoint[n];
+ for (int i = 0; i < n; i++)
+ {
+ newPoints[i].x = record->points[i].x;
+ newPoints[i].y = record->points[i].y;
+ }
+
+ wxOpPolyDraw *op = new wxOpPolyDraw(DRAWOP_DRAW_POLYGON, n, newPoints);
+ m_ops.Append(op);
+ break;
+ }
+ case META_POLYLINE:
+ {
+ int n = (int)record->param1;
+ wxRealPoint *newPoints = new wxRealPoint[n];
+ for (int i = 0; i < n; i++)
+ {
+ newPoints[i].x = record->points[i].x;
+ newPoints[i].y = record->points[i].y;
+ }
+
+ wxOpPolyDraw *op = new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE, n, newPoints);
+ m_ops.Append(op);
+ break;
+ }
+// case META_ESCAPE:
+// case META_RESTOREDC:
+// case META_FILLREGION:
+// case META_FRAMEREGION:
+// case META_INVERTREGION:
+// case META_PAINTREGION:
+// case META_SELECTCLIPREGION: // DO THIS!
+ case META_SELECTOBJECT:
+ {
+ // The pen, brush etc. has already been created when the metafile
+ // was read in, so we don't create it - we set it.
+ wxNode *recNode = metaFile->gdiObjects.Nth((int)record->param2);
+ if (recNode)
+ {
+ wxMetaRecord *gdiRec = (wxMetaRecord *)recNode->Data();
+ if (gdiRec && (gdiRec->param1 != 0))
+ {
+ wxObject *obj = (wxObject *)gdiRec->param1;
+ if (obj->IsKindOf(CLASSINFO(wxPen)))
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_PEN, this, (int)record->param2);
+ m_ops.Append(op);
+ }
+ else if (obj->IsKindOf(CLASSINFO(wxBrush)))
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_BRUSH, this, (int)record->param2);
+ m_ops.Append(op);
+ }
+ else if (obj->IsKindOf(CLASSINFO(wxFont)))
+ {
+ wxOpSetGDI *op = new wxOpSetGDI(DRAWOP_SET_FONT, this, (int)record->param2);
+ m_ops.Append(op);
+ }
+ }
+ }
+ break;
+ }
+// case META_SETTEXTALIGN:
+// case META_DRAWTEXT:
+// case META_CHORD:
+// case META_SETMAPPERFLAGS:
+// case META_EXTTEXTOUT:
+// case META_SETDIBTODEV:
+// case META_SELECTPALETTE:
+// case META_REALIZEPALETTE:
+// case META_ANIMATEPALETTE:
+// case META_SETPALENTRIES:
+// case META_POLYPOLYGON:
+// case META_RESIZEPALETTE:
+// case META_DIBBITBLT:
+// case META_DIBSTRETCHBLT:
+ case META_DIBCREATEPATTERNBRUSH:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+// case META_STRETCHDIB:
+// case META_EXTFLOODFILL:
+// case META_RESETDC:
+// case META_STARTDOC:
+// case META_STARTPAGE:
+// case META_ENDPAGE:
+// case META_ABORTDOC:
+// case META_ENDDOC:
+// case META_DELETEOBJECT: // DO!!
+ case META_CREATEPALETTE:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ case META_CREATEBRUSH:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ case META_CREATEPATTERNBRUSH:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ case META_CREATEPENINDIRECT:
+ {
+ // The pen is created when the metafile is read in.
+ // We keep track of all the GDI objects needed for this
+ // image so when reading the wxDrawnShape from file,
+ // we can read in all the GDI objects, then refer
+ // to them by an index starting from zero thereafter.
+ m_gdiObjects.Append((wxObject *)record->param1);
+ break;
+ }
+ case META_CREATEFONTINDIRECT:
+ {
+ m_gdiObjects.Append((wxObject *)record->param1);
+ break;
+ }
+ case META_CREATEBRUSHINDIRECT:
+ {
+ // Don't have to do anything here: the pen is created
+ // when the metafile is read in.
+ m_gdiObjects.Append((wxObject *)record->param1);
+ break;
+ }
+ case META_CREATEBITMAPINDIRECT:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ case META_CREATEBITMAP:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ case META_CREATEREGION:
+ {
+ // Place holder
+ m_gdiObjects.Append(NULL);
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ node = node->Next();
+ }
+ double actualWidth = (double)fabs(metaFile->right - metaFile->left);
+ double actualHeight = (double)fabs(metaFile->bottom - metaFile->top);
+
+ double initialScaleX = 1.0;
+ double initialScaleY = 1.0;
+
+ double xoffset, yoffset;
+
+ // Translate so origin is at centre of rectangle
+ if (metaFile->bottom > metaFile->top)
+ yoffset = - (double)((metaFile->bottom - metaFile->top)/2.0);
+ else
+ yoffset = - (double)((metaFile->top - metaFile->bottom)/2.0);
+
+ if (metaFile->right > metaFile->left)
+ xoffset = - (double)((metaFile->right - metaFile->left)/2.0);
+ else
+ xoffset = - (double)((metaFile->left - metaFile->right)/2.0);
+
+ Translate(xoffset, yoffset);
+
+ // Scale to a reasonable size (take the width of this wxDrawnShape
+ // as a guide)
+ if (actualWidth != 0.0)
+ {
+ initialScaleX = (double)((*rwidth) / actualWidth);
+ initialScaleY = initialScaleX;
+ (*rheight) = initialScaleY*actualHeight;
+ }
+ Scale(initialScaleX, initialScaleY);
+
+ m_width = (actualWidth*initialScaleX);
+ m_height = *rheight;
+
+ delete metaFile;
+ return TRUE;
+}
+
+// Scale to fit size
+void wxPseudoMetaFile::ScaleTo(double w, double h)
+{
+ double scaleX = (double)(w/m_width);
+ double scaleY = (double)(h/m_height);
+
+ // Do the scaling
+ Scale(scaleX, scaleY);
+}
+
+void wxPseudoMetaFile::GetBounds(double *boundMinX, double *boundMinY, double *boundMaxX, double *boundMaxY)
+{
+ double maxX = (double) -99999.9;
+ double maxY = (double) -99999.9;
+ double minX = (double) 99999.9;
+ double minY = (double) 99999.9;
+
+ wxNode *node = m_ops.First();
+ while (node)
+ {
+ wxDrawOp *op = (wxDrawOp *)node->Data();
+ switch (op->GetOp())
+ {
+ case DRAWOP_DRAW_LINE:
+ case DRAWOP_DRAW_RECT:
+ case DRAWOP_DRAW_ROUNDED_RECT:
+ case DRAWOP_DRAW_ELLIPSE:
+ case DRAWOP_DRAW_POINT:
+ case DRAWOP_DRAW_TEXT:
+ {
+ wxOpDraw *opDraw = (wxOpDraw *)op;
+ if (opDraw->m_x1 < minX) minX = opDraw->m_x1;
+ if (opDraw->m_x1 > maxX) maxX = opDraw->m_x1;
+ if (opDraw->m_y1 < minY) minY = opDraw->m_y1;
+ if (opDraw->m_y1 > maxY) maxY = opDraw->m_y1;
+ if (op->GetOp() == DRAWOP_DRAW_LINE)
+ {
+ if (opDraw->m_x2 < minX) minX = opDraw->m_x2;
+ if (opDraw->m_x2 > maxX) maxX = opDraw->m_x2;
+ if (opDraw->m_y2 < minY) minY = opDraw->m_y2;
+ if (opDraw->m_y2 > maxY) maxY = opDraw->m_y2;
+ }
+ else if (op->GetOp() == DRAWOP_DRAW_RECT ||
+ op->GetOp() == DRAWOP_DRAW_ROUNDED_RECT ||
+ op->GetOp() == DRAWOP_DRAW_ELLIPSE)
+ {
+ if ((opDraw->m_x1 + opDraw->m_x2) < minX) minX = (opDraw->m_x1 + opDraw->m_x2);
+ if ((opDraw->m_x1 + opDraw->m_x2) > maxX) maxX = (opDraw->m_x1 + opDraw->m_x2);
+ if ((opDraw->m_y1 + opDraw->m_y2) < minY) minY = (opDraw->m_y1 + opDraw->m_y2);
+ if ((opDraw->m_y1 + opDraw->m_y2) > maxY) maxY = (opDraw->m_y1 + opDraw->m_y2);
+ }
+ break;
+ }
+ case DRAWOP_DRAW_ARC:
+ {
+ // TODO: don't yet know how to calculate the bounding box
+ // for an arc. So pretend it's a line; to get a correct
+ // bounding box, draw a blank rectangle first, of the correct
+ // size.
+ wxOpDraw *opDraw = (wxOpDraw *)op;
+ if (opDraw->m_x1 < minX) minX = opDraw->m_x1;
+ if (opDraw->m_x1 > maxX) maxX = opDraw->m_x1;
+ if (opDraw->m_y1 < minY) minY = opDraw->m_y1;
+ if (opDraw->m_y1 > maxY) maxY = opDraw->m_y1;
+ if (opDraw->m_x2 < minX) minX = opDraw->m_x2;
+ if (opDraw->m_x2 > maxX) maxX = opDraw->m_x2;
+ if (opDraw->m_y2 < minY) minY = opDraw->m_y2;
+ if (opDraw->m_y2 > maxY) maxY = opDraw->m_y2;
+ break;
+ }
+ case DRAWOP_DRAW_POLYLINE:
+ case DRAWOP_DRAW_POLYGON:
+ case DRAWOP_DRAW_SPLINE:
+ {
+ wxOpPolyDraw *poly = (wxOpPolyDraw *)op;
+ for (int i = 0; i < poly->m_noPoints; i++)
+ {
+ if (poly->m_points[i].x < minX) minX = poly->m_points[i].x;
+ if (poly->m_points[i].x > maxX) maxX = poly->m_points[i].x;
+ if (poly->m_points[i].y < minY) minY = poly->m_points[i].y;
+ if (poly->m_points[i].y > maxY) maxY = poly->m_points[i].y;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ node = node->Next();
+ }
+
+ *boundMinX = minX;
+ *boundMinY = minY;
+ *boundMaxX = maxX;
+ *boundMaxY = maxY;
+/*
+ *w = (double)fabs(maxX - minX);
+ *h = (double)fabs(maxY - minY);
+*/
+}
+
+// Calculate size from current operations
+void wxPseudoMetaFile::CalculateSize(wxDrawnShape* shape)
+{
+ double boundMinX, boundMinY, boundMaxX, boundMaxY;
+
+ GetBounds(& boundMinX, & boundMinY, & boundMaxX, & boundMaxY);
+
+ SetSize(boundMaxX - boundMinX, boundMaxY - boundMinY);
+
+ if (shape)
+ {
+ shape->SetWidth(m_width);
+ shape->SetHeight(m_height);
+ }
+}
+
+// Set of functions for drawing into a pseudo metafile.
+// They use integers, but doubles are used internally for accuracy
+// when scaling.
+
+void wxPseudoMetaFile::DrawLine(const wxPoint& pt1, const wxPoint& pt2)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_LINE,
+ (double) pt1.x, (double) pt1.y, (double) pt2.x, (double) pt2.y);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawRectangle(const wxRect& rect)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_RECT,
+ (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect& rect, double radius)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT,
+ (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
+
+ theOp->m_radius = radius;
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawEllipse(const wxRect& rect)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ELLIPSE,
+ (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ARC,
+ (double) centrePt.x, (double) centrePt.y, (double) startPt.x, (double) startPt.y);
+
+ theOp->m_x3 = (double) endPt.x;
+ theOp->m_y3 = (double) endPt.y;
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle)
+{
+ const double pi = 3.1415926535897932384626433832795 ;
+
+ double startAngleRadians = startAngle* (pi*2.0/360.0);
+ double endAngleRadians = endAngle* (pi*2.0/360.0);
+
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC,
+ (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
+
+ theOp->m_x3 = startAngleRadians;
+ theOp->m_y3 = endAngleRadians;
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawPoint(const wxPoint& pt)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_POINT,
+ (double) pt.x, (double) pt.y, 0.0, 0.0);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawText(const wxString& text, const wxPoint& pt)
+{
+ wxOpDraw *theOp = new wxOpDraw(DRAWOP_DRAW_TEXT,
+ (double) pt.x, (double) pt.y, 0.0, 0.0);
+
+ theOp->m_textString = copystring(text);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawLines(int n, wxPoint pts[])
+{
+ wxRealPoint* realPoints = new wxRealPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ realPoints[i].x = pts[i].x;
+ realPoints[i].y = pts[i].y;
+ }
+ wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE, n, realPoints);
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::DrawPolygon(int n, wxPoint pts[], int flags)
+{
+ wxRealPoint* realPoints = new wxRealPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ realPoints[i].x = pts[i].x;
+ realPoints[i].y = pts[i].y;
+ }
+ wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_POLYGON, n, realPoints);
+ m_ops.Append(theOp);
+
+ if (flags & oglMETAFLAGS_OUTLINE)
+ m_outlineOp = (m_ops.Number() - 1);
+}
+
+void wxPseudoMetaFile::DrawSpline(int n, wxPoint pts[])
+{
+ wxRealPoint* realPoints = new wxRealPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ realPoints[i].x = pts[i].x;
+ realPoints[i].y = pts[i].y;
+ }
+ wxOpPolyDraw* theOp = new wxOpPolyDraw(DRAWOP_DRAW_SPLINE, n, realPoints);
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::SetClippingRect(const wxRect& rect)
+{
+ wxOpSetClipping* theOp = new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT,
+ (double) rect.x, (double) rect.y, (double) rect.width, (double) rect.height);
+}
+
+void wxPseudoMetaFile::DestroyClippingRect()
+{
+ wxOpSetClipping* theOp = new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT,
+ 0.0, 0.0, 0.0, 0.0);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::SetPen(wxPen* pen, bool isOutline)
+{
+ m_gdiObjects.Append(pen);
+ int n = m_gdiObjects.Number();
+
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_PEN, this, n - 1);
+
+ m_ops.Append(theOp);
+
+ if (isOutline)
+ {
+ m_outlineColours.Append((wxObject*) (n - 1));
+ }
+}
+
+void wxPseudoMetaFile::SetBrush(wxBrush* brush, bool isFill)
+{
+ m_gdiObjects.Append(brush);
+ int n = m_gdiObjects.Number();
+
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_BRUSH, this, n - 1);
+
+ m_ops.Append(theOp);
+
+ if (isFill)
+ {
+ m_fillColours.Append((wxObject*) (n - 1));
+ }
+}
+
+void wxPseudoMetaFile::SetFont(wxFont* font)
+{
+ m_gdiObjects.Append(font);
+ int n = m_gdiObjects.Number();
+
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_FONT, this, n - 1);
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::SetTextColour(const wxColour& colour)
+{
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR, this, 0);
+ theOp->m_r = colour.Red();
+ theOp->m_g = colour.Green();
+ theOp->m_b = colour.Blue();
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::SetBackgroundColour(const wxColour& colour)
+{
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_BK_COLOUR, this, 0);
+ theOp->m_r = colour.Red();
+ theOp->m_g = colour.Green();
+ theOp->m_b = colour.Blue();
+
+ m_ops.Append(theOp);
+}
+
+void wxPseudoMetaFile::SetBackgroundMode(int mode)
+{
+ wxOpSetGDI* theOp = new wxOpSetGDI(DRAWOP_SET_BK_MODE, this, 0, mode);
+
+ m_ops.Append(theOp);
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: drawn.h
+// Purpose: wxDrawnShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_DRAWN_H_
+#define _OGL_DRAWN_H_
+
+#ifdef __GNUG__
+#pragma interface "drawn.h"
+#endif
+
+#include "basic.h"
+
+#define oglMETAFLAGS_OUTLINE 1
+#define oglMETAFLAGS_ATTACHMENTS 2
+
+class wxDrawnShape;
+class wxPseudoMetaFile: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile)
+ public:
+ wxPseudoMetaFile();
+ wxPseudoMetaFile(wxPseudoMetaFile& mf);
+ ~wxPseudoMetaFile();
+
+ void Draw(wxDC& dc, double xoffset, double yoffset);
+
+#ifdef PROLOGIO
+ void WriteAttributes(wxExpr *clause, int whichAngle);
+ void ReadAttributes(wxExpr *clause, int whichAngle);
+#endif
+
+ void Clear();
+
+ void Copy(wxPseudoMetaFile& copy);
+
+ void Scale(double sx, double sy);
+ void ScaleTo(double w, double h); // Scale to fit size
+ void Translate(double x, double y);
+
+ // Rotate about the given axis by theta radians from the x axis.
+ void Rotate(double x, double y, double theta);
+
+ bool LoadFromMetaFile(char *filename, double *width, double *height);
+
+ void GetBounds(double *minX, double *minY, double *maxX, double *maxY);
+
+ // Calculate size from current operations
+ void CalculateSize(wxDrawnShape* shape);
+
+ inline wxList& GetOutlineColours() const { return (wxList&) m_outlineColours; }
+ inline wxList& GetFillColours() const { return (wxList&) m_fillColours; }
+ inline void SetRotateable(bool rot) { m_rotateable = rot; }
+ inline bool GetRotateable() const { return m_rotateable; }
+
+ inline void SetSize(double w, double h) { m_width = w; m_height = h; }
+
+ inline void SetFillBrush(wxBrush* brush) { m_fillBrush = brush; }
+ inline wxBrush* GetFillBrush() const { return m_fillBrush; }
+
+ inline void SetOutlinePen(wxPen* pen) { m_outlinePen = pen; }
+ inline wxPen* GetOutlinePen() const { return m_outlinePen; }
+
+ inline void SetOutlineOp(int op) { m_outlineOp = op; }
+ inline int GetOutlineOp() const { return m_outlineOp; }
+
+ inline wxList& GetOps() const { return (wxList&) m_ops; }
+
+ // Is this a valid (non-empty) metafile?
+ inline bool IsValid() const { return (m_ops.Number() > 0); }
+
+public:
+ /// Set of functions for drawing into a pseudo metafile.
+ /// They use integers, but doubles are used internally for accuracy
+ /// when scaling.
+
+ virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
+ virtual void DrawRectangle(const wxRect& rect);
+ virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
+ virtual void DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt);
+ virtual void DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle);
+ virtual void DrawEllipse(const wxRect& rect);
+ virtual void DrawPoint(const wxPoint& pt);
+ virtual void DrawText(const wxString& text, const wxPoint& pt);
+ virtual void DrawLines(int n, wxPoint pts[]);
+ // flags:
+ // oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
+ // also drawing lines/arrows at the circumference.
+ // oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment points at
+ // the vertices (perhaps a rare case...)
+ virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
+ virtual void DrawSpline(int n, wxPoint pts[]);
+
+ virtual void SetClippingRect(const wxRect& rect);
+ virtual void DestroyClippingRect();
+
+ virtual void SetPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
+ virtual void SetBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
+ virtual void SetFont(wxFont* font);
+ virtual void SetTextColour(const wxColour& colour);
+ virtual void SetBackgroundColour(const wxColour& colour);
+ virtual void SetBackgroundMode(int mode);
+
+public:
+ bool m_rotateable;
+ double m_width;
+ double m_height;
+ wxList m_ops; // List of drawing operations (see drawnp.h)
+ wxList m_gdiObjects; // List of pens, brushes and fonts for this object.
+ int m_outlineOp; // The op representing the outline, if any
+
+ // Pen/brush specifying outline/fill colours
+ // to override operations.
+ wxPen* m_outlinePen;
+ wxBrush* m_fillBrush;
+ wxList m_outlineColours; // List of the GDI operations that comprise the outline
+ wxList m_fillColours; // List of the GDI operations that fill the shape
+ double m_currentRotation;
+};
+
+#define oglDRAWN_ANGLE_0 0
+#define oglDRAWN_ANGLE_90 1
+#define oglDRAWN_ANGLE_180 2
+#define oglDRAWN_ANGLE_270 3
+
+class wxDrawnShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxDrawnShape)
+ public:
+ wxDrawnShape();
+ ~wxDrawnShape();
+
+ void OnDraw(wxDC& dc);
+
+#ifdef PROLOGIO
+ // I/O
+ void WriteAttributes(wxExpr *clause);
+ void ReadAttributes(wxExpr *clause);
+#endif
+
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ void Scale(double sx, double sy);
+ void Translate(double x, double y);
+ // Rotate about the given axis by theta radians from the x axis.
+ void Rotate(double x, double y, double theta);
+
+ // Get current rotation
+ inline double GetRotation() const { return m_rotation; }
+
+ void SetSize(double w, double h, bool recursive = TRUE);
+ bool LoadFromMetaFile(char *filename);
+
+ inline void SetSaveToFile(bool save) { m_saveToFile = save; }
+ inline wxPseudoMetaFile& GetMetaFile(int which = 0) const { return (wxPseudoMetaFile&) m_metafiles[which]; }
+
+ void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
+
+ // Get the perimeter point using the special outline op, if there is one,
+ // otherwise use default wxRectangleShape scheme
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3);
+
+ /// Set of functions for drawing into a pseudo metafile.
+ /// They use integers, but doubles are used internally for accuracy
+ /// when scaling.
+
+ virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
+ virtual void DrawRectangle(const wxRect& rect);
+ virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
+ virtual void DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt);
+ virtual void DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle);
+ virtual void DrawEllipse(const wxRect& rect);
+ virtual void DrawPoint(const wxPoint& pt);
+ virtual void DrawText(const wxString& text, const wxPoint& pt);
+ virtual void DrawLines(int n, wxPoint pts[]);
+ virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
+ virtual void DrawSpline(int n, wxPoint pts[]);
+
+ virtual void SetClippingRect(const wxRect& rect);
+ virtual void DestroyClippingRect();
+
+ virtual void SetDrawnPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
+ virtual void SetDrawnBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
+ virtual void SetDrawnFont(wxFont* font);
+ virtual void SetDrawnTextColour(const wxColour& colour);
+ virtual void SetDrawnBackgroundColour(const wxColour& colour);
+ virtual void SetDrawnBackgroundMode(int mode);
+
+ // Set the width/height according to the shapes in the metafile.
+ // Call this after drawing into the shape.
+ inline void CalculateSize() { m_metafiles[m_currentAngle].CalculateSize(this); }
+
+ inline void DrawAtAngle(int angle) { m_currentAngle = angle; };
+
+ inline int GetAngle() const { return m_currentAngle; }
+
+// Implementation
+protected:
+ // Which metafile do we use now? Based on current rotation and validity
+ // of metafiles.
+ int DetermineMetaFile(double rotation);
+
+private:
+ // One metafile for each 90 degree rotation (or just a single one).
+ wxPseudoMetaFile m_metafiles[4];
+
+ // Don't save all wxDrawnShape metafiles to file: sometimes
+ // we take the metafile data from a symbol library.
+ bool m_saveToFile;
+
+ // Which angle are we using/drawing into?
+ int m_currentAngle;
+};
+
+#endif
+ // _DRAWN_H_
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: drawnp.h
+// Purpose: Private header for wxDrawnShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_DRAWNP_H_
+#define _OGL_DRAWNP_H_
+
+#ifdef __GNUG__
+#pragma interface "drawnp.h"
+#endif
+
+#include "drawn.h"
+
+/*
+ * Drawing operations
+ *
+ */
+
+#define DRAWOP_SET_PEN 1
+#define DRAWOP_SET_BRUSH 2
+#define DRAWOP_SET_FONT 3
+#define DRAWOP_SET_TEXT_COLOUR 4
+#define DRAWOP_SET_BK_COLOUR 5
+#define DRAWOP_SET_BK_MODE 6
+#define DRAWOP_SET_CLIPPING_RECT 7
+#define DRAWOP_DESTROY_CLIPPING_RECT 8
+
+/*
+#define DRAWOP_CREATE_PEN 10
+#define DRAWOP_CREATE_BRUSH 11
+#define DRAWOP_CREATE_FONT 12
+*/
+
+#define DRAWOP_DRAW_LINE 20
+#define DRAWOP_DRAW_POLYLINE 21
+#define DRAWOP_DRAW_POLYGON 22
+#define DRAWOP_DRAW_RECT 23
+#define DRAWOP_DRAW_ROUNDED_RECT 24
+#define DRAWOP_DRAW_ELLIPSE 25
+#define DRAWOP_DRAW_POINT 26
+#define DRAWOP_DRAW_ARC 27
+#define DRAWOP_DRAW_TEXT 28
+#define DRAWOP_DRAW_SPLINE 29
+#define DRAWOP_DRAW_ELLIPTIC_ARC 30
+
+/*
+ * Base, virtual class
+ *
+ */
+
+class wxDrawOp: public wxObject
+{
+public:
+ inline wxDrawOp(int theOp) { m_op = theOp; }
+ inline ~wxDrawOp() {}
+ inline virtual void Scale(double xScale, double yScale) {};
+ inline virtual void Translate(double x, double y) {};
+ inline virtual void Rotate(double x, double y, double theta, double sinTheta, double cosTheta) {};
+ virtual void Do(wxDC& dc, double xoffset, double yoffset) = 0;
+ virtual wxDrawOp *Copy(wxPseudoMetaFile *newImage) = 0;
+ virtual wxExpr *WriteExpr(wxPseudoMetaFile *image) = 0;
+ virtual void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr) = 0;
+
+ inline int GetOp() const { return m_op; }
+
+ // Draw an outline using the current operation. By default, return FALSE (not drawn)
+ virtual bool OnDrawOutline(wxDC& dc, double x, double y, double w, double h,
+ double oldW, double oldH) { return FALSE; }
+
+ // Get the perimeter point using this data
+ virtual bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3,
+ double xOffset, double yOffset,
+ int attachmentMode)
+ { return FALSE; }
+
+protected:
+ int m_op;
+
+};
+
+/*
+ * Set font, brush, text colour
+ *
+ */
+
+class wxOpSetGDI: public wxDrawOp
+{
+ public:
+ wxOpSetGDI(int theOp, wxPseudoMetaFile *theImage, int theGdiIndex, int theMode = 0);
+ void Do(wxDC& dc, double xoffset, double yoffset);
+ wxDrawOp *Copy(wxPseudoMetaFile *newImage);
+ wxExpr *WriteExpr(wxPseudoMetaFile *image);
+ void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
+
+public:
+ int m_mode;
+ int m_gdiIndex;
+ wxPseudoMetaFile* m_image;
+ unsigned char m_r;
+ unsigned char m_g;
+ unsigned char m_b;
+};
+
+/*
+ * Set/destroy clipping
+ *
+ */
+
+class wxOpSetClipping: public wxDrawOp
+{
+public:
+ wxOpSetClipping(int theOp, double theX1, double theY1, double theX2, double theY2);
+ void Do(wxDC& dc, double xoffset, double yoffset);
+ void Scale(double xScale, double yScale);
+ void Translate(double x, double y);
+ wxDrawOp *Copy(wxPseudoMetaFile *newImage);
+ wxExpr *WriteExpr(wxPseudoMetaFile *image);
+ void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
+
+public:
+ double m_x1;
+ double m_y1;
+ double m_x2;
+ double m_y2;
+};
+
+/*
+ * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
+ *
+ */
+
+class wxOpDraw: public wxDrawOp
+{
+ public:
+ wxOpDraw(int theOp, double theX1, double theY1, double theX2, double theY2,
+ double radius = 0.0, char *s = NULL);
+ ~wxOpDraw();
+ void Do(wxDC& dc, double xoffset, double yoffset);
+ void Scale(double scaleX, double scaleY);
+ void Translate(double x, double y);
+ void Rotate(double x, double y, double theta, double sinTheta, double cosTheta);
+ wxDrawOp *Copy(wxPseudoMetaFile *newImage);
+ wxExpr *WriteExpr(wxPseudoMetaFile *image);
+ void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
+
+public:
+ double m_x1;
+ double m_y1;
+ double m_x2;
+ double m_y2;
+ double m_x3;
+ double m_y3;
+ double m_radius;
+ char* m_textString;
+
+};
+
+/*
+ * Draw polyline, spline, polygon
+ *
+ */
+
+class wxOpPolyDraw: public wxDrawOp
+{
+public:
+ wxOpPolyDraw(int theOp, int n, wxRealPoint *thePoints);
+ ~wxOpPolyDraw();
+ void Do(wxDC& dc, double xoffset, double yoffset);
+ void Scale(double scaleX, double scaleY);
+ void Translate(double x, double y);
+ void Rotate(double x, double y, double theta, double sinTheta, double cosTheta);
+ wxDrawOp *Copy(wxPseudoMetaFile *newImage);
+ wxExpr *WriteExpr(wxPseudoMetaFile *image);
+ void ReadExpr(wxPseudoMetaFile *image, wxExpr *expr);
+
+ // Draw an outline using the current operation.
+ virtual bool OnDrawOutline(wxDC& dc, double x, double y, double w, double h,
+ double oldW, double oldH);
+
+ // Get the perimeter point using this data
+ bool GetPerimeterPoint(double x1, double y1,
+ double x2, double y2,
+ double *x3, double *y3,
+ double xOffset, double yOffset,
+ int attachmentMode);
+
+public:
+ wxRealPoint* m_points;
+ int m_noPoints;
+
+};
+
+#endif
+ // _OGL_DRAWNP_H_
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: lines.cpp
+// Purpose: wxLineShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "lines.h"
+#pragma implementation "linesp.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+
+#include <ctype.h>
+#include <math.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "lines.h"
+#include "linesp.h"
+#include "drawn.h"
+#include "misc.h"
+#include "canvas.h"
+
+// Line shape
+IMPLEMENT_DYNAMIC_CLASS(wxLineShape, wxShape)
+
+wxLineShape::wxLineShape()
+{
+ m_sensitivity = OP_CLICK_LEFT | OP_CLICK_RIGHT;
+ m_draggable = FALSE;
+ m_attachmentTo = 0;
+ m_attachmentFrom = 0;
+/*
+ m_actualTextWidth = 0.0;
+ m_actualTextHeight = 0.0;
+*/
+ m_from = NULL;
+ m_to = NULL;
+ m_erasing = FALSE;
+ m_arrowSpacing = 5.0; // For the moment, don't bother saving this to file.
+ m_ignoreArrowOffsets = FALSE;
+ m_isSpline = FALSE;
+ m_maintainStraightLines = FALSE;
+ m_alignmentStart = 0;
+ m_alignmentEnd = 0;
+
+ m_lineControlPoints = NULL;
+
+ // Clear any existing regions (created in an earlier constructor)
+ // and make the three line regions.
+ ClearRegions();
+ wxShapeRegion *newRegion = new wxShapeRegion;
+ newRegion->SetName("Middle");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+
+ newRegion = new wxShapeRegion;
+ newRegion->SetName("Start");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+
+ newRegion = new wxShapeRegion;
+ newRegion->SetName("End");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+
+ for (int i = 0; i < 3; i++)
+ m_labelObjects[i] = NULL;
+}
+
+wxLineShape::~wxLineShape()
+{
+ if (m_lineControlPoints)
+ {
+ ClearPointList(*m_lineControlPoints);
+ delete m_lineControlPoints;
+ }
+ for (int i = 0; i < 3; i++)
+ {
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Select(FALSE);
+ m_labelObjects[i]->RemoveFromCanvas(m_canvas);
+ delete m_labelObjects[i];
+ m_labelObjects[i] = NULL;
+ }
+ }
+ ClearArrowsAtPosition(-1);
+}
+
+void wxLineShape::MakeLineControlPoints(int n)
+{
+ if (m_lineControlPoints)
+ {
+ ClearPointList(*m_lineControlPoints);
+ delete m_lineControlPoints;
+ }
+ m_lineControlPoints = new wxList;
+
+ int i = 0;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint *point = new wxRealPoint(-999, -999);
+ m_lineControlPoints->Append((wxObject*) point);
+ }
+}
+
+wxNode *wxLineShape::InsertLineControlPoint(wxDC* dc)
+{
+ if (dc)
+ Erase(*dc);
+
+ wxNode *last = m_lineControlPoints->Last();
+ wxNode *second_last = last->Previous();
+ wxRealPoint *last_point = (wxRealPoint *)last->Data();
+ wxRealPoint *second_last_point = (wxRealPoint *)second_last->Data();
+
+ // Choose a point half way between the last and penultimate points
+ double line_x = ((last_point->x + second_last_point->x)/2);
+ double line_y = ((last_point->y + second_last_point->y)/2);
+
+ wxRealPoint *point = new wxRealPoint(line_x, line_y);
+ wxNode *node = m_lineControlPoints->Insert(last, (wxObject*) point);
+ return node;
+}
+
+bool wxLineShape::DeleteLineControlPoint()
+{
+ if (m_lineControlPoints->Number() < 3)
+ return FALSE;
+
+ wxNode *last = m_lineControlPoints->Last();
+ wxNode *second_last = last->Previous();
+
+ wxRealPoint *second_last_point = (wxRealPoint *)second_last->Data();
+ delete second_last_point;
+ delete second_last;
+
+ return TRUE;
+}
+
+void wxLineShape::Initialise()
+{
+ if (m_lineControlPoints)
+ {
+ // Just move the first and last control points
+ wxNode *first = m_lineControlPoints->First();
+ wxRealPoint *first_point = (wxRealPoint *)first->Data();
+
+ wxNode *last = m_lineControlPoints->Last();
+ wxRealPoint *last_point = (wxRealPoint *)last->Data();
+
+ // If any of the line points are at -999, we must
+ // initialize them by placing them half way between the first
+ // and the last.
+ wxNode *node = first->Next();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ if (point->x == -999)
+ {
+ double x1, y1, x2, y2;
+ if (first_point->x < last_point->x)
+ { x1 = first_point->x; x2 = last_point->x; }
+ else
+ { x2 = first_point->x; x1 = last_point->x; }
+
+ if (first_point->y < last_point->y)
+ { y1 = first_point->y; y2 = last_point->y; }
+ else
+ { y2 = first_point->y; y1 = last_point->y; }
+
+ point->x = ((x2 - x1)/2 + x1);
+ point->y = ((y2 - y1)/2 + y1);
+ }
+ node = node->Next();
+ }
+ }
+}
+
+// Format a text string according to the region size, adding
+// strings with positions to region text list
+void wxLineShape::FormatText(wxDC& dc, const wxString& s, int i)
+{
+ double w, h;
+ ClearText(i);
+
+ if (m_regions.Number() < 1)
+ return;
+ wxNode *node = m_regions.Nth(i);
+ if (!node)
+ return;
+
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->SetText(s);
+ dc.SetFont(* region->GetFont());
+
+ region->GetSize(&w, &h);
+ // Initialize the size if zero
+ if (((w == 0) || (h == 0)) && (strlen(s) > 0))
+ {
+ w = 100; h = 50;
+ region->SetSize(w, h);
+ }
+
+ wxStringList *string_list = oglFormatText(dc, s, (w-5), (h-5), region->GetFormatMode());
+ node = string_list->First();
+ while (node)
+ {
+ char *s = (char *)node->Data();
+ wxShapeTextLine *line = new wxShapeTextLine(0.0, 0.0, s);
+ region->GetFormattedText().Append((wxObject *)line);
+ node = node->Next();
+ }
+ delete string_list;
+ double actualW = w;
+ double actualH = h;
+ if (region->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS)
+ {
+ oglGetCentredTextExtent(dc, &(region->GetFormattedText()), m_xpos, m_ypos, w, h, &actualW, &actualH);
+ if ((actualW != w ) || (actualH != h))
+ {
+ double xx, yy;
+ GetLabelPosition(i, &xx, &yy);
+ EraseRegion(dc, region, xx, yy);
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Select(FALSE, &dc);
+ m_labelObjects[i]->Erase(dc);
+ m_labelObjects[i]->SetSize(actualW, actualH);
+ }
+
+ region->SetSize(actualW, actualH);
+
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Select(TRUE, & dc);
+ m_labelObjects[i]->Draw(dc);
+ }
+ }
+ }
+ oglCentreText(dc, &(region->GetFormattedText()), m_xpos, m_ypos, actualW, actualH, region->GetFormatMode());
+ m_formatted = TRUE;
+}
+
+void wxLineShape::DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y)
+{
+ if (GetDisableLabel())
+ return;
+
+ double w, h;
+ double xx, yy;
+ region->GetSize(&w, &h);
+
+ // Get offset from x, y
+ region->GetPosition(&xx, &yy);
+
+ double xp = xx + x;
+ double yp = yy + y;
+
+ // First, clear a rectangle for the text IF there is any
+ if (region->GetFormattedText().Number() > 0)
+ {
+ dc.SetPen(* g_oglWhiteBackgroundPen);
+ dc.SetBrush(* g_oglWhiteBackgroundBrush);
+
+ // Now draw the text
+ if (region->GetFont()) dc.SetFont(* region->GetFont());
+
+ dc.DrawRectangle((long)(xp - w/2.0), (long)(yp - h/2.0), (long)w, (long)h);
+
+ if (m_pen) dc.SetPen(* m_pen);
+ dc.SetTextForeground(* region->GetActualColourObject());
+
+#ifdef __WXMSW__
+ dc.SetTextBackground(g_oglWhiteBackgroundBrush->GetColour());
+#endif
+
+ oglDrawFormattedText(dc, &(region->GetFormattedText()), xp, yp, w, h, region->GetFormatMode());
+ }
+}
+
+void wxLineShape::EraseRegion(wxDC& dc, wxShapeRegion *region, double x, double y)
+{
+ if (GetDisableLabel())
+ return;
+
+ double w, h;
+ double xx, yy;
+ region->GetSize(&w, &h);
+
+ // Get offset from x, y
+ region->GetPosition(&xx, &yy);
+
+ double xp = xx + x;
+ double yp = yy + y;
+
+ if (region->GetFormattedText().Number() > 0)
+ {
+ dc.SetPen(* g_oglWhiteBackgroundPen);
+ dc.SetBrush(* g_oglWhiteBackgroundBrush);
+
+ dc.DrawRectangle((long)(xp - w/2.0), (long)(yp - h/2.0), (long)w, (long)h);
+ }
+}
+
+// Get the reference point for a label. Region x and y
+// are offsets from this.
+// position is 0, 1, 2
+void wxLineShape::GetLabelPosition(int position, double *x, double *y)
+{
+ switch (position)
+ {
+ case 0:
+ {
+ // Want to take the middle section for the label
+ int n = m_lineControlPoints->Number();
+ int half_way = (int)(n/2);
+
+ // Find middle of this line
+ wxNode *node = m_lineControlPoints->Nth(half_way - 1);
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxNode *next_node = node->Next();
+ wxRealPoint *next_point = (wxRealPoint *)next_node->Data();
+
+ double dx = (next_point->x - point->x);
+ double dy = (next_point->y - point->y);
+ *x = (double)(point->x + dx/2.0);
+ *y = (double)(point->y + dy/2.0);
+ break;
+ }
+ case 1:
+ {
+ wxNode *node = m_lineControlPoints->First();
+ *x = ((wxRealPoint *)node->Data())->x;
+ *y = ((wxRealPoint *)node->Data())->y;
+ break;
+ }
+ case 2:
+ {
+ wxNode *node = m_lineControlPoints->Last();
+ *x = ((wxRealPoint *)node->Data())->x;
+ *y = ((wxRealPoint *)node->Data())->y;
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+/*
+ * Find whether line is supposed to be vertical or horizontal and
+ * make it so.
+ *
+ */
+void GraphicsStraightenLine(wxRealPoint *point1, wxRealPoint *point2)
+{
+ double dx = point2->x - point1->x;
+ double dy = point2->y - point1->y;
+
+ if (dx == 0.0)
+ return;
+ else if (fabs(dy/dx) > 1.0)
+ {
+ point2->x = point1->x;
+ }
+ else point2->y = point1->y;
+}
+
+void wxLineShape::Straighten(wxDC *dc)
+{
+ if (!m_lineControlPoints || m_lineControlPoints->Number() < 3)
+ return;
+
+ if (dc)
+ Erase(* dc);
+
+ wxNode *first_point_node = m_lineControlPoints->First();
+ wxNode *last_point_node = m_lineControlPoints->Last();
+ wxNode *second_last_point_node = last_point_node->Previous();
+
+ wxRealPoint *last_point = (wxRealPoint *)last_point_node->Data();
+ wxRealPoint *second_last_point = (wxRealPoint *)second_last_point_node->Data();
+
+ GraphicsStraightenLine(last_point, second_last_point);
+
+ wxNode *node = first_point_node;
+ while (node && (node != second_last_point_node))
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *next_point = (wxRealPoint *)(node->Next()->Data());
+
+ GraphicsStraightenLine(point, next_point);
+ node = node->Next();
+ }
+
+ if (dc)
+ Draw(* dc);
+}
+
+
+void wxLineShape::Unlink()
+{
+ if (m_to)
+ m_to->GetLines().DeleteObject(this);
+ if (m_from)
+ m_from->GetLines().DeleteObject(this);
+ m_to = NULL;
+ m_from = NULL;
+}
+
+void wxLineShape::SetEnds(double x1, double y1, double x2, double y2)
+{
+ // Find centre point
+ wxNode *first_point_node = m_lineControlPoints->First();
+ wxNode *last_point_node = m_lineControlPoints->Last();
+ wxRealPoint *first_point = (wxRealPoint *)first_point_node->Data();
+ wxRealPoint *last_point = (wxRealPoint *)last_point_node->Data();
+
+ first_point->x = x1;
+ first_point->y = y1;
+ last_point->x = x2;
+ last_point->y = y2;
+
+ m_xpos = (double)((x1 + x2)/2.0);
+ m_ypos = (double)((y1 + y2)/2.0);
+}
+
+// Get absolute positions of ends
+void wxLineShape::GetEnds(double *x1, double *y1, double *x2, double *y2)
+{
+ wxNode *first_point_node = m_lineControlPoints->First();
+ wxNode *last_point_node = m_lineControlPoints->Last();
+ wxRealPoint *first_point = (wxRealPoint *)first_point_node->Data();
+ wxRealPoint *last_point = (wxRealPoint *)last_point_node->Data();
+
+ *x1 = first_point->x; *y1 = first_point->y;
+ *x2 = last_point->x; *y2 = last_point->y;
+}
+
+void wxLineShape::SetAttachments(int from_attach, int to_attach)
+{
+ m_attachmentFrom = from_attach;
+ m_attachmentTo = to_attach;
+}
+
+bool wxLineShape::HitTest(double x, double y, int *attachment, double *distance)
+{
+ if (!m_lineControlPoints)
+ return FALSE;
+
+ // Look at label regions in case mouse is over a label
+ bool inLabelRegion = FALSE;
+ for (int i = 0; i < 3; i ++)
+ {
+ wxNode *regionNode = m_regions.Nth(i);
+ if (regionNode)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)regionNode->Data();
+ if (region->m_formattedText.Number() > 0)
+ {
+ double xp, yp, cx, cy, cw, ch;
+ GetLabelPosition(i, &xp, &yp);
+ // Offset region from default label position
+ region->GetPosition(&cx, &cy);
+ region->GetSize(&cw, &ch);
+ cx += xp;
+ cy += yp;
+ double rLeft = (double)(cx - (cw/2.0));
+ double rTop = (double)(cy - (ch/2.0));
+ double rRight = (double)(cx + (cw/2.0));
+ double rBottom = (double)(cy + (ch/2.0));
+ if (x > rLeft && x < rRight && y > rTop && y < rBottom)
+ {
+ inLabelRegion = TRUE;
+ i = 3;
+ }
+ }
+ }
+ }
+
+ wxNode *node = m_lineControlPoints->First();
+
+ while (node && node->Next())
+ {
+ wxRealPoint *point1 = (wxRealPoint *)node->Data();
+ wxRealPoint *point2 = (wxRealPoint *)node->Next()->Data();
+
+ // Allow for inaccurate mousing or vert/horiz lines
+ int extra = 4;
+ double left = wxMin(point1->x, point2->x) - extra;
+ double right = wxMax(point1->x, point2->x) + extra;
+
+ double bottom = wxMin(point1->y, point2->y) - extra;
+ double top = wxMax(point1->y, point2->y) + extra;
+
+ if ((x > left && x < right && y > bottom && y < top) || inLabelRegion)
+ {
+ // Work out distance from centre of line
+ double centre_x = (double)(left + (right - left)/2.0);
+ double centre_y = (double)(bottom + (top - bottom)/2.0);
+
+ *attachment = 0;
+ *distance = (double)sqrt((centre_x - x)*(centre_x - x) + (centre_y - y)*(centre_y - y));
+ return TRUE;
+ }
+
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+void wxLineShape::DrawArrows(wxDC& dc)
+{
+ // Distance along line of each arrow: space them out evenly.
+ double startArrowPos = 0.0;
+ double endArrowPos = 0.0;
+ double middleArrowPos = 0.0;
+
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ switch (arrow->GetArrowEnd())
+ {
+ case ARROW_POSITION_START:
+ {
+ if ((arrow->GetXOffset() != 0.0) && !m_ignoreArrowOffsets)
+ // If specified, x offset is proportional to line length
+ DrawArrow(dc, arrow, arrow->GetXOffset(), TRUE);
+ else
+ {
+ DrawArrow(dc, arrow, startArrowPos, FALSE); // Absolute distance
+ startArrowPos += arrow->GetSize() + arrow->GetSpacing();
+ }
+ break;
+ }
+ case ARROW_POSITION_END:
+ {
+ if ((arrow->GetXOffset() != 0.0) && !m_ignoreArrowOffsets)
+ DrawArrow(dc, arrow, arrow->GetXOffset(), TRUE);
+ else
+ {
+ DrawArrow(dc, arrow, endArrowPos, FALSE);
+ endArrowPos += arrow->GetSize() + arrow->GetSpacing();
+ }
+ break;
+ }
+ case ARROW_POSITION_MIDDLE:
+ {
+ arrow->SetXOffset(middleArrowPos);
+ if ((arrow->GetXOffset() != 0.0) && !m_ignoreArrowOffsets)
+ DrawArrow(dc, arrow, arrow->GetXOffset(), TRUE);
+ else
+ {
+ DrawArrow(dc, arrow, middleArrowPos, FALSE);
+ middleArrowPos += arrow->GetSize() + arrow->GetSpacing();
+ }
+ break;
+ }
+ }
+ node = node->Next();
+ }
+}
+
+void wxLineShape::DrawArrow(wxDC& dc, wxArrowHead *arrow, double xOffset, bool proportionalOffset)
+{
+ wxNode *first_line_node = m_lineControlPoints->First();
+ wxRealPoint *first_line_point = (wxRealPoint *)first_line_node->Data();
+ wxNode *second_line_node = first_line_node->Next();
+ wxRealPoint *second_line_point = (wxRealPoint *)second_line_node->Data();
+
+ wxNode *last_line_node = m_lineControlPoints->Last();
+ wxRealPoint *last_line_point = (wxRealPoint *)last_line_node->Data();
+ wxNode *second_last_line_node = last_line_node->Previous();
+ wxRealPoint *second_last_line_point = (wxRealPoint *)second_last_line_node->Data();
+
+ // Position where we want to start drawing
+ double positionOnLineX, positionOnLineY;
+
+ // Position of start point of line, at the end of which we draw the arrow.
+ double startPositionX, startPositionY;
+
+ switch (arrow->GetPosition())
+ {
+ case ARROW_POSITION_START:
+ {
+ // If we're using a proportional offset, calculate just where this will
+ // be on the line.
+ double realOffset = xOffset;
+ if (proportionalOffset)
+ {
+ double totalLength =
+ (double)sqrt((second_line_point->x - first_line_point->x)*(second_line_point->x - first_line_point->x) +
+ (second_line_point->y - first_line_point->y)*(second_line_point->y - first_line_point->y));
+ realOffset = (double)(xOffset * totalLength);
+ }
+ GetPointOnLine(second_line_point->x, second_line_point->y,
+ first_line_point->x, first_line_point->y,
+ realOffset, &positionOnLineX, &positionOnLineY);
+ startPositionX = second_line_point->x;
+ startPositionY = second_line_point->y;
+ break;
+ }
+ case ARROW_POSITION_END:
+ {
+ // If we're using a proportional offset, calculate just where this will
+ // be on the line.
+ double realOffset = xOffset;
+ if (proportionalOffset)
+ {
+ double totalLength =
+ (double)sqrt((second_last_line_point->x - last_line_point->x)*(second_last_line_point->x - last_line_point->x) +
+ (second_last_line_point->y - last_line_point->y)*(second_last_line_point->y - last_line_point->y));
+ realOffset = (double)(xOffset * totalLength);
+ }
+ GetPointOnLine(second_last_line_point->x, second_last_line_point->y,
+ last_line_point->x, last_line_point->y,
+ realOffset, &positionOnLineX, &positionOnLineY);
+ startPositionX = second_last_line_point->x;
+ startPositionY = second_last_line_point->y;
+ break;
+ }
+ case ARROW_POSITION_MIDDLE:
+ {
+ // Choose a point half way between the last and penultimate points
+ double x = ((last_line_point->x + second_last_line_point->x)/2);
+ double y = ((last_line_point->y + second_last_line_point->y)/2);
+
+ // If we're using a proportional offset, calculate just where this will
+ // be on the line.
+ double realOffset = xOffset;
+ if (proportionalOffset)
+ {
+ double totalLength =
+ (double)sqrt((second_last_line_point->x - x)*(second_last_line_point->x - x) +
+ (second_last_line_point->y - y)*(second_last_line_point->y - y));
+ realOffset = (double)(xOffset * totalLength);
+ }
+
+ GetPointOnLine(second_last_line_point->x, second_last_line_point->y,
+ x, y, realOffset, &positionOnLineX, &positionOnLineY);
+ startPositionX = second_last_line_point->x;
+ startPositionY = second_last_line_point->y;
+ break;
+ }
+ }
+
+ /*
+ * Add yOffset to arrow, if any
+ */
+
+ const double myPi = (double) 3.14159265;
+ // The translation that the y offset may give
+ double deltaX = 0.0;
+ double deltaY = 0.0;
+ if ((arrow->GetYOffset() != 0.0) && !m_ignoreArrowOffsets)
+ {
+ /*
+ |(x4, y4)
+ |d
+ |
+ (x1, y1)--------------(x3, y3)------------------(x2, y2)
+ x4 = x3 - d * sin(theta)
+ y4 = y3 + d * cos(theta)
+
+ Where theta = tan(-1) of (y3-y1)/(x3-x1)
+ */
+ double x1 = startPositionX;
+ double y1 = startPositionY;
+ double x3 = positionOnLineX;
+ double y3 = positionOnLineY;
+ double d = -arrow->GetYOffset(); // Negate so +offset is above line
+
+ double theta = 0.0;
+ if (x3 == x1)
+ theta = (double)(myPi/2.0);
+ else
+ theta = (double)atan((y3-y1)/(x3-x1));
+
+ double x4 = (double)(x3 - (d*sin(theta)));
+ double y4 = (double)(y3 + (d*cos(theta)));
+
+ deltaX = x4 - positionOnLineX;
+ deltaY = y4 - positionOnLineY;
+ }
+
+ switch (arrow->_GetType())
+ {
+ case ARROW_ARROW:
+ {
+ double arrowLength = arrow->GetSize();
+ double arrowWidth = (double)(arrowLength/3.0);
+
+ double tip_x, tip_y, side1_x, side1_y, side2_x, side2_y;
+ oglGetArrowPoints(startPositionX+deltaX, startPositionY+deltaY,
+ positionOnLineX+deltaX, positionOnLineY+deltaY,
+ arrowLength, arrowWidth, &tip_x, &tip_y,
+ &side1_x, &side1_y, &side2_x, &side2_y);
+
+ wxPoint points[4];
+ points[0].x = (int) tip_x; points[0].y = (int) tip_y;
+ points[1].x = (int) side1_x; points[1].y = (int) side1_y;
+ points[2].x = (int) side2_x; points[2].y = (int) side2_y;
+ points[3].x = (int) tip_x; points[3].y = (int) tip_y;
+
+ dc.SetPen(* m_pen);
+ dc.SetBrush(* m_brush);
+ dc.DrawPolygon(4, points);
+ break;
+ }
+ case ARROW_HOLLOW_CIRCLE:
+ case ARROW_FILLED_CIRCLE:
+ {
+ // Find point on line of centre of circle, which is a radius away
+ // from the end position
+ double diameter = (double)(arrow->GetSize());
+ double x, y;
+ GetPointOnLine(startPositionX+deltaX, startPositionY+deltaY,
+ positionOnLineX+deltaX, positionOnLineY+deltaY,
+ (double)(diameter/2.0),
+ &x, &y);
+
+ // Convert ellipse centre to top-left coordinates
+ double x1 = (double)(x - (diameter/2.0));
+ double y1 = (double)(y - (diameter/2.0));
+
+ dc.SetPen(* m_pen);
+ if (arrow->_GetType() == ARROW_HOLLOW_CIRCLE)
+ dc.SetBrush(* g_oglWhiteBackgroundBrush);
+ else
+ dc.SetBrush(* m_brush);
+
+ dc.DrawEllipse((long) x1, (long) y1, (long) diameter, (long) diameter);
+ break;
+ }
+ case ARROW_SINGLE_OBLIQUE:
+ {
+ break;
+ }
+ case ARROW_METAFILE:
+ {
+ if (arrow->GetMetaFile())
+ {
+ // Find point on line of centre of object, which is a half-width away
+ // from the end position
+ /*
+ * width
+ * <-- start pos <-----><-- positionOnLineX
+ * _____
+ * --------------| x | <-- e.g. rectangular arrowhead
+ * -----
+ */
+ double x, y;
+ GetPointOnLine(startPositionX, startPositionY,
+ positionOnLineX, positionOnLineY,
+ (double)(arrow->GetMetaFile()->m_width/2.0),
+ &x, &y);
+
+ // Calculate theta for rotating the metafile.
+ /*
+ |
+ | o(x2, y2) 'o' represents the arrowhead.
+ | /
+ | /
+ | /theta
+ | /(x1, y1)
+ |______________________
+ */
+ double theta = 0.0;
+ double x1 = startPositionX;
+ double y1 = startPositionY;
+ double x2 = positionOnLineX;
+ double y2 = positionOnLineY;
+
+ if ((x1 == x2) && (y1 == y2))
+ theta = 0.0;
+
+ else if ((x1 == x2) && (y1 > y2))
+ theta = (double)(3.0*myPi/2.0);
+
+ else if ((x1 == x2) && (y2 > y1))
+ theta = (double)(myPi/2.0);
+
+ else if ((x2 > x1) && (y2 >= y1))
+ theta = (double)atan((y2 - y1)/(x2 - x1));
+
+ else if (x2 < x1)
+ theta = (double)(myPi + atan((y2 - y1)/(x2 - x1)));
+
+ else if ((x2 > x1) && (y2 < y1))
+ theta = (double)(2*myPi + atan((y2 - y1)/(x2 - x1)));
+
+ else
+ {
+ wxFatalError("Unknown arrowhead rotation case in lines.cc");
+ }
+
+ // Rotate about the centre of the object, then place
+ // the object on the line.
+ if (arrow->GetMetaFile()->GetRotateable())
+ arrow->GetMetaFile()->Rotate(0.0, 0.0, theta);
+
+ if (m_erasing)
+ {
+ // If erasing, just draw a rectangle.
+ double minX, minY, maxX, maxY;
+ arrow->GetMetaFile()->GetBounds(&minX, &minY, &maxX, &maxY);
+ // Make erasing rectangle slightly bigger or you get droppings.
+ int extraPixels = 4;
+ dc.DrawRectangle((long)(deltaX + x + minX - (extraPixels/2.0)), (long)(deltaY + y + minY - (extraPixels/2.0)),
+ (long)(maxX - minX + extraPixels), (long)(maxY - minY + extraPixels));
+ }
+ else
+ arrow->GetMetaFile()->Draw(dc, x+deltaX, y+deltaY);
+ }
+ break;
+ }
+ default:
+ {
+ }
+ }
+}
+
+void wxLineShape::OnErase(wxDC& dc)
+{
+ wxPen *old_pen = m_pen;
+ wxBrush *old_brush = m_brush;
+ SetPen(g_oglWhiteBackgroundPen);
+ SetBrush(g_oglWhiteBackgroundBrush);
+
+ double bound_x, bound_y;
+ GetBoundingBoxMax(&bound_x, &bound_y);
+ if (m_font) dc.SetFont(* m_font);
+
+ // Undraw text regions
+ for (int i = 0; i < 3; i++)
+ {
+ wxNode *node = m_regions.Nth(i);
+ if (node)
+ {
+ double x, y;
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ GetLabelPosition(i, &x, &y);
+ EraseRegion(dc, region, x, y);
+ }
+ }
+
+ // Undraw line
+ dc.SetPen(* g_oglWhiteBackgroundPen);
+ dc.SetBrush(* g_oglWhiteBackgroundBrush);
+
+ // Drawing over the line only seems to work if the line has a thickness
+ // of 1.
+ if (old_pen && (old_pen->GetWidth() > 1))
+ {
+ dc.DrawRectangle((long)(m_xpos - (bound_x/2.0) - 2.0), (long)(m_ypos - (bound_y/2.0) - 2.0),
+ (long)(bound_x+4.0), (long)(bound_y+4.0));
+ }
+ else
+ {
+ m_erasing = TRUE;
+ GetEventHandler()->OnDraw(dc);
+ GetEventHandler()->OnEraseControlPoints(dc);
+ m_erasing = FALSE;
+ }
+
+ if (old_pen) SetPen(old_pen);
+ if (old_brush) SetBrush(old_brush);
+}
+
+void wxLineShape::GetBoundingBoxMin(double *w, double *h)
+{
+ double x1 = 10000;
+ double y1 = 10000;
+ double x2 = -10000;
+ double y2 = -10000;
+
+ wxNode *node = m_lineControlPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+
+ if (point->x < x1) x1 = point->x;
+ if (point->y < y1) y1 = point->y;
+ if (point->x > x2) x2 = point->x;
+ if (point->y > y2) y2 = point->y;
+
+ node = node->Next();
+ }
+ *w = (double)(x2 - x1);
+ *h = (double)(y2 - y1);
+}
+
+/*
+ * For a node image of interest, finds the position of this arc
+ * amongst all the arcs which are attached to THIS SIDE of the node image,
+ * and the number of same.
+ */
+void wxLineShape::FindNth(wxShape *image, int *nth, int *no_arcs, bool incoming)
+{
+ int n = -1;
+ int num = 0;
+ wxNode *node = image->GetLines().First();
+ int this_attachment;
+ if (image == m_to)
+ this_attachment = m_attachmentTo;
+ else
+ this_attachment = m_attachmentFrom;
+
+ // Find number of lines going into/out of this particular attachment point
+ while (node)
+ {
+ wxLineShape *line = (wxLineShape *)node->Data();
+
+ if (line->m_from == image)
+ {
+ // This is the nth line attached to 'image'
+ if ((line == this) && !incoming)
+ n = num;
+
+ // Increment num count if this is the same side (attachment number)
+ if (line->m_attachmentFrom == this_attachment)
+ num ++;
+ }
+
+ if (line->m_to == image)
+ {
+ // This is the nth line attached to 'image'
+ if ((line == this) && incoming)
+ n = num;
+
+ // Increment num count if this is the same side (attachment number)
+ if (line->m_attachmentTo == this_attachment)
+ num ++;
+ }
+
+ node = node->Next();
+ }
+ *nth = n;
+ *no_arcs = num;
+}
+
+void wxLineShape::OnDrawOutline(wxDC& dc, double x, double y, double w, double h)
+{
+ wxPen *old_pen = m_pen;
+ wxBrush *old_brush = m_brush;
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ SetPen(& dottedPen);
+ SetBrush( wxTRANSPARENT_BRUSH );
+
+ GetEventHandler()->OnDraw(dc);
+
+ if (old_pen) SetPen(old_pen);
+ else SetPen(NULL);
+ if (old_brush) SetBrush(old_brush);
+ else SetBrush(NULL);
+}
+
+bool wxLineShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+ double x_offset = x - old_x;
+ double y_offset = y - old_y;
+
+ if (m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
+ {
+ wxNode *node = m_lineControlPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ point->x += x_offset;
+ point->y += y_offset;
+ node = node->Next();
+ }
+
+ }
+
+ // Move temporary label rectangles if necessary
+ for (int i = 0; i < 3; i++)
+ {
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Erase(dc);
+ double xp, yp, xr, yr;
+ GetLabelPosition(i, &xp, &yp);
+ wxNode *node = m_regions.Nth(i);
+ if (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ region->GetPosition(&xr, &yr);
+ }
+ else
+ {
+ xr = 0.0; yr = 0.0;
+ }
+
+ m_labelObjects[i]->Move(dc, xp+xr, yp+yr);
+ }
+ }
+ return TRUE;
+}
+
+void wxLineShape::OnMoveLink(wxDC& dc, bool moveControlPoints)
+{
+ if (!m_from || !m_to)
+ return;
+
+ if (m_lineControlPoints->Number() > 2)
+ Initialise();
+
+ // Do each end - nothing in the middle. User has to move other points
+ // manually if necessary.
+ double end_x, end_y;
+ double other_end_x, other_end_y;
+
+ FindLineEndPoints(&end_x, &end_y, &other_end_x, &other_end_y);
+
+ wxNode *first = m_lineControlPoints->First();
+ wxRealPoint *first_point = (wxRealPoint *)first->Data();
+ wxNode *last = m_lineControlPoints->Last();
+ wxRealPoint *last_point = (wxRealPoint *)last->Data();
+
+/* This is redundant, surely? Done by SetEnds.
+ first_point->x = end_x; first_point->y = end_y;
+ last_point->x = other_end_x; last_point->y = other_end_y;
+*/
+
+ double oldX = m_xpos;
+ double oldY = m_ypos;
+
+ SetEnds(end_x, end_y, other_end_x, other_end_y);
+
+ // Do a second time, because one may depend on the other.
+ FindLineEndPoints(&end_x, &end_y, &other_end_x, &other_end_y);
+ SetEnds(end_x, end_y, other_end_x, other_end_y);
+
+ // Try to move control points with the arc
+ double x_offset = m_xpos - oldX;
+ double y_offset = m_ypos - oldY;
+
+// if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
+ // Only move control points if it's a self link. And only works if attachment mode is ON.
+ if ((m_from == m_to) && (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE) && moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
+ {
+ wxNode *node = m_lineControlPoints->First();
+ while (node)
+ {
+ if ((node != m_lineControlPoints->First()) && (node != m_lineControlPoints->Last()))
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ point->x += x_offset;
+ point->y += y_offset;
+ }
+ node = node->Next();
+ }
+ }
+
+ Move(dc, m_xpos, m_ypos);
+}
+
+// Finds the x, y points at the two ends of the line.
+// This function can be used by e.g. line-routing routines to
+// get the actual points on the two node images where the lines will be drawn
+// to/from.
+void wxLineShape::FindLineEndPoints(double *fromX, double *fromY, double *toX, double *toY)
+{
+ if (!m_from || !m_to)
+ return;
+
+ // Do each end - nothing in the middle. User has to move other points
+ // manually if necessary.
+ double end_x, end_y;
+ double other_end_x, other_end_y;
+
+ wxNode *first = m_lineControlPoints->First();
+ wxRealPoint *first_point = (wxRealPoint *)first->Data();
+ wxNode *last = m_lineControlPoints->Last();
+ wxRealPoint *last_point = (wxRealPoint *)last->Data();
+
+ wxNode *second = first->Next();
+ wxRealPoint *second_point = (wxRealPoint *)second->Data();
+
+ wxNode *second_last = last->Previous();
+ wxRealPoint *second_last_point = (wxRealPoint *)second_last->Data();
+
+ if (m_lineControlPoints->Number() > 2)
+ {
+ if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
+ {
+ int nth, no_arcs;
+ FindNth(m_from, &nth, &no_arcs, FALSE); // Not incoming
+ m_from->GetAttachmentPosition(m_attachmentFrom, &end_x, &end_y, nth, no_arcs, this);
+ }
+ else
+ (void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(),
+ (double)second_point->x, (double)second_point->y,
+ &end_x, &end_y);
+
+ if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
+ {
+ int nth, no_arcs;
+ FindNth(m_to, &nth, &no_arcs, TRUE); // Incoming
+ m_to->GetAttachmentPosition(m_attachmentTo, &other_end_x, &other_end_y, nth, no_arcs, this);
+ }
+ else
+ (void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(),
+ (double)second_last_point->x, (double)second_last_point->y,
+ &other_end_x, &other_end_y);
+ }
+ else
+ {
+ double fromX = m_from->GetX();
+ double fromY = m_from->GetY();
+ double toX = m_to->GetX();
+ double toY = m_to->GetY();
+
+ if (m_from->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
+ {
+ int nth, no_arcs;
+ FindNth(m_from, &nth, &no_arcs, FALSE);
+ m_from->GetAttachmentPosition(m_attachmentFrom, &end_x, &end_y, nth, no_arcs, this);
+ fromX = end_x;
+ fromY = end_y;
+ }
+
+ if (m_to->GetAttachmentMode() != ATTACHMENT_MODE_NONE)
+ {
+ int nth, no_arcs;
+ FindNth(m_to, &nth, &no_arcs, TRUE);
+ m_to->GetAttachmentPosition(m_attachmentTo, &other_end_x, &other_end_y, nth, no_arcs, this);
+ toX = other_end_x;
+ toY = other_end_y;
+ }
+
+ if (m_from->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
+ (void) m_from->GetPerimeterPoint(m_from->GetX(), m_from->GetY(),
+ toX, toY,
+ &end_x, &end_y);
+
+ if (m_to->GetAttachmentMode() == ATTACHMENT_MODE_NONE)
+ (void) m_to->GetPerimeterPoint(m_to->GetX(), m_to->GetY(),
+ fromX, fromY,
+ &other_end_x, &other_end_y);
+ }
+ *fromX = end_x;
+ *fromY = end_y;
+ *toX = other_end_x;
+ *toY = other_end_y;
+}
+
+void wxLineShape::OnDraw(wxDC& dc)
+{
+ if (m_lineControlPoints)
+ {
+ if (m_pen)
+ dc.SetPen(* m_pen);
+ if (m_brush)
+ dc.SetBrush(* m_brush);
+
+ int n = m_lineControlPoints->Number();
+ wxPoint *points = new wxPoint[n];
+ int i;
+ for (i = 0; i < n; i++)
+ {
+ wxRealPoint* point = (wxRealPoint*) m_lineControlPoints->Nth(i)->Data();
+ points[i].x = WXROUND(point->x);
+ points[i].y = WXROUND(point->y);
+ }
+
+ if (m_isSpline)
+ dc.DrawSpline(n, points);
+ else
+ dc.DrawLines(n, points);
+
+#ifdef __WXMSW__
+ // For some reason, last point isn't drawn under Windows.
+ dc.DrawPoint(points[n-1]);
+#endif
+
+ delete[] points;
+
+
+ // Problem with pen - if not a solid pen, does strange things
+ // to the arrowhead. So make (get) a new pen that's solid.
+ if (m_pen && (m_pen->GetStyle() != wxSOLID))
+ {
+ wxPen *solid_pen =
+ wxThePenList->FindOrCreatePen(m_pen->GetColour(), 1, wxSOLID);
+ if (solid_pen)
+ dc.SetPen(* solid_pen);
+ }
+ DrawArrows(dc);
+ }
+}
+
+void wxLineShape::OnDrawControlPoints(wxDC& dc)
+{
+ if (!m_drawHandles)
+ return;
+
+ // Draw temporary label rectangles if necessary
+ for (int i = 0; i < 3; i++)
+ {
+ if (m_labelObjects[i])
+ m_labelObjects[i]->Draw(dc);
+ }
+ wxShape::OnDrawControlPoints(dc);
+}
+
+void wxLineShape::OnEraseControlPoints(wxDC& dc)
+{
+ // Erase temporary label rectangles if necessary
+ for (int i = 0; i < 3; i++)
+ {
+ if (m_labelObjects[i])
+ m_labelObjects[i]->Erase(dc);
+ }
+ wxShape::OnEraseControlPoints(dc);
+}
+
+void wxLineShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+}
+
+void wxLineShape::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+}
+
+void wxLineShape::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+}
+
+/*
+void wxLineShape::SetArrowSize(double length, double width)
+{
+ arrow_length = length;
+ arrow_width = width;
+}
+
+void wxLineShape::SetStartArrow(int style)
+{
+ start_style = style;
+}
+
+void wxLineShape::SetMiddleArrow(int style)
+{
+ middle_style = style;
+}
+
+void wxLineShape::SetEndArrow(int style)
+{
+ end_style = style;
+}
+*/
+
+void wxLineShape::OnDrawContents(wxDC& dc)
+{
+ if (GetDisableLabel())
+ return;
+
+ for (int i = 0; i < 3; i++)
+ {
+ wxNode *node = m_regions.Nth(i);
+ if (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ double x, y;
+ GetLabelPosition(i, &x, &y);
+ DrawRegion(dc, region, x, y);
+ }
+ }
+}
+
+void wxLineShape::SetTo(wxShape *object)
+{
+ m_to = object;
+}
+
+void wxLineShape::SetFrom(wxShape *object)
+{
+ m_from = object;
+}
+
+void wxLineShape::MakeControlPoints()
+{
+ if (m_canvas && m_lineControlPoints)
+ {
+ wxNode *first = m_lineControlPoints->First();
+ wxNode *last = m_lineControlPoints->Last();
+ wxRealPoint *first_point = (wxRealPoint *)first->Data();
+ wxRealPoint *last_point = (wxRealPoint *)last->Data();
+
+ wxLineControlPoint *control = new wxLineControlPoint(m_canvas, this, CONTROL_POINT_SIZE,
+ first_point->x, first_point->y,
+ CONTROL_POINT_ENDPOINT_FROM);
+ control->m_point = first_point;
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+
+ wxNode *node = first->Next();
+ while (node != last)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+
+ control = new wxLineControlPoint(m_canvas, this, CONTROL_POINT_SIZE,
+ point->x, point->y,
+ CONTROL_POINT_LINE);
+ control->m_point = point;
+
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ node = node->Next();
+ }
+ control = new wxLineControlPoint(m_canvas, this, CONTROL_POINT_SIZE,
+ last_point->x, last_point->y,
+ CONTROL_POINT_ENDPOINT_TO);
+ control->m_point = last_point;
+ m_canvas->AddShape(control);
+ m_controlPoints.Append(control);
+
+ }
+
+}
+
+void wxLineShape::ResetControlPoints()
+{
+ if (m_canvas && m_lineControlPoints && m_controlPoints.Number() > 0)
+ {
+ wxNode *node = m_controlPoints.First();
+ wxNode *control_node = m_lineControlPoints->First();
+ while (node && control_node)
+ {
+ wxRealPoint *point = (wxRealPoint *)control_node->Data();
+ wxLineControlPoint *control = (wxLineControlPoint *)node->Data();
+ control->SetX(point->x);
+ control->SetY(point->y);
+
+ node = node->Next();
+ control_node = control_node->Next();
+ }
+ }
+}
+
+#ifdef PROLOGIO
+void wxLineShape::WriteAttributes(wxExpr *clause)
+{
+ wxShape::WriteAttributes(clause);
+
+ if (m_from)
+ clause->AddAttributeValue("from", m_from->GetId());
+ if (m_to)
+ clause->AddAttributeValue("to", m_to->GetId());
+
+ if (m_attachmentTo != 0)
+ clause->AddAttributeValue("attachment_to", (long)m_attachmentTo);
+ if (m_attachmentFrom != 0)
+ clause->AddAttributeValue("attachment_from", (long)m_attachmentFrom);
+
+ if (m_alignmentStart != 0)
+ clause->AddAttributeValue("align_start", (long)m_alignmentStart);
+ if (m_alignmentEnd != 0)
+ clause->AddAttributeValue("align_end", (long)m_alignmentEnd);
+
+ clause->AddAttributeValue("is_spline", (long)m_isSpline);
+ if (m_maintainStraightLines)
+ clause->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines);
+
+ // Make a list of lists for the (sp)line controls
+ wxExpr *list = new wxExpr(wxExprList);
+ wxNode *node = m_lineControlPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxExpr *point_list = new wxExpr(wxExprList);
+ wxExpr *x_expr = new wxExpr((double) point->x);
+ wxExpr *y_expr = new wxExpr((double) point->y);
+ point_list->Append(x_expr);
+ point_list->Append(y_expr);
+ list->Append(point_list);
+
+ node = node->Next();
+ }
+ clause->AddAttributeValue("controls", list);
+
+ // Write arc arrows in new OGL format, if there are any.
+ // This is a list of lists. Each sublist comprises:
+ // (arrowType arrowEnd xOffset arrowSize)
+ if (m_arcArrows.Number() > 0)
+ {
+ wxExpr *arrow_list = new wxExpr(wxExprList);
+ node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *head = (wxArrowHead *)node->Data();
+ wxExpr *head_list = new wxExpr(wxExprList);
+ head_list->Append(new wxExpr((long)head->_GetType()));
+ head_list->Append(new wxExpr((long)head->GetArrowEnd()));
+ head_list->Append(new wxExpr(head->GetXOffset()));
+ head_list->Append(new wxExpr(head->GetArrowSize()));
+ head_list->Append(new wxExpr(wxExprString, head->GetName()));
+ head_list->Append(new wxExpr(head->GetId()));
+
+ // New members of wxArrowHead
+ head_list->Append(new wxExpr(head->GetYOffset()));
+ head_list->Append(new wxExpr(head->GetSpacing()));
+
+ arrow_list->Append(head_list);
+
+ node = node->Next();
+ }
+ clause->AddAttributeValue("arrows", arrow_list);
+ }
+}
+
+void wxLineShape::ReadAttributes(wxExpr *clause)
+{
+ wxShape::ReadAttributes(clause);
+
+ int iVal = (int) m_isSpline;
+ clause->AssignAttributeValue("is_spline", &iVal);
+ m_isSpline = (iVal != 0);
+
+ iVal = (int) m_maintainStraightLines;
+ clause->AssignAttributeValue("keep_lines_straight", &iVal);
+ m_maintainStraightLines = (iVal != 0);
+
+ clause->AssignAttributeValue("align_start", &m_alignmentStart);
+ clause->AssignAttributeValue("align_end", &m_alignmentEnd);
+
+ // Compatibility: check for no regions.
+ if (m_regions.Number() == 0)
+ {
+ wxShapeRegion *newRegion = new wxShapeRegion;
+ newRegion->SetName("Middle");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+ if (m_text.Number() > 0)
+ {
+ newRegion->ClearText();
+ wxNode *node = m_text.First();
+ while (node)
+ {
+ wxShapeTextLine *textLine = (wxShapeTextLine *)node->Data();
+ wxNode *next = node->Next();
+ newRegion->GetFormattedText().Append((wxObject *)textLine);
+ delete node;
+ node = next;
+ }
+ }
+
+ newRegion = new wxShapeRegion;
+ newRegion->SetName("Start");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+
+ newRegion = new wxShapeRegion;
+ newRegion->SetName("End");
+ newRegion->SetSize(150, 50);
+ m_regions.Append((wxObject *)newRegion);
+ }
+
+ m_attachmentTo = 0;
+ m_attachmentFrom = 0;
+
+ clause->AssignAttributeValue("attachment_to", &m_attachmentTo);
+ clause->AssignAttributeValue("attachment_from", &m_attachmentFrom);
+
+ wxExpr *line_list = NULL;
+
+ // When image is created, there are default control points. Override
+ // them if there are some in the file.
+ clause->AssignAttributeValue("controls", &line_list);
+
+ if (line_list)
+ {
+ // Read a list of lists for the spline controls
+ if (m_lineControlPoints)
+ {
+ ClearPointList(*m_lineControlPoints);
+ }
+ else
+ m_lineControlPoints = new wxList;
+
+ wxExpr *node = line_list->value.first;
+
+ while (node)
+ {
+ wxExpr *xexpr = node->value.first;
+ double x = xexpr->RealValue();
+
+ wxExpr *yexpr = xexpr->next;
+ double y = yexpr->RealValue();
+
+ wxRealPoint *point = new wxRealPoint(x, y);
+ m_lineControlPoints->Append((wxObject*) point);
+
+ node = node->next;
+ }
+ }
+
+ // Read arrow list, for new OGL code
+ wxExpr *arrow_list = NULL;
+
+ clause->AssignAttributeValue("arrows", &arrow_list);
+ if (arrow_list)
+ {
+ wxExpr *node = arrow_list->value.first;
+
+ while (node)
+ {
+ WXTYPE arrowType = ARROW_ARROW;
+ int arrowEnd = 0;
+ double xOffset = 0.0;
+ double arrowSize = 0.0;
+ wxString arrowName("");
+ long arrowId = -1;
+
+ wxExpr *type_expr = node->Nth(0);
+ wxExpr *end_expr = node->Nth(1);
+ wxExpr *dist_expr = node->Nth(2);
+ wxExpr *size_expr = node->Nth(3);
+ wxExpr *name_expr = node->Nth(4);
+ wxExpr *id_expr = node->Nth(5);
+
+ // New members of wxArrowHead
+ wxExpr *yOffsetExpr = node->Nth(6);
+ wxExpr *spacingExpr = node->Nth(7);
+
+ if (type_expr)
+ arrowType = (int)type_expr->IntegerValue();
+ if (end_expr)
+ arrowEnd = (int)end_expr->IntegerValue();
+ if (dist_expr)
+ xOffset = dist_expr->RealValue();
+ if (size_expr)
+ arrowSize = size_expr->RealValue();
+ if (name_expr)
+ arrowName = name_expr->StringValue();
+ if (id_expr)
+ arrowId = id_expr->IntegerValue();
+
+ if (arrowId == -1)
+ arrowId = wxNewId();
+ else
+ wxRegisterId(arrowId);
+
+ wxArrowHead *arrowHead = AddArrow(arrowType, arrowEnd, arrowSize, xOffset, (char*) (const char*) arrowName, NULL, arrowId);
+ if (yOffsetExpr)
+ arrowHead->SetYOffset(yOffsetExpr->RealValue());
+ if (spacingExpr)
+ arrowHead->SetSpacing(spacingExpr->RealValue());
+
+ node = node->next;
+ }
+ }
+}
+#endif
+
+void wxLineShape::Copy(wxShape& copy)
+{
+ wxShape::Copy(copy);
+
+ wxASSERT( copy.IsKindOf(CLASSINFO(wxLineShape)) );
+
+ wxLineShape& lineCopy = (wxLineShape&) copy;
+
+ lineCopy.m_to = m_to;
+ lineCopy.m_from = m_from;
+ lineCopy.m_attachmentTo = m_attachmentTo;
+ lineCopy.m_attachmentFrom = m_attachmentFrom;
+ lineCopy.m_isSpline = m_isSpline;
+ lineCopy.m_alignmentStart = m_alignmentStart;
+ lineCopy.m_alignmentEnd = m_alignmentEnd;
+ lineCopy.m_maintainStraightLines = m_maintainStraightLines;
+ lineCopy.m_lineOrientations.Clear();
+
+ wxNode *node = m_lineOrientations.First();
+ while (node)
+ {
+ lineCopy.m_lineOrientations.Append(node->Data());
+ node = node->Next();
+ }
+
+ if (lineCopy.m_lineControlPoints)
+ {
+ ClearPointList(*lineCopy.m_lineControlPoints);
+ delete lineCopy.m_lineControlPoints;
+ }
+
+ lineCopy.m_lineControlPoints = new wxList;
+
+ node = m_lineControlPoints->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ wxRealPoint *new_point = new wxRealPoint(point->x, point->y);
+ lineCopy.m_lineControlPoints->Append((wxObject*) new_point);
+ node = node->Next();
+ }
+
+ // Copy arrows
+ lineCopy.ClearArrowsAtPosition(-1);
+ node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ lineCopy.m_arcArrows.Append(new wxArrowHead(*arrow));
+ node = node->Next();
+ }
+}
+
+// Override select, to create/delete temporary label-moving objects
+void wxLineShape::Select(bool select, wxDC* dc)
+{
+ wxShape::Select(select, dc);
+ if (select)
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ wxNode *node = m_regions.Nth(i);
+ if (node)
+ {
+ wxShapeRegion *region = (wxShapeRegion *)node->Data();
+ if (region->m_formattedText.Number() > 0)
+ {
+ double w, h, x, y, xx, yy;
+ region->GetSize(&w, &h);
+ region->GetPosition(&x, &y);
+ GetLabelPosition(i, &xx, &yy);
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Select(FALSE);
+ m_labelObjects[i]->RemoveFromCanvas(m_canvas);
+ delete m_labelObjects[i];
+ }
+ m_labelObjects[i] = OnCreateLabelShape(this, region, w, h);
+ m_labelObjects[i]->AddToCanvas(m_canvas);
+ m_labelObjects[i]->Show(TRUE);
+ if (dc)
+ m_labelObjects[i]->Move(*dc, (double)(x + xx), (double)(y + yy));
+ m_labelObjects[i]->Select(TRUE, dc);
+ }
+ }
+ }
+ }
+ else
+ {
+ for (int i = 0; i < 3; i++)
+ {
+ if (m_labelObjects[i])
+ {
+ m_labelObjects[i]->Select(FALSE, dc);
+ m_labelObjects[i]->Erase(*dc);
+ m_labelObjects[i]->RemoveFromCanvas(m_canvas);
+ delete m_labelObjects[i];
+ m_labelObjects[i] = NULL;
+ }
+ }
+ }
+}
+
+/*
+ * Line control point
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint, wxControlPoint)
+
+wxLineControlPoint::wxLineControlPoint(wxShapeCanvas *theCanvas, wxShape *object, double size, double x, double y, int the_type):
+ wxControlPoint(theCanvas, object, size, x, y, the_type)
+{
+ m_xpos = x;
+ m_ypos = y;
+ m_type = the_type;
+ m_point = NULL;
+}
+
+wxLineControlPoint::~wxLineControlPoint()
+{
+}
+
+void wxLineControlPoint::OnDraw(wxDC& dc)
+{
+ wxRectangleShape::OnDraw(dc);
+}
+
+// Implement movement of Line point
+void wxLineControlPoint::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingDragLeft(this, draw, x, y, keys, attachment);
+}
+
+void wxLineControlPoint::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingBeginDragLeft(this, x, y, keys, attachment);
+}
+
+void wxLineControlPoint::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ m_shape->GetEventHandler()->OnSizingEndDragLeft(this, x, y, keys, attachment);
+}
+
+// Control points ('handles') redirect control to the actual shape, to make it easier
+// to override sizing behaviour.
+void wxLineShape::OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys, int attachment)
+{
+ wxLineControlPoint* lpt = (wxLineControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ dc.SetLogicalFunction(OGLRBLF);
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ if (lpt->m_type == CONTROL_POINT_LINE)
+ {
+ m_canvas->Snap(&x, &y);
+
+ lpt->SetX(x); lpt->SetY(y);
+ lpt->m_point->x = x; lpt->m_point->y = y;
+
+ wxLineShape *lineShape = (wxLineShape *)this;
+
+ wxPen *old_pen = lineShape->GetPen();
+ wxBrush *old_brush = lineShape->GetBrush();
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ lineShape->SetPen(& dottedPen);
+ lineShape->SetBrush(wxTRANSPARENT_BRUSH);
+
+ lineShape->GetEventHandler()->OnMoveLink(dc, FALSE);
+
+ lineShape->SetPen(old_pen);
+ lineShape->SetBrush(old_brush);
+ }
+
+ if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+// lpt->SetX(x); lpt->SetY(y);
+ }
+
+}
+
+void wxLineShape::OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ wxLineControlPoint* lpt = (wxLineControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxLineShape *lineShape = (wxLineShape *)this;
+ if (lpt->m_type == CONTROL_POINT_LINE)
+ {
+ lpt->m_originalPos = * (lpt->m_point);
+ m_canvas->Snap(&x, &y);
+
+ this->Erase(dc);
+
+ // Redraw start and end objects because we've left holes
+ // when erasing the line
+ lineShape->GetFrom()->OnDraw(dc);
+ lineShape->GetFrom()->OnDrawContents(dc);
+ lineShape->GetTo()->OnDraw(dc);
+ lineShape->GetTo()->OnDrawContents(dc);
+
+ this->SetDisableLabel(TRUE);
+ dc.SetLogicalFunction(OGLRBLF);
+
+ lpt->m_xpos = x; lpt->m_ypos = y;
+ lpt->m_point->x = x; lpt->m_point->y = y;
+
+ wxPen *old_pen = lineShape->GetPen();
+ wxBrush *old_brush = lineShape->GetBrush();
+
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ lineShape->SetPen(& dottedPen);
+ lineShape->SetBrush(wxTRANSPARENT_BRUSH);
+
+ lineShape->GetEventHandler()->OnMoveLink(dc, FALSE);
+
+ lineShape->SetPen(old_pen);
+ lineShape->SetBrush(old_brush);
+ }
+
+ if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+ m_canvas->SetCursor(* g_oglBullseyeCursor);
+ lpt->m_oldCursor = wxSTANDARD_CURSOR;
+ }
+}
+
+void wxLineShape::OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys, int attachment)
+{
+ wxLineControlPoint* lpt = (wxLineControlPoint*) pt;
+
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ this->SetDisableLabel(FALSE);
+ wxLineShape *lineShape = (wxLineShape *)this;
+
+ if (lpt->m_type == CONTROL_POINT_LINE)
+ {
+ m_canvas->Snap(&x, &y);
+
+ wxRealPoint pt = wxRealPoint(x, y);
+
+ // Move the control point back to where it was;
+ // MoveControlPoint will move it to the new position
+ // if it decides it wants. We only moved the position
+ // during user feedback so we could redraw the line
+ // as it changed shape.
+ lpt->m_xpos = lpt->m_originalPos.x; lpt->m_ypos = lpt->m_originalPos.y;
+ lpt->m_point->x = lpt->m_originalPos.x; lpt->m_point->y = lpt->m_originalPos.y;
+
+ OnMoveMiddleControlPoint(dc, lpt, pt);
+ }
+ if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM)
+ {
+ if (lpt->m_oldCursor)
+ m_canvas->SetCursor(* lpt->m_oldCursor);
+
+// this->Erase(dc);
+
+// lpt->m_xpos = x; lpt->m_ypos = y;
+
+ if (lineShape->GetFrom())
+ {
+ lineShape->GetFrom()->MoveLineToNewAttachment(dc, lineShape, x, y);
+ }
+ }
+ if (lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+ if (lpt->m_oldCursor)
+ m_canvas->SetCursor(* lpt->m_oldCursor);
+
+// lpt->m_xpos = x; lpt->m_ypos = y;
+
+ if (lineShape->GetTo())
+ {
+ lineShape->GetTo()->MoveLineToNewAttachment(dc, lineShape, x, y);
+ }
+ }
+
+ // Needed?
+#if 0
+ int i = 0;
+ for (i = 0; i < lineShape->GetLineControlPoints()->Number(); i++)
+ if (((wxRealPoint *)(lineShape->GetLineControlPoints()->Nth(i)->Data())) == lpt->m_point)
+ break;
+
+ // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
+ // the line and therefore deleted 'this'. -> GPF, intermittently.
+ // So assume at this point that we've been blown away.
+
+ lineShape->OnMoveControlPoint(i+1, x, y);
+#endif
+}
+
+// This is called only when a non-end control point is moved.
+bool wxLineShape::OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt)
+{
+ lpt->m_xpos = pt.x; lpt->m_ypos = pt.y;
+ lpt->m_point->x = pt.x; lpt->m_point->y = pt.y;
+
+ GetEventHandler()->OnMoveLink(dc);
+
+ return TRUE;
+}
+
+// Implement movement of endpoint to a new attachment
+// OBSOLETE: done by dragging with the left button.
+
+#if 0
+void wxLineControlPoint::OnDragRight(bool draw, double x, double y, int keys, int attachment)
+{
+ if (m_type == CONTROL_POINT_ENDPOINT_FROM || m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+ m_xpos = x; m_ypos = y;
+ }
+}
+
+void wxLineControlPoint::OnBeginDragRight(double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxLineShape *lineShape = (wxLineShape *)m_shape;
+ if (m_type == CONTROL_POINT_ENDPOINT_FROM || m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+ Erase(dc);
+ lineShape->GetEventHandler()->OnDraw(dc);
+ if (m_type == CONTROL_POINT_ENDPOINT_FROM)
+ {
+ lineShape->GetFrom()->GetEventHandler()->OnDraw(dc);
+ lineShape->GetFrom()->GetEventHandler()->OnDrawContents(dc);
+ }
+ else
+ {
+ lineShape->GetTo()->GetEventHandler()->OnDraw(dc);
+ lineShape->GetTo()->GetEventHandler()->OnDrawContents(dc);
+ }
+ m_canvas->SetCursor(g_oglBullseyeCursor);
+ m_oldCursor = wxSTANDARD_CURSOR;
+ }
+}
+
+void wxLineControlPoint::OnEndDragRight(double x, double y, int keys, int attachment)
+{
+ wxClientDC dc(GetCanvas());
+ GetCanvas()->PrepareDC(dc);
+
+ wxLineShape *lineShape = (wxLineShape *)m_shape;
+ if (m_type == CONTROL_POINT_ENDPOINT_FROM)
+ {
+ if (m_oldCursor)
+ m_canvas->SetCursor(m_oldCursor);
+
+ m_xpos = x; m_ypos = y;
+
+ if (lineShape->GetFrom())
+ {
+ lineShape->GetFrom()->EraseLinks(dc);
+
+ int new_attachment;
+ double distance;
+
+ if (lineShape->GetFrom()->HitTest(x, y, &new_attachment, &distance))
+ lineShape->SetAttachments(new_attachment, lineShape->GetAttachmentTo());
+
+ lineShape->GetFrom()->MoveLinks(dc);
+ }
+ }
+ if (m_type == CONTROL_POINT_ENDPOINT_TO)
+ {
+ if (m_oldCursor)
+ m_canvas->SetCursor(m_oldCursor);
+ m_shape->Erase(dc);
+
+ m_xpos = x; m_ypos = y;
+
+ if (lineShape->GetTo())
+ {
+ lineShape->GetTo()->EraseLinks(dc);
+
+ int new_attachment;
+ double distance;
+ if (lineShape->GetTo()->HitTest(x, y, &new_attachment, &distance))
+ lineShape->SetAttachments(lineShape->GetAttachmentFrom(), new_attachment);
+
+ lineShape->GetTo()->MoveLinks(dc);
+ }
+ }
+ int i = 0;
+ for (i = 0; i < lineShape->GetLineControlPoints()->Number(); i++)
+ if (((wxRealPoint *)(lineShape->GetLineControlPoints()->Nth(i)->Data())) == m_point)
+ break;
+ lineShape->OnMoveControlPoint(i+1, x, y);
+ if (!m_canvas->GetQuickEditMode()) m_canvas->Redraw(dc);
+}
+#endif
+
+/*
+ * Get the point on the given line (x1, y1) (x2, y2)
+ * distance 'length' along from the end,
+ * returned values in x and y
+ */
+
+void GetPointOnLine(double x1, double y1, double x2, double y2,
+ double length, double *x, double *y)
+{
+ double l = (double)sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+
+ if (l < 0.01)
+ l = (double) 0.01;
+
+ double i_bar = (x2 - x1)/l;
+ double j_bar = (y2 - y1)/l;
+
+ *x = (- length*i_bar) + x2;
+ *y = (- length*j_bar) + y2;
+}
+
+wxArrowHead *wxLineShape::AddArrow(WXTYPE type, int end, double size, double xOffset,
+ const wxString& name, wxPseudoMetaFile *mf, long arrowId)
+{
+ wxArrowHead *arrow = new wxArrowHead(type, end, size, xOffset, name, mf, arrowId);
+ m_arcArrows.Append(arrow);
+ return arrow;
+}
+
+/*
+ * Add arrowhead at a particular position in the arrowhead list.
+ */
+bool wxLineShape::AddArrowOrdered(wxArrowHead *arrow, wxList& referenceList, int end)
+{
+ wxNode *refNode = referenceList.First();
+ wxNode *currNode = m_arcArrows.First();
+ wxString targetName(arrow->GetName());
+ if (!refNode) return FALSE;
+
+ // First check whether we need to insert in front of list,
+ // because this arrowhead is the first in the reference
+ // list and should therefore be first in the current list.
+ wxArrowHead *refArrow = (wxArrowHead *)refNode->Data();
+ if (refArrow->GetName() == targetName)
+ {
+ m_arcArrows.Insert(arrow);
+ return TRUE;
+ }
+
+ while (refNode && currNode)
+ {
+ wxArrowHead *currArrow = (wxArrowHead *)currNode->Data();
+ refArrow = (wxArrowHead *)refNode->Data();
+
+ // Matching: advance current arrow pointer
+ if ((currArrow->GetArrowEnd() == end) &&
+ (currArrow->GetName() == refArrow->GetName()))
+ {
+ currNode = currNode->Next(); // Could be NULL now
+ if (currNode)
+ currArrow = (wxArrowHead *)currNode->Data();
+ }
+
+ // Check if we're at the correct position in the
+ // reference list
+ if (targetName == refArrow->GetName())
+ {
+ if (currNode)
+ m_arcArrows.Insert(currNode, arrow);
+ else
+ m_arcArrows.Append(arrow);
+ return TRUE;
+ }
+ refNode = refNode->Next();
+ }
+ m_arcArrows.Append(arrow);
+ return TRUE;
+}
+
+void wxLineShape::ClearArrowsAtPosition(int end)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ wxNode *next = node->Next();
+ switch (end)
+ {
+ case -1:
+ {
+ delete arrow;
+ delete node;
+ break;
+ }
+ case ARROW_POSITION_START:
+ {
+ if (arrow->GetArrowEnd() == ARROW_POSITION_START)
+ {
+ delete arrow;
+ delete node;
+ }
+ break;
+ }
+ case ARROW_POSITION_END:
+ {
+ if (arrow->GetArrowEnd() == ARROW_POSITION_END)
+ {
+ delete arrow;
+ delete node;
+ }
+ break;
+ }
+ case ARROW_POSITION_MIDDLE:
+ {
+ if (arrow->GetArrowEnd() == ARROW_POSITION_MIDDLE)
+ {
+ delete arrow;
+ delete node;
+ }
+ break;
+ }
+ }
+ node = next;
+ }
+}
+
+bool wxLineShape::ClearArrow(const wxString& name)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ if (arrow->GetName() == name)
+ {
+ delete arrow;
+ delete node;
+ return TRUE;
+ }
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+/*
+ * Finds an arrowhead at the given position (if -1, any position)
+ *
+ */
+
+wxArrowHead *wxLineShape::FindArrowHead(int position, const wxString& name)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ if (((position == -1) || (position == arrow->GetArrowEnd())) &&
+ (arrow->GetName() == name))
+ return arrow;
+ node = node->Next();
+ }
+ return NULL;
+}
+
+wxArrowHead *wxLineShape::FindArrowHead(long arrowId)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ if (arrowId == arrow->GetId())
+ return arrow;
+ node = node->Next();
+ }
+ return NULL;
+}
+
+/*
+ * Deletes an arrowhead at the given position (if -1, any position)
+ *
+ */
+
+bool wxLineShape::DeleteArrowHead(int position, const wxString& name)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ if (((position == -1) || (position == arrow->GetArrowEnd())) &&
+ (arrow->GetName() == name))
+ {
+ delete arrow;
+ delete node;
+ return TRUE;
+ }
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+// Overloaded DeleteArrowHead: pass arrowhead id.
+bool wxLineShape::DeleteArrowHead(long id)
+{
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrow = (wxArrowHead *)node->Data();
+ if (arrow->GetId() == id)
+ {
+ delete arrow;
+ delete node;
+ return TRUE;
+ }
+ node = node->Next();
+ }
+ return FALSE;
+}
+
+/*
+ * Calculate the minimum width a line
+ * occupies, for the purposes of drawing lines in tools.
+ *
+ */
+
+double wxLineShape::FindMinimumWidth()
+{
+ double minWidth = 0.0;
+ wxNode *node = m_arcArrows.First();
+ while (node)
+ {
+ wxArrowHead *arrowHead = (wxArrowHead *)node->Data();
+ minWidth += arrowHead->GetSize();
+ if (node->Next())
+ minWidth += arrowHead->GetSpacing();
+
+ node = node->Next();
+ }
+ // We have ABSOLUTE minimum now. So
+ // scale it to give it reasonable aesthetics
+ // when drawing with line.
+ if (minWidth > 0.0)
+ minWidth = (double)(minWidth * 1.4);
+ else
+ minWidth = 20.0;
+
+ SetEnds(0.0, 0.0, minWidth, 0.0);
+ Initialise();
+
+ return minWidth;
+}
+
+// Find which position we're talking about at this (x, y).
+// Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
+int wxLineShape::FindLinePosition(double x, double y)
+{
+ double startX, startY, endX, endY;
+ GetEnds(&startX, &startY, &endX, &endY);
+
+ // Find distances from centre, start and end. The smallest wins.
+ double centreDistance = (double)(sqrt((x - m_xpos)*(x - m_xpos) + (y - m_ypos)*(y - m_ypos)));
+ double startDistance = (double)(sqrt((x - startX)*(x - startX) + (y - startY)*(y - startY)));
+ double endDistance = (double)(sqrt((x - endX)*(x - endX) + (y - endY)*(y - endY)));
+
+ if (centreDistance < startDistance && centreDistance < endDistance)
+ return ARROW_POSITION_MIDDLE;
+ else if (startDistance < endDistance)
+ return ARROW_POSITION_START;
+ else
+ return ARROW_POSITION_END;
+}
+
+// Set alignment flags
+void wxLineShape::SetAlignmentOrientation(bool isEnd, bool isHoriz)
+{
+ if (isEnd)
+ {
+ if (isHoriz && ((m_alignmentEnd & LINE_ALIGNMENT_HORIZ) != LINE_ALIGNMENT_HORIZ))
+ m_alignmentEnd |= LINE_ALIGNMENT_HORIZ;
+ else if (!isHoriz && ((m_alignmentEnd & LINE_ALIGNMENT_HORIZ) == LINE_ALIGNMENT_HORIZ))
+ m_alignmentEnd -= LINE_ALIGNMENT_HORIZ;
+ }
+ else
+ {
+ if (isHoriz && ((m_alignmentStart & LINE_ALIGNMENT_HORIZ) != LINE_ALIGNMENT_HORIZ))
+ m_alignmentStart |= LINE_ALIGNMENT_HORIZ;
+ else if (!isHoriz && ((m_alignmentStart & LINE_ALIGNMENT_HORIZ) == LINE_ALIGNMENT_HORIZ))
+ m_alignmentStart -= LINE_ALIGNMENT_HORIZ;
+ }
+}
+
+void wxLineShape::SetAlignmentType(bool isEnd, int alignType)
+{
+ if (isEnd)
+ {
+ if (alignType == LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ {
+ if ((m_alignmentEnd & LINE_ALIGNMENT_TO_NEXT_HANDLE) != LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ m_alignmentEnd |= LINE_ALIGNMENT_TO_NEXT_HANDLE;
+ }
+ else if ((m_alignmentEnd & LINE_ALIGNMENT_TO_NEXT_HANDLE) == LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ m_alignmentEnd -= LINE_ALIGNMENT_TO_NEXT_HANDLE;
+ }
+ else
+ {
+ if (alignType == LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ {
+ if ((m_alignmentStart & LINE_ALIGNMENT_TO_NEXT_HANDLE) != LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ m_alignmentStart |= LINE_ALIGNMENT_TO_NEXT_HANDLE;
+ }
+ else if ((m_alignmentStart & LINE_ALIGNMENT_TO_NEXT_HANDLE) == LINE_ALIGNMENT_TO_NEXT_HANDLE)
+ m_alignmentStart -= LINE_ALIGNMENT_TO_NEXT_HANDLE;
+ }
+}
+
+bool wxLineShape::GetAlignmentOrientation(bool isEnd)
+{
+ if (isEnd)
+ return ((m_alignmentEnd & LINE_ALIGNMENT_HORIZ) == LINE_ALIGNMENT_HORIZ);
+ else
+ return ((m_alignmentStart & LINE_ALIGNMENT_HORIZ) == LINE_ALIGNMENT_HORIZ);
+}
+
+int wxLineShape::GetAlignmentType(bool isEnd)
+{
+ if (isEnd)
+ return (m_alignmentEnd & LINE_ALIGNMENT_TO_NEXT_HANDLE);
+ else
+ return (m_alignmentStart & LINE_ALIGNMENT_TO_NEXT_HANDLE);
+}
+
+wxRealPoint *wxLineShape::GetNextControlPoint(wxShape *nodeObject)
+{
+ int n = m_lineControlPoints->Number();
+ int nn = 0;
+ if (m_to == nodeObject)
+ {
+ // Must be END of line, so we want (n - 1)th control point.
+ // But indexing ends at n-1, so subtract 2.
+ nn = n - 2;
+ }
+ else nn = 1;
+ wxNode *node = m_lineControlPoints->Nth(nn);
+ if (node)
+ {
+ return (wxRealPoint *)node->Data();
+ }
+ else
+ return FALSE;
+}
+
+/*
+ * Arrowhead
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxArrowHead, wxObject)
+
+wxArrowHead::wxArrowHead(WXTYPE type, int end, double size, double dist, const wxString& name,
+ wxPseudoMetaFile *mf, long arrowId)
+{
+ m_arrowType = type; m_arrowEnd = end; m_arrowSize = size;
+ m_xOffset = dist;
+ m_yOffset = 0.0;
+ m_spacing = 5.0;
+
+ m_arrowName = name;
+ m_metaFile = mf;
+ m_id = arrowId;
+ if (m_id == -1)
+ m_id = wxNewId();
+}
+
+wxArrowHead::wxArrowHead(wxArrowHead& toCopy)
+{
+ m_arrowType = toCopy.m_arrowType; m_arrowEnd = toCopy.GetArrowEnd();
+ m_arrowSize = toCopy.m_arrowSize;
+ m_xOffset = toCopy.m_xOffset;
+ m_yOffset = toCopy.m_yOffset;
+ m_spacing = toCopy.m_spacing;
+ m_arrowName = toCopy.m_arrowName ;
+ if (toCopy.m_metaFile)
+ m_metaFile = new wxPseudoMetaFile(*(toCopy.m_metaFile));
+ else
+ m_metaFile = NULL;
+ m_id = wxNewId();
+}
+
+wxArrowHead::~wxArrowHead()
+{
+ if (m_metaFile) delete m_metaFile;
+}
+
+void wxArrowHead::SetSize(double size)
+{
+ m_arrowSize = size;
+ if ((m_arrowType == ARROW_METAFILE) && m_metaFile)
+ {
+ double oldWidth = m_metaFile->m_width;
+ if (oldWidth == 0.0)
+ return;
+
+ double scale = (double)(size/oldWidth);
+ if (scale != 1.0)
+ m_metaFile->Scale(scale, scale);
+ }
+}
+
+// Can override this to create a different class of label shape
+wxLabelShape* wxLineShape::OnCreateLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h)
+{
+ return new wxLabelShape(parent, region, w, h);
+}
+
+/*
+ * Label object
+ *
+ */
+
+IMPLEMENT_DYNAMIC_CLASS(wxLabelShape, wxRectangleShape)
+
+wxLabelShape::wxLabelShape(wxLineShape *parent, wxShapeRegion *region, double w, double h):wxRectangleShape(w, h)
+{
+ m_lineShape = parent;
+ m_shapeRegion = region;
+ SetPen(wxThePenList->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT));
+}
+
+wxLabelShape::~wxLabelShape()
+{
+}
+
+void wxLabelShape::OnDraw(wxDC& dc)
+{
+ if (m_lineShape && !m_lineShape->GetDrawHandles())
+ return;
+
+ double x1 = (double)(m_xpos - m_width/2.0);
+ double y1 = (double)(m_ypos - m_height/2.0);
+
+ if (m_pen)
+ {
+ if (m_pen->GetWidth() == 0)
+ dc.SetPen(* g_oglTransparentPen);
+ else
+ dc.SetPen(* m_pen);
+ }
+ dc.SetBrush(* wxTRANSPARENT_BRUSH);
+
+ if (m_cornerRadius > 0.0)
+ dc.DrawRoundedRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height), m_cornerRadius);
+ else
+ dc.DrawRectangle(WXROUND(x1), WXROUND(y1), WXROUND(m_width), WXROUND(m_height));
+}
+
+void wxLabelShape::OnDrawContents(wxDC& dc)
+{
+}
+
+void wxLabelShape::OnDragLeft(bool draw, double x, double y, int keys, int attachment)
+{
+ wxRectangleShape::OnDragLeft(draw, x, y, keys, attachment);
+}
+
+void wxLabelShape::OnBeginDragLeft(double x, double y, int keys, int attachment)
+{
+ wxRectangleShape::OnBeginDragLeft(x, y, keys, attachment);
+}
+
+void wxLabelShape::OnEndDragLeft(double x, double y, int keys, int attachment)
+{
+ wxRectangleShape::OnEndDragLeft(x, y, keys, attachment);
+}
+
+bool wxLabelShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
+{
+ return m_lineShape->OnLabelMovePre(dc, this, x, y, old_x, old_y, display);
+}
+
+bool wxLineShape::OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display)
+{
+ labelShape->m_shapeRegion->SetSize(labelShape->GetWidth(), labelShape->GetHeight());
+
+ // Find position in line's region list
+ int i = 0;
+ wxNode *node = GetRegions().First();
+ while (node)
+ {
+ if (labelShape->m_shapeRegion == (wxShapeRegion *)node->Data())
+ node = NULL;
+ else
+ {
+ node = node->Next();
+ i ++;
+ }
+ }
+ double xx, yy;
+ GetLabelPosition(i, &xx, &yy);
+ // Set the region's offset, relative to the default position for
+ // each region.
+ labelShape->m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy));
+
+ labelShape->SetX(x);
+ labelShape->SetY(y);
+
+ // Need to reformat to fit region.
+ if (labelShape->m_shapeRegion->GetText())
+ {
+
+ wxString s(labelShape->m_shapeRegion->GetText());
+ labelShape->FormatText(dc, s, i);
+ DrawRegion(dc, labelShape->m_shapeRegion, xx, yy);
+ }
+ return TRUE;
+}
+
+// Divert left and right clicks to line object
+void wxLabelShape::OnLeftClick(double x, double y, int keys, int attachment)
+{
+ m_lineShape->GetEventHandler()->OnLeftClick(x, y, keys, attachment);
+}
+
+void wxLabelShape::OnRightClick(double x, double y, int keys, int attachment)
+{
+ m_lineShape->GetEventHandler()->OnRightClick(x, y, keys, attachment);
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: lines.h
+// Purpose: wxLineShape
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_LINES_H_
+#define _OGL_LINES_H_
+
+#ifdef __GNUG__
+#pragma interface "lines.h"
+#endif
+
+class wxLabelShape;
+class wxPseudoMetaFile;
+class wxLineControlPoint;
+/*
+ * Arcs with multiple arrowheads
+ *
+ */
+
+// Types of arrowhead
+// (i) Built-in
+#define ARROW_HOLLOW_CIRCLE 1
+#define ARROW_FILLED_CIRCLE 2
+#define ARROW_ARROW 3
+#define ARROW_SINGLE_OBLIQUE 4
+#define ARROW_DOUBLE_OBLIQUE 5
+// (ii) Custom
+#define ARROW_METAFILE 20
+
+// Position of arrow on line
+#define ARROW_POSITION_START 0
+#define ARROW_POSITION_END 1
+#define ARROW_POSITION_MIDDLE 2
+
+// Line alignment flags
+// Vertical by default
+#define LINE_ALIGNMENT_HORIZ 1
+#define LINE_ALIGNMENT_VERT 0
+#define LINE_ALIGNMENT_TO_NEXT_HANDLE 2
+#define LINE_ALIGNMENT_NONE 0
+
+class wxArrowHead: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxArrowHead)
+
+ public:
+ wxArrowHead(WXTYPE type = 0, int end = 0, double size = 0.0, double dist = 0.0, const wxString& name = "", wxPseudoMetaFile *mf = NULL,
+ long arrowId = -1);
+ ~wxArrowHead();
+ wxArrowHead(wxArrowHead& toCopy);
+
+ inline WXTYPE _GetType() const { return m_arrowType; }
+ inline int GetPosition() const { return m_arrowEnd; }
+ inline void SetPosition(int pos) { m_arrowEnd = pos; }
+ inline double GetXOffset() const { return m_xOffset; }
+ inline double GetYOffset() const { return m_yOffset; }
+ inline double GetSpacing() const { return m_spacing; }
+ inline double GetSize() const { return m_arrowSize; }
+ inline wxString GetName() const { return m_arrowName; }
+ inline void SetXOffset(double x) { m_xOffset = x; }
+ inline void SetYOffset(double y) { m_yOffset = y; }
+ inline wxPseudoMetaFile *GetMetaFile() const { return m_metaFile; }
+ inline long GetId() const { return m_id; }
+ inline int GetArrowEnd() const { return m_arrowEnd; }
+ inline double GetArrowSize() const { return m_arrowSize; }
+ void SetSize(double size);
+ inline void SetSpacing(double sp) { m_spacing = sp; }
+
+ protected:
+ WXTYPE m_arrowType;
+ int m_arrowEnd; // Position on line
+ double m_xOffset; // Distance from arc start or end, w.r.t. point on arrowhead
+ // nearest start or end. If zero, use default spacing.
+ double m_yOffset; // vertical offset (w.r.t. a horizontal line). Normally zero.
+ double m_spacing; // Spacing from the last arrowhead
+ double m_arrowSize; // Length of arrowhead
+ wxString m_arrowName; // Name of arrow
+ bool m_saveToFile; // TRUE if we want to save custom arrowheads to file.
+ wxPseudoMetaFile* m_metaFile; // Pseudo metafile if this is a custom arrowhead
+ long m_id; // identifier
+};
+
+// Line object
+class wxLabelShape;
+class wxLineShape: public wxShape
+{
+ DECLARE_DYNAMIC_CLASS(wxLineShape)
+
+ public:
+ wxLineShape();
+ ~wxLineShape();
+
+ // Called when a connected object has moved, to move the link to
+ // correct position
+ // moveControlPoints must be disabled when a control point is being
+ // dragged.
+ void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE);
+ bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+ void OnDraw(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+ void OnDrawControlPoints(wxDC& dc);
+ void OnEraseControlPoints(wxDC& dc);
+ void OnErase(wxDC& dc);
+ virtual bool OnMoveControlPoint(int WXUNUSED(which), double WXUNUSED(x), double WXUNUSED(y)) { return FALSE; }
+ virtual bool OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt);
+ virtual bool OnLabelMovePre(wxDC& dc, wxLabelShape* labelShape, double x, double y, double old_x, double old_y, bool display);
+ void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
+ void GetBoundingBoxMin(double *w, double *h);
+ void FormatText(wxDC& dc, const wxString& s, int regionId = 0);
+ virtual void SetEnds(double x1, double y1, double x2, double y2);
+ virtual void GetEnds(double *x1, double *y1, double *x2, double *y2);
+ inline virtual wxShape *GetFrom() { return m_from; }
+ inline virtual wxShape *GetTo() { return m_to; }
+ inline virtual int GetAttachmentFrom() { return m_attachmentFrom; }
+ inline virtual int GetAttachmentTo() { return m_attachmentTo; }
+
+ virtual void SetFrom(wxShape *object);
+ virtual void SetTo(wxShape *object);
+ virtual void DrawArrows(wxDC& dc);
+
+ // Finds the x, y points at the two ends of the line.
+ // This function can be used by e.g. line-routing routines to
+ // get the actual points on the two node images where the lines will be drawn
+ // to/from.
+ void FindLineEndPoints(double *fromX, double *fromY, double *toX, double *toY);
+
+ // Format one region at this position
+ void DrawRegion(wxDC& dc, wxShapeRegion *region, double x, double y);
+
+ // Erase one region at this position
+ void EraseRegion(wxDC& dc, wxShapeRegion *region, double x, double y);
+
+ // Get the reference point for a label. Region x and y
+ // are offsets from this.
+ // position is 0 (middle), 1 (start), 2 (end)
+ void GetLabelPosition(int position, double *x, double *y);
+
+ // Can override this to create a different class of label shape
+ virtual wxLabelShape* OnCreateLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
+
+ // Straighten verticals and horizontals
+ virtual void Straighten(wxDC* dc = NULL);
+
+ // Not implemented
+ inline void SetMaintainStraightLines(bool flag) { m_maintainStraightLines = flag; }
+ inline bool GetMaintainStraightLines() const { return m_maintainStraightLines; }
+
+ // Make handle control points
+ void MakeControlPoints();
+ void ResetControlPoints();
+
+ // Make a given number of control points
+ virtual void MakeLineControlPoints(int n);
+ virtual wxNode *InsertLineControlPoint(wxDC* dc);
+ virtual bool DeleteLineControlPoint();
+ virtual void Initialise();
+ inline wxList *GetLineControlPoints() { return m_lineControlPoints; }
+
+ // Override dragging behaviour - don't want to be able to drag lines!
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+
+ // Control points ('handles') redirect control to the actual shape, to make it easier
+ // to override sizing behaviour.
+ virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+ virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0);
+
+ // Override select, to create/delete temporary label-moving objects
+ void Select(bool select = TRUE, wxDC* dc = NULL);
+
+ // Set to spline (TRUE) or line (FALSE)
+ inline void SetSpline(bool spl) { m_isSpline = spl; }
+ inline bool IsSpline() const { return m_isSpline; }
+
+ void Unlink();
+ void SetAttachments(int from_attach, int to_attach);
+ inline void SetAttachmentFrom(int attach) { m_attachmentFrom = attach; }
+ inline void SetAttachmentTo(int attach) { m_attachmentTo = attach; }
+
+ bool HitTest(double x, double y, int *attachment, double *distance);
+
+#ifdef PROLOGIO
+ // I/O
+ virtual void WriteAttributes(wxExpr *clause);
+ virtual void ReadAttributes(wxExpr *clause);
+#endif
+
+ virtual void FindNth(wxShape *image, int *nth, int *no_arcs, bool incoming);
+
+ // Find which position we're talking about at this (x, y).
+ // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
+ int FindLinePosition(double x, double y);
+
+ // This is really to distinguish between lines and other images.
+ // For lines, want to pass drag to canvas, since lines tend to prevent
+ // dragging on a canvas (they get in the way.)
+ virtual bool Draggable() const { return FALSE; }
+
+ // Does the copying for this object
+ void Copy(wxShape& copy);
+
+ // Add an arrowhead.
+ wxArrowHead *AddArrow(WXTYPE type, int end = ARROW_POSITION_END,
+ double arrowSize = 10.0, double xOffset = 0.0, const wxString& name = "",
+ wxPseudoMetaFile *mf = NULL, long arrowId = -1);
+
+ // Add an arrowhead in the position indicated by the reference
+ // list of arrowheads, which contains all legal arrowheads for this
+ // line, in the correct order.
+ // E.g. reference list: a b c d e
+ // Current line list: a d
+ // Add c, then line list is: a c d
+ // If no legal arrowhead position, return FALSE.
+ // Assume reference list is for one end only, since it potentially defines
+ // the ordering for any one of the 3 positions. So we don't check
+ // the reference list for arrowhead position.
+ bool AddArrowOrdered(wxArrowHead *arrow, wxList& referenceList, int end);
+
+ // Delete arrowhead(s)
+ void ClearArrowsAtPosition(int end = -1);
+ bool ClearArrow(const wxString& name);
+ wxArrowHead *FindArrowHead(int position, const wxString& name);
+ wxArrowHead *FindArrowHead(long arrowId);
+ bool DeleteArrowHead(int position, const wxString& name);
+ bool DeleteArrowHead(long arrowId);
+ void DrawArrow(wxDC& dc, wxArrowHead *arrow, double xOffset, bool proportionalOffset);
+ inline void SetIgnoreOffsets(bool ignore) { m_ignoreArrowOffsets = ignore; }
+ inline wxList& GetArrows() const { return (wxList&) m_arcArrows; }
+
+ // Find horizontal width for drawing a line with
+ // arrows in minimum space. Assume arrows at
+ // END only
+ double FindMinimumWidth();
+
+ // Set alignment flags. ALIGNMENT NOT IMPLEMENTED.
+ void SetAlignmentOrientation(bool isEnd, bool isHoriz);
+ void SetAlignmentType(bool isEnd, int alignType);
+ bool GetAlignmentOrientation(bool isEnd);
+ int GetAlignmentType(bool isEnd);
+
+ // Find next control point in line after the start/end point
+ // (depending on whether the node object is at start or end)
+ wxRealPoint *GetNextControlPoint(wxShape *nodeObject);
+ inline bool IsEnd(wxShape *nodeObject) const { return (m_to == nodeObject); }
+
+private:
+ bool m_erasing; // flag to say whether we're erasing or drawing
+ // this line (really so metafiles can draw a
+ // blank rectangle)
+ bool m_ignoreArrowOffsets; // Don't always want to draw arrowhead offsets
+ // because they may not work on tool palettes (for example)
+ bool m_isSpline;
+ bool m_maintainStraightLines;
+
+protected:
+ // Temporary list of line segment orientations
+ // so we know what direction the line is supposed to be dog-legging
+ // in. The values are integer: 0 for vertical, 1 for horizontal.
+ wxList m_lineOrientations;
+
+ // Temporary pointers for start, middle and end label editing objects
+ // (active only when the line is selected)
+ wxLabelShape* m_labelObjects[3];
+
+ // These define the segmented line - not to be confused with temporary control
+ // points which appear when object is selected (although in this case they'll
+ // probably be the same)
+ wxList* m_lineControlPoints;
+
+ double m_arrowSpacing; // Separation between adjacent arrows
+
+ wxShape* m_to;
+ wxShape* m_from;
+
+ int m_attachmentTo; // Attachment point at one end
+ int m_attachmentFrom; // Attachment point at other end
+
+ // Alignment flags
+ int m_alignmentStart;
+ int m_alignmentEnd;
+
+ wxList m_arcArrows;
+
+};
+
+#endif
+ // _OGL_LINES_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: linesp.h
+// Purpose: Lines private header file
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_LINESP_H_
+#define _OGL_LINESP_H_
+
+#ifdef __GNUG__
+#pragma interface "linesp.h"
+#endif
+
+class wxLineShape;
+class wxLineControlPoint: public wxControlPoint
+{
+ DECLARE_DYNAMIC_CLASS(wxLineControlPoint)
+ friend class wxLineShape;
+ public:
+
+ wxLineControlPoint(wxShapeCanvas *the_canvas = NULL, wxShape *object = NULL, double size = 0.0,
+ double x = 0.0, double y = 0.0, int the_type = 0);
+ ~wxLineControlPoint();
+
+ void OnDraw(wxDC& dc);
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+
+ // Obsolete (left-dragging now moves attachment point to new relative position OR new
+ // attachment id)
+#if 0
+ void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragRight(double x, double y, int keys=0, int attachment = 0);
+#endif
+
+public:
+
+ int m_type;
+ wxRealPoint* m_point; // Line point
+ wxRealPoint m_originalPos;
+
+};
+
+/*
+ * Temporary arc label object
+ */
+
+class wxLabelShape: public wxRectangleShape
+{
+ DECLARE_DYNAMIC_CLASS(wxLabelShape)
+
+ public:
+ wxLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
+ ~wxLabelShape();
+
+ void OnDraw(wxDC& dc);
+ void OnDrawContents(wxDC& dc);
+ void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
+ void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
+ void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0);
+ void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0);
+ void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
+ bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE);
+
+public:
+ wxLineShape* m_lineShape;
+ wxShapeRegion* m_shapeRegion;
+
+};
+
+/*
+ * Get the point on the given line (x1, y1) (x2, y2)
+ * distance 'length' along from the end,
+ * returned values in x and y
+ */
+
+void GetPointOnLine(double x1, double y1, double x2, double y2,
+ double length, double *x, double *y);
+
+#endif
+ // _OGL_LINESP_H_
+
--- /dev/null
+#
+# File: makefile.b32
+# Author: Julian Smart
+# Created: 1999
+# Updated:
+# Copyright:
+#
+# Makefile : Builds OGL library for 32-bit BC++
+
+WXDIR = $(WXWIN)
+
+LIBTARGET=$(WXDIR)\lib\ogl.lib
+
+OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\
+ composit.obj drawn.obj bmpshape.obj mfutils.obj
+
+!include $(WXDIR)\src\makelib.b32
+
--- /dev/null
+#
+# File: makefile.bcc
+# Author: Julian Smart
+# Created: 1998
+# Updated:
+#
+# Builds OGL library for BC++, 16-bit
+
+!if "$(WXWIN)" == ""
+!error You must define the WXWIN variable in autoexec.bat, e.g. WXWIN=c:\wx
+!endif
+
+WXDIR = $(WXWIN)
+
+LIBTARGET=$(WXDIR)\lib\ogl.lib
+
+OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\
+ composit.obj drawn.obj bmpshape.obj mfutils.obj
+
+!include $(WXDIR)\src\makelib.bcc
+
--- /dev/null
+#
+# File: makefile.dos
+# Author: Julian Smart
+# Created: 1993
+# Updated:
+# Copyright: (c) 1993, AIAI, University of Edinburgh
+#
+# "%W% %G%"
+#
+# Makefile: Builds object graphics library (DOS).
+# Use FINAL=1 argument to nmake to build final version with no debugging
+# info
+
+# Set WXDIR for your system
+WXDIR = $(WXWIN)
+
+!include $(WXDIR)\src\makemsc.env
+
+OGLDIR = $(WXDIR)\utils\ogl
+THISDIR = $(OGLDIR)\src
+DOCDIR = $(OGLDIR)\docs
+WXLIB = $(WXDIR)\lib\wx.lib
+LIBS=$(WXLIB) libw llibcew commdlg shell ctl3dv2
+
+GRAPHICSLIB = $(WXDIR)\lib\ogl.lib
+INC = /I$(WXDIR)\include
+
+# Normally set OPTIONS =
+# to disable PROLOGIO-dependent code
+OPTIONS = -DPROLOGIO
+
+OBJECTS = basic.obj basic2.obj canvas.obj ogldiag.obj lines.obj misc.obj divided.obj constrnt.obj\
+ composit.obj drawn.obj bitmap.obj mfutils.obj
+
+all: $(GRAPHICSLIB)
+
+wx:
+ cd $(WXDIR)\src\msw
+ nmake -f makefile.dos $(WXLIB) FINAL=$(FINAL)
+ cd $(THISDIR)
+
+$(GRAPHICSLIB): $(OBJECTS)
+ erase $(GRAPHICSLIB)
+ lib /PAGESIZE:128 @<<
+$(GRAPHICSLIB)
+y
+$(OBJECTS)
+nul
+;
+<<
+
+# NOTE: This causes a floating point stack error when optimized,
+# so DON'T optimize!
+
+basic.obj: basic.$(SRCSUFF) basic.h lines.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /Od /c /Tp $*.$(SRCSUFF)
+<<
+
+basic2.obj: basic2.$(SRCSUFF) basic.h lines.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /Od /c /Tp $*.$(SRCSUFF)
+<<
+
+canvas.obj: canvas.$(SRCSUFF) basic.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+ogldiag.obj: ogldiag.$(SRCSUFF) ogldiag.h canvas.h basic.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+lines.obj: lines.$(SRCSUFF) basic.h misc.h canvas.h lines.h basicp.h linesp.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+misc.obj: misc.$(SRCSUFF) basic.h misc.h constrnt.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+divided.obj: divided.$(SRCSUFF) basic.h misc.h canvas.h divided.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+constrnt.obj: constrnt.$(SRCSUFF) basic.h constrnt.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+composit.obj: composit.$(SRCSUFF) basic.h misc.h canvas.h constrnt.h composit.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+drawn.obj: drawn.$(SRCSUFF) basic.h misc.h canvas.h drawn.h drawnp.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+bitmap.obj: bitmap.$(SRCSUFF) basic.h misc.h canvas.h bitmap.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+mfutils.obj: mfutils.$(SRCSUFF) mfutils.h
+ cl @<<
+$(CPPFLAGS) /c /Tp $*.$(SRCSUFF)
+<<
+
+# Making documents
+docs: hlp
+hlp: $(DOCDIR)/ogl.hlp
+hlp32: $(DOCDIR)/hlp32/ogl.hlp
+rtf: $(DOCDIR)/ogl.rtf
+
+$(DOCDIR)/ogl.hlp: $(DOCDIR)/ogl.rtf $(DOCDIR)/ogl.hpj
+ cd $(DOCDIR)
+ -erase ogl.ph
+ hc ogl
+ cd $(THISDIR)
+
+$(DOCDIR)/hlp32/ogl.hlp: $(DOCDIR)/hlp32/ogl.rtf $(DOCDIR)/hlp32/ogl.hpj
+ cd $(DOCDIR)/hlp32
+ -erase ogl.ph
+ start /w hcw /c /e ogl.hpj
+ cd $(THISDIR)
+
+$(DOCDIR)/ogl.rtf: $(DOCDIR)/classes.tex $(DOCDIR)/intro.tex $(DOCDIR)/ogl.tex
+ cd $(DOCDIR)
+ start /w tex2rtf $(DOCDIR)/ogl.tex $(DOCDIR)/ogl.rtf -twice -winhelp
+ cd $(THISDIR)
+
+$(DOCDIR)/hlp32/ogl.rtf: $(DOCDIR)/classes.tex $(DOCDIR)/intro.tex $(DOCDIR)/ogl.tex
+ cd $(DOCDIR)
+ start /w tex2rtf $(DOCDIR)/ogl.tex $(DOCDIR)/hlp32/ogl.rtf -twice -winhelp -macros $(DOCDIR)/t2rtf32.ini
+ cd $(THISDIR)
+
+wordrtf:
+ cd $(DOCDIR)
+ -wx /W tex2rtf $(DOCDIR)/ogl.tex $(DOCDIR)/ogl.rtf -twice -rtf
+ cd $(THISDIR)
+
+clean:
+ -erase *.obj
+ -erase *.sbr
+ -erase *.exe
+ -erase *.res
+ -erase *.map
+ -erase *.pdb
+ -erase *.lib
+ -erase ..\lib\*.lib
+
+wxclean:
+ cd $(WXDIR)\src\msw
+ nmake -f makefile.dos clean
+ cd $(THISDIR)
--- /dev/null
+#
+# File: makefile.g95
+# Author: Julian Smart
+# Created: 1999
+# Updated:
+# Copyright: (c) Julian Smart, 1999
+#
+# Makefile for wxWindows OGL library Cygwin/Mingw32).
+
+WXDIR = ../../..
+
+LIBTARGET=$(WXDIR)/lib/libogl.a
+OBJECTS = basic.o basic2.o canvas.o ogldiag.o lines.o misc.o divided.o constrnt.o\
+ composit.o drawn.o bmpshape.o mfutils.o
+
+include $(WXDIR)/src/makelib.g95
+
--- /dev/null
+#
+# File: makefile.unx
+# Author: Julian Smart
+# Created: 1998
+# Updated:
+# Copyright: (c) 1998
+#
+#
+# Makefile for OGL library, Unix
+
+include ../../../src/make.env
+
+OGLLIB=$(WXDIR)/lib/libogl$(GUISUFFIX).a
+
+LIB_CPP_SRC=\
+\
+ basic.o\
+ basic2.o\
+ canvas.o\
+ ogldiag.o\
+ lines.o\
+ misc.o\
+ divided.o\
+ constrnt.o\
+ composit.o\
+ drawn.o\
+ bmpshape.o\
+ mfutils.o
+
+all: $(OGLLIB)
+
+# Define library objects
+OBJECTS=\
+ $(LIB_CPP_SRC:.cpp=.o)
+
+$(OGLLIB) : $(OBJECTS)
+ ar $(AROPTIONS) $@ $(OBJECTS)
+ $(RANLIB) $@
+
+clean:
+ rm -f $(OBJECTS) $(OGLLIB)
+
--- /dev/null
+
+# File: makefile.vc
+# Author: Julian Smart
+# Created: 1993
+# Updated:
+# Copyright: (c) 1993, AIAI, University of Edinburgh
+#
+# "%W% %G%"
+#
+# Makefile : Builds OGL classes library (MS VC++).
+# Use FINAL=1 argument to nmake to build final version with no debugging
+# info
+
+
+# Set WXDIR for your system
+WXDIR = $(WXWIN)
+OBJECTSDIR = $(WXDIR)\utils\ogl
+THISDIR = $(WXDIR)\utils\ogl\src
+#EXTRALIBS=$(WXDIR)\lib\ogl.lib $(WXDIR)\lib\mfutils.lib
+#EXTRAINC=/I$(WXDIR)\utils\mfutils\src /I$(WXDIR)\utils\prologio\src
+EXTRAFLAGS=/DPROLOGIO=1
+DOCDIR=$(WXDIR)\docs
+LOCALDOCDIR=$(WXDIR)\utils\ogl\docs
+
+!include $(WXDIR)\src\makevc.env
+
+PROGRAM=test
+
+OBJECTS = $(D)\basic.obj $(D)\basic2.obj $(D)\canvas.obj $(D)\ogldiag.obj $(D)\lines.obj $(D)\misc.obj $(D)\divided.obj $(D)\constrnt.obj\
+ $(D)\composit.obj $(D)\drawn.obj $(D)\bmpshape.obj $(D)\mfutils.obj
+
+LIBTARGET=$(WXDIR)\lib\ogl$(LIBEXT).lib
+
+all: $(D) $(LIBTARGET)
+
+$(PROGRAM): $(PROGRAM).exe
+
+$(D) :
+ mkdir $(D)
+
+wx:
+ cd $(WXDIR)\src\msw
+ nmake -f makefile.vc FINAL=$(FINAL)
+ cd $(THISDIR)
+
+wxclean:
+ cd $(WXDIR)\src\msw
+ nmake -f makefile.vc clean
+ cd $(THISDIR)
+
+$(LIBTARGET): $(OBJECTS)
+ -erase $(LIBTARGET)
+ $(implib) @<<
+-out:$(LIBTARGET)
+-machine:$(CPU)
+$(OBJECTS)
+<<
+
+# NOTE: This causes a floating point stack error when optimized,
+# so DON'T optimize!
+$(D)\basic.obj: basic.$(SRCSUFF) basic.h lines.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /Od /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\basic2.obj: basic2.$(SRCSUFF) basic.h lines.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /Od /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\canvas.obj: canvas.$(SRCSUFF) basic.h misc.h canvas.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\ogldiag.obj: ogldiag.$(SRCSUFF) ogldiag.h canvas.h basic.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\lines.obj: lines.$(SRCSUFF) basic.h misc.h canvas.h lines.h basicp.h linesp.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\misc.obj: misc.$(SRCSUFF) basic.h misc.h constrnt.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\divided.obj: divided.$(SRCSUFF) basic.h misc.h canvas.h divided.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\constrnt.obj: constrnt.$(SRCSUFF) basic.h constrnt.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\composit.obj: composit.$(SRCSUFF) basic.h misc.h canvas.h constrnt.h composit.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\drawn.obj: drawn.$(SRCSUFF) basic.h misc.h canvas.h drawn.h drawnp.h basicp.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\bmpshape.obj: bmpshape.$(SRCSUFF) basic.h misc.h canvas.h bmpshape.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+$(D)\mfutils.obj: mfutils.$(SRCSUFF) mfutils.h
+ cl @<<
+$(CPPFLAGS) /c /Fo$@ /Tp $(*B).$(SRCSUFF)
+<<
+
+clean:
+ -erase $(D)\*.obj
+ -erase *.sbr
+ -erase *.exe
+ -erase *.res
+ -erase *.map
+ -erase *.pdb
+ -erase $(LIBTARGET)
+
+DOCSOURCES=$(LOCALDOCDIR)\ogl.tex \
+ $(LOCALDOCDIR)\bugs.tex $(LOCALDOCDIR)\changes.tex\
+ $(LOCALDOCDIR)\classes.tex $(LOCALDOCDIR)\intro.tex\
+ $(LOCALDOCDIR)\topics.tex $(LOCALDOCDIR)\sample.tex
+
+html: $(DOCDIR)\html\ogl\ogl.htm
+htmlhelp: $(DOCDIR)\html\ogl\ogl.chm
+hlp: $(DOCDIR)\winhelp\ogl.hlp
+pdfrtf: $(DOCDIR)\pdf\ogl.rtf
+ps: $(DOCDIR)\ps\ogl.ps
+
+touchmanual:
+ touch $(LOCALDOCDIR)\ogl.tex
+
+
+$(DOCDIR)\winhelp\ogl.hlp: $(LOCALDOCDIR)\ogl.rtf $(LOCALDOCDIR)\ogl.hpj
+ cd $(LOCALDOCDIR)
+ -erase ogl.ph
+ hc ogl
+ move ogl.hlp $(DOCDIR)\winhelp\ogl.hlp
+ move ogl.cnt $(DOCDIR)\winhelp\ogl.cnt
+ cd $(THISDIR)
+
+$(LOCALDOCDIR)\ogl.rtf: $(DOCSOURCES)
+ cd $(LOCALDOCDIR)
+ -start $(WAITFLAG) tex2rtf $(LOCALDOCDIR)\ogl.tex $(LOCALDOCDIR)\ogl.rtf -twice -winhelp
+ cd $(THISDIR)
+
+$(DOCDIR)\pdf\ogl.rtf: $(DOCSOURCES)
+ cd $(LOCALDOCDIR)
+ -copy *.bmp $(DOCDIR)\pdf
+ -start $(WAITFLAG) tex2rtf $(LOCALDOCDIR)\ogl.tex $(DOCDIR)\pdf\ogl.rtf -twice -rtf
+ cd $(THISDIR)
+
+$(DOCDIR)\html\ogl\ogl.htm: $(DOCSOURCES)
+ cd $(LOCALDOCDIR)
+ -mkdir $(DOCDIR)\html\ogl
+ copy *.gif $(DOCDIR)\html\ogl
+ -start $(WAITFLAG) tex2rtf $(LOCALDOCDIR)\ogl.tex $(DOCDIR)\html\ogl\ogl.htm -twice -html
+ -erase $(DOCDIR)\html\ogl\*.con
+ -erase *.con
+ -erase $(DOCDIR)\html\ogl\*.ref
+ cd $(THISDIR)
+
+
+$(DOCDIR)\html\ogl\ogl.chm: $(DOCDIR)\html\ogl\ogl.htm $(DOCDIR)\html\ogl\ogl.hhp
+ cd $(DOCDIR)\html\ogl
+ -hhc ogl.hhp
+ cd $(THISDIR)
+
+
+$(LOCALDOCDIR)\ogl.dvi: $(DOCSOURCES)
+ cd $(LOCALDOCDIR)
+ -latex ogl
+ -latex ogl
+ -makeindx ogl
+ -bibtex ogl
+ -latex ogl
+ -latex ogl
+ cd $(THISDIR)
+
+$(WXDIR)\docs\ps\ogl.ps: $(LOCALDOCDIR)\ogl.dvi
+ cd $(LOCALDOCDIR)
+ -dvips32 -o ogl.ps ogl
+ move ogl.ps $(WXDIR)\docs\ps\ogl.ps
+ cd $(THISDIR)
+
+
--- /dev/null
+# Objects makefile
+
+WXDIR = ..\..\..
+
+!include $(WXDIR)\src\makewat.env
+
+EXTRACPPFLAGS=/DPROLOGIO
+
+OBJECTSLIB = $(WXDIR)\utils\objects\lib\graphics.lib
+THISDIR = $(WXDIR)\utils\objects\src
+
+NAME = graphics
+LNK = $(name).lnk
+
+IFLAGS = -i=$(WXINC) -i=$(WXBASEINC) -i=..\..\mfutils\src -i=..\..\prologio\src
+
+OBJECTS = basic.obj basic2.obj canvas.obj lines.obj misc.obj divided.obj constrnt.obj composit.obj drawn.obj bitmap.obj
+
+all: $(OBJECTSLIB)
+
+$(OBJECTSLIB): $(OBJECTS)
+ *wlib /b /c /n /P=256 $(OBJECTSLIB) $(OBJECTS)
+
+clean: .SYMBOLIC
+ -erase *.obj *.bak *.err *.pch $(OBJECTSLIB) *.lbc
+
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: mfutils.cpp
+// Purpose: Metafile utillities
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "mfutils.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/metafile.h>
+#include <wx/utils.h>
+
+#include "mfutils.h"
+#include <stdio.h>
+
+static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F' };
+
+static void DecToHex(int dec, char *buf)
+{
+ int firstDigit = (int)(dec/16.0);
+ int secondDigit = (int)(dec - (firstDigit*16.0));
+ buf[0] = hexArray[firstDigit];
+ buf[1] = hexArray[secondDigit];
+ buf[2] = 0;
+}
+
+// 16-bit unsigned integer
+static unsigned int getshort(FILE *fp)
+{
+ int c, c1;
+ c = getc(fp); c1 = getc(fp);
+ unsigned int res = ((unsigned int) c) + (((unsigned int) c1) << 8);
+ return res;
+}
+
+// 16-bit signed integer
+static int getsignedshort(FILE *fp)
+{
+ int c, c1;
+ c = getc(fp); c1 = getc(fp);
+ int testRes = ((unsigned int) c) + (((unsigned int) c1) << 8);
+ unsigned long res1 = ((unsigned int) c) + (((unsigned int) c1) << 8);
+ int res = 0;
+ if (res1 > 32767)
+ res = (int)(res1 - 65536);
+ else
+ res = (int)(res1);
+ return res;
+}
+
+// 32-bit integer
+static long getint(FILE *fp)
+{
+ int c, c1, c2, c3;
+ c = getc(fp); c1 = getc(fp); c2 = getc(fp); c3 = getc(fp);
+ long res = (long)((long) c) +
+ (((long) c1) << 8) +
+ (((long) c2) << 16) +
+ (((long) c3) << 24);
+ return res;
+}
+
+
+/* Placeable metafile header
+struct mfPLACEABLEHEADER {
+ DWORD key; // 32-bit
+ HANDLE hmf; // 16-bit
+ RECT bbox; // 4x16 bit
+ WORD inch; // 16-bit
+ DWORD reserved; // 32-bit
+ WORD checksum; // 16-bit
+};
+*/
+
+wxMetaRecord::~wxMetaRecord(void)
+{
+ if (points) delete[] points;
+ if (stringParam) delete[] stringParam;
+}
+
+wxXMetaFile::wxXMetaFile(char *file)
+{
+ ok = FALSE;
+ top = 0.0;
+ bottom = 0.0;
+ left = 0.0;
+ right = 0.0;
+
+ if (file)
+ ok = ReadFile(file);
+}
+
+/*
+ Handle table gdiObjects
+ ------------ ----------
+ [0] wxPen
+ [1]----param2--- wxBrush
+ [2] | wxFont
+ [3] | -> wxPen
+
+ The handle table works as follows.
+ When a GDI object is created whilst reading in the
+ metafile, the (e.g.) createpen record is added to the
+ first free entry in the handle table. The createpen
+ record's param1 is a pointer to the actual wxPen, and
+ its param2 is the index into the gdiObjects list, which only
+ grows and never shrinks (unlike the handle table.)
+
+ When SelectObject(index) is found, the index in the file
+ refers to the position in the handle table. BUT we then
+ set param2 to be the position of the wxPen in gdiObjects,
+ i.e. to param2 of the CreatePen record, itself found in
+ the handle table.
+
+ When an object is deleted, the entry in the handletable is
+ NULLed but the gdiObjects entry is not removed (no point, and
+ allows us to create all GDI objects in advance of playing the
+ metafile).
+*/
+
+
+static wxMetaRecord *HandleTable[100];
+static int HandleTableSize = 0;
+
+void DeleteMetaRecordHandle(int index)
+{
+ HandleTable[index] = NULL;
+}
+
+int AddMetaRecordHandle(wxMetaRecord *record)
+{
+ for (int i = 0; i < HandleTableSize; i++)
+ if (!HandleTable[i])
+ {
+ HandleTable[i] = record;
+ return i;
+ }
+ // No free spaces in table, so append.
+
+ HandleTable[HandleTableSize] = record;
+ HandleTableSize ++;
+ return (HandleTableSize - 1);
+}
+
+bool wxXMetaFile::ReadFile(char *file)
+{
+ HandleTableSize = 0;
+
+ FILE *handle = fopen(file, "rb");
+ if (!handle) return FALSE;
+
+ // Read placeable metafile header, if any
+ long key = getint(handle);
+
+ if (key == (long) 0x9AC6CDD7)
+ {
+ long hmf = getshort(handle);
+ int iLeft, iTop, iRight, iBottom;
+ iLeft = getsignedshort(handle);
+ iTop = getsignedshort(handle);
+ iRight = getsignedshort(handle);
+ iBottom = getsignedshort(handle);
+
+ left = (double)iLeft;
+ top = (double)iTop;
+ right = (double)iRight;
+ bottom = (double)iBottom;
+
+ int inch = getshort(handle);
+ long reserved = getint(handle);
+ int checksum = getshort(handle);
+/*
+ double widthInUnits = (double)right - left;
+ double heightInUnits = (double)bottom - top;
+ *width = (int)((widthInUnits*1440.0)/inch);
+ *height = (int)((heightInUnits*1440.0)/inch);
+*/
+ }
+ else rewind(handle);
+
+ // Read METAHEADER
+ int mtType = getshort(handle);
+
+ if (mtType != 1 && mtType != 2)
+ {
+ fclose(handle);
+ return FALSE;
+ }
+
+ int mtHeaderSize = getshort(handle);
+ int mtVersion = getshort(handle);
+
+ if (mtVersion != 0x0300 && mtVersion != 0x0100)
+ {
+ fclose(handle);
+ return FALSE;
+ }
+
+ long mtSize = getint(handle);
+ int mtNoObjects = getshort(handle);
+ long mtMaxRecord = getint(handle);
+ int mtNoParameters = getshort(handle);
+
+ while (!feof(handle))
+ {
+ long rdSize = getint(handle); // 4 bytes
+ int rdFunction = getshort(handle); // 2 bytes
+ if (feof(handle))
+ break;
+
+ switch (rdFunction)
+ {
+ case META_SETBKCOLOR:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETBKCOLOR);
+ long colorref = getint(handle); // COLORREF
+ rec->param1 = GetRValue(colorref);
+ rec->param2 = GetGValue(colorref);
+ rec->param3 = GetBValue(colorref);
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_SETBKMODE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETBKMODE);
+ rec->param1 = getshort(handle); // Background mode
+ if (rec->param1 == OPAQUE) rec->param1 = wxSOLID;
+ else rec->param1 = wxTRANSPARENT;
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_SETMAPMODE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETMAPMODE);
+ rec->param1 = getshort(handle);
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_SETROP2:
+// case META_SETRELABS:
+// case META_SETPOLYFILLMODE:
+// case META_SETSTRETCHBLTMODE:
+// case META_SETTEXTCHAREXTRA:
+ case META_SETTEXTCOLOR:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETTEXTCOLOR);
+ long colorref = getint(handle); // COLORREF
+ rec->param1 = GetRValue(colorref);
+ rec->param2 = GetGValue(colorref);
+ rec->param3 = GetBValue(colorref);
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_SETTEXTJUSTIFICATION:
+ case META_SETWINDOWORG:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWORG);
+ rec->param2 = getshort(handle);
+ rec->param1 = getshort(handle);
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_SETWINDOWEXT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWEXT);
+ rec->param2 = getshort(handle);
+ rec->param1 = getshort(handle);
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_SETVIEWPORTORG:
+// case META_SETVIEWPORTEXT:
+// case META_OFFSETWINDOWORG:
+// case META_SCALEWINDOWEXT:
+// case META_OFFSETVIEWPORTORG:
+// case META_SCALEVIEWPORTEXT:
+ case META_LINETO:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_LINETO);
+ rec->param1 = getshort(handle); // x1
+ rec->param2 = getshort(handle); // y1
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_MOVETO:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_MOVETO);
+ rec->param1 = getshort(handle); // x1
+ rec->param2 = getshort(handle); // y1
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_EXCLUDECLIPRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
+ rec->param4 = getshort(handle); // y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_INTERSECTCLIPRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_INTERSECTCLIPRECT);
+ rec->param4 = getshort(handle); // y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_ARC: // DO!!!
+ case META_ELLIPSE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_ELLIPSE);
+ rec->param4 = getshort(handle); // y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_FLOODFILL:
+// case META_PIE: // DO!!!
+ case META_RECTANGLE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_RECTANGLE);
+ rec->param4 = getshort(handle); // y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_ROUNDRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_ROUNDRECT);
+ rec->param6 = getshort(handle); // width
+ rec->param5 = getshort(handle); // height
+ rec->param4 = getshort(handle); // y2
+ rec->param3 = getshort(handle); // x2
+ rec->param2 = getshort(handle); // y1
+ rec->param1 = getshort(handle); // x1
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_PATBLT:
+// case META_SAVEDC:
+ case META_SETPIXEL:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SETPIXEL);
+ rec->param1 = getshort(handle); // x1
+ rec->param2 = getshort(handle); // y1
+ rec->param3 = getint(handle); // COLORREF
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_OFFSETCLIPRGN:
+ case META_TEXTOUT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_TEXTOUT);
+ int count = getshort(handle);
+ rec->stringParam = new char[count+1];
+ fread((void *)rec->stringParam, sizeof(char), count, handle);
+ rec->stringParam[count] = 0;
+ rec->param2 = getshort(handle); // Y
+ rec->param1 = getshort(handle); // X
+ metaRecords.Append(rec);
+ break;
+ }
+/*
+ case META_EXTTEXTOUT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_EXTTEXTOUT);
+ int cellSpacing = getshort(handle);
+ int count = getshort(handle);
+ rec->stringParam = new char[count+1];
+ fread((void *)rec->stringParam, sizeof(char), count, handle);
+ rec->stringParam[count] = 0;
+ // Rectangle
+ int rectY2 = getshort(handle);
+ int rectX2 = getshort(handle);
+ int rectY1 = getshort(handle);
+ int rectX1 = getshort(handle);
+ int rectType = getshort(handle);
+ rec->param2 = getshort(handle); // Y
+ rec->param1 = getshort(handle); // X
+ metaRecords.Append(rec);
+ break;
+ }
+*/
+// case META_BITBLT:
+// case META_STRETCHBLT:
+ case META_POLYGON:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_POLYGON);
+ rec->param1 = getshort(handle);
+ rec->points = new wxRealPoint[(int)rec->param1];
+ for (int i = 0; i < rec->param1; i++)
+ {
+ rec->points[i].x = getshort(handle);
+ rec->points[i].y = getshort(handle);
+ }
+
+ metaRecords.Append(rec);
+ break;
+ }
+ case META_POLYLINE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_POLYLINE);
+ rec->param1 = (long)getshort(handle);
+ rec->points = new wxRealPoint[(int)rec->param1];
+ for (int i = 0; i < rec->param1; i++)
+ {
+ rec->points[i].x = getshort(handle);
+ rec->points[i].y = getshort(handle);
+ }
+
+ metaRecords.Append(rec);
+ break;
+ }
+// case META_ESCAPE:
+// case META_RESTOREDC:
+// case META_FILLREGION:
+// case META_FRAMEREGION:
+// case META_INVERTREGION:
+// case META_PAINTREGION:
+// case META_SELECTCLIPREGION: // DO THIS!
+ case META_SELECTOBJECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_SELECTOBJECT);
+ rec->param1 = (long)getshort(handle); // Position of object in gdiObjects list
+ metaRecords.Append(rec);
+ // param2 gives the index into gdiObjects, which is different from
+ // the index into the handle table.
+ rec->param2 = HandleTable[(int)rec->param1]->param2;
+ break;
+ }
+// case META_SETTEXTALIGN:
+// case META_DRAWTEXT:
+// case META_CHORD:
+// case META_SETMAPPERFLAGS:
+// case META_EXTTEXTOUT:
+// case META_SETDIBTODEV:
+// case META_SELECTPALETTE:
+// case META_REALIZEPALETTE:
+// case META_ANIMATEPALETTE:
+// case META_SETPALENTRIES:
+// case META_POLYPOLYGON:
+// case META_RESIZEPALETTE:
+// case META_DIBBITBLT:
+// case META_DIBSTRETCHBLT:
+ case META_DIBCREATEPATTERNBRUSH:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_DIBCREATEPATTERNBRUSH);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+// case META_STRETCHDIB:
+// case META_EXTFLOODFILL:
+// case META_RESETDC:
+// case META_STARTDOC:
+// case META_STARTPAGE:
+// case META_ENDPAGE:
+// case META_ABORTDOC:
+// case META_ENDDOC:
+ case META_DELETEOBJECT:
+ {
+ int index = getshort(handle);
+ DeleteMetaRecordHandle(index);
+ break;
+ }
+ case META_CREATEPALETTE:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEBRUSH:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSH);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEPATTERNBRUSH:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEPATTERNBRUSH);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEPENINDIRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEPENINDIRECT);
+ int msStyle = getshort(handle); // Style: 2 bytes
+ int x = getshort(handle); // X: 2 bytes
+ int y = getshort(handle); // Y: 2 bytes
+ long colorref = getint(handle); // COLORREF 4 bytes
+
+ int style;
+ if (msStyle == PS_DOT)
+ style = wxDOT;
+ else if (msStyle == PS_DASH)
+ style = wxSHORT_DASH;
+ else if (msStyle == PS_NULL)
+ style = wxTRANSPARENT;
+ else style = wxSOLID;
+
+ wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
+ rec->param1 = (long)wxThePenList->FindOrCreatePen(colour, x, style);
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+
+ // For some reason, the size of this record is sometimes 9 words!!!
+ // instead of the usual 8. So read 2 characters extra.
+ if (rdSize == 9)
+ {
+ (void) getshort(handle);
+ }
+ break;
+ }
+ case META_CREATEFONTINDIRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEFONTINDIRECT);
+ int lfHeight = getshort(handle); // 2 bytes
+ int lfWidth = getshort(handle); // 2 bytes
+ int lfEsc = getshort(handle); // 2 bytes
+ int lfOrient = getshort(handle); // 2 bytes
+ int lfWeight = getshort(handle); // 2 bytes
+ char lfItalic = getc(handle); // 1 byte
+ char lfUnderline = getc(handle); // 1 byte
+ char lfStrikeout = getc(handle); // 1 byte
+ char lfCharSet = getc(handle); // 1 byte
+ char lfOutPrecision = getc(handle); // 1 byte
+ char lfClipPrecision = getc(handle); // 1 byte
+ char lfQuality = getc(handle); // 1 byte
+ char lfPitchAndFamily = getc(handle); // 1 byte (18th)
+ char lfFacename[32];
+ // Read the rest of the record, which is total record size
+ // minus the number of bytes already read (18 record, 6 metarecord
+ // header)
+ fread((void *)lfFacename, sizeof(char), (int)((2*rdSize) - 18 - 6), handle);
+
+ int family;
+ if (lfPitchAndFamily & FF_MODERN)
+ family = wxMODERN;
+ else if (lfPitchAndFamily & FF_MODERN)
+ family = wxMODERN;
+ else if (lfPitchAndFamily & FF_ROMAN)
+ family = wxROMAN;
+ else if (lfPitchAndFamily & FF_SWISS)
+ family = wxSWISS;
+ else if (lfPitchAndFamily & FF_DECORATIVE)
+ family = wxDECORATIVE;
+ else
+ family = wxDEFAULT;
+
+ int weight;
+ if (lfWeight == 300)
+ weight = wxLIGHT;
+ else if (lfWeight == 400)
+ weight = wxNORMAL;
+ else if (lfWeight == 900)
+ weight = wxBOLD;
+ else weight = wxNORMAL;
+
+ int style;
+ if (lfItalic != 0)
+ style = wxITALIC;
+ else
+ style = wxNORMAL;
+
+ // About how many pixels per inch???
+ int logPixelsY = 100;
+ int pointSize = (int)(lfHeight*72.0/logPixelsY);
+
+ wxFont *theFont =
+ wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, (lfUnderline != 0));
+
+ rec->param1 = (long) theFont;
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEBRUSHINDIRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSHINDIRECT);
+ int msStyle = getshort(handle); // Style: 2 bytes
+ long colorref = getint(handle); // COLORREF: 4 bytes
+ int hatchStyle = getshort(handle); // Hatch style 2 bytes
+
+ int style;
+ switch (msStyle)
+ {
+ case BS_HATCHED:
+ {
+ switch (hatchStyle)
+ {
+ case HS_BDIAGONAL:
+ style = wxBDIAGONAL_HATCH;
+ break;
+ case HS_DIAGCROSS:
+ style = wxCROSSDIAG_HATCH;
+ break;
+ case HS_FDIAGONAL:
+ style = wxFDIAGONAL_HATCH;
+ break;
+ case HS_HORIZONTAL:
+ style = wxHORIZONTAL_HATCH;
+ break;
+ case HS_VERTICAL:
+ style = wxVERTICAL_HATCH;
+ break;
+ default:
+ case HS_CROSS:
+ style = wxCROSS_HATCH;
+ break;
+ }
+ break;
+ }
+ case BS_SOLID:
+ default:
+ style = wxSOLID;
+ break;
+ }
+ if (msStyle == PS_DOT)
+ style = wxDOT;
+ else if (msStyle == PS_DASH)
+ style = wxSHORT_DASH;
+ else if (msStyle == PS_NULL)
+ style = wxTRANSPARENT;
+ else style = wxSOLID;
+
+ wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
+ rec->param1 = (long)wxTheBrushList->FindOrCreateBrush(colour, style);
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEBITMAPINDIRECT:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAPINDIRECT);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEBITMAP:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAP);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ case META_CREATEREGION:
+ {
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEREGION);
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+
+ metaRecords.Append(rec);
+ gdiObjects.Append(rec);
+ AddMetaRecordHandle(rec);
+ rec->param2 = (long)(gdiObjects.Number() - 1);
+ break;
+ }
+ default:
+ {
+ fread((void *)wxBuffer, sizeof(char), (int)((2*rdSize) - 6), handle);
+ break;
+ }
+ }
+ }
+ fclose(handle);
+ return TRUE;
+}
+
+wxXMetaFile::~wxXMetaFile(void)
+{
+ wxNode *node = metaRecords.First();
+ while (node)
+ {
+ wxMetaRecord *rec = (wxMetaRecord *)node->Data();
+ delete rec;
+ wxNode *next = node->Next();
+ delete node;
+ node = next;
+ }
+}
+
+bool wxXMetaFile::SetClipboard(int width, int height)
+{
+ return FALSE;
+}
+
+bool wxXMetaFile::Play(wxDC *dc)
+{
+ wxNode *node = metaRecords.First();
+ while (node)
+ {
+ wxMetaRecord *rec = (wxMetaRecord *)node->Data();
+ int rdFunction = rec->metaFunction;
+
+ switch (rdFunction)
+ {
+ case META_SETBKCOLOR:
+ {
+ break;
+ }
+ case META_SETBKMODE:
+ {
+ break;
+ }
+ case META_SETMAPMODE:
+ {
+ break;
+ }
+// case META_SETROP2:
+// case META_SETRELABS:
+// case META_SETPOLYFILLMODE:
+// case META_SETSTRETCHBLTMODE:
+// case META_SETTEXTCHAREXTRA:
+ case META_SETTEXTCOLOR:
+ {
+ break;
+ }
+// case META_SETTEXTJUSTIFICATION:
+ case META_SETWINDOWORG:
+ {
+ break;
+ }
+ case META_SETWINDOWEXT:
+ {
+ break;
+ }
+// case META_SETVIEWPORTORG:
+// case META_SETVIEWPORTEXT:
+// case META_OFFSETWINDOWORG:
+// case META_SCALEWINDOWEXT:
+// case META_OFFSETVIEWPORTORG:
+// case META_SCALEVIEWPORTEXT:
+ case META_LINETO:
+ {
+ long x1 = rec->param1;
+ long y1 = rec->param2;
+ dc->DrawLine((long) lastX, (long) lastY, x1, y1);
+ break;
+ }
+ case META_MOVETO:
+ {
+ lastX = (double)rec->param1;
+ lastY = (double)rec->param2;
+ break;
+ }
+ case META_EXCLUDECLIPRECT:
+ {
+ break;
+ }
+ case META_INTERSECTCLIPRECT:
+ {
+ break;
+ }
+// case META_ARC: // DO!!!
+ case META_ELLIPSE:
+ {
+ break;
+ }
+// case META_FLOODFILL:
+// case META_PIE: // DO!!!
+ case META_RECTANGLE:
+ {
+ dc->DrawRectangle((long)rec->param1, (long)rec->param2,
+ (long)rec->param3 - rec->param1,
+ (long)rec->param4 - rec->param2);
+ break;
+ }
+ case META_ROUNDRECT:
+ {
+ dc->DrawRoundedRectangle((long)rec->param1, (long)rec->param2,
+ (long)rec->param3 - rec->param1,
+ (long)rec->param4 - rec->param2,
+ (long)rec->param5);
+ break;
+ }
+// case META_PATBLT:
+// case META_SAVEDC:
+ case META_SETPIXEL:
+ {
+// rec->param1 = getshort(handle); // x1
+// rec->param2 = getshort(handle); // y1
+// rec->param3 = getint(handle); // COLORREF
+ break;
+ }
+// case META_OFFSETCLIPRGN:
+ case META_TEXTOUT:
+ {
+/*
+ int count = getshort(handle);
+ rec->stringParam = new char[count+1];
+ fread((void *)rec->stringParam, sizeof(char), count, handle);
+ rec->stringParam[count] = 0;
+ rec->param2 = getshort(handle); // Y
+ rec->param1 = getshort(handle); // X
+*/
+ break;
+ }
+// case META_BITBLT:
+// case META_STRETCHBLT:
+ case META_POLYGON:
+ {
+/*
+ rec->param1 = getshort(handle);
+ rec->points = new wxRealPoint[(int)rec->param1];
+ for (int i = 0; i < rec->param1; i++)
+ {
+ rec->points[i].x = getshort(handle);
+ rec->points[i].y = getshort(handle);
+ }
+*/
+ break;
+ }
+ case META_POLYLINE:
+ {
+/*
+ wxMetaRecord *rec = new wxMetaRecord(META_POLYLINE);
+ rec->param1 = (long)getshort(handle);
+ rec->points = new wxRealPoint[(int)rec->param1];
+ for (int i = 0; i < rec->param1; i++)
+ {
+ rec->points[i].x = getshort(handle);
+ rec->points[i].y = getshort(handle);
+ }
+*/
+ break;
+ }
+// case META_ESCAPE:
+// case META_RESTOREDC:
+// case META_FILLREGION:
+// case META_FRAMEREGION:
+// case META_INVERTREGION:
+// case META_PAINTREGION:
+// case META_SELECTCLIPREGION: // DO THIS!
+ case META_SELECTOBJECT:
+ {
+/*
+ wxMetaRecord *rec = new wxMetaRecord(META_SELECTOBJECT);
+ rec->param1 = (long)getshort(handle); // Position of object in gdiObjects list
+*/
+ break;
+ }
+// case META_SETTEXTALIGN:
+// case META_DRAWTEXT:
+// case META_CHORD:
+// case META_SETMAPPERFLAGS:
+// case META_EXTTEXTOUT:
+// case META_SETDIBTODEV:
+// case META_SELECTPALETTE:
+// case META_REALIZEPALETTE:
+// case META_ANIMATEPALETTE:
+// case META_SETPALENTRIES:
+// case META_POLYPOLYGON:
+// case META_RESIZEPALETTE:
+// case META_DIBBITBLT:
+// case META_DIBSTRETCHBLT:
+ case META_DIBCREATEPATTERNBRUSH:
+ {
+/*
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+// case META_STRETCHDIB:
+// case META_EXTFLOODFILL:
+// case META_RESETDC:
+// case META_STARTDOC:
+// case META_STARTPAGE:
+// case META_ENDPAGE:
+// case META_ABORTDOC:
+// case META_ENDDOC:
+// case META_DELETEOBJECT: // DO!!
+ case META_CREATEPALETTE:
+ {
+/*
+ wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+ case META_CREATEBRUSH:
+ {
+/*
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+ case META_CREATEPATTERNBRUSH:
+ {
+/*
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+ case META_CREATEPENINDIRECT:
+ {
+/*
+ int msStyle = getshort(handle); // Style: 2 bytes
+ int x = getshort(handle); // X: 2 bytes
+ int y = getshort(handle); // Y: 2 bytes
+ int colorref = getint(handle); // COLORREF 4 bytes
+
+ int style;
+ if (msStyle == PS_DOT)
+ style = wxDOT;
+ else if (msStyle == PS_DASH)
+ style = wxSHORT_DASH;
+ else if (msStyle == PS_NULL)
+ style = wxTRANSPARENT;
+ else style = wxSOLID;
+
+ wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
+ rec->param1 = (long)wxThePenList->FindOrCreatePen(&colour, x, style);
+*/
+ break;
+ }
+ case META_CREATEFONTINDIRECT:
+ {
+/*
+ int lfHeight = getshort(handle);
+ int lfWidth = getshort(handle);
+ int lfEsc = getshort(handle);
+ int lfOrient = getshort(handle);
+ int lfWeight = getshort(handle);
+ char lfItalic = getc(handle);
+ char lfUnderline = getc(handle);
+ char lfStrikeout = getc(handle);
+ char lfCharSet = getc(handle);
+ char lfOutPrecision = getc(handle);
+ char lfClipPrecision = getc(handle);
+ char lfQuality = getc(handle);
+ char lfPitchAndFamily = getc(handle);
+ char lfFacename[32];
+ fread((void *)lfFacename, sizeof(char), 32, handle);
+
+ int family;
+ if (lfPitchAndFamily & FF_MODERN)
+ family = wxMODERN;
+ else if (lfPitchAndFamily & FF_MODERN)
+ family = wxMODERN;
+ else if (lfPitchAndFamily & FF_ROMAN)
+ family = wxROMAN;
+ else if (lfPitchAndFamily & FF_SWISS)
+ family = wxSWISS;
+ else if (lfPitchAndFamily & FF_DECORATIVE)
+ family = wxDECORATIVE;
+ else
+ family = wxDEFAULT;
+
+ int weight;
+ if (lfWeight == 300)
+ weight = wxLIGHT;
+ else if (lfWeight == 400)
+ weight = wxNORMAL;
+ else if (lfWeight == 900)
+ weight = wxBOLD;
+ else weight = wxNORMAL;
+
+ int style;
+ if ((bool)lfItalic)
+ style = wxITALIC;
+ else
+ style = wxNORMAL;
+
+ // About how many pixels per inch???
+ int logPixelsY = 100;
+ int pointSize = (int)(lfHeight*72.0/logPixelsY);
+
+ wxFont *theFont =
+ wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, (bool)lfUnderline);
+
+ rec->param1 = (long)theFont;
+*/
+ break;
+ }
+ case META_CREATEBRUSHINDIRECT:
+ {
+/*
+ int msStyle = getshort(handle); // Style: 2 bytes
+ int colorref = getint(handle); // COLORREF: 4 bytes
+ int hatchStyle = getshort(handle); // Hatch style 2 bytes
+
+ int style;
+ if (msStyle == PS_DOT)
+ style = wxDOT;
+ else if (msStyle == PS_DASH)
+ style = wxSHORT_DASH;
+ else if (msStyle == PS_NULL)
+ style = wxTRANSPARENT;
+ else style = wxSOLID;
+
+ wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
+ rec->param1 = (long)wxTheBrushList->FindOrCreateBrush(&colour, wxSOLID);
+*/
+ break;
+ }
+ case META_CREATEBITMAPINDIRECT:
+ {
+/*
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+ case META_CREATEBITMAP:
+ {
+/*
+ fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
+*/
+ break;
+ }
+ case META_CREATEREGION:
+ {
+ dc->DestroyClippingRegion();
+/*
+ rec->param1 = getshort(handle); // Style: 2 bytes
+*/
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ node = node->Next();
+ }
+ return TRUE;
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: mfutils.h
+// Purpose: Metafile utilities: reading a placeable metafile independently
+// of Windows.
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _MFUTILS_H_
+#define _MFUTILS_H_
+
+#ifdef __GNUG__
+#pragma interface "mfutils.h"
+#endif
+
+#include <wx/metafile.h>
+
+#ifndef GetRValue
+#define GetRValue(rgb) ((unsigned char)(rgb))
+#define GetGValue(rgb) ((unsigned char)(((int)(rgb)) >> 8))
+#define GetBValue(rgb) ((unsigned char)((rgb)>>16))
+#endif
+
+/* Metafile Functions */
+/* Win32s/Borland need these macros, although META_SETBKCOLOR is defined */
+#if 1 // !defined(META_SETBKCOLOR) // || defined(WIN32)
+
+#define META_SETBKCOLOR 0x0201
+#define META_SETBKMODE 0x0102
+#define META_SETMAPMODE 0x0103
+#define META_SETROP2 0x0104
+#define META_SETRELABS 0x0105
+#define META_SETPOLYFILLMODE 0x0106
+#define META_SETSTRETCHBLTMODE 0x0107
+#define META_SETTEXTCHAREXTRA 0x0108
+#define META_SETTEXTCOLOR 0x0209
+#define META_SETTEXTJUSTIFICATION 0x020A
+#define META_SETWINDOWORG 0x020B
+#define META_SETWINDOWEXT 0x020C
+#define META_SETVIEWPORTORG 0x020D
+#define META_SETVIEWPORTEXT 0x020E
+#define META_OFFSETWINDOWORG 0x020F
+#define META_SCALEWINDOWEXT 0x0410
+#define META_OFFSETVIEWPORTORG 0x0211
+#define META_SCALEVIEWPORTEXT 0x0412
+#define META_LINETO 0x0213
+#define META_MOVETO 0x0214
+#define META_EXCLUDECLIPRECT 0x0415
+#define META_INTERSECTCLIPRECT 0x0416
+#define META_ARC 0x0817
+#define META_ELLIPSE 0x0418
+#define META_FLOODFILL 0x0419
+#define META_PIE 0x081A
+#define META_RECTANGLE 0x041B
+#define META_ROUNDRECT 0x061C
+#define META_PATBLT 0x061D
+#define META_SAVEDC 0x001E
+#define META_SETPIXEL 0x041F
+#define META_OFFSETCLIPRGN 0x0220
+#define META_TEXTOUT 0x0521
+#define META_BITBLT 0x0922
+#define META_STRETCHBLT 0x0B23
+#define META_POLYGON 0x0324
+#define META_POLYLINE 0x0325
+#define META_ESCAPE 0x0626
+#define META_RESTOREDC 0x0127
+#define META_FILLREGION 0x0228
+#define META_FRAMEREGION 0x0429
+#define META_INVERTREGION 0x012A
+#define META_PAINTREGION 0x012B
+#define META_SELECTCLIPREGION 0x012C
+#define META_SELECTOBJECT 0x012D
+#define META_SETTEXTALIGN 0x012E
+#define META_DRAWTEXT 0x062F
+
+#define META_CHORD 0x0830
+#define META_SETMAPPERFLAGS 0x0231
+#define META_EXTTEXTOUT 0x0a32
+#define META_SETDIBTODEV 0x0d33
+#define META_SELECTPALETTE 0x0234
+#define META_REALIZEPALETTE 0x0035
+#define META_ANIMATEPALETTE 0x0436
+#define META_SETPALENTRIES 0x0037
+#define META_POLYPOLYGON 0x0538
+#define META_RESIZEPALETTE 0x0139
+
+#define META_DIBBITBLT 0x0940
+#define META_DIBSTRETCHBLT 0x0b41
+#define META_DIBCREATEPATTERNBRUSH 0x0142
+#define META_STRETCHDIB 0x0f43
+
+#define META_EXTFLOODFILL 0x0548
+
+#define META_RESETDC 0x014C
+#define META_STARTDOC 0x014D
+#define META_STARTPAGE 0x004F
+#define META_ENDPAGE 0x0050
+#define META_ABORTDOC 0x0052
+#define META_ENDDOC 0x005E
+
+#define META_DELETEOBJECT 0x01f0
+
+#define META_CREATEPALETTE 0x00f7
+#define META_CREATEBRUSH 0x00F8
+#define META_CREATEPATTERNBRUSH 0x01F9
+#define META_CREATEPENINDIRECT 0x02FA
+#define META_CREATEFONTINDIRECT 0x02FB
+#define META_CREATEBRUSHINDIRECT 0x02FC
+#define META_CREATEBITMAPINDIRECT 0x02FD
+#define META_CREATEBITMAP 0x06FE
+#define META_CREATEREGION 0x06FF
+
+/* Background Modes */
+#define TRANSPARENT 1
+#define OPAQUE 2
+
+/* Pen Styles */
+#define PS_SOLID 0
+#define PS_DASH 1
+#define PS_DOT 2
+#define PS_DASHDOT 3
+#define PS_DASHDOTDOT 4
+#define PS_NULL 5
+#define PS_INSIDEFRAME 6
+
+/* PitchAndFamily family values (high 4 bits) */
+/* Win32s/Borland don't need this */
+#ifndef FF_DONTCARE // !defined(__BORLANDC__) && !defined(WIN32)
+#define FF_DONTCARE 0x00
+#define FF_ROMAN 0x10
+#define FF_SWISS 0x20
+#define FF_MODERN 0x30
+#define FF_SCRIPT 0x40
+#define FF_DECORATIVE 0x50
+#endif
+
+/* Brush Styles */
+#define BS_SOLID 0
+#define BS_NULL 1
+#define BS_HOLLOW BS_NULL
+#define BS_HATCHED 2
+#define BS_PATTERN 3
+#define BS_INDEXED 4
+#define BS_DIBPATTERN 5
+
+/* Hatch Styles */
+#define HS_HORIZONTAL 0
+#define HS_VERTICAL 1
+#define HS_FDIAGONAL 2
+#define HS_BDIAGONAL 3
+#define HS_CROSS 4
+#define HS_DIAGCROSS 5
+
+#endif // metafile functions
+
+class wxMetaRecord: public wxObject
+{
+ public:
+ int metaFunction;
+ long param1;
+ long param2;
+ long param3;
+ long param4;
+ long param5;
+ long param6;
+ long param7;
+ long param8;
+ char *stringParam;
+ wxRealPoint *points;
+
+ wxMetaRecord(int fun)
+ {
+ metaFunction = fun; points = NULL; stringParam = NULL;
+ param1 = 0;
+ }
+ ~wxMetaRecord(void);
+};
+
+class wxXMetaFile: public wxObject
+{
+ public:
+ double lastX;
+ double lastY;
+ bool ok;
+
+ double left;
+ double top;
+ double right;
+ double bottom;
+
+ wxList metaRecords;
+ wxList gdiObjects; // List of wxMetaRecord objects created with Create...,
+ // referenced by position in list by SelectObject
+ wxXMetaFile(char *file = NULL);
+ ~wxXMetaFile(void);
+
+ // After this is called, the metafile cannot be used for anything
+ // since it is now owned by the clipboard.
+ bool SetClipboard(int width = 0, int height = 0);
+
+ bool Play(wxDC *dc);
+ inline bool Ok(void) const { return ok; }
+ bool ReadFile(char *file);
+};
+
+#endif
+ // _MFUTILS_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: misc.cpp
+// Purpose: Miscellaneous OGL support functions
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "misc.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#include <wx/types.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#else
+#include <iostream>
+#endif
+#include <ctype.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "misc.h"
+#include "constrnt.h"
+#include "composit.h"
+
+wxFont* g_oglNormalFont;
+wxPen* g_oglBlackPen;
+wxPen* g_oglWhiteBackgroundPen;
+wxPen* g_oglTransparentPen;
+wxBrush* g_oglWhiteBackgroundBrush;
+wxPen* g_oglBlackForegroundPen;
+wxCursor* g_oglBullseyeCursor = NULL;
+
+char* oglBuffer = NULL;
+
+wxList oglObjectCopyMapping(wxKEY_INTEGER);
+
+
+
+void wxOGLInitialize()
+{
+ g_oglBullseyeCursor = new wxCursor(wxCURSOR_BULLSEYE);
+
+ g_oglNormalFont = new wxFont(10, wxSWISS, wxNORMAL, wxNORMAL);
+
+ g_oglBlackPen = new wxPen("BLACK", 1, wxSOLID);
+
+ g_oglWhiteBackgroundPen = new wxPen("WHITE", 1, wxSOLID);
+ g_oglTransparentPen = new wxPen("WHITE", 1, wxTRANSPARENT);
+ g_oglWhiteBackgroundBrush = new wxBrush("WHITE", wxSOLID);
+ g_oglBlackForegroundPen = new wxPen("BLACK", 1, wxSOLID);
+
+ OGLInitializeConstraintTypes();
+
+ // Initialize big buffer used when writing images
+ oglBuffer = new char[3000];
+
+}
+
+void wxOGLCleanUp()
+{
+ if (oglBuffer)
+ {
+ delete[] oglBuffer;
+ oglBuffer = NULL;
+ }
+ oglBuffer = NULL;
+ if (g_oglBullseyeCursor)
+ {
+ delete g_oglBullseyeCursor;
+ g_oglBullseyeCursor = NULL;
+ }
+
+ if (g_oglNormalFont)
+ {
+ delete g_oglNormalFont;
+ g_oglNormalFont = NULL;
+ }
+ if (g_oglBlackPen)
+ {
+ delete g_oglBlackPen;
+ g_oglBlackPen = NULL;
+ }
+ if (g_oglWhiteBackgroundPen)
+ {
+ delete g_oglWhiteBackgroundPen;
+ g_oglWhiteBackgroundPen = NULL;
+ }
+ if (g_oglTransparentPen)
+ {
+ delete g_oglTransparentPen;
+ g_oglTransparentPen = NULL;
+ }
+ if (g_oglWhiteBackgroundBrush)
+ {
+ delete g_oglWhiteBackgroundBrush;
+ g_oglWhiteBackgroundBrush = NULL;
+ }
+ if (g_oglBlackForegroundPen)
+ {
+ delete g_oglBlackForegroundPen;
+ g_oglBlackForegroundPen = NULL;
+ }
+
+ OGLCleanUpConstraintTypes();
+}
+
+wxFont *oglMatchFont(int point_size)
+{
+ wxFont *font = wxTheFontList->FindOrCreateFont(point_size, wxSWISS, wxNORMAL, wxNORMAL);
+#if 0
+ switch (point_size)
+ {
+ case 4:
+ font = swiss_font_4;
+ break;
+ case 6:
+ font = swiss_font_6;
+ break;
+ case 8:
+ font = swiss_font_8;
+ break;
+ case 12:
+ font = swiss_font_12;
+ break;
+ case 14:
+ font = swiss_font_14;
+ break;
+ case 18:
+ font = swiss_font_18;
+ break;
+ case 24:
+ font = swiss_font_24;
+ break;
+ default:
+ case 10:
+ font = swiss_font_10;
+ break;
+ }
+#endif
+ return font;
+}
+
+int FontSizeDialog(wxFrame *parent, int old_size)
+{
+ if (old_size <= 0)
+ old_size = 10;
+ char buf[40];
+ sprintf(buf, "%d", old_size);
+ wxString ans = wxGetTextFromUser("Enter point size", "Font size", buf, parent);
+ if (ans == "")
+ return 0;
+
+ int new_size = atoi(ans);
+ if ((new_size <= 0) || (new_size > 40))
+ {
+ wxMessageBox("Invalid point size!", "Error", wxOK);
+ return 0;
+ }
+ return new_size;
+/*
+ char *strings[8];
+ strings[0] = "4";
+ strings[1] = "6";
+ strings[2] = "8";
+ strings[3] = "10";
+ strings[4] = "12";
+ strings[5] = "14";
+ strings[6] = "18";
+ strings[7] = "24";
+ char *ans = wxGetSingleChoice("Choose", "Choose a font size", 8, strings, parent);
+ if (ans)
+ {
+ int size;
+ sscanf(ans, "%d", &size);
+ return oglMatchFont(size);
+ }
+ else return NULL;
+*/
+}
+
+// Centre a list of strings in the given box. xOffset and yOffset are the
+// the positions that these lines should be relative to, and this might be
+// the same as m_xpos, m_ypos, but might be zero if formatting from left-justifying.
+void oglCentreText(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height,
+ int formatMode)
+{
+ int n = text_list->Number();
+
+ if (!text_list || (n == 0))
+ return;
+
+ // First, get maximum dimensions of box enclosing text
+
+ long char_height = 0;
+ long max_width = 0;
+ long current_width = 0;
+
+ // Store text extents for speed
+ double *widths = new double[n];
+
+ wxNode *current = text_list->First();
+ int i = 0;
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+ dc.GetTextExtent(line->GetText(), ¤t_width, &char_height);
+ widths[i] = current_width;
+
+ if (current_width > max_width)
+ max_width = current_width;
+ current = current->Next();
+ i ++;
+ }
+
+ double max_height = n*char_height;
+
+ double xoffset, yoffset, xOffset, yOffset;
+
+ if (formatMode & FORMAT_CENTRE_VERT)
+ {
+ if (max_height < height)
+ yoffset = (double)(m_ypos - (height/2.0) + (height - max_height)/2.0);
+ else
+ yoffset = (double)(m_ypos - (height/2.0));
+ yOffset = m_ypos;
+ }
+ else
+ {
+ yoffset = 0.0;
+ yOffset = 0.0;
+ }
+
+ if (formatMode & FORMAT_CENTRE_HORIZ)
+ {
+ xoffset = (double)(m_xpos - width/2.0);
+ xOffset = m_xpos;
+ }
+ else
+ {
+ xoffset = 0.0;
+ xOffset = 0.0;
+ }
+
+ current = text_list->First();
+ i = 0;
+
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+
+ double x;
+ if ((formatMode & FORMAT_CENTRE_HORIZ) && (widths[i] < width))
+ x = (double)((width - widths[i])/2.0 + xoffset);
+ else
+ x = xoffset;
+ double y = (double)(i*char_height + yoffset);
+
+ line->SetX( x - xOffset ); line->SetY( y - yOffset );
+ current = current->Next();
+ i ++;
+ }
+
+ delete widths;
+}
+
+// Centre a list of strings in the given box
+void oglCentreTextNoClipping(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height)
+{
+ int n = text_list->Number();
+
+ if (!text_list || (n == 0))
+ return;
+
+ // First, get maximum dimensions of box enclosing text
+
+ long char_height = 0;
+ long max_width = 0;
+ long current_width = 0;
+
+ // Store text extents for speed
+ double *widths = new double[n];
+
+ wxNode *current = text_list->First();
+ int i = 0;
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+ dc.GetTextExtent(line->GetText(), ¤t_width, &char_height);
+ widths[i] = current_width;
+
+ if (current_width > max_width)
+ max_width = current_width;
+ current = current->Next();
+ i ++;
+ }
+
+ double max_height = n*char_height;
+
+ double yoffset = (double)(m_ypos - (height/2.0) + (height - max_height)/2.0);
+
+ double xoffset = (double)(m_xpos - width/2.0);
+
+ current = text_list->First();
+ i = 0;
+
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+
+ double x = (double)((width - widths[i])/2.0 + xoffset);
+ double y = (double)(i*char_height + yoffset);
+
+ line->SetX( x - m_xpos ); line->SetY( y - m_ypos );
+ current = current->Next();
+ i ++;
+ }
+ delete widths;
+}
+
+void oglGetCentredTextExtent(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height,
+ double *actual_width, double *actual_height)
+{
+ int n = text_list->Number();
+
+ if (!text_list || (n == 0))
+ {
+ *actual_width = 0;
+ *actual_height = 0;
+ return;
+ }
+
+ // First, get maximum dimensions of box enclosing text
+
+ long char_height = 0;
+ long max_width = 0;
+ long current_width = 0;
+
+ wxNode *current = text_list->First();
+ int i = 0;
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+ dc.GetTextExtent(line->GetText(), ¤t_width, &char_height);
+
+ if (current_width > max_width)
+ max_width = current_width;
+ current = current->Next();
+ i ++;
+ }
+
+ *actual_height = n*char_height;
+ *actual_width = max_width;
+}
+
+// Format a string to a list of strings that fit in the given box.
+// Interpret %n and 10 or 13 as a new line.
+wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double height, int formatMode)
+{
+ // First, parse the string into a list of words
+ wxStringList word_list;
+
+ // Make new lines into NULL strings at this point
+ int i = 0; int j = 0; int len = strlen(text);
+ char word[200]; word[0] = 0;
+ bool end_word = FALSE; bool new_line = FALSE;
+ while (i < len)
+ {
+ switch (text[i])
+ {
+ case '%':
+ {
+ i ++;
+ if (i == len)
+ { word[j] = '%'; j ++; }
+ else
+ {
+ if (text[i] == 'n')
+ { new_line = TRUE; end_word = TRUE; i++; }
+ else
+ { word[j] = '%'; j ++; word[j] = text[i]; j ++; i ++; }
+ }
+ break;
+ }
+ case 10:
+ {
+ new_line = TRUE; end_word = TRUE; i++;
+ break;
+ }
+ case 13:
+ {
+ new_line = TRUE; end_word = TRUE; i++;
+ }
+ case ' ':
+ {
+ end_word = TRUE;
+ i ++;
+ break;
+ }
+ default:
+ {
+ word[j] = text[i];
+ j ++; i ++;
+ break;
+ }
+ }
+ if (i == len) end_word = TRUE;
+ if (end_word)
+ {
+ word[j] = 0;
+ j = 0;
+ word_list.Add(word);
+ end_word = FALSE;
+ }
+ if (new_line)
+ {
+ word_list.Append(NULL);
+ new_line = FALSE;
+ }
+ }
+ // Now, make a list of strings which can fit in the box
+ wxStringList *string_list = new wxStringList;
+
+ char buffer[400];
+ buffer[0] = 0;
+ wxNode *node = word_list.First();
+ long x, y;
+
+ while (node)
+ {
+ wxString oldBuffer(buffer);
+
+ char *s = (char *)node->Data();
+ if (!s)
+ {
+ // FORCE NEW LINE
+ if (strlen(buffer) > 0)
+ string_list->Add(buffer);
+
+ buffer[0] = 0;
+ }
+ else
+ {
+ if (buffer[0] != 0)
+ strcat(buffer, " ");
+
+ strcat(buffer, s);
+ dc.GetTextExtent(buffer, &x, &y);
+
+ // Don't fit within the bounding box if we're fitting shape to contents
+ if ((x > width) && !(formatMode & FORMAT_SIZE_TO_CONTENTS))
+ {
+ // Deal with first word being wider than box
+ if (oldBuffer.Length() > 0)
+ string_list->Add(oldBuffer);
+
+ buffer[0] = 0;
+ strcat(buffer, s);
+ }
+ }
+
+ node = node->Next();
+ }
+ if (buffer[0] != 0)
+ string_list->Add(buffer);
+
+ return string_list;
+}
+
+void oglDrawFormattedText(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height,
+ int formatMode)
+{
+ double xoffset, yoffset;
+ if (formatMode & FORMAT_CENTRE_HORIZ)
+ xoffset = m_xpos;
+ else
+ xoffset = (double)(m_xpos - (width / 2.0));
+
+ if (formatMode & FORMAT_CENTRE_VERT)
+ yoffset = m_ypos;
+ else
+ yoffset = (double)(m_ypos - (height / 2.0));
+
+ dc.SetClippingRegion(
+ (long)(m_xpos - width/2.0), (long)(m_ypos - height/2.0),
+ (long)width, (long)height);
+
+ wxNode *current = text_list->First();
+ while (current)
+ {
+ wxShapeTextLine *line = (wxShapeTextLine *)current->Data();
+
+ dc.DrawText(line->GetText(), WXROUND(xoffset + line->GetX()), WXROUND(yoffset + line->GetY()));
+ current = current->Next();
+ }
+
+ dc.DestroyClippingRegion();
+}
+
+/*
+ * Find centroid given list of points comprising polyline
+ *
+ */
+
+void oglFindPolylineCentroid(wxList *points, double *x, double *y)
+{
+ double xcount = 0;
+ double ycount = 0;
+
+ wxNode *node = points->First();
+ while (node)
+ {
+ wxRealPoint *point = (wxRealPoint *)node->Data();
+ xcount += point->x;
+ ycount += point->y;
+ node = node->Next();
+ }
+
+ *x = (xcount/points->Number());
+ *y = (ycount/points->Number());
+}
+
+/*
+ * Check that (x1, y1) -> (x2, y2) hits (x3, y3) -> (x4, y4).
+ * If so, ratio1 gives the proportion along the first line
+ * that the intersection occurs (or something like that).
+ * Used by functions below.
+ *
+ */
+void oglCheckLineIntersection(double x1, double y1, double x2, double y2,
+ double x3, double y3, double x4, double y4,
+ double *ratio1, double *ratio2)
+{
+ double denominator_term = (y4 - y3)*(x2 - x1) - (y2 - y1)*(x4 - x3);
+ double numerator_term = (x3 - x1)*(y4 - y3) + (x4 - x3)*(y1 - y3);
+
+ double line_constant;
+ double length_ratio = 1.0;
+ double k_line = 1.0;
+
+ // Check for parallel lines
+ if ((denominator_term < 0.005) && (denominator_term > -0.005))
+ line_constant = -1.0;
+ else
+ line_constant = numerator_term/denominator_term;
+
+ // Check for intersection
+ if ((line_constant < 1.0) && (line_constant > 0.0))
+ {
+ // Now must check that other line hits
+ if (((y4 - y3) < 0.005) && ((y4 - y3) > -0.005))
+ k_line = ((x1 - x3) + line_constant*(x2 - x1))/(x4 - x3);
+ else
+ k_line = ((y1 - y3) + line_constant*(y2 - y1))/(y4 - y3);
+
+ if ((k_line >= 0.0) && (k_line < 1.0))
+ length_ratio = line_constant;
+ else
+ k_line = 1.0;
+ }
+ *ratio1 = length_ratio;
+ *ratio2 = k_line;
+}
+
+/*
+ * Find where (x1, y1) -> (x2, y2) hits one of the lines in xvec, yvec.
+ * (*x3, *y3) is the point where it hits.
+ *
+ */
+void oglFindEndForPolyline(double n, double xvec[], double yvec[],
+ double x1, double y1, double x2, double y2, double *x3, double *y3)
+{
+ int i;
+ double lastx = xvec[0];
+ double lasty = yvec[0];
+
+ double min_ratio = 1.0;
+ double line_ratio;
+ double other_ratio;
+
+ for (i = 1; i < n; i++)
+ {
+ oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[i], yvec[i],
+ &line_ratio, &other_ratio);
+ lastx = xvec[i];
+ lasty = yvec[i];
+
+ if (line_ratio < min_ratio)
+ min_ratio = line_ratio;
+ }
+
+ // Do last (implicit) line if last and first doubles are not identical
+ if (!(xvec[0] == lastx && yvec[0] == lasty))
+ {
+ oglCheckLineIntersection(x1, y1, x2, y2, lastx, lasty, xvec[0], yvec[0],
+ &line_ratio, &other_ratio);
+
+ if (line_ratio < min_ratio)
+ min_ratio = line_ratio;
+ }
+
+ *x3 = (x1 + (x2 - x1)*min_ratio);
+ *y3 = (y1 + (y2 - y1)*min_ratio);
+
+}
+
+/*
+ * Find where the line hits the box.
+ *
+ */
+
+void oglFindEndForBox(double width, double height,
+ double x1, double y1, // Centre of box (possibly)
+ double x2, double y2, // other end of line
+ double *x3, double *y3) // End on box edge
+{
+ double xvec[5];
+ double yvec[5];
+
+ xvec[0] = (double)(x1 - width/2.0);
+ yvec[0] = (double)(y1 - height/2.0);
+ xvec[1] = (double)(x1 - width/2.0);
+ yvec[1] = (double)(y1 + height/2.0);
+ xvec[2] = (double)(x1 + width/2.0);
+ yvec[2] = (double)(y1 + height/2.0);
+ xvec[3] = (double)(x1 + width/2.0);
+ yvec[3] = (double)(y1 - height/2.0);
+ xvec[4] = (double)(x1 - width/2.0);
+ yvec[4] = (double)(y1 - height/2.0);
+
+ oglFindEndForPolyline(5, xvec, yvec, x2, y2, x1, y1, x3, y3);
+}
+
+/*
+ * Find where the line hits the circle.
+ *
+ */
+
+void oglFindEndForCircle(double radius,
+ double x1, double y1, // Centre of circle
+ double x2, double y2, // Other end of line
+ double *x3, double *y3)
+{
+ double H = (double)sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+
+ if (H == 0.0)
+ {
+ *x3 = x1;
+ *y3 = y1;
+ }
+ else
+ {
+ *y3 = radius * (y2 - y1)/H + y1;
+ *x3 = radius * (x2 - x1)/H + x1;
+ }
+}
+
+/*
+ * Given the line (x1, y1) -> (x2, y2), and an arrow size of given length and width,
+ * return the position of the tip of the arrow and the left and right vertices of the arrow.
+ *
+ */
+
+void oglGetArrowPoints(double x1, double y1, double x2, double y2,
+ double length, double width,
+ double *tip_x, double *tip_y,
+ double *side1_x, double *side1_y,
+ double *side2_x, double *side2_y)
+{
+ double l = (double)sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
+
+ if (l < 0.01)
+ l = (double) 0.01;
+
+ double i_bar = (x2 - x1)/l;
+ double j_bar = (y2 - y1)/l;
+
+ double x3 = (- length*i_bar) + x2;
+ double y3 = (- length*j_bar) + y2;
+
+ *side1_x = width*(-j_bar) + x3;
+ *side1_y = width*i_bar + y3;
+
+ *side2_x = -width*(-j_bar) + x3;
+ *side2_y = -width*i_bar + y3;
+
+ *tip_x = x2; *tip_y = y2;
+}
+
+/*
+ * Given an ellipse and endpoints of a line, returns the point at which
+ * the line touches the ellipse in values x4, y4.
+ * This function assumes that the centre of the ellipse is at x1, y1, and the
+ * ellipse has a width of width1 and a height of height1. It also assumes you are
+ * wanting to draw an arc FROM point x2, y2 TOWARDS point x3, y3.
+ * This function calculates the x,y coordinates of the intersection point of
+ * the arc with the ellipse.
+ * Author: Ian Harrison
+ */
+
+void oglDrawArcToEllipse(double x1, double y1, double width1, double height1, double x2, double y2, double x3, double y3,
+ double *x4, double *y4)
+{
+ double a1 = (double)(width1/2.0);
+ double b1 = (double)(height1/2.0);
+
+ // These are required to give top left x and y coordinates for DrawEllipse
+// double top_left_x1 = (double)(x1 - a1);
+// double top_left_y1 = (double)(y1 - b1);
+/*
+ // Check for vertical line
+ if (fabs(x2 - x3) < 0.05)
+ {
+ *x4 = x3;
+ if (y2 < y3)
+ *y4 = (double)(y1 - b1);
+ else
+ *y4 = (double)(y1 + b1);
+ return;
+ }
+*/
+ // Check that x2 != x3
+ if (fabs(x2 - x3) < 0.05)
+ {
+ *x4 = x2;
+ if (y3 > y2)
+ *y4 = (double)(y1 - sqrt((b1*b1 - (((x2-x1)*(x2-x1))*(b1*b1)/(a1*a1)))));
+ else
+ *y4 = (double)(y1 + sqrt((b1*b1 - (((x2-x1)*(x2-x1))*(b1*b1)/(a1*a1)))));
+ return;
+ }
+
+ // Calculate the x and y coordinates of the point where arc intersects ellipse
+
+ double A, B, C, D, E, F, G, H, K;
+ double ellipse1_x, ellipse1_y;
+
+ A = (double)(1/(a1 * a1));
+ B = (double)((y3 - y2) * (y3 - y2)) / ((x3 - x2) * (x3 - x2) * b1 * b1);
+ C = (double)(2 * (y3 - y2) * (y2 - y1)) / ((x3 - x2) * b1 * b1);
+ D = (double)((y2 - y1) * (y2 - y1)) / (b1 * b1);
+ E = (double)(A + B);
+ F = (double)(C - (2 * A * x1) - (2 * B * x2));
+ G = (double)((A * x1 * x1) + (B * x2 * x2) - (C * x2) + D - 1);
+ H = (double)((y3 - y2) / (x3 - x2));
+ K = (double)((F * F) - (4 * E * G));
+
+ if (K >= 0)
+ // In this case the line intersects the ellipse, so calculate intersection
+ {
+ if(x2 >= x1)
+ {
+ ellipse1_x = (double)(((F * -1) + sqrt(K)) / (2 * E));
+ ellipse1_y = (double)((H * (ellipse1_x - x2)) + y2);
+ }
+ else
+ {
+ ellipse1_x = (double)(((F * -1) - sqrt(K)) / (2 * E));
+ ellipse1_y = (double)((H * (ellipse1_x - x2)) + y2);
+ }
+ }
+ else
+ // in this case, arc does not intersect ellipse, so just draw arc
+ {
+ ellipse1_x = x3;
+ ellipse1_y = y3;
+ }
+ *x4 = ellipse1_x;
+ *y4 = ellipse1_y;
+
+/*
+ // Draw a little circle (radius = 2) at the end of the arc where it hits
+ // the ellipse .
+
+ double circle_x = ellipse1_x - 2.0;
+ double circle_y = ellipse1_y - 2.0;
+ m_canvas->DrawEllipse(circle_x, circle_y, 4.0, 4.0);
+*/
+}
+
+// Update a list item from a list of strings
+void UpdateListBox(wxListBox *item, wxList *list)
+{
+ item->Clear();
+ if (!list)
+ return;
+
+ wxNode *node = list->First();
+ while (node)
+ {
+ char *s = (char *)node->Data();
+ item->Append(s);
+ node = node->Next();
+ }
+}
+
+bool oglRoughlyEqual(double val1, double val2, double tol)
+{
+ return ( (val1 < (val2 + tol)) && (val1 > (val2 - tol)) &&
+ (val2 < (val1 + tol)) && (val2 > (val1 - tol)));
+}
+
+/*
+ * Hex<->Dec conversion
+ */
+
+// Array used in DecToHex conversion routine.
+static char sg_HexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
+ 'C', 'D', 'E', 'F' };
+
+// Convert 2-digit hex number to decimal
+unsigned int oglHexToDec(char* buf)
+{
+ int firstDigit, secondDigit;
+
+ if (buf[0] >= 'A')
+ firstDigit = buf[0] - 'A' + 10;
+ else
+ firstDigit = buf[0] - '0';
+
+ if (buf[1] >= 'A')
+ secondDigit = buf[1] - 'A' + 10;
+ else
+ secondDigit = buf[1] - '0';
+
+ return firstDigit * 16 + secondDigit;
+}
+
+// Convert decimal integer to 2-character hex string
+void oglDecToHex(unsigned int dec, char *buf)
+{
+ int firstDigit = (int)(dec/16.0);
+ int secondDigit = (int)(dec - (firstDigit*16.0));
+ buf[0] = sg_HexArray[firstDigit];
+ buf[1] = sg_HexArray[secondDigit];
+ buf[2] = 0;
+}
+
+// 3-digit hex to wxColour
+wxColour oglHexToColour(const wxString& hex)
+{
+ if (hex.Length() == 6)
+ {
+ char buf[7];
+ strncpy(buf, hex, 7);
+ unsigned int r = oglHexToDec((char *)buf);
+ unsigned int g = oglHexToDec((char *)(buf+2));
+ unsigned int b = oglHexToDec((char *)(buf+4));
+ return wxColour(r, g, b);
+ }
+ else
+ return wxColour(0,0,0);
+}
+
+// RGB to 3-digit hex
+wxString oglColourToHex(const wxColour& colour)
+{
+ char buf[7];
+ unsigned int red = colour.Red();
+ unsigned int green = colour.Green();
+ unsigned int blue = colour.Blue();
+
+ oglDecToHex(red, buf);
+ oglDecToHex(green, buf+2);
+ oglDecToHex(blue, buf+4);
+
+ return wxString(buf);
+}
+
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: misc.h
+// Purpose: Miscellaneous utilities for OGL
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_MISC_H_
+#define _OGL_MISC_H_
+
+#ifdef __GNUG__
+#pragma interface "misc.h"
+#endif
+
+// List to use when copying objects; may need to associate elements of new objects
+// with elements of old objects, e.g. when copying constraint.s
+extern wxList oglObjectCopyMapping;
+
+/*
+ * TEXT FORMATTING FUNCTIONS
+ *
+ */
+
+// Centres the given list of wxShapeTextLine strings in the given box
+// (changing the positions in situ). Doesn't actually draw into the DC.
+void oglCentreText(wxDC& dc, wxList *text, double m_xpos, double m_ypos,
+ double width, double height,
+ int formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT);
+
+// Given a string, returns a list of strings that fit within the given
+// width of box. Height is ignored.
+wxStringList *oglFormatText(wxDC& dc, const wxString& text, double width, double height, int formatMode = 0);
+
+// Centres the list of wxShapeTextLine strings, doesn't clip.
+// Doesn't actually draw into the DC.
+void oglCentreTextNoClipping(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height);
+
+// Gets the maximum width and height of the given list of wxShapeTextLines.
+void oglGetCentredTextExtent(wxDC& dc, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height,
+ double *actual_width, double *actual_height);
+
+// Actually draw the preformatted list of wxShapeTextLines.
+void oglDrawFormattedText(wxDC& context, wxList *text_list,
+ double m_xpos, double m_ypos, double width, double height,
+ int formatMode = FORMAT_CENTRE_HORIZ | FORMAT_CENTRE_VERT);
+
+// Give it a list of points, finds the centre.
+void oglFindPolylineCentroid(wxList *points, double *x, double *y);
+
+void oglCheckLineIntersection(double x1, double y1, double x2, double y2,
+ double x3, double y3, double x4, double y4,
+ double *ratio1, double *ratio2);
+
+void oglFindEndForPolyline(double n, double xvec[], double yvec[],
+ double x1, double y1, double x2, double y2, double *x3, double *y3);
+
+
+void oglFindEndForBox(double width, double height,
+ double x1, double y1, // Centre of box (possibly)
+ double x2, double y2, // other end of line
+ double *x3, double *y3); // End on box edge
+
+void oglFindEndForCircle(double radius,
+ double x1, double y1, // Centre of circle
+ double x2, double y2, // Other end of line
+ double *x3, double *y3);
+
+void oglGetArrowPoints(double x1, double y1, double x2, double y2,
+ double length, double width,
+ double *tip_x, double *tip_y,
+ double *side1_x, double *side1_y,
+ double *side2_x, double *side2_y);
+
+/*
+ * Given an ellipse and endpoints of a line, returns the point at which
+ * the line touches the ellipse in values x4, y4.
+ * This function assumes that the centre of the ellipse is at x1, y1, and the
+ * ellipse has a width of a1 and a height of b1. It also assumes you are
+ * wanting to draw an arc FROM point x2, y2 TOWARDS point x3, y3.
+ * This function calculates the x,y coordinates of the intersection point of
+ * the arc with the ellipse.
+ * Author: Ian Harrison
+ */
+
+void oglDrawArcToEllipse(double x1, double y1, double a1, double b1, double x2, double y2, double x3, double y3,
+ double *x4, double *y4);
+
+bool oglRoughlyEqual(double val1, double val2, double tol = 0.00001);
+
+extern wxFont* g_oglNormalFont;
+extern wxPen* g_oglBlackPen;
+extern wxPen* g_oglWhiteBackgroundPen;
+extern wxPen* g_oglTransparentPen;
+extern wxBrush* g_oglWhiteBackgroundBrush;
+extern wxPen* g_oglBlackForegroundPen;
+extern wxCursor* g_oglBullseyeCursor;
+
+extern wxFont* oglMatchFont(int point_size);
+
+extern wxString oglColourToHex(const wxColour& colour);
+extern wxColour oglHexToColour(const wxString& hex);
+extern void oglDecToHex(unsigned int dec, char *buf);
+extern unsigned int oglHexToDec(char* buf);
+
+
+#endif
+ // _OGL_MISC_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: ogl.h
+// Purpose: OGL main include
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_OGL_H_
+#define _OGL_OGL_H_
+
+#include "basic.h" // Basic shapes
+#include "lines.h" // Lines and splines
+#include "divided.h" // Vertically-divided rectangle
+#include "composit.h" // Composite images
+#include "canvas.h" // wxShapeCanvas for displaying objects
+#include "ogldiag.h" // wxDiagram
+
+extern void wxOGLInitialize();
+extern void wxOGLCleanUp();
+
+#endif
+ // _OGL_OGL_H_
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: ogldiag.cpp
+// Purpose: wxDiagram
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "ogldiag.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+#pragma hdrstop
+#endif
+
+#ifndef WX_PRECOMP
+#include <wx/wx.h>
+#endif
+
+#include <wx/wxexpr.h>
+
+#if wxUSE_IOSTREAMH
+#include <iostream.h>
+#include <fstream.h>
+#else
+#include <iostream>
+#include <fstream>
+#ifdef _MSC_VER
+using namespace std;
+#endif
+#endif
+
+#include <ctype.h>
+#include <math.h>
+#include <stdlib.h>
+
+#include "basic.h"
+#include "basicp.h"
+#include "canvas.h"
+#include "ogldiag.h"
+#include "lines.h"
+#include "composit.h"
+#include "misc.h"
+
+IMPLEMENT_DYNAMIC_CLASS(wxDiagram, wxObject)
+
+// Object canvas
+wxDiagram::wxDiagram()
+{
+ m_diagramCanvas = NULL;
+ m_quickEditMode = FALSE;
+ m_snapToGrid = TRUE;
+ m_gridSpacing = 5.0;
+ m_shapeList = new wxList;
+ m_mouseTolerance = DEFAULT_MOUSE_TOLERANCE;
+}
+
+wxDiagram::~wxDiagram()
+{
+ if (m_shapeList)
+ delete m_shapeList;
+}
+
+void wxDiagram::SetSnapToGrid(bool snap)
+{
+ m_snapToGrid = snap;
+}
+
+void wxDiagram::SetGridSpacing(double spacing)
+{
+ m_gridSpacing = spacing;
+}
+
+void wxDiagram::Snap(double *x, double *y)
+{
+ if (m_snapToGrid)
+ {
+ *x = m_gridSpacing * ((int)(*x/m_gridSpacing + 0.5));
+ *y = m_gridSpacing * ((int)(*y/m_gridSpacing + 0.5));
+ }
+}
+
+
+void wxDiagram::Redraw(wxDC& dc)
+{
+ if (m_shapeList)
+ {
+ if (GetCanvas())
+ GetCanvas()->SetCursor(* wxHOURGLASS_CURSOR);
+ wxNode *current = m_shapeList->First();
+
+ while (current)
+ {
+ wxShape *object = (wxShape *)current->Data();
+ if (!object->GetParent())
+ object->Draw(dc);
+
+ current = current->Next();
+ }
+ if (GetCanvas())
+ GetCanvas()->SetCursor(* wxSTANDARD_CURSOR);
+ }
+}
+
+void wxDiagram::Clear(wxDC& dc)
+{
+ dc.Clear();
+}
+
+// Insert object after addAfter, or at end of list.
+void wxDiagram::AddShape(wxShape *object, wxShape *addAfter)
+{
+ wxNode *nodeAfter = NULL;
+ if (addAfter)
+ nodeAfter = m_shapeList->Member(addAfter);
+
+ if (!m_shapeList->Member(object))
+ {
+ if (nodeAfter)
+ {
+ if (nodeAfter->Next())
+ m_shapeList->Insert(nodeAfter->Next(), object);
+ else
+ m_shapeList->Append(object);
+ }
+ else
+ m_shapeList->Append(object);
+ object->SetCanvas(GetCanvas());
+ }
+}
+
+void wxDiagram::InsertShape(wxShape *object)
+{
+ m_shapeList->Insert(object);
+ object->SetCanvas(GetCanvas());
+}
+
+void wxDiagram::RemoveShape(wxShape *object)
+{
+ m_shapeList->DeleteObject(object);
+}
+
+// Should this delete the actual objects too? I think not.
+void wxDiagram::RemoveAllShapes()
+{
+ m_shapeList->Clear();
+}
+
+void wxDiagram::DeleteAllShapes()
+{
+ wxNode *node = m_shapeList->First();
+ while (node)
+ {
+ wxShape *shape = (wxShape *)node->Data();
+ if (!shape->GetParent())
+ {
+ RemoveShape(shape);
+ delete shape;
+ node = m_shapeList->First();
+ }
+ else
+ node = node->Next();
+ }
+}
+
+void wxDiagram::ShowAll(bool show)
+{
+ wxNode *current = m_shapeList->First();
+
+ while (current)
+ {
+ wxShape *object = (wxShape *)current->Data();
+ object->Show(show);
+
+ current = current->Next();
+ }
+}
+
+void wxDiagram::DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2)
+{
+ wxPen dottedPen(wxColour(0, 0, 0), 1, wxDOT);
+ dc.SetPen(dottedPen);
+ dc.SetBrush((* wxTRANSPARENT_BRUSH));
+
+ wxPoint points[5];
+
+ points[0].x = (int) x1;
+ points[0].y = (int) y1;
+
+ points[1].x = (int) x2;
+ points[1].y = (int) y1;
+
+ points[2].x = (int) x2;
+ points[2].y = (int) y2;
+
+ points[3].x = (int) x1;
+ points[3].y = (int) y2;
+
+ points[4].x = (int) x1;
+ points[4].y = (int) y1;
+ dc.DrawLines(5, points);
+}
+
+// Make sure all text that should be centred, is centred.
+void wxDiagram::RecentreAll(wxDC& dc)
+{
+ wxNode *object_node = m_shapeList->First();
+ while (object_node)
+ {
+ wxShape *obj = (wxShape *)object_node->Data();
+ obj->Recentre(dc);
+ object_node = object_node->Next();
+ }
+}
+
+// Input/output
+#ifdef PROLOGIO
+bool wxDiagram::SaveFile(const wxString& filename)
+{
+ wxBeginBusyCursor();
+
+ wxExprDatabase *database = new wxExprDatabase;
+
+ // First write the diagram type
+ wxExpr *header = new wxExpr("diagram");
+ OnHeaderSave(*database, *header);
+
+ database->Append(header);
+
+ wxNode *node = m_shapeList->First();
+ while (node)
+ {
+ wxShape *shape = (wxShape *)node->Data();
+
+ if (!shape->IsKindOf(CLASSINFO(wxControlPoint)))
+ {
+ wxExpr *expr = NULL;
+ if (shape->IsKindOf(CLASSINFO(wxLineShape)))
+ expr = new wxExpr("line");
+ else
+ expr = new wxExpr("shape");
+
+ OnShapeSave(*database, *shape, *expr);
+ }
+ node = node->Next();
+ }
+ OnDatabaseSave(*database);
+
+ char tempFile[400];
+ wxGetTempFileName("diag", tempFile);
+ FILE* file = fopen(tempFile, "w");
+ if (! file)
+ {
+ wxEndBusyCursor();
+ delete database;
+ return FALSE;
+ }
+
+ database->Write(file);
+ fclose(file);
+ delete database;
+
+/*
+ // Save backup
+ if (FileExists(filename))
+ {
+ char buf[400];
+#ifdef __X__
+ sprintf(buf, "%s.bak", filename);
+#endif
+#ifdef __WXMSW__
+ sprintf(buf, "_diagram.bak");
+#endif
+ if (FileExists(buf)) wxRemoveFile(buf);
+ if (!wxRenameFile(filename, buf))
+ {
+ wxCopyFile(filename, buf);
+ wxRemoveFile(filename);
+ }
+ }
+*/
+
+ // Copy the temporary file to the correct filename
+ if (!wxRenameFile(tempFile, filename))
+ {
+ wxCopyFile(tempFile, filename);
+ wxRemoveFile(tempFile);
+ }
+
+ wxEndBusyCursor();
+ return TRUE;
+}
+
+bool wxDiagram::LoadFile(const wxString& filename)
+{
+ wxBeginBusyCursor();
+
+ wxExprDatabase database(wxExprInteger, "id");
+ if (!database.Read(filename))
+ {
+ wxEndBusyCursor();
+ return FALSE;
+ }
+
+ DeleteAllShapes();
+
+ database.BeginFind();
+ wxExpr *header = database.FindClauseByFunctor("diagram");
+
+ if (header)
+ OnHeaderLoad(database, *header);
+
+ // Scan through all clauses and register the ids
+ wxNode *node = database.First();
+ while (node)
+ {
+ wxExpr *clause = (wxExpr *)node->Data();
+ long id = -1;
+ clause->GetAttributeValue("id", id);
+ wxRegisterId(id);
+ node = node->Next();
+ }
+
+ ReadNodes(database);
+ ReadContainerGeometry(database);
+ ReadLines(database);
+
+ OnDatabaseLoad(database);
+
+ wxEndBusyCursor();
+
+ return TRUE;
+}
+
+void wxDiagram::ReadNodes(wxExprDatabase& database)
+{
+ // Find and create the node images
+ database.BeginFind();
+ wxExpr *clause = database.FindClauseByFunctor("shape");
+ while (clause)
+ {
+ char *type = NULL;
+ long parentId = -1;
+
+ clause->AssignAttributeValue("type", &type);
+ clause->AssignAttributeValue("parent", &parentId);
+ wxClassInfo *classInfo = wxClassInfo::FindClass(type);
+ if (classInfo)
+ {
+ wxShape *shape = (wxShape *)classInfo->CreateObject();
+ OnShapeLoad(database, *shape, *clause);
+
+ shape->SetCanvas(GetCanvas());
+ shape->Show(TRUE);
+
+ m_shapeList->Append(shape);
+
+ // If child of composite, link up
+ if (parentId > -1)
+ {
+ wxExpr *parentExpr = database.HashFind("shape", parentId);
+ if (parentExpr && parentExpr->GetClientData())
+ {
+ wxShape *parent = (wxShape *)parentExpr->GetClientData();
+ shape->SetParent(parent);
+ parent->GetChildren().Append(shape);
+ }
+ }
+
+ clause->SetClientData(shape);
+ }
+ if (type)
+ delete[] type;
+
+ clause = database.FindClauseByFunctor("shape");
+ }
+ return;
+}
+
+void wxDiagram::ReadLines(wxExprDatabase& database)
+{
+ database.BeginFind();
+ wxExpr *clause = database.FindClauseByFunctor("line");
+ while (clause)
+ {
+ wxString type("");
+ long parentId = -1;
+
+ clause->GetAttributeValue("type", type);
+ clause->GetAttributeValue("parent", parentId);
+ wxClassInfo *classInfo = wxClassInfo::FindClass((char*) (const char*) type);
+ if (classInfo)
+ {
+ wxLineShape *shape = (wxLineShape *)classInfo->CreateObject();
+ shape->Show(TRUE);
+
+ OnShapeLoad(database, *shape, *clause);
+ shape->SetCanvas(GetCanvas());
+
+ long image_to = -1; long image_from = -1;
+ clause->GetAttributeValue("to", image_to);
+ clause->GetAttributeValue("from", image_from);
+
+ wxExpr *image_to_expr = database.HashFind("shape", image_to);
+
+ if (!image_to_expr)
+ {
+ // Error
+ }
+ wxExpr *image_from_expr = database.HashFind("shape", image_from);
+
+ if (!image_from_expr)
+ {
+ // Error
+ }
+
+ if (image_to_expr && image_from_expr)
+ {
+ wxShape *image_to_object = (wxShape *)image_to_expr->GetClientData();
+ wxShape *image_from_object = (wxShape *)image_from_expr->GetClientData();
+
+ if (image_to_object && image_from_object)
+ {
+ image_from_object->AddLine(shape, image_to_object, shape->GetAttachmentFrom(), shape->GetAttachmentTo());
+ }
+ }
+ clause->SetClientData(shape);
+
+ m_shapeList->Append(shape);
+ }
+
+ clause = database.FindClauseByFunctor("line");
+ }
+}
+
+// Containers have divisions that reference adjoining divisions,
+// so we need a separate pass to link everything up.
+// Also used by Symbol Library.
+void wxDiagram::ReadContainerGeometry(wxExprDatabase& database)
+{
+ database.BeginFind();
+ wxExpr *clause = database.FindClauseByFunctor("shape");
+ while (clause)
+ {
+ wxShape *image = (wxShape *)clause->GetClientData();
+ if (image && image->IsKindOf(CLASSINFO(wxCompositeShape)))
+ {
+ wxCompositeShape *composite = (wxCompositeShape *)image;
+ wxExpr *divisionExpr = NULL;
+
+ // Find the list of divisions in the composite
+ clause->GetAttributeValue("divisions", &divisionExpr);
+ if (divisionExpr)
+ {
+ int i = 0;
+ wxExpr *idExpr = divisionExpr->Nth(i);
+ while (idExpr)
+ {
+ long divisionId = idExpr->IntegerValue();
+ wxExpr *childExpr = database.HashFind("shape", divisionId);
+ if (childExpr && childExpr->GetClientData())
+ {
+ wxDivisionShape *child = (wxDivisionShape *)childExpr->GetClientData();
+ composite->GetDivisions().Append(child);
+
+ // Find the adjoining shapes
+ long leftSideId = -1;
+ long topSideId = -1;
+ long rightSideId = -1;
+ long bottomSideId = -1;
+ childExpr->GetAttributeValue("left_side", leftSideId);
+ childExpr->GetAttributeValue("top_side", topSideId);
+ childExpr->GetAttributeValue("right_side", rightSideId);
+ childExpr->GetAttributeValue("bottom_side", bottomSideId);
+ if (leftSideId > -1)
+ {
+ wxExpr *leftExpr = database.HashFind("shape", leftSideId);
+ if (leftExpr && leftExpr->GetClientData())
+ {
+ wxDivisionShape *leftSide = (wxDivisionShape *)leftExpr->GetClientData();
+ child->SetLeftSide(leftSide);
+ }
+ }
+ if (topSideId > -1)
+ {
+ wxExpr *topExpr = database.HashFind("shape", topSideId);
+ if (topExpr && topExpr->GetClientData())
+ {
+ wxDivisionShape *topSide = (wxDivisionShape *)topExpr->GetClientData();
+ child->SetTopSide(topSide);
+ }
+ }
+ if (rightSideId > -1)
+ {
+ wxExpr *rightExpr = database.HashFind("shape", rightSideId);
+ if (rightExpr && rightExpr->GetClientData())
+ {
+ wxDivisionShape *rightSide = (wxDivisionShape *)rightExpr->GetClientData();
+ child->SetRightSide(rightSide);
+ }
+ }
+ if (bottomSideId > -1)
+ {
+ wxExpr *bottomExpr = database.HashFind("shape", bottomSideId);
+ if (bottomExpr && bottomExpr->GetClientData())
+ {
+ wxDivisionShape *bottomSide = (wxDivisionShape *)bottomExpr->GetClientData();
+ child->SetBottomSide(bottomSide);
+ }
+ }
+ }
+ i ++;
+ idExpr = divisionExpr->Nth(i);
+ }
+ }
+ }
+
+ clause = database.FindClauseByFunctor("shape");
+ }
+}
+
+// Allow for modifying file
+bool wxDiagram::OnDatabaseLoad(wxExprDatabase& db)
+{
+ return TRUE;
+}
+
+bool wxDiagram::OnDatabaseSave(wxExprDatabase& db)
+{
+ return TRUE;
+}
+
+bool wxDiagram::OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
+{
+ shape.WriteAttributes(&expr);
+ db.Append(&expr);
+
+ if (shape.IsKindOf(CLASSINFO(wxCompositeShape)))
+ {
+ wxNode *node = shape.GetChildren().First();
+ while (node)
+ {
+ wxShape *childShape = (wxShape *)node->Data();
+ wxExpr *childExpr = new wxExpr("shape");
+ OnShapeSave(db, *childShape, *childExpr);
+ node = node->Next();
+ }
+ }
+
+ return TRUE;
+}
+
+bool wxDiagram::OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr)
+{
+ shape.ReadAttributes(&expr);
+ return TRUE;
+}
+
+bool wxDiagram::OnHeaderSave(wxExprDatabase& db, wxExpr& expr)
+{
+ return TRUE;
+}
+
+bool wxDiagram::OnHeaderLoad(wxExprDatabase& db, wxExpr& expr)
+{
+ return TRUE;
+}
+
+#endif
+
+void wxDiagram::SetCanvas(wxShapeCanvas *can)
+{
+ m_diagramCanvas = can;
+}
+
+// Find a shape by its id
+wxShape* wxDiagram::FindShape(long id) const
+{
+ wxNode* node = GetShapeList()->First();
+ while (node)
+ {
+ wxShape* shape = (wxShape*) node->Data();
+ if (shape->GetId() == id)
+ return shape;
+ node = node->Next();
+ }
+ return NULL;
+}
+
+
+//// Crossings classes
+
+wxLineCrossings::wxLineCrossings()
+{
+}
+
+wxLineCrossings::~wxLineCrossings()
+{
+ ClearCrossings();
+}
+
+void wxLineCrossings::FindCrossings(wxDiagram& diagram)
+{
+ ClearCrossings();
+ wxNode* node1 = diagram.GetShapeList()->First();
+ while (node1)
+ {
+ wxShape* shape1 = (wxShape*) node1->Data();
+ if (shape1->IsKindOf(CLASSINFO(wxLineShape)))
+ {
+ wxLineShape* lineShape1 = (wxLineShape*) shape1;
+ // Iterate through the segments
+ wxList* pts1 = lineShape1->GetLineControlPoints();
+ int i;
+ for (i = 0; i < (pts1->Number() - 1); i++)
+ {
+ wxRealPoint* pt1_a = (wxRealPoint*) (pts1->Nth(i)->Data());
+ wxRealPoint* pt1_b = (wxRealPoint*) (pts1->Nth(i+1)->Data());
+
+ // Now we iterate through the segments again
+
+ wxNode* node2 = diagram.GetShapeList()->First();
+ while (node2)
+ {
+ wxShape* shape2 = (wxShape*) node2->Data();
+
+ // Assume that the same line doesn't cross itself
+ if (shape2->IsKindOf(CLASSINFO(wxLineShape)) && (shape1 != shape2))
+ {
+ wxLineShape* lineShape2 = (wxLineShape*) shape2;
+ // Iterate through the segments
+ wxList* pts2 = lineShape2->GetLineControlPoints();
+ int j;
+ for (j = 0; j < (pts2->Number() - 1); j++)
+ {
+ wxRealPoint* pt2_a = (wxRealPoint*) (pts2->Nth(j)->Data());
+ wxRealPoint* pt2_b = (wxRealPoint*) (pts2->Nth(j+1)->Data());
+
+ // Now let's see if these two segments cross.
+ double ratio1, ratio2;
+ oglCheckLineIntersection(pt1_a->x, pt1_a->y, pt1_b->x, pt1_b->y,
+ pt2_a->x, pt2_a->y, pt2_b->x, pt2_b->y,
+ & ratio1, & ratio2);
+
+ if ((ratio1 < 1.0) && (ratio1 > -1.0))
+ {
+ // Intersection!
+ wxLineCrossing* crossing = new wxLineCrossing;
+ crossing->m_intersect.x = (pt1_a->x + (pt1_b->x - pt1_a->x)*ratio1);
+ crossing->m_intersect.y = (pt1_a->y + (pt1_b->y - pt1_a->y)*ratio1);
+
+ crossing->m_pt1 = * pt1_a;
+ crossing->m_pt2 = * pt1_b;
+ crossing->m_pt3 = * pt2_a;
+ crossing->m_pt4 = * pt2_b;
+
+ crossing->m_lineShape1 = lineShape1;
+ crossing->m_lineShape2 = lineShape2;
+
+ m_crossings.Append(crossing);
+ }
+ }
+ }
+ node2 = node2->Next();
+ }
+ }
+ }
+
+ node1 = node1->Next();
+ }
+}
+
+void wxLineCrossings::DrawCrossings(wxDiagram& diagram, wxDC& dc)
+{
+ dc.SetBrush(*wxTRANSPARENT_BRUSH);
+
+ long arcWidth = 8;
+
+ wxNode* node = m_crossings.First();
+ while (node)
+ {
+ wxLineCrossing* crossing = (wxLineCrossing*) node->Data();
+// dc.DrawEllipse((long) (crossing->m_intersect.x - (arcWidth/2.0) + 0.5), (long) (crossing->m_intersect.y - (arcWidth/2.0) + 0.5),
+// arcWidth, arcWidth);
+
+
+ // Let's do some geometry to find the points on either end of the arc.
+/*
+
+(x1, y1)
+ |\
+ | \
+ | \
+ | \
+ | \
+ | |\ c c1
+ | a | \
+ | \
+ | - x <-- centre of arc
+ a1 | b |\
+ | | \ c2
+ | a2 | \
+ | - \
+ | b2 \
+ | \
+ |_______________\ (x2, y2)
+ b1
+
+*/
+
+ double a1 = wxMax(crossing->m_pt1.y, crossing->m_pt2.y) - wxMin(crossing->m_pt1.y, crossing->m_pt2.y) ;
+ double b1 = wxMax(crossing->m_pt1.x, crossing->m_pt2.x) - wxMin(crossing->m_pt1.x, crossing->m_pt2.x) ;
+ double c1 = sqrt( (a1*a1) + (b1*b1) );
+
+ double c = arcWidth / 2.0;
+ double a = c * a1/c1 ;
+ double b = c * b1/c1 ;
+
+ // I'm not sure this is right, since we don't know which direction we should be going in - need
+ // to know which way the line slopes and choose the sign appropriately.
+ double arcX1 = crossing->m_intersect.x - b;
+ double arcY1 = crossing->m_intersect.y - a;
+
+ double arcX2 = crossing->m_intersect.x + b;
+ double arcY2 = crossing->m_intersect.y + a;
+
+ dc.SetPen(*wxBLACK_PEN);
+ dc.DrawArc( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2,
+ (long) crossing->m_intersect.x, (long) crossing->m_intersect.y);
+
+ dc.SetPen(*wxWHITE_PEN);
+ dc.DrawLine( (long) arcX1, (long) arcY1, (long) arcX2, (long) arcY2 );
+
+ node = node->Next();
+ }
+}
+
+void wxLineCrossings::ClearCrossings()
+{
+ wxNode* node = m_crossings.First();
+ while (node)
+ {
+ wxLineCrossing* crossing = (wxLineCrossing*) node->Data();
+ delete crossing;
+ node = node->Next();
+ }
+ m_crossings.Clear();
+}
+
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: ogldiag.h
+// Purpose: OGL - wxDiagram class
+// Author: Julian Smart
+// Modified by:
+// Created: 12/07/98
+// RCS-ID: $Id$
+// Copyright: (c) Julian Smart
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef _OGL_OGLDIAG_H_
+#define _OGL_OGLDIAG_H_
+
+#ifdef __GNUG__
+#pragma interface "ogldiag.h"
+#endif
+
+#include "basic.h"
+
+class wxDiagram: public wxObject
+{
+ DECLARE_DYNAMIC_CLASS(wxDiagram)
+
+public:
+
+ wxDiagram();
+ virtual ~wxDiagram();
+
+ void SetCanvas(wxShapeCanvas *can);
+
+ inline wxShapeCanvas *GetCanvas() const { return m_diagramCanvas; }
+
+ virtual void Redraw(wxDC& dc);
+ virtual void Clear(wxDC& dc);
+ virtual void DrawOutline(wxDC& dc, double x1, double y1, double x2, double y2);
+
+ // Add object to end of object list (if addAfter is NULL)
+ // or just after addAfter.
+ virtual void AddShape(wxShape *object, wxShape *addAfter = NULL);
+
+ // Add object to front of object list
+ virtual void InsertShape(wxShape *object);
+
+ void SetSnapToGrid(bool snap);
+ void SetGridSpacing(double spacing);
+ inline double GetGridSpacing() const { return m_gridSpacing; }
+ inline bool GetSnapToGrid() const { return m_snapToGrid; }
+ void Snap(double *x, double *y);
+
+ inline void SetQuickEditMode(bool qem) { m_quickEditMode = qem; }
+ inline bool GetQuickEditMode() const { return m_quickEditMode; }
+
+ virtual void RemoveShape(wxShape *object);
+ virtual void RemoveAllShapes();
+ virtual void DeleteAllShapes();
+ virtual void ShowAll(bool show);
+
+ // Find a shape by its id
+ wxShape* FindShape(long id) const;
+
+ inline void SetMouseTolerance(int tol) { m_mouseTolerance = tol; }
+ inline int GetMouseTolerance() const { return m_mouseTolerance; }
+ inline wxList *GetShapeList() const { return m_shapeList; }
+ inline int GetCount() const { return m_shapeList->Number(); }
+
+ // Make sure all text that should be centred, is centred.
+ void RecentreAll(wxDC& dc);
+
+#ifdef PROLOGIO
+ virtual bool SaveFile(const wxString& filename);
+ virtual bool LoadFile(const wxString& filename);
+
+ virtual void ReadNodes(wxExprDatabase& database);
+ virtual void ReadLines(wxExprDatabase& database);
+ virtual void ReadContainerGeometry(wxExprDatabase& database);
+
+ // Allow for modifying file
+ virtual bool OnDatabaseLoad(wxExprDatabase& db);
+ virtual bool OnDatabaseSave(wxExprDatabase& db);
+ virtual bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
+ virtual bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
+ virtual bool OnHeaderSave(wxExprDatabase& db, wxExpr& expr);
+ virtual bool OnHeaderLoad(wxExprDatabase& db, wxExpr& expr);
+#endif
+
+protected:
+ wxShapeCanvas* m_diagramCanvas;
+ bool m_quickEditMode;
+ bool m_snapToGrid;
+ double m_gridSpacing;
+ int m_mouseTolerance;
+ wxList* m_shapeList;
+};
+
+class wxLineCrossing: public wxObject
+{
+public:
+ wxLineCrossing() { m_lineShape1 = NULL; m_lineShape2 = NULL; }
+ wxRealPoint m_pt1; // First line
+ wxRealPoint m_pt2;
+ wxRealPoint m_pt3; // Second line
+ wxRealPoint m_pt4;
+ wxRealPoint m_intersect;
+ wxLineShape* m_lineShape1;
+ wxLineShape* m_lineShape2;
+};
+
+class wxLineCrossings: public wxObject
+{
+public:
+ wxLineCrossings();
+ ~wxLineCrossings();
+
+ void FindCrossings(wxDiagram& diagram);
+ void DrawCrossings(wxDiagram& diagram, wxDC& dc);
+ void ClearCrossings();
+
+public:
+ wxList m_crossings;
+};
+
+#endif
+ // _OGL_OGLDIAG_H_