~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/tb/cellvector.h

  • 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
#ifndef _CELLVECTOR_H
 
23
#define _CELLVECTOR_H
 
24
 
 
25
#include "llist.h"
 
26
#include "lstring.h"
 
27
#include "textalign.h"
 
28
class TableViewer;
 
29
class RowColumnLabel;
 
30
class Cell;
 
31
class LinePiece;
 
32
class Grafport;
 
33
class InputFile;
 
34
class OutputFile;
 
35
 
 
36
/// abstract base class of table rows and columns.
 
37
class CellVector {
 
38
/*@Doc: {\large {\bf scope:} table} */
 
39
public:
 
40
        /// creation.
 
41
        CellVector(TableViewer *v, unsigned number);
 
42
 
 
43
        virtual ~CellVector();                   
 
44
 
 
45
        /// -1,0,1 iff c1.number ==,<,> c2.number
 
46
        friend int operator==(const CellVector &c1, const CellVector &c2);
 
47
 
 
48
        /// -1,0,1 iff c1.number ==,<,> c2.number
 
49
        friend int Compare(CellVector *c1, CellVector *c2) {
 
50
                return operator==(*c1, *c2);}
 
51
 
 
52
        /// draw cell vector.
 
53
        void Draw();
 
54
        /// erase cell vector.
 
55
        void Undraw();
 
56
 
 
57
        ///
 
58
        void DrawCells();
 
59
        ///
 
60
        void UndrawCells();
 
61
 
 
62
        ///
 
63
        void DrawLines();
 
64
        ///
 
65
        void UndrawLines();
 
66
 
 
67
        ///
 
68
        void DrawLabels();
 
69
        ///
 
70
        void UndrawLabels();
 
71
        
 
72
        ///
 
73
        void SetGrafport(Grafport *g);
 
74
        
 
75
        /// Make all cells and lines (in)visible.
 
76
        void SetVisible(bool b);
 
77
 
 
78
        ///
 
79
        TableViewer *GetViewer() const {return viewer;}
 
80
 
 
81
        ///
 
82
        virtual void UpdatePosition(int delta) =0;
 
83
 
 
84
        ///
 
85
        virtual LinePiece *HitLinePiece(int x, int y) =0;
 
86
 
 
87
        ///
 
88
        bool HasCell(Cell *c);
 
89
 
 
90
        ///
 
91
        RowColumnLabel *HitLabel(int x, int y) const;
 
92
 
 
93
        /// append cell to column.
 
94
        virtual void AddCell(Cell *c, bool redraw=False)=0;     
 
95
 
 
96
        /// delete cell from column.
 
97
        virtual void DeleteCell(Cell *c, bool redraw=False)=0;  
 
98
 
 
99
        /// insert cell in column.
 
100
        virtual void InsertCell(Cell *c, unsigned n, bool redraw=False)=0;
 
101
 
 
102
        ///
 
103
        virtual bool ContainsPt(int x, int y) const =0;
 
104
 
 
105
        ///
 
106
        virtual void Write(OutputFile *f) = 0;
 
107
 
 
108
        ///
 
109
        virtual void WritePartial(OutputFile *f, int i, List<int> *nrs) = 0;
 
110
 
 
111
        ///
 
112
        virtual bool Read(InputFile *f, unsigned from = 0, 
 
113
                double format = 1.0) = 0;
 
114
 
 
115
        ///
 
116
        TextAlign::Type GetAlignment() const {return alignment;}
 
117
 
 
118
        ///
 
119
        void SetAlignment(TextAlign::Type a);
 
120
 
 
121
        ///
 
122
        void UpdateAlignment(TextAlign::Type a);
 
123
 
 
124
        ///
 
125
        virtual void UpdateNumber(unsigned nr);
 
126
 
 
127
        ///
 
128
        virtual void SetLabelsVisible(bool s) {labelsVisible = s;}
 
129
 
 
130
        ///
 
131
        void SetNumber(unsigned nr);
 
132
 
 
133
        /// return first cell, 0 if cells is empty.
 
134
        Cell *FirstCell();      
 
135
 
 
136
        /// return next cell, 0 if cells is empty.
 
137
        Cell *NextCell();
 
138
 
 
139
        /// return n-th cell, 0 if n-th cell does not exist.
 
140
        Cell *NthCell(unsigned n);      
 
141
 
 
142
        /// return first line, 0 if lines is empty.
 
143
        LinePiece *FirstLine(); 
 
144
 
 
145
        /// return next line, 0 if lines is empty.
 
146
        LinePiece *NextLine();
 
147
 
 
148
        /// return n-th line, 0 if n-th line does not exist.
 
149
        LinePiece *NthLine(unsigned n);
 
150
 
 
151
        ///
 
152
        unsigned GetNumber() const {return number;}
 
153
 
 
154
        ///
 
155
        RowColumnLabel *GetLabel1() const {return label1;}
 
156
        ///
 
157
        RowColumnLabel *GetLabel2() const {return label2;}
 
158
        ///
 
159
        void UpdateLabel1(const string *txt);
 
160
        ///
 
161
        void UpdateLabel2(const string *txt);
 
162
 
 
163
        ///
 
164
        unsigned NrCells() const {return cells->count();}
 
165
 
 
166
        ///
 
167
        int GetIndex(LinePiece *l) {return lines->find(l);}
 
168
 
 
169
        /// return nr of cells having empty texts.
 
170
        unsigned HasEmptyText();
 
171
 
 
172
        /// return nr of cells having this text.
 
173
        unsigned HasText(const string *s);
 
174
 
 
175
        ///
 
176
        bool IsAllEmpty() {return HasEmptyText() == NrCells();}
 
177
 
 
178
        ///
 
179
        void EmptyCells() {cells->empty();} // remove all from cells
 
180
 
 
181
        ///
 
182
        virtual void CalcLabelPositions() = 0;
 
183
protected:
 
184
        /// the cells in the vector.
 
185
        List<Cell *> *cells;    
 
186
 
 
187
        /// cell boundaries between the cells in the vector. 
 
188
        List<LinePiece *> *lines; 
 
189
 
 
190
        ///
 
191
        Grafport *GetGrafport() const {return grafport;}
 
192
private:
 
193
        ///
 
194
        TableViewer *viewer;
 
195
        ///
 
196
        Grafport *grafport;
 
197
 
 
198
        /// the row or column numbers.
 
199
        unsigned number;                
 
200
 
 
201
        /// a number label drawn near beginning of vector (like spreadsheet)
 
202
        RowColumnLabel *label1; 
 
203
 
 
204
        /// a number label drawn near end of vector.
 
205
        RowColumnLabel *label2; 
 
206
 
 
207
        /// is label number displayed ?
 
208
        bool labelsVisible;     
 
209
 
 
210
        /// beginning=left, end=right, center=center.
 
211
        TextAlign::Type alignment;
 
212
};
 
213
#endif