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

kbd.H

Go to the documentation of this file.
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 // EVENTkbd - is a keyboard keypress or keyrelease event
00014 //
00015 // An EVENTkbd represents a keyboard key transition, either up or down.
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 };  // used by interactor GUARDs
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     /* ----------- TYPEDOBJ methods ------------ */
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     /* ----------- EVENT methods ------------ */
00048      bool compare(cEVENTptr &e) const;
00049 };
00050 
00051 
00052 //
00053 //   EVENTkbd - a keyboard event w/ an associated locator position
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     /* ----------- TYPEDOBJ methods --------------- */
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 //   EVENTkbd - a keyboard event w/ an associated locator position
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     /* ----------- TYPEDOBJ methods --------------- */
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 //   DEVice_kbd - represents a keyboard device 
00107 //     
00108 //   A keyboard device is intended to represent a conventional keyboard
00109 //  in which events are generate for each character pressed or released.
00110 //  In addition, special events are generated for pressing and releasing
00111 //  the Shift and Control keys.
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     /* ----------- TYPEDOBJ methods --------------- */
00126     DEFINE_DERIVED_TYPE(DEVice_kbd, DEVice, const DEVice *);
00127 };
00128 #endif

Generated on Mon Sep 15 16:25:56 2003 for gluebase by doxygen1.2.18