From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/Wasabi/api/wnd/popexitchecker.cpp | 79 +++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 Src/Wasabi/api/wnd/popexitchecker.cpp (limited to 'Src/Wasabi/api/wnd/popexitchecker.cpp') diff --git a/Src/Wasabi/api/wnd/popexitchecker.cpp b/Src/Wasabi/api/wnd/popexitchecker.cpp new file mode 100644 index 00000000..31ec91a6 --- /dev/null +++ b/Src/Wasabi/api/wnd/popexitchecker.cpp @@ -0,0 +1,79 @@ +#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 ? + } + } +} -- cgit