blob: aacfa9896909d791613fc08f4af42e2158b480a4 [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
Guido van Rossum9b1bfc81991-08-16 13:17:27 +00004# unimpl() below: getminsize(), getbounds() and setbounds().
Guido van Rossum2e449671990-11-05 19:44:36 +00005
6Error = 'Split.Error' # Exception
7
8import rect
Guido van Rossum9b1bfc81991-08-16 13:17:27 +00009from stdwinevents import *
Guido van Rossum2e449671990-11-05 19:44:36 +000010
Guido van Rossumce084481991-12-26 13:06:29 +000011class Split:
Guido van Rossum2e449671990-11-05 19:44:36 +000012 #
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 Rossum9b1bfc81991-08-16 13:17:27 +000024 self.mouse_focus = None
25 self.keybd_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +000026 return self
27 #
28 # Downcalls from parent to child
29 #
30 def destroy(self):
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000031 self.parent = None
Guido van Rossum2e449671990-11-05 19:44:36 +000032 for child in self.children:
33 child.destroy()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000034 del self.children[:]
35 del self.mouse_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000036 del self.keybd_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000037 del self.timer_interest[:]
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000038 del self.altdraw_interest[:]
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000039 self.mouse_focus = None
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000040 self.keybd_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +000041 #
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000042 def getminsize(self, (m, (width, height))):
43 return unimpl() # Should ask children
44 def getbounds(self):
45 return unimpl()
46 def setbounds(self, bounds):
47 unimpl() # Should tell children
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000048 #
49 def realize(self):
50 for child in self.children:
51 child.realize()
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000052 #
53 def draw(self, d_detail):
Guido van Rossum2e449671990-11-05 19:44:36 +000054 # (Could avoid calls to children outside the area)
55 for child in self.children:
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +000056 child.draw(d_detail)
Guido van Rossum2e449671990-11-05 19:44:36 +000057 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +000058 def altdraw(self, detail):
59 for child in self.altdraw_interest:
60 child.altdraw(detail)
61 #
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000062 # Keyboard focus handling (used internally)
63 # XXX This is not enough if two levels of splits
64 # XXX surround text fields!
65 #
66 def set_keybd_focus(self, child):
67 if self.keybd_focus <> child:
68 if self.keybd_focus:
69 self.keybd_focus.deactivate()
70 self.keybd_focus = None
71 if child:
72 child.activate()
73 self.keybd_focus = child
74 def next_keybd_focus(self):
75 if not self.keybd_interest:
76 self.set_keybd_focus(None)
77 return
78 if self.keybd_focus in self.keybd_interest:
79 i = self.keybd_interest.index(self.keybd_focus)
80 i = (i+1) % len(self.keybd_interest)
81 else:
82 i = 0
83 self.set_keybd_focus(self.keybd_interest[i])
84 #
Guido van Rossum2e449671990-11-05 19:44:36 +000085 # Downcalls only made after certain upcalls
86 #
87 def mouse_down(self, detail):
88 if self.mouse_focus:
89 self.mouse_focus.mouse_down(detail)
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000090 return
Guido van Rossum2e449671990-11-05 19:44:36 +000091 p = detail[0]
92 for child in self.mouse_interest:
93 if rect.pointinrect(p, child.getbounds()):
94 self.mouse_focus = child
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000095 if child in self.keybd_interest:
96 self.set_keybd_focus(child)
Guido van Rossum2e449671990-11-05 19:44:36 +000097 child.mouse_down(detail)
98 def mouse_move(self, detail):
99 if self.mouse_focus:
100 self.mouse_focus.mouse_move(detail)
101 def mouse_up(self, detail):
102 if self.mouse_focus:
103 self.mouse_focus.mouse_up(detail)
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000104 self.mouse_focus = None
105 #
106 def activate(self):
107 if self.keybd_focus:
108 self.keybd_focus.activate()
109 else:
110 self.next_keybd_focus()
111 def deactivate(self):
112 if self.keybd_focus:
113 self.keybd_focus.deactivate()
Guido van Rossum2e449671990-11-05 19:44:36 +0000114 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000115 def keybd(self, type_detail):
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000116 if not self.keybd_focus:
117 self.set_keybd_focus(self.keybd_interest[0])
118 type, detail = type_detail
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000119 if type == WE_COMMAND and detail == WC_TAB and \
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000120 len(self.keybd_interest) > 1:
121 self.next_keybd_focus()
122 return
123 self.keybd_focus.keybd(type_detail)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000124 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000125 def timer(self):
126 for child in self.timer_interest:
127 child.timer()
128 #
129 # Upcalls from child to parent
130 #
131 def addchild(self, child):
132 if child in self.children:
133 raise Error, 'addchild: child already inlist'
134 self.children.append(child)
135 def delchild(self, child):
136 if child not in self.children:
137 raise Error, 'delchild: child not in list'
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000138 self.children.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000139 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000140 self.mouse_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000141 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000142 self.keybd_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000143 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000144 self.timer_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000145 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000146 self.altdraw_interest.remove(child)
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000147 if child == self.mouse_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000148 self.mouse_focus = None
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000149 if child == self.keybd_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000150 self.keybd_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +0000151 #
152 def need_mouse(self, child):
153 if child not in self.mouse_interest:
154 self.mouse_interest.append(child)
155 self.parent.need_mouse(self)
156 def no_mouse(self, child):
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000157 if child == self.mouse_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000158 self.mouse_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +0000159 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000160 self.mouse_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000161 if not self.mouse_interest:
162 self.parent.no_mouse(self)
163 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000164 def need_keybd(self, child):
165 if child not in self.keybd_interest:
166 self.keybd_interest.append(child)
167 self.parent.need_keybd(self)
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000168 if not self.keybd_focus:
169 self.set_keybd_focus(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000170 def no_keybd(self, child):
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000171 if child == self.keybd_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000172 self.keybd_focus = None # Don't call child.deactivate()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000173 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000174 self.keybd_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000175 if not self.keybd_interest:
176 self.parent.no_keybd(self)
177 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000178 def need_timer(self, child):
179 if child not in self.timer_interest:
180 self.timer_interest.append(child)
181 self.parent.need_timer(self)
182 def no_timer(self, child):
183 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000184 self.timer_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000185 if not self.timer_interest:
186 self.parent.no_timer(self)
187 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000188 def need_altdraw(self, child):
189 if child not in self.altdraw_interest:
190 self.altdraw_interest.append(child)
191 self.parent.need_altdraw(self)
192 def no_altdraw(self, child):
193 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000194 self.altdraw_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000195 if not self.altdraw_interest:
196 self.parent.no_altdraw(self)
197 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000198 # The rest are transparent:
199 #
200 def begindrawing(self):
201 return self.parent.begindrawing()
202 def beginmeasuring(self):
203 return self.parent.beginmeasuring()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000204 def getwindow(self):
205 return self.parent.getwindow()
Guido van Rossum2e449671990-11-05 19:44:36 +0000206 #
207 def change(self, area):
208 self.parent.change(area)
Guido van Rossuma1ec5fe1990-12-26 15:33:35 +0000209 def scroll(self, area_vector):
210 self.parent.scroll(area_vector)
Guido van Rossum2e449671990-11-05 19:44:36 +0000211 def settimer(self, itimer):
212 self.parent.settimer(itimer)