589 ! |
589 ! |
590 |
590 |
591 at:index put:aString |
591 at:index put:aString |
592 "change a line and redisplay" |
592 "change a line and redisplay" |
593 |
593 |
594 |visibleLine y| |
594 |visibleLine y fontHeightBefore| |
595 |
595 |
|
596 fontHeightBefore := fontHeight. |
596 self withoutRedrawAt:index put:aString. |
597 self withoutRedrawAt:index put:aString. |
|
598 |
597 shown ifTrue:[ |
599 shown ifTrue:[ |
598 "/ synchronous: |
600 "/ synchronous drawing: |
599 self redrawLine:index |
601 |
|
602 "/ this could have changed the font height; |
|
603 "/ must clear all below last line, if it became smaller |
|
604 fontHeightBefore > fontHeight ifTrue:[ |
|
605 (self listLineIsVisible:(self size)) ifTrue:[ |
|
606 self clearRectangle:(margin @ (self yOfVisibleLine:nLinesShown+1)) |
|
607 corner:(width-margin) @ (height-margin). |
|
608 ]. |
|
609 self redrawFromLine:index |
|
610 ] ifFalse:[ |
|
611 self redrawLine:index |
|
612 ]. |
600 |
613 |
601 "/ asynchronous: |
614 "/ asynchronous: |
602 "/ visibleLine := self listLineToVisibleLine:index. |
615 "/ visibleLine := self listLineToVisibleLine:index. |
603 "/ visibleLine notNil ifTrue:[ |
616 "/ visibleLine notNil ifTrue:[ |
604 "/ y := self yOfVisibleLine:visibleLine. |
617 "/ y := self yOfVisibleLine:visibleLine. |
605 "/ self invalidate:((margin @ y) extent:(width@fontHeight)) |
618 "/ self invalidate:((margin @ y) extent:(width@fontHeight)) |
606 "/ ]. |
619 "/ ]. |
607 ] |
620 ] |
608 |
621 |
609 "Modified: 18.4.1997 / 14:52:28 / cg" |
622 "Modified: / 26.7.1998 / 13:36:33 / cg" |
610 ! |
623 ! |
611 |
624 |
612 characterAtLine:lineNr col:colNr |
625 characterAtLine:lineNr col:colNr |
613 "return the character at physical line/col. |
626 "return the character at physical line/col. |
614 The lineNr and colNr arguments start at 1, for the top-left cgaracter. |
627 The lineNr and colNr arguments start at 1, for the top-left cgaracter. |
723 If expand is true, tabs are expanded (to spaces). |
736 If expand is true, tabs are expanded (to spaces). |
724 If scan is true, scan the passed list for nonStrings; |
737 If scan is true, scan the passed list for nonStrings; |
725 otherwise, take the information from the nonStrings arg. |
738 otherwise, take the information from the nonStrings arg. |
726 (the nonStrings information is remembered to optimize later redraws & height computations)." |
739 (the nonStrings information is remembered to optimize later redraws & height computations)." |
727 |
740 |
728 |oldFirst oldLeft nonStringsBefore| |
741 |oldFirst oldLeft nonStringsBefore fontHeightBefore| |
729 |
742 |
730 (aCollection isNil and:[list isNil]) ifTrue:[ |
743 (aCollection isNil and:[list isNil]) ifTrue:[ |
731 "no change" |
744 "no change" |
732 self scrollToTop. |
745 self scrollToTop. |
733 self scrollToLeft. |
746 self scrollToLeft. |
734 ^ self |
747 ^ self |
735 ]. |
748 ]. |
736 list := aCollection. |
749 list := aCollection. |
737 |
750 |
738 nonStringsBefore := includesNonStrings. |
751 nonStringsBefore := includesNonStrings. |
|
752 fontHeightBefore := fontHeight. |
739 includesNonStrings := false. |
753 includesNonStrings := false. |
740 |
754 |
741 list notNil ifTrue:[ |
755 list notNil ifTrue:[ |
742 expand ifTrue:[ |
756 expand ifTrue:[ |
743 self expandTabs |
757 self expandTabs |
747 ] ifFalse:[ |
761 ] ifFalse:[ |
748 includesNonStrings := nonStrings |
762 includesNonStrings := nonStrings |
749 ] |
763 ] |
750 ]. |
764 ]. |
751 ]. |
765 ]. |
752 (includesNonStrings ~~ nonStringsBefore) ifTrue:[self getFontParameters]. |
766 (includesNonStrings ~~ nonStringsBefore) ifTrue:[ |
|
767 self getFontParameters. |
|
768 ]. |
753 |
769 |
754 widthOfWidestLine := nil. "/ i.e. unknown |
770 widthOfWidestLine := nil. "/ i.e. unknown |
755 oldFirst := firstLineShown. |
771 oldFirst := firstLineShown. |
756 oldLeft := leftOffset. |
772 oldLeft := leftOffset. |
757 firstLineShown := 1. |
773 firstLineShown := 1. |
758 leftOffset := 0. |
774 leftOffset := 0. |
759 |
775 |
760 realized ifTrue:[ |
776 realized ifTrue:[ |
761 self computeNumberOfLinesShown. |
777 (includesNonStrings ~~ nonStringsBefore) ifTrue:[ |
|
778 self computeNumberOfLinesShown. |
|
779 ]. |
762 self contentsChanged. |
780 self contentsChanged. |
763 " |
781 " |
764 dont use scroll here to avoid the redraw |
782 dont use scroll here to avoid double redraw |
765 " |
783 " |
766 viewOrigin := 0 @ 0. |
784 viewOrigin := 0 @ 0. |
767 |
785 |
768 oldFirst ~~ firstLineShown ifTrue:[ |
786 oldFirst ~~ firstLineShown ifTrue:[ |
769 self originChanged:0 @ ((oldFirst - 1) * fontHeight negated). |
787 self originChanged:0 @ ((oldFirst - 1) * fontHeight negated). |
770 ]. |
788 ]. |
771 shown ifTrue:[ |
789 shown ifTrue:[ |
772 self redrawFromVisibleLine:1 to:nLinesShown |
790 self redrawFromVisibleLine:1 to:nLinesShown. |
|
791 |
|
792 fontHeightBefore > fontHeight ifTrue:[ |
|
793 (self listLineIsVisible:(self size)) ifTrue:[ |
|
794 "/ self clearRectangle:((margin @ (self yOfVisibleLine:nLinesShown+1)) |
|
795 "/ corner:(width-margin) @ (height-margin)). |
|
796 ]. |
|
797 ] |
773 ] |
798 ] |
774 ] |
799 ] |
775 |
800 |
776 "Modified: 30.8.1995 / 19:07:13 / claus" |
801 "Modified: / 30.8.1995 / 19:07:13 / claus" |
777 "Modified: 5.6.1997 / 11:09:56 / cg" |
802 "Created: / 5.6.1997 / 12:40:06 / cg" |
778 "Created: 5.6.1997 / 12:40:06 / cg" |
803 "Modified: / 26.7.1998 / 13:47:35 / cg" |
779 ! |
804 ! |
780 |
805 |
781 removeIndex:lineNr |
806 removeIndex:lineNr |
782 "delete a line, redraw the view" |
807 "delete a line, redraw the view" |
783 |
808 |
911 self expandTabs |
936 self expandTabs |
912 ] ifFalse:[ |
937 ] ifFalse:[ |
913 includesNonStrings := (list findFirst:[:e | e isString not]) ~~ 0. |
938 includesNonStrings := (list findFirst:[:e | e isString not]) ~~ 0. |
914 ]. |
939 ]. |
915 ]. |
940 ]. |
916 (includesNonStrings ~~ nonStringsBefore) ifTrue:[self getFontParameters]. |
941 (includesNonStrings ~~ nonStringsBefore) ifTrue:[ |
|
942 self getFontParameters. |
|
943 self computeNumberOfLinesShown. |
|
944 ]. |
917 |
945 |
918 "/ new - reposition horizontally if too big |
946 "/ new - reposition horizontally if too big |
919 widthOfWidestLine := nil. "/ i.e. unknown |
947 widthOfWidestLine := nil. "/ i.e. unknown |
920 innerWidth >= self widthOfContents ifTrue:[ |
948 innerWidth >= self widthOfContents ifTrue:[ |
921 viewOrigin x:0. |
949 viewOrigin x:0. |
961 "/ ] |
989 "/ ] |
962 "/ ] |
990 "/ ] |
963 ] |
991 ] |
964 |
992 |
965 "Modified: / 18.12.1995 / 23:27:54 / stefan" |
993 "Modified: / 18.12.1995 / 23:27:54 / stefan" |
966 "Modified: / 6.3.1997 / 15:23:37 / cg" |
|
967 "Created: / 22.4.1998 / 11:11:51 / cg" |
994 "Created: / 22.4.1998 / 11:11:51 / cg" |
|
995 "Modified: / 26.7.1998 / 13:46:49 / cg" |
968 ! |
996 ! |
969 |
997 |
970 size |
998 size |
971 "return the size (i.e. number of lines) |
999 "return the size (i.e. number of lines) |
972 this allows textViews to be used like collections in some places." |
1000 this allows textViews to be used like collections in some places." |
1002 ! |
1030 ! |
1003 |
1031 |
1004 withoutRedrawAt:index put:aString |
1032 withoutRedrawAt:index put:aString |
1005 "change a line without redisplay" |
1033 "change a line without redisplay" |
1006 |
1034 |
1007 |w| |
1035 |w didIncludeNonStrings| |
1008 |
1036 |
1009 self checkForExistingLine:index. |
1037 self checkForExistingLine:index. |
1010 list at:index put:aString. |
1038 list at:index put:aString. |
|
1039 didIncludeNonStrings := includesNonStrings. |
1011 includesNonStrings ifFalse:[ |
1040 includesNonStrings ifFalse:[ |
1012 includesNonStrings := (aString notNil and:[aString isString not]). |
1041 includesNonStrings := (aString notNil and:[aString isString not]). |
1013 ] ifTrue:[ |
1042 ] ifTrue:[ |
1014 (aString isNil or:[aString isString]) ifTrue:[ |
1043 (aString isNil or:[aString isString]) ifTrue:[ |
1015 includesNonStrings := (list findFirst:[:l | l notNil and:[l isString not]]) ~~ 0. |
1044 includesNonStrings := (list findFirst:[:l | l notNil and:[l isString not]]) ~~ 0. |
1016 ] |
1045 ] |
|
1046 ]. |
|
1047 |
|
1048 includesNonStrings ~~ didIncludeNonStrings ifTrue:[ |
|
1049 self getFontParameters. |
|
1050 self computeNumberOfLinesShown |
1017 ]. |
1051 ]. |
1018 |
1052 |
1019 widthOfWidestLine notNil ifTrue:[ |
1053 widthOfWidestLine notNil ifTrue:[ |
1020 aString isString ifTrue:[ |
1054 aString isString ifTrue:[ |
1021 w := font widthOf:aString |
1055 w := font widthOf:aString |
2066 stop := endCol. |
2100 stop := endCol. |
2067 (stop > line size) ifTrue:[stop := line size]. |
2101 (stop > line size) ifTrue:[stop := line size]. |
2068 ^ line copyTo:stop |
2102 ^ line copyTo:stop |
2069 ! |
2103 ! |
2070 |
2104 |
|
2105 listLineIsVisible:listLineNr |
|
2106 "return true, if a particular line is visible" |
|
2107 |
|
2108 |visibleLineNr "{ Class: SmallInteger }"| |
|
2109 |
|
2110 shown ifFalse:[^ false]. |
|
2111 listLineNr isNil ifTrue:[^ false]. |
|
2112 visibleLineNr := listLineNr + 1 - firstLineShown. |
|
2113 ^ (visibleLineNr between:1 and:nLinesShown) |
|
2114 |
|
2115 "Created: / 26.7.1998 / 13:24:16 / cg" |
|
2116 ! |
|
2117 |
2071 listLineToVisibleLine:listLineNr |
2118 listLineToVisibleLine:listLineNr |
2072 "given a list line (1..) return visible linenr or nil" |
2119 "given a list line (1..) return visible linenr or nil" |
2073 |
2120 |
2074 |visibleLineNr "{ Class: SmallInteger }"| |
2121 |visibleLineNr "{ Class: SmallInteger }"| |
2075 |
2122 |
2242 ^ (font widthOf:line from:1 to:tcol) + textStartLeft |
2289 ^ (font widthOf:line from:1 to:tcol) + textStartLeft |
2243 ]. |
2290 ]. |
2244 ^ ((line copyTo:tcol) widthOn:self) + textStartLeft |
2291 ^ ((line copyTo:tcol) widthOn:self) + textStartLeft |
2245 |
2292 |
2246 "Modified: 19.7.1996 / 20:38:54 / cg" |
2293 "Modified: 19.7.1996 / 20:38:54 / cg" |
|
2294 ! |
|
2295 |
|
2296 yOfLine:lineNr |
|
2297 "given a physical lineNr, return y-coordinate in view |
|
2298 - works for fix-height fonts only" |
|
2299 |
|
2300 ^ self yOfVisibleLine:(self listLineToVisibleLine:lineNr) |
|
2301 |
|
2302 "Created: / 26.7.1998 / 13:23:16 / cg" |
2247 ! |
2303 ! |
2248 |
2304 |
2249 yOfVisibleLine:visLineNr |
2305 yOfVisibleLine:visLineNr |
2250 "given a visible lineNr, return y-coordinate in view |
2306 "given a visible lineNr, return y-coordinate in view |
2251 - works for fix-height fonts only" |
2307 - works for fix-height fonts only" |