diff -r 3d8a5dd293ba -r 04459d76932e Tools__ViewTreeModel.st --- a/Tools__ViewTreeModel.st Thu Jan 29 10:01:04 2009 +0100 +++ b/Tools__ViewTreeModel.st Thu Jan 29 10:04:06 2009 +0100 @@ -5,7 +5,8 @@ ValueModel subclass:#ViewTreeModel instanceVariableNames:'lockSema selectedSuperItems selection hiddenLevel listOfItems inputEventAction mappedViewAction beforeSelectionChangedAction - testMode icons timedUpdateTask selectOnClickHolder' + icons timedUpdateTask selectOnClickHolder testModeChannel + hasTargetWidgetChannel' classVariableNames:'' poolDictionaries:'' category:'A-Views-Support' @@ -32,8 +33,9 @@ [Instance variables:] lockSema lock selection notifications and redraws - testMode true, the selection is not highlighted and - all input events are eaten. + testModeChannel true, than running in test mode. + + hasTargetWidgetChannel true, than any target view is grapped selection selected items or nil @@ -123,12 +125,6 @@ listOfItems application:anApplication. ! -listOfItems - "hiearchical list build from existing items - " - ^ listOfItems -! - rootItem "get the rootItem the event viewer is established on " @@ -141,6 +137,7 @@ |expanded| timedUpdateTask := nil. + self deselect. lockSema critical:[ anItem notNil ifTrue:[ expanded := anItem isExpanded ] @@ -234,12 +231,6 @@ !ViewTreeModel methodsFor:'accessing visibility'! -selectOnClickHolder - "boolean holder, which indicates whether the selection will change on click - " - ^ selectOnClickHolder -! - signalHiddenLevel "show the selection if signaled; increments hiddenLevel see: #waitHiddenLevel @@ -250,25 +241,6 @@ ]. ! -testMode - "false, than all input events are eaten and the selection - is shown on the target view - " - ^ testMode -! - -testMode:aBoolean - "false, than all input events are eaten and the selection - is shown on the target view - " - testMode ~~ aBoolean ifTrue:[ - self withSelectionHiddenDo:[ - self value:nil. - testMode := aBoolean. - ]. - ]. -! - waitHiddenLevel "hide the selection until signaled; increments hiddenLevel see: #signalHiddenLevel @@ -289,8 +261,42 @@ ]. ! ! +!ViewTreeModel methodsFor:'aspects'! + +hasTargetWidgetChannel + "answer the channel which is set to true if a target widget exists" + + ^ hasTargetWidgetChannel +! + +listOfItems + "hiearchical list build from existing items" + + ^ listOfItems +! + +selectOnClickHolder + "boolean holder, which indicates whether the selection will change on click + " + ^ selectOnClickHolder +! + +testModeChannel + "answer a boolean channel which describes the behaviour how to process + events on the target view. + + false: all input events are eaten and the selection is shown on the target view. + true: no input events are eaten and no selection is shown on the target view." + + ^ testModeChannel +! ! + !ViewTreeModel methodsFor:'change & update'! +targetWidgetChanged + hasTargetWidgetChannel value:(self rootItem notNil). +! + timedUpdateTaskCycle |view myTaskId| @@ -317,6 +323,21 @@ ]. ! +update:something with:someArgument from:aModel + + aModel == testModeChannel ifTrue:[ + (hiddenLevel == 0 and:[selection size > 0]) ifTrue:[ + testModeChannel value ifTrue:[ + self redrawUnselected:selection andLock:false checkTestMode:false. + ] ifFalse:[ + self invalidateSelection. + ]. + ]. + ^ self + ]. + super update:something with:someArgument from:aModel. +! + updateChildren |rootItem| @@ -336,7 +357,7 @@ "catch and process all WindowEvents for the rootComponent and its contained widgets; redraw selection in case of damage .... " - |evView item rootView| + |evView item rootView testMode| evView := anEvent view. evView isNil ifTrue:[ @@ -382,6 +403,8 @@ ]. ^ false ]. + testMode := testModeChannel value. + anEvent isFocusEvent ifTrue:[ evView == rootView ifTrue:[ self invalidateSelection @@ -421,13 +444,17 @@ " super initialize. - hiddenLevel := 0. - lockSema := RecursionLock new. - listOfItems := ItemList new on:self. - selectedSuperItems := #(). - testMode := false. - icons := IdentityDictionary new. - selectOnClickHolder := true asValue. + hiddenLevel := 0. + lockSema := RecursionLock new. + listOfItems := ItemList new on:self. + selectedSuperItems := #(). + icons := IdentityDictionary new. + + hasTargetWidgetChannel := false asValue. + selectOnClickHolder := true asValue. + + testModeChannel := false asValue. + testModeChannel addDependent:self. ! ! !ViewTreeModel methodsFor:'private selection'! @@ -437,7 +464,7 @@ " |topView| - testMode ifTrue:[ ^ self ]. "/ test whether running testMode + testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode ( hiddenLevel == 0 and:[selection notNil @@ -528,7 +555,7 @@ " |topView size| - testMode ifTrue:[ ^ self ]. "/ test whether running testMode + testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode ( hiddenLevel == 0 and:[(size := selection size) > 0 @@ -540,19 +567,24 @@ ]. lockSema critical:[ - topView paint:(Color black). + |list| + + list := selection. - topView clippedByChildren:false. - - selection keysAndValuesReverseDo:[:anIndex :anItem| - (anIndex == 1 and:[size > 1]) ifTrue:[ topView paint:(Color red) ]. + list size > 0 ifTrue:[ + topView paint:(Color black). + topView clippedByChildren:false. - anItem handlesDo:[:aRect :what| - what isNil ifTrue:[topView displayRectangle:aRect] - ifFalse:[topView fillRectangle:aRect] - ] + list keysAndValuesReverseDo:[:anIndex :anItem| + (anIndex == 1 and:[size > 1]) ifTrue:[ topView paint:(Color red) ]. + + anItem handlesDo:[:aRect :what| + what isNil ifTrue:[topView displayRectangle:aRect] + ifFalse:[topView fillRectangle:aRect] + ] + ]. + topView clippedByChildren:true. ]. - topView clippedByChildren:true. ]. ! @@ -560,6 +592,13 @@ "redraw all items unselected; if doLock is true, the hiddenLevel is incremented and thus the select mechanism is locked. " + self redrawUnselected:aList andLock:doLock checkTestMode:true. +! + +redrawUnselected:aList andLock:doLock checkTestMode:checkTestMode + "redraw all items unselected; if doLock is true, the hiddenLevel + is incremented and thus the select mechanism is locked. + " |rootView damages subViews x y w h| doLock ifTrue:[ @@ -568,7 +607,9 @@ ] ifFalse:[ hiddenLevel ~~ 0 ifTrue:[^ self]. ]. - testMode ifTrue:[ ^ self ]. "/ test whether running testMode + checkTestMode ifTrue:[ + testModeChannel value ifTrue:[ ^ self ]. "/ test whether running testMode + ]. ( aList size ~~ 0 and:[(rootView := listOfItems rootView) notNil @@ -595,7 +636,6 @@ damages add:handle ] ]. - "/ rootView clippedByChildren:false. damages do:[:el| x := el left. @@ -606,7 +646,6 @@ rootView clearRectangleX:x y:y width:w height:h. rootView exposeX:x y:y width:w height:h. ]. - "/ rootView clippedByChildren:true. (subViews := rootView subViews) notNil ifTrue:[ subViews reverseDo:[:v| self recursiveRepair:damages startIn:v relativeTo:rootView ]. @@ -614,6 +653,15 @@ ]. ! ! +!ViewTreeModel methodsFor:'queries'! + +isInTestMode + "answer false, all input events are eaten and the selection is shown on the target view. + answer true, no input events are eaten and no selection is shown on the target view." + + ^ testModeChannel value +! ! + !ViewTreeModel methodsFor:'selection accessing'! at:anIndex @@ -1172,6 +1220,10 @@ ] forkAt:(Processor userSchedulingPriority + 2). ]. + treeModel notNil ifTrue:[ + treeModel targetWidgetChanged. + ]. + ^ root. ! @@ -1234,7 +1286,7 @@ processEvent:anEvent "post process event " - ^ treeModel testMode not + ^ treeModel isInTestMode not ! ! !ViewTreeModel::ItemList methodsFor:'instance creation'!