'From Squeakland 3.8.5976 of 25 August 2004 [latest update: #267] on 29 August 2004 at 12:43:01 pm'! "Change Set: SelectionMorphEnh-dgd Date: 29 August 2004 Author: Diego Gomez Deck Assorted improvements for SelectionMorph. To try SelectionMorph you have to start a drag&drop operation with SHIFT pressed. May be be need an entry in Object Catalog for SelectionMorph? Improvements: - Some look&feel changes (color, border color and border width). - More convenient external name. - Two new options: distribute horizontally & distribute vertically. Redistribute the spaces between selected objects in a 'democratic' way. Enjoy it!! "! !SelectionMorph methodsFor: 'halo commands' stamp: 'dgd 8/28/2004 19:10'! addCustomMenuItems: aMenu hand: aHandMorph "Add custom menu items to the menu" super addCustomMenuItems: aMenu hand: aHandMorph. aMenu addLine. aMenu add: 'add or remove items' translated target: self selector: #addOrRemoveItems: argument: aHandMorph. aMenu addList: { #-. {'place into a row' translated. #organizeIntoRow}. {'place into a column' translated. #organizeIntoColumn}. #-. {'align left edges' translated. #alignLeftEdges}. {'align top edges' translated. #alignTopEdges}. {'align right edges' translated. #alignRightEdges}. {'align bottom edges' translated. #alignBottomEdges}. #-. {'align centers vertically' translated. #alignCentersVertically}. {'align centers horizontally' translated. #alignCentersHorizontally}. #-. {'distribute vertically' translated. #distributeVertically}. {'distribute horizontally' translated. #distributeHorizontally}. } ! ! !SelectionMorph methodsFor: 'halo commands' stamp: 'dgd 8/28/2004 19:45'! distributeHorizontally "Distribute the empty vertical space in a democratic way." | minLeft maxRight totalWidth currentLeft space | self selectedItems size > 1 ifFalse: [^ self]. "" minLeft := self selectedItems anyOne left. maxRight := self selectedItems anyOne right. totalWidth := 0. self selectedItems do: [:each | minLeft := minLeft min: each left. maxRight := maxRight max: each right. totalWidth := totalWidth + each width]. "" currentLeft := minLeft. space := (maxRight - minLeft - totalWidth / (self selectedItems size - 1)) rounded. (self selectedItems asSortedCollection: [:x :y | x left <= y left]) do: [:each | each left: currentLeft. currentLeft := currentLeft + each width + space]! ! !SelectionMorph methodsFor: 'halo commands' stamp: 'dgd 8/28/2004 19:48'! distributeVertically "Distribute the empty vertical space in a democratic way." | minTop maxBottom totalHeight currentTop space | self selectedItems size > 1 ifFalse: [^ self]. "" minTop := self selectedItems anyOne top. maxBottom := self selectedItems anyOne bottom. totalHeight := 0. self selectedItems do: [:each | minTop := minTop min: each top. maxBottom := maxBottom max: each bottom. totalHeight := totalHeight + each height]. "" currentTop := minTop. space := (maxBottom - minTop - totalHeight / (self selectedItems size - 1)) rounded. (self selectedItems asSortedCollection:[:x :y | x top <= y top]) do: [:each | each top: currentTop. currentTop := currentTop + each height + space]! ! !SelectionMorph methodsFor: 'initialization' stamp: 'dgd 8/28/2004 19:04'! defaultBorderColor "answer the default border color/fill style for the receiver" ^ Color blue twiceDarker alpha: 0.7! ! !SelectionMorph methodsFor: 'initialization' stamp: 'dgd 8/28/2004 19:00'! defaultBorderWidth "answer the default border width for the receiver" ^ 2! ! !SelectionMorph methodsFor: 'initialization' stamp: 'dgd 8/28/2004 19:01'! defaultColor "answer the default color/fill style for the receiver" ^ Color blue alpha: 0.1! ! !SelectionMorph methodsFor: 'viewer' stamp: 'dgd 8/29/2004 12:34'! externalName ^ 'Selected {1} objects' translated format:{self selectedItems size}! ! !SelectionMorph reorganize! ('*connectors-dropping/grabbing' dismissMorph) ('*connectors-halo commands' addOrRemoveItems:) ('accessing' borderColor: borderWidth:) ('drawing' drawOn:) ('dropping/grabbing' aboutToBeGrabbedBy: justDroppedInto:event: slideToTrash:) ('geometry' bounds: extent:) ('halo commands' addCustomMenuItems:hand: alignBottomEdges alignCentersHorizontally alignCentersVertically alignLeftEdges alignRightEdges alignTopEdges distributeHorizontally distributeVertically doDup:fromHalo:handle: organizeIntoColumn organizeIntoRow) ('halos and balloon help' addHandlesTo:box: addOptionalHandlesTo:box: balloonHelpTextForHandle: hasHalo:) ('initialization' defaultBorderColor defaultBorderWidth defaultColor extendByHand: extendByHandPlus: initialize) ('menus' maybeAddCollapseItemTo:) ('submorphs-add/remove' dismissViaHalo) ('undo' borderColorForItems: borderWidthForItems: fillStyleForItems: refineUndoTarget:selector:arguments:in: undoMove:redo:owner:bounds:predecessor:) ('visual properties' fillStyle:) ('private' doneExtending privateFullMoveBy: selectSubmorphsOf: selectedItems setOtherSelection: setSelectedItems:) ('viewer' externalName) !