# HG changeset patch # User Claus Gittinger # Date 1288526472 -3600 # Node ID 16652b9859a700fb1ffb8af24aa643630c6a4f01 # Parent 178e5a5da19b1f240a3e3d0d56c718c6c2fd3f64 snapAdornment stuff cleanup diff -r 178e5a5da19b -r 16652b9859a7 VariablePanel.st --- a/VariablePanel.st Sun Oct 31 12:53:00 2010 +0100 +++ b/VariablePanel.st Sun Oct 31 13:01:12 2010 +0100 @@ -24,6 +24,15 @@ category:'Views-Layout' ! +Object subclass:#SnapAdornment + instanceVariableNames:'level mode selectedLevel enterLevel selectedBgColor enterBgColor + iconLeftRight iconUpDown iconLeft iconRight iconUp iconDown width + height' + classVariableNames:'' + poolDictionaries:'' + privateIn:VariablePanel +! + !VariablePanel class methodsFor:'documentation'! copyright @@ -1083,10 +1092,10 @@ ! setBarHeight:nPixel - "check whether snap matches to extent of bar otherwise disable snap - " + "check whether snap matches to extent of bar otherwise disable snap" + snapAdornment notNil ifTrue:[ - barHeight := nPixel max:(snapAdornment at:#height ifAbsent:0) + barHeight := nPixel max:(snapAdornment height ? 0) ] ifFalse:[ barHeight := nPixel max:0 ]. @@ -1095,6 +1104,7 @@ self resizeSubviews ] + "Modified: / 31-10-2010 / 13:00:06 / cg" ! showHandle @@ -1141,10 +1151,11 @@ #minMax on press the view is increased or decreased dependent on its current extent " snapAdornment notNil ifTrue:[ - ^ snapAdornment at:#mode ifAbsent:nil + ^ snapAdornment mode ]. ^ nil + "Modified: / 31-10-2010 / 13:00:16 / cg" ! snapMode:aMode @@ -1167,7 +1178,7 @@ (snapAdornment notNil and:[aMode notNil]) ifTrue:[ "must only redraw" - snapAdornment at:#mode put:aMode + snapAdornment mode:aMode ] ifFalse:[ "must recompute barHeight and redraw" @@ -1175,7 +1186,7 @@ snapAdornment := nil ] ifFalse:[ self initSnapAdornment. - snapAdornment at:#mode put:aMode. + snapAdornment mode:aMode. ]. oldHeight := barHeight. @@ -1187,7 +1198,9 @@ self resizeSubviews. ] ]. - self redrawIfShown. + self redrawIfShown. + + "Modified: / 31-10-2010 / 13:00:39 / cg" ! style:styleSymbol @@ -1495,51 +1508,48 @@ ! drawSnapAt:anIndex - "draw the snap for a handle at an index - " - |layout icon level offLevel paint canChangeExtent + "draw the snap for a handle at an index" + + |snapLayout icon level offLevel paint canChangeExtent left "{ Class:SmallInteger }" top "{ Class:SmallInteger }" width "{ Class:SmallInteger }" height "{ Class:SmallInteger }" - snapMode leftEdge wEdge topEdge hEdge part wPart hPart - | - - (layout := self snapLayoutAt:anIndex) isNil ifTrue:[ + snapMode leftEdge wEdge topEdge hEdge part wPart hPart| + + (snapLayout := self snapLayoutAt:anIndex) isNil ifTrue:[ "snap disabled" ^ self ]. - left := layout left. - top := layout top. - width := layout width. - height := layout height. + left := snapLayout left. + top := snapLayout top. + width := snapLayout width. + height := snapLayout height. snapMode := self snapMode. - offLevel := level := snapAdornment at:#level ifAbsent:0. + offLevel := level := (snapAdornment level ? 0). canChangeExtent := self canChangeExtentOfViewAt:anIndex. canChangeExtent ifTrue:[ (controller isSnapEntered:anIndex) ifTrue:[ controller isSnapPressed ifTrue:[ - level := #selectedLevel. - paint := #selectedBgColor. + level := snapAdornment selectedLevel ? 0. + paint := snapAdornment selectedBgColor. ] ifFalse:[ - level := #enterLevel. - paint := #enterBgColor. + level := snapAdornment enterLevel ? 0. + paint := snapAdornment enterBgColor. ]. - level := snapAdornment at:level ifAbsent:0. ] ]. - paint notNil ifTrue:[ - paint := snapAdornment at:paint ifAbsent:viewBackground - ] ifFalse:[ - paint := viewBackground + paint isNil ifTrue:[ + paint := viewBackground. ]. + self paint:paint. - level == 0 ifTrue:[ - ]. +"/ level == 0 ifTrue:[ +"/ ]. self fillRectangleX:left+1 y:top+1 width:width-2 height:height-2. @@ -1589,18 +1599,25 @@ canChangeExtent ifFalse:[^ self]. snapMode == #both ifTrue:[ - icon := orientation == #vertical ifTrue:[#iconUpDown] ifFalse:[#iconLeftRight] + icon := (orientation == #vertical) + ifTrue:[snapAdornment iconUpDown] + ifFalse:[snapAdornment iconLeftRight] ] ifFalse:[ (self snapAtIndexWillGrow:anIndex) ifTrue:[ - icon := orientation == #vertical ifTrue:[#iconDown] ifFalse:[#iconRight] + icon := (orientation == #vertical) + ifTrue:[snapAdornment iconDown] + ifFalse:[snapAdornment iconRight] ] ifFalse:[ - icon := orientation == #vertical ifTrue:[#iconUp] ifFalse:[#iconLeft] + icon := (orientation == #vertical) + ifTrue:[snapAdornment iconUp] + ifFalse:[snapAdornment iconLeft] ]. ]. - icon := snapAdornment at:icon ifAbsent:nil. - - icon displayOn:self x:(left + (width - icon width // 2)) - y:(top + (height - icon height // 2)). + + icon displayOn:self x:(left + ((width - icon width) // 2)) + y:(top + ((height - icon height) // 2)). + + "Modified: / 31-10-2010 / 12:58:27 / cg" ! invertHandleBarAtX:hx y:hy @@ -1658,10 +1675,9 @@ ! redrawHandlesFrom:start to:stop - "redraw some handles and snaps - " + "redraw some handles and snaps" + subViews size ~~ 0 ifTrue:[ - "/ do not draw handle, if there is a snapper ... self handleOriginsWithIndexFrom:start to:stop do:[:hPoint :hIndex | |hx hy| @@ -1670,14 +1686,19 @@ barLevel notNil ifTrue:[ self drawEdgesForX:0 y:hy width:width height:barHeight level:barLevel. ]. - (showHandle and:[snapAdornment isNil]) ifTrue:[ - self drawHandle:hIndex atX:hx y:hy. + + "/ do not draw handle, if there is a snapper ... + self hasSnapHandle ifTrue:[ + self drawSnapAt:hIndex-1 + ] ifFalse:[ + showHandle ifTrue:[ + self drawHandle:hIndex atX:hx y:hy. + ]. ]. - snapAdornment notNil ifTrue:[ - self drawSnapAt:hIndex-1 - ] ]. ]. + + "Modified: / 31-10-2010 / 12:43:33 / cg" ! unlockRedraw @@ -2172,54 +2193,59 @@ initSnapAdornment |num icon level enterLevel selectedLevel color| - snapAdornment notNil ifTrue:[^ snapAdornment ]. - - snapAdornment := IdentityDictionary new. - - level := styleSheet at:#'variablePanel.snapLevel' default:1. - enterLevel := styleSheet at:#'variablePanel.snapEnterLevel' default:level. - selectedLevel := styleSheet at:#'variablePanel.selectedLevel' default:(level negated). - - snapAdornment at:#level put:level. - snapAdornment at:#enterLevel put:enterLevel. - snapAdornment at:#selectedLevel put:selectedLevel. - snapAdornment at:#mode put:#min. - - color := styleSheet colorAt:#'variablePanel.snapSelectedBgColor' - default:(StyleSheet colorAt:#'button.activeBackgroundColor'). - color notNil ifTrue:[ - snapAdornment at:#selectedBgColor put:(color onDevice:device) + snapAdornment isNil ifTrue:[ + + snapAdornment := SnapAdornment "IdentityDictionary" new. + + level := styleSheet at:#'variablePanel.snapLevel' default:1. + enterLevel := styleSheet at:#'variablePanel.snapEnterLevel' default:level. + selectedLevel := styleSheet at:#'variablePanel.selectedLevel' default:(level negated). + + snapAdornment level:level. + snapAdornment enterLevel:enterLevel. + snapAdornment selectedLevel:selectedLevel. + snapAdornment mode:#min. + + color := styleSheet + colorAt:#'variablePanel.snapSelectedBgColor' + default:(StyleSheet colorAt:#'button.activeBackgroundColor'). + color notNil ifTrue:[ + snapAdornment selectedBgColor:(color onDevice:device) + ]. + + color := StyleSheet + colorAt:#'variablePanel.snapEnterBgColor' + default:(StyleSheet colorAt:#'button.enteredBackgroundColor'). + color notNil ifTrue:[ + snapAdornment enterBgColor:(color onDevice:device) + ]. + + self class snapIcons keysAndValuesDo:[:aKey :anIcon| + anIcon device == device ifTrue:[ + icon := anIcon + ] ifFalse:[ + icon := anIcon copy onDevice:device. + icon clearMaskedPixels. + device == Display ifTrue:[ + self class snapIcons at:aKey put:icon. + ] + ]. + snapAdornment at:aKey put:icon + ]. + "compute required snap extent including level and margins ..." + + num := level abs max:(enterLevel abs). + num := num max:(selectedLevel abs). + num := (num + 2) "margin into handle := 1" * 2. + icon := snapAdornment iconUp. + + snapAdornment height:(icon height + num). + snapAdornment width:(icon width + num). ]. - color := StyleSheet colorAt:#'variablePanel.snapEnterBgColor' - default:(StyleSheet colorAt:#'button.enteredBackgroundColor'). - color notNil ifTrue:[ - snapAdornment at:#enterBgColor put:(color onDevice:device) - ]. - - self class snapIcons keysAndValuesDo:[:aKey :anIcon| - anIcon device == device ifTrue:[ - icon := anIcon - ] ifFalse:[ - icon := anIcon copy onDevice:device. - icon clearMaskedPixels. - device == Display ifTrue:[ - self class snapIcons at:aKey put:icon. - ] - ]. - snapAdornment at:aKey put:icon - ]. - "compute required snap extent including level and margins ..." - - num := level abs max:(enterLevel abs). - num := num max:(selectedLevel abs). - num := num + 2 "margin into handle := 1" * 2. - icon := snapAdornment at:#iconUp. - - snapAdornment at:#height put:(icon height + num). - snapAdornment at:#width put:(icon width + num). - ^ snapAdornment + + "Modified: / 31-10-2010 / 12:59:39 / cg" ! snapAtIndexWillGrow:anIndex @@ -2252,11 +2278,11 @@ " |v1 v2 left top right bot w snapX snapY| - snapAdornment isNil ifTrue:[^ nil]. "snap disabled" + self hasSnapHandle ifFalse:[^ nil]. "snap disabled" v1 := subViews at:anIndex ifAbsent:[^ nil]. v2 := subViews at:anIndex + 1 ifAbsent:[^ nil]. - w := snapAdornment at:#width ifAbsent:0. + w := snapAdornment width ? 0. handlePosition "snapHandlePosition" == #left ifTrue:[ snapX := snapY := margin. "/ ViewSpacing. @@ -2282,6 +2308,8 @@ bot := top + w. ]. ^ Rectangle left:left top:top right:right bottom:bot + + "Modified: / 31-10-2010 / 12:47:16 / cg" ! ! !VariablePanel methodsFor:'private-tableView protocol'! @@ -2336,6 +2364,12 @@ !VariablePanel methodsFor:'queries'! +hasSnapHandle + ^ snapAdornment notNil + + "Created: / 31-10-2010 / 12:43:21 / cg" +! + isLayoutWrapper "answer true, if this view defines the layout of it's subviews" @@ -2374,12 +2408,149 @@ "Modified: 28.1.1997 / 17:54:15 / cg" ! ! +!VariablePanel::SnapAdornment methodsFor:'accessing'! + +enterBgColor + ^ enterBgColor +! + +enterBgColor:something + enterBgColor := something. +! + +enterLevel + ^ enterLevel +! + +enterLevel:something + enterLevel := something. +! + +height + ^ height +! + +height:something + height := something. +! + +iconDown + ^ iconDown +! + +iconDown:something + iconDown := something. +! + +iconLeft + ^ iconLeft +! + +iconLeft:something + iconLeft := something. +! + +iconLeftRight + ^ iconLeftRight +! + +iconLeftRight:something + iconLeftRight := something. +! + +iconRight + ^ iconRight +! + +iconRight:something + iconRight := something. +! + +iconUp + ^ iconUp +! + +iconUp:something + iconUp := something. +! + +iconUpDown + ^ iconUpDown +! + +iconUpDown:something + iconUpDown := something. +! + +level + ^ level +! + +level:something + level := something. +! + +mode + ^ mode +! + +mode:something + mode := something. +! + +selectedBgColor + ^ selectedBgColor +! + +selectedBgColor:something + selectedBgColor := something. +! + +selectedLevel + ^ selectedLevel +! + +selectedLevel:something + selectedLevel := something. +! + +width + ^ width +! + +width:something + width := something. +! ! + +!VariablePanel::SnapAdornment methodsFor:'backward compatibility'! + +at:key + ^ self perform:key + + "Created: / 31-10-2010 / 12:38:58 / cg" +! + +at:key ifAbsent:default + |value| + + value := self perform:key. + ^ value ? default + + "Created: / 31-10-2010 / 12:41:10 / cg" +! + +at:key put:aValue + self perform:(key,':') asSymbol with:aValue + + "Created: / 31-10-2010 / 12:38:48 / cg" +! ! + !VariablePanel class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libwidg/VariablePanel.st,v 1.90 2009-10-28 17:02:39 cg Exp $' + ^ '$Header: /cvs/stx/stx/libwidg/VariablePanel.st,v 1.91 2010-10-31 12:01:12 cg Exp $' ! version_CVS - ^ '$Header: /cvs/stx/stx/libwidg/VariablePanel.st,v 1.90 2009-10-28 17:02:39 cg Exp $' + ^ '$Header: /cvs/stx/stx/libwidg/VariablePanel.st,v 1.91 2010-10-31 12:01:12 cg Exp $' ! !