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 */
28 /*Externally-advertised array of light onode operations*/
29 struct onodeops gator_light_ops = {
35 static char mn[] = "gator_lightobject"; /*Module name */
37 /*------------------------------------------------------------------------
41 * Create a gator light object.
44 * struct onode *light_onp : Ptr to the light onode to fill out.
45 * struct onode_createparams *params : Generic ptr to creation
50 * Error value otherwise.
53 * The base onode fields have already been set. Lights are turned
57 * Creates and initializes the light private data area, including
58 * a window string-drawing parameter structure. These areas are
59 * garbage-collected upon failure.
60 *------------------------------------------------------------------------*/
63 gator_light_create(light_onp, params)
64 struct onode *light_onp;
65 struct onode_createparams *params;
67 { /*gator_light_create */
69 static char rn[] = "gator_light_create"; /*Routine name */
70 struct gator_light_crparams *light_params; /*My specific creation params */
71 struct gator_lightobj *light_data; /*Ptr to private data */
72 struct gwin_strparams *light_strparams; /*Light label params */
74 light_params = (struct gator_light_crparams *)params;
76 fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn,
79 "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n",
80 light_params->appearance, light_params->flashfreq,
81 light_params->label_x, light_params->label_y,
86 * Allocate the private data area, including the lower-level
87 * structure, then fill it in.
90 (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj));
91 if (light_data == (struct gator_lightobj *)0) {
93 "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n",
94 mn, rn, sizeof(struct gator_lightobj), errno);
99 (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams));
100 if (light_strparams == (struct gwin_strparams *)0) {
102 "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n",
103 mn, rn, sizeof(struct gwin_strparams), errno);
109 * Now that we have the private structures allocated, set them up.
111 light_data->setting = 0;
112 light_data->appearance = light_params->appearance;
113 light_data->flashfreq = light_params->flashfreq;
114 light_data->lasttoggletime = 0;
115 strcpy(light_data->label, light_params->label);
117 light_strparams->x = light_onp->o_x + light_params->label_x;
118 light_strparams->y = light_onp->o_y + light_params->label_y;
119 light_strparams->s = light_data->label;
120 light_strparams->highlight = 0;
121 light_data->llrock = (int *)light_strparams;
124 * Attach the private data to the onode, then return the happy news.
126 light_onp->o_data = (int *)light_data;
129 } /*gator_light_create */
131 /*------------------------------------------------------------------------
132 * gator_light_destroy
135 * Destroy a gator light object.
138 * struct onode *onp : Ptr to the light onode to delete.
142 * Error value otherwise.
145 * Nothing interesting.
149 *------------------------------------------------------------------------*/
152 gator_light_destroy(onp)
155 { /*gator_light_destroy */
158 * For now, this is a no-op.
162 } /*gator_light_destroy */
164 /*------------------------------------------------------------------------
165 * gator_light_display
168 * Display/redraw a gator light object.
171 * struct onode *onp: Ptr to the light onode to display.
175 * Error value otherwise.
178 * Light objects have a pointer to string-drawing params in the
179 * lower-level rock, with the proper highlighting set according
180 * to whether the light is on or off, so we just have to draw
181 * that string to get the proper effect.
185 *------------------------------------------------------------------------*/
188 gator_light_display(onp)
191 { /*gator_light_display */
193 static char rn[] = "gator_light_display"; /*Routine name */
194 struct gator_lightobj *light_data; /*Ptr to light obj data */
195 struct gwin_strparams *label_strparams; /*String-drawing params */
198 * Draw the label, with proper highlighting depending on whether
201 light_data = (struct gator_lightobj *)(onp->o_data);
202 label_strparams = (struct gwin_strparams *)(light_data->llrock);
204 fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n",
205 mn, rn, label_strparams->s, label_strparams->x,
207 WOP_DRAWSTRING(onp->o_window, label_strparams);
210 } /*gator_light_display */
212 /*------------------------------------------------------------------------
213 * gator_light_release
216 * Drop the refcount on a gator light object.
219 * struct onode *onp : Ptr to the onode whose refcount is
224 * Error value otherwise.
227 * Nothing interesting.
231 *------------------------------------------------------------------------*/
234 gator_light_release(onp)
237 { /*gator_light_release */
240 * For now, this is a no-op.
244 } /*gator_light_release */
246 /*------------------------------------------------------------------------
250 * Set the value of the given gator light object.
253 * struct onode *onp : Ptr to the light onode to be set.
254 * int setting : Non-zero for ``on'', zero for ``off''.
258 * Error value otherwise.
261 * We need to set not only the setting field, but the lower-
262 * level structure stored in the rock must have its highlight
263 * field set correctly.
266 * Does NOT redisplay the light object.
267 *------------------------------------------------------------------------*/
270 gator_light_set(onp, setting)
274 { /*gator_light_set */
276 static char rn[] = "gator_light_set"; /*Routine name */
277 struct gator_lightobj *light_data; /*Ptr to light obj data */
278 struct gwin_strparams *label_strparams; /*String-drawing params */
281 * Set the object correctly, then set the highlight field in
282 * the lower-level rock.
284 light_data = (struct gator_lightobj *)(onp->o_data);
285 label_strparams = (struct gwin_strparams *)(light_data->llrock);
287 fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn,
288 rn, onp, setting, (setting ? "ON" : "OFF"));
289 light_data->setting = setting;
290 label_strparams->highlight = setting;
294 } /*gator_light_set */