2
* Copyright 1994, Integrated Computer Solutions, Inc.
10
* Almost a direct copy of the tree.c demo code
14
/**************************************************************
16
**************************************************************/
20
#include <X11/Intrinsic.h>
23
#include <Xm/Outline.h>
24
#include <Xm/Hierarchy.h>
25
#include <Xm/IconButton.h>
28
#include <Xm/BulletinB.h>
29
#include <Xm/MessageB.h>
30
#include <Xm/RowColumn.h>
32
#include <Xm/Separator.h>
33
#include <Xm/ToggleB.h>
35
#include <Xm/PanedW.h>
36
#include <Xm/ScrolledW.h>
39
/**************************************************************
40
* STATIC FUNCTION DECLARATIONS
41
**************************************************************/
42
static Widget CreateNode(Widget, Widget, char *, XmHierarchyNodeState);
43
static void BuildHierarchy(Widget, WidgetClass);
44
static void WriteUpHype(Widget);
45
static void MakeControlPanel(Widget);
46
static void ShowCB(Widget, XtPointer, XtPointer);
47
static void ExplainCB(Widget, XtPointer, XtPointer);
48
static void CallbackTogCB(Widget, XtPointer, XtPointer);
49
static void QuitCB(Widget, XtPointer, XtPointer);
50
void InitializePanel(Widget);
52
/**************************************************************
54
**************************************************************/
55
static Widget G_outline = NULL;
58
/**************************************************************
60
**************************************************************/
62
BuildHierarchy(Widget parent)\n\
64
Widget outline, hierarchy, w1, w2, w3;\n\
66
outline = XtCreateManagedWidget(\"outline_widget\", xmOutlineWidgetClass,\n\
67
parent, NULL, (Cardinal) 0);\n\
69
w1 = CreateNode(outline, NULL, \"Widgets\", XmOpen);\n\
71
w2 = CreateNode(outline, w1, \"Writing Widgets\", XmOpen);\n\
73
(void) CreateNode(outline, w2, \"Widget Data Structures\", XmAlwaysOpen);\n\
74
(void) CreateNode(outline, w2, \"Structure Naming Conventions\", XmAlwaysOpen);\n\
75
w3 = CreateNode(outline, w2, \"Writing Header Files\", XmOpen);\n\
78
(void) CreateNode(outline, w3, \"Writing Private Header Files\", XmAlwaysOpen);\n\
79
(void) CreateNode(outline, w3, \"Writing Public Header Files\", XmAlwaysOpen);\n\
80
(void) CreateNode(outline, w3, \"Internal Header Files\", XmAlwaysOpen);\n\
82
w3 = CreateNode(outline, w2, \"The Base Widget Classes\", XmOpen);\n\
83
(void) CreateNode(outline, w3, \"The Core Class Structure\", XmAlwaysOpen);\n\
84
(void) CreateNode(outline, w3, \"The Core Instance Structure\", XmAlwaysOpen);\n\
85
(void) CreateNode(outline, w3, \"The Composite Class Structure\", XmAlwaysOpen);\n\
86
(void) CreateNode(outline, w3, \"The Composite Instance Structure\", XmAlwaysOpen);\n\
87
(void) CreateNode(outline, w3, \"The Constraint Class Structure\", XmAlwaysOpen);\n\
88
(void) CreateNode(outline, w3, \"The Constraint Instance Structure\", XmAlwaysOpen);\n\
92
CreateNode(Widget w_parent, Widget parent_node, char * name, \n\
93
XmHierarchyNodeState state)\n\
100
xmstring = XmStringCreateSimple(name);\n\
103
XtSetArg(args[num_args], XmNlabelString, xmstring); num_args++;\n\
104
XtSetArg(args[num_args], XmNnodeState, state); num_args++;\n\
105
XtSetArg(args[num_args], XmNparentNode, parent_node); num_args++;\n\
107
w = XtCreateManagedWidget(name, xmPushButtonWidgetClass,\n\
108
w_parent, args, num_args);\n\
110
XmStringFree(xmstring);\n\
114
/**************************************************************
116
**************************************************************/
117
static String fallbacks[] = {
118
"*fontList: -*-helvetica-medium-r-*-*-*-140-*-*-*-*-*-*",
119
"*hypelabel*fontList: -*-helvetica-bold-r-*-*-*-140-*-*-*-*-*-*",
120
"*show_code*fontList: -*-courier-*-r-normal-*-*-*-*-*-*-*-*-*",
121
"*show_pb.labelString: Show Layout Code...",
122
"*explain_pb.labelString: Other Resources...",
123
"*rc_1*XmSeparator*orientation: XmVERTICAL",
124
"*ladder_tog.labelString: Connect Style:",
125
"*callback_tog.labelString: Node State Callback:",
126
"*autoclose_tog.labelString: Auto Close",
127
"*connect_tog.labelString: Connect Nodes",
128
"*quit_pb.labelString: Quit",
133
* Function Name: InitializePanel
134
* Description: Checks the resources at start up and sets their
135
* labels and toggles appropriately
136
* Arguments: pane - area containing the buttons and toggles
141
InitializePanel(Widget pane)
148
XtCallbackStatus status;
149
Widget lab_temp, tog_temp;
152
XtSetArg(args[argcnt], XmNautoClose, &auto_close); argcnt++;
153
XtSetArg(args[argcnt], XmNconnectNodes, &connect); argcnt++;
154
XtGetValues(G_outline, args, argcnt);
157
* Initialize Node State Callback Toggle and Label
159
lab_temp = XtNameToWidget(pane, "*callback_lab");
160
if (lab_temp == NULL) {
161
fprintf(stderr, "InitializePane: cannot find callback_lab\n");
164
tog_temp = XtNameToWidget(pane, "*callback_tog");
165
if (tog_temp == NULL) {
166
fprintf(stderr, "InitializePane: cannot find callback_tog\n");
170
status = XtHasCallbacks(G_outline, XmNnodeStateCallback);
172
case XtCallbackHasSome:
173
XmToggleButtonSetState(tog_temp, True, False);
174
xmstring = XmStringCreateSimple("Added");
176
case XtCallbackNoList:
177
case XtCallbackHasNone:
179
XmToggleButtonSetState(tog_temp, False, False);
180
xmstring = XmStringCreateSimple("Not Added");
184
XtSetArg(args[argcnt], XmNlabelString, xmstring); argcnt++;
185
XtSetValues(lab_temp, args, argcnt);
186
XmStringFree(xmstring);
189
* Initialize Auto Close Toggle
191
tog_temp = XtNameToWidget(pane, "*autoclose_tog");
192
if (tog_temp == NULL) {
193
fprintf(stderr, "InitializePane: cannot find autoclose_tog\n");
196
XmToggleButtonSetState(tog_temp, auto_close, False);
198
tog_temp = XtNameToWidget(pane, "*connect_tog");
199
if (tog_temp == NULL) {
200
fprintf(stderr, "InitializePane: cannot find connecct_tog\n");
203
XmToggleButtonSetState(tog_temp, connect, False);
207
* Function Name: main
209
* Arguments: the usual suspects
214
main(int argc, char **argv)
219
XtAppContext app_con;
222
XtSetArg(args[num_args], XmNtitle, "Outline Demo"); num_args++;
223
XtSetArg(args[num_args], XmNallowShellResize, True); num_args++;
224
top = XtAppInitialize(&app_con, "Treedemo",
225
NULL, 0, &argc, argv,
226
fallbacks, args, num_args);
231
pane = XtCreateManagedWidget("pane", xmPanedWindowWidgetClass,
232
top, args, num_args);
236
XtSetArg(args[num_args], XmNscrollingPolicy, XmAUTOMATIC); num_args++;
237
XtSetArg(args[num_args], XmNheight, 500); num_args++;
238
sw = XtCreateManagedWidget("pane", xmScrolledWindowWidgetClass,
239
pane, args, num_args);
241
BuildHierarchy(sw, xmOutlineWidgetClass);
242
MakeControlPanel(pane);
244
InitializePanel(pane);
248
XtRealizeWidget(top);
250
/* Process events, unwrapping correctly. */
254
XtAppNextEvent(app_con, &event);
255
XtDispatchEvent(&event);
257
XtDestroyWidget(top);
258
XtDestroyApplicationContext(app_con);
262
/**************************************************************
264
**************************************************************/
266
* Function Name: BuildHierarchy
273
BuildHierarchy(Widget parent, WidgetClass class)
275
Widget outline, hierarchy, w1, w2, w3;
277
G_outline = outline = XtCreateManagedWidget("outline_widget", class,
278
parent, NULL, (Cardinal) 0);
280
w1 = CreateNode(outline, NULL, "Widgets", XmOpen);
282
w2 = CreateNode(outline, w1, "Writing Widgets", XmOpen);
284
(void) CreateNode(outline, w2, "Widget Data Structures", XmAlwaysOpen);
285
(void) CreateNode(outline, w2, "Structure Naming Conventions", XmAlwaysOpen);
286
w3 = CreateNode(outline, w2, "Writing Header Files", XmOpen);
289
(void) CreateNode(outline, w3, "Writing Private Header Files", XmAlwaysOpen);
290
(void) CreateNode(outline, w3, "Writing Public Header Files", XmAlwaysOpen);
291
(void) CreateNode(outline, w3, "Internal Header Files", XmAlwaysOpen);
293
w3 = CreateNode(outline, w2, "The Base Widget Classes", XmOpen);
294
(void) CreateNode(outline, w3, "The Core Class Structure", XmAlwaysOpen);
295
(void) CreateNode(outline, w3, "The Core Instance Structure", XmAlwaysOpen);
296
(void) CreateNode(outline, w3, "The Composite Class Structure", XmAlwaysOpen);
297
(void) CreateNode(outline, w3, "The Composite Instance Structure", XmAlwaysOpen);
298
(void) CreateNode(outline, w3, "The Constraint Class Structure", XmAlwaysOpen);
299
(void) CreateNode(outline, w3, "The Constraint Instance Structure", XmAlwaysOpen);
302
static void NewChildCB(Widget w, XtPointer client, XtPointer call)
304
static int count = 0;
306
sprintf (buffer, "New Child %d", count++);
307
CreateNode((Widget)client, w, buffer, XmAlwaysOpen);
311
* Function Name: CreateNode
318
CreateNode(Widget w_parent, Widget parent_node, char * name,
319
XmHierarchyNodeState state)
326
xmstring = XmStringCreateSimple(name);
329
XtSetArg(args[num_args], XmNlabelString, xmstring); num_args++;
330
XtSetArg(args[num_args], XmNnodeState, state); num_args++;
331
XtSetArg(args[num_args], XmNparentNode, parent_node); num_args++;
333
w = XtCreateManagedWidget(name, xmPushButtonWidgetClass,
334
w_parent, args, num_args);
336
XtAddCallback(w,XmNactivateCallback,NewChildCB,w_parent);
338
XmStringFree(xmstring);
343
* Function Name: WriteUpHype
344
* Description: Prints up the "Hype" message in a label
345
* Arguments: the usual suspects
349
void WriteUpHype(Widget parent)
356
xmstring = XmStringCreateLtoR(
357
"The OpenMotif Outline Widget displays hierarchical data in an outline layout with a Motif\n\
358
look and feel. The Outline widget displayed below has several Motif PushButtons (the\n\
359
Outline can accept any type of widget); press one to add a new child.\n\
361
The Outline Widget uses \"constraints\" to arrange the children with the right layout.\n\
362
To see the code to generate the tree below, press \"Show Layout Code...\".\n\
364
The toggles below set different resources on the Outline widget itself.\n\
366
Press \"Other Resources...\" for more information on the various resources.",
367
XmSTRING_DEFAULT_CHARSET);
370
XtSetArg(args[argcnt], XmNmarginHeight, 10); argcnt++;
371
XtSetArg(args[argcnt], XmNmarginWidth, 10); argcnt++;
372
XtSetArg(args[argcnt], XmNalignment, XmALIGNMENT_BEGINNING); argcnt++;
373
XtSetArg(args[argcnt], XmNlabelString, xmstring); argcnt++;
374
w = XtCreateManagedWidget("hypelabel", xmLabelWidgetClass,
375
parent, args, argcnt);
377
XmStringFree(xmstring);
382
* Function Name: ShowCB
384
* Arguments: This is an XtCallback
387
static void ShowCB(Widget w, XtPointer client, XtPointer call)
389
static Widget info = NULL;
395
XmString ok_xmstring;
397
ok_xmstring = XmStringCreateSimple("OK");
400
XtSetArg(args[argcnt], XmNtitle, "Show Code..."); argcnt++;
401
/* XtSetArg(args[argcnt], XmNmessageString, xmstring); argcnt++; */
402
XtSetArg(args[argcnt], XmNokLabelString, ok_xmstring); argcnt++;
403
XtSetArg(args[argcnt], XmNallowShellResize, True); argcnt++;
404
info = XmCreateTemplateDialog(G_outline, "show_code", args, argcnt);
407
XtSetArg(args[argcnt], XmNcolumns, 60); argcnt++;
408
XtSetArg(args[argcnt], XmNrows, 20); argcnt++;
409
XtSetArg(args[argcnt], XmNvalue, CODE); argcnt++;
410
XtSetArg(args[argcnt], XmNeditable, False); argcnt++;
411
XtSetArg(args[argcnt], XmNeditMode, XmMULTI_LINE_EDIT); argcnt++;
412
temp = XmCreateScrolledText(info, "show_text", args, argcnt);
415
XmStringFree(ok_xmstring);
422
* Function Name: ExplainCB
424
* Arguments: This is an XtCallback
427
static void ExplainCB(Widget w, XtPointer client, XtPointer call)
429
static Widget info = NULL;
437
xmstring = XmStringCreateLtoR(
438
"The OpenMotif Tree and Outline widget actually derive behavior from the\n\
439
Hierarchy Widget. The Hierarchy widget provides resources that specify\n\
440
the relationships between children.\n\
442
XmNautoClose specifies whether the Tree or Outline automatically closes\n\
443
any nodes if a parent node is closed. To see the behavior, press the Auto\n\
444
Close toggle, then close and reopen the Core.\n\
446
XmNnodeState is a constraint resource on a child of the Tree or Outline.\n\
447
It determines whether a node is Open, Closed, Hidden, or Always Visible.\n\
448
Use \"Show Layout Code...\" to see how this demo used this resource.\n\
450
XmNparentNode specifies this node's parent. This resource determines the\n\
451
node's logical parent (the widget instance tree says the node is a child of\n\
452
the Tree or Outline, but the parentNode will specify where on the layout\n\
453
the node will appear. Use \"Show Layout Code...\" to see how this demo used\n\
456
XmNnodeStateCallback provides a way to receive feedback when any node is\n\
457
opened or closed. To use this callback, press the Node State Callback toggle.",
458
XmSTRING_DEFAULT_CHARSET);
461
XtSetArg(args[argcnt], XmNtitle, "Explanation"); argcnt++;
462
XtSetArg(args[argcnt], XmNmessageString, xmstring); argcnt++;
463
info = XmCreateInformationDialog(G_outline, "explain", args, argcnt);
465
temp = XmMessageBoxGetChild(info, XmDIALOG_CANCEL_BUTTON);
466
XtUnmanageChild(temp);
467
temp = XmMessageBoxGetChild(info, XmDIALOG_HELP_BUTTON);
468
XtUnmanageChild(temp);
469
XmStringFree(xmstring);
476
* Function Name: NodeStateCB
478
* Arguments: This is an XtCallback
481
void NodeStateCB(Widget w, XtPointer client, XtPointer call)
486
XmHierarchyNodeStateData *node_data = (XmHierarchyNodeStateData *) call;
492
XtSetArg(args[argcnt], XmNlabelString, &xmstring); argcnt++;
493
XtGetValues(node_data->widget, args, argcnt);
495
XmStringGetLtoR(xmstring, XmFONTLIST_DEFAULT_TAG, &name);
497
if (node_data->state == XmOpen)
498
sprintf(buf, "%s has switched to the XmOpen state.", name);
499
else if (node_data->state == XmClosed)
500
sprintf(buf, "%s has switched to the XmClosed state.", name);
501
else if (node_data->state == XmAlwaysOpen)
502
sprintf(buf, "%s has switched to the XmAlwaysOpen state.", name);
503
else if (node_data->state == XmHidden)
504
sprintf(buf, "%s has switched to the XmHidden state.", name);
506
sprintf(buf, "%s has switched node state.", name);
508
xmstring = XmStringCreateSimple(buf);
511
XtSetArg(args[argcnt], XmNtitle, "Node State Changed"); argcnt++;
512
XtSetArg(args[argcnt], XmNmessageString, xmstring); argcnt++;
513
info = XmCreateInformationDialog(w, "nodechange", args, argcnt);
515
temp = XmMessageBoxGetChild(info, XmDIALOG_CANCEL_BUTTON);
516
XtUnmanageChild(temp);
517
temp = XmMessageBoxGetChild(info, XmDIALOG_HELP_BUTTON);
518
XtUnmanageChild(temp);
520
XmStringFree(xmstring);
527
* Function Name: CallbackTogCB
529
* Arguments: This is an XtCallback
532
static void CallbackTogCB(Widget w, XtPointer client, XtPointer call)
536
Widget lab = (Widget) client;
539
if (XmToggleButtonGetState(w)) {
540
XtAddCallback(G_outline, XmNnodeStateCallback, NodeStateCB, NULL);
541
xmstring = XmStringCreateSimple("Added");
543
XtRemoveAllCallbacks(G_outline, XmNnodeStateCallback);
544
xmstring = XmStringCreateSimple("Not Added");
548
XtSetArg(args[argcnt], XmNlabelString, xmstring); argcnt++;
549
XtSetValues(lab, args, argcnt);
550
XmStringFree(xmstring);
554
* Function Name: AutoCloseTogCB
556
* Arguments: This is an XtCallback
559
static void AutoCloseTogCB(Widget w, XtPointer client, XtPointer call)
561
XtVaSetValues(G_outline, XmNautoClose, XmToggleButtonGetState(w), NULL);
564
static void ConnectTogCB(Widget w, XtPointer client, XtPointer call)
566
XtVaSetValues(G_outline, XmNconnectNodes, XmToggleButtonGetState(w), NULL);
571
* Function Name: QuitCB
572
* Description: Exits the program
573
* Arguments: This is an XtCallback
577
QuitCB(Widget w, XtPointer client, XtPointer call)
583
* Function Name: MakeControlPanel
584
* Description: Prints up the "Hype" message in a label
585
* Arguments: the usual suspects
589
void MakeControlPanel(Widget parent)
593
Widget big_rc, rc_1, rc_2, show_pb, explain_pb, ladder_tog, ladder_lab,
594
callback_tog, callback_lab, quit_pb, autoclose_tog, sep, connect_tog;
596
/* Big Vertical Row Column for the control panel */
598
XtSetArg(args[argcnt], XmNorientation, XmVERTICAL); argcnt++;
599
XtSetArg(args[argcnt], XmNpacking, XmPACK_TIGHT); argcnt++;
600
big_rc = XtCreateManagedWidget("big_rc", xmRowColumnWidgetClass,
601
parent, args, argcnt);
605
XtSetArg(args[argcnt], XmNorientation, XmHORIZONTAL); argcnt++;
606
XtSetArg(args[argcnt], XmNpacking, XmPACK_TIGHT); argcnt++;
607
rc_1 = XtCreateManagedWidget("rc_1", xmRowColumnWidgetClass,
608
big_rc, args, argcnt);
611
callback_tog = XtCreateManagedWidget("callback_tog",
612
xmToggleButtonWidgetClass,
615
callback_lab = XtCreateManagedWidget("callback_lab", xmLabelWidgetClass,
617
XtAddCallback(callback_tog, XmNvalueChangedCallback,
618
CallbackTogCB, (XtPointer) callback_lab);
621
sep = XtCreateManagedWidget("sep_two", xmSeparatorWidgetClass,
625
autoclose_tog = XtCreateManagedWidget("autoclose_tog",
626
xmToggleButtonWidgetClass,
628
XtAddCallback(autoclose_tog, XmNvalueChangedCallback,
629
AutoCloseTogCB, NULL);
632
sep = XtCreateManagedWidget("sep_two", xmSeparatorWidgetClass,
636
connect_tog = XtCreateManagedWidget("connect_tog",
637
xmToggleButtonWidgetClass,
639
XtAddCallback(connect_tog, XmNvalueChangedCallback,
645
XtSetArg(args[argcnt], XmNorientation, XmHORIZONTAL); argcnt++;
646
XtSetArg(args[argcnt], XmNpacking, XmPACK_TIGHT); argcnt++;
647
rc_2 = XtCreateManagedWidget("rc_2", xmRowColumnWidgetClass,
648
big_rc, args, argcnt);
651
show_pb = XtCreateManagedWidget("show_pb", xmPushButtonWidgetClass,
653
XtAddCallback(show_pb, XmNactivateCallback, ShowCB, NULL);
656
explain_pb = XtCreateManagedWidget("explain_pb", xmPushButtonWidgetClass,
658
XtAddCallback(explain_pb, XmNactivateCallback, ExplainCB, NULL);
661
quit_pb = XtCreateManagedWidget("quit_pb", xmPushButtonWidgetClass,
664
XtAddCallback(quit_pb, XmNactivateCallback, QuitCB, NULL);