blob: d7b22362e241624c909bad192a5a28ff03e3b137 [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 #
Guido van Rossuma82a2751991-04-21 19:27:48 +000017 def settext(self, text):
18 self.editor.settext(text)
19 #
Guido van Rossum2d844d11991-04-07 13:41:50 +000020 # Downcalls from parent to child
21 #
22 def destroy(self):
23 del self.parent
24 del self.editor
25 del self.window
26 #
27 def minsize(self, m):
28 return self.cols*m.textwidth('n'), self.rows*m.lineheight()
29 def setbounds(self, bounds):
30 self.bounds = bounds
31 if self.editor:
32 self.editor.move(bounds)
33 def getbounds(self, bounds):
34 if self.editor:
35 return self.editor.getrect()
36 else:
37 return self.bounds
38 def realize(self):
39 self.window = self.parent.getwindow()
40 self.editor = self.window.textcreate(self.bounds)
Guido van Rossuma82a2751991-04-21 19:27:48 +000041 self.editor.settext(self.text)
Guido van Rossum2d844d11991-04-07 13:41:50 +000042 self.parent.need_mouse(self)
43 self.parent.need_keybd(self)
44 self.parent.need_altdraw(self)
45 def draw(self, (d, area)):
46 pass
47 def altdraw(self, area):
48 self.editor.draw(area)
49 #
50 # Event downcalls
51 #
52 def mouse_down(self, detail):
53 x = self.editor.event(WE_MOUSE_DOWN, self.window, detail)
54 def mouse_move(self, detail):
55 x = self.editor.event(WE_MOUSE_MOVE, self.window, detail)
56 def mouse_up(self, detail):
57 x = self.editor.event(WE_MOUSE_UP, self.window, detail)
58 #
59 def keybd(self, (type, detail)):
60 x = self.editor.event(type, self.window, detail)
61 #