void CFlowTreeView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CFEManDoc* pDoc = GetDocument();
	Screen *pWorkScreen;
	ScreenLink *pWorkLink;

	// Left button is pressed.  We have several choices.
	// 1: Pressed on nothing.  Start dragging a selection window.
	// 2: Pressed on a Screen.  Select the screen and drag it.
	// 3: Pressed on a Screen Link.  Select the link and drag it.
	// 4: Pressed on an already selected Screen.  Drag all selected items.
	// 5: Pressed on an already selected Screen Link.  Drag all selected items.

	lastLeftClick = point;
	
	switch(lButtonStatus)
	{
	case LBS_NORMAL:		// Nothing special.
		// Find out where I clicked and choose one of the tracking modes.
		
		pWorkScreen = pDoc->PointOnScreenIcon(&point);
		pWorkLink = pDoc->PointOnScreenLink(&point);
		
		if(pWorkScreen)
		{
			// Clicked on a screen icon.

			// If nothing selected, OR this screen is not 
			// selected, clear all other selections and drag this screen.
			if((pDoc->GetNumSelectedScreenIcons() == 0) || 
				(!pDoc->IsSelectedScreenIcon(pWorkScreen)))
			{
				pDoc->ClearAllSelectedScreenIcons();

				pDoc->SelectScreenIcon(pWorkScreen);
			}

			// If this screen selected, drag all selected items.
			lButtonStatus = LBS_SCREENCLICK;
		}
		else if (pDoc->PointOnScreenLink(&point))
		{
			// Clicked on a screen link.

			// Clear all screen selections, select the screen we're on 
			// and the screenlink we're on and drag the link.
			pDoc->ClearAllSelectedScreenIcons();

			pWorkScreen = pWorkLink->GetMyScreen();
			
			pDoc->SelectScreenIcon(pWorkScreen);

			pWorkScreen->SelectScreenLink(pWorkLink);

			pWorkLink->Detach();
			pWorkLink->SetLinkDst(&point);
			
			// If this screen selected, drag all selected items.
			lButtonStatus = LBS_LINKCLICK;
		}
		else 
		{
			// Clicked on the flow tree window.

			// Clear all the selections and start dragging a selection window.
			pDoc->ClearAllSelectedScreenIcons();

			lButtonStatus = LBS_WINDOWCLICK;

			selectionWindow.left = lastLeftClick.x;
			selectionWindow.top = lastLeftClick.y;

			selectionWindow.right = lastLeftClick.x;
			selectionWindow.bottom = lastLeftClick.y;
		}

		// Make sure we redraw to reflect the changes.
		Invalidate();
		break;

	case LBS_WINDOWCLICK:	// Clicked on a window.
	case LBS_SCREENCLICK:	// Clicked on a screen.
	case LBS_LINKCLICK:		// Clicked on a screenlink.
		// In a tracking mode.  Probably do nothing.
		break;
	}

	ChooseMouseCursor();

	pDoc->SetModifiedFlag();
	
	CView::OnLButtonDown(nFlags, point);
}
void CFlowTreeView::OnContextMenu(CWnd* pWnd, CPoint point) 
{
	CFEManDoc* pDoc = GetDocument();
	Screen *pWorkScreen;
	ScreenLink *pWorkLink;
	
	// Save the position of this last right click.
	lastRightClick = point;

	// Keep this click in client coordinates?
	ScreenToClient(&lastRightClick);
	
	// Three types of context menus in this pane;
	// 1: Default context menu.
	// 2: Screen context menu.
	// 3: Screen Link context menu.

	// Load the Screen context menu.
	pWorkScreen = pDoc->PointOnScreenIcon(&lastRightClick);
	pWorkLink = pDoc->PointOnScreenLink(&lastRightClick);

	if(pWorkScreen)
	{	
		CMenu contextMenu, *pContextMenu;

		if(!pDoc->IsSelectedScreenIcon(pWorkScreen))
		{
			pDoc->ClearAllSelectedScreenIcons();
		}
		
		pDoc->SelectScreenIcon(pWorkScreen);

		Invalidate();

		contextMenu.LoadMenu(IDR_SCREENICON);

		pContextMenu = contextMenu.GetSubMenu(0);

		// Disable properties if there is more than one item selected.
		if(pDoc->GetNumSelectedScreenIcons() > 1)
		{
			pContextMenu->EnableMenuItem(ID_SI_PROPERTIES, MF_GRAYED);
			pContextMenu->EnableMenuItem(ID_SI_NEW_SCREENLINK, MF_GRAYED);
		}
		
		pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());
	}

	// Load the Screen Link context menu.
	else if(pWorkLink)
	{
		CMenu contextMenu, *pContextMenu;
		
		pWorkScreen = pWorkLink->GetMyScreen();
		
		if(!pDoc->IsSelectedScreenIcon(pWorkScreen))
		{
			pDoc->ClearAllSelectedScreenIcons();
		}

		pDoc->SelectScreenIcon(pWorkScreen);

		pWorkScreen->SelectScreenLink(pWorkLink);

		Invalidate();

		contextMenu.LoadMenu(IDR_SCREENLINK);

		pContextMenu = contextMenu.GetSubMenu(0);

		// Disable properties if there is more than one item selected.
		if(pDoc->GetNumSelectedScreenIcons() > 1)
		{
			pContextMenu->EnableMenuItem(ID_SL_PROPERTIES, MF_GRAYED);
			pContextMenu->EnableMenuItem(ID_SL_DELETESCREENLINK, MF_GRAYED);
		}

		if(pWorkLink->IsReadOnly())
		{
			pContextMenu->EnableMenuItem(ID_SL_DELETESCREENLINK, MF_GRAYED);
		}
		
		pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());
	}
	// Load the default context menu.
	else
	{
		CMenu contextMenu, *pContextMenu;

		pDoc->ClearAllSelectedScreenIcons();
		
		Invalidate();

		contextMenu.LoadMenu(IDR_FLOWTREEDEFAULT);

		pContextMenu = contextMenu.GetSubMenu(0);

		pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());
	}
}