blob: 31ec91a625c5c5785a1cdf7fdd5991694414fd32 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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 ?
}
}
}
|