1 /**
2  *
3  * $Header: /cvsroot/lesstif/lesstif/lib/Xm-2.1/Direction.c,v 1.1 2004/08/28 19:22:43 dannybackx Exp $
4  *
5  * Copyright (C) 1998 Free Software Foundation, Inc.
6  * Copyright (C) 1998-2002 LessTif Development Team
7  *
8  * This file is part of the GNU LessTif Library.
9  *
10  * This library is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Library General Public
12  * License as published by the Free Software Foundation; either
13  * version 2 of the License, or (at your option) any later version.
14  *
15  * This library is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18  * Library General Public License for more details.
19  *
20  * You should have received a copy of the GNU Library General Public
21  * License along with this library; if not, write to the Free
22  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  *
24  **/
25 
26 static const char rcsid[] = "$Header: /cvsroot/lesstif/lesstif/lib/Xm-2.1/Direction.c,v 1.1 2004/08/28 19:22:43 dannybackx Exp $";
27 
28 #include <LTconfig.h>
29 
30 #include <Xm/XmP.h>
31 #include <Xm/TraitP.h>
32 #include <Xm/LayoutT.h>
33 #include <XmI/DirectionI.h>
34 
35 #include <XmI/DebugUtil.h>
36 
37 
38 /* ================================================================ */
39 /* Internal toolkit routines (but external scope) */
40 
41 void
_XmDirectionDefault(Widget w,int offset,XrmValue * value)42 _XmDirectionDefault(Widget w, int offset, XrmValue *value)
43 {
44    /* FIX ME: I'm a stub */
45 
46    static XmDirection dir = XmDEFAULT_DIRECTION;
47 
48    DEBUGOUT(_LtDebug(__FILE__, w, "_XmDirectionDefault\n"));
49 
50    value->addr = (char *) &dir;
51    value->size = sizeof(XmDirection);
52 }
53 
54 XmDirection
_XmGetLayoutDirection(Widget w)55 _XmGetLayoutDirection(Widget w)
56 {
57    /* FIX ME: this is a guess */
58 
59    XmSpecifyLayoutDirectionTrait ptrait;
60    XmDirection dir = XmDEFAULT_DIRECTION;
61 
62    if ((ptrait = (XmSpecifyLayoutDirectionTrait)
63                   XmeTraitGet((XtPointer)XtClass(w),
64 		  XmQTspecifyLayoutDirection))!= NULL)
65    {
66       if(ptrait->get_direction != NULL)
67       {
68          dir =  ptrait->get_direction(w);
69       }
70    }
71 
72    return dir;
73 }
74 
75 void
_XmFromLayoutDirection(Widget widget,int offset,XtArgVal * value)76 _XmFromLayoutDirection(Widget widget, int offset, XtArgVal *value)
77 {
78     /* FIX ME: this is a guess */
79     XmDirection dir;
80     XmStringDirection sdir;
81 
82     dir = *((XmDirection *) (((char *)widget) + offset));
83 
84     sdir = XmDirectionToStringDirection(dir);
85 
86     *value = (XtArgVal)sdir;
87 }
88 
89 
90 XmImportOperator
_XmToLayoutDirection(Widget widget,int offset,XtArgVal * value)91 _XmToLayoutDirection(Widget widget, int offset, XtArgVal *value)
92 {
93     /* FIX ME: this is a guess */
94     XmDirection dir;
95     XmStringDirection sdir;
96 
97     sdir = (XmStringDirection) *value;
98     dir = XmStringDirectionToDirection(sdir);
99 
100     *value = (XtArgVal)dir;
101 
102     return XmSYNTHETIC_LOAD;
103 }
104 
105 /* ================================================================ */
106 /* Public routines */
107 
108 Boolean
XmDirectionMatch(XmDirection dir1,XmDirection dir2)109 XmDirectionMatch(XmDirection dir1, XmDirection dir2)
110 {
111    /* A nice exercise in Boolean algebra...
112       Somehow I think one could do better ;-) */
113    if ( (dir1&dir2&XmHORIZONTAL_MASK) &&
114         ((dir1&XmHORIZONTAL_MASK) != (dir2&XmHORIZONTAL_MASK)) )
115       return False;
116    if ((dir1&dir2&XmVERTICAL_MASK) &&
117         ((dir1&XmVERTICAL_MASK) != (dir2&XmVERTICAL_MASK)) )
118       return False;
119    if ((dir1&dir2&XmPRECEDENCE_MASK) &&
120         ((dir1&XmPRECEDENCE_MASK) != (dir2&XmPRECEDENCE_MASK)) )
121       return False;
122 
123    return True;
124 }
125 
126 Boolean
XmDirectionMatchPartial(XmDirection dir1,XmDirection dir2,XmDirection dir_mask)127 XmDirectionMatchPartial(XmDirection dir1, XmDirection dir2, XmDirection dir_mask)
128 {
129 
130    if ( (dir1 & dir_mask) == (dir2 & dir_mask) )
131       return True;
132    else
133       return False;
134 }
135 
136 /*
137    FUNCTION: XmDirectionToStringDirection
138    SYNOPSIS: XmStringDirection XmDirectionToStringDirection(XmDirection dir)
139    DESCRIPTION:
140    XmDirectionToStringDirection converts a XmDirection value into
141    its equivalent XmStringDirection value.
142    END:
143 */
144 XmStringDirection
XmDirectionToStringDirection(XmDirection dir)145 XmDirectionToStringDirection(XmDirection dir)
146 {
147    XmStringDirection sdir = XmSTRING_DIRECTION_DEFAULT;
148 
149    /* check for horizontal element */
150    if (dir & XmHORIZONTAL_MASK)
151    {
152       /* horizontal flag found */
153       if (dir & XmLEFT_TO_RIGHT_MASK)
154       {
155          sdir = XmSTRING_DIRECTION_L_TO_R;
156       }
157       else if (dir & XmRIGHT_TO_LEFT_MASK)
158       {
159          sdir = XmSTRING_DIRECTION_R_TO_L;
160       }
161    }
162    return sdir;
163 }
164 
165 /*
166    FUNCTION: XmStringDirectionToDirection
167    SYNOPSIS: XmDirection XmStringDirectionToDirection(XmStringDirection sdir)
168    DESCRIPTION:
169    XmStringDirectionToDirection converts a XmStringDirection value into
170    its equivalent XmDirection value.
171    END:
172 */
173 XmDirection
XmStringDirectionToDirection(XmStringDirection sdir)174 XmStringDirectionToDirection(XmStringDirection sdir)
175 {
176 
177    XmDirection dir = XmDEFAULT_DIRECTION;
178 
179    if (sdir == XmSTRING_DIRECTION_L_TO_R)
180    {
181       dir = XmLEFT_TO_RIGHT;
182    }
183    else if (sdir == XmSTRING_DIRECTION_R_TO_L)
184    {
185       dir = XmRIGHT_TO_LEFT;
186    }
187 
188    return dir;
189 }
190