blob: 5ff98088c417e22fffd2d6bdd35f48702bb3a6af [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 Rossum89a78691992-12-14 12:57:56 +000042 def getminsize(self, m, (width, height)):
Guido van Rossum9b1bfc81991-08-16 13:17:27 +000043 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 #
Guido van Rossumfea2af11993-01-04 09:16:51 +000053 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 Rossumfea2af11993-01-04 09:16:51 +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 Rossumfea2af11993-01-04 09:16:51 +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])
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000118 if type == WE_COMMAND and detail == WC_TAB and \
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000119 len(self.keybd_interest) > 1:
120 self.next_keybd_focus()
121 return
Guido van Rossumfea2af11993-01-04 09:16:51 +0000122 self.keybd_focus.keybd(type, detail)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000123 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000124 def timer(self):
125 for child in self.timer_interest:
126 child.timer()
127 #
128 # Upcalls from child to parent
129 #
130 def addchild(self, child):
131 if child in self.children:
132 raise Error, 'addchild: child already inlist'
133 self.children.append(child)
134 def delchild(self, child):
135 if child not in self.children:
136 raise Error, 'delchild: child not in list'
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000137 self.children.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000138 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000139 self.mouse_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000140 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000141 self.keybd_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000142 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000143 self.timer_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000144 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000145 self.altdraw_interest.remove(child)
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000146 if child == self.mouse_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000147 self.mouse_focus = None
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000148 if child == self.keybd_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000149 self.keybd_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +0000150 #
151 def need_mouse(self, child):
152 if child not in self.mouse_interest:
153 self.mouse_interest.append(child)
154 self.parent.need_mouse(self)
155 def no_mouse(self, child):
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000156 if child == self.mouse_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000157 self.mouse_focus = None
Guido van Rossum2e449671990-11-05 19:44:36 +0000158 if child in self.mouse_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000159 self.mouse_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000160 if not self.mouse_interest:
161 self.parent.no_mouse(self)
162 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000163 def need_keybd(self, child):
164 if child not in self.keybd_interest:
165 self.keybd_interest.append(child)
166 self.parent.need_keybd(self)
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000167 if not self.keybd_focus:
168 self.set_keybd_focus(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000169 def no_keybd(self, child):
Guido van Rossumbdfcfcc1992-01-01 19:35:13 +0000170 if child == self.keybd_focus:
Guido van Rossum9b1bfc81991-08-16 13:17:27 +0000171 self.keybd_focus = None # Don't call child.deactivate()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000172 if child in self.keybd_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000173 self.keybd_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000174 if not self.keybd_interest:
175 self.parent.no_keybd(self)
176 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000177 def need_timer(self, child):
178 if child not in self.timer_interest:
179 self.timer_interest.append(child)
180 self.parent.need_timer(self)
181 def no_timer(self, child):
182 if child in self.timer_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000183 self.timer_interest.remove(child)
Guido van Rossum2e449671990-11-05 19:44:36 +0000184 if not self.timer_interest:
185 self.parent.no_timer(self)
186 #
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000187 def need_altdraw(self, child):
188 if child not in self.altdraw_interest:
189 self.altdraw_interest.append(child)
190 self.parent.need_altdraw(self)
191 def no_altdraw(self, child):
192 if child in self.altdraw_interest:
Guido van Rossumb8f5c091991-04-21 19:26:45 +0000193 self.altdraw_interest.remove(child)
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000194 if not self.altdraw_interest:
195 self.parent.no_altdraw(self)
196 #
Guido van Rossum2e449671990-11-05 19:44:36 +0000197 # The rest are transparent:
198 #
199 def begindrawing(self):
200 return self.parent.begindrawing()
201 def beginmeasuring(self):
202 return self.parent.beginmeasuring()
Guido van Rossumaa57a9d1991-04-07 13:33:39 +0000203 def getwindow(self):
204 return self.parent.getwindow()
Guido van Rossum2e449671990-11-05 19:44:36 +0000205 #
206 def change(self, area):
207 self.parent.change(area)
Guido van Rossumfea2af11993-01-04 09:16:51 +0000208 def scroll(self, area, vector):
209 self.parent.scroll(area, vector)
Guido van Rossum2e449671990-11-05 19:44:36 +0000210 def settimer(self, itimer):
211 self.parent.settimer(itimer)