gtx-prototypes-20090316
[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 #include "gtxinput.h"
25
26 struct gtx_frame *frameA, *frameB;
27
28 struct onode *objectA, *objectB;
29 struct onode *lightA, *lightB;
30
31 static int
32 ChangeMenuCmd(void *param1, void *param2)
33 {
34     struct gwin * awin = (struct gwin *) param1;
35     afs_int32 arock = (afs_int32) param2;
36     
37     register struct gtx_frame *tf;
38     register afs_int32 code;
39
40     tf = awin->w_frame;
41     if (!tf)
42         return -1;
43
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");
54     }
55     return 0;
56 }
57
58 static int
59 ChangeListCmd(void *param1, void *param2)
60 {
61     struct gwin *awin = (struct gwin *) param1;
62     afs_int32 arock = (afs_int32) param2;
63     
64     register struct gtx_frame *tf;
65     register afs_int32 code;
66
67     tf = awin->w_frame;
68     if (!tf)
69         return -1;
70
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);
81     }
82     return 0;
83 }
84
85 static int
86 NoCallCmd(void *param, void *unused)
87 {
88     struct gwin *awin = (struct gwin *)param;
89     
90     gtxframe_DisplayString(awin->w_frame,
91                            "Function should be mapped on '$d', not 'd'");
92     return 0;
93 }
94
95 static int
96 ChangeCmd(void *param, void *unused)
97 {
98     struct gwin *awin = (struct gwin *) param;
99     char tbuffer[100];
100     register afs_int32 code;
101
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);
108     }
109     return 0;
110 }
111
112 static int
113 StupidCmd(void *param, void *unused)
114 {
115     struct gwin *awin = (struct gwin *)param;
116     
117     gtxframe_DisplayString(awin->w_frame,
118                            "You're already showing that frame!");
119     return 0;
120 }
121
122 static int
123 SwitchToACmd(void *param, void *unused)
124 {
125     struct gwin *awin = (struct gwin *)param;
126     gtxframe_SetFrame(awin, frameA);
127     return 0;
128 }
129
130 static int
131 SwitchToBCmd(void *param, void *unused)
132 {
133     struct gwin *awin = (struct gwin *)param;
134     gtxframe_SetFrame(awin, frameB);
135     return 0;
136 }
137
138 #include "AFS_component_version_number.c"
139
140 int
141 main(int argc, char **argv)
142 {
143     struct gwin *win;
144     struct gator_textobj_params textcrparams;
145     struct gator_light_crparams lightcrparams;
146     register struct keymap_map *tmap;
147
148     win = gtx_Init(0, -1);
149
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;
165
166     objectA =
167         gator_objects_create((struct onode_createparams *)(&textcrparams));
168     gator_text_Write(objectA, "This is object A", 0, 0, 0);
169
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;
185
186     objectB =
187         gator_objects_create((struct onode_createparams *)(&textcrparams));
188     gator_text_Write(objectB, "This is object B", 0, 0, 0);
189
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));
207
208     /* create basic frames */
209     frameA = gtxframe_Create();
210     frameB = gtxframe_Create();
211
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");
233
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");
243
244     /* finally setup the first window */
245     gtxframe_AddToList(frameA, objectA);
246     gtxframe_SetFrame(win, frameA);
247
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);
253
254     gtx_InputServer(win);
255     return 0;
256 }