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