Initial revision
authorclaus
Fri, 31 Mar 1995 05:08:53 +0200
changeset 59 98a4d38cfc96
parent 58 a48ab73befdb
child 60 c9dc64d2b4d6
Initial revision
ActiveHelp.st
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ActiveHelp.st	Fri Mar 31 05:08:53 1995 +0200
@@ -0,0 +1,253 @@
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+'From Smalltalk/X, Version:2.10.5 on 26-mar-1995 at 10:19:20 am'!
+
+EventListener subclass:#ActiveHelp
+	 instanceVariableNames:'currentView currentHelpView currentFrame closeProcess'
+	 classVariableNames:'ShowTime TheOneAndOnlyHelpListener'
+	 poolDictionaries:''
+	 category:'Interface-Help'
+!
+
+!ActiveHelp class methodsFor:'documentation'!
+
+version
+"
+$Header: /cvs/stx/stx/libview2/ActiveHelp.st,v 1.1 1995-03-31 03:08:53 claus Exp $
+"
+!
+
+documentation
+"
+    The active help listener
+"
+!
+
+copyright
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+! !
+
+!ActiveHelp class methodsFor:'initialization'!
+
+initialize
+    ShowTime := 15
+! !
+
+!ActiveHelp class methodsFor:'startup'!
+
+start
+    TheOneAndOnlyHelpListener isNil ifTrue:[
+	TheOneAndOnlyHelpListener := self new.
+    ].
+    TheOneAndOnlyHelpListener listen
+
+    "
+     ActiveHelp start
+    "
+!
+
+stop
+    TheOneAndOnlyHelpListener notNil ifTrue:[
+	TheOneAndOnlyHelpListener unlisten.
+    ].
+
+    "
+     ActiveHelp stop
+    "
+
+!
+
+release 
+    self stop.
+    TheOneAndOnlyHelpListener := nil
+
+    "
+     ActiveHelp release
+    "
+! !
+
+!ActiveHelp methodsFor:'private'!
+
+helpTextFor:aView atX:x y:y
+    |model text view org found v sv|
+
+    view := aView.
+
+    (model := aView model) notNil ifTrue:[
+"/ model printNL.
+	(model respondsTo:#helpTextFor:at:) ifTrue:[
+	    text := model helpTextFor:aView at:x@y.
+	    text notNil ifTrue:[^ text].
+	].
+	(model respondsTo:#helpTextFor:) ifTrue:[
+	    text := model helpTextFor:aView.
+	    text notNil ifTrue:[^ text].
+	]
+    ].
+
+    (aView respondsTo:#helpText) ifTrue:[
+	text := aView helpText.
+	text notNil ifTrue:[^ text].
+    ].
+
+    "walk up the chain - maybe someone knows about its subview ..."
+    v := aView.
+
+    [(sv := v superView) notNil] whileTrue:[
+	(model := sv model) notNil ifTrue:[
+	    (model respondsTo:#helpTextFor:at:) ifTrue:[
+		text := model helpTextFor:aView at:x@y.
+		text notNil ifTrue:[^ text].
+	    ].
+	    (model respondsTo:#helpTextFor:) ifTrue:[
+		text := model helpTextFor:aView.
+		text notNil ifTrue:[^ text].
+	    ]
+	].
+
+	(sv respondsTo:#helpTextFor:) ifTrue:[
+	    text := sv helpTextFor:aView.
+	    text notNil ifTrue:[^ text].
+	    text := sv helpTextFor:v.
+	    text notNil ifTrue:[^ text].
+	 ].
+	 v := sv.
+    ].
+
+    (view class respondsTo:#helpText) ifTrue:[
+	text := view class helpText.
+	text notNil ifTrue:[^ text].
+    ].
+
+    ^ nil
+!
+
+hideIfPointerLeft:aView
+    |whereOnScreen|
+
+    whereOnScreen := aView device pointerPosition.
+
+    (currentFrame notNil
+    and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[
+	self hideHelp.
+	currentView := nil
+    ].
+
+! !
+
+!ActiveHelp methodsFor:'listening'!
+
+buttonPress:state x:x y:y view:view
+    self hideHelp.
+    ^ false
+!
+
+pointerEnter:state x:x y:y view:aView
+    |text|
+
+    self hideIfPointerLeft:aView.
+    aView topView == currentHelpView ifTrue:[
+	^ true
+    ].
+
+    text := self helpTextFor:aView atX:x y:y.
+
+    text notNil ifTrue:[
+	self showHelp:text for:aView
+    ].
+
+    ^ false
+!
+
+pointerLeave:state view:view
+    self hideIfPointerLeft:view.
+    ^ false
+!
+
+keyPress:state x:x y:y view:view
+    self hideHelp.
+    ^ false
+!
+
+buttonMotion:state x:x y:y view:view
+    self hideIfPointerLeft:view.
+    ^ false
+! !
+
+!ActiveHelp methodsFor:'show / hide help'!
+
+hideHelp
+    currentHelpView notNil ifTrue:[
+	[
+	    currentHelpView destroy.
+	    currentHelpView := nil.
+	    currentView := nil.
+	] valueUninterruptably
+    ].
+    currentFrame := nil.
+    closeProcess notNil ifTrue:[
+	closeProcess terminate.
+    ]
+!
+
+showHelp:aHelpText for:view
+    |org|
+
+    view == currentView ifTrue:[^ self].
+
+    currentHelpView notNil ifTrue:[
+	self hideHelp
+    ].
+
+    org := view originRelativeTo:nil.
+    currentFrame := org extent:view extent.
+    org :=org + (view extent // 2).
+
+org := view device pointerPosition.
+
+    currentHelpView := ActiveHelpView for:aHelpText withCRs.
+    currentHelpView origin:org.
+"/    currentHelpView open.
+    currentHelpView realize.
+    currentHelpView enableButtonMotionEvents.
+    currentHelpView enableMotionEvents.
+
+    currentView := view.
+    closeProcess := [
+	Process terminateSignal handle:[:ex |
+	    closeProcess := nil.
+	] do:[
+	    (Delay forSeconds:ShowTime) wait.
+	    [
+		currentHelpView notNil ifTrue:[
+		    currentHelpView destroy.
+		    currentHelpView := nil.
+		]
+	    ] valueUninterruptably
+	].
+    ] forkAt:(Processor userSchedulingPriority + 1).
+! !
+
+ActiveHelp initialize!