Adonthell  0.4
win_container.cc
1 /*
2  (C) Copyright 2000 Joel Vennin
3  Part of the Adonthell Project <http://adonthell.nongnu.org>
4 
5  Adonthell is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  Adonthell is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Adonthell. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #include "win_container.h"
21 
22 win_container::win_container()
23 {
24  move(0,0);
25 
26  set_layout(NO_LAYOUT);
27 
28  set_space_with_border(SPACE_WITH_BORDER);
29 
30  set_space_with_object(SPACE_WITH_OBJECT);
31 
32  focus_object_ = NULL;
33 
34 }
35 
36 win_container::~win_container()
37 {
38  destroy();
39 }
40 
42 {
43  win_base::move(tx,ty);
44  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
45  (*i)->update_position();
46 }
47 
49 {
50  win_base::resize(tl,th);
51 
52  update_layout();
53 
54 }
55 
56 void win_container::update_position()
57 {
58  win_base::update_position();
59  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
60  (*i)->update_position();
61 }
62 
63 void win_container::add(win_base * w)
64 {
65  list_wb_.push_back(w);
66 
67  w->set_container(this);
68 
69  update_layout();
70 }
71 
72 void win_container::remove(win_base * w)
73 {
74  list_wb_.remove(w);
75 
76  w->set_container(NULL);
77 
78  update_layout();
79 }
80 
81 void win_container::remove_all()
82 {
83  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
84  {
85  (*i)->set_container(NULL);
86  list_wb_.erase(i);
87  }
88 }
89 
90 void win_container::destroy()
91 {
92  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
93  delete *i;
94  list_wb_.clear();
95 }
96 
98 {
99  if(win_base::update())
100  {
101  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
102  {
103  if(!(*i)->update())
104  {
105  list_wb_.erase(i);
106  delete *i--;
107  }
108  }
109  return true;
110  }
111  return false;
112 }
113 
114 
116 {
118  {
119  if(focus_object_) focus_object_->input_update();
120  return true;
121  }
122  return false;
123 }
124 
125 
126 void win_container::set_focus_object(win_base * f)
127 {
128  if(focus_object_) focus_object_->set_focus(false);
129  if(f) f->set_focus(true);
130  focus_object_ = f;
131 }
132 
134 {
136 
137  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
138  (*i)->set_brightness(b);
139 }
140 
142 {
144 
145  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
146  (*i)->set_trans(b);
147 }
148 
149 void win_container::set_visible_all(bool b)
150 {
151  set_visible(b);
152  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
153  (*i)->set_visible(b);
154 }
155 
156 
157 
159 {
160  if(win_base::draw())
161  {
162  assign_drawing_area(wb_father_);
163 
164  win_background::draw(this);
165 
166  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
167  (*i)->draw();
168 
169  win_border::draw(wb_father_);
170 
172 
173  return true;
174  }
175  return false;
176 }
177 
178 
179 
180 void win_container::update_layout()
181 {
182 
183  u_int16 indice_h=space_with_border_;
184 
185  switch(layout_)
186  {
187  case LIST_LAYOUT:
188 
189  for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
190  {
191  (*i)->move((*i)->x(),indice_h);
192 
193  indice_h+=(*i)->height()+space_with_object_;
194  }
195 
196  break;
197  }
198 }
199 
200 /*
201 #include <list>
202 #include "types.h"
203 #include "image.h"
204 #include "win_types.h"
205 #include "win_base.h"
206 #include "win_border.h"
207 #include "win_theme.h"
208 #include "win_container.h"
209 
210 
211 //constructor
212 win_container::win_container(s_int16 tx,s_int16 ty,u_int16 tl,u_int16 th,win_theme * wth):win_base(tx,ty,tl,th,wth)
213 {
214  //clear the list og object
215  list_obj.clear();
216 
217  //set the space between border and object
218  space_between_border_=WIN_SPACE_BETWEEN_BORDER;
219 
220  //set space between object and another object
221  space_between_object_=WIN_SPACE_BETWEEN_OBJECT;
222 */
223  /*
224  //set justify ----> WARNING MAYBE IN WIN_BASE ????
225  justify_=WIN_JUSTIFY_NO;
226 
227  */
228 /*
229  //set layout equals no
230  layout_=WIN_LAYOUT_NO;
231 }
232 
233 
234 void win_container::set_space_between_object(u_int16 tmp)
235 {
236  //set the space between object and call update layout to redefine position of each element
237  space_between_object_=tmp;
238  update_layout();
239 }
240 
241 void win_container::set_space_between_border(u_int16 tmp)
242 {
243  //set the space between border and object and call update layout to redefine position of each element
244  space_between_border_=tmp;
245  update_layout();
246 }
247 
248 win_container::~win_container()
249 {
250  destroy();
251 }
252 
253 void win_container::add(win_base * tmp)
254 {
255  //add the object
256  list_obj.push_back(tmp);
257 
258  //set the new object
259  tmp->wb_father_=this;
260  tmp->update_real_position();
261 
262 
263  tmp->update_align();
264 
265  //update layout
266  update_layout();
267  //if the win_container is brightness set the new object in brightness mode
268  if(draw_brightness_) tmp->set_draw_brightness(true);
269 }
270 
271 
272 void win_container::remove(win_base * tmp)
273 {
274  list<win_base *>::iterator i=list_obj.begin();
275  while(i!=list_obj.end() && tmp!=(*i)) i++;
276  if(i!=list_obj.end())
277  {
278  //list_obj.remove(tmp);
279  tmp->wb_father_=NULL;
280  list_obj.erase(i);
281  update_layout();
282  }
283 }
284 
285 void win_container::remove_all()
286 {
287  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
288  (*i)->wb_father_=NULL;
289  list_obj.clear();
290 }
291 
292 void win_container::destroy()
293 {
294  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
295  delete *i;
296  list_obj.clear();
297 }
298 
299 void win_container::resize(u_int16 tl,u_int16 th)
300 {
301  win_base::resize(tl,th);
302  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
303  (*i)->update_align();
304 }
305 
306 bool win_container::update()
307 {
308  //call the win update ---> on update()
309  if(win_base::update())
310  {
311  //update all the element in the list
312  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
313  {
314  if(!(*i)->update())
315  {
316  remove(*i);
317  delete *i--;
318  }
319  }
320  return true;
321  }
322  return false;
323 }
324 
325 
326 bool win_container::draw()
327 {
328  if(win_base::draw())
329  {
330  assign_drawing_area(); //assign drawing area
331  //draw the background
332  draw_background();
333  //next draw all the element
334  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
335  (*i)->draw();
336  //draw the border
337  draw_border();
338  //detach the drawing area
339  detach_drawing_area();
340  return true;
341  }
342  return false;
343 }
344 
345 
346 //set visible mode for all element in list
347 void win_container::set_visible_all(bool b)
348 {
349  visible_=b;
350  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
351  (*i)->set_visible(visible_);
352 }
353 
354 //set draw brightness for all element in the list
355 void win_container::set_draw_brightness(bool b)
356 {
357  win_base::set_draw_brightness(b);
358  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
359  (*i)->set_draw_brightness(b);
360 }
361 */
362 /*
363 
364 //set justify an object in this container
365 void win_container::set_justify(win_base * wb, u_int8 just)
366 {
367  switch(just)
368  {
369  case WIN_JUSTIFY_LEFT:
370  wb->move(space_between_border_,wb->y());
371  break;
372  case WIN_JUSTIFY_RIGHT:
373  wb->move(length_-space_between_border_-wb->length(),wb->y());
374  break;
375  case WIN_JUSTIFY_CENTER:
376  if(length_>wb->length())
377  wb->move((length_-wb->length())>>1,wb->y());
378  break;
379  }
380 }
381 
382 //justify all the element
383 
384 */
385 
386 /*
387 void win_container::set_align_all(u_int8 a)
388 {
389  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
390  (*i)->set_align(a);
391 }
392 
393 
394 
395 
396 //sezt the layout and update
397 void win_container::set_layout(u_int8 lay)
398 {
399  layout_=lay;
400  update_layout();
401 }
402 
403 //
404 void win_container::update_real_position()
405 {
406  win_base::update_real_position();
407  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
408  (*i)->update_real_position();
409 }
410 
411 void win_container::move(s_int16 tx,s_int16 ty)
412 {
413  win_base::move(tx,ty);
414  update_real_position();
415 }
416 
417 
418 //just one layout actually but i whish add another --> grid layout
419 void win_container::update_layout()
420 {
421  u_int16 old_h=0;
422  u_int16 indice_h=space_between_border_;
423  u_int16 indice_l=space_between_border_;
424  switch(layout_)
425  {
426  case WIN_LAYOUT_LIST:
427  //u_int16 indice=space_between_border_;
428  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
429  {
430  (*i)->move((*i)->x(),indice_h);
431  indice_h+=(*i)->height()+space_between_object_;
432  }
433  break;
434 
435  case WIN_LAYOUT_AUTO:
436 
437  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
438  {
439 
440  if(indice_l+(*i)->length()>length_)
441  {
442  indice_l=space_between_border_;
443  indice_h+=old_h+space_between_object_;
444  (*i)->move(indice_l,indice_h);
445  }
446 
447  (*i)->move(indice_l,indice_h);
448  indice_l+=(*i)->length()+space_between_object_;
449  old_h=(*i)->height();
450  }
451  break;
452 
453 
454 
455 
456  default:
457  break;
458  }
459 }
460 
461 
462 void win_container::set_focus(bool b)
463 {
464  for(list<win_base *>::iterator i=list_obj.begin();i!=list_obj.end();i++)
465  (*i)->set_focus(b);
466  focus_=b;
467 }
468 
469 
470 
471 
472 
473 
474 */
475 
476 
477 
478 
479 
480 
481 
482 
win_base::draw
virtual bool draw()
Draw process.
Definition: win_base.cc:111
win_base
Common properties for each win_base's object.
Definition: win_base.h:51
win_base::set_visible
void set_visible(const bool b)
Set the visible parameter.
Definition: win_base.h:140
win_base::input_update
virtual bool input_update()
Input Update process .
Definition: win_base.cc:106
win_container::move
void move(s_int16, s_int16)
Move the win_*.
Definition: win_container.cc:41
win_base::set_focus
void set_focus(const bool b)
Set the focus parameter.
Definition: win_base.h:170
win_base::update
virtual bool update()
Update process.
Definition: win_base.cc:94
s_int16
#define s_int16
16 bits long signed integer
Definition: types.h:47
win_base::resize
virtual void resize(u_int16 tl, u_int16 th)
Rezise the win_*.
Definition: win_base.cc:85
win_base::move
virtual void move(s_int16 tx, s_int16 ty)
Move the win_*.
Definition: win_base.cc:75
win_container::input_update
virtual bool input_update()
Input Update process .
Definition: win_container.cc:115
win_base::set_trans
virtual void set_trans(const bool b)
Set the transluency parameter.
Definition: win_base.h:184
win_base::set_brightness
virtual void set_brightness(const bool b)
Set the transluency parameter.
Definition: win_base.h:198
win_container::draw
virtual bool draw()
Draw process.
Definition: win_container.cc:158
drawing_area::assign_drawing_area
void assign_drawing_area(const drawing_area *da)
Assign a drawing_area to this drawing_area.
Definition: drawing_area.h:131
win_container::resize
void resize(u_int16, u_int16)
Rezise the win_*.
Definition: win_container.cc:48
drawing_area::detach_drawing_area
void detach_drawing_area()
Detach (if needed) the drawing_area which was attached to this one.
Definition: drawing_area.h:150
u_int16
#define u_int16
16 bits long unsigned integer
Definition: types.h:38
win_container::update
virtual bool update()
Update process.
Definition: win_container.cc:97
win_container::set_brightness
virtual void set_brightness(bool b)
Set the transluency parameter.
Definition: win_container.cc:133
win_container::set_trans
virtual void set_trans(bool b)
Set the transluency parameter.
Definition: win_container.cc:141