diff options
author | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
---|---|---|
committer | Jef <jef@targetspot.com> | 2024-09-24 08:54:57 -0400 |
commit | 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d (patch) | |
tree | 12f17f78986871dd2cfb0a56e5e93b545c1ae0d0 /Src/Wasabi/api/wnd/popexitchecker.cpp | |
parent | 537bcbc86291b32fc04ae4133ce4d7cac8ebe9a7 (diff) | |
download | winamp-20d28e80a5c861a9d5f449ea911ab75b4f37ad0d.tar.gz |
Initial community commit
Diffstat (limited to 'Src/Wasabi/api/wnd/popexitchecker.cpp')
-rw-r--r-- | Src/Wasabi/api/wnd/popexitchecker.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
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 <precomp.h> +#include "popexitchecker.h" +#include <api/wnd/popexitcb.h> +#include <api/wnd/api_window.h> +#include <api/syscb/callbacks/syscbi.h> +#include <api/wnd/wndtrack.h> + +//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;i<parent->getNumRootWndChildren();i++) { + if (parent->enumRootWndChildren(i) == child) return 1; + } + + for (i=0;i<parent->getNumRootWndChildren();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;i<watchers.getNumItems();i++) { + PopupExitCallbackEntry *e = watchers.enumItem(i); + if (e->cbd == 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;i<watchers.getNumItems();i++) { + PopupExitCallbackEntry *e = watchers.enumItem(i); + if (e->cb == 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 ? + } + } +} |