00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
00027 Widget::Widget(MetaObject* s) : MetaObject(s), accessControl(&NoPropertyAccessControl::static_)
00028 {
00029 }
00030
00031 Widget::~Widget() {
00032 }
00033
00034
00035
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
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
00068
00069 const string Widget::getType() {
00070 return string("gui:widget");
00071 }
00072
00073
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
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
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