home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / evbl0627.zip / everblue_20010627.zip / x11 / Xlib_pmatms.c < prev    next >
C/C++ Source or Header  |  2000-05-02  |  6KB  |  236 lines

  1.  
  2. /*
  3.  * This allocates PM atoms for font cacheing & stipples
  4.  */
  5.  
  6. #include "Xlib_private.h"
  7.  
  8. #define PMATOM_LIMIT 1024
  9.  
  10. LONG Xlib_AllocFontAtom(Xlib_Pixmap *client, Xlib_Font *font)
  11. {
  12.     DBUG_ENTER("Xlib_AllocFontAtom")
  13.     Xlib_Pixmap **pixatom;
  14.     PMAtoms *pmatom;
  15.     LONG atom = 0;
  16.     if (!client || !font) DBUG_RETURN(0);
  17.     if (!(pmatom = client->pmatoms)) 
  18.     if (!(pmatom = client->pmatoms = calloc(PMATOM_LIMIT, sizeof(PMAtoms)))) DBUG_RETURN(0);
  19.     if (!(pixatom = font->pixatoms)) 
  20.     if (!(pixatom = font->pixatoms = calloc(PMATOM_LIMIT, sizeof(void *)))) DBUG_RETURN(0);
  21.  
  22.     while (atom < PMATOM_LIMIT-1) {
  23.         pmatom++; pixatom++; atom++;
  24.         if (pmatom->type != PMATM_NULL || *pixatom) {
  25.             if (pmatom->type == PMATM_FONT && *pixatom == client &&
  26.                 pmatom->data.font == font) DBUG_RETURN(atom);
  27.             continue;
  28.         }
  29.         *pixatom = client;
  30.         pmatom->type = PMATM_FONT;
  31.         pmatom->data.font = font;
  32.         GpiCreateLogFont(client->hps, NULL, atom, &font->fattrs);
  33.         DBUG_RETURN(atom)
  34.     }
  35.     DBUG_RETURN(0);
  36. }
  37.  
  38. LONG Xlib_AllocPixmapAtom(Xlib_Pixmap *client, Xlib_Pixmap *pixmap)
  39. {
  40.     DBUG_ENTER("Xlib_AllocPixmapAtom")
  41.     Xlib_Pixmap **pixatom;
  42.     PMAtoms *pmatom;
  43.     LONG atom = 0;
  44.     if (!client || !pixmap) DBUG_RETURN(0);
  45.  
  46. #ifdef DEBUG_VERBOSE
  47.     fprintf(stderr,"Xlib_AllocPixmapAtom(%p,%p): pmatoms=%p, pixatoms=%p\n",
  48.         client, pixmap, client->pmatoms, pixmap->pixatoms );
  49. #endif
  50.  
  51.  
  52.     if (!(pmatom = client->pmatoms))
  53.     if (!(pmatom = client->pmatoms = calloc(PMATOM_LIMIT, sizeof(PMAtoms)))) DBUG_RETURN(0);
  54.     if (!(pixatom = pixmap->pixatoms)) {
  55.     if (!(pixatom = pixmap->pixatoms = calloc(PMATOM_LIMIT, sizeof(void *)))) DBUG_RETURN(0);
  56.  
  57. #ifdef DEBUG_VERBOSE
  58.     fprintf(stderr,"Xlib_AllocPixmapAtom(%p,%p): pmatom=%p, pixatom=%p\n",
  59.         client, pixmap, pmatom, pixatom );
  60. #endif
  61. }
  62.     while (atom < PMATOM_LIMIT-1) {
  63. #ifdef DEBUG_VERBOSE
  64.         char dbug_st[128];
  65. #endif
  66.         pmatom++; pixatom++; atom++;
  67. #ifdef DEBUG_VERBOSE
  68.         sprintf(dbug_st,"client=%p, pixmap=%p, atom=%ld, pmatom=%p, pixatom=%p",client,pixmap,atom,pmatom,pixatom);
  69.         DBUG_POINT(dbug_st);
  70. #endif
  71.         if (pmatom->type != PMATM_NULL || *pixatom) {
  72.             if (pmatom->type == PMATM_BITMAP && *pixatom == client &&
  73.                 pmatom->data.pixmap == pixmap) DBUG_RETURN(atom);
  74.             continue;
  75.         }
  76.         *pixatom = client;
  77.         pmatom->type = PMATM_BITMAP;
  78.         pmatom->data.pixmap = pixmap;
  79.         GpiSetBitmapId(client->hps, pixmap->hbm, atom);
  80.         DBUG_RETURN(atom)
  81.     }
  82.     DBUG_RETURN(0);
  83. }
  84.  
  85. static void Xlib_FreeSpecificAtom(HPS hps, PMAtoms *pmatom, LONG atom)
  86. {
  87.     DBUG_ENTER("Xlib_FreeSpecificAtom")
  88.     switch (pmatom->type) {
  89.     case PMATM_NULL:
  90.         /* Nothing to do here */
  91.         break;
  92.     case PMATM_FONT:
  93.         if (!pmatom->data.font || !pmatom->data.font->pixatoms) break;
  94.         pmatom->data.font->pixatoms[atom] = NULL;
  95.         if (GpiQueryCharSet(hps) == atom)
  96.             GpiSetCharSet(hps, LCID_DEFAULT);
  97.         GpiDeleteSetId(hps, atom);
  98.         break;
  99.     case PMATM_BITMAP:
  100.         if (!pmatom->data.pixmap || !pmatom->data.pixmap->pixatoms) break;
  101.         pmatom->data.pixmap->pixatoms[atom] = NULL;
  102.         if (GpiQueryPatternSet(hps) == atom)
  103.             GpiSetPatternSet(hps, LCID_DEFAULT);
  104.         GpiDeleteSetId(hps, atom);
  105.         break;
  106.     }
  107.     pmatom->type = PMATM_NULL;
  108.     DBUG_VOID_RETURN;    
  109. }
  110.  
  111. void Xlib_FreePMAtom(Xlib_Pixmap *client, LONG atom)
  112. {
  113.     DBUG_ENTER("Xlib_FreePMAtom")
  114.     if (!client || atom < 1 || atom > PMATOM_LIMIT-1 || !client->pmatoms) DBUG_VOID_RETURN;
  115.     Xlib_FreeSpecificAtom(client->hps, &client->pmatoms[atom], atom);
  116.     DBUG_VOID_RETURN;
  117. }
  118.  
  119. void Xlib_FreeAllAtoms(Xlib_Pixmap *client)
  120. {
  121.     DBUG_ENTER("Xlib_FreeAllAtoms")
  122.     PMAtoms *pmatom;
  123.     LONG atom = 0;
  124.     if (!client || !(pmatom=client->pmatoms)) DBUG_VOID_RETURN;
  125. #ifdef DBUG_VERBOSE
  126.     fprintf(stderr,"Xlib_FreeAllAtoms: client=%p\n",client);
  127. #endif
  128.     while (atom < PMATOM_LIMIT-1) {
  129.         pmatom++; atom++;
  130.         Xlib_FreeSpecificAtom(client->hps, pmatom, atom);
  131.     }
  132.     free(client->pmatoms); client->pmatoms = NULL;
  133.     DBUG_VOID_RETURN;
  134. }
  135.  
  136. void Xlib_FreeFontAtom(Xlib_Font *font)
  137. {
  138.     DBUG_ENTER("Xlib_FreeFontAtom")
  139.     Xlib_Pixmap **pixatom;
  140.     LONG atom = 0;
  141.     if (!font || !(pixatom = font->pixatoms)) DBUG_VOID_RETURN;
  142. #ifdef DBUG_VERBOSE
  143.     fprintf(stderr,"Xlib_FreeFontAtom: font=%p\n",font);
  144. #endif
  145.     while (atom < PMATOM_LIMIT-1) {
  146.         Xlib_Pixmap *client = *(++pixatom); atom++;
  147.         if (!client || !client->pmatoms) continue;
  148.         Xlib_FreeSpecificAtom(client->hps, &client->pmatoms[atom], atom);
  149.     }
  150.     free(font->pixatoms); font->pixatoms = NULL;
  151.     DBUG_VOID_RETURN;
  152. }
  153.  
  154. void Xlib_FreePixmapAtom(Xlib_Pixmap *pixmap)
  155. {
  156.     DBUG_ENTER("Xlib_FreePixmapAtom")
  157.     Xlib_Pixmap **pixatom;
  158.     LONG atom = 0;
  159.     if (!pixmap || !(pixatom = pixmap->pixatoms)) DBUG_VOID_RETURN;
  160. #ifdef DBUG_VERBOSE
  161.     fprintf(stderr,"Xlib_FreePixmapAtom: pixmap=%p\n",pixmap);
  162. #endif
  163.     while (atom < PMATOM_LIMIT-1) {
  164.         Xlib_Pixmap *client = *(++pixatom); atom++;
  165.         if (!client || !client->pmatoms) continue;
  166.         Xlib_FreeSpecificAtom(client->hps, &client->pmatoms[atom], atom);
  167.     }
  168.     free(pixmap->pixatoms); pixmap->pixatoms = NULL;
  169.     DBUG_VOID_RETURN;
  170. }
  171.  
  172. static XID **res_list = NULL;
  173. static int res_listsize = 0, res_listused = 0;
  174.  
  175. /*
  176.  * The following is primitive, but what the heck!
  177.  */
  178.  
  179. void Xlib_MonitorResource(XID *resource)
  180. {
  181.     DBUG_ENTER("Xlib_MonitorResource")
  182.     XID **res;
  183.     if (!(res = res_list))
  184.     if (!(res = res_list = calloc(res_listsize = 512, sizeof(XID *))))
  185.         DBUG_VOID_RETURN;
  186.     if (res_listused==res_listsize) {
  187.         res = calloc(res_listsize * 2, sizeof(XID *));
  188.         memcpy(res, res_list, res_listsize * sizeof(XID *));
  189.         res_listsize *= 2;
  190.         free(res_list); res_list = res;
  191.     }
  192.     while (*res) {
  193.         if (*res == resource) DBUG_VOID_RETURN;
  194.         res++;
  195.     }
  196.     *res = resource;
  197.     res_listused++;
  198.     DBUG_VOID_RETURN;
  199. }
  200.  
  201. void Xlib_UnmonitorResource(XID *resource)
  202. {
  203.     DBUG_ENTER("Xlib_UnmonitorResource")
  204.     XID **res = res_list;
  205.     int res_count = 0;
  206.     if (!res || !res_listused) DBUG_VOID_RETURN;
  207.     while (res_count < res_listused) {
  208.         if (*res == resource) {
  209.             *res = NULL;
  210.             res_listused--;
  211.             DBUG_VOID_RETURN;
  212.         }
  213.         if (*res) res_count++;
  214.         res++;
  215.     }
  216.     DBUG_VOID_RETURN;
  217. }
  218.  
  219. void Xlib_InvalidateResource(XID resource)
  220. {
  221.     DBUG_ENTER("Xlib_InvalidateResource")
  222.     XID **res = res_list;
  223.     int res_count = 0;
  224.     if (!res || !res_listused || !resource) DBUG_VOID_RETURN;
  225.     while (res_count < res_listused) {
  226.         if (*res && **res == resource) {
  227.             **res = (XID)0;
  228.             *res = NULL;
  229.             res_listused--;
  230.         }
  231.         if (*res) res_count++;
  232.         res++;
  233.     }
  234.     DBUG_VOID_RETURN;
  235. }
  236.