19 classVariableNames:'' |
19 classVariableNames:'' |
20 poolDictionaries:'' |
20 poolDictionaries:'' |
21 privateIn:UIObjectView::UndoHistory |
21 privateIn:UIObjectView::UndoHistory |
22 ! |
22 ! |
23 |
23 |
|
24 |
|
25 !UIObjectView class methodsFor:'conversion'! |
|
26 |
|
27 asLayoutFrameFromView:aView |
|
28 "convert layout from aView to a frameLayout. On success the frameLayout is |
|
29 returned otherwise nil |
|
30 " |
|
31 |lF lO rF rO tF tO bF bO layout| |
|
32 |
|
33 (layout := aView geometryLayout) isNil ifTrue:[ |
|
34 ^ nil |
|
35 ]. |
|
36 |
|
37 layout isLayout ifTrue:[ |
|
38 layout isLayoutFrame ifTrue:[^ layout copy]. |
|
39 |
|
40 lF := layout leftFraction. |
|
41 lO := layout leftOffset. |
|
42 tF := layout topFraction. |
|
43 tO := layout topOffset. |
|
44 bF := tF. |
|
45 bO := tO + aView extent y. |
|
46 rF := lF. |
|
47 rO := lO + aView extent x. |
|
48 ] ifFalse:[ |
|
49 lF := rF := tF := bF := 0. |
|
50 |
|
51 layout isRectangle ifTrue:[ |
|
52 lO := layout left. |
|
53 tO := layout top. |
|
54 rO := layout right. |
|
55 bO := layout bottom. |
|
56 ] ifFalse:[ |
|
57 layout isPoint ifFalse:[ ^ nil ]. |
|
58 |
|
59 lO := layout x. |
|
60 tO := layout y. |
|
61 rO := lO + aView extent x. |
|
62 bO := tO + aView extent y. |
|
63 ]. |
|
64 ]. |
|
65 |
|
66 ^ LayoutFrame leftFraction:lF offset:lO rightFraction:rF offset:rO |
|
67 topFraction:tF offset:tO bottomFraction:bF offset:bO |
|
68 ! ! |
24 |
69 |
25 !UIObjectView class methodsFor:'defaults'! |
70 !UIObjectView class methodsFor:'defaults'! |
26 |
71 |
27 defaultGrid |
72 defaultGrid |
28 ^ 4 @ 4 |
73 ^ 4 @ 4 |
1554 |
1599 |
1555 ! ! |
1600 ! ! |
1556 |
1601 |
1557 !UIObjectView methodsFor:'user actions - position'! |
1602 !UIObjectView methodsFor:'user actions - position'! |
1558 |
1603 |
|
1604 alignFrameLayout:aBlock |
|
1605 "perform block on a frameLayout assigned to the current single selection |
|
1606 " |
|
1607 self transaction:#align selectionDo:[:aView| |
|
1608 layout := self class asLayoutFrameFromView:aView. |
|
1609 |
|
1610 layout notNil ifTrue:[ |
|
1611 self undoLayoutView:aView. |
|
1612 aBlock value:layout. |
|
1613 aView geometryLayout:layout. |
|
1614 self elementChangedSize:aView. |
|
1615 ] |
|
1616 ] |
|
1617 ! |
|
1618 |
1559 alignSelectionBottom |
1619 alignSelectionBottom |
1560 "align selection to the bottom of the first object in the selection; in case |
1620 "align selection to the bottom of the first object in the selection; in case |
1561 of one selection the object is aligned to the bottom of its superview |
1621 of one selection the object is aligned to the bottom of its superview |
1562 " |
1622 " |
1563 |bmost delta layout| |
1623 |bmost delta| |
1564 |
1624 |
1565 (self canMove:selection) ifTrue:[ |
1625 (self canMove:selection) ifTrue:[ |
1566 self withSelectionHiddenDo:[ |
1626 self withSelectionHiddenDo:[ |
1567 self numberOfSelections > 1 ifTrue:[ |
1627 self numberOfSelections > 1 ifTrue:[ |
1568 bmost := (selection at:1) computeCorner y. |
1628 bmost := (selection at:1) computeCorner y. |
1571 (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1631 (delta := bmost - (v computeCorner y)) ~~ 0 ifTrue:[ |
1572 self shiftLayout:v top:delta bottom:delta. |
1632 self shiftLayout:v top:delta bottom:delta. |
1573 ] |
1633 ] |
1574 ] |
1634 ] |
1575 ] ifFalse:[ |
1635 ] ifFalse:[ |
1576 layout := selection geometryLayout. |
1636 self alignFrameLayout:[:aLayout| |
1577 |
1637 aLayout bottomOffset:0. |
1578 (layout isLayout and:[layout isLayoutFrame]) ifTrue:[ |
1638 aLayout bottomFraction:1.0 |
1579 self transaction:#layout selectionDo:[:aView| |
|
1580 self undoLayoutView:aView. |
|
1581 layout := aView geometryLayout. |
|
1582 layout bottomOffset:0. |
|
1583 layout bottomFraction:1.0. |
|
1584 aView geometryLayout:layout. |
|
1585 ] |
|
1586 ] |
1639 ] |
1587 ] |
1640 ] |
1588 ]. |
1641 ]. |
1589 self changed:#layout |
1642 self changed:#layout |
1590 ] |
1643 ] |
1664 |
1717 |
1665 alignSelectionLeft |
1718 alignSelectionLeft |
1666 "align selection to the left of the first object in the selection; in case |
1719 "align selection to the left of the first object in the selection; in case |
1667 of one selection the object is aligned to the left of its superview |
1720 of one selection the object is aligned to the left of its superview |
1668 " |
1721 " |
1669 |lmost delta layout| |
1722 |lmost delta| |
1670 |
1723 |
1671 (self canMove:selection) ifTrue:[ |
1724 (self canMove:selection) ifTrue:[ |
1672 self withSelectionHiddenDo:[ |
1725 self withSelectionHiddenDo:[ |
1673 self numberOfSelections > 1 ifTrue:[ |
1726 self numberOfSelections > 1 ifTrue:[ |
1674 lmost := (selection at:1) computeOrigin x. |
1727 lmost := (selection at:1) computeOrigin x. |
1677 (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1730 (delta := lmost - (v computeOrigin x)) ~~ 0 ifTrue:[ |
1678 self shiftLayout:v left:delta right:delta |
1731 self shiftLayout:v left:delta right:delta |
1679 ] |
1732 ] |
1680 ] |
1733 ] |
1681 ] ifFalse:[ |
1734 ] ifFalse:[ |
1682 self transaction:#layout selectionDo:[:aView| |
1735 self alignFrameLayout:[:aLayout| |
1683 layout := aView geometryLayout. |
1736 aLayout leftOffset:0. |
1684 |
1737 aLayout leftFraction:0.0. |
1685 layout isLayout ifTrue:[ |
|
1686 self undoLayoutView:aView. |
|
1687 layout leftOffset:0. |
|
1688 layout leftFraction:0.0. |
|
1689 aView geometryLayout:layout. |
|
1690 ] |
|
1691 ] |
1738 ] |
1692 ] |
1739 ] |
1693 ]. |
1740 ]. |
1694 self changed:#layout |
1741 self changed:#layout |
1695 ] |
1742 ] |
1697 |
1744 |
1698 alignSelectionLeftAndRight |
1745 alignSelectionLeftAndRight |
1699 "align selection to the left/right of the first object in the selection; in case |
1746 "align selection to the left/right of the first object in the selection; in case |
1700 of one selection the object is aligned to the left/right of its superview |
1747 of one selection the object is aligned to the left/right of its superview |
1701 " |
1748 " |
1702 |lmost rmost layout| |
1749 |lmost rmost| |
1703 |
1750 |
1704 (self canMove:selection) ifTrue:[ |
1751 (self canMove:selection) ifTrue:[ |
1705 self withSelectionHiddenDo:[ |
1752 self withSelectionHiddenDo:[ |
1706 self numberOfSelections > 1 ifTrue:[ |
1753 self numberOfSelections > 1 ifTrue:[ |
1707 lmost := (selection at:1) computeOrigin x. |
1754 lmost := (selection at:1) computeOrigin x. |
1712 right:(rmost - (v computeCorner x)). |
1759 right:(rmost - (v computeCorner x)). |
1713 |
1760 |
1714 self elementChangedSize:v. |
1761 self elementChangedSize:v. |
1715 ] |
1762 ] |
1716 ] ifFalse:[ |
1763 ] ifFalse:[ |
1717 self transaction:#layout selectionDo:[:aView| |
1764 self alignFrameLayout:[:aLayout| |
1718 layout := aView geometryLayout. |
1765 aLayout leftOffset:0. |
1719 |
1766 aLayout leftFraction:0.0. |
1720 layout isLayout ifTrue:[ |
1767 aLayout rightOffset:0. |
1721 self undoLayoutView:aView. |
1768 aLayout rightFraction:1.0. |
1722 layout leftOffset:0. |
|
1723 layout leftFraction:0.0. |
|
1724 |
|
1725 (layout isLayout and:[layout isLayoutFrame]) ifTrue:[ |
|
1726 layout rightOffset:0. |
|
1727 layout rightFraction:1.0. |
|
1728 ]. |
|
1729 aView geometryLayout:layout. |
|
1730 self elementChangedSize:aView. |
|
1731 ] |
|
1732 ] |
1769 ] |
1733 ] |
1770 ] |
1734 ]. |
1771 ]. |
1735 self changed:#layout |
1772 self changed:#layout |
1736 ]. |
1773 ]. |
1739 |
1776 |
1740 alignSelectionRight |
1777 alignSelectionRight |
1741 "align selection to the right of the first object in the selection; in case |
1778 "align selection to the right of the first object in the selection; in case |
1742 of one selection the object is aligned to the right of its superview |
1779 of one selection the object is aligned to the right of its superview |
1743 " |
1780 " |
1744 |rmost delta layout| |
1781 |rmost delta| |
1745 |
1782 |
1746 (self canMove:selection) ifTrue:[ |
1783 (self canMove:selection) ifTrue:[ |
1747 self withSelectionHiddenDo:[ |
1784 self withSelectionHiddenDo:[ |
1748 self numberOfSelections > 1 ifTrue:[ |
1785 self numberOfSelections > 1 ifTrue:[ |
1749 rmost := (selection at:1) computeCorner x. |
1786 rmost := (selection at:1) computeCorner x. |
1752 (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1789 (delta := rmost - (v computeCorner x)) ~~ 0 ifTrue:[ |
1753 self shiftLayout:v left:delta right:delta |
1790 self shiftLayout:v left:delta right:delta |
1754 ] |
1791 ] |
1755 ] |
1792 ] |
1756 ] ifFalse:[ |
1793 ] ifFalse:[ |
1757 layout := selection geometryLayout. |
1794 self alignFrameLayout:[:aLayout| |
1758 |
1795 aLayout rightOffset:0. |
1759 (layout isLayout and:[layout isLayoutFrame]) ifTrue:[ |
1796 aLayout rightFraction:1.0. |
1760 self transaction:#layout selectionDo:[:aView| |
|
1761 self undoLayoutView:aView. |
|
1762 layout := aView geometryLayout. |
|
1763 layout rightOffset:0. |
|
1764 layout rightFraction:1.0. |
|
1765 aView geometryLayout:layout. |
|
1766 ] |
|
1767 ] |
1797 ] |
1768 ] |
1798 ] |
1769 ]. |
1799 ]. |
1770 self changed:#layout |
1800 self changed:#layout |
1771 ] |
1801 ] |
1773 |
1803 |
1774 alignSelectionTop |
1804 alignSelectionTop |
1775 "align selection to the top of the first object in the selection; in case |
1805 "align selection to the top of the first object in the selection; in case |
1776 of one selection the object is aligned to the top of its superview |
1806 of one selection the object is aligned to the top of its superview |
1777 " |
1807 " |
1778 |tmost delta layout| |
1808 |tmost delta| |
1779 |
1809 |
1780 (self canMove:selection) ifTrue:[ |
1810 (self canMove:selection) ifTrue:[ |
1781 self withSelectionHiddenDo:[ |
1811 self withSelectionHiddenDo:[ |
1782 self numberOfSelections > 1 ifTrue:[ |
1812 self numberOfSelections > 1 ifTrue:[ |
1783 tmost := (selection at:1) computeOrigin y. |
1813 tmost := (selection at:1) computeOrigin y. |
1786 (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
1816 (delta := tmost - (v computeOrigin y)) ~~ 0 ifTrue:[ |
1787 self shiftLayout:v top:delta bottom:delta |
1817 self shiftLayout:v top:delta bottom:delta |
1788 ] |
1818 ] |
1789 ] |
1819 ] |
1790 ] ifFalse:[ |
1820 ] ifFalse:[ |
1791 self transaction:#layout selectionDo:[:aView| |
1821 self alignFrameLayout:[:aLayout| |
1792 layout := aView geometryLayout. |
1822 aLayout topOffset:0. |
1793 |
1823 aLayout topFraction:0.0. |
1794 layout isLayout ifTrue:[ |
|
1795 self undoLayoutView:aView. |
|
1796 layout topOffset:0. |
|
1797 layout topFraction:0.0. |
|
1798 aView geometryLayout:layout. |
|
1799 ] |
|
1800 ] |
1824 ] |
1801 ] |
1825 ] |
1802 ]. |
1826 ]. |
1803 self changed:#layout |
1827 self changed:#layout |
1804 ] |
1828 ] |
1807 |
1831 |
1808 alignSelectionTopAndBottom |
1832 alignSelectionTopAndBottom |
1809 "align selection to the top/bottom of the first object in the selection; in case |
1833 "align selection to the top/bottom of the first object in the selection; in case |
1810 of one selection the object is aligned to the top/bottom of its superview |
1834 of one selection the object is aligned to the top/bottom of its superview |
1811 " |
1835 " |
1812 |tmost bmost layout| |
1836 |tmost bmost| |
1813 |
1837 |
1814 (self canMove:selection) ifTrue:[ |
1838 (self canMove:selection) ifTrue:[ |
1815 self withSelectionHiddenDo:[ |
1839 self withSelectionHiddenDo:[ |
1816 self numberOfSelections > 1 ifTrue:[ |
1840 self numberOfSelections > 1 ifTrue:[ |
1817 tmost := (selection at:1) computeOrigin y. |
1841 tmost := (selection at:1) computeOrigin y. |
1821 self shiftLayout:v top:(tmost - (v computeOrigin y)) |
1845 self shiftLayout:v top:(tmost - (v computeOrigin y)) |
1822 bottom:(bmost - (v computeCorner y)). |
1846 bottom:(bmost - (v computeCorner y)). |
1823 self elementChangedSize:v. |
1847 self elementChangedSize:v. |
1824 ] |
1848 ] |
1825 ] ifFalse:[ |
1849 ] ifFalse:[ |
1826 self transaction:#align selectionDo:[:aView| |
1850 self alignFrameLayout:[:aLayout| |
1827 layout := aView geometryLayout. |
1851 aLayout topOffset:0. |
1828 |
1852 aLayout topFraction:0.0. |
1829 layout isLayout ifTrue:[ |
1853 aLayout bottomOffset:0. |
1830 self undoLayoutView:aView. |
1854 aLayout bottomFraction:1.0. |
1831 layout topOffset:0. |
|
1832 layout topFraction:0.0. |
|
1833 |
|
1834 (layout isLayout and:[layout isLayoutFrame]) ifTrue:[ |
|
1835 layout bottomOffset:0. |
|
1836 layout bottomFraction:1.0. |
|
1837 ]. |
|
1838 aView geometryLayout:layout. |
|
1839 ] ifFalse:[ |
|
1840 |y x| |
|
1841 |
|
1842 self undoLayoutView:aView. |
|
1843 x := aView extent x. |
|
1844 y := aView superView extent y. |
|
1845 aView extent:(x @ y) |
|
1846 ]. |
|
1847 self elementChangedSize:aView. |
|
1848 ] |
1855 ] |
1849 ] |
1856 ] |
1850 ]. |
1857 ]. |
1851 self changed:#layout |
1858 self changed:#layout |
1852 ] |
1859 ] |
1853 ! |
|
1854 |
|
1855 alignSingleSelection:aBlock |
|
1856 |
|
1857 |type layout| |
|
1858 |
|
1859 self withSelectionHiddenDo:[ |
|
1860 self transaction:#align selectionDo:[:aView| |
|
1861 type := self class layoutType:aView. |
|
1862 |
|
1863 type notNil ifTrue:[ |
|
1864 self undoLayoutView:aView. |
|
1865 |
|
1866 layout := aView layout. |
|
1867 |
|
1868 type == #LayoutFrame ifFalse:[ |
|
1869 layout := aView bounds asLayout |
|
1870 ]. |
|
1871 aBlock value:layout. |
|
1872 aView geometryLayout:layout. |
|
1873 ] |
|
1874 ] |
|
1875 ]. |
|
1876 self changed:#layout |
|
1877 |
|
1878 |
|
1879 |
|
1880 ! |
1860 ! |
1881 |
1861 |
1882 centerSelection:aOneArgBlockXorY orientation:orientation |
1862 centerSelection:aOneArgBlockXorY orientation:orientation |
1883 "center selection horizontal or vertical dependant on the block result( x or y). |
1863 "center selection horizontal or vertical dependant on the block result( x or y). |
1884 The argument to the block is the point. |
1864 The argument to the block is the point. |