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.cc

Go to the documentation of this file.
00001 /* $Id: button.cc,v 1.14 2003/07/23 00:17:20 reed Exp $ 
00002 
00003     Copyright (C) 2002 Reed Hedges
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Lesser General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Lesser General Public License for more details.
00014 
00015     You should have received a copy of the GNU Lesser General Public
00016     License along with this library; if not, write to the Free Software
00017     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00018 
00019 */
00020 
00021 
00022 /** @file button.cc A MetaObject for Button object types. */
00023 
00024 #include <vos/corelibs/vos/vos.hh>
00025 #include <vos/metaobjects/property/property.hh>
00026 #include "button.hh"
00027 
00028 using namespace VOSGUI;
00029 
00030 /* Constructor */
00031 Button::Button(MetaObject* s) : Widget(s), MetaObject(s)
00032 {
00033 }
00034 
00035 Button::~Button() {
00036 }
00037 
00038 
00039 
00040 LocalButton::LocalButton(MetaObject* s) : Button(s), LocalWidget(s), Widget(s), MetaObject(s)
00041 {
00042     addMessageHandler<LocalButton>("gui:push-button", this, &LocalButton::handlePushed);
00043 }
00044 
00045 
00046 /* Initialize required subobjects: */
00047 
00048 void LocalButton::initialize(PropertyAccessControl* ac) {
00049 
00050     LocalWidget::initialize(ac);
00051 
00052     vRef<LocalSite> localsite = Site::getDefaultPeer();
00053     try {
00054         vRef<Vobject> v = findObject("gui:label");
00055     } catch(NoSuchObjectError) {
00056         setLabel("undefined", "text/plain");
00057     }
00058 }
00059 
00060 
00061 RemoteButton::RemoteButton(MetaObject* s) : Button(s), RemoteWidget(s),
00062 Widget(s), MetaObject(s)
00063 {
00064 }
00065 
00066 /* Return type string ("gui:widget.button") */
00067 
00068 const string Button::getType() {
00069     return string("gui:widget.button");
00070 }
00071 
00072 /* Register extenders with libvos MetaFactory */
00073 void Button::registerExtenders() {
00074     LocalSite::addLocalObjectExtension(typeid(LocalButton).name(), &LocalButton::new_LocalButton);
00075     LocalSite::addLocalObjectExtension(typeid(Button).name(), &LocalButton::new_LocalButton);
00076     LocalSite::addLocalObjectExtension("gui:widget.button", &LocalButton::new_LocalButton);
00077     RemoteSite::addRemoteObjectExtension(typeid(RemoteButton).name(), &RemoteButton::new_RemoteButton);
00078     RemoteSite::addRemoteObjectExtension(typeid(Button).name(), &RemoteButton::new_RemoteButton);
00079     RemoteSite::addRemoteObjectExtension("gui:widget.button", &RemoteButton::new_RemoteButton);
00080 }
00081 
00082 
00083 bool Button::getIsDefaultButton() {
00084     return Property::getBoolProperty(*this, "gui:is-default-button", false);
00085 }
00086 
00087 void Button::setIsDefaultButton(bool value, PropertyAccessControl* pac) {
00088     if(pac == 0)
00089         pac = accessControl;
00090     Property::setProperty(*this, "gui:is-default-button", (value?"yes":"no"), "text/x-yes-no", pac);
00091 }
00092 
00093 
00094 Property* Button::getIsDefaultButtonObj() {
00095     Property* p = meta_cast<Property*>(&findObject("gui:is-default-button"));
00096     if(!p) throw bad_cast();
00097     return p;
00098 }
00099 
00100 void Button::setIsDefaultButtonObj(Property* newobj) {
00101     try {
00102         vRef<ParentChildRelation> pcr = findChild("gui:is-default-button");
00103         setChild(pcr->position, "gui:is-default-button", newobj);
00104     } catch (NoSuchObjectError) {
00105         insertChild(-1, "gui:is-default-button", newobj);
00106     }
00107 }
00108 
00109 
00110 
00111 void LocalButton::push(const string& userinfo) {
00112 }
00113 
00114 void LocalButton::handlePushed(Message* m) {
00115     ButtonEvent event;
00116     try {
00117         event.userid = m->getField("userid").value;
00118     } catch(Message::NoSuchFieldError) {
00119         event.userid = "";
00120     }
00121 
00122     for(set<ButtonListener*>::const_iterator i = buttonListeners.begin(); 
00123             i != buttonListeners.end(); i++)
00124     {
00125         if(*i)
00126             (*i)->push(event);
00127     }
00128 
00129     // for old apps that subclass LocalButton
00130     push(event.userid);
00131 }
00132 
00133 void LocalButton::addButtonListener(ButtonListener* l) {
00134     RefCounted* rc = dynamic_cast<RefCounted*>(l);
00135     if(rc)
00136         rc->acquire();
00137     buttonListeners.insert(l);
00138 }
00139 
00140 void LocalButton::removeButtonListener(ButtonListener* l) {
00141     if(buttonListeners.erase(l) != 0) {
00142         RefCounted* rc = dynamic_cast<RefCounted*>(l);
00143         if(rc)
00144             rc->acquire();
00145     }
00146 }
00147 
00148 void RemoteButton::push(const string& userid) {
00149     vRef<Message> m = new Message();
00150     vRef<LocalSite> ls = RemoteVobject::initFields(this, &m, "gui:push-button", true);
00151     if(userid != "") 
00152         m->insertField(-1, "userid", userid);
00153     sendMessage(&m);
00154 }
00155 
00156 
00157 
00158 MetaObject* LocalButton::new_LocalButton(MetaObject *s, const string& type) {
00159     LocalButton* o = new LocalButton(s);
00160     return o;
00161 }
00162 
00163 MetaObject* RemoteButton::new_RemoteButton(MetaObject *s, const string& type) {
00164     return new RemoteButton(s);
00165 }
00166 

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