00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <vos/corelibs/vos/vos.hh>
00027 #include <vos/metaobjects/property/property.hh>
00028 #include "container.hh"
00029
00030 using namespace VOSGUI;
00031
00032
00033 Container::Container(MetaObject* s) : Widget(s), MetaObject(s) {
00034 }
00035
00036 Container::~Container() {
00037 }
00038
00039
00040
00041 LocalContainer::LocalContainer(MetaObject* s) : Container(s), LocalWidget(s), Widget(s), MetaObject(s) {
00042
00043 addMessageHandler<LocalContainer>("gui:start-listening", this, &LocalContainer::handleStartListening);
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 const string Container::getType() {
00053 return string("gui:widget.container");
00054 }
00055
00056
00057 void Container::registerExtenders() {
00058 LocalSite::addLocalObjectExtension(typeid(LocalContainer).name(), &LocalContainer::new_LocalContainer);
00059 LocalSite::addLocalObjectExtension(typeid(Container).name(), &LocalContainer::new_LocalContainer);
00060 LocalSite::addLocalObjectExtension("gui:widget.container", &LocalContainer::new_LocalContainer);
00061 RemoteSite::addRemoteObjectExtension(typeid(RemoteContainer).name(), &RemoteContainer::new_RemoteContainer);
00062 RemoteSite::addRemoteObjectExtension(typeid(Container).name(), &RemoteContainer::new_RemoteContainer);
00063 RemoteSite::addRemoteObjectExtension("gui:widget.container", &RemoteContainer::new_RemoteContainer);
00064
00065
00066 LocalSite::addLocalObjectExtension("gui:container", &LocalContainer::new_LocalContainer);
00067 RemoteSite::addRemoteObjectExtension("gui:container", &RemoteContainer::new_RemoteContainer);
00068 }
00069
00070
00071
00072
00073
00074 string Container::getLayout() {
00075 return Property::getProperty(*this, "gui:layout", "vertical");
00076 }
00077
00078 void Container::setLayout(const string& value, PropertyAccessControl* ac) {
00079 if(!ac)
00080 ac = accessControl;
00081 Property::setProperty(*this, "gui:layout", value, "text/plain", ac);
00082 }
00083
00084 bool Container::getBorder() {
00085 return Property::getBoolProperty(*this, "gui:border", false);
00086 }
00087
00088 void Container::setBorder(bool value, PropertyAccessControl* ac) {
00089 if(!ac)
00090 ac = accessControl;
00091 Property::setProperty(*this, "gui:border", value?"yes":"no", "text/x-yes-no", ac);
00092 }
00093
00094 bool Container::getCompact() {
00095 return Property::getBoolProperty(*this, "gui:compact", false);
00096 }
00097
00098 void Container::setCompact(bool val, PropertyAccessControl* ac) {
00099 if(!ac) ac = accessControl;
00100 Property::setBoolProperty(*this, "gui:compact", val, ac);
00101 }
00102
00103 void Container::setCompactObject(Property* obj) {
00104 assert(obj);
00105 try {
00106 vRef<ParentChildRelation> pcr = findChild("gui:compact");
00107 setChild(pcr->position, "gui:compact", obj);
00108 } catch (NoSuchObjectError) {
00109 insertChild(-1, "gui:compact", obj);
00110 }
00111 }
00112
00113 Property* Container::getCompactObject() {
00114 Property* p = meta_cast<Property*>(&findObject("gui:target"));
00115 if(!p) throw bad_cast();
00116 return p;
00117 }
00118
00119
00120
00121 void LocalContainer::raise() {
00122 LOG("VOSGUI::LocalContainer", 2, "Sending raise message");
00123 vRef<Message> m = new Message();
00124 m->setType("update");
00125 m->setFrom(getURL().getString());
00126 m->setSourceSite(&getSite());
00127 m->setMethod("gui:raise-container");
00128 for(vector<Vobject*>::const_iterator i = remoteWindows.begin();
00129 i != remoteWindows.end(); i++)
00130 {
00131 m->setTo( (*i)->getURL().getString() );
00132 (*i)->getSite().sendMessage(&m);
00133 }
00134 }
00135
00136 #if 0
00137 void LocalContainer::hide() {
00138 LOG("VOSGUI::LocalContainer", 2, "Sending hide messages");
00139 vRef<Message> m = new Message();
00140 m->setType("update");
00141 m->setFrom(getURL().getString());
00142 m->setSourceSite(&getSite());
00143 m->setMethod("gui:hide-container");
00144 for(vector<Vobject*>::const_iterator i = remoteWindows.begin();
00145 i != remoteWindows.end(); i++)
00146 {
00147 m->setTo( (*i)->getURL().getString() );
00148 (*i)->getSite().sendMessage(&m);
00149 }
00150 }
00151 #endif
00152
00153 void LocalContainer::handleStartListening(Message* m) {
00154
00155 try {
00156 remoteWindows.push_back(&(Vobject::findObjectFromRoot(m->getFrom())));
00157 } catch(exception& e) {
00158 LOG("VOSGUI::LocalContainer", 0, "Error handling \"start-listening\" message: " << e.what());
00159 }
00160 }
00161
00162 RemoteContainer::RemoteContainer(MetaObject* s) : Container(s), RemoteWidget(s), Widget(s), MetaObject(s) {
00163 LOG("Remotecontainer", 0, "registering raise handler");
00164 addUpdateHandler<RemoteContainer>("gui:raise-container", this, &RemoteContainer::handleRaise);
00165
00166 LOG("VOSGUI::RemoteContainer", 2, "Sending start-listening message");
00167 vRef<Message> m = new Message();
00168 vRef<LocalSite> ls = RemoteVobject::initFields(this, &m, "gui:start-listening", true);
00169 m->insertField(-1, "listen", "raise");
00170 sendMessage(&m);
00171 }
00172
00173
00174 #if 0
00175 void RemoteContainer::hidden() {
00176 LOG("VOSGUI::RemoteContainer", 2, "Sending hidden message");
00177 vRef<Message> m = new Message();
00178 vRef<LocalSite> ls = RemoteVobject::initFields(this, &m, "gui:container-hidden", true);
00179 sendMessage(&m);
00180 }
00181
00182 void LocalContainer::handleHidden(Message* m) {
00183 hidden();
00184 }
00185
00186 void LocalContainer::hidden() {
00187
00188 }
00189
00190 #endif
00191
00192 void RemoteContainer::raise() {
00193 LOG("VOSGUI::RemoteContainer", 0, "INTERNAL ERROR: raise() in base class called.");
00194 }
00195
00196
00197
00198
00199
00200 void RemoteContainer::handleRaise(Message* m) {
00201 LOG("VOSGUI::RemoteContainer", 2, "Recieved raise message...");
00202 raise();
00203 }
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215 MetaObject* LocalContainer::new_LocalContainer(MetaObject *s, const string& type) {
00216 return new LocalContainer(s);
00217 }
00218
00219 MetaObject* RemoteContainer::new_RemoteContainer(MetaObject *s, const string& type) {
00220 return new RemoteContainer(s);
00221 }
00222