]> git.saurik.com Git - wxWidgets.git/blame - src/xpm/XpmI.h
1. restored wxEvent::operator=()
[wxWidgets.git] / src / xpm / XpmI.h
CommitLineData
cfbe03c9 1/*
e6ed776f 2 * Copyright (C) 1989-95 GROUPE BULL
cfbe03c9
JS
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to
6 * deal in the Software without restriction, including without limitation the
7 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
8 * sell copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
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
17 * GROUPE BULL 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 GROUPE BULL 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 GROUPE BULL.
24 */
25
26/*****************************************************************************\
e6ed776f 27* XpmI.h: *
cfbe03c9
JS
28* *
29* XPM library *
e6ed776f
GRG
30* Internal Include file *
31* *
32* ** Everything defined here is subject to changes any time. ** *
cfbe03c9
JS
33* *
34* Developed by Arnaud Le Hors *
35\*****************************************************************************/
36
37/*
38 * The code related to FOR_MSW has been added by
39 * HeDu (hedu@cul-ipn.uni-kiel.de) 4/94
40 */
41
e6ed776f
GRG
42#ifndef XPMI_h
43#define XPMI_h
cfbe03c9 44
e6ed776f 45#include "xpm.h"
cfbe03c9 46
e06b9569 47// Added by JACS for some compilers (no popen/pclose functions)
6158481f 48#if defined(__WATCOMC__) || (!defined(WIN32) && defined(_MSC_VER)) || (!defined(WIN32) && defined(__BORLANDC__))
457e6c54
JS
49#define NO_ZPIPE
50#endif
51
cfbe03c9
JS
52/*
53 * lets try to solve include files
54 */
cfbe03c9
JS
55
56#include <stdio.h>
e6ed776f 57#include <stdlib.h>
cfbe03c9
JS
58/* stdio.h doesn't declare popen on a Sequent DYNIX OS */
59#ifdef sequent
60extern FILE *popen();
61#endif
62
e6ed776f 63#if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32)
cfbe03c9
JS
64#include <string.h>
65
66#ifndef index
67#define index strchr
68#endif
69
70#ifndef rindex
71#define rindex strrchr
72#endif
73
e6ed776f 74#else /* defined(SYSV) || defined(SVR4) || defined(VMS) */
cfbe03c9
JS
75#include <strings.h>
76#endif
77
cfbe03c9
JS
78
79
e6ed776f
GRG
80#if defined(SYSV) || defined(SVR4) || defined(VMS) || defined(WIN32)
81#ifndef bcopy
cfbe03c9 82#define bcopy(source, dest, count) memcpy(dest, source, count)
e6ed776f
GRG
83#endif
84#ifndef bzero
cfbe03c9
JS
85#define bzero(b, len) memset(b, 0, len)
86#endif
e6ed776f 87#endif
cfbe03c9 88
e6ed776f
GRG
89/* the following is defined in X11R6 but not in previous versions */
90#ifdef __alpha
91#ifndef LONG64
92#define LONG64
93#endif
94#endif
95
96#ifdef VMS
97#include <unixio.h>
98#include <file.h>
99#endif
100
101/* The following should help people wanting to use their own memory allocation
102 * functions. To avoid the overhead of a function call when the standard
103 * functions are used these are all macros, even the XpmFree function which
104 * needs to be a real function for the outside world though.
105 * So if change these be sure to change the XpmFree function in misc.c
106 * accordingly.
107 */
108#define XpmFree(ptr) free(ptr)
cfbe03c9 109
cfbe03c9
JS
110#ifndef FOR_MSW
111#define XpmMalloc(size) malloc((size))
112#define XpmRealloc(ptr, size) realloc((ptr), (size))
113#define XpmCalloc(nelem, elsize) calloc((nelem), (elsize))
114#else
115/* checks for mallocs bigger than 64K */
116#define XpmMalloc(size) boundCheckingMalloc((long)(size))/* in simx.[ch] */
117#define XpmRealloc(ptr, size) boundCheckingRealloc((ptr),(long)(size))
118#define XpmCalloc(nelem, elsize) \
119 boundCheckingCalloc((long)(nelem),(long) (elsize))
120#endif
121
e6ed776f 122#define XPMMAXCMTLEN BUFSIZ
cfbe03c9
JS
123typedef struct {
124 unsigned int type;
125 union {
126 FILE *file;
127 char **data;
128 } stream;
129 char *cptr;
130 unsigned int line;
131 int CommentLength;
e6ed776f 132 char Comment[XPMMAXCMTLEN];
cfbe03c9
JS
133 char *Bcmt, *Ecmt, Bos, Eos;
134 int format; /* 1 if XPM1, 0 otherwise */
e6ed776f
GRG
135#ifdef CXPMPROG
136 int lineNum;
137 int charNum;
138#endif
cfbe03c9
JS
139} xpmData;
140
141#define XPMARRAY 0
142#define XPMFILE 1
143#define XPMPIPE 2
144#define XPMBUFFER 3
145
146#define EOL '\n'
147#define TAB '\t'
148#define SPC ' '
149
150typedef struct {
151 char *type; /* key word */
152 char *Bcmt; /* string beginning comments */
153 char *Ecmt; /* string ending comments */
154 char Bos; /* character beginning strings */
155 char Eos; /* character ending strings */
156 char *Strs; /* strings separator */
157 char *Dec; /* data declaration string */
158 char *Boa; /* string beginning assignment */
159 char *Eoa; /* string ending assignment */
160} xpmDataType;
161
162extern xpmDataType xpmDataTypes[];
163
164/*
165 * rgb values and ascii names (from rgb text file) rgb values,
166 * range of 0 -> 65535 color mnemonic of rgb value
167 */
168typedef struct {
169 int r, g, b;
170 char *name;
171} xpmRgbName;
172
173/* Maximum number of rgb mnemonics allowed in rgb text file. */
174#define MAX_RGBNAMES 1024
175
176extern char *xpmColorKeys[];
177
178#define TRANSPARENT_COLOR "None" /* this must be a string! */
179
180/* number of xpmColorKeys */
181#define NKEYS 5
182
e6ed776f 183/* XPM internal routines */
cfbe03c9
JS
184
185FUNC(xpmParseData, int, (xpmData *data, XpmImage *image, XpmInfo *info));
e6ed776f
GRG
186FUNC(xpmParseDataAndCreate, int, (Display *display, xpmData *data,
187 XImage **image_return,
188 XImage **shapeimage_return,
189 XpmImage *image, XpmInfo *info,
190 XpmAttributes *attributes));
cfbe03c9
JS
191
192FUNC(xpmFreeColorTable, void, (XpmColor *colorTable, int ncolors));
193
194FUNC(xpmInitAttributes, void, (XpmAttributes *attributes));
195
196FUNC(xpmInitXpmImage, void, (XpmImage *image));
197
198FUNC(xpmInitXpmInfo, void, (XpmInfo *info));
199
200FUNC(xpmSetInfoMask, void, (XpmInfo *info, XpmAttributes *attributes));
201FUNC(xpmSetInfo, void, (XpmInfo *info, XpmAttributes *attributes));
202FUNC(xpmSetAttributes, void, (XpmAttributes *attributes, XpmImage *image,
203 XpmInfo *info));
204
e6ed776f 205#if !defined(FOR_MSW) && !defined(AMIGA)
cfbe03c9
JS
206FUNC(xpmCreatePixmapFromImage, void, (Display *display, Drawable d,
207 XImage *ximage, Pixmap *pixmap_return));
208
209FUNC(xpmCreateImageFromPixmap, void, (Display *display, Pixmap pixmap,
210 XImage **ximage_return,
211 unsigned int *width,
212 unsigned int *height));
213#endif
214
e6ed776f
GRG
215/* structures and functions related to hastable code */
216
217typedef struct _xpmHashAtom {
218 char *name;
219 void *data;
220} *xpmHashAtom;
221
222typedef struct {
223 int size;
224 int limit;
225 int used;
226 xpmHashAtom *atomTable;
227} xpmHashTable;
228
229FUNC(xpmHashTableInit, int, (xpmHashTable *table));
230FUNC(xpmHashTableFree, void, (xpmHashTable *table));
231FUNC(xpmHashSlot, xpmHashAtom *, (xpmHashTable *table, char *s));
232FUNC(xpmHashIntern, int, (xpmHashTable *table, char *tag, void *data));
233
234#define HashAtomData(i) ((void *)i)
235#define HashColorIndex(slot) ((unsigned int)((*slot)->data))
236#define USE_HASHTABLE (cpp > 2 && ncolors > 4)
237
cfbe03c9
JS
238/* I/O utility */
239
240FUNC(xpmNextString, int, (xpmData *mdata));
241FUNC(xpmNextUI, int, (xpmData *mdata, unsigned int *ui_return));
242FUNC(xpmGetString, int, (xpmData *mdata, char **sptr, unsigned int *l));
243
244#define xpmGetC(mdata) \
245 ((!mdata->type || mdata->type == XPMBUFFER) ? \
246 (*mdata->cptr++) : (getc(mdata->stream.file)))
247
248FUNC(xpmNextWord, unsigned int,
249 (xpmData *mdata, char *buf, unsigned int buflen));
250FUNC(xpmGetCmt, int, (xpmData *mdata, char **cmt));
cfbe03c9 251FUNC(xpmParseHeader, int, (xpmData *mdata));
e6ed776f
GRG
252FUNC(xpmParseValues, int, (xpmData *data, unsigned int *width,
253 unsigned int *height, unsigned int *ncolors,
254 unsigned int *cpp, unsigned int *x_hotspot,
255 unsigned int *y_hotspot, unsigned int *hotspot,
256 unsigned int *extensions));
257
258FUNC(xpmParseColors, int, (xpmData *data, unsigned int ncolors,
259 unsigned int cpp, XpmColor **colorTablePtr,
260 xpmHashTable *hashtable));
261
262FUNC(xpmParseExtensions, int, (xpmData *data, XpmExtension **extensions,
263 unsigned int *nextensions));
cfbe03c9
JS
264
265/* RGB utility */
266
267FUNC(xpmReadRgbNames, int, (char *rgb_fname, xpmRgbName *rgbn));
268FUNC(xpmGetRgbName, char *, (xpmRgbName *rgbn, int rgbn_max,
269 int red, int green, int blue));
270FUNC(xpmFreeRgbNames, void, (xpmRgbName *rgbn, int rgbn_max));
271#ifdef FOR_MSW
272FUNC(xpmGetRGBfromName,int, (char *name, int *r, int *g, int *b));
273#endif
274
e6ed776f 275#ifndef AMIGA
cfbe03c9
JS
276FUNC(xpm_xynormalizeimagebits, void, (register unsigned char *bp,
277 register XImage *img));
278FUNC(xpm_znormalizeimagebits, void, (register unsigned char *bp,
279 register XImage *img));
280
281/*
282 * Macros
283 *
284 * The XYNORMALIZE macro determines whether XY format data requires
285 * normalization and calls a routine to do so if needed. The logic in
286 * this module is designed for LSBFirst byte and bit order, so
287 * normalization is done as required to present the data in this order.
288 *
289 * The ZNORMALIZE macro performs byte and nibble order normalization if
290 * required for Z format data.
291 *
292 * The XYINDEX macro computes the index to the starting byte (char) boundary
293 * for a bitmap_unit containing a pixel with coordinates x and y for image
294 * data in XY format.
295 *
296 * The ZINDEX* macros compute the index to the starting byte (char) boundary
297 * for a pixel with coordinates x and y for image data in ZPixmap format.
298 *
299 */
300
301#define XYNORMALIZE(bp, img) \
302 if ((img->byte_order == MSBFirst) || (img->bitmap_bit_order == MSBFirst)) \
303 xpm_xynormalizeimagebits((unsigned char *)(bp), img)
304
305#define ZNORMALIZE(bp, img) \
306 if (img->byte_order == MSBFirst) \
307 xpm_znormalizeimagebits((unsigned char *)(bp), img)
308
309#define XYINDEX(x, y, img) \
310 ((y) * img->bytes_per_line) + \
311 (((x) + img->xoffset) / img->bitmap_unit) * (img->bitmap_unit >> 3)
312
313#define ZINDEX(x, y, img) ((y) * img->bytes_per_line) + \
314 (((x) * img->bits_per_pixel) >> 3)
315
316#define ZINDEX32(x, y, img) ((y) * img->bytes_per_line) + ((x) << 2)
317
318#define ZINDEX16(x, y, img) ((y) * img->bytes_per_line) + ((x) << 1)
319
320#define ZINDEX8(x, y, img) ((y) * img->bytes_per_line) + (x)
321
322#define ZINDEX1(x, y, img) ((y) * img->bytes_per_line) + ((x) >> 3)
e6ed776f 323#endif /* not AMIGA */
cfbe03c9 324
e6ed776f 325#ifdef __STDC__
cfbe03c9
JS
326#define Const const
327#else
328#define Const /**/
329#endif
330
cfbe03c9 331#ifdef NEED_STRDUP
e6ed776f
GRG
332FUNC(xpmstrdup, char *, (char *s1));
333#else
334#undef xpmstrdup
335#define xpmstrdup strdup
cfbe03c9
JS
336#endif
337
338#ifdef NEED_STRCASECMP
e6ed776f
GRG
339FUNC(xpmstrcasecmp, int, (char *s1, char *s2));
340#else
341#undef xpmstrcasecmp
342#define xpmstrcasecmp strcasecmp
cfbe03c9
JS
343#endif
344
e6ed776f
GRG
345FUNC(xpmatoui, unsigned int,
346 (char *p, unsigned int l, unsigned int *ui_return));
cfbe03c9
JS
347
348#endif