Merged 6f3514837c99 and a18a03c5c572 (branch delegated_gc) delegated_gc_text-view-selection-refactoring
authorJan Vrany <jan.vrany@fit.cvut.cz>
Thu, 05 Jun 2014 08:22:27 +0100
branchdelegated_gc_text-view-selection-refactoring
changeset 5087 001f9ac320b2
parent 5086 6f3514837c99 (current diff)
parent 5023 a18a03c5c572 (diff)
child 5088 1c8a17975b43
Merged 6f3514837c99 and a18a03c5c572 (branch delegated_gc)
EditTextView.st
ListView.st
TextCollector.st
TextView.st
--- a/EditTextView.st	Wed Jun 04 22:40:15 2014 +0100
+++ b/EditTextView.st	Thu Jun 05 08:22:27 2014 +0100
@@ -1458,6 +1458,39 @@
 
 !EditTextView methodsFor:'accessing-dimensions'!
 
+absoluteXOfPosition:positionInText 
+    |accumulatedX container|
+
+    accumulatedX := 0.
+    container := self.
+    [ container notNil ] whileTrue:[
+        accumulatedX := accumulatedX + container origin x.
+        container := container isTopView ifFalse:[
+                    container container
+                ] ifTrue:[ nil ].
+    ].
+    ^ (self xOfPosition:positionInText) + accumulatedX
+
+    "Created: / 16-02-2010 / 10:05:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+absoluteYOfCursor
+
+    | accumulatedY container |
+    accumulatedY := 0.
+    container := self.
+    [ container notNil ] whileTrue:[
+        accumulatedY := accumulatedY + container origin y.
+        container := container isTopView 
+            ifFalse:[container container]
+            ifTrue:[nil].
+    ].
+    ^(self yOfCursor) + accumulatedY
+
+    "Created: / 27-05-2005 / 07:45:53 / janfrog"
+    "Modified: / 27-05-2005 / 23:03:40 / janfrog"
+!
+
 xOfCursor
     |point|
 
@@ -1482,6 +1515,34 @@
     ^self xOfCol:cursorCol inVisibleLine:cursorVisibleLine.
 
     "Created: / 27-05-2005 / 07:43:41 / janfrog"
+!
+
+xOfPosition: positionInText
+
+    | line col |
+    line := self lineOfCharacterPosition: positionInText.
+    col  := positionInText - (self characterPositionOfLine:line col:1) + 1.
+    ^
+        (self xOfCol:col inVisibleLine:(self listLineToVisibleLine: line))
+            - viewOrigin x.
+
+    "Created: / 16-02-2010 / 10:04:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
+yOfCursor
+
+    ^self yOfVisibleLine:cursorVisibleLine.
+
+    "Created: / 27-05-2005 / 07:43:41 / janfrog"
+!
+
+yOfPosition: positionInText
+
+    | line |
+    line := self lineOfCharacterPosition: positionInText.
+    ^self yOfVisibleLine:(self listLineToVisibleLine: line)
+
+    "Created: / 16-02-2010 / 10:08:21 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !EditTextView methodsFor:'accessing-look'!
@@ -4398,7 +4459,7 @@
      This is not prepared to encounter special chars (except TAB)
      in the string."
 
-    |line lineSize newLine newLineSpecies endCol|
+    |line lineSize newLine endCol|
 
     self checkModificationsAllowed ifFalse:[ ^ self].
 
@@ -4410,14 +4471,21 @@
     (lineSize == 0) ifTrue:[
         newLine := aString species new:endCol.
     ] ifFalse: [
-        (aString isText or:[aString bitsPerCharacter > line bitsPerCharacter]) ifTrue:[ 
-            newLineSpecies := aString stringSpecies
-        ] ifFalse:[
-            newLineSpecies := line species
-        ].
-
-        newLine := newLineSpecies new:(endCol max:lineSize).
-        newLine replaceFrom:1 to:lineSize with:line startingAt:1.
+        (endCol > lineSize) ifTrue: [
+            aString isText ifTrue:[
+                newLine := aString species new:endCol.
+            ] ifFalse:[
+                newLine := line species new:endCol.
+            ].
+            newLine replaceFrom:1 to:lineSize with:line startingAt:1.
+        ] ifFalse: [
+            aString isText ifTrue:[
+                newLine := aString species new:line size.
+                newLine replaceFrom:1 to:lineSize with:line startingAt:1.
+            ] ifFalse:[
+                newLine := line copy.
+            ]
+        ]
     ].
     newLine replaceFrom:colNr with:aString.
     (aString includes:(Character tab)) ifTrue:[
@@ -8827,11 +8895,11 @@
 !EditTextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.605 2014-05-30 21:20:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.604.2.1 2014-05-08 08:30:56 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.605 2014-05-30 21:20:49 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/EditTextView.st,v 1.604.2.1 2014-05-08 08:30:56 stefan Exp $'
 !
 
 version_HG
--- a/ListView.st	Wed Jun 04 22:40:15 2014 +0100
+++ b/ListView.st	Thu Jun 05 08:22:27 2014 +0100
@@ -11,8 +11,6 @@
 "
 "{ Package: 'stx:libwidg' }"
 
-"{ Package: 'stx:libwidg' }"
-
 View subclass:#ListView
 	instanceVariableNames:'list firstLineShown nFullLinesShown nLinesShown fgColor bgColor
 		partialLines leftMargin topMargin textStartLeft textStartTop
--- a/TextView.st	Wed Jun 04 22:40:15 2014 +0100
+++ b/TextView.st	Thu Jun 05 08:22:27 2014 +0100
@@ -289,15 +289,15 @@
     "extract values from the styleSheet and cache them in class variables"
 
     <resource: #style (#'textView.background'
-		       #'text.selectionForegroundColor'
-		       #'text.selectionBackgroundColor'
-		       #'text.alternativeSelectionForegroundColor'
-		       #'text.alternativeSelectionBackgroundColor'
-		       #'textView.font'
-		       #'text.wordSelectCatchesBlanks'
-		       #'text.st80Selections')>
-
-    DefaultViewBackground := StyleSheet colorAt:'textView.background' default:White.
+                       #'text.selectionForegroundColor'
+                       #'text.selectionBackgroundColor'
+                       #'text.alternativeSelectionForegroundColor'
+                       #'text.alternativeSelectionBackgroundColor'
+                       #'textView.font'
+                       #'text.wordSelectCatchesBlanks'
+                       #'text.st80Selections')>
+
+    DefaultViewBackground := StyleSheet colorAt:'textView.background' default:Color white.
     DefaultSelectionForegroundColor := StyleSheet colorAt:'text.selectionForegroundColor'.
     DefaultSelectionBackgroundColor := StyleSheet colorAt:'text.selectionBackgroundColor'.
 "/    DefaultAlternativeSelectionForegroundColor := StyleSheet colorAt:'text.alternativeSelectionForegroundColor' default:DefaultSelectionForegroundColor.
@@ -708,11 +708,11 @@
 setupForFile:aFileName
     "setup a textView on a file; return the textView"
 
-    |textView f|
+    |textView|
 
     textView := self setupEmpty.
     aFileName notNil ifTrue:[
-	textView setupForFile:aFileName.
+        textView setupForFile:aFileName.
     ].
 
     ^ textView
@@ -812,17 +812,17 @@
     |encodingSymOrNil|
 
     encodingSymOrNil := encodingArg isNil
-			    ifTrue:[#'iso10646-1']
-			    ifFalse:[encodingArg asSymbol].
-
-    characterEncoding ~~ encodingSymOrNil ifTrue:[
-	"/ TODO: reencode contents if required.
-	(list size ~~ 0
-	and:[ list contains:[:line | line size > 0]]) ifTrue:[
-	    (self confirm:'Your text may need to be re-coded - this is not yet supported.\\Proceed ?')
-	    ifFalse:[^ self].
-	].
-	characterEncoding := encodingSymOrNil.
+                            ifTrue:[#'iso10646-1']
+                            ifFalse:[encodingArg asSymbol].
+
+    gc characterEncoding ~~ encodingSymOrNil ifTrue:[
+        "/ TODO: reencode contents if required.
+        (list size ~~ 0
+        and:[ list contains:[:line | line size > 0]]) ifTrue:[
+            (self confirm:'Your text may need to be re-coded - this is not yet supported.\\Proceed ?')
+            ifFalse:[^ self].
+        ].
+        super characterEncoding:encodingSymOrNil.
     ].
 
     "Modified (format): / 25-01-2012 / 00:28:27 / cg"
@@ -1116,10 +1116,10 @@
      The default is defined by the styleSheet;
      typically black-on-green for color displays and white-on-black for b&w displays."
 
-    selectionFgColor := color1 onDevice:device.
-    selectionBgColor := color2 onDevice:device.
+    selectionFgColor := color1 onDevice:self graphicsDevice.
+    selectionBgColor := color2 onDevice:self graphicsDevice.
     self hasSelection ifTrue:[
-	self invalidate
+        self invalidate
     ]
 
     "Modified: 29.5.1996 / 16:22:15 / cg"
@@ -1205,68 +1205,68 @@
      matchingFamilyFonts matchingFamilyFaceFonts matchingFamilyFaceStyleFonts
      matchingFamilyFaceStyleSizeFonts|
 
-    fontsEncoding := font encoding.
+    fontsEncoding := gc font encoding.
 
     pref := FontDescription preferredFontEncodingFor:newEncoding.
 
     (pref match:fontsEncoding) ifTrue:[
-	^ self
+        ^ self
     ].
     (CharacterEncoder isEncoding:pref subSetOf:fontsEncoding) ifTrue:[
-	^ self
+        ^ self
     ].
 
     filter := [:f | |coding|
-		    (coding := f encoding) notNil
-		    and:[pref match:coding]].
-
-    device flushListOfAvailableFonts.
-    matchingFonts := device listOfAvailableFonts select:filter.
-    matchingFamilyFonts := matchingFonts select:[:f | f family = font family].
-    matchingFamilyFaceFonts := matchingFamilyFonts select:[:f | f face = font face].
-    matchingFamilyFaceStyleFonts := matchingFamilyFaceFonts select:[:f | f style = font style].
-    matchingFamilyFaceStyleSizeFonts := matchingFamilyFaceStyleFonts select:[:f | f size = font size].
+                    (coding := f encoding) notNil
+                    and:[pref match:coding]].
+
+    self graphicsDevice flushListOfAvailableFonts.
+    matchingFonts := self graphicsDevice listOfAvailableFonts select:filter.
+    matchingFamilyFonts := matchingFonts select:[:f | f family = gc font family].
+    matchingFamilyFaceFonts := matchingFamilyFonts select:[:f | f face = gc font face].
+    matchingFamilyFaceStyleFonts := matchingFamilyFaceFonts select:[:f | f style = gc font style].
+    matchingFamilyFaceStyleSizeFonts := matchingFamilyFaceStyleFonts select:[:f | f size = gc font size].
     matchingFamilyFaceStyleSizeFonts size > 0 ifTrue:[
-	defaultFont := matchingFamilyFaceStyleSizeFonts first
+        defaultFont := matchingFamilyFaceStyleSizeFonts first
     ] ifFalse:[
-	matchingFamilyFaceStyleFonts size > 0 ifTrue:[
-	    defaultFont := matchingFamilyFaceStyleFonts first
-	] ifFalse:[
-	    matchingFamilyFaceFonts size > 0 ifTrue:[
-		defaultFont := matchingFamilyFaceFonts first
-	    ] ifFalse:[
-		matchingFamilyFonts size > 0 ifTrue:[
-		    defaultFont := matchingFamilyFonts first
-		] ifFalse:[
-		    matchingFonts size > 0 ifTrue:[
-			defaultFont := matchingFonts first
-		    ].
-		].
-	    ].
-	].
+        matchingFamilyFaceStyleFonts size > 0 ifTrue:[
+            defaultFont := matchingFamilyFaceStyleFonts first
+        ] ifFalse:[
+            matchingFamilyFaceFonts size > 0 ifTrue:[
+                defaultFont := matchingFamilyFaceFonts first
+            ] ifFalse:[
+                matchingFamilyFonts size > 0 ifTrue:[
+                    defaultFont := matchingFamilyFonts first
+                ] ifFalse:[
+                    matchingFonts size > 0 ifTrue:[
+                        defaultFont := matchingFonts first
+                    ].
+                ].
+            ].
+        ].
     ].
 
     defaultFont isNil ifTrue:[
-	defaultFont isNil ifTrue:[
-	    self warn:'Your display does not seem to provide any ' , newEncoding allBold , ' encoded font.\\Please select an appropriate font (iso10646-Unicode recommended)'.
-	    pref := #'iso10646-1'.
-	]
+        defaultFont isNil ifTrue:[
+            self warn:'Your display does not seem to provide any ' , newEncoding allBold , ' encoded font.\\Please select an appropriate font (iso10646-Unicode recommended)'.
+            pref := #'iso10646-1'.
+        ]
     ].
 
     msg := 'Switch to a %1 encoded font ?'.
     (ask not or:[self confirm:(resources stringWithCRs:msg with:pref)])
     ifTrue:[
-	self withWaitCursorDo:[
-	    f := FontPanel
-		    fontFromUserInitial:defaultFont
-		    title:(resources string:'Font selection')
-		    filter:filter
-		    encoding:pref.
-
-	    f notNil ifTrue:[
-		self font:f.
-	    ]
-	]
+        self withWaitCursorDo:[
+            f := FontPanel
+                    fontFromUserInitial:defaultFont
+                    title:(resources string:'Font selection')
+                    filter:filter
+                    encoding:pref.
+
+            f notNil ifTrue:[
+                self font:f.
+            ]
+        ]
     ]
 
     "Created: 26.10.1996 / 12:06:54 / cg"
@@ -1839,8 +1839,8 @@
 
 mapped
     super mapped.
-    selectionFgColor := selectionFgColor onDevice:device.
-    selectionBgColor := selectionBgColor onDevice:device.
+    selectionFgColor := selectionFgColor onDevice:self graphicsDevice.
+    selectionBgColor := selectionBgColor onDevice:self graphicsDevice.
 !
 
 quadClickX:x y:y
@@ -1868,8 +1868,8 @@
 
     super fetchDeviceResources.
 
-    selectionFgColor notNil ifTrue:[selectionFgColor := selectionFgColor onDevice:device].
-    selectionBgColor notNil ifTrue:[selectionBgColor := selectionBgColor onDevice:device].
+    selectionFgColor notNil ifTrue:[selectionFgColor := selectionFgColor onDevice:self graphicsDevice].
+    selectionBgColor notNil ifTrue:[selectionBgColor := selectionBgColor onDevice:self graphicsDevice].
 
     "Created: 14.1.1997 / 00:14:33 / cg"
 !
@@ -1884,21 +1884,21 @@
     selectionFgColor isNil ifTrue:[selectionFgColor := bgColor].
     selectionBgColor := DefaultSelectionBackgroundColor.
     selectionBgColor isNil ifTrue:[
-	device hasColors ifTrue:[
-	    DefaultSelectionForegroundColor isNil ifTrue:[
-		selectionFgColor := fgColor
-	    ].
-	    selectionBgColor := Color green
-	] ifFalse:[
-	    device hasGrayscales ifTrue:[
-		DefaultSelectionForegroundColor isNil ifTrue:[
-		    selectionFgColor := fgColor
-		].
-		selectionBgColor := Color grey
-	    ] ifFalse:[
-		selectionBgColor := fgColor
-	    ]
-	]
+        self graphicsDevice hasColors ifTrue:[
+            DefaultSelectionForegroundColor isNil ifTrue:[
+                selectionFgColor := fgColor
+            ].
+            selectionBgColor := Color green
+        ] ifFalse:[
+            self graphicsDevice hasGrayscales ifTrue:[
+                DefaultSelectionForegroundColor isNil ifTrue:[
+                    selectionFgColor := fgColor
+                ].
+                selectionBgColor := Color grey
+            ] ifFalse:[
+                selectionBgColor := fgColor
+            ]
+        ]
     ].
 
     "Modified: / 22-01-1997 / 11:57:53 / cg"
@@ -1965,7 +1965,7 @@
     |newFont|
 
     self withWaitCursorDo:[
-        newFont := FontPanel fontFromUserInitial:font.
+        newFont := FontPanel fontFromUserInitial:gc font.
     ].
     newFont notNil ifTrue:[
         self font:newFont.
@@ -2067,9 +2067,9 @@
 fontLargerOrSmaller:largerBoolean
     |newFont|
 
-    newFont := font asSize:(largerBoolean
-                            ifTrue:[font size + 1]
-                            ifFalse:[(font size-1) max:4]).
+    newFont := gc font asSize:(largerBoolean
+                            ifTrue:[gc font size + 1]
+                            ifFalse:[(gc font size-1) max:4]).
     self font:newFont.
 
     "Modified: / 27-02-1996 / 00:53:51 / cg"
@@ -2550,7 +2550,7 @@
 
     self removeTrailingWhitespace.
 
-    encoder := CharacterEncoder encoderToEncodeFrom:characterEncoding into:encodingSymOrNil.
+    encoder := CharacterEncoder encoderToEncodeFrom:gc characterEncoding into:encodingSymOrNil.
     encoder isNullEncoder ifTrue:[
         (list contains:[:lineOrNil|
                             |s|
@@ -2575,7 +2575,7 @@
         startNr := 1.
         nLines := list size.
         [startNr <= nLines] whileTrue:[
-            string := list 
+            string := list
                         asStringWithCRsFrom:startNr
                         to:((startNr + 1000) min:nLines)
                         compressTabs:compressTabs.
@@ -2601,27 +2601,27 @@
      line separation. This is required, to allow for proper handling of
      national characters, such as A-diaresis ..."
 
-    |italicFont boldFont fA iA bA|
-
-    font := font onDevice:device.
-    italicFont := font asItalic onDevice:device.
-    boldFont := font asBold onDevice:device.
-
-    fontHeight := font height max:(italicFont height max:(boldFont height)).
+    |italicFont boldFont fA iA bA currentDeviceFont|
+
+    currentDeviceFont := gc createFontOnDevice.
+    italicFont := currentDeviceFont asItalic onDevice:gc device.
+    boldFont := currentDeviceFont asBold onDevice:gc device.
+
+    fontHeight := currentDeviceFont height max:(italicFont height max:(boldFont height)).
     includesNonStrings == true ifTrue:[
         "/ for now, we do not support variable height entries ...
         fontHeight := fontHeight max:(list first heightOn:self).
     ].
     fontHeight := fontHeight + lineSpacing.
-    fA := font ascent. 
-    "/ fA := font maxAscent. 
-    iA := italicFont ascent. 
-    "/ iA := italicFont maxAscent. 
-    bA := boldFont ascent. 
-    "/ bA := boldFont maxAscent. 
+    fA := currentDeviceFont ascent.
+    "/ fA := font maxAscent.
+    iA := italicFont ascent.
+    "/ iA := italicFont maxAscent.
+    bA := boldFont ascent.
+    "/ bA := boldFont maxAscent.
     fontAscent := fA max:(iA max:bA).
-    fontWidth := font width.
-    fontIsFixedWidth := font isFixedWidth and:[ italicFont isFixedWidth and:[ boldFont isFixedWidth ]].
+    fontWidth := currentDeviceFont width.
+    fontIsFixedWidth := currentDeviceFont isFixedWidth and:[ italicFont isFixedWidth and:[ boldFont isFixedWidth ]].
 
     "Modified: 22.5.1996 / 12:02:47 / cg"
     "Created: 22.5.1996 / 12:18:34 / cg"
@@ -4757,9 +4757,9 @@
     selectionStartLine isNil ifTrue:[^ nil].
     sel := self textFromLine:selectionStartLine col:(selectionStartCol max:1) toLine:selectionEndLine col:selectionEndCol.
     sel notNil ifTrue:[
-	(characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[
-	    sel := sel encodeFrom:characterEncoding into:#'iso10646-1'
-	].
+        (gc characterEncoding ? #'iso10646-1' "eg unicode") ~~ #'iso10646-1' ifTrue:[
+            sel := sel encodeFrom:gc characterEncoding into:#'iso10646-1'
+        ].
     ].
     ^ sel
 
@@ -4801,10 +4801,10 @@
 setPrimarySelection
     "can be redefined for notification or special actions"
 
-    device notNil ifTrue:[
-	"On X11, be nice and set the PRIMARY selection.
-	 (#setPrimaryText:ownerView: is void in DeviceWorkstation)"
-	device setPrimaryText: self selectionAsString ownerView: self.
+    self graphicsDevice notNil ifTrue:[
+        "On X11, be nice and set the PRIMARY selection.
+         (#setPrimaryText:ownerView: is void in DeviceWorkstation)"
+        self graphicsDevice setPrimaryText: self selectionAsString ownerView: self.
     ].
 
     "Created: / 17-04-2012 / 20:59:32 / Jan Vrany <jan.vrany@fit.cvut.cz>"
@@ -4891,11 +4891,11 @@
 !TextView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.374 2014-05-31 02:36:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.373.2.1 2014-05-08 08:30:56 stefan Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.374 2014-05-31 02:36:23 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/TextView.st,v 1.373.2.1 2014-05-08 08:30:56 stefan Exp $'
 !
 
 version_HG