blob: ef0f2fcb17dd6f36bf2c8908622510b23493efa6 [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 = []
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000021 self.keybd_interest = []
Guido van Rossum2e449671990-11-05 19:44:36 +000022 self.timer_interest = []
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000023 self.altdraw_interest = []
Guido van Rossum2e449671990-11-05 19:44:36 +000024 self.mouse_focus = 0
25 return self
26 #
27 # Downcalls from parent to child
28 #
29 def destroy(self):
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000030 self.parent = None
Guido van Rossum2e449671990-11-05 19:44:36 +000031 for child in self.children:
32 child.destroy()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000033 del self.children[:]
34 del self.mouse_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000035 del self.keybd_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000036 del self.timer_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000037 del self.altdraw_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000038 self.mouse_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +000039 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000040 def minsize(self, m): return unimpl() # Should ask children
Guido van Rossum2e449671990-11-05 19:44:36 +000041 def getbounds(self): return unimpl()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000042 def setbounds(self, bounds): unimpl() # Should tell children
43 #
44 def realize(self):
45 for child in self.children:
46 child.realize()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000047 #
48 def draw(self, d_detail):
Guido van Rossum2e449671990-11-05 19:44:36 +000049 # (Could avoid calls to children outside the area)
50 for child in self.children:
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000051 child.draw(d_detail)
Guido van Rossum2e449671990-11-05 19:44:36 +000052 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000053 def altdraw(self, detail):
54 for child in self.altdraw_interest:
55 child.altdraw(detail)
56 #
Guido van Rossum2e449671990-11-05 19:44:36 +000057 # Downcalls only made after certain upcalls
58 #
59 def mouse_down(self, detail):
60 if self.mouse_focus:
61 self.mouse_focus.mouse_down(detail)
62 p = detail[0]
63 for child in self.mouse_interest:
64 if rect.pointinrect(p, child.getbounds()):
65 self.mouse_focus = child
66 child.mouse_down(detail)
67 def mouse_move(self, detail):
68 if self.mouse_focus:
69 self.mouse_focus.mouse_move(detail)
70 def mouse_up(self, detail):
71 if self.mouse_focus:
72 self.mouse_focus.mouse_up(detail)
73 self.mouse_focus = 0
74 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000075 def keybd(self, type_detail):
76 for child in self.keybd_interest:
77 child.keybd(type_detail)
78 #
Guido van Rossum2e449671990-11-05 19:44:36 +000079 def timer(self):
80 for child in self.timer_interest:
81 child.timer()
82 #
83 # Upcalls from child to parent
84 #
85 def addchild(self, child):
86 if child in self.children:
87 raise Error, 'addchild: child already inlist'
88 self.children.append(child)
89 def delchild(self, child):
90 if child not in self.children:
91 raise Error, 'delchild: child not in list'
92 remove(child, self.children)
93 if child in self.mouse_interest:
94 remove(child, self.mouse_interest)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000095 if child in self.keybd_interest:
96 remove(child, self.keybd_interest)
Guido van Rossum2e449671990-11-05 19:44:36 +000097 if child in self.timer_interest:
98 remove(child, self.timer_interest)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000099 if child in self.altdraw_interest:
100 remove(child, self.altdraw_interest)
Guido van Rossum2e449671990-11-05 19:44:36 +0000101 if child = self.mouse_focus:
102 self.mouse_focus = 0
103 #
104 def need_mouse(self, child):
105 if child not in self.mouse_interest:
106 self.mouse_interest.append(child)
107 self.parent.need_mouse(self)
108 def no_mouse(self, child):
109 if child in self.mouse_interest:
110 remove(child, self.mouse_interest)
111 if not self.mouse_interest:
112 self.parent.no_mouse(self)
113 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000114 def need_keybd(self, child):
115 if child not in self.keybd_interest:
116 self.keybd_interest.append(child)
117 self.parent.need_keybd(self)
118 def no_keybd(self, child):
119 if child in self.keybd_interest:
120 remove(child, self.keybd_interest)
121 if not self.keybd_interest:
122 self.parent.no_keybd(self)
123 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000124 def need_timer(self, child):
125 if child not in self.timer_interest:
126 self.timer_interest.append(child)
127 self.parent.need_timer(self)
128 def no_timer(self, child):
129 if child in self.timer_interest:
130 remove(child, self.timer_interest)
131 if not self.timer_interest:
132 self.parent.no_timer(self)
133 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000134 def need_altdraw(self, child):
135 if child not in self.altdraw_interest:
136 self.altdraw_interest.append(child)
137 self.parent.need_altdraw(self)
138 def no_altdraw(self, child):
139 if child in self.altdraw_interest:
140 remove(child, self.altdraw_interest)
141 if not self.altdraw_interest:
142 self.parent.no_altdraw(self)
143 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000144 # The rest are transparent:
145 #
146 def begindrawing(self):
147 return self.parent.begindrawing()
148 def beginmeasuring(self):
149 return self.parent.beginmeasuring()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000150 def getwindow(self):
151 return self.parent.getwindow()
Guido van Rossum2e449671990-11-05 19:44:36 +0000152 #
153 def change(self, area):
154 self.parent.change(area)
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +0000155 def scroll(self, area_vector):
156 self.parent.scroll(area_vector)
Guido van Rossum2e449671990-11-05 19:44:36 +0000157 def settimer(self, itimer):
158 self.parent.settimer(itimer)