~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic-proposed

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2013, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// hdPolyLineHandle.cpp - Handle for manipulation of multiple flexibility points lines.
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

// wxWindows headers
#include <wx/wx.h>
#include <wx/dcbuffer.h>

// App headers
#include "hotdraw/handles/hdPolyLineHandle.h"
#include "hotdraw/figures/hdPolyLineFigure.h"
#include "hotdraw/locators/hdPolyLineLocator.h"
#include "hotdraw/main/hdDrawingView.h"


hdPolyLineHandle::hdPolyLineHandle(hdPolyLineFigure *figure, hdILocator *loc, int index):
	hdLocatorHandle((hdIFigure *)figure, loc)
{
	indx = index;
}

hdPolyLineHandle::~hdPolyLineHandle()
{
}

void hdPolyLineHandle::draw(wxBufferedDC &context, hdDrawingView *view)
{
	//A Handle at polyline figure without a respetive flexibility point at line
	//Hack to allow handles of polylines reuse between different versions of same line.
	if(getOwner() && indx < (((hdPolyLineFigure *) getOwner())->countPointsAt(view->getIdx()) - 1) ) //indx 0 is first, count first is 1
	{
		hdRect copy = getDisplayBox(view->getIdx());
		view->CalcScrolledPosition(copy.x, copy.y, &copy.x, &copy.y);

		/* Uncomment this for testing purposes of handles in a polyline figure
		wxString pos = wxString::Format(_("%d"),indx);
		double middle2 = copy.width / 2;
		context.DrawText(pos,copy.x + middle2+3, copy.y + middle2);
		*/

		double middle = copy.width / 2;
		context.DrawCircle(
		    wxPoint(copy.x + middle, copy.y + middle),
		    wxCoord(middle)
		);
	}
}

void hdPolyLineHandle::invokeStep(hdMouseEvent &event, hdDrawingView *view)
{
	int x = event.GetPosition().x, y = event.GetPosition().y;
	((hdPolyLineFigure *) getOwner())->setPointAt(view->getIdx(), indx, x, y);
	view->notifyChanged();

}

void hdPolyLineHandle::invokeStart(hdMouseEvent &event, hdDrawingView *view)
{
	if(event.RightDown())
	{
		((hdPolyLineFigure *) getOwner())->removePointAt(view->getIdx(), indx);
		view->notifyChanged();
	}
}
wxCursor hdPolyLineHandle::createCursor()
{
	return wxCursor(wxCURSOR_CROSS);

}

int hdPolyLineHandle::getIndex()
{
	return indx;
}

void hdPolyLineHandle::setIndex(int index)
{
	indx = index;
	hdPolyLineLocator *l = (hdPolyLineLocator *) locator();
	l->setIndex(index);
}