File: ddSouthTableSizeHandle.cpp

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (94 lines) | stat: -rw-r--r-- 2,605 bytes parent folder | download
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
91
92
93
94
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// ddSouthTableSizeHandle.cpp - Allow to change table size by using drag and drop from south side of table rectangle
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

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

// App headers
#include "dd/dditems/handles/ddSouthTableSizeHandle.h"
#include "dd/dditems/figures/ddTableFigure.h"
#include "hotdraw/utilities/hdGeometry.h"
#include "hotdraw/figures/defaultAttributes/hdFontAttribute.h"
#include "hotdraw/main/hdDrawingView.h"

ddSouthTableSizeHandle::ddSouthTableSizeHandle(ddTableFigure *owner, hdILocator *locator):
	hdLocatorHandle(owner, locator)
{
}

hdRect &ddSouthTableSizeHandle::getDisplayBox(int posIdx)
{
	hdPoint p = locate(posIdx);
	ddTableFigure *table = (ddTableFigure *) getOwner();
	displayBox.width = table->getFullSpace().width * 0.5; //as defined at locator
	displayBox.height = 3;
	displayBox.SetPosition(p);
	return displayBox;
}


wxCursor ddSouthTableSizeHandle::createCursor()
{
	return wxCursor(wxCURSOR_SIZENS);
}

void ddSouthTableSizeHandle::draw(wxBufferedDC &context, hdDrawingView *view)
{
}

ddSouthTableSizeHandle::~ddSouthTableSizeHandle()
{
}

void ddSouthTableSizeHandle::invokeStart(hdMouseEvent &event, hdDrawingView *view)
{
	anchorY = event.GetPosition().y;
}

void ddSouthTableSizeHandle::invokeStep(hdMouseEvent &event, hdDrawingView *view)
{
	int y = event.GetPosition().y;
	ddTableFigure *table = (ddTableFigure *) getOwner();
	wxFont font = *hdFontAttribute::defaultFont;
	int colOffset = table->getColDefaultHeight(font);

	int divBy = (table->getTotalColumns() - table->getColumnsWindow());
	if(divBy <= 0)
		divBy = table->getColumnsWindow();

	hdGeometry g;
	if ( g.ddabs(anchorY - y) > colOffset)
	{
		if((anchorY - y) > 0)
		{
			table->setColumnsWindow(view->getIdx(), table->getColumnsWindow() - 1);
		}
		else
		{
			table->setColumnsWindow(view->getIdx(), table->getColumnsWindow() + 1);
		}
		anchorY = y;
	}

	//hack to update relationship position when table size change
	table->manuallyNotifyChange(view->getIdx());
	view->notifyChanged();
}

void ddSouthTableSizeHandle::invokeEnd(hdMouseEvent &event, hdDrawingView *view)
{
	//hack to update relationship position when table size change
	ddTableFigure *table = (ddTableFigure *) getOwner();
	table->manuallyNotifyChange(view->getIdx());
	view->notifyChanged();
}