Files
lcdproc/server/widget.c
T

199 lines
3.5 KiB
C
Raw Normal View History

/*
* widget.c
* This file is part of LCDd, the lcdproc server.
*
* This file is released under the GNU General Public License. Refer to the
* COPYING file distributed with this package.
*
* Copyright (c) 1999, William Ferrell, Scott Scriven
2002-05-26 19:21:23 +00:00
* 2002, Joris Robijn
*
*
2002-05-26 19:21:23 +00:00
* Does all actions on widgets
*
*/
1999-12-09 23:15:14 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "shared/sockets.h"
2001-11-29 14:09:13 +00:00
#include "shared/report.h"
1999-12-09 23:15:14 +00:00
#include "screen.h"
#include "widget.h"
#include "render.h"
#include "drivers/lcd.h"
1999-12-09 23:15:14 +00:00
char *typenames[] = {
"none",
2000-04-03 22:13:57 +00:00
"string",
"hbar",
"vbar",
"icon",
"title",
"scroller",
"frame",
"num",
NULL,
};
1999-12-09 23:15:14 +00:00
struct icontable {
int icon;
char *iconname;
} icontable[] = {
{ICON_BLOCK_FILLED, "BLOCK_FILLED"},
{ICON_HEART_OPEN, "HEART_OPEN"},
{ICON_HEART_FILLED, "HEART_FILLED"},
{ICON_ARROW_UP, "ARROW_UP"},
{ICON_ARROW_DOWN, "ARROW_DOWN"},
{ICON_ARROW_LEFT, "ARROW_LEFT"},
{ICON_ARROW_RIGHT, "ARROW_RIGHT"},
2002-05-23 18:03:36 +00:00
{ICON_CHECKBOX_OFF, "CHECKBOX_OFF"},
{ICON_CHECKBOX_ON, "CHECKBOX_ON"},
{ICON_CHECKBOX_GRAY, "CHECKBOX_GRAY"},
{ICON_SELECTOR_AT_LEFT, "SELECTOR_AT_LEFT"},
{ICON_SELECTOR_AT_RIGHT, "SELECTOR_AT_RIGHT"},
{ICON_ELLIPSIS, "ELLIPSIS"},
{ICON_PAUSE, "PAUSE"},
{ICON_PLAY, "PLAY"},
{ICON_PLAYR, "PLAYR"},
{ICON_FF, "FF"},
{ICON_FR, "FR"},
{ICON_NEXT, "NEXT"},
{ICON_PREV, "PREV"},
{ICON_REC, "REC"},
{0,NULL}
};
Widget *
widget_create (char *id, WidgetType type, Screen * screen)
1999-12-09 23:15:14 +00:00
{
Widget * w;
1999-12-09 23:15:14 +00:00
debug (RPT_DEBUG, "%s( id=\"%s\", type=%d, screen=[%s] )", __FUNCTION__, id, type, screen->id );
/* Create it */
w = malloc (sizeof (Widget));
2000-04-03 22:13:57 +00:00
if (!w) {
report (RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
2000-04-03 22:13:57 +00:00
return NULL;
}
1999-12-09 23:15:14 +00:00
w->id = strdup(id);
if (!w->id) {
report (RPT_DEBUG, "%s: Error allocating", __FUNCTION__);
return NULL;
}
w->type = type;
w->screen = screen;
2000-04-03 22:13:57 +00:00
w->x = 1;
w->y = 1;
w->width = 0;
w->height = 0;
2000-04-03 22:13:57 +00:00
w->left = 1;
w->top = 1;
w->right = 0;
w->bottom = 0;
w->length = 1;
w->speed = 1;
w->text = NULL;
//w->kids = NULL;
if (w->type == WID_FRAME) {
/* create a screen for the frame widget */
char * frame_name;
frame_name = malloc (strlen("frame_") + strlen(id) + 1);
strcpy (frame_name, "frame_");
strcat (frame_name, id);
w->frame_screen = screen_create (frame_name, screen->client);
free (frame_name); /* not needed anymore */
}
2000-04-03 22:13:57 +00:00
return w;
1999-12-09 23:15:14 +00:00
}
int
widget_destroy (Widget * w)
1999-12-09 23:15:14 +00:00
{
debug (RPT_DEBUG, "%s( w=[%s] )", __FUNCTION__, w->id);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
if (!w)
return -1;
2000-04-03 22:13:57 +00:00
if (w->id)
free (w->id);
if (w->text)
free (w->text);
1999-12-09 23:15:14 +00:00
/* Free subscreen of frame widget too */
if (w->type == WID_FRAME) {
screen_destroy (w->frame_screen);
2000-04-03 22:13:57 +00:00
}
2000-04-03 22:13:57 +00:00
free (w);
1999-12-09 23:15:14 +00:00
2000-04-03 22:13:57 +00:00
return 0;
1999-12-09 23:15:14 +00:00
}
WidgetType
widget_typename_to_type (char * typename)
1999-12-09 23:15:14 +00:00
{
WidgetType wid_type = WID_NONE;
2000-04-03 22:13:57 +00:00
int i;
1999-12-09 23:15:14 +00:00
for (i = 0; typenames[i]; i++) {
if (strcmp (typenames[i], typename) == 0) {
2000-04-03 22:13:57 +00:00
wid_type = i;
2001-12-30 00:15:25 +00:00
break; /* it's valid: skip out...*/
2000-04-03 22:13:57 +00:00
}
}
return wid_type;
}
char *
widget_type_to_typename (WidgetType t)
{
return typenames[t];
}
1999-12-09 23:15:14 +00:00
Widget *
widget_search_subs (Widget * w, char * id)
{
2000-04-03 22:13:57 +00:00
if (w->type == WID_FRAME) {
return screen_find_widget (w->frame_screen, id);
} else {
return NULL; /* no kids */
2000-04-03 22:13:57 +00:00
}
1999-12-09 23:15:14 +00:00
}
char *widget_icon_to_iconname (int icon)
{
int i;
for (i=0; icontable[i].iconname; i++) {
if (icontable[i].icon == icon) {
return icontable[i].iconname;
}
}
return NULL;
}
int widget_iconname_to_icon (char *iconname)
{
int i;
for (i=0; icontable[i].iconname; i++) {
if (strcasecmp( icontable[i].iconname, iconname) == 0) {
return icontable[i].icon;
}
}
return -1;
}