void CLayerTreeDlg::ExpandTreeItem(HTREEITEM hItem)
{
	if (NULL != hItem)
	{
		m_tree.Expand(hItem, TVE_EXPAND);

		hItem = m_tree.GetChildItem(hItem);

		// 递归展开所有子项
		while (hItem != NULL)
		{
			ExpandTreeItem(hItem);
			hItem = m_tree.GetNextItem(hItem, TVGN_NEXT);
		}
	}
}
Beispiel #2
0
void CSpellbookDlg::AddSpellBook(const char * pszFileName)
{
    //open the spell book
    CSectionFile SpellBook;
    SpellBook.Open( CByakheeApp::GetDefaultDirectory() + pszFileName );

    //read the title
    CString strTitle = SpellBook.GetSection( "TITLE" );
	char * psTitle = strTitle.GetBuffer();
    if( strTitle.IsEmpty() )
    {
        //trim off path and extension, if there is one, and use that for the title
		char * psFileName;
		psFileName = (char*)malloc(sizeof(char)*strlen(pszFileName));
		strcpy(psFileName, pszFileName);
        char* pszTemp = strrchr(psFileName, '\\');
        if( pszTemp ) psFileName = ++pszTemp;
        pszTemp = strrchr(psFileName, '.' );
        if( pszTemp ) *pszTemp = '\0';
        strTitle = psFileName;
    }
    else
    {
        //find the end of the first line
        char* pszTemp = strchr( psTitle, '\r' );
        char* pszTemp2 = strchr( psTitle, '\n' );
        if( pszTemp != NULL || pszTemp2 != NULL )
        {
            //find the one nearest to the end of the first line
            if( pszTemp == NULL ) pszTemp = pszTemp2;
                else if( pszTemp2 != NULL && pszTemp2 < pszTemp ) pszTemp = pszTemp2;

            //terminate it at that point
            *pszTemp = '\0';
            CString strTemp = LPCSTR(psTitle);
            *pszTemp = '\n';
            strTitle = strTemp;
        }
    }

    //read the rest of the spellbook (1D10 months, D6 SAN...)
    CString strContents = SpellBook.GetSection( "SPELLS" );
    if( strContents.IsEmpty() ) return; //book was empty

    //add this book to the tree
    HTREEITEM hSpellBook = m_wndSpellList.InsertItem( strTitle, 1, 1 );
    HTREEITEM hParent = hSpellBook;
    ExpandTreeItem( hSpellBook );

    //read each line
    CParseBuffer ParseBuffer(strContents);
    while( ParseBuffer.IsEmpty() == FALSE )
    {
        //add item
        CString strItem;
        switch( ParseBuffer.PeekNextChar() )
        {
            case '*':
                hParent = hSpellBook;
                strItem = ParseBuffer.ExtractSurroundedString( '*', '*' );
                if(strItem.IsEmpty() == FALSE )
                    hParent = m_wndSpellList.InsertItem( strItem, 0, 0, hParent );
                break;

            default: //this default will generate a parse error if it's not a "", which will report an error in the spellbook
            case '\"':
                strItem = ParseBuffer.ExtractQuotedString();
                if(strItem.IsEmpty() == FALSE ) m_wndSpellList.InsertItem( strItem, 2, 2, hParent );
                break;
        }

        //skip over the rest of the line
        ParseBuffer.SkipToNextLine();
    }


}
BOOL CTreePropSheetBase::OnInitDialog() 
{
	if (m_bTreeViewMode && !IsWizardMode() )
	{
	  // Fix suggested by Przemek Miszczuk 
	  // http://www.codeproject.com/property/TreePropSheetEx.asp?msg=1024928#xx1024928xx
    TreePropSheet::CIncrementScope RefillingPageTreeContentGuard(m_nRefillingPageTreeContent );

		// be sure, there are no stacked tabs, because otherwise the
		// page caption will be to large in tree view mode
		EnableStackedTabs(FALSE);

		// Initialize image list.
		if (m_DefaultImages.GetSafeHandle())
		{
			IMAGEINFO	ii;
			m_DefaultImages.GetImageInfo(0, &ii);
			if (ii.hbmImage) DeleteObject(ii.hbmImage);
			if (ii.hbmMask) DeleteObject(ii.hbmMask);
			m_Images.Create(ii.rcImage.right-ii.rcImage.left, ii.rcImage.bottom-ii.rcImage.top, ILC_COLOR32|ILC_MASK, 0, 1);
		}
		else
			m_Images.Create(16, 16, ILC_COLOR32|ILC_MASK, 0, 1);
	}

	// perform default implementation
	BOOL bResult = CPropertySheet::OnInitDialog();

  // If in wizard mode, stop here.
  if( IsWizardMode() )
    return bResult;

	// Get tab control...
	CTabCtrl	*pTab = GetTabControl();
	if (!IsWindow(pTab->GetSafeHwnd()))
	{
		ASSERT(FALSE);
		return bResult;
	}

  // HighColorTab::UpdateImageList to change the internal image list to 24 bits colors)
  HighColorTab::UpdateImageList( *this );

	// If not in tree mode, stop here.
  if (!m_bTreeViewMode)
		// stop here, if we would like to use tabs
		return bResult;

	// ... and hide it
	pTab->ShowWindow(SW_HIDE);
	pTab->EnableWindow(FALSE);

	// Place another (empty) tab ctrl, to get a frame instead
	CRect	rectFrame;
	pTab->GetWindowRect(rectFrame);
	ScreenToClient(rectFrame);

	m_pFrame = CreatePageFrame();
	if (!m_pFrame)
	{
		ASSERT(FALSE);
		AfxThrowMemoryException();
	}
	m_pFrame->Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0xFFFF);
	m_pFrame->ShowCaption(m_bPageCaption);

	// Lets make place for the tree ctrl
	const int	nTreeWidth = m_nPageTreeWidth;

	CRect	rectSheet;
	GetWindowRect(rectSheet);
	rectSheet.right+= nTreeWidth;
	SetWindowPos(NULL, -1, -1, rectSheet.Width(), rectSheet.Height(), SWP_NOZORDER|SWP_NOMOVE);
	CenterWindow();

	MoveChildWindows(nTreeWidth, 0);

	// Lets calculate the rectangle for the tree ctrl
	CRect	rectTree(rectFrame);
	rectTree.right = rectTree.left + nTreeWidth - m_nSeparatorWidth;

	// calculate caption height
	CTabCtrl	wndTabCtrl;
	wndTabCtrl.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0x1234);
	wndTabCtrl.InsertItem(0, _T(""));
	CRect	rectFrameCaption;
	wndTabCtrl.GetItemRect(0, rectFrameCaption);
	wndTabCtrl.DestroyWindow();
	m_pFrame->SetCaptionHeight(rectFrameCaption.Height());

	// if no caption should be displayed, make the window smaller in
	// height
	if (!m_bPageCaption)
	{
		// make frame smaller
		m_pFrame->GetWnd()->GetWindowRect(rectFrame);
		ScreenToClient(rectFrame);
		rectFrame.top+= rectFrameCaption.Height();
		m_pFrame->GetWnd()->MoveWindow(rectFrame);

		// move all child windows up
		MoveChildWindows(0, -rectFrameCaption.Height());

		// modify rectangle for the tree ctrl
		rectTree.bottom-= rectFrameCaption.Height();

		// make us smaller
		CRect	rect;
		GetWindowRect(rect);
		rect.top+= rectFrameCaption.Height()/2;
		rect.bottom-= rectFrameCaption.Height()-rectFrameCaption.Height()/2;
		if (GetParent())
			GetParent()->ScreenToClient(rect);
		MoveWindow(rect);
    CenterWindow();
	}

	// finally create the tree control
	const DWORD	dwTreeStyle = TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS;
	m_pwndPageTree = CreatePageTreeObject();
	if (!m_pwndPageTree)
	{
		ASSERT(FALSE);
		AfxThrowMemoryException();
	}
	
	// MFC7-support here (Thanks to Rainer Wollgarten)
  // YT: Cast tree control to CWnd and calls CWnd::CreateEx in all cases (VC 6 and7).
  ((CWnd*)m_pwndPageTree)->CreateEx(
    WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, 
    _T("SysTreeView32"), _T("PageTree"), 
    WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, 
    rectTree, this, s_unPageTreeId);
	
	if (m_bTreeImages)
	{
		m_pwndPageTree->SetImageList(&m_Images, TVSIL_NORMAL);
		m_pwndPageTree->SetImageList(&m_Images, TVSIL_STATE);
	}

  // TreePropSheetEx: Fix refresh problem.
	// Fill the tree ctrl
  {
    TreePropSheet::CWindowRedrawScope WindowRedrawScope( m_pwndPageTree, true );
    // Populate the tree control.
    RefillPageTree();
    // Expand the tree if necessary.
    if( IsAutoExpandTree() )
    {
      ExpandTreeItem( m_pwndPageTree, m_pwndPageTree->GetRootItem(), TVE_EXPAND );
    }
    // Select item for the current page
	  if (pTab->GetCurSel() > -1)
		  SelectPageTreeItem(pTab->GetCurSel());
  }
	return bResult;
}