Class new title: Textframe subclassof: Object fields: 'frame window para style lines lastline' declare: 'tab cr space ' Initializations Testing aboutToFrame adjustLines: t1 by: t2 | [lines  t1 stopi_ (lines  t1) stopi + t2. for t1 from: t1 + 1 to: lastline do [lines  t1 slide: t2]] charnearpt: t1 | t2 [self charofpoint: t1 andrect [t2]] charofpoint: t1 | t2 [self charofpoint: t1 andrect [t2]] charofpoint: t1 andrect t2 | t3 t4 t5 t6 t7 t8 t9 t10 [t3 _ 0 max: (self lineofy: t1 y). t6 _ self yofline: t3. [t3 = 0  [t7 _ 1. t9 _ frame minX  (t6 + style lineheight)] t1 y > (t6 + style lineheight)  [self pointofchar: para length + 1 andrect [t10]. t2 value_ t10. para length + 1] t8 _ self printer: false. t8 scanline: lines  t3 at: t6 stopx: t1 x stopchar: (lines  t3) stopi. t7 _ t8 chari. t5 _ t8 rightx. t4 _ t8 leftx. t1 x  (t4 + t5 / 2) or para  t7 = cr  [t9 _ t4  t6] t7 _ t7 + 1. t9 _ t5  t6]. t2 value_ Rectangle new origin: t9 extent: 0  style lineheight. t7] charofpt: t1 | t2 [self charofpoint: t1 andrect [t2]] classInit [space _ 32. cr _ 13. tab _ 9] clear [(frame intersect: window) clear] clearfrom: t1 [((frame origin x  t1 rect: frame corner) intersect: window) clear: white] comp [window comp] displayall | t1 [t1 _ self displaylines: 1 to: lastline. self clearfrom: t1] displayline: t1 at: t2 | t3 t4 t5 t6 [t4 _ self printer: true. t3 _ t2 + style lineheight. [para alignment > 1  [t5 _ frame minX + [para alignment = 4  [t1 padwidth] t1 padwidth / 2]. (window minX  t2 rect: t5  t3) clear: white]]. t4 scanline: t1 at: t2 stopx: window maxX stopchar: t1 stopi. para alignment nomask: 1  [(t4 rightx  t2 rect: window maxX  t3) clear: white]] displaylines: t1 to: t2 | t3 t4 t5 t6 t7 [t1 _ t1 max: (self lineofy: window minY). t2 _ t2 min: (self lineofy: window maxY). t3 _ self yofline: t1. t6 _ t3 + style lineheight. t5 _ self printer: true. for t1 from: t1 to: t2 do [t4 _ lines  t1. [para alignment > 1  [t7 _ frame minX + [para alignment = 4  [t4 padwidth] t4 padwidth / 2]. (window minX  t3 rect: t7  t6) clear: white]]. t5 scanline: t4 at: t3 stopx: window maxX stopchar: t4 stopi. [para alignment nomask: 1  [(t5 rightx  t3 rect: window maxX  t6) clear: white]]. t3 _ t6. t6 _ t6 + style lineheight]. t3] erase [(window inset: 2  2) clear] findmaxx: t1 | t2 t3 t4 [self measureall. t4 _ 0. for t2 to: lastline do [self pointofchar: (lines  t2) stopi andrect [t3]. t3 corner x > t4  [t4 _ t3 corner x]]. t4  t3 corner y] frame [frame] frame: t1 window: t2 para: t3 style: t4 [frame _ t1. window _ t2. para _ t3. style _ t4. [NoteTaker or frame  nil  [] window _ frame intersect: user screenrect. frame _ window]. lines _ Vector new: 32. lastline _ 0. para  nil or frame  nil  [] self measureall] frame_ t1 [frame _ t1. window _ frame] hardcopy | t1 [user displayoffwhile [t1 _ dp0 pressfile: 'frame.press'. self hardcopy: t1. t1 close. t1 toPrinter]] hardcopy: t1 | t2 t3 t4 t5 t6 t7 [for t2 from: ((window inset: 2) minus: window) do [t1 showrect: t2 color: 0]. [para  nil  [self makeParagraph]]. t7 _ para asParagraph. frame = window  [t7 presson: t1 in: (t1 transrect: window)] t5 _ window minY. t4 _ (self charofpt: frame minX + 2  (t5 + 4)) - 1. t6 _ t7 length. while (t4 < t6 and t5 < window maxY) do [t3 _ t4 + 1. t4 _ (self charofpt: frame maxX - 1  (t5 + 4)) min: t6. t2 _ self rectofchar: t4. t5 _ t5 + t2 height. (t7 copy: t3 to: t4) presson: t1 in: (t1 transrect: (frame minX  t2 minY rect: window maxX  (t5 + 10)))]] lastshown | t1 [self charofpoint: window corner andrect [t1]] line: t1 _ t2 [[t1 > lastline  [lastline _ t1]]. [lastline > lines length  [lines _ lines grow]]. lines  t1 _ t2] lineheight [style lineheight] lineofchar: t1 | t2 [for t2 to: lastline do [t1  (lines  t2) stopi  [t2]]. lastline] lineofy: t1 [t1 - frame minY / style lineheight + 1 min: lastline] makeParagraph [para  nil  [para _ 'NIL !' asParagraph]] maxx: t1 | t2 t3 t4 [self measureall. t4 _ 0. for t2 to: lastline do [self pointofchar: (lines  t2) stopi andrect [t3]. t3 corner x > t4  [t4 _ t3 corner x]]. t4  t3 corner y] measureall | t1 t2 t3 [t3 _ 1. t1 _ t3. t2 _ para length. until t1 > t2 do [self line: t3 _ self measurefrom: t1 to: t2. t1 _ (lines  t3) stopi + 1. t3 _ t3 + 1]. self trimLinesTo: t3 - 1] measurefrom: t1 to: t2 | t3 t4 t5 t6 t7 t8 [t3 _ CharLine new starti: t1 stopi: t2 spaces: 0 padwidth: 0. t7 _ self printer: false. t8 _ frame maxX. t7 scanline: t3 at: 0 stopx: t8 stopchar: t2. t4 _ t7 chari. t5 _ t7 spacecount. [t4 = t2 or para  t4 = cr  [t6 _ t8 - t7 rightx. t5 _ 0] t5 > 0  [t4 _ t7 spacei. t6 _ t8 - t7 spacex. [t4 > t1 and para  (t4 - 1) = space  [t5 _ t5 - 1. t6 _ t6 + t7 rightx - t7 leftx] t4 < t2 and para  (t4 + 1) = space  [t4 _ t4 + 1]]. t5 _ 1 max: t5 - 1] t4 _ t4 - 1. t6 _ t8 - t7 leftx]. t3 starti: t1 stopi: t4 spaces: t5 padwidth: t6] outline [window border: 2 color: black] para [para] para: t1 frame: t2 [para _ t1. frame _ t2. self frame: frame window: frame para: para style: DefaultTextStyle] para: t1 frame: t2 style: t3 [para _ t1. frame _ t2. style _ t3. self frame: frame window: frame para: para style: style] pointofchar: t1 | t2 [self pointofchar: t1 andrect [t2]] pointofchar: t1 andrect t2 | t3 t4 t5 t6 [t3 _ self lineofchar: t1. t4 _ self yofline: t3. [t1 > para length  [para length = 0 or para  para length = cr  [t6 _ frame minX  (t4 + style lineheight)] t5 _ self printer: false. t5 scanline: lines  t3 at: t4 stopx: 9999 stopchar: t1 - 1. t6 _ t5 rightx  t4] t5 _ self printer: false. t5 scanline: lines  t3 at: t4 stopx: 9999 stopchar: t1. t6 _ t5 leftx  t4]. t2 value_ Rectangle new origin: t6 extent: 0  style lineheight. t6] printer: t1 [TextScanner new frame: frame window: window para: para style: style printing: t1] ptofchar: t1 | t2 [self pointofchar: t1 andrect [t2]] ptofpt: t1 | t2 [self charofpoint: t1 andrect [t2]. t2 origin] put: t1 at: t2 [para _ t1. self put: para at: t2 centered: false] put: t1 at: t2 centered: t3 | t4 [para _ t1. frame _ t2 rect: 1000  1000. window _ frame. self measureall. self pointofchar: para length + 1 andrect [t4]. window growto: t4 corner. [t3  [window moveby: t2 - window center]]. window _ window inset: 3  2. window clear: white. self show] put: t1 centered: t2 [para _ t1. self put: para at: t2 centered: true] rectofchar: t1 | t2 [self pointofchar: t1 andrect [t2]. t2] replace: t1 to: t2 with: t3 | t4 t5 t6 t7 t8 t9 t10 t11 t12 t13 t14 t15 t16 t17 [para replace: t1 to: t2 by: t3. lastline = 0  [self measureall. self displayall] t13 _ lines copy. t9 _ lastline. t7 _ self lineofchar: t1. t4 _ t7. t8 _ self lineofchar: t2. t11 _ t3 length - (t2 - t1 + 1). t14 _ (lines  t4) starti. [t7 > 1  [t10 _ self measurefrom: (lines  (t7 - 1)) starti to: para length. lines  (t7 - 1) = t10  [] t7 _ t7 - 1. self line: t7 _ t10. t14 _ t10 stopi + 1]]. [t14 > para length  [self trimLinesTo: (t4 - 1 max: 0). para length = 0  [window clear: white. self]]]. t12 _ false. t5 _ t8. until (t12 or t14 > para length) do [t10 _ self measurefrom: t14 to: para length. self line: t4 _ t10. until (t5 > t9 or [t2 _ (t13  t5) stopi + t11. t10 stopi < t2]) do [t2 = t10 stopi  [t15 _ self yofline: t5 + [t11 < 0  [0] 1]. t16 _ self yofline: t4 + [t11 < 0  [0] 1]. t8 _ t4. t12 _ true. t17 _ t9. t5 _ t5 + 1. t6 _ t5 - 1. while [t6 _ 1 + t6. t17  t6] do [t4 _ t4 + 1. self line: t4 _ t13  t6 slide: t11]. self trimLinesTo: t4] t5 _ t5 + 1]. t14 _ t10 stopi + 1. t4 _ t4 + 1]. [t14 > para length  [t8 _ t4 min: lastline. self displaylines: t7 to: t8] (frame minX  t15 rect: window corner) blt: frame minX  t16 mode: storing. self displaylines: t7 to: t8. t16 < t15 and (self yofline: t9 + 1) > window maxY  [t8 _ self lineofy: window maxY. self displaylines: (self lineofy: window maxY - (t15 - t16)) to: t8]]. t8  lastline  [self clearfrom: (self yofline: lastline + 1)]] reversefrom: t1 to: t2 | t3 t4 [[t1 > t2  [t3 _ t1. t1 _ t2. t2 _ t3]]. t3 _ self pointofchar: t1. t4 _ self pointofchar: t2. t1 = t2  [((t3 rect: t3 x + 1  (t3 y + style lineheight)) intersect: window) comp] t3 y = t4 y  [((t3 rect: t4 x  (t4 y + style lineheight)) intersect: window) comp] ((t3 rect: frame corner x  (t3 y + style lineheight)) intersect: window) comp. [t3 y + style lineheight < t4 y  [((frame origin x  (t3 y + style lineheight) rect: frame corner x  t4 y) intersect: window) comp]]. ((frame origin x  t4 y rect: t4 x  (t4 y + style lineheight)) intersect: window) comp] scrolln: t1 [self charofpt: frame corner x  (frame origin y + (t1 * style lineheight))] selectchar: t1 | t2 [self pointofchar: t1 andrect [t2]] show [self measureall. self displayall] show: t1 [para _ t1. self measureall. self displayall] showin: t1 | t2 [t2 _ window. window _ t1. self show. window _ t2] style [style] takeCursor [user cursorloc_ window center] trimLinesTo: t1 | t2 [for t2 from: t1 + 1 to: lastline do [lines  t2 _ nil]. lastline _ t1. lastline < (lines length / 2)  [lines _ lines growby: 0 - (lines length / 2)]] window [window] yofline: t1 [frame minY + (t1 - 1 * style lineheight)]