popexitchecker.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <precomp.h>
  2. #include "popexitchecker.h"
  3. #include <api/wnd/popexitcb.h>
  4. #include <api/wnd/api_window.h>
  5. #include <api/syscb/callbacks/syscbi.h>
  6. #include <api/wnd/wndtrack.h>
  7. //PopupExitChecker *popupExitChecker;
  8. PopupExitChecker::PopupExitChecker() {
  9. }
  10. PopupExitChecker::~PopupExitChecker() {
  11. watchers.deleteAll();
  12. }
  13. void PopupExitChecker::registerCallback(PopupExitCallback *cb, ifc_window *watched) {
  14. ifc_dependent *a = cb->popupexit_getDependencyPtr();
  15. ifc_dependent *b = watched->getDependencyPtr();
  16. watchers.addItem(new PopupExitCallbackEntry(cb, watched, a, b));
  17. viewer_addViewItem(a);
  18. viewer_addViewItem(b);
  19. }
  20. int PopupExitChecker::check(ifc_window *w) {
  21. int n=0;
  22. foreach(watchers)
  23. PopupExitCallbackEntry *e = watchers.getfor();
  24. if (w != e->watched && !isGrandChildren(e->watched, w)) {
  25. e->cb->popupexitcb_onExitPopup();
  26. n++;
  27. }
  28. endfor;
  29. return n > 0;
  30. }
  31. void PopupExitChecker::signal() {
  32. foreach(watchers)
  33. watchers.getfor()->cb->popupexitcb_onExitPopup();
  34. endfor;
  35. }
  36. int PopupExitChecker::isGrandChildren(ifc_window *parent, ifc_window *child) {
  37. int i;
  38. for (i=0;i<parent->getNumRootWndChildren();i++) {
  39. if (parent->enumRootWndChildren(i) == child) return 1;
  40. }
  41. for (i=0;i<parent->getNumRootWndChildren();i++) {
  42. ifc_window *w = parent->enumRootWndChildren(i);
  43. int r = 0;
  44. if (w->getNumRootWndChildren() > 0) r = isGrandChildren(w, child);
  45. if (r) return 1;
  46. }
  47. return 0;
  48. }
  49. int PopupExitChecker::viewer_onItemDeleted(ifc_dependent *item) {
  50. for (int i=0;i<watchers.getNumItems();i++) {
  51. PopupExitCallbackEntry *e = watchers.enumItem(i);
  52. if (e->cbd == item || e->wd == item) {
  53. watchers.removeByPos(i); i--;
  54. delete e;
  55. // no break, wnd can be watched by many people
  56. }
  57. }
  58. return 0;
  59. }
  60. void PopupExitChecker::deregisterCallback(PopupExitCallback *cb) {
  61. for (int i=0;i<watchers.getNumItems();i++) {
  62. PopupExitCallbackEntry *e = watchers.enumItem(i);
  63. if (e->cb == cb) {
  64. watchers.removeByPos(i); i--;
  65. delete e;
  66. // no break, watcher can watch many windows, but wait, there cannot be 2 popups at once on a screen! who says so ?
  67. }
  68. }
  69. }