focusdata.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_FOCUSDATA_H
00022 #define WT_FOCUSDATA_H
00023 
00024 #include <list>
00025 
00026 namespace Wt {
00027 
00028 class Widget;
00029 typedef std::list<Widget *> WidgetList;
00030 
00031 class FocusData : public WidgetList {
00032 public:
00033     Widget *focusWidget() const {
00034         return (current_it_ != end()) ? *current_it_ : 0;
00035     }
00036 
00037     Widget *home() {
00038         it_ = current_it_;
00039         return focusWidget();
00040     }
00041 
00042     Widget *next() {
00043         if (it_ == end())
00044             return 0;
00045         ++it_;
00046         if (it_ == end())
00047             it_ = begin();
00048         return *it_;
00049     }
00050 
00051     Widget *prev() {
00052         if (it_ == end())
00053             return 0;
00054         if (it_ == begin())
00055             it_ = end();
00056         else {
00057             --it_;
00058         }
00059         return *it_;
00060     }
00061 
00062     Widget *first() const {
00063         if (!size())
00064             return 0;
00065         return front();
00066     }
00067 
00068     Widget *last() const {
00069         if (!size())
00070             return 0;
00071         return back();
00072     }
00073 
00074     int count() const {
00075         return size();
00076     }
00077 
00078 protected:
00079     friend class Widget;
00080     FocusData() :
00081             current_it_(end()),
00082     it_(end()) {}
00083 
00084     Widget *setFocus(const Widget *w) {
00085         it_ = find(begin(), end(), w);
00086         current_it_ = it_;
00087         return focusWidget();
00088     }
00089 
00090     /// stop being clever and loose the damn focus
00091     void looseFocus() {
00092         current_it_ = end();
00093         it_ = begin();
00094     }
00095 
00096 private:
00097     WidgetList::iterator current_it_, it_;
00098 };
00099 
00100 }
00101 #endif // WT_FOCUSDATA_H

Generated Fri Jul 28 19:23:00 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.