source: titan/titan/choicebox.h @ 27845

Last change on this file since 27845 was 23664, checked in by nit, 11 years ago

[titan] fix

File size: 2.7 KB
Line 
1#ifndef CHOICEBOX_H
2#define CHOICEBOX_H
3
4int addchoicebox(struct skin* choicebox, char* value, char* text)
5{
6        char* tmp = NULL;
7
8        if(choicebox == NULL || value == NULL || text == NULL || strlen(value) == 0)
9        {
10                err("NULL detect");
11                return 1;
12        }
13
14        if(choicebox->input == NULL || choicebox->choiceboxvalue == NULL)
15        {
16                changeinput(choicebox, NULL);
17                changechoiceboxvalue(choicebox, NULL);
18                tmp = ostrcat(tmp, text, 1, 0);
19                changeinput(choicebox, tmp);
20                free(tmp); tmp = NULL;
21                tmp = ostrcat(tmp, value, 1, 0);
22                changechoiceboxvalue(choicebox, tmp);
23        }
24        else
25        {
26                //check once
27                if(ostrcmp(choicebox->choiceboxvalue, value) == 0) return 0;
28                //check first
29                tmp = ostrcat(value, "\n", 0, 0);
30                if(ostrstr(choicebox->choiceboxvalue, tmp) == choicebox->choiceboxvalue)
31                {
32                        free(tmp); tmp = NULL;
33                        return 0;
34                }
35                free(tmp); tmp = NULL;
36                //check mitddle
37                tmp = ostrcat("\n", value, 0, 0);
38                tmp = ostrcat(tmp, "\n", 1, 0);
39                if(ostrstr(choicebox->choiceboxvalue, tmp) != NULL)
40                {
41                        free(tmp); tmp = NULL;
42                        return 0;
43                }
44                free(tmp); tmp = NULL;
45                //check end
46                tmp = ostrcat("\n", value, 0, 0);
47                char* c = ostrstr(choicebox->choiceboxvalue, tmp);
48                if(c != NULL && choicebox->choiceboxvalue + strlen(choicebox->choiceboxvalue) == c + strlen(tmp))
49                {
50                        free(tmp); tmp = NULL;
51                        return 0;
52                }
53                free(tmp); tmp = NULL;
54
55                tmp = ostrcat(choicebox->choiceboxvalue, "\n", 0, 0);
56                tmp = ostrcat(tmp, value, 1, 0);
57                changechoiceboxvalue(choicebox, tmp);
58                free(tmp); tmp = NULL;
59
60                tmp = ostrcat(choicebox->input, "\n", 0, 0);
61                tmp = ostrcat(tmp, text, 1, 0);
62                changeinput(choicebox, tmp);
63        }
64       
65        free(tmp);
66
67        return 0;
68}
69
70int setchoiceboxselection(struct skin* choicebox, char* value)
71{
72        int treffer = 0;
73        char* pos = NULL, *epos = NULL, *end = NULL;
74
75        if(choicebox == NULL)
76        {
77                err("NULL detect");
78                return 1;
79        }
80       
81        if(choicebox->input == NULL) return 1;
82
83        choicebox->aktpage = 0;
84
85        if(value == NULL) return 1;
86
87        if(choicebox->choiceboxvalue != NULL)
88                pos = choicebox->choiceboxvalue;
89        else
90                pos = choicebox->input;
91
92        if(pos != NULL) end = pos + strlen(pos) + 1;
93
94        while(pos != NULL)
95        {
96                choicebox->aktpage++;
97
98                if(strncmp(pos, value, strlen(value)) == 0)
99                {
100                        epos = pos + strlen(value);
101                        if(epos > end) break;
102                        if(*epos == '\n' || *epos == '\0')
103                        {
104                                changeret(choicebox, value);
105                                treffer = 1;
106                                break;
107                        }
108                }
109
110                pos = strchr(pos, '\n');
111                if(pos != NULL) pos++;
112        }
113
114        if(treffer == 0)
115        {
116                if(choicebox->choiceboxvalue != NULL)
117                        pos = choicebox->choiceboxvalue;
118                else
119                        pos = choicebox->input;
120
121                if(pos != NULL)
122                {
123                        epos = strchr(pos, '\n');
124                        if(epos == NULL)
125                                changeret(choicebox, pos);
126                        else
127                        {
128                                char c = 0;
129                                c = *epos;
130                                *epos = '\0';
131                                changeret(choicebox, pos);
132                                *epos = c;
133                        }
134                        choicebox->aktpage = 1;
135                }
136        }
137
138        return 0;
139}
140
141#endif
Note: See TracBrowser for help on using the repository browser.