UIPainterView.st
changeset 1832 ba152306fbf5
parent 1830 78a5cf39dc0e
child 1833 6ad211a201cf
equal deleted inserted replaced
1831:f5ba45d3d70a 1832:ba152306fbf5
   298 
   298 
   299 deleteTotalSelection
   299 deleteTotalSelection
   300     "delete the selection
   300     "delete the selection
   301     "            
   301     "            
   302     self deleteSelectionBuffered: false
   302     self deleteSelectionBuffered: false
       
   303 !
       
   304 
       
   305 getSelectedViewsAndSpecs
       
   306     "return an array filed with selected views and corresponding specs.
       
   307      Nil if there is none.
       
   308     "
       
   309     |specs coll sel|
       
   310 
       
   311     sel := treeView selection.
       
   312 
       
   313     coll := self minSetOfSuperViews:(self selection).
       
   314 
       
   315     coll isNil ifTrue:[^ nil].
       
   316 
       
   317     specs := coll collect:[:aView| self fullSpecFor:aView ].
       
   318     ^ Array with: coll with: specs
   303 !
   319 !
   304 
   320 
   305 pasteBuffer
   321 pasteBuffer
   306     "add the objects in the paste-buffer to the object view
   322     "add the objects in the paste-buffer to the object view
   307     "
   323     "
  1446 
  1462 
  1447     self invalidate
  1463     self invalidate
  1448 
  1464 
  1449 ! !
  1465 ! !
  1450 
  1466 
       
  1467 !UIPainterView methodsFor:'group & ungroup'!
       
  1468 
       
  1469 group
       
  1470 
       
  1471     self groupSelectionWithLayout: false
       
  1472 !
       
  1473 
       
  1474 groupSelectionWithLayout: withLayout
       
  1475     | spec rect views box layout specs canvas view oldSelection cS nViews menu item xOffset yOffset |
       
  1476 
       
  1477     menu := Menu new.
       
  1478     menu receiver: self.
       
  1479     item := MenuItem label:'Box' value:[spec := ViewSpec new].
       
  1480     menu addItem: item.
       
  1481     item := MenuItem label:'TBox' value:[spec := TBoxSpec new].
       
  1482     menu addItem: item.
       
  1483     item := MenuItem label:'FramedBox' value:[spec := FramedBoxSpec new].
       
  1484     menu addItem: item.
       
  1485     item := MenuItem label:'HorizontalPanel' value:[spec := HorizontalPanelViewSpec new].
       
  1486     menu addItem: item.
       
  1487     item := MenuItem label:'VerticalPanel' value:[spec := VerticalPanelViewSpec new].
       
  1488     menu addItem: item.
       
  1489     (MenuPanel menu: menu) startUp.
       
  1490     canvas := self painter.
       
  1491     cS := canvas getSelectedViewsAndSpecs.
       
  1492     cS isNil ifTrue:[^self].
       
  1493     views := cS first.
       
  1494     specs := cS last. 
       
  1495     rect := views first frame.
       
  1496     2 to: views size do:[:i| rect := rect merge: (views at: i) frame].
       
  1497     layout := LayoutFrame leftFraction:0.0 offset: rect origin x 
       
  1498                          rightFraction:0.0 offset: rect corner x + 1 
       
  1499                            topFraction:0.0 offset: rect origin y 
       
  1500                         bottomFraction:0.0 offset:rect corner y + 1.
       
  1501     oldSelection := canvas selection.
       
  1502     canvas select: views first superView.
       
  1503     spec layout: layout.
       
  1504     spec class == VerticalPanelViewSpec ifTrue:[
       
  1505         spec verticalLayout: #topSpace.
       
  1506         spec horizontalLayout: #fit.
       
  1507     ].
       
  1508     spec class == HorizontalPanelViewSpec ifTrue:[
       
  1509         spec verticalLayout: #fit.
       
  1510         spec horizontalLayout: #leftSpace.
       
  1511     ].
       
  1512 
       
  1513     box := self pasteSpecifications:spec keepLayout:true at:nil.
       
  1514 
       
  1515     xOffset := box origin x.
       
  1516     yOffset := box origin y.
       
  1517     withLayout ifFalse:[
       
  1518         1 to: specs size do:[:i|
       
  1519             view := views at: i.
       
  1520             layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x - xOffset)
       
  1521                                   rightFraction:0.0 offset: (view corner x - xOffset + 1)
       
  1522                                     topFraction:0.0 offset: (view origin y - yOffset )
       
  1523                                  bottomFraction:0.0 offset: (view corner y - yOffset + 1).
       
  1524             (specs at: i) layout: layout.
       
  1525         ].
       
  1526     ]. 
       
  1527     canvas selection: oldSelection.
       
  1528     canvas deleteSelection.
       
  1529     canvas selection:box.
       
  1530     nViews := canvas pasteSpecifications:specs keepLayout:true.
       
  1531     canvas selection: box.
       
  1532 !
       
  1533 
       
  1534 groupWithLayout
       
  1535 
       
  1536     self groupSelectionWithLayout: true
       
  1537 !
       
  1538 
       
  1539 ungroup
       
  1540 
       
  1541     self ungroupSelectionWithLayout: false
       
  1542 !
       
  1543 
       
  1544 ungroupSelectionWithLayout: withLayout
       
  1545 
       
  1546     | canvas cS views specs frame view layout superView|
       
  1547 
       
  1548     canvas := self painter.
       
  1549     cS := canvas getSelectedViewsAndSpecs.
       
  1550     cS isNil ifTrue:[^self].
       
  1551     views := cS first first subViews copy.
       
  1552     superView := cS first first superView.
       
  1553     cS last first component isNil ifTrue:[^self].
       
  1554     cS last first component collection isEmpty ifTrue:[^self].
       
  1555     specs := cS last first component collection copy. 
       
  1556     frame := cS first first frame.
       
  1557     canvas deleteSelection.
       
  1558     withLayout ifFalse:[
       
  1559         1 to: specs size do:[:i|
       
  1560             view := views at: i.
       
  1561             layout :=  LayoutFrame leftFraction:0.0 offset: (view origin x + frame origin x)
       
  1562                                   rightFraction:0.0 offset: (view corner x + frame origin x + 1)
       
  1563                                     topFraction:0.0 offset: (view origin y + frame origin y )
       
  1564                                  bottomFraction:0.0 offset: (view corner y + frame origin y + 1).
       
  1565             (specs at: i) layout: layout.
       
  1566         ].
       
  1567     ]. 
       
  1568     canvas selection: superView.
       
  1569     canvas pasteSpecifications:specs keepLayout:true.
       
  1570     canvas selection: superView.
       
  1571 !
       
  1572 
       
  1573 ungroupWithLayout
       
  1574 
       
  1575     self ungroupSelectionWithLayout: true
       
  1576 ! !
       
  1577 
  1451 !UIPainterView methodsFor:'initialization'!
  1578 !UIPainterView methodsFor:'initialization'!
  1452 
  1579 
  1453 create
  1580 create
  1454     "colors on device
  1581     "colors on device
  1455     "
  1582     "
  1536     ].
  1663     ].
  1537   ^ nil
  1664   ^ nil
  1538 ! !
  1665 ! !
  1539 
  1666 
  1540 !UIPainterView methodsFor:'private-handles'!
  1667 !UIPainterView methodsFor:'private-handles'!
       
  1668 
       
  1669 painter
       
  1670     ^ treeView canvas
       
  1671 !
  1541 
  1672 
  1542 showSelected:aComponent
  1673 showSelected:aComponent
  1543     "show object selected
  1674     "show object selected
  1544     "
  1675     "
  1545     |wasClipped sel hColor bg|
  1676     |wasClipped sel hColor bg|
  1951     aSpec needsRebuildForAttributes ifTrue:[
  2082     aSpec needsRebuildForAttributes ifTrue:[
  1952         "/ needs a full rebuild (in case view class depends upon spec-attribute)
  2083         "/ needs a full rebuild (in case view class depends upon spec-attribute)
  1953         v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView).
  2084         v := aSpec buildViewWithLayoutFor:builder in:(self findContainerOfView:aView).
  1954         v realize.    
  2085         v realize.    
  1955         aView destroy.
  2086         aView destroy.
  1956         device flush  "sync" .
  2087         device sync.
       
  2088         device flush.
  1957         aView becomeSameAs:v.
  2089         aView becomeSameAs:v.
       
  2090         inputView raise.
  1958     ] ifFalse:[
  2091     ] ifFalse:[
  1959         aSpec setAttributesIn:aView with:builder.
  2092         aSpec setAttributesIn:aView with:builder.
  1960         self elementChangedSize:aView.
  2093         self elementChangedSize:aView.
  1961     ].
  2094     ].
       
  2095 
  1962 !
  2096 !
  1963 
  2097 
  1964 specFor:anObject
  2098 specFor:anObject
  1965     "returns spec assigned to an object
  2099     "returns spec assigned to an object
  1966     "
  2100     "