NS_IMETHODIMP nsTreeContentView::SetTree(nsITreeBoxObject* aTree) { ClearRows(); mBoxObject = aTree; if (aTree && !mRoot) { // Get our root element nsCOMPtr<nsIBoxObject> boxObject = do_QueryInterface(mBoxObject); nsCOMPtr<nsIDOMElement> element; boxObject->GetElement(getter_AddRefs(element)); mRoot = do_QueryInterface(element); NS_ENSURE_STATE(mRoot); // Add ourselves to document's observers. nsIDocument* document = mRoot->GetDocument(); if (document) { document->AddObserver(this); mDocument = document; } nsCOMPtr<nsIDOMElement> bodyElement; mBoxObject->GetTreeBody(getter_AddRefs(bodyElement)); if (bodyElement) { mBody = do_QueryInterface(bodyElement); int32_t index = 0; Serialize(mBody, -1, &index, mRows); } } return NS_OK; }
void nsTreeContentView::NodeWillBeDestroyed(const nsINode* aNode) { // XXXbz do we need this strong ref? Do we drop refs to self in ClearRows? nsCOMPtr<nsIMutationObserver> kungFuDeathGrip(this); ClearRows(); }
wxWrapSizer::~wxWrapSizer() { ClearRows(); }
void wxWrapSizer::RecalcSizes() { // First restore any proportions we may have changed and remove the old rows ClearRows(); if ( m_children.empty() ) return; // Put all our items into as many row box sizers as needed. const int majorSize = SizeInMajorDir(m_size); // max size of each row int rowTotalMajor = 0; // running row major size int maxRowMinor = 0; m_minSizeMinor = 0; m_minItemMajor = INT_MAX; m_maxSizeMajor = 0; // We need at least one row size_t nRow = 0; wxSizer *sizer = GetRowSizer(nRow); wxSizerItem *itemLast = NULL, // last item processed in this row *itemSpace = NULL; // spacer which we delayed adding // Now put our child items into child sizers instead for ( wxSizerItemList::iterator i = m_children.begin(); i != m_children.end(); ++i ) { wxSizerItem * const item = *i; if ( !item->IsShown() ) continue; wxSize minItemSize = item->GetMinSizeWithBorder(); const int itemMajor = SizeInMajorDir(minItemSize); const int itemMinor = SizeInMinorDir(minItemSize); if ( itemMajor > 0 && itemMajor < m_minItemMajor ) m_minItemMajor = itemMajor; // Is there more space on this line? Notice that if this is the first // item we add it unconditionally as it wouldn't fit in the next line // any better than in this one. if ( !rowTotalMajor || rowTotalMajor + itemMajor <= majorSize ) { // There is enough space here rowTotalMajor += itemMajor; if ( itemMinor > maxRowMinor ) maxRowMinor = itemMinor; } else // Start a new row { FinishRow(nRow, rowTotalMajor, maxRowMinor, itemLast); rowTotalMajor = itemMajor; maxRowMinor = itemMinor; // Get a new empty sizer to insert into sizer = GetRowSizer(++nRow); itemLast = itemSpace = NULL; } // Only remove first/last spaces if that flag is set if ( (m_flags & wxREMOVE_LEADING_SPACES) && IsSpaceItem(item) ) { // Remember space only if we have a first item if ( itemLast ) itemSpace = item; } else // not a space { if ( itemLast && itemSpace ) { // We had a spacer after a real item and now that we add // another real item to the same row we need to add the spacer // between them two. sizer->Add(itemSpace); } // Notice that we reuse a pointer to our own sizer item here, so we // must remember to remove it by calling ClearRows() to avoid // double deletion later sizer->Add(item); itemLast = item; itemSpace = NULL; } // If item is a window, it now has a pointer to the child sizer, // which is wrong. Set it to point to us. if ( wxWindow *win = item->GetWindow() ) win->SetContainingSizer(this); } FinishRow(nRow, rowTotalMajor, maxRowMinor, itemLast); // Now do layout on row sizer m_rows.SetDimension(m_position, m_size); }