PegPresentationManager. Next() would return PegWindow2. Since all lists are
terminated with a NULL, Previous() would return NULL. So, if we wanted traverse all
of the children of an object, we could use the following code:
PegThing *pTest = Parent()->First(); // first child of my parent
int iSiblings = 0;
// Since all lists are NULL terminated,
// we can loop on while ptest!=NULL
while(pTest)
{
if (pTest != this)
{
iSiblings++;
}
pTest = pTest->Next();
}
Adding to and Removing from the Tree
PEG provides two functions to add PegThings to the presentation tree:
void PegThing::Add(PegThing *Who, BOOL bDraw = TRUE);
void PegThing::AddToEnd(PegThing *Who, BOOL bDraw = TRUE);
Add() always adds the child to the beginning of the linked list of children. If you would
like to add to the end, use AddToEnd().
Let’s look at some example code and see what the tree it creates will look like:
PegRect Rect(10, 10, 40, 40);
PegWindow *child_window = new PegWindow(Rect);
PegWindow *parent_window = new PegWindow(Rect + 50);
PegPrompt *prompt1 = new PegPrompt(0, 0, “Prompt1”);
PegPrompt *prompt2 = new PegPrompt(0,30, “”Prompt2”);
prent_window->Add(child_window);
child_window->Add(prompt1);
child_window->AddToEnd(prompt2);
child_window
rompt1
rompt2
arent_window
There are also two functions to remove an object from the tree:
10