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 "CompoundString.hh"
00043 #include "IMTriggerKeyList.hh"
00044 #ifndef Bool
00045 #define Bool int
00046 #define True 1
00047 #define False 0
00048 #endif
00049 
00050 // Hard Coded
00051 #define XK_space               0x020
00052 
00055 #define IM_ShiftMask               (1<<0)
00056 #define IM_LockMask                (1<<1)
00057 #define IM_ControlMask             (1<<2)
00058 #define IM_Mod1Mask                (1<<3)
00059 #define IM_Mod2Mask                (1<<4)
00060 #define IM_Mod3Mask                (1<<5)
00061 #define IM_Mod4Mask                (1<<6)
00062 #define IM_Mod5Mask                (1<<7)
00063 
00064 static
00065 unsigned int
00066 to_modifier(const char *str) {
00067   CompoundString modifier(str);
00068   if (modifier == CompoundString("Ctrl")) return IM_ControlMask;
00069   if (modifier == CompoundString("Shift")) return IM_ShiftMask;
00070   if (modifier == CompoundString("Meta")) return IM_Mod4Mask;
00071   if (modifier == CompoundString("Alt")) return IM_Mod1Mask;
00072   return 0;
00073 }
00074 
00075 void
00076 IMTriggerKeyList::add(const char *str) {
00077     if (!str) return;
00078 
00079   CompoundString buf;
00080   Bool is_modmask;
00081   unsigned int mod, mod_mask, tmp_mask;
00082   unsigned int keysym, modifier, modifier_mask;
00083 
00084   CompoundString names(str);
00085 
00086   buf = names;
00087   is_modmask = False;
00088   mod = mod_mask = 0;
00089 
00090   char *bufp = buf;
00091   CompoundString temp;
00092   unsigned int pos, pos2;
00093 
00094   // skip leading whitespaces
00095   while (*bufp == ' ' || *bufp == '\t') bufp++;
00096 
00097   while (*bufp) {
00098     switch(*bufp) {
00099     case '~':
00100       if (is_modmask)
00101         goto done;
00102       is_modmask = True;
00103       bufp += 1;
00104       while (*bufp == ' ' || *bufp == '\t') bufp++;
00105       break;
00106     case '<':
00107       bufp++;
00108       while (*bufp == ' ' || *bufp == '\t') bufp++;
00109       temp = bufp;
00110       pos = temp.search(">");
00111       if (pos == -1 || pos == 0) goto done;
00112       pos2 = temp.search(" ");
00113       if (pos2 < pos)
00114         *(bufp + pos2) = 0;
00115       else
00116         *(bufp + pos) = 0;
00117       if ((tmp_mask = to_modifier(bufp)) == 0)
00118         goto done;
00119       if (is_modmask) {
00120         mod_mask |= tmp_mask;
00121         is_modmask = False;
00122       } else {
00123         mod |= tmp_mask;
00124       }
00125       bufp += 1 + pos;
00126       while (*bufp == ' ' || *bufp == '\t') bufp++;
00127       if (!*bufp)
00128         goto done;
00129       break;
00130     default:
00131       if (is_modmask) goto done;
00132       while (*bufp == ' ' || *bufp == '\t') bufp++;
00133       temp = bufp;
00134       pos = temp.search(" ");
00135       if (pos != -1) *(bufp + pos) = 0;
00136       // keysym = XStringToKeysym(bufp);     FIX ME
00137       keysym = XK_space;
00138       modifier = mod;
00139       modifier_mask = mod_mask;
00140       /* FIX ME */
00141       modifier_mask = modifier;
00142 
00143       add(keysym, modifier, modifier_mask);
00144       mod = 0;
00145       if (pos != -1) {
00146         bufp += 1 + pos;
00147         break;
00148       } else {
00149         goto done;
00150       }
00151     }
00152   }
00153  done:
00154   return;
00155 }
00156 
00157