00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <vos/corelibs/vos/vos.hh>
00024 #include <vos/metaobjects/property/property.hh>
00025 #include "select_list.hh"
00026
00027 using namespace VOSGUI;
00028
00029
00030 SelectList::SelectList(MetaObject* s) : MetaObject(s), Select(s), Widget(s),
00031 choices(0), selected(0)
00032 {
00033 }
00034
00035
00036 SelectList::~SelectList() {
00037 }
00038
00039
00040 LocalSelectList::LocalSelectList(MetaObject* s) : SelectList(s), MetaObject(s), Select(s), LocalSelect(s), Widget(s), LocalWidget(s)
00041 {
00042 }
00043
00044 LocalSelectList::~LocalSelectList() {
00045 }
00046
00047
00048
00049 RemoteSelectList::RemoteSelectList(MetaObject* s) : SelectList(s), MetaObject(s), Select(s), RemoteSelect(s), Widget(s), RemoteWidget(s)
00050 {
00051 }
00052
00053 RemoteSelectList::~RemoteSelectList() {
00054 }
00055
00056
00057
00058 const string SelectList::getType() {
00059 return string("gui:widget.select.list");
00060 }
00061
00062
00063 void SelectList::registerExtenders() {
00064 LocalSite::addLocalObjectExtension(typeid(LocalSelectList).name(), &LocalSelectList::new_LocalSelectList);
00065 LocalSite::addLocalObjectExtension(typeid(SelectList).name(), &LocalSelectList::new_LocalSelectList);
00066 LocalSite::addLocalObjectExtension("gui:widget.select.list", &LocalSelectList::new_LocalSelectList);
00067 RemoteSite::addRemoteObjectExtension(typeid(RemoteSelectList).name(), &RemoteSelectList::new_RemoteSelectList);
00068 RemoteSite::addRemoteObjectExtension(typeid(SelectList).name(), &RemoteSelectList::new_RemoteSelectList);
00069 RemoteSite::addRemoteObjectExtension("gui:widget.select.list", &RemoteSelectList::new_RemoteSelectList);
00070 }
00071
00072
00073
00074 deque<Vobject*> SelectList::getSelected() {
00075 deque<Vobject*> ret;
00076 const ChildList& cl = selected->getChildren();
00077 for(ChildList::const_iterator i = cl.begin(); i != cl.end(); i++) {
00078 ret.push_back((*i)->child);
00079 }
00080 return ret;
00081 }
00082
00083 Vobject* SelectList::getFirstSelected() {
00084 const ChildList& cl = selected->getChildren();
00085 for(ChildList::const_iterator i = cl.begin(); i != cl.end(); i++) {
00086 return (*i)->child;
00087 }
00088 return 0;
00089 }
00090
00091
00092 void SelectList::add(Vobject* obj, const string& name, int pos) {
00093 choices->insertChild(pos, name, obj);
00094 }
00095
00096 void SelectList::remove(Vobject* obj) throw(NoSuchObjectError) {
00097
00098
00099
00100 {
00101 const ChildList& cl = choices->getChildren();
00102 int pos = -1;
00103 for(ChildList::const_iterator i = cl.begin(); i != cl.end(); i++) {
00104 if((*i)->child == obj) {
00105 pos = (*i)->position;
00106 break;
00107 }
00108 }
00109 if(pos == -1)
00110 throw NoSuchObjectError("No such object in the selection's choices-object list");
00111 else
00112 choices->removeChild(pos);
00113 }
00114
00115 {
00116 const ChildList& cl = selected->getChildren();
00117 int pos = -1;
00118 for(ChildList::const_iterator i = cl.begin(); i != cl.end(); i++) {
00119 if((*i)->child == obj) {
00120 pos = (*i)->position;
00121 break;
00122 }
00123 }
00124 if(pos != -1)
00125 selected->removeChild(pos);
00126 }
00127 }
00128
00129 Vobject* SelectList::selectedObjectList() {
00130 return &selected;
00131 }
00132
00133 void SelectList::setSelectedObj(Vobject* obj) {
00134 selected = obj;
00135
00136 insertChild(-1, "gui:selected", &selected);
00137 }
00138
00139
00140 Vobject* SelectList::choicesObjectList() {
00141 return &choices;
00142 }
00143
00144 void SelectList::setChoicesObj(Vobject* obj) {
00145 choices = obj;
00146
00147 insertChild(-1, "gui:choices", &choices);
00148 }
00149
00150 void SelectList::setMultiple(bool m, PropertyAccessControl* pac) {
00151 if(!pac) pac = accessControl;
00152 Property::setProperty(*this, "gui:multiple", (m?"yes":"no"), "text/x-yes-no", pac);
00153 }
00154
00155 bool SelectList::getMultiple() {
00156 vRef<Property> m = getMultipleObj();
00157 if(m->read() == "yes")
00158 return true;
00159 else
00160 return false;
00161 }
00162
00163 Property* SelectList::getMultipleObj() {
00164 return meta_cast<Property*>(&findObject("gui:multiple"));
00165 }
00166
00167
00168
00169
00170
00171 MetaObject* LocalSelectList::new_LocalSelectList(MetaObject *s, const string& type) {
00172 LocalSelectList* o = new LocalSelectList(s);
00173 return o;
00174 }
00175
00176 MetaObject* RemoteSelectList::new_RemoteSelectList(MetaObject *s, const string& type) {
00177 return new RemoteSelectList(s);
00178 }
00179
00180 void LocalSelectList::initialize() {
00181 vRef<Site> site = &getSite();
00182 try {
00183 choices = findObject("gui:choices");
00184 } catch(NoSuchObjectError) {
00185 choices = site->createMetaObject("gui:choices", 0);
00186 insertChild(-1, "gui:choices", &choices);
00187 choices->addChildListener(&DoNothingListener::static_);
00188 }
00189 try {
00190 selected = findObject("gui:selected");
00191 } catch(NoSuchObjectError) {
00192 selected = site->createMetaObject("gui:selected");
00193 insertChild(-1, "gui:selected", &selected);
00194 selected->addChildListener(&DoNothingListener::static_);
00195 }
00196 setMultiple(true);
00197 SelectList::initialize();
00198 }
00199
00200 void SelectList::initialize() {
00201 try {
00202 choices = findObject("gui:choices");
00203 } catch(NoSuchObjectError) {
00204 LOG("GUI::SelectList", 2, "initialize(): Warning: no \"gui:choices\" object found.");
00205 }
00206 try {
00207 selected = findObject("gui:selected");
00208 } catch(NoSuchObjectError) {
00209 LOG("GUI::SelectList", 2, "initialize(): Warning: no \"gui:selected\" object found.");
00210 }
00211 }
00212
00213
00214 Property* SelectList::getItemLabel(Vobject& item) {
00215 const char* subobjs[4];
00216 subobjs[0] = "misc:label";
00217 subobjs[1] = "misc:title";
00218 subobjs[2] = "misc:name";
00219 subobjs[3] = "misc:nick";
00220 for(int i = 0; i < 4; i++) {
00221 try {
00222 vRef<Vobject> v = item.findObject(subobjs[i]);
00223 Property* p = meta_cast<Property*>(&v);
00224 if(p) {
00225 p->acquire();
00226 return p;
00227 }
00228 } catch(...) {}
00229 }
00230 return 0;
00231 }
00232
00233
00234