int CHeaderCtrlExt::FindVisibleItem(int nIndex)
{
	if(GetVisible(nIndex))return nIndex;

	int nOrder = IndexToOrder(nIndex);
	while(nOrder > 0)
	{
		nIndex = OrderToIndex(--nOrder);
		if(GetVisible(nIndex))return nIndex;
	}

	return -1;
}
Exemplo n.º 2
0
//****************************************************************************************
CBCGPGridItemID CBCGPGridSerializeManager::GetDropOffset (const CBCGPGridItemID& idDragFrom,
														  const CBCGPGridItemID& idDropTo) const
{
	if (idDragFrom.IsNull ())
	{
		CBCGPGridItemID idOffset;
		if (!IndexToOrder (idDropTo, idOffset))
		{
			idOffset.m_nRow = idDropTo.m_nRow;
			idOffset.m_nColumn = 0;
		}

		idOffset.m_nColumn = max (0, idOffset.m_nColumn);
		idOffset.m_nRow = max (0, idOffset.m_nRow);
		return idOffset;
	}

	CBCGPGridItemID idDelta(0 ,0);
	if (idDragFrom.m_nColumn != -1 && idDropTo.m_nColumn != -1 && !m_bWholeRowSelected)
	{
		CBCGPGridItemID idDragFromOrder, idDropToOrder;
		if (IndexToOrder (idDragFrom, idDragFromOrder) &&
			IndexToOrder (idDropTo, idDropToOrder))
		{
			idDelta.m_nColumn = idDropToOrder.m_nColumn - idDragFromOrder.m_nColumn;
		}
	}
	if (idDragFrom.m_nRow != -1 && idDropTo.m_nRow != -1 && !m_bWholeColSelected)
	{
		idDelta.m_nRow = idDropTo.m_nRow - idDragFrom.m_nRow;
	}
	
	CBCGPGridItemID idOffset = m_idRangesOffset;
	idOffset.m_nColumn = max (0, idOffset.m_nColumn + idDelta.m_nColumn);
	idOffset.m_nRow = max (0, idOffset.m_nRow + idDelta.m_nRow);
	
	return idOffset;
}
Exemplo n.º 3
0
void CSHListCtrl::OnLButtonDblClk(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	LVHITTESTINFO ht;
	ht.pt = point;
	// Test for which subitem was clicked.
	// Use macro since this is new and not in MFC.
	int rval = ListView_SubItemHitTest( m_hWnd, &ht );
	
	// Store the old column number and set the new column value.
	int oldsubitem = m_CurSubItem;
	m_CurSubItem = IndexToOrder( ht.iSubItem );
	
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	// Make the column fully visible.
	// We have to take into account that the columns may be reordered
	MakeColumnVisible( Header_OrderToIndex( pHeader->m_hWnd, m_CurSubItem ) );
	
	// Store old state of the item.
	int state = GetItemState( ht.iItem, LVIS_FOCUSED );
	
	// Bail if the state from before was not focused or the 
	// user has not already clicked on this cell.
	if( !state 
		|| m_CurSubItem == -1 
		|| oldsubitem != m_CurSubItem ) return;
	
    // Send Notification to parent of ListView ctrl
	CString str;
	str = GetItemText( ht.iItem, ht.iSubItem );
    LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_BEGINLABELEDIT;
	
	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = ht.iItem;
	dispinfo.item.iSubItem = ht.iSubItem;
	dispinfo.item.pszText = (LPTSTR)((LPCTSTR)str);
	dispinfo.item.cchTextMax = str.GetLength();
	
	GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), 
		(LPARAM)&dispinfo );
	// My code end here
	
	CListCtrl::OnLButtonDblClk(nFlags, point);
}
void CHeaderCtrlExt::SetVisible(int nIndex, BOOL bVisible)
{
	CItemData* pData = (CItemData*)GetItemData(nIndex);

	if(! pData)return;

	if(pData->m_bVisible != bVisible)
	{
		pData->m_bVisible = bVisible;
		// get total items
		int nCount = GetItemCount();
		// get current item's order
		int nOrder = IndexToOrder(nIndex);
		int* piCols = new int[nCount];
		ASSERT(piCols);

		GetOrderArray(piCols, nCount);
		if(bVisible)
		{
			// restore item width
			ResetItemWidth(nIndex);
			// move the item to the original position
			int nTarget;
			int nVisible = GetVisibleItemCount();
			if(nIndex > nVisible - 1)nTarget = nVisible - 1;
			else nTarget = nIndex;

			ASSERT(nTarget <= nOrder);

			for(int i = nOrder;i > nTarget;--i)piCols[i] = piCols[i - 1];
			piCols[nTarget] = nIndex;
		}
		else
		{
			// hide item
			SetItemWidth(nIndex, 0);
		}

		SetOrderArray(nCount, piCols);
		delete []piCols;
	}
}
Exemplo n.º 5
0
/////////////////////////////////////////////////////////////////////////////
// CSHListCtrl message handlers
void CSHListCtrl::OnLButtonDown(UINT nFlags, CPoint point)
{
	LVHITTESTINFO ht;
	ht.pt = point;
	int rval = SubItemHitTest(&ht);
	
	int oldsubitem = m_CurSubItem;
	m_CurSubItem = IndexToOrder(ht.iSubItem);
	
	CHeaderCtrl* pHeader = (CHeaderCtrl*)GetDlgItem(0);
	// Make the column fully visible.
	// We have to take into account that the columns may be reordered
	MakeColumnVisible(Header_OrderToIndex(pHeader->m_hWnd, m_CurSubItem));
	
	// Store old state of the item.
	int state = GetItemState(ht.iItem, LVIS_FOCUSED);

	if (m_CurSubItem == -1 || ht.iItem == -1)
	{
		if(ht.iItem == -1)
		{
			NMLISTVIEW dispinfo;
			dispinfo.hdr.hwndFrom = m_hWnd;
			dispinfo.hdr.idFrom = GetDlgCtrlID();
			dispinfo.hdr.code = NM_CLICK;
			
			dispinfo.iItem = -1;
			dispinfo.iSubItem = ht.iSubItem;
			
			GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), 
				(LPARAM)&dispinfo );
		}
		return;
	}
	
	
	// Call default left button click is here just before we might bail.
	// Also updates the state of the item.
	if (m_bClickEdit)
		m_bKeyEvent = FALSE;

	CListCtrl::OnLButtonDown(nFlags, point);
	
	// Bail if the state from before was not focused or the 
	// user has not already clicked on this cell.
	if (!m_bClickEdit)
	{
		if( !state || m_CurSubItem == -1 || oldsubitem != m_CurSubItem )
			return;
	
		int doedit = 0;
		// If we are in column 0 make sure that the user clicked on 
		// the item label.
		if( 0 == ht.iSubItem )
		{
			if (ht.flags & LVHT_ONITEMLABEL)
				doedit = 1;
		}
		else
		{
			doedit = 1;
		}
		if ( !doedit )
			return;
	}	
    // Send Notification to parent of ListView ctrl
	CString str;
	str = GetItemText( ht.iItem, ht.iSubItem );
    LV_DISPINFO dispinfo;
	dispinfo.hdr.hwndFrom = m_hWnd;
	dispinfo.hdr.idFrom = GetDlgCtrlID();
	dispinfo.hdr.code = LVN_BEGINLABELEDIT;
	
	dispinfo.item.mask = LVIF_TEXT;
	dispinfo.item.iItem = ht.iItem;
	dispinfo.item.iSubItem = ht.iSubItem;
	dispinfo.item.pszText = (LPTSTR)((LPCTSTR)str);
	dispinfo.item.cchTextMax = str.GetLength();
	
	GetParent()->SendMessage( WM_NOTIFY, GetDlgCtrlID(), 
		(LPARAM)&dispinfo );
}
Exemplo n.º 6
0
//****************************************************************************************
BOOL CBCGPGridSerializeManager::PrepareDataFromSelection ()
{
	ASSERT (m_pOwnerGrid != NULL);

	CleanUp ();

	if (m_pOwnerGrid != NULL)
	{
		m_nLastColumn = m_pOwnerGrid->GetColumnsInfo ().GetColumnCount (TRUE) - 1;
		m_nLastRow = m_pOwnerGrid->GetTotalRowCount () - 1;
	}

	if (m_ClipboardFormatType == CF_Rows)
	{
		if (!m_pOwnerGrid->NormalizeSelectionList ())
		{
			return FALSE;
		}
	}

	//---------------------
	// Calculate min offset
	//---------------------
	int i = 0;
	CBCGPGridItemID idOffset (-1, -1);
	for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++)
	{
		CBCGPGridRange rangeIndex, rangeOrder;
		if (m_pOwnerGrid->GetSelection (i, rangeIndex) && 
			IndexToOrder (rangeIndex, rangeOrder))
		{
			const int nRow = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop: 0;
			const int nCol = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft: 0;
			
			if (idOffset.m_nRow == -1 || nRow <= idOffset.m_nRow)
			{
				idOffset.m_nRow = nRow;
			}
			
			if (idOffset.m_nColumn == -1 || nCol <= idOffset.m_nColumn)
			{
				idOffset.m_nColumn = nCol;
			}

			if (idOffset.m_nRow == -1 || 
				idOffset.m_nRow == 0 && idOffset.m_nRow == m_nLastRow)
			{
				m_bWholeColSelected = TRUE;
			}

			if (idOffset.m_nColumn == -1 || 
				idOffset.m_nColumn == 0 && idOffset.m_nColumn == m_nLastColumn)
			{
				m_bWholeRowSelected = TRUE;
			}
		}
	}
	
	if (idOffset.m_nRow == -1)
	{
		idOffset.m_nRow = 0;
	}
	if (idOffset.m_nColumn == -1)
	{
		idOffset.m_nColumn = 0;
	}

	ASSERT (idOffset.m_nRow >= 0);
	ASSERT (idOffset.m_nColumn >= 0);
	m_idRangesOffset = idOffset;

	//------------------------------
	// Prepare serialized selection:
	//------------------------------
	for (i = 0; i < m_pOwnerGrid->GetSelectionCount (); i++)
	{
		CBCGPGridRange rangeIndex, rangeOrder;
		if (m_pOwnerGrid->GetSelection (i, rangeIndex) &&
			IndexToOrder (rangeIndex, rangeOrder))
		{
			const int nRowOffset = (rangeOrder.m_nTop != -1) ? rangeOrder.m_nTop - m_idRangesOffset.m_nRow: 0;
			const int nColOffset = (rangeOrder.m_nLeft != -1) ? rangeOrder.m_nLeft - m_idRangesOffset.m_nColumn: 0;
		
			CBCGPGridRange rangeRelative (
				nColOffset, 
				nRowOffset, 
				nColOffset + (rangeOrder.m_nRight - rangeOrder.m_nLeft), 
				nRowOffset + (rangeOrder.m_nBottom - rangeOrder.m_nTop));

			try
			{
				CMemFile f;

				CArchive archive (&f, CArchive::store | CArchive::bNoFlushOnDelete);
				if (m_ClipboardFormatType == CF_Items)
				{
					WriteItemsToArchive (archive, rangeOrder);
				}
				else if (m_ClipboardFormatType == CF_Rows)
				{
					WriteRowsToArchive (archive, rangeOrder);
				}
				archive.Close ();

				if (f.GetLength () <= 0)
				{
					return FALSE;
				}
				
				UINT	cbSize = (UINT)f.GetLength ();
				BYTE*	pData = new BYTE[cbSize];
				
				if (NULL == pData)
				{
					delete [] pData;
					return FALSE;
				}
				
				f.SeekToBegin ();
				if (f.Read (pData, cbSize) != cbSize)
				{
					delete [] pData;
					return FALSE;
				}
				
				AddRange (rangeRelative, cbSize, pData);
			}
			catch (CFileException* pEx)
			{
				TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. File exception\r\n"));
				pEx->Delete ();
				
				return FALSE;
			}
			catch (CException* e)
			{
				TRACE(_T("CBCGPGridSerializeManager::PrepareDataFromSelection. Exception\r\n"));
				e->Delete ();
				return FALSE;
			}
		}
	}

	return TRUE;
}