00001 #ifndef GLUE_KBD_H
00002 #define GLUE_KBD_H
00003
00004 #include "event/event.H"
00005 #include "dev/dev.H"
00006
00007 class XYpt;
00008 typedef const XYpt cXYpt;
00009 class Wpt;
00010 typedef const Wpt cWpt;
00011
00012
00013
00014
00015
00016
00017
00018 MAKE_PTR_SUBC(EVENTkbd, EVENT);
00019 class DllImpExp EVENTkbd : public EVENT {
00020 public:
00021 enum mod { NONE = 0, SHIFT = 1, CTRL = 2 };
00022 enum trans { UP = 0, DOWN = 1, BOTH = 2 };
00023 static const char ANY;
00024
00025 virtual ~EVENTkbd() { delete [] _char; }
00026 EVENTkbd(EVENTsource *s, char c, trans t=DOWN): EVENT(s), _transition(t) {
00027 _char = new char[2];
00028 _char[0] = c; _char[1]='\0'; }
00029 EVENTkbd(EVENTsource *s, char *c, trans t=DOWN): EVENT(s), _transition(t) {
00030 int i = 0; for (; c[i]; i++) ;
00031 _char = new char[i+1];
00032 strcpy(_char, c); }
00033
00034 void debug(ostream &o) const { o << class_name() <<"(" << keys() <<")"; }
00035 char *keys() const { return _char; }
00036 trans transition() const { return _transition; }
00037
00038
00039 DEFINE_DERIVED_TYPE(EVENTkbd, EVENT, cEVENTptr);
00040 static EVENTkbdptr cast(cEVENTptr &e) { return EVENTkbd::isa(e) ?
00041 (EVENTkbd *)&*e : 0; }
00042
00043 protected:
00044 char *_char;
00045 trans _transition;
00046
00047
00048 bool compare(cEVENTptr &e) const;
00049 };
00050
00051
00052
00053
00054
00055
00056 MAKE_PTR_SUBC(EVENTkbd_2d, EVENTkbd);
00057 class EVENTkbd_2d : public EVENTkbd {
00058
00059 protected:
00060 cXYpt &_cur;
00061
00062 public:
00063
00064 EVENTkbd_2d(EVENTsource *s, cXYpt &p, char c, trans t=DOWN):
00065 EVENTkbd(s,c,t),_cur(p){}
00066 EVENTkbd_2d(EVENTsource *s, cXYpt &p, char *c,trans t=DOWN):
00067 EVENTkbd(s,c,t),_cur(p){}
00068
00069 cXYpt &cur() const { return _cur; }
00070
00071
00072
00073 DEFINE_DERIVED_TYPE(EVENTkbd_2d, EVENTkbd, cEVENTptr);
00074 static EVENTkbd_2dptr cast(cEVENTptr &e) { return EVENTkbd_2d::isa(e) ?
00075 (EVENTkbd_2d *)&*e : 0; }
00076 };
00077
00078
00079
00080
00081
00082 MAKE_PTR_SUBC(EVENTkbd_3d, EVENTkbd);
00083 class EVENTkbd_3d : public EVENTkbd {
00084
00085 protected:
00086 cWpt &_cur;
00087
00088 public:
00089
00090 EVENTkbd_3d(EVENTsource *s, cWpt &p, char c, trans t=DOWN):
00091 EVENTkbd(s,c,t),_cur(p){}
00092 EVENTkbd_3d(EVENTsource *s, cWpt &p, char *c,trans t=DOWN):
00093 EVENTkbd(s,c,t),_cur(p){}
00094
00095 cXYpt cur() const;
00096
00097
00098
00099 DEFINE_DERIVED_TYPE(EVENTkbd_3d, EVENTkbd, cEVENTptr);
00100 static EVENTkbd_3dptr cast(cEVENTptr &e) { return EVENTkbd_3d::isa(e) ?
00101 (EVENTkbd_3d *)&*e : 0; }
00102 };
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 class DllImpExp DEVice_kbd : public DEVice {
00114 public :
00115 DEVice_kbd(Cstr_ptr &n):DEVice(n,"kbd") { }
00116 virtual ~DEVice_kbd() { }
00117
00118 virtual void event(char c, cXYpt &p, EVENTkbd::trans t) {
00119 distrib(new EVENTkbd_2d(this,p,c,t)); }
00120 virtual void event(char c, cWpt &p, EVENTkbd::trans t) {
00121 distrib(new EVENTkbd_3d(this,p,c,t)); }
00122 virtual void event(char c, EVENTkbd::trans t) {
00123 distrib(new EVENTkbd(this,c,t)); }
00124
00125
00126 DEFINE_DERIVED_TYPE(DEVice_kbd, DEVice, const DEVice *);
00127 };
00128 #endif