core/vgui/vgui_wrapper_tableau.h
Go to the documentation of this file.
00001 // This is core/vgui/vgui_wrapper_tableau.h
00002 #ifndef vgui_wrapper_tableau_h_
00003 #define vgui_wrapper_tableau_h_
00004 //:
00005 // \file
00006 // \author fsm
00007 // \brief  Base class tableau for tableau who want only a single child.
00008 //
00009 //  Contains classes: vgui_wrapper_tableau  vgui_wrapper_tableau_new
00010 
00011 #include "vgui_wrapper_tableau_sptr.h"
00012 #include <vgui/vgui_tableau.h>
00013 #include <vgui/vgui_parent_child_link.h>
00014 
00015 //: Base class tableau for tableau who want only a single child.
00016 //
00017 // Q: So what does a vgui_wrapper_tableau do, then?
00018 // A: It's a convenient base class for tableaux who want only a single child,
00019 //    providing mixin code for adding and removing children, and handling the
00020 //    popup menu.
00021 //    To pass on an event to (the child of) a slot use
00022 //      return child.handle(e);
00023 //    which will work even if the slot is empty (returns false).
00024 //
00025 // Q: Why does it have such a silly name?
00026 // A: Because it is a tableau which "wraps" itself around another tableau.
00027 //    "vgui_parent" was too vague and it was needed for something else anyway.
00028 //    I would welcome suggestions for a better name.
00029 class vgui_wrapper_tableau : public vgui_tableau
00030 {
00031  public:
00032   //: Constructor - don't use this, use vgui_wrapper_tableau_new.
00033   //  The child tableau is added later using add_child.
00034   vgui_wrapper_tableau();
00035 
00036   //: Constructor - don't use this, use vgui_wrapper_tableau_new.
00037   //  Takes the single child tableau for this tableau.
00038   vgui_wrapper_tableau(vgui_tableau_sptr const&);
00039 
00040   //: Adds given tableau as child if none exists, else causes error.
00041   bool add_child(vgui_tableau_sptr const&);
00042 
00043   //: The child tableau is removed if it is the same as the given tableau.
00044   bool remove_child(vgui_tableau_sptr const&);
00045 
00046   //: Returns the child's file_name if it exists.
00047   vcl_string file_name() const;
00048 
00049   //: Returns nice version of the name which also includes details of the child.
00050   vcl_string pretty_name() const;
00051 
00052   //: Returns the type of tableau ('vgui_wrapper_tableau').
00053   vcl_string type_name() const;
00054 
00055   //: Handle all events sent to this tableau.
00056   //  It is pointless to derive from vgui_wrapper_tableau
00057   //  unless this method is also overridden!
00058   bool handle(vgui_event const &);
00059 
00060   //: Get the bounding box for this tableau.
00061   //  Defaults to getting the bounding box of the child.
00062   bool get_bounding_box(float low[3], float high[3]) const;
00063 
00064   //: The single child of this tableau.
00065   vgui_parent_child_link child;
00066 
00067  protected:
00068   // Destructor - called by vgui_wrapper_tableau_sptr.
00069   ~vgui_wrapper_tableau();
00070 };
00071 
00072 //: Create a smart-pointer to a vgui_wrapper_tableau.
00073 struct vgui_wrapper_tableau_new : public vgui_wrapper_tableau_sptr {
00074   typedef vgui_wrapper_tableau_sptr base;
00075 
00076   //: Constructor - creates a default vgui_wrapper_tableau.
00077   vgui_wrapper_tableau_new() : base(new vgui_wrapper_tableau()) { }
00078 
00079   //: Constructor - takes the single child for the vgui_wrapper_tableau.
00080   vgui_wrapper_tableau_new(vgui_tableau_sptr const&b) : base(new vgui_wrapper_tableau(b)) { }
00081 };
00082 
00083 #endif // vgui_wrapper_tableau_h_