//-----------------------------------------------------------------------------
// 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);
    }
    }
}
/*
 * Paint the row lines.
 */
void CScrolledTreeCtrl::OnPaint(wxPaintEvent& event)
{
    wxPaintDC dc(this);

    wxTreeCtrl::OnPaint(event);

    if (! m_drawRowLines)
        return;

    // Reset the device origin since it may have been set
    dc.SetDeviceOrigin(0, 0);

    wxPen pen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DLIGHT), 1, wxSOLID);
    dc.SetPen(pen);
    dc.SetBrush(* wxTRANSPARENT_BRUSH);

    wxSize clientSize = GetClientSize();
    wxRect itemRect;
    int cy=0;
    wxTreeItemId h, lastH;
    for(h = GetFirstVisibleItem(); h.IsOk(); h = GetNextVisible(h)) {
        if (GetBoundingRect(h, itemRect)) {
            cy = itemRect.GetTop();
            dc.DrawLine(0, cy, clientSize.x, cy);
            lastH = h;
        }
        if (!IsVisible(h)) {
            break;
        }
    }
    if (lastH.IsOk() && GetBoundingRect(lastH, itemRect)) {
        cy = itemRect.GetBottom();
        dc.DrawLine(0, cy, clientSize.x, cy);
    }
}
void CDirectoryTreeCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	UINT uFlags;
	HTREEITEM hItem = HitTest(point, &uFlags);
	HTREEITEM tItem = GetFirstVisibleItem();

	if((hItem) && (uFlags & TVHT_ONITEMSTATEICON))
	{
		CheckChanged(hItem, !GetCheck(hItem));

		if(nFlags & MK_CONTROL)
		{
			Expand(hItem, TVE_TOGGLE);
			HTREEITEM hChild;
			hChild = GetChildItem(hItem);
			while (hChild != NULL)
			{
				MarkChilds(hChild,!GetCheck(hItem));
				hChild = GetNextSiblingItem(hChild);
			}
			Expand(hItem, TVE_TOGGLE);
		}
	}
	SelectSetFirstVisible(tItem);
	CTreeCtrl::OnLButtonDown(nFlags, point);
}
Example #4
0
	    void OnPaint(wxPaintEvent& event)
        {
	        wxPaintDC dc(this);

	        wxTreeCtrl::OnPaint(event);

            // Reset the device origin since it may have been set
            dc.SetDeviceOrigin(0, 0);

	        wxPen pen(wxColour(_T("BLACK")), 1, wxSOLID);
	        dc.SetPen(pen);
            
	        dc.SetBrush(* wxTRANSPARENT_BRUSH);

            wxSize clientSize = GetClientSize();
	        wxRect itemRect;
	        int cy=0;
	        wxTreeItemId h, lastH;
	        for(h=GetFirstVisibleItem();h;h=GetNextVisible(h))
	        {
		        if (h.IsOk() && GetBoundingRect(h, itemRect))
		        {
			        cy = itemRect.GetTop();
			        dc.DrawLine(0, cy, clientSize.x, cy);
			        lastH = h;
		        }
	        }
	        if (lastH.IsOk() && GetBoundingRect(lastH, itemRect))
	        {
		        cy = itemRect.GetBottom();
		        dc.DrawLine(0, cy, clientSize.x, cy);
	        }
        }
Example #5
0
wxTreeItemId wxTreeCtrlEx::GetBottomItem() const
{
	wxTreeItemId cur = GetFirstVisibleItem();
	if (cur) {
		wxTreeItemId next;
		while ((next = GetNextVisible(cur)).IsOk()) {
			cur = next;
		}
	}
	return cur;
}
Example #6
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 #7
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 #8
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 );
}
void CDirectoryTreeCtrl::OnTvnKeydown(NMHDR *pNMHDR, LRESULT *pResult)
{ 
	LPNMTVKEYDOWN pTVKeyDown = reinterpret_cast<LPNMTVKEYDOWN>(pNMHDR);

	switch(pTVKeyDown->wVKey)
	{
		case VK_SPACE:
		case VK_RETURN:
		{
			HTREEITEM hItem = GetSelectedItem();

			if(hItem)
			{		
				HTREEITEM tItem = GetFirstVisibleItem();

				CheckChanged(hItem, !GetCheck(hItem));
								
				if(m_bCtrlPressed)
				{
					Expand(hItem, TVE_TOGGLE);
					HTREEITEM hChild;
					hChild = GetChildItem(hItem);

					while(hChild != NULL)
					{ 
						MarkChilds(hChild,!GetCheck(hItem));
						hChild = GetNextSiblingItem( hChild );
					}

					SetCheck(hItem, !GetCheck(hItem));
					Expand(hItem, TVE_TOGGLE);
				}
		 
				SelectSetFirstVisible(tItem);
			}

			break;
		}

		default:
			break;
	}

	*pResult = 0;
}
Example #10
0
wxSize AutoResizingTreeCtrl::DoGetBestSize() const
{
    AutoResizingTreeCtrl& myself = const_cast<AutoResizingTreeCtrl&>(*this);
    wxWindowUpdateLocker update_locker(&myself);

    wxSize best_size(0, 0);

    wxTreeItemId const selection = GetSelection();
    wxTreeItemId const first_visible = GetFirstVisibleItem();

    wxTreeItemId const root = GetRootItem();
    myself.DoGetBestSizePrivate(best_size, root, true);

    // need some minimal size even for an empty tree
    if(best_size.x == 0 || best_size.y == 0)
        {
        wxSize min_size = wxTreeCtrl::DoGetBestSize();

        if(best_size.x == 0)
            {
            best_size.x = min_size.x;
            }
        if(best_size.y == 0)
            {
            best_size.y = min_size.y;
            }
        }
    best_size += GetSize() - GetClientSize();

    if(selection.IsOk())
        {
        myself.SelectItem(selection);
        }
    if(first_visible.IsOk())
        {
        myself.ScrollTo(first_visible);
        }

    CacheBestSize(best_size);

    return best_size;
}
Example #11
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;
}
void CDirectoryTreeCtrl::ShareSubDirTree(HTREEITEM hItem, BOOL bRecurse)
{
	CWaitCursor curWait;
	SetRedraw(FALSE);

	HTREEITEM hItemVisibleItem = GetFirstVisibleItem();
	CheckChanged(hItem, !GetCheck(hItem));
	if (bRecurse)
	{
		Expand(hItem, TVE_TOGGLE);
		HTREEITEM hChild = GetChildItem(hItem);
		while (hChild != NULL)
		{
			MarkChilds(hChild, !GetCheck(hItem));
			hChild = GetNextSiblingItem(hChild);
		}
		Expand(hItem, TVE_TOGGLE);
	}
	if (hItemVisibleItem)
		SelectSetFirstVisible(hItemVisibleItem);

	SetRedraw(TRUE);
	Invalidate();
}
Example #13
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 #14
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);
}
//绘画子项
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;
}
Example #16
0
void KGTreeCtrl::OnTimer(UINT nIDEvent)
{
	if (nIDEvent == m_nHoverTimerID)
	{
		KillTimer(m_nHoverTimerID);
		m_nHoverTimerID = 0;
		HTREEITEM  trItem = 0;
		UINT  uFlag = 0;
		trItem = HitTest(m_HoverPoint, &uFlag);
		if (trItem && m_bDragging)
		{
			//SelectItem(trItem);
			Expand(trItem, TVE_EXPAND);
			Invalidate();

			CRect rect;
			GetItemRect(trItem, &rect, true);
			rect.left -= 35;
			m_curPointLeft.x = rect.left;
			m_curPointLeft.y = rect.bottom;
			m_curPointRigh.x = rect.right;
			m_curPointRigh.y = rect.bottom;
		}
	}
	else if(nIDEvent == m_nScrollTimerID)
	{
		m_TimerTicks++;
		CPoint  pt;
		GetCursorPos(&pt);
		CRect  rect;
		GetClientRect(&rect);
		ClientToScreen(&rect);

		HTREEITEM  hItem = GetFirstVisibleItem();

		if ( pt.y < rect.top +10)
		{
			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_hItemDragD = hItem;
				CImageList::DragShowNolock ( true );
			}
		}
		else if( pt.y > rect.bottom - 10 )
		{
			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_hItemDragD = hItem;
				CImageList::DragShowNolock ( true );
			}
		}
	}
	else if (nIDEvent == m_nDrawLineTimerID)
	{
		CClientDC dc(this);

		CPen penP(PS_SOLID, 2, GetBkColor());
		dc.SelectObject(&penP);
		dc.MoveTo(m_pointLeft);
		dc.LineTo(m_pointRigh);
		dc.MoveTo(m_pointLeft.x, m_pointLeft.y - 5);
		dc.LineTo(m_pointLeft.x, m_pointLeft.y + 5);

		CPen penN(PS_SOLID, 2, RGB(122, 178, 255));
		dc.SelectObject(&penN);
		dc.MoveTo(m_curPointLeft);
		dc.LineTo(m_curPointRigh);
		dc.MoveTo(m_curPointLeft.x, m_curPointLeft.y - 5);
		dc.LineTo(m_curPointLeft.x, m_curPointLeft.y + 5);

		m_pointLeft.x = m_curPointLeft.x;
		m_pointLeft.y = m_curPointLeft.y;
		m_pointRigh.x = m_curPointRigh.x;
		m_pointRigh.y = m_curPointRigh.y;
	}
	else
		CTreeCtrl::OnTimer(nIDEvent);
}
Example #17
0
void CTreeFileCtrl::OnTimer(UINT nIDEvent) 
{
	if (nIDEvent != m_nTimerID)
  {
	  CTreeCtrl::OnTimer(nIDEvent);
    return;
  }

  //Show the dragging effect
  POINT pt;
  GetCursorPos(&pt);
  RECT rect;
  GetClientRect(&rect);
  ClientToScreen(&rect);
  CImageList::DragMove(pt);

  HTREEITEM hFirstItem = GetFirstVisibleItem();
  CRect ItemRect;
  GetItemRect(hFirstItem, &ItemRect, FALSE);
  if (pt.y < (rect.top + (ItemRect.Height()*2)) && pt.y > rect.top)
  {
    //we need to scroll up
    CImageList::DragShowNolock(FALSE);
    SendMessage(WM_VSCROLL, SB_LINEUP);
    EnsureVisible(hFirstItem);
    SelectDropTarget(hFirstItem);
    m_hItemDrop = hFirstItem;
    CImageList::DragShowNolock(TRUE);
  }
  else if (pt.y > (rect.bottom - (ItemRect.Height()*2)) && pt.y < rect.bottom)
  {
    //we need to scroll down
    CImageList::DragShowNolock(FALSE);
    SendMessage(WM_VSCROLL, SB_LINEDOWN);
    HTREEITEM hLastItem = hFirstItem;
    int nCount = GetVisibleCount();
    for (int i=0; i<(nCount-1); i++)
      hLastItem = GetNextVisibleItem(hLastItem);
    SelectDropTarget(hLastItem);
    EnsureVisible(hLastItem);
    m_hItemDrop = hLastItem;
    CImageList::DragShowNolock(TRUE);
  }

  //Expand the item if the timer ticks has expired
  if (m_TimerTicks == 3)
  {
    m_TimerTicks = 0;
    Expand(m_hItemDrop, TVE_EXPAND);
  }

  //Expand the selected item if it is collapsed and
  //the timeout has occurred
  TV_ITEM tvItem;
  tvItem.hItem = m_hItemDrop;
  tvItem.mask = TVIF_HANDLE | TVIF_CHILDREN | TVIF_STATE;
  tvItem.stateMask = TVIS_EXPANDED;
  GetItem(&tvItem);
  if (tvItem.cChildren && ((tvItem.state & TVIS_EXPANDED) == 0))
  {
    m_TimerTicks++;
  }
}
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);
}
void CImageTreeCtrl::OnPaint()
{
	//获取当前绘制对象的DC
	CPaintDC dc(this);

	// 使用将要绘制的对象的DC创建一个memory DC
	//memory device context的概念:是在内存中创建一个结构来反映一个显示(屏幕区域、窗口、
	//打印机等)的表面。可以用来先在内存中准备好要显示的图像,从而实现双缓存,提高刷新
	//速度减少刷新时产生的闪烁。
	CDC memDC;
	//从当前DC创建内存对象
	memDC.CreateCompatibleDC( &dc );

	//定义CRect对象,用来确定区域
	CRect rcClip, rcClient;
	//获取当前对象的边界区域
	dc.GetClipBox( &rcClip );
	//获取当前对象的用户区域
	GetClientRect(&rcClient);

	// Select a compatible bitmap into the memory DC
	//创建一个bmp文件,作为memDC的内容
	//该文件的大小与用于区域相同
	CBitmap bitmap;
	bitmap.CreateCompatibleBitmap( &dc, rcClient.Width(), rcClient.Height() );
	memDC.SelectObject( &bitmap );

	// Set clip region to be same as that in paint DC
	//通过对象的边界区域创建CRgn对象
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcClip );

	//rcClip.bottom = rcClip.bottom + 10;

	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
			{
				// 用户没有定义,使用系统字体
				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 );
			//rect.bottom = rect.bottom + 2;
			//设置背景色为系统色
			memDC.FillSolidRect(&rect,GetSysColor( COLOR_WINDOW ));//clr);

			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 );

}
Example #20
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 );
}
void CTreeListCtrl::OnPaint() 
{
   CPaintDC dc(this); // device context for painting

   CRect rcClip, rcClient;
   dc.GetClipBox( &rcClip );
   GetClientRect(&rcClient);

   // Set clip region to be same as that in paint DC
   CRgn rgn;
   rgn.CreateRectRgnIndirect( &rcClip );
   dc.SelectClipRgn(&rgn);
   rgn.DeleteObject();
   
   COLORREF m_wndColor = GetSysColor( COLOR_WINDOW );

   dc.SetViewportOrg(m_nOffset, 0);

   dc.SetTextColor(m_wndColor);

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

   HTREEITEM hItem = GetFirstVisibleItem();

   int n = GetVisibleCount(), m_nWidth;

   dc.FillSolidRect(GetColumnWidth(0),1,rcClient.Width(),rcClient.Height(),m_wndColor);

   CTreeListItem *pItem;

   // the most urgent thing is to erase the labels that were drawn by the tree
   while(hItem!=NULL && n>=0)
   {
      CRect rect;

      UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
   
      CRect m_labelRect;
      GetItemRect( hItem, &m_labelRect, TRUE );
      GetItemRect( hItem, &rect, FALSE );
      if (GetColumnsNum()>1)
         rect.left = min(m_labelRect.left, GetColumnWidth(0));
      else
         rect.left = m_labelRect.left;
      rect.right = m_nColumnsWidth;
      dc.FillSolidRect(rect.left,rect.top,rect.Width(),rect.Height(),m_wndColor);

      hItem = GetNextVisibleItem( hItem );
      n--;
   }

   // create the font
   CFont *pFontDC;
   CFont fontDC, boldFontDC;
   LOGFONT logfont;

   CFont *pFont = GetFont();
   pFont->GetLogFont( &logfont );

   fontDC.CreateFontIndirect( &logfont );
   pFontDC = dc.SelectObject( &fontDC );

   logfont.lfWeight = 700;
   boldFontDC.CreateFontIndirect( &logfont );

   // and now let's get to the painting itself

   hItem = GetFirstVisibleItem();
   n = GetVisibleCount();

   while (hItem != NULL && n >= 0)
   {
      CRect rect;

      UINT selflag = TVIS_DROPHILITED | TVIS_SELECTED;
   
      if ( !(GetItemState( hItem, selflag ) & selflag ))
      {
         dc.SetBkMode(TRANSPARENT);

         pItem = (CTreeListItem *)CTreeCtrl::GetItemData(hItem);
         CString sItem = ((pItem != NULL) ? pItem->GetItemText() : "");

         CRect m_labelRect;
         GetItemRect( hItem, &m_labelRect, TRUE );
         GetItemRect( hItem, &rect, FALSE );
         if (GetColumnsNum()>1)
            rect.left = min(m_labelRect.left, GetColumnWidth(0));
         else
            rect.left = m_labelRect.left;
         rect.right = m_nColumnsWidth;

         dc.SetBkColor( m_wndColor );

         if (pItem != NULL)
         {
            dc.SetTextColor( pItem->m_Color );

            if (pItem->m_Bold)
            {
               dc.SelectObject( &boldFontDC );
            }
         }

         int imageIndex;
         int selectedImageIndex;

         GetItemImage(hItem,imageIndex,selectedImageIndex);

         int imageOffset = 0;

         if (imageIndex >= 0)
         {
            m_imageList->Draw(&dc,imageIndex,rect.TopLeft(),ILD_TRANSPARENT);
            imageOffset = 16;
         }

         DrawItemText(&dc, sItem, CRect(rect.left+2+imageOffset, rect.top, GetColumnWidth(0)-imageOffset, rect.bottom),
            GetColumnWidth(0)-rect.left-2-imageOffset, GetColumnAlign(0));

         m_nWidth = 0;

         for (int i = 1;i < m_nColumns;i++)
         {
            CString subString = ((pItem != NULL) ? pItem->GetSubstring(*this,hItem,i) : "");

            m_nWidth += GetColumnWidth(i-1);
            DrawItemText(&dc,subString,CRect(m_nWidth, rect.top, m_nWidth+GetColumnWidth(i), rect.bottom), GetColumnWidth(i), GetColumnAlign(i));
         }
         
         dc.SetTextColor(::GetSysColor (COLOR_WINDOWTEXT ));

         if (pItem != NULL && pItem->m_Bold)
         {
            dc.SelectObject( &fontDC );
         }
      }
      else
      {
         CRect m_labelRect;
         GetItemRect( hItem, &m_labelRect, TRUE );
         GetItemRect( hItem, &rect, FALSE );

         if (GetColumnsNum() > 1)
            rect.left = min(m_labelRect.left, GetColumnWidth(0));
         else
            rect.left = m_labelRect.left;

         rect.right = m_nColumnsWidth;

         int imageIndex;
         int selectedImageIndex;

         GetItemImage(hItem,imageIndex,selectedImageIndex);

         int imageOffset = 0;

         if (selectedImageIndex >= 0)
         {
            m_imageList->Draw(&dc,selectedImageIndex,rect.TopLeft(),ILD_TRANSPARENT);
            imageOffset = 16;
         }

         // If the item is selected, paint the rectangle with the system color
         // COLOR_HIGHLIGHT

         COLORREF m_highlightColor = ::GetSysColor (COLOR_HIGHLIGHT);

         CBrush brush(m_highlightColor);
         CRect fillRect(rect);
         fillRect.left += imageOffset;
         dc.FillRect (fillRect, &brush);

         // draw a dotted focus rectangle

         dc.DrawFocusRect (rect);
         
         pItem = (CTreeListItem *)CTreeCtrl::GetItemData(hItem);
         CString sItem = ((pItem != NULL) ? pItem->GetItemText() : "");

         dc.SetBkColor(m_highlightColor);

         dc.SetTextColor(::GetSysColor (COLOR_HIGHLIGHTTEXT));

         if (pItem != NULL && pItem->m_Bold)
         {
            dc.SelectObject( &boldFontDC );
         }

         //DrawItemText(&dc, sItem, CRect(rect.left+2, rect.top, GetColumnWidth(0), rect.bottom), GetColumnWidth(0)-rect.left-2, GetColumnAlign(0));
         DrawItemText(&dc, sItem, CRect(rect.left+2+imageOffset, rect.top, GetColumnWidth(0)-imageOffset, rect.bottom),
            GetColumnWidth(0)-rect.left-2-imageOffset, GetColumnAlign(0));

         m_nWidth = 0;

         for (int i = 1;i < m_nColumns;i++)
         {
            CString subString = ((pItem != NULL) ? pItem->GetSubstring(*this,hItem,i) : "");

            m_nWidth += GetColumnWidth(i-1);
            DrawItemText(&dc,subString,CRect(m_nWidth, rect.top, m_nWidth+GetColumnWidth(i), rect.bottom), GetColumnWidth(i), GetColumnAlign(i));
         }

         if (pItem != NULL && pItem->m_Bold)
         {
            dc.SelectObject( &fontDC );
         }
      }

      hItem = GetNextVisibleItem( hItem );
      n--;
   }

   dc.SelectObject( pFontDC );
}
Example #22
0
void CMyTreeCtrl::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if (nIDEvent == 1000)
	{

	// Doesn't matter that we didn't initialize m_timerticks
		m_timerticks++;

		POINT pt;
		GetCursorPos( &pt );
		CRect 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();

  		int iMaxV = GetScrollLimit(SB_VERT);
 		int iPosV = GetScrollPos(SB_VERT);
		// The cursor must not only be SOMEWHERE above/beneath the tree control
		// BUT RIGHT above or beneath it 
		// i.e. the x-coordinates must be those of the control (+/- SCROLL_BORDER)
		if ( pt.x < rect.left - SCROLL_BORDER ) 
		  ; // Too much to the left
		else if ( pt.x > rect.right + SCROLL_BORDER ) 
		  ; // Too much to the right
		else if( (pt.y < rect.top + SCROLL_BORDER) && iPosV )
		{
			// We need to scroll up
			// Scroll slowly if cursor near the treeview control
			int slowscroll = 6 - (rect.top + SCROLL_BORDER - pt.y) / SCROLL_SPEED_ZONE_WIDTH;
			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 - SCROLL_BORDER) && (iPosV!=iMaxV) )
		{
			// We need to scroll down
			// Scroll slowly if cursor near the treeview control
			int slowscroll = 6 - (pt.y - rect.bottom + SCROLL_BORDER ) / SCROLL_SPEED_ZONE_WIDTH;
			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);
			}
		}

		// The cursor must be in a small zone IN the treecontrol at the left/right
		int iPosH = GetScrollPos(SB_HORZ);
		int iMaxH = GetScrollLimit(SB_HORZ);

		if ( !rect.PtInRect(pt) ) return; // not in TreeCtrl
		else if ( (pt.x < rect.left + SCROLL_BORDER) && (iPosH != 0) )
		{
			// We need to scroll to the left
			CImageList::DragShowNolock(FALSE);
			SendMessage(WM_HSCROLL, SB_LINELEFT);
			CImageList::DragShowNolock(TRUE);
		}
		else if ( (pt.x > rect.right - SCROLL_BORDER) && (iPosH != iMaxH) )
		{
			// We need to scroll to the right
			CImageList::DragShowNolock(FALSE);
			SendMessage(WM_HSCROLL, SB_LINERIGHT);
			CImageList::DragShowNolock(TRUE);
		}

	}
//	CDialog::OnTimer(nIDEvent);
}
Example #23
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 #24
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 CDragDropTreeCtrl::OnTimer(UINT_PTR nIDEvent)
{
    CTreeCtrl::OnTimer(nIDEvent);

    // Reset the timer.
    SetTimer(1, m_nScrollInterval, NULL);

    // Get the current cursor position and window height.
    DWORD dwPos = ::GetMessagePos();
    CPoint point(LOWORD(dwPos), HIWORD(dwPos));
    ScreenToClient(&point);

    CRect rect;
    GetClientRect(rect);
    int cy = rect.Height();

    // Scroll the window if the cursor is near the top or bottom.
    if (point.y >= 0 && point.y <= m_nScrollMargin)
    {
        HTREEITEM hFirstVisible = GetFirstVisibleItem();
        m_pImageList->DragShowNolock(FALSE);
        SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEUP, 0), NULL);
        m_pImageList->DragShowNolock(TRUE);

        // Kill the timer if the window did not scroll, or redraw the
        // drop target highlight if the window did scroll.
        if (GetFirstVisibleItem() == hFirstVisible)
            KillTimer(1);
        else
        {
            HighlightDropTarget(point);
            return;
        }
    }
    else if (point.y >= cy - m_nScrollMargin && point.y <= cy)
    {
        HTREEITEM hFirstVisible = GetFirstVisibleItem();
        m_pImageList->DragShowNolock(FALSE);
        SendMessage(WM_VSCROLL, MAKEWPARAM(SB_LINEDOWN, 0), NULL);
        m_pImageList->DragShowNolock(TRUE);

        // Kill the timer if the window did not scroll, or redraw the
        // drop target highlight if the window did scroll.
        if (GetFirstVisibleItem() == hFirstVisible)
            KillTimer(1);
        else
        {
            HighlightDropTarget(point);
            return;
        }
    }

    // If the cursor is hovering over a collapsed item, expand the tree.
    UINT nFlags;
    HTREEITEM hItem = HitTest(point, &nFlags);

    if (hItem != NULL && ItemHasChildren(hItem) && !IsItemExpanded(hItem))
    {
        m_pImageList->DragShowNolock(FALSE);
        Expand(hItem, TVE_EXPAND);
        m_pImageList->DragShowNolock(TRUE);
        KillTimer(1);
        return;
    }
}
Example #26
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();
}
Example #27
0
void CColorTree::OnPaint()
{
	CTreeCtrl::OnPaint();
	CPaintDC dc(this); // device context for painting
	HTREEITEM hItem;
	CImageList *List;
			List = GetImageList(0);

	
	hItem = GetFirstVisibleItem();
	CRect rec, recText;

	 CBrush brush0(m_colRow1);
	CBrush brush1(m_colRow2);

	int i;
	i = 0;
	CDC * pDC;
	pDC = GetDC();
	CFont Font;
	Font.CreateFontW(15,0,0,0,FW_NORMAL, FALSE, FALSE,FALSE,RUSSIAN_CHARSET,OUT_DEFAULT_PRECIS,CLIP_DEFAULT_PRECIS,ANTIALIASED_QUALITY,FF_MODERN|DEFAULT_PITCH,_T("TestFont"));
	pDC->SelectObject(Font);
	while(hItem!=NULL)
	{
		GetItemRect(hItem,rec,FALSE);
		GetItemRect(hItem,recText,TRUE);
		//
		if(i % 2 == 0)
			{
				pDC->FillRect(rec,&brush0);
				pDC->SetBkColor(m_colRow1);
			}
		else
			{
				pDC->SetBkColor(m_colRow2);
				pDC->FillRect(rec,&brush1);
			}
		CString sName;
		sName = GetItemText(hItem);
		if(sName.Find(_T("\n"))>-1)
		{
			sName =  sName.Left(sName.Find(_T("\n")));
		}
		if(sName.Find(_T("\t"))>-1)
			{
				CString sVal;
				sVal = sName.Left(sName.Find(_T("\t")));
				pDC->TextOutW(recText.left-20 ,rec.top,sVal,sVal.GetLength());
				
				sVal = sName.Right(sName.GetLength()-1-sVal.GetLength());
				pDC->TextOutW(rec.left + (rec.right - rec.left)/2,rec.top,sVal,sVal.GetLength());
			}
		else
			pDC->TextOutW(recText.left - 20,rec.top,sName,sName.GetLength());


		if(GetItemState(hItem, TVIS_EXPANDED)& TVIS_EXPANDED)
		{
			if(List!=NULL)
			{
				CPoint xy; 		
				xy =  recText.TopLeft();
				xy.x = xy.x - 40;
				List->Draw(pDC,1,xy,ILD_NORMAL);
			}
		}
		else
		{
			if(List!=NULL)
			{
				CPoint xy; 		
				xy =  recText.TopLeft();
				xy.x = xy.x - 40;
				if(GetChildItem(hItem)!=NULL)
					List->Draw(pDC,0, xy,ILD_NORMAL);
				else
					List->Draw(pDC,2, xy,ILD_NORMAL);
			}
		}

		hItem = GetNextVisibleItem(hItem);
		i++;
	}
}