blob: 80e1e7427c39de5011cb5c3a6c3fbcb35430aed2 [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
Guido van Rossum2e449671990-11-05 19:44:36 +00009
10class Split():
11 #
12 # Calls from creator
13 # NB derived classes may add parameters to create()
14 #
15 def create(self, parent):
16 parent.addchild(self)
17 self.parent = parent
18 self.children = []
19 self.mouse_interest = []
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000020 self.keybd_interest = []
Guido van Rossum2e449671990-11-05 19:44:36 +000021 self.timer_interest = []
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000022 self.altdraw_interest = []
Guido van Rossum2e449671990-11-05 19:44:36 +000023 self.mouse_focus = 0
24 return self
25 #
26 # Downcalls from parent to child
27 #
28 def destroy(self):
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000029 self.parent = None
Guido van Rossum2e449671990-11-05 19:44:36 +000030 for child in self.children:
31 child.destroy()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000032 del self.children[:]
33 del self.mouse_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000034 del self.keybd_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000035 del self.timer_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000036 del self.altdraw_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000037 self.mouse_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +000038 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000039 def minsize(self, m): return unimpl() # Should ask children
Guido van Rossum2e449671990-11-05 19:44:36 +000040 def getbounds(self): return unimpl()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000041 def setbounds(self, bounds): unimpl() # Should tell children
42 #
43 def realize(self):
44 for child in self.children:
45 child.realize()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000046 #
47 def draw(self, d_detail):
Guido van Rossum2e449671990-11-05 19:44:36 +000048 # (Could avoid calls to children outside the area)
49 for child in self.children:
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000050 child.draw(d_detail)
Guido van Rossum2e449671990-11-05 19:44:36 +000051 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000052 def altdraw(self, detail):
53 for child in self.altdraw_interest:
54 child.altdraw(detail)
55 #
Guido van Rossum2e449671990-11-05 19:44:36 +000056 # Downcalls only made after certain upcalls
57 #
58 def mouse_down(self, detail):
59 if self.mouse_focus:
60 self.mouse_focus.mouse_down(detail)
61 p = detail[0]
62 for child in self.mouse_interest:
63 if rect.pointinrect(p, child.getbounds()):
64 self.mouse_focus = child
65 child.mouse_down(detail)
66 def mouse_move(self, detail):
67 if self.mouse_focus:
68 self.mouse_focus.mouse_move(detail)
69 def mouse_up(self, detail):
70 if self.mouse_focus:
71 self.mouse_focus.mouse_up(detail)
72 self.mouse_focus = 0
73 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000074 def keybd(self, type_detail):
75 for child in self.keybd_interest:
76 child.keybd(type_detail)
77 #
Guido van Rossum2e449671990-11-05 19:44:36 +000078 def timer(self):
79 for child in self.timer_interest:
80 child.timer()
81 #
82 # Upcalls from child to parent
83 #
84 def addchild(self, child):
85 if child in self.children:
86 raise Error, 'addchild: child already inlist'
87 self.children.append(child)
88 def delchild(self, child):
89 if child not in self.children:
90 raise Error, 'delchild: child not in list'
Guido van Rossumb8f5c091991-04-21 19:26:45 +000091 self.children.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +000092 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +000093 self.mouse_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000094 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +000095 self.keybd_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +000096 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +000097 self.timer_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000098 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +000099 self.altdraw_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000100 if child = self.mouse_focus:
101 self.mouse_focus = 0
102 #
103 def need_mouse(self, child):
104 if child not in self.mouse_interest:
105 self.mouse_interest.append(child)
106 self.parent.need_mouse(self)
107 def no_mouse(self, child):
108 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000109 self.mouse_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000110 if not self.mouse_interest:
111 self.parent.no_mouse(self)
112 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000113 def need_keybd(self, child):
114 if child not in self.keybd_interest:
115 self.keybd_interest.append(child)
116 self.parent.need_keybd(self)
117 def no_keybd(self, child):
118 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000119 self.keybd_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000120 if not self.keybd_interest:
121 self.parent.no_keybd(self)
122 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000123 def need_timer(self, child):
124 if child not in self.timer_interest:
125 self.timer_interest.append(child)
126 self.parent.need_timer(self)
127 def no_timer(self, child):
128 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000129 self.timer_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000130 if not self.timer_interest:
131 self.parent.no_timer(self)
132 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000133 def need_altdraw(self, child):
134 if child not in self.altdraw_interest:
135 self.altdraw_interest.append(child)
136 self.parent.need_altdraw(self)
137 def no_altdraw(self, child):
138 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000139 self.altdraw_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000140 if not self.altdraw_interest:
141 self.parent.no_altdraw(self)
142 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000143 # The rest are transparent:
144 #
145 def begindrawing(self):
146 return self.parent.begindrawing()
147 def beginmeasuring(self):
148 return self.parent.beginmeasuring()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000149 def getwindow(self):
150 return self.parent.getwindow()
Guido van Rossum2e449671990-11-05 19:44:36 +0000151 #
152 def change(self, area):
153 self.parent.change(area)
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +0000154 def scroll(self, area_vector):
155 self.parent.scroll(area_vector)
Guido van Rossum2e449671990-11-05 19:44:36 +0000156 def settimer(self, itimer):
157 self.parent.settimer(itimer)