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