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

« back to all changes in this revision

Viewing changes to src/tb/tableviewer.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 _TABLEVIEWER_H
 
23
#define _TABLEVIEWER_H
 
24
 
 
25
#include "point.h"
 
26
#include "lstring.h"
 
27
#include "llist.h"
 
28
#include "bool.h"
 
29
#include "textalign.h"
 
30
#include "side.h"
 
31
#include "linepiece.h"
 
32
#include "viewer.h"
 
33
#include "cellselection.h"
 
34
class TableWindow;
 
35
class Table;
 
36
class CellTextBuffer;
 
37
class CellTextEditor;
 
38
class CellRow;
 
39
class CellColumn;
 
40
class CellVector;
 
41
class CellText;
 
42
class Cell;
 
43
class Grafport;
 
44
class Config;
 
45
class InputFile;
 
46
class OutputFile;
 
47
class RowColumnLabel;
 
48
 
 
49
// the table viewer manages the configuration of the
 
50
// whole set of cells. Cells are partitioned into rows
 
51
// and partitioned into columns such that each cell is 
 
52
// part of exactly 1 row and 1 column. A subset of 
 
53
// the cells is member of the cell selection list.
 
54
 
 
55
/// table viewer class.
 
56
class TableViewer: public Viewer {      
 
57
/*@Doc: {\large {\bf scope:} table} */
 
58
public:
 
59
        /// creation
 
60
        TableViewer(Config *c, TableWindow *t); 
 
61
 
 
62
        /// deletion
 
63
        virtual ~TableViewer();         
 
64
 
 
65
        ///
 
66
        void SetTable(Table *t) {table = t;}
 
67
 
 
68
        /// create table of (defaultNumberOf)Rows x (defaultNumberOf)Columns.
 
69
        virtual void Initialize();
 
70
 
 
71
        ///
 
72
        void InitTable(unsigned rows, unsigned columns);
 
73
 
 
74
        /// Make all cells and lines (in)visible
 
75
        void SetVisible(bool b);
 
76
 
 
77
        /// draw all cells and labels
 
78
        void Draw();                    
 
79
 
 
80
        /// erase all cells and labels
 
81
        void Undraw();                  
 
82
 
 
83
        /// start edit object initialized with c
 
84
        bool TextMode(CellText *c);     
 
85
 
 
86
        /// stop edit object and update cell-text.
 
87
        void TextModeOff();             
 
88
 
 
89
        // These actions are called from the drawing area event handler.
 
90
        /// key is pressed at (x,y)
 
91
        void KeyTyped(int x, int y, int key);
 
92
 
 
93
        /// button1 is pressed at (x,y)
 
94
        void Select(int x, int y);
 
95
 
 
96
        /// button2 is pressed at (x,y)
 
97
        void Adjust(int x, int y);
 
98
 
 
99
        /// mouse pointer moved to (x,y)
 
100
        void MovingPointer(int x, int y);
 
101
 
 
102
        /// button1 is dragged to (x,y)
 
103
        Command *Drag(int x, int y);
 
104
 
 
105
        /// button2 is dragged to (x,y)
 
106
        Command *Connect(int x, int y); 
 
107
 
 
108
        /// return cell iff (x,y) is in cell, 
 
109
        Cell *HitCell(int x, int y);
 
110
 
 
111
        /// return cell-text iff (x,y) is in text, 
 
112
        CellText *HitCellText(int x, int y);
 
113
 
 
114
        /// return line iff (x,y) is on vertical line, 
 
115
        LinePiece *HitVLinePiece(int x, int y);
 
116
 
 
117
        /// return line iff (x,y) is on horizontal line, 
 
118
        LinePiece *HitHLinePiece(int x, int y);
 
119
 
 
120
        /// return row label iff (x,y) is in row-label,
 
121
        RowColumnLabel *HitRowLabel(int x, int y);
 
122
 
 
123
        /// return column label iff (x,y) is in column-label,
 
124
        RowColumnLabel *HitColumnLabel(int x, int y);
 
125
 
 
126
        /// return rownr if (x,y) is in row, 
 
127
        int HitRow(int x, int y);
 
128
 
 
129
        /// return colnr if (x,y) is in column,
 
130
        int HitColumn(int x, int y);
 
131
 
 
132
        ///
 
133
        void ShowRowColumnLabels(bool b);
 
134
        ///
 
135
        void PrintRowColumnLabels(bool b);
 
136
 
 
137
        ///
 
138
        bool IsShowRowColumnLabels() const {return showRowColumnLabels;}
 
139
        ///
 
140
        bool IsPrintRowColumnLabels() const {return printRowColumnLabels;}
 
141
 
 
142
        /// adapt cell size (row + column) to fit its cell text.
 
143
        void RecomputeSizeCell(Cell *c); 
 
144
 
 
145
        /// update the text in cell c.
 
146
        void UpdateText(Cell *c, const string *newtext);
 
147
 
 
148
        /// move row from oldpos to newpos.
 
149
        virtual void MoveRow(CellRow *r, unsigned newpos);      
 
150
 
 
151
        /// move column from oldpos to newpos.
 
152
        virtual void MoveColumn(CellColumn *c, unsigned newpos);
 
153
 
 
154
        /// add row to end of table.
 
155
        virtual void AddRow(CellRow *c);        
 
156
 
 
157
        /// add column to right of table.
 
158
        virtual void AddColumn(CellColumn *c);
 
159
 
 
160
        /// insert row into table (automatically shifting).
 
161
        virtual void InsertRow(CellRow *c);      
 
162
 
 
163
        /// insert column into table (automatically shifting)
 
164
        virtual void InsertColumn(CellColumn *c);
 
165
 
 
166
        /// delete row from table.
 
167
        virtual void DeleteRow(CellRow *c);     
 
168
 
 
169
        /// delete column from table.
 
170
        virtual void DeleteColumn(CellColumn *c); 
 
171
 
 
172
        ///
 
173
        void ResizeRow(CellRow *r, int newSize); 
 
174
 
 
175
        ///
 
176
        void ResizeColumn(CellColumn *c, int newSize);
 
177
 
 
178
        /// move entire table.
 
179
        void Move(const Point *delta);  
 
180
 
 
181
        /// return r-th row.
 
182
        CellRow *GiveRow(unsigned r);   
 
183
 
 
184
        /// return c-th column.
 
185
        CellColumn *GiveColumn(unsigned c);
 
186
 
 
187
        ///
 
188
        void GetSelectedRows(List<CellRow *> *r);
 
189
        ///
 
190
        void GetSelectedColumns(List<CellColumn *> *c);
 
191
 
 
192
        ///
 
193
        void GetEmptyRows(List<CellRow *> *r);
 
194
        ///
 
195
        void GetEmptyColumns(List<CellColumn *> *c);
 
196
 
 
197
        // selection operations that are called by other classes. 
 
198
        // These actions are all forwarded to the selection object.
 
199
        ///
 
200
        void DeselectAll() {selection->DeselectAll();}
 
201
        ///
 
202
        void SelectAll();
 
203
        ///
 
204
        void SelectCell(Cell *c) {selection->SelectCell(c);}
 
205
        ///
 
206
        void DeselectCell(Cell *c) {selection->DeselectCell(c);}
 
207
        ///
 
208
        void SelectVector(CellVector *v);
 
209
        ///
 
210
        void DeselectVector(CellVector *v);
 
211
        ///
 
212
        bool IsAllSelected(CellVector *v);
 
213
        ///
 
214
        void MoveSelection(int key);
 
215
        ///
 
216
        void CalcSizeElements(Point &topLeft, Point &bottomRight); 
 
217
        ///
 
218
        void CalcSizeSelection(Point &topLeft, Point &bottomRight);
 
219
 
 
220
        ///
 
221
        void UpdateMarginWidth(int newWidth);
 
222
        ///
 
223
        void UpdateMarginHeight(int newHeight);
 
224
        ///
 
225
        void UpdateDefaultRowHeight(int n);
 
226
        ///
 
227
        void UpdateDefaultColumnWidth(int n);
 
228
 
 
229
        ///
 
230
        int GetDefaultRowHeight() const {return defaultRowHeight;}
 
231
        ///
 
232
        int GetDefaultColumnWidth() const {return defaultColumnWidth;}
 
233
        ///
 
234
        unsigned GetNumberOfColumns() const {return columns->count();}
 
235
        ///
 
236
        unsigned GetNumberOfRows() const {return rows->count();}
 
237
        ///
 
238
        unsigned GetDefaultNumberOfColumns() const {
 
239
                return defaultNumberOfColumns;}
 
240
        ///
 
241
        unsigned GetDefaultNumberOfRows() const {
 
242
                return defaultNumberOfRows;}
 
243
        ///
 
244
        TextAlign::Type GetDefaultRowAlignment() const {
 
245
                return defaultRowAlignment;}
 
246
        ///
 
247
        TextAlign::Type GetDefaultColumnAlignment() const {
 
248
                return defaultColumnAlignment;}
 
249
        ///
 
250
        int GetRowHeight(unsigned row);
 
251
        ///
 
252
        int GetColumnWidth(unsigned column);
 
253
 
 
254
        ///
 
255
        const Point *GetTopLeft() const {return &topLeft;}
 
256
        ///
 
257
        int GetWidth() const {return width;}
 
258
        ///
 
259
        int GetHeight() const {return height;}
 
260
        ///
 
261
        int GetMarginWidth() const {return marginWidth;}
 
262
        ///
 
263
        int GetMarginHeight() const {return marginHeight;}
 
264
 
 
265
        ///
 
266
        Point GetRowTopLeft(unsigned row);
 
267
        ///
 
268
        Point GetColumnTopLeft(unsigned column);
 
269
        
 
270
        ///
 
271
        void SetGrafport(Grafport *g);
 
272
 
 
273
        ///
 
274
        CellTextBuffer *GetBuffer() const {return buffer;}
 
275
 
 
276
        /// return index of topmost selected row, or -1 if selection is empty.
 
277
        int GetTopSelectionRow();
 
278
 
 
279
        /// return index of leftmost selected column, -1 if selection is empty.
 
280
        int GetLeftSelectionColumn(); 
 
281
 
 
282
        ///
 
283
        List<Cell *> *GetSelection() const {return selection->cells;}
 
284
        ///
 
285
        unsigned NrSelected() const {return selection->cells->count();}
 
286
 
 
287
        ///
 
288
        unsigned GetCurrentRow() const {return currentRow;}
 
289
        ///
 
290
        unsigned GetCurrentColumn() const {return currentColumn;}
 
291
        ///
 
292
        void SetCurrentRow(unsigned n) {currentRow=n;}
 
293
        ///
 
294
        void SetCurrentColumn(unsigned n) {currentColumn=n;}
 
295
 
 
296
        /// get cell containing s as text (case sensitive, substring).
 
297
        void GetCells(List<Cell *> *cell, const string *s,
 
298
                        bool sens, bool substring);
 
299
 
 
300
        /// return the next cell containing s as text.
 
301
        Cell *GetNextCell(const string *s, bool sens, bool substring);
 
302
 
 
303
        ///
 
304
        void SetDefaultColumnAlignment(TextAlign::Type a) {
 
305
                defaultColumnAlignment = a;}
 
306
        ///
 
307
        void SetDefaultRowAlignment(TextAlign::Type a) {
 
308
                defaultRowAlignment = a;}
 
309
 
 
310
        ///
 
311
        void SetLineStyle(Side::Type side, LineStyle::Type style);
 
312
 
 
313
        ///
 
314
        void SetDefaultNumberOfRows(unsigned);
 
315
        ///
 
316
        void SetDefaultNumberOfColumns(unsigned);
 
317
 
 
318
        ///
 
319
        void UpdateLineWidthSelection(unsigned wd);
 
320
        ///
 
321
        void UpdateLineStyleSelection(LineStyle::Type l);
 
322
        ///
 
323
        void UpdateTextAlignmentSelection(TextAlign::Type a);
 
324
        ///
 
325
        void UpdateLineColorSelection(const string *color);
 
326
        ///
 
327
        void UpdateTextColorSelection(const string *color);
 
328
        ///
 
329
        void UpdateFillColorSelection(const string *color,
 
330
                FillStyle::Type f);
 
331
 
 
332
        ///
 
333
        void SetDefaultFont(XFont *ft);
 
334
        /// set font family, style, size (no update when value < 0).
 
335
        void UpdateFontSelection(int f, int s, int p);
 
336
 
 
337
        ///
 
338
        bool ReadAttributes(InputFile *f, bool appending, unsigned &rowsToAdd, 
 
339
                unsigned &columnsToAdd, double format);
 
340
        ///
 
341
        bool ReadColumns(InputFile *f, unsigned nr, unsigned fromRow, 
 
342
                unsigned fromColumn, double format);
 
343
        ///
 
344
        bool ReadRows(InputFile *f, unsigned nr, unsigned fromRow, 
 
345
                unsigned fromColumn, double format);
 
346
 
 
347
        ///
 
348
        void WriteAttributes(OutputFile *f);
 
349
        ///
 
350
        void WriteColumns(OutputFile *f);
 
351
        ///
 
352
        void WriteRows(OutputFile *f);
 
353
        ///
 
354
        void WriteSelection(OutputFile *f);
 
355
protected:
 
356
        /// 
 
357
        List<CellRow *> *GetRows() const { return rows;}
 
358
        /// 
 
359
        List<CellColumn *> *GetColumns() const { return columns;}
 
360
        ///
 
361
        void SetDefaultColumnWidth(int w);
 
362
        ///
 
363
        void SetDefaultRowHeight(int h);
 
364
        ///
 
365
        void SetMarginWidth(int w);
 
366
        ///
 
367
        void SetMarginHeight(int h);
 
368
private:
 
369
        ///
 
370
        Table *table;
 
371
 
 
372
        /// the topleft position of the table.
 
373
        Point topLeft;                  
 
374
 
 
375
        /// the width of all cells + row or column labels.
 
376
        int width;
 
377
 
 
378
        /// the height of all cells + row or column labels.
 
379
        int height;             
 
380
 
 
381
        /// a list of rows (List is user-defined ADT).
 
382
        List<CellRow *> *rows;
 
383
 
 
384
        /// a list of columns
 
385
        List<CellColumn *> *columns;    
 
386
 
 
387
        /// the current selection.
 
388
        CellSelection *selection;       
 
389
 
 
390
        /// a cut buffer for storing cell texts;
 
391
        CellTextBuffer *buffer;         
 
392
 
 
393
        /// minimal distance between text and column boundaries. 
 
394
        int marginWidth;        
 
395
 
 
396
        /// minimal distance between text and row boundaries.
 
397
        int marginHeight;       
 
398
 
 
399
        /// each newly created clm is aligned like this
 
400
        TextAlign::Type defaultColumnAlignment;
 
401
 
 
402
        /// each newly created row is aligned like this.
 
403
        TextAlign::Type defaultRowAlignment;    
 
404
 
 
405
        /// each newly created row has this height.
 
406
        int defaultRowHeight;           
 
407
 
 
408
        /// each newly created column has this width.
 
409
        int defaultColumnWidth;         
 
410
 
 
411
        /// when there are no other rows/columns yet.
 
412
        unsigned defaultNumberOfRows;   
 
413
 
 
414
        /// each newly created row/column get this number of cells.
 
415
        unsigned defaultNumberOfColumns;
 
416
 
 
417
        ///
 
418
        unsigned currentRow;
 
419
        ///
 
420
        unsigned currentColumn;
 
421
        ///
 
422
        bool showRowColumnLabels;
 
423
        ///
 
424
        bool printRowColumnLabels;
 
425
        ///
 
426
        Point defaultTopLeft;
 
427
 
 
428
        ///
 
429
        void DeleteCells();
 
430
        ///
 
431
        bool GoIntoTextMode(Cell *cell);
 
432
};
 
433
#endif