/*************************************************************************** * Copyright (C) 2004 by Christoph Freundl * * Christoph.Freundl@informatik.uni-erlangen.de * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef SDLWIDGETS_ACTION_H #define SDLWIDGETS_ACTION_H #include #include namespace SDLwidgets { class ActionWidget; class ActionListener { public: virtual ~ActionListener() {}; // causes segfault with gcc4.0.1 virtual void actionPerformed( Uint32 cmd, void* source ) = 0; }; class ActionWidget { protected: Uint32 _cmd; std::vector _action_listener; public: void setCommand( Uint32 cmd ) { _cmd = cmd; } void addActionListener( ActionListener* l ) { _action_listener.push_back( l ); } protected: void fireAction( void* source ) { for ( std::vector::iterator it = _action_listener.begin(); it != _action_listener.end(); it++ ) { (*it)->actionPerformed( _cmd, source ); } } void fireAction( Uint32 cmd, void* source ) { for ( std::vector::iterator it = _action_listener.begin(); it != _action_listener.end(); it++ ) { (*it)->actionPerformed( cmd, source ); } } }; } #endif // SDLWIDGETS_ACTION_H