UIObjectView.st
changeset 1427 85b9b5da0b8d
parent 1399 a0687f5e1f54
child 1437 daaf701ab6a2
equal deleted inserted replaced
1426:fcf2ecbdde67 1427:85b9b5da0b8d
   940     self invertOutlineOf:object
   940     self invertOutlineOf:object
   941 ! !
   941 ! !
   942 
   942 
   943 !UIObjectView methodsFor:'private handles'!
   943 !UIObjectView methodsFor:'private handles'!
   944 
   944 
   945 handleAffectedViews:aViewOrSeqOfViews
       
   946     "update affected views
       
   947     "
       
   948     |c|
       
   949 
       
   950     self forEach:aViewOrSeqOfViews do:[:v|
       
   951 	v shown ifTrue:[
       
   952 	    v fill:v viewBackground.
       
   953 	    v borderWidth ~~ 0 ifTrue:[
       
   954 		c := v borderColor.
       
   955 		v borderColor:(Color colorId:1).
       
   956 		v borderColor:c.
       
   957 	    ].
       
   958 	    v exposeX:0 y:0 width:(v width) height:(v height)
       
   959 	]
       
   960     ]
       
   961 
       
   962     "Modified: / 16.9.1998 / 01:40:30 / cg"
       
   963 !
       
   964 
       
   965 handlesOf:aComponent do:aTwoArgAction
   945 handlesOf:aComponent do:aTwoArgAction
   966     "perform action on each handle of a component
   946     "perform action on each handle of a component
   967     "
   947     "
   968     |dlt ext|
   948     |dlt ext|
   969 
   949 
   970     dlt := (aComponent originRelativeTo:self) - aComponent origin.
   950     dlt := (aComponent originRelativeTo:self) - aComponent origin.
   971     dlt := dlt - (3@3).
   951     dlt := dlt - (3@3).
   972     ext := 6@6.
   952     ext := 6@6.
   973 
   953 
   974     self class handlesOf:aComponent do:[:pnt :wht |
   954     self class handlesOf:aComponent do:[:pnt :wht |
   975 	aTwoArgAction value:(pnt + dlt extent:ext) value:wht
   955         aTwoArgAction value:(pnt + dlt extent:ext) value:wht
   976     ]
   956     ]
   977 !
       
   978 
       
   979 showUnselected:aComponent
       
   980     "show object unselected
       
   981     "
       
   982     self showUnselected:aComponent addAffectedViewsTo:nil
       
   983 !
       
   984 
       
   985 showUnselected:aComponent addAffectedViewsTo:aSet
       
   986     "show object unselected. If the set, an IdentitySet, is not nil, the
       
   987      affected subviews are added into the set, otherwise an expose event
       
   988      to each affected component is raised.
       
   989     "
       
   990     |wasClipped r v|
       
   991 
       
   992     selectionHiddenLevel ~~ 0 ifTrue:[^ self].
       
   993 
       
   994 "/    "/ new: simply create a little view ontop,
       
   995 "/    "/ and move it over the handles. This will generate
       
   996 "/    "/ the required expose events automatically.
       
   997 "/    "/ mhmh - does not work correctly with inverted frame (exposes destroy it)
       
   998 "/
       
   999 "/    v := SimpleView in:self.
       
  1000 "/    self handlesOf:aComponent do:[:rec :wht | 
       
  1001 "/        r isNil 
       
  1002 "/            ifTrue:[r := rec]
       
  1003 "/            ifFalse:[r := r merge:rec].
       
  1004 "/    ].
       
  1005 "/
       
  1006 "/    "/ if the area is small, make one big rectangle-expose
       
  1007 "/    r area < 10000 ifTrue:[
       
  1008 "/        v origin:r origin extent:r extent.
       
  1009 "/        v map.
       
  1010 "/        v unmap.
       
  1011 "/    ] ifFalse:[
       
  1012 "/        self handlesOf:aComponent do:[:rec :wht | 
       
  1013 "/            v origin:rec origin extent:rec extent.
       
  1014 "/            v map.
       
  1015 "/            v unmap.
       
  1016 "/        ].
       
  1017 "/    ].
       
  1018 "/    v destroy.
       
  1019 "/    ^ self.
       
  1020 
       
  1021     (wasClipped := clipChildren) ifTrue:[
       
  1022 	self clippedByChildren:(clipChildren := false). 
       
  1023     ].
       
  1024 
       
  1025     self handlesOf:aComponent do:[:rec :wht| self clearRectangle:rec ].
       
  1026 
       
  1027     wasClipped ifTrue:[
       
  1028 	self clippedByChildren:(clipChildren := true). 
       
  1029     ].
       
  1030 
       
  1031     "/ must redraw all components which are affected b the handles
       
  1032     r := (aComponent originRelativeTo:self) - (3@3) extent:(aComponent extent + (6@6)).
       
  1033 
       
  1034     subViews do:[:anotherComponent |
       
  1035 	|absOrg absFrame|
       
  1036 
       
  1037 	anotherComponent ~~ inputView ifTrue:[
       
  1038 	    absOrg := anotherComponent originRelativeTo:self.
       
  1039 	    absFrame := absOrg extent:(anotherComponent extent).
       
  1040 	    (absFrame intersects:r) ifTrue:[
       
  1041 		anotherComponent withAllSubViewsDo:[:v |
       
  1042 		    v shown ifTrue:[
       
  1043 			aSet notNil ifTrue:[
       
  1044 			    aSet add:v
       
  1045 			] ifFalse:[
       
  1046 			    self handleAffectedViews:v
       
  1047 			]
       
  1048 		    ]
       
  1049 		]
       
  1050 	    ]
       
  1051 	]
       
  1052     ].
       
  1053 
       
  1054     "Modified: / 24.8.1998 / 12:19:38 / cg"
       
  1055 !
   957 !
  1056 
   958 
  1057 whichHandleOf:aComponent isHitBy:aPoint
   959 whichHandleOf:aComponent isHitBy:aPoint
  1058     "returns kind of handle or nil
   960     "returns kind of handle or nil
  1059     "
   961     "
  1256 ! !
  1158 ! !
  1257 
  1159 
  1258 !UIObjectView methodsFor:'selections'!
  1160 !UIObjectView methodsFor:'selections'!
  1259 
  1161 
  1260 hideSelection
  1162 hideSelection
  1261     "hide the selection - undraw hilights - whatever that is"
  1163     "hide the selection - undraw hilights - whatever that is
  1262 
  1164     "
  1263     |aSet|
  1165     self showUnselected:selection.
  1264 
       
  1265     self selectionDo:[:object|
       
  1266 	aSet isNil ifTrue:[
       
  1267 	    aSet := IdentitySet new
       
  1268 	].
       
  1269 	self showUnselected:object addAffectedViewsTo:aSet.
       
  1270     ].
       
  1271     self handleAffectedViews:aSet.
       
  1272 
       
  1273 
       
  1274 !
  1166 !
  1275 
  1167 
  1276 moveableSelection
  1168 moveableSelection
  1277     "checks whether the selection is not empty and all selected instances
  1169     "checks whether the selection is not empty and all selected instances
  1278      can be moved. If true the selection is returned otherwise nil
  1170      can be moved. If true the selection is returned otherwise nil
  1411 
  1303 
  1412 ! !
  1304 ! !
  1413 
  1305 
  1414 !UIObjectView methodsFor:'selections basic'!
  1306 !UIObjectView methodsFor:'selections basic'!
  1415 
  1307 
       
  1308 recursiveRepair:theDamages startIn:aView
       
  1309     "repair all views and contained views, which intersects the damage.
       
  1310      !!!! all damages repaired are removed from the list of damages !!!!
       
  1311     "
       
  1312     |color isRepaired relOrg damage
       
  1313      bwWidth    "{ Class:SmallInteger }"
       
  1314      x          "{ Class:SmallInteger }"
       
  1315      y          "{ Class:SmallInteger }"
       
  1316      w          "{ Class:SmallInteger }"
       
  1317      h          "{ Class:SmallInteger }"
       
  1318      relOrgX    "{ Class:SmallInteger }"
       
  1319      relOrgY    "{ Class:SmallInteger }"
       
  1320      width      "{ Class:SmallInteger }"
       
  1321      height     "{ Class:SmallInteger }"
       
  1322      size       "{ Class:SmallInteger }"
       
  1323     |
       
  1324     aView isInputOnly ifTrue:[^ self].
       
  1325 
       
  1326     (aView shown and:[theDamages notEmpty]) ifFalse:[ ^ theDamages ].
       
  1327 
       
  1328     aView subViews notNil ifTrue:[
       
  1329         aView subViews reverseDo:[:v| self recursiveRepair:theDamages startIn:v ].
       
  1330         theDamages isEmpty ifTrue:[ ^ self ].
       
  1331     ].
       
  1332 
       
  1333     relOrg  := aView originRelativeTo:self.
       
  1334     bwWidth := aView borderWidth.
       
  1335     size    := theDamages size.
       
  1336 
       
  1337     "/ compute relative origin starting from border left@top
       
  1338     relOrgX := relOrg x - bwWidth.
       
  1339     relOrgY := relOrg y - bwWidth.
       
  1340     width   := aView width  + bwWidth + bwWidth.
       
  1341     height  := aView height + bwWidth + bwWidth.
       
  1342 
       
  1343     size to:1 by:-1 do:[:anIndex|
       
  1344         damage := theDamages at:anIndex.
       
  1345 
       
  1346         "/ compute the rectangle into the view
       
  1347         y := damage top  - relOrgY.
       
  1348         x := damage left - relOrgX.
       
  1349         w := damage width.
       
  1350         h := damage height.
       
  1351 
       
  1352         isRepaired := true.
       
  1353 
       
  1354         x     < 0      ifTrue:[ w := w + x. x := 0. isRepaired := false ].
       
  1355         y     < 0      ifTrue:[ h := h + y. y := 0. isRepaired := false ].
       
  1356         x + w > width  ifTrue:[ w := width  - x.    isRepaired := false ].
       
  1357         y + h > height ifTrue:[ h := height - y.    isRepaired := false ].
       
  1358 
       
  1359         (w > 0 and:[h > 0]) ifTrue:[
       
  1360             bwWidth ~~ 0 ifTrue:[
       
  1361                 color isNil ifTrue:[
       
  1362                     "/ must force redraw of border
       
  1363                     color := aView borderColor.
       
  1364                     aView borderColor:(Color colorId:1).
       
  1365                     aView borderColor:color.
       
  1366                 ].
       
  1367                 w := w - bwWidth.
       
  1368                 h := h - bwWidth.
       
  1369 
       
  1370                 (x := x - bwWidth) < 0 ifTrue:[w := w + x. x := 0].
       
  1371                 (y := y - bwWidth) < 0 ifTrue:[h := h + y. y := 0].
       
  1372 
       
  1373                 (w > 0 and:[h > 0])  ifFalse:[w := 0].
       
  1374             ].
       
  1375 
       
  1376             w > 0 ifTrue:[
       
  1377 "/                    aView clearRectangleX:x y:y width:w height:h.
       
  1378                 aView exposeX:x y:y width:w height:h
       
  1379             ].
       
  1380         ] ifFalse:[
       
  1381             isRepaired := false
       
  1382         ].
       
  1383         isRepaired ifTrue:[ theDamages removeIndex:anIndex ].
       
  1384     ].
       
  1385 !
       
  1386 
  1416 selection
  1387 selection
  1417     "returns the current selection
  1388     "returns the current selection
  1418     "
  1389     "
  1419     ^ selection
  1390     ^ selection
  1420 
  1391 
  1435 	selection := sel.
  1406 	selection := sel.
  1436 	self showSelection
  1407 	self showSelection
  1437     ] ifFalse:[
  1408     ] ifFalse:[
  1438 	selection := sel
  1409 	selection := sel
  1439     ]
  1410     ]
       
  1411 !
       
  1412 
       
  1413 showUnselected:something
       
  1414     "show a component ot list of components unselected
       
  1415     "
       
  1416     |damages oldClipped|
       
  1417 
       
  1418     (selectionHiddenLevel ~~ 0 or:[something isNil]) ifTrue:[
       
  1419         ^ self
       
  1420     ].
       
  1421     damages := OrderedCollection new.
       
  1422 
       
  1423     (oldClipped := clipChildren) ifTrue:[
       
  1424         self clippedByChildren:(clipChildren := false)
       
  1425     ].
       
  1426 
       
  1427     self forEach:something do:[:v|
       
  1428         self handlesOf:v do:[:rec :wht|
       
  1429             self clearRectangle:rec.
       
  1430             damages add:rec
       
  1431         ]
       
  1432     ].
       
  1433 
       
  1434     subViews notNil ifTrue:[
       
  1435         self clippedByChildren:(clipChildren := true).
       
  1436         subViews reverseDo:[:v| self recursiveRepair:damages startIn:v ].
       
  1437     ].
       
  1438     oldClipped ~~ clipChildren ifTrue:[
       
  1439         self clippedByChildren:(clipChildren := oldClipped).
       
  1440     ].
  1440 ! !
  1441 ! !
  1441 
  1442 
  1442 !UIObjectView methodsFor:'testing'!
  1443 !UIObjectView methodsFor:'testing'!
  1443 
  1444 
  1444 hasSelection
  1445 hasSelection