#include #include "popexitchecker.h" #include #include #include #include //PopupExitChecker *popupExitChecker; PopupExitChecker::PopupExitChecker() { } PopupExitChecker::~PopupExitChecker() { watchers.deleteAll(); } void PopupExitChecker::registerCallback(PopupExitCallback *cb, ifc_window *watched) { ifc_dependent *a = cb->popupexit_getDependencyPtr(); ifc_dependent *b = watched->getDependencyPtr(); watchers.addItem(new PopupExitCallbackEntry(cb, watched, a, b)); viewer_addViewItem(a); viewer_addViewItem(b); } int PopupExitChecker::check(ifc_window *w) { int n=0; foreach(watchers) PopupExitCallbackEntry *e = watchers.getfor(); if (w != e->watched && !isGrandChildren(e->watched, w)) { e->cb->popupexitcb_onExitPopup(); n++; } endfor; return n > 0; } void PopupExitChecker::signal() { foreach(watchers) watchers.getfor()->cb->popupexitcb_onExitPopup(); endfor; } int PopupExitChecker::isGrandChildren(ifc_window *parent, ifc_window *child) { int i; for (i=0;igetNumRootWndChildren();i++) { if (parent->enumRootWndChildren(i) == child) return 1; } for (i=0;igetNumRootWndChildren();i++) { ifc_window *w = parent->enumRootWndChildren(i); int r = 0; if (w->getNumRootWndChildren() > 0) r = isGrandChildren(w, child); if (r) return 1; } return 0; } int PopupExitChecker::viewer_onItemDeleted(ifc_dependent *item) { for (int i=0;icbd == item || e->wd == item) { watchers.removeByPos(i); i--; delete e; // no break, wnd can be watched by many people } } return 0; } void PopupExitChecker::deregisterCallback(PopupExitCallback *cb) { for (int i=0;icb == cb) { watchers.removeByPos(i); i--; delete e; // no break, watcher can watch many windows, but wait, there cannot be 2 popups at once on a screen! who says so ? } } }