home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-10 | 6.6 KB | 299 lines | [TEXT/MSET] |
- \ Oct95 JRF Added noClip to Activate: & Deactivate: per MRH suggestion
- \ modified New: to enable outline highliting of inactive TE
-
- \ 25May93 DBH Added lastchar: to commonize a routine.
- \ added kludge to #lines: to fix a bug.
- \ Completely reworked currentline: to fix a speed problem.
-
- \ 15May93 DBH Added textaddr: method to improve readability and code reuse.
- \ Use textaddr: self in getline: .
- \ Deleted addrlinestart: method because it is never reused.
- \ Added lineEnd: method, so we can move there easily.
- \ Delte general class declaration.
- \ 11May93 DBH fixed getLine: so null is returned if last char in TE is
- \ a carriage return. Added getpoint: and idle: methods.
-
- need terecord
-
- \ some routines to handle the clipboard
-
- : TODESK ( -- oserr )
- 0 call ZeroScrap IF exit THEN \ out if error
- 0 \ room for oserr
- global TEScrpLength w@ \ length
- 'type TEXT \ theType
- global TEScrpHandle @ @
- call PutScrap
- ;
-
- variable OFFSET \ used in GetScrap call
-
- : FROMDESK ( -- oserr )
- 0 \ room for result
- global TEScrpHandle @
- 'type TEXT \ theType
- offset
- call GetScrap
- dup 0>= IF global TEScrpLength w! \ store scrap length
- false \ no error
- THEN
- ;
-
-
-
- : SELCUT
- actW IF cut: [ actW ] THEN ;
-
- : SELCOPY
- actW IF copy: [ actW ] THEN ;
-
- : SELPASTE
- actW IF paste: [ actW ] THEN ;
-
- : SELCLEAR
- actW IF clear: [ actW ] THEN ;
-
-
-
- :CLASS TextEdit super{ object }
-
- handle TEHandle
-
- :m new: { dest view -- }
- 0 \ space for returned handle
- dest
- view
- call TENew
- put: TEHandle
- word0 2 1 pack \ 2 selects OutlineHilite feature
- get: TEHandle \ 1 sets its flag
- call TEFeatureFlag
- makeint ;m \ drop the returned int
-
- :m handle: ( -- tehandle )
- get: TEHandle ;m
-
- :m ptr: ( -- teRecord )
- ptr: TEHandle ;m
-
-
- :m noWrap: \ **
- ptr: self noWrap: teRecord ;m
-
- :m WrapIt:
- ptr: self wrapIt: teRecord ;m
-
-
- :m SETVIEWRECT: { left top rt bot \ adr -- }
- ptr: TEHandle -> adr \ ptr: TEHandle setview: teRecord ;m ?? \ 19May93 DBH
- top adr 8 + w! left adr 10 + w!
- bot adr 12 + w! rt adr 14 + w! ;m
-
-
- :m LINEHEIGHT: ( -- n )
- ptr: TEHandle lineHeight: teRecord ;m
-
- \ :m #lines: ( -- n)
- \ ptr: TEHandle #lines: teRecord \ note message to class
- \ ;m
-
- :m cut:
- get: TEHandle call TECut
- todesk drop ;m \ not looking at error
-
- :m copy:
- get: TEHandle call TECopy
- todesk drop ;m \ not looking at error
-
- :m paste:
- fromdesk IF exit THEN \ out if error
- get: TEHandle call TEPaste ;m
-
- :m clear:
- 0 call SetOrigin
- get: TEHandle call TEDelete ;m
-
- :m update: \ ( rptr -- )
- 0 call SetOrigin
- get: TEHandle
- call TEUpdate
- ;m
-
- :m SCROLL: \ ( dx dy -- )
- 0 call SetOrigin
- pack get: TEHandle call TEScroll ;m
-
-
- :m size: ( -- len ) \ returns the length of the text
- ptr: TEHandle size: teRecord ;m \ note message to class
-
- :m TextHandle: \ ( -- hndl )
- 0 get: TEhandle call TEGetText ;m
-
- :m textaddr: \ ( -- $addr ) \ addr of the first char of the TE text
- textHandle: self @ ;m
-
- :m get: ( -- $addr len )
- textaddr: self
- size: self ;m
-
- :m put: ( $addr len -- )
- get: TEHandle call TESetText
- update: self ;m
-
- :m insert: ( $addr len -- )
- get: TEHandle call TEInsert
- ;m
-
- :m activate:
- noClip
- get: TEHandle call TEActivate ;m
-
- :m deactivate:
- noClip
- get: TEHandle call TEDeactivate ;m
-
- :m release:
- get: TEHandle call TEDispose
- clear: TEHandle ;m
-
- :m click:
- where: fEvent g->l
- mods: fevent $ 200 and makeint \ extend if shift key
- handle: self call TEClick
- ;m
-
- :m select: ( start end -- ) \ hilites the given range
- get: TEHandle call TESetSelect ;m
-
- :m selectAll: \ hilites all of the text
- 0 ( start)
- size: self ( end)
- select: self ;m
-
- :m selStart: ( -- n )
- ptr: TEHandle selStart: teRecord ;m
-
- :m selEnd: ( -- n )
- ptr: TEHandle selEnd: teRecord ;m
-
- :m lastchar: ( -- char ) \ return last character in TE
- textaddr: self size: self 1- + c@ ;m
-
-
- :m key: { char \ bSel eSel -- }
- \ TE for some reason doesn't handle forward delete, so we
- \ have to special-case it.
-
- char 127 =
- IF \ yes, it's forward delete
- selStart: self -> bSel
- selEnd: self -> eSel
- bSel eSel =
- IF eSel size: self >= ?EXIT
- eSel 1+ dup select: self
- ELSE
- eSel size: self <
- IF bSel eSel 1+ select: self THEN
- THEN
- 8 -> char
- THEN
- char makeint
- get: TEHandle
- call TEKey ;m
-
-
- 0 value kludge
-
- :m #lines: ( -- n)
- 0 -> kludge
- ptr: TEHandle #lines: teRecord \ note message to class
- lastchar: self ret = IF -1 -> kludge 1+ THEN \ kludge Apple line numbering scheme!!
- ;m
-
- \ given the zero-based line number, return the character# of the start of
- \ that line
-
- :m at: { n -- linestart }
- n kludge + 1 + #lines: self > abort" TE linestart index out of range"
-
- ptr: TEHandle addrLineStart: teRecord n 2 * + w@ ;m
-
- :m GETPOINT: { offset -- x y } \ given the char offset into the text, return the
- \ corresponding x y location See IM V-269.
- 0 offset makeint get: TEHandle call TEGetPoint unpack ;m
-
- :m currentLine: ( -- n ) \ **
- selend: self GETPOINT: self ( x y ) nip ( cursor.y )
- ptr: TEHandle ( dest) gettopy: rect - ( cursor.y - dest.top )
-
- lineheight: self / 1-
-
- selend: self size: self = \ true if at last char
- size: self and \ and if not an empty size
- IF
- lastchar: self ret =
- IF \ uh-oh, handle special case where last char is a ret
- 1+
- THEN
- THEN
- ;m
-
- :m getLine: { \ l -- addr len }
- size: self 0= IF pad 0 exit THEN \ return nil and get out if no text
- currentLine: self -> l
- #lines: self 1 - l =
- IF \ we are on the last line
- lastchar: self
- ret =
- IF \ we are on the last line AND just beyond a carriage return!
- pad 0 exit \ return nil and get out here
- THEN
-
- textaddr: self l at: self + ( addr )
- size: self
- l at: self - ( len)
-
- ELSE
-
- textaddr: self l at: self + ( addr )
-
- l 1 + at: self
- l at: self - 1 - ( len )
- THEN
- ;m
-
- :m LINEEND: { \ len pos -- pos } \ return the character position corresponding to the
- \ end of the last line of the current selection.
- selend: self size: self =
- IF \ we are at the end of the text
- size: self
- ELSE
- currentline: self at: self ( linestart ) -> pos
- getline: self nip -> len
- pos len +
- THEN ;m
-
- :m getselect: ( -- addr len ) \ returns hilited selection
- ptr: TEHandle getselect: teRecord ;m
-
-
- :m IDLE: \ May94 mh - Setting cursor now moved to TEScroller
- get: TEHandle call TEIdle
- ;m
-
- :m DUMP:
- selstart: self
- selend: self
- currentline: self
- lineEnd: self
- size: self { ss se cl le sz -- }
- \ ss " selstart " >debug
- \ se " selend " >debug
- \ cl " currentline " >debug
- \ le " lineEnd " >debug
- \ sz " size " >debug
- ;m
-
- ;CLASS
-