www.pudn.com > xvoice-0.8.1.rar > EventStream.h
// -*- C++ -*- /** * EventStream.h * * Description: declaration of an ordered list of X events * * Copyright (c) 1999, David Z. Creemer. * See the LICENSE file. All rights not granted therein are reserved. * * @author David Z. Creemer * @version 1.0 * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. * */ #ifndef _EVENTSTREAM_H_ #define _EVENTSTREAM_H_ #includeenum EventType { EVKEY, EVMOUSE, EVGRAM }; class Event { public: EventType type; union { struct { bool alt, ctrl, shift; int c; } key; struct { bool alt, ctrl, shift, down; int x, y, button; } mouse; struct { bool enable; char *name; } grammar; } val; /** * constructor */ Event(bool alt0, bool ctrl0, bool shift0, int c0) { type = EVKEY; val.key.alt = alt0; val.key.ctrl = ctrl0; val.key.shift = shift0; val.key.c = c0; } Event(bool alt0, bool ctrl0, bool shift0, bool down0, int x0, int y0, int button0) { type = EVMOUSE; val.mouse.alt = alt0; val.mouse.ctrl = ctrl0; val.mouse.shift = shift0; val.mouse.x = x0; val.mouse.y = y0; val.mouse.button = button0; } Event(bool enable0, const char* name0) { type = EVGRAM; val.grammar.enable = enable0; val.grammar.name = new char[strlen(name0)+1]; strcpy(val.grammar.name,name0); } Event(const Event& ev) { type = ev.type; if (type == EVGRAM) { val.grammar.name = new char[strlen(ev.val.grammar.name)+1]; strcpy(val.grammar.name,ev.val.grammar.name); val.grammar.enable = ev.val.grammar.enable; } else { val = ev.val; } } ~Event() { if (type == EVGRAM) delete val.grammar.name; } }; class EventStream : public list
{ public: /** * parse an XML attribute list for key events, and add the result * to the event stream * * @param attrs an attr=value pair array * * @return true if parse OK */ bool parseKeyEvent( const char** attrs ); /** * parse an XML attribute list for mouse button events, and add * the result to the event stream * * @param attrs an attr=value pair array * * @return true if parse OK */ bool parseMouseEvent( const char** attrs ); bool parseGrammarEvent( const char** attrs ); }; #endif // _EVENTSTREAM_H_