Example #1
0
BOOL CLibraryFolderCtrl::SelectItems(HTREEITEM hItemFrom, HTREEITEM hItemTo)
{
	HTREEITEM hItem = GetRootItem();

	while ( hItem && hItem != hItemFrom && hItem != hItemTo )
	{
		hItem = GetNextVisibleItem( hItem );
		SetItemState( hItem, 0, TVIS_SELECTED );
	}

	if ( ! hItem ) return FALSE;

	if ( hItem == hItemTo )
	{
		hItemTo		= hItemFrom;
		hItemFrom	= hItem;
	}

	BOOL bSelect = TRUE;

	while ( hItem )
	{
		SetItemState( hItem, bSelect ? TVIS_SELECTED : 0, TVIS_SELECTED );
		if ( hItem == hItemTo ) bSelect = FALSE;
		hItem = GetNextVisibleItem( hItem );
	}

	return TRUE;
}
Example #2
0
HDUITREEITEM		CDUITreeViewImpl::GetNextVisibleItem(HDUITREEITEM pItem)
{
	if ( pItem == NULL || !pItem->IsVisible() )
		return NULL;

	HDUITREEITEM hNextItemRet = NULL;

	if ( pItem->IsParent() )
	{
		if ( pItem->IsExpand() )
		{
			INT nCount = pItem->GetControlCount();
			if ( nCount > 0)
			{
				HDUITREEITEM hNextItem = pItem->GetFirstChild();
				if ( hNextItem )
				{
					if ( hNextItem->IsVisible() )
						return hNextItem;
					else
						hNextItemRet = GetNextVisibleItem(hNextItem);
				}
			}
		}
		else
		{
			HDUITREEITEM hNextItem = pItem->GetNextSibling();
			if ( hNextItem )
			{
				if ( hNextItem->IsVisible() )
					return hNextItem;
				else
				{
					hNextItemRet = GetNextVisibleItem(hNextItem);
				}
			}
		}
	}
	else
	{
		HDUITREEITEM hNextItem = pItem->GetNextSibling();
		if ( hNextItem )
		{
			if ( hNextItem->IsVisible() )
				return hNextItem;
			else
			{
				hNextItemRet = GetNextVisibleItem(hNextItem);
			}
		}
		else  // return to the parent
		{
			hNextItem = pItem->GetParent()->GetNextSibling();
			return GetNextVisibleItem(hNextItem);
		}
	}

	return hNextItemRet;
}
Example #3
0
HTREEITEM CTreeCtrlEx::GetNextSelectedItem( HTREEITEM hItem )
{
	for ( hItem = GetNextVisibleItem( hItem ); hItem!=NULL; hItem = GetNextVisibleItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			return hItem;

	return NULL;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input  : nIDEvent -
//-----------------------------------------------------------------------------
void CGroupList::OnTimer(UINT nIDEvent)
{
    //DBG("OnTimer\n");
    switch (nIDEvent)
    {
    case TIMER_GROUP_DRAG_SCROLL:
    {
        CPoint point;
        GetCursorPos(&point);

        CRect rect;
        GetWindowRect(&rect);

        if (!rect.PtInRect(point))
        {
            if (point.y > rect.bottom)
            {
                // scroll down
                int nCount = GetVisibleCount();
                HTREEITEM hItem = GetFirstVisibleItem();
                for (int i = 1; i < nCount; i++)
                {
                    hItem = GetNextVisibleItem(hItem);
                }

                hItem = GetNextVisibleItem(hItem);

                if (hItem)
                {
                    CTreeCtrl::EnsureVisible(hItem);
                }
            }
            else if (point.y < rect.top)
            {
                HTREEITEM hItem = GetFirstVisibleItem();
                HTREEITEM hPrevVisible = this->GetPrevVisibleItem(hItem);
                if (hPrevVisible)
                {
                    // scroll up
                    CTreeCtrl::EnsureVisible(hPrevVisible);
                }
            }
        }

        break;
    }

    default:
    {
        CTreeCtrl::OnTimer(nIDEvent);
    }
    }
}
Example #5
0
int duTreeListCtrl::GetInsertItem(TreeListItem *pItem, vector<duPlugin *> &vtInsert)
{
	int nIndex = GetTreeItemIndex(pItem);
	TreeListItem *pNext = GetNextVisibleItem(pItem);
	while (pNext)
	{
		if (pNext == pItem->pNextSibling)
			break;
		
		vtInsert.push_back(pNext->pPlugin);
		pNext = GetNextVisibleItem(pNext);
	}
	
	return nIndex;
}
Example #6
0
BOOL CTreeCtrlEx::SelectItems( HTREEITEM hFromItem, HTREEITEM hToItem )
{
	// Determine direction of selection 
	// (see what item comes first in the tree)
	HTREEITEM hItem = GetRootItem();

	while ( hItem && hItem!=hFromItem && hItem!=hToItem )
		hItem = GetNextVisibleItem( hItem );

	if ( !hItem )
		return FALSE;	// Items not visible in tree

	BOOL bReverse = hItem==hToItem;

	// "Really" select the 'to' item (which will deselect 
	// the previously selected item)

	SelectItem( hToItem );

	// Go through all visible items again and select/unselect

	hItem = GetRootItem();
	BOOL bSelect = FALSE;

	while ( hItem )
	{
		if ( hItem == ( bReverse ? hToItem : hFromItem ) )
			bSelect = TRUE;

		if ( bSelect )
		{
			if ( !( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) )
				SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
		}
		else
		{
			if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
				SetItemState( hItem, 0, TVIS_SELECTED );
		}

		if ( hItem == ( bReverse ? hFromItem : hToItem ) )
			bSelect = FALSE;

		hItem = GetNextVisibleItem( hItem );
	}

	return TRUE;
}
Example #7
0
VOID CDUITreeViewImpl::DoPaint(HDC dc, const RECT& rtDraw)
{
	DUI_ASSERT(dc && rtDraw.bottom-rtDraw.top >0 && rtDraw.right - rtDraw.left > 0 );
	
	RECT rtAvailable = GetContentRect();
	HDUITREEITEM hFirst = m_hTopItem;

	for ( hFirst;hFirst!=NULL;hFirst=GetNextVisibleItem(hFirst) )
	{
		CDUIRenderClip clip(dc, GetContentRect());

		RECT rtControl = hFirst->GetControlRect();
		hFirst->DoPaint(dc,rtControl);
		
		
		if ( rtControl.bottom >= rtAvailable.bottom )
			break;
	}
	
	if(m_pVertSB != NULL 
		&& (m_pVertSB->IsVisible()))
	{
		CDUIRenderClip clip(dc, GetContentRect());
		
		m_pVertSB->DoPaint(dc, rtDraw);
	}
}
Example #8
0
int duTreeListCtrl::GetTreeItemIndex(TreeListItem *pItem)
{
	int nIndex = 0;
	TreeListItem *pNext = GetNextVisibleItem(&m_RootItem);
	while (pNext)
	{
		if (pNext == pItem)
			return nIndex;

		
		nIndex++;
		pNext = GetNextVisibleItem(pNext);
	}

	return -1;
}
Example #9
0
void CTreeCtrlEx::ClearSelection(BOOL bMultiOnly/*=FALSE*/)
{
//	if ( !bMultiOnly )
//		SelectItem( NULL );

	for ( HTREEITEM hItem=GetRootItem(); hItem!=NULL; hItem=GetNextVisibleItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			SetItemState( hItem, 0, TVIS_SELECTED );
}
Example #10
0
UINT CTreeCtrlEx::GetSelectedCount() const
{
	// Only visible items should be selected!
	UINT uCount=0;
	for ( HTREEITEM hItem = GetRootItem(); hItem!=NULL; hItem = GetNextVisibleItem( hItem ) )
		if ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED )
			uCount++;

	return uCount;
}
Example #11
0
void CLibraryFolderCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
	if ( ( nChar == VK_UP || nChar == VK_DOWN ) && ( GetKeyState( VK_SHIFT ) & 0x8000 ) && m_bMultiSelect )
	{
		if ( ! m_hFirstSelected )
		{
			m_hFirstSelected = GetFirstSelectedItem();
			ClearSelection( m_hFirstSelected );
		}

		HTREEITEM hItemPrevSel = GetSelectedItem();
		HTREEITEM hItemNext;

		if ( nChar == VK_UP )
			hItemNext = GetPrevVisibleItem( hItemPrevSel );
		else
			hItemNext = GetNextVisibleItem( hItemPrevSel );

		if ( hItemNext )
		{
			BOOL bReselect = ! ( GetItemState( hItemNext, TVIS_SELECTED ) & TVIS_SELECTED );

			SelectItem( hItemNext );

			if ( bReselect ) SetItemState( hItemPrevSel, TVIS_SELECTED, TVIS_SELECTED );
		}

		NotifySelectionChanged();

		return;
	}
	else if ( nChar >= VK_SPACE )
	{
		m_hFirstSelected = NULL;
		ClearSelection();
	}
	else if ( nChar == 'A' && ( GetAsyncKeyState( VK_CONTROL ) & 0x8000 ) && m_bMultiSelect )
	{
		BOOL bChanged = FALSE;

		for ( HTREEITEM hItem = GetRootItem() ; hItem != NULL ; hItem = GetNextItem( hItem, TVGN_NEXTVISIBLE ) )
		{
			if ( ( GetItemState( hItem, TVIS_SELECTED ) & TVIS_SELECTED ) == 0 )
			{
				SetItemState( hItem, TVIS_SELECTED, TVIS_SELECTED );
				bChanged = TRUE;
			}
		}

		if ( bChanged ) NotifySelectionChanged();
		return;
	}

	CTreeCtrl::OnKeyDown( nChar, nRepCnt, nFlags );
}
Example #12
0
void CTreeCtrlFolder::SelectNextItem(BOOL selectNext)
{
	HTREEITEM item = GetSelectedItem();
	if (selectNext)
		item = GetNextVisibleItem(item);
	else
		item = GetPrevVisibleItem(item);
	if (item != NULL)
	{	SelectItem(item);
		Inform();
	}
}
Example #13
0
// Determine if a referenced item is visible within the control window
bool VividTree::ItemIsVisible( HTREEITEM item )
{
	HTREEITEM scan_item;
	scan_item = GetFirstVisibleItem();
	while ( scan_item != NULL )
	{
		if ( item == scan_item )
			return true;
		scan_item = GetNextVisibleItem( scan_item );
	}
	return false;
}
Example #14
0
IDUIControl* CDUITreeViewImpl::FindControl(FINDCONTROLPROC Proc, LPVOID pData, UINT uFlags)
{
	if((uFlags & FIND_FLAG_VISIBLE)
		&& !(GetStyle() & CONTROL_STYLE_VISIBLE)) return NULL;
	
	if((uFlags & FIND_FLAG_ENABLED)
		&& (GetStatus() & CONTROL_STATUS_DISABLE)) return NULL;
	
	if((uFlags & FIND_FLAG_HITTEST)
		&& 
		(!(PtInRect(&m_rtControl, *static_cast<LPPOINT>(pData)))
		|| (GetStyle() & CONTROL_STYLE_TRANSPARENT))) return NULL;
	
	IDUIControl* pRet = NULL;
	if((uFlags & FIND_FLAG_MEFIRST))
	{
		pRet = Proc(this, pData);
		if(pRet != NULL) return pRet;
	}


	RECT rtAvailable = GetContentRect();
	HDUITREEITEM hFirst = m_hTopItem;
	
	for ( hFirst;hFirst!=NULL;hFirst=GetNextVisibleItem(hFirst) )
	{
		RECT rtControl = hFirst->GetControlRect();

		pRet =	hFirst->FindControl(Proc, pData, uFlags);
		if ( pRet )  return pRet;		
		
		if ( rtControl.bottom >= rtAvailable.bottom )
			break;
	}

// 	INT nCount = m_arChildControl.size();
// 	for(int i=m_nTopIndex; (i<nCount && i<=m_nLastIndex); ++i)
// 	{
// 		pRet = m_arChildControl[i]->FindControl(Proc, pData, uFlags);
// 		if(pRet != NULL) return pRet;
// 	}
	
	IDUIScrollBar* pScrollBar = GetVerticalSB();
	if(pScrollBar != NULL)
	{
		pRet = pScrollBar->FindControl(Proc, pData, uFlags);
		if(pRet != NULL) return pRet;
	}
	
	return Proc(this, pData);
}
Example #15
0
TreeCtrlItem *duTreeCtrl::GetFirstVisibleItem(int &nOffset)
{
	nOffset = 0;
	if (m_nItems == 0)
		return m_pRoot;
	
	POINT ptScroll = GetViewPoint();
	int nCalcHeight = 0;
	TreeCtrlItem *pTreeItem = GetNextVisibleItem(m_pRoot);
	while (pTreeItem)
	{
		nCalcHeight += m_nItemHeight;
		if (nCalcHeight > ptScroll.y)
		{
			nOffset = (ptScroll.y + m_nItemHeight) - nCalcHeight;
			return pTreeItem;
		}

		pTreeItem = GetNextVisibleItem(pTreeItem);
	}

	return NULL;
}
Example #16
0
void CMyTreeCtrl::HandleScrollTimer()
{
	// Doesn't matter that we didn't initialize m_timerticks
	m_timerticks++;

	POINT pt, clientPt;
	GetCursorPos( &pt );
	RECT rect;
	GetClientRect( &rect );
	ClientToScreen( &rect );
	clientPt = pt;
	ScreenToClient( &clientPt );

	CImageList::DragMove(clientPt);

	HTREEITEM hitem = GetFirstVisibleItem();

	if( pt.y < rect.top + 10 )
	{
		// We need to scroll up
		// Scroll slowly if cursor near the treeview control
		int slowscroll = 6 - (rect.top + 10 - pt.y) / 4;
		if( 0 == ( m_timerticks % (slowscroll > 0? slowscroll : 1) ) )
		{
			CImageList::DragShowNolock(FALSE);
			SendMessage( WM_VSCROLL, SB_LINEUP);
			SelectDropTarget(hitem);
			m_hitemDrop = hitem;
			CImageList::DragShowNolock(TRUE);
		}
	}
	else if( pt.y > rect.bottom - 10 )
	{
		// We need to scroll down
		// Scroll slowly if cursor near the treeview control
		int slowscroll = 6 - (pt.y - rect.bottom + 10 ) / 4;
		if( 0 == ( m_timerticks % (slowscroll > 0? slowscroll : 1) ) )
		{
			CImageList::DragShowNolock(FALSE);
			SendMessage( WM_VSCROLL, SB_LINEDOWN);
			int nCount = GetVisibleCount();
			for ( int i=0; i<nCount-1; ++i )
				hitem = GetNextVisibleItem(hitem);
			if( hitem )
				SelectDropTarget(hitem);
			m_hitemDrop = hitem;
			CImageList::DragShowNolock(TRUE);
		}
	}
}
Example #17
0
void VividTree::DrawItemLines(CDC* pDC)
{
	// draw items
	HTREEITEM show_item, parent;
	CRect rc_item, rc_parent;
	bool has_children;

	show_item = GetFirstVisibleItem();
	if ( show_item == NULL )
		return;

	do
	{
		parent = GetParentItem( show_item );
		has_children = ItemHasChildren( show_item ) || parent == NULL;

		if ( GetItemRect( show_item, rc_item, TRUE ) )
		{
			if( parent )
			{
				CPen pen(PS_SOLID, 1, RGB(0xff,0xff,0));
				CPen* pOldPen = pDC->SelectObject(&pen);

				int nOldRop = pDC->SetROP2(R2_COPYPEN);

				GetItemRect(parent, rc_parent, TRUE);
				BITMAP bm;
				m_bmp_tree_open.GetBitmap(&bm);

				pDC->MoveTo(rc_parent.left-bm.bmWidth/2-2, rc_parent.bottom);
				pDC->LineTo(rc_parent.left-bm.bmWidth/2-2, rc_item.top+bm.bmHeight/2);
				pDC->MoveTo(rc_parent.left-bm.bmWidth/2-2, rc_item.top+bm.bmHeight/2);
				if(has_children)
				{
					pDC->LineTo(rc_item.left-bm.bmWidth-2, rc_item.top+bm.bmHeight/2);
				}
				else
				{
					pDC->LineTo(rc_item.left-2, rc_item.top+bm.bmHeight/2);
				}

				pDC->SetROP2(nOldRop);
				pDC->SelectObject(pOldPen);
			}
		}
	} while ( (show_item = GetNextVisibleItem( show_item )) != NULL );
}
Example #18
0
VOID CDUITreeViewImpl::SetControlRect(const RECT& rt)
{
	m_rtControl = rt;
	
	int nMaxWidth = 0;
	m_nTotalHeight =CalculateTotalHeight();
	
	RECT rtAvailable = GetContentRect();

	BOOL bUpdateScroll = ProcessVerticalSB(rtAvailable, m_nTotalHeight, m_nExtraHeight);
	if(bUpdateScroll) return; //layout at next time
	
	if(!m_pVertSB.IsNull() &&
		(m_pVertSB->IsVisible()))
	{
		INT nThumbWidth = m_pVertSB->GetFixedSize().cx;
		RECT rtScrollBar = rtAvailable;
		rtScrollBar.left = rtScrollBar.right - nThumbWidth;
		
		m_pVertSB->SetControlRect(rtScrollBar);
		
		rtAvailable.right -= nThumbWidth;
	}
	
	IDUIControl* pControl = NULL;
	INT nCurrentHeight(0), nControlHeight(0);;
	
	RECT rtControl = rtAvailable;

	m_hTopItem = CalculateTopItem();
	CTrace::TraceInfo(_T("2011-09-18,hTopItem = %x"),m_hTopItem);

	HDUITREEITEM hFirst = m_hTopItem;
	for ( hFirst;hFirst!=NULL;hFirst=GetNextVisibleItem(hFirst) )
	{
		CTrace::TraceInfo(_T("2011-09-18,hFirst = %x"),hFirst);

		rtControl.top = rtAvailable.top + nCurrentHeight;
		rtControl.bottom = rtControl.top + hFirst->GetItemHeight();

		hFirst->SetControlRect(rtControl);

		nCurrentHeight += hFirst->GetItemHeight();
		if ( nCurrentHeight >= rtAvailable.bottom - rtAvailable.top )
			break;
	}
}
Example #19
0
void CMultiSelTreeCtrl::ScrollToFirstItem( HTREEITEM firstItem )
{
    ASSERT(firstItem != NULL);
    HTREEITEM lastItem= firstItem;

    EnsureVisible( firstItem );
    int c=GetVisibleCount();

    for( int i=1; i < c && lastItem != NULL; i++ )
        lastItem= GetNextVisibleItem( lastItem );
            
    // Make the last item visible, then scroll up if required to make sure the
    // first item is still visible (user may have changed window height while
    // we were running the refresh)
    if( lastItem != NULL )
    {
        EnsureVisible( lastItem );
        EnsureVisible( firstItem );
    }
}
Example #20
0
void duTreeCtrl::GetViewSize(LPSIZE lpSize)
{
	if (lpSize == NULL)
		return;

	lpSize->cx = lpSize->cy = 0;

	int nMaxWidth = 0;
	int nTotalHeight = 0;
	TreeCtrlItem *pItem = m_pRoot->pFirstChild;
	while (pItem)
	{
		int nItemWidth = CalcItemWidth(pItem);
		nMaxWidth = max(nMaxWidth, nItemWidth);
		nTotalHeight += m_nItemHeight;
		pItem = GetNextVisibleItem(pItem);
	}
	
	lpSize->cx = nMaxWidth;
	lpSize->cy = nTotalHeight;
}
HTREEITEM CEditTreeCtrl::GetDropTarget(EDropHint & hint) {
	ASSERT(m_pDragData != 0);

	CPoint pt;
	GetCursorPos(&pt);
	ScreenToClient(&pt);

	UINT flags;
	HTREEITEM hDrop = HitTest(pt, &flags);
	hint = GetDropHint(flags);
	m_pDragData->SetDropTarget(hDrop);
	if(hDrop) {
		m_pDragData->DragLeave();	// allow updates

		SelectDropTarget(hDrop);

		if(m_pDragData->CheckExpand(hDrop))
			Expand(hDrop, TVE_EXPAND);

		// Make sure the surrounding items are visible, too
		// This will scroll the tree if necessary.
		HTREEITEM hPrev = GetPrevVisibleItem(hDrop);
		if(hPrev)
			EnsureVisible(hPrev);
		HTREEITEM hNext = GetNextVisibleItem(hDrop);
		if(hNext)
			EnsureVisible(hNext);

		// if the drop target is a descendent of the dragged item, then
		// disallow dropping the item here...
		if(IsAncestor(m_pDragData->GetDragItem(), hDrop) || !CanDropItem(m_pDragData->GetDragItem(), hDrop, hint))
			hint = DROP_NODROP;

		m_pDragData->DragEnter(pt);
	} else if(hint != DROP_NODROP && !CanDropItem(m_pDragData->GetDragItem(), hDrop, hint))
		hint = DROP_NODROP;

	return hDrop;
}
Example #22
0
TreeCtrlItem *duTreeCtrl::yHitTest(const duRect &rcTreeCtrl, const POINT pt, duRect &rcItem)
{
	POINT ptClient(pt);
	ptClient.x -= rcTreeCtrl.left;
	ptClient.y -= rcTreeCtrl.top;
	
	int nOffsetY = 0;
	TreeCtrlItem *pFirstVisible = GetFirstVisibleItem(nOffsetY);
	if (pFirstVisible == NULL || pFirstVisible == m_pRoot)
		return NULL;
	
	POINT ptView = GetViewPoint();
	duSize sizeView;
	GetViewSize(&sizeView);
	int nDrawHeight = -nOffsetY;
	TreeCtrlItem *pItem = pFirstVisible;
	while (pItem)
	{
		rcItem.SetRectEmpty();
		rcItem.left = -ptView.x;
		rcItem.right = rcItem.left + sizeView.cx;
		rcItem.top = nDrawHeight;
		rcItem.bottom = rcItem.top + m_nItemHeight;

		if (rcItem.PtInRect(ptClient))
			return pItem;

		if (nDrawHeight - nOffsetY > rcTreeCtrl.Height())
			break;

		nDrawHeight += m_nItemHeight;
		pItem = GetNextVisibleItem(pItem);
	}
	
	return NULL;
}
Example #23
0
BOOL CMultiSelTreeCtrl::ScrollTree( int linesToScroll ) 
{
	BOOL moved= FALSE;
	HTREEITEM firstItem;
	HTREEITEM currentItem;

	if( linesToScroll < 0 )
	{
		// Scrolling down
		firstItem=GetFirstVisibleItem();
		long visible=GetVisibleCount();	
		int count=0;

		for(int i=0; i < visible - linesToScroll; i++)
		{
			currentItem= firstItem;
			firstItem= GetNextVisibleItem(currentItem);
			if( firstItem == NULL )
			{
				firstItem= currentItem;
				break;
			}
			else
				count++;
		}
		if( count >= visible )
			moved= TRUE;
	}
	else if( linesToScroll > 0 )
	{
		// Scrolling up
		firstItem=GetFirstVisibleItem();
		
		for(int i=0; i < linesToScroll; i++)
		{
			currentItem= firstItem;
			firstItem= GetPrevVisibleItem(currentItem);
			if( firstItem == NULL )
			{
				firstItem= currentItem;
				break;
			}
			else
				moved= TRUE;
		}
	}
    else
    {
        ASSERT(0);
        return moved;
    }

	// Turn on redraws
	if(moved)
	{
		EnsureVisible(firstItem);

		// Redraw w/out erase to avoid slow video update
		RedrawWindow( NULL, NULL, RDW_UPDATENOW );
	}

	return moved;
}
Example #24
0
// Draw TreeCtrl Items
void VividTree::DrawItems( CDC *pDC )
{
	// draw items
	HTREEITEM show_item, parent;
	CRect rc_item;
	CString name;
	COLORREF color;
	DWORD tree_style;
	BITMAP bm;
	CDC dc_mem;
	CBitmap *button;
	int count = 0;
	int state;
	bool selected;
	bool has_children;

	show_item = GetFirstVisibleItem();
	if ( show_item == NULL )
		return;

	dc_mem.CreateCompatibleDC(NULL);
	color = pDC->GetTextColor();
	tree_style = ::GetWindowLong( m_hWnd, GWL_STYLE ); 

	do
	{
		state = GetItemState( show_item, TVIF_STATE );
		parent = GetParentItem( show_item );
		has_children = ItemHasChildren( show_item ) || parent == NULL;
		selected = (state & TVIS_SELECTED) && ((this == GetFocus()) || 
				(tree_style & TVS_SHOWSELALWAYS));

		if ( GetItemRect( show_item, rc_item, TRUE ) )
		{
			if( selected)
			{
				CRect rc_all;
				GetItemRect(show_item,&rc_all, FALSE);
				pDC->FillSolidRect(&rc_all, RGB(170,155,119));
			}
			if ( has_children  || selected )
			{
				COLORREF from;
				CRect rect;
				// Show 
				if ( selected )
					from = m_gradient_bkgd_sel;
				else
					from = m_gradient_bkgd_to - (m_gradient_bkgd_from - m_gradient_bkgd_to);
				rect.top = rc_item.top;
				rect.bottom = rc_item.bottom;
				rect.right = m_h_size + m_h_offset;
				if ( !has_children )
					rect.left = rc_item.left + m_h_offset;
				else
					rect.left = m_h_offset;
				//GradientFillRect( pDC, rect, from, m_gradient_bkgd_to, FALSE );
				//pDC->SetTextColor( RGB( 0, 0, 255 ) );
				pDC->SetTextColor(GetSysColor(COLOR_HIGHLIGHTTEXT));

				if ( has_children )
				{
					// Draw an Open/Close button
					if ( state & TVIS_EXPANDED )
						button = &m_bmp_tree_open;
					else
						button = &m_bmp_tree_closed;
					VERIFY(button->GetObject(sizeof(bm), (LPVOID)&bm));
					CBitmap *bmp_old = (CBitmap*)dc_mem.SelectObject(button); 
					pDC->TransparentBlt(rc_item.left - bm.bmWidth - 2, rc_item.top, bm.bmWidth, bm.bmHeight, 
						&dc_mem, 0, 0,bm.bmWidth,bm.bmWidth, GetSysColor(COLOR_HIGHLIGHTTEXT));
					//pDC->BitBlt( rc_item.left - bm.bmWidth - 2, rc_item.top, bm.bmWidth, bm.bmHeight, 
					//	&dc_mem, 0, 0, SRCCOPY );
					// CleanUp
					dc_mem.SelectObject( bmp_old );
				}
			}
			if ( !has_children )
			{
				// lookup the ICON instance (if any) and draw it
				HICON icon;
				icon = GetItemIcon( show_item );
				if ( icon != NULL )
					DrawIconEx( pDC->m_hDC, rc_item.left - 18, rc_item.top, icon, 16, 16,0,0, DI_NORMAL );
			}
			name = GetItemText( show_item );
			rc_item.DeflateRect( 0,1,0,1 );
			if ( selected )
			{
				if ( !has_children  )
					pDC->SetTextColor( GetSysColor(COLOR_HIGHLIGHTTEXT) );
				COLORREF col = pDC->GetBkColor();
				//pDC->SetBkColor( /*GetSysColor(COLOR_HIGHLIGHT)*/RGB(170,155,119) );
				pDC->DrawText( name, rc_item, DT_LEFT );
				pDC->SetTextColor( color );
				pDC->SetBkColor( col );
			}
			else
			{
				pDC->SetTextColor( GetSysColor(COLOR_HIGHLIGHTTEXT) );
				pDC->DrawText( name, rc_item, DT_LEFT );
				pDC->SetTextColor( color );
			}
			//if ( state & TVIS_BOLD )
			//	pDC->SelectObject( font );
		}
	} while ( (show_item = GetNextVisibleItem( show_item )) != NULL );
}
Example #25
0
void CInspectorTreeCtrl::drawValues(CPaintDC & dc)
{
    CRect rect;
    GetWindowRect(rect);

    dc.SetViewportOrg(0, 0);
    dc.SelectObject(linePen);
    dc.SetBkMode(TRANSPARENT);
    dc.SelectObject(GetFont());
    dc.SetTextColor(color_windowtext);  

    DRAWLINE(0, 0, rect.right, 0);

    int cWid0 = getColumnWidth(0);
    int cWid1 = getColumnWidth(1);

    int height = 0;
    HTREEITEM hItemFocus = GetSelectedItem();
    HTREEITEM hItem = GetFirstVisibleItem();
    while(hItem && height < rect.Height())
    {
        CRect iRect;
        GetItemRect(hItem, &iRect, FALSE);

        DRAWLINE(0, iRect.bottom, rect.right, iRect.bottom);
        height += iRect.Height();

        CTreeListItem * itemData = GetTreeListItem(hItem);
        if(itemData)
        {
            iRect.left = cWid0 + 6;
            iRect.right = cWid0 + cWid1;
            
            if(hItem == hItemFocus)
            {
                CRect whitespaceRect;
                GetItemRect(hItem, &whitespaceRect, TRUE);

                if(whitespaceRect.right < cWid0)
                {
                    whitespaceRect.left = whitespaceRect.right;
                    whitespaceRect.right = cWid0;
                
                    CWnd * focusWnd = GetFocus();
                    if(focusWnd && (focusWnd->m_hWnd == m_hWnd))        // I have focus             
                        dc.FillRect(whitespaceRect, &whitespaceHighlightBrush_Focused);                 
                    else                
                        dc.FillRect(whitespaceRect, &whitespaceHighlightBrush_Unfocused);                                   
                }               
                CString xpath;
                getTypeText(itemData->getType(), xpath, true);
                if(getFullXPath(hItem, xpath)) 
                {
                    CRect itemRect, r;
                    GetItemRect(hItem, &itemRect, FALSE);
                    r.UnionRect(&itemRect, &whitespaceRect);
                    tooltipCtrl->DelTool(this, TREE_TOOLTIP_ID);
                    tooltipCtrl->AddTool(this, xpath, r, TREE_TOOLTIP_ID);
                }
            }
            dc.DrawText(itemData->getValue(), &iRect, DT_SINGLELINE | DT_LEFT);
        }
        hItem = GetNextVisibleItem(hItem);      
    }
    DRAWLINE(cWid0, 0, cWid0, height);
}
Example #26
0
void duTreeCtrl::DrawObject(HDC hDC)
{
	duRect rcTreeCtrl;
	Plugin_GetRect(this, &rcTreeCtrl);
	rcTreeCtrl.OffsetRect(-rcTreeCtrl.left, -rcTreeCtrl.top);

	BITMAPINFO bmInfo;
	BYTE *pBits;

	HDC hMemDC = ::CreateCompatibleDC(hDC);
	InitBitmapInfo(&bmInfo, rcTreeCtrl.Width(), rcTreeCtrl.Height());
	HBITMAP hBmp = ::CreateDIBSection(hDC, &bmInfo, DIB_RGB_COLORS,(void**)&pBits, 0, 0);
	HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemDC, hBmp);

	BLENDFUNCTION bf = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
	::AlphaBlend(hMemDC, 0, 0, rcTreeCtrl.Width(), rcTreeCtrl.Height(), hDC, 0, 0, rcTreeCtrl.Width(), rcTreeCtrl.Height(), bf);


	duStyleGroup *pStyleGroup = (duStyleGroup *)GetResObj(GetStyle(), DU_RES_STYLEGROUP);
	if (pStyleGroup)
		pStyleGroup->Draw(hMemDC, &rcTreeCtrl, GetState(), NULL, GetAlpha());
	
	int nOffsetY = 0;
	TreeCtrlItem *pFirstVisible = GetFirstVisibleItem(nOffsetY);
	if (pFirstVisible == NULL || pFirstVisible == m_pRoot)
		return;
		
	duRect rcClient = _GetClientRect();
	
	POINT ptView = GetViewPoint();
	duFont *pFont = (duFont *)GetResObj(m_szFont, DU_RES_FONT);
	
	duSize sizeView;
	GetViewSize(&sizeView);
	
	int nDrawHeight = -nOffsetY;
	TreeCtrlItem *pItem = pFirstVisible;
	while (pItem)
	{
		duRect rcItem;
		
		rcItem.left   = -ptView.x;
		rcItem.right  = rcClient.right;
		rcItem.top    = nDrawHeight;
		rcItem.bottom = rcItem.top + m_nItemHeight;

		UINT uItemState = DU_STATE_NORMAL;
		if (pItem == m_pHot)
			uItemState = DU_STATE_OVER;
		
		if (pItem == m_pSelect)
			uItemState = DU_STATE_PRESS;
		
		DrawByStyle(this, m_szItemStyle, hMemDC, &rcItem, uItemState, NULL, GetAlpha());

		// draw indent[-+]
		int nLeft = (pItem->nLevel - 1) * m_nIndentWidth;
		duRect rcIndent = CalcVCenterRect(rcItem, nLeft, m_nIndentWidth, m_nIndentHeight);
		if (ItemHasChildren(pItem))
		{
			UINT nIndentState = pItem->fExpand ? DU_STATE_NORMAL : DU_STATE_CHECKED;
			DrawByStyle(this, m_szIndentStyle, hMemDC, &rcIndent, nIndentState, NULL, GetAlpha());
		}

		// draw icon
		nLeft += (m_nIndentWidth + m_nIndentIconSpace);
		duRect rcIcon = CalcVCenterRect(rcItem, nLeft, m_nIconWidth, m_nIconHeight);
		duImage *pIcon = (duImage *)GetResObj(pItem->strImage.c_str(), DU_RES_IMAGE);
		if (pIcon)
			DrawNormal(hMemDC, rcIcon.left, rcIcon.top, rcIcon.Width(), rcIcon.Height(), pIcon, 0, 0, GetAlpha());

		// draw text
		duRect rcText;
		nLeft += (m_nIconWidth + m_nIconTextSpace);
		rcText = rcItem;
		rcText.left = rcItem.left + nLeft;
		if (pItem->strText.length() > 0)
			DrawText32Bpp(hMemDC, pFont, m_clrText, pItem->strText.c_str(), pItem->strText.length(), &rcText, DT_LEFT|DT_VCENTER|DT_SINGLELINE, GetAlpha());

		if (nDrawHeight - nOffsetY > rcTreeCtrl.Height())
			break;

		nDrawHeight += m_nItemHeight;
		pItem = GetNextVisibleItem(pItem);
	}

	::AlphaBlend(hDC, 0, 0, rcTreeCtrl.Width(), rcTreeCtrl.Height(), hMemDC, 0, 0, rcTreeCtrl.Width(), rcTreeCtrl.Height(), bf);

	::SelectObject(hMemDC, hOldBitmap);
	::DeleteObject(hBmp);
	::DeleteDC(hMemDC);
}
Example #27
0
// the timer event for expanding nodes in drag n drop procedure
void CNZProjectTreeCtrl::OnTimer(UINT nIDEvent) 
{
	if( nIDEvent == m_nExpandTimer )
	{
		HTREEITEM htiFloat = GetDropHilightItem();
		if( htiFloat && htiFloat == m_htiDrop )
		{
			if( ItemHasChildren( htiFloat ) )
				Expand( htiFloat, TVE_EXPAND );
		}
	}
	else if( nIDEvent == m_nScrollTimer )
	{
		// Doesn't matter that we didn't initialize m_timerticks
		m_timerticks++;

		POINT pt;
		GetCursorPos( &pt );
		RECT rect;
		GetClientRect( &rect );
		ClientToScreen( &rect );

		// NOTE: Screen coordinate is being used because the call
		// to DragEnter had used the Desktop window.
		//CImageList::DragMove(pt);

		HTREEITEM hitem = GetFirstVisibleItem();

		if( pt.y < rect.top + 10 ) // scroll up
		{
			// Scroll slowly if cursor near the treeview control
			int slowscroll = 6 - (rect.top + 10 - pt.y) / 20;
			if( 0 == ( m_timerticks % (slowscroll > 0? slowscroll : 1) ) )
			{
				CImageList::DragShowNolock(FALSE);
				SendMessage( WM_VSCROLL, SB_LINEUP);
				SelectDropTarget(hitem);
				m_htiDrop = hitem;
				CImageList::DragShowNolock(TRUE);
			}
		}
		else if( pt.y > rect.bottom - 10 ) // scroll down
		{
			// Scroll slowly if cursor near the treeview control
			int slowscroll = 6 - (pt.y - rect.bottom + 10 ) / 20;
			if( 0 == ( m_timerticks % (slowscroll > 0? slowscroll : 1) ) )
			{
				CImageList::DragShowNolock(FALSE);
				SendMessage( WM_VSCROLL, SB_LINEDOWN);
				int nCount = GetVisibleCount();
				for ( int i=0; i<nCount-1; ++i )
					hitem = GetNextVisibleItem(hitem);
				if( hitem )
					SelectDropTarget(hitem);
				m_htiDrop = hitem;
				CImageList::DragShowNolock(TRUE);
			}
		}
	}

	CTreeCtrl::OnTimer(nIDEvent);
}
VOID CEasySkinTreeCtrl::DrawTreeItem( CDC * pDC, CRect & rcClient, CRect & rcClipBox )
{
	//首项判断
	HTREEITEM hItemCurrent=GetFirstVisibleItem();
	if (hItemCurrent==NULL) return;

	//获取属性
	UINT uTreeStyte = GetStyle();

	//绘画子项
	do
	{
		//变量定义
		CRect rcItem;
		CRect rcRect;

		//获取状态
		HTREEITEM hParent=GetParentItem(hItemCurrent);
		UINT uItemState=GetItemState(hItemCurrent,TVIF_STATE);

		//获取属性
		bool bDrawChildren=(ItemHasChildren(hItemCurrent)==TRUE);
		bool bDrawSelected=(uItemState&TVIS_SELECTED)&&((this==GetFocus())||(uTreeStyte&TVS_SHOWSELALWAYS));

		//获取区域
		if (GetItemRect(hItemCurrent,rcItem,TRUE))
		{
			//绘画过滤
			if (rcItem.top>=rcClient.bottom) break;
			if (rcItem.top>=rcClipBox.bottom) continue;

			//设置位置
			rcRect.left=0;
			rcRect.top=rcItem.top+1;
			rcRect.bottom=rcItem.bottom;
			rcRect.right=rcClient.Width();

			//绘画选择
			if (bDrawSelected)
			{
				if (m_pPressImg != NULL && !m_pPressImg->IsNull())
					m_pPressImg->Draw(pDC,rcRect);
				else
					pDC->FillSolidRect(&rcRect,m_colPress);
			}

			//绘画经过
 			if ((bDrawSelected==false)&&(m_hItemMouseHover==hItemCurrent))
 			{
				if (m_pHovenImg != NULL && !m_pHovenImg->IsNull())
					m_pHovenImg->Draw(pDC,rcRect);
				else
 					pDC->FillSolidRect(&rcRect,m_colHoven);
 			}

			//绘制箭头
 			if (bDrawChildren && (uTreeStyte&TVS_HASBUTTONS) )
 			{
				if (m_pImageButton != NULL && !m_pImageButton->IsNull())
				{
					//计算位置
					INT nXPos=rcItem.left-m_pImageButton->GetWidth()/2;
					INT nYPos=rcItem.top+1+(rcItem.Height()-m_pImageButton->GetHeight())/2;

					//绘画图标
					INT nIndex=(uItemState&TVIS_EXPANDED)?1L:0L;
					m_pImageButton->DrawImage(pDC,nXPos,nYPos,m_pImageButton->GetWidth()/2,m_pImageButton->GetHeight(),nIndex*m_pImageButton->GetWidth()/2,0);
				
					rcItem.left += m_pImageButton->GetWidth();
					rcItem.right += m_pImageButton->GetWidth();;
				}

 			}

			//绘制列表
			DrawListImage(pDC,rcItem,hItemCurrent,bDrawSelected);	

			//绘制文本
			DrawItemString(pDC,rcItem,hItemCurrent,bDrawSelected);
		}
	} while ((hItemCurrent=GetNextVisibleItem(hItemCurrent))!= NULL);
}
Example #29
0
void CMyTreeCtrl::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	// Create a memory DC compatible with the paint DC
	CDC memDC;
	memDC.CreateCompatibleDC( &dc );
	
	CRect rcClip, rcClient;
	dc.GetClipBox( &rcClip );
	GetClientRect(&rcClient);

	// Select a compatible bitmap into the memory DC
	CBitmap bitmap;
	bitmap.CreateCompatibleBitmap( &dc, rcClient.Width(), rcClient.Height() );
	CBitmap *pOldBitmap=memDC.SelectObject( &bitmap );

	// Set clip region to be same as that in paint DC
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcClip );
	memDC.SelectClipRgn(&rgn);
	rgn.DeleteObject();

	// First let the control do its default drawing.
	CWnd::DefWindowProc( WM_PAINT, (WPARAM)memDC.m_hDC, 0 );

	HTREEITEM hItem = GetFirstVisibleItem();
	
	int n = GetVisibleCount()+1;
	while( hItem && n--)
	{
		CRect rect;

		// Do not meddle with selected items or drop highlighted items
		UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
		
		Color_Font cf;	
		if ( !(GetItemState( hItem, selflag ) & selflag ) && m_mapColorFont.Lookup( hItem, cf ))
		{
			CFont *pFontDC;
			CFont fontDC;

			LOGFONT logfont;
			
			if( cf.logfont.lfFaceName[0] != '\0' )
			{
				logfont = cf.logfont;
			}
			else
			{
				// No font specified, so use window font
				CFont *pFont = GetFont();
				pFont->GetLogFont( &logfont );
			}
			
			if( GetItemBold( hItem ) )
			{
				logfont.lfWeight = 700;
			}

			fontDC.CreateFontIndirect( &logfont );
			pFontDC = memDC.SelectObject( &fontDC );
			
			if( cf.color != (COLORREF)-1 )
			{
				memDC.SetTextColor( cf.color );
			}
			
			CString sItem = GetItemText( hItem );
			GetItemRect( hItem, &rect, TRUE );
			memDC.SetBkColor( GetSysColor( COLOR_WINDOW ) );
			memDC.TextOut( rect.left+2, rect.top+1, sItem );			

			memDC.SelectObject( pFontDC );
		}	
		hItem = GetNextVisibleItem( hItem );
	}

	dc.BitBlt( rcClip.left, rcClip.top, rcClip.Width(), rcClip.Height(), &memDC,
			   rcClip.left, rcClip.top, SRCCOPY );

	memDC.SelectObject(pOldBitmap);
	bitmap.DeleteObject();
}
//绘画子项
VOID CServerItemView::DrawTreeItem(CDC * pDC, CRect & rcClient, CRect & rcClipBox)
{
	//首项判断
	HTREEITEM hItemCurrent=GetFirstVisibleItem();
	if (hItemCurrent==NULL) return;

	//获取属性
	UINT uTreeStyte=GetWindowLong(m_hWnd,GWL_STYLE);

	////获取对象
	//ASSERT(CSkinRenderManager::GetInstance()!=NULL);
	//CSkinRenderManager * pSkinRenderManager=CSkinRenderManager::GetInstance();

	//绘画子项
	do
	{
		//变量定义
		CRect rcItem;
		CRect rcRect;

		//获取状态
		HTREEITEM hParent=GetParentItem(hItemCurrent);
		UINT uItemState=GetItemState(hItemCurrent,TVIF_STATE);

		//获取属性
		bool bDrawChildren=(ItemHasChildren(hItemCurrent)==TRUE);
		bool bDrawSelected=(uItemState&TVIS_SELECTED)&&((this==GetFocus())||(uTreeStyte&TVS_SHOWSELALWAYS));

		//获取区域
		if (GetItemRect(hItemCurrent,rcItem,TRUE))
		{
			//绘画过滤
			if (rcItem.top>=rcClient.bottom)
				break;
			if (rcItem.top>=rcClipBox.bottom)
				continue;

			//设置位置
			rcRect.left=0;
			rcRect.top=rcItem.top+1;
			rcRect.bottom=rcItem.bottom;
			rcRect.right=rcClient.Width();

			//绘画选择
			if (bDrawSelected==true)
			{
				pDC->FillSolidRect(&rcRect,RGB(253,231,161));
			}

			//绘画经过
			if ((bDrawSelected==false)&&(m_hItemMouseHover==hItemCurrent))
			{
				pDC->FillSolidRect(&rcRect,RGB(157,182,249));
			}

			//绘制箭头
			if (bDrawChildren==true)
			{
				//计算位置
				INT nXPos=rcItem.left-m_ImageArrow.GetWidth()/2-25;
				INT nYPos=rcItem.top+1+(rcItem.Height()-m_ImageArrow.GetHeight())/2;

				//绘画图标
				INT nIndex=(uItemState&TVIS_EXPANDED)?1L:0L;
				m_ImageArrow.DrawImage(pDC,nXPos,nYPos,m_ImageArrow.GetWidth()/2,m_ImageArrow.GetHeight(),nIndex*m_ImageArrow.GetWidth()/2,0);
			}

			//绘制列表
			DrawListImage(pDC,rcItem,hItemCurrent);	

			rcItem.right+=20;
			//绘制文本
			DrawItemString(pDC,rcItem,hItemCurrent,bDrawSelected);
		}
	} while ((hItemCurrent=GetNextVisibleItem(hItemCurrent))!= NULL);

	return;
}