Ejemplo n.º 1
0
void FocusHandler::requestFocus(const Widget *const widget)
{
    if (!widget || widget == mFocusedWidget)
        return;

    int toBeFocusedIndex = -1;
    for (unsigned int i = 0, fsz = CAST_U32(
         mWidgets.size()); i < fsz; ++i)
    {
        if (mWidgets[i] == widget)
        {
            toBeFocusedIndex = i;
            break;
        }
    }

    if (toBeFocusedIndex < 0)
        return;

    Widget *const oldFocused = mFocusedWidget;

    if (oldFocused != widget)
    {
        mFocusedWidget = mWidgets.at(toBeFocusedIndex);

        if (oldFocused)
        {
            Event focusEvent(oldFocused);
            distributeFocusLostEvent(focusEvent);
        }

        Event focusEvent(mWidgets.at(toBeFocusedIndex));
        distributeFocusGainedEvent(focusEvent);
    }
}
Ejemplo n.º 2
0
    void FocusHandler::focusPrevious()
    {
        if (mWidgets.size() == 0)
        {
            mFocusedWidget = NULL;
            return;
        }

        int i;
        int focusedWidget = -1;
        for (i = 0; i < (int)mWidgets.size(); ++i)
        {
            if (mWidgets[i] == mFocusedWidget)
            {
                focusedWidget = i;
            }
        }
        int focused = focusedWidget;

        // i is a counter that ensures that the following loop
        // won't get stuck in an infinite loop
        i = (int)mWidgets.size();
        do
        {
            --focusedWidget;

            if (i==0)
            {
                focusedWidget = -1;
                break;
            }

            --i;

            if (focusedWidget <= 0)
            {
                focusedWidget = mWidgets.size() - 1;
            }

            if (focusedWidget == focused)
            {
                return;
            }
        }
        while (!mWidgets.at(focusedWidget)->isFocusable());

        if (focusedWidget >= 0)
        {
            mFocusedWidget = mWidgets.at(focusedWidget);
            Event focusEvent(mFocusedWidget);
            distributeFocusGainedEvent(focusEvent);
        }

        if (focused >= 0)
        {
            Event focusEvent(mWidgets.at(focused));
            distributeFocusLostEvent(focusEvent);
        }
    }
Ejemplo n.º 3
0
void FocusHandler::focusPrevious()
{
    if (mWidgets.empty())
    {
        mFocusedWidget = nullptr;
        return;
    }

    int i;
    int focusedWidget = -1;
    const int sz = CAST_S32(mWidgets.size());
    for (i = 0; i < sz; ++ i)
    {
        if (mWidgets[i] == mFocusedWidget)
            focusedWidget = i;
    }
    const int focused = focusedWidget;

    // i is a counter that ensures that the following loop
    // won't get stuck in an infinite loop
    i = sz;
    do
    {
        -- focusedWidget;

        if (i == 0)
        {
            focusedWidget = -1;
            break;
        }

        -- i;

        if (focusedWidget <= 0)
            focusedWidget = sz - 1;

        if (focusedWidget == focused)
            return;
    }
    while (!mWidgets.at(focusedWidget)->isFocusable());

    if (focusedWidget >= 0)
    {
        mFocusedWidget = mWidgets.at(focusedWidget);
        Event focusEvent(mFocusedWidget);
        distributeFocusGainedEvent(focusEvent);
    }

    if (focused >= 0)
    {
        Event focusEvent(mWidgets.at(focused));
        distributeFocusLostEvent(focusEvent);
    }
}
Ejemplo n.º 4
0
void FocusHandler::focusNext()
{
    int i;
    int focusedWidget = -1;
    const int sz = static_cast<int>(mWidgets.size());
    for (i = 0; i < sz; ++i)
    {
        if (mWidgets[i] == mFocusedWidget)
            focusedWidget = i;
    }
    const int focused = focusedWidget;

    // i is a counter that ensures that the following loop
    // won't get stuck in an infinite loop
    i = sz;
    do
    {
        ++ focusedWidget;

        if (i == 0)
        {
            focusedWidget = -1;
            break;
        }

        -- i;

        if (focusedWidget >= sz)
            focusedWidget = 0;

        if (focusedWidget == focused)
            return;
    }
    while (!mWidgets.at(focusedWidget)->isFocusable());

    if (focusedWidget >= 0)
    {
        mFocusedWidget = mWidgets.at(focusedWidget);

        Event focusEvent(mFocusedWidget);
        distributeFocusGainedEvent(focusEvent);
    }

    if (focused >= 0)
    {
        Event focusEvent(mWidgets.at(focused));
        distributeFocusLostEvent(focusEvent);
    }
}
Ejemplo n.º 5
0
 void FocusHandler::requestFocus(Widget* widget)
 {
     if (widget == NULL
         || widget == mFocusedWidget)
     {
         return;
     }
     
     unsigned int i = 0;
     int toBeFocusedIndex = -1;
     for (i = 0; i < mWidgets.size(); ++i)
     {
         if (mWidgets[i] == widget)
         {
             toBeFocusedIndex = i;
             break;
         }
     }
     
     if (toBeFocusedIndex < 0)
     {
         throw FCN_EXCEPTION("Trying to focus a none existing widget.");
     }
     
     Widget *oldFocused = mFocusedWidget;
     
     if (oldFocused != widget)
     {
         mFocusedWidget = mWidgets.at(toBeFocusedIndex);
         
         if (oldFocused != NULL)
         {
             Event focusEvent(oldFocused);
             distributeFocusLostEvent(focusEvent);
         }
         
         Event focusEvent(mWidgets.at(toBeFocusedIndex));
         distributeFocusGainedEvent(focusEvent);
     }        
 }
Ejemplo n.º 6
0
void FocusHandler::tabPrevious()
{
    if (mFocusedWidget)
    {
        if (!mFocusedWidget->isTabOutEnabled())
            return;
    }

    if (mWidgets.empty())
    {
        mFocusedWidget = nullptr;
        return;
    }

    int i;
    int focusedWidget = -1;
    const int sz = CAST_S32(mWidgets.size());
    for (i = 0; i < sz; ++ i)
    {
        if (mWidgets[i] == mFocusedWidget)
            focusedWidget = i;
    }
    const int focused = focusedWidget;
    bool done = false;

    // i is a counter that ensures that the following loop
    // won't get stuck in an infinite loop
    i = sz;
    do
    {
        -- focusedWidget;

        if (i == 0)
        {
            focusedWidget = -1;
            break;
        }

        -- i;

        if (focusedWidget <= 0)
            focusedWidget = sz - 1;

        if (focusedWidget == focused)
            return;

        const Widget *const widget = mWidgets.at(focusedWidget);
        if (widget->isFocusable() && widget->isTabInEnabled() &&
            (!mModalFocusedWidget || widget->isModalFocused()))
        {
            done = true;
        }
    }
    while (!done);

    if (focusedWidget >= 0)
    {
        mFocusedWidget = mWidgets.at(focusedWidget);
        Event focusEvent(mFocusedWidget);
        distributeFocusGainedEvent(focusEvent);
    }

    if (focused >= 0)
    {
        Event focusEvent(mWidgets.at(focused));
        distributeFocusLostEvent(focusEvent);
    }

    checkForWindow();
}
Ejemplo n.º 7
0
    void FocusHandler::tabPrevious()
    {
        if (mFocusedWidget != NULL)
        {
            if (!mFocusedWidget->isTabOutEnabled())
            {
                return;
            }
        }

        if (mWidgets.size() == 0)
        {
            mFocusedWidget = NULL;
            return;
        }

        int i;
        int focusedWidget = -1;
        for (i = 0; i < (int)mWidgets.size(); ++i)
        {
            if (mWidgets[i] == mFocusedWidget)
            {
                focusedWidget = i;
            }
        }
        int focused = focusedWidget;
        bool done = false;

        // i is a counter that ensures that the following loop
        // won't get stuck in an infinite loop
        i = (int)mWidgets.size();
        do
        {
            --focusedWidget;

            if (i==0)
            {
                focusedWidget = -1;
                break;
            }

            --i;

            if (focusedWidget <= 0)
            {
                focusedWidget = mWidgets.size() - 1;
            }

            if (focusedWidget == focused)
            {
                return;
            }

            if (mWidgets.at(focusedWidget)->isFocusable() &&
                mWidgets.at(focusedWidget)->isTabInEnabled() &&
                (mModalFocusedWidget == NULL ||
                 mWidgets.at(focusedWidget)->isModalFocused()))
            {
                done = true;
            }
        }
        while (!done);

        if (focusedWidget >= 0)
        {
            mFocusedWidget = mWidgets.at(focusedWidget);
            Event focusEvent(mFocusedWidget);
            distributeFocusGainedEvent(focusEvent);
        }

        if (focused >= 0)
        {
            Event focusEvent(mWidgets.at(focused));
            distributeFocusLostEvent(focusEvent);
        }
    }