home *** CD-ROM | disk | FTP | other *** search
- /*
- dispcurr.c
-
- % Functions for borrowing and restoring the current display manager.
-
- 3/21/89 by Ted.
-
- OWL 1.2
- Copyright (c) 1988, 1989 by Oakland Group, Inc.
- ALL RIGHTS RESERVED.
-
- Revision History:
- -----------------
- 11/07/89 ted Zeroed out the whole data blocks.
- 11/08/89 ted Made use of block chain so pchdata can also be swapped.
-
- 11/27/89 ted Rearranged dmgr, disp, & dig structs for data block chaining.
- 1/03/90 ted Split disp_RestoreCurrent() func out from disp_SetCurrent().
- 3/28/90 jmd ansi-fied
- 6/22/90 ted added "void" to no-parameter function per ansii.
- */
-
- #include "oakhead.h"
- #include "disppriv.h"
-
- /* Definitions for use in tracing the chain. The chain is constructed so that */
- /* each block ends with the pointer and size of the next block */
-
- typedef struct _chain {
- VOID *nextblock;
- SIZE_T nextsize;
- } chain_struct;
-
- #define nextchain(b,bs) \
- ((chain_struct *)(((byte *)b) + blocksize - sizeof(chain_struct)))
-
- /* -------------------------------------------------------------------------- */
-
- VOID *disp_GetCurrent(void)
- /*
- 'Borrow' the current display manager so that it can be restored later after
- a different display manager has been put into effect.
- */
- {
- VOID *dispp, *blockp;
- byte *savep;
- SIZE_T blocksize, savesize;
- chain_struct *next;
-
- /* If the current dmgr is not valid, don't allow it to be copied */
- owl_Assert(disp_Ok(), OE_GC_DISP);
-
- /* Trace the chain to find sum of block sizes */
- blockp = (VOID *) curr_dmgr;
- blocksize = sizeof(dmgr_struct);
- savesize = 0;
- while (blocksize != 0) {
- savesize += blocksize;
- next = nextchain(blockp, blocksize);
- blockp = next->nextblock;
- blocksize = next->nextsize;
- }
-
- /* Allocate a save area for a copy of the current dmgr */
- dispp = omalloc(OA_SAVDISP, savesize);
- if (dispp == NULL) {
- return(NULL);
- }
-
- /* Trace the chain making copies of all the blocks and then clearing them */
- blockp = (VOID *) curr_dmgr;
- blocksize = sizeof(dmgr_struct);
- savep = (byte *) dispp;
- while (blocksize != 0) {
- memmove((VOID *) savep, blockp, blocksize);
-
- /* Use savep here because blockp is going to get zeroed out */
- next = nextchain(savep, blocksize);
- savep += blocksize;
-
- /* Clear out the previous block to make it invalid because it's been borrowed */
- memset(blockp, 0, blocksize);
-
- blockp = next->nextblock;
- blocksize = next->nextsize;
- }
- /* curr_dmgr->id == 0 is the element that we actually look at. */
-
- return(dispp);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean disp_SetCurrent(VOID *dispp)
- /*
- Put back into effect a display manager which has previously been 'borrowed'
- using disp_GetCurrent.
- NOTE: This function frees the 'borrowed' display manager. It must be
- borrowed again before it can be restored again.
- */
- {
- if (disp_RestoreCurrent(dispp)) {
- disp_InitMode();
- disp_Repaint();
-
- if (hard_IsMouseOn()) {
- hard_InitMouse();
- }
- return(TRUE);
- }
- else return(FALSE);
- }
- /* -------------------------------------------------------------------------- */
-
- boolean disp_RestoreCurrent(VOID *dispp)
- /*
- Put back into effect a display manager which has previously been 'borrowed'
- using disp_GetCurrent, assuming display mode and screen appearance have not
- been altered.
- NOTE: This function frees the 'borrowed' display manager. It must be
- borrowed again before it can be restored again.
- */
- {
- VOID *blockp;
- byte *savep;
- SIZE_T blocksize, savesize;
- chain_struct *next;
-
- /* If the dmgr saved in dispp is not valid, don't install it */
- owl_Assert(dispp != NULL, OE_SC_DISP);
-
- /* Trace the chain restoring from all the blocks */
- blockp = (VOID *) curr_dmgr;
- blocksize = sizeof(dmgr_struct);
- savep = (byte *) dispp;
- savesize = 0;
- while (blocksize != 0) {
- memmove(blockp, (VOID *) savep, blocksize);
- savep += blocksize;
- savesize += blocksize;
-
- next = nextchain(blockp, blocksize);
- blocksize = next->nextsize;
- blockp = next->nextblock;
- }
-
- /* Make the saved dmgr invalid because it has been un-borrowed */
- /* (In case someone looks at it even though it's about to be freed) */
- memset(dispp, 0, savesize);
-
- /* Free the invalidated save area. */
- /* (It has to be borrowed again before it can be restored again) */
- ofree(OA_SAVDISP, dispp);
-
- /* Check the new dmgr now that it is installed */
- owl_Assert(disp_Ok(), OE_SC_DISP);
-
- return(TRUE);
- }
- /* -------------------------------------------------------------------------- */
-
-