core/vgui/vgui_event_server.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_event_server.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \author Philip C. Pritchett, RRG, University of Oxford
00008 // \date   29 Sep 99
00009 // \brief  See vgui_event_server.h for a description of this file.
00010 
00011 #include "vgui_event_server.h"
00012 
00013 #include <vgui/vgui.h>
00014 #include <vgui/vgui_wrapper_tableau.h>
00015 
00016 // the default is 'false'. don't check in 'true'.
00017 //static bool debug = false;
00018 
00019 class vgui_event_server_interpose_tableau : public vgui_wrapper_tableau
00020 {
00021  public:
00022   vgui_event_server* the_server_;
00023 
00024   vgui_event_server_interpose_tableau(vgui_event_server* s)
00025     : vgui_wrapper_tableau(0), // child to be added later
00026       the_server_(s) {}
00027 
00028   bool handle(const vgui_event& event);
00029   vcl_string type_name() const {return "vgui_event_server";}
00030 };
00031 
00032 //: Interaction (i.e. mouse/kb) events are saved, and said to be consumed.
00033 bool vgui_event_server_interpose_tableau::handle(const vgui_event& event)
00034 {
00035   // Pass draw events down -- we're just grabbing the interactions
00036   if (event.type == vgui_DRAW)
00037     return child.handle(event);
00038 
00039   // Do not grab TIMERs
00040   if (event.type == vgui_TIMER)
00041     return false;
00042 
00043   // Grab anything else
00044   the_server_->last_event_ = event;
00045   the_server_->use_event_ = true;
00046   return true;
00047 }
00048 
00049 //: Construct a vgui_event_server, which grabs all events intended for tableau t
00050 vgui_event_server::vgui_event_server(vgui_tableau_sptr const& t)
00051   : grabber_(0)
00052 {
00053   use_event_ = false;
00054   grabber_ = new vgui_event_server_interpose_tableau(this);
00055   grabber_reference_ = grabber_;
00056 
00057   // link up grabber
00058   vgui_parent_child_link::replace_child_everywhere(t, grabber_);
00059 
00060   // Link t to grabber as child
00061   grabber_->add_child(t);
00062 }
00063 
00064 vgui_event_server::~vgui_event_server()
00065 {
00066   // Replace the grabber with its child
00067   vgui_parent_child_link::replace_child_everywhere(grabber_, grabber_->child);
00068 }
00069 
00070 void vgui_event_server::reset()
00071 {
00072 }
00073 
00074 bool vgui_event_server::next()
00075 {
00076   use_event_ = false;
00077   while (!use_event_)
00078     vgui::run_one_event();
00079 
00080   return true;
00081 }