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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
//------------------------------------------------------------------------------
// 
// This file is part of Toolkit for Conceptual Modeling (TCM).
// (c) copyright 1996, Vrije Universiteit Amsterdam.
// Author: Frank Dehne (frank@cs.vu.nl).
//
// TCM is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// TCM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with TCM; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
// 02111-1307, USA.
//-----------------------------------------------------------------------------
#ifndef _TABLEVIEWER_H
#define _TABLEVIEWER_H

#include "point.h"
#include "lstring.h"
#include "llist.h"
#include "bool.h"
#include "textalign.h"
#include "side.h"
#include "linepiece.h"
#include "viewer.h"
#include "cellselection.h"
class TableWindow;
class Table;
class CellTextBuffer;
class CellTextEditor;
class CellRow;
class CellColumn;
class CellVector;
class CellText;
class Cell;
class Grafport;
class Config;
class InputFile;
class OutputFile;
class RowColumnLabel;

// the table viewer manages the configuration of the
// whole set of cells. Cells are partitioned into rows
// and partitioned into columns such that each cell is 
// part of exactly 1 row and 1 column. A subset of 
// the cells is member of the cell selection list.

/// table viewer class.
class TableViewer: public Viewer {	
/*@Doc: {\large {\bf scope:} table} */
public:
	/// creation
	TableViewer(Config *c, TableWindow *t);	

	/// deletion
	virtual ~TableViewer();		

	///
	void SetTable(Table *t) {table = t;}

	/// create table of (defaultNumberOf)Rows x (defaultNumberOf)Columns.
	virtual void Initialize();

	///
	void InitTable(unsigned rows, unsigned columns);

	/// Make all cells and lines (in)visible
	void SetVisible(bool b);

	/// draw all cells and labels
	void Draw();			

	/// erase all cells and labels
	void Undraw();			

	/// start edit object initialized with c
	bool TextMode(CellText *c);	

	/// stop edit object and update cell-text.
	void TextModeOff();		

	// These actions are called from the drawing area event handler.
	/// key is pressed at (x,y)
	void KeyTyped(int x, int y, int key);

	/// button1 is pressed at (x,y)
	void Select(int x, int y);

	/// button2 is pressed at (x,y)
	void Adjust(int x, int y);

	/// mouse pointer moved to (x,y)
	void MovingPointer(int x, int y);

	/// button1 is dragged to (x,y)
	Command *Drag(int x, int y);

	/// button2 is dragged to (x,y)
	Command *Connect(int x, int y);	

	/// return cell iff (x,y) is in cell, 
	Cell *HitCell(int x, int y);

	/// return cell-text iff (x,y) is in text, 
	CellText *HitCellText(int x, int y);

	/// return line iff (x,y) is on vertical line, 
	LinePiece *HitVLinePiece(int x, int y);

	/// return line iff (x,y) is on horizontal line, 
	LinePiece *HitHLinePiece(int x, int y);

	/// return row label iff (x,y) is in row-label,
	RowColumnLabel *HitRowLabel(int x, int y);

	/// return column label iff (x,y) is in column-label,
	RowColumnLabel *HitColumnLabel(int x, int y);

	/// return rownr if (x,y) is in row, 
	int HitRow(int x, int y);

	/// return colnr if (x,y) is in column,
	int HitColumn(int x, int y);

	///
	void ShowRowColumnLabels(bool b);
	///
	void PrintRowColumnLabels(bool b);

	///
	bool IsShowRowColumnLabels() const {return showRowColumnLabels;}
	///
	bool IsPrintRowColumnLabels() const {return printRowColumnLabels;}

	/// adapt cell size (row + column) to fit its cell text.
	void RecomputeSizeCell(Cell *c); 

	/// update the text in cell c.
	void UpdateText(Cell *c, const string *newtext);

	/// move row from oldpos to newpos.
	virtual void MoveRow(CellRow *r, unsigned newpos);	

	/// move column from oldpos to newpos.
	virtual void MoveColumn(CellColumn *c, unsigned newpos);

	/// add row to end of table.
	virtual void AddRow(CellRow *c);	

	/// add column to right of table.
	virtual void AddColumn(CellColumn *c);

	/// insert row into table (automatically shifting).
	virtual void InsertRow(CellRow *c);	 

	/// insert column into table (automatically shifting)
	virtual void InsertColumn(CellColumn *c);

	/// delete row from table.
	virtual void DeleteRow(CellRow *c);	

	/// delete column from table.
	virtual void DeleteColumn(CellColumn *c); 

	///
	void ResizeRow(CellRow *r, int newSize); 

	///
	void ResizeColumn(CellColumn *c, int newSize);

	/// move entire table.
	void Move(const Point *delta);	

	/// return r-th row.
	CellRow *GiveRow(unsigned r);	

	/// return c-th column.
	CellColumn *GiveColumn(unsigned c);

	///
	void GetSelectedRows(List<CellRow *> *r);
	///
	void GetSelectedColumns(List<CellColumn *> *c);

	///
	void GetEmptyRows(List<CellRow *> *r);
	///
	void GetEmptyColumns(List<CellColumn *> *c);

	// selection operations that are called by other classes. 
	// These actions are all forwarded to the selection object.
	///
	void DeselectAll() {selection->DeselectAll();}
	///
	void SelectAll();
	///
	void SelectCell(Cell *c) {selection->SelectCell(c);}
	///
	void DeselectCell(Cell *c) {selection->DeselectCell(c);}
	///
	void SelectVector(CellVector *v);
	///
	void DeselectVector(CellVector *v);
	///
	bool IsAllSelected(CellVector *v);
	///
	void MoveSelection(int key);
	///
	void CalcSizeElements(Point &topLeft, Point &bottomRight); 
	///
	void CalcSizeSelection(Point &topLeft, Point &bottomRight);

	///
	void UpdateMarginWidth(int newWidth);
	///
	void UpdateMarginHeight(int newHeight);
	///
	void UpdateDefaultRowHeight(int n);
	///
	void UpdateDefaultColumnWidth(int n);

	///
	int GetDefaultRowHeight() const {return defaultRowHeight;}
	///
	int GetDefaultColumnWidth() const {return defaultColumnWidth;}
	///
	unsigned GetNumberOfColumns() const {return columns->count();}
	///
	unsigned GetNumberOfRows() const {return rows->count();}
	///
	unsigned GetDefaultNumberOfColumns() const {
		return defaultNumberOfColumns;}
	///
	unsigned GetDefaultNumberOfRows() const {
		return defaultNumberOfRows;}
	///
	TextAlign::Type GetDefaultRowAlignment() const {
		return defaultRowAlignment;}
	///
	TextAlign::Type GetDefaultColumnAlignment() const {
		return defaultColumnAlignment;}
	///
	int GetRowHeight(unsigned row);
	///
	int GetColumnWidth(unsigned column);

	///
	const Point *GetTopLeft() const {return &topLeft;}
	///
	int GetWidth() const {return width;}
	///
	int GetHeight() const {return height;}
	///
	int GetMarginWidth() const {return marginWidth;}
	///
	int GetMarginHeight() const {return marginHeight;}

	///
	Point GetRowTopLeft(unsigned row);
	///
	Point GetColumnTopLeft(unsigned column);
	
	///
	void SetGrafport(Grafport *g);

	///
	CellTextBuffer *GetBuffer() const {return buffer;}

	/// return index of topmost selected row, or -1 if selection is empty.
	int GetTopSelectionRow();

	/// return index of leftmost selected column, -1 if selection is empty.
	int GetLeftSelectionColumn(); 

	///
	List<Cell *> *GetSelection() const {return selection->cells;}
	///
	unsigned NrSelected() const {return selection->cells->count();}

	///
	unsigned GetCurrentRow() const {return currentRow;}
	///
	unsigned GetCurrentColumn() const {return currentColumn;}
	///
	void SetCurrentRow(unsigned n) {currentRow=n;}
	///
	void SetCurrentColumn(unsigned n) {currentColumn=n;}

	/// get cell containing s as text (case sensitive, substring).
	void GetCells(List<Cell *> *cell, const string *s,
			bool sens, bool substring);
 
	/// return the next cell containing s as text.
	Cell *GetNextCell(const string *s, bool sens, bool substring);
 
	///
	void SetDefaultColumnAlignment(TextAlign::Type a) {
		defaultColumnAlignment = a;}
	///
	void SetDefaultRowAlignment(TextAlign::Type a) {
		defaultRowAlignment = a;}

	///
	void SetLineStyle(Side::Type side, LineStyle::Type style);

	///
	void SetDefaultNumberOfRows(unsigned);
	///
	void SetDefaultNumberOfColumns(unsigned);

	///
	void UpdateLineWidthSelection(unsigned wd);
	///
	void UpdateLineStyleSelection(LineStyle::Type l);
	///
	void UpdateTextAlignmentSelection(TextAlign::Type a);
	///
	void UpdateLineColorSelection(const string *color);
	///
	void UpdateTextColorSelection(const string *color);
	///
	void UpdateFillColorSelection(const string *color,
		FillStyle::Type f);
 
	///
	void SetDefaultFont(XFont *ft);
	/// set font family, style, size (no update when value < 0).
	void UpdateFontSelection(int f, int s, int p);

	///
	bool ReadAttributes(InputFile *f, bool appending, unsigned &rowsToAdd, 
		unsigned &columnsToAdd, double format);
	///
	bool ReadColumns(InputFile *f, unsigned nr, unsigned fromRow, 
		unsigned fromColumn, double format);
	///
	bool ReadRows(InputFile *f, unsigned nr, unsigned fromRow, 
		unsigned fromColumn, double format);

	///
	void WriteAttributes(OutputFile *f);
	///
	void WriteColumns(OutputFile *f);
	///
	void WriteRows(OutputFile *f);
	///
	void WriteSelection(OutputFile *f);
protected:
	/// 
	List<CellRow *> *GetRows() const { return rows;}
	/// 
	List<CellColumn *> *GetColumns() const { return columns;}
	///
	void SetDefaultColumnWidth(int w);
	///
	void SetDefaultRowHeight(int h);
	///
	void SetMarginWidth(int w);
	///
	void SetMarginHeight(int h);
private:
	///
	Table *table;

	/// the topleft position of the table.
	Point topLeft;			

	/// the width of all cells + row or column labels.
	int width;

	/// the height of all cells + row or column labels.
	int height;		

	/// a list of rows (List is user-defined ADT).
	List<CellRow *> *rows;

	/// a list of columns
	List<CellColumn *> *columns;	

	/// the current selection.
	CellSelection *selection;	

	/// a cut buffer for storing cell texts;
	CellTextBuffer *buffer;		

	/// minimal distance between text and column boundaries. 
	int marginWidth;	

	/// minimal distance between text and row boundaries.
	int marginHeight;	

	/// each newly created clm is aligned like this
	TextAlign::Type defaultColumnAlignment;

	/// each newly created row is aligned like this.
	TextAlign::Type defaultRowAlignment; 	

	/// each newly created row has this height.
	int defaultRowHeight;		

	/// each newly created column has this width.
	int defaultColumnWidth;		

	/// when there are no other rows/columns yet.
	unsigned defaultNumberOfRows;	

	/// each newly created row/column get this number of cells.
	unsigned defaultNumberOfColumns;

	///
	unsigned currentRow;
	///
	unsigned currentColumn;
	///
	bool showRowColumnLabels;
	///
	bool printRowColumnLabels;
	///
	Point defaultTopLeft;

	///
	void DeleteCells();
	///
	bool GoIntoTextMode(Cell *cell);
};
#endif