Wt::Application Class Reference

Toplevel application class. More...

#include <application.h>

Inheritance diagram for Wt::Application:

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

Collaboration graph
[legend]
List of all members.

Public Types

typedef std::list< Object * > List

Public Member Functions

 Application (int argc=0, char **argv=0)
 Constructor.
virtual ~Application ()
 Default destructor.
void processEvents (Condition *cond)
 process all events until the condition is met
void processEvent ()
 process on event event if we have to wait for it
void processEvents (int ms=3000)
 process all the events in the queue for a maximum period of time
void processEvents (const bool &var)
 process all events while the var is true
int exec ()
 process all events so far until the end of the application
void quit ()
 Halt execution and close window.
virtual bool event (Event *e)
 event handling
virtual bool notify (Object *receiver, Event *event)
std::list< std::string > & argv ()
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 ()

Static Public Member Functions

static void sendPostedEvents ()
 process the already posted events -- empties the queue
static void exit (int exitcode=0)
 Halt execution and close window with a return code.
static bool sendEvent (Object *receiver, Event &event)
static void postEvent (Object *receiver, Event *event)
static WidgetmainWidget ()
static DERIVED * instance ()
template<class GRANDCHILD>
static DERIVED * instance ()
 instantiates the pointer compatible child of DERIVED aka grandchild
static DERIVED * existingInstance ()

Public Attributes

sigc::signal< void > aboutToQuit
Signal01< void, const Object * > destroyed
 signals

Protected Member Functions

void parseArgs (int argc, char **argv)
virtual void childEvent (ChildEvent *)
 event handling specialization
virtual void customEvent (CustomEvent *)
virtual void timerEvent (TimerEvent *)
bool filterEvent (Event *)

Static Protected Member Functions

static DERIVED * load ()
 try to load the instance

Static Protected Attributes

static DERIVED * instance_ = 0

Private Types

typedef std::list< EventQueueItemEventQueueList
typedef std::stack< Condition * > ConditionStack

Private Member Functions

void init ()

Private Attributes

EventQueueList queue
ConditionStack condition_stack
std::list< std::string > argv_
int exitcode_
bool running_
int width_
int height_
int depth_

Friends

class Singleton< Application >

Classes

class  Condition
class  EventQueueItem
class  Exception

Detailed Description

Toplevel application class.

Extend this class to create your application.

Definition at line 41 of file application.h.


Member Typedef Documentation

typedef std::stack<Condition *> Wt::Application::ConditionStack [private]

Definition at line 112 of file application.h.

typedef std::list<EventQueueItem> Wt::Application::EventQueueList [private]

Definition at line 110 of file application.h.

typedef std::list<Object*> Wt::Object::List [inherited]

Definition at line 47 of file object.h.


Constructor & Destructor Documentation

Wt::Application::Application ( int  argc = 0,
char **  argv = 0 
)

Constructor.

Definition at line 51 of file application.cpp.

References depth_, Error, height_, Wt::Font::init(), Wt::SDLTimer::init(), Wt::Singleton< DERIVED >::init(), parseArgs(), trace, and width_.

00052         : Object(0, "Application::anon"),
00053         Singleton<Application>(this),
00054         exitcode_(0),
00055         running_(true),
00056         width_(Display::defaultWidth),
00057         height_(Display::defaultHeight),
00058 depth_(Display::defaultDepth) {
00059     parseArgs(argc, argv);
00060     Uint32 sdl_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE | SDL_INIT_TIMER;
00061 
00062 #if !defined( __WIN32__ ) && !defined( __CYGWIN32__ )
00063 
00064     sdl_flags |= SDL_INIT_EVENTTHREAD;
00065 #endif
00066 
00067     /* Initialize SDL step by step*/
00068     trace("app") << "trying to initialize SDLvideo ... " << std::endl;
00069     if ( SDL_Init(sdl_flags) < 0 ) {
00070         Error("Cannot initialize SDL\n");
00071         throw Exception();
00072     }
00073 
00074     //init SDLEventHandler
00075     SDLEvent::init();
00076     //init SDLInput
00077     SDLInput::init();
00078     //init SDLTimers
00079     SDLTimer::init();
00080     // initialize audio handling
00081     Audio::init();
00082     // initialize font handling
00083     Font::init();
00084     // initialize rootwindow
00085     new RootWindow(width_, height_, depth_);
00086 
00087     //parseArgs(argc, argv, other_flags);
00088 
00089     trace("app", "Enabling SDL Unicode support\n");
00090     SDL_EnableUNICODE(1);
00091 
00092     SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
00093 }

Here is the call graph for this function:

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

Default destructor.

Definition at line 169 of file application.cpp.

References aboutToQuit, Wt::RootWindow::instance(), Wt::SDLTimer::quit(), Wt::Singleton< DERIVED >::quit(), Wt::Font::quit(), and trace.

00169                           {
00170     trace("app") << "In application destructor" << std::endl;
00171 
00172     aboutToQuit.emit();
00173 
00174     trace("app") << "Doing video shutdown" << std::endl;
00175 
00176     delete RootWindow::instance();
00177 
00178     trace("app") << "Quitting SDL" << std::endl;
00179 
00180     Font::quit();
00181     Audio::quit();
00182     SDLTimer::quit();
00183     SDLInput::quit();
00184     SDLEvent::quit();
00185     // shut down video (to kill the window) before shutting down
00186     // audio, since audio shutdown takes _so_ long
00187     SDL_QuitSubSystem(SDL_INIT_VIDEO);
00188     SDL_Quit();
00189 }

Here is the call graph for this function:


Member Function Documentation

std::list< std::string > & Wt::Application::argv (  ) 

Definition at line 95 of file application.cpp.

References argv_.

00095                                       {
00096     return argv_;
00097 }

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

event handling specialization

Reimplemented in Wt::Window::Frame.

Definition at line 146 of file object.h.

Referenced by Wt::Object::event().

00146 {}

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

Definition at line 61 of file object.h.

References Wt::Object::children_.

00061                      {
00062         return children_;
00063     }

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

Definition at line 57 of file object.h.

References Wt::Object::children_.

Referenced by Wt::RootWindow::blit_region_ex(), Wt::Widget::childAt(), Wt::Object::deleteAllChildren(), Wt::Object::deleteFirstChild(), Wt::Object::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, inherited]

Definition at line 147 of file object.h.

Referenced by Wt::Object::event().

00147 {}

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

Definition at line 106 of file object.h.

References Wt::Object::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, inherited]

Definition at line 72 of file object.h.

References Wt::Object::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, inherited]

Definition at line 89 of file object.h.

References Wt::Object::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::Application::event ( Event e  )  [virtual]

event handling

Reimplemented from Wt::Object.

Definition at line 303 of file application.cpp.

References Wt::Object::filterEvent().

Referenced by notify(), postEvent(), and sendEvent().

00303                                 {
00304     return filterEvent(e);
00305 }

Here is the call graph for this function:

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

Reimplemented in Wt::Layout.

Definition at line 130 of file object.h.

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

00130                                                 {
00131         return false;
00132     }

int Wt::Application::exec (  ) 

process all events so far until the end of the application

Definition at line 284 of file application.cpp.

References exitcode_, processEvents(), running_, and sendPostedEvents().

00284                       {
00285     processEvents(running_);
00286     sendPostedEvents();
00287     return exitcode_;
00288 }

Here is the call graph for this function:

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::existingInstance (  )  [inline, static, inherited]

Definition at line 36 of file singleton.h.

Referenced by exit(), postEvent(), sendEvent(), and sendPostedEvents().

00036                                        {
00037         return instance_;
00038     }

void Wt::Application::exit ( int  exitcode = 0  )  [static]

Halt execution and close window with a return code.

Definition at line 290 of file application.cpp.

References Wt::Singleton< DERIVED >::existingInstance(), exitcode_, running_, and trace.

Referenced by Wt::SDLInput::handleQuitEvent(), and quit().

00290                                    {
00291     Application *app = existingInstance();
00292     if (!app)
00293         return;
00294     trace("app") << "Application: was requested to exit." << std::endl;
00295     app->running_ = false;
00296     app->exitcode_ = exitcode;
00297 }

Here is the call graph for this function:

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

Definition at line 164 of file object.cpp.

References Wt::Object::eventFilters_.

Referenced by Wt::Object::event(), and 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::Application::init (  )  [private]

Note:
cannot fail

Reimplemented from Wt::Singleton< DERIVED >.

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

Definition at line 81 of file object.cpp.

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

Referenced by Wt::Object::Object(), and Wt::Object::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  )  [inherited]

Definition at line 124 of file object.cpp.

References Wt::Object::destroyed, Wt::Object::eventFilters_, and Wt::Object::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:

template<class DERIVED>
template<class GRANDCHILD>
static DERIVED* Wt::Singleton< DERIVED >::instance (  )  [inline, static, inherited]

instantiates the pointer compatible child of DERIVED aka grandchild

it is handy in driver like situations

Definition at line 43 of file singleton.h.

00043                                {
00044         return (instance_) ? instance_ : GRANDCHILD::load();
00045     }

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::instance (  )  [inline, static, inherited]

Definition at line 32 of file singleton.h.

Referenced by Wt::Audio::Audio(), Wt::Sound::available(), Wt::SDLMixer::Chunk::channel(), Wt::NullAudio::Chunk::channel(), Wt::SDLSurface::defaultDepth(), Wt::SDLInput::EventInfo::EventInfo(), Wt::Dialog::exec(), Wt::Widget::grabKeyboard(), Wt::Widget::grabMouse(), Wt::Audio::handleAudioEvent(), Wt::SDLInput::handleKeyEvent(), Wt::Singleton< Wt::Audio >::init(), Wt::SDLTimer::init(), Wt::Sound::isAvailable(), Wt::Widget::keyboardGrabber(), Wt::Audio::load(), Wt::Widget::mouseGrabber(), Wt::SDLMixer::onChannelFinish(), Wt::Audio::onChannelFinish(), Wt::Sound::play(), Wt::Singleton< Wt::Audio >::quit(), Wt::Widget::releaseKeyboard(), Wt::Widget::releaseMouse(), Wt::SDLInput::SDLInput(), Wt::SDLMixer::setMusicVolume(), Wt::SDLMixer::Channel::setVolume(), and Wt::SDLMixer::Chunk::setVolume().

00032                                {
00033         return (instance_) ? instance_ : DERIVED::load();
00034     }

bool Wt::Object::isDescendant ( const Object p  )  const [inherited]

Definition at line 67 of file object.cpp.

References Wt::Object::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  )  [inherited]

Definition at line 145 of file object.cpp.

References Wt::Object::timers_.

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

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

void Wt::Object::killTimers (  )  [inherited]

Definition at line 150 of file object.cpp.

References Wt::Object::timers_.

Referenced by Wt::Object::~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 }

template<class DERIVED>
static DERIVED* Wt::Singleton< DERIVED >::load (  )  [inline, static, protected, inherited]

try to load the instance

if it fails return NULL if it succeeds must return the newly created object

Reimplemented in Wt::Audio, Wt::NullAudio, and Wt::SDLMixer.

Definition at line 86 of file singleton.h.

00086                            {
00087         instance_ = new DERIVED;
00088         return  instance_;
00089     }

Widget * Wt::Application::mainWidget (  )  [static]

Definition at line 191 of file application.cpp.

References Wt::RootWindow::instance().

00191                                 {
00192     return static_cast<Widget *>(RootWindow::instance());
00193 }

Here is the call graph for this function:

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

Definition at line 124 of file object.h.

References Wt::Object::name_.

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

00124                                   {
00125         return name_;
00126     }

bool Wt::Application::notify ( Object receiver,
Event event 
) [virtual]

Definition at line 307 of file application.cpp.

References Wt::Widget::enabled, Wt::Object::event(), event(), Wt::Event::KeyPress, Wt::Event::KeyRelease, Wt::Event::MouseButtonDblClick, Wt::Event::MouseButtonPress, Wt::Event::MouseButtonRelease, Wt::Event::MouseMove, and Wt::Event::Wheel.

Referenced by sendEvent().

00307                                                        {
00308     if (this->event(event))
00309         return true;
00310     const int type = event->type();
00311     Widget *w = dynamic_cast<Widget *>(receiver);
00312     if (w) {
00313         const bool input_event = (type == Event::MouseButtonPress) ||
00314                                  (type == Event::MouseButtonRelease) ||
00315                                  (type == Event::MouseButtonDblClick) ||
00316                                  (type == Event::MouseMove) ||
00317                                  (type == Event::KeyPress) ||
00318                                  (type == Event::KeyRelease) ||
00319                                  (type == Event::Wheel);
00320 
00321         if (input_event && !w->enabled) {
00322             return false;
00323         }
00324         return receiver->event(event);
00325     }
00326 
00327     return receiver->event(event);
00328 }

Here is the call graph for this function:

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

Definition at line 53 of file object.h.

References Wt::Object::parent_.

Referenced by Wt::Widget::event(), Wt::Widget::focusNextPrevChild(), Wt::Window::Frame::Frame(), Wt::Widget::is_hidden(), Wt::Object::isDescendant(), Wt::Layout::isTopLevel(), Wt::Layout::Layout(), Wt::Widget::lower(), Wt::Layout::mainWidget(), Wt::operator<<(), Wt::Widget::paintEvent(), Wt::Widget::parentWidget(), 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::Application::parseArgs ( int  argc,
char **  argv 
) [protected]

Definition at line 99 of file application.cpp.

References argv_, depth_, Wt::SDL::enableDebug(), enableTrace, height_, Wt::Object::name(), quit(), trace, and width_.

Referenced by Application().

00099                                                  {
00100     enum {
00101         TRACE, XSYNC, WT_WIDTH, WT_HEIGHT, WT_DEPTH, WT_HELP, HELP
00102     };
00103 
00104     class Option {
00105     public:
00106         Option(const std::string& name, const std::string& help)
00107                 : name(name),
00108         help(help) {}
00109         std::string name;
00110         std::string help;
00111     };
00112 
00113     Option options[] = {
00114                            Option("--wt-trace=", "enables tracing for a comma separated list of subsystems"),
00115                            Option("--wt-xsync", "enables X sync to help debugging"),
00116                            Option("--wt-width=", "the preffered width of the application"),
00117                            Option("--wt-height=", "the preffered height of the application"),
00118                            Option("--wt-depth=", "the preffered color depth of the application"),
00119                            Option("--wt-help", "display this help and quits"),
00120                            Option("--help", "display this help and quits")
00121                        };
00122 
00123     const int numopts = sizeof(options) / sizeof(options[0]);
00124 
00125     for (int i = 0; i < argc; i++) {
00126         std::string s = argv[i];
00127         if (s.find(options[TRACE].name) == 0) {
00128             std::string rest = std::string(s, options[TRACE].name.length());
00129             do {
00130                 //look for comma
00131                 std::string channel;
00132                 int comma_index = rest.find(",");
00133                 if (comma_index > 0) {
00134                     channel = std::string(rest, 0, comma_index);
00135                     rest = std::string(rest, comma_index + 1);
00136                     enableTrace(channel);
00137                 } else if (comma_index < 0) {
00138                     channel = std::string(rest, 0);
00139                     rest = "";
00140                     enableTrace(channel);
00141                 } else {
00142                     // == 0
00143                     rest = std::string(rest, comma_index + 1);
00144                 }
00145             } while(rest.length());
00146         } else if (s.find(options[XSYNC].name) == 0) {
00147             trace("app", "Enabling X-sync for debugging\n");
00148             SDL::enableDebug();
00149         } else if (s.find(options[WT_WIDTH].name) == 0) {
00150             width_ = boost::lexical_cast<int>(std::string(s, options[WT_WIDTH].name.length()));
00151         } else if (s.find(options[WT_HEIGHT].name) == 0) {
00152             height_ = boost::lexical_cast<int>(std::string(s, options[WT_HEIGHT].name.length()));
00153         } else if (s.find(options[WT_DEPTH].name) == 0) {
00154             depth_ = boost::lexical_cast<int>(std::string(s, options[WT_DEPTH].name.length()));
00155         } else if (s.find(options[WT_HELP].name) == 0 ||
00156                    s.find(options[HELP].name) == 0) {
00157             std::cout << "Standard wt options are:\n";
00158             for (int j = 0; j < numopts; j++) {
00159                 std::cout << "\t" << options[j].name <<
00160                 "\t" << options[j].help << std::endl;
00161             }
00162             quit();
00163         } else {
00164             argv_.push_back(s);
00165         }
00166     }
00167 }

Here is the call graph for this function:

void Wt::Application::postEvent ( Object receiver,
Event event 
) [static]

Definition at line 339 of file application.cpp.

References Wt::Event::ChildInserted, Wt::Event::ChildRemoved, Wt::Application::EventQueueItem::event, Wt::Object::event(), event(), Wt::Singleton< DERIVED >::existingInstance(), Wt::Region::isEmpty(), Wt::Event::LayoutHint, Wt::Widget::mapToParent(), Wt::Event::Move, Wt::Event::Paint, Wt::Object::parent(), queue, Wt::Application::EventQueueItem::receiver, Wt::PaintEvent::region(), Wt::Event::Resize, sendEvent(), trace, and Wt::Widget::update().

Referenced by Wt::SDLInput::handleActiveEvent(), Wt::SDLInput::handleKeyEvent(), Wt::SDLInput::handleMouseEvent(), Wt::SDLTimer::handleTimerEvent(), Wt::Widget::hiddenChanged(), Wt::Object::insertChild(), Wt::Widget::move(), Wt::Layout::postLayoutHintEvent(), Wt::postLayoutHintEventRecursively(), Wt::Object::removeChild(), Wt::Widget::resize(), Wt::Widget::setFocus(), Wt::Widget::setLayout(), Wt::Widget::update(), Wt::Widget::updateGeometry(), and Wt::Object::~Object().

00339                                                           {
00340     Application *app = existingInstance();
00341     if (!app) {
00342         sendEvent(receiver, *event);
00343         delete event;
00344         return;
00345     }
00346     EventQueueList& queue = app->queue;
00347     EventQueueItem new_item(receiver, event);
00348     int type = event->type();
00349 
00350     trace("event") << "Posting " << event
00351     << " for " << receiver << std::endl;
00352 
00353     // obvious optimization: eliminate unnedded/unprocessed/overwritten events
00354     // let only the last one suvive for move, size, layouthint
00355     // aggregate paint
00356     // also eliminate child events when they are followed by destruction
00357     switch (type) {
00358     case Event::ChildRemoved: {
00359             Object *dead_obj = (static_cast<ChildEvent *>(event))->child();
00360             for (EventQueueList::iterator I(queue.begin()),
00361                     E(queue.end()); I != E;) {
00362                 const EventQueueItem& item = *I;
00363                 if ((item.receiver == new_item.receiver &&
00364                         item.event->type() == Event::ChildInserted) ||
00365                         item.receiver == dead_obj) {
00366                     trace("event") << "Eliminating " << item.event <<
00367                     " for " << static_cast<void *>(item.receiver) << std::endl;
00368                     delete item.event;
00369                     I = queue.erase(I);
00370                 } else {
00371                     ++I;
00372                 }
00373             }
00374             // we are not going to deliver this sucker
00375             if (!receiver) {
00376                 delete event;
00377                 return;
00378             }
00379         }
00380         break;
00381     case Event::Paint: {
00382             Region region;
00383 
00384             for (EventQueueList::iterator I(queue.begin()),
00385                     E(queue.end()); I != E;) {
00386                 const EventQueueItem& item = *I;
00387                 if(item == new_item) {
00388                     PaintEvent *paint_e;
00389                     if (region.isEmpty()) {
00390                         paint_e = static_cast<PaintEvent *>(new_item.event);
00391                         region = paint_e->region();
00392                     }
00393                     // aggregate paint events
00394                     paint_e = static_cast<PaintEvent *>(item.event);
00395                     trace("event") << "Before Aggregation: " << region;
00396                     region |= paint_e->region();
00397                     trace("event") << "Aggregate: " << paint_e->region();
00398                     trace("event") << "After Aggregation: " << region;
00399                     trace("event") << "Eliminating "
00400                     << item.event << " " << static_cast<void *>(item.event)
00401                     << " for " << receiver << std::endl;
00402                     delete item.event;
00403                     I = queue.erase(I);
00404                 } else {
00405                     ++I;
00406                 }
00407             }
00408 
00409             if (!region.isEmpty()) {
00410                 bool erased = static_cast<PaintEvent *>(new_item.event)->erased();
00411                 delete new_item.event;
00412                 // clip to parent if exists
00413                 Widget *w = static_cast<Widget *>(new_item.receiver);
00414                 Widget *wp = static_cast<Widget *>(w->parent());
00415                 if (wp) {
00416                     Widget::update(wp, w->mapToParent(region));
00417                 }
00418                 new_item.event = new PaintEvent(region, erased);
00419             }
00420 
00421         }
00422         break;
00423     case Event::Resize:
00424     case Event::Move:
00425     case Event::LayoutHint:
00426         for (EventQueueList::iterator I(queue.begin()),
00427                 E(queue.end()); I != E;) {
00428             const EventQueueItem& item = *I;
00429             if(item == new_item) {
00430                 trace("event") << "Eliminating " << item.event << " for " << receiver << std::endl;
00431                 delete item.event;
00432                 I = queue.erase(I);
00433             } else {
00434                 ++I;
00435             }
00436         }
00437         break;
00438     default:
00439         break;
00440     }
00441 
00442     queue.push_back(new_item);
00443 }

Here is the call graph for this function:

void Wt::Application::processEvent (  ) 

process on event event if we have to wait for it

Definition at line 239 of file application.cpp.

References processEvents().

00239                                {
00240     SingleShot c;
00241     processEvents(&c);
00242 }

Here is the call graph for this function:

void Wt::Application::processEvents ( const bool &  var  ) 

process all events while the var is true

Definition at line 278 of file application.cpp.

References processEvents().

00278                                                {
00279     VarBlock v(var);
00280     processEvents(&v);
00281 }

Here is the call graph for this function:

void Wt::Application::processEvents ( int  ms = 3000  ) 

process all the events in the queue for a maximum period of time

Definition at line 260 of file application.cpp.

References processEvents().

00260                                       {
00261     TimerBlock t(ms);
00262     processEvents(&t);
00263 }

Here is the call graph for this function:

void Wt::Application::processEvents ( Condition cond  ) 

process all events until the condition is met

Definition at line 211 of file application.cpp.

References condition_stack, queue, sendPostedEvents(), and Wt::SDLEvent::wait().

Referenced by exec(), processEvent(), and processEvents().

00211                                                {
00212     condition_stack.push(cond);
00213     while (!(*cond)()) {
00214         if (queue.empty())
00215             SDLEvent::wait();
00216         sendPostedEvents();
00217     }
00218     condition_stack.pop();
00219 }

Here is the call graph for this function:

void Wt::Application::quit (  ) 

Halt execution and close window.

Reimplemented from Wt::Singleton< DERIVED >.

Definition at line 299 of file application.cpp.

References exit().

Referenced by parseArgs().

00299                        {
00300     Application::exit(0);
00301 }

Here is the call graph for this function:

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

Definition at line 88 of file object.cpp.

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

Referenced by Wt::Object::reparent(), and Wt::Object::~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  )  [inherited]

Definition at line 132 of file object.cpp.

References Wt::Object::eventFilters_.

Referenced by Wt::Object::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  )  [inherited]

Definition at line 100 of file object.cpp.

References Wt::Object::insertChild(), Wt::Object::parent_, Wt::Object::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:

bool Wt::Application::sendEvent ( Object receiver,
Event event 
) [static]

Definition at line 330 of file application.cpp.

References event(), Wt::Singleton< DERIVED >::existingInstance(), and notify().

Referenced by Wt::Widget::close(), Wt::Widget::event(), postEvent(), Wt::Widget::repaint(), and sendPostedEvents().

00330                                                           {
00331     Application *app = existingInstance();
00332     if (app)
00333         return app->notify(receiver, &event);
00334     else if (receiver)
00335         return receiver->event(&event);
00336     return 0;
00337 }

Here is the call graph for this function:

void Wt::Application::sendPostedEvents (  )  [static]

process the already posted events -- empties the queue

Definition at line 195 of file application.cpp.

References Wt::Singleton< DERIVED >::existingInstance(), queue, sendEvent(), and trace.

Referenced by exec(), Wt::Layout::Layout(), processEvents(), Wt::Widget::Widget(), Wt::Window::Window(), and Wt::Object::~Object().

00195                                    {
00196     Application *app = existingInstance();
00197     if (!app)
00198         return;
00199     EventQueueList& queue = app->queue;
00200     while (!queue.empty()) {
00201         const EventQueueItem item = queue.front();
00202         Object *receiver = item.receiver;
00203         Event *e = item.event;
00204         queue.pop_front();
00205         trace("event") << "Handling " << e << std::endl;
00206         sendEvent(receiver, *e);
00207         delete e;
00208     }
00209 }

Here is the call graph for this function:

int Wt::Object::startTimer ( int  interval  )  [inherited]

Definition at line 139 of file object.cpp.

References Wt::Object::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 }

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

Reimplemented in Wt::Timer.

Definition at line 148 of file object.h.

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

00148 {}

Object * Wt::Object::topParent (  )  const [inherited]

returns top level parent: it may return itself

Definition at line 116 of file object.cpp.

References Wt::Object::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 }


Friends And Related Function Documentation

friend class Singleton< Application > [friend]

Definition at line 42 of file application.h.


Member Data Documentation

sigc::signal<void> Wt::Application::aboutToQuit

Definition at line 86 of file application.h.

Referenced by ~Application().

std::list<std::string> Wt::Application::argv_ [private]

Definition at line 118 of file application.h.

Referenced by argv(), and parseArgs().

ConditionStack Wt::Application::condition_stack [private]

Definition at line 113 of file application.h.

Referenced by processEvents().

int Wt::Application::depth_ [private]

Definition at line 127 of file application.h.

Referenced by Application(), and parseArgs().

Signal01<void, const Object *> Wt::Object::destroyed [inherited]

signals

Definition at line 139 of file object.h.

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

int Wt::Application::exitcode_ [private]

Definition at line 121 of file application.h.

Referenced by exec(), and exit().

int Wt::Application::height_ [private]

Definition at line 126 of file application.h.

Referenced by Application(), and parseArgs().

template<class DERIVED>
DERIVED * Wt::Singleton< DERIVED >::instance_ = 0 [static, protected, inherited]

Definition at line 91 of file singleton.h.

Referenced by Wt::Singleton< Wt::Audio >::existingInstance(), Wt::Singleton< Wt::Audio >::instance(), Wt::Singleton< Wt::Audio >::load(), Wt::SDLDisplay::load(), Wt::Audio::load(), Wt::Singleton< Wt::Audio >::Singleton(), and Wt::Singleton< Wt::Audio >::~Singleton().

EventQueueList Wt::Application::queue [private]

Definition at line 111 of file application.h.

Referenced by postEvent(), processEvents(), and sendPostedEvents().

bool Wt::Application::running_ [private]

Definition at line 123 of file application.h.

Referenced by exec(), and exit().

int Wt::Application::width_ [private]

Definition at line 125 of file application.h.

Referenced by Application(), and parseArgs().


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

Generated Fri Jul 28 19:25:33 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.