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

« back to all changes in this revision

Viewing changes to src/sd/tr/trwindow.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 1996, 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 "trwindow.h"
 
23
#include "trdiagram.h"
 
24
#include "trviewer.h"
 
25
#include "trgraph.h"
 
26
#include "menu.h"
 
27
#include "mstring.h"
 
28
#include "liteclue.h"
 
29
#include <Xm/XmAll.h>
 
30
 
 
31
#include "TextNode.xbm"
 
32
#include "TextRoot.xbm"
 
33
#include "Comment.xbm"
 
34
#include "Line.xbm"
 
35
 
 
36
const char *TRWindow::TR_NODE_NAMES[] =  { "Text root", "Text node", "Comment"};
 
37
 
 
38
const Bitmap TRWindow::TR_NODE_ICONS [] = { 
 
39
        {TextRoot_width, TextRoot_height, TextRoot_bits},
 
40
        {TextNode_width, TextNode_height, TextNode_bits},
 
41
        {Comment_width, Comment_height, Comment_bits}};
 
42
 
 
43
const char *TRWindow::TR_EDGE_NAMES[] = {"Line"};
 
44
const Bitmap TRWindow::TR_EDGE_ICONS [] = {
 
45
        {Line_width, Line_height, Line_bits}};
 
46
 
 
47
TRWindow::TRWindow(const char *n): DiagramWindow(n) {}
 
48
 
 
49
DiagramViewer *TRWindow::CreateViewer(Config *cfg) {
 
50
        return new TRViewer(cfg, this);
 
51
}
 
52
 
 
53
Graph *TRWindow::CreateGraph() {
 
54
        return new TRGraph();
 
55
}
 
56
 
 
57
Diagram *TRWindow::CreateDiagram(Config *c, DiagramViewer *v, Graph *g) {
 
58
         return new TRDiagram(c, this, (TRViewer *)v, (TRGraph *)g);
 
59
}
 
60
 
 
61
void TRWindow::DetermineIcons() {
 
62
         nodeNames = TR_NODE_NAMES;
 
63
         nodeIcons = TR_NODE_ICONS;
 
64
         edgeNames = TR_EDGE_NAMES;
 
65
         edgeIcons = TR_EDGE_ICONS;
 
66
         nrNodes = XtNumber(TR_NODE_NAMES);
 
67
         nrEdges = XtNumber(TR_EDGE_NAMES);
 
68
}
 
69
 
 
70
Widget TRWindow::CreateMenuBar(Widget parent) {
 
71
        Widget bar = DiagramWindow::CreateMenuBar(parent);
 
72
        // make the duplicate item insensitive.
 
73
        Widget w1 = editMenu->GetMenuItem("Duplicate");
 
74
        if (w1)
 
75
                XtVaSetValues(w1, XmNsensitive, False, 0);
 
76
        return bar;
 
77
}
 
78
 
 
79
Widget TRWindow::CreateTiles(Widget parent) {
 
80
        Widget t = DiagramWindow::CreateTiles(parent);
 
81
        (void)CreateLayoutTiles(t);
 
82
        XtManageChild(t);
 
83
        return t;
 
84
}
 
85
 
 
86
Widget TRWindow::CreateLayoutTiles(Widget parent) {
 
87
        Arg args[9];
 
88
        int i = 0;
 
89
        // create a frame
 
90
        Widget frame = XtVaCreateManagedWidget("layout_tiles_frame1",
 
91
                xmFrameWidgetClass, parent,
 
92
                XmNshadowType, XmSHADOW_ETCHED_IN, 0);
 
93
        // create the label
 
94
        XtVaCreateManagedWidget("Layout",
 
95
                        xmLabelWidgetClass, frame,
 
96
                        XmNchildType, XmFRAME_TITLE_CHILD, 0);
 
97
        // create a rowcolumn
 
98
        Widget rc = XtVaCreateWidget("rc1", xmRowColumnWidgetClass, frame,
 
99
                XmNentryAlignment, XmALIGNMENT_CENTER, 0);
 
100
        // create a radiobox for the tiles
 
101
        XtSetArg(args[i], XmNradioAlwaysOne, True); i++;
 
102
        char wname[8] = "Layout";
 
103
        Widget rb = XmCreateRadioBox(rc, wname, args, i);
 
104
        // create all layout tiles
 
105
        XmString lb1, lb2;
 
106
        lb1 = CreateXmString("Editable\nGraph");
 
107
        lb2 = CreateXmString("Forked\nTree");
 
108
        editButton = XtVaCreateManagedWidget("EditableGraph",
 
109
                        xmToggleButtonWidgetClass, rb,
 
110
                        XmNset, True,
 
111
                        XmNhighlightThickness, 0,
 
112
                        XmNlabelType, XmSTRING,
 
113
                        XmNlabelString, lb1,
 
114
                        XmNuserData, (XtPointer)0,
 
115
                        XmNalignment, XmALIGNMENT_CENTER, 0);
 
116
        XtAddCallback(editButton, XmNvalueChangedCallback,
 
117
                        TRWindow::LayoutCB, (XtPointer)this);
 
118
        AddLiteClue(editButton, "Edit mode in which document is drawn as a graph");
 
119
        treeButton = XtVaCreateManagedWidget("ForkedTree",
 
120
                        xmToggleButtonWidgetClass, rb,
 
121
                        XmNset, False,
 
122
                        XmNlabelString, lb2,
 
123
                        XmNlabelType, XmSTRING,
 
124
                        XmNhighlightThickness, 0,
 
125
                        XmNuserData, (XtPointer)1,
 
126
                        XmNalignment, XmALIGNMENT_CENTER, 0);
 
127
        XtAddCallback(treeButton, XmNvalueChangedCallback,
 
128
                        TRWindow::LayoutCB, (XtPointer)this);
 
129
        AddLiteClue(treeButton, "View mode in which document has a forked tree layout");
 
130
        XtManageChild(rb);
 
131
        XtManageChild(rc);
 
132
        XmStringFree(lb1);
 
133
        XmStringFree(lb2);
 
134
        return frame;
 
135
}
 
136
 
 
137
void TRWindow::SetLayout(bool b) {
 
138
        TRViewer *v = (TRViewer *)GetDiagramViewer();
 
139
        if (!v->IsPasting() && !v->IsZigZag()) {
 
140
                SetStatus("action: set layout");
 
141
                v->UpdateTreeMode(b);
 
142
        }
 
143
        else if (b != v->IsTreeMode()) {
 
144
                SetStatus("I'm busy with something else");
 
145
                XmToggleButtonSetState(editButton, b, False);
 
146
                XmToggleButtonSetState(treeButton, !b, False);
 
147
        }
 
148
        SetSensitive(editMenu, "Cut", !b);
 
149
        SetSensitive(editMenu, "Copy", !b);
 
150
        SetSensitive(editMenu, "Paste", !b);
 
151
        SetSensitive(editMenu, "Delete", !b);
 
152
        SetSensitive(editMenu, "Delete All", !b);
 
153
        SetSensitive(editMenu, "Select All", !b);
 
154
        SetSensitive(editMenu, "Same Size", !b);
 
155
        SetSensitive(editMenu, "Align Nodes", !b);
 
156
        GetDrawingArea()->Enable("Cut", !b);
 
157
        GetDrawingArea()->Enable("Copy", !b);
 
158
        GetDrawingArea()->Enable("Paste", !b);
 
159
        GetDrawingArea()->Enable("Delete", !b);
 
160
        GetDrawingArea()->Enable("Delete All", !b);
 
161
        GetDrawingArea()->Enable("Select All", !b);
 
162
        GetDrawingArea()->Enable("Same Size", !b);
 
163
        GetDrawingArea()->Enable("Align Nodes", !b);
 
164
        SetSensitive(fileMenu, "Append", !b);
 
165
        SetSensitive(fileMenu, "Save Selection As", !b);
 
166
        SetSensitive(searchMenu, "Replace", !b);
 
167
        SetSensitive(propertiesMenu, "Node/Edge Annotation", !b);
 
168
        SetSensitive(propertiesMenu, "Update Text Font", !b);
 
169
        SetSensitive(propertiesMenu, "Update Line Width", !b);
 
170
        SetSensitive(propertiesMenu, "Update Line Style", !b);
 
171
        SetSensitive(propertiesMenu, "Update Line Ends", !b);
 
172
        SetSensitive(propertiesMenu, "Set/Unset Text Underlining", !b);
 
173
        SetSensitive(propertiesMenu, "Update Text Alignment", !b);
 
174
        SetSensitive(propertiesMenu, "Update Line Color", !b);
 
175
        SetSensitive(propertiesMenu, "Update Text Color", !b);
 
176
        SetSensitive(propertiesMenu, "Update Fill Color", !b);
 
177
}
 
178
 
 
179
void TRWindow::SetSensitive(Menu *menu, const char *label, bool b) {
 
180
        Widget w = menu->GetMenuItem(label);
 
181
        if (w)
 
182
                XtVaSetValues(w, XmNsensitive, b, 0);
 
183
}
 
184
 
 
185
void TRWindow::LayoutCB(Widget w, XtPointer cd, XtPointer) {
 
186
        if (XmToggleButtonGetState(w)) {
 
187
                int num;
 
188
                XtVaGetValues(w, XmNuserData, &num, 0);
 
189
                ((TRWindow *)cd)->SetLayout(num);
 
190
        }
 
191
}
 
192