EraseRegion(dc, region, xx, yy);
if (m_labelObjects[i])
{
- m_labelObjects[i]->Select(FALSE);
+ m_labelObjects[i]->Select(FALSE, &dc);
m_labelObjects[i]->Erase(dc);
m_labelObjects[i]->SetSize(actualW, actualH);
}
else point2->y = point1->y;
}
-void wxLineShape::Straighten(wxDC& dc)
+void wxLineShape::Straighten(wxDC *dc)
{
if (!m_lineControlPoints || m_lineControlPoints->Number() < 3)
return;
- Erase(dc);
+ if (dc)
+ Erase(* dc);
wxNode *first_point_node = m_lineControlPoints->First();
wxNode *last_point_node = m_lineControlPoints->Last();
node = node->Next();
}
- Draw(dc);
+ if (dc)
+ Draw(* dc);
}
m_attachmentFrom = 0;
clause->AssignAttributeValue("attachment_to", &m_attachmentTo);
- clause->AssignAttributeValue("attachmen_from", &m_attachmentFrom);
+ clause->AssignAttributeValue("attachment_from", &m_attachmentFrom);
wxExpr *line_list = NULL;
m_labelObjects[i]->RemoveFromCanvas(m_canvas);
delete m_labelObjects[i];
}
- m_labelObjects[i] = new wxLabelShape(this, region, w, h);
+ 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);
+ m_labelObjects[i]->Select(TRUE, dc);
}
}
}
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;
m_xpos = x;
m_ypos = y;
m_type = the_type;
+ m_point = NULL;
}
wxLineControlPoint::~wxLineControlPoint()
if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
{
- lpt->SetX(x); lpt->SetY(y);
+// lpt->SetX(x); lpt->SetY(y);
}
}
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);
if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM || lpt->m_type == CONTROL_POINT_ENDPOINT_TO)
{
- lpt->Erase(dc);
- lineShape->OnDraw(dc);
- if (lpt->m_type == CONTROL_POINT_ENDPOINT_FROM)
- {
- lineShape->GetFrom()->OnDraw(dc);
- lineShape->GetFrom()->OnDrawContents(dc);
- }
- else
- {
- lineShape->GetTo()->OnDraw(dc);
- lineShape->GetTo()->OnDrawContents(dc);
- }
m_canvas->SetCursor(g_oglBullseyeCursor);
lpt->m_oldCursor = wxSTANDARD_CURSOR;
}
{
m_canvas->Snap(&x, &y);
- dc.SetLogicalFunction(wxCOPY);
- lpt->m_xpos = x; lpt->m_ypos = y;
- lpt->m_point->x = x; lpt->m_point->y = 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;
- lineShape->GetEventHandler()->OnMoveLink(dc);
+ 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;
+// this->Erase(dc);
+
+// lpt->m_xpos = x; lpt->m_ypos = y;
if (lineShape->GetFrom())
{
if (lpt->m_oldCursor)
m_canvas->SetCursor(lpt->m_oldCursor);
- lpt->m_xpos = x; lpt->m_ypos = y;
+// lpt->m_xpos = x; lpt->m_ypos = y;
if (lineShape->GetTo())
{
// 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.
- wxLineShape *lineObj = lineShape;
- wxShapeCanvas *objCanvas = m_canvas;
- lineObj->OnMoveControlPoint(i+1, x, y);
+ 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.
}
}
+// 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
*
bool wxLabelShape::OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display)
{
- m_shapeRegion->SetSize(m_width, m_height);
+ 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 = m_lineShape->GetRegions().First();
+ wxNode *node = GetRegions().First();
while (node)
{
- if (m_shapeRegion == (wxShapeRegion *)node->Data())
+ if (labelShape->m_shapeRegion == (wxShapeRegion *)node->Data())
node = NULL;
else
{
}
}
double xx, yy;
- m_lineShape->GetLabelPosition(i, &xx, &yy);
+ GetLabelPosition(i, &xx, &yy);
// Set the region's offset, relative to the default position for
// each region.
- m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy));
+ labelShape->m_shapeRegion->SetPosition((double)(x - xx), (double)(y - yy));
+
+ labelShape->SetX(x);
+ labelShape->SetY(y);
// Need to reformat to fit region.
- if (m_shapeRegion->GetText())
+ if (labelShape->m_shapeRegion->GetText())
{
- wxString s(m_shapeRegion->GetText());
- m_lineShape->FormatText(dc, s, i);
- m_lineShape->DrawRegion(dc, m_shapeRegion, xx, yy);
+ wxString s(labelShape->m_shapeRegion->GetText());
+ labelShape->FormatText(dc, s, i);
+ DrawRegion(dc, labelShape->m_shapeRegion, xx, yy);
}
return TRUE;
}
};
// Line object
+class wxLabelShape;
class wxLineShape: public wxShape
{
DECLARE_DYNAMIC_CLASS(wxLineShape)
void OnDrawControlPoints(wxDC& dc);
void OnEraseControlPoints(wxDC& dc);
void OnErase(wxDC& dc);
- virtual inline void OnMoveControlPoint(int WXUNUSED(which), double WXUNUSED(x), double WXUNUSED(y)) {}
+ 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);
// 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);
+ virtual void Straighten(wxDC* dc = NULL);
// Not implemented
inline void SetMaintainStraightLines(bool flag) { m_maintainStraightLines = flag; }