~ubuntu-branches/ubuntu/trusty/lcd4linux/trusty-proposed

« back to all changes in this revision

Viewing changes to widget.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2006-08-27 17:16:46 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20060827171646-j63wpiogypbaik7a
* New Maintainer! 
* Dropping old maintainer in agreement with nobse@debian.org. 
  Thanks for your work so far, nobse!
* urgency medium because of release critical bugs
* Bump standards version to 3.7.2 (no changes needed)
* add build depends on libmpd-dev for mpd support
* new upstream snapshot
* drop dependency of ${misc:Depends}, not used anyway
* now supporting USB2LCD
* don't update config.{sub,guess} in clean target automatically
* new target ``update-config-sub-guess'' to update config.{sub,guess}
* Acking NMU, Thanks Steinar! (Closes: #374682)
* Bug fix: "FTBFS: undefined reference to many X functions", thanks to
  Eric Dorland. The problem was in driver.m4 (Closes: #381606).
* Bug fix: "Please stop Build-Depending on automake", thanks to Eric
  Dorland (Closes: #381812).
* Don't ship /etc/lcd4linux.conf anymore. Please install and customize 
  it yourself using /usr/share/doc/lcd4linux.conf.sample as template
* Bug fix: "lcd4linux - FTBFS: uses ia32 assembler", thanks to Bastian
  Blank. Fixed by adding #ifdefs to produce those asm statements on i386
  and amd64 only. (Closes: #336017).
* Removing outdated NEWS, FAQ, README.KDE on upstream request.
* Install manpage for lcd4linux

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: widget.c,v 1.19 2005/05/08 04:32:45 reinelt Exp $
 
1
/* $Id: widget.c,v 1.26 2006/08/09 17:25:34 harbaum Exp $
2
2
 *
3
3
 * generic widget handling
4
4
 *
21
21
 *
22
22
 *
23
23
 * $Log: widget.c,v $
 
24
 * Revision 1.26  2006/08/09 17:25:34  harbaum
 
25
 * Better bar color support and new bold font
 
26
 *
 
27
 * Revision 1.25  2006/08/08 20:16:29  harbaum
 
28
 * Added "extracolor" (used for e.g. bar border) and RGB support for LEDMATRIX
 
29
 *
 
30
 * Revision 1.24  2006/08/08 19:28:18  reinelt
 
31
 * widget type checking corrected
 
32
 *
 
33
 * Revision 1.23  2006/02/21 05:50:34  reinelt
 
34
 * keypad support from Cris Maj
 
35
 *
 
36
 * Revision 1.22  2006/01/30 05:47:38  reinelt
 
37
 * graphic subsystem changed to full-color RGBA
 
38
 *
 
39
 * Revision 1.21  2005/12/18 16:18:36  reinelt
 
40
 * GPO's added again
 
41
 *
 
42
 * Revision 1.20  2005/11/06 09:17:20  reinelt
 
43
 * re-use icons (thanks to Jesus de Santos Garcia)
 
44
 *
24
45
 * Revision 1.19  2005/05/08 04:32:45  reinelt
25
46
 * CodingStyle added and applied
26
47
 *
165
186
    int i;
166
187
    for (i = 0; i < nWidgets; i++) {
167
188
        Widgets[i].class->quit(&(Widgets[i]));
 
189
        if (Widgets[i].name)
 
190
            free(Widgets[i].name);
168
191
    }
169
192
    free(Widgets);
170
193
 
174
197
    nClasses = 0;
175
198
}
176
199
 
177
 
int widget_add(const char *name, const int row, const int col)
 
200
int widget_color(const char *section, const char *name, const char *key, RGBA * C)
 
201
{
 
202
    char *color;
 
203
 
 
204
    C->R = 0;
 
205
    C->G = 0;
 
206
    C->B = 0;
 
207
    C->A = 0;
 
208
 
 
209
    color = cfg_get(section, key, NULL);
 
210
 
 
211
    if (color == NULL)
 
212
        return 0;
 
213
 
 
214
    if (*color == '\0') {
 
215
        free(color);
 
216
        return 0;
 
217
    }
 
218
 
 
219
    if (color2RGBA(color, C) < 0) {
 
220
        error("widget '%s': ignoring illegal %s color '%s'", name, key, color);
 
221
        free(color);
 
222
        return 0;
 
223
    }
 
224
    free(color);
 
225
    return 1;
 
226
}
 
227
 
 
228
int widget_add(const char *name, const int type, const int layer, const int row, const int col)
178
229
{
179
230
    int i;
180
231
    char *section;
181
232
    char *class;
 
233
    int fg_valid, bg_valid;
 
234
    RGBA FG, BG;
182
235
 
183
236
    WIDGET_CLASS *Class;
184
237
    WIDGET *Widget;
 
238
    WIDGET *Parent;
185
239
 
186
240
    /* prepare config section */
187
241
    /* strlen("Widget:")=7 */
195
249
        error("error: widget '%s' has no class!", name);
196
250
        if (class)
197
251
            free(class);
 
252
        free(section);
198
253
        return -1;
199
254
    }
 
255
 
 
256
    /* get widget foreground color */
 
257
    fg_valid = widget_color(section, name, "foreground", &FG);
 
258
    bg_valid = widget_color(section, name, "background", &BG);
 
259
 
200
260
    free(section);
 
261
 
201
262
    /* lookup widget class */
202
263
    Class = NULL;
203
264
    for (i = 0; i < nClasses; i++) {
212
273
            free(class);
213
274
        return -1;
214
275
    }
 
276
 
 
277
    /* check if widget type matches */
 
278
    if (Class->type != type) {
 
279
        error("widget '%s': class '%s' not applicable", name, class);
 
280
        free(class);
 
281
        return -1;
 
282
    }
 
283
 
215
284
    if (class)
216
285
        free(class);
217
286
 
 
287
 
218
288
    /* do NOT use realloc here because there may be pointers to the old */
219
289
    /* memory area, which would point to nowhere if realloc moves the area */
220
290
    if (Widgets == NULL) {
231
301
        return -1;
232
302
    }
233
303
 
 
304
    /* look up parent widget (widget with the same name) */
 
305
    Parent = NULL;
 
306
    for (i = 0; i < nWidgets; i++) {
 
307
        if (strcmp(name, Widgets[i].name) == 0) {
 
308
            Parent = &(Widgets[i]);
 
309
            break;
 
310
        }
 
311
    }
 
312
 
234
313
    Widget = &(Widgets[nWidgets]);
235
314
    nWidgets++;
236
315
 
237
 
    Widget->name = (char *) name;
 
316
    Widget->name = strdup(name);
238
317
    Widget->class = Class;
 
318
    Widget->parent = Parent;
 
319
    Widget->fg_color = FG;
 
320
    Widget->bg_color = BG;
 
321
    Widget->fg_valid = fg_valid;
 
322
    Widget->bg_valid = bg_valid;
 
323
    Widget->layer = layer;
239
324
    Widget->row = row;
240
325
    Widget->col = col;
241
326
 
242
 
    if (Class->init != 0) {
 
327
    if (Class->init != NULL) {
243
328
        Class->init(Widget);
244
329
    }
245
330
 
246
331
    return 0;
247
332
}
 
333
 
 
334
/* return the found widget, or else NULL */
 
335
WIDGET *widget_find(int type, void *needle)
 
336
{
 
337
    WIDGET *widget = NULL;
 
338
    int i;
 
339
 
 
340
    for (i = 0; i < nWidgets; i++) {
 
341
        widget = &(Widgets[i]);
 
342
        if (widget->class->type == type) {
 
343
            if (widget->class->find != NULL && widget->class->find(widget, needle) == 0)
 
344
                break;
 
345
        }
 
346
        widget = NULL;
 
347
    }
 
348
 
 
349
    return widget;
 
350
}