1
// $Id: test-graph.C,v 1.14 2001/04/26 11:08:07 zeller Exp $
4
// Copyright (C) 1995 Technische Universitaet Braunschweig, Germany.
5
// Written by Andreas Zeller <zeller@gnu.org>.
7
// This file is part of DDD.
9
// DDD is free software; you can redistribute it and/or
10
// modify it under the terms of the GNU General Public
11
// License as published by the Free Software Foundation; either
12
// version 2 of the License, or (at your option) any later version.
14
// DDD is distributed in the hope that it will be useful,
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
// See the GNU General Public License for more details.
19
// You should have received a copy of the GNU General Public
20
// License along with DDD -- see the file COPYING.
21
// If not, write to the Free Software Foundation, Inc.,
22
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
// DDD is the data display debugger.
25
// For details, see the DDD World-Wide-Web page,
26
// `http://www.gnu.org/software/ddd/',
27
// or send a mail to the DDD developers <ddd@gnu.org>.
29
char test_graph_rcsid[] =
30
"$Id: test-graph.C,v 1.14 2001/04/26 11:08:07 zeller Exp $";
38
#include <Xm/ScrolledW.h>
39
#include <Xm/RowColumn.h>
40
#include <X11/Shell.h>
41
#include "ScrolledGE.h"
43
#include "GraphEdit.h"
45
#include "converters.h"
49
#include "StringBox.h"
53
#include "BoxGraphN.h"
54
#include "HintGraphN.h"
55
#include "ArcGraphE.h"
59
#define EXIT_SUCCESS 0
63
#define EXIT_FAILURE 1
66
// Build a simple graph
69
MarkBox *hugo = new MarkBox(new StringBox("Select"));
70
Box *berta = new StringBox("Me");
71
HAlignBox *hbox = new HAlignBox();
75
GraphNode *n0 = new BoxGraphNode(hbox, BoxPoint(50, 50), hugo);
78
new HintGraphNode(BoxPoint(65, 65));
80
new BoxGraphNode(new StringBox("30, 30"), BoxPoint(30, 30));
82
new BoxGraphNode(new StringBox("100, 30"), BoxPoint(100, 30));
84
new BoxGraphNode(new StringBox("30, 100"), BoxPoint(30, 100));
86
new BoxGraphNode(new StringBox("100, 100"), BoxPoint(100, 100));
88
new BoxGraphNode(new StringBox("100, 100 a"), BoxPoint(100, 100));
90
new HintGraphNode(BoxPoint(100, 50));
92
new BoxGraphNode(new StringBox("100, 100 b"), BoxPoint(100, 100));
94
BoxEdgeAnnotation *a1 = new BoxEdgeAnnotation(new StringBox("a1"));
95
BoxEdgeAnnotation *a2 = new BoxEdgeAnnotation(new StringBox("a2"));
97
n2->selected() = True;
129
*g += new LineGraphEdge(n0, n0);
132
*g += new LineGraphEdge(n1, n2);
135
*g += new LineGraphEdge(n1, n3);
138
*g += new LineGraphEdge(n1, n4);
141
*g += new LineGraphEdge(n1, n5);
144
*g += new LineGraphEdge(n2, n3);
147
*g += new LineGraphEdge(n2, n4);
150
*g += new LineGraphEdge(n2, n5);
153
*g += new LineGraphEdge(n3, n4);
156
*g += new LineGraphEdge(n3, n5);
159
*g += new LineGraphEdge(n4, n5, a1);
162
GraphEdge *e67 = new ArcGraphEdge(n6, n7);
166
GraphEdge *e78 = new ArcGraphEdge(n7, n8, a2);
170
GraphEdge *e56 = new LineGraphEdge(n5, n6);
174
Graph *g2 = g->dup();
181
static String fallback_resources[] = {
182
"*allowShellResize: True",
186
void PositionChanged(Widget, XtPointer, XtPointer call_data)
188
GraphEditPositionChangedInfo *info =
189
(GraphEditPositionChangedInfo *)call_data;
191
clog << "Moving node " << *info->node << " from " <<
192
info->old_position << " to " << info->new_position;
202
static void OneCB(Widget widget, XtPointer, XtPointer)
204
cout << longName(widget) << "\n";
207
static void TwoCB(Widget widget, XtPointer, XtPointer)
209
cout << longName(widget) << "\n";
212
static void ThreeCB(Widget widget, XtPointer, XtPointer)
214
cout << longName(widget) << "\n";
217
static MMDesc simpleMenu[] =
221
{ "one", MMPush, { OneCB } },
222
{ "two", MMPush, { TwoCB } },
223
{ "three", MMPush, { ThreeCB } },
227
void Popup(Widget w, XEvent *event, String *, Cardinal *)
229
if (event->type != ButtonPress && event->type != ButtonRelease)
231
cerr << "popup(): may only be used with button events\n";
235
static Widget popup = 0;
239
popup = MMcreatePopupMenu(w, "popup", simpleMenu);
240
MMaddCallbacks(simpleMenu);
243
XmMenuPosition(popup, &event->xbutton);
244
XtManageChild(popup);
247
XtActionsRec actions[] = {
252
int main(int argc, char *argv[])
256
XtAppContext app_context;
259
Widget toplevel = XtAppInitialize(&app_context, "Test-graph",
260
XtPointer(0), 0, &argc, argv, fallback_resources, XtPointer(0), 0);
262
// register additional converters...
263
registerOwnConverters();
265
// register own actions...
266
XtAppAddActions(app_context, actions, XtNumber(actions));
268
// Build the font table...
269
StringBox::fontTable = new FontTable(XtDisplay(toplevel));
271
// Build a graph editor
272
Graph *graph = myGraph();
274
XtSetArg(args[arg], XtNgraph, graph); arg++;
275
Widget editor = createPannedGraphEdit(toplevel, "graphEdit",
277
XtManageChild(editor);
279
XtAddCallback(editor, XtNpositionChangedCallback,
280
PositionChanged, XtPointer(0));
282
XtRealizeWidget(toplevel);
283
XtAppMainLoop(app_context);