1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "gui/list_box.hh"
|
---|
10 | #include "gui/button.hh"
|
---|
11 | #include "gui/deco_win.hh"
|
---|
12 | #include "gui/image_win.hh"
|
---|
13 |
|
---|
14 | void i4_list_box_class:: set_top(i4_menu_item_class *item)
|
---|
15 | {
|
---|
16 | if (top)
|
---|
17 | delete top;
|
---|
18 |
|
---|
19 | top=item->copy();
|
---|
20 |
|
---|
21 | int h=top->height() >= height()-(t+b) ? top->height() : height()-(t+b);
|
---|
22 |
|
---|
23 | top->set_menu_parent(this);
|
---|
24 | top->resize(width()-(l+r)-down->width(), h);
|
---|
25 | top->do_deactivate();
|
---|
26 |
|
---|
27 | i4_parent_window_class::add_child(l,t, top);
|
---|
28 | }
|
---|
29 |
|
---|
30 | i4_list_box_class::~i4_list_box_class()
|
---|
31 | {
|
---|
32 | hide();
|
---|
33 |
|
---|
34 | for (int i=0; i<entries.size(); i++)
|
---|
35 | delete entries[i];
|
---|
36 |
|
---|
37 | if (top)
|
---|
38 | delete top;
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | i4_list_box_class::i4_list_box_class(w16 w,
|
---|
43 | i4_graphical_style_class *style,
|
---|
44 | i4_parent_window_class *root_window)
|
---|
45 |
|
---|
46 | : i4_menu_class(i4_F), entries(0,8), style(style), root_window(root_window)
|
---|
47 | {
|
---|
48 | i4_image_class *down_im=style->icon_hint->down_icon;
|
---|
49 |
|
---|
50 | down=new i4_button_class(0, new i4_image_window_class(down_im), style,
|
---|
51 | 0,
|
---|
52 | new i4_event_reaction_class(this, 1));
|
---|
53 | down->set_popup(i4_T);
|
---|
54 |
|
---|
55 | l=1; r=1; t=1; b=1;
|
---|
56 |
|
---|
57 | resize(w, down->height()+(t+b));
|
---|
58 |
|
---|
59 |
|
---|
60 |
|
---|
61 | i4_parent_window_class::add_child(w-down->width()-r, t, down);
|
---|
62 | top=0;
|
---|
63 | pull_down=0;
|
---|
64 | current=0;
|
---|
65 | }
|
---|
66 |
|
---|
67 |
|
---|
68 | void i4_list_box_class::parent_draw(i4_draw_context_class &context)
|
---|
69 | {
|
---|
70 | local_image->clear(0, context);
|
---|
71 | // style->draw_in_deco(local_image, 0,0,width()-1, height()-1, i4_F, context);
|
---|
72 | }
|
---|
73 |
|
---|
74 |
|
---|
75 | void i4_list_box_class::add_item(i4_menu_item_class *item)
|
---|
76 | {
|
---|
77 |
|
---|
78 |
|
---|
79 | if (item->height()+t+b>height())
|
---|
80 | resize(width(), item->height()+t+b);
|
---|
81 |
|
---|
82 | if (entries.size()==0)
|
---|
83 | set_top(item);
|
---|
84 |
|
---|
85 | entries.add(item);
|
---|
86 |
|
---|
87 | item->set_menu_parent(this);
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | void i4_list_box_class::set_current_item(int entry_num)
|
---|
92 | {
|
---|
93 | if (entry_num>=0 && entry_num<entries.size())
|
---|
94 | {
|
---|
95 | set_top(entries[entry_num]);
|
---|
96 | current=entry_num;
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | class i4_list_pull_down_class : public i4_deco_window_class
|
---|
101 | {
|
---|
102 | i4_window_class *buddy;
|
---|
103 | public:
|
---|
104 | i4_list_pull_down_class(w16 w, w16 h, i4_window_class *buddy, i4_graphical_style_class *style)
|
---|
105 | : i4_deco_window_class(w,h, i4_T, style), buddy(buddy)
|
---|
106 | {
|
---|
107 | }
|
---|
108 |
|
---|
109 | void grab()
|
---|
110 | {
|
---|
111 | i4_window_request_mouse_grab_class grab(this);
|
---|
112 | i4_kernel.send_event(parent, &grab);
|
---|
113 | }
|
---|
114 |
|
---|
115 | void receive_event(i4_event *ev)
|
---|
116 | {
|
---|
117 | if (ev->type()==i4_event::MOUSE_BUTTON_DOWN)
|
---|
118 | {
|
---|
119 | CAST_PTR(mev, i4_mouse_move_event_class, ev);
|
---|
120 | if (mev->x<0 || mev->y<0 || mev->x>=width() || mev->y>=height())
|
---|
121 | {
|
---|
122 | i4_window_request_mouse_ungrab_class ungrab(this);
|
---|
123 | i4_kernel.send_event(parent, &ungrab);
|
---|
124 |
|
---|
125 | i4_user_message_event_class uev(1);
|
---|
126 | i4_kernel.send_event(buddy, &uev);
|
---|
127 | }
|
---|
128 | }
|
---|
129 |
|
---|
130 | i4_deco_window_class::receive_event(ev);
|
---|
131 | }
|
---|
132 |
|
---|
133 | char *name() { return "list_box_pull_down"; }
|
---|
134 | };
|
---|
135 |
|
---|
136 | void i4_list_box_class::show(i4_parent_window_class *show_on, i4_coord px, i4_coord py)
|
---|
137 | {
|
---|
138 | if (!pull_down)
|
---|
139 | {
|
---|
140 |
|
---|
141 | int i, y=0, x;
|
---|
142 |
|
---|
143 | for (i=0; i<entries.size(); i++)
|
---|
144 | y+=entries[i]->height();
|
---|
145 |
|
---|
146 | pull_down=new i4_list_pull_down_class(width()-(l+r), y, this, style);
|
---|
147 | y=pull_down->get_y1();
|
---|
148 | x=pull_down->get_x1();
|
---|
149 |
|
---|
150 | for (i=0; i<entries.size(); i++)
|
---|
151 | {
|
---|
152 | entries[i]->resize(width(), entries[i]->height());
|
---|
153 |
|
---|
154 | pull_down->add_child(x,y, entries[i]);
|
---|
155 | y+=entries[i]->height();
|
---|
156 | }
|
---|
157 |
|
---|
158 | show_on->add_child(px,py, pull_down);
|
---|
159 | pull_down->grab();
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 |
|
---|
164 | void i4_list_box_class::hide()
|
---|
165 | {
|
---|
166 | if (pull_down)
|
---|
167 | {
|
---|
168 |
|
---|
169 | for (int i=0; i<entries.size(); i++)
|
---|
170 | pull_down->remove_child(entries[i]);
|
---|
171 |
|
---|
172 | root_window->remove_child(pull_down);
|
---|
173 | delete pull_down;
|
---|
174 | pull_down=0;
|
---|
175 | }
|
---|
176 | }
|
---|
177 |
|
---|
178 |
|
---|
179 |
|
---|
180 | void i4_list_box_class::receive_event(i4_event *ev)
|
---|
181 | {
|
---|
182 | if (ev->type()==i4_event::USER_MESSAGE)
|
---|
183 | {
|
---|
184 | if (!pull_down)
|
---|
185 | show(root_window, x(), y()+height());
|
---|
186 | else hide();
|
---|
187 | }
|
---|
188 | else
|
---|
189 | i4_menu_class::receive_event(ev);
|
---|
190 | }
|
---|
191 |
|
---|
192 |
|
---|
193 | void i4_list_box_class::note_reaction_sent(i4_menu_item_class *who, // this is who sent it
|
---|
194 | i4_event_reaction_class *ev, // who it was to
|
---|
195 | i4_menu_item_class::reaction_type type)
|
---|
196 | {
|
---|
197 | if (type==i4_menu_item_class::PRESSED)
|
---|
198 | {
|
---|
199 | if (who==top)
|
---|
200 | show(root_window, x(), y()+height());
|
---|
201 | else
|
---|
202 | {
|
---|
203 | for (int i=0; i<entries.size(); i++)
|
---|
204 | if (entries[i]==who)
|
---|
205 | set_current_item(i);
|
---|
206 |
|
---|
207 | hide();
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 |
|
---|