application.h

Go to the documentation of this file.
00001 /*
00002   libwt - Vassilis Virvilis Toolkit - a widget library
00003   Copyright (C) 2006 Vassilis Virvilis <vasvir2@fastmail.fm>
00004  
00005   This library is free software; you can redistribute it and/or
00006   modify it under the terms of the GNU Lesser General Public
00007   License as published by the Free Software Foundation; either
00008   version 2.1 of the License, or (at your option) any later version.
00009   
00010   This library is distributed in the hope that it will be useful,
00011   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013   Lesser General Public License for more details.
00014   
00015   You should have received a copy of the GNU Lesser General Public
00016   License along with this library; if not, write to the
00017   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018   Boston, MA  02111-1307, SA.
00019 */
00020 
00021 #ifndef WT_APPLICATION_H
00022 #define WT_APPLICATION_H
00023 
00024 #include <list>
00025 #include <stack>
00026 #include <exception>
00027 
00028 #include <wt/object.h>
00029 #include <wt/singleton.h>
00030 
00031 namespace Wt {
00032 
00033 class Widget;
00034 class Event;
00035 class Region;
00036 
00037 /** Toplevel application class
00038  * 
00039  * Extend this class to create your application.
00040  **/
00041 class Application : public Object, public Singleton<Application> {
00042     friend class Singleton<Application>;
00043 public:
00044     /// Constructor.
00045     Application(int argc = 0, char **argv = 0);
00046 
00047     /// Default destructor.
00048     virtual ~Application();
00049 
00050     class Condition {
00051     public:
00052         virtual ~Condition() {}
00053         virtual bool operator()() = 0;
00054     };
00055 
00056     /// process all events until the condition is met
00057     void processEvents(Condition* cond);
00058 
00059     /// process on event event if we have to wait for it
00060     void processEvent();
00061 
00062     /// process all the events in the queue for a maximum period of time
00063     void processEvents(int ms = 3000);
00064 
00065     /// process all events while the var is true
00066     void processEvents(const bool& var);
00067 
00068     /// process the already posted events -- empties the queue
00069     static void sendPostedEvents();
00070 
00071     /// run mainloop
00072     int exec();
00073 
00074     /// Halt execution and close window with a return code
00075     static void exit(int exitcode = 0);
00076 
00077     /// Halt execution and close window
00078     void quit();
00079 
00080     virtual bool event(Event *e);
00081     virtual bool notify(Object *receiver, Event *event);
00082     // these functions will work even if Application is deleted
00083     static bool sendEvent(Object *receiver, Event& event);
00084     static void postEvent(Object *receiver, Event *event);
00085 
00086     sigc::signal<void> aboutToQuit;
00087 
00088     static Widget *mainWidget();
00089 
00090     std::list<std::string>& argv();
00091 
00092 class Exception : public std::exception {
00093     public:
00094         virtual const char *what() const throw();
00095     };
00096 
00097 protected:
00098     void parseArgs(int argc, char** argv);
00099 
00100 private:
00101     class EventQueueItem {
00102     public:
00103         EventQueueItem(Object *receiver, Event *event);
00104         bool operator==(const EventQueueItem& other) const;
00105 
00106         Object *receiver;
00107         Event *event;
00108     };
00109 
00110     typedef std::list<EventQueueItem> EventQueueList;
00111     EventQueueList queue;
00112     typedef std::stack<Condition *> ConditionStack;
00113     ConditionStack condition_stack;
00114 
00115     // start up the application
00116     void init();
00117 
00118     std::list<std::string> argv_;
00119 
00120     ///
00121     int exitcode_;
00122     ///
00123     bool running_;
00124 
00125     int width_;
00126     int height_;
00127     int depth_;
00128 };
00129 
00130 }
00131 
00132 #endif // !WT_APPLICATION_H

Generated Fri Jul 28 19:22:59 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.