#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include "theme.h"
#include "lexer/theme-parser.h"
#include "helper.h"
#include "settings.h"
#include "widgets/textbox.h"
#include "view.h"
/** Logging domain for theme */
#define LOG_DOMAIN "Theme"
void yyerror ( YYLTYPE *ylloc, const char *);
static gboolean distance_compare ( Distance d, Distance e )
{
return ( d.type == e.type && d.distance == e.distance && d.style == e.style );
}
ThemeWidget *rofi_theme_find_or_create_name ( ThemeWidget *base, const char *name )
{
for ( unsigned int i = 0; i < base->num_widgets;i++){
if ( g_strcmp0(base->widgets[i]->name, name) == 0 ){
return base->widgets[i];
}
}
base->widgets = g_realloc ( base->widgets, sizeof(ThemeWidget*)*(base->num_widgets+1));
base->widgets[base->num_widgets] = g_malloc0(sizeof(ThemeWidget));
ThemeWidget *retv = base->widgets[base->num_widgets];
retv->parent = base;
retv->name = g_strdup(name);
base->num_widgets++;
return retv;
}
/**
* Properties
*/
Property *rofi_theme_property_create ( PropertyType type )
{
Property *retv = g_malloc0 ( sizeof(Property) );
retv->type = type;
return retv;
}
void rofi_theme_property_free ( Property *p )
{
if ( p == NULL ) {
return;
}
g_free ( p->name );
if ( p->type == P_STRING ) {
g_free ( p->value.s );
} else if ( p->type == P_LINK ) {
g_free ( p->value.link.name );
}
g_free(p);
}
void rofi_theme_free ( ThemeWidget *widget )
{
if ( widget == NULL ){
return;
}
if ( widget->properties ) {
g_hash_table_destroy ( widget->properties );
}
for ( unsigned int i = 0; i < widget->num_widgets; i++ ){
rofi_theme_free ( widget->widgets[i] );
}
g_free ( widget->widgets );
g_free ( widget->name );
g_free ( widget );
}
/**
* print
*/
static void rofi_theme_print_distance ( Distance d )
{
if ( d.type == PW_PX ) {
printf("%upx ", (int)d.distance );
} else if ( d.type == PW_PERCENT ) {
printf("%f%% ", d.distance );
} else {
printf("%fem ", d.distance );
}
if ( d.style == DASH ) {
printf("dash ");
}
}
static void rofi_theme_print_property_index ( int depth, Property *p )
{
printf("%*s%s: ", depth, "", p->name );
switch ( p->type )
{
case P_POSITION:
// TODO Name
printf("%d;", p->value.i);
break;
case P_STRING:
printf("\"%s\";", p->value.s);
break;
case P_INTEGER:
printf("%d;", p->value.i);
break;
case P_DOUBLE:
printf("%.2f;", p->value.f);
break;
case P_BOOLEAN:
printf("%s;", p->value.b?"true":"false");
break;
case P_COLOR:
printf("#%02X%02X%02X%02X;",
(unsigned char)(p->value.color.alpha*255.0),
(unsigned char)(p->value.color.red*255.0),
(unsigned char)(p->value.color.green*255.0),
(unsigned char)(p->value.color.blue*255.0));
break;
case P_PADDING:
if ( distance_compare ( p->value.padding.top, p->value.padding.bottom) &&
distance_compare ( p->value.padding.left, p->value.padding.right<