'From Cuis 5.0 [latest update: #4338] on 5 August 2020 at 12:29:55 pm'!

!Morph methodsFor: 'updating' stamp: 'jmv 8/5/2020 12:17:02'!
invalidateBounds
	"Report that the area occupied by this morph should be redrawn, 
	but most likely we are not going to be redrawn on it, or maybe we'll not be fully visible. See senders."

	self invalidateDisplayRect: self displayBoundsOrBogus fromSubmorph: nil for: owner.! !


!Morph methodsFor: 'drawing' stamp: 'jmv 8/5/2020 12:23:18'!
visible: aBoolean
	"set the 'visible' attribute of the receiver to aBoolean
	Store value of 'hidden', because flags default to false."

	self visible == aBoolean
		ifTrue: [ ^ self ].
	aBoolean
		ifTrue: [ self redrawNeeded ]
		ifFalse: [ self invalidateBounds ].
	self privateFlagAt: 3 put: aBoolean not.
	owner ifNotNil: [ owner someSubmorphPositionOrExtentChanged ].! !

!Morph methodsFor: 'submorphs-add/remove' stamp: 'jmv 8/5/2020 12:04:47'!
removeMorph: aMorph
	"Remove the given morph from my submorphs"

	aMorph owner == self ifFalse: [^self].
	aMorph redrawNeeded.
	self privateRemove: aMorph.
	aMorph privateOwner: nil.
	self removedMorph: aMorph.
	self someSubmorphPositionOrExtentChanged.! !

!Morph methodsFor: 'private' stamp: 'jmv 8/5/2020 12:17:14'!
privateAddMorph: aMorph atIndex: index

	| oldIndex myWorld itsWorld oldOwner |
	(self canAdd: aMorph) ifFalse: [
		^self error: 'We can''t add requested morph. Maybe install and activate VectorGraphics canvas.' ].
	((index >= 1) and: [index <= (submorphs size + 1)])
		ifFalse: [^ self error: 'index out of range'].
	myWorld _ self world.
	oldOwner _ aMorph owner.
	(oldOwner == self and: [(oldIndex _ submorphs indexOf: aMorph) > 0]) ifTrue:[
		"aMorph's position changes within in the submorph chain"
		oldIndex < index ifTrue:[
			"moving aMorph to back"
			submorphs replaceFrom: oldIndex to: index-2 with: submorphs startingAt: oldIndex+1.
			submorphs at: index-1 put: aMorph.
		] ifFalse:[
			"moving aMorph to front"
			oldIndex-1 to: index by: -1 do:[:i|
				submorphs at: i+1 put: (submorphs at: i)].
			submorphs at: index put: aMorph.
		].
	] ifFalse:[
		"adding a new morph"
		oldOwner ifNotNil:[
			itsWorld _ aMorph world.
			itsWorld ifNotNil: [aMorph invalidateBounds].
			oldOwner privateRemove: aMorph.
			oldOwner removedMorph: aMorph.
		].
		aMorph privateOwner: self.
		submorphs _ submorphs copyReplaceFrom: index to: index-1 with: (Array with: aMorph).
		(itsWorld == myWorld) ifFalse: [aMorph intoWorld: myWorld].
	].
	myWorld ifNotNil: [aMorph invalidateBounds].
	self someSubmorphPositionOrExtentChanged.
	oldOwner == self ifFalse: [
		self addedMorph: aMorph.
		aMorph noteNewOwner: self ].
! !

!Morph methodsFor: 'previewing' stamp: 'jmv 8/5/2020 12:21:15'!
endPreview

	self previewing ifTrue: [
		owner notNil ifTrue: [
			self visible: self visibleBeforePreview.
			owner addMorph: self inFrontOf: self morphBehindBeforePreview ].
		self previewing: false. ]! !


!DamageRecorder methodsFor: 'recording' stamp: 'jmv 8/5/2020 11:44:26'!
damageReportedNotVisibleAndCarriedByHand
	| answer |
	answer _ OrderedCollection new.
	self pvtAccessProtect critical: [
		damageByRoot keysAndValuesDo: [ :m :r |
			(m isNil or: [
				m visible not or: [m owner isNil or: [m owner is: #HandMorph]]]) ifTrue: [
					answer add: r]]].
	^answer! !

