From 9e6804e49cac8d859b899ae49509ffdf347eda7f Mon Sep 17 00:00:00 2001 From: reinelt Date: Sun, 13 Aug 2006 11:38:20 +0000 Subject: [lcd4linux @ 2006-08-13 11:38:20 by reinelt] text widget uses dynamic properties git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@691 3ae390bd-cb1e-0410-b409-cd5a39f66f1f --- property.c | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'property.c') diff --git a/property.c b/property.c index b2302ba..d465275 100644 --- a/property.c +++ b/property.c @@ -1,4 +1,4 @@ -/* $Id: property.c,v 1.1 2006/08/13 09:53:10 reinelt Exp $ +/* $Id: property.c,v 1.2 2006/08/13 11:38:20 reinelt Exp $ * * dynamic properties * @@ -23,6 +23,9 @@ * * * $Log: property.c,v $ + * Revision 1.2 2006/08/13 11:38:20 reinelt + * text widget uses dynamic properties + * * Revision 1.1 2006/08/13 09:53:10 reinelt * dynamic properties added (used by 'style' of text widget) * @@ -38,6 +41,8 @@ * void property_free (PROPERTY *prop) * frees all property allocations * + * int property_eval(PROPERTY * prop) + * evaluates a property; returns 1 if value has changed * * double P2N(PROPERTY * prop) * returns a (already evaluated) property as number @@ -84,12 +89,38 @@ void property_load(const char *section, const char *name, const char *defval, PR } -void property_eval(PROPERTY * prop) +int property_eval(PROPERTY * prop) { - if (prop->compiled != NULL) { - DelResult(&prop->result); - Eval(prop->compiled, &prop->result); + RESULT old; + int update = 1; + + /* this is a bit ugly: we need to remember the old value */ + + old.type = prop->result.type; + old.size = prop->result.size; + old.number = prop->result.number; + old.string = prop->result.string != NULL ? strdup(prop->result.string) : NULL; + + DelResult(&prop->result); + Eval(prop->compiled, &prop->result); + + if (prop->result.type & R_NUMBER && old.type & R_NUMBER && prop->result.number == old.number) { + update = 0; } + + if (prop->result.type & R_STRING && old.type & R_STRING && prop->result.size == old.size) { + if (prop->result.string == NULL && old.string == NULL) { + update = 0; + } + else if (prop->result.string != NULL && old.string != NULL && strcmp(prop->result.string, old.string) == 0) { + update = 0; + } + } + + if (old.string) + free (old.string); + + return update; } -- cgit v1.2.3