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

« back to all changes in this revision

Viewing changes to src/tb/celltextbuffer.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 "celltextbuffer.h"
 
23
#include "tableviewer.h"
 
24
#include "celltext.h"
 
25
#include "cell.h"
 
26
 
 
27
CellTextBuffer::CellTextBuffer() {
 
28
        cellTexts = 0;
 
29
        prevCellTexts = 0;
 
30
        rcPositions = new List<Point *>;
 
31
        prevRcPositions = new List<Point *>;
 
32
}
 
33
 
 
34
CellTextBuffer::~CellTextBuffer() {
 
35
        if (cellTexts) {
 
36
                cellTexts->clear();
 
37
                delete cellTexts;
 
38
        }
 
39
        if (prevCellTexts) {
 
40
                prevCellTexts->clear();
 
41
                delete prevCellTexts;
 
42
        }
 
43
        rcPositions->clear();
 
44
        prevRcPositions->clear();
 
45
        delete rcPositions;
 
46
        delete prevRcPositions;
 
47
}
 
48
 
 
49
void CellTextBuffer::PutTexts(List<CellText *> *c) {
 
50
        if (prevCellTexts) {
 
51
                prevCellTexts->clear();
 
52
                delete prevCellTexts;
 
53
        }
 
54
        prevCellTexts = cellTexts;
 
55
        cellTexts = new List<CellText *>;
 
56
        // make a copy.
 
57
        for (c->first(); !c->done(); c->next()) {
 
58
                CellText *t1 = c->cur();
 
59
                CellText *t2 = new CellText(*t1);
 
60
                cellTexts->add(t2);
 
61
        }
 
62
        CalcSizeBuffer();
 
63
}
 
64
 
 
65
void CellTextBuffer::PutPositions(List<Point *> *p) {
 
66
        prevRcPositions->clear();
 
67
        *prevRcPositions = *rcPositions;
 
68
        rcPositions->empty();
 
69
        if (p->first())
 
70
                rcTopLeft = *p->cur();
 
71
        else
 
72
                rcTopLeft = Point(0,0);
 
73
        for (p->first(); !p->done(); p->next()) {
 
74
                rcPositions->add(new Point(*p->cur()));
 
75
                rcTopLeft = Point(min(rcTopLeft.x,p->cur()->x),
 
76
                                  min(rcTopLeft.y,p->cur()->y));
 
77
        }
 
78
}
 
79
 
 
80
List<CellText *> *CellTextBuffer::GetTexts() {
 
81
        if (cellTexts) { // make a copy.
 
82
                List<CellText *> *copy = new List<CellText *>;
 
83
                for (cellTexts->first(); !cellTexts->done(); 
 
84
                     cellTexts->next()) {
 
85
                        CellText *t = new CellText(*cellTexts->cur());
 
86
                        copy->add(t);
 
87
                }
 
88
                return copy;
 
89
        }
 
90
        else
 
91
                return 0;
 
92
}
 
93
 
 
94
void CellTextBuffer::UndoPut() {
 
95
        if (cellTexts) {
 
96
                cellTexts->clear();
 
97
                delete cellTexts;
 
98
        }
 
99
        cellTexts = prevCellTexts;
 
100
        if (cellTexts)
 
101
                CalcSizeBuffer();
 
102
        prevCellTexts = 0;
 
103
        rcPositions->clear();
 
104
        *rcPositions = *prevRcPositions;
 
105
        prevRcPositions->empty();
 
106
}
 
107
 
 
108
bool CellTextBuffer::IsEmpty() {
 
109
        return (cellTexts == 0 || cellTexts->count() == 0);
 
110
}
 
111
 
 
112
 
 
113
void CellTextBuffer::CalcSizeBuffer() {
 
114
        int x_max=-1, x_min=-1, y_max=-1, y_min=-1;
 
115
        int x, y;
 
116
        List<CellText *> *texts = cellTexts;
 
117
        if (!check(texts))
 
118
                return;
 
119
        for (texts->first(); !texts->done(); texts->next()) {
 
120
                CellText *celltext = texts->cur();
 
121
                if (!check(celltext))
 
122
                        break;
 
123
                Point pt = *celltext->GetTopLeft();
 
124
                int wd = celltext->GetWidth();
 
125
                int ht = celltext->GetHeight();
 
126
                x = pt.x + wd + 3;
 
127
                if (x>x_max || x_max == -1)
 
128
                        x_max = x;
 
129
                x = pt.x - 3;
 
130
                if (x<x_min || x_min == -1)
 
131
                        x_min = x;
 
132
                y = pt.y + ht + 3;
 
133
                if (y>y_max || y_max == -1)
 
134
                        y_max = y;
 
135
                y = pt.y - 3;
 
136
                if (y<y_min || y_min == -1)
 
137
                        y_min = y;
 
138
        }
 
139
        topLeft.Set(x_min, y_min);
 
140
        bottomRight.Set(x_max, y_max);
 
141
}