1
///////////////////////////////////////////////////////////////////////////////
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1997, 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
////////////////////////////////////////////////////////////////////////////////
24
#include "editstubs.h"
35
#include "messagedialog.h"
36
#include "Teapot2a.xbm"
38
EditWindow::EditWindow(const char *n): MainWindow(n) {
48
printerOptionsItems = 0;
50
pageOrientationItems = 0;
74
generateLatexFonts = False;
78
EditWindow::~EditWindow() {
86
delete popupEditItems;
93
if (printerOptionsItems)
94
delete printerOptionsItems;
96
delete bannerPageItems;
104
delete propertiesItems;
105
if (pageOrientationItems)
106
delete pageOrientationItems;
108
delete pageSizeItems;
113
void EditWindow::Manage() {
115
MainWindow::Manage();
117
MainWindow::ManageUnmapped();
120
Widget EditWindow::CreateWorkArea(Widget parent, int argc, char **argv) {
123
logoBitmap.xbm_width = Teapot2a_width;
124
logoBitmap.xbm_height = Teapot2a_height;
125
logoBitmap.xbm_bits = (unsigned char *)Teapot2a_bits;
126
logoPixmap = logoBitmap.CreatePixmap(parent, GetDisplay());
127
Widget form = XtVaCreateManagedWidget(GetName()->getstr(),
128
xmFormWidgetClass, parent, 0);
129
// find type of document tool
130
int tool = GetTool();
131
// parse command line options
132
DetermineScreen(XtScreen(parent)); // determine screen sizes.
133
ParseUserOptions(argc, argv);
134
// Create application objects.
138
CreateComponents(form); // create the UI components of the main window.
139
string title = Toolkit::TOOLKIT_NAME;
141
title += Toolkit::TOOL_TITLES[tool];
143
title += Version::TOOLKIT_VERSION;
145
// set name and pixmap of the icon.
146
SetIconName(Toolkit::TOOL_NAMES[tool]);
147
SetIconPixmap(logoPixmap);
151
void EditWindow::ParseUserOptions(int argc, char **argv) {
155
// look for help option.
156
if (System::FindArg(argv, argc, "-help", n) ||
157
System::FindArg(argv, argc, "-h", n)) {
161
// look for version option.
162
if (System::FindArg(argv, argc, "-version", n) ||
163
System::FindArg(argv, argc, "-v", n)) {
164
std::cerr << argv[0] << ": " << Version::TOOLKIT_VERSION << std::endl;
169
// find but ignore priv_cmap option here.
170
if (System::FindArg(argv, argc, "-priv_cmap", n)) {
173
// look for -project option to set working directory.
174
if (System::FindArg(argv, argc, "-projdir", n)) {
184
// look for -toPS option to generate PS.
185
if (System::FindArg(argv, argc, "-toPS", n)) {
191
char *c = strrchr(argv[n+1], '.');
192
if (c && equal(c, ".ps")) {
198
// look for -toEPS option to generate EPS.
199
if (System::FindArg(argv, argc, "-toEPS", n)) {
205
char *c = strrchr(argv[n+1], '.');
206
if (c && equal(c, ".eps")) {
212
// look for -toPNG option to generate PNG.
213
if (System::FindArg(argv, argc, "-toPNG", n)) {
219
char *c = strrchr(argv[n+1], '.');
220
if (c && equal(c, ".png")) {
226
// look for -toFig option to generate Fig.
227
if (System::FindArg(argv, argc, "-toFig", n) ||
228
System::FindArg(argv, argc, "-toFIG", n)) {
234
char *c = strrchr(argv[n+1], '.');
235
if (c && equal(c, ".fig")) {
240
if (System::FindArg(argv, argc, "-latex", n)) {
242
generateLatexFonts = True;
247
void EditWindow::WriteUsage(const char *prog) {
248
const char *OPTIONS =
249
"-drawing <w>x<h>\tCreate drawing area of <w>x<h> pixels\n"
250
"-h[elp]\t\t\tShow this message and quit\n"
251
"-maxdrawing <w>x<h>\tSet maximum drawing area size to <w>x<h> pixels\n"
252
"-projdir <dir>\t\tSet the project directory to <dir>\n"
253
"-priv_cmap\t\tStart the editor with a private colormap\n"
254
"-toPS [<file>.ps]\tGenerate PostScript (to <file>.ps or else stdout) "
256
"-toEPS [<file>.eps]\tGenerate EPS (to <file>.eps or else stdout) "
258
"-toFig [<file>.fig] [-latex]\tGenerate Fig format (to <file>.fig "
259
"or else\n\t\t\tstdout) and quit. "
260
"When the -latex option is given\n\t\t\tLaTeX fonts are "
261
"generated, otherwise normal PostScript\n\t\t\t fonts"
263
"-toPNG <file>.png\tGenerate PNG format to <file>.png and quit\n"
264
"-v[ersion]\t\tShow the TCM version and quit\n"
265
"remark: the -toXXX options require an existing TCM document file\n";
266
std::cerr << "Usage: " << prog << " [options] [document]\nOptions:\n"
267
<< OPTIONS << std::endl;
271
Widget EditWindow::CreateLogo(Widget parent) {
272
// draws a little picture in the top right corner of parent.
276
// get the foreground and background colors of the parent
277
// to make the pixmaps appear using a consistent color
278
XtVaGetValues(parent, XmNforeground, &fg, XmNbackground, &bg, 0);
279
// the pixmap is loaded from a X11 bitmap, called DEFAULT_ICON.
280
Pixmap px = logoBitmap.CreatePixmap(parent, GetDisplay());
281
Widget button = XtVaCreateManagedWidget(
282
"logo", xmPushButtonWidgetClass, parent,
284
XmNlabelType, XmPIXMAP,
285
XmNtopAttachment, XmATTACH_FORM,
286
XmNrightAttachment, XmATTACH_FORM, 0);
287
XtAddCallback(button, XmNactivateCallback, AboutCB, (XtPointer)this);
288
AddLiteClue(button, "TCM logo");
292
Widget EditWindow::CreateDocumentArea(Widget parent) {
293
// draws a label and a text-field which is intended to contain the
294
// name and type of document that is being edited
297
Widget rc = XtVaCreateWidget("DocumentArea",
298
xmRowColumnWidgetClass, parent,
300
XmNorientation, XmHORIZONTAL,
301
XmNleftAttachment, XmATTACH_FORM, 0);
303
XtVaSetValues(rc, XmNtopAttachment, XmATTACH_WIDGET,
304
XmNtopWidget, menubar, 0);
306
XtVaSetValues(rc, XmNrightAttachment, XmATTACH_WIDGET,
307
XmNrightWidget, logo, 0);
308
XtVaCreateManagedWidget("Document Type: ",
309
xmLabelWidgetClass, rc,
310
XmNalignment, XmALIGNMENT_BEGINNING, 0);
311
documentType = XtVaCreateManagedWidget("DocumentType",
312
xmTextFieldWidgetClass, rc,
315
XmNcursorPositionVisible, False, 0);
316
AddLiteClue(documentType,
317
"The type of document that is edited by this editor (fixed)");
318
XtVaCreateManagedWidget("Name: ",
319
xmLabelWidgetClass, rc,
320
XmNalignment, XmALIGNMENT_BEGINNING, 0);
321
documentName = XtVaCreateManagedWidget("DocumentName",
322
xmTextFieldWidgetClass, rc,
325
XmNcursorPositionVisible, True, 0);
326
AddLiteClue(documentName,
327
"The document name. Can be changed (apply with <enter>)");
329
XtAddCallback(documentName, XmNactivateCallback,
330
EditStubs::ChangeNameCB, (XtPointer)document);
331
if (Toolkit::HierarchicEditor(GetTool())) {
332
// XtVaCreateManagedWidget("Level: ",
333
// xmLabelWidgetClass, rc,
334
// XmNalignment, XmALIGNMENT_BEGINNING, 0);
335
// documentLevel = XtVaCreateManagedWidget("DocumentLevel",
336
// xmTextFieldWidgetClass, rc,
337
// XmNeditable, False,
338
// XmNcursorPositionVisible, False, 0);
339
// AddLiteClue(documentLevel,
340
// "The current level in the document (fixed)");
342
modifiedToggle = CreateToggle(rc, "modified", False,
343
EditStubs::SetModifiedCB, (XtPointer)document);
344
AddLiteClue(modifiedToggle, "Indicates document modification");
345
XtUninstallTranslations(modifiedToggle);
350
Widget EditWindow::CreateControlArea(Widget parent) {
353
Widget rc = XtVaCreateWidget("ControlArea",
354
xmRowColumnWidgetClass, parent,
355
XmNorientation, XmHORIZONTAL, 0);
357
XtVaSetValues(rc, XmNtopWidget, statusArea,
358
XmNtopAttachment, XmATTACH_WIDGET, 0);
359
XtVaSetValues(rc, XmNbottomAttachment, XmATTACH_FORM, 0);
364
Widget EditWindow::CreateStatusArea(Widget parent) {
365
// create a single line uneditable text field. This is the area
366
// intended for (status) text output of the application.
369
Widget rc = XtVaCreateWidget("StatusArea",
370
xmRowColumnWidgetClass, parent,
371
XmNorientation, XmHORIZONTAL, 0);
373
XtVaSetValues(rc, XmNbottomWidget, controlArea,
374
XmNbottomAttachment, XmATTACH_WIDGET, 0);
375
statusText = XtVaCreateManagedWidget("StatusText",
376
xmTextFieldWidgetClass, rc,
378
XmNcursorPositionVisible, False,
379
XmNshadowThickness, 0,
381
if (screenType <= SVGA)
382
XtVaSetValues(statusText, XmNcolumns, 40, 0);
384
XtVaSetValues(statusText, XmNcolumns, 50, 0);
389
Widget EditWindow::CreateToggle(Widget parent, const char *label, bool Init,
390
XtCallbackProc fun, XtPointer clientData) {
393
XmString text = CreateXmString(label);
394
Widget toggle = XtVaCreateManagedWidget(label,
395
xmToggleButtonWidgetClass, parent,
396
XmNlabelString, text,
398
XtAddCallback(toggle, XmNvalueChangedCallback, fun, clientData);
403
void EditWindow::EnableUndo(bool flag) {
404
// change edit pulldown menu undo sensitiveness.
407
Widget undoMenuItem = editMenu->GetMenuItem("Undo");
409
XtVaSetValues(undoMenuItem, XmNsensitive, flag, 0);
413
void EditWindow::EnableRedo(bool flag) {
414
// change edit pulldown menu redo sensitiveness.
417
Widget redoMenuItem = editMenu->GetMenuItem("Redo");
419
XtVaSetValues(redoMenuItem, XmNsensitive, flag, 0);
422
void EditWindow::SetUndoName(const char *uname) {
423
// change edit pulldown menu undo label.
426
XmString s = CreateXmString(uname);
427
Widget undoMenuItem = editMenu->GetMenuItem("Undo");
429
XtVaSetValues(undoMenuItem, XmNlabelString, s, 0);
433
void EditWindow::SetRedoName(const char *uname) {
434
// change edit pulldown menu redo label.
437
XmString s = CreateXmString(uname);
438
Widget redoMenuItem = editMenu->GetMenuItem("Redo");
440
XtVaSetValues(redoMenuItem, XmNlabelString, s, 0);
444
void EditWindow::DetermineScreen(Screen *s) {
445
int width = WidthOfScreen(s);
446
int height = HeightOfScreen(s);
448
error("screen wxh = %dx%d\n", width, height);
450
// Find out what popular resolution the screen has.
451
if (width >= 1280 && height >= 1024)
453
else if (width >= 1024 && height >= 1024)
455
else if (width >= 1152 && height >= 900)
457
else if (width >= 1024 && height >= 800)
459
else if (width >= 1024 && height >= 768)
461
else if (width >= 800 && height >= 600)
463
else if (width >= 640 && height >= 480)
469
void EditWindow::CreatePrinter() {
470
if (check(document) && check(GetConfig()))
471
printer = new Printer(GetConfig(), document);
474
void EditWindow::CreateHelper() {
475
helper = new Helper(GetConfig(), this);
478
void EditWindow::Finalize() {
479
document->UpdateWindow();
481
document->NewDir(&projDir);
483
// if a file is given as command line option, try to load it.
485
loadFile.setSuffix(*document->GetSuffix());
486
if (System::FileExists(loadFile.getstr()))
487
document->DoLoad(&loadFile);
490
document->NewFile(&loadFile);
493
// "send email on startup?"
494
if (GetConfig()->GetSendEmailOnStartup()) {
495
System::SendEmail(System::emailAddress,
496
System::TOOLKIT_STAT_HEADER, Toolkit::TOOL_NAMES[GetTool()],
497
Version::TOOLKIT_VERSION, "");
499
// generate PS, EPS, PNG or Fig??
502
std::cerr << "error: no document file name given" << std::endl;
503
WriteUsage(Toolkit::EXECUTABLE_NAMES[GetTool()]);
505
else if (!document->IsLoaded()) {
506
std::cerr << "error: incorrect or non-existent document "
507
"file given" << std::endl;
508
WriteUsage(Toolkit::EXECUTABLE_NAMES[GetTool()]);
512
printer->SavePostScript(&psFile, False);
514
printer->SaveEPS(&epsFile);
516
printer->SavePNG(&pngFile);
518
printer->SaveFig(&figFile, generateLatexFonts);
524
void EditWindow::SetStatus(const char *message) {
526
XtVaSetValues(statusText, XmNvalue, message, 0);
529
void EditWindow::SetStatus(const string *message) {
530
SetStatus(message->getstr());
533
void EditWindow::SetDocumentName(const char *s) {
535
int columns = min(30, max(10, strlen(s)+2));
536
XtVaSetValues(documentName, XmNvalue, s,
537
XmNcolumns, columns, 0);
538
// show document name also in the icon.
543
void EditWindow::SetDocumentName(const string *s) {
544
SetDocumentName(s->getstr());
547
void EditWindow::SetDocumentType(const char *s) {
549
int columns = min(30, max(10, strlen(s)+2));
550
XtVaSetValues(documentType, XmNvalue, s,
551
XmNcolumns, columns, 0);
555
void EditWindow::SetDocumentType(const string *s) {
556
SetDocumentType(s->getstr());
559
void EditWindow::SetDirName(const char *s) {
561
int columns = min(30, max(10, strlen(s)+4));
562
XtVaSetValues(dirName, XmNvalue, s,
563
XmNcolumns, columns, 0);
567
void EditWindow::SetDirName(const string *s) {
568
SetDirName(s->getstr());
571
void EditWindow::SetModified(bool set) {
573
XtVaSetValues(modifiedToggle, XmNset, set, 0);
576
void EditWindow::AboutCB(Widget w, XtPointer, XtPointer) {
577
MessageDialog *t = new MessageDialog(w, MessageDialog::MESSAGE);
578
t->Show("About TCM", Version::ABOUT_TEXT);
581
void EditWindow::SetDocumentLevel(const char *s) {
583
XtVaSetValues(documentLevel, XmNvalue, s,
584
XmNcolumns, strlen(s)+1, 0);
587
void EditWindow::SetDocumentLevel(const string *s) {
588
SetDocumentLevel(s->getstr());
591
void EditWindow::SetPageSubMenuItem(const char *text, int n) {
594
Widget item = pageMenu->GetMenuItem(text);
596
Menu::SetNthChildToggleState(
597
item, Menu::PULLDOWN, n+1, True, True);
600
void EditWindow::SetPageMenuItem(const char *text, bool b) {
603
Menu::SetChildToggleState(pageMenu->GetWidget(),
604
Menu::PULLDOWN, text, b);