Debian Codegraph @

demos/unsupported/dogs/dogs.c

raw
1 /*
2 * Motif
3 *
4 * Copyright (c) 1987-2012, The Open Group. All rights reserved.
5 *
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
10 * any later version.
11 *
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
16 * details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
22 */
23 /*
24 * HISTORY
25 */
26 #ifdef REV_INFO
27 #ifndef lint
28 static char rcsid[] = "$XConsortium: dogs.c /main/5 1995/07/14 10:07:19 drk $"
29 #endif
30 #endif
31
32 /*****************************************************************************
33 *
34 * dogs.c - Square & Dog widget demo source file.
35 *
36 ******************************************************************************/
37
38 #include <stdio.h>
39 #include <stdlib.h>
40 #include <Xm/Xm.h>
41 #include <Xm/MessageB.h>
42 #include <Mrm/MrmPublic.h>
43 #include "Square.h"
44 #include "Dog.h"
45
46 XtAppContext app_context;
47
48 #define k_dog1_id 1
49 #define k_dog2_id 2
50 #define k_dog3_id 3
51 #define k_help_id 4
52
53 static void create_cb();
54 static void bark_cb();
55 static void tb_cb();
56 static void scale_cb();
57 static void help_cb();
58 static void exit_cb();
59
60 static MrmHierarchy mrm_id;
61 static char *mrm_vec[]={"dogs.uid"};
62 static MrmCode mrm_class;
63 static MRMRegisterArg mrm_names[] = {
64 {"create_cb", (caddr_t)create_cb },
65 {"bark_cb", (caddr_t)bark_cb },
66 {"tb_cb", (caddr_t)tb_cb },
67 {"scale_cb", (caddr_t)scale_cb },
68 {"help_cb", (caddr_t)help_cb },
69 {"exit_cb", (caddr_t)exit_cb }
70 };
71
72 static Widget dog1_id;
73 static Widget dog2_id;
74 static Widget dog3_id;
75 static Widget help_id;
76
77 int main(argc, argv)
78 int argc;
79 char **argv;
80 {
81 Widget shell;
82 Display *display;
83 Widget app_main = NULL;
84 Arg args[3];
85
86 MrmInitialize ();
87 SquareMrmInitialize();
88 DogMrmInitialize();
89
90 XtToolkitInitialize();
91 app_context = XtCreateApplicationContext();
92 display = XtOpenDisplay(app_context, NULL, argv[0], "Dogs",
93 NULL, 0, &argc, argv);
94
95 if (display == NULL) {
96 fprintf(stderr, "%s: Can't open display\n", argv[0]);
97 exit(1);
98 }
99
100 XtSetArg (args[0], XtNallowShellResize, True);
101 XtSetArg (args[1], XtNminWidth, 620);
102 XtSetArg (args[2], XtNminHeight, 370);
103 shell = XtAppCreateShell(argv[0], NULL, applicationShellWidgetClass,
104 display, args, 3);
105
106 if (MrmOpenHierarchy (1, mrm_vec, NULL, &mrm_id) != MrmSUCCESS) exit(0);
107 MrmRegisterNames(mrm_names, XtNumber(mrm_names));
108 MrmFetchWidget (mrm_id, "app_main", shell, &app_main, &mrm_class);
109 XtManageChild(app_main);
110 XtRealizeWidget(shell);
111 XtAppMainLoop(app_context);
112
113 return 0; /* make compiler happy */
114 }
115
116 static void create_cb(w, id, reason)
117 Widget w;
118 int *id;
119 unsigned long *reason;
120 {
121 switch (*id) {
122 case k_dog1_id: dog1_id = w; break;
123 case k_dog2_id: dog2_id = w; break;
124 case k_dog3_id: dog3_id = w; break;
125 case k_help_id:
126 help_id = w;
127 XtUnmanageChild((Widget)XmMessageBoxGetChild(help_id,
128 XmDIALOG_CANCEL_BUTTON));
129 XtUnmanageChild((Widget)XmMessageBoxGetChild(help_id,
130 XmDIALOG_HELP_BUTTON));
131 break;
132 }
133 }
134
135 static void bark_cb (w, volume, cb)
136 Widget w;
137 int *volume;
138 XtPointer cb;
139 {
140 XBell(XtDisplay(w), *volume);
141 }
142
143 static void tb_cb (w, tag, cb)
144 Widget w;
145 int *tag;
146 XmToggleButtonCallbackStruct *cb;
147 {
148 Arg args[1];
149 Widget dog=NULL;
150
151 switch (*tag) {
152 case(1) : dog = dog1_id; break;
153 case(2) : dog = dog2_id; break;
154 case(3) : dog = dog3_id; break;
155 }
156 XtSetArg(args[0], SquareNmakeSquare, cb->set);
157 XtSetValues(dog, args, 1);
158 }
159
160 static void scale_cb(w, tag, cb)
161 Widget w;
162 int *tag;
163 XmScaleCallbackStruct *cb;
164 {
165 Arg args[1];
166 Widget dog = NULL;
167
168 switch (*tag) {
169 case(1) : dog = dog1_id; break;
170 case(2) : dog = dog2_id; break;
171 case(3) : dog = dog3_id; break;
172 }
173 XtSetArg(args[0], DogNwagTime, cb->value);
174 XtSetValues(dog, args, 1);
175 }
176
177 static void help_cb (w, name, cb)
178 Widget w;
179 XmString name;
180 XtPointer cb;
181 {
182 Arg args[1];
183
184 if (name == NULL) return;
185 XtSetArg (args[0], XmNmessageString, name);
186 XtSetValues(help_id, args, 1);
187 XtManageChild(help_id);
188 }
189
190 static void exit_cb (w, name, cb)
191 Widget w;
192 XmString name;
193 XtPointer cb;
194 {
195 exit(0);
196 }
197