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 <afs/param.h>
17 #include <afsconfig.h>
21 #include "gtxlightobj.h" /*Interface for this module*/
22 #include <stdio.h> /*Standard I/O stuff*/
25 /*Externally-advertised array of light onode operations*/
26 struct onodeops gator_light_ops = {
32 static char mn[] = "gator_lightobject"; /*Module name*/
34 /*------------------------------------------------------------------------
38 * Create a gator light object.
41 * struct onode *light_onp : Ptr to the light onode to fill out.
42 * struct onode_createparams *params : Generic ptr to creation
47 * Error value otherwise.
50 * The base onode fields have already been set. Lights are turned
54 * Creates and initializes the light private data area, including
55 * a window string-drawing parameter structure. These areas are
56 * garbage-collected upon failure.
57 *------------------------------------------------------------------------*/
59 int gator_light_create(light_onp, params)
60 struct onode *light_onp;
61 struct onode_createparams *params;
63 { /*gator_light_create*/
65 static char rn[] = "gator_light_create"; /*Routine name*/
66 struct gator_light_crparams *light_params; /*My specific creation params*/
67 struct gator_lightobj *light_data; /*Ptr to private data*/
68 struct gwin_strparams *light_strparams; /*Light label params*/
70 light_params = (struct gator_light_crparams *)params;
72 fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn, rn);
73 fprintf(stderr, "\tAppearance: %d, flashfreq: %d, label at offset (%d, %d): '%s'\n", light_params->appearance, light_params->flashfreq, light_params->label_x, light_params->label_y, light_params->label);
77 * Allocate the private data area, including the lower-level
78 * structure, then fill it in.
80 light_data = (struct gator_lightobj *)malloc(sizeof(struct gator_lightobj));
81 if (light_data == (struct gator_lightobj *)0) {
82 fprintf(stderr, "[%s:%s] Can't allocate %d bytes for light object private data region, errno is %d\n", mn, rn, sizeof(struct gator_lightobj), errno);
86 light_strparams = (struct gwin_strparams *)malloc(sizeof(struct gwin_strparams));
87 if (light_strparams == (struct gwin_strparams *)0) {
88 fprintf(stderr, "[%s:%s] Can't allocate %d bytes for light object label in private data region, errno is %d\n", mn, rn, sizeof(struct gwin_strparams), errno);
94 * Now that we have the private structures allocated, set them up.
96 light_data->setting = 0;
97 light_data->appearance = light_params->appearance;
98 light_data->flashfreq = light_params->flashfreq;
99 light_data->lasttoggletime = 0;
100 strcpy(light_data->label, light_params->label);
102 light_strparams->x = light_onp->o_x + light_params->label_x;
103 light_strparams->y = light_onp->o_y + light_params->label_y;
104 light_strparams->s = light_data->label;
105 light_strparams->highlight = 0;
106 light_data->llrock = (int *)light_strparams;
109 * Attach the private data to the onode, then return the happy news.
111 light_onp->o_data = (int *)light_data;
114 } /*gator_light_create*/
116 /*------------------------------------------------------------------------
117 * gator_light_destroy
120 * Destroy a gator light object.
123 * struct onode *onp : Ptr to the light onode to delete.
127 * Error value otherwise.
130 * Nothing interesting.
134 *------------------------------------------------------------------------*/
136 int gator_light_destroy(onp)
139 { /*gator_light_destroy*/
142 * For now, this is a no-op.
146 } /*gator_light_destroy*/
148 /*------------------------------------------------------------------------
149 * gator_light_display
152 * Display/redraw a gator light object.
155 * struct onode *onp: Ptr to the light onode to display.
159 * Error value otherwise.
162 * Light objects have a pointer to string-drawing params in the
163 * lower-level rock, with the proper highlighting set according
164 * to whether the light is on or off, so we just have to draw
165 * that string to get the proper effect.
169 *------------------------------------------------------------------------*/
171 int gator_light_display(onp)
174 { /*gator_light_display*/
176 static char rn[] = "gator_light_display"; /*Routine name*/
177 struct gator_lightobj *light_data; /*Ptr to light obj data*/
178 struct gwin_strparams *label_strparams; /*String-drawing params*/
181 * Draw the label, with proper highlighting depending on whether
184 light_data = (struct gator_lightobj *)(onp->o_data);
185 label_strparams = (struct gwin_strparams *)(light_data->llrock);
187 fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n", mn, rn, label_strparams->s, label_strparams->x, label_strparams->y);
188 WOP_DRAWSTRING(onp->o_window, label_strparams);
191 } /*gator_light_display*/
193 /*------------------------------------------------------------------------
194 * gator_light_release
197 * Drop the refcount on a gator light object.
200 * struct onode *onp : Ptr to the onode whose refcount is
205 * Error value otherwise.
208 * Nothing interesting.
212 *------------------------------------------------------------------------*/
214 int gator_light_release(onp)
217 { /*gator_light_release*/
220 * For now, this is a no-op.
224 } /*gator_light_release*/
226 /*------------------------------------------------------------------------
230 * Set the value of the given gator light object.
233 * struct onode *onp : Ptr to the light onode to be set.
234 * int setting : Non-zero for ``on'', zero for ``off''.
238 * Error value otherwise.
241 * We need to set not only the setting field, but the lower-
242 * level structure stored in the rock must have its highlight
243 * field set correctly.
246 * Does NOT redisplay the light object.
247 *------------------------------------------------------------------------*/
249 int gator_light_set(onp, setting)
253 { /*gator_light_set*/
255 static char rn[] = "gator_light_set"; /*Routine name*/
256 struct gator_lightobj *light_data; /*Ptr to light obj data*/
257 struct gwin_strparams *label_strparams; /*String-drawing params*/
260 * Set the object correctly, then set the highlight field in
261 * the lower-level rock.
263 light_data = (struct gator_lightobj *)(onp->o_data);
264 label_strparams = (struct gwin_strparams *)(light_data->llrock);
266 fprintf(stderr, "[%s:%s] Setting light object at 0x%x to %d (%s)", mn, rn, onp, setting, (setting? "ON" : "OFF"));
267 light_data->setting = setting;
268 label_strparams->highlight = setting;
272 } /*gator_light_set*/