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 | #ifdef _MANGLE_INC
|
---|
10 | #include "gui/BROWS~B4.HH"
|
---|
11 | #else
|
---|
12 | #include "gui/browse_tree.hh"
|
---|
13 | #endif
|
---|
14 | #include "window/style.hh"
|
---|
15 | #include "window/colorwin.hh"
|
---|
16 | #include "window/win_evt.hh"
|
---|
17 |
|
---|
18 | void i4_vertical_compact_window_class::compact()
|
---|
19 | {
|
---|
20 | sw32 my=0,largest_width=0;
|
---|
21 | i4_parent_window_class::win_iter w;
|
---|
22 | for (w=children.begin();
|
---|
23 | w!=children.end(); ++w)
|
---|
24 | if (w->width()>largest_width)
|
---|
25 | largest_width=w->width();
|
---|
26 |
|
---|
27 | for (w=children.begin();
|
---|
28 | w!=children.end(); ++w)
|
---|
29 | {
|
---|
30 | if (center)
|
---|
31 | w->private_move(x() + largest_width/2-(sw32)w->width()/2 - w->x(), y() + my - w->y());
|
---|
32 | else
|
---|
33 | w->private_move(0, y() + my - w->y());
|
---|
34 |
|
---|
35 | my+=w->height();
|
---|
36 | }
|
---|
37 | if (width()!=largest_width || my!=height())
|
---|
38 | resize(largest_width, my);
|
---|
39 | }
|
---|
40 |
|
---|
41 |
|
---|
42 | void i4_horizontal_compact_window_class::compact()
|
---|
43 | {
|
---|
44 | sw32 mx=0,largest_height=0;
|
---|
45 | i4_parent_window_class::win_iter w;
|
---|
46 | for (w=children.begin();
|
---|
47 | w!=children.end(); ++w)
|
---|
48 | if (w->height()>largest_height)
|
---|
49 | largest_height=w->height();
|
---|
50 |
|
---|
51 | for (w=children.begin();
|
---|
52 | w!=children.end(); ++w)
|
---|
53 | {
|
---|
54 | if (center)
|
---|
55 | w->private_move(x() + mx - w->x(), y() + largest_height/2-(sw32)w->height()/2 - w->y());
|
---|
56 | else
|
---|
57 | w->private_move(x() + mx - w->x(), 0);
|
---|
58 |
|
---|
59 | mx+=w->width();
|
---|
60 | }
|
---|
61 | if (mx!=width() || largest_height!=height())
|
---|
62 | resize(mx, largest_height);
|
---|
63 | }
|
---|
64 |
|
---|
65 | void i4_vertical_compact_window_class::receive_event(i4_event *ev)
|
---|
66 | {
|
---|
67 | if (ev->type()==i4_event::WINDOW_MESSAGE)
|
---|
68 | {
|
---|
69 | CAST_PTR(mess,i4_window_message_class,ev);
|
---|
70 |
|
---|
71 | if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
|
---|
72 | {
|
---|
73 | CAST_PTR(res,i4_window_notify_resize_class,ev);
|
---|
74 | sw32 ow=res->from()->width(), oh=res->from()->height();
|
---|
75 | res->from()->private_resize(res->new_width, res->new_height);
|
---|
76 |
|
---|
77 | compact();
|
---|
78 |
|
---|
79 | res->from()->private_resize(ow, oh);
|
---|
80 |
|
---|
81 | note_undrawn(0,0, width()-1, height()-1);
|
---|
82 |
|
---|
83 | } else i4_parent_window_class::receive_event(ev);
|
---|
84 | } else i4_parent_window_class::receive_event(ev);
|
---|
85 | }
|
---|
86 |
|
---|
87 | void i4_vertical_compact_window_class::parent_draw(i4_draw_context_class &context)
|
---|
88 | {
|
---|
89 | i4_rect_list_class child_clip(&context.clip,0,0);
|
---|
90 | child_clip.intersect_list(&undrawn_area);
|
---|
91 |
|
---|
92 | child_clip.swap(&context.clip);
|
---|
93 |
|
---|
94 | local_image->clear(color,context);
|
---|
95 |
|
---|
96 | child_clip.swap(&context.clip);
|
---|
97 |
|
---|
98 | }
|
---|
99 |
|
---|
100 |
|
---|
101 | void i4_horizontal_compact_window_class::receive_event(i4_event *ev)
|
---|
102 | {
|
---|
103 | if (ev->type()==i4_event::WINDOW_MESSAGE)
|
---|
104 | {
|
---|
105 | CAST_PTR(mess,i4_window_message_class,ev);
|
---|
106 |
|
---|
107 | if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
|
---|
108 | {
|
---|
109 | CAST_PTR(res,i4_window_notify_resize_class,ev);
|
---|
110 | sw32 ow=res->from()->width(), oh=res->from()->height();
|
---|
111 | res->from()->private_resize(res->new_width, res->new_height);
|
---|
112 | compact();
|
---|
113 | res->from()->private_resize(ow, oh);
|
---|
114 | note_undrawn(0,0, width()-1, height()-1);
|
---|
115 | } else i4_parent_window_class::receive_event(ev);
|
---|
116 | } else i4_parent_window_class::receive_event(ev);
|
---|
117 | }
|
---|
118 |
|
---|
119 | void i4_horizontal_compact_window_class::parent_draw(i4_draw_context_class &context)
|
---|
120 | {
|
---|
121 | i4_rect_list_class child_clip(&context.clip,0,0);
|
---|
122 | child_clip.intersect_list(&undrawn_area);
|
---|
123 | child_clip.swap(&context.clip);
|
---|
124 | local_image->clear(color,context);
|
---|
125 | child_clip.swap(&context.clip);
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | class i4_browse_toggle_class : public i4_window_class
|
---|
130 | {
|
---|
131 | public:
|
---|
132 | char *name() { return "browse_toggle"; }
|
---|
133 |
|
---|
134 | enum { EXPANDED, COMPACTED, NO_CHILDREN } state;
|
---|
135 |
|
---|
136 | i4_browse_window_class *browse_parent;
|
---|
137 | i4_graphical_style_class *style;
|
---|
138 |
|
---|
139 | i4_browse_toggle_class(i4_graphical_style_class *style,
|
---|
140 | i4_browse_window_class *browse_parent,
|
---|
141 | i4_bool show_plus_minus,
|
---|
142 | i4_bool expanded,
|
---|
143 | i4_bool has_a_child)
|
---|
144 |
|
---|
145 | : i4_window_class(style->icon_hint->plus_icon->width()+4,
|
---|
146 | style->icon_hint->plus_icon->height()),
|
---|
147 | browse_parent(browse_parent),
|
---|
148 | style(style)
|
---|
149 | {
|
---|
150 | if (show_plus_minus)
|
---|
151 | {
|
---|
152 | if (expanded)
|
---|
153 | state=EXPANDED;
|
---|
154 | else
|
---|
155 | state=COMPACTED;
|
---|
156 | }
|
---|
157 | else
|
---|
158 | state=NO_CHILDREN;
|
---|
159 | }
|
---|
160 |
|
---|
161 | virtual void draw(i4_draw_context_class &context)
|
---|
162 | {
|
---|
163 | local_image->clear(style->color_hint->window.passive.medium, context);
|
---|
164 | if (state!=NO_CHILDREN)
|
---|
165 | {
|
---|
166 | if (state==EXPANDED)
|
---|
167 | style->icon_hint->plus_icon->put_image_trans(local_image, 0,0, 0, context);
|
---|
168 | else
|
---|
169 | style->icon_hint->minus_icon->put_image_trans(local_image, 0,0, 0, context);
|
---|
170 | }
|
---|
171 | }
|
---|
172 |
|
---|
173 | virtual void receive_event(i4_event *ev)
|
---|
174 | {
|
---|
175 | if (ev->type()==i4_event::MOUSE_BUTTON_DOWN && state!=NO_CHILDREN)
|
---|
176 | {
|
---|
177 | if (state==EXPANDED)
|
---|
178 | {
|
---|
179 | state=COMPACTED;
|
---|
180 | browse_parent->compress();
|
---|
181 | }
|
---|
182 | else
|
---|
183 | {
|
---|
184 | state=EXPANDED;
|
---|
185 | browse_parent->expand();
|
---|
186 |
|
---|
187 | }
|
---|
188 | request_redraw();
|
---|
189 | }
|
---|
190 | }
|
---|
191 | } ;
|
---|
192 |
|
---|
193 |
|
---|
194 | void i4_browse_window_class::add_arranged_child(i4_window_class *child)
|
---|
195 | {
|
---|
196 | title_area->add_child(0,0,child);
|
---|
197 | ((i4_horizontal_compact_window_class *)title_area)->compact();
|
---|
198 |
|
---|
199 |
|
---|
200 | private_resize(0,0);
|
---|
201 | arrange_right_down();
|
---|
202 | if (child_object)
|
---|
203 | child_object->move(x_start(), 0);
|
---|
204 | resize_to_fit_children();
|
---|
205 | }
|
---|
206 |
|
---|
207 | void i4_browse_window_class::compress()
|
---|
208 | {
|
---|
209 | if (child_object && expanded)
|
---|
210 | {
|
---|
211 | expanded=i4_F;
|
---|
212 | i4_parent_window_class::remove_child(child_object);
|
---|
213 | resize_to_fit_children();
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | void i4_browse_window_class::expand()
|
---|
218 | {
|
---|
219 | if (child_object && !expanded)
|
---|
220 | {
|
---|
221 | expanded=i4_T;
|
---|
222 | i4_parent_window_class::add_child(0,0,child_object);
|
---|
223 | private_resize(0,0);
|
---|
224 | arrange_right_down();
|
---|
225 | if (child_object)
|
---|
226 | child_object->move(x_start(), 0);
|
---|
227 | resize_to_fit_children();
|
---|
228 | }
|
---|
229 | }
|
---|
230 |
|
---|
231 | void i4_browse_window_class::replace_object(i4_window_class *object)
|
---|
232 | {
|
---|
233 | if (child_object)
|
---|
234 | {
|
---|
235 | if (expanded)
|
---|
236 | remove_child(child_object);
|
---|
237 |
|
---|
238 | delete child_object;
|
---|
239 | child_object=0;
|
---|
240 |
|
---|
241 | /*
|
---|
242 | if (((i4_browse_toggle_class *)toggle_button)->state == i4_browse_toggle_class::EXPANDED)
|
---|
243 | ((i4_browse_toggle_class *)toggle_button)->state=i4_browse_toggle_class::COMPACTED;
|
---|
244 | else if (((i4_browse_toggle_class *)toggle_button)->state == i4_browse_toggle_class::COMPACTED)
|
---|
245 | ((i4_browse_toggle_class *)toggle_button)->state=i4_browse_toggle_class::EXPANDED;
|
---|
246 | */
|
---|
247 |
|
---|
248 | toggle_button->request_redraw();
|
---|
249 |
|
---|
250 | private_resize(0,0);
|
---|
251 | resize_to_fit_children();
|
---|
252 | }
|
---|
253 |
|
---|
254 | if (object)
|
---|
255 | {
|
---|
256 | child_object=object;
|
---|
257 | if (expanded)
|
---|
258 | i4_parent_window_class::add_child(0,0,object);
|
---|
259 |
|
---|
260 | private_resize(0,0);
|
---|
261 | arrange_right_down();
|
---|
262 | object->move(x_start(), 0);
|
---|
263 |
|
---|
264 | resize_to_fit_children();
|
---|
265 | }
|
---|
266 | }
|
---|
267 |
|
---|
268 | class i4_browse_title_container_class : public i4_parent_window_class
|
---|
269 | {
|
---|
270 | public:
|
---|
271 | i4_browse_title_container_class() : i4_parent_window_class(0,0) {}
|
---|
272 | char *name() { return "browse title container"; }
|
---|
273 | };
|
---|
274 |
|
---|
275 | i4_browse_window_class::i4_browse_window_class(i4_graphical_style_class *style,
|
---|
276 | i4_window_class *title_object,
|
---|
277 | i4_window_class *child_obj,
|
---|
278 | i4_bool show_plus_minus,
|
---|
279 | i4_bool expanded)
|
---|
280 | : style(style),
|
---|
281 | expanded(expanded),
|
---|
282 | i4_parent_window_class(0,0)
|
---|
283 | {
|
---|
284 | toggle_button=0;
|
---|
285 | child_object=0;
|
---|
286 |
|
---|
287 | title_area=new i4_horizontal_compact_window_class(style->color_hint->window.passive.medium,
|
---|
288 | i4_T);
|
---|
289 | ((i4_horizontal_compact_window_class *)title_area)->compact();
|
---|
290 | i4_parent_window_class::add_child(0,0,title_area);
|
---|
291 |
|
---|
292 |
|
---|
293 | toggle_button=new i4_browse_toggle_class(style, this,
|
---|
294 | show_plus_minus,
|
---|
295 | expanded,
|
---|
296 | (i4_bool)(child_obj!=0));
|
---|
297 | title_area->add_child(0,0,toggle_button);
|
---|
298 |
|
---|
299 | if (title_object)
|
---|
300 | add_arranged_child(title_object);
|
---|
301 |
|
---|
302 | if (child_obj)
|
---|
303 | replace_object(child_obj);
|
---|
304 |
|
---|
305 | }
|
---|
306 |
|
---|
307 |
|
---|
308 | sw32 i4_browse_window_class::x_start()
|
---|
309 | {
|
---|
310 | return style->icon_hint->plus_icon->width() + 10;
|
---|
311 | }
|
---|
312 |
|
---|
313 |
|
---|
314 |
|
---|
315 | void i4_browse_window_class::receive_event(i4_event *ev)
|
---|
316 | {
|
---|
317 | if (ev->type()==i4_event::WINDOW_MESSAGE)
|
---|
318 | {
|
---|
319 | CAST_PTR(mess,i4_window_message_class,ev);
|
---|
320 |
|
---|
321 | if (mess->sub_type==i4_window_message_class::NOTIFY_RESIZE)
|
---|
322 | {
|
---|
323 | CAST_PTR(resize,i4_window_notify_resize_class,ev);
|
---|
324 |
|
---|
325 | note_undrawn(0,0, width()-1, height()-1);
|
---|
326 |
|
---|
327 | w16 ow=resize->from()->width(),
|
---|
328 | oh=resize->from()->height();
|
---|
329 |
|
---|
330 | resize->from()->private_resize(resize->new_width,resize->new_height);
|
---|
331 |
|
---|
332 | private_resize(0,0);
|
---|
333 | arrange_right_down();
|
---|
334 | if (child_object)
|
---|
335 | child_object->move(x_start(), 0);
|
---|
336 | resize_to_fit_children();
|
---|
337 |
|
---|
338 | note_undrawn(0,0, width()-1, height()-1);
|
---|
339 |
|
---|
340 | resize->from()->private_resize(ow, oh);
|
---|
341 | }
|
---|
342 | else
|
---|
343 | i4_parent_window_class::receive_event(ev);
|
---|
344 | }
|
---|
345 | else i4_parent_window_class::receive_event(ev);
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 | void i4_browse_window_class::parent_draw(i4_draw_context_class &context)
|
---|
351 | {
|
---|
352 | i4_rect_list_class child_clip(&context.clip,0,0);
|
---|
353 | child_clip.intersect_list(&undrawn_area);
|
---|
354 |
|
---|
355 | child_clip.swap(&context.clip);
|
---|
356 |
|
---|
357 | local_image->clear(style->color_hint->window.passive.medium,context);
|
---|
358 |
|
---|
359 | child_clip.swap(&context.clip);
|
---|
360 | }
|
---|