home *** CD-ROM | disk | FTP | other *** search
- /*
- * BCTree.cpp
- * $Header: /bcsample/BUGBNCHX/MAINERR/BCTREE.CPP 1 5/28/96 1:11p Dave $
- *
- * Description:
- * Standard helper functions that mimic the support given by the MFC
- * CTreeCtrl class are implemented here. Also included are
- * additional functions to help with Expanding/Collapsing all nodes
- * under a specific tree item and getting the LPARAM info from the
- * selected item.
- *
- * Notes:
- * <implementation notes go here>
- *
- ***********************************************************************
- *
- * Nu-Mega Technologies, Inc.
- * P.O. Box 7780
- * Nashua, NH 03060
- *
- * (c) Copyright 1994, 1995 Nu-Mega Technologies, Inc.
- * ALL RIGHTS RESERVED.
- *
- ***********************************************************************
- *
- **********************************************************************/
- #include "stdafx.h"
- #include "BCTree.h"
-
- ////////////////////////////////////////////////////////////////////////
- // Standard tree control helpers
- //
- // All of the following functions are of the flavor of sending a message
- // to the specified HWND.
- HTREEITEM TreeCtrl_InsertItem ( HWND hWnd , LPTV_INSERTSTRUCT lpInsertStruct )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd ,
- TVM_INSERTITEM ,
- 0 ,
- ( LPARAM ) lpInsertStruct ) ;
- }
-
- BOOL TreeCtrl_DeleteAllItems ( HWND hWnd )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( BOOL ) SendMessage( hWnd ,
- TVM_DELETEITEM ,
- 0 ,
- ( LPARAM ) TVI_ROOT ) ;
- }
-
- BOOL TreeCtrl_GetItem ( HWND hWnd , TV_ITEM* pItem )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( BOOL ) SendMessage ( hWnd ,
- TVM_GETITEM ,
- 0 ,
- ( LPARAM ) pItem ) ;
- }
-
- HTREEITEM TreeCtrl_GetParentItem ( HWND hWnd , HTREEITEM hItem )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd ,
- TVM_GETNEXTITEM ,
- TVGN_PARENT ,
- ( LPARAM ) hItem );
- }
-
- HTREEITEM TreeCtrl_GetChildItem ( HWND hWnd , HTREEITEM hItem )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd ,
- TVM_GETNEXTITEM ,
- TVGN_CHILD ,
- ( LPARAM ) hItem );
- }
-
- HTREEITEM TreeCtrl_GetSelectedItem ( HWND hWnd )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd ,
- TVM_GETNEXTITEM ,
- TVGN_CARET ,
- 0 );
- }
-
- HTREEITEM TreeCtrl_GetNextItem ( HWND hWnd ,
- HTREEITEM hItem ,
- UINT nCode )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd,
- TVM_GETNEXTITEM,
- nCode,
- ( LPARAM ) hItem ) ;
- }
-
- HTREEITEM TreeCtrl_Select ( HWND hWnd ,
- HTREEITEM hItem ,
- UINT nCode )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( HTREEITEM ) SendMessage ( hWnd ,
- TVM_SELECTITEM ,
- nCode ,
- ( LPARAM ) hItem );
- }
-
- BOOL TreeCtrl_EnsureVisible ( HWND hWnd , HTREEITEM hItem )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( BOOL ) SendMessage ( hWnd ,
- TVM_ENSUREVISIBLE ,
- 0 ,
- ( LPARAM ) hItem ) ;
- }
-
- BOOL TreeCtrl_Expand ( HWND hWnd ,
- HTREEITEM hItem ,
- UINT nCode )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
- return ( BOOL ) SendMessage ( hWnd ,
- TVM_EXPAND ,
- nCode ,
- ( LPARAM ) hItem ) ;
- }
-
- ////////////////////////////////////////////////////////////////////////
- // Tree Control Extensions
- //
- // Additional work is needed to get the tree control functionality
- // desired.
-
- // Expand/Collapse all items in the tree.
- void TreeCtrl_ExpandAll ( HWND hWnd , UINT nCode )
- {
- // In the NT 3.51 RC, the Tree control will not notify the
- // parent window that the selected item has changed when we collapse
- // the tree. To work around this we will force all collapse all's
- // to select the first item.
- HTREEITEM hFirstItem = TreeCtrl_GetNextItem ( hWnd , NULL , TVGN_CHILD ) ;
- HTREEITEM hItem = hFirstItem ;
- while ( NULL != hItem )
- {
- TreeCtrl_Expand ( hWnd , hItem , nCode ) ;
- TreeCtrl_ExpandCollapseAllBelow ( hWnd , hItem , nCode ) ;
- hItem = TreeCtrl_GetNextItem ( hWnd , hItem , TVGN_NEXT ) ;
- }
- if ( TVE_COLLAPSE == nCode )
- TreeCtrl_Select ( hWnd , hFirstItem , TVGN_CARET ) ;
- }
-
-
- // Extends the Expand function to do the operation on all items below
- // the specified node.
- void TreeCtrl_ExpandCollapseAllBelow ( HWND hWnd ,
- HTREEITEM hItem ,
- UINT nCode )
- {
- // The degenerative case.
- if ( NULL == hItem )
- return ;
- else
- {
- // Get the first child of the node passed in.
- HTREEITEM hChild = TreeCtrl_GetChildItem ( hWnd , hItem ) ;
- while ( NULL != hChild )
- {
- // Expand the child.
- TreeCtrl_Expand ( hWnd , hChild , nCode ) ;
- // Go all the way diagonally, expanding each
- // node as we come to it.
- HTREEITEM hChildTwo = TreeCtrl_GetChildItem ( hWnd , hChild ) ;
- while ( NULL != hChildTwo )
- {
- // Expand the child.
- TreeCtrl_Expand ( hWnd , hChildTwo , nCode ) ;
- hChildTwo = TreeCtrl_GetChildItem ( hWnd , hChildTwo ) ;
- // Do ALL the expansion on the child. And I thought
- // I would never see recursion after college!
- TreeCtrl_ExpandCollapseAllBelow ( hWnd , hChildTwo , nCode ) ;
- }
- // Get the next child sibling.
- hChild = TreeCtrl_GetNextItem ( hWnd , hChild , TVGN_NEXT ) ;
- }
- }
- }
-
- // Gets the data out of the selected item and returns it
- // as LPVOID.
- LPVOID TreeCtrl_GetSelectedLParam ( HWND hWnd )
- {
- ASSERT ( IsWindow ( hWnd ) ) ;
-
- // Get the currently selected item.
- HTREEITEM hItem = TreeCtrl_GetSelectedItem ( hWnd ) ;
- ASSERT ( NULL != hItem ) ;
-
- if ( NULL == hItem )
- return ( NULL ) ;
-
- // Get the information out of the selected item.
- TV_ITEM stTVI ;
- memset ( &stTVI , NULL , sizeof ( TV_ITEM ) ) ;
- stTVI.hItem = hItem ;
- VERIFY ( TreeCtrl_GetItem ( hWnd , &stTVI ) ) ;
- return ( (void*) stTVI.lParam ) ;
-
- }
-
-