home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
WINCPP.ZIP
/
WLIST.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-22
|
2KB
|
133 lines
#include "window.h"
WindowList::WindowList()
{
Bottom = NULL;
Top = NULL;
Current = NULL;
}
WindowList::~WindowList()
{
WindowListNode *NextNode;
Current = Bottom;
while (Current != NULL) {
NextNode = Current->Next;
delete Current;
Current = NextNode;
}
}
void WindowList::Add(Window *w)
{
if (w == NULL)
return;
else {
if (Top == NULL) {
Top = new WindowListNode;
if (Top == NULL)
Error("Can't allocate Top item");
Top->Prev = NULL;
Top->Next = NULL;
Top->WindowPtr = w;
Bottom = Top;
}
else {
Top->Next = new WindowListNode;
if (Top->Next == NULL)
Error("can't allocate new item");
Top->Next->Next = NULL;
Top->Next->Prev = Top;
Top = Top->Next;
Top->WindowPtr = w;
}
}
}
void WindowList::Delete(Window *w)
{
if (w == NULL)
return;
else {
Current = Bottom;
while ((Current != NULL) && (Current->WindowPtr != w))
Current = Current->Next;
if (Current->WindowPtr == w) {
if (Current->Prev == NULL)
Bottom = Current->Next;
else
Current->Prev->Next = Current->Next;
if (Current->Next == NULL)
Top = Current->Prev;
else
Current->Next->Prev = Current->Prev;
delete Current;
}
}
}
void WindowList::MoveTop(Window *w)
{
if (w == NULL)
return;
else {
Delete(w);
Add(w);
}
}
void WindowList::MoveBottom(Window *w)
{
if (w == NULL)
return;
else {
Delete(w);
Bottom->Prev = new WindowListNode;
if (Bottom->Prev == NULL)
Error("Can't allocate new item");
Bottom->Prev->Prev = NULL;
Bottom->Prev->Next = Bottom;
Bottom->Prev->WindowPtr = w;
Bottom = Bottom->Prev;
}
}
short WindowList::IsTop(Window *w)
{
if (Top != NULL)
return(w == Top->WindowPtr);
else
return 0;
}
Window * WindowList::AtBottom()
{
Current = Bottom;
if (Current == NULL)
return NULL;
else
return Current->WindowPtr;
}
Window * WindowList::NextWindow()
{
if (Current == NULL)
return NULL;
else {
Current = Current->Next;
if (Current == NULL)
return NULL;
else
return Current->WindowPtr;
}
}