/* wn_free.c *********** Copyright 1988-1993 by Vermont Creative Software *********** wn_free() Frees all memory allocated for a window Call #include void wn_free(wnp) WINDOWPTR wnp; Pointer to a window structure to free Returns None Description wn_free() frees all memory controlled by a window structure, including: * Any protected objects on window (boxes, lines, text). * The scroll bar structure, if any. * The shadow structures, if any. * The memory allocated for a stored window image saved by a previous call to wi_sav(). * The window's memory screen buffer if one exists and its use count will now be zero. If the window structure was allocated by wn_def(), it too is then freed. Related Functions wn_def() Cautions Window structures allocated from the heap are not freed. */ #include #include #ifdef OLD_STYLE void FASTCALL wn_free(wnp) WINDOWPTR wnp; #else void FASTCALL wn_free(WINDOWPTR wnp) #endif { UCHAR *bdr_vstp; WINDOWPTR twnp; #ifndef NO_DEBUG_CODE static UCHAR fn[] = "wn_free"; #endif INIT_MODULE(fn); if (wnp) /* if valid pointer passed */ { #ifndef NO_DEBUG_CODE if (wn_isup(wnp)) { VV_ERR = WNISUP; goto END; } #endif /*----------------------------------------------------------------------------*/ /* Remove the window from the linked list of windows */ /*----------------------------------------------------------------------------*/ if (_wnhdndp == wnp) /*unlink the form */ _wnhdndp = wnp->nd_wnp; else { for (twnp = _wnhdndp; twnp; twnp = twnp->nd_wnp) { if (twnp->nd_wnp == wnp) { twnp->nd_wnp = wnp->nd_wnp; break; } } } if (wnp->storp) /* free window storage */ { mem_free((PTR) wnp->storp); wnp->storp = (UCHAR *) NULLP; } /* Remove this next one line after pop-up flags purged by library converter! */ if (wnp->flags & HEAP_WN) if (wnp->flags & DESWIN) _liblattfree(wnp->lib_name); if (wnp->vvd_stbuff) { mem_free((PTR) wnp->vvd_stbuff); wnp->vvd_stbuff = (UCHAR *)NULLP; } if (wnp->sbarp) /* free the scroll bar structure */ { mem_free((PTR) wnp->sbarp); wnp->sbarp = (SBARP)NULLP; } if (wnp->bdr_txt.next_textp) /* Free any extra border text structs */ sw_bdrtxt(NULLP, BDR_ALL, NULLPARM, NULLPARM, wnp); if ((bdr_vstp = wnp->bdr_vstp) && (bdr_vstp != _fullbdr_vstp)) { mem_free((PTR)bdr_vstp); wnp->bdr_vstp = (UCHAR *)NULLP; } if (wnp->shadp) /* free the shadow structure */ { mem_free((PTR) wnp->shadp); wnp->shadp = (VSHADOW (*)[2]) NULLP; } ms_free(wnp->bufp); /*release hold on ms buffer (if any) */ ms_free(wnp->destp); /*release hold on ms dest */ if (wnp->flags & HEAP_WN) /* if window allocated from heap */ { #ifndef NO_DEBUG_CODE wnp->tag = 0xff; /*corrupt tag to prevent mistaken use */ #endif mem_free((PTR) wnp); /* free the window structure */ } } #ifndef NO_DEBUG_CODE END: EXIT_MODULE(fn); #else EXIT_NOERRH(fn); #endif return; }