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 "addcolumnscmd.h"
23
#include "tableviewer.h"
25
#include "cellcolumn.h"
28
AddColumnsCmd::AddColumnsCmd(Table *t, TableViewer *v, int n, int p):
30
// add n columns to end of table.
32
numberOfColumns = n; // nr. of columns to be added.
33
columns = new List<CellColumn *>; // columns to be added.
35
int tcolumns = tviewer->GetNumberOfColumns(); // current nr of columns
36
int trows = tviewer->GetNumberOfRows(); // current nr of rows
37
int width = tviewer->GetDefaultColumnWidth(); // width of new columns
38
if (columnPosition >= tcolumns)
39
columnPosition = tcolumns;
40
int x, y; // coordinates of each new cell.
41
if (tcolumns == 0) { // empty table.
42
x = tviewer->GetTopLeft()->x + width/2;
43
trows = tviewer->GetDefaultNumberOfRows();
45
else if (columnPosition < tcolumns) { // insert in table:
46
// look at column left.
47
Point pt = tviewer->GetColumnTopLeft(columnPosition);
50
else { // add to the left of table: look at leftmost column.
51
Point pt = tviewer->GetColumnTopLeft(columnPosition-1);
52
x = pt.x + tviewer->GetColumnWidth(columnPosition-1) + width/2;
54
for (int i = 0; i < n; i++) {
55
// create a new column
56
int colnr = columnPosition + i;
57
CellColumn *column = new CellColumn(tviewer, colnr, width);
59
column->SetLabelsVisible(tviewer->IsShowRowColumnLabels());
60
for (int j = 0; j < trows; j++) {
61
// fill column with new cells.
62
int height = tviewer->GetRowHeight(j);
63
Point pt = tviewer->GetRowTopLeft(j);
65
Cell *c = new Cell(GetGrafport(),
66
tviewer->GetDefaultFont(),
67
tviewer->GiveRow(j), column, x, y,
80
AddColumnsCmd::~AddColumnsCmd() {
86
void AddColumnsCmd::Execute() {
87
// add columns to viewer
88
for (columns->first(); !columns->done(); columns->next())
89
tviewer->InsertColumn(columns->cur());
90
if (columns->count() > 0) {
92
GetMainWindow()->FitDocument();
95
GetMainWindow()->SetStatus(
96
"aborted: no columns are to be added");
101
void AddColumnsCmd::UnExecute() {
102
for (columns->last(); !columns->done(); columns->prev())
103
tviewer->DeleteColumn(columns->cur());
104
if (check(columns->count() > 0))
105
Command::UnExecute();
107
GetMainWindow()->SetStatus(
108
"aborted: no columns are to be removed");
111
void AddColumnsCmd::ReExecute() {
112
for (columns->first(); !columns->done(); columns->next())
113
columns->cur()->Draw();