Example #1
0
bool UIWidget::propagateOnMousePress(const Point& mousePos, Fw::MouseButton button)
{
    // do a backup of children list, because it may change while looping it
    UIWidgetPtr clickedChild;
    for(const UIWidgetPtr& child : m_children) {
        // events on hidden or disabled widgets are discarded
        if(!child->isExplicitlyEnabled() || !child->isExplicitlyVisible())
            continue;

        // mouse press events only go to children that contains the mouse position
        if(child->containsPoint(mousePos) && child == getChildByPos(mousePos)) {
            clickedChild = child;
            break;
        }
    }

    if(clickedChild) {
        // focusable child gains focus when clicked
        if(clickedChild->isFocusable())
            focusChild(clickedChild, Fw::MouseFocusReason);

        // stop propagating if the child accept the event
        if(clickedChild->propagateOnMousePress(mousePos, button))
            return true;
    }

    // only non phatom widgets receives mouse press events
    if(!isPhantom()) {
        bool ret = onMousePress(mousePos, button);
        if(button == Fw::MouseLeftButton && !isPressed())
            setPressed(true);
        return ret;
    }

    return false;
}