NS_IMETHODIMP
sbLocalDatabaseMediaListViewSelection::SelectOnly(PRInt32 aIndex)
{
  NS_ENSURE_ARG_RANGE(aIndex, 0, (PRInt32) mLength - 1);
  nsresult rv;

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

  mSelection.Clear();
  mSelectionIsAll = PR_FALSE;

  rv = AddToSelection(aIndex);
  NS_ENSURE_SUCCESS(rv, rv);

  CheckSelectAll();

  NOTIFY_LISTENERS(OnSelectionChanged, ());

#ifdef DEBUG
  LogSelection();
#endif

  return NS_OK;
}
Exemplo n.º 2
0
NS_IMETHODIMP
TaskbarWindowPreview::SetProgressState(nsTaskbarProgressState aState,
                                       uint64_t aCurrentValue,
                                       uint64_t aMaxValue)
{
    NS_ENSURE_ARG_RANGE(aState,
                        nsTaskbarProgressState(0),
                        nsTaskbarProgressState(ArrayLength(sNativeStates) - 1));

    TBPFLAG nativeState = sNativeStates[aState];
    if (nativeState == TBPF_NOPROGRESS || nativeState == TBPF_INDETERMINATE) {
        NS_ENSURE_TRUE(aCurrentValue == 0, NS_ERROR_INVALID_ARG);
        NS_ENSURE_TRUE(aMaxValue == 0, NS_ERROR_INVALID_ARG);
    }

    if (aCurrentValue > aMaxValue)
        return NS_ERROR_ILLEGAL_VALUE;

    mState = nativeState;
    mCurrentValue = aCurrentValue;
    mMaxValue = aMaxValue;

    // Only update if we can
    return CanMakeTaskbarCalls() ? UpdateTaskbarProgress() : 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;
}
NS_IMETHODIMP
sbLocalDatabaseMediaListViewSelection::SetCurrentIndex(PRInt32 aCurrentIndex)
{
  NS_ENSURE_ARG_RANGE(aCurrentIndex, -1, (PRInt32) mLength - 1);
  nsresult rv;
  mCurrentIndex = aCurrentIndex;
  rv = GetUniqueIdForIndex(mCurrentIndex, mCurrentUID);
  NS_ENSURE_SUCCESS(rv, rv);
  NOTIFY_LISTENERS(OnCurrentIndexChanged, ());
  return NS_OK;
}
NS_IMETHODIMP
sbLocalDatabaseMediaListViewSelection::SelectRange(PRInt32 aStartIndex,
                                                   PRInt32 aEndIndex)
{
  TRACE(("sbLocalDatabaseMediaListViewSelection[0x%.8x] - SelectRange(%d, %d)",
         this, aStartIndex, aEndIndex));

  NS_ENSURE_ARG_RANGE(aStartIndex, 0, (PRInt32) mLength - 1);
  NS_ENSURE_ARG_RANGE(aEndIndex,   0, (PRInt32) mLength - 1);

  nsresult rv;

  if (mSelectionIsAll) {
    return NS_OK;
  }

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

  PRInt32 start = PR_MIN(aStartIndex, aEndIndex);
  PRInt32 end   = PR_MAX(aStartIndex, aEndIndex);

  for (PRInt32 i = start; i <= end; i++) {
    rv = AddToSelection((PRUint32) i);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  CheckSelectAll();

  NOTIFY_LISTENERS(OnSelectionChanged, ());

#ifdef DEBUG
  LogSelection();
#endif

  return NS_OK;
}
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;
}
Exemplo n.º 7
0
NS_IMETHODIMP
nsIOService::EscapeString(const nsACString& aString,
                          PRUint32 aEscapeType,
                          nsACString& aResult)
{
  NS_ENSURE_ARG_RANGE(aEscapeType, 0, 4);

  nsCAutoString stringCopy(aString);
  nsCString result;

  if (!NS_Escape(stringCopy, result, (nsEscapeMask) aEscapeType))
    return NS_ERROR_OUT_OF_MEMORY;

  aResult.Assign(result);

  return NS_OK;
}