1/* 2 3Copyright 1989, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25*/ 26 27#ifdef HAVE_CONFIG_H 28#include <config.h> 29#endif 30#include <X11/Intrinsic.h> 31#include <X11/Xmu/Converters.h> 32#include <X11/Xmu/CharSet.h> 33 34#define done(address, type) \ 35{ (*toVal).size = sizeof(type); (*toVal).addr = (XPointer) address; } 36 37/* 38 * Initialization 39 */ 40static struct _namepair { 41 XrmQuark quark; 42 _Xconst char *name; 43 XtGravity gravity; 44} names[] = { 45 { NULLQUARK, XtEForget, ForgetGravity }, 46 { NULLQUARK, XtENorthWest, NorthWestGravity }, 47 { NULLQUARK, XtENorth, NorthGravity }, 48 { NULLQUARK, XtENorthEast, NorthEastGravity }, 49 { NULLQUARK, XtEWest, WestGravity }, 50 { NULLQUARK, XtECenter, CenterGravity }, 51 { NULLQUARK, XtEEast, EastGravity }, 52 { NULLQUARK, XtESouthWest, SouthWestGravity }, 53 { NULLQUARK, XtESouth, SouthGravity }, 54 { NULLQUARK, XtESouthEast, SouthEastGravity }, 55 { NULLQUARK, XtEStatic, StaticGravity }, 56 { NULLQUARK, XtEUnmap, UnmapGravity }, 57 { NULLQUARK, XtEleft, WestGravity }, 58 { NULLQUARK, XtEtop, NorthGravity }, 59 { NULLQUARK, XtEright, EastGravity }, 60 { NULLQUARK, XtEbottom, SouthGravity }, 61 { NULLQUARK, NULL, ForgetGravity } 62}; 63 64/* 65 * This function is deprecated as of the addition of 66 * XtCvtStringToGravity in R6 67 */ 68void 69XmuCvtStringToGravity(XrmValuePtr args, Cardinal *num_args, 70 XrmValuePtr fromVal, XrmValuePtr toVal) 71{ 72 static Boolean haveQuarks = False; 73 char name[10]; 74 XrmQuark q; 75 struct _namepair *np; 76 77 if (*num_args != 0) 78 XtWarningMsg("wrongParameters","cvtStringToGravity","XtToolkitError", 79 "String to Gravity conversion needs no extra arguments", 80 (String *)NULL, (Cardinal *)NULL); 81 82 if (!haveQuarks) 83 { 84 for (np = names; np->name; np++) 85 np->quark = XrmPermStringToQuark(np->name); 86 haveQuarks = True; 87 } 88 89 XmuNCopyISOLatin1Lowered(name, (char *)fromVal->addr, sizeof(name)); 90 q = XrmStringToQuark(name); 91 92 for (np = names; np->name; np++) 93 { 94 if (np->quark == q) 95 { 96 done(&np->gravity, XtGravity); 97 return; 98 } 99 } 100 101 XtStringConversionWarning((char *)fromVal->addr, XtRGravity); 102} 103 104/*ARGSUSED*/ 105Boolean 106XmuCvtGravityToString(Display *dpy, XrmValue *args, Cardinal *num_args, 107 XrmValue *fromVal, XrmValue *toVal, XtPointer *data) 108{ 109 static const char *buffer; 110 Cardinal size; 111 struct _namepair *np; 112 XtGravity gravity; 113 114 gravity = *(XtGravity *)fromVal->addr; 115 buffer = NULL; 116 for (np = names; np->name; np++) 117 if (np->gravity == gravity) 118 { 119 buffer = np->name; 120 break; 121 } 122 123 if (!buffer) 124 { 125 XtAppWarning(XtDisplayToApplicationContext(dpy), 126 "Cannot convert Gravity to String"); 127 toVal->addr = NULL; 128 toVal->size = 0; 129 130 return (False); 131 } 132 133 size = strlen(buffer) + 1; 134 if (toVal->addr != NULL) 135 { 136 if (toVal->size <= size) 137 { 138 toVal->size = size; 139 return (False); 140 } 141 strcpy((char *)toVal->addr, buffer); 142 } 143 else 144 toVal->addr = (XPointer)buffer; 145 toVal->size = size; 146 147 return (True); 148} 149