00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
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 
00039 
00040 
00041 
00042     class VOSGUI_API Button : public virtual Widget
00043     {
00044 
00045 
00046     public:
00047 
00048 
00049         Button(MetaObject* superobject);
00050 
00051     
00052 
00053         virtual ~Button();
00054 
00055 
00056         virtual const string getType();
00057 
00058 
00059         static void registerExtenders();
00060 
00061 
00062 
00063 
00064 
00065 
00066 
00067 
00068 
00069 
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 
00080 
00081 
00082 
00083 
00084 
00085 
00086         virtual void push(const string& userid = "") = 0;
00087 
00088     };
00089 
00090 
00091 
00092     class VOSGUI_API ButtonEvent {
00093     public:
00094         string userid;
00095     };
00096 
00097 
00098     class VOSGUI_API ButtonListener {
00099     public:
00100         virtual void push(const VOSGUI::ButtonEvent& event) = 0;
00101     };
00102 
00103 
00104 
00105     class VOSGUI_API LocalButton : public virtual LocalWidget, public virtual Button
00106     {
00107     private:
00108         std::set<ButtonListener*> buttonListeners;
00109 
00110     public:
00111 
00112 
00113         LocalButton(MetaObject* superobject);
00114 
00115         virtual void initialize(PropertyAccessControl* ac);
00116         virtual void initialize() {
00117             LocalWidget::initialize();
00118         }
00119 
00120 
00121         static MetaObject* new_LocalButton(MetaObject* superobject, const string& type);
00122 
00123 
00124         void addButtonListener(ButtonListener* l);
00125 
00126 
00127         void removeButtonListener(ButtonListener* l);
00128 
00129 
00130 
00131 
00132 
00133         virtual void push(const string& userid = "");
00134 
00135     protected:
00136 
00137 
00138         virtual void handlePushed(Message* m);
00139 
00140     };
00141 
00142 
00143 
00144     class VOSGUI_API RemoteButton : public virtual RemoteWidget, public virtual Button
00145     {
00146     public:
00147 
00148 
00149         RemoteButton(MetaObject* superobject);
00150 
00151 
00152         static MetaObject* new_RemoteButton(MetaObject* superobject, const string& type);
00153 
00154         virtual void push(const string& userid = "");
00155     };
00156 
00157 
00158 
00159 
00160 
00161 
00162 
00163 
00164 
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 
00185 
00186 
00187 
00188 
00189 
00190 
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