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

okeyfilter.cpp

Go to the documentation of this file.
00001 /*
00002                             This file is part of the Opie Project
00003              =.             Copyright (C) 2004 Rajko 'Alwin' Albrecht <alwin@handhelds.org>
00004            .=l.             Copyright (C) The Opie Team <opie-devel@handhelds.org>
00005           .>+-=
00006 _;:,     .>    :=|.         This program is free software; you can
00007 .> <`_,   >  .   <=         redistribute it and/or  modify it under
00008 :`=1 )Y*s>-.--   :          the terms of the GNU Library General Public
00009 .="- .-=="i,     .._        License as published by the Free Software
00010 - .   .-<_>     .<>         Foundation; either version 2 of the License,
00011     ._= =}       :          or (at your option) any later version.
00012    .%`+i>       _;_.
00013    .i_,=:_.      -<s.       This program is distributed in the hope that
00014     +  .  -:.       =       it will be useful,  but WITHOUT ANY WARRANTY;
00015    : ..    .:,     . . .    without even the implied warranty of
00016    =_        +     =;=|`    MERCHANTABILITY or FITNESS FOR A
00017  _.=:.       :    :=>`:     PARTICULAR PURPOSE. See the GNU
00018 ..}^=.=       =       ;     Library General Public License for more
00019 ++=   -.     .`     .:      details.
00020 :     =  ...= . :.=-
00021 -.   .:....=;==+<;          You should have received a copy of the GNU
00022  -_. . .   )=.  =           Library General Public License along with
00023    --        :-=`           this library; see the file COPYING.LIB.
00024                             If not, write to the Free Software Foundation,
00025                             Inc., 59 Temple Place - Suite 330,
00026                             Boston, MA 02111-1307, USA.
00027 */
00028 
00029 #include "okeyfilter.h"
00030 #include "device/odevice.h"
00031 #include "odebug.h"
00032 
00033 namespace Opie {
00034 namespace Core {
00035 
00036 class OKeyFilterPrivate:public OKeyFilter, QWSServer::KeyboardFilter
00037 {
00038     static QValueList<QWSServer::KeyboardFilter*> filterList;
00039     static QValueList<QWSServer::KeyboardFilter*> preFilterList;
00040 protected:
00041     OKeyFilterPrivate(const OKeyFilterPrivate&):OKeyFilter(),QWSServer::KeyboardFilter(){};
00042     virtual void addPreHandler(QWSServer::KeyboardFilter* aFilter);
00043     virtual void remPreHandler(QWSServer::KeyboardFilter* aFilter);
00044 
00045 public:
00046     OKeyFilterPrivate();
00047     virtual ~OKeyFilterPrivate();
00048     virtual bool filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat );
00049     virtual void addHandler(QWSServer::KeyboardFilter* aFilter);
00050     virtual void remHandler(QWSServer::KeyboardFilter* aFilter);
00051 };
00052 
00053 QValueList<QWSServer::KeyboardFilter*> OKeyFilterPrivate::filterList;
00054 QValueList<QWSServer::KeyboardFilter*> OKeyFilterPrivate::preFilterList;
00055 
00056 OKeyFilter::OKeyFilter()
00057 {
00058 }
00059 
00060 OKeyFilter::~OKeyFilter()
00061 {
00062 }
00063 
00064 OKeyFilter* OKeyFilter::inst()
00065 {
00066     static OKeyFilter*ofilter = 0;
00067     if (!ofilter) {
00068         ofilter = new OKeyFilterPrivate;
00069     }
00070     return ofilter;
00071 }
00072 
00073 bool OKeyFilterPrivate::filter( int unicode, int keycode, int modifiers, bool isPress, bool autoRepeat )
00074 {
00075     QValueList<QWSServer::KeyboardFilter*>::Iterator iter;
00076     for (iter=preFilterList.begin();iter!=preFilterList.end();++iter) {
00077         if ((*iter)->filter(unicode,keycode,modifiers,isPress,autoRepeat)) {
00078             return true;
00079         }
00080     }
00081     for (iter=filterList.begin();iter!=filterList.end();++iter) {
00082         if ((*iter)->filter(unicode,keycode,modifiers,isPress,autoRepeat)) {
00083             return true;
00084         }
00085     }
00086     return false;
00087 }
00088 
00089 void OKeyFilterPrivate::addHandler(QWSServer::KeyboardFilter*aF)
00090 {
00091     if (!aF) return;
00092     if (filterList.find(aF)!=filterList.end()) {
00093         return;
00094     }
00095     odebug << "adding a keyboard filter handler"<<oendl;
00096     filterList.append(aF);
00097 }
00098 
00099 void OKeyFilterPrivate::remHandler(QWSServer::KeyboardFilter*aF)
00100 {
00101     if (!aF) return;
00102     QValueList<QWSServer::KeyboardFilter*>::Iterator iter;
00103     if ( (iter=filterList.find(aF))==filterList.end() ) {
00104         return;
00105     }
00106     odebug << "removing a keyboard filter handler"<<oendl;
00107     filterList.remove(iter);
00108 }
00109 
00110 void OKeyFilterPrivate::addPreHandler(QWSServer::KeyboardFilter*aF)
00111 {
00112     if (!aF) return;
00113     if (preFilterList.find(aF)!=preFilterList.end()) {
00114         return;
00115     }
00116     odebug << "adding a preferred keyboard filter handler"<<oendl;
00117     preFilterList.append(aF);
00118 }
00119 
00120 void OKeyFilterPrivate::remPreHandler(QWSServer::KeyboardFilter*aF)
00121 {
00122     if (!aF) return;
00123     QValueList<QWSServer::KeyboardFilter*>::Iterator iter;
00124     if ( (iter=preFilterList.find(aF))==preFilterList.end() ) {
00125         return;
00126     }
00127     odebug << "removing a preferred keyboard filter handler"<<oendl;
00128     preFilterList.remove(iter);
00129 }
00130 
00131 OKeyFilterPrivate::OKeyFilterPrivate()
00132     :OKeyFilter(),QWSServer::KeyboardFilter()
00133 {
00134     filterList.clear();
00135     preFilterList.clear();
00136     if ( isQWS( ) ) {
00137         QWSServer::setKeyboardFilter ( this );
00138     }
00139 }
00140 
00141 OKeyFilterPrivate::~OKeyFilterPrivate()
00142 {
00143 }
00144 
00145 /* namespace Core */
00146 }
00147 /* namespace Opie */
00148 }

Generated on Sat Nov 5 16:16:09 2005 for OPIE by  doxygen 1.4.2