2 * Copyright 2000, International Business Machines Corporation and others.
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
12 * Implementation of the gator object interface.
14 *------------------------------------------------------------------------*/
16 #include <afsconfig.h>
17 #include <afs/param.h>
22 #include "gtxobjects.h" /*Interface for this module */
23 #include "gtxtextobj.h" /*Text object interface */
24 #include "gtxlightobj.h" /*Light object interface */
25 #include "gtxobjdict.h" /*Object dictionary module */
26 #include <stdio.h> /*Standard I/O stuff */
40 * Number of known gator object types.
42 #define GATOR_NUM_OBJTYPES 3
44 static char mn[] = "gator_objects"; /*Module name */
45 int objects_debug; /*Is debugging output on? */
47 int (*on_create[GATOR_NUM_OBJTYPES]) (); /*Array of ptrs to creation functions */
48 struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays */
51 /*--------------------------------------------------------------------------------
55 * Initialize the gator object package.
58 * struct onode_initparams *params: Initialization parameters.
62 * Error value otherwise.
65 * *** MUST BE THE FIRST ROUTINE CALLED FROM
70 *--------------------------------------------------------------------------------*/
73 gator_objects_init(params)
74 struct onode_initparams *params;
76 { /*gator_objects_init */
78 static char rn[] = "gator_objects_init"; /*Routine name */
79 static int initialized = 0; /*Have we been called? */
80 register int code; /*Return code */
83 * If we've already been called, just return.
88 fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n",
94 * Remember our debugging level.
96 objects_debug = params->i_debug;
99 * Set up the onode op array, one entry for each known gator object type.
102 fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn);
103 objops[GATOR_OBJ_TEXT] = gator_text_ops;
104 objops[GATOR_OBJ_LIGHT] = gator_light_ops;
107 * Initialize the object dictionary.
110 fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn);
111 code = gator_objdict_init(objects_debug);
114 "[%s:%s] Can't initialize object dictionary: error code is %d\n",
120 * Initialize the chosen window package. Remember the base window
121 * is accessible as gator_basegwin.
125 "[%s:%s] Initializing gator window module for package %d.\n",
126 mn, rn, params->i_gwparams->i_type);
128 "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n",
129 params->i_gwparams->i_type, params->i_gwparams->i_x,
130 params->i_gwparams->i_y, params->i_gwparams->i_width,
131 params->i_gwparams->i_height, params->i_gwparams->i_debug);
133 code = gw_init(params->i_gwparams);
136 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
137 mn, rn, params->i_gwparams->i_type, code);
142 * Set up the array of creation functions.
146 "[%s:%s] Initializing gator object creation function array.\n",
148 on_create[GATOR_OBJ_TEXT] = gator_text_create;
149 on_create[GATOR_OBJ_LIGHT] = gator_light_create;
152 * Finally, return the good news.
156 } /*gator_objects_init */
158 /*--------------------------------------------------------------------------------
159 * gator_objects_create
162 * Create an onode of the given type.
165 * struct onode_createparams *params: Ptr to creation params.
168 * Ptr to newly-created onode if successful,
169 * Null pointer otherwise.
172 * Nothing interesting.
176 *--------------------------------------------------------------------------------*/
179 gator_objects_create(params)
180 struct onode_createparams *params;
182 { /*gator_objects_create */
184 static char rn[] = "gator_objects_create"; /*Routine name */
185 register int code; /*Return code */
186 struct onode *new_onode; /*Ptr to new onode */
189 fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn,
190 rn, params->cr_type, params->cr_name);
191 fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y);
192 fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width,
194 fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring);
195 fprintf(stderr, "\tWindow struct at 0x%x\n", params->cr_window);
200 "[%s:%s] Allocating %d bytes for new onode structure\n", mn,
201 rn, sizeof(struct onode));
202 new_onode = (struct onode *)malloc(sizeof(struct onode));
203 if (new_onode == NULL) {
205 "[%s:%s] Can't allocate %d bytes for new onode structure; errno is %d\n",
206 mn, rn, sizeof(struct onode), errno);
211 * Fill in the onode fields we can do right away.
212 * **** Don't do anything with cr_helpstring yet - eventually,
213 * we'll create a scrollable text help object with it ****
216 fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn,
217 sizeof(struct onode));
218 new_onode->o_type = params->cr_type;
219 strcpy(new_onode->o_name, params->cr_name);
220 new_onode->o_x = params->cr_x;
221 new_onode->o_y = params->cr_y;
222 new_onode->o_width = params->cr_width;
223 new_onode->o_height = params->cr_height;
224 new_onode->o_changed = 1;
225 new_onode->o_refcount = 1;
226 new_onode->o_window = params->cr_window;
227 new_onode->o_op = &(objops[params->cr_type]);
228 new_onode->o_home = params->cr_home_obj;
229 new_onode->o_help = NULL;
230 new_onode->o_nextobj = NULL;
231 new_onode->o_upobj = params->cr_parent_obj;
232 new_onode->o_downobj = NULL;
235 * Call the proper routine to initialize the private parts of the
240 "[%s:%s] Calling the creation routine for gator object type %d\n",
241 mn, rn, params->cr_type);
242 code = (on_create[params->cr_type]) (new_onode, params);
246 "[%s:%s] Error %d in creation routine for gator object type %d\n",
247 mn, rn, code, params->cr_type);
253 * Set the links on the parent and previous objects, if so directed.
255 if (params->cr_prev_obj != NULL) {
258 "[%s:%s] Setting o_nextobj pointer in the previous object located at 0x%x (previous value was 0x%x)\n",
259 mn, rn, params->cr_prev_obj,
260 params->cr_prev_obj->o_nextobj);
261 params->cr_prev_obj->o_nextobj = new_onode;
263 if (params->cr_parent_obj != NULL) {
266 "[%s:%s] Setting o_downobj pointer in the parent object located at 0x%x (previous value was 0x%x)\n",
267 mn, rn, params->cr_parent_obj,
268 params->cr_parent_obj->o_downobj);
269 params->cr_parent_obj->o_downobj = new_onode;
273 * Return the location of the completely-initialized onode object.
277 } /*gator_objects_create */
279 /*--------------------------------------------------------------------------------
280 * gator_objects_lookup
286 * char *onode_name: Onode string name to find.
289 * Ptr to onode matching the given name if one exists,
290 * Null pointer otherwise.
293 * Nothing interesting.
297 *--------------------------------------------------------------------------------*/
300 gator_objects_lookup(onode_name)
303 { /*gator_objects_lookup */
305 static char rn[] = "gator_objects_lookup"; /*Routine name */
308 * Life is very simple here - just call the dictionary routine.
311 fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn,
313 return (gator_objdict_lookup(onode_name));
315 } /*gator_objects_lookup */