ActiveHelp.st
changeset 3664 dcd522133e4f
parent 3507 039fedc083d3
child 3665 fd067a732096
equal deleted inserted replaced
3662:779d8eab9cf8 3664:dcd522133e4f
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1995 by Claus Gittinger
     2  COPYRIGHT (c) 1995 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
    47 
    45 
    48 !
    46 !
    49 
    47 
    50 documentation
    48 documentation
    51 "
    49 "
    52     The active help listener.
    50     The active help (tooltip) listener.
    53 
    51 
    54     The one and only instance of myself intercepts incoming mouse & keyboard 
    52     The one and only instance of myself intercepts incoming mouse & keyboard 
    55     events for the display device, being especially interested in view-enter/
    53     events for the display device, being especially interested in view-enter/
    56     leave events. When such an event arrives, it asks the corresponding view
    54     leave events. When such an event arrives, it asks the corresponding view
    57     or its model for a help message and displays it via an ActiveHelpView.
    55     or its model for a help message and displays it via an ActiveHelpView.
    58     Actually, the view is first asked if it would like to display it itself
    56     Actually, the view is first asked if it would like to display it itself
    59     - for example, in some information-view at the bottom of its main window.
    57     - for example, in some information-view at the bottom of its main window.
    60 
    58 
    61     The query for the helpText is repeated along the views superView chain, 
    59     The query for the helpText is repeated along the view's superView chain, 
    62     until any model or view returns a nonNil answer for the #helpTextFor:at 
    60     until any model or view returns a nonNil answer for the 
    63     or #helpTextFor message.
    61     #helpTextFor:<aSubView> at:<position> or #helpTextFor:<aSubView> message.
    64 
    62 
    65     All I need for automatic help is some model/view/applicationModel along
    63     All I need for automatic help is some model/view/applicationModel along
    66     the superview chain of the entered component, which responds to the
    64     the superview chain of the entered component, which responds to the
    67     #helpTextFor: message with a non-nil (string-) answer.
    65     #helpTextFor: message with a non-nil (string-) answer.
    68     I close down the help view after a while, if a key is pressed or the mouse
    66     I close down the help view after a while, if a key is pressed or the mouse
    70 
    68 
    71     Who should provide the helpText:
    69     Who should provide the helpText:
    72         the best place is the application object (an instance of ApplicationModel)
    70         the best place is the application object (an instance of ApplicationModel)
    73         or the topView, if its a derived class of StandardSystemView.
    71         or the topView, if its a derived class of StandardSystemView.
    74         This should know about its components and return the string
    72         This should know about its components and return the string
    75         when asked via #helpTextFor:aComponent.
    73         when asked via #helpTextFor:<aSubView>.
    76         See examples in FileBrowser, Launcher etc.
    74         See examples in FileBrowser, Launcher etc.
    77 
    75 
    78     Be aware, that for applicationModels, there must be a link from the
    76     Be aware, that for applicationModels, there must be a link from the
    79     topView to this applicationModel 
    77     topView to this applicationModel 
    80     (set via: aTopView application:anApplicationModel)
    78     (set via: aTopView application:anApplicationModel)
    96         Individual apps may enable/disable active help for themself by:
    94         Individual apps may enable/disable active help for themself by:
    97         'ActiveHelp startFor:app' or 'ActiveHelp stopFor:app', passing either
    95         'ActiveHelp startFor:app' or 'ActiveHelp stopFor:app', passing either
    98         the topView or the topViews application as argument.
    96         the topView or the topViews application as argument.
    99         This is usually done by applications which want to show contextHelp in
    97         This is usually done by applications which want to show contextHelp in
   100         some infoView.
    98         some infoView.
   101 
    99         Late note: thsi is no longer recommended - one such mouse watcher process is
       
   100         good enough for all views.
   102         
   101         
   103     [author:]
   102     [author:]
   104         Claus Gittinger
   103         Claus Gittinger
   105 
   104 
   106     [start with:]
   105     [start with:]
   466         domainPointOrNil := aView transformation applyInverseTo:aDevicePointOrNil.
   465         domainPointOrNil := aView transformation applyInverseTo:aDevicePointOrNil.
   467     ] ifFalse:[
   466     ] ifFalse:[
   468         domainPointOrNil := aDevicePointOrNil.
   467         domainPointOrNil := aDevicePointOrNil.
   469     ].
   468     ].
   470 
   469 
   471     text := self helpTextFromView:aView at:domainPointOrNil.
   470 "/    text := self helpTextFromView:aView at:domainPointOrNil.
   472     text notNil ifTrue:[ ^ text ].
   471 "/    text notNil ifTrue:[ ^ text ].
   473 
   472 
   474     ((aView respondsTo:#application)
   473     ((aView respondsTo:#application)
   475     and:[ (app1 := aView application) notNil ]) ifTrue:[
   474     and:[ (app1 := aView application) notNil ]) ifTrue:[
   476         text := self helpTextFromModel:app1 view:aView at:domainPointOrNil.
   475         text := self helpTextFromModel:app1 view:aView at:domainPointOrNil.
   477         text notNil ifTrue:[ ^ text ].
   476         text notNil ifTrue:[ ^ text ].
   478     ] ifFalse:[
   477     ] ifFalse:[
   479         "/ old style (i.e. StandardSystemView ...)
   478         "/ old style (i.e. StandardSystemView ...)
   480         topView := aView topView.
   479         topView := aView topView.
   481         (topView notNil and:[topView ~~ aView]) ifTrue:[
   480         text := self helpTextFromModel:topView view:aView at:domainPointOrNil.
   482             text := self helpTextFromModel:topView view:aView at:domainPointOrNil.
   481         text notNil ifTrue:[ ^ text ].
   483             text notNil ifTrue:[ ^ text ].
       
   484         ]
       
   485     ].
   482     ].
   486 
   483 
   487     (model := aView model) notNil ifTrue:[
   484     (model := aView model) notNil ifTrue:[
   488         model ~~ app1 ifTrue:[
   485         model ~~ app1 ifTrue:[
   489             text := self helpTextFromModel:model view:aView at:domainPointOrNil.
   486             text := self helpTextFromModel:model view:aView at:domainPointOrNil.
   490             text notNil ifTrue:[ ^ text ].
   487             text notNil ifTrue:[ ^ text ].
   491         ].
   488         ].
   492     ].
   489     ].
   493     text := self helpTextFromView:aView at:domainPointOrNil.
   490     text := self helpTextFromView:aView at:domainPointOrNil.
   494     text notNil ifTrue:[ ^ text ].
   491     text notNil ifTrue:[
       
   492          ^ text 
       
   493     ].
   495 
   494 
   496     "walk up the chain - maybe someone knows about its subview ..."
   495     "walk up the chain - maybe someone knows about its subview ..."
   497     v := aView.
   496     v := aView.
   498     [
   497     [
   499         (sv := v container) notNil
   498         (sv := v container) notNil
   525 
   524 
   526     "Modified: / 31.8.1995 / 20:38:00 / claus"
   525     "Modified: / 31.8.1995 / 20:38:00 / claus"
   527     "Modified: / 28.7.1998 / 01:47:27 / cg"
   526     "Modified: / 28.7.1998 / 01:47:27 / cg"
   528 !
   527 !
   529 
   528 
   530 helpTextFromModel:aModel view:aView at:aPointOrNil 
   529 helpTextFromModel:aModelOrTopView view:aView at:aPointOrNil 
   531     "helper: ask aModel for its helpText."
   530     "helper: ask aModel for its helpText."
   532 
   531 
   533     |text text2|
   532     |text|
   534 
   533 
   535     aPointOrNil notNil ifTrue:[
   534     aPointOrNil notNil ifTrue:[
   536         (aModel respondsTo:#helpTextFor:at:) ifTrue:[
   535         (aModelOrTopView respondsTo:#helpTextFor:at:) ifTrue:[
   537             text := aModel helpTextFor:aView at:aPointOrNil.
   536             text := aModelOrTopView helpTextFor:aView at:aPointOrNil.
   538             text notNil ifTrue:[^ text].
   537             text notNil ifTrue:[^ text].
   539         ].
   538         ].
   540     ].
   539     ].
   541     (aModel respondsTo:#helpTextFor:) ifTrue:[
   540     (aModelOrTopView respondsTo:#helpTextFor:) ifTrue:[
   542         text := aModel helpTextFor:aView.
   541         text := aModelOrTopView helpTextFor:aView.
   543         "/ cg: I dont understand this...
   542         text notNil ifTrue:[^ text].
   544 "/        text notNil ifTrue:[
       
   545 "/            text2 := self helpTextFromView:aView at:aPointOrNil.
       
   546 "/            text2 notNil ifTrue:[ ^ text2 ].
       
   547 "/        ].
       
   548     ].
   543     ].
   549     ^ text
   544     ^ text
   550 !
   545 !
   551 
   546 
   552 helpTextFromView:aView at:aPointOrNil 
   547 helpTextFromView:aView at:aPointOrNil