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

Go to the documentation of this file.
00001 /* $Id: select_value.cc,v 1.5 2003/07/23 00:17:21 reed Exp $ */
00002 
00003 /** @file select_value.cc Code: a MetaObject for widget.select.value object types. 
00004 
00005     Copyright (C) 2002 Reed Hedges
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Lesser General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Lesser General Public License for more details.
00016 
00017     You should have received a copy of the GNU Lesser General Public
00018     License along with this library; if not, write to the Free Software
00019     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00020 
00021 */
00022 
00023 #include <vos/corelibs/vos/vos.hh>
00024 #include <vos/metaobjects/property/property.hh>
00025 #include "select_value.hh"
00026 
00027 using namespace std;
00028 using namespace VOSGUI;
00029 
00030 /* Constructor */
00031 SelectValue::SelectValue(MetaObject* s) : MetaObject(s), Select(s), Widget(s),
00032     choices(0), selected(0)
00033 {
00034 }
00035 
00036 /* Destructor */
00037 SelectValue::~SelectValue() {
00038 }
00039 
00040 
00041 LocalSelectValue::LocalSelectValue(MetaObject* s) : SelectValue(s), MetaObject(s), Select(s), LocalSelect(s), Widget(s), LocalWidget(s)
00042 {
00043 }
00044 
00045 LocalSelectValue::~LocalSelectValue() {
00046 }
00047 
00048 
00049 
00050 RemoteSelectValue::RemoteSelectValue(MetaObject* s) : SelectValue(s), MetaObject(s), Select(s), RemoteSelect(s), Widget(s), RemoteWidget(s)
00051 {
00052 }
00053 
00054 RemoteSelectValue::~RemoteSelectValue() {
00055 }
00056 
00057 /* Return type string ("gui:widget.select.value") */
00058 const string SelectValue::getType() {
00059     return string("gui:widget.select.value");
00060 }
00061 
00062 /* Register extenders with libvos MetaFactory */
00063 void SelectValue::registerExtenders() {
00064     LocalSite::addLocalObjectExtension(typeid(LocalSelectValue).name(), &LocalSelectValue::new_LocalSelectValue);
00065     LocalSite::addLocalObjectExtension(typeid(SelectValue).name(), &LocalSelectValue::new_LocalSelectValue);
00066     LocalSite::addLocalObjectExtension("gui:widget.select.value", &LocalSelectValue::new_LocalSelectValue);
00067     RemoteSite::addRemoteObjectExtension(typeid(RemoteSelectValue).name(), &RemoteSelectValue::new_RemoteSelectValue);
00068     RemoteSite::addRemoteObjectExtension(typeid(SelectValue).name(), &RemoteSelectValue::new_RemoteSelectValue);
00069     RemoteSite::addRemoteObjectExtension("gui:widget.select.value", &RemoteSelectValue::new_RemoteSelectValue);
00070 }
00071 
00072 string SelectValue::getValue() {
00073     return selected->read();
00074 }
00075 
00076 void SelectValue::getValue(string& v) {
00077     selected->read(v);
00078 }
00079 
00080 void SelectValue::setValue(const string& v) {
00081     selected->replace(v);
00082 }
00083 
00084 
00085 void SelectValue::add(const string& label, Property* p) {
00086     choices->insertChild(-1, label, p);
00087 }
00088 
00089 void SelectValue::add(Property* p) {
00090     add(p->read(), p);
00091 }
00092 
00093 void SelectValue::add(const string& label, const string& value, PropertyAccessControl* pac) {
00094     vRef<Site> site = getSite();
00095     vRef<LocalProperty> p = meta_cast<LocalProperty*>(site->createMetaObject("", typeid(LocalProperty).name(), 0));
00096     p->insertPropertyAccessControl(0, pac);
00097     p->replace(value);
00098     add(label, &p);
00099 }
00100 
00101 void SelectValue::add(const string& val, PropertyAccessControl* pac) {
00102     add(val, val, pac);
00103 }
00104 
00105 void SelectValue::remove(const string& v) throw(NoSuchObjectError) {
00106 
00107     ///@bug only removes the first occurance of the object.
00108 
00109     const ChildList& cl = choices->getChildren();
00110     int pos = -1;
00111     for(ChildList::const_iterator i = cl.begin(); i != cl.end(); i++) {
00112         vRef<Property> p = meta_cast<Property*>((*i)->child);
00113         if(&p) {
00114             if(p->read() == v) {
00115                 pos = (*i)->position;
00116                 break;
00117             }
00118         }
00119     }
00120     if(pos == -1)
00121        throw NoSuchObjectError("No such object in the selection's choices-object value");
00122     else
00123            choices->removeChild(pos); 
00124 }
00125 
00126 
00127 Property* SelectValue::getSelectedObj() {
00128     return &selected;
00129 }
00130 
00131 Property* SelectValue::getStyleObj() {
00132     vRef<Property> p = meta_cast<Property*>(&findObject("gui:style"));
00133     if(!&p) throw bad_cast();
00134     return &p;
00135 }
00136 
00137 void SelectValue::setSelectedObj(Property* obj) {
00138     selected = obj;
00139     // TODO: remove existing "gui:selected" ?
00140     insertChild(-1, "gui:selected", &selected);
00141 }
00142 
00143 
00144 Vobject* SelectValue::getChoicesObj() {
00145     return &choices;
00146 }
00147 
00148 
00149 void SelectValue::setChoicesObj(Vobject* obj) {
00150     choices = obj;
00151     // TODO: remove existing "gui:choices" ?
00152     insertChild(-1, "gui:choices", &choices);
00153 }
00154 
00155 void SelectValue::setStyle(const string& style, PropertyAccessControl* pac) {
00156     if(!pac) pac = accessControl;
00157     Property::setProperty(*this, "gui:style", style, "text/plain", pac);
00158 }
00159     
00160 void SelectValue::setPopup(PropertyAccessControl* pac) {
00161     setStyle("popup", pac);
00162 }
00163 
00164 void SelectValue::setRadio(PropertyAccessControl* pac) {
00165     setStyle("radio", pac);
00166 }
00167 
00168 string SelectValue::getStyle() {
00169     return Property::getProperty(*this, "gui:style", "popup");
00170 }
00171 
00172 void SelectValue::setRadioOrientation(const string& ori, PropertyAccessControl* ac) {
00173     if(ac == 0) 
00174         ac = accessControl;
00175     Property::setProperty(*this, "gui:radio-orientation", ori, "text/plain", ac);
00176 }
00177 
00178 string SelectValue::getRadioOrientation() {
00179     return Property::getProperty(*this, "gui:radio-orientation", "horizontal");
00180 }
00181 
00182 void SelectValue::setRadioSize(int n, PropertyAccessControl* ac) {
00183     if(ac == 0)
00184         ac = accessControl;
00185     Property::setIntProperty(*this, "gui:radio-size", n, ac);
00186 }
00187 
00188 int SelectValue::getRadioSize() {
00189     return Property::getIntProperty(*this, "gui:radio-size");
00190 }
00191 
00192 MetaObject* LocalSelectValue::new_LocalSelectValue(MetaObject *s, const string& type) {
00193     LocalSelectValue* o = new LocalSelectValue(s);
00194     return o;
00195 }
00196 
00197 MetaObject* RemoteSelectValue::new_RemoteSelectValue(MetaObject *s, const string& type) {
00198     return new RemoteSelectValue(s);
00199 }
00200 
00201 void LocalSelectValue::initialize() {
00202     vRef<Site> site = getSite();
00203     try {
00204         choices = findObject("gui:choices");
00205     } catch(NoSuchObjectError) {
00206         choices = site->createMetaObject("gui:choices", 0);
00207         insertChild(-1, "gui:choices", &choices);
00208         choices->addChildListener(&DoNothingListener::static_);
00209     }
00210     try {
00211         selected = meta_cast<Property*>(&findObject("gui:selected"));
00212         assert(&selected);
00213     } catch(NoSuchObjectError) {
00214         selected = meta_cast<Property*>(site->createMetaObject("gui:selected", typeid(Property).name(), 0));
00215         insertChild(-1, "gui:selected", &selected);
00216     } 
00217     setPopup();
00218     SelectValue::initialize();
00219 }
00220 
00221 void SelectValue::initialize() {
00222     try {
00223         choices = findObject("gui:choices");
00224     } catch(NoSuchObjectError) {
00225         LOG("GUI::SelectValue", 2, "initialize(): Warning: no \"gui:choices\" object found.");
00226     }
00227     try {
00228         selected = meta_cast<Property*>(&findObject("gui:selected"));
00229         assert(&selected);
00230     } catch(NoSuchObjectError) {
00231         LOG("GUI::SelectValue", 2, "initialize(): Warning: no \"gui:selected\" object found.");
00232     }
00233 }
00234 

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