~ubuntu-branches/ubuntu/intrepid/tcm/intrepid

« back to all changes in this revision

Viewing changes to src/tb/addcolumnscmd.c

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
ImportĀ upstreamĀ versionĀ 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
////////////////////////////////////////////////////////////////////////////////
 
2
//
 
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).
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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
 
20
// 02111-1307, USA.
 
21
////////////////////////////////////////////////////////////////////////////////
 
22
#include "addcolumnscmd.h"
 
23
#include "tableviewer.h"
 
24
#include "table.h"
 
25
#include "cellcolumn.h"
 
26
#include "cell.h"
 
27
 
 
28
AddColumnsCmd::AddColumnsCmd(Table *t, TableViewer *v, int n, int p): 
 
29
                Command(t, v) {
 
30
        // add n columns to end of table.
 
31
        columnPosition = p;
 
32
        numberOfColumns = n;              // nr. of columns to be added.
 
33
        columns = new List<CellColumn *>; // columns to be added.
 
34
        tviewer = v;
 
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();
 
44
        }
 
45
        else if (columnPosition < tcolumns) {   // insert in table: 
 
46
                                                // look at column left.
 
47
                Point pt = tviewer->GetColumnTopLeft(columnPosition);
 
48
                x = pt.x + width/2;
 
49
        }
 
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;
 
53
        }
 
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);
 
58
                columns->add(column);
 
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);
 
64
                        y = pt.y + height/2;
 
65
                        Cell *c = new Cell(GetGrafport(), 
 
66
                                tviewer->GetDefaultFont(),
 
67
                                tviewer->GiveRow(j), column, x, y, 
 
68
                                width, height);
 
69
#ifdef DEBUG
 
70
                        string s = j;
 
71
                        s += ","; s+= colnr;
 
72
                        c->UpdateText(&s);
 
73
#endif
 
74
                        column->AddCell(c);
 
75
                }
 
76
                x += width;
 
77
        }
 
78
}
 
79
 
 
80
AddColumnsCmd::~AddColumnsCmd() {
 
81
        if (!CmdDone())
 
82
                columns->clear();
 
83
        delete columns;
 
84
}
 
85
 
 
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) {
 
91
                Command::Execute();
 
92
                GetMainWindow()->FitDocument();
 
93
        }
 
94
        else {
 
95
                GetMainWindow()->SetStatus(
 
96
                        "aborted: no columns are to be added");
 
97
                Abort();
 
98
        }
 
99
}
 
100
 
 
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();
 
106
        else
 
107
                GetMainWindow()->SetStatus(
 
108
                        "aborted: no columns are to be removed");
 
109
}
 
110
 
 
111
void AddColumnsCmd::ReExecute() {
 
112
        for (columns->first(); !columns->done(); columns->next())
 
113
                columns->cur()->Draw();
 
114
        Execute();
 
115
}