int ZMeshViewList::GetItemWidth(void)
{
    int nVisibleCount = GetVisibleCount();
    if(nVisibleCount==0) nVisibleCount = 1;

    return GetItemVisibleWidth()/nVisibleCount;
}
void ZMeshViewList::RecalcBounds(void)
{
    MRECT r = GetClientRect();

    //m_pLeft->SetBounds(r.x, r.y, LEFTRIGHT_WIDTH, r.h);
    //m_pRight->SetBounds(r.x+r.w-LEFTRIGHT_WIDTH, r.y, LEFTRIGHT_WIDTH, r.h);
    m_pBmLeft->SetBounds(r.x, r.y, LEFTRIGHT_WIDTH, r.h);
    m_pBmRight->SetBounds(r.x+r.w-LEFTRIGHT_WIDTH, r.y, LEFTRIGHT_WIDTH, r.h);

    int nVisibleCount = GetVisibleCount();
    int nItemWidth = GetItemWidth();
    int nItemCount = GetItemCount();
    if(m_nItemStartIndex+nVisibleCount>nItemCount) {
        m_nItemStartIndex = nItemCount - nVisibleCount;
        if(m_nItemStartIndex<0) m_nItemStartIndex = 0;
    }

    int nCount = GetItemCount();

    if(m_nItemStartIndex>0) m_pBmLeft->Enable(true);
    else m_pBmLeft->Enable(false);
    //if(m_nItemStartIndex+nVisibleCount<nCount) m_pRight->Enable(true);
    //else m_pRight->Enable(false);
    if(m_nItemStartIndex+nVisibleCount<nCount) m_pBmRight->Enable(true);
    else m_pBmRight->Enable(false);

    for(int i=0; i<nCount; i++) {
        MWidget* pChild = GetItem(i);
        pChild->SetBounds(r.x+LEFTRIGHT_WIDTH+(i-m_nItemStartIndex)*nItemWidth, r.y, nItemWidth, r.h);
        if(i-m_nItemStartIndex<0 || i-m_nItemStartIndex>=nVisibleCount) pChild->Show(false);
        else pChild->Show(true);
    }
}
bool ZMeshViewList::OnCommand(MWidget* pWidget, const char* szMessage)
{
    //if(pWidget==m_pLeft && strcmp(szMessage, MBTN_CLK_MSG)==0){
    //	if(m_nItemStartIndex>0){
    //		m_nItemStartIndex--;
    //		RecalcBounds();
    //	}
    //	return true;
    //}
    //else if(pWidget==m_pRight && strcmp(szMessage, MBTN_CLK_MSG)==0){
    //	if(m_nItemStartIndex+GetVisibleCount()<GetItemCount()){
    //		m_nItemStartIndex++;
    //		RecalcBounds();
    //	}
    //	return true;
    //}
    if(pWidget==m_pBmLeft && strcmp(szMessage, MBTN_CLK_MSG)==0) {
        if(m_nItemStartIndex>0) {
            m_nItemStartIndex--;
            RecalcBounds();
        }
        return true;
    }
    else if(pWidget==m_pBmRight && strcmp(szMessage, MBTN_CLK_MSG)==0) {
        if(m_nItemStartIndex+GetVisibleCount()<GetItemCount()) {
            m_nItemStartIndex++;
            RecalcBounds();
        }
        return true;
    }
    return false;
}
//-----------------------------------------------------------------------------
// 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
void CTreeView::ExpandToView()
{
	unsigned count = 0;
	int depth = 0;
	for (auto it = m_levels.begin(); it != m_levels.end(); ++it)
	{
		count += *it;
		if (count > GetVisibleCount())
			break;
		++depth;
	}
	ExpandToDepth(TVI_ROOT, depth);
}
Example #6
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);
		}
	}
}
//-------------------------------------------------------------------------------//
void CBCGPAutoHideToolBar::UpdateVisibleState ()
{
	BOOL bVisible = IsWindowVisible ();
	int nCount = GetVisibleCount ();

	ASSERT (m_pParentDockBar != NULL);

	if (/*bVisible &&*/ nCount == 0)
	{
		m_pParentDockBar->ShowControlBar (this, FALSE, FALSE, FALSE);	
	}
	else if (!bVisible && nCount > 0)
	{
		m_pParentDockBar->ShowControlBar (this, TRUE, FALSE, TRUE);	
	}
}
Example #8
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 #9
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);
}
Example #10
0
void CMultiSelTreeCtrl::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	MainFrame()->SetGotUserInput( );

	if (nChar == VK_RETURN || nChar == VK_APPS)
		return;

	if (nChar == VK_TAB && m_CtrlDown)	// Ctrl+TAB switches to opposite pane
	{
		BOOL bShift = m_ShiftDown;
		m_CtrlDown= m_ShiftDown= FALSE;	// clear these because we may miss the Up
		m_PendingKeyedDeselect = FALSE;	//	in the other pane
		MainFrame()->SwitchPanes(DYNAMIC_DOWNCAST(CView, GetParent()), bShift);
		return;
	}

	if( nChar == VK_CONTROL )
		m_CtrlDown= TRUE;
	else if( nChar == VK_SHIFT )
	{
		m_ShiftDown= TRUE;
		if( m_SelectionSet.GetSize() > 0 )
		{
			m_AnchorItem= m_LastSelect;
			m_PendingKeyedDeselect= TRUE;
		}
	}
	
	if( m_ShiftDown && m_SelectionSet.GetSize() > 0 )
	{
		// Try to range select, and scroll the tree only as necessary
		// to ensure that the last item selected is visible
		switch( nChar )
		{
		case VK_DOWN:
			ExpandSelection( -1 );
			break;
		case VK_UP:
			ExpandSelection( 1 );
			break;
		case VK_END:
			ExpandSelection( - (int) GetCount() );
			break;
		case VK_HOME:
			ExpandSelection( (int) GetCount() );
			break;
		case VK_PGDN:
			ExpandSelection( - (int) GetVisibleCount() +1 );
			break;
		case VK_PGUP:
			ExpandSelection( (int) GetVisibleCount() -1 );
			break;
		default:
			break;
		}
	}
	else if( m_CtrlDown || m_SelectionSet.GetSize() == 0)
	{
		// Scroll the tree, but do not fool with the selection set
		// or move a focus rect around
		switch( nChar )
		{
		case VK_DOWN:
			ScrollTree( -1 );
			break;
		case VK_UP:
			ScrollTree( 1 );
			break;
		case VK_END:
			ScrollTree( - (int) GetCount() );
			break;
		case VK_HOME:
			ScrollTree( GetCount() );
			break;
		case VK_PGDN:
			ScrollTree( - (int) GetVisibleCount() +1 );
			break;
		case VK_PGUP:
			ScrollTree( GetVisibleCount() -1 );
			break;
		default:
			break;
		}
	}
	else
	{
		// Deselect all, reposition at m_LastSelect + offset, reselect the new
		// item, and ensure visible
		HTREEITEM item= m_LastSelect;
		ASSERT( item != NULL );
		HTREEITEM newItem;
		UnselectAll();
#if 0
		HTREEITEM lastItem;
		int i, count;
#endif
		switch( nChar )
		{
		case VK_END:
			ScrollTree( - (int) GetCount() );
			newItem= GetNextItem(TVI_ROOT, TVGN_LASTVISIBLE);
			break;
		case VK_HOME:
			ScrollTree( GetCount() );
			newItem= GetNextItem(TVI_ROOT, TVGN_ROOT );
			break;
#if 0	// This code was removed to fix job004105 - removing it causes the DepotView to behave like a normal TreeView when page-up and page-down are pressed
		case VK_PGDN:
			count=GetVisibleCount() - 1;
			newItem= GetFirstVisible();

			// First, find the last visible item on the screen
			for( i=0; i< count; i++)
			{
				lastItem= newItem;
				newItem= GetNextVisible(newItem );
				if( newItem == NULL )
				{
					newItem= lastItem;
					break;
				}
			}

			// If current item is the last one on the screen, move down
			// a page beyond the end of current page
			if( newItem == item )
			{
				for( i=0; i< count; i++)
				{
					lastItem= newItem;
					newItem= GetNextVisible( newItem );
					if( newItem==NULL)
					{
						newItem= lastItem;
						break;
					}
				}
			}
			break;
		case VK_PGUP:
			if( item == GetFirstVisible() )
			{
				count=GetVisibleCount() - 1;
				newItem= GetFirstVisible();
				for( i=0; i< count; i++)
				{
					lastItem= newItem;
					newItem= GetPrevVisible( newItem );
					if( newItem==NULL)
					{
						newItem= lastItem;
						break;
					}
				}
			}
			else
				newItem= GetFirstVisible();
			break;
#endif
		default:
			newItem= NULL;
			break;
		}

		// If something went wrong, like hitting top or bottom,
		// use our saved copy of m_LastSelect
		if( newItem == NULL )
			newItem= item;

		if(newItem != NULL )
		{
			SetSelectState( newItem, TRUE );
			EnsureVisible( newItem );

			// Redraw w/out erase to avoid slow video update
			RedrawWindow( NULL, NULL, RDW_UPDATENOW );
		}
	}
	if (!m_CtrlDown && !m_ShiftDown)
		CTreeCtrl::OnKeyDown(nChar, nRepCnt, nFlags);
}
Example #11
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 #12
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);
}
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 );
}
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 #15
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++;
  }
}
Example #16
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 #17
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);
}