'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 22 October 2008 at 6:09:40 pm'!
!classDefinition: #CheckBoxLW category: #'LightWidgets-Kernel'!
LightWidget subclass: #CheckBoxLW
	instanceVariableNames: 'selected label font foreColor backColor selectedForeColor selectedBackColor'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!

!CheckBoxLW commentStamp: '<historical>' prior: 0!
A basic CheckBox. It holds a boolean value that is retrieved from the target and used to update it.!


!LightWidget methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 09:13'!
skipsNavigationFocus
	^false! !


!ButtonLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 13:35'!
keyDown: evt
	"Handle a key down event."
	"
	(evt commandKeyPressed and: [evt keyValue = 13]) ifTrue: [
		ActiveHand navigationFocus notNil ifTrue: [
			ActiveHand navigationFocus: self].
		pressed _ true.
		self updateView].
	super keyDown: evt
	"! !

!ButtonLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 13:37'!
keyStroke: anEvent	
	
	(anEvent commandKeyPressed and: [anEvent keyValue = 13]) ifTrue: [
		ActiveHand navigationFocus notNil ifTrue: [
			ActiveHand navigationFocus: self].
		self performAction.
		self updateView].

	super keyStroke: anEvent
	! !

!ButtonLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 15:58'!
keyUp: evt
	"Handle a key up event."
"	(evt commandKeyPressed and: [evt keyValue = 13]) ifTrue: [
		target perform: action.
		pressed _ false.
		self updateView].
	super keyUp: evt"! !


!CheckBoxLW methodsFor: 'initialization' stamp: 'jmv 10/21/2008 13:49'!
initialize
	super initialize.
	target _ self.
	aspect _ #visible.
	action _ #visible:.
	bounds _ 10@10 extent: 200@30.
	label _ 'CheckBox label'.
	font _ (TextStyle named: 'Vera') fontNamed: 'Vera 12'.
	foreColor _ Color white.
	selectedForeColor _ Color white.
	backColor _ Color r: 0.32 g: 0.39 b: 0.63.
	selectedBackColor _ Color r: 0.42 g: 0.5 b: 0.81.
	selected _ false! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
backColor
	^self hasNavigationFocus
		ifTrue: [ selectedBackColor ]
		ifFalse: [ backColor ]! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
backColor: aColor
	backColor _ aColor! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
font: aFont
	font _ aFont! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
foreColor
	^self hasNavigationFocus
		ifTrue: [ selectedForeColor ]
		ifFalse: [ foreColor ]! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
foreColor: aColor
	foreColor _ aColor! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:17'!
label
	^label! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:18'!
label: aString
	label _ aString! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:18'!
selectedBackColor: aColor
	selectedBackColor _ aColor! !

!CheckBoxLW methodsFor: 'accessing' stamp: 'jmv 10/21/2008 11:18'!
selectedForeColor: aColor
	selectedForeColor _ aColor! !

!CheckBoxLW methodsFor: 'drawing' stamp: 'jmv 10/21/2008 11:15'!
drawHighlightOn: aCanvas
	"Nothing to do. This class does highlighting in #drawOn:"! !

!CheckBoxLW methodsFor: 'drawing' stamp: 'jmv 10/21/2008 12:08'!
drawOn: aCanvas
	| h c r pt1 pt2 pt3 |
	c _ self backColor.
	aCanvas fillRectangle: bounds fillStyle: c.
	h _ font ascent // 2.
	aCanvas
		drawString: label 
		at: bounds leftCenter + (5 @ h negated) 
		font: font 
		color: self foreColor.
	h _ font ascent.
	r _ bounds rightCenter - (h+5@(h//2 - 1)) extent: h@h.
	aCanvas 
		frameAndFillRectangle: r
		fillColor: self foreColor
		borderWidth: 2
		borderColor: Color black.
	selected ifTrue: [
		pt2 _ r center + (-1@3).
		pt1 _ pt2 - (4@4).
		pt3 _ pt2 + (8@-8).
		c _ Color green.
		aCanvas
			line: pt1 to: pt2 width: 3 color: c;
			line: pt2 to: pt3 width: 4 color: c]
		! !

!CheckBoxLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 13:40'!
keyStroke: anEvent	
	
	(anEvent commandKeyPressed and: [anEvent keyValue = 13]) ifTrue: [
		ActiveHand navigationFocus notNil ifTrue: [
			ActiveHand navigationFocus: self].
		selected _ selected not.
		target perform: action with: selected.
		self updateView].

	super keyStroke: anEvent! !

!CheckBoxLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 13:48'!
mouseDown: evt
	ActiveHand navigationFocus notNil ifTrue: [
		ActiveHand navigationFocus: self]! !

!CheckBoxLW methodsFor: 'event handling' stamp: 'jmv 10/21/2008 13:41'!
mouseUp: evt
	"Handle a mouse up event."

	(self containsPoint: evt cursorPoint) ifTrue: [
		ActiveHand navigationFocus notNil ifTrue: [
			ActiveHand navigationFocus: self].
		selected _ selected not.
		target perform: action with: selected.
		self updateView].! !

!CheckBoxLW methodsFor: 'events-processing' stamp: 'jmv 10/21/2008 13:28'!
handlesKeyboard: evt
	^true! !

!CheckBoxLW methodsFor: 'events-processing' stamp: 'jmv 10/21/2008 13:47'!
handlesMouseDown: evt
	^  true! !

!CheckBoxLW methodsFor: 'updating' stamp: 'jmv 10/21/2008 13:46'!
modelChanged
	"The model changed is some way.
	This is usually the place to call #targetAspect to fetch the current value of the aspect from the
		model, and to store it in some Model Extension.
	We must update all Model Extension instance variables with values from the model (i.e. target)
		or with appropriate defaults.
	We must update ourselves and all subviews to reflect the model's new state"

	selected _ self targetAspect == true.
	
	super modelChanged! !


!EntryFieldLW methodsFor: 'drawing' stamp: 'jmv 10/22/2008 10:21'!
drawOn: aCanvas
	| string leftX w cColor borderWidth  stringBounds font xOffset xExtent selectionBounds orig ext cursorBounds str |
	borderWidth _ self borderWidth.
	aCanvas frameAndFillRectangle: bounds fillColor: self backgroundColor borderWidth: borderWidth borderColor: self borderColor.

	self isValid ifFalse:[aCanvas fillRectangle: bounds  color: (Color red alpha:0.4)].
 
	string _ self value.
	stringBounds _ self stringPosition extent: bounds extent - (2* borderWidth). 
	hideValue ifTrue:[ str _ string collect:[:char| $*]] ifFalse:[ str_ string].
	aCanvas drawString: str in: stringBounds font: self font color: color.

	self hasSelection
		ifTrue:[ 
			font _ self font.
			xOffset _ 0.
			(1 to: selection first - 1) do:[:i| xOffset _  xOffset + (font widthOf: (string at:i))].
			xExtent _ 0.
			 selection do:[:i|  xExtent _ xExtent + (font widthOf: (string at:i))]. 
			selectionBounds _  (stringBounds origin +(xOffset@0) ) extent: (xExtent@ stringBounds extent y).
			aCanvas fillRectangle: selectionBounds color: (Color green lighter alpha:0.5)]. 
	
	
	xOffset _ 0. 
	font _ self font.
	(string notNil and:[string notEmpty ])
		ifTrue:[	
				cursorPosition _ cursorPosition min: string size+1.
				(0 to: cursorPosition -2 ) do:[:i|  xOffset _ xOffset + (font widthOf: (string at:i+1))]].	
	orig _ self stringPosition + (xOffset@0).
	ext _  2@ stringBounds extent y.
	cursorBounds _ orig extent: ext.
	leftX _ cursorBounds origin x + (cursorBounds extent x / 2).

	ActiveHand keyboardFocus = self ifTrue: [
		w := 4.
		cColor :=  self cursorColor.
		1 to: w do: [:i | 
			aCanvas fillRectangle: ((leftX - w + i - 1) @ (cursorBounds origin y + i - 1)
					extent: ((w - i) * 2 + 3) @ 1)
				color: cColor.
			aCanvas fillRectangle: ((leftX - w + i - 1) @ (cursorBounds origin y + cursorBounds extent y - i) 
					extent: ((w - i) * 2 + 3) @ 1)
				color: cColor].
		aCanvas fillRectangle: cursorBounds color: cColor ]
	
			
	! !


!OldMorph methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 09:13'!
skipsNavigationFocus
	^false! !


!OldHandMorph methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 09:14'!
navigationFocusIn
	navigationFocus isNil
		ifTrue: [
			^self navigationFocus:World submorphs first].
	navigationFocus submorphs isEmpty
		ifTrue: [^self].
	self navigationFocus: navigationFocus submorphs first.
	navigationFocus skipsNavigationFocus ifTrue: [
		self navigationFocusNext ]! !

!OldHandMorph methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 09:14'!
navigationFocusNext
	(navigationFocus isNil or: [navigationFocus owner isNil])
		ifTrue: [
			^self navigationFocus: World submorphs first].
	navigationFocus owner submorphs size < 2
		ifTrue: [^self].
	navigationFocus goBehind.
	self navigationFocus: navigationFocus owner submorphs first.
	navigationFocus skipsNavigationFocus ifTrue: [
		self navigationFocusNext ]
! !

!OldHandMorph methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 11:23'!
navigationFocusOut
	navigationFocus isNil
		ifTrue: [^self].
	self navigationFocus: navigationFocus owner.
	(navigationFocus notNil and: [ navigationFocus skipsNavigationFocus ]) ifTrue: [
		self navigationFocusNext ]
! !

!OldHandMorph methodsFor: 'focus handling' stamp: 'jmv 10/22/2008 09:13'!
navigationFocusPrevious
	(navigationFocus isNil or: [navigationFocus owner isNil])
		ifTrue: [
			^self navigationFocus: World submorphs first].
	navigationFocus owner submorphs size < 2
		ifTrue: [^self].
	self navigationFocus: navigationFocus owner submorphs last.
	navigationFocus skipsNavigationFocus ifTrue: [
		self navigationFocusPrevious ]
! !

