1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
/* $XConsortium: Direction.c /main/6 1996/03/28 15:14:33 daniel $ */
/*
* Motif
*
* Copyright (c) 1987-2012, The Open Group. All rights reserved.
*
* These libraries and programs are free software; you can
* redistribute them and/or modify them under the terms of the GNU
* Lesser General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* These libraries and programs are distributed in the hope that
* they will be useful, but WITHOUT ANY WARRANTY; without even the
* implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with these librararies and programs; if not, write
* to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301 USA
*
*/
/*
* HISTORY
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "XmI.h"
#include <Xm/ManagerP.h>
#include <Xm/GadgetP.h>
#include <Xm/PrimitiveP.h>
#include <Xm/TraitP.h>
#include <Xm/LayoutT.h>
/*********************************************************************
*
* _XmDirectionDefault
* This procedure provides the dynamic resource default for
* the layout direction resource dependent on the parent's value.
*
*********************************************************************/
/*ARGSUSED*/
void
_XmDirectionDefault(Widget widget,
int offset, /* unused */
XrmValue *value )
{
static XmDirection direction;
value->addr = (XPointer) &direction;
/* This is an ugly hack, but what to do when user sets stringDirection
in resource file. Dependent on that stringDirection comes before
layoutDirection in resource list. Part of the reason is that this is
the same field. Yuck! */
if (XmIsManager(widget) &&
(((XmManagerWidget)widget)->manager.string_direction !=
XmSTRING_DIRECTION_DEFAULT))
direction =
XmStringDirectionToDirection(((XmManagerWidget)widget)->manager.
string_direction);
else
direction = _XmGetLayoutDirection(XtParent(widget));
}
/*ARGSUSED*/
void
_XmFromLayoutDirection(
Widget wid,
int resource_offset, /* unused */
XtArgVal *value )
{
if (XmIsManager(wid))
*value = (XtArgVal)XmDirectionToStringDirection((XmDirection)*value);
else if (XmIsLabel(wid) || XmIsLabelGadget(wid) || XmIsList(wid))
*value =
(XtArgVal)XmDirectionToStringDirection(_XmGetLayoutDirection(wid));
}
/*ARGSUSED*/
XmImportOperator
_XmToLayoutDirection(
Widget wid,
int resource_offset, /* unused */
XtArgVal *value )
{
if (XmIsManager(wid)) {
*value = (XtArgVal)XmStringDirectionToDirection((XmStringDirection)*value);
return XmSYNTHETIC_LOAD;
} else if (XmIsLabel(wid) || XmIsList(wid)) {
XmPrim_layout_direction(((XmPrimitiveWidget)wid)) =
XmStringDirectionToDirection((XmStringDirection)*value);
return XmSYNTHETIC_NONE;
} else if (XmIsLabelGadget(wid)) {
((XmGadget)wid)->gadget.layout_direction =
XmStringDirectionToDirection((XmStringDirection)*value);
return XmSYNTHETIC_NONE;
}
return XmSYNTHETIC_LOAD;
}
XmStringDirection
XmDirectionToStringDirection(XmDirection dir)
{
if (XmDirectionMatch(dir, XmLEFT_TO_RIGHT))
return XmSTRING_DIRECTION_L_TO_R;
else if (XmDirectionMatch(dir, XmRIGHT_TO_LEFT))
return XmSTRING_DIRECTION_R_TO_L;
return XmSTRING_DIRECTION_DEFAULT;
}
XmDirection
XmStringDirectionToDirection(XmStringDirection dir)
{
switch (dir) {
case XmSTRING_DIRECTION_L_TO_R:
return XmLEFT_TO_RIGHT;
case XmSTRING_DIRECTION_R_TO_L:
return XmRIGHT_TO_LEFT;
default:
return XmDEFAULT_DIRECTION;
}
}
XmDirection
_XmGetLayoutDirection( Widget w )
{
XmSpecifyLayoutDirectionTrait layoutT = NULL;
while (w && !(layoutT = (XmSpecifyLayoutDirectionTrait)
XmeTraitGet((XtPointer) XtClass(w),
XmQTspecifyLayoutDirection)))
w = XtParent(w);
if (w && layoutT && layoutT->get_direction)
return layoutT->get_direction(w);
else
return XmLEFT_TO_RIGHT;
}
/* Handle compatibility with XmStringDirection */
#define Fixdir(d) (((d) <= 1) ? (~((d)+1)) : ((d) | XmDIRECTION_IGNORED))
Boolean
XmDirectionMatch(XmDirection d1,
XmDirection d2)
{
d1 = Fixdir(d1);
d2 = Fixdir(d2);
return (((XmDirection)(d1 & d2) == (XmDirection)d1) ||
((XmDirection)(d1 & d2) == (XmDirection)d2));
}
Boolean
XmDirectionMatchPartial(XmDirection d1,
XmDirection d2,
XmDirection dmask)
{
return XmDirectionMatch(d1 & dmask, d2 & dmask);
}
|