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

« back to all changes in this revision

Viewing changes to src/tb/table.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 1995, 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 "table.h"
 
23
#include "tablewindow.h"
 
24
#include "tablestubs.h"
 
25
#include "tableviewer.h"
 
26
#include "texteditdialog.h"
 
27
#include "togglelistdialog.h"
 
28
#include "textalignmentdialog.h"
 
29
#include "linewidthsidedialog.h"
 
30
#include "linestylesidedialog.h"
 
31
#include "scaledialog.h"
 
32
#include "questiondialog.h"
 
33
#include "fileselectiondialog.h"
 
34
#include "config.h"
 
35
#include "cell.h"
 
36
#include "cellrow.h"
 
37
#include "cellcolumn.h"
 
38
#include "appendtablecmd.h"
 
39
#include "addrowscmd.h"
 
40
#include "addcolumnscmd.h"
 
41
#include "deleterowscmd.h"
 
42
#include "deletecolumnscmd.h"
 
43
#include "deleteallcellscmd.h"
 
44
#include "purgecellscmd.h"
 
45
#include "cutcelltextscmd.h"
 
46
#include "pastecelltextscmd.h"
 
47
#include "sortrowscmd.h"
 
48
#include "sortcolumnscmd.h"
 
49
#include "findnextcellcmd.h"
 
50
#include "updatecelltextcmd.h"
 
51
#include "movetablecmd.h"
 
52
#include "replaceallcelltextscmd.h"
 
53
#include "replacenextcelltextcmd.h"
 
54
#include "updaterowalignmentcmd.h"
 
55
#include "updatecolumnalignmentcmd.h"
 
56
#include "updatelinestyletablecmd.h"
 
57
#include "updatelinewidthtablecmd.h"
 
58
#include "updatecelltextunderlinecmd.h"
 
59
#include "celltextbuffer.h"
 
60
 
 
61
const int Table::MIN_ROW_HEIGHT = 10;
 
62
const int Table::MIN_COLUMN_WIDTH = 10;
 
63
const int Table::MAX_ROW_HEIGHT = 200;
 
64
const int Table::MAX_COLUMN_WIDTH = 200;
 
65
const int Table::MIN_MARGIN_WIDTH = 0;
 
66
const int Table::MIN_MARGIN_HEIGHT = 0;
 
67
const int Table::MAX_MARGIN_WIDTH = 30;
 
68
const int Table::MAX_MARGIN_HEIGHT = 30;
 
69
const int Table::MIN_NUMBER_OF_ROWS = 1;
 
70
const int Table::MIN_NUMBER_OF_COLUMNS = 1;
 
71
const int Table::MAX_NUMBER_OF_ROWS = 30;
 
72
const int Table::MAX_NUMBER_OF_COLUMNS = 30; 
 
73
 
 
74
const int Table::DEFAULT_ADD_ROWS = 1;
 
75
const int Table::DEFAULT_ADD_COLUMNS = 1;
 
76
 
 
77
Table::Table(Config *c, TableWindow *w, TableViewer *v): Document(c, w, v) {
 
78
        tviewer = v;
 
79
        topAdd = False;
 
80
        leftAdd = False;
 
81
        appendBottom = True;
 
82
        annotationCell = 0;
 
83
        string l = "Append table to the: ";
 
84
        List<string *> s;
 
85
        s.add(new string("Bottom"));
 
86
        s.add(new string("Right"));
 
87
        GetEltAnnotationDialog()->
 
88
                SetOKCallback(TableStubs::AnnotateCellOKCB, this);
 
89
        GetFileSelectionDialog()->CreateOptionMenu(&l, &s);
 
90
        GetFileSelectionDialog()->SetOptionChangedCallback(
 
91
                TableStubs::AppendToggleCB, this);
 
92
        s.clear();
 
93
        scaleDialog = new ScaleDialog(w->GetWidget());
 
94
        scaleDialog->Initialize();
 
95
        List<string *> labels;
 
96
        labels.add(new string("this entry sucks"));
 
97
        labels.add(new string("this entry sucks even more"));
 
98
        promptToggleDialog = new ToggleListDialog(w->GetWidget(), True);
 
99
        promptToggleDialog->Initialize();
 
100
        promptToggleDialog->CreateToggles(&labels); // labels are changed later.
 
101
        labels.clear();
 
102
        defaultNumberOfRows = tviewer->GetDefaultNumberOfRows();
 
103
        defaultNumberOfColumns = tviewer->GetDefaultNumberOfColumns();
 
104
        defaultRowHeight = tviewer->GetDefaultRowHeight();
 
105
        defaultColumnWidth = tviewer->GetDefaultColumnWidth();
 
106
        defaultMarginWidth = tviewer->GetMarginWidth();
 
107
        defaultMarginHeight = tviewer->GetMarginHeight();
 
108
        // line style stuff
 
109
        tableLineStyleDialog = new LineStyleSideDialog(w->GetWidget());
 
110
        tableLineStyleDialog->Initialize();
 
111
        tableLineStyleDialog->SetTitle("update line style");
 
112
        tableLineStyleDialog->SetHelpCallback(
 
113
                TableStubs::UpdateTableLineStyleDefaultCB, this);
 
114
        tableLineStyleDialog->SetOKCallback(
 
115
                TableStubs::UpdateTableLineStyleOKCB, this);
 
116
        // line width stuff
 
117
        tableLineWidthDialog = new LineWidthSideDialog(w->GetWidget());
 
118
        tableLineWidthDialog->Initialize();
 
119
        tableLineWidthDialog->SetTitle("update line width");
 
120
        tableLineWidthDialog->SetHelpCallback(
 
121
                TableStubs::UpdateTableLineWidthDefaultCB, this);
 
122
        tableLineWidthDialog->SetOKCallback(
 
123
                TableStubs::UpdateTableLineWidthOKCB, this);
 
124
        // alignment stuff
 
125
        columnAlignmentDialog = GetViewer()->GetTextAlignmentDialog();
 
126
        rowAlignmentDialog = new TextAlignmentDialog(w->GetWidget(), False);
 
127
        rowAlignmentDialog->Initialize();
 
128
        ShowConfigLineStyle();
 
129
        ShowConfigLineWidth();
 
130
        ShowConfigColumnAlignment();
 
131
        ShowConfigRowAlignment();
 
132
}
 
133
 
 
134
Table::~Table() {
 
135
        delete scaleDialog;
 
136
        delete promptToggleDialog;
 
137
        delete tableLineStyleDialog;
 
138
        delete tableLineWidthDialog;
 
139
        delete rowAlignmentDialog;
 
140
}
 
141
 
 
142
 
 
143
/* virtual */ void Table::Initialize() {
 
144
        Document::Initialize();
 
145
        tviewer->Initialize();
 
146
}
 
147
 
 
148
 
 
149
void Table::Append() {
 
150
        GetFileSelectionDialog()->ManageOptionMenu(True);
 
151
        Document::Append();
 
152
}
 
153
 
 
154
void Table::RemoveAll() {
 
155
        DeleteAllCells();
 
156
        tviewer->DeleteCommands();
 
157
}
 
158
 
 
159
void Table::LoadEntries() {
 
160
        if (IsAppending()) {
 
161
                tviewer->NewCommand(new AppendTableCmd(this, tviewer));
 
162
                tviewer->ExecuteCommand();
 
163
                return;
 
164
        }
 
165
        tviewer->TextModeOff();
 
166
        // delete the document contents.
 
167
        DeleteAllCells();
 
168
        unsigned rows, columns;
 
169
        InputFile *ipf = GetInputFile();
 
170
        if (tviewer->ReadAttributes(ipf, IsAppending(), rows, 
 
171
                                    columns, GetLoadFormat())) {
 
172
                // load: add new rows and columns
 
173
                tviewer->InitTable(rows, columns);
 
174
                tviewer->SetVisible(False);
 
175
                if (GetLoadFormat() >= 1.09) {
 
176
                        if (tviewer->ReadRows(ipf, rows, 0, 0, GetLoadFormat()))
 
177
                                tviewer->ReadColumns(
 
178
                                        ipf, columns, 0, 0, GetLoadFormat());
 
179
                }
 
180
                else {
 
181
                        if (tviewer->ReadColumns(ipf, columns, 0, 0, 
 
182
                                                 GetLoadFormat()))
 
183
                                tviewer->ReadRows(ipf, rows, 0, 0, 
 
184
                                                  GetLoadFormat());
 
185
                }
 
186
                tviewer->DeleteCommands();
 
187
        }
 
188
        tviewer->SetVisible(True);
 
189
        tviewer->Refresh();
 
190
        FitTable();
 
191
}
 
192
 
 
193
void Table::FitTable() {
 
194
        Point p1, p2;
 
195
        tviewer->CalcSizeElements(p1, p2);
 
196
        double wd = tviewer->Scale(p2.x) + 300.0;
 
197
        double ht = tviewer->Scale(p2.y) + 300.0;
 
198
        ((DrawWindow *)GetMainWindow())->FitDocument(static_cast<int>(0.5 + wd),
 
199
                                                                                                 static_cast<int>(0.5 + ht));
 
200
}
 
201
 
 
202
void Table::SaveEntries() {
 
203
        tviewer->TextModeOff();
 
204
        OutputFile *opf = GetOutputFile();
 
205
        if (IsSaveSelection()) {
 
206
                tviewer->WriteSelection(opf);
 
207
        }
 
208
        else {
 
209
                tviewer->WriteAttributes(opf);
 
210
                tviewer->WriteRows(opf);
 
211
                tviewer->WriteColumns(opf);
 
212
        }
 
213
}
 
214
 
 
215
void Table::SetAppendToggle(bool set) {
 
216
        appendBottom = set;
 
217
        if (set)
 
218
                SetStatus("append to the bottom of the table");
 
219
        else
 
220
                SetStatus("append to the right of the table");
 
221
}
 
222
 
 
223
void Table::AddRows() {
 
224
        SetStatus("action: add rows");
 
225
        string d = DEFAULT_ADD_ROWS;
 
226
        string s0("To the bottom of the table");
 
227
        string s1("To the top of the selection");
 
228
        promptToggleDialog->SetToggleText(0, &s0);
 
229
        promptToggleDialog->SetToggleText(1, &s1);
 
230
        promptToggleDialog->SetTitle("Add rows");
 
231
        promptToggleDialog->SetSelectionLabel("Number of rows to add");
 
232
        promptToggleDialog->SetTextString(&d);
 
233
        promptToggleDialog->SetOKCallback(TableStubs::AddRowsOKCB, this);
 
234
        promptToggleDialog->SetToggleChangedCallback(
 
235
                                TableStubs::AddRowsToggleCB, this);
 
236
        promptToggleDialog->SetValue(topAdd);
 
237
        promptToggleDialog->Popup();
 
238
}
 
239
 
 
240
void Table::AddColumns() {
 
241
        SetStatus("action: add columns");
 
242
        string d = DEFAULT_ADD_COLUMNS;
 
243
        string s0("To the right of the table");
 
244
        string s1("To the left of the selection");
 
245
        promptToggleDialog->SetToggleText(0, &s0);
 
246
        promptToggleDialog->SetToggleText(1, &s1);
 
247
        promptToggleDialog->SetTitle("Add columns");
 
248
        promptToggleDialog->SetSelectionLabel("Number of columns to add");
 
249
        promptToggleDialog->SetTextString(&d);
 
250
        promptToggleDialog->SetOKCallback(TableStubs::AddColumnsOKCB, this);
 
251
        promptToggleDialog->SetToggleChangedCallback(
 
252
                                TableStubs::AddColumnsToggleCB, this);
 
253
        promptToggleDialog->SetValue(leftAdd);
 
254
        promptToggleDialog->Popup();
 
255
}
 
256
 
 
257
void Table::SetAddRowsToggle(bool set) {
 
258
        topAdd = set;
 
259
        if (set)
 
260
                SetStatus("add rows at the top of the selection");
 
261
        else
 
262
                SetStatus("add rows at the bottom of the table");
 
263
}
 
264
 
 
265
void Table::SetAddColumnsToggle(bool set) {
 
266
        leftAdd = set;
 
267
        if (set)
 
268
                SetStatus("add columns at the left of the selection");
 
269
        else
 
270
                SetStatus("add columns at the right of the table");
 
271
}
 
272
 
 
273
void Table::AddRows(unsigned n) {
 
274
        int m;
 
275
        if (topAdd) {
 
276
                if ((m = tviewer->GetTopSelectionRow()) == -1)
 
277
                        m = tviewer->GetNumberOfRows();
 
278
        }
 
279
        else
 
280
                m = tviewer->GetNumberOfRows();
 
281
        tviewer->NewCommand(new AddRowsCmd(this, tviewer, n, m));
 
282
        tviewer->ExecuteCommand();
 
283
}
 
284
 
 
285
void Table::AddColumns(unsigned n) {
 
286
        int m;
 
287
        if (leftAdd) {
 
288
                if ((m = tviewer->GetLeftSelectionColumn()) == -1)
 
289
                        m = tviewer->GetNumberOfColumns();
 
290
        }
 
291
        else
 
292
                m = tviewer->GetNumberOfColumns();
 
293
        tviewer->NewCommand(new AddColumnsCmd(this, tviewer, n, m));
 
294
        tviewer->ExecuteCommand();
 
295
}
 
296
 
 
297
void Table::DeleteRows() {
 
298
        SetStatus("action: delete rows");
 
299
        if (tviewer->NrSelected() > 0) {
 
300
                tviewer->NewCommand(new DeleteRowsCmd(this, tviewer));
 
301
                tviewer->ExecuteCommand();
 
302
        }
 
303
        else
 
304
                EmptySelectionMessage();
 
305
}
 
306
 
 
307
void Table::DeleteColumns() {
 
308
        SetStatus("action: delete columns");
 
309
        if (tviewer->NrSelected() > 0) {
 
310
                tviewer->NewCommand(new DeleteColumnsCmd(this, tviewer));
 
311
                tviewer->ExecuteCommand();
 
312
        }
 
313
        else
 
314
                EmptySelectionMessage();
 
315
}
 
316
 
 
317
void Table::DeleteAll() {
 
318
        SetStatus("action: delete all");
 
319
        if (tviewer->GetNumberOfRows() > 0) {
 
320
                QuestionDialog q(GetMainWindow()->GetWidget(), False);
 
321
                q.Initialize();
 
322
                q.SetTitle("delete all");
 
323
                q.SetMessageString(
 
324
                        "Are you sure you want to delete everything?");
 
325
                int answer = q.GetAnswer();
 
326
                if (answer == QuestionDialog::YES)
 
327
                        DeleteAllCells();
 
328
                else if (answer == QuestionDialog::NO)
 
329
                        SetStatus("aborted: nothing is deleted");
 
330
        }
 
331
        else
 
332
                SetStatus("aborted: table is empty");
 
333
}
 
334
 
 
335
void Table::DeleteAllCells() {
 
336
        tviewer->NewCommand(new DeleteAllCellsCmd(this, tviewer));
 
337
        tviewer->ExecuteCommand();
 
338
}
 
339
 
 
340
void Table::Purge() {
 
341
        SetStatus("action: purge table");
 
342
        if (tviewer->GetNumberOfRows() > 0) {
 
343
                tviewer->NewCommand(new PurgeCellsCmd(this, tviewer));
 
344
                tviewer->ExecuteCommand();
 
345
        }
 
346
        else
 
347
                SetStatus("aborted: table is empty");
 
348
}
 
349
 
 
350
void Table::CutTexts() {
 
351
        SetStatus("action: cut texts");
 
352
        if (tviewer->NrSelected() > 0) {
 
353
                tviewer->NewCommand(new CutCellTextsCmd(this, tviewer));
 
354
                tviewer->ExecuteCommand();
 
355
        }
 
356
        else
 
357
                EmptySelectionMessage();
 
358
}
 
359
 
 
360
void Table::CopyTexts() {
 
361
        SetStatus("action: copy texts");
 
362
        if (tviewer->NrSelected() > 0) {
 
363
                tviewer->NewCommand(new CopyCellTextsCmd(this, tviewer));
 
364
                tviewer->ExecuteCommand();
 
365
        }
 
366
        else
 
367
                EmptySelectionMessage();
 
368
}
 
369
 
 
370
void Table::PasteTexts() {
 
371
        SetStatus("action: paste texts");
 
372
        if (!tviewer->GetBuffer()->IsEmpty())
 
373
                tviewer->NewCommand(new PasteCellTextsCmd(this, tviewer));
 
374
        else {
 
375
                (new MessageDialog(GetMainWindow()->GetWidget(), 
 
376
                        MessageDialog::WARNING))->
 
377
                        Show("Warning", "There is nothing in the paste buffer");
 
378
                SetStatus("aborted: paste buffer is empty");
 
379
        }
 
380
}
 
381
 
 
382
void Table::SortRows() {
 
383
        SetStatus("action: sort rows");
 
384
        tviewer->NewCommand(new SortRowsCmd(this, tviewer));
 
385
        tviewer->ExecuteCommand();
 
386
}
 
387
 
 
388
void Table::SortColumns() {
 
389
        SetStatus("action: sort columns");
 
390
        tviewer->NewCommand(new SortColumnsCmd(this, tviewer));
 
391
        tviewer->ExecuteCommand();
 
392
}
 
393
 
 
394
void Table::FindAll(const string *s, bool sens, bool substr, bool) {
 
395
        tviewer->NewCommand(new FindAllCellsCmd(
 
396
                        this, tviewer, s, sens, substr));
 
397
        tviewer->ExecuteCommand();
 
398
}
 
399
 
 
400
void Table::FindNext(const string *s, bool sens, bool substr, bool) {
 
401
        tviewer->NewCommand(new FindNextCellCmd(
 
402
                        this, tviewer, s, sens, substr));
 
403
        tviewer->ExecuteCommand();
 
404
}
 
405
 
 
406
void Table::ReplaceNext(const string *s1, const string *s2, 
 
407
                bool sens, bool substr, bool) {
 
408
        tviewer->NewCommand(new ReplaceNextCellTextCmd(
 
409
                        this, tviewer, s1, s2, sens, substr));
 
410
        tviewer->ExecuteCommand();
 
411
}
 
412
 
 
413
void Table::ReplaceAll(const string *s1, const string *s2, 
 
414
                bool sens, bool substr, bool) {
 
415
        tviewer->NewCommand(new ReplaceAllCellTextsCmd(
 
416
                        this, tviewer, s1, s2, sens, substr));
 
417
        tviewer->ExecuteCommand();
 
418
}
 
419
 
 
420
void Table::SameWidth() { }
 
421
 
 
422
void Table::SameHeight() { }
 
423
 
 
424
void Table::Span() { }
 
425
 
 
426
void Table::UnSpan() { }
 
427
 
 
428
void Table::SelectAll() {
 
429
        SetStatus("action: select all");
 
430
        tviewer->NewCommand(new SelectAllCellsCmd(this, tviewer));
 
431
        tviewer->ExecuteCommand();
 
432
}
 
433
 
 
434
void Table::Move(Document::MoveType t) {
 
435
        tviewer->NewCommand(new MoveTableCmd(this, tviewer, t));
 
436
        tviewer->ExecuteCommand();
 
437
}
 
438
 
 
439
void Table::SetDefaultNumberOfRows(unsigned n) {
 
440
        string txt = "def. number of rows is ";
 
441
        txt += n;
 
442
        SetStatus(&txt);
 
443
        tviewer->SetDefaultNumberOfRows(n);
 
444
}
 
445
 
 
446
void Table::SetDefaultNumberOfColumns(unsigned n) {
 
447
        string txt = "def. number of columns is ";
 
448
        txt += n;
 
449
        SetStatus(&txt);
 
450
        tviewer->SetDefaultNumberOfColumns(n);
 
451
}
 
452
 
 
453
void Table::SetDefaultRowHeight(int n) {
 
454
        string txt = "default row height is ";
 
455
        txt += n;
 
456
        SetStatus(&txt);
 
457
        tviewer->TextModeOff();
 
458
        tviewer->UpdateDefaultRowHeight(n);
 
459
}
 
460
 
 
461
void Table::SetDefaultColumnWidth(int n) {
 
462
        string txt = "default column width is ";
 
463
        txt += n;
 
464
        SetStatus(&txt);
 
465
        tviewer->TextModeOff();
 
466
        tviewer->UpdateDefaultColumnWidth(n);
 
467
}
 
468
 
 
469
void Table::SetMarginWidth(int n) {
 
470
        string txt = "text margin width is ";
 
471
        txt += n;
 
472
        SetStatus(&txt);
 
473
        tviewer->TextModeOff();
 
474
        tviewer->UpdateMarginWidth(n);
 
475
}
 
476
 
 
477
void Table::SetMarginHeight(int n) {
 
478
        string txt = "text margin height is ";
 
479
        txt += n;
 
480
        SetStatus(&txt);
 
481
        tviewer->TextModeOff();
 
482
        tviewer->UpdateMarginHeight(n);
 
483
}
 
484
 
 
485
void Table::ShowRowColumnLabels(bool b) {
 
486
        string txt = (b ? "Show":"Don't show");
 
487
        txt += " row and column labels";
 
488
        SetStatus(&txt);
 
489
        tviewer->ShowRowColumnLabels(b);
 
490
}
 
491
 
 
492
void Table::PrintRowColumnLabels(bool b) {
 
493
        string txt = (b ? "Print":"Don't print");
 
494
        txt += " row and column labels";
 
495
        SetStatus(&txt);
 
496
        tviewer->PrintRowColumnLabels(b);
 
497
}
 
498
 
 
499
void Table::SetDefaultNumberOfRows() {
 
500
        SetStatus("action: set number of rows");
 
501
        scaleDialog->SetTitle("Number of rows");
 
502
        scaleDialog->SetScaleLabel("Default number of rows:        ");
 
503
        scaleDialog->SetScaleValues(MIN_NUMBER_OF_ROWS, MAX_NUMBER_OF_ROWS, 
 
504
                tviewer->GetDefaultNumberOfRows(), 0, defaultNumberOfRows);
 
505
        scaleDialog->SetValueChangedCallback(TableStubs::NumberOfRowsCB, this);
 
506
        scaleDialog->Popup();
 
507
}
 
508
 
 
509
void Table::SetDefaultNumberOfColumns() {
 
510
        SetStatus("action: set number of columns");
 
511
        scaleDialog->SetTitle("Number of columns");
 
512
        scaleDialog->SetScaleLabel("Default number of columns:  ");
 
513
        scaleDialog->SetScaleValues(MIN_NUMBER_OF_COLUMNS, 
 
514
                MAX_NUMBER_OF_COLUMNS, tviewer->GetDefaultNumberOfColumns(), 
 
515
                0, defaultNumberOfColumns);
 
516
        scaleDialog->SetValueChangedCallback(
 
517
                TableStubs::NumberOfColumnsCB, this);
 
518
        scaleDialog->Popup();
 
519
}
 
520
 
 
521
void Table::SetDefaultRowHeight() {
 
522
        SetStatus("action: set default row height");
 
523
        scaleDialog->SetTitle("Row Height");
 
524
        scaleDialog->SetScaleLabel("Default row height (in pixels)    ");
 
525
        scaleDialog->SetScaleValues(MIN_ROW_HEIGHT, MAX_ROW_HEIGHT,
 
526
                tviewer->GetDefaultRowHeight(), 0, defaultRowHeight);
 
527
        scaleDialog->SetValueChangedCallback(TableStubs::RowHeightCB, this);
 
528
        scaleDialog->Popup();
 
529
}
 
530
 
 
531
void Table::SetDefaultColumnWidth() {
 
532
        SetStatus("action: set default column width");
 
533
        scaleDialog->SetTitle("Column Width");
 
534
        scaleDialog->SetScaleLabel("Default column width (in pixels)  ");
 
535
        scaleDialog->SetScaleValues(MIN_COLUMN_WIDTH,MAX_COLUMN_WIDTH,
 
536
                tviewer->GetDefaultColumnWidth(), 0, defaultColumnWidth);
 
537
        scaleDialog->SetValueChangedCallback(TableStubs::ColumnWidthCB, this);
 
538
        scaleDialog->Popup();
 
539
}
 
540
 
 
541
void Table::UpdateLineStyle(Side::Type side, 
 
542
                            LineStyle::Type ltype) {
 
543
        SetStatus("action: update line style");
 
544
        if (tviewer->NrSelected() > 0) {
 
545
                tviewer->NewCommand(new UpdateLineStyleTableCmd(
 
546
                                this, tviewer, side, ltype));
 
547
                tviewer->ExecuteCommand();
 
548
        }
 
549
        else
 
550
                EmptySelectionMessage();
 
551
}
 
552
 
 
553
void Table::UpdateCellTextUnderline() {
 
554
        SetStatus("action: set/unset cell text underlinings");
 
555
        if (tviewer->NrSelected() > 0) {
 
556
                tviewer->NewCommand(new UpdateCellTextUnderlineCmd(
 
557
                                this, tviewer));
 
558
                tviewer->ExecuteCommand();
 
559
        }
 
560
        else
 
561
                EmptySelectionMessage();
 
562
}
 
563
 
 
564
void Table::UpdateLineWidth(Side::Type side, unsigned width) {
 
565
        SetStatus("action: update line width");
 
566
        if (tviewer->NrSelected() > 0) {
 
567
                tviewer->NewCommand(new UpdateLineWidthTableCmd(
 
568
                                this, tviewer, side, width));
 
569
                tviewer->ExecuteCommand();
 
570
        }
 
571
        else
 
572
                EmptySelectionMessage();
 
573
}
 
574
 
 
575
void Table::UpdateColumnAlignment(TextAlign::Type a) {
 
576
        SetStatus("action: update column alignment");
 
577
        if (tviewer->NrSelected() > 0) {
 
578
                tviewer->NewCommand(new 
 
579
                                UpdateColumnAlignmentCmd(this, tviewer, a));
 
580
                tviewer->ExecuteCommand();
 
581
        }
 
582
        else
 
583
                EmptySelectionMessage();
 
584
}
 
585
 
 
586
void Table::UpdateRowAlignment(TextAlign::Type a) {
 
587
        SetStatus("action: update row alignment");
 
588
        if (tviewer->NrSelected() > 0) {
 
589
                tviewer->NewCommand(new 
 
590
                                UpdateRowAlignmentCmd(this, tviewer, a));
 
591
                tviewer->ExecuteCommand();
 
592
        }
 
593
        else
 
594
                EmptySelectionMessage();
 
595
}
 
596
 
 
597
void Table::UpdateMarginWidth() {
 
598
        SetStatus("action: set margin width");
 
599
        scaleDialog->SetTitle("Text margin width");
 
600
        scaleDialog->SetScaleLabel("New text margin width (in pixels)   ");
 
601
        scaleDialog->SetScaleValues(MIN_MARGIN_WIDTH, MAX_MARGIN_WIDTH,
 
602
                tviewer->GetMarginWidth(), 0, defaultMarginWidth);
 
603
        scaleDialog->SetValueChangedCallback(TableStubs::MarginWidthCB, this);
 
604
        scaleDialog->Popup();
 
605
}
 
606
 
 
607
void Table::UpdateMarginHeight() {
 
608
        SetStatus("action: set margin height");
 
609
        scaleDialog->SetTitle("Text margin height");
 
610
        scaleDialog->SetScaleLabel("New text margin height (in pixels)  ");
 
611
        scaleDialog->SetScaleValues(MIN_MARGIN_HEIGHT, MAX_MARGIN_HEIGHT,
 
612
                tviewer->GetMarginHeight(), 0, defaultMarginHeight);
 
613
        scaleDialog->SetValueChangedCallback(TableStubs::MarginHeightCB, this);
 
614
        scaleDialog->Popup();
 
615
}
 
616
 
 
617
void Table::UpdateDefaultColumnAlignment(TextAlign::Type newType) {
 
618
        SetStatus("action: default column alignment");
 
619
        tviewer->SetDefaultColumnAlignment(newType);
 
620
        List<CellColumn *> columns;
 
621
        tviewer->GetEmptyColumns(&columns);
 
622
        for (columns.first(); !columns.done(); columns.next())
 
623
                columns.cur()->UpdateAlignment(newType);
 
624
}
 
625
 
 
626
void Table::UpdateDefaultRowAlignment(TextAlign::Type newType) {
 
627
        SetStatus("action: default row alignment");
 
628
        tviewer->SetDefaultRowAlignment(newType);
 
629
        List<CellRow *> rows;
 
630
        tviewer->GetEmptyRows(&rows);
 
631
        for (rows.first(); !rows.done(); rows.next())
 
632
                rows.cur()->UpdateAlignment(newType);
 
633
}
 
634
 
 
635
bool Table::UpdateText(Cell *c, const string *t) {
 
636
        if (!check(c))
 
637
                return False;
 
638
        c->UpdateText(t);
 
639
        return True;
 
640
}
 
641
 
 
642
void Table::AnnotateCell() {
 
643
        SetStatus("action: annotate cell");
 
644
        if (tviewer->NrSelected() == 1) {
 
645
                Cell *cell = (*tviewer->GetSelection())[0];
 
646
                AnnotateCell(cell);
 
647
        }
 
648
        else if (tviewer->NrSelected() == 0)
 
649
                EmptySelectionMessage();
 
650
        else {
 
651
                (new MessageDialog(GetMainWindow()->GetWidget(), 
 
652
                MessageDialog::WARNING))->
 
653
                Show("Warning", "Select only one single cell to annotate");
 
654
                SetStatus("aborted: selection too large");
 
655
        }
 
656
}
 
657
 
 
658
void Table::AnnotateCell(Cell *cell) {
 
659
        if (GetEltAnnotationDialog()->IsManaged()) {
 
660
                ShowDialog(MessageDialog::WARNING, "Warning",
 
661
                        "At most one cell annotation dialog "
 
662
                        "can be opened at a time");
 
663
                return;
 
664
        }
 
665
        string n = cell->GetRow()->GetNumber();
 
666
        n += ",";
 
667
        n += cell->GetColumn()->GetNumber();
 
668
        const string *annot = cell->GetAnnotation();
 
669
        annotationCell = cell;
 
670
        string title = "Annotation of cell " + n;
 
671
        GetEltAnnotationDialog()->SetTitle(&title);
 
672
        GetEltAnnotationDialog()->SetTextString(annot);
 
673
        GetEltAnnotationDialog()->Popup();
 
674
        GetEltAnnotationDialog()->SetStatus(&title);
 
675
}
 
676
 
 
677
void Table::SetCellAnnotation(const string *s) {
 
678
        SetStatus("action: update cell annotation");
 
679
        if (!check(annotationCell))
 
680
                return;
 
681
        // make here an undoable command!
 
682
        annotationCell->SetAnnotation(s);
 
683
}
 
684
 
 
685
void Table::EmptySelectionMessage() {
 
686
        (new MessageDialog(GetMainWindow()->GetWidget(), 
 
687
                MessageDialog::WARNING))->
 
688
                Show("Warning", "No cells are selected");
 
689
        SetStatus("aborted: selection is empty");
 
690
}
 
691
 
 
692
void Table::EmptyTableMessage() {
 
693
        (new MessageDialog(GetMainWindow()->GetWidget(), 
 
694
                MessageDialog::WARNING))->Show("Warning", "Table is empty");
 
695
        SetStatus("aborted: there are no cells");
 
696
}
 
697
 
 
698
void Table::DefaultRowAlignment() {
 
699
        SetStatus("action: default row alignment");
 
700
        rowAlignmentDialog->SetTitle("default row alignment");
 
701
        rowAlignmentDialog->SetHelpCallback(
 
702
                TableStubs::DefaultRowAlignmentDefaultCB, this);
 
703
        rowAlignmentDialog->SetOKCallback(
 
704
                TableStubs::DefaultRowAlignmentOKCB, this);
 
705
        ShowDefaultRowAlignment();
 
706
        rowAlignmentDialog->Popup();
 
707
}
 
708
 
 
709
void Table::DefaultColumnAlignment() {
 
710
        SetStatus("action: default column alignment");
 
711
        columnAlignmentDialog->SetTitle("default column alignment");
 
712
        columnAlignmentDialog->SetHelpCallback(
 
713
                TableStubs::DefaultColumnAlignmentDefaultCB, this);
 
714
        columnAlignmentDialog->SetOKCallback(
 
715
                TableStubs::DefaultColumnAlignmentOKCB, this);
 
716
        ShowDefaultColumnAlignment();
 
717
        columnAlignmentDialog->Popup();
 
718
}
 
719
 
 
720
void Table::UpdateRowAlignment() {
 
721
        SetStatus("action: update row alignment");
 
722
        rowAlignmentDialog->SetTitle("update row alignment");
 
723
        rowAlignmentDialog->SetHelpCallback(
 
724
                TableStubs::UpdateRowAlignmentDefaultCB, this);
 
725
        rowAlignmentDialog->SetOKCallback(
 
726
                TableStubs::UpdateRowAlignmentOKCB, this);
 
727
        rowAlignmentDialog->Popup();
 
728
}
 
729
 
 
730
void Table::UpdateColumnAlignment() {
 
731
        SetStatus("action: update column alignment");
 
732
        columnAlignmentDialog->SetTitle("update column alignment");
 
733
        columnAlignmentDialog->SetHelpCallback(
 
734
                TableStubs::UpdateColumnAlignmentDefaultCB, this);
 
735
        columnAlignmentDialog->SetOKCallback(
 
736
                TableStubs::UpdateColumnAlignmentOKCB, this);
 
737
        columnAlignmentDialog->Popup();
 
738
}
 
739
 
 
740
void Table::UpdateTableLineStyle() {
 
741
        SetStatus("action: update line style");
 
742
        tableLineStyleDialog->Popup();
 
743
}
 
744
 
 
745
void Table::UpdateTableLineWidth() {
 
746
        SetStatus("action: update line width");
 
747
        tableLineWidthDialog->Popup();
 
748
}
 
749
 
 
750
void Table::ShowDefaultLineStyle() {
 
751
        SetStatus("reset to default line style");
 
752
        string text;
 
753
        LineStyle::Type2String(GetViewer()->GetDefaultLineStyle(), &text);
 
754
        tableLineStyleDialog->SetValueOfText(0, &text);
 
755
        tableLineStyleDialog->SetValue(1, 0);
 
756
}
 
757
 
 
758
void Table::ShowConfigLineStyle() {
 
759
        SetStatus("reset to config line style");
 
760
        string text;
 
761
        LineStyle::Type2String(GetConfig()->GetLineStyle(), &text);
 
762
        tableLineStyleDialog->SetValueOfText(0, &text);
 
763
        tableLineStyleDialog->SetValue(1, 0);
 
764
}
 
765
 
 
766
void Table::ShowDefaultLineWidth() {
 
767
        SetStatus("reset to default line width");
 
768
        string text = GetViewer()->GetDefaultLineWidth();
 
769
        tableLineWidthDialog->SetValueOfText(0, &text);
 
770
        tableLineWidthDialog->SetValue(1, 0);
 
771
}
 
772
 
 
773
void Table::ShowConfigLineWidth() {
 
774
        SetStatus("reset to config line width");
 
775
        int wd = max(Viewer::MIN_LINE_WIDTH, 
 
776
                 min(GetConfig()->GetLineWidth(), Viewer::MAX_LINE_WIDTH));
 
777
        string text = wd;
 
778
        tableLineWidthDialog->SetValueOfText(0, &text);
 
779
        tableLineWidthDialog->SetValue(1, 0);
 
780
}
 
781
 
 
782
void Table::ShowDefaultColumnAlignment() {
 
783
        SetStatus("reset to default column alignment");
 
784
        string text;
 
785
        TextAlign::Type2String(tviewer->GetDefaultColumnAlignment(), &text);
 
786
        columnAlignmentDialog->SetValueOfText(0, &text);
 
787
}
 
788
 
 
789
void Table::ShowConfigColumnAlignment() {
 
790
        SetStatus("reset to config column alignment");
 
791
        string text;
 
792
        TextAlign::Type2String(GetConfig()->GetColumnAlignment(), &text);
 
793
        columnAlignmentDialog->SetValueOfText(0, &text);
 
794
}
 
795
 
 
796
void Table::ShowDefaultRowAlignment() {
 
797
        SetStatus("reset to default row alignment");
 
798
        string text;
 
799
        TextAlign::Type2String(tviewer->GetDefaultRowAlignment(), &text);
 
800
        if (text %= "Left")
 
801
                rowAlignmentDialog->SetValue(0, 0);
 
802
        else if (text %= "Right")
 
803
                rowAlignmentDialog->SetValue(0, 2);
 
804
        else
 
805
                rowAlignmentDialog->SetValue(0, 1);
 
806
}
 
807
 
 
808
void Table::ShowConfigRowAlignment() {
 
809
        SetStatus("reset to config row alignment");
 
810
        string text;
 
811
        TextAlign::Type2String(GetConfig()->GetRowAlignment(), &text);
 
812
        if (text %= "Left")
 
813
                rowAlignmentDialog->SetValue(0, 0);
 
814
        else if (text %= "Right")
 
815
                rowAlignmentDialog->SetValue(0, 2);
 
816
        else
 
817
                rowAlignmentDialog->SetValue(0, 1);
 
818
}