home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / xfe / XfeWidgets / Xfe / Converters.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  3.2 KB  |  99 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18. /*-----------------------------------------*/
  19. /*                                                                        */
  20. /* Name:        <Xfe/Converters.c>                                        */
  21. /* Description:    Xfe widgets resource converters source.                    */
  22. /* Author:        Ramiro Estrugo <ramiro@netscape.com>                    */
  23. /*                                                                        */
  24. /*----------------------------------------------------------------------*/
  25.  
  26.  
  27. #include <Xfe/XfeP.h>
  28.  
  29. #include <string.h> /* for strncasecmp() */
  30.  
  31. /*----------------------------------------------------------------------*/
  32. /*                                                                        */
  33. /* Converter Args for StringTo{misc}                                    */
  34. /*                                                                        */
  35. /*----------------------------------------------------------------------*/
  36. static XtConvertArgRec _XfeWidgetConvertArg[] = 
  37. {
  38.     {
  39.         XtWidgetBaseOffset,
  40.         (XtPointer) XtOffsetOf(WidgetRec , core . self),
  41.         sizeof(Widget)
  42.     }
  43. };
  44. /*----------------------------------------------------------------------*/
  45.  
  46. #define COMPARE(s,v) (strncasecmp( (s),(v),strlen(v) ) == 0)
  47.  
  48. /*----------------------------------------------------------------------*/
  49. /* extern */ Boolean
  50. XfeCvtStringToModifiers(Display *    dpy,
  51.                        XrmValue *    args,
  52.                        Cardinal *    nargs,
  53.                        XrmValue *    from,
  54.                        XrmValue *    to,
  55.                        XtPointer *    data)
  56. {
  57.     String        str = (String) from->addr;
  58.     Modifiers    mod = 0;
  59.    
  60.     if      (COMPARE(str,"no"))            mod = 0;
  61.     else if (COMPARE(str,"any"))        mod = AnyModifier;
  62.     else if (COMPARE(str,"alt"))        mod = Mod1Mask;
  63.     else if (COMPARE(str,"control"))    mod = ControlMask;
  64.     else if (COMPARE(str,"lock"))        mod = LockMask;
  65.     else if (COMPARE(str,"mod1"))        mod = Mod1Mask;
  66.     else if (COMPARE(str,"mod2"))        mod = Mod2Mask;
  67.     else if (COMPARE(str,"mod3"))        mod = Mod3Mask;
  68.     else if (COMPARE(str,"mod4"))        mod = Mod4Mask;
  69.     else if (COMPARE(str,"mod5"))        mod = Mod4Mask;
  70.     else if (COMPARE(str,"shift"))        mod = ShiftMask;
  71.     else
  72.     {
  73.         XtDisplayStringConversionWarning(dpy,str,XmRModifiers);
  74.  
  75.         return False;
  76.     }
  77.  
  78.     _XfeConverertDone(mod,Modifiers);
  79. }
  80. /*----------------------------------------------------------------------*/
  81. /* extern */ void
  82. XfeRegisterStringToModifiersCvt()
  83. {
  84.     XtSetTypeConverter(XmRString,
  85.                        XmRModifiers,
  86.                        XfeCvtStringToModifiers,
  87.                        _XfeWidgetConvertArg,
  88.                        XtNumber(_XfeWidgetConvertArg),
  89.                        XtCacheNone,
  90.                        NULL);
  91. }
  92. /*----------------------------------------------------------------------*/
  93. /* extern */ void
  94. XfeRegisterConverters()
  95. {
  96.     XfeRegisterStringToModifiersCvt();
  97. }
  98. /*----------------------------------------------------------------------*/
  99.