home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_Atom.c < prev    next >
C/C++ Source or Header  |  1999-11-02  |  3KB  |  99 lines

  1.  
  2. #include "Xlib_private.h"
  3.  
  4. char* atmNames[XA_LAST_PREDEFINED+1] = { NULL,
  5.     "PRIMARY",        "SECONDARY",        "ARC",            "ATOM",
  6.     "BITMAP",        "CARDINAL",        "COLORMAP",        "CURSOR",
  7.     "CUT_BUFFER0",        "CUT_BUFFER1",        "CUT_BUFFER2",        "CUT_BUFFER3",
  8.     "CUT_BUFFER4",        "CUT_BUFFER5",        "CUT_BUFFER6",        "CUT_BUFFER7",
  9.     "DRAWABLE",        "FONT",            "INTEGER",        "PIXMAP",
  10.     "POINT",        "RECTANGLE",        "RESOURCE_MANAGER",    "RGB_COLOR_MAP",
  11.     "RGB_BEST_MAP",        "RGB_BLUE_MAP",        "RGB_DEFAULT_MAP",    "RGB_GRAY_MAP",
  12.     "RGB_GREEN_MAP",    "RGB_RED_MAP",        "STRING",        "VISUALID",
  13.     "WINDOW",        "WM_COMMAND",        "WM_HINTS",        "WM_CLIENT_MACHINE",
  14.     "ICON_NAME",        "ICON_SIZE",        "WM_NAME",        "WM_NORMAL_HINTS",
  15.     "WM_SIZE_HINTS",    "WM_ZOOM_HINTS",    "MIN_SPACE",        "NORM_SPACE",
  16.     "MAX_SPACE",        "END_SPACE",        "SUPERSCRIPT_X",    "SUPERSCRIPT_Y",
  17.     "SUBSCRIPT_X",        "SUBSCRIPT_Y",        "UNDERLINE_POSITION",    "UNDERLINE_THICKNESS",
  18.     "STRIKEOUT_ASCENT",    "STRIKEOUT_DESCENT",    "ITALIC_ANGLE",        "X_HEIGHT",
  19.     "QUAD_WIDTH",        "WEIGHT",        "POINT_SIZE",        "RESOLUTION",
  20.     "COPYRIGHT",        "NOTICE",        "FONT_NAME",        "FAMILY_NAME",
  21.     "FULL_NAME",        "CAP_HEIGHT",        "WM_CLASS",        "WM_TRANSIENT_FOR"
  22. };
  23.  
  24. char** atomNames = (char **)&atmNames;
  25.  
  26. Atom (*Xlib_XInternAtom)(char*, Bool) = NULL;
  27. char *(*Xlib_GetAtomName)(Atom) = NULL;
  28.  
  29. char *XGetAtomName(Display *dpy, Atom atom)
  30. {
  31.     DBUG_ENTER("XGetAtomName")
  32.     char *name = NULL, *entry = NULL;
  33.     if (Xlib_GetAtomName)
  34.         entry = Xlib_GetAtomName(atom);
  35.     else 
  36.     if (atom > 0 && atom <= XA_LAST_PREDEFINED)
  37.         entry = atomNames[atom];
  38.     if (entry) 
  39.         name = strdup(entry);
  40.     SyncHandle();
  41.     DBUG_RETURN(name);
  42. }
  43.  
  44. Status XGetAtomNames(Display* dpy, Atom* atoms, int count, char** names_return)
  45. {
  46.     DBUG_ENTER("XGetAtomNames")
  47.     while (atoms && count && names_return) {
  48.         *names_return = XGetAtomName(dpy,*atoms);
  49.         count--; atoms++; names_return++;
  50.     }
  51.     SyncHandle();
  52.     DBUG_RETURN(True);
  53. }
  54.  
  55. Atom XInternAtom(Display* dpy, _Xconst char* atom_name, Bool only_if_exists)
  56. {
  57.     DBUG_ENTER("XInternAtom")
  58.     Atom res = 0;
  59.     if (atom_name) {
  60.         if (Xlib_XInternAtom)
  61.             res = Xlib_XInternAtom((char*)atom_name, only_if_exists);
  62.         else {
  63.             int i;
  64.             for (i = 1; i <= XA_LAST_PREDEFINED; i++)
  65.             if (!strcmp((char*)atom_name, atomNames[i])) {
  66.                 res = i;
  67.                 break;
  68.             }
  69.         }
  70.     }
  71.     SyncHandle();
  72.     DBUG_RETURN(res);
  73. }
  74.  
  75. Status XInternAtoms(Display* dpy, char** names, int count, Bool onlyIfExists, Atom* atoms_return)
  76. {
  77.     DBUG_ENTER("XInternAtoms")
  78.     while (names && count) {
  79.         Atom atom;
  80.         atom = XInternAtom(dpy, *names, onlyIfExists);
  81.         if (atoms_return) *(atoms_return++) = atom;
  82.         count--; names++;
  83.     }
  84.     SyncHandle();
  85.     DBUG_RETURN(True);
  86. }
  87.  
  88. void Xlib_InitAtoms(Display* dpy)
  89. {
  90.     DBUG_ENTER("Xlib_InitAtoms")
  91.     Atom i;
  92.     for (i = 1; i <= XA_LAST_PREDEFINED; i++) {
  93.         if (XInternAtom(dpy, atmNames[i], FALSE) == i)
  94.             continue;
  95.         fprintf(stderr,"Error initialising atoms!");
  96.         abort();
  97.     }
  98.     DBUG_VOID_RETURN;
  99. }