Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

ccomponent.cpp

00001 #include "ccomponent.h"
00002 #include "citerator.h"
00003 #include "cevent.h"
00004 
00005 void CPanel::draw(CSurface &surface, CRect &rect)
00006 {
00007   /* If we're not visible, don't draw anything. */
00008   if (!visible()) return;
00009 
00010   /* We want to draw ourself from the background to foreground, so
00011      draw ourself first, and then draw all our children from rear
00012      to front. */
00013   CComponent::draw(surface, rect);
00014 
00015   CDequeBackwardIterator<CComponent> iter(children);
00016 
00017   while (!iter.is_done()) {
00018     iter.current_item()->draw(surface, rect);
00019     iter.next();
00020   }
00021 }
00022 
00023 /* Event handling is done using a chain of responsiblity pattern. */
00024 int CPanel::handle_event(CEvent &event)
00025 {
00026   /* First see if any of our children handle the request; if not, we'll
00027      try to handle it. */
00028   CDequeForwardIterator<CComponent> iter(children);
00029 
00030   while (!iter.is_done()) {
00031     int result = iter.current_item()->handle_event(event);
00032     if (result) return result;
00033     iter.next();
00034   }
00035 
00036   return do_handle_event(event);
00037 }
00038 
00039 void CPanel::set_absolute_pos(const CPoint &pos) {
00040   CComponent::set_absolute_pos(pos);
00041 
00042   return;
00043 
00044   CDequeForwardIterator<CComponent> iter(children);
00045 
00046   while (!iter.is_done()) {
00047     iter.current_item()->set_absolute_pos(pos);
00048     iter.next();
00049   }
00050 }
00051 
00053 void CPanel::set_pos(const CPoint &pos) {
00054   /* \todo Note this is very inefficient since it's also telling all the components to
00055      invalidate and redraw themselves!  It would be more efficient to only do this for
00056      this parent component, since all its children are contained within it and will be
00057      redrawn anyways. */
00058   CComponent::set_pos(pos);
00059 
00060   CDequeForwardIterator<CComponent> iter(children);
00061 
00062   while (!iter.is_done()) {
00063     /* \bug I don't believe this will support containers inside containers,
00064        as update_absolute_pos() isn't recursive. */
00065     update_absolute_pos(iter.current_item());
00066     iter.next();
00067   }
00068 }

Generated on Wed Aug 27 11:58:41 2003 for GFW by doxygen 1.3.3