Esempio n. 1
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;
}
void CCxNDArrayDimGrid::OnLButtonDown(UINT nFlags, CPoint point)
{
	//CBCGPGridCtrl::OnLButtonDown(nFlags, point);

	CWnd::OnLButtonDown(nFlags, point);

	OnFilterBarSetFocus (-1);
	SetFocus ();

	//--------------------
	// Group-by-box click:
	//--------------------
	CRect rectColumn;
	int nGroupHit = HitTestGroupByBox (point, rectColumn);

	if (nGroupHit >= 0)
	{
		m_ptStartDrag = point;
		StartDragColumn (nGroupHit, rectColumn, TRUE, FALSE);
		return;
	}

	// -------------
	// Track header:
	// -------------
	CPoint ptHeader = point;
	if (OnTrackHeader () && m_rectList.PtInRect (point))
	{
		ptHeader.y = m_rectHeader.top;
	}
	int nColumnHit = GetColumnsInfo ().HitTestColumn (ptHeader, TRUE, STRETCH_DELTA);
	if (nColumnHit != -1)
	{
		int nLButton = GetSystemMetrics (SM_SWAPBUTTON) ? VK_RBUTTON : VK_LBUTTON;
		if ((GetAsyncKeyState (nLButton) & 0x8000) == 0)
		{
			return;
		}

		if (!GetColumnsInfo ().CanChangeWidth (nColumnHit))
		{
			// column can't be resized
			return;
		}

		CRect rectHeaderColumn;
		GetColumnsInfo ().GetColumnRect (nColumnHit, rectHeaderColumn);

		SetCapture ();
		m_nTrackColumn = nColumnHit;
		TrackHeader (rectHeaderColumn.right);
		m_bTracking = TRUE;
		return;
	}

	if (IsDragSelectionBorderEnabled () && HitTestSelectionBorder (point))
	{
		if (StartDragItems (point))
		{
			return;
		}
	}

	//--------------
	// Header click:
	//--------------
	CBCGPGridColumnsInfo::ClickArea clickAreaHeader;
	nColumnHit = GetColumnsInfo ().HitTestColumn (point, FALSE, STRETCH_DELTA, &clickAreaHeader);

	if (nColumnHit >= 0)
	{
		DoColumnHeaderClick (nColumnHit, point, clickAreaHeader);
		return;
	}

	//-------------------------
	// "Select all" area click:
	//-------------------------
	if (m_rectSelectAllArea.PtInRect (point))
	{
		OnSelectAllClick ();
		return;
	}

	//------------------
	// Row header click:
	//------------------
	CRect rectRowHeader;
	CCxNDArrayDimRow* pHitHeaderRow = (CCxNDArrayDimRow*)HitTestRowHeader (point, rectRowHeader);
	if (pHitHeaderRow != NULL)
	{
		DoRowHeaderClick (pHitHeaderRow, point, rectRowHeader);
		return;
	}

	// ---------------------------
	// Set selection (first click):
	// ---------------------------
	CBCGPGridRow::ClickArea clickArea;
	CBCGPGridItemID id;
	CBCGPGridItem* pHitItem = NULL;
	CBCGPGridRow* pHitRow = HitTest (point, id, pHitItem, &clickArea);

	BOOL bSelChanged = id != m_idLastSel;
	BOOL bIsButtonClick = pHitItem != NULL && ((CCxNDArrayDimItem*)pHitItem)->m_rectButton.PtInRect (point);

	const BOOL bShift = (::GetAsyncKeyState (VK_SHIFT) & 0x8000) != 0 && !m_bIgnoreShiftBtn;
	const BOOL bCtrl = (::GetAsyncKeyState (VK_CONTROL) & 0x8000) != 0 && !m_bIgnoreCtrlBtn;

	if (IsDragSelectionEnabled () && IsItemSelected (id) && !(bCtrl && m_bInvertSelOnCtrl))
	{
		if (StartDragItems (point))
		{
			return;
		}
	}

	DWORD dwSelMode = SM_NONE;
	if (!id.IsNull ())
	{
		dwSelMode = SM_FIRST_CLICK |
			(m_bSingleSel ? SM_SINGE_SEL_GROUP :
			(bCtrl ? SM_ADD_SEL_GROUP :
			(bShift ? SM_CONTINUE_SEL_GROUP : SM_SINGE_SEL_GROUP)));

		if (bCtrl && m_bInvertSelOnCtrl)
		{
			dwSelMode |= SM_INVERT_SEL;
		}

		if (pHitRow != NULL && id.IsRow ())
		{
			dwSelMode |= SM_ROW;
		}
		if (id.IsColumn ())
		{
			dwSelMode |= SM_COLUMN;
		}
	}
	
	m_bNoUpdateWindow = TRUE; // prevent flickering
	m_pSetSelItem = m_bVirtualMode ? NULL : pHitItem;

	SetCurSel (id, dwSelMode);

	m_pSetSelItem = NULL;
	m_bNoUpdateWindow = FALSE;

	if (id.IsNull () || pHitRow == NULL)
	{
		return;
	}

	ASSERT_VALID (pHitRow);
	EnsureVisible (pHitRow);

	CCxNDArrayDimRow* pCurSel = (CCxNDArrayDimRow*)GetCurSel ();
	CCxNDArrayDimItem* pItem = ( CCxNDArrayDimItem* )GetCurSelItem (pCurSel);
	if (id != m_idActive || pCurSel == NULL || (pItem == NULL && clickArea == CBCGPGridRow::ClickValue))
	{
		// The hitten item is not active - do not translate a click to the grid item.
		// Translate a click for single item only.
		return;
	}

	// ------------------------------
	// Translate a click to the item:
	// ------------------------------
	ASSERT_VALID (pCurSel); // pCurSel - hitten row

	switch (clickArea)
	{
	case CBCGPGridRow::ClickExpandBox:
		pCurSel->Expand (!pCurSel->IsExpanded ());
		break;

	case CBCGPGridRow::ClickName:
		pCurSel->OnClickName (point);

		// Start selecting range of items:
		StartSelectItems ();
		break;

	case CBCGPGridRow::ClickValue:
		ASSERT_VALID (pItem);	// pItem - hitten active item
		if (pCurSel->m_bEnabled && pItem->IsEnabled ())
		{
			if (bIsButtonClick || m_bSingleSel)
			{
				DoClickValue (pItem, WM_LBUTTONDOWN, point, bSelChanged, bIsButtonClick);
			}
			else
			{
				// Defer the item click:
				SetTimer (GRID_CLICKVALUE_TIMER_ID, GRID_CLICKVALUE_TIMER_INTERVAL, NULL);
				m_bClickTimer = TRUE;
				m_ptClickOnce = point;
				m_bIsFirstClick = bSelChanged;
				m_bIsButtonClick = bIsButtonClick;
				m_bHeaderRowSelecting = FALSE;
				m_bHeaderColSelecting = FALSE;

				StartSelectItems ();
				return;
			}
		}
		break;

	default:
		break;
	}
}
Esempio n. 3
0
//****************************************************************************************
BOOL CBCGPGridSerializeManager::DoDropRows (CBCGPGridItemID idDropTo, CBCGPGridItemID idDragFrom,
											BOOL bMove, BOOL bInsertAfter)
{
	ASSERT (m_pOwnerGrid != NULL);
	ASSERT (m_ClipboardFormatType == CF_Rows);
	
	if (GetRangeCount () == 0)
	{
		return FALSE; // no data
	}

	// Copied rows are already removed if called from Paste or dragged from another app
	BOOL bNoRemove = idDragFrom.IsNull ();

	//---------------------
	// Calculate new offset
	//---------------------
	idDragFrom.SetNull ();
	if (bInsertAfter)
	{
		idDropTo.m_nRow++;
	}
	
	CBCGPGridItemID idTo = GetDropOffset (idDragFrom, idDropTo);
	ASSERT (idTo.m_nRow >= 0);
	ASSERT (idTo.m_nColumn >= 0);

	//----------------
	// Mark selection:	(save ranges to remove selection later)
	//----------------
	CleanUpImplementationData ();
	if (bNoRemove)
	{
		m_arrCutRanges.SetSize (0);
	}
	else
	{
		m_arrCutRanges.SetSize (GetRangeCount ());
		
		for (int i = 0; i < GetRangeCount (); i++)
		{
			CBCGPGridRange rangeOrder;
			if (!GetRange (i, rangeOrder))
			{
				return FALSE;
			}
			
			
			rangeOrder.m_nTop += m_idRangesOffset.m_nRow; 
			rangeOrder.m_nBottom += m_idRangesOffset.m_nRow;
			m_arrCutRanges [i] = (CMarkedGridRange) rangeOrder;
			
			if (rangeOrder.m_nTop < idDropTo.m_nRow &&
				rangeOrder.m_nBottom >= idDropTo.m_nRow)
			{
				//idDropTo = rangeOrder.m_nTop;
				return FALSE; // can't insert inside range
			}
		}
	}

	//-------------
	// Drop ranges:
	//-------------
	for (int i = 0; i < GetRangeCount (); i++)
	{
		CBCGPGridRange rangeOrder;
		if (!GetRange (i, rangeOrder))
		{
			return FALSE;
		}

		if (rangeOrder.m_nTop < 0 || rangeOrder.m_nBottom < rangeOrder.m_nTop)
		{
			return FALSE;
		}

		const int nRowOffset = -rangeOrder.m_nTop + idTo.m_nRow + (int)m_lstNewRows.GetCount ();
		rangeOrder.m_nTop += nRowOffset;
		rangeOrder.m_nBottom += nRowOffset;

		//------------
		// Drop range:
		//------------
		UINT	nDataSize = 0;
		BYTE*	pData = GetRangeData (i, nDataSize);
		
		if (pData == NULL || nDataSize <= 0)
		{
			return FALSE;
		}
		
		CMemFile f(pData, nDataSize);
		
		CArchive archive (&f, CArchive::load);
		if (!ReadRowsFromArchive (archive, rangeOrder))
		{
			return FALSE;
		}
		archive.Close ();
	}

 	if (!m_bSkipData)
 	{
		//---------------------------
		// Remove previous selection:
		//---------------------------
		CBCGPGridItemID id;
		m_pOwnerGrid->SetCurSel (id, SM_NONE, FALSE);

 		//-------------------------
 		// Insert new rows to grid:
 		//-------------------------
 		InsertNewSelection (idTo.m_nRow, m_lstNewRows);

		if (bMove)
		{
			//---------------------
			// Remove marked items (previous selection):
			//---------------------
			if (!RemovePreviosSelection ())
			{
				return FALSE; // can't clear non empty items 
			}
		}

		UpdateSelectionRect (idTo);
		m_pOwnerGrid->AdjustLayout ();

		//-------------------
		// Set new selection:
		//-------------------
		CBCGPGridRange rangeSel = m_InsertRange;
		if (rangeSel.IsValid ())
		{
			CBCGPGridItemID idFirst (rangeSel.m_nTop);
			CBCGPGridItemID idSecond (rangeSel.m_nBottom);
			
			m_pOwnerGrid->SetCurSel (idFirst, SM_FIRST_CLICK | SM_SINGE_SEL_GROUP, FALSE);
			m_pOwnerGrid->SetCurSel (idSecond, SM_SECOND_CLICK | SM_CONTINUE_SEL_GROUP, TRUE);
		}
	}

 	CleanUpImplementationData ();

	return TRUE;
}