Tizen 2.1 base
[framework/uifw/xorg/lib/libxmu.git] / src / StrToShap.c
1 /*
2
3 Copyright 1988, 1998  The Open Group
4
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in 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 <string.h>
31 #include <X11/Intrinsic.h>
32 #include "Converters.h"
33 #include "CharSet.h"
34
35 /* ARGSUSED */
36 #define done(type, value) \
37         {                                                       \
38             if (toVal->addr != NULL) {                          \
39                 if (toVal->size < sizeof(type)) {               \
40                     toVal->size = sizeof(type);                 \
41                     return False;                               \
42                 }                                               \
43                 *(type*)(toVal->addr) = (value);                \
44             }                                                   \
45             else {                                              \
46                 static type static_val;                         \
47                 static_val = (value);                           \
48                 toVal->addr = (XtPointer)&static_val;           \
49             }                                                   \
50             toVal->size = sizeof(type);                         \
51             return True;                                        \
52         }
53
54
55 /*ARGSUSED*/
56 Boolean
57 XmuCvtStringToShapeStyle(Display *dpy, XrmValue *args, Cardinal *num_args,
58                          XrmValue *from, XrmValue *toVal, XtPointer *data)
59 {
60   String name = (String)from->addr;
61
62   if (XmuCompareISOLatin1(name, XtERectangle) == 0)
63     done(int, XmuShapeRectangle);
64   if (XmuCompareISOLatin1(name, XtEOval) == 0)
65     done(int, XmuShapeOval);
66   if (XmuCompareISOLatin1(name, XtEEllipse) == 0)
67     done(int, XmuShapeEllipse);
68   if (XmuCompareISOLatin1(name, XtERoundedRectangle) == 0)
69     done(int, XmuShapeRoundedRectangle);
70
71   XtDisplayStringConversionWarning(dpy, name, XtRShapeStyle);
72
73   return (False);
74 }
75
76 /*ARGSUSED*/
77 Boolean
78 XmuCvtShapeStyleToString(Display *dpy, XrmValue *args, Cardinal *num_args,
79                          XrmValue *fromVal, XrmValue *toVal, XtPointer *data)
80 {
81   static char *buffer;
82   Cardinal size;
83
84   switch (*(int *)fromVal->addr)
85     {
86     case XmuShapeRectangle:
87       buffer = XtERectangle;
88       break;
89     case XmuShapeOval:
90       buffer = XtEOval;
91       break;
92     case XmuShapeEllipse:
93       buffer = XtEEllipse;
94       break;
95     case XmuShapeRoundedRectangle:
96       buffer = XtERoundedRectangle;
97       break;
98     default:
99       XtAppWarning(XtDisplayToApplicationContext(dpy),
100                    "Cannot convert ShapeStyle to String");
101       toVal->addr = NULL;
102       toVal->size = 0;
103
104       return (False);
105             }
106
107   size = strlen(buffer) + 1;
108   if (toVal->addr != NULL)
109     {
110       if (toVal->size <= size)
111         {
112           toVal->size = size;
113           return (False);
114         }
115       strcpy((char *)toVal->addr, buffer);
116     }
117   else
118     toVal->addr = (XPointer)buffer;
119   toVal->size = size;
120
121   return (True);
122 }