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

vos/gui/gui/button.hh

Go to the documentation of this file.
00001 /* $Id: button.hh,v 1.26 2003/08/05 14:23:15 reed Exp $ */
00002 
00003 
00004 /* This file was generated by otd2cpp.pl, a script for VOS by Reed Hedges <reed@zerohour.net>
00005    and Peter Amstutz <tetron@interreality.org>
00006 
00007    Search for TODO for stuff that needs editing. You will want to especially fill in constructors,
00008    destructors, message handlers, non-property subobjects...
00009 
00010    I can make no guarantee that this code will work, or even that it even is safe to run.
00011    Use it at your own risk.
00012 */
00013 
00014 /** @file button.hh Defines MetaObject class for Button type (revision 0).
00015 
00016 */
00017 
00018 #ifndef _BUTTON_HH_
00019 #define _BUTTON_HH_
00020 
00021 #if defined(_WIN32) && defined(_MSC_VER)
00022 # ifdef VOSGUI_EXPORTS
00023 #  define VOSGUI_API __declspec(dllexport)
00024 # else
00025 #  define VOSGUI_API __declspec(dllimport)
00026 # endif
00027 #else
00028 # define VOSGUI_API
00029 #endif
00030 
00031 #include <vos/corelibs/vos/vos.hh>
00032 #include <vos/metaobjects/property/property.hh>
00033 #include "widget.hh"
00034 
00035 namespace VOSGUI
00036 {
00037 
00038     /** MetaObject implementing Button Object Type.
00039         Represents a button component, which sends a message back to the
00040         LocalButton when pressed.
00041     */
00042     class VOSGUI_API Button : public virtual Widget
00043     {
00044 
00045 
00046     public:
00047 
00048         /** Constructor */
00049         Button(MetaObject* superobject);
00050 
00051     
00052         /** Destructor */
00053         virtual ~Button();
00054 
00055         /** Return type string ("gui:widget.button") */
00056         virtual const string getType();
00057 
00058         /** Register Extenders */
00059         static void registerExtenders();
00060 
00061 
00062         /** The client application may choose a button to be the "default"
00063           * choice in a window or other application context.  Use this
00064           * property to indicate which button you want to be the default.
00065           * If more than one button has this property set to true, then
00066           * the client application will choose one (typically the last
00067           * one it loads.) Changing this property to true will also probably
00068           * cause already-connected clients to use this button as their
00069           * new default.
00070          */
00071         //@{
00072         virtual void setIsDefaultButton(bool v = true, PropertyAccessControl* pac = 0);
00073         virtual bool getIsDefaultButton();
00074         virtual void setIsDefaultButtonObj(Property* newobj);
00075         virtual Property* getIsDefaultButtonObj();
00076         //@}
00077 
00078 
00079         /** Call on remote objects to indicate a putton press. Local objects
00080          *  will notify listeners (see LocalButton::push).
00081          *  @param userid If available, this is a string that can be used to
00082          *                identify a particular user. Typically, it will be
00083          *                in the form "user@hostname" or "usertype:someid@hostname"
00084          *
00085          */
00086         virtual void push(const string& userid = "") = 0;
00087 
00088     };
00089 
00090 
00091     /** Represents a button event. */
00092     class VOSGUI_API ButtonEvent {
00093     public:
00094         string userid;
00095     };
00096 
00097     /** Listener for button events (ie, push) */
00098     class VOSGUI_API ButtonListener {
00099     public:
00100         virtual void push(const VOSGUI::ButtonEvent& event) = 0;
00101     };
00102 
00103 
00104     /** Local version of Button.  */
00105     class VOSGUI_API LocalButton : public virtual LocalWidget, public virtual Button
00106     {
00107     private:
00108         std::set<ButtonListener*> buttonListeners;
00109 
00110     public:
00111 
00112         /** Constructor */
00113         LocalButton(MetaObject* superobject);
00114 
00115         virtual void initialize(PropertyAccessControl* ac);
00116         virtual void initialize() {
00117             LocalWidget::initialize();
00118         }
00119 
00120         /** Static generator, for factory. */
00121         static MetaObject* new_LocalButton(MetaObject* superobject, const string& type);
00122 
00123         /** Add a new listener */
00124         void addButtonListener(ButtonListener* l);
00125 
00126         /** Remove an existing listener */
00127         void removeButtonListener(ButtonListener* l);
00128 
00129 
00130         /** Called when the button is pressed. 
00131          * @deprecated use a ButtonListener instead.
00132          */
00133         virtual void push(const string& userid = "");
00134 
00135     protected:
00136 
00137         /** Handle message pushed by simply calling this->push(); */
00138         virtual void handlePushed(Message* m);
00139 
00140     };
00141 
00142 
00143 /** Remote version of Button. */
00144     class VOSGUI_API RemoteButton : public virtual RemoteWidget, public virtual Button
00145     {
00146     public:
00147 
00148         /** Constructor */
00149         RemoteButton(MetaObject* superobject);
00150 
00151         /** Static generator, for factory. */
00152         static MetaObject* new_RemoteButton(MetaObject* superobject, const string& type);
00153 
00154         virtual void push(const string& userid = "");
00155     };
00156 
00157 
00158 /** @def VOSGUI_DEFINE_BUTTON 
00159  * @deprecated Don't use this, use a ButtonListener with a LocalButton object
00160  * This macro defines a subclass of VOSGUI::Button named CLASS. The button will
00161  * have label LABEL. The push() method is left undefined; you must define
00162  * a method void CLASS::push() somewhere. You may supply a class DATA, and
00163  * a member object of that class will be declared (protected)named data. DATA
00164  * must be a subclass of RefCounted.
00165  */
00166 #define VOSGUI_DEFINE_BUTTON(CLASS, DATA, LABEL)  \
00167     class CLASS : public virtual VOSGUI::LocalButton { \
00168     protected: \
00169         vRef<DATA> data; \
00170     public: \
00171         CLASS(MetaObject* super) : VOSGUI::LocalButton(super), VOSGUI::Button(super), VOSGUI::LocalWidget(super), VOSGUI::Widget(super), MetaObject(super) {  \
00172         }\
00173         static MetaObject* new_##CLASS (MetaObject* super, const string& type) { \
00174             return new CLASS(super); \
00175         }\
00176         void setup(DATA* data_p = 0) { \
00177             data = data_p; \
00178             setLabel(LABEL); \
00179         }\
00180         virtual void push(const string& userid = ""); \
00181     };
00182 
00183 
00184 /** @def VOSGUI_CREATE_BUTTON
00185  *  @deprecated Don't use this, use a ButtonListener on a LocalButton object.
00186  *  This macro registers a local metaobject extension for CLASS and then creates
00187  *  a MetaObject instantiation of CLASS on site SITE (a pointer or a vRef) and 
00188  *  inserts it into the  Vobject PARENT (a pointer or a vRef). DATA should be an 
00189  *  object whose class you passed to VOSGUI_DEFINE_BUTTON.
00190  *  The button's name will be the same as its CLASS name.
00191  */
00192 #define VOSGUI_CREATE_BUTTON(CLASS, PARENT, SITE, DATA) { \
00193     LocalSite::addLocalObjectExtension(typeid(CLASS).name(), &CLASS::new_##CLASS); \
00194     vRef<MetaObject> o = (SITE)->createMetaObject(#CLASS, typeid(CLASS).name(), 0); \
00195     vRef<CLASS> b = MetaObject::meta_cast<CLASS*>(&o); \
00196     assert(&b); \
00197     b->initialize(&NoPropertyAccessControl::static_); \
00198     b->setup(DATA); \
00199     (PARENT)->insertChild(-1, #CLASS, &o); \
00200 }
00201 
00202 }
00203 
00204 #endif // #ifdef _BUTTON_HH_
00205 

Generated on Tue Aug 12 03:55:42 2003 for Interreality Project - VOS by doxygen 1.3.2