Wt::Object Class Reference

#include <object.h>

Inheritance diagram for Wt::Object:

Inheritance graph
[legend]
Collaboration diagram for Wt::Object:

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::list< Object * > List

Public Member Functions

 Object (Object *parent=0, const std::string &name="Object::anon")
virtual ~Object ()
Objectparent () const
const Listchildren () const
Listchildren ()
bool isDescendant (const Object *p) const
virtual void insertChild (Object *obj)
virtual void removeChild (Object *obj)
void reparent (Object *new_parent)
template<typename T>
void deleteFirstChild ()
template<typename T>
void deleteLastChild ()
template<typename T>
void deleteAllChildren ()
ObjecttopParent () const
 returns top level parent: it may return itself
const std::string & name () const
void installEventFilter (const Object *filterObj)
void removeEventFilter (const Object *obj)
virtual bool eventFilter (Object *, Event *)
int startTimer (int interval)
void killTimer (int id)
void killTimers ()
virtual bool event (Event *e)
 event handling

Public Attributes

Signal01< void, const Object * > destroyed
 signals

Protected Member Functions

virtual void childEvent (ChildEvent *)
 event handling specialization
virtual void customEvent (CustomEvent *)
virtual void timerEvent (TimerEvent *)
bool filterEvent (Event *)

Private Types

typedef std::map< int, SDLTimer * > SDLTimerPtrMap

Private Member Functions

SDLTimertimer (int id) const
 check if SDL timer still exists

Private Attributes

Objectparent_
std::string name_
List children_
List eventFilters_
SDLTimerPtrMap timers_

Detailed Description

Definition at line 45 of file object.h.


Member Typedef Documentation

typedef std::list<Object*> Wt::Object::List

Definition at line 47 of file object.h.

typedef std::map<int, SDLTimer *> Wt::Object::SDLTimerPtrMap [private]

Definition at line 161 of file object.h.


Constructor & Destructor Documentation

Wt::Object::Object ( Object parent = 0,
const std::string &  name = "Object::anon" 
)

Definition at line 30 of file object.cpp.

References insertChild(), parent_, and trace.

00030                                                     :
00031         parent_(parent),
00032 name_(name) {
00033     trace("obj") << "Creating " << this << std::endl;
00034     if (parent_)
00035         parent_->insertChild(this);
00036 }

Here is the call graph for this function:

Wt::Object::~Object (  )  [virtual]

Definition at line 38 of file object.cpp.

References Wt::Event::ChildRemoved, children_, destroyed, killTimers(), parent_, Wt::Application::postEvent(), removeChild(), Wt::Application::sendPostedEvents(), and trace.

00038                 {
00039     trace("obj") << "Entering Destructor for " <<  this << std::endl;
00040     destroyed(this);
00041     // delete childs
00042     while (!children_.empty()) {
00043         Object *child = *children_.begin();
00044         trace("obj") << "Deleting child " << child << std::endl;
00045         delete child;
00046     }
00047 
00048     if (parent_)
00049         parent_->removeChild(this);
00050 
00051     // kill all pending timers
00052     killTimers();
00053 
00054     // this is to signal queue to not deliver any message to this object
00055 
00056     // from this point on it is not possible to deliver any SDLTimeEvent
00057     // in the SDL stack. We only have to take care the interval == 0 case.
00058     // Actually we don't have to do that either because rescheduling happens
00059     // on the same level with the timer event and we are not going to get
00060     // anymore of that after the next statement.
00061     Event *child_event = new ChildEvent(Event::ChildRemoved, this);
00062     Application::postEvent(0, child_event);
00063     trace("obj") << "Destroyed " <<  this << std::endl;
00064     Application::sendPostedEvents();
00065 }

Here is the call graph for this function:


Member Function Documentation

virtual void Wt::Object::childEvent ( ChildEvent  )  [inline, protected, virtual]

event handling specialization

Reimplemented in Wt::Window::Frame.

Definition at line 146 of file object.h.

Referenced by event().

00146 {}

List& Wt::Object::children (  )  [inline]

Definition at line 61 of file object.h.

References children_.

00061                      {
00062         return children_;
00063     }

const List& Wt::Object::children (  )  const [inline]

Definition at line 57 of file object.h.

References children_.

Referenced by Wt::RootWindow::blit_region_ex(), Wt::Widget::childAt(), deleteAllChildren(), deleteFirstChild(), deleteLastChild(), Wt::Widget::focusNextPrevChild(), Wt::Widget::fontChange(), Wt::Widget::lower(), Wt::postLayoutHintEventRecursively(), and Wt::Widget::raise().

00057                                  {
00058         return children_;
00059     }

virtual void Wt::Object::customEvent ( CustomEvent  )  [inline, protected, virtual]

Definition at line 147 of file object.h.

Referenced by event().

00147 {}

template<typename T>
void Wt::Object::deleteAllChildren (  )  [inline]

Definition at line 106 of file object.h.

References children().

00106                              {
00107         List::iterator it(children().begin());
00108         List::iterator end(children().end());
00109 
00110         while (it != end) {
00111             T *t = dynamic_cast<T *>(*it);
00112             // before iteration invalidation
00113             ++it;
00114             // this will invalidate the iterator
00115             if (t) {
00116                 delete t;
00117             }
00118         }
00119     }

Here is the call graph for this function:

template<typename T>
void Wt::Object::deleteFirstChild (  )  [inline]

Definition at line 72 of file object.h.

References children().

00072                             {
00073         List::iterator it(children().begin());
00074         List::iterator end(children().end());
00075 
00076         while (it != end) {
00077             T *t = dynamic_cast<T *>(*it);
00078             // before iteration invalidation
00079             ++it;
00080             // this will invalidate the iterator
00081             if (t) {
00082                 delete t;
00083                 break;
00084             }
00085         }
00086     }

Here is the call graph for this function:

template<typename T>
void Wt::Object::deleteLastChild (  )  [inline]

Definition at line 89 of file object.h.

References children().

00089                            {
00090         List::reverse_iterator it(children().rbegin());
00091         List::reverse_iterator end(children().rend());
00092 
00093         while (it != end) {
00094             T *t = dynamic_cast<T *>(*it);
00095             // before iteration invalidation
00096             ++it;
00097             // this will invalidate the iterator
00098             if (t) {
00099                 delete t;
00100                 break;
00101             }
00102         }
00103     }

Here is the call graph for this function:

bool Wt::Object::event ( Event e  )  [virtual]

event handling

Reimplemented in Wt::Application, and Wt::Widget.

Definition at line 173 of file object.cpp.

References childEvent(), Wt::Event::ChildInserted, Wt::Event::ChildRemoved, customEvent(), filterEvent(), Wt::SDLTimer::scheduleNext(), timer(), Wt::Event::Timer, timerEvent(), Wt::Event::type(), and Wt::Event::User.

Referenced by Wt::Widget::event(), Wt::Application::notify(), and Wt::Application::postEvent().

00173                            {
00174     bool handled = true;
00175 
00176     if (filterEvent(e))
00177         return true;
00178 
00179     switch (e->type()) {
00180     case Event::Timer: {
00181             TimerEvent *te = static_cast<TimerEvent *>(e);
00182             int id = te->timerid();
00183             if (timer(id)) {
00184                 timerEvent(te);
00185             }
00186             // if it is signle shot it may have been killed
00187             // during eventhandling
00188             SDLTimer *t = timer(id);
00189             if (t)
00190                 t->scheduleNext();
00191         }
00192         break;
00193     case Event::ChildInserted:
00194     case Event::ChildRemoved:
00195         childEvent(static_cast<ChildEvent *>(e));
00196         break;
00197     default:
00198         if (e->type() >= Event::User) {
00199             customEvent(static_cast<CustomEvent *>(e));
00200         } else {
00201             handled = false;
00202         }
00203         break;
00204     }
00205 
00206     return handled;
00207 }

Here is the call graph for this function:

virtual bool Wt::Object::eventFilter ( Object ,
Event  
) [inline, virtual]

Reimplemented in Wt::Layout.

Definition at line 130 of file object.h.

Referenced by Wt::Layout::eventFilter().

00130                                                 {
00131         return false;
00132     }

bool Wt::Object::filterEvent ( Event  )  [protected]

Definition at line 164 of file object.cpp.

References eventFilters_.

Referenced by event(), and Wt::Application::event().

00164                                  {
00165     for (List::iterator filter(eventFilters_.begin()),
00166             end(eventFilters_.end()); filter != end; ++filter) {
00167         if ((*filter)->eventFilter(this, e))
00168             return true;
00169     }
00170     return false;
00171 }

void Wt::Object::insertChild ( Object obj  )  [virtual]

Definition at line 81 of file object.cpp.

References Wt::Event::ChildInserted, children_, parent_, and Wt::Application::postEvent().

Referenced by Object(), and reparent().

00081                                     {
00082     children_.push_back(obj);
00083     obj->parent_ = this;
00084     Event *child_event = new ChildEvent(Event::ChildInserted, obj);
00085     Application::postEvent(this, child_event);
00086 }

Here is the call graph for this function:

void Wt::Object::installEventFilter ( const Object filterObj  ) 

Definition at line 124 of file object.cpp.

References destroyed, eventFilters_, and removeEventFilter().

Referenced by Wt::Widget::setLayout().

00124                                                        {
00125     // we have to deconstify here. We cannot deliver event to const objects
00126     Object *obj = const_cast<Object *>(filterObj);
00127     eventFilters_.push_back(obj);
00128     obj->destroyed.connect(sigc::slot1<void, const Object *>(
00129                                sigc::mem_fun(*this, &Object::removeEventFilter)));
00130 }

Here is the call graph for this function:

bool Wt::Object::isDescendant ( const Object p  )  const

Definition at line 67 of file object.cpp.

References parent().

Referenced by Wt::SDLInput::EventInfo::EventInfo(), and Wt::SDLInput::handleKeyEvent().

00067                                                {
00068     if (!p)
00069         return false;
00070 
00071     const Object *q = this;
00072 
00073     do {
00074         if (p == q)
00075             return true;
00076     } while ((q = q->parent()));
00077 
00078     return false;
00079 }

Here is the call graph for this function:

void Wt::Object::killTimer ( int  id  ) 

Definition at line 145 of file object.cpp.

References timers_.

Referenced by Wt::Timer::stop().

00145                              {
00146     delete timers_[id];
00147     timers_.erase(id);
00148 }

void Wt::Object::killTimers (  ) 

Definition at line 150 of file object.cpp.

References timers_.

Referenced by ~Object().

00150                         {
00151     uint n = timers_.size() + 1;
00152     for (uint i = 1; i < n; i++) {
00153         delete timers_[i];
00154     }
00155     timers_.clear();
00156 }

const std::string& Wt::Object::name (  )  const [inline]

Definition at line 124 of file object.h.

References name_.

Referenced by Wt::operator<<(), Wt::Application::parseArgs(), and Wt::PushButton::setButtonSize().

00124                                   {
00125         return name_;
00126     }

Object* Wt::Object::parent (  )  const [inline]

Definition at line 53 of file object.h.

References parent_.

Referenced by Wt::Widget::event(), Wt::Widget::focusNextPrevChild(), Wt::Window::Frame::Frame(), Wt::Widget::is_hidden(), isDescendant(), Wt::Layout::isTopLevel(), Wt::Layout::Layout(), Wt::Widget::lower(), Wt::Layout::mainWidget(), Wt::operator<<(), Wt::Widget::paintEvent(), Wt::Widget::parentWidget(), Wt::Application::postEvent(), Wt::Widget::raise(), Wt::Widget::updateGeometry(), Wt::Widget::Widget(), Wt::Window::Window(), Wt::Layout::~Layout(), and Wt::Widget::~Widget().

00053                            {
00054         return parent_;
00055     };

void Wt::Object::removeChild ( Object obj  )  [virtual]

Definition at line 88 of file object.cpp.

References Wt::Event::ChildRemoved, children_, parent_, and Wt::Application::postEvent().

Referenced by reparent(), and ~Object().

00088                                     {
00089     List::iterator end = children_.end();
00090     List::iterator p = find(children_.begin(), end, obj);
00091 
00092     if (p != end) {
00093         children_.erase(p);
00094         obj->parent_ = 0;
00095         Event *child_event = new ChildEvent(Event::ChildRemoved, obj);
00096         Application::postEvent(this, child_event);
00097     }
00098 }

Here is the call graph for this function:

void Wt::Object::removeEventFilter ( const Object obj  ) 

Definition at line 132 of file object.cpp.

References eventFilters_.

Referenced by installEventFilter().

00132                                                 {
00133     List::iterator p, end(eventFilters_.end());
00134     p = find(eventFilters_.begin(), end, obj);
00135     if (p != end)
00136         eventFilters_.erase(p);
00137 }

void Wt::Object::reparent ( Object new_parent  ) 

Definition at line 100 of file object.cpp.

References insertChild(), parent_, removeChild(), and trace.

Referenced by Wt::Layout::addItem(), Wt::Widget::reparent(), and Wt::Widget::setLayout().

00100                                         {
00101     if (parent_ == new_parent)
00102         return;
00103     trace("obj") << "Reparenting " <<  this << std::endl;
00104 
00105     if (parent_) {
00106         trace("obj") << "   Leaving parent " <<  parent_ << std::endl;
00107         parent_->removeChild(this);
00108     }
00109     if (new_parent) {
00110         trace("obj") << "   Going to new parent " <<  new_parent << std::endl;
00111         new_parent->insertChild(this);
00112     }
00113     parent_ = new_parent;
00114 }

Here is the call graph for this function:

int Wt::Object::startTimer ( int  interval  ) 

Definition at line 139 of file object.cpp.

References timers_.

Referenced by Wt::Timer::start().

00139                                    {
00140     int id = timers_.size() + 1;
00141     timers_[id] = new SDLTimer(this, id, interval);
00142     return id;
00143 }

SDLTimer * Wt::Object::timer ( int  id  )  const [private]

check if SDL timer still exists

Definition at line 159 of file object.cpp.

References timers_.

Referenced by event().

00159                                     {
00160     SDLTimerPtrMap::const_iterator it = timers_.find(id);
00161     return (it != timers_.end() ? it->second : 0);
00162 }

virtual void Wt::Object::timerEvent ( TimerEvent  )  [inline, protected, virtual]

Reimplemented in Wt::Timer.

Definition at line 148 of file object.h.

Referenced by event(), and Wt::Timer::timerEvent().

00148 {}

Object * Wt::Object::topParent (  )  const

returns top level parent: it may return itself

Definition at line 116 of file object.cpp.

References parent_.

Referenced by Wt::Widget::topParentWidget().

00116                                 {
00117     const Object *p = this;
00118     while (p->parent_) {
00119         p = p->parent_;
00120     }
00121     return const_cast<Object *>(p);
00122 }


Member Data Documentation

List Wt::Object::children_ [private]

Definition at line 155 of file object.h.

Referenced by children(), Wt::Widget::focusNextPrevChild(), insertChild(), removeChild(), and ~Object().

Signal01<void, const Object *> Wt::Object::destroyed

signals

Definition at line 139 of file object.h.

Referenced by Wt::Layout::addItem(), installEventFilter(), and ~Object().

List Wt::Object::eventFilters_ [private]

Definition at line 156 of file object.h.

Referenced by filterEvent(), installEventFilter(), and removeEventFilter().

std::string Wt::Object::name_ [private]

Definition at line 154 of file object.h.

Referenced by name().

Object* Wt::Object::parent_ [private]

Definition at line 153 of file object.h.

Referenced by insertChild(), Object(), parent(), removeChild(), reparent(), topParent(), and ~Object().

SDLTimerPtrMap Wt::Object::timers_ [private]

Definition at line 162 of file object.h.

Referenced by killTimer(), killTimers(), startTimer(), and timer().


The documentation for this class was generated from the following files:

Generated Fri Jul 28 19:30:24 2006.
Copyright © 1998-2003 by the respective authors.

This document is licensed under the terms of the GNU Free Documentation License and may be freely distributed under the conditions given by this license.