bool Window::setFirstFocusable() { WidgetList focusList; if(getFocusList(focusList)) { _setFocused(focusList.front().get()); return true; } return false; }
bool InputHandler::_focusChanged( RootPanel * pRoot, Widget * pOldFocused, Widget * pNewFocused ) { if (pRoot != m_pFocusedRoot.rawPtr() ) return false; // Root does not have focus, thus can't assign focus to its child. if( pOldFocused ) _setUnfocused( pOldFocused ); if (pNewFocused ) _setFocused(pNewFocused); return true; }
bool Window::setNextFocusable() { WidgetList focusList; if(!getFocusList(focusList)) return false; WidgetList::iterator w = focusList.begin(); // TODO: This needs to be a more complicated object, since the focus may be // in a child Window instead of a Widget. unsigned int focusedIndex = 0; for(unsigned int i = 0; w != focusList.end(); w++, i++) if(*w == _focused) { focusedIndex = i; break; } if(focusedIndex < focusList.size() - 1) _setFocused((++w)->get()); else _setFocused(focusList.front().get()); return true; }
void InputHandler::setFocusedWindow( const RootPanel_p& pRoot ) { if( pRoot == m_pFocusedRoot ) return; if( m_pFocusedRoot ) { Widget * p = m_pFocusedRoot->_focusedChild(); if( p ) _setUnfocused( p ); } m_pFocusedRoot = pRoot.rawPtr(); if( pRoot ) { Widget * p = pRoot->_focusedChild(); if( p ) _setFocused( p ); else _setFocused( pRoot->widget().rawPtr() ); // Bottom container gets focus per default. } }
// 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; }
bool Window::setFocused(const std::string& name) { Widget* w1 = getByName(name); bool found = false; if(!w1) { // Just like above, we couldn't find the widget in the toplevel, so lets see if // one of our EmbeddedWindow objects has it. The difference here is that we // search by name. WindowList wl; getEmbeddedList(wl); for(WindowList::iterator w = wl.begin(); w != wl.end(); w++) { Widget* w2 = w->get()->getByName(name); if(w2) { found = true; w1 = w2; } } } else found = true; if(!found) { warn() << "Window [" << _name << "] couldn't find a Widget named [" << name << "] to set as it's focus." << std::endl ; return false; } _setFocused(w1); return true; }