bool C4EditCursor::LeftButtonDown(DWORD dwKeyState)
{

	// Hold
	Hold=true;

	switch (Mode)
	{
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	case C4CNS_ModeEdit:
		if (dwKeyState & MK_CONTROL)
		{
			// Toggle target
			if (Target)
				if (!RemoveFromSelection(Target))
					AddToSelection(Target);
		}
		else
		{
			// Click on unselected: select single
			if (Target)
			{
				C4ObjectLink * it;
				for(it = Selection.First; it; it = it->Next){
					if(it->Obj->At(X, Y))
						break;
				}
				if(!it) // means loop didn't break
					{ ClearSelection(); AddToSelection(Target); }
			}
			// Click on nothing: drag frame
			if (!Target)
				{ ClearSelection(); DragFrame=true; X2=X; Y2=Y; }
		}
		break;
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	case C4CNS_ModeDraw:
		switch (Console.ToolsDlg.Tool)
		{
		case C4TLS_Brush: ApplyToolBrush(); break;
		case C4TLS_Line: DragLine=true; X2=X; Y2=Y; break;
		case C4TLS_Rect: DragFrame=true; X2=X; Y2=Y; break;
		case C4TLS_Fill:
			if (Game.HaltCount)
				{ Hold=false; Console.Message(LoadResStr("IDS_CNS_FILLNOHALT")); return false; }
			break;
		case C4TLS_Picker: ApplyToolPicker(); break;
		}
		break;
		// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
	}

	DropTarget=NULL;

	OnSelectionChanged();
	return true;
}
NS_IMETHODIMP
sbLocalDatabaseMediaListViewSelection::Toggle(PRInt32 aIndex)
{
  NS_ENSURE_ARG_RANGE((PRInt32) aIndex, 0, (PRInt32) mLength - 1);
  nsresult rv;

  mCurrentIndex = aIndex;
  rv = GetUniqueIdForIndex(mCurrentIndex, mCurrentUID);
  NS_ENSURE_SUCCESS(rv, rv);

  // If have an all selection, fill the selection with everything but the
  // toggled index
  if (mSelectionIsAll) {
    mSelectionIsAll = PR_FALSE;
    for (PRUint32 i = 0; i < mLength; i++) {
      if (i != (PRUint32) aIndex) {
        rv = AddToSelection(i);
        NS_ENSURE_SUCCESS(rv, rv);
      }
    }
    return NS_OK;
  }

  // Otherwise, simply do the toggle
  PRBool isSelected;
  rv = IsIndexSelected(aIndex, &isSelected);
  NS_ENSURE_SUCCESS(rv, rv);

  if (isSelected) {
    rv = RemoveFromSelection(aIndex);
    NS_ENSURE_SUCCESS(rv, rv);
  }
  else {
    rv = AddToSelection(aIndex);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  CheckSelectAll();

  NOTIFY_LISTENERS(OnSelectionChanged, ());

#ifdef DEBUG
  LogSelection();
#endif

  return NS_OK;
}
NS_IMETHODIMP
sbLocalDatabaseMediaListViewSelection::ClearRange(PRInt32 aStartIndex,
                                                  PRInt32 aEndIndex)
{
  NS_ENSURE_ARG_RANGE(aStartIndex, 0, (PRInt32) mLength - 1);
  NS_ENSURE_ARG_RANGE(aEndIndex,   0, (PRInt32) mLength - 1);

  nsresult rv;

  mCurrentIndex = aEndIndex;
  rv = GetUniqueIdForIndex(mCurrentIndex, mCurrentUID);
  NS_ENSURE_SUCCESS(rv, rv);

  // If have an all selection, fill the selection with everything but the
  // range we're clearing
  if (mSelectionIsAll) {
    mSelectionIsAll = PR_FALSE;
    for (PRUint32 i = 0; i < mLength; i++) {
      if (i < (PRUint32) aStartIndex || i > (PRUint32) aEndIndex) {
        rv = AddToSelection(i);
        NS_ENSURE_SUCCESS(rv, rv);
      }
    }

    NOTIFY_LISTENERS(OnSelectionChanged, ());

    return NS_OK;
  }

  for (PRInt32 i = aStartIndex; i <= aEndIndex; i++) {
    rv = RemoveFromSelection((PRUint32) i);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  NOTIFY_LISTENERS(OnSelectionChanged, ());

#ifdef DEBUG
  LogSelection();
#endif

  return NS_OK;
}