| 1 |
|
| 2 |
/* |
| 3 |
* |
| 4 |
* Code and supporting documentation (c) Copyright 1990 1991 Tektronix, Inc. |
| 5 |
* All Rights Reserved |
| 6 |
* |
| 7 |
* This file is a component of an X Window System-specific implementation |
| 8 |
* of Xcms based on the TekColor Color Management System. Permission is |
| 9 |
* hereby granted to use, copy, modify, sell, and otherwise distribute this |
| 10 |
* software and its documentation for any purpose and without fee, provided |
| 11 |
* that this copyright, permission, and disclaimer notice is reproduced in |
| 12 |
* all copies of this software and in supporting documentation. TekColor |
| 13 |
* is a trademark of Tektronix, Inc. |
| 14 |
* |
| 15 |
* Tektronix makes no representation about the suitability of this software |
| 16 |
* for any purpose. It is provided "as is" and with all faults. |
| 17 |
* |
| 18 |
* TEKTRONIX DISCLAIMS ALL WARRANTIES APPLICABLE TO THIS SOFTWARE, |
| 19 |
* INCLUDING THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
| 20 |
* PARTICULAR PURPOSE. IN NO EVENT SHALL TEKTRONIX BE LIABLE FOR ANY |
| 21 |
* SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER |
| 22 |
* RESULTING FROM LOSS OF USE, DATA, OR PROFITS, WHETHER IN AN ACTION OF |
| 23 |
* CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 24 |
* CONNECTION WITH THE USE OR THE PERFORMANCE OF THIS SOFTWARE. |
| 25 |
* |
| 26 |
* NAME |
| 27 |
* XcmsProp.c |
| 28 |
* |
| 29 |
* DESCRIPTION |
| 30 |
* This utility routines for manipulating properties. |
| 31 |
* |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifdef HAVE_CONFIG_H |
| 35 |
#include <config.h> |
| 36 |
#endif |
| 37 |
#include <nx-X11/Xatom.h> |
| 38 |
#include "Xlibint.h" |
| 39 |
#include "Xcmsint.h" |
| 40 |
#include "Cv.h" |
| 41 |
|
| 42 |
|
| 43 |
/************************************************************************ |
| 44 |
* * |
| 45 |
* API PRIVATE ROUTINES * |
| 46 |
* * |
| 47 |
************************************************************************/ |
| 48 |
|
| 49 |
|
| 50 |
/* |
| 51 |
* NAME |
| 52 |
* _XcmsGetElement -- get an element value from the property passed |
| 53 |
* |
| 54 |
* SYNOPSIS |
| 55 |
*/ |
| 56 |
unsigned long |
| 57 |
_XcmsGetElement( |
| 58 |
int format, |
| 59 |
char **pValue, |
| 60 |
unsigned long *pCount) |
| 61 |
/* |
| 62 |
* DESCRIPTION |
| 63 |
* Get the next element from the property and return it. |
| 64 |
* Also increment the pointer the amount needed. |
| 65 |
* |
| 66 |
* Returns |
| 67 |
* unsigned long |
| 68 |
*/ |
| 69 |
{ |
| 70 |
unsigned long value; |
| 71 |
|
| 72 |
switch (format) { |
| 73 |
case 32: |
| 74 |
value = *((unsigned long *)(*pValue)) & 0xFFFFFFFF; |
| 75 |
*pValue += sizeof(unsigned long); |
| 76 |
*pCount -= 1; |
| 77 |
break; |
| 78 |
case 16: |
| 79 |
value = *((unsigned short *)(*pValue)); |
| 80 |
*pValue += sizeof(unsigned short); |
| 81 |
*pCount -= 1; |
| 82 |
break; |
| 83 |
case 8: |
| 84 |
value = *((unsigned char *) (*pValue)); |
| 85 |
*pValue += 1; |
| 86 |
*pCount -= 1; |
| 87 |
break; |
| 88 |
default: |
| 89 |
value = 0; |
| 90 |
break; |
| 91 |
} |
| 92 |
return(value); |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
/* |
| 97 |
* NAME |
| 98 |
* _XcmsGetProperty -- Determine the existance of a property |
| 99 |
* |
| 100 |
* SYNOPSIS |
| 101 |
*/ |
| 102 |
int |
| 103 |
_XcmsGetProperty( |
| 104 |
Display *pDpy, |
| 105 |
Window w, |
| 106 |
Atom property, |
| 107 |
int *pFormat, |
| 108 |
unsigned long *pNItems, |
| 109 |
unsigned long *pNBytes, |
| 110 |
char **pValue) |
| 111 |
/* |
| 112 |
* DESCRIPTION |
| 113 |
* |
| 114 |
* Returns |
| 115 |
* 0 if property does not exist. |
| 116 |
* 1 if property exists. |
| 117 |
*/ |
| 118 |
{ |
| 119 |
char *prop_ret; |
| 120 |
int format_ret; |
| 121 |
long len = 6516; |
| 122 |
#ifdef NXAGENT_SERVER |
| 123 |
unsigned long nitems_ret, after_ret = 0; |
| 124 |
#else |
| 125 |
unsigned long nitems_ret, after_ret; |
| 126 |
#endif |
| 127 |
Atom atom_ret; |
| 128 |
int xgwp_ret; |
| 129 |
|
| 130 |
while (True) { |
| 131 |
xgwp_ret = XGetWindowProperty (pDpy, w, property, 0, len, False, |
| 132 |
XA_INTEGER, &atom_ret, &format_ret, |
| 133 |
&nitems_ret, &after_ret, |
| 134 |
(unsigned char **)&prop_ret); |
| 135 |
if (xgwp_ret == Success && after_ret > 0) { |
| 136 |
len += nitems_ret * (format_ret >> 3); |
| 137 |
XFree (prop_ret); |
| 138 |
} else { |
| 139 |
break; |
| 140 |
} |
| 141 |
} |
| 142 |
if (xgwp_ret != Success || format_ret == 0 || nitems_ret == 0) { |
| 143 |
/* the property does not exist or is of an unexpected type or |
| 144 |
getting window property failed */ |
| 145 |
XFree (prop_ret); |
| 146 |
return(XcmsFailure); |
| 147 |
} |
| 148 |
|
| 149 |
*pFormat = format_ret; |
| 150 |
*pNItems = nitems_ret; |
| 151 |
*pNBytes = nitems_ret * (format_ret >> 3); |
| 152 |
*pValue = prop_ret; |
| 153 |
return(XcmsSuccess); |
| 154 |
} |