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>
21 #include "gtxlightobj.h" /*Interface for this module */
23 /*Externally-advertised array of light onode operations*/
24 struct onodeops gator_light_ops = {
30 static char mn[] = "gator_lightobject"; /*Module name */
32 /*------------------------------------------------------------------------
36 * Create a gator light object.
39 * struct onode *light_onp : Ptr to the light onode to fill out.
40 * struct onode_createparams *params : Generic ptr to creation
45 * Error value otherwise.
48 * The base onode fields have already been set. Lights are turned
52 * Creates and initializes the light private data area, including
53 * a window string-drawing parameter structure. These areas are
54 * garbage-collected upon failure.
55 *------------------------------------------------------------------------*/
58 gator_light_create(struct onode *light_onp, struct onode_createparams *params)
59 { /*gator_light_create */
61 static char rn[] = "gator_light_create"; /*Routine name */
62 struct gator_light_crparams *light_params; /*My specific creation params */
63 struct gator_lightobj *light_data; /*Ptr to private data */
64 struct gwin_strparams *light_strparams; /*Light label params */
66 light_params = (struct gator_light_crparams *)params;
68 fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn,
71 "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n",
72 light_params->appearance, light_params->flashfreq,
73 light_params->label_x, light_params->label_y,
78 * Allocate the private data area, including the lower-level
79 * structure, then fill it in.
82 (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj));
83 if (light_data == (struct gator_lightobj *)0) {
85 "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object private data region, errno is %d\n",
86 mn, rn, sizeof(struct gator_lightobj), errno);
91 (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams));
92 if (light_strparams == (struct gwin_strparams *)0) {
94 "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object label in private data region, errno is %d\n",
95 mn, rn, sizeof(struct gwin_strparams), errno);
101 * Now that we have the private structures allocated, set them up.
103 light_data->setting = 0;
104 light_data->appearance = light_params->appearance;
105 light_data->flashfreq = light_params->flashfreq;
106 light_data->lasttoggletime = 0;
107 strcpy(light_data->label, light_params->label);
109 light_strparams->x = light_onp->o_x + light_params->label_x;
110 light_strparams->y = light_onp->o_y + light_params->label_y;
111 light_strparams->s = light_data->label;
112 light_strparams->highlight = 0;
113 light_data->llrock = (int *)light_strparams;
116 * Attach the private data to the onode, then return the happy news.
118 light_onp->o_data = (int *)light_data;
121 } /*gator_light_create */
123 /*------------------------------------------------------------------------
124 * gator_light_destroy
127 * Destroy a gator light object.
130 * struct onode *onp : Ptr to the light onode to delete.
134 * Error value otherwise.
137 * Nothing interesting.
141 *------------------------------------------------------------------------*/
144 gator_light_destroy(struct onode *onp)
145 { /*gator_light_destroy */
148 * For now, this is a no-op.
152 } /*gator_light_destroy */
154 /*------------------------------------------------------------------------
155 * gator_light_display
158 * Display/redraw a gator light object.
161 * struct onode *onp: Ptr to the light onode to display.
165 * Error value otherwise.
168 * Light objects have a pointer to string-drawing params in the
169 * lower-level rock, with the proper highlighting set according
170 * to whether the light is on or off, so we just have to draw
171 * that string to get the proper effect.
175 *------------------------------------------------------------------------*/
178 gator_light_display(struct onode *onp)
179 { /*gator_light_display */
181 static char rn[] = "gator_light_display"; /*Routine name */
182 struct gator_lightobj *light_data; /*Ptr to light obj data */
183 struct gwin_strparams *label_strparams; /*String-drawing params */
186 * Draw the label, with proper highlighting depending on whether
189 light_data = (struct gator_lightobj *)(onp->o_data);
190 label_strparams = (struct gwin_strparams *)(light_data->llrock);
192 fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n",
193 mn, rn, label_strparams->s, label_strparams->x,
195 WOP_DRAWSTRING(onp->o_window, label_strparams);
198 } /*gator_light_display */
200 /*------------------------------------------------------------------------
201 * gator_light_release
204 * Drop the refcount on a gator light object.
207 * struct onode *onp : Ptr to the onode whose refcount is
212 * Error value otherwise.
215 * Nothing interesting.
219 *------------------------------------------------------------------------*/
222 gator_light_release(struct onode *onp)
223 { /*gator_light_release */
226 * For now, this is a no-op.
230 } /*gator_light_release */
232 /*------------------------------------------------------------------------
236 * Set the value of the given gator light object.
239 * struct onode *onp : Ptr to the light onode to be set.
240 * int setting : Non-zero for ``on'', zero for ``off''.
244 * Error value otherwise.
247 * We need to set not only the setting field, but the lower-
248 * level structure stored in the rock must have its highlight
249 * field set correctly.
252 * Does NOT redisplay the light object.
253 *------------------------------------------------------------------------*/
256 gator_light_set(struct onode *onp, int setting)
257 { /*gator_light_set */
259 static char rn[] = "gator_light_set"; /*Routine name */
260 struct gator_lightobj *light_data; /*Ptr to light obj data */
261 struct gwin_strparams *label_strparams; /*String-drawing params */
264 * Set the object correctly, then set the highlight field in
265 * the lower-level rock.
267 light_data = (struct gator_lightobj *)(onp->o_data);
268 label_strparams = (struct gwin_strparams *)(light_data->llrock);
270 fprintf(stderr, "[%s:%s] Setting light object at %p to %d (%s)", mn,
271 rn, onp, setting, (setting ? "ON" : "OFF"));
272 light_data->setting = setting;
273 label_strparams->highlight = setting;
277 } /*gator_light_set */