Back to index

im-sdk  12.3.91
IMTriggerKeyListP.cpp
Go to the documentation of this file.
00001 /*
00002 Copyright 1990-2001 Sun Microsystems, Inc. All Rights Reserved.
00003 
00004 Permission is hereby granted, free of charge, to any person obtaining a
00005 copy of this software and associated documentation files (the
00006 "Software"), to deal in the Software without restriction, including
00007 without limitation the rights to use, copy, modify, merge, publish,
00008 distribute, sublicense, and/or sell copies of the Software, and to
00009 permit persons to whom the Software is furnished to do so, subject to
00010 the following conditions: The above copyright notice and this
00011 permission notice shall be included in all copies or substantial
00012 portions of the Software.
00013 
00014 
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00016 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00017 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00018 IN NO EVENT SHALL THE OPEN GROUP OR SUN MICROSYSTEMS, INC. BE LIABLE
00019 FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
00020 CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
00021 THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE EVEN IF
00022 ADVISED IN ADVANCE OF THE POSSIBILITY OF SUCH DAMAGES.
00023 
00024 
00025 Except as contained in this notice, the names of The Open Group and/or
00026 Sun Microsystems, Inc. shall not be used in advertising or otherwise to
00027 promote the sale, use or other dealings in this Software without prior
00028 written authorization from The Open Group and/or Sun Microsystems,
00029 Inc., as applicable.
00030 
00031 
00032 X Window System is a trademark of The Open Group
00033 
00034 OSF/1, OSF/Motif and Motif are registered trademarks, and OSF, the OSF
00035 logo, LBX, X Window System, and Xinerama are trademarks of the Open
00036 Group. All other trademarks and registered trademarks mentioned herein
00037 are the property of their respective owners. No right, title or
00038 interest in or to any trademark, service mark, logo or trade name of
00039 Sun Microsystems, Inc. or its licensors is granted.
00040 
00041 */
00042 #include "IMTriggerKeyList.hh"
00043 #include "CompoundString.hh"
00044 #include <X11/Xlib.h>
00045 #include <X11/keysym.h>
00046 #include <X11/Xutil.h>
00047 
00048 static
00049 unsigned int
00050 to_modifier(const char *str) {
00051   CompoundString modifier(str);
00052   if (modifier == CompoundString("Ctrl")) return ControlMask;
00053   if (modifier == CompoundString("Shift")) return ShiftMask;
00054   if (modifier == CompoundString("Meta")) return Mod4Mask;
00055   if (modifier == CompoundString("Alt")) return Mod1Mask;
00056   return 0;
00057 }
00058 
00059 void
00060 IMTriggerKeyList::add(const char *str) {
00061   if (!str) return;
00062 
00063   CompoundString buf;
00064   Bool is_modmask;
00065   unsigned int mod, mod_mask, tmp_mask;
00066   unsigned int keysym, modifier, modifier_mask;
00067 
00068   CompoundString names(str);
00069 
00070   buf = names;
00071   is_modmask = False;
00072   mod = mod_mask = 0;
00073 
00074   char *bufp = buf;
00075   CompoundString temp;
00076   int pos, pos2;
00077 
00078   // skip leading whitespaces
00079   while (*bufp == ' ' || *bufp == '\t') bufp++;
00080 
00081   while (*bufp) {
00082     switch(*bufp) {
00083     case '~':
00084       if (is_modmask)
00085        goto done;
00086       is_modmask = True;
00087       bufp += 1;
00088       while (*bufp == ' ' || *bufp == '\t') bufp++;
00089       break;
00090     case '<':
00091       bufp++;
00092       while (*bufp == ' ' || *bufp == '\t') bufp++;
00093       temp = bufp;
00094       pos = temp.search(">");
00095       if (pos == -1 || pos == 0) goto done;
00096       pos2 = temp.search(" ");
00097       if (pos2 != -1 && pos2 < pos)
00098        *(bufp + pos2) = 0;
00099       else
00100        *(bufp + pos) = 0;
00101       if ((tmp_mask = to_modifier(bufp)) == 0)
00102        goto done;
00103       if (is_modmask) {
00104        mod_mask |= tmp_mask;
00105        is_modmask = False;
00106       } else {
00107        mod |= tmp_mask;
00108       }
00109       bufp += 1 + pos;
00110       while (*bufp == ' ' || *bufp == '\t') bufp++;
00111       if (!*bufp)
00112        goto done;
00113       break;
00114     default:
00115       if (is_modmask) goto done;
00116       while (*bufp == ' ' || *bufp == '\t') bufp++;
00117       temp = bufp;
00118       pos = temp.search(" ");
00119       if (pos != -1) *(bufp + pos) = 0;
00120       keysym = XStringToKeysym(bufp);
00121       modifier = mod;
00122       modifier_mask = mod_mask;
00123       /* FIX ME */
00124       modifier_mask = modifier;
00125 
00126       add(keysym, modifier, modifier_mask);
00127       mod = 0;
00128       if (pos != -1) {
00129        bufp += 1 + pos;
00130        break;
00131       } else {
00132        goto done;
00133       }
00134     }
00135   }
00136  done:
00137   return;
00138 }