1
////////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1996, 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
////////////////////////////////////////////////////////////////////////////////
22
#include "tableviewer.h"
27
#include "celltextbuffer.h"
29
#include "pastecelltextscmd.h"
31
const int PasteCellTextsCmd::MIN_BOX_SIZE = 10;
33
PasteCellTextsCmd::PasteCellTextsCmd(Table *t, TableViewer *v): Command(t, v) {
35
buffer = v->GetBuffer();
36
pastedCells = new List<Cell *>;
37
oldStrings = new List<string *>;
39
if (buffer->IsEmpty()) {
40
GetMainWindow()->SetStatus("aborted: empty paste buffer");
43
cellTexts = buffer->GetTexts();
47
PasteCellTextsCmd::~PasteCellTextsCmd() {
56
void PasteCellTextsCmd::MakeBox() {
58
topLeft = buffer->GetTopLeft();
59
bottomRight = buffer->GetBottomRight();
60
width = bottomRight.x - topLeft.x;
61
width = max(width, MIN_BOX_SIZE);
62
height = bottomRight.y - topLeft.y;
63
height = max(height, MIN_BOX_SIZE);
64
tviewer->SetPasting(True);
65
Point pt = Scale(&topLeft);
66
// Start mouse operation
67
TrackMouse(TRACK_PRESS, &pt, &pt, &pt);
70
void PasteCellTextsCmd::Execute() {
71
Point p = topLeft + delta;
72
Cell *topLeftCell = tviewer->HitCell(p.x, p.y);
74
GetMainWindow()->SetStatus(
75
"aborted: topleft of the box is out of the table");
79
Point tl1 = Point(topLeftCell->GetRow()->GetNumber(),
80
topLeftCell->GetColumn()->GetNumber());
81
List<Point *> *rcPositions = buffer->GetPositions();
82
for (unsigned i=0; i<cellTexts->count(); i++) {
85
CellText *t = (*cellTexts)[i];
86
Point pt = *(*rcPositions)[i];
87
pt = pt - buffer->GetRcTopLeft();
89
if ((row = tviewer->GiveRow(pt.x))) {
90
if ((cell = row->NthCell(pt.y))) {
91
string oldText = *cell->GetText();
92
pastedCells->add(cell);
93
oldStrings->add(new string (oldText));
95
if (!((Table *)GetDocument())->UpdateText(
96
cell, t->GetText())) {
97
cell->UpdateText(&oldText);
98
GetMainWindow()->SetStatus(
99
"aborted: cannot paste text "
103
if (tviewer->IsAutoResize())
104
tviewer->RecomputeSizeCell(cell);
109
GetMainWindow()->FitDocument();
112
void PasteCellTextsCmd::UnExecute() {
113
if (pastedCells->first() && oldStrings->first()) {
115
pastedCells->cur()->UpdateText(oldStrings->cur());
116
if (tviewer->IsAutoResize())
117
tviewer->RecomputeSizeCell(pastedCells->cur());
118
} while (pastedCells->next() && oldStrings->next());
120
Command::UnExecute();
123
void PasteCellTextsCmd::Abort() {
125
tviewer->SetPasting(False);
129
void PasteCellTextsCmd::TrackMouse(TrackType aPhase, Point *anchorPoint,
130
Point*, Point *nextPoint) {
133
GetMainWindow()->SetCursor(MouseCursor::FLEUR);
135
delta = *nextPoint - *anchorPoint;
138
anchor = *anchorPoint;
144
delta = *nextPoint - anchor;
148
GetMainWindow()->SetCursor(MouseCursor::LEFT_PTR);
151
delta = ScaleCorrect(&delta);
152
MoveCellTexts(&delta);
153
tviewer->SetPasting(False);
154
tviewer->ExecuteCommand();
157
error("unknown track type\n");
162
void PasteCellTextsCmd::MoveCellTexts(const Point *d) {
163
for (cellTexts->first(); !cellTexts->done(); cellTexts->next()) {
164
CellText *t = cellTexts->cur();
165
Point newPos = *t->GetPosition() + *d;
166
t->SetPosition(&newPos);
170
void PasteCellTextsCmd::DrawOutLine(const Point *d) {
172
Point p2 = ScaleCorrect(d);
174
GetGrafport()->SetLineWidth(1);
175
GetGrafport()->SetLineStyle(LineStyle::DOTTED);
176
GetGrafport()->DrawRectangle(pt.x, pt.y, width, height);