home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / historic / v92.tgz / v92.tar / v92 / src / runtime / rpmrsc.ri < prev    next >
Text File  |  1996-03-22  |  6KB  |  256 lines

  1. /*
  2.  * File: rpmrsc.r
  3.  *  OS/2 Presentation Manager Window resource module
  4.  *
  5.  * Resources are allocated through a layer of internal management
  6.  * routines in order to handle aliasing and resource sharing.
  7.  */
  8. LONG NumWindows = 0;
  9.  
  10. /*
  11.  * allocate a context.    Can't be called until w has a display and window.
  12.  */
  13. wcp alc_context(w)
  14. wbp w;
  15.    {
  16.    int i;
  17.    wcp wc;
  18.    GRFX_ALLOC(wc, _wcontext);
  19.    /*
  20.     * need to make the dependant list
  21.     */
  22.    if (!(wc->depWindows = calloc(INITDEPS, sizeof(wsp)))) {
  23.       free(wc);
  24.       ReturnErrNum(305, NULL);
  25.       }
  26.    /*
  27.     * size of table
  28.     */
  29.    wc->maxDeps = INITDEPS;
  30.    /*
  31.     * fill style is initially solid
  32.     */
  33.    wc->fillstyle = FS_SOLID;
  34.    /*
  35.     * gamma value is a configuration default
  36.     */
  37.    wc->gamma = GammaCorrection;
  38.  
  39.    GRFX_LINK(wc, wcntxts);
  40.    return wc;
  41.    }
  42.  
  43. /*
  44.  * allocate a context, cloning attributes from an existing context
  45.  */
  46. wcp clone_context(w)
  47. wbp w;
  48.    {
  49.    wcp wc, wc2 = w->context;
  50.    wsp ws = w->window;
  51.    Protect(wc = alc_context(w), return NULL);
  52.    /*
  53.     * copy over some stuff
  54.     */
  55.    wc->charBundle = wc2->charBundle;
  56.    wc->areaBundle = wc2->areaBundle;
  57.    wc->lineBundle = wc2->lineBundle;
  58.    wc->fntLeading = wc2->fntLeading;
  59.    wc->font = wc2->font;
  60.    wc->dx = wc2->dx; wc->dy = wc2->dy;
  61.    wc->drawop = wc2->drawop;
  62.    wc->gamma = wc2->gamma;
  63.    wc->bits = wc2->bits;
  64.    /*
  65.     * bump up reference counts on colors
  66.     */
  67.    AddColorDependant(wc->charBundle.lColor);
  68.    AddColorDependant(wc->charBundle.lBackColor);
  69.    /*
  70.     * have to bump up reference count on pattern and font, if not default
  71.     */
  72.    wc->currPattern = wc2->currPattern;
  73.    AddPatternDependant(wc->currPattern);
  74.    /*
  75.     * font ..
  76.     */
  77.    AddFontDependant(wc->charBundle.usSet);
  78.    /* copy the clipping region */
  79.    wc->clipx = wc2->clipx;
  80.    wc->clipy = wc2->clipy;
  81.    wc->clipw = wc2->clipw;
  82.    wc->cliph = wc2->cliph;
  83.    /*
  84.     * make the dependencies
  85.     */
  86.    if (!AddWindowDep(ws, wc) || !AddContextDep(ws, wc))
  87.       return NULL;
  88.    return wc;
  89.    }
  90.  
  91. /*
  92.  * allocate a window state structure
  93.  */
  94. wsp alc_winstate()
  95.    {
  96.    int i;
  97.    wsp ws;
  98.  
  99.    GRFX_ALLOC(ws, _wstate);
  100.    ws->bits = 1024;                /* echo ON; others OFF */
  101.    ws->filep = nulldesc;
  102.    ws->listp = nulldesc;
  103.    /*
  104.     * make the dependant list
  105.     */
  106.    if (!(ws->depContexts = calloc(INITDEPS, sizeof(wcp)))) {
  107.       free(ws);
  108.       ReturnErrNum(305, NULL);
  109.       }
  110.    ws->maxDeps = INITDEPS;
  111.    /*
  112.     * we now have one more window
  113.     */
  114.    NumWindows++;
  115.    GRFX_LINK(ws, wstates);
  116.    return ws;
  117.    }
  118.  
  119. /*
  120.  * free a window state
  121.  */
  122. free_window(ws)
  123. wsp ws;
  124.    {
  125.    ws->refcount--;
  126.    if(ws->refcount == 0) {
  127.       HRGN hscrap;
  128.       wcp wc;
  129.       int i, j;
  130.       BOOL bret;
  131.       HBITMAP hbm;
  132.  
  133.       /*
  134.        * remove this window from the context dependencies
  135.        */
  136.       for (i = 0; i < ws->maxDeps && ws->numDeps > 0; i++)
  137.      if (wc = ws->depContexts[i]) { /* found a valid dep */
  138.         for (j = 0; j < wc->maxDeps; j++)
  139.            if (wc->depWindows[j] == ws) { /* found the mapping */
  140.           wc->depWindows[j] = NULL;
  141.           wc->numDeps--;
  142.           break;
  143.           }
  144.         ws->numDeps--;
  145.         }
  146.  
  147.       /*
  148.        * free the dependant list
  149.        */
  150.       free(ws->depContexts);
  151.       ws->depContexts = NULL;
  152.       /*
  153.        * remove the clip regions - if present
  154.        */
  155.       GpiSetClipRegion(ws->hpsBitmap, NULLHANDLE, &hscrap);
  156.       if (ws->hpsWin)
  157.      GpiSetClipRegion(ws->hpsWin, NULLHANDLE, &hscrap);
  158.       /*
  159.        * kill the window - if this was done previously, there
  160.        * is no harm in calling this again
  161.        */
  162.       DestroyWindow(ws);
  163.       /*
  164.        * now time to kill the bitmap stuff
  165.        */
  166.       GpiDestroyPS(ws->hpsBitmap);
  167.       GpiDeleteBitmap(ws->hBitmap);
  168.       DevCloseDC(ws->hdcBitmap);
  169.       ws->hpsBitmap = ws->hdcBitmap = ws->hBitmap = NULLHANDLE;
  170.       /*
  171.        * close the mutex semaphore
  172.        */
  173.       if (ws->mutex) {
  174.     DosCloseMutexSem(ws->mutex);
  175.     ws->mutex = NULLHANDLE;
  176.     } /* End of if - mutex semaphore open */
  177.       /* get rid of the window pointer */
  178.       if (ws->hPointer) {
  179.     /* this has to be destroyed by the creating thread */
  180.     WinDestroyPointer(ws->hPointer);
  181.     ws->hPointer = NULLHANDLE;
  182.     } /* End of if - pointer exists */
  183.  
  184.       /*
  185.        * release the window background color
  186.        */
  187.       ReleaseColor(ws->winbg);
  188.       /*
  189.        * destroy the initial bitmap
  190.        */
  191.       if (ws->hInitialBitmap)
  192.      GpiDeleteBitmap(ws->hInitialBitmap);
  193.       /*
  194.        * free the strings for titles, etc.
  195.        */
  196.       free(ws->windowlabel);
  197.       free(ws->iconlabel);
  198.       free(ws->iconimage);
  199.       /*
  200.        * we now have one less window
  201.        */
  202.       NumWindows--;
  203.       GRFX_UNLINK(ws, wstates);
  204.       }
  205.    return 0;
  206.    }
  207.  
  208. /*
  209.  * free a window context
  210.  */
  211. novalue free_context(wc)
  212. wcp wc;
  213.    {
  214.    wc->refcount--;
  215.    if(wc->refcount == 0) {
  216.       wsp ws;
  217.       int i, j;
  218.       LONG tmp;
  219.  
  220.       /*
  221.        * free the pattern and font, and release the foreground and background
  222.        */
  223.       ReleasePattern(wc->currPattern);
  224.       ReleaseFont(wc->charBundle.usSet);
  225.  
  226.       tmp = (ISXORREVERSEW(wc)) ? wc->charBundle.lColor ^ wc->charBundle.lBackColor :
  227.                   wc->charBundle.lColor;
  228.       ReleaseColor(tmp);
  229.       ReleaseColor(wc->charBundle.lBackColor);
  230.       /*
  231.        * remove this context from the window's dependencies
  232.        */
  233.       for (i = 0; i < wc->maxDeps && wc->numDeps > 0; i++)
  234.     if (ws = wc->depWindows[i]) { /* a valid window pointer */
  235.       if (ws->charContext == wc) ws->charContext = NULL;
  236.       if (ws->areaContext == wc) ws->areaContext = NULL;
  237.       if (ws->lineContext == wc) ws->lineContext = NULL;
  238.       if (ws->imageContext == wc) ws->imageContext = NULL;
  239.       if (ws->clipContext == wc) ws->clipContext = NULL;
  240.       for (j = 0; j < ws->maxDeps; j++)
  241.         if (ws->depContexts[j] == wc) { /* found the mapping */
  242.           ws->depContexts[j] = NULL;
  243.           ws->numDeps--;
  244.           break;
  245.           }
  246.       wc->numDeps--;
  247.       }
  248.       /*
  249.        * free the dependant list
  250.        */
  251.       free(wc->depWindows);
  252.       wc->depWindows = NULL;
  253.       GRFX_UNLINK(wc, wcntxts);
  254.       }
  255.    }
  256.