'From Squeak3.7 of ''4 September 2004'' [latest update: #5989] on 30 June 2008 at 11:24:06 pm'!
!classDefinition: #ButtonLW category: #'LightWidgets-Kernel'!
LightWidget subclass: #ButtonLW
	instanceVariableNames: 'pressed contentsOrGetter font label actionArgument '
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!

!ButtonLW commentStamp: '<historical>' prior: 0!
Basic Button Light Widget.
As Buttons don't have user editable data, an optional actionArgument might be passed on construction, to further customize the button behavior. This object will be used as a method argument when performing action on the target.!


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

!ButtonLW methodsFor: 'event handling' stamp: 'jmv 6/30/2008 07:02'!
mouseUp: evt
	"Handle a mouse up event."

	(self containsPoint: evt cursorPoint)
		ifTrue: [self performAction].
	pressed _ false.
	self updateView! !

!ButtonLW methodsFor: 'as yet unclassified' stamp: 'jdb 6/30/2008 07:01'!
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: 'view of a model or target' stamp: 'jmv 6/30/2008 07:02'!
performAction

	| a |
	target isNil ifTrue: [
		^self].
	action isNil ifTrue: [
		^self].
	actionArgument isNil ifTrue: [
		^target perform: action].
	a _ actionAdaptor isNil
		ifTrue: [actionArgument]
		ifFalse: [actionArgument perform: actionAdaptor].
	target perform: action with: a! !

!ButtonLW methodsFor: 'view of a model or target' stamp: 'jmv 6/30/2008 07:06'!
target: aModelOrView action: aSymbol argument: anObject
	"As a view I show some aspect of a model (or target widget) (may use aspectAdaptor).
	I also can act on my model (or target widget), using some action together with an 
	argument (may use actionAdaptor)."
	
	self target: aModelOrView action: aSymbol.
	actionArgument _ anObject! !


!ButtonLW class methodsFor: 'instance creation' stamp: 'jmv 6/30/2008 07:29'!
target: aModelOrView action: aSymbol argument: anObject label: aString
	^self new
		target: aModelOrView action: aSymbol argument: anObject;
		label: aString! !

!ButtonLW class methodsFor: 'instance creation' stamp: 'jmv 6/30/2008 07:29'!
target: aModelOrView action: aSymbol label: aString
	^self new
		target: aModelOrView action: aSymbol argument: nil;
		label: aString! !


!ListLW methodsFor: 'submorphs-add/remove' stamp: 'jmv 6/30/2008 07:22'!
addItem: aString action: aSymbol

	^self addItem: aString target: owner action: aSymbol argument: nil! !

!ListLW methodsFor: 'submorphs-add/remove' stamp: 'jmv 6/30/2008 07:22'!
addItem: aString action: aSymbol argument: anotherObject

	^self addItem: aString target: owner action: aSymbol argument: anotherObject! !

!ListLW methodsFor: 'submorphs-add/remove' stamp: 'jmv 6/30/2008 07:22'!
addItem: aString target: anObject action: aSymbol

	^self addItem: aString target: anObject action: aSymbol argument: nil! !

!ListLW methodsFor: 'submorphs-add/remove' stamp: 'jmv 6/30/2008 07:08'!
addItem: aString target: anObject action: aSymbol argument: anotherObject

	| item |
	item _ self defaultItemClass 
		target: anObject action: aSymbol argument: anotherObject label: aString.
	self addMorph: item.
	^item! !

!ListLW methodsFor: 'accessing' stamp: 'jmv 6/30/2008 06:49'!
defaultItemClass
	^MenuItemLW! !

MenuItemLW class removeSelector: #target:action:label:!
!classDefinition: #ButtonLW category: #'LightWidgets-Kernel'!
LightWidget subclass: #ButtonLW
	instanceVariableNames: 'actionArgument pressed contentsOrGetter font label'
	classVariableNames: ''
	poolDictionaries: ''
	category: 'LightWidgets-Kernel'!
