Merge 1.8.0~pre4 packaging into master
[pkg-k5-afs_openafs.git] / src / gtx / lightobject.c
blob92cd03c9f042095d7bc166a9f72a52b162b70e00
1 /*
2 * Copyright 2000, International Business Machines Corporation and others.
3 * All Rights Reserved.
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
8 */
11 * Description:
12 * Implementation of the gator light object.
14 *------------------------------------------------------------------------*/
16 #include <afsconfig.h>
17 #include <afs/param.h>
19 #include <roken.h>
21 #include "gtxlightobj.h" /*Interface for this module */
23 /*Externally-advertised array of light onode operations*/
24 struct onodeops gator_light_ops = {
25 gator_light_destroy,
26 gator_light_display,
27 gator_light_release
30 static char mn[] = "gator_lightobject"; /*Module name */
32 /*------------------------------------------------------------------------
33 * gator_light_create
35 * Description:
36 * Create a gator light object.
38 * Arguments:
39 * struct onode *light_onp : Ptr to the light onode to fill out.
40 * struct onode_createparams *params : Generic ptr to creation
41 * parameters.
43 * Returns:
44 * Zero if successful,
45 * Error value otherwise.
47 * Environment:
48 * The base onode fields have already been set. Lights are turned
49 * off at creation.
51 * Side Effects:
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 *------------------------------------------------------------------------*/
57 int
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;
67 if (objects_debug) {
68 fprintf(stderr, "[%s:%s] Private data passed to light object:\n", mn,
69 rn);
70 fprintf(stderr,
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,
74 light_params->label);
78 * Allocate the private data area, including the lower-level
79 * structure, then fill it in.
81 light_data = malloc(sizeof(struct gator_lightobj));
82 if (light_data == (struct gator_lightobj *)0) {
83 fprintf(stderr,
84 "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object private data region, errno is %d\n",
85 mn, rn, sizeof(struct gator_lightobj), errno);
86 return (errno);
89 light_strparams = malloc(sizeof(struct gwin_strparams));
90 if (light_strparams == (struct gwin_strparams *)0) {
91 fprintf(stderr,
92 "[%s:%s] Can't allocate %" AFS_SIZET_FMT " bytes for light object label in private data region, errno is %d\n",
93 mn, rn, sizeof(struct gwin_strparams), errno);
94 free(light_data);
95 return (errno);
99 * Now that we have the private structures allocated, set them up.
101 light_data->setting = 0;
102 light_data->appearance = light_params->appearance;
103 light_data->flashfreq = light_params->flashfreq;
104 light_data->lasttoggletime = 0;
105 strcpy(light_data->label, light_params->label);
107 light_strparams->x = light_onp->o_x + light_params->label_x;
108 light_strparams->y = light_onp->o_y + light_params->label_y;
109 light_strparams->s = light_data->label;
110 light_strparams->highlight = 0;
111 light_data->llrock = (int *)light_strparams;
114 * Attach the private data to the onode, then return the happy news.
116 light_onp->o_data = (int *)light_data;
117 return (0);
119 } /*gator_light_create */
121 /*------------------------------------------------------------------------
122 * gator_light_destroy
124 * Description:
125 * Destroy a gator light object.
127 * Arguments:
128 * struct onode *onp : Ptr to the light onode to delete.
130 * Returns:
131 * 0: Success
132 * Error value otherwise.
134 * Environment:
135 * Nothing interesting.
137 * Side Effects:
138 * As advertised.
139 *------------------------------------------------------------------------*/
142 gator_light_destroy(struct onode *onp)
143 { /*gator_light_destroy */
146 * For now, this is a no-op.
148 return (0);
150 } /*gator_light_destroy */
152 /*------------------------------------------------------------------------
153 * gator_light_display
155 * Description:
156 * Display/redraw a gator light object.
158 * Arguments:
159 * struct onode *onp: Ptr to the light onode to display.
161 * Returns:
162 * 0: Success
163 * Error value otherwise.
165 * Environment:
166 * Light objects have a pointer to string-drawing params in the
167 * lower-level rock, with the proper highlighting set according
168 * to whether the light is on or off, so we just have to draw
169 * that string to get the proper effect.
171 * Side Effects:
172 * As advertised.
173 *------------------------------------------------------------------------*/
176 gator_light_display(struct onode *onp)
177 { /*gator_light_display */
179 static char rn[] = "gator_light_display"; /*Routine name */
180 struct gator_lightobj *light_data; /*Ptr to light obj data */
181 struct gwin_strparams *label_strparams; /*String-drawing params */
184 * Draw the label, with proper highlighting depending on whether
185 * the light is on.
187 light_data = (struct gator_lightobj *)(onp->o_data);
188 label_strparams = (struct gwin_strparams *)(light_data->llrock);
189 if (objects_debug)
190 fprintf(stderr, "[%s:%s] Printing out light label '%s' at (%d, %d)\n",
191 mn, rn, label_strparams->s, label_strparams->x,
192 label_strparams->y);
193 WOP_DRAWSTRING(onp->o_window, label_strparams);
194 return (0);
196 } /*gator_light_display */
198 /*------------------------------------------------------------------------
199 * gator_light_release
201 * Description:
202 * Drop the refcount on a gator light object.
204 * Arguments:
205 * struct onode *onp : Ptr to the onode whose refcount is
206 * to be dropped.
208 * Returns:
209 * 0: Success
210 * Error value otherwise.
212 * Environment:
213 * Nothing interesting.
215 * Side Effects:
216 * As advertised.
217 *------------------------------------------------------------------------*/
220 gator_light_release(struct onode *onp)
221 { /*gator_light_release */
224 * For now, this is a no-op.
226 return (0);
228 } /*gator_light_release */
230 /*------------------------------------------------------------------------
231 * gator_light_set
233 * Description:
234 * Set the value of the given gator light object.
236 * Arguments:
237 * struct onode *onp : Ptr to the light onode to be set.
238 * int setting : Non-zero for ``on'', zero for ``off''.
240 * Returns:
241 * 0: Success
242 * Error value otherwise.
244 * Environment:
245 * We need to set not only the setting field, but the lower-
246 * level structure stored in the rock must have its highlight
247 * field set correctly.
249 * Side Effects:
250 * Does NOT redisplay the light object.
251 *------------------------------------------------------------------------*/
254 gator_light_set(struct onode *onp, int setting)
255 { /*gator_light_set */
257 static char rn[] = "gator_light_set"; /*Routine name */
258 struct gator_lightobj *light_data; /*Ptr to light obj data */
259 struct gwin_strparams *label_strparams; /*String-drawing params */
262 * Set the object correctly, then set the highlight field in
263 * the lower-level rock.
265 light_data = (struct gator_lightobj *)(onp->o_data);
266 label_strparams = (struct gwin_strparams *)(light_data->llrock);
267 if (objects_debug)
268 fprintf(stderr, "[%s:%s] Setting light object at %p to %d (%s)", mn,
269 rn, onp, setting, (setting ? "ON" : "OFF"));
270 light_data->setting = setting;
271 label_strparams->highlight = setting;
273 return (0);
275 } /*gator_light_set */