| 686 | } |
| 687 | |
| 688 | void Manager::setFocus(Widget* widget) |
| 689 | { |
| 690 | if ((focus_widget != widget) |
| 691 | && (!(widget) |
| 692 | || (!(widget->hasFlags(DISABLED)) |
| 693 | && !(widget->hasFlags(HIDDEN)) |
| 694 | && !(widget->hasFlags(DECORATIVE)) |
| 695 | && someParentIsFocusStop(widget)))) { |
| 696 | WidgetsList widget_parents; |
| 697 | Widget* common_parent = NULL; |
| 698 | |
| 699 | if (widget) |
| 700 | widget->getParents(false, widget_parents); |
| 701 | |
| 702 | // Fetch the focus |
| 703 | if (focus_widget) { |
| 704 | WidgetsList focus_parents; |
| 705 | focus_widget->getParents(true, focus_parents); |
| 706 | |
| 707 | Message* msg = new Message(kFocusLeaveMessage); |
| 708 | |
| 709 | for (Widget* parent1 : focus_parents) { |
| 710 | if (widget) { |
| 711 | for (Widget* parent2 : widget_parents) { |
| 712 | if (parent1 == parent2) { |
| 713 | common_parent = parent1; |
| 714 | break; |
| 715 | } |
| 716 | } |
| 717 | if (common_parent) |
| 718 | break; |
| 719 | } |
| 720 | |
| 721 | if (parent1->hasFocus()) { |
| 722 | parent1->disableFlags(HAS_FOCUS); |
| 723 | msg->addRecipient(parent1); |
| 724 | } |
| 725 | } |
| 726 | |
| 727 | enqueueMessage(msg); |
| 728 | } |
| 729 | |
| 730 | // Put the focus |
| 731 | focus_widget = widget; |
| 732 | if (widget) { |
| 733 | WidgetsList::iterator it; |
| 734 | |
| 735 | if (common_parent) { |
| 736 | it = std::find(widget_parents.begin(), |
| 737 | widget_parents.end(), |
| 738 | common_parent); |
| 739 | ASSERT(it != widget_parents.end()); |
| 740 | ++it; |
| 741 | } |
| 742 | else |
| 743 | it = widget_parents.begin(); |
| 744 | |
| 745 | Message* msg = new Message(kFocusEnterMessage); |
no test coverage detected