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 */
33 * Number of known gator object types.
35 #define GATOR_NUM_OBJTYPES 3
37 static char mn[] = "gator_objects"; /*Module name */
38 int objects_debug; /*Is debugging output on? */
40 int (*on_create[GATOR_NUM_OBJTYPES]) (); /*Array of ptrs to creation functions */
41 struct onodeops objops[GATOR_NUM_OBJTYPES]; /*Per-type op arrays */
44 /*--------------------------------------------------------------------------------
48 * Initialize the gator object package.
51 * struct onode_initparams *params: Initialization parameters.
55 * Error value otherwise.
58 * *** MUST BE THE FIRST ROUTINE CALLED FROM
63 *--------------------------------------------------------------------------------*/
66 gator_objects_init(params)
67 struct onode_initparams *params;
69 { /*gator_objects_init */
71 static char rn[] = "gator_objects_init"; /*Routine name */
72 static int initialized = 0; /*Have we been called? */
73 register int code; /*Return code */
76 * If we've already been called, just return.
81 fprintf(stderr, "[%s:%s] Called more than once!! (%d time[s])\n",
87 * Remember our debugging level.
89 objects_debug = params->i_debug;
92 * Set up the onode op array, one entry for each known gator object type.
95 fprintf(stderr, "[%s:%s] Setting up objops array\n", mn, rn);
96 objops[GATOR_OBJ_TEXT] = gator_text_ops;
97 objops[GATOR_OBJ_LIGHT] = gator_light_ops;
100 * Initialize the object dictionary.
103 fprintf(stderr, "[%s:%s] Initializing object dictionary\n", mn, rn);
104 code = gator_objdict_init(objects_debug);
107 "[%s:%s] Can't initialize object dictionary: error code is %d\n",
113 * Initialize the chosen window package. Remember the base window
114 * is accessible as gator_basegwin.
118 "[%s:%s] Initializing gator window module for package %d.\n",
119 mn, rn, params->i_gwparams->i_type);
121 "\tWindow init params are: type %d, (%d, %d), width=%d, height=%d, debug=%d\n",
122 params->i_gwparams->i_type, params->i_gwparams->i_x,
123 params->i_gwparams->i_y, params->i_gwparams->i_width,
124 params->i_gwparams->i_height, params->i_gwparams->i_debug);
126 code = gw_init(params->i_gwparams);
129 "[%s:%s] Can't initialize gator windows for package %d; error is: %d\n",
130 mn, rn, params->i_gwparams->i_type, code);
135 * Set up the array of creation functions.
139 "[%s:%s] Initializing gator object creation function array.\n",
141 on_create[GATOR_OBJ_TEXT] = gator_text_create;
142 on_create[GATOR_OBJ_LIGHT] = gator_light_create;
145 * Finally, return the good news.
149 } /*gator_objects_init */
151 /*--------------------------------------------------------------------------------
152 * gator_objects_create
155 * Create an onode of the given type.
158 * struct onode_createparams *params: Ptr to creation params.
161 * Ptr to newly-created onode if successful,
162 * Null pointer otherwise.
165 * Nothing interesting.
169 *--------------------------------------------------------------------------------*/
172 gator_objects_create(params)
173 struct onode_createparams *params;
175 { /*gator_objects_create */
177 static char rn[] = "gator_objects_create"; /*Routine name */
178 register int code; /*Return code */
179 struct onode *new_onode; /*Ptr to new onode */
182 fprintf(stderr, "[%s:%s] Creating onode type %d, named '%s'\n", mn,
183 rn, params->cr_type, params->cr_name);
184 fprintf(stderr, "\tOrigin at (%d, %d)\n", params->cr_x, params->cr_y);
185 fprintf(stderr, "\tWidth=%d, height=%d\n", params->cr_width,
187 fprintf(stderr, "\tHelpstring='%s'\n", params->cr_helpstring);
188 fprintf(stderr, "\tWindow struct at 0x%x\n", params->cr_window);
193 "[%s:%s] Allocating %d bytes for new onode structure\n", mn,
194 rn, sizeof(struct onode));
195 new_onode = (struct onode *)malloc(sizeof(struct onode));
196 if (new_onode == NULL) {
198 "[%s:%s] Can't allocate %d bytes for new onode structure; errno is %d\n",
199 mn, rn, sizeof(struct onode), errno);
204 * Fill in the onode fields we can do right away.
205 * **** Don't do anything with cr_helpstring yet - eventually,
206 * we'll create a scrollable text help object with it ****
209 fprintf(stderr, "[%s:%s] Filling in onode fields\n", mn, rn,
210 sizeof(struct onode));
211 new_onode->o_type = params->cr_type;
212 strcpy(new_onode->o_name, params->cr_name);
213 new_onode->o_x = params->cr_x;
214 new_onode->o_y = params->cr_y;
215 new_onode->o_width = params->cr_width;
216 new_onode->o_height = params->cr_height;
217 new_onode->o_changed = 1;
218 new_onode->o_refcount = 1;
219 new_onode->o_window = params->cr_window;
220 new_onode->o_op = &(objops[params->cr_type]);
221 new_onode->o_home = params->cr_home_obj;
222 new_onode->o_help = NULL;
223 new_onode->o_nextobj = NULL;
224 new_onode->o_upobj = params->cr_parent_obj;
225 new_onode->o_downobj = NULL;
228 * Call the proper routine to initialize the private parts of the
233 "[%s:%s] Calling the creation routine for gator object type %d\n",
234 mn, rn, params->cr_type);
235 code = (on_create[params->cr_type]) (new_onode, params);
239 "[%s:%s] Error %d in creation routine for gator object type %d\n",
240 mn, rn, code, params->cr_type);
246 * Set the links on the parent and previous objects, if so directed.
248 if (params->cr_prev_obj != NULL) {
251 "[%s:%s] Setting o_nextobj pointer in the previous object located at 0x%x (previous value was 0x%x)\n",
252 mn, rn, params->cr_prev_obj,
253 params->cr_prev_obj->o_nextobj);
254 params->cr_prev_obj->o_nextobj = new_onode;
256 if (params->cr_parent_obj != NULL) {
259 "[%s:%s] Setting o_downobj pointer in the parent object located at 0x%x (previous value was 0x%x)\n",
260 mn, rn, params->cr_parent_obj,
261 params->cr_parent_obj->o_downobj);
262 params->cr_parent_obj->o_downobj = new_onode;
266 * Return the location of the completely-initialized onode object.
270 } /*gator_objects_create */
272 /*--------------------------------------------------------------------------------
273 * gator_objects_lookup
279 * char *onode_name: Onode string name to find.
282 * Ptr to onode matching the given name if one exists,
283 * Null pointer otherwise.
286 * Nothing interesting.
290 *--------------------------------------------------------------------------------*/
293 gator_objects_lookup(onode_name)
296 { /*gator_objects_lookup */
298 static char rn[] = "gator_objects_lookup"; /*Routine name */
301 * Life is very simple here - just call the dictionary routine.
304 fprintf(stderr, "[%s:%s] Looking up gator object '%s'\n", mn, rn,
306 return (gator_objdict_lookup(onode_name));
308 } /*gator_objects_lookup */