1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
////////////////////////////////////////////////////////////////////////////////
23
#include "shapeview.h"
25
#include "diagramviewer.h"
26
#include "textshape.h"
27
#include "nodeshape.h"
30
TextShape::TextShape(ShapeView *v, Grafport *g, Shape *shape): Shape(v,g) {
35
alignment = v->GetViewer()->GetDefaultTextAlignment();
36
font = v->GetViewer()->GetDefaultFont();
37
SetColor(v->GetViewer()->GetDefaultTextColor());
42
wellPositioned = True;
43
underlined = v->GetViewer()->GetDefaultFont()->IsUnderlined();
45
readDirection = ReadDirection::NONE;
48
TextShape::TextShape(const TextShape &t): Shape(t) {
51
description = t.description;
54
alignment = t.alignment;
55
stringWidth = t.stringWidth;
56
stringHeight = t.stringHeight;
57
sequence = t.sequence;
58
wellPositioned = True;
59
underlined = t.underlined;
60
directed = t.directed;
61
readDirection = t.readDirection;
65
void TextShape::SetString(const string *s) {
68
text.replace('\r', ' ');
70
font->Box(&text, w, h);
76
void TextShape::SetString(const char *ch) {
79
text.replace('\r', ' ');
81
font->Box(&text, w, h);
87
void TextShape::TextBox(int &wd, int &ht) {
92
void TextShape::SetPosition(const Point *pos, bool) {
93
Shape::SetPosition(pos, False);
96
void TextShape::DrawOutLine(const Point *c) {
97
int x = c->x - GetWidth() / 2;
98
int y = c->y - GetHeight() / 2;
99
SetOutlineAttributes();
100
GetGrafport()->DrawRectangle(x, y, GetWidth(), GetHeight());
103
void TextShape::UpdateAlignment(TextAlign::Type a) {
104
if (a != alignment) {
111
void TextShape::SetFont(XFont *ft) {
113
font->Box(&text, stringWidth, stringHeight);
114
SetSize(stringWidth+2, stringHeight);
117
void TextShape::UpdateFont(XFont *ft) {
125
void TextShape::Draw() {
126
bool setempty = False;
127
if (underlined && text.length() == 0) {
128
// show little dash with empty underlined text.
132
if (text.length() > 0) {
134
GetGrafport()->SetFont(font);
135
Point pos = *GetPosition();
136
if (alignment == TextAlign::CENTER)
137
GetGrafport()->DrawStringsCentered(
138
pos.x, pos.y, &text, underlined);
139
else if (alignment == TextAlign::LEFT) {
140
double tlx = pos.x - stringWidth * 0.5;
141
double tly = pos.y - stringHeight * 0.5;
142
GetGrafport()->DrawStringsLeft(tlx, tly, &text,
146
double tlx = pos.x + stringWidth * 0.5;
147
double tly = pos.y - stringHeight * 0.5;
148
GetGrafport()->DrawStringsRight(tlx, tly, &text,
157
void TextShape::DrawSelect() {
158
if (text.length() > 0 && IsSelected()) {
159
Point pos = *GetPosition();
160
int x = pos.x - GetWidth() / 2;
161
int y = pos.y - GetHeight() / 2;
162
GetGrafport()->SetLineWidth(1);
163
GetGrafport()->SetLineStyle(LineStyle::DOTTED);
164
GetGrafport()->DrawRectangle(x, y, GetWidth(), GetHeight());
168
bool TextShape::HasString(const string *s, bool sens, bool substr) const {
172
// make them the same case.
177
return (t2.contains(t1));
182
int TextShape::ReplaceString(const string *s1, const string *s2,
183
bool sens, bool substr) {
187
if (!substr && pat != text)
191
int n = copy.replace(pat, repl, sens);
193
GetViewer()->GetDiagram()->SetText(this, ©);
197
void TextShape::UpdateUnderlined(bool b) {
198
if (underlined != b) {
205
bool TextShape::HasString(const string *s1,
206
bool sens, bool substr, List<TextShape *> *list) {
207
bool b= HasString(s1, sens, substr);
209
TextShape *me = this;
215
bool TextShape::InTextArea(int x, int y) {
216
return (ContainsPt(x, y));
219
bool TextShape::ContainsPt(int x, int y) {
220
if (text.length() == 0)
222
Rectangle rect(GetLeftMost(), GetTopMost(), GetWidth(), GetHeight());
223
bool iR1 = rect.Inside(x, y);
224
bool iR2 = rect.Inside(x, y); // also init
226
if (directed) { // directed textshape
227
Rectangle rect2(GetLeftMost(), GetTopMost(),
228
GetWidth() + 16, GetHeight());
229
iR2 = rect2.Inside(x, y);
231
return (iR1 || iR2 );
234
void TextShape::UpdateReadDirection(ReadDirection::Type d) {
235
if (readDirection != d) {