Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

KeyBinder.C

00001 /* $Id: KeyBinder.C,v 1.1 2001/01/01 00:25:56 rpav Exp $
00002  *
00003  * SFW - Studio FrameWork
00004  * Copyright (C) 2000  Ryan Pavlik
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  *
00011  * This program 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
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  *
00020  */
00021 
00022 /*
00023  * KeyBinder.C
00024  *
00025  * KeyBinder class implementation
00026  *
00027  */ 
00028 
00029 #include <SFW/GC.H>
00030 #include <SFW/Curses/KeyBinder.H>
00031 #include <SFW/Curses/Curses.H>
00032 
00033 TYPE_INIT(SFW::Curses::KeyBinder);
00034 
00035 using namespace SFW;
00036 using namespace SFW::Curses;
00037 
00038 KeyBinder::KeyBinder(Object *_o) {
00039     o = _o;
00040 }
00041 
00042 KeyBinder::~KeyBinder() {
00043     for(Map::iterator i = keymap.begin(); i != keymap.end(); i++)
00044         GC.done(i->second);
00045 }
00046 
00047 void KeyBinder::bind(int key, Method *_m) {
00048     Map::iterator pos = keymap.find(key);
00049     GC.use(_m);
00050     
00051     if(pos != keymap.end())
00052         GC.done(pos->second);
00053 
00054     keymap[key] = _m;
00055 }
00056 
00057 int KeyBinder::listen() {
00058     Map::iterator pos;
00059     int ch = Input::getch();
00060     
00061     if((pos = keymap.find(ch)) != keymap.end()) {
00062         Method *m = (Method*)pos->second;
00063         var v = ch;
00064         (*m)(o, &v);
00065 
00066         return -1;
00067     }
00068 
00069     return ch;
00070 }

Generated at Tue Jan 2 15:38:33 2001 for SFW by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000