[BUG][FIX] TextMorph focus handling

Andreas Raab andreas.raab at gmx.de
Sat Jun 18 23:20:19 UTC 2005


"Change Set:		FixTextFocus
Date:			18 June 2005
Author:			Andreas Raab

This change set fixes text morph focus handling. When lazily 
(re)creating the text morph's paragraph we need to know whether the text 
morph holds the keyboard focus but this information can be hard to 
retrieve - it outright fails for example, when we are in a project 
transition.

This change set simply makes it so that text morphs explicitly remember 
whether they hold the focus or not."
-------------- next part --------------
'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 18 June 2005 at 4:18:39 pm'!
"Change Set:		FixTextFocus
Date:			18 June 2005
Author:			Andreas Raab

This change set fixes text morph focus handling. When lazily (re)creating the text morph's paragraph we need to know whether the text morph holds the keyboard focus but this information can be hard to retrieve - it outright fails for example, when we are in a project entering transition.

This change set simply makes it so that text morphs explicitly remember whether they hold the focus or not."!

RectangleMorph subclass: #TextMorph
	instanceVariableNames: 'textStyle text wrapFlag paragraph editor container predecessor successor backgroundColor margins focused'
	classVariableNames: 'CaretForm'
	poolDictionaries: ''
	category: 'Morphic-Basic'!

!TextMorph methodsFor: 'accessing' stamp: 'ar 6/18/2005 16:14'!
focused
	"Answer whether the receiver currently holds the keyboard focus."
	^focused ifNil:[false]! !

!TextMorph methodsFor: 'accessing' stamp: 'ar 6/18/2005 16:14'!
focused: aBool
	"Indicate whether the receiver currently holds the keyboard focus."
	focused := aBool.! !

!TextMorph methodsFor: 'copying' stamp: 'ar 6/18/2005 16:18'!
veryDeepInner: deepCopier 
	"Copy all of my instance variables. Some need to be not copied at all, but shared.
	Warning!!!! Every instance variable defined in this class must be handled.
	We must also implement veryDeepFixupWith:.  See DeepCopier class comment."

	super veryDeepInner: deepCopier.
	textStyle _ textStyle veryDeepCopyWith: deepCopier.
	text _ text veryDeepCopyWith: deepCopier.
	wrapFlag _ wrapFlag veryDeepCopyWith: deepCopier.
	paragraph _ paragraph veryDeepCopyWith: deepCopier.
	editor _ editor veryDeepCopyWith: deepCopier.
	container _ container veryDeepCopyWith: deepCopier.
	predecessor _ predecessor.
	successor _ successor.
	backgroundColor _ backgroundColor veryDeepCopyWith: deepCopier.
	margins _ margins veryDeepCopyWith: deepCopier.
	focused _ focused veryDeepCopyWith: deepCopier.! !

!TextMorph methodsFor: 'event handling' stamp: 'ar 6/18/2005 16:13'!
keyboardFocusChange: aBoolean 
	| w |
	self focused: aBoolean.
	paragraph isNil ifFalse:[paragraph focused: aBoolean].
	aBoolean 
		ifTrue: 
			["A hand is wanting to send us characters..."

			self hasFocus ifFalse: [self editor	"Forces install"]]
		ifFalse: 
			["A hand has clicked elsewhere..."

			(w := self world) isNil 
				ifFalse: 
					[w handsDo: [:h | h keyboardFocus == self ifTrue: [^self]].
					"Release control unless some hand is still holding on"
					self releaseEditor]]! !

!TextMorph methodsFor: 'private' stamp: 'ar 6/18/2005 16:13'!
paragraph
	"Paragraph instantiation is lazy -- create it only when needed"
	paragraph ifNotNil: [^ paragraph].

self setProperty: #CreatingParagraph toValue: true.

	self setDefaultContentsIfNil.

	"...Code here to recreate the paragraph..."
	paragraph _ (self paragraphClass new textOwner: self owner).
	paragraph wantsColumnBreaks: successor notNil.
	paragraph
		compose: text
		style: textStyle copy
		from: self startingIndex
		in: self container.
	wrapFlag ifFalse:
		["Was given huge container at first... now adjust"
		paragraph adjustRightX].
	paragraph focused: self focused.
	self fit.
self removeProperty: #CreatingParagraph.


	^ paragraph! !



More information about the Squeak-dev mailing list