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

Go to the documentation of this file.
00001 /* $Id: container.cc,v 1.20 2003/08/05 14:23:15 reed Exp $ */
00002 
00003 
00004 /*
00005 
00006     Copyright (C) 2002 Reed Hedges
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Lesser General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Lesser General Public License for more details.
00017 
00018     You should have received a copy of the GNU Lesser General Public
00019     License along with this library; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00021 */
00022 
00023 
00024 /** @file container.cc Code: a MetaObject for Container object types. */
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 /* Constructor */
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     //addMessageHandler<LocalContainer>("gui:container-hidden", this, &LocalContainer::handleHidden);
00043     addMessageHandler<LocalContainer>("gui:start-listening", this, &LocalContainer::handleStartListening);
00044 }
00045 
00046 
00047 
00048 
00049 
00050 /* Return type string ("gui:container") */
00051 
00052 const string Container::getType() {
00053     return string("gui:widget.container");
00054 }
00055 
00056 /* Register extenders with libvos MetaFactory */
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     // these names are deprecated
00066     LocalSite::addLocalObjectExtension("gui:container", &LocalContainer::new_LocalContainer);
00067     RemoteSite::addRemoteObjectExtension("gui:container", &RemoteContainer::new_RemoteContainer);
00068 }
00069 
00070 
00071 
00072 /* Get and set Subproperties and other Subobjects */
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     // TODO: could check that the "listen" field is "raise"...
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     // override me
00188 }
00189 
00190 #endif 
00191 
00192 void RemoteContainer::raise() { 
00193     LOG("VOSGUI::RemoteContainer", 0, "INTERNAL ERROR: raise() in base class called.");
00194 }
00195 
00196 //void RemoteContainer::hide() { 
00197 //    LOG("VOSGUI::RemoteContainer", 0, "INTERNAL ERROR: hide() in base class called.");
00198 //}
00199 
00200 void RemoteContainer::handleRaise(Message* m) {
00201     LOG("VOSGUI::RemoteContainer", 2, "Recieved raise message...");
00202     raise();
00203 }
00204 
00205 
00206 //void RemoteContainer::handleHide(Message* m) {
00207 //    LOG("VOSGUI::RemoteContainer", 2, "Recieved hide message...");
00208 //    hide();
00209 //}
00210 
00211 
00212 /* Generators for factory */
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 

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