home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
568b.lha
/
PowerSource_v3.0
/
source.lzh
/
source
/
mem.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-15
|
4KB
|
135 lines
/*----------------------------------------------------------------------*
mem.c Version 3.0 - © Copyright 1990-91 Jaba Development
Author : Jan van den Baard
Purpose: Freeing the alocated memory the gadgets take up
*----------------------------------------------------------------------*/
extern struct Window *MainWindow;
extern struct GadgetList Gadgets;
extern struct BorderList SBorders;
extern struct MemoryChain Memory;
extern struct Gadget TextGadget;
extern USHORT GadgetCount, id;
extern BOOL Saved;
/*
* Free the memory of any type off gadget rendering attached to the gadget.
*/
void FreeRender( struct MyGadget *gd )
{
struct Image *image;
struct Border *border, *border1;
struct Gadget *gadget;
ULONG ps;
gadget = &gd->Gadget;
if(TestBits((ULONG)gadget->GadgetType,PROPGADGET)) {
image = (struct Image *)gadget->GadgetRender;
if(TestBits((ULONG)gadget->Flags,GADGIMAGE))
rem_user(image);
else
FreeItem(&Memory,image,(long)sizeof(struct Image));
} else if(TestBits((ULONG)gadget->Flags,GADGIMAGE)) {
image = (struct Image *)gadget->GadgetRender;
rem_user(image);
} else {
border = (struct Border *)gadget->GadgetRender;
if((TestBits((ULONG)gd->SpecialFlags,BORDERONLY)) OR
(TestBits((ULONG)gd->SpecialFlags,NOBORDER))) {
FreeItem(&Memory,border->XY,(long)(border->Count << 2));
FreeItem(&Memory,border,(long)sizeof(struct Border));
} else
RemUser(border);
if(TestBits((ULONG)gd->SpecialFlags,OS20HIGHBORDER)) {
border = (struct Border *)gadget->SelectRender;
RemUser(border);
}
}
if((TestBits((ULONG)gadget->Flags,GADGHIMAGE)) AND
(NOT TestBits((ULONG)gadget->Flags,GADGHBOX)) AND
(NOT TestBits((ULONG)gd->SpecialFlags,OS20HIGHBORDER))) {
image = (struct Image *)gadget->SelectRender;
rem_user(image);
}
}
/*
* Free the memory a gadget takes up.
*/
void FreeGadget( struct MyGadget *gadget )
{
struct IntuiText *itext,*tmp;
struct StringInfo *sinfo;
if(TestBits((ULONG)gadget->Gadget.GadgetType,PROPGADGET)) {
if(gadget->Gadget.SpecialInfo)
FreeItem(&Memory,gadget->Gadget.SpecialInfo,(long)sizeof(struct PropInfo));
}
FreeRender(gadget);
itext = gadget->Gadget.GadgetText;
if(itext) {
while(1) {
tmp = itext->NextText;
if(itext->IText) FreeItem(&Memory,itext->IText,80L);
FreeItem(&Memory,itext,(long)sizeof(struct IntuiText));
if(!tmp) break;
itext = tmp;
}
}
if(TestBits((ULONG)gadget->Gadget.GadgetType,STRGADGET)) {
sinfo = (struct StringInfo *)gadget->Gadget.SpecialInfo;
if(sinfo->Buffer) {
FreeItem(&Memory,sinfo->Buffer,sinfo->MaxChars);
}
if(sinfo->UndoBuffer) {
FreeItem(&Memory,sinfo->UndoBuffer,sinfo->MaxChars);
}
FreeItem(&Memory,sinfo,(long)sizeof(struct StringInfo));
}
FreeItem(&Memory,gadget,(long)sizeof(struct MyGadget));
}
/*
* Free the complete list of gadgets.
*/
void FreeGList( void )
{
struct MyGadget *gadget, *tmp;
struct IntuiText *t, *t1;
add_bo();
while(gadget = (struct MyGadget *)RemHead((void *)&Gadgets)) {
un_grel(MainWindow,&gadget->Gadget);
RemoveGadget(MainWindow,&gadget->Gadget);
FreeGadget(gadget);
}
NewList((void *)&Gadgets);
GadgetCount = id = 0;
if((t = TextGadget.GadgetText)) {
while(1) {
t1 = t->NextText;
if(t->IText) FreeItem(&Memory,t->IText,80L);
FreeItem(&Memory,t,(long)sizeof(struct IntuiText));
if(NOT t1) break;
t = t1;
}
TextGadget.GadgetText = NULL;
}
Saved = TRUE;
NewList((void *)&SBorders);
}