bool nuiContainer::DrawChildren(nuiDrawContext* pContext) { CheckValid(); IteratorPtr pIt; if (mReverseRender) { for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) DrawChild(pContext, pItem); } delete pIt; } else { for (pIt = GetFirstChild(); pIt && pIt->IsValid(); GetNextChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) DrawChild(pContext, pItem); } delete pIt; } return true; }
bool nuiContainer::DispatchMouseUnclick(const nglMouseInfo& rInfo) { CheckValid(); nuiAutoRef; if (!mMouseEventEnabled || mTrashed) return false; bool hasgrab = HasGrab(rInfo.TouchId); if (IsDisabled() && !hasgrab) return false; nglMouseInfo info(rInfo); GlobalToLocal(info.X, info.Y); // Get a chance to preempt the mouse event before the children get it: if (PreMouseUnclicked(info)) { Ungrab(); return true; } if (IsInsideFromRoot(rInfo.X, rInfo.Y) || hasgrab) { if (!hasgrab) { IteratorPtr pIt; for (pIt = GetLastChild(false); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) { if (IsEnabled()) { if ((pItem)->DispatchMouseUnclick(rInfo)) { delete pIt; return true; } } } } delete pIt; } bool res = PreUnclicked(info); if (!res) { res = MouseUnclicked(info); res |= Unclicked(info); } res = res | (!mClickThru); if (res) Ungrab(); return res; } return false; }
nuiWidgetPtr nuiContainer::GetPreviousFocussableChild(nuiWidgetPtr pChild) const { CheckValid(); ConstIteratorPtr pIt = pChild ? GetChildIterator(pChild) : GetLastChild(); if (!pIt->IsValid()) return NULL; if (pChild) GetPreviousChild(pIt); while (pIt->IsValid() && !pIt->GetWidget()->GetWantKeyboardFocus() && pIt->GetWidget()) GetPreviousChild(pIt); if (pIt->IsValid()) { nuiWidgetPtr pW = pIt->GetWidget(); delete pIt; return pW; } delete pIt; return NULL; }
bool nuiWindowManager::DispatchMouseClick(const nglMouseInfo& rInfo) { if (!IsEnabled()) return false; if (IsInsideFromRoot(rInfo.X, rInfo.Y)) { if (!mWindows.empty()) { std::list<nuiWindow*>::iterator it; std::list<nuiWindow*>::iterator begin = mWindows.begin(); it = mWindows.end(); do { it--; nuiWindow* win = *it; if (win->IsInsideFromRoot(rInfo.X, rInfo.Y)) { if (GetActiveWindow() != win) ActivateWindow(win); break; } } while (it!=begin); } IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsVisible() && pItem->IsEnabled()) { if (pItem->DispatchMouseClick(rInfo)) { delete pIt; return true; } } } delete pIt; nglMouseInfo info(rInfo); GlobalToLocal(info.X, info.Y); bool ret = MouseClicked(info); ret |= Clicked(info); return ret; } return false; }
nuiWindow* nuiWindowManager::GetWindow(nuiSize X, nuiSize Y, bool ClientAreaOnly) { IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsInsideFromParent(X,Y)) { delete pIt; return (nuiWindow*)pItem; } } delete pIt; return NULL; }
bool nuiWindowManager::DispatchMouseUnclick(const nglMouseInfo& rInfo) { //OUT("OnMouseUnclick\n"); IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsVisible() && pItem->IsEnabled()) { if (pItem->DispatchMouseUnclick(rInfo)) return true; } } delete pIt; return nuiSimpleContainer::DispatchMouseUnclick(rInfo); }
nuiWidgetPtr nuiContainer::GetPreviousSibling(nuiWidgetPtr pChild) const { CheckValid(); ConstIteratorPtr pIt = pChild ? GetChildIterator(pChild) : GetFirstChild(); if (!pIt->IsValid()) return NULL; if (pChild) GetPreviousChild(pIt); nuiWidgetPtr pW = NULL; if (pIt->IsValid()) pW = pIt->GetWidget(); delete pIt; return pW; }
nuiWidgetPtr nuiContainer::GetChildIf(nuiSize X, nuiSize Y, TestWidgetFunctor* pFunctor) { CheckValid(); X -= mRect.mLeft; Y -= mRect.mTop; IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsInsideFromParent(X,Y)) { nuiContainerPtr pContainer = dynamic_cast<nuiContainerPtr>(pItem); if (pContainer) { nuiWidget* pWidget = pContainer->GetChildIf(X,Y, pFunctor); if (pWidget) { delete pIt; return pWidget; } } else { if ((*pFunctor)(pItem)) { delete pIt; return pItem; } } } } delete pIt; if ((*pFunctor)(this)) return this; return NULL; }
bool nuiContainer::DispatchMouseCanceled(nuiWidgetPtr pThief, const nglMouseInfo& rInfo) { CheckValid(); nuiAutoRef; if (mTrashed) return false; bool hasgrab = HasGrab(rInfo.TouchId); nglMouseInfo info(rInfo); GlobalToLocal(info.X, info.Y); // Get a chance to preempt the mouse event before the children get it: PreClickCanceled(info); IteratorPtr pIt; for (pIt = GetLastChild(false); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) { pItem->DispatchMouseCanceled(pThief, rInfo); } } delete pIt; if (pThief != this) { GlobalToLocal(info.X, info.Y); PreClickCanceled(info); bool ret = MouseCanceled(info); ret |= ClickCanceled(info); ret = ret | (!mClickThru); return ret; } return false; }
void nuiContainer::GetChildren(nuiSize X, nuiSize Y, nuiWidgetList& rChildren, bool DeepSearch) { CheckValid(); X -= mRect.mLeft; Y -= mRect.mTop; IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsInsideFromParent(X,Y)) { if (DeepSearch) { nuiContainerPtr pContainer = dynamic_cast<nuiContainerPtr>(pItem); if (pContainer) pContainer->GetChildren(X, Y, rChildren, DeepSearch); } rChildren.push_back(pItem); } } delete pIt; }
nuiWidgetPtr nuiContainer::GetChild(nuiSize X, nuiSize Y) { CheckValid(); X -= mRect.mLeft; Y -= mRect.mTop; IteratorPtr pIt; for (pIt = GetLastChild(); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem && pItem->IsInsideFromSelf(X,Y)) { delete pIt; nuiContainerPtr pContainer = dynamic_cast<nuiContainerPtr>(pItem); if (pContainer) return pContainer->GetChild(X,Y); else return pItem; } } delete pIt; return this; }
nuiWidgetPtr nuiContainer::DispatchMouseMove(const nglMouseInfo& rInfo) { CheckValid(); nuiAutoRef; if (!mMouseEventEnabled || mTrashed) return false; nuiWidgetPtr pHandled=NULL; bool inside=false,res=false; bool hasgrab = HasGrab(rInfo.TouchId); if (IsDisabled() && !hasgrab) return NULL; nglMouseInfo info(rInfo); GlobalToLocal(info.X, info.Y); // Get a chance to preempt the mouse event before the children get it: if (PreMouseMoved(info)) return this; if (IsInsideFromRoot(rInfo.X, rInfo.Y) || hasgrab) { inside = true; // If the object has the grab we should not try to notify its children of mouse events! if (!hasgrab) { IteratorPtr pIt; for (pIt = GetLastChild(false); pIt && pIt->IsValid(); GetPreviousChild(pIt)) { nuiWidgetPtr pItem = pIt->GetWidget(); if (pItem) { if (pItem->IsVisible()) { pHandled = pItem->DispatchMouseMove(rInfo); } } if (pHandled) { // stop as soon as someone caught the event delete pIt; return pHandled; } } delete pIt; } res = MouseMoved(info); res |= MovedMouse(info); } else { if (GetHover()) { res = MouseMoved(info); res |= MovedMouse(info); } } if (!pHandled && (res | (!mClickThru)) && inside) { nuiTopLevelPtr pRoot = GetTopLevel(); if (pRoot) return this; } if (pHandled) return pHandled; return (res && inside) ? this : NULL; }