UIObjectView.st
changeset 49 7f58dd5fc836
parent 47 5e4319953a0b
child 50 fb4359c9bdc4
equal deleted inserted replaced
48:2fb81a3e0246 49:7f58dd5fc836
     1 ObjectView subclass:#UIObjectView
     1 ObjectView subclass:#UIObjectView
     2 	instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject
     2 	instanceVariableNames:'inputView testMode undoHistory copiedExtent resizedObject
     3 		resizeSelector createInWidget createFrame createdObject
     3 		resizeSelector createInWidget createFrame createdObject
     4 		createClass'
     4 		createClass clipChildren'
     5 	classVariableNames:''
     5 	classVariableNames:''
     6 	poolDictionaries:''
     6 	poolDictionaries:''
     7 	category:'Interface-UIPainter'
     7 	category:'Interface-UIPainter'
     8 !
     8 !
     9 
     9 
   103         ] ifFalse:[
   103         ] ifFalse:[
   104             inputView raise.
   104             inputView raise.
   105             inputView realize
   105             inputView realize
   106         ]
   106         ]
   107     ]
   107     ]
   108 
       
   109 
       
   110 ! !
       
   111 
       
   112 !UIObjectView methodsFor:'cut & paste'!
       
   113 
       
   114 convertForPaste:something
       
   115     Transcript showCR:'convertForPaste'.
       
   116     ^ nil
       
   117 
       
   118 
       
   119 !
       
   120 
       
   121 deleteSelection
       
   122     "delete the selection
       
   123     "
       
   124     undoHistory transactionNamed:'delete' do:[
       
   125         super deleteSelection
       
   126     ].
       
   127 
       
   128 ! !
       
   129 
       
   130 !UIObjectView methodsFor:'dragging object move'!
       
   131 
       
   132 doObjectMove:aPoint
       
   133     "move selection
       
   134     "
       
   135 
       
   136     selection isCollection ifTrue:[^ self].
       
   137 
       
   138     movedObject isNil ifTrue:[
       
   139         (movedObject := selection) isNil ifTrue:[
       
   140             ^ self
       
   141         ].
       
   142         super unselect.
       
   143         moveDelta := aPoint - movedObject computeOrigin.
       
   144         self invertOutlineOf:movedObject
       
   145     ].
       
   146 
       
   147     self moveObject:movedObject to:(aPoint - moveDelta)
       
   148 
       
   149 
       
   150 !
       
   151 
       
   152 endObjectMove
       
   153     "cleanup after object move"
       
   154 
       
   155     movedObject notNil ifTrue:[
       
   156         self invertOutlineOf:movedObject.
       
   157         self setDefaultActions.
       
   158         self select:movedObject.
       
   159         movedObject := nil
       
   160     ].
       
   161 
       
   162     "Modified: 5.9.1995 / 12:20:31 / claus"
       
   163 
       
   164 
       
   165 !
       
   166 
       
   167 startObjectMove:aView at:aPoint
       
   168 
       
   169     super startObjectMove:aView at:aPoint.
       
   170 
       
   171     aView notNil ifTrue:[
       
   172         undoHistory transactionNamed:'move' do:[
       
   173             self undoBlockPositionChanged:aView
       
   174         ]
       
   175     ]
       
   176 
       
   177 
       
   178 !
       
   179 
       
   180 startSelectMoreOrMove:aPoint
       
   181     "add/remove to/from selection"
       
   182 
       
   183     |anObject|
       
   184 
       
   185     testMode ifTrue:[^ self].
       
   186 
       
   187     anObject := self findObjectAtVisible:aPoint.
       
   188     anObject notNil ifTrue:[
       
   189         (self isSelected:anObject) ifTrue:[
       
   190             self removeFromSelection:anObject
       
   191         ] ifFalse:[
       
   192             self addToSelection:anObject
       
   193         ]
       
   194     ]
       
   195 !
       
   196 
       
   197 startSelectOrMove:aPoint
       
   198     "a button is pressed at a point
       
   199     "
       
   200     |anObject b|
       
   201 
       
   202     testMode ifTrue:[^ self].
       
   203 
       
   204     "if there is one selection and point hits handle, start a resize
       
   205     "
       
   206     self singleSelection notNil ifTrue:[
       
   207         b := self whichHandleOf:selection isHitBy:aPoint.
       
   208 
       
   209         (b notNil and:[b ~~ #view]) ifTrue:[
       
   210             ^ self startResizeBorder:b of:selection at:aPoint.
       
   211         ]
       
   212     ].
       
   213 
       
   214     anObject := self findObjectAtVisible:aPoint.
       
   215 
       
   216     "nothing is selected
       
   217     "
       
   218     anObject isNil ifTrue:[
       
   219         ^ self unselect
       
   220     ].
       
   221 
       
   222     "object not in selection; clear selection and add anObject to selection
       
   223     "
       
   224     (self isSelected:anObject) ifFalse:[
       
   225         super unselect.
       
   226         self select:anObject.
       
   227     ] ifTrue:[
       
   228         selection isCollection ifTrue:[
       
   229             ^ self removeFromSelection:anObject.
       
   230         ]
       
   231     ].
       
   232 
       
   233     "prepare move operation for an object
       
   234     "
       
   235     motionAction := [:movePoint|
       
   236         (aPoint dist:movePoint) > 2.0 ifTrue:[
       
   237             self startObjectMove:anObject at:aPoint
       
   238         ]
       
   239     ].
       
   240     releaseAction := [self setDefaultActions].
       
   241 
   108 
   242 
   109 
   243 ! !
   110 ! !
   244 
   111 
   245 !UIObjectView methodsFor:'event handling'!
   112 !UIObjectView methodsFor:'event handling'!
   344 
   211 
   345     inputView eventReceiver:self.
   212     inputView eventReceiver:self.
   346     inputView enableButtonEvents.
   213     inputView enableButtonEvents.
   347     inputView enableButtonMotionEvents.
   214     inputView enableButtonMotionEvents.
   348 
   215 
       
   216     self setDefaultActions.
       
   217 
   349     undoHistory := UndoHistory new.
   218     undoHistory := UndoHistory new.
   350 
   219 
   351     undoHistory modifiedAction:[:what|
   220     undoHistory modifiedAction:[:what|
   352         self changed:#undoHistory with:what
   221         self changed:#undoHistory with:what
   353     ].
   222     ].
   354 
   223 
   355     testMode := false.
   224     testMode := false.
       
   225     clipChildren := true.
   356 
   226 
   357     (self class gridShown) ifTrue:[
   227     (self class gridShown) ifTrue:[
   358         super showGrid
   228         super showGrid
   359     ].
   229     ].
   360 
   230 
   376 
   246 
   377 
   247 
   378 !
   248 !
   379 
   249 
   380 invertOutlineOf:anObject
   250 invertOutlineOf:anObject
   381     |delta|
   251     |wasClipped delta|
   382 
   252 
   383     self clippedByChildren:false.
   253     (wasClipped := clipChildren) ifTrue:[
       
   254         self clippedByChildren:(clipChildren := false).
       
   255     ].
   384     delta := (anObject originRelativeTo:self) - anObject origin.
   256     delta := (anObject originRelativeTo:self) - anObject origin.
       
   257 
   385     self xoring:[
   258     self xoring:[
   386         self displayRectangle:((anObject origin + delta) extent:anObject extent).
   259         self displayRectangle:((anObject origin + delta) extent:anObject extent).
   387     ].
   260     ].
   388     self clippedByChildren:true.
   261 
       
   262     wasClipped ifTrue:[
       
   263         self clippedByChildren:(clipChildren := true).
       
   264     ].
   389 
   265 
   390     "Modified: 5.9.1995 / 12:25:25 / claus"
   266     "Modified: 5.9.1995 / 12:25:25 / claus"
   391 
   267 
       
   268 
       
   269 !
       
   270 
       
   271 setDefaultActions
       
   272 
       
   273     pressAction      := [:pressPoint | self startSelectOrMove:pressPoint].
       
   274     shiftPressAction := [:pressPoint | self startSelectMoreOrMove:pressPoint].
       
   275     motionAction     := [:movePoint  | nil].
       
   276     releaseAction    := [nil].
       
   277     keyPressAction   := [:key | self doKeyInput:key].
       
   278 
       
   279     self cursor:Cursor normal.
   392 
   280 
   393 !
   281 !
   394 
   282 
   395 showDragging:something offset:anOffset
   283 showDragging:something offset:anOffset
   396     "drag around a View"
   284     "drag around a View"
   427 !
   315 !
   428 
   316 
   429 endCreate
   317 endCreate
   430     "end a widget create drag
   318     "end a widget create drag
   431     "
   319     "
       
   320     |layout x y|
       
   321 
   432     self invertOutlineOf:createdObject.
   322     self invertOutlineOf:createdObject.
   433     self cursor:oldCursor.
       
   434     inputView raise.
   323     inputView raise.
   435 
   324 
   436     createdObject geometryLayout:(createdObject bounds asLayout).
   325     layout := createdObject bounds asLayout.
       
   326     createdObject geometryLayout:layout.
   437 
   327 
   438     self changed:#tree.
   328     self changed:#tree.
   439     self select:createdObject.
   329     self select:createdObject.
   440     createdObject := nil.
   330     createdObject := nil.
   441 
   331 
   442     pressAction   := [:pressPoint | self startSelectOrMove:pressPoint].
   332     self setDefaultActions.
   443     motionAction  := [:movePoint | true].
   333 
   444     releaseAction := [ true ].
   334 !
   445 
   335 
   446     self cursor:Cursor normal.
   336 setupCreatedObject:anObject
   447 
       
   448 
       
   449 !
       
   450 
       
   451 initializeCreatedObject:anObject
       
   452     self subclassResponsibility
   337     self subclassResponsibility
   453 !
   338 !
   454 
   339 
   455 startCreate:aPoint
   340 startCreate:aPoint
   456     "start a widget create
   341     "start a widget create
   457     "
   342     "
   458     |props index startPoint|
   343     |startPoint|
   459 
   344 
   460     createClass isNil ifTrue:[
   345     createClass isNil ifTrue:[
   461         ^ self
   346         ^ self setDefaultActions
       
   347     ].
       
   348     (selection isKindOf:Collection) ifTrue:[
       
   349         self unselect.
       
   350       ^ self setDefaultActions.
   462     ].
   351     ].
   463 
   352 
   464     startPoint    := self alignToGrid:aPoint.
   353     startPoint    := self alignToGrid:aPoint.
   465     motionAction  := [:movePoint | self doDragCreate:movePoint].
   354     motionAction  := [:movePoint| self doDragCreate:movePoint].
   466     releaseAction := [self endCreate].
   355     releaseAction := [ self endCreate].
   467 
   356 
   468     (selection isNil or:[selection isKindOf:Collection]) ifTrue:[
   357     selection notNil ifTrue:[
   469         createInWidget := self findObjectIn:self at:aPoint
   358         (    (self isPoint:aPoint containedIn:selection)
   470     ] ifFalse:[
   359          and:[selection specClass basicNew supportsSubComponents]
   471         createInWidget := self findObjectIn:selection at:aPoint
   360         ) ifFalse:[
   472     ].
   361             self unselect
   473     super unselect.
   362         ]
   474     self select:createInWidget.
   363     ].
   475 
   364 
   476     oldCursor := cursor.
   365     oldCursor := cursor.
   477     self cursor:(Cursor leftHand).
   366     self cursor:(Cursor leftHand).
   478 
   367 
   479     createInWidget isNil ifTrue:[
   368     createInWidget := selection ? self.
   480         createdObject  := createClass in:self.
   369     createdObject  := createClass new.
   481         createInWidget := self.
   370     createInWidget addSubView:createdObject.
   482     ] ifFalse:[
       
   483         createdObject := createClass new.
       
   484         createInWidget addSubView:createdObject.
       
   485     ].
       
   486 
   371 
   487     createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self))
   372     createFrame := Rectangle origin:(startPoint - (createInWidget originRelativeTo:self))
   488                              corner:startPoint.
   373                              corner:startPoint.
   489 
   374 
   490     createdObject origin:(createFrame origin).
   375     createdObject origin:(createFrame origin).
   491 
   376 
   492     undoHistory transactionNamed:'create' do:[
   377     undoHistory transactionNamed:'create' do:[
   493         self initializeCreatedObject:createdObject.
   378         self setupCreatedObject:createdObject.
   494     ].
   379     ].
   495     createdObject realize.
   380     createdObject realize.
   496     self invertOutlineOf:createdObject.
   381     self invertOutlineOf:createdObject.
       
   382 ! !
       
   383 
       
   384 !UIObjectView methodsFor:'object moving'!
       
   385 
       
   386 doObjectMove:aPoint
       
   387     "move selection
       
   388     "
       
   389     movedObject notNil ifTrue:[
       
   390         movedObject keysAndValuesDo:[:nr :aView|
       
   391             self invertOutlineOf:aView.
       
   392             self moveObject:aView to:(aPoint - (moveDelta at:nr)).
       
   393             self invertOutlineOf:aView.
       
   394         ]
       
   395     ]
       
   396 
       
   397 !
       
   398 
       
   399 endObjectMove
       
   400     "cleanup after object move"
       
   401 
       
   402     movedObject notNil ifTrue:[
       
   403         movedObject do:[:aView|
       
   404             self invertOutlineOf:aView
       
   405         ].
       
   406 
       
   407         movedObject do:[:aView|
       
   408             self showSelected:aView
       
   409         ].
       
   410         movedObject size == 1 ifTrue:[
       
   411             selection := movedObject at:1
       
   412         ] ifFalse:[
       
   413             selection := movedObject
       
   414         ].
       
   415 
       
   416         movedObject := nil.
       
   417         self setDefaultActions.
       
   418         self changed:#layout.
       
   419     ].
       
   420 !
       
   421 
       
   422 startObjectMoveAt:aPoint
       
   423 
       
   424     self startObjectMove:selection at:aPoint.
       
   425 
       
   426     selection size == 0 ifTrue:[
       
   427         movedObject := Array with:selection
       
   428     ] ifFalse:[
       
   429         movedObject := selection
       
   430     ].
       
   431     super unselect.
       
   432 
       
   433     moveDelta := movedObject collect:[:aView|
       
   434         aPoint - aView computeOrigin
       
   435     ].
       
   436 
       
   437     undoHistory transactionNamed:'move' do:[
       
   438         movedObject do:[:aView|
       
   439             self invertOutlineOf:aView.
       
   440             self undoBlockPositionChanged:aView
       
   441         ]
       
   442     ]
       
   443 !
       
   444 
       
   445 startSelectMoreOrMove:aPoint
       
   446     "add/remove to/from selection"
       
   447 
       
   448     |anObject|
       
   449 
       
   450     testMode ifTrue:[^ self].
       
   451 
       
   452     anObject := self findObjectAt:aPoint.
       
   453     anObject notNil ifTrue:[
       
   454         (self isSelected:anObject) ifTrue:[
       
   455             self removeFromSelection:anObject
       
   456         ] ifFalse:[
       
   457             self addToSelection:anObject
       
   458         ]
       
   459     ]
       
   460 !
       
   461 
       
   462 startSelectOrMove:aPoint
       
   463     "a button is pressed at a point
       
   464     "
       
   465     |anObject b|
       
   466 
       
   467     testMode ifTrue:[^ self].
       
   468 
       
   469     "if there is one selection and point hits handle, start a resize
       
   470     "
       
   471     self singleSelection notNil ifTrue:[
       
   472         b := self whichHandleOf:selection isHitBy:aPoint.
       
   473 
       
   474         (b notNil and:[b ~~ #view]) ifTrue:[
       
   475             ^ self startResizeBorder:b of:selection at:aPoint.
       
   476         ]
       
   477     ].
       
   478 
       
   479     anObject := self findObjectAt:aPoint.
       
   480 
       
   481     "nothing is selected
       
   482     "
       
   483     anObject isNil ifTrue:[
       
   484         ^ self unselect
       
   485     ].
       
   486 
       
   487     (self isSelected:anObject) ifFalse:[
       
   488         super unselect.
       
   489         self select:anObject.
       
   490     ].
       
   491 
       
   492     selection isCollection ifTrue:[
       
   493         releaseAction := [
       
   494             self setDefaultActions.
       
   495             self select:anObject
       
   496         ]
       
   497     ] ifFalse:[
       
   498         releaseAction := [self setDefaultActions]
       
   499     ].
       
   500 
       
   501     "prepare move operation for an object
       
   502     "
       
   503     motionAction := [:movePoint|
       
   504         (aPoint dist:movePoint) > 2.0 ifTrue:[
       
   505             self startObjectMoveAt:aPoint
       
   506         ]
       
   507     ].
   497 ! !
   508 ! !
   498 
   509 
   499 !UIObjectView methodsFor:'private handles'!
   510 !UIObjectView methodsFor:'private handles'!
   500 
   511 
   501 handlesOf:aComponent do:aBlock
   512 handlesOf:aComponent do:aBlock
   536 
   547 
   537 
   548 
   538 !
   549 !
   539 
   550 
   540 showSelected:aComponent
   551 showSelected:aComponent
   541     |delta oldPaint|
   552     |wasClipped delta oldPaint|
   542 
   553 
   543     self paint:Color black. 
   554     self paint:Color black.
   544     self clippedByChildren:false. 
   555 
       
   556     (wasClipped := clipChildren) ifTrue:[
       
   557         self clippedByChildren:(clipChildren := false). 
       
   558     ].
   545 
   559 
   546     self handlesOf:aComponent do:[:pnt :what |
   560     self handlesOf:aComponent do:[:pnt :what |
   547         what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)]
   561         what == #view ifTrue:[self displayRectangle:(pnt - (4@4) extent:7@7)]
   548                      ifFalse:[self    fillRectangle:(pnt - (4@4) extent:7@7)]
   562                      ifFalse:[self    fillRectangle:(pnt - (4@4) extent:7@7)]
   549     ].
   563     ].
   550 
   564 
   551     self clippedByChildren:true.
   565     wasClipped ifTrue:[
       
   566         self clippedByChildren:(clipChildren := true).
       
   567     ].
   552     self paint:oldPaint.
   568     self paint:oldPaint.
   553 !
   569 !
   554 
   570 
   555 showUnselected:aComponent
   571 showUnselected:aComponent
   556     |delta r oldPaint|
   572     |wasClipped delta r oldPaint|
   557 
   573 
   558     r := aComponent origin extent:8@8.
   574     r := aComponent origin extent:8@8.
   559 
   575 
   560     self clippedByChildren:false. 
   576     (wasClipped := clipChildren) ifTrue:[
       
   577         self clippedByChildren:(clipChildren := false). 
       
   578     ].
   561 
   579 
   562     self handlesOf:aComponent do:[:pnt :what |
   580     self handlesOf:aComponent do:[:pnt :what |
   563         self clearRectangle:(pnt - (4@4) extent:7@7).
   581         self clearRectangle:(pnt - (4@4) extent:7@7).
   564     ].
   582     ].
   565 
   583 
   566     self clippedByChildren:true. 
   584     wasClipped ifTrue:[
       
   585         self clippedByChildren:(clipChildren := true). 
       
   586     ].
   567 
   587 
   568     "/ must redraw all components which are affected b the handles
   588     "/ must redraw all components which are affected b the handles
   569 
   589 
   570     r := (aComponent originRelativeTo:self) - (4@4)
   590     r := (aComponent originRelativeTo:self) - (4@4)
   571              extent:(aComponent extent + (4@4)).
   591              extent:(aComponent extent + (4@4)).
   715 ! !
   735 ! !
   716 
   736 
   717 !UIObjectView methodsFor:'searching'!
   737 !UIObjectView methodsFor:'searching'!
   718 
   738 
   719 findObjectAt:aPoint
   739 findObjectAt:aPoint
   720     "find the origin/corner of the currentWidget"
       
   721 
       
   722      selection notNil ifTrue:[
       
   723         (selection isKindOf:Collection) ifTrue:[
       
   724             ^ self findObjectIn:(selection first) at:aPoint
       
   725         ].
       
   726         ^ self findObjectIn:selection at:aPoint
       
   727      ].
       
   728      ^ self findObjectIn:self at:aPoint
       
   729 
       
   730 
       
   731 
       
   732 !
       
   733 
       
   734 findObjectIn:aView at:aPoint
       
   735     "find the origin/corner of the currentWidget
   740     "find the origin/corner of the currentWidget
   736     "
   741     "
   737     |relPoint|
   742     |view viewId lastId point|
   738 
   743 
   739     aView isNil ifTrue:[^ nil].
   744     viewId := rootView id.
   740     aView subViews notNil ifTrue:[
   745     point  := aPoint + (device translatePoint:0@0 from:(self id) to:viewId).
   741         relPoint := aPoint - (aView originRelativeTo:self).
   746 
   742         self subviewsOf:aView do:[:aView |
   747     inputView lower.
   743             |org ext|
   748 
   744 
   749     [viewId notNil] whileTrue:[
   745             (aView isKindOf:InputView) ifFalse:[
   750         lastId := viewId.
   746                 org := aView computeOrigin.
   751         viewId := device viewIdFromPoint:point in:lastId
   747                 ext := aView computeExtent.
   752     ].
   748                 ((org extent:ext) containsPoint:relPoint) ifTrue:[
   753 
   749                     ^ aView
   754     inputView raise.
   750                 ]
   755 
   751             ]
   756     view := device viewFromId:lastId.
   752         ]
   757 
   753     ].
   758     view ~~ inputView ifTrue:[^ view]
   754     (aView == self) ifTrue:[^ nil].
   759                      ifFalse:[^ nil]
   755 
   760 
   756     ^ self findObjectIn:(aView superView) at:aPoint
   761 
       
   762 !
       
   763 
       
   764 isPoint:aPoint containedIn:aView
       
   765     "checks whether a point is covered by a view.
       
   766     "
       
   767     |org ext|
       
   768 
       
   769     org := aView computeOrigin.
       
   770     ext := aView computeExtent.
       
   771 
       
   772     ^ ((org extent:ext) containsPoint:aPoint)
   757 !
   773 !
   758 
   774 
   759 whichBorderOf:aView isHitBy:aPoint
   775 whichBorderOf:aView isHitBy:aPoint
   760     |p r bw org|
   776     |p r bw org|
   761 
   777 
   783 
   799 
   784 !UIObjectView methodsFor:'selections'!
   800 !UIObjectView methodsFor:'selections'!
   785 
   801 
   786 addToSelection:something
   802 addToSelection:something
   787     (testMode or:[something == selection]) ifFalse:[
   803     (testMode or:[something == selection]) ifFalse:[
   788         selection ~~ something ifTrue:[
   804         super addToSelection:something.
   789             super addToSelection:something.
   805         self changed:#selection.
   790             self changed:#selection.
       
   791         ]
       
   792     ]
   806     ]
   793 !
   807 !
   794 
   808 
   795 inspectSelection
   809 inspectSelection
   796     self singleSelectionDo:[:aView |
   810     self singleSelectionDo:[:aView |
  1058     "move anObject to newOrigin, aPoint
  1072     "move anObject to newOrigin, aPoint
  1059     "
  1073     "
  1060     |dX dY org delta|
  1074     |dX dY org delta|
  1061 
  1075 
  1062     anObject notNil ifTrue:[
  1076     anObject notNil ifTrue:[
  1063         self invertOutlineOf:anObject.
       
  1064 
       
  1065         org := anObject computeOrigin.
  1077         org := anObject computeOrigin.
  1066 
  1078 
  1067         delta := aPoint - org.
  1079         delta := aPoint - org.
  1068         delta := (self alignToGrid:aPoint) - org.
  1080         delta := (self alignToGrid:aPoint) - org.
  1069         dX := delta x.
  1081         dX := delta x.
  1071 
  1083 
  1072         undoHistory disabledTransitionDo:[
  1084         undoHistory disabledTransitionDo:[
  1073             self shifLayout:anObject top:dY bottom:dY left:dX right:dX
  1085             self shifLayout:anObject top:dY bottom:dY left:dX right:dX
  1074         ].
  1086         ].
  1075         self elementChangedLayout:anObject.
  1087         self elementChangedLayout:anObject.
  1076         self invertOutlineOf:anObject.
       
  1077     ]
  1088     ]
  1078 
  1089 
  1079 !
  1090 !
  1080 
  1091 
  1081 moveSelectionDown
  1092 moveSelectionDown