'From Cuis 5.0 [latest update: #4961] on 1 November 2021 at 10:13:16 am'!
!classDefinition: #TextParagraphMorph category: 'Morphic-Widgets'!
WidgetMorph subclass: #TextParagraphMorph
	instanceVariableNames: 'textComposition'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'Morphic-Widgets'!
!TextParagraphMorph commentStamp: 'jmv 11/1/2021 09:58:10' prior: 0!
TextParagraphMorph support display of text with emphasis. It can be used on its own, no need to include them in some kind of TextModelMorph / ScrollPane.

Clipping to extent is done, and word wrap is optional. Support all features of Text, including fonts, sizes, emphasis and embedded morphs.

Text display is clipped to the innerBounds of the rectangle, and text composition is normally performed within a rectangle which is innerBounds inset by the margins parameter.


(TextParagraphMorph contents: 'Hello
World!!') openInWorld.


(TextParagraphMorph contents: Utilities defaultTextEditorContents) openInWorld.


| t s |
t := TextParagraphMorph contents: Utilities defaultTextEditorContents.
s := PluggableScrollPane new.
s scroller: t.
s openInWorld.!


!TextParagraphMorph methodsFor: 'accessing' stamp: 'hlsf 10/31/2021 19:52:05'!
contents: aStringOrText
	textComposition textComposed ~= aStringOrText ifTrue: [
		textComposition		
			setModel: (TextModel withText: aStringOrText);
			composeAll.
		extent _ textComposition usedExtent + 8]! !


!TextParagraphMorph methodsFor: 'initialization' stamp: 'jmv 11/1/2021 10:08:39'!
initialize
	super initialize.
	textComposition _ TextComposition new.
	textComposition
		setModel: (TextModel withText: '');
		extentForComposing: extent x @ 9999999;
		composeAll.! !


!TextParagraphMorph methodsFor: 'drawing' stamp: 'hlsf 10/31/2021 20:06:11'!
drawOn: aCanvas
	aCanvas
		textComposition: textComposition
		bounds: self morphLocalBounds 
		color: Theme current text
		selectionColor: `Color red`.! !


!TextParagraphMorph methodsFor: 'geometry' stamp: 'jmv 11/1/2021 10:10:55'!
adjustExtent
"So far, copied verbatim from InnerTextMorph."
	"This is just a suggestion. If we do wordwrap, the width will be honored.
	But the height is whatever is appropriate for the contents!! See #fit"
	self morphExtent: owner viewableExtent! !

!TextParagraphMorph methodsFor: 'geometry' stamp: 'jmv 11/1/2021 10:09:17'!
extentChanged: oldExtent
	"Our extent changed. Reflow text."
	super extentChanged: oldExtent.
			extent x = oldExtent x ifFalse: [
			textComposition
				initialize;
				extentForComposing: extent x @ 9999999;
				composeAll.
				(owner is: #ScrollPane) ifTrue: [
					owner
						updateScrollBarsBounds;
						setScrollDeltas ]].! !

!TextParagraphMorph methodsFor: 'geometry' stamp: 'jmv 11/1/2021 10:12:32'!
privateExtent: aPoint
	| newExtent |
"So far, copied verbatim from InnerTextMorph."

	newExtent _ aPoint.
	(owner is: #ScrollPane) ifTrue: [

		"Just update width. Height is set by ourselves. See #fit"
		newExtent _ aPoint x truncated @ extent y ].

	^ super privateExtent: newExtent! !

"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!

!classDefinition: 'TextParagraphMorph class' category: 'Morphic-Widgets'!
TextParagraphMorph class
	instanceVariableNames: ''!

!TextParagraphMorph class methodsFor: 'instance creation' stamp: 'hlsf 10/31/2021 19:58:58'!
contents: aStringOrText
	^ self new 
		contents: aStringOrText ;
		yourself ! !
