Update NEWS for 1.6.22
[pkg-k5-afs_openafs.git] / src / gtx / gtxtest.c
blob29fabf58b88b35e8378694f1683298d450868c39
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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 */
10 #include <afsconfig.h>
11 #include <afs/param.h>
14 #include <string.h>
15 #ifdef HAVE_STDINT_H
16 #include <stdint.h>
17 #endif
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 #include "gtxinput.h"
26 struct gtx_frame *frameA, *frameB;
28 struct onode *objectA, *objectB;
29 struct onode *lightA, *lightB;
31 static int
32 ChangeMenuCmd(void *param1, void *param2)
34 struct gwin * awin = (struct gwin *) param1;
35 afs_int32 arock = (intptr_t)param2;
37 struct gtx_frame *tf;
38 afs_int32 code;
40 tf = awin->w_frame;
41 if (!tf)
42 return -1;
44 if (arock == 1) {
45 gtxframe_ClearMenus(tf);
46 } else if (arock == 2) {
47 code = gtxframe_DeleteMenu(tf, "NewLabel");
48 if (code)
49 gtxframe_DisplayString(tf, "Can't delete menu!");
50 } else if (arock == 3) {
51 code = gtxframe_ClearMenus(tf);
52 gtxframe_AddMenu(frameA, "FrameB", "b");
53 gtxframe_AddMenu(frameA, "NewLabel", "c");
55 return 0;
58 static int
59 ChangeListCmd(void *param1, void *param2)
61 struct gwin *awin = (struct gwin *) param1;
62 afs_int32 arock = (intptr_t)param2;
64 struct gtx_frame *tf;
65 afs_int32 code;
67 tf = awin->w_frame;
68 if (!tf)
69 return -1;
71 if (arock == 1) {
72 gtxframe_ClearList(tf);
73 } else if (arock == 2) {
74 code = gtxframe_RemoveFromList(tf, lightA);
75 if (code)
76 gtxframe_DisplayString(tf, "Can't delete light!");
77 } else if (arock == 3) {
78 code = gtxframe_ClearList(tf);
79 gtxframe_AddToList(frameA, objectA);
80 gtxframe_AddToList(frameA, lightA);
82 return 0;
85 static int
86 NoCallCmd(void *param, void *unused)
88 struct gwin *awin = (struct gwin *)param;
90 gtxframe_DisplayString(awin->w_frame,
91 "Function should be mapped on '$d', not 'd'");
92 return 0;
95 static int
96 ChangeCmd(void *param, void *unused)
98 struct gwin *awin = (struct gwin *) param;
99 char tbuffer[100];
100 afs_int32 code;
102 code =
103 gtxframe_AskForString(awin->w_frame, "New object string: ", "TestNew",
104 tbuffer, sizeof(tbuffer));
105 if (code == 0) {
106 /* have new value, write it to object A */
107 gator_text_Write(objectA, tbuffer, 0, 0, 0);
109 return 0;
112 static int
113 StupidCmd(void *param, void *unused)
115 struct gwin *awin = (struct gwin *)param;
117 gtxframe_DisplayString(awin->w_frame,
118 "You're already showing that frame!");
119 return 0;
122 static int
123 SwitchToACmd(void *param, void *unused)
125 struct gwin *awin = (struct gwin *)param;
126 gtxframe_SetFrame(awin, frameA);
127 return 0;
130 static int
131 SwitchToBCmd(void *param, void *unused)
133 struct gwin *awin = (struct gwin *)param;
134 gtxframe_SetFrame(awin, frameB);
135 return 0;
138 #include "AFS_component_version_number.c"
141 main(int argc, char **argv)
143 struct gwin *win;
144 struct gator_textobj_params textcrparams;
145 struct gator_light_crparams lightcrparams;
146 struct keymap_map *tmap;
148 win = gtx_Init(0, -1);
150 /* create a couple of objects, a and b, and have the "a" and "b" keys
151 * switch the display from one to the other */
152 textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT;
153 strcpy(textcrparams.onode_params.cr_name, "Text1-A");
154 textcrparams.onode_params.cr_x = 30;
155 textcrparams.onode_params.cr_y = 10;
156 textcrparams.onode_params.cr_width = 35;
157 textcrparams.onode_params.cr_height = 7;
158 textcrparams.onode_params.cr_window = win; /* ???? */
159 textcrparams.onode_params.cr_home_obj = NULL;
160 textcrparams.onode_params.cr_prev_obj = NULL;
161 textcrparams.onode_params.cr_parent_obj = NULL;
162 textcrparams.onode_params.cr_helpstring = "Help string for text";
163 textcrparams.maxEntries = 7;
164 textcrparams.maxCharsPerEntry = 35;
166 objectA =
167 gator_objects_create((struct onode_createparams *)(&textcrparams));
168 gator_text_Write(objectA, "This is object A", 0, 0, 0);
170 /* create a couple of objects, a and b, and have the "a" and "b" keys
171 * switch the display from one to the other */
172 textcrparams.onode_params.cr_type = GATOR_OBJ_TEXT;
173 strcpy(textcrparams.onode_params.cr_name, "Text2-B");
174 textcrparams.onode_params.cr_x = 30;
175 textcrparams.onode_params.cr_y = 10;
176 textcrparams.onode_params.cr_width = 35;
177 textcrparams.onode_params.cr_height = 7;
178 textcrparams.onode_params.cr_window = win; /* ???? */
179 textcrparams.onode_params.cr_home_obj = NULL;
180 textcrparams.onode_params.cr_prev_obj = NULL;
181 textcrparams.onode_params.cr_parent_obj = NULL;
182 textcrparams.onode_params.cr_helpstring = "Help string for text";
183 textcrparams.maxEntries = 7;
184 textcrparams.maxCharsPerEntry = 35;
186 objectB =
187 gator_objects_create((struct onode_createparams *)(&textcrparams));
188 gator_text_Write(objectB, "This is object B", 0, 0, 0);
190 lightcrparams.onode_params.cr_type = GATOR_OBJ_LIGHT;
191 lightcrparams.onode_params.cr_x = 10;
192 lightcrparams.onode_params.cr_y = 10;
193 lightcrparams.onode_params.cr_width = 10;
194 lightcrparams.onode_params.cr_height = 10;
195 lightcrparams.onode_params.cr_window = win; /* ???? */
196 lightcrparams.onode_params.cr_home_obj = NULL;
197 lightcrparams.onode_params.cr_prev_obj = NULL;
198 lightcrparams.onode_params.cr_parent_obj = NULL;
199 lightcrparams.onode_params.cr_helpstring = "Help string for text";
200 strcpy(lightcrparams.label, "Light-1");
201 lightcrparams.label_x = 0;
202 lightcrparams.label_y = 0;
203 lightcrparams.flashfreq = 100;
204 lightcrparams.appearance = GATOR_LIGHTMASK_INVVIDEO;
205 lightA =
206 gator_objects_create((struct onode_createparams *)(&lightcrparams));
208 /* create basic frames */
209 frameA = gtxframe_Create();
210 frameB = gtxframe_Create();
212 /* setup A's frame */
213 gtxframe_ClearList(frameA);
214 gtxframe_AddToList(frameA, objectA);
215 gtxframe_AddToList(frameA, lightA);
216 keymap_BindToString(frameA->keymap, "b", SwitchToBCmd, NULL, NULL);
217 keymap_BindToString(frameA->keymap, "a", StupidCmd, NULL, NULL);
218 keymap_BindToString(frameA->keymap, "c", ChangeCmd, NULL, NULL);
219 keymap_BindToString(frameA->keymap, "\033a", ChangeMenuCmd, "ChangeMenu",
220 (char *)1);
221 keymap_BindToString(frameA->keymap, "\033b", ChangeMenuCmd, "ChangeMenu",
222 (char *)2);
223 keymap_BindToString(frameA->keymap, "\033c", ChangeMenuCmd, "ChangeMenu",
224 (char *)3);
225 keymap_BindToString(frameA->keymap, "\0331", ChangeListCmd, "ChangeList",
226 (char *)1);
227 keymap_BindToString(frameA->keymap, "\0332", ChangeListCmd, "ChangeList",
228 (char *)2);
229 keymap_BindToString(frameA->keymap, "\0333", ChangeListCmd, "ChangeList",
230 (char *)3);
231 gtxframe_AddMenu(frameA, "FrameB", "b");
232 gtxframe_AddMenu(frameA, "NewLabel", "c");
234 /* setup B's frame */
235 gtxframe_ClearList(frameB);
236 gtxframe_AddToList(frameB, objectB);
237 keymap_BindToString(frameB->keymap, "a", SwitchToACmd, NULL, NULL);
238 keymap_BindToString(frameB->keymap, "b", StupidCmd, NULL, NULL);
239 keymap_BindToString(frameB->keymap, "d", NoCallCmd, NULL, NULL);
240 keymap_BindToString(frameB->keymap, "d", (int (*)())0, NULL, NULL);
241 keymap_BindToString(frameB->keymap, "\033d", NoCallCmd, NULL, NULL);
242 gtxframe_AddMenu(frameB, "FrameA", "a");
244 /* finally setup the first window */
245 gtxframe_AddToList(frameA, objectA);
246 gtxframe_SetFrame(win, frameA);
248 /* play with maps for a while */
249 tmap = (struct keymap_map *)keymap_Create();
250 keymap_BindToString(tmap, "d", NoCallCmd, "test", (char *)1);
251 keymap_BindToString(tmap, "cd", NoCallCmd, "bozo", NULL);
252 keymap_Delete(tmap);
254 gtx_InputServer(win);
255 return 0;