home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Shareware 1999 March
/
PCShareware-3-99.iso
/
IMPLE
/
DJGPP.RAR
/
DJGPP2
/
XLIB-SR0.ZIP
/
SRC
/
XLIBEMU
/
ATOM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-14
|
4KB
|
167 lines
/* $Id: atom.c 1.2 1994/01/15 02:02:41 ulrich Exp $ */
/*
* atom.c
*
* X library atom functions.
* Atoms are implemented with quarks.
*/
#include "Xlibemu.h"
#include <X11/XAtom.h>
#include <X11/Xresource.h>
typedef struct _XDisplayAtoms {
int next;
int size;
XrmQuark rep[1];
} DisplayAtoms;
static int
PredefineAtoms (Display *display)
{
if (display->atoms != NULL)
return 0;
display->atoms = (DisplayAtoms *)
Xmalloc (sizeof (DisplayAtoms) +
sizeof (XrmQuark) * XA_LAST_PREDEFINED);
display->atoms->next = XA_LAST_PREDEFINED+1;
display->atoms->size = XA_LAST_PREDEFINED+1;
display->atoms->rep[0] = XrmPermStringToQuark("NULL");
#define XA_Intern(name) \
display->atoms->rep[XA_ ## name] = XrmPermStringToQuark(# name);
/* from X11/XAtom.h */
XA_Intern(PRIMARY);
XA_Intern(SECONDARY);
XA_Intern(ARC);
XA_Intern(ATOM);
XA_Intern(BITMAP);
XA_Intern(CARDINAL);
XA_Intern(COLORMAP);
XA_Intern(CURSOR);
XA_Intern(CUT_BUFFER0);
XA_Intern(CUT_BUFFER1);
XA_Intern(CUT_BUFFER2);
XA_Intern(CUT_BUFFER3);
XA_Intern(CUT_BUFFER4);
XA_Intern(CUT_BUFFER5);
XA_Intern(CUT_BUFFER6);
XA_Intern(CUT_BUFFER7);
XA_Intern(DRAWABLE);
XA_Intern(FONT);
XA_Intern(INTEGER);
XA_Intern(PIXMAP);
XA_Intern(POINT);
XA_Intern(RECTANGLE);
XA_Intern(RESOURCE_MANAGER);
XA_Intern(RGB_COLOR_MAP);
XA_Intern(RGB_BEST_MAP);
XA_Intern(RGB_BLUE_MAP);
XA_Intern(RGB_DEFAULT_MAP);
XA_Intern(RGB_GRAY_MAP);
XA_Intern(RGB_GREEN_MAP);
XA_Intern(RGB_RED_MAP);
XA_Intern(STRING);
XA_Intern(VISUALID);
XA_Intern(WINDOW);
XA_Intern(WM_COMMAND);
XA_Intern(WM_HINTS);
XA_Intern(WM_CLIENT_MACHINE);
XA_Intern(WM_ICON_NAME);
XA_Intern(WM_ICON_SIZE);
XA_Intern(WM_NAME);
XA_Intern(WM_NORMAL_HINTS);
XA_Intern(WM_SIZE_HINTS);
XA_Intern(WM_ZOOM_HINTS);
XA_Intern(MIN_SPACE);
XA_Intern(NORM_SPACE);
XA_Intern(MAX_SPACE);
XA_Intern(END_SPACE);
XA_Intern(SUPERSCRIPT_X);
XA_Intern(SUPERSCRIPT_Y);
XA_Intern(SUBSCRIPT_X);
XA_Intern(SUBSCRIPT_Y);
XA_Intern(UNDERLINE_POSITION);
XA_Intern(UNDERLINE_THICKNESS);
XA_Intern(STRIKEOUT_ASCENT);
XA_Intern(STRIKEOUT_DESCENT);
XA_Intern(ITALIC_ANGLE);
XA_Intern(X_HEIGHT);
XA_Intern(QUAD_WIDTH);
XA_Intern(WEIGHT);
XA_Intern(POINT_SIZE);
XA_Intern(RESOLUTION);
XA_Intern(COPYRIGHT);
XA_Intern(NOTICE);
XA_Intern(FONT_NAME);
XA_Intern(FAMILY_NAME);
XA_Intern(FULL_NAME);
XA_Intern(CAP_HEIGHT);
XA_Intern(WM_CLASS);
XA_Intern(WM_TRANSIENT_FOR);
#undef XA_Intern
return 0;
}
Atom
XInternAtom(
Display* display,
_Xconst char* atom_name,
Bool only_if_exists)
{
int i;
XrmQuark atom_rep;
if (display->atoms == NULL)
PredefineAtoms (display);
atom_rep = XrmStringToQuark (atom_name);
for (i = display->atoms->next; --i >= 0; ) {
if (atom_rep == display->atoms->rep[i])
return (Atom) i;
}
if (only_if_exists == False)
return (Atom) 0;
if (display->atoms->next >= display->atoms->size) {
display->atoms->size += display->atoms->size / 2 + 1;
display->atoms = (DisplayAtoms *)
Xrealloc (display->atoms, sizeof (DisplayAtoms) +
sizeof (XrmQuark) * display->atoms->size);
}
i = display->atoms->next;
display->atoms->rep[i] = atom_rep;
display->atoms->next++;
return (Atom) i;
}
char *
XGetAtomName
(Display* display,
Atom atom)
{
char *atom_name, *name;
if (display->atoms == NULL)
PredefineAtoms (display);
if (atom == 0 || atom >= display->atoms->next)
return NULL;
atom_name = XrmQuarkToString (display->atoms->rep[(int) atom]);
if (! atom_name)
return NULL;
name = (char *) Xmalloc (strlen (atom_name) + 1);
if (name)
strcpy (name, atom_name);
return name;
}