toplevel.h

00001 // toplevel.h                          -*-c++-*-
00002 //
00003 //  Copyright 2000, 2005, 2007-2008 Daniel Burrows
00004 //
00005 //  This program is free software; you can redistribute it and/or modify
00006 //  it under the terms of the GNU General Public License as published by
00007 //  the Free Software Foundation; either version 2 of the License, or
00008 //  (at your option) any later version.
00009 //
00010 //  This program 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
00013 //  GNU General Public License for more details.
00014 //
00015 //  You should have received a copy of the GNU General Public License
00016 //  along with this program; see the file COPYING.  If not, write to
00017 //  the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018 //  Boston, MA 02111-1307, USA.
00019 //
00020 //  This file declares general routines and interfaces for the cwidget
00021 //  code.
00022 //
00023 //  Basically, you can set the toplevel widget here and run a main loop.
00024 //  The toplevel widget is responsible for almost everything else.
00025 
00026 #ifndef TOPLEVEL_H
00027 #define TOPLEVEL_H
00028 
00029 #include <sigc++/signal.h>
00030 
00031 #include <cwidget/generic/util/ref_ptr.h>
00032 
00034 namespace cwidget
00035 {
00037   std::string version();
00038 
00039   namespace threads
00040   {
00041     class mutex;
00042   }
00043 
00044   namespace widgets
00045   {
00046     class widget;
00047   }
00048 
00049   namespace toplevel
00050   {
00054     class event
00055     {
00056     public:
00057       virtual void dispatch() = 0;
00058       virtual ~event();
00059     };
00060 
00070     class slot_event : public event
00071     {
00072       sigc::slot0<void> the_slot;
00073     public:
00074       slot_event(const sigc::slot0<void> &_the_slot)
00075         : the_slot(_the_slot)
00076       {
00077       }
00078 
00079       void dispatch();
00080     };
00081 
00082     void init();
00083     // Performs initialization tasks (including calling init_curses())
00084 
00085     void install_sighandlers();
00086     // Installs signal handlers for TERM, INT, QUIT, SEGV, and ABRT which
00087     // cleanly shut the program down.  This can be called after the
00088     // program starts to re-initialize the display code.
00089 
00095     util::ref_ptr<widgets::widget> settoplevel(const util::ref_ptr<widgets::widget> &widget);
00096 
00100     void queuelayout();
00101 
00102     void layoutnow();
00103     // Lays out all widgets immediately.
00104 
00105     //   Main loop handlers:
00106 
00126     void mainloop(int synch=0);
00127     // Enters a loop, calling getch() over and over and over again..
00128     // A valid cwidget must be currently displayed.
00129 
00137     void post_event(event *ev);
00138 
00145     bool poll();
00146 
00147     void exitmain();
00148     // Exits the main loop.
00149 
00150     void redraw();
00151     // Redraws the screen completely from scratch
00152 
00154     void update();
00155 
00157     void tryupdate();
00158 
00162     void updatecursor();
00163 
00169     void suspend();
00170 
00175     void suspend_without_signals();
00176 
00181     void shutdown();
00182 
00186     void resume();
00187 
00194     int addtimeout(event *ev, int msecs);
00195 
00197     void deltimeout(int id);
00198 
00199     void handleresize();
00200     // Does anything needed to handle a window resize event.
00201     // FIXME: I --think-- that this is now redundant
00202 
00203     //  Return a mutex that is held whenever the main loop is processing
00204     //  events or drawing the screen.  The mutex can be held by other
00205     //  threads that want to do their own drawing or processing, although
00206     //  this is highly discouraged (use the event posting system instead
00207     //  to run code in the main loop).
00208     threads::mutex &get_mutex();
00209 
00220     int get_suspend_count();
00221 
00222     extern sigc::signal0<void> main_hook;
00223     // Called right after we finish handling input in the mainloop.  Can
00224     // be used (eg) to insert extra actions to be performed after all
00225     // user-input (aptitude uses this to check for apt errors and pop up a
00226     // message about them)
00227   }
00228 }
00229 
00230 #endif

Generated on Fri Feb 8 12:54:56 2008 for cwidget by  doxygen 1.5.4