File: hdSimpleTextFigure.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 (139 lines) | stat: -rw-r--r-- 3,218 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Copyright (C) 2002 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// hdSimpleTextFigure.cpp - A simple rectangle  figure with text inside it
//
//////////////////////////////////////////////////////////////////////////

#include "pgAdmin3.h"

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

// App headers
#include "hotdraw/figures/hdSimpleTextFigure.h"
#include "hotdraw/tools/hdSimpleTextTool.h"
#include "hotdraw/utilities/hdGeometry.h"
#include "hotdraw/figures/defaultAttributes/hdFontAttribute.h"

// dummy image
#include "images/ddnull.pngc"

hdSimpleTextFigure::hdSimpleTextFigure(wxString textString)
{
	textEditable = false;
	font = *hdFontAttribute::defaultFont;
	padding = 2;
	setText(textString);
	showMenu = false;
}

hdSimpleTextFigure::~hdSimpleTextFigure()
{
}

void hdSimpleTextFigure::setText(wxString textString)
{
	text = textString;
	recalculateDisplayBox();
}

//extended is flag that inform about returning an extended version of text stored at figure
wxString &hdSimpleTextFigure::getText(bool extended)
{
	return text;
}

void hdSimpleTextFigure::setFont(wxFont textFont)
{
	font = textFont;
	recalculateDisplayBox();
}

void hdSimpleTextFigure::getFontMetrics(int &width, int &height)
{
	wxBitmap emptyBitmap(*ddnull_png_img);
	wxMemoryDC temp_dc;
	temp_dc.SelectObject(emptyBitmap);
	temp_dc.SetFont(font);
	if(getText(true).length() > 5)
		temp_dc.GetTextExtent(getText(true), &width, &height);
	else
		temp_dc.GetTextExtent(wxT("EMPTY"), &width, &height);
}

void hdSimpleTextFigure::recalculateDisplayBox()
{
	int w, h;

	getFontMetrics(w, h);

	hdGeometry g;
	displayBox().width = g.max(w, 10) + padding;
	displayBox().height = g.max(h, 10) + padding;
}

void hdSimpleTextFigure::basicDraw(wxBufferedDC &context, hdDrawingView *view)
{
	hdRect copy = displayBox().gethdRect(view->getIdx());
	view->CalcScrolledPosition(copy.x, copy.y, &copy.x, &copy.y);
	context.DrawText(getText(true), copy.GetPosition());
}

void hdSimpleTextFigure::basicDrawSelected(wxBufferedDC &context, hdDrawingView *view)
{
	hdRect copy = displayBox().gethdRect(view->getIdx());
	view->CalcScrolledPosition(copy.x, copy.y, &copy.x, &copy.y);
	context.DrawText(getText(true), copy.GetPosition());
}

void hdSimpleTextFigure::basicMoveBy(int posIdx, int x, int y)
{
	displayBox().x[posIdx] += x;
	displayBox().y[posIdx] += y;
}

hdITool *hdSimpleTextFigure::CreateFigureTool(hdDrawingView *view, hdITool *defaultTool)
{
	return textEditable ? new hdSimpleTextTool(view, this, defaultTool) : defaultTool;
}

void hdSimpleTextFigure::setEditable(bool value)
{
	textEditable = value;
}

bool hdSimpleTextFigure::getEditable()
{
	return textEditable;
}

int hdSimpleTextFigure::getPadding()
{
	return padding;
}

void hdSimpleTextFigure::enablePopUp()
{
	showMenu = true;
}

void hdSimpleTextFigure::disablePopUp()
{
	showMenu = false;
}

bool hdSimpleTextFigure::menuEnabled()
{
	return 	showMenu;
}

void hdSimpleTextFigure::OnGenericPopupClick(wxCommandEvent &event, hdDrawingView *view)
{
	setText(strings[event.GetId()]);
}