#ifdef __GNUC__ #pragma implementation "Child.h" #endif #include #include //#include char ChildWin::newflag = 0; void ChildWin::link(ChildWin *p) { //cerr << "ChildWin::link(" << this << ',' << p << ")\n"; if (parent = p) { if (p->cur) { next = p->cur->next; p->cur->next = this; ++p->idx; } else { next = p->child; p->child = this; p->idx = 0; } p->cur = this; ++p->cnt; } } void ChildWin::unlink() { if (parent) { int adj = 1; for (ChildWin **p = &parent->child; *p; p = &(*p)->next) { if (*p == parent->cur) adj = 0; if (*p == this) { if (this == parent->cur) parent->cur = next; *p = next; parent->idx -= adj; --parent->cnt; break; } } parent = 0; } } // perhaps we should just unlink all children // and have a destroy method that deletes all children ChildWin::~ChildWin() { unlink(); Window::hide(); // hide first so we won't try to draw while (child) destroy(child); } void ChildWin::destroy(ChildWin *c) { if (c->destroy_flag) delete c; else c->unlink(); } void ChildWin::top() { Window::top(); // bring us to top for (ChildWin *p = child; p; p = p->next) p->top(); // bring children to top } void ChildWin::hide() { Window::hide(); // hide us for (ChildWin *p = child; p; p = p->next) p->hide(); // hide childen } void ChildWin::bury() { #ifdef PARENT_FIRST if (parent && !from_parent) parent->bury(); else { from_parent = 1; #endif for (ChildWin *p = child; p; p = p->next) p->bury(); Window::bury(); #ifdef PARENT_FIRST from_parent = 0; } #endif } void ChildWin::setphys(const Rect &r) { int oldrow = loc.r1, oldcol = loc.c1; if (parent) Window::setphys(r.moverel(parent->loc.r1,parent->loc.c1)); else Window::setphys(r); ChildWinList i(*this); for (ChildWin *p = i.first(); p; p = i.next()) p->setphys(p->loc.moverel(-oldrow,-oldcol)); } ChildWin::ChildWin(ChildWin *p) { destroy_flag = newflag; //fprintf(stderr,"%08X: destroy_flag = %d\n",this,destroy_flag); newflag = 0; //from_parent = 0; link(p); idx = 0; child = cur = 0; cnt = 0; } ChildWin *ChildWin::operator[](int i) { if (i < idx || !cur) cur = child, idx = 0; while (i > idx && cur) cur = cur->next, ++idx; return (i == idx) ? cur : 0; }