Files
lcdproc/server/widget.c
T

151 lines
2.6 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
*
*
* Does widget management
*
*/
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"
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
//static widget *widget_finder (LinkedList * list, char *id);
//static int widget_remover (LinkedList * list, widget * w);
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
report (RPT_INFO, "widget_create(%s,%d)", id, type);
/* Create it */
w = malloc (sizeof (Widget));
2000-04-03 22:13:57 +00:00
if (!w) {
report (RPT_DEBUG, "widget_create: Error allocating");
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, "widget_create: Error allocating");
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_INFO, "widget_destroy(%s)", 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);
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "widget_destroy: id...");*/
2000-04-03 22:13:57 +00:00
if (w->text)
free (w->text);
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "widget_destroy: text...");*/
1999-12-09 23:15:14 +00:00
if (w->type == WID_FRAME) {
/* TODO: create a screen for the frame widget */
}
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);
2001-12-30 00:15:25 +00:00
/*debug(RPT_DEBUG, "widget_destroy: widget...");*/
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
}