void nuiPopupMenu::CalcTreeSize(nuiRect& rRect, nuiTreeNode* pTree, uint32& cpt) { NGL_ASSERT(pTree); // no chance to happen cpt++; nuiRect rect(0,0,0,0); nuiWidgetPtr pWidget; nuiRect WidgetRect; uint32 depth = cpt; uint32 count = pTree->GetChildrenCount(); if (count <= 0) return; bool HasNonEmpty = false; for (uint32 i = 0; i < count; i++) { nuiTreeNode* pNode = dynamic_cast<nuiTreeNode*>(pTree->GetChild(i)); NGL_ASSERT(pNode); pWidget = pNode->GetElement(); NGL_ASSERT(pWidget); WidgetRect = pWidget->GetIdealRect(); rect.SetSize(MAX(rect.GetWidth(), WidgetRect.GetWidth()), rect.GetHeight() + WidgetRect.GetHeight()); if (!pNode->IsEmpty()) { HasNonEmpty = true; } if (pNode->IsOpened()) { if (mRects.size() <= depth + 1) // ensure that there is a rect for the next node { nuiMenuRect* pMenuRect = new nuiMenuRect(this, cpt+1); mRects.push_back(pMenuRect); mPopupTreeSink.Connect(pMenuRect->mpSBar->ValueChanged, &nuiPopupMenu::OnScrollBarChange, pMenuRect); } mRects[depth+1]->mpFromNode = pNode; CalcTreeSize(rRect, pNode, cpt); } } if (HasNonEmpty) { mRects[depth]->mHasNonEmpty = true; rect.SetSize(rect.GetWidth() + NUI_POPUP_TREE_HANDLE_SIZE * 2, rect.GetHeight()); } else { mRects[depth]->mHasNonEmpty = false; } mRects[depth]->mRect = rect; NGL_ASSERT(mRects.size() >= depth+1); rRect.SetSize(rect.GetWidth()+rRect.GetWidth(), rect.GetHeight()+rRect.GetHeight()); }
// Adjust the containing wxScrolledWindow's scrollbars appropriately void wxRemotelyScrolledTreeCtrl::AdjustRemoteScrollbars() { #if USE_GENERIC_TREECTRL || !defined(__WXMSW__) if (IsKindOf(CLASSINFO(wxGenericTreeCtrl))) { // This is for the generic tree control. // It calls SetScrollbars which has been overridden // to adjust the parent scrolled window vertical // scrollbar. ((wxGenericTreeCtrl*) this)->AdjustMyScrollbars(); return; } else #endif { // This is for the wxMSW tree control wxScrolledWindow* scrolledWindow = GetScrolledWindow(); if (scrolledWindow) { wxRect itemRect; if (GetBoundingRect(GetRootItem(), itemRect)) { // Actually, the real height seems to be 1 less than reported // (e.g. 16 instead of 16) int itemHeight = itemRect.GetHeight() - 1; int w, h; GetClientSize(&w, &h); wxRect rect(0, 0, 0, 0); CalcTreeSize(rect); double f = ((double) (rect.GetHeight()) / (double) itemHeight) ; int treeViewHeight = (int) ceil(f); int scrollPixelsPerLine = itemHeight; int scrollPos = - (itemRect.y / itemHeight); scrolledWindow->SetScrollbars(0, scrollPixelsPerLine, 0, treeViewHeight, 0, scrollPos); // Ensure that when a scrollbar becomes hidden or visible, // the contained window sizes are right. // Problem: this is called too early (?) wxSizeEvent event(scrolledWindow->GetSize(), scrolledWindow->GetId()); scrolledWindow->GetEventHandler()->ProcessEvent(event); } } } }
void CScrolledTreeCtrl::CalcTreeSize(const wxTreeItemId & id, wxRect & rect) { //wxLogVerbose(wxT("CScrolledTreeCtrl::CalcTreeSize")); // More efficient implementation would be to find the last item (but how?) // Q: is the bounding rect relative to the top of the virtual tree workspace // or the top of the window? How would we convert? wxRect itemSize; if (GetBoundingRect(id, itemSize)) { rect = CombineRectangles(rect, itemSize); } wxTreeItemIdValue cookie; wxTreeItemId childId = GetFirstChild(id, cookie); while (childId) { CalcTreeSize(childId, rect); childId = GetNextChild(childId, cookie); } }
void wxRemotelyScrolledTreeCtrl::CalcTreeSize(wxRect& rect) { // g_count = 0; CalcTreeSize(GetRootItem(), rect); }
nuiRect nuiPopupMenu::CalcIdealSize() { if (mTrashRemoval) return nuiRect(); uint32 cpt = 0; nuiRect rect = mInitialPos; // this rect is for initial position of the menu if (mRects.empty()) { mRects.push_back(new nuiMenuRect(this, 0)); mPopupTreeSink.Connect(mRects[0]->mpSBar->ValueChanged, &nuiPopupMenu::OnScrollBarChange, mRects[0]); mRects[0]->mpFromNode = mpTree; } NGL_ASSERT(mpTree); nuiWidgetPtr pWidget = mpTree->GetElement(); NGL_ASSERT(pWidget); nuiRect WidgetRect = pWidget->GetIdealRect(); if (mShowFirstNode) rect.SetSize((nuiSize)ToAbove(WidgetRect.GetWidth() + NUI_POPUP_MARGIN), (nuiSize)ToAbove(WidgetRect.GetHeight())); //size of the first element we wish not to be selectable else rect.SetSize((nuiSize)0,(nuiSize)0); //size of the first element we wish not to be selectable bool HasNonEmpty = false; uint32 count = mpTree->GetChildrenCount(); nuiRect GlobRect = rect; for (uint32 i = 0; i < count; i++) { nuiTreeNode* pNode = dynamic_cast<nuiTreeNode*>(mpTree->GetChild(i)); if (pNode) { pWidget = pNode->GetElement(); WidgetRect = pWidget->GetIdealRect(); rect.SetSize(MAX(rect.GetWidth(), WidgetRect.GetWidth()), rect.GetHeight() + WidgetRect.GetHeight()); if (!pNode->IsEmpty()) HasNonEmpty = true; if (pNode->IsOpened()) { if (mRects.size() <= cpt + 1) // ensure that there is a rect for the next node { nuiMenuRect* pMenuRect = new nuiMenuRect(this, cpt+1); mRects.push_back(pMenuRect); mPopupTreeSink.Connect(pMenuRect->mpSBar->ValueChanged, &nuiPopupMenu::OnScrollBarChange, pMenuRect); } mRects[cpt+1]->mpFromNode = pNode; NGL_ASSERT(mRects.size() > cpt+1); GlobRect = rect; CalcTreeSize(GlobRect, pNode, cpt); } } } if (HasNonEmpty) { mRects[0]->mHasNonEmpty = true; rect.SetSize(rect.GetWidth() + NUI_POPUP_TREE_HANDLE_SIZE * 2, rect.GetHeight()); } else { mRects[0]->mHasNonEmpty = false; } if (mInitialPos.GetWidth() > rect.GetWidth()) rect.SetWidth(mInitialPos.GetWidth()); mRects[0]->mRect = rect; if (cpt+1 < mRects.size()) { // there is unused rects int eraser_countdown = cpt; for (std::vector<nuiMenuRect*>::iterator it = mRects.begin(); it != mRects.end(); eraser_countdown--) { if (eraser_countdown >= 0) { it++; } else { if((*it)->mpSBar) { (*it)->mpSBar->SetVisible(false); (*it)->mpSBar->SetEnabled(false); mPopupTreeSink.DisconnectSource((*it)->mpSBar->ValueChanged); mSBarsPool.push_back((*it)->mpSBar); } delete *it; it = mRects.erase(it); } } } mIdealRect = GlobRect; return mIdealRect; }
void CScrolledTreeCtrl::CalcTreeSize(wxRect & rect) { CalcTreeSize(GetRootItem(), rect); }