home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / Samples / CSAPE32.ARJ / SOURCE / OWLSCR / DISPCURR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-22  |  4.5 KB  |  161 lines

  1. /*
  2.     dispcurr.c
  3.  
  4.     % Functions for borrowing and restoring the current display manager.
  5.  
  6.     3/21/89  by Ted.
  7.  
  8.     OWL 1.2
  9.     Copyright (c) 1988, 1989 by Oakland Group, Inc.
  10.     ALL RIGHTS RESERVED.
  11.  
  12.     Revision History:
  13.     -----------------
  14.     11/07/89 ted    Zeroed out the whole data blocks.
  15.     11/08/89 ted    Made use of block chain so pchdata can also be swapped.
  16.  
  17.     11/27/89 ted    Rearranged dmgr, disp, & dig structs for data block chaining.
  18.      1/03/90 ted    Split disp_RestoreCurrent() func out from disp_SetCurrent().
  19.      3/28/90 jmd    ansi-fied
  20.      6/22/90 ted    added "void" to no-parameter function per ansii.
  21. */
  22.  
  23. #include "oakhead.h"
  24. #include "disppriv.h"
  25.  
  26. /* Definitions for use in tracing the chain. The chain is constructed so that */
  27. /*  each block ends with the pointer and size of the next block */
  28.  
  29. typedef struct _chain {
  30.     VOID *nextblock;
  31.     SIZE_T nextsize;
  32. } chain_struct;
  33.  
  34. #define nextchain(b,bs)                                \
  35.     ((chain_struct *)(((byte *)b) + blocksize - sizeof(chain_struct)))
  36.  
  37. /* -------------------------------------------------------------------------- */
  38.  
  39. VOID *disp_GetCurrent(void)
  40. /*
  41.     'Borrow' the current display manager so that it can be restored later after
  42.     a different display manager has been put into effect.
  43. */
  44. {
  45.     VOID *dispp, *blockp;
  46.     byte *savep;
  47.     SIZE_T blocksize, savesize;
  48.     chain_struct *next;
  49.  
  50.     /* If the current dmgr is not valid, don't allow it to be copied */
  51.     owl_Assert(disp_Ok(), OE_GC_DISP);
  52.  
  53.     /* Trace the chain to find sum of block sizes */
  54.     blockp = (VOID *) curr_dmgr;
  55.     blocksize = sizeof(dmgr_struct);
  56.     savesize = 0;
  57.     while (blocksize != 0) {
  58.         savesize += blocksize;
  59.         next = nextchain(blockp, blocksize);
  60.         blockp    = next->nextblock;
  61.         blocksize = next->nextsize;
  62.     }
  63.  
  64.     /* Allocate a save area for a copy of the current dmgr */
  65.     dispp = omalloc(OA_SAVDISP, savesize);
  66.     if (dispp == NULL) {
  67.         return(NULL);
  68.     }
  69.  
  70.     /* Trace the chain making copies of all the blocks and then clearing them */
  71.     blockp = (VOID *) curr_dmgr;
  72.     blocksize = sizeof(dmgr_struct);
  73.     savep = (byte *) dispp;
  74.     while (blocksize != 0) {
  75.         memmove((VOID *) savep, blockp, blocksize);
  76.  
  77.         /* Use savep here because blockp is going to get zeroed out */
  78.         next = nextchain(savep, blocksize);
  79.         savep += blocksize;
  80.  
  81.         /* Clear out the previous block to make it invalid because it's been borrowed */
  82.         memset(blockp, 0, blocksize);
  83.  
  84.         blockp    = next->nextblock;
  85.         blocksize = next->nextsize;
  86.     }
  87.     /* curr_dmgr->id == 0 is the element that we actually look at. */
  88.  
  89.     return(dispp);
  90. }
  91. /* -------------------------------------------------------------------------- */
  92.  
  93. boolean disp_SetCurrent(VOID *dispp)
  94. /*
  95.     Put back into effect a display manager which has previously been 'borrowed'
  96.     using disp_GetCurrent.
  97.     NOTE: This function frees the 'borrowed' display manager. It must be
  98.     borrowed again before it can be restored again.
  99. */
  100. {
  101.     if (disp_RestoreCurrent(dispp)) {
  102.         disp_InitMode();
  103.         disp_Repaint();
  104.  
  105.         if (hard_IsMouseOn()) {
  106.             hard_InitMouse();
  107.         }
  108.         return(TRUE);
  109.     }
  110.     else return(FALSE);
  111. }
  112. /* -------------------------------------------------------------------------- */
  113.  
  114. boolean disp_RestoreCurrent(VOID *dispp)
  115. /*
  116.     Put back into effect a display manager which has previously been 'borrowed'
  117.     using disp_GetCurrent, assuming display mode and screen appearance have not
  118.     been altered.
  119.     NOTE: This function frees the 'borrowed' display manager. It must be
  120.     borrowed again before it can be restored again.
  121. */
  122. {
  123.     VOID *blockp;
  124.     byte *savep;
  125.     SIZE_T blocksize, savesize;
  126.     chain_struct *next;
  127.  
  128.     /* If the dmgr saved in dispp is not valid, don't install it */
  129.     owl_Assert(dispp != NULL, OE_SC_DISP);
  130.  
  131.     /* Trace the chain restoring from all the blocks */
  132.     blockp = (VOID *) curr_dmgr;
  133.     blocksize = sizeof(dmgr_struct);
  134.     savep = (byte *) dispp;
  135.     savesize = 0;
  136.     while (blocksize != 0) {
  137.         memmove(blockp, (VOID *) savep, blocksize);
  138.         savep += blocksize;
  139.         savesize += blocksize;
  140.         
  141.         next = nextchain(blockp, blocksize);
  142.         blocksize = next->nextsize;
  143.         blockp    = next->nextblock;
  144.     }
  145.  
  146.     /* Make the saved dmgr invalid because it has been un-borrowed */
  147.     /* (In case someone looks at it even though it's about to be freed) */
  148.     memset(dispp, 0, savesize);
  149.  
  150.     /* Free the invalidated save area. */
  151.     /* (It has to be borrowed again before it can be restored again) */
  152.     ofree(OA_SAVDISP, dispp);
  153.  
  154.     /* Check the new dmgr now that it is installed */
  155.     owl_Assert(disp_Ok(), OE_SC_DISP);
  156.  
  157.     return(TRUE);
  158. }
  159. /* -------------------------------------------------------------------------- */
  160.  
  161.