blob: 8d12465eaa777b37f9904591de2dab019562e738 [file] [log] [blame]
Guido van Rossum2d844d11991-04-07 13:41:50 +00001# Text editing widget
2
3from stdwinevents import *
4
5class TextEdit():
6 #
7 def create(self, (parent, (cols, rows))):
8 parent.addchild(self)
9 self.parent = parent
10 self.cols = cols
11 self.rows = rows
12 self.text = ''
13 # Creation of the editor is done in realize()
14 self.editor = 0
15 return self
16 #
17 # Downcalls from parent to child
18 #
19 def destroy(self):
20 del self.parent
21 del self.editor
22 del self.window
23 #
24 def minsize(self, m):
25 return self.cols*m.textwidth('n'), self.rows*m.lineheight()
26 def setbounds(self, bounds):
27 self.bounds = bounds
28 if self.editor:
29 self.editor.move(bounds)
30 def getbounds(self, bounds):
31 if self.editor:
32 return self.editor.getrect()
33 else:
34 return self.bounds
35 def realize(self):
36 self.window = self.parent.getwindow()
37 self.editor = self.window.textcreate(self.bounds)
38 self.editor.replace(self.text)
39 self.parent.need_mouse(self)
40 self.parent.need_keybd(self)
41 self.parent.need_altdraw(self)
42 def draw(self, (d, area)):
43 pass
44 def altdraw(self, area):
45 self.editor.draw(area)
46 #
47 # Event downcalls
48 #
49 def mouse_down(self, detail):
50 x = self.editor.event(WE_MOUSE_DOWN, self.window, detail)
51 def mouse_move(self, detail):
52 x = self.editor.event(WE_MOUSE_MOVE, self.window, detail)
53 def mouse_up(self, detail):
54 x = self.editor.event(WE_MOUSE_UP, self.window, detail)
55 #
56 def keybd(self, (type, detail)):
57 x = self.editor.event(type, self.window, detail)
58 #