Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / examples / motif / dogs / dogs.c
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-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  * (c) Copyright 1989, 1990, 1991, 1992 OPEN SOFTWARE FOUNDATION, INC. 
25  * ALL RIGHTS RESERVED 
26 */ 
27 /* 
28  * Motif Release 1.2
29 */ 
30 #ifdef REV_INFO
31 #ifndef lint
32 static char rcsid[] = "$XConsortium: dogs.c /main/3 1995/10/27 10:43:03 rswiston $"
33 #endif
34 #endif
35
36 /*****************************************************************************
37 *
38 *  dogs.c - Square & Dog widget demo source file.
39 *  
40 ******************************************************************************/
41
42 #include <stdio.h>
43 #include <Xm/Xm.h>
44 #include <Mrm/MrmPublic.h>
45 #include "Square.h"
46 #include "Dog.h"
47
48 XtAppContext  app_context;
49
50 #define k_dog1_id 1
51 #define k_dog2_id 2
52 #define k_dog3_id 3
53 #define k_help_id 4
54
55 static void create_cb();
56 static void bark_cb();
57 static void tb_cb();
58 static void scale_cb();
59 static void help_cb();
60 static void exit_cb();
61
62 static MrmHierarchy mrm_id = 0;
63 static char *mrm_vec[]={"dogs.uid", NULL};
64 static MrmCode mrm_class;
65 static MRMRegisterArg mrm_names[] = {
66         {"create_cb", (XtPointer)create_cb },
67         {"bark_cb", (XtPointer)bark_cb },
68         {"tb_cb", (XtPointer)tb_cb },
69         {"scale_cb", (XtPointer)scale_cb },
70         {"help_cb", (XtPointer)help_cb },
71         {"exit_cb", (XtPointer)exit_cb }
72 };
73
74 static Widget dog1_id;
75 static Widget dog2_id;
76 static Widget dog3_id;
77 static Widget help_id;
78
79 main(argc, argv)
80     int argc;
81     char **argv;
82 {
83     Widget shell;
84     Display *display;
85     Widget app_main = NULL;
86     Arg args[3];
87
88     MrmInitialize ();
89     SquareMrmInitialize();
90     DogMrmInitialize();
91
92     XtToolkitInitialize();
93     app_context = XtCreateApplicationContext();
94     display = XtOpenDisplay(app_context, NULL, argv[0], "Dogs",
95                         NULL, 0, &argc, argv);
96     
97     if (display == NULL) {
98             fprintf(stderr, "%s:  Can't open display\n", argv[0]);
99             exit(1);
100     }
101
102     XtSetArg (args[0], XtNallowShellResize, True);
103     XtSetArg (args[1], XtNminWidth, 620);
104     XtSetArg (args[2], XtNminHeight, 370);
105     shell = XtAppCreateShell(argv[0], NULL, applicationShellWidgetClass,
106                           display, args, 3);
107
108     if (MrmOpenHierarchy(1, mrm_vec, NULL, &mrm_id) != MrmSUCCESS) exit(0);
109     MrmRegisterNames(mrm_names, XtNumber(mrm_names));
110     MrmFetchWidget (mrm_id, "app_main", shell, &app_main, &mrm_class);
111
112     XtManageChild(app_main);
113     XtRealizeWidget(shell);
114     XtAppMainLoop(app_context);
115 }
116
117 static void create_cb(w, id, reason)
118     Widget w;
119     int *id;
120     unsigned long *reason;
121 {
122     switch (*id) {
123         case k_dog1_id: dog1_id = w; break;
124         case k_dog2_id: dog2_id = w; break;
125         case k_dog3_id: dog3_id = w; break;
126         case k_help_id:
127             help_id = w;
128             XtUnmanageChild((Widget)XmMessageBoxGetChild(help_id,
129                                 XmDIALOG_CANCEL_BUTTON));
130             XtUnmanageChild((Widget)XmMessageBoxGetChild(help_id,
131                                 XmDIALOG_HELP_BUTTON));
132             break;
133     }
134 }
135
136 static void bark_cb (w, volume, cb)
137     Widget w;
138     int *volume;
139     XtPointer cb;
140 {
141     XBell(XtDisplay(w), *volume);
142 }
143
144 static void tb_cb (w, tag, cb)
145     Widget w;
146     int *tag;
147     XmToggleButtonCallbackStruct *cb;
148 {
149     Arg args[1];
150     Widget dog;
151
152     switch (*tag) {
153         case(1) : dog = dog1_id; break;
154         case(2) : dog = dog2_id; break; 
155         case(3) : dog = dog3_id; break; 
156     }
157     XtSetArg(args[0], SquareNmakeSquare, cb->set);
158     XtSetValues(dog, args, 1);
159 }
160
161 static void scale_cb(w, tag, cb)
162     Widget w;
163     int *tag;
164     XmScaleCallbackStruct *cb;
165 {
166     Arg args[1];
167     Widget dog;
168
169     switch (*tag) {
170         case(1) : dog = dog1_id; break;
171         case(2) : dog = dog2_id; break; 
172         case(3) : dog = dog3_id; break; 
173     }
174     XtSetArg(args[0], DogNwagTime, cb->value);
175     XtSetValues(dog, args, 1);
176 }
177
178 static void help_cb (w, name, cb)
179     Widget w;
180     XmString name;
181     XtPointer cb;
182 {
183     Arg args[1];
184
185     if (name == NULL) return;
186     XtSetArg (args[0], XmNmessageString, name);
187     XtSetValues(help_id, args, 1);
188     XtManageChild(help_id);
189 }
190
191 static void exit_cb (w, name, cb)
192     Widget w;
193     XmString name;
194     XtPointer cb;
195 {
196     exit(0);
197 }
198