Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | Related Pages

focus.h

00001 /*
00002   libwftk - Worldforge Toolkit - a widget library
00003   Copyright (C) 2002 Malcolm Walker <malcolm@worldforge.org>
00004   Based on code copyright  (C) 1999-2002  Karsten Laux
00005 
00006   This library is free software; you can redistribute it and/or
00007   modify it under the terms of the GNU Lesser General Public
00008   License as published by the Free Software Foundation; either
00009   version 2.1 of the License, or (at your option) any later version.
00010   
00011   This library is distributed in the hope that it will be useful,
00012   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   Lesser General Public License for more details.
00015   
00016   You should have received a copy of the GNU Lesser General Public
00017   License along with this library; if not, write to the
00018   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00019   Boston, MA  02111-1307, SA.
00020 */
00021 
00022 
00023 #ifndef _FOCUS_H
00024 #define _FOCUS_H
00025 
00026 #include <assert.h>
00027 
00028 #include <list>
00029 
00030 #include <sigc++/marshal.h>
00031 #if SIGC_MAJOR_VERSION == 1 && SIGC_MINOR_VERSION == 0
00032 #include <sigc++/signal_system.h>
00033 #else
00034 #include <sigc++/signal.h>
00035 #include <sigc++/object.h>
00036 #endif
00037 
00038 #include <SDL/SDL_events.h>
00039 
00040 #include <wftk/marshal.h>
00041 #include <wftk/timer.h>
00042 
00043 namespace wftk {
00044 
00045 class Widget;
00046 
00048 class Focus
00049 {
00050  public:
00052   Focus() : CursorSparkle(300), owner_(0),
00053     have_focus_((SDL_GetAppState() & SDL_APPINPUTFOCUS) != 0)
00054     {assert(!instance_); instance_ = this;}
00056   ~Focus() {assert(instance_ = this); instance_ = 0;}
00058   static Focus* instance() {return instance_ ? instance_ : new Focus();}
00059 
00065   SigC::Signal2<bool,const SDL_keysym&,bool,BoolMarshal> keystroke;
00067   SigC::Signal0<bool,BoolMarshal> lostFocus;
00069   SigC::Signal0<bool,BoolMarshal> gotFocus;
00071   Timer CursorSparkle;
00072 
00074   bool release(Widget* w) {return grab(0);}
00076   bool grab(Widget* w);
00078   bool haveFocus() const {return have_focus_;}
00080   Widget* currentFocus() const {return owner_;}
00082   Widget* nextFocus();
00084   Widget* prevFocus();
00087   void addFocusable(Widget*);
00089   void removeFocusable(Widget*);
00090 
00092   bool handleEvent(const SDL_Event*);
00093  
00094  private:
00096   Widget* owner_;
00098   bool have_focus_;
00100   typedef std::list<Widget*> Foci;
00102   Foci focusable_;
00104   Foci::iterator find(Widget*);
00106   static Focus* instance_;
00107 };
00108 
00109 
00110 } // namespace
00111 
00112 #endif

Generated Tue Apr 12 22:48:51 2005.
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.