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 light object.
14 *------------------------------------------------------------------------*/
16 #include <afsconfig.h>
17 #include <afs/param.h>
22 #include "gtxlightobj.h" /*Interface for this module */
23 #include <stdio.h> /*Standard I/O stuff */
36 /*Externally-advertised array of light onode operations*/
37 struct onodeops gator_light_ops = {
43 static char mn[] = "gator_lightobject"; /*Module name */
45 /*------------------------------------------------------------------------
49 * Create a gator light object.
52 * struct onode *light_onp : Ptr to the light onode to fill out.
53 * struct onode_createparams *params : Generic ptr to creation
58 * Error value otherwise.
61 * The base onode fields have already been set. Lights are turned
65 * Creates and initializes the light private data area, including
66 * a window string-drawing parameter structure. These areas are
67 * garbage-collected upon failure.
68 *------------------------------------------------------------------------*/
71 gator_light_create(light_onp, params)
72 struct onode *light_onp;
73 struct onode_createparams *params;
75 { /*gator_light_create */
77 static char rn[] = "gator_light_create"; /*Routine name */
78 struct gator_light_crparams *light_params; /*My specific creation params */
79 struct gator_lightobj *light_data; /*Ptr to private data */
80 struct gwin_strparams *light_strparams; /*Light label params */
82 light_params = (struct gator_light_crparams *)params;
84 fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn,
87 "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n",
88 light_params->appearance, light_params->flashfreq,
89 light_params->label_x, light_params->label_y,
94 * Allocate the private data area, including the lower-level
95 * structure, then fill it in.
98 (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj));
99 if (light_data == (struct gator_lightobj *)0) {
101 "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n",
102 mn, rn, sizeof(struct gator_lightobj), errno);
107 (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams));
108 if (light_strparams == (struct gwin_strparams *)0) {
110 "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n",
111 mn, rn, sizeof(struct gwin_strparams), errno);
117 * Now that we have the private structures allocated, set them up.
119 light_data->setting = 0;
120 light_data->appearance = light_params->appearance;
121 light_data->flashfreq = light_params->flashfreq;
122 light_data->lasttoggletime = 0;
123 strcpy(light_data->label, light_params->label);
125 light_strparams->x = light_onp->o_x + light_params->label_x;
126 light_strparams->y = light_onp->o_y + light_params->label_y;
127 light_strparams->s = light_data->label;
128 light_strparams->highlight = 0;
129 light_data->llrock = (int *)light_strparams;
132 * Attach the private data to the onode, then return the happy news.
134 light_onp->o_data = (int *)light_data;
137 } /*gator_light_create */
139 /*------------------------------------------------------------------------
140 * gator_light_destroy
143 * Destroy a gator light object.
146 * struct onode *onp : Ptr to the light onode to delete.
150 * Error value otherwise.
153 * Nothing interesting.
157 *------------------------------------------------------------------------*/
160 gator_light_destroy(onp)
163 { /*gator_light_destroy */
166 * For now, this is a no-op.
170 } /*gator_light_destroy */
172 /*------------------------------------------------------------------------
173 * gator_light_display
176 * Display/redraw a gator light object.
179 * struct onode *onp: Ptr to the light onode to display.
183 * Error value otherwise.
186 * Light objects have a pointer to string-drawing params in the
187 * lower-level rock, with the proper highlighting set according
188 * to whether the light is on or off, so we just have to draw
189 * that string to get the proper effect.
193 *------------------------------------------------------------------------*/
196 gator_light_display(onp)
199 { /*gator_light_display */
201 static char rn[] = "gator_light_display"; /*Routine name */
202 struct gator_lightobj *light_data; /*Ptr to light obj data */
203 struct gwin_strparams *label_strparams; /*String-drawing params */
206 * Draw the label, with proper highlighting depending on whether
209 light_data = (struct gator_lightobj *)(onp->o_data);
210 label_strparams = (struct gwin_strparams *)(light_data->llrock);
212 fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n",
213 mn, rn, label_strparams->s, label_strparams->x,
215 WOP_DRAWSTRING(onp->o_window, label_strparams);
218 } /*gator_light_display */
220 /*------------------------------------------------------------------------
221 * gator_light_release
224 * Drop the refcount on a gator light object.
227 * struct onode *onp : Ptr to the onode whose refcount is
232 * Error value otherwise.
235 * Nothing interesting.
239 *------------------------------------------------------------------------*/
242 gator_light_release(onp)
245 { /*gator_light_release */
248 * For now, this is a no-op.
252 } /*gator_light_release */
254 /*------------------------------------------------------------------------
258 * Set the value of the given gator light object.
261 * struct onode *onp : Ptr to the light onode to be set.
262 * int setting : Non-zero for ``on'', zero for ``off''.
266 * Error value otherwise.
269 * We need to set not only the setting field, but the lower-
270 * level structure stored in the rock must have its highlight
271 * field set correctly.
274 * Does NOT redisplay the light object.
275 *------------------------------------------------------------------------*/
278 gator_light_set(onp, setting)
282 { /*gator_light_set */
284 static char rn[] = "gator_light_set"; /*Routine name */
285 struct gator_lightobj *light_data; /*Ptr to light obj data */
286 struct gwin_strparams *label_strparams; /*String-drawing params */
289 * Set the object correctly, then set the highlight field in
290 * the lower-level rock.
292 light_data = (struct gator_lightobj *)(onp->o_data);
293 label_strparams = (struct gwin_strparams *)(light_data->llrock);
295 fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn,
296 rn, onp, setting, (setting ? "ON" : "OFF"));
297 light_data->setting = setting;
298 label_strparams->highlight = setting;
302 } /*gator_light_set */