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

Go to the documentation of this file.
00001 /* $Id: widget.cc,v 1.22 2003/08/05 14:23:15 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 #include <vos/corelibs/vos/vos.hh>
00021 #include <vos/metaobjects/property/property.hh>
00022 #include "widget.hh"
00023 
00024 using namespace VOSGUI;
00025 
00026 /* Constructor */
00027 Widget::Widget(MetaObject* s) : MetaObject(s), accessControl(&NoPropertyAccessControl::static_)
00028 {
00029 }
00030 
00031 Widget::~Widget() {
00032 }
00033 
00034 
00035 /* Get/Set default AC */
00036 void Widget::setPropertyAccessControl(PropertyAccessControl* ac) {
00037     accessControl = ac;
00038 }
00039 
00040 PropertyAccessControl* Widget::getPropertyAccessControl() {
00041     return accessControl;
00042 }
00043 
00044 
00045 LocalWidget::LocalWidget(MetaObject* s) : Widget(s), MetaObject(s) {
00046 }
00047 
00048 
00049 /* Initialize required subobjects: */
00050 
00051 void Widget::initialize(PropertyAccessControl* ac) {
00052     setPropertyAccessControl(ac);
00053     setEnabled();
00054     setVisible();
00055 }
00056 
00057 void Widget::initialize() {
00058     initialize(&NoPropertyAccessControl::static_);
00059     setEnabled();
00060     setVisible();
00061 }
00062 
00063 RemoteWidget::RemoteWidget(MetaObject* s) : Widget(s), MetaObject(s) {
00064 }
00065 
00066 
00067 /* Return type string ("gui:widget") */
00068 
00069 const string Widget::getType() {
00070     return string("gui:widget");
00071 }
00072 
00073 /* Register extenders with libvos MetaFactory */
00074 void Widget::registerExtenders() {
00075     LocalSite::addLocalObjectExtension(typeid(LocalWidget).name(), &LocalWidget::new_LocalWidget);
00076     LocalSite::addLocalObjectExtension(typeid(Widget).name(), &LocalWidget::new_LocalWidget);
00077     LocalSite::addLocalObjectExtension("gui:widget", &LocalWidget::new_LocalWidget);
00078     RemoteSite::addRemoteObjectExtension(typeid(RemoteWidget).name(), &RemoteWidget::new_RemoteWidget);
00079     RemoteSite::addRemoteObjectExtension(typeid(Widget).name(), &RemoteWidget::new_RemoteWidget);
00080     RemoteSite::addRemoteObjectExtension("gui:widget", &RemoteWidget::new_RemoteWidget);
00081 }
00082 
00083 /* Get and set Subproperties and other Subobjects */
00084 
00085 string Widget::getAlignment() {
00086     string s;
00087     try {
00088         vRef<Vobject> v= findObject("gui:alignment");
00089         Property* p = meta_cast<Property*>(&v);
00090         if(!p) throw bad_cast();
00091         p->read(s);
00092     } catch(Vobject::NoSuchObjectError) {
00093         return "fill";
00094     }
00095     return s;
00096 }
00097 
00098 int Widget::getPadding() {
00099     int p;
00100     try {
00101         string s;
00102         vRef<Vobject> v =findObject("gui:padding");
00103         Property* r = meta_cast<Property*>(&v);
00104         if(!r) throw bad_cast();
00105         r->read(s); 
00106         p = atoi(s.c_str());
00107     } catch(Vobject::NoSuchObjectError) {
00108         p = 0;
00109     }
00110     return p;
00111 }
00112 
00113 int Widget::getProportion() {
00114     int p;
00115     try {
00116         string s;
00117         vRef<Vobject> v = findObject("gui:proportion");
00118         Property* r = meta_cast<Property*>(&v);
00119         if(!r) throw bad_cast();
00120         r->read(s);
00121         p = atoi(s.c_str());
00122     } catch(Vobject::NoSuchObjectError) {
00123         p = 1;
00124     }
00125     return p;
00126 }
00127 
00128 string Widget::getLabel() {
00129     string s;
00130     try {
00131         vRef<Vobject> v = findObject("gui:label");
00132         Property* p = meta_cast<Property*>(&v);
00133         if(!p) throw bad_cast();
00134         p->read(s);
00135     } catch (Vobject::NoSuchObjectError) {
00136         s = "";
00137     }
00138     return s;
00139 }
00140 
00141 void Widget::setAlignment(const string& value, PropertyAccessControl* ac) {
00142     if(!ac) ac = accessControl;
00143     Property::setProperty(*this, "gui:alignment", value, "text/plain", ac);
00144 }
00145 
00146 
00147 void Widget::setPadding(int value, PropertyAccessControl* ac) {
00148     if(!ac) ac = accessControl;
00149     char s[16];
00150     snprintf(s, sizeof(s), "%d", value);
00151     Property::setProperty(*this, "gui:padding", s, "text/plain", ac);
00152 }
00153 
00154 void Widget::setProportion(int value, PropertyAccessControl* ac) {
00155     if(!ac) ac = accessControl;
00156     char s[16];
00157     snprintf(s, sizeof(s), "%d", value);
00158     Property::setProperty(*this, "gui:proportion", s, "text/plain", ac);
00159 }
00160 
00161 void Widget::setLabel(const string& value, const string& datatype, PropertyAccessControl* ac) {
00162     if(!ac) ac = accessControl;
00163     Property::setProperty(*this, "gui:label", value, datatype, ac);
00164 }
00165 
00166 
00167 void Widget::setLabelObj(Property* newobj) {
00168     try {
00169         vRef<ParentChildRelation> pcr = findChild("gui:label");
00170         setChild(pcr->position, "gui:label", newobj);
00171     } catch (NoSuchObjectError) {
00172         insertChild(-1, "gui:label", newobj);
00173     }
00174 }
00175 
00176 
00177 
00178             
00179 Property* Widget::getLabelObj() {
00180     return meta_cast<Property*>(&findObject("gui:label"));
00181 }
00182         
00183 string Widget::getLabelDatatype() {
00184     string s;
00185     vRef<Vobject> v = findObject("gui:label");
00186     s = meta_cast<Property*>(&v)->getDataType(); 
00187     return s;
00188 }
00189 
00190 
00191 
00192 /* Generators for site factory */
00193 
00194 
00195 MetaObject* LocalWidget::new_LocalWidget(MetaObject *s, const string& type) {
00196     return new LocalWidget(s);
00197 }
00198 
00199 MetaObject* RemoteWidget::new_RemoteWidget(MetaObject *s, const string& type) {
00200     return new RemoteWidget(s);
00201 }
00202 
00203 void Widget::setOrInsertChild(const string& name, Vobject* obj) {
00204     try {
00205         vRef<ParentChildRelation> pcr = findChild(name);
00206         setChild(pcr->position, name, obj);
00207     } catch(NoSuchObjectError) {
00208         insertChild(-1, name, obj);
00209     }
00210 }
00211 
00212 void Widget::setEnabled(bool q, PropertyAccessControl* ac) {
00213     Property::setBoolProperty(*this, "gui:enabled", q, ac);
00214 }
00215 
00216 bool Widget::getEnabled() {
00217     return Property::getBoolProperty(*this, "gui:enabled", true);
00218 }
00219 
00220 void Widget::setEnabledObj(Property* newobj) {
00221     try {
00222         vRef<ParentChildRelation> pcr = findChild("gui:enabled");
00223         setChild(pcr->position, "gui:enabled", newobj);
00224     } catch (NoSuchObjectError) {
00225         insertChild(-1, "gui:enabled", newobj);
00226     }
00227 }
00228 
00229 Property* Widget::getEnabledObj() {
00230     return meta_cast<Property*>(&findObject("gui:enabled"));
00231 }
00232 
00233 void Widget::setVisible(bool q, PropertyAccessControl* ac) {
00234     Property::setBoolProperty(*this, "gui:visible", q, ac);
00235 }
00236 
00237 bool Widget::getVisible() {
00238     return Property::getBoolProperty(*this, "gui:visible", true);
00239 }
00240 
00241 void Widget::setVisibleObj(Property* newobj) {
00242     try {
00243         vRef<ParentChildRelation> pcr = findChild("gui:visible");
00244         setChild(pcr->position, "gui:visible", newobj);
00245     } catch (NoSuchObjectError) {
00246         insertChild(-1, "gui:visible", newobj);
00247     }
00248 }
00249 
00250 Property* Widget::getVisibleObj() {
00251     return meta_cast<Property*>(&findObject("gui:visible"));
00252 }
00253 

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