1
//------------------------------------------------------------------------------
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).
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.
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.
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
21
//-----------------------------------------------------------------------------
22
#ifndef _TABLEVIEWER_H
23
#define _TABLEVIEWER_H
29
#include "textalign.h"
31
#include "linepiece.h"
33
#include "cellselection.h"
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.
55
/// table viewer class.
56
class TableViewer: public Viewer {
57
/*@Doc: {\large {\bf scope:} table} */
60
TableViewer(Config *c, TableWindow *t);
63
virtual ~TableViewer();
66
void SetTable(Table *t) {table = t;}
68
/// create table of (defaultNumberOf)Rows x (defaultNumberOf)Columns.
69
virtual void Initialize();
72
void InitTable(unsigned rows, unsigned columns);
74
/// Make all cells and lines (in)visible
75
void SetVisible(bool b);
77
/// draw all cells and labels
80
/// erase all cells and labels
83
/// start edit object initialized with c
84
bool TextMode(CellText *c);
86
/// stop edit object and update cell-text.
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);
93
/// button1 is pressed at (x,y)
94
void Select(int x, int y);
96
/// button2 is pressed at (x,y)
97
void Adjust(int x, int y);
99
/// mouse pointer moved to (x,y)
100
void MovingPointer(int x, int y);
102
/// button1 is dragged to (x,y)
103
Command *Drag(int x, int y);
105
/// button2 is dragged to (x,y)
106
Command *Connect(int x, int y);
108
/// return cell iff (x,y) is in cell,
109
Cell *HitCell(int x, int y);
111
/// return cell-text iff (x,y) is in text,
112
CellText *HitCellText(int x, int y);
114
/// return line iff (x,y) is on vertical line,
115
LinePiece *HitVLinePiece(int x, int y);
117
/// return line iff (x,y) is on horizontal line,
118
LinePiece *HitHLinePiece(int x, int y);
120
/// return row label iff (x,y) is in row-label,
121
RowColumnLabel *HitRowLabel(int x, int y);
123
/// return column label iff (x,y) is in column-label,
124
RowColumnLabel *HitColumnLabel(int x, int y);
126
/// return rownr if (x,y) is in row,
127
int HitRow(int x, int y);
129
/// return colnr if (x,y) is in column,
130
int HitColumn(int x, int y);
133
void ShowRowColumnLabels(bool b);
135
void PrintRowColumnLabels(bool b);
138
bool IsShowRowColumnLabels() const {return showRowColumnLabels;}
140
bool IsPrintRowColumnLabels() const {return printRowColumnLabels;}
142
/// adapt cell size (row + column) to fit its cell text.
143
void RecomputeSizeCell(Cell *c);
145
/// update the text in cell c.
146
void UpdateText(Cell *c, const string *newtext);
148
/// move row from oldpos to newpos.
149
virtual void MoveRow(CellRow *r, unsigned newpos);
151
/// move column from oldpos to newpos.
152
virtual void MoveColumn(CellColumn *c, unsigned newpos);
154
/// add row to end of table.
155
virtual void AddRow(CellRow *c);
157
/// add column to right of table.
158
virtual void AddColumn(CellColumn *c);
160
/// insert row into table (automatically shifting).
161
virtual void InsertRow(CellRow *c);
163
/// insert column into table (automatically shifting)
164
virtual void InsertColumn(CellColumn *c);
166
/// delete row from table.
167
virtual void DeleteRow(CellRow *c);
169
/// delete column from table.
170
virtual void DeleteColumn(CellColumn *c);
173
void ResizeRow(CellRow *r, int newSize);
176
void ResizeColumn(CellColumn *c, int newSize);
178
/// move entire table.
179
void Move(const Point *delta);
182
CellRow *GiveRow(unsigned r);
184
/// return c-th column.
185
CellColumn *GiveColumn(unsigned c);
188
void GetSelectedRows(List<CellRow *> *r);
190
void GetSelectedColumns(List<CellColumn *> *c);
193
void GetEmptyRows(List<CellRow *> *r);
195
void GetEmptyColumns(List<CellColumn *> *c);
197
// selection operations that are called by other classes.
198
// These actions are all forwarded to the selection object.
200
void DeselectAll() {selection->DeselectAll();}
204
void SelectCell(Cell *c) {selection->SelectCell(c);}
206
void DeselectCell(Cell *c) {selection->DeselectCell(c);}
208
void SelectVector(CellVector *v);
210
void DeselectVector(CellVector *v);
212
bool IsAllSelected(CellVector *v);
214
void MoveSelection(int key);
216
void CalcSizeElements(Point &topLeft, Point &bottomRight);
218
void CalcSizeSelection(Point &topLeft, Point &bottomRight);
221
void UpdateMarginWidth(int newWidth);
223
void UpdateMarginHeight(int newHeight);
225
void UpdateDefaultRowHeight(int n);
227
void UpdateDefaultColumnWidth(int n);
230
int GetDefaultRowHeight() const {return defaultRowHeight;}
232
int GetDefaultColumnWidth() const {return defaultColumnWidth;}
234
unsigned GetNumberOfColumns() const {return columns->count();}
236
unsigned GetNumberOfRows() const {return rows->count();}
238
unsigned GetDefaultNumberOfColumns() const {
239
return defaultNumberOfColumns;}
241
unsigned GetDefaultNumberOfRows() const {
242
return defaultNumberOfRows;}
244
TextAlign::Type GetDefaultRowAlignment() const {
245
return defaultRowAlignment;}
247
TextAlign::Type GetDefaultColumnAlignment() const {
248
return defaultColumnAlignment;}
250
int GetRowHeight(unsigned row);
252
int GetColumnWidth(unsigned column);
255
const Point *GetTopLeft() const {return &topLeft;}
257
int GetWidth() const {return width;}
259
int GetHeight() const {return height;}
261
int GetMarginWidth() const {return marginWidth;}
263
int GetMarginHeight() const {return marginHeight;}
266
Point GetRowTopLeft(unsigned row);
268
Point GetColumnTopLeft(unsigned column);
271
void SetGrafport(Grafport *g);
274
CellTextBuffer *GetBuffer() const {return buffer;}
276
/// return index of topmost selected row, or -1 if selection is empty.
277
int GetTopSelectionRow();
279
/// return index of leftmost selected column, -1 if selection is empty.
280
int GetLeftSelectionColumn();
283
List<Cell *> *GetSelection() const {return selection->cells;}
285
unsigned NrSelected() const {return selection->cells->count();}
288
unsigned GetCurrentRow() const {return currentRow;}
290
unsigned GetCurrentColumn() const {return currentColumn;}
292
void SetCurrentRow(unsigned n) {currentRow=n;}
294
void SetCurrentColumn(unsigned n) {currentColumn=n;}
296
/// get cell containing s as text (case sensitive, substring).
297
void GetCells(List<Cell *> *cell, const string *s,
298
bool sens, bool substring);
300
/// return the next cell containing s as text.
301
Cell *GetNextCell(const string *s, bool sens, bool substring);
304
void SetDefaultColumnAlignment(TextAlign::Type a) {
305
defaultColumnAlignment = a;}
307
void SetDefaultRowAlignment(TextAlign::Type a) {
308
defaultRowAlignment = a;}
311
void SetLineStyle(Side::Type side, LineStyle::Type style);
314
void SetDefaultNumberOfRows(unsigned);
316
void SetDefaultNumberOfColumns(unsigned);
319
void UpdateLineWidthSelection(unsigned wd);
321
void UpdateLineStyleSelection(LineStyle::Type l);
323
void UpdateTextAlignmentSelection(TextAlign::Type a);
325
void UpdateLineColorSelection(const string *color);
327
void UpdateTextColorSelection(const string *color);
329
void UpdateFillColorSelection(const string *color,
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);
338
bool ReadAttributes(InputFile *f, bool appending, unsigned &rowsToAdd,
339
unsigned &columnsToAdd, double format);
341
bool ReadColumns(InputFile *f, unsigned nr, unsigned fromRow,
342
unsigned fromColumn, double format);
344
bool ReadRows(InputFile *f, unsigned nr, unsigned fromRow,
345
unsigned fromColumn, double format);
348
void WriteAttributes(OutputFile *f);
350
void WriteColumns(OutputFile *f);
352
void WriteRows(OutputFile *f);
354
void WriteSelection(OutputFile *f);
357
List<CellRow *> *GetRows() const { return rows;}
359
List<CellColumn *> *GetColumns() const { return columns;}
361
void SetDefaultColumnWidth(int w);
363
void SetDefaultRowHeight(int h);
365
void SetMarginWidth(int w);
367
void SetMarginHeight(int h);
372
/// the topleft position of the table.
375
/// the width of all cells + row or column labels.
378
/// the height of all cells + row or column labels.
381
/// a list of rows (List is user-defined ADT).
382
List<CellRow *> *rows;
384
/// a list of columns
385
List<CellColumn *> *columns;
387
/// the current selection.
388
CellSelection *selection;
390
/// a cut buffer for storing cell texts;
391
CellTextBuffer *buffer;
393
/// minimal distance between text and column boundaries.
396
/// minimal distance between text and row boundaries.
399
/// each newly created clm is aligned like this
400
TextAlign::Type defaultColumnAlignment;
402
/// each newly created row is aligned like this.
403
TextAlign::Type defaultRowAlignment;
405
/// each newly created row has this height.
406
int defaultRowHeight;
408
/// each newly created column has this width.
409
int defaultColumnWidth;
411
/// when there are no other rows/columns yet.
412
unsigned defaultNumberOfRows;
414
/// each newly created row/column get this number of cells.
415
unsigned defaultNumberOfColumns;
420
unsigned currentColumn;
422
bool showRowColumnLabels;
424
bool printRowColumnLabels;
426
Point defaultTopLeft;
431
bool GoIntoTextMode(Cell *cell);