Rev 4415 | Rev 4662 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3225 | leency | 1 | //list_box |
2 | |||
3 | struct llist |
||
4 | { |
||
4078 | leency | 5 | int x, y, w, h, min_h, line_h, text_y; |
4415 | leency | 6 | int column_max; |
3225 | leency | 7 | int count, visible, first, current; |
4409 | leency | 8 | int active; |
3225 | leency | 9 | void ClearList(); |
4073 | leency | 10 | int ProcessKey(dword key); |
4077 | leency | 11 | int MouseOver(int xx, yy); |
12 | int ProcessMouse(int xx, yy); |
||
4059 | leency | 13 | int KeyDown(); |
14 | int KeyUp(); |
||
4063 | leency | 15 | int KeyHome(); |
16 | int KeyEnd(); |
||
3225 | leency | 17 | void SetSizes(int xx, yy, ww, hh, min_hh, line_hh); |
18 | int MouseScroll(dword scroll_state); |
||
19 | }; |
||
20 | |||
21 | |||
22 | void llist::ClearList() |
||
23 | { |
||
24 | count = visible = first = current = 0; |
||
25 | } |
||
26 | |||
27 | |||
28 | void llist::SetSizes(int xx, yy, ww, hh, min_hh, line_hh) |
||
29 | { |
||
30 | x = xx; |
||
31 | y = yy; |
||
32 | w = ww; |
||
33 | h = hh; |
||
34 | min_h = min_hh; |
||
35 | line_h = line_hh; |
||
4078 | leency | 36 | text_y = line_hh / 2 - 4; |
3368 | leency | 37 | visible = h / line_h; |
4078 | leency | 38 | if (visible > count) visible=count; |
3225 | leency | 39 | } |
40 | |||
41 | |||
42 | int llist::MouseScroll(dword scroll_state) |
||
43 | { |
||
4533 | leency | 44 | if (count<=visible) return 0; |
3225 | leency | 45 | if (scroll_state == 65535) |
46 | { |
||
47 | if (first == 0) return 0; |
||
48 | if (first > 3) first -= 2; else first=0; |
||
49 | return 1; |
||
50 | } |
||
51 | if (scroll_state == 1) |
||
52 | { |
||
53 | if (visible+first+3 >= count) first = count - visible; else first+=2; |
||
54 | return 1; |
||
55 | } |
||
56 | return 0; |
||
4059 | leency | 57 | } |
58 | |||
4077 | leency | 59 | int llist::MouseOver(int xx, yy) |
60 | { |
||
61 | if (xx>x) && (xx |
||
62 | return 0; |
||
63 | } |
||
64 | |||
65 | int llist::ProcessMouse(int xx, yy) |
||
66 | { |
||
4078 | leency | 67 | int current_temp; |
4077 | leency | 68 | if (MouseOver(xx, yy)) |
69 | { |
||
70 | current_temp = yy - y / line_h + first; |
||
4078 | leency | 71 | if (current_temp != current) && (current_temp |
4077 | leency | 72 | { |
73 | current = current_temp; |
||
74 | return 1; |
||
75 | } |
||
76 | } |
||
77 | return 0; |
||
78 | } |
||
79 | |||
4073 | leency | 80 | int llist::ProcessKey(dword key) |
81 | { |
||
82 | switch(key) |
||
83 | { |
||
84 | case 177: return KeyDown(); |
||
85 | case 178: return KeyUp(); |
||
86 | case 180: return KeyHome(); |
||
87 | case 181: return KeyEnd(); |
||
88 | } |
||
89 | return 0; |
||
90 | } |
||
91 | |||
4059 | leency | 92 | int llist::KeyDown() |
93 | { |
||
94 | if (current-first+1 |
||
95 | { |
||
4063 | leency | 96 | if (current+1>=count) return 0; |
4059 | leency | 97 | current++; |
98 | } |
||
99 | else |
||
100 | { |
||
4063 | leency | 101 | if (visible+first>=count) return 0; |
4059 | leency | 102 | first++; |
103 | current++; |
||
104 | } |
||
105 | return 1; |
||
106 | } |
||
107 | |||
108 | int llist::KeyUp() |
||
109 | { |
||
110 | if (current>first) |
||
111 | { |
||
112 | current--; |
||
113 | } |
||
114 | else |
||
115 | { |
||
4063 | leency | 116 | if (first==0) return 0; |
4059 | leency | 117 | first--; |
118 | current--; |
||
119 | } |
||
120 | return 1; |
||
4063 | leency | 121 | } |
122 | |||
123 | int llist::KeyHome() |
||
124 | { |
||
125 | if (current==0) && (first==0) return 0; |
||
126 | current=0; |
||
127 | first=0; |
||
128 | return 1; |
||
129 | } |
||
130 | |||
131 | int llist::KeyEnd() |
||
132 | { |
||
133 | if (current==count-1) && (first==count-visible) return 0; |
||
134 | current=count-1; |
||
135 | first=count-visible; |
||
136 | return 1; |
||
3225 | leency | 137 | } |