1
////////////////////////////////////////////////////////////////////////////////
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).
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
////////////////////////////////////////////////////////////////////////////////
26
#include "inlineeditor.h"
28
#include "scaledialog.h"
29
#include "ntogglelistdialog.h"
30
#include "linestyledialog.h"
31
#include "linewidthdialog.h"
32
#include "textalignmentdialog.h"
33
#include "fontchooserdialog.h"
34
#include "colorchooserdialog.h"
35
#include "editstubs.h"
39
const int Viewer::MIN_LINE_WIDTH=1;
40
const int Viewer::MAX_LINE_WIDTH=10;
42
Viewer::Viewer(Config *c, DrawWindow *d) {
47
scaler = new Scaler(c, this, d);
49
lastCmdIllegal = True;
56
// set these defaults from config.
57
autoResizing = config->GetAutoResizing();
58
inlineEditor = config->GetInlineEditor();
59
defaultLineWidth=max(MIN_LINE_WIDTH,
60
min(config->GetLineWidth(), MAX_LINE_WIDTH));
61
defaultLineStyle=config->GetLineStyle();
62
defaultLineColor=*config->GetLineColor();
63
defaultTextColor=*config->GetTextColor();
64
defaultFillColor=*config->GetFillColor();
65
defaultFillStyle = FillStyle::UNFILLED;
66
defaultTextAlignment = config->GetTextAlignment();
67
defaultFont = new XFont(config->GetFontFoundry(),
68
config->GetFontFamily(), config->GetFontStyle(),
69
config->GetPointSize(), config->GetScalableFonts());
70
defaultFont->SetUnderlined(config->GetUnderlined());
71
fontList = new List<XFont *>;
72
fontList->add(defaultFont);
74
fontChooserDialog = new FontChooserDialog(d->GetWidget(),
75
config->GetAddPointSizes());
76
fontChooserDialog->Initialize();
77
// color chooser stuff
78
colorChooserDialog = new ColorChooserDialog(d->GetWidget());
79
colorChooserDialog->Initialize();
81
lineWidthDialog = new LineWidthDialog(d->GetWidget());
82
lineWidthDialog->Initialize();
84
lineStyleDialog = new LineStyleDialog(d->GetWidget());
85
lineStyleDialog->Initialize();
87
textAlignmentDialog = new TextAlignmentDialog(d->GetWidget());
88
textAlignmentDialog->Initialize();
90
ShowConfigLineStyle();
91
ShowConfigLineWidth();
92
ShowConfigTextAlignment();
94
ShowConfigLineColor();
103
for (int i=0; i<cmdHistSize; i++)
105
delete lineWidthDialog;
106
delete lineStyleDialog;
107
delete fontChooserDialog;
108
delete colorChooserDialog;
109
delete textAlignmentDialog;
112
void Viewer::Undo() {
113
mainwindow->SetStatus("action: undo");
114
if (!(pasting || zigZag))
118
void Viewer::Redo() {
119
mainwindow->SetStatus("action: redo");
120
if (!(pasting || zigZag))
124
Command *Viewer::GetLastCmd() {
125
if (lastCmdIllegal || lastCmd < 0 || lastCmd >= cmdHistSize)
128
return cmdHist[lastCmd];
132
void Viewer::Refresh() {
133
// can take a while ...
134
mainwindow->SetCursor(MouseCursor::WATCH);
139
mainwindow->SetCursor(MouseCursor::LEFT_PTR);
142
void Viewer::Redraw() {
148
FileSelectionDialog *Viewer::GetPrintFileSelectionDialog() {
149
return printer->GetFileSelectionDialog();
152
void Viewer::ClearGrafport() {
153
grafport->ClearArea(0,0,grafport->GetWidth(),grafport->GetHeight());
156
XFont *Viewer::GetFont(int family, int style, int size) {
157
// look for font in font list.
158
for (fontList->first(); !fontList->done(); fontList->next()) {
159
XFont *ft = fontList->cur();
160
if (ft->GetFamily() == family && ft->GetStyle() == style &&
161
ft->GetSize() == size) {
165
// if not found, load new font and add to font list.
166
XFont *newFont = new XFont(config->GetFontFoundry(),
167
family, style, size, config->GetScalableFonts());
168
fontList->add(newFont);
172
XFont *Viewer::GetFont(const char *description) {
173
int family = XFont::FindFamily(description);
174
int style = XFont::FindStyle(description);
175
int size = XFont::FindSize(description);
176
return GetFont(family, style, size);
179
void Viewer::SetDefaultFontAttributes(int f, int s, int p) {
180
if (defaultFont->GetFamily()==f &&
181
defaultFont->GetStyle()==s &&
182
defaultFont->GetSize()==p)
184
SetDefaultFont(GetFont(f, s, p));
185
printer->SetDefaultFont(f, s, p);
188
void Viewer::DoubleClick() {
189
error("Double click is not implemented\n");
192
void Viewer::DoFunctionKey(int i) {
193
error("Function key %d, (not implemented)\n", i);
196
void Viewer::DeleteCommands() {
198
lastCmdIllegal = True;
199
for (int i=0; i<cmdHistSize; i++)
202
mainwindow->SetUndoName("Undo");
203
mainwindow->EnableUndo(False);
204
mainwindow->SetRedoName("Redo");
205
mainwindow->EnableRedo(False);
209
void Viewer::NewCommand(Command *newcmd) {
212
lastCmdIllegal = True;
215
lastCmdIllegal = False;
217
if (lastCmd >= cmdHistSize-1 && cmdHistSize >= MAXHISTSIZE) {
218
Command *delCmd = cmdHist[0];
220
for (int i=1; i<cmdHistSize; i++)
221
cmdHist[i-1] = cmdHist[i];
223
lastCmd = cmdHistSize-1;
225
for (int i=lastCmd+1; i<cmdHistSize; i++)
228
cmdHistSize = lastCmd+1;
229
cmdHist[lastCmd] = newcmd;
231
s += newcmd->GetName();
233
mainwindow->SetUndoName(s.getstr());
234
mainwindow->EnableUndo(True);
235
mainwindow->SetRedoName("Redo");
236
mainwindow->EnableRedo(False);
239
void Viewer::AbortCommand() {
240
if (!lastCmdIllegal && lastCmd >= 0 && check(lastCmd==cmdHistSize-1)) {
241
delete cmdHist[lastCmd];
246
s += cmdHist[lastCmd]->GetName();
248
mainwindow->SetUndoName(s.getstr());
249
mainwindow->EnableUndo(True);
252
lastCmdIllegal = True;
253
mainwindow->SetUndoName("Undo");
254
mainwindow->EnableUndo(False);
256
mainwindow->SetRedoName("Redo");
257
mainwindow->EnableRedo(False);
261
void Viewer::ExecuteCommand() {
265
if (lastCmd >= 0 && check(lastCmd < cmdHistSize))
266
cmdHist[lastCmd]->Execute();
269
void Viewer::UndoCommand() {
272
if (edit && editing && inlineEditor) {
277
Command *cmd = cmdHist[lastCmd];
280
if (cmd->CmdDone()) {
285
mainwindow->SetRedoName(s.getstr());
286
mainwindow->EnableRedo(True);
291
s += cmdHist[lastCmd]->GetName();
293
mainwindow->SetUndoName(s.getstr());
294
mainwindow->EnableUndo(True);
299
mainwindow->SetStatus("there's nothing to undo");
300
mainwindow->SetUndoName("Undo");
301
mainwindow->EnableUndo(False);
304
void Viewer::RedoCommand() {
308
if (edit && editing && inlineEditor) {
312
if (lastCmd < -1 || lastCmd > cmdHistSize-1)
315
Command *cmd = cmdHist[lastCmd];
318
if (!cmd->CmdDone()) {
323
mainwindow->SetUndoName(s.getstr());
324
mainwindow->EnableUndo(True);
326
if (lastCmd >= 0 && lastCmd < cmdHistSize-1) {
328
s += cmdHist[lastCmd+1]->GetName();
330
mainwindow->SetRedoName(s.getstr());
331
mainwindow->EnableRedo(True);
336
mainwindow->SetStatus("there's nothing to redo");
337
mainwindow->SetRedoName("Redo");
338
mainwindow->EnableRedo(False);
341
void Viewer::EditText(int key) {
344
if (key == Key::BACKSPACE) {
346
mainwindow->SetStatus("delete previous char");
348
else if (key == Key::DELETE) {
350
mainwindow->SetStatus("delete next char");
352
else if (key == Key::VERTICAL_TAB || key == Key::ESCAPE) {
354
mainwindow->SetStatus("delete all chars");
356
else if (key == Key::HOME || key == Key::RS) {
358
mainwindow->SetStatus("move cursor to first char");
360
else if (key == Key::END || key == Key::FS) {
362
mainwindow->SetStatus("move cursor to last char");
364
else if (key == Key::LEFT) {
366
mainwindow->SetStatus("move cursor 1 char left");
368
else if (key == Key::DOWN) {
370
mainwindow->SetStatus("move cursor 1 line down");
372
else if (key == Key::UP) {
374
mainwindow->SetStatus("move cursor 1 line up");
376
else if (key == Key::RIGHT) {
378
mainwindow->SetStatus("move cursor 1 char right");
381
unsigned char c = (unsigned char)key;
384
if (!iscntrl(c) || key == '\n')
387
mainwindow->SetStatus("ignoring char");
391
void Viewer::GetPageSize(double &w, double &h) {
393
printer->GetPageSize(w, h);
396
void Viewer::SetAutoResize(bool s) {
397
string buf = "Autoresize is ";
402
mainwindow->SetStatus(&buf);
406
void Viewer::SetInlineEdit(bool s) {
407
string buf = "In-line edit is ";
412
mainwindow->SetStatus(&buf);
417
void Viewer::DefaultLineWidth() {
418
mainwindow->SetStatus("action: default line width");
419
lineWidthDialog->SetTitle("default line width");
420
lineWidthDialog->SetHelpCallback(
421
EditStubs::DefaultLineWidthDefaultCB, this);
422
lineWidthDialog->SetOKCallback(
423
EditStubs::DefaultLineWidthOKCB, this);
424
ShowDefaultLineWidth();
425
lineWidthDialog->Popup();
428
void Viewer::UpdateLineWidth() {
429
mainwindow->SetStatus("action: update line width");
430
lineWidthDialog->SetTitle("update line width");
431
lineWidthDialog->SetHelpCallback(
432
EditStubs::UpdateLineWidthDefaultCB, this);
433
lineWidthDialog->SetOKCallback(
434
EditStubs::UpdateLineWidthOKCB, this);
435
lineWidthDialog->Popup();
438
void Viewer::SetDefaultLineWidth(unsigned d) {
439
defaultLineWidth=max(MIN_LINE_WIDTH, min(d, MAX_LINE_WIDTH));
440
// otherwise some problems with pixel droppings.
444
void Viewer::DefaultLineColor() {
445
mainwindow->SetStatus("action: default line color");
446
colorChooserDialog->SetTitle("default line color");
447
colorChooserDialog->SetHelpCallback(
448
EditStubs::DefaultLineColorDefaultCB, this);
449
colorChooserDialog->SetOKCallback(
450
EditStubs::DefaultLineColorOKCB, this);
451
colorChooserDialog->ManageFillToggle(False);
452
ShowDefaultLineColor();
453
colorChooserDialog->Popup();
456
void Viewer::UpdateLineColor() {
457
mainwindow->SetStatus("action: update line color");
458
colorChooserDialog->SetTitle("update line color");
459
colorChooserDialog->SetHelpCallback(
460
EditStubs::UpdateLineColorDefaultCB, this);
461
colorChooserDialog->SetOKCallback(
462
EditStubs::UpdateLineColorOKCB, this);
463
colorChooserDialog->ManageFillToggle(False);
464
colorChooserDialog->Popup();
467
void Viewer::ShowConfigLineColor() {
468
colorChooserDialog->SetTextString(config->GetLineColor());
469
colorChooserDialog->SelectItem(config->GetLineColor());
472
void Viewer::ShowDefaultLineColor() {
473
colorChooserDialog->SetTextString(&defaultLineColor);
474
colorChooserDialog->SelectItem(&defaultLineColor);
477
void Viewer::DefaultTextColor() {
478
mainwindow->SetStatus("action: default text color");
479
colorChooserDialog->SetTitle("default text color");
480
colorChooserDialog->SetHelpCallback(
481
EditStubs::DefaultTextColorDefaultCB, this);
482
colorChooserDialog->SetOKCallback(
483
EditStubs::DefaultTextColorOKCB, this);
484
colorChooserDialog->ManageFillToggle(False);
485
ShowDefaultTextColor();
486
colorChooserDialog->Popup();
489
void Viewer::UpdateTextColor() {
490
mainwindow->SetStatus("action: update text color");
491
colorChooserDialog->SetTitle("update text color");
492
colorChooserDialog->SetHelpCallback(
493
EditStubs::UpdateTextColorDefaultCB, this);
494
colorChooserDialog->SetOKCallback(
495
EditStubs::UpdateTextColorOKCB, this);
496
colorChooserDialog->ManageFillToggle(False);
497
colorChooserDialog->Popup();
500
void Viewer::ShowConfigTextColor() {
501
colorChooserDialog->SetTextString(config->GetTextColor());
502
colorChooserDialog->SelectItem(config->GetTextColor());
505
void Viewer::ShowDefaultTextColor() {
506
colorChooserDialog->SetTextString(&defaultTextColor);
507
colorChooserDialog->SelectItem(&defaultTextColor);
510
void Viewer::DefaultFillColor() {
511
mainwindow->SetStatus("action: default fill color");
512
colorChooserDialog->SetTitle("default fill color");
513
colorChooserDialog->SetHelpCallback(
514
EditStubs::DefaultFillColorDefaultCB, this);
515
colorChooserDialog->SetOKCallback(
516
EditStubs::DefaultFillColorOKCB, this);
517
colorChooserDialog->SetFillToggle(defaultFillStyle==FillStyle::FILLED);
518
colorChooserDialog->ManageFillToggle(True);
519
colorChooserDialog->SetFillToggleLabel("fill shapes by default");
520
ShowDefaultFillColor();
521
colorChooserDialog->Popup();
524
void Viewer::UpdateFillColor() {
525
mainwindow->SetStatus("action: update fill color");
526
colorChooserDialog->SetTitle("update fill color");
527
colorChooserDialog->SetHelpCallback(
528
EditStubs::UpdateFillColorDefaultCB, this);
529
colorChooserDialog->SetOKCallback(
530
EditStubs::UpdateFillColorOKCB, this);
531
colorChooserDialog->ManageFillToggle(True);
532
colorChooserDialog->SetFillToggleLabel("fill selected shapes");
533
colorChooserDialog->Popup();
536
void Viewer::ShowConfigFillColor() {
537
colorChooserDialog->SetTextString(config->GetFillColor());
538
colorChooserDialog->SelectItem(config->GetFillColor());
541
void Viewer::ShowDefaultFillColor() {
542
colorChooserDialog->SetTextString(&defaultTextColor);
543
colorChooserDialog->SelectItem(&defaultTextColor);
546
void Viewer::DefaultLineStyle() {
547
mainwindow->SetStatus("action: default line style");
548
lineStyleDialog->SetTitle("default line style");
549
lineStyleDialog->SetHelpCallback(
550
EditStubs::DefaultLineStyleDefaultCB, this);
551
lineStyleDialog->SetOKCallback(
552
EditStubs::DefaultLineStyleOKCB, this);
553
ShowDefaultLineStyle();
554
lineStyleDialog->Popup();
557
void Viewer::UpdateLineStyle() {
558
mainwindow->SetStatus("action: update line style");
559
lineStyleDialog->SetTitle("update line style");
560
lineStyleDialog->SetHelpCallback(
561
EditStubs::UpdateLineStyleDefaultCB, this);
562
lineStyleDialog->SetOKCallback(
563
EditStubs::UpdateLineStyleOKCB, this);
564
lineStyleDialog->Popup();
567
void Viewer::ShowDefaultLineWidth() {
568
string text = defaultLineWidth;
569
lineWidthDialog->SetValueOfText(0, &text);
572
void Viewer::ShowConfigLineWidth() {
573
string text = config->GetLineWidth();
574
lineWidthDialog->SetValueOfText(0, &text);
577
void Viewer::ShowDefaultLineStyle() {
579
LineStyle::Type2String(defaultLineStyle, &text);
580
lineStyleDialog->SetValueOfText(0, &text);
583
void Viewer::ShowConfigLineStyle() {
585
LineStyle::Type2String(config->GetLineStyle(), &text);
586
lineStyleDialog->SetValueOfText(0, &text);
589
void Viewer::DefaultFont() {
590
mainwindow->SetStatus("action: default font");
591
fontChooserDialog->SetTitle("default text font");
592
fontChooserDialog->SetOKCallback(
593
EditStubs::DefaultFontOKCB, this);
594
fontChooserDialog->SetHelpCallback(
595
EditStubs::DefaultFontDefaultCB, this);
596
fontChooserDialog->SetOptionsVisible(False);
598
fontChooserDialog->Popup();
601
void Viewer::UpdateFont() {
602
mainwindow->SetStatus("action: update font");
603
fontChooserDialog->SetTitle("update text font");
604
fontChooserDialog->SetOKCallback(
605
EditStubs::UpdateFontOKCB, this);
606
fontChooserDialog->SetHelpCallback(
607
EditStubs::UpdateFontDefaultCB, this);
608
fontChooserDialog->SetOptionsVisible(True);
609
fontChooserDialog->ShowExample();
610
fontChooserDialog->Popup();
613
void Viewer::ShowDefaultFont() {
614
mainwindow->SetStatus("show default font");
615
fontChooserDialog->SetFamily(defaultFont->GetFamily());
616
fontChooserDialog->SetStyle(defaultFont->GetStyle());
617
fontChooserDialog->SetSize(defaultFont->GetSize());
618
fontChooserDialog->ShowExample();
621
void Viewer::ShowConfigFont() {
622
mainwindow->SetStatus("show config font");
623
fontChooserDialog->SetFamily(config->GetFontFamily());
624
fontChooserDialog->SetStyle(config->GetFontStyle());
625
fontChooserDialog->SetSize(config->GetPointSize());
626
fontChooserDialog->ShowExample();
629
void Viewer::DefaultTextAlignment() {
630
mainwindow->SetStatus("action: default text alignment");
631
textAlignmentDialog->SetTitle("default text alignment");
632
textAlignmentDialog->SetHelpCallback(
633
EditStubs::DefaultTextAlignmentDefaultCB, this);
634
textAlignmentDialog->SetOKCallback(
635
EditStubs::DefaultTextAlignmentOKCB, this);
636
ShowDefaultTextAlignment();
637
textAlignmentDialog->Popup();
640
void Viewer::UpdateTextAlignment() {
641
mainwindow->SetStatus("action: update text alignment");
642
textAlignmentDialog->SetTitle("update text alignment");
643
textAlignmentDialog->SetHelpCallback(
644
EditStubs::UpdateTextAlignmentDefaultCB, this);
645
textAlignmentDialog->SetOKCallback(
646
EditStubs::UpdateTextAlignmentOKCB, this);
647
textAlignmentDialog->Popup();
650
void Viewer::ShowDefaultTextAlignment() {
652
TextAlign::Type2String(defaultTextAlignment, &text);
653
textAlignmentDialog->SetValueOfText(0, &text);
656
void Viewer::ShowConfigTextAlignment() {
658
TextAlign::Type2String(config->GetTextAlignment(), &text);
659
textAlignmentDialog->SetValueOfText(0, &text);
662
void Viewer::Save(OutputFile *f) {
667
bool Viewer::Load(InputFile *f, double format) {
668
return (printer->Load(f, format) &&
669
scaler->Load(f, format));
672
bool Viewer::Check(InputFile *f, double format) {
673
return (printer->Check(f, format) &&
674
scaler->Check(f, format));