source: titan/titan/choicebox.h @ 23206

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

[titan] revert

File size: 2.8 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)
86        {
87                err("NULL detect");
88                return 1;
89        }
90
91        if(choicebox->choiceboxvalue != NULL)
92                pos = choicebox->choiceboxvalue;
93        else
94                pos = choicebox->input;
95
96        if(pos != NULL) end = pos + strlen(pos) + 1;
97
98        while(pos != NULL)
99        {
100                choicebox->aktpage++;
101
102                if(strncmp(pos, value, strlen(value)) == 0)
103                {
104                        epos = pos + strlen(value);
105                        if(epos > end) break;
106                        if(*epos == '\n' || *epos == '\0')
107                        {
108                                changeret(choicebox, value);
109                                treffer = 1;
110                                break;
111                        }
112                }
113
114                pos = strchr(pos, '\n');
115                if(pos != NULL) pos++;
116        }
117
118        if(treffer == 0)
119        {
120                if(choicebox->choiceboxvalue != NULL)
121                        pos = choicebox->choiceboxvalue;
122                else
123                        pos = choicebox->input;
124
125                if(pos != NULL)
126                {
127                        epos = strchr(pos, '\n');
128                        if(epos == NULL)
129                                changeret(choicebox, pos);
130                        else
131                        {
132                                char c = 0;
133                                c = *epos;
134                                *epos = '\0';
135                                changeret(choicebox, pos);
136                                *epos = c;
137                        }
138                        choicebox->aktpage = 1;
139                }
140        }
141
142        return 0;
143}
144
145#endif
Note: See TracBrowser for help on using the repository browser.