# HG changeset patch # User Claus Gittinger # Date 830765610 -7200 # Node ID 196eb68b707c53247231309242b8c3f2690464c5 # Parent b898f5762952c1cf01fee5515ff6e283b3d0e763 documentation diff -r b898f5762952 -r 196eb68b707c ActiveHelp.st --- a/ActiveHelp.st Sat Apr 27 19:59:33 1996 +0200 +++ b/ActiveHelp.st Mon Apr 29 10:13:30 1996 +0200 @@ -78,14 +78,21 @@ [author:] Claus Gittinger + [start with:] + ActiveHelp start + ActiveHelp stop + [See also:] - ActiveHelp + ActiveHelpView + WindowGroup WindowEvent + ApplicationModel StandardSystemView " ! examples " - (make certain that activeHelp is turned on ...) + (make certain that activeHelp is turned on ... + ... otherwise, you will see nothing) the following example uses a Plug as a model replacement. In concrete application, you would create a method to implement the helpText @@ -117,8 +124,10 @@ top open [exEnd] + (make certain that activeHelp is turned on ... + ... otherwise, you will see nothing) + alternatively, display of the helpMessage in a local, private view: - [exBegin] |app top button1 button2 infoView| @@ -156,40 +165,56 @@ !ActiveHelp class methodsFor:'initialization'! initialize + "set default delay & help-display times" + ShowTime := 15. DelayTime := 2. " ActiveHelp initialize " + + "Modified: 27.4.1996 / 15:07:27 / cg" ! ! !ActiveHelp class methodsFor:'startup'! -isActive +isActive + "return true, if activeHelp is turned on" + ^ TheOneAndOnlyHelpListener notNil + + "Modified: 27.4.1996 / 15:07:57 / cg" ! start + "start activeHelp" + TheOneAndOnlyHelpListener isNil ifTrue:[ - TheOneAndOnlyHelpListener := self new. + TheOneAndOnlyHelpListener := self new. ]. TheOneAndOnlyHelpListener listen " ActiveHelp start " + + "Modified: 27.4.1996 / 15:08:05 / cg" ! stop + "stop activeHelp" + TheOneAndOnlyHelpListener notNil ifTrue:[ - TheOneAndOnlyHelpListener unlisten. + TheOneAndOnlyHelpListener unlisten. ]. TheOneAndOnlyHelpListener := nil " ActiveHelp stop " + + "Modified: 27.4.1996 / 15:08:11 / cg" ! ! !ActiveHelp class methodsFor:'times'! @@ -223,130 +248,154 @@ !ActiveHelp methodsFor:'listening'! buttonMotion:state x:x y:y view:view + "handle motion events - if the mousepointer left the + previous helped view, hide the help" + self hideIfPointerLeft:view. ^ false + + "Modified: 27.4.1996 / 15:09:48 / cg" ! buttonPress:state x:x y:y view:view + "handle button press - unconditionally hide the help" + self hideHelp. ^ false + + "Modified: 27.4.1996 / 15:09:45 / cg" ! keyPress:state x:x y:y view:view + "handle key press - unconditionally hide the help" + self hideHelp. ^ false + + "Modified: 27.4.1996 / 15:09:57 / cg" ! pointerEnter:state x:x y:y view:aView + "handle pointer entering a view; setup timeOut to show help" + |text p| showProcess notNil ifTrue:[ - p := showProcess. showProcess := nil. - p terminate. + p := showProcess. showProcess := nil. + p terminate. ]. self hideIfPointerLeft:aView. aView topView == currentHelpView ifTrue:[ - ^ true + ^ true ]. self initiateHelpFor:aView atX:x y:y. ^ false + + "Modified: 27.4.1996 / 15:10:27 / cg" ! pointerLeave:state view:view + "handle pointer leaving a view; hide help text" + self hideIfPointerLeft:view. ^ false + + "Modified: 27.4.1996 / 15:10:41 / cg" ! ! !ActiveHelp methodsFor:'private'! helpTextFor:aView atX:x y:y - "pointer entered aView; + "retrieve helptext for aView as a string; walk along the views superView chain, asking models and views encountered while walking. The first one who understands and returns a nonNil answer to the - #helpTextFor:at: or #helpTextFor: message ends this walk and the + #helpTextFor:at: or #helpTextFor: message ends this search and the returned string is returned." |model text view org found v sv| view := aView. (model := aView 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]. - ] + (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]. + 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]. - ] - ]. + (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. + (sv respondsTo:#helpTextFor:) ifTrue:[ + text := sv helpTextFor:aView. + text notNil ifTrue:[^ text]. + text := sv helpTextFor:v. + text notNil ifTrue:[^ text]. + ]. + v := sv. ]. (v notNil and:[v respondsTo:#application]) ifTrue:[ - (model := v application) 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]. - ] - ] + (model := v application) 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]. + ] + ] ]. (v notNil and:[v respondsTo:#model]) ifTrue:[ - (model := v 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]. - ] - ] + (model := v 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]. + ] + ] ]. (view class respondsTo:#helpText) ifTrue:[ - text := view class helpText. - text notNil ifTrue:[^ text]. + text := view class helpText. + text notNil ifTrue:[^ text]. ]. ^ nil "Modified: 31.8.1995 / 20:38:00 / claus" + "Modified: 27.4.1996 / 15:11:22 / cg" ! hideIfPointerLeft:aView + "hide help, if the pointer is not in aView" + |whereOnScreen p| "/ showProcess notNil ifTrue:[ @@ -358,67 +407,79 @@ (currentFrame notNil and:[(currentFrame insetBy:1@1) containsPoint:whereOnScreen]) ifFalse:[ - self hideHelp. - currentView := nil + self hideHelp. + currentView := nil ]. + + "Modified: 27.4.1996 / 15:11:35 / cg" ! initiateHelpFor:aView atX:x y:y + "start a timeout process to display help for aView after some delay" + |text p| text := self helpTextFor:aView atX:x y:y. text notNil ifTrue:[ - DelayTime > 0 ifTrue:[ - showProcess notNil ifTrue:[ - p := showProcess. showProcess := nil. - p terminate. - ]. - showProcess := [ - (Delay forSeconds:DelayTime) wait. - showProcess := nil. - self showHelp:text for:aView - ] forkAt:(Processor userSchedulingPriority + 1). - ] ifFalse:[ - self showHelp:text for:aView - ] + DelayTime > 0 ifTrue:[ + showProcess notNil ifTrue:[ + p := showProcess. showProcess := nil. + p terminate. + ]. + showProcess := [ + (Delay forSeconds:DelayTime) wait. + showProcess := nil. + self showHelp:text for:aView + ] forkAt:(Processor userSchedulingPriority + 1). + ] ifFalse:[ + self showHelp:text for:aView + ] ]. + + "Modified: 27.4.1996 / 15:12:03 / cg" ! ! !ActiveHelp methodsFor:'show / hide help'! hideHelp + "hide the help text" + |p| showProcess notNil ifTrue:[ - p := showProcess. showProcess := nil. - p terminate. + p := showProcess. showProcess := nil. + p terminate. ]. currentHelpView notNil ifTrue:[ - [ - currentHelpView destroy. - currentHelpView := nil. - currentView := nil. - ] valueUninterruptably + [ + currentHelpView destroy. + currentHelpView := nil. + currentView := nil. + ] valueUninterruptably ]. currentFrame := nil. closeProcess notNil ifTrue:[ - p := closeProcess. closeProcess := nil. - p terminate. + p := closeProcess. closeProcess := nil. + p terminate. ] + + "Modified: 27.4.1996 / 15:12:13 / cg" ! showHelp:aHelpText for:view + "show the help text for aView" + |org p v| view == currentView ifTrue:[^ self]. closeProcess notNil ifTrue:[ - p := closeProcess. closeProcess := nil. - p terminate. + p := closeProcess. closeProcess := nil. + p terminate. ]. currentHelpView notNil ifTrue:[ - self hideHelp + self hideHelp ]. org := view originRelativeTo:nil. @@ -430,10 +491,10 @@ org := view device pointerPosition. org := org + (10@10). (org x + v width) > view device width ifTrue:[ - org := (org x - v width) @ org y + org := (org x - v width) @ org y ]. (org y + v height) > view device height ifTrue:[ - org := org x @ (org y - v height). + org := org x @ (org y - v height). ]. v origin:org. @@ -445,25 +506,26 @@ currentView := view. closeProcess := [ - Process terminateSignal handle:[:ex | - closeProcess := nil. - ] do:[ - (Delay forSeconds:ShowTime) wait. - [ - currentHelpView notNil ifTrue:[ - currentHelpView destroy. - currentHelpView := nil. - ] - ] valueUninterruptably - ]. + Process terminateSignal handle:[:ex | + closeProcess := nil. + ] do:[ + (Delay forSeconds:ShowTime) wait. + [ + currentHelpView notNil ifTrue:[ + currentHelpView destroy. + currentHelpView := nil. + ] + ] valueUninterruptably + ]. ] forkAt:(Processor userSchedulingPriority + 1). "Modified: 31.8.1995 / 19:20:45 / claus" + "Modified: 27.4.1996 / 15:12:25 / cg" ! ! !ActiveHelp class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview2/ActiveHelp.st,v 1.11 1996-04-27 12:42:52 cg Exp $' + ^ '$Header: /cvs/stx/stx/libview2/ActiveHelp.st,v 1.12 1996-04-29 08:13:19 cg Exp $' ! ! ActiveHelp initialize! diff -r b898f5762952 -r 196eb68b707c ActiveHelpView.st --- a/ActiveHelpView.st Sat Apr 27 19:59:33 1996 +0200 +++ b/ActiveHelpView.st Mon Apr 29 10:13:30 1996 +0200 @@ -40,10 +40,12 @@ documentation " a talking view. + Instances of myself show up either as a comics-like talking view, or as a simple square popup. This is configured via the - styleSheet; the default is simple-square. To get the fancy cmics - view, add a resource 'activeHelpStyle' with a symbol-value of #cartoon. + styleSheet; the default is simple-square. + To get the fancy comics style, add a resource 'activeHelpStyle' with + a symbol-value of #cartoon. However, be aware that some servers have performance problems with these view-shapes (or do not support shapes at all). @@ -58,6 +60,8 @@ !ActiveHelpView class methodsFor:'instance creation'! for:someText + "create a talking-view for some text" + |helpView textView| helpView := self new. @@ -70,9 +74,13 @@ (ActiveHelpView for:'hello world\this is an ActiveHelpView' withCRs) realize (ActiveHelpView for:'press here\to open a new\SystemBrowser' withCRs) realize " + + "Modified: 27.4.1996 / 15:14:07 / cg" ! with:aView + "create a talking-view wrapping some other view" + ^ self new withView:aView " @@ -80,45 +88,42 @@ (ActiveHelpView with:(TextView new)) open (ActiveHelpView with:(Button label:'ok')) open " + + "Modified: 27.4.1996 / 15:14:18 / cg" ! ! !ActiveHelpView methodsFor:'accessing'! contents:someText + "set the text" + (myView isKindOf:Label) ifTrue:[ - myView label:someText asString. - myView extent:(myView preferredExtent). + myView label:someText asString. + myView extent:(myView preferredExtent). ] ifFalse:[ - myView contents:someText. + myView contents:someText. ]. self resizeToFit -! -createOnTop - ^ true -! - -isPopUpView - ^ true + "Modified: 27.4.1996 / 15:14:56 / cg" ! withView:aView + "set the component view" + (aView isKindOf:Label) ifTrue:[ - aView viewBackground:viewBackground. - aView backgroundColor:viewBackground. + aView viewBackground:viewBackground. + aView backgroundColor:viewBackground. ]. self addSubView:aView. myView := aView. myView borderWidth:0 + + "Modified: 27.4.1996 / 15:16:46 / cg" ! ! !ActiveHelpView methodsFor:'events'! -XXsizeChanged:how - super sizeChanged:how. - self computeShape -! - redraw self fill:White ! ! @@ -151,6 +156,8 @@ !ActiveHelpView methodsFor:'private'! computeShape + "compute the shape, based upon the size of my component view" + |extent shapeForm borderForm y1 bw h w mirrorH mirrorV p1 p2 p3 pB1 pB2 pB3 offs| @@ -163,17 +170,17 @@ offs := 0. self corner x > self device width ifTrue:[ - mirrorH := true. - self origin:((self origin x - w) @ (self origin y)). - offs := bw * 2. + mirrorH := true. + self origin:((self origin x - w) @ (self origin y)). + offs := bw * 2. ] ifFalse:[ - mirrorH := false + mirrorH := false ]. self corner y > self device height ifTrue:[ - mirrorV := true. - self origin:(self origin x @ (self origin y - h)). + mirrorV := true. + self origin:(self origin x @ (self origin y - h)). ] ifFalse:[ - mirrorV := false + mirrorV := false ]. borderForm := Form width:w height:h. @@ -182,21 +189,21 @@ shapeForm fill:(Color colorId:0). mirrorV ifTrue:[ - myView origin:(w // 7 + offs) @ (h//8) - extent:(w // 7 * 6) @ (h // 3 * 2). - y1 := 0. + myView origin:(w // 7 + offs) @ (h//8) + extent:(w // 7 * 6) @ (h // 3 * 2). + y1 := 0. ] ifFalse:[ - myView origin:(w // 7 + offs) @ (h // 3) - extent:(w // 7 * 6) @ (h // 3 * 2). - y1 := h // 4. + myView origin:(w // 7 + offs) @ (h // 3) + extent:(w // 7 * 6) @ (h // 3 * 2). + y1 := h // 4. ]. borderForm fillArcX:0 - y:y1 - w:w - h:(h // 3 * 2) - from:0 - angle:360. + y:y1 + w:w + h:(h // 3 * 2) + from:0 + angle:360. "/ shapeForm fillArcX:bw y:(h // 4) + bw "/ w:(w - (bw * 2)) @@ -205,37 +212,37 @@ "/ angle:360. mirrorH ifTrue:[ - mirrorV ifTrue:[ - p1 := w @ h. - p2 := ((w * 7 // 8) @ (h // 2)). - p3 := ((w // 2) @ (h // 2)). - pB1 := (w-bw) @ (h-bw). - pB2 := ((w * 7 // 8 - bw) @ (h // 2 - bw)). - pB3 := ((w // 2 + bw) @ (h // 2 - bw)) - ] ifFalse:[ - p1 := w @ 0. - p2 := ((w * 7 // 8) @ (h // 2)). - p3 := ((w // 2) @ (h // 2)). - pB1 := (w-bw) @ bw. - pB2 := ((w * 7 // 8 - bw) @ (h // 2 + bw)). - pB3 := ((w // 2 + bw) @ (h // 2 + bw)) - ] + mirrorV ifTrue:[ + p1 := w @ h. + p2 := ((w * 7 // 8) @ (h // 2)). + p3 := ((w // 2) @ (h // 2)). + pB1 := (w-bw) @ (h-bw). + pB2 := ((w * 7 // 8 - bw) @ (h // 2 - bw)). + pB3 := ((w // 2 + bw) @ (h // 2 - bw)) + ] ifFalse:[ + p1 := w @ 0. + p2 := ((w * 7 // 8) @ (h // 2)). + p3 := ((w // 2) @ (h // 2)). + pB1 := (w-bw) @ bw. + pB2 := ((w * 7 // 8 - bw) @ (h // 2 + bw)). + pB3 := ((w // 2 + bw) @ (h // 2 + bw)) + ] ] ifFalse:[ - mirrorV ifTrue:[ - p1 := 0@h. - p2 := ((w // 8) @ (h // 2)). - p3 := ((w // 2) @ (h // 2)). - pB1 := bw@(h-bw). - pB2 := ((w // 8 + bw) @ (h // 2 - bw)). - pB3 := ((w // 2 - bw) @ (h // 2 - bw)). - ] ifFalse:[ - p1 := 0@0. - p2 := ((w // 8) @ (h // 2)). - p3 := ((w // 2) @ (h // 2)). - pB1 := bw@bw. - pB2 := ((w // 8 + bw) @ (h // 2 + bw)). - pB3 := ((w // 2 - bw) @ (h // 2 + bw)). - ] + mirrorV ifTrue:[ + p1 := 0@h. + p2 := ((w // 8) @ (h // 2)). + p3 := ((w // 2) @ (h // 2)). + pB1 := bw@(h-bw). + pB2 := ((w // 8 + bw) @ (h // 2 - bw)). + pB3 := ((w // 2 - bw) @ (h // 2 - bw)). + ] ifFalse:[ + p1 := 0@0. + p2 := ((w // 8) @ (h // 2)). + p3 := ((w // 2) @ (h // 2)). + pB1 := bw@bw. + pB2 := ((w // 8 + bw) @ (h // 2 + bw)). + pB3 := ((w // 2 - bw) @ (h // 2 + bw)). + ] ]. borderForm fillPolygon:(Array with:p1 with:p2 with:p3). @@ -247,32 +254,56 @@ shapeForm paint:(Color colorId:1). shapeForm fillArcX:bw - y:y1 + bw - w:(w - (bw * 2)) - h:(h // 3 * 2 - (bw * 2)) - from:0 - angle:360. + y:y1 + bw + w:(w - (bw * 2)) + h:(h // 3 * 2 - (bw * 2)) + from:0 + angle:360. self borderShape:borderForm. self viewShape:shapeForm + + "Modified: 27.4.1996 / 15:16:15 / cg" ! resizeToFit + "resize myself to make the component view fit" + |h w| (styleSheet at:'activeHelpStyle' default:nil) == #cartoon ifTrue:[ - h := myView height. "/ heightOfContents. - w := myView width. "/ widthOfContents. - self extent:((w * 0.85) rounded asInteger) - @ - ((h * 2.5) rounded asInteger) + h := myView height. "/ heightOfContents. + w := myView width. "/ widthOfContents. + self extent:((w * 0.85) rounded asInteger) + @ + ((h * 2.5) rounded asInteger) ] ifFalse:[ - self extent:myView extent + self extent:myView extent ] + + "Modified: 27.4.1996 / 15:16:29 / cg" +! ! + +!ActiveHelpView methodsFor:'queries'! + +createOnTop + "return true - I always want to popUp onTop of others" + + ^ true + + "Modified: 27.4.1996 / 15:15:13 / cg" +! + +isPopUpView + "return true - I am a popUp type of view" + + ^ true + + "Modified: 27.4.1996 / 15:15:42 / cg" ! ! !ActiveHelpView class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libview2/ActiveHelpView.st,v 1.8 1996-04-25 16:32:07 cg Exp $' + ^ '$Header: /cvs/stx/stx/libview2/ActiveHelpView.st,v 1.9 1996-04-29 08:13:30 cg Exp $' ! !