/***************************************************************************** Collapses all levels of a branch -- not just 1 level. Using this in conjunction with TreeDataExpandOneLevel will get a tree grid that performs like VC++ watch window. Windows explorer tree differs: it "remembers" last expansion. Note that it doesn't check whether adjacent nodes are properply represented, it just does the collapse. *****************************************************************************/ void CTreeColumn::TreeDataCollapseAllSubLevels( int aiGridRow) { ASSERT( m_iColumnWithTree >= 0); ASSERT( m_pGrid != NULL); ASSERT( aiGridRow >= m_iFixedRowCount && aiGridRow < m_iRowCount); // display desired node and save its level and make visible CGridTreeCell* pGridTreeCell = (CGridTreeCell*)m_pGrid->GetCell( aiGridRow, m_iColumnWithTree); if( pGridTreeCell == NULL) return; unsigned char ucLevelCurrent = pGridTreeCell->GetLevel(); if( ucLevelCurrent <= 0) return; // don't expand or collapse items not part of the tree pGridTreeCell->SetViewable( TRUE); unsigned char ucLevel; int i1; for( i1 = aiGridRow + 1; i1 < m_iRowCount; i1++) { CGridTreeCell* pGridTreeCell = (CGridTreeCell*)m_pGrid->GetCell( i1, m_iColumnWithTree); if( pGridTreeCell == NULL) return; ucLevel = pGridTreeCell->GetLevel(); if( ucLevel <= ucLevelCurrent) break; pGridTreeCell->SetViewable( FALSE); } }
/***************************************************************************** Callable by class consumer to prepare one's own data array of tree info to display something reasonable. High order Bits of the tree display data are modified. *****************************************************************************/ void CTreeColumn::TreeDataPrepOutline(unsigned char aucLevel, // level to display >= 0x80 displays all int aiIndex, // Index to tree display data to modify int aiNbrElements) // nbr of elements in tree display data { ASSERT( aucLevel > 0); ASSERT( m_iColumnWithTree >= 0); ASSERT( aiIndex >= 0 ); ASSERT( aiNbrElements > 0); ASSERT( m_pGrid != NULL); ASSERT( aiIndex + aiNbrElements <= m_iRowCount - m_iFixedRowCount ); int i1; if( aucLevel >= 0x80) { for( i1=0; i1 < aiNbrElements; i1++) { int iCellRow = m_iFixedRowCount + aiIndex + i1; CGridTreeCell* pGridTreeCell = (CGridTreeCell*)m_pGrid->GetCell( iCellRow, m_iColumnWithTree); if( pGridTreeCell == NULL) return; pGridTreeCell->SetViewable( TRUE); } } else { for( i1=0; i1 < aiNbrElements; i1++) { int iCellRow = m_iFixedRowCount + aiIndex + i1; CGridTreeCell* pGridTreeCell = (CGridTreeCell*)m_pGrid->GetCell( iCellRow, m_iColumnWithTree); if( pGridTreeCell == NULL) return; if( pGridTreeCell->GetLevel() <= aucLevel) pGridTreeCell->SetViewable( TRUE); else pGridTreeCell->SetViewable( FALSE); } } }
void CVariablesGrid::RestoreExpandInfo(bool extraRow) { if (m_expandInfo.GetSize() == 0) return; // Get the full name. CString fullName; int curExpandPos = 0; int numRows = GetRowCount(); if (extraRow) numRows--; for (int i = 1; i < numRows; ++i) { CGridTreeCell* treeCell = (CGridTreeCell*)GetCell(i, 0); int level = treeCell->GetLevel(); if (level == 1) { fullName = GetItemText(i, 0); } else { fullName += "." + GetItemText(i, 0); } if (m_expandInfo[curExpandPos].m_fullName == fullName) { // m_treeColumn.TreeDataExpandOneLevel(i); treeCell->SetViewable(TRUE); curExpandPos++; if (curExpandPos == m_expandInfo.GetSize()) { m_treeColumn.TreeRefreshRows(); return; } } } m_treeColumn.TreeRefreshRows(); }
/***************************************************************************** 3/2001: Allows one to add to the existing tree structure. Repeatedly calling TreeSetup() with different tree configurations was the only way to change the tree structure with the original implementation, but had the disadvantage of destroying cell contents. The original implementation forced you to NOT store data directly in grid cells if you wished to change the tree. No validation of the tree branch "levels" done. Drawing code assumes a parent / child relationship of tree nodes. Thus, if the lines of the tree don't look right, make sure that the parent / child relationship is not violated. *****************************************************************************/ int CTreeColumn::InsertTreeBranch( const unsigned char* apucTreeLevelAry, // Tree Level data array -- // must have aiNbrElements of entries int aiNbrElements, // NUmber of tree elements to add int aiRow, // insert tree elements beginning at this row // If -1, append to end; If 0, Insert // at top no matter how many fixed rows BOOL abRedraw) // T=redraw; F=don't // returns: row where elements inserted; -1 on error { ASSERT( apucTreeLevelAry != NULL); ASSERT( aiNbrElements >= 0); ASSERT( aiRow >= -1); ASSERT( m_pGrid != NULL); // Must call TreeSetup(), first ASSERT( m_iFixedRowCount >= 0); ASSERT( m_pRuntimeClassTreeCell != NULL); if( aiNbrElements <= 0) return -1; // if user specified 0 or -1, adjust int iRowForAppend = 0; if( m_iRowCount <= m_iFixedRowCount) aiRow = -1; // if no non-fixed rows, then gotta append if( aiRow <= -1) { iRowForAppend = -1; aiRow = m_iRowCount; } else if( aiRow < m_iFixedRowCount) aiRow = m_iFixedRowCount; m_bAllowDraw = FALSE; // prevents crash during reset // retain old cell properties: establishes size for // tree drawing box based on current font CGridTreeCell GridCellCopy; GridCellCopy.SetTreeColumn( this); CGridCellBase* pCurrCell = m_pGrid->GetCell( m_iRowCount-1, m_iColumnWithTree); if (pCurrCell) GridCellCopy = *pCurrCell; // insert rows while replacing tree column cells to tree cell type int iCellRow = aiRow; int i1; for( i1=0; i1 < aiNbrElements; i1++) { // CGridCtrl's InsertRow() requires a -1 to append values to // the end of the grid if( iRowForAppend != -1) iRowForAppend = iCellRow; if( m_pGrid->InsertRow( "", iRowForAppend) < 0) { aiRow = -1; // error break; } if( !m_pGrid->SetCellType( iCellRow, m_iColumnWithTree, m_pRuntimeClassTreeCell ) ) { aiRow = -1; // error break; } CGridTreeCell* pGridTreeCell = (CGridTreeCell*)m_pGrid->GetCell( iCellRow, m_iColumnWithTree); if( pGridTreeCell != NULL) { pGridTreeCell->SetTreeColumn( this); pGridTreeCell->SetLevelAndHide( *apucTreeLevelAry ); pGridTreeCell->SetViewable( TRUE); } iCellRow++; m_iRowCount++; apucTreeLevelAry++; } ASSERT( m_iRowCount == m_pGrid->GetRowCount() ); // have to re-number all cells below insertion point if( aiRow > 0) { int iRow; int iColumnCount = m_pGrid->GetColumnCount(); for( iRow=iCellRow; iRow < m_iRowCount; iRow++) { int iCol; for (iCol = 0; iCol < iColumnCount; iCol++) { CGridCellBase* pGridCellBase = m_pGrid->GetCell( iRow, iCol); if( pGridCellBase != NULL) { pGridCellBase->SetCoords( iRow, iCol); } } } } m_bAllowDraw = TRUE; TreeRefreshRows(); if( abRedraw) m_pGrid->Invalidate(); return aiRow; }