Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 1 | # Generic Split implementation. |
| 2 | # Use as a base class for other splits. |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 3 | # Derived classes should at least implement the methods that call |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 4 | # unimpl() below: getminsize(), getbounds() and setbounds(). |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 5 | |
| 6 | Error = 'Split.Error' # Exception |
| 7 | |
| 8 | import rect |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 9 | from stdwinevents import * |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 10 | |
| 11 | class 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 Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 21 | self.keybd_interest = [] |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 22 | self.timer_interest = [] |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 23 | self.altdraw_interest = [] |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 24 | self.mouse_focus = None |
| 25 | self.keybd_focus = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 26 | return self |
| 27 | # |
| 28 | # Downcalls from parent to child |
| 29 | # |
| 30 | def destroy(self): |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 31 | self.parent = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 32 | for child in self.children: |
| 33 | child.destroy() |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 34 | del self.children[:] |
| 35 | del self.mouse_interest[:] |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 36 | del self.keybd_interest[:] |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 37 | del self.timer_interest[:] |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 38 | del self.altdraw_interest[:] |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 39 | self.mouse_focus = None |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 40 | self.keybd_focus = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 41 | # |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 42 | 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 Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 48 | # |
| 49 | def realize(self): |
| 50 | for child in self.children: |
| 51 | child.realize() |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 52 | # |
| 53 | def draw(self, d_detail): |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 54 | # (Could avoid calls to children outside the area) |
| 55 | for child in self.children: |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 56 | child.draw(d_detail) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 57 | # |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 58 | def altdraw(self, detail): |
| 59 | for child in self.altdraw_interest: |
| 60 | child.altdraw(detail) |
| 61 | # |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 62 | # 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 Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 85 | # 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 Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 90 | return |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 91 | p = detail[0] |
| 92 | for child in self.mouse_interest: |
| 93 | if rect.pointinrect(p, child.getbounds()): |
| 94 | self.mouse_focus = child |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 95 | if child in self.keybd_interest: |
| 96 | self.set_keybd_focus(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 97 | 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 Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 104 | 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 Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 114 | # |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 115 | def keybd(self, type_detail): |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 116 | if not self.keybd_focus: |
| 117 | self.set_keybd_focus(self.keybd_interest[0]) |
| 118 | type, detail = type_detail |
| 119 | if type = WE_COMMAND and detail = WC_TAB and \ |
| 120 | len(self.keybd_interest) > 1: |
| 121 | self.next_keybd_focus() |
| 122 | return |
| 123 | self.keybd_focus.keybd(type_detail) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 124 | # |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 125 | 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 Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 138 | self.children.remove(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 139 | if child in self.mouse_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 140 | self.mouse_interest.remove(child) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 141 | if child in self.keybd_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 142 | self.keybd_interest.remove(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 143 | if child in self.timer_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 144 | self.timer_interest.remove(child) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 145 | if child in self.altdraw_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 146 | self.altdraw_interest.remove(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 147 | if child = self.mouse_focus: |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 148 | self.mouse_focus = None |
| 149 | if child = self.keybd_focus: |
| 150 | self.keybd_focus = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 151 | # |
| 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 Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 157 | if child = self.mouse_focus: |
| 158 | self.mouse_focus = None |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 159 | if child in self.mouse_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 160 | self.mouse_interest.remove(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 161 | if not self.mouse_interest: |
| 162 | self.parent.no_mouse(self) |
| 163 | # |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 164 | 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 Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 168 | if not self.keybd_focus: |
| 169 | self.set_keybd_focus(child) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 170 | def no_keybd(self, child): |
Guido van Rossum | 9b1bfc8 | 1991-08-16 13:17:27 +0000 | [diff] [blame^] | 171 | if child = self.keybd_focus: |
| 172 | self.keybd_focus = None # Don't call child.deactivate() |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 173 | if child in self.keybd_interest: |
Guido van Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 174 | self.keybd_interest.remove(child) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 175 | if not self.keybd_interest: |
| 176 | self.parent.no_keybd(self) |
| 177 | # |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 178 | 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 Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 184 | self.timer_interest.remove(child) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 185 | if not self.timer_interest: |
| 186 | self.parent.no_timer(self) |
| 187 | # |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 188 | 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 Rossum | b8f5c09 | 1991-04-21 19:26:45 +0000 | [diff] [blame] | 194 | self.altdraw_interest.remove(child) |
Guido van Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 195 | if not self.altdraw_interest: |
| 196 | self.parent.no_altdraw(self) |
| 197 | # |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 198 | # 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 Rossum | aa57a9d | 1991-04-07 13:33:39 +0000 | [diff] [blame] | 204 | def getwindow(self): |
| 205 | return self.parent.getwindow() |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 206 | # |
| 207 | def change(self, area): |
| 208 | self.parent.change(area) |
Guido van Rossum | a1ec5fe | 1990-12-26 15:33:35 +0000 | [diff] [blame] | 209 | def scroll(self, area_vector): |
| 210 | self.parent.scroll(area_vector) |
Guido van Rossum | 2e44967 | 1990-11-05 19:44:36 +0000 | [diff] [blame] | 211 | def settimer(self, itimer): |
| 212 | self.parent.settimer(itimer) |