void CScreenEditView::DoContextMenu(CPoint point)
{
	CFEManDoc* pDoc = GetDocument();
	Screen *pWorkScreen;
	ScreenObject *pScreenObject;
	
	// Save the position of this last right click.
	lastRightClick = point;

	// Keep this click in client coordinates?
	ScreenToClient(&lastRightClick);
	
	// These are the types of context menus in this pane;
	// 1: Default context menu.
	// 2: Screen Object context menu.
	
	// Load the Screen Object context menu.
	pWorkScreen = pDoc->GetFirstSelectedScreen();

	if(!pWorkScreen)
		return;

	pScreenObject = pWorkScreen->PointOnScreenObject(&lastRightClick);
	
	if(pScreenObject)
	{	
		CMenu contextMenu, *pContextMenu;

		if(!pWorkScreen->IsSelectedScreenObject(pScreenObject))
		{
			pWorkScreen->ClearAllSelectedScreenObjects();
		}
		
		pWorkScreen->SelectScreenObject(pScreenObject);

		Invalidate();

		if(pScreenObject->GetType() == ScreenObject::SOT_SCREENOBJECTRECT)
		{
			contextMenu.LoadMenu(IDR_SCREENOBJECTRECT);

			pContextMenu = contextMenu.GetSubMenu(0);

			// Disable properties if there is more than one item selected.
			if(pWorkScreen->GetNumSelectedScreenObjects() > 1)
			{
				pContextMenu->EnableMenuItem(ID_SOR_PROPERTIES, MF_GRAYED);
			}

			// Disable delete if one of the screens is the default page.
			// Delete screen won't delete this screen anyway.
			if(pWorkScreen->IsObjectDefaultPage(pScreenObject))
			{
				pContextMenu->EnableMenuItem(ID_SOR_DELETESELECTEDSCREENS, MF_GRAYED);
			}
			
			pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());
		}

		else if(pScreenObject->GetType() == ScreenObject::SOT_SCREENOBJECTBITMAP)
		{
			contextMenu.LoadMenu(IDR_SCREENOBJECTBITMAP);

			pContextMenu = contextMenu.GetSubMenu(0);

			// Disable properties if there is more than one item selected.
			if(pWorkScreen->GetNumSelectedScreenObjects() > 1)
			{
				pContextMenu->EnableMenuItem(ID_SOB_PROPERTIES, MF_GRAYED);
			}

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

		else if(pScreenObject->GetType() == ScreenObject::SOT_SCREENOBJECTSTRING)
		{
			contextMenu.LoadMenu(IDR_SCREENOBJECTSTRING);

			pContextMenu = contextMenu.GetSubMenu(0);

			// Disable properties if there is more than one item selected.
			if(pWorkScreen->GetNumSelectedScreenObjects() > 1)
			{
				pContextMenu->EnableMenuItem(ID_SOS_PROPERTIES, MF_GRAYED);
			}

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

	// Load the default context menu.
	else
	{
		CMenu contextMenu, *pContextMenu;
		
		pWorkScreen->ClearAllSelectedScreenObjects();
		
		Invalidate();

		contextMenu.LoadMenu(IDR_SCREENEDITDEFAULT);

		pContextMenu = contextMenu.GetSubMenu(0);

		pContextMenu->CheckMenuItem(ID_SED_GRID, MF_BYCOMMAND | (pDoc->gridActive ? MF_CHECKED : MF_UNCHECKED));

		pContextMenu->TrackPopupMenu(TPM_LEFTALIGN, point.x, point.y, GetParent());
	}
}
void CScreenEditView::ChooseMouseCursor(CPoint *point)
{
	CFEManDoc* pDoc = GetDocument();
	Screen *pWorkScreen;
	ScreenObject *pScreenObject;

	if(lButtonStatus == LBS_NORMAL)
	{
		pWorkScreen = pDoc->GetFirstSelectedScreen();

		if(!pWorkScreen)
			return;

		pScreenObject = pWorkScreen->PointOnScreenObject(point);
		
		if(pScreenObject)
		{
			// Moved over on a screen object.

			// Only do this if there is just one screen object selected.
			if(pScreenObject->GetStatus() == ScreenObject::SOS_SELECTED)
			{
				mousePosStatus = pScreenObject->CheckSelectionDragGizmos(point);
			}
			else
			{
				// If this screen selected, drag all selected items.
				mousePosStatus = LBS_NORMAL;	
			}
		}
		else
		{
			mousePosStatus = LBS_NORMAL;
		}
	}
	else
	{
		mousePosStatus = lButtonStatus;
	}

	switch(mousePosStatus)
	{
	case LBS_SCREENOBJECTCLICK:
		::SetCursor(theApp.LoadStandardCursor(IDC_SIZEALL));
		break;

	case LBS_IN_GIZMO_TOP_LEFT:
	case LBS_IN_GIZMO_BOTTOM_RIGHT:
		::SetCursor(theApp.LoadStandardCursor(IDC_SIZENWSE));
		break;

	case LBS_IN_GIZMO_TOP_RIGHT:
	case LBS_IN_GIZMO_BOTTOM_LEFT:
		::SetCursor(theApp.LoadStandardCursor(IDC_SIZENESW));
		break;

	case LBS_IN_GIZMO_MIDDLE_LEFT:
	case LBS_IN_GIZMO_MIDDLE_RIGHT:
		::SetCursor(theApp.LoadStandardCursor(IDC_SIZEWE));
		break;

	case LBS_IN_GIZMO_TOP_MIDDLE:
	case LBS_IN_GIZMO_BOTTOM_MIDDLE:
		::SetCursor(theApp.LoadStandardCursor(IDC_SIZENS));
	break;

	default:
		::SetCursor(theApp.LoadStandardCursor(IDC_ARROW));
		break;
	}
}
void CScreenEditView::OnLButtonDown(UINT nFlags, CPoint point)
{
	CFEManDoc* pDoc = GetDocument();
	Screen *pWorkScreen;
	ScreenObject *pScreenObject;
	
	// Only draw the screen object if there is one screen selected.
	if(pDoc->GetNumSelectedScreenIcons() != 1)
		return;
	
	// Left button is pressed.  We have several choices.
	// 1: Pressed on nothing.  Start dragging a selection window.
	// 2: Pressed on a ScreenObject.  Select the screen object and drag it.
	// 4: Pressed on an already selected Screen Object.  Drag all selected items.
	
	if(pDoc->gridActive)
	{
		CPoint tempPoint;

		tempPoint.x = point.x - DEFAULT_SCREEN_OFFSET_X;
		tempPoint.y = point.y - DEFAULT_SCREEN_OFFSET_Y;

		unsigned long xRes = tempPoint.x / pDoc->gridSpacing;
		unsigned long yRes = tempPoint.y / pDoc->gridSpacing;

		lastLeftClick.x = pDoc->gridSpacing * xRes;
		lastLeftClick.y = pDoc->gridSpacing * yRes;

		lastLeftClick.x += DEFAULT_SCREEN_OFFSET_X;
		lastLeftClick.y += DEFAULT_SCREEN_OFFSET_Y;
	}
	else
	{
		lastLeftClick = point;
	}
	
	switch(lButtonStatus)
	{
	case LBS_NORMAL:		// Nothing special.
		// Find out where I clicked and choose one of the tracking modes.
		
		pWorkScreen = pDoc->GetFirstSelectedScreen();
		pScreenObject = pWorkScreen->PointOnScreenObject(&point);
		
		if(pScreenObject)
		{
			// Clicked on a screen object.

			// If nothing selected, OR this screen object is not
			// selected, clear all other selections and drag this screen.
			if((pWorkScreen->GetNumSelectedScreenObjects() == 0) ||
				(!pWorkScreen->IsSelectedScreenObject(pScreenObject)))
			{
				pWorkScreen->ClearAllSelectedScreenObjects();

				pWorkScreen->SelectScreenObject(pScreenObject);
			}

			// Only do this if there is just one screen object selected.
			if(pWorkScreen->GetNumSelectedScreenObjects() == 1)
			{
				lButtonStatus = pScreenObject->CheckSelectionDragGizmos(&point);
			}
			else
			{
				// If this screen selected, drag all selected items.
				lButtonStatus = LBS_SCREENOBJECTCLICK;	
			}
		}
		
		else
		{
			// Didn't click on a screen object.  Start Dragging the selection widow.

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

			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_SCREENOBJECTCLICK:	// Clicked on a screen object.
			// In a tracking mode.  Probably do nothing.
		break;
	}

	ChooseMouseCursor(&point);
}