blob: c442fe3ef0a7226e4584835ce4fc50486dff9ebe [file] [log] [blame]
Guido van Rossum2e449671990-11-05 19:44:36 +00001# Generic Split implementation.
2# Use as a base class for other splits.
3
4Error = 'Split.Error' # Exception
5
6import rect
7from util import remove
8
9class Split():
10 #
11 # Calls from creator
12 # NB derived classes may add parameters to create()
13 #
14 def create(self, parent):
15 parent.addchild(self)
16 self.parent = parent
17 self.children = []
18 self.mouse_interest = []
19 self.timer_interest = []
20 self.mouse_focus = 0
21 return self
22 #
23 # Downcalls from parent to child
24 #
25 def destroy(self):
26 self.parent = 0
27 for child in self.children:
28 child.destroy()
29 self.children[:] = []
30 self.mouse_interest[:] = []
31 self.timer_interest[:] = []
32 self.mouse_focus = 0
33 #
34 def minsize(self, m): return unimpl()
35 def getbounds(self): return unimpl()
36 def setbounds(self, bounds): unimpl()
37 def draw(self, args):
38 # (Could avoid calls to children outside the area)
39 for child in self.children:
40 child.draw(args)
41 #
42 # Downcalls only made after certain upcalls
43 #
44 def mouse_down(self, detail):
45 if self.mouse_focus:
46 self.mouse_focus.mouse_down(detail)
47 p = detail[0]
48 for child in self.mouse_interest:
49 if rect.pointinrect(p, child.getbounds()):
50 self.mouse_focus = child
51 child.mouse_down(detail)
52 def mouse_move(self, detail):
53 if self.mouse_focus:
54 self.mouse_focus.mouse_move(detail)
55 def mouse_up(self, detail):
56 if self.mouse_focus:
57 self.mouse_focus.mouse_up(detail)
58 self.mouse_focus = 0
59 #
60 def timer(self):
61 for child in self.timer_interest:
62 child.timer()
63 #
64 # Upcalls from child to parent
65 #
66 def addchild(self, child):
67 if child in self.children:
68 raise Error, 'addchild: child already inlist'
69 self.children.append(child)
70 def delchild(self, child):
71 if child not in self.children:
72 raise Error, 'delchild: child not in list'
73 remove(child, self.children)
74 if child in self.mouse_interest:
75 remove(child, self.mouse_interest)
76 if child in self.timer_interest:
77 remove(child, self.timer_interest)
78 if child = self.mouse_focus:
79 self.mouse_focus = 0
80 #
81 def need_mouse(self, child):
82 if child not in self.mouse_interest:
83 self.mouse_interest.append(child)
84 self.parent.need_mouse(self)
85 def no_mouse(self, child):
86 if child in self.mouse_interest:
87 remove(child, self.mouse_interest)
88 if not self.mouse_interest:
89 self.parent.no_mouse(self)
90 #
91 def need_timer(self, child):
92 if child not in self.timer_interest:
93 self.timer_interest.append(child)
94 self.parent.need_timer(self)
95 def no_timer(self, child):
96 if child in self.timer_interest:
97 remove(child, self.timer_interest)
98 if not self.timer_interest:
99 self.parent.no_timer(self)
100 #
101 # The rest are transparent:
102 #
103 def begindrawing(self):
104 return self.parent.begindrawing()
105 def beginmeasuring(self):
106 return self.parent.beginmeasuring()
107 #
108 def change(self, area):
109 self.parent.change(area)
110 def scroll(self, args):
111 self.parent.scroll(args)
112 def settimer(self, itimer):
113 self.parent.settimer(itimer)