Added support for DE200C VFD
[lcdproc-de200c.git] / server / widget.c
blobd956b29f8bbb0473d855b0883701eee7dbabe138
1 /*
2 * widget.c
3 * This file is part of LCDd, the lcdproc server.
5 * This file is released under the GNU General Public License. Refer to the
6 * COPYING file distributed with this package.
8 * Copyright (c) 1999, William Ferrell, Scott Scriven
9 * 2002, Joris Robijn
12 * Does all actions on widgets
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <string.h>
20 #include "shared/sockets.h"
21 #include "shared/report.h"
23 #include "screen.h"
24 #include "widget.h"
25 #include "render.h"
26 #include "drivers/lcd.h"
28 char *typenames[] = {
29 "none",
30 "string",
31 "hbar",
32 "vbar",
33 "icon",
34 "title",
35 "scroller",
36 "frame",
37 "num",
38 NULL,
41 struct icontable {
42 int icon;
43 char *iconname;
44 } icontable[] = {
45 {ICON_BLOCK_FILLED, "BLOCK_FILLED"},
46 {ICON_HEART_OPEN, "HEART_OPEN"},
47 {ICON_HEART_FILLED, "HEART_FILLED"},
48 {ICON_ARROW_UP, "ARROW_UP"},
49 {ICON_ARROW_DOWN, "ARROW_DOWN"},
50 {ICON_ARROW_LEFT, "ARROW_LEFT"},
51 {ICON_ARROW_RIGHT, "ARROW_RIGHT"},
52 {ICON_CHECKBOX_OFF, "CHECKBOX_OFF"},
53 {ICON_CHECKBOX_ON, "CHECKBOX_ON"},
54 {ICON_CHECKBOX_GRAY, "CHECKBOX_GRAY"},
55 {ICON_SELECTOR_AT_LEFT, "SELECTOR_AT_LEFT"},
56 {ICON_SELECTOR_AT_RIGHT, "SELECTOR_AT_RIGHT"},
57 {ICON_ELLIPSIS, "ELLIPSIS"},
58 {ICON_STOP, "STOP"},
59 {ICON_PAUSE, "PAUSE"},
60 {ICON_PLAY, "PLAY"},
61 {ICON_PLAYR, "PLAYR"},
62 {ICON_FF, "FF"},
63 {ICON_FR, "FR"},
64 {ICON_NEXT, "NEXT"},
65 {ICON_PREV, "PREV"},
66 {ICON_REC, "REC"},
67 {0,NULL}
71 Widget *
72 widget_create(char *id, WidgetType type, Screen *screen)
74 Widget *w;
76 debug(RPT_DEBUG, "%s(id=\"%s\", type=%d, screen=[%s])", __FUNCTION__, id, type, screen->id);
78 /* Create it */
79 w = malloc(sizeof(Widget));
80 if (!w) {
81 report(RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
82 return NULL;
85 w->id = strdup(id);
86 if (!w->id) {
87 report(RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
88 return NULL;
91 w->type = type;
92 w->screen = screen;
93 w->x = 1;
94 w->y = 1;
95 w->width = 0;
96 w->height = 0;
97 w->left = 1;
98 w->top = 1;
99 w->right = 0;
100 w->bottom = 0;
101 w->length = 1;
102 w->speed = 1;
103 w->text = NULL;
104 //w->kids = NULL;
106 if (w->type == WID_FRAME) {
107 /* create a screen for the frame widget */
108 char *frame_name;
109 frame_name = malloc(strlen("frame_") + strlen(id) + 1);
110 strcpy(frame_name, "frame_");
111 strcat(frame_name, id);
113 w->frame_screen = screen_create(frame_name, screen->client);
115 free(frame_name); /* not needed anymore */
117 return w;
121 widget_destroy(Widget *w)
123 debug(RPT_DEBUG, "%s(w=[%s])", __FUNCTION__, w->id);
125 if (!w)
126 return -1;
128 if (w->id)
129 free(w->id);
130 if (w->text)
131 free(w->text);
133 /* Free subscreen of frame widget too */
134 if (w->type == WID_FRAME) {
135 screen_destroy(w->frame_screen);
138 free(w);
140 return 0;
143 WidgetType
144 widget_typename_to_type(char *typename)
146 WidgetType wid_type = WID_NONE;
147 int i;
149 for (i = 0; typenames[i]; i++) {
150 if (strcmp(typenames[i], typename) == 0) {
151 wid_type = i;
152 break; /* it's valid: skip out...*/
155 return wid_type;
158 char *
159 widget_type_to_typename(WidgetType t)
161 return typenames[t];
164 Widget *
165 widget_search_subs(Widget *w, char *id)
167 if (w->type == WID_FRAME) {
168 return screen_find_widget(w->frame_screen, id);
169 } else {
170 return NULL; /* no kids */
174 char *widget_icon_to_iconname(int icon)
176 int i;
178 for (i = 0; icontable[i].iconname; i++) {
179 if (icontable[i].icon == icon) {
180 return icontable[i].iconname;
184 return NULL;
187 int widget_iconname_to_icon(char *iconname)
189 int i;
191 for (i = 0; icontable[i].iconname; i++) {
192 if (strcasecmp(icontable[i].iconname, iconname) == 0) {
193 return icontable[i].icon;
197 return -1;