bool Window::getFocusList(WidgetList& wl) const {
    for(ConstIterator i = begin(); i != end(); i++) if(i->valid()) {
        EmbeddedWindow* ew = dynamic_cast<EmbeddedWindow*>(i->get());

        if(!ew) {
            if(i->get()->canFocus()) wl.push_back(i->get());
        }

        else {
            if(ew->getWindow()) ew->getWindow()->getFocusList(wl);
        }
    }

    return wl.size() != 0;
}
bool Window::getEmbeddedList(WindowList& wl) const {
    for(ConstIterator i = begin(); i != end(); i++) if(i->valid()) {
        EmbeddedWindow* ew = dynamic_cast<EmbeddedWindow*>(i->get());

        if(!ew || !ew->getWindow()) continue;

        else {
            wl.push_back(ew->getWindow());

            ew->getWindow()->getEmbeddedList(wl);
        }
    }

    return wl.size() != 0;
}
// The topmost Window always has this method called, instead of the embedded window directly.
bool Window::setFocused(const Widget* widget) {
    // TODO: I've turned on the warn() here, but perhaps I shouldn't? I need to define
    // the conditions under which it's okay to call setFocus() with a NULL widget.
    if(!widget) {
        warn() << "Window [" << _name << "] can't focus a NULL Widget." << std::endl;

        return false;
    }

    ConstIterator i = std::find(begin(), end(), widget);

    bool found = false;

    if(i == end()) {
        // We couldn't find the widget in the toplevel, so lets see if one of our
        // EmbeddedWindow objects has it.
        WindowList wl;

        getEmbeddedList(wl);

        for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) {
            ConstIterator ii = std::find(w->get()->begin(), w->get()->end(), widget);
            
            if(ii != w->get()->end()) {
                found = true;
                i     = ii;
            }
        }
    }

    else found = true;

    if(!found) {
        warn()
            << "Window [" << _name
            << "] couldn't find the Widget [" << widget->getName()
            << "] in it's object list." << std::endl
        ;

        return false;
    }

    _setFocused(i->get());

    return true;
}
Beispiel #4
0
bool WindowManager::setFocused(Window* window) {
    Event ev(this);

    ev._window = window;

    // Inform the previously focused Window that it is going to be unfocused.
    if(_focused.valid()) _focused->callMethodAndCallbacks(ev.makeType(EVENT_UNFOCUS));

    _focused = window;

    if(!window || !window->canFocus()) return false;

    // Build a vector of every Window that is focusable, in the foreground, and in the
    // background. All these Windows are handled differently.
    Vector focusable;
    Vector bg;
    Vector fg;

    for(ConstIterator it = begin(); it != end(); it++) if(it->valid()) {
        Window* w = it->get();

        if(w->getStrata() == Window::STRATA_FOREGROUND) fg.push_back(w);

        else if(w->getStrata() == Window::STRATA_BACKGROUND) bg.push_back(w);

        else focusable.push_back(w);
    }

    // After this call to sort, the internal objects will be arranged such that the
    // previously focused window is the first, followed by all other Windows in
    // descending order.
    std::sort(focusable.begin(), focusable.end(), WindowZCompare());

    // This is the depth range for each Window. Each Window object must be informed of
    // the Z space allocated to it so that it can properly arrange it's children. We
    // add 2 additional Windows here for anything that should appear in the background
    // and foreground areas.
    matrix_type zRange = 1.0f / (focusable.size() + 2.0f);

    // Our offset for the following for() loop.
    unsigned int i = 3;

    // Handle all of our focusable Windows.
    for(Iterator w = focusable.begin(); w != focusable.end(); w++) {
        Window* win = w->get();

        // Set our newly focused Window as the topmost element.
        if(*w == window) win->_z = -zRange * 2.0f;

        // Set the current Z of the remaining Windows and set their zRange so that
        // they can update their own children.
        else {
            win->_z = -zRange * i;

            i++;
        }
    }

    // Handled our special BACKGROUND Windows.
    for(Iterator w = bg.begin(); w != bg.end(); w++) w->get()->_z = -zRange * i;

    // Handle our special FOREGOUND Windows.
    for(Iterator w = fg.begin(); w != fg.end(); w++) w->get()->_z = -zRange;

    // Update every window, regardless.
    for(Iterator w = begin(); w != end(); w++) {
        Window* win = w->get();

        win->_zRange = zRange;

        win->update();
    }

    _focused->callMethodAndCallbacks(ev.makeType(EVENT_FOCUS));

    return true;
}
Beispiel #5
0
		const Entry* EntryBase::getEntry( const std::string& path ) const
		{
			ConstIterator it = getEntryIterator( path );
			return ( ( it == end() ) ? NULL : it->get() );
		}