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

x_kbd.H

Go to the documentation of this file.
00001 /*
00002  * Copyright 1997, Brown University, Providence, RI.
00003  * 
00004  *                         All Rights Reserved
00005  * 
00006  * Permission to use, copy, modify, and distribute this software and its
00007  * documentation for any purpose other than its incorporation into a
00008  * commercial product is hereby granted without fee, provided that the
00009  * above copyright notice appear in all copies and that both that
00010  * copyright notice and this permission notice appear in supporting
00011  * documentation, and that the name of Brown University not be used in
00012  * advertising or publicity pertaining to distribution of the software
00013  * without specific, written prior permission.
00014  * 
00015  * BROWN UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00016  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ANY
00017  * PARTICULAR PURPOSE.  IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE FOR
00018  * ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
00019  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
00020  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
00021  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  */
00023 #ifndef DEV_X_KBD_H
00024 #define DEV_X_KBD_H 
00025 
00026 #include "dev/kbd.H"
00027 #include "std/strings.H"
00028 #include <string.h>
00029 #include <X11/keysym.h>  // For Keycodes
00030 #include <X11/StringDefs.h>
00031 #include <X11/Intrinsic.h>
00032 #include <X11/Xatom.h>
00033 
00034 //----------------------------------------------
00035 //
00036 //  X_kbd -
00037 //     An X windows keyboard device
00038 //
00039 //----------------------------------------------
00040 class X_kbd : public DEVice_kbd {
00041  protected :
00042   static void key(Widget w,XtPointer client_data,XEvent *xevent,Boolean *) {
00043       XKeyEvent  *kev((XKeyEvent *)xevent);
00044       X_kbd      *kbd((X_kbd     *)client_data);
00045       char        buffer[1024], number;
00046       KeySym      keysym;
00047 
00048       if ((number = XLookupString(kev, buffer, 1024, &keysym, 0))) {
00049      if (keysym  == XK_Return || keysym == XK_Linefeed)
00050         buffer[number-1] = '\n';
00051      buffer[number] = '\0';
00052          kbd->send_event(buffer[0], EVENTkbd::DOWN, kev->x, kev->y);
00053       } else if (keysym == XK_Shift_R || keysym == XK_Shift_L)
00054          kbd->send_event((char) EVENTkbd::SHIFT, EVENTkbd::DOWN, kev->x,kev->y);
00055       else if (keysym == XK_Control_R || keysym == XK_Control_L)
00056          kbd->send_event((char) EVENTkbd::CTRL, EVENTkbd::DOWN, kev->x, kev->y);
00057    }
00058   static void key_up(Widget w,XtPointer client_data,XEvent *xevent,Boolean *) {
00059    XKeyEvent  *kev((XKeyEvent *)xevent);
00060    X_kbd      *kbd((X_kbd     *)client_data);
00061    char        buffer[1024], number;
00062    KeySym      keysym;
00063 
00064    if ((number = XLookupString(kev, buffer, 1024, &keysym, 0))) { 
00065        if (keysym  == XK_Return || keysym == XK_Linefeed)
00066           buffer[number-1] = '\n';
00067        buffer[number] = '\0';
00068        kbd->send_event(buffer[0], EVENTkbd::UP, kev->x, kev->y);
00069    } else if (keysym == XK_Shift_R || keysym == XK_Shift_L)
00070        kbd->send_event((char) EVENTkbd::SHIFT, EVENTkbd::UP, kev->x, kev->y);
00071    else if (keysym == XK_Control_R || keysym == XK_Control_L)
00072        kbd->send_event((char) EVENTkbd::CTRL, EVENTkbd::UP, kev->x, kev->y);
00073   }
00074 
00075   virtual void send_event(char key, EVENTkbd::trans t, int, int){ event(key,t);}
00076   Widget _widg;
00077 
00078    public:
00079      X_kbd(Widget w, Cstr_ptr &n="kbd"):DEVice_kbd(n),_widg(w) {
00080        XtAddEventHandler(w, KeyPressMask,   (Boolean)0, key,   (void *)this);
00081        XtAddEventHandler(w, KeyReleaseMask, (Boolean)0, key_up,(void *)this);
00082      }
00083 };
00084 #endif

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