pull-prototypes-to-head-20020821
[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("$Header$");
14
15
16 #ifdef HAVE_STRING_H
17 #include <string.h>
18 #else
19 #ifdef HAVE_STRINGS_H
20 #include <strings.h>
21 #endif
22 #endif
23
24 #include "gtxwindows.h"
25 #include "gtxobjects.h"
26 #include "gtxtextobj.h"
27 #include "gtxlightobj.h"
28 #include "gtxframe.h"
29
30 struct gtx_frame *frameA, *frameB;
31
32 struct onode *objectA, *objectB;
33 struct onode *lightA, *lightB;
34
35 static int ChangeMenuCmd(awin, arock)
36 afs_int32 arock;
37 register struct gwin *awin; {
38     register struct gtx_frame *tf;
39     register afs_int32 code;
40
41     tf = awin->w_frame;
42     if (!tf) return -1;
43
44     if (arock == 1) {
45         gtxframe_ClearMenus(tf);
46     }
47     else if (arock == 2) {
48         code = gtxframe_DeleteMenu(tf, "NewLabel");
49         if (code) gtxframe_DisplayString(tf, "Can't delete menu!");
50     }
51     else if (arock == 3) {
52         code = gtxframe_ClearMenus(tf);
53         gtxframe_AddMenu(frameA, "FrameB", "b");
54         gtxframe_AddMenu(frameA, "NewLabel", "c");
55     }
56     return 0;
57 }
58
59 static int ChangeListCmd(awin, arock)
60 afs_int32 arock;
61 register struct gwin *awin; {
62     register struct gtx_frame *tf;
63     register afs_int32 code;
64
65     tf = awin->w_frame;
66     if (!tf) return -1;
67
68     if (arock == 1) {
69         gtxframe_ClearList(tf);
70     }
71     else if (arock == 2) {
72         code = gtxframe_RemoveFromList(tf, lightA);
73         if (code) gtxframe_DisplayString(tf, "Can't delete light!");
74     }
75     else if (arock == 3) {
76         code = gtxframe_ClearList(tf);
77         gtxframe_AddToList(frameA, objectA);
78         gtxframe_AddToList(frameA, lightA);
79     }
80     return 0;
81 }
82
83 static int NoCallCmd(awin)
84 struct gwin *awin; {
85     gtxframe_DisplayString(awin->w_frame, "Function should be mapped on '$d', not 'd'");
86     return 0;
87 }
88
89 static int ChangeCmd(awin)
90 struct gwin *awin; {
91     char tbuffer[100];
92     register afs_int32 code;
93
94     code = gtxframe_AskForString(awin->w_frame, "New object string: ", "TestNew",
95                           tbuffer, sizeof(tbuffer));
96     if (code == 0) {
97         /* have new value, write it to object A */
98         gator_text_Write(objectA, tbuffer, 0, 0, 0);
99     }
100     return 0;
101 }
102
103 static int StupidCmd(awin)
104 struct gwin *awin; {
105     gtxframe_DisplayString(awin->w_frame, "You're already showing that frame!");
106     return 0;
107 }
108
109 static int SwitchToACmd(awin)
110 struct gwin *awin; {
111     gtxframe_SetFrame(awin, frameA);
112     return 0;
113 }
114
115 static int SwitchToBCmd(awin)
116 struct gwin *awin; {
117     gtxframe_SetFrame(awin, frameB);
118     return 0;
119 }
120
121 #include "AFS_component_version_number.c"
122
123 main() {
124     struct gwin *win;
125     struct gator_textobj_params textcrparams;
126     struct gator_light_crparams lightcrparams;
127     register struct keymap_map *tmap;
128
129     win = gtx_Init(0, -1);
130
131     /* create a couple of objects, a and b, and have the "a" and "b" keys
132        switch the display from one to the other */
133     textcrparams.onode_params.cr_type        = GATOR_OBJ_TEXT;
134     strcpy(textcrparams.onode_params.cr_name, "Text1-A");
135     textcrparams.onode_params.cr_x           = 30;
136     textcrparams.onode_params.cr_y           = 10;
137     textcrparams.onode_params.cr_width       = 35;
138     textcrparams.onode_params.cr_height     =  7;
139     textcrparams.onode_params.cr_window     = win;      /* ???? */
140     textcrparams.onode_params.cr_home_obj   = NULL;
141     textcrparams.onode_params.cr_prev_obj   = NULL;
142     textcrparams.onode_params.cr_parent_obj = NULL;
143     textcrparams.onode_params.cr_helpstring = "Help string for text";
144     textcrparams.maxEntries        =  7;
145     textcrparams.maxCharsPerEntry = 35;
146
147     objectA = gator_objects_create((struct onode_createparams *)(&textcrparams));
148     gator_text_Write(objectA, "This is object A", 0, 0, 0);
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, "Text2-B");
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     objectB = gator_objects_create((struct onode_createparams *)(&textcrparams));
167     gator_text_Write(objectB, "This is object B", 0, 0, 0);
168
169     lightcrparams.onode_params.cr_type       = GATOR_OBJ_LIGHT;
170     lightcrparams.onode_params.cr_x          = 10;
171     lightcrparams.onode_params.cr_y          = 10;
172     lightcrparams.onode_params.cr_width      = 10;
173     lightcrparams.onode_params.cr_height     = 10;
174     lightcrparams.onode_params.cr_window     = win;     /* ???? */
175     lightcrparams.onode_params.cr_home_obj   = NULL;
176     lightcrparams.onode_params.cr_prev_obj   = NULL;
177     lightcrparams.onode_params.cr_parent_obj = NULL;
178     lightcrparams.onode_params.cr_helpstring = "Help string for text";
179     strcpy(lightcrparams.label, "Light-1");
180     lightcrparams.label_x = 0;
181     lightcrparams.label_y = 0;
182     lightcrparams.flashfreq = 100;
183     lightcrparams.appearance = GATOR_LIGHTMASK_INVVIDEO;
184     lightA = gator_objects_create((struct onode_createparams *)(&lightcrparams));
185
186     /* create basic frames */
187     frameA = gtxframe_Create();
188     frameB = gtxframe_Create();
189
190     /* setup A's frame */
191     gtxframe_ClearList(frameA);
192     gtxframe_AddToList(frameA, objectA);
193     gtxframe_AddToList(frameA, lightA);
194     keymap_BindToString(frameA->keymap, "b", SwitchToBCmd, NULL, NULL);
195     keymap_BindToString(frameA->keymap, "a", StupidCmd, NULL, NULL);
196     keymap_BindToString(frameA->keymap, "c", ChangeCmd, NULL, NULL);
197     keymap_BindToString(frameA->keymap, "\033a", ChangeMenuCmd, "ChangeMenu", (char *) 1);
198     keymap_BindToString(frameA->keymap, "\033b", ChangeMenuCmd, "ChangeMenu", (char *) 2);
199     keymap_BindToString(frameA->keymap, "\033c", ChangeMenuCmd, "ChangeMenu", (char *) 3);
200     keymap_BindToString(frameA->keymap, "\0331", ChangeListCmd, "ChangeList", (char *) 1);
201     keymap_BindToString(frameA->keymap, "\0332", ChangeListCmd, "ChangeList", (char *) 2);
202     keymap_BindToString(frameA->keymap, "\0333", ChangeListCmd, "ChangeList", (char *) 3);
203     gtxframe_AddMenu(frameA, "FrameB", "b");
204     gtxframe_AddMenu(frameA, "NewLabel", "c");
205
206     /* setup B's frame */
207     gtxframe_ClearList(frameB);
208     gtxframe_AddToList(frameB, objectB);
209     keymap_BindToString(frameB->keymap, "a", SwitchToACmd, NULL, NULL);
210     keymap_BindToString(frameB->keymap, "b", StupidCmd, NULL, NULL);
211     keymap_BindToString(frameB->keymap, "d", NoCallCmd, NULL, NULL);
212     keymap_BindToString(frameB->keymap, "d", (int (*)()) 0, NULL, NULL);
213     keymap_BindToString(frameB->keymap, "\033d", NoCallCmd, NULL, NULL);
214     gtxframe_AddMenu(frameB, "FrameA", "a");
215
216     /* finally setup the first window */
217     gtxframe_AddToList(frameA, objectA);
218     gtxframe_SetFrame(win, frameA);
219
220     /* play with maps for a while */
221     tmap = (struct keymap_map *) keymap_Create();
222     keymap_BindToString(tmap, "d", NoCallCmd, "test", (char *) 1);
223     keymap_BindToString(tmap, "cd", NoCallCmd, "bozo", NULL);
224     keymap_Delete(tmap);
225
226     gtx_InputServer(win);
227 }