core/vgui/vgui_active_tableau.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_active_tableau.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 //:
00006 // \file
00007 // \brief  See vgui_active_tableau.h for a description of this file.
00008 // \author Philip C. Pritchett, RRG, University of Oxford
00009 // \date   25 Jan 00
00010 //
00011 // \verbatim
00012 //  Modifications
00013 //   25-JAN-2000 P.Pritchett - Initial version.
00014 // \endverbatim
00015 
00016 #include "vgui_active_tableau.h"
00017 
00018 #include <vgui/vgui_command.h>
00019 #include <vgui/vgui_menu.h>
00020 
00021 //----------------------------------------------------------------------------
00022 //: Constructor - don't use this, use vgui_active_tableau_new
00023 vgui_active_tableau::vgui_active_tableau(vgui_tableau_sptr const & t,
00024                                          bool name_in_menu )
00025   : vgui_wrapper_tableau(t)
00026   , active_(true)
00027   , visible_(true)
00028   , name_in_menu_( name_in_menu )
00029 {
00030 }
00031 
00032 //----------------------------------------------------------------------------
00033 //: Destructor - called by vgui_active_tableau_sptr.
00034 vgui_active_tableau::~vgui_active_tableau()
00035 {
00036 }
00037 
00038 //----------------------------------------------------------------------------
00039 //: Returns the type of this tableau ('vgui_active_tableau').
00040 vcl_string vgui_active_tableau::type_name() const
00041 {
00042   return "vgui_active_tableau";
00043 }
00044 
00045 
00046 //----------------------------------------------------------------------------
00047 //: Handles all events sent to this tableau.
00048 //  If visible, then use drawing events, else pass them to the child tableau.
00049 //  If active, use non-drawing events, else pass them to the child tableau.
00050 bool vgui_active_tableau::handle(const vgui_event &e)
00051 {
00052   // If tableau is not visible then do nothing with vgui_DRAW,
00053   // or vgui_DRAW_OVERLAY
00054   if (!visible_)
00055     if (e.type == vgui_DRAW || e.type == vgui_DRAW_OVERLAY)
00056       return false;
00057 
00058   // If tableau is inactive then ignore all events except draw events.
00059   if (!active_)
00060     if (e.type != vgui_DRAW &&e.type != vgui_DRAW_OVERLAY)
00061       return false;
00062 
00063   return vgui_wrapper_tableau::handle(e);
00064 }
00065 
00066 
00067 //----------------------------------------------------------------------------
00068 //: Add option to the popup menu to toggle active and visible.
00069 void vgui_active_tableau::add_popup(vgui_menu& menu)
00070 {
00071   vgui_menu popup;
00072 
00073   vcl_string active_label("Toggle active ");
00074   if (active_) active_label+="[on]";
00075   else active_label+="[off]";
00076 
00077   popup.add(active_label.c_str(),
00078             new vgui_command_simple<vgui_active_tableau>(this, &vgui_active_tableau::toggle_active));
00079 
00080 
00081   vcl_string visible_label("Toggle visible ");
00082   if (visible_) visible_label+="[on]";
00083   else visible_label+="[off]";
00084 
00085   popup.add(visible_label.c_str(),
00086             new vgui_command_simple<vgui_active_tableau>(this, &vgui_active_tableau::toggle_visible));
00087 
00088   if (!name_in_menu_)
00089     menu.include( popup );
00090   else
00091     menu.add( name(), popup );
00092 }
00093 
00094 //----------------------------------------------------------------------------
00095 //: Toggle between active (using events) and inactive (passing events on).
00096 void vgui_active_tableau::toggle_active()
00097 {
00098   active_ = !active_;
00099   post_redraw();
00100 }
00101 
00102 //----------------------------------------------------------------------------
00103 //: Toggle between visible (using drawing events) and invisible.
00104 void vgui_active_tableau::toggle_visible()
00105 {
00106   visible_ = !visible_;
00107   post_redraw();
00108 }
00109