5277c01094e24af530a99b780e4f182c6195916f
[openafs.git] / src / gtx / gtxtest.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #include <afsconfig.h>
11 #include <afs/param.h>
12
13 RCSID
14     ("$Header$");
15
16 #include <string.h>
17
18 #include "gtxwindows.h"
19 #include "gtxobjects.h"
20 #include "gtxtextobj.h"
21 #include "gtxlightobj.h"
22 #include "gtxkeymap.h"
23 #include "gtxframe.h"
24
25 struct gtx_frame *frameA, *frameB;
26
27 struct onode *objectA, *objectB;
28 struct onode *lightA, *lightB;
29
30 static int
31 ChangeMenuCmd(awin, arock)
32      afs_int32 arock;
33      register struct gwin *awin;
34 {
35     register struct gtx_frame *tf;
36     register afs_int32 code;
37
38     tf = awin->w_frame;
39     if (!tf)
40         return -1;
41
42     if (arock == 1) {
43         gtxframe_ClearMenus(tf);
44     } else if (arock == 2) {
45         code = gtxframe_DeleteMenu(tf, "NewLabel");
46         if (code)
47             gtxframe_DisplayString(tf, "Can't delete menu!");
48     } else if (arock == 3) {
49         code = gtxframe_ClearMenus(tf);
50         gtxframe_AddMenu(frameA, "FrameB", "b");
51         gtxframe_AddMenu(frameA, "NewLabel", "c");
52     }
53     return 0;
54 }
55
56 static int
57 ChangeListCmd(awin, arock)
58      afs_int32 arock;
59      register struct gwin *awin;
60 {
61     register struct gtx_frame *tf;
62     register afs_int32 code;
63
64     tf = awin->w_frame;
65     if (!tf)
66         return -1;
67
68     if (arock == 1) {
69         gtxframe_ClearList(tf);
70     } else if (arock == 2) {
71         code = gtxframe_RemoveFromList(tf, lightA);
72         if (code)
73             gtxframe_DisplayString(tf, "Can't delete light!");
74     } else if (arock == 3) {
75         code = gtxframe_ClearList(tf);
76         gtxframe_AddToList(frameA, objectA);
77         gtxframe_AddToList(frameA, lightA);
78     }
79     return 0;
80 }
81
82 static int
83 NoCallCmd(awin)
84      struct gwin *awin;
85 {
86     gtxframe_DisplayString(awin->w_frame,
87                            "Function should be mapped on '$d', not 'd'");
88     return 0;
89 }
90
91 static int
92 ChangeCmd(awin)
93      struct gwin *awin;
94 {
95     char tbuffer[100];
96     register afs_int32 code;
97
98     code =
99         gtxframe_AskForString(awin->w_frame, "New object string: ", "TestNew",
100                               tbuffer, sizeof(tbuffer));
101     if (code == 0) {
102         /* have new value, write it to object A */
103         gator_text_Write(objectA, tbuffer, 0, 0, 0);
104     }
105     return 0;
106 }
107
108 static int
109 StupidCmd(awin)
110      struct gwin *awin;
111 {
112     gtxframe_DisplayString(awin->w_frame,
113                            "You're already showing that frame!");
114     return 0;
115 }
116
117 static int
118 SwitchToACmd(awin)
119      struct gwin *awin;
120 {
121     gtxframe_SetFrame(awin, frameA);
122     return 0;
123 }
124
125 static int
126 SwitchToBCmd(awin)
127      struct gwin *awin;
128 {
129     gtxframe_SetFrame(awin, frameB);
130     return 0;
131 }
132
133 #include "AFS_component_version_number.c"
134
135 main()
136 {
137     struct gwin *win;
138     struct gator_textobj_params textcrparams;
139     struct gator_light_crparams lightcrparams;
140     register struct keymap_map *tmap;
141
142     win = gtx_Init(0, -1);
143
144     /* create a couple of objects, a and b, and have the "a" and "b" keys
145      * switch the display from one to the other */
146     textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT;
147     strcpy(textcrparams.onode_params.cr_name, "Text1-A");
148     textcrparams.onode_params.cr_x = 30;
149     textcrparams.onode_params.cr_y = 10;
150     textcrparams.onode_params.cr_width = 35;
151     textcrparams.onode_params.cr_height = 7;
152     textcrparams.onode_params.cr_window = win;  /* ???? */
153     textcrparams.onode_params.cr_home_obj = NULL;
154     textcrparams.onode_params.cr_prev_obj = NULL;
155     textcrparams.onode_params.cr_parent_obj = NULL;
156     textcrparams.onode_params.cr_helpstring = "Help string for text";
157     textcrparams.maxEntries = 7;
158     textcrparams.maxCharsPerEntry = 35;
159
160     objectA =
161         gator_objects_create((struct onode_createparams *)(&textcrparams));
162     gator_text_Write(objectA, "This is object A", 0, 0, 0);
163
164     /* create a couple of objects, a and b, and have the "a" and "b" keys
165      * switch the display from one to the other */
166     textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT;
167     strcpy(textcrparams.onode_params.cr_name, "Text2-B");
168     textcrparams.onode_params.cr_x = 30;
169     textcrparams.onode_params.cr_y = 10;
170     textcrparams.onode_params.cr_width = 35;
171     textcrparams.onode_params.cr_height = 7;
172     textcrparams.onode_params.cr_window = win;  /* ???? */
173     textcrparams.onode_params.cr_home_obj = NULL;
174     textcrparams.onode_params.cr_prev_obj = NULL;
175     textcrparams.onode_params.cr_parent_obj = NULL;
176     textcrparams.onode_params.cr_helpstring = "Help string for text";
177     textcrparams.maxEntries = 7;
178     textcrparams.maxCharsPerEntry = 35;
179
180     objectB =
181         gator_objects_create((struct onode_createparams *)(&textcrparams));
182     gator_text_Write(objectB, "This is object B", 0, 0, 0);
183
184     lightcrparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
185     lightcrparams.onode_params.cr_x = 10;
186     lightcrparams.onode_params.cr_y = 10;
187     lightcrparams.onode_params.cr_width = 10;
188     lightcrparams.onode_params.cr_height = 10;
189     lightcrparams.onode_params.cr_window = win; /* ???? */
190     lightcrparams.onode_params.cr_home_obj = NULL;
191     lightcrparams.onode_params.cr_prev_obj = NULL;
192     lightcrparams.onode_params.cr_parent_obj = NULL;
193     lightcrparams.onode_params.cr_helpstring = "Help string for text";
194     strcpy(lightcrparams.label, "Light-1");
195     lightcrparams.label_x = 0;
196     lightcrparams.label_y = 0;
197     lightcrparams.flashfreq = 100;
198     lightcrparams.appearance = GATOR_LIGHTMASK_INVVIDEO;
199     lightA =
200         gator_objects_create((struct onode_createparams *)(&lightcrparams));
201
202     /* create basic frames */
203     frameA = gtxframe_Create();
204     frameB = gtxframe_Create();
205
206     /* setup A's frame */
207     gtxframe_ClearList(frameA);
208     gtxframe_AddToList(frameA, objectA);
209     gtxframe_AddToList(frameA, lightA);
210     keymap_BindToString(frameA->keymap, "b", SwitchToBCmd, NULL, NULL);
211     keymap_BindToString(frameA->keymap, "a", StupidCmd, NULL, NULL);
212     keymap_BindToString(frameA->keymap, "c", ChangeCmd, NULL, NULL);
213     keymap_BindToString(frameA->keymap, "\033a", ChangeMenuCmd, "ChangeMenu",
214                         (char *)1);
215     keymap_BindToString(frameA->keymap, "\033b", ChangeMenuCmd, "ChangeMenu",
216                         (char *)2);
217     keymap_BindToString(frameA->keymap, "\033c", ChangeMenuCmd, "ChangeMenu",
218                         (char *)3);
219     keymap_BindToString(frameA->keymap, "\0331", ChangeListCmd, "ChangeList",
220                         (char *)1);
221     keymap_BindToString(frameA->keymap, "\0332", ChangeListCmd, "ChangeList",
222                         (char *)2);
223     keymap_BindToString(frameA->keymap, "\0333", ChangeListCmd, "ChangeList",
224                         (char *)3);
225     gtxframe_AddMenu(frameA, "FrameB", "b");
226     gtxframe_AddMenu(frameA, "NewLabel", "c");
227
228     /* setup B's frame */
229     gtxframe_ClearList(frameB);
230     gtxframe_AddToList(frameB, objectB);
231     keymap_BindToString(frameB->keymap, "a", SwitchToACmd, NULL, NULL);
232     keymap_BindToString(frameB->keymap, "b", StupidCmd, NULL, NULL);
233     keymap_BindToString(frameB->keymap, "d", NoCallCmd, NULL, NULL);
234     keymap_BindToString(frameB->keymap, "d", (int (*)())0, NULL, NULL);
235     keymap_BindToString(frameB->keymap, "\033d", NoCallCmd, NULL, NULL);
236     gtxframe_AddMenu(frameB, "FrameA", "a");
237
238     /* finally setup the first window */
239     gtxframe_AddToList(frameA, objectA);
240     gtxframe_SetFrame(win, frameA);
241
242     /* play with maps for a while */
243     tmap = (struct keymap_map *)keymap_Create();
244     keymap_BindToString(tmap, "d", NoCallCmd, "test", (char *)1);
245     keymap_BindToString(tmap, "cd", NoCallCmd, "bozo", NULL);
246     keymap_Delete(tmap);
247
248     gtx_InputServer(win);
249 }