summaryrefslogtreecommitdiff
path: root/libtemplate/templateviewlist.c
blob: 808a89fbf21bd7aab4f059a3c281b5f8deee0061 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "templateviewlist.h"
#include "../config.h"

cTemplateViewList::cTemplateViewList(void) : cTemplateViewElement() {
    listElement = NULL;
    currentElement = NULL;
}

cTemplateViewList::~cTemplateViewList(void) {
    if (listElement)
        delete listElement;
    if (currentElement)
        delete currentElement;
}

void cTemplateViewList::SetGlobals(cGlobals *globals) { 
    cTemplateViewElement::SetGlobals(globals);
    if (listElement)
        listElement->SetGlobals(globals);
    if (currentElement)
        currentElement->SetGlobals(globals);
}

bool cTemplateViewList::CalculateListParameters(void) {
    if (!parameters)
        return false;
    parameters->SetContainer(containerX, containerY, containerWidth, containerHeight);
    parameters->SetGlobals(globals);
    bool paramsValid = parameters->CalculateParameters();
    if (!listElement)
        return false;
    listElement->SetContainer(parameters->GetNumericParameter(ptX),
                              parameters->GetNumericParameter(ptY),
                              parameters->GetNumericParameter(ptWidth), 
                              parameters->GetNumericParameter(ptHeight));
    paramsValid = listElement->CalculateParameters();
    paramsValid = listElement->CalculatePixmapParametersList(parameters->GetNumericParameter(ptOrientation), 
                                                             parameters->GetNumericParameter(ptNumElements));
    if (!currentElement)
        return paramsValid;
    currentElement->SetContainer(parameters->GetNumericParameter(ptX),
                                 parameters->GetNumericParameter(ptY),
                                 parameters->GetNumericParameter(ptWidth), 
                                 parameters->GetNumericParameter(ptHeight));
    paramsValid = currentElement->CalculateParameters();
    paramsValid = currentElement->CalculatePixmapParameters();
    currentElement->SetPixOffset(0);
    return paramsValid;
}

bool cTemplateViewList::CalculateListParameters(map < string, int > *intTokens) {
    if (!parameters)
        return false;
    parameters->ClearDynamicParameters();
    parameters->SetIntTokens(intTokens);
    parameters->ParseParameters();
    parameters->UnsetIntTokens();

    listElement->SetContainer(parameters->GetNumericParameter(ptX),
                              parameters->GetNumericParameter(ptY),
                              parameters->GetNumericParameter(ptWidth), 
                              parameters->GetNumericParameter(ptHeight));
    bool paramsValid = listElement->CalculateParameters();
    paramsValid = listElement->CalculatePixmapParametersList(parameters->GetNumericParameter(ptOrientation), 
                                                             parameters->GetNumericParameter(ptNumElements));
    return paramsValid;
}

int cTemplateViewList::GetAverageFontWidth(void) {
    int defaultAverageFontWidth = 20;

    if (!listElement)
        return defaultAverageFontWidth;

    int numItems = GetNumericParameter(ptNumElements);
    int listHeight = GetNumericParameter(ptHeight);
    if (listHeight <= 0)
        return defaultAverageFontWidth;
    int itemHeight = (double)listHeight / (double)numItems;
    string fontFuncName = parameters->GetParameter(ptDeterminateFont);

    cTemplateFunction *fontFunc = listElement->GetFunction(fontFuncName);
    if (!fontFunc)
        return defaultAverageFontWidth;

    string fontNameToken = fontFunc->GetParameter(ptFont);
    string paramFontSize = fontFunc->GetParameter(ptFontSize);

    string fontName = "";
    if ((fontNameToken.find("{") == 0) && (fontNameToken.find("}") == (fontNameToken.size()-1))) {
        fontNameToken = fontNameToken.substr(1, fontNameToken.size()-2);
        map<string,string>::iterator hit = globals->fonts.find(fontNameToken);
        if (hit != globals->fonts.end()) {
            fontName = hit->second;
        } else {
            map<string,string>::iterator def = globals->fonts.find("vdrOsd");
            if (def == globals->fonts.end())
                return defaultAverageFontWidth;
            fontName = def->second;
        }
    } else {
        //if no token, directly use input
        fontName = fontNameToken;
    }

    cNumericParameter pFontSize(paramFontSize);
    pFontSize.SetGlobals(globals);
    pFontSize.SetAreaSize(1000, itemHeight);
    pFontSize.SetVertical();
    int fontSize = pFontSize.Parse(paramFontSize);
    if (!pFontSize.Valid())
        return defaultAverageFontWidth;

    int averageFontWidth = fontManager->Width(fontName, fontSize, "x") + 3;
    return averageFontWidth;
}

int cTemplateViewList::GetMenuItemWidth(void) {
    return GetNumericParameter(ptMenuItemWidth);    
}


int cTemplateViewList::GetNumPixmaps(void) {
    if (!listElement)
        return 0;
    return listElement->GetNumPixmaps();
}

void cTemplateViewList::Debug(void) {
    if (parameters)
        parameters->Debug();
    esyslog("skindesigner: --- listelement: ");
    if (listElement)
        listElement->Debug();
    esyslog("skindesigner: --- currentelement: ");
    if (currentElement)
        currentElement->Debug();
}