* \brief Get the widget with the highest level, which is a direct ancestor of * widget1 and widget2. */
| 1627 | * widget1 and widget2. |
| 1628 | */ |
| 1629 | Widget *Widget::getNearestCommonAncestor (Widget *otherWidget) |
| 1630 | { |
| 1631 | Widget *widget1 = this, *widget2 = otherWidget; |
| 1632 | int level1 = widget1->getLevel (), level2 = widget2->getLevel(); |
| 1633 | |
| 1634 | /* Get both widgets onto the same level.*/ |
| 1635 | while (level1 > level2) { |
| 1636 | widget1 = widget1->parent; |
| 1637 | level1--; |
| 1638 | } |
| 1639 | |
| 1640 | while (level2 > level1) { |
| 1641 | widget2 = widget2->parent; |
| 1642 | level2--; |
| 1643 | } |
| 1644 | |
| 1645 | /* Search upwards. */ |
| 1646 | while (widget1 != widget2) { |
| 1647 | if (widget1->parent == NULL) { |
| 1648 | MSG_WARN("widgets in different trees\n"); |
| 1649 | return NULL; |
| 1650 | } |
| 1651 | |
| 1652 | widget1 = widget1->parent; |
| 1653 | widget2 = widget2->parent; |
| 1654 | } |
| 1655 | |
| 1656 | return widget1; |
| 1657 | } |
| 1658 | |
| 1659 | void Widget::scrollTo (HPosition hpos, VPosition vpos, |
| 1660 | int x, int y, int width, int height) |