| 1 |
/* @(#)unit.c 17.1 (ESO-IPG) 01/25/02 17:26:36 */ |
| 2 |
/*--------------------------------------------------------------------- |
| 3 |
* $Date: 2003-06-04 14:49:19 $ $Revision: 1.1.1.1 $ |
| 4 |
*--------------------------------------------------------------------- |
| 5 |
* |
| 6 |
* |
| 7 |
* Copyright (c) 1992, Visual Edge Software Ltd. |
| 8 |
* |
| 9 |
* ALL RIGHTS RESERVED. Permission to use, copy, modify, and |
| 10 |
* distribute this software and its documentation for any purpose |
| 11 |
* and without fee is hereby granted, provided that the above |
| 12 |
* copyright notice appear in all copies and that both that |
| 13 |
* copyright notice and this permission notice appear in supporting |
| 14 |
* documentation, and that the name of Visual Edge Software not be |
| 15 |
* used in advertising or publicity pertaining to distribution of |
| 16 |
* the software without specific, written prior permission. The year |
| 17 |
* included in the notice is the year of the creation of the work. |
| 18 |
*-------------------------------------------------------------------*/ |
| 19 |
|
| 20 |
/* --------------------------------------------------------------------------- |
| 21 |
NAME: unit.c |
| 22 |
DESCRIPTION: Utilities for Motif unit type handling. |
| 23 |
|
| 24 |
CREATION: Nov 21 1990 Visual Edge Software |
| 25 |
REVISIONS: Nov 30 1990 |
| 26 |
-- Added ifdef statements for MOTIF_WIDGETS and added |
| 27 |
"else" cases. |
| 28 |
---------------------------------------------------------------------------*/ |
| 29 |
|
| 30 |
#include <Xm/Xm.h> |
| 31 |
|
| 32 |
/****************************************************************************** |
| 33 |
NAME: UxFindUnitType |
| 34 |
RETURN: unsigned char -- unitType value |
| 35 |
INPUTS: Widget wid; -- widget in question |
| 36 |
|
| 37 |
DESCRIPTION: Determines the widget's unitType. |
| 38 |
CREATION: 21 Nov 1990 (bug1154) |
| 39 |
-----------------------------------------------------------------------------*/ |
| 40 |
|
| 41 |
unsigned char UxFindUnitType (wid) |
| 42 |
Widget wid; |
| 43 |
{ |
| 44 |
unsigned char unittype; |
| 45 |
|
| 46 |
#ifdef MOTIF_WIDGETS |
| 47 |
if (XmIsVendorShell(wid)) |
| 48 |
{ |
| 49 |
XtVaGetValues (wid, |
| 50 |
XmNshellUnitType, &unittype, |
| 51 |
NULL); |
| 52 |
} |
| 53 |
else if (XmIsManager(wid) || XmIsPrimitive(wid) || XmIsGadget(wid)) |
| 54 |
{ |
| 55 |
XtVaGetValues (wid, |
| 56 |
XmNunitType, &unittype, |
| 57 |
NULL); |
| 58 |
} |
| 59 |
else |
| 60 |
{ |
| 61 |
unittype = XmPIXELS; |
| 62 |
} |
| 63 |
#else |
| 64 |
unittype = 0; |
| 65 |
#endif /* MOTIF_WIDGETS */ |
| 66 |
|
| 67 |
return (unittype); |
| 68 |
} |
| 69 |
|
| 70 |
/****************************************************************************** |
| 71 |
NAME: UxConvertPosition |
| 72 |
INPUTS: Widget wid; -- widget in question |
| 73 |
unsigned char from; -- unitType to convert from |
| 74 |
Position xval; -- x value to convert |
| 75 |
Position yval; -- y value to convert |
| 76 |
unsigned char to; -- unitType to convert to |
| 77 |
Position *x; -- x storage |
| 78 |
Position *y; -- y storage |
| 79 |
|
| 80 |
DESCRIPTION: Converts x and y resources to a new unit type. |
| 81 |
CREATION: 21 Nov 1990 (bug1154) |
| 82 |
-----------------------------------------------------------------------------*/ |
| 83 |
|
| 84 |
void UxConvertPosition (wid, from, xval, yval, to, x, y) |
| 85 |
Widget wid; |
| 86 |
unsigned char from; |
| 87 |
Position xval; |
| 88 |
Position yval; |
| 89 |
unsigned char to; |
| 90 |
Position *x; |
| 91 |
Position *y; |
| 92 |
{ |
| 93 |
int xInt, yInt; |
| 94 |
#ifdef MOTIF_WIDGETS |
| 95 |
*x = xInt = XmConvertUnits (wid, XmHORIZONTAL, from, (int) xval, to); |
| 96 |
*y = yInt = XmConvertUnits (wid, XmVERTICAL, from, (int) yval, to); |
| 97 |
/* if converted value is invalid, set to ZERO. */ |
| 98 |
if (xInt != (int)(*x)) { |
| 99 |
*x = 0; |
| 100 |
} |
| 101 |
if (yInt != (int)(*y)) { |
| 102 |
*y = 0; |
| 103 |
} |
| 104 |
#else |
| 105 |
*x = xval; |
| 106 |
*y = yval; |
| 107 |
#endif /* MOTIF_WIDGETS */ |
| 108 |
} |
| 109 |
|
| 110 |
/****************************************************************************** |
| 111 |
NAME: UxConvertDimension |
| 112 |
INPUTS: Widget wid; -- widget in question |
| 113 |
unsigned char from; -- unitType to convert from |
| 114 |
Dimension wval; -- width value to convert |
| 115 |
Dimension hval; -- height value to convert |
| 116 |
unsigned char to; -- unitType to convert to |
| 117 |
Dimension *w; -- width storage |
| 118 |
Dimension *h; -- height storage |
| 119 |
|
| 120 |
DESCRIPTION: Converts width and height resources to a new unit type. |
| 121 |
CREATION: 21 Nov 1990 (bug1154) |
| 122 |
-----------------------------------------------------------------------------*/ |
| 123 |
|
| 124 |
void UxConvertDimension (wid, from, wval, hval, to, w, h) |
| 125 |
Widget wid; |
| 126 |
unsigned char from; |
| 127 |
Dimension wval; |
| 128 |
Dimension hval; |
| 129 |
unsigned char to; |
| 130 |
Dimension *w; |
| 131 |
Dimension *h; |
| 132 |
{ |
| 133 |
int wInt, hInt; |
| 134 |
#ifdef MOTIF_WIDGETS |
| 135 |
*w = wInt = XmConvertUnits (wid, XmHORIZONTAL, from, (int) wval, to); |
| 136 |
*h = hInt = XmConvertUnits (wid, XmVERTICAL, from, (int) hval, to); |
| 137 |
/* if converted value is invalid, set to 100. */ |
| 138 |
if (wInt != (int)(*w)) { |
| 139 |
*w = XmConvertUnits (wid, XmHORIZONTAL, XmPIXELS, (int) 100, to); |
| 140 |
} |
| 141 |
if (hInt != (int)(*h)) { |
| 142 |
*h = XmConvertUnits (wid, XmVERTICAL, XmPIXELS, (int) 100, to); |
| 143 |
} |
| 144 |
#else |
| 145 |
*w = wval; |
| 146 |
*h = hval; |
| 147 |
#endif /* MOTIF_WIDGETS */ |
| 148 |
} |
| 149 |
|