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 >
C/C++ Source or Header  |  1994-01-14  |  4KB  |  167 lines

  1. /* $Id: atom.c 1.2 1994/01/15 02:02:41 ulrich Exp $ */
  2. /*
  3.  * atom.c
  4.  *
  5.  * X library atom functions.
  6.  * Atoms are implemented with quarks.
  7.  */
  8.  
  9. #include "Xlibemu.h"
  10. #include <X11/XAtom.h>
  11. #include <X11/Xresource.h>
  12.  
  13.  
  14. typedef struct _XDisplayAtoms {
  15.   int        next;
  16.   int        size;
  17.   XrmQuark    rep[1];
  18. } DisplayAtoms;
  19.  
  20. static int
  21. PredefineAtoms (Display *display)
  22. {
  23.   if (display->atoms != NULL)
  24.     return 0;
  25.  
  26.   display->atoms = (DisplayAtoms *)
  27.     Xmalloc (sizeof (DisplayAtoms) +
  28.          sizeof (XrmQuark) * XA_LAST_PREDEFINED);
  29.   display->atoms->next = XA_LAST_PREDEFINED+1;
  30.   display->atoms->size = XA_LAST_PREDEFINED+1;
  31.  
  32.   display->atoms->rep[0] = XrmPermStringToQuark("NULL");
  33.  
  34. #define XA_Intern(name) \
  35.   display->atoms->rep[XA_ ## name] = XrmPermStringToQuark(# name);
  36.  
  37.   /* from X11/XAtom.h */
  38.  
  39.   XA_Intern(PRIMARY);
  40.   XA_Intern(SECONDARY);
  41.   XA_Intern(ARC);
  42.   XA_Intern(ATOM);
  43.   XA_Intern(BITMAP);
  44.   XA_Intern(CARDINAL);
  45.   XA_Intern(COLORMAP);
  46.   XA_Intern(CURSOR);
  47.   XA_Intern(CUT_BUFFER0);
  48.   XA_Intern(CUT_BUFFER1);
  49.   XA_Intern(CUT_BUFFER2);
  50.   XA_Intern(CUT_BUFFER3);
  51.   XA_Intern(CUT_BUFFER4);
  52.   XA_Intern(CUT_BUFFER5);
  53.   XA_Intern(CUT_BUFFER6);
  54.   XA_Intern(CUT_BUFFER7);
  55.   XA_Intern(DRAWABLE);
  56.   XA_Intern(FONT);
  57.   XA_Intern(INTEGER);
  58.   XA_Intern(PIXMAP);
  59.   XA_Intern(POINT);
  60.   XA_Intern(RECTANGLE);
  61.   XA_Intern(RESOURCE_MANAGER);
  62.   XA_Intern(RGB_COLOR_MAP);
  63.   XA_Intern(RGB_BEST_MAP);
  64.   XA_Intern(RGB_BLUE_MAP);
  65.   XA_Intern(RGB_DEFAULT_MAP);
  66.   XA_Intern(RGB_GRAY_MAP);
  67.   XA_Intern(RGB_GREEN_MAP);
  68.   XA_Intern(RGB_RED_MAP);
  69.   XA_Intern(STRING);
  70.   XA_Intern(VISUALID);
  71.   XA_Intern(WINDOW);
  72.   XA_Intern(WM_COMMAND);
  73.   XA_Intern(WM_HINTS);
  74.   XA_Intern(WM_CLIENT_MACHINE);
  75.   XA_Intern(WM_ICON_NAME);
  76.   XA_Intern(WM_ICON_SIZE);
  77.   XA_Intern(WM_NAME);
  78.   XA_Intern(WM_NORMAL_HINTS);
  79.   XA_Intern(WM_SIZE_HINTS);
  80.   XA_Intern(WM_ZOOM_HINTS);
  81.   XA_Intern(MIN_SPACE);
  82.   XA_Intern(NORM_SPACE);
  83.   XA_Intern(MAX_SPACE);
  84.   XA_Intern(END_SPACE);
  85.   XA_Intern(SUPERSCRIPT_X);
  86.   XA_Intern(SUPERSCRIPT_Y);
  87.   XA_Intern(SUBSCRIPT_X);
  88.   XA_Intern(SUBSCRIPT_Y);
  89.   XA_Intern(UNDERLINE_POSITION);
  90.   XA_Intern(UNDERLINE_THICKNESS);
  91.   XA_Intern(STRIKEOUT_ASCENT);
  92.   XA_Intern(STRIKEOUT_DESCENT);
  93.   XA_Intern(ITALIC_ANGLE);
  94.   XA_Intern(X_HEIGHT);
  95.   XA_Intern(QUAD_WIDTH);
  96.   XA_Intern(WEIGHT);
  97.   XA_Intern(POINT_SIZE);
  98.   XA_Intern(RESOLUTION);
  99.   XA_Intern(COPYRIGHT);
  100.   XA_Intern(NOTICE);
  101.   XA_Intern(FONT_NAME);
  102.   XA_Intern(FAMILY_NAME);
  103.   XA_Intern(FULL_NAME);
  104.   XA_Intern(CAP_HEIGHT);
  105.   XA_Intern(WM_CLASS);
  106.   XA_Intern(WM_TRANSIENT_FOR);
  107.  
  108. #undef XA_Intern
  109.  
  110.   return 0;
  111. }
  112.  
  113. Atom
  114. XInternAtom(
  115.     Display*        display,
  116.     _Xconst char*    atom_name,
  117.     Bool        only_if_exists)
  118. {
  119.   int i;
  120.   XrmQuark atom_rep;
  121.  
  122.   if (display->atoms == NULL)
  123.     PredefineAtoms (display);
  124.  
  125.   atom_rep = XrmStringToQuark (atom_name);
  126.   for (i = display->atoms->next; --i >= 0; ) {
  127.     if (atom_rep == display->atoms->rep[i])
  128.       return (Atom) i;
  129.   }
  130.   if (only_if_exists == False)
  131.     return (Atom) 0;
  132.  
  133.   if (display->atoms->next >= display->atoms->size) {
  134.     display->atoms->size += display->atoms->size / 2 + 1;
  135.     display->atoms = (DisplayAtoms *)
  136.       Xrealloc (display->atoms, sizeof (DisplayAtoms) +
  137.         sizeof (XrmQuark) * display->atoms->size);
  138.   }
  139.   i = display->atoms->next;
  140.   display->atoms->rep[i] = atom_rep;
  141.   display->atoms->next++;
  142.   return (Atom) i;
  143. }
  144.  
  145. char *
  146. XGetAtomName
  147. (Display*    display,
  148.  Atom        atom)
  149. {
  150.   char *atom_name, *name;
  151.  
  152.   if (display->atoms == NULL)
  153.     PredefineAtoms (display);
  154.  
  155.   if (atom == 0 || atom >= display->atoms->next)
  156.     return NULL;
  157.  
  158.   atom_name = XrmQuarkToString (display->atoms->rep[(int) atom]);
  159.   if (! atom_name)
  160.     return NULL;
  161.  
  162.   name = (char *) Xmalloc (strlen (atom_name) + 1);
  163.   if (name)
  164.     strcpy (name, atom_name);
  165.   return name;
  166. }
  167.