void
HTMLTextAreaElement::SetSelectionEnd(uint32_t aSelectionEnd, ErrorResult& aError)
{
  if (mState.IsSelectionCached()) {
    mState.GetSelectionProperties().mEnd = aSelectionEnd;
    return;
  }

  nsAutoString direction;
  nsresult rv = GetSelectionDirection(direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  int32_t start, end;
  rv = GetSelectionRange(&start, &end);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  end = aSelectionEnd;
  if (start > end) {
    start = end;
  }
  rv = SetSelectionRange(start, end, direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
void
HTMLTextAreaElement::SetSelectionEnd(const Nullable<uint32_t>& aSelectionEnd,
                                     ErrorResult& aError)
{
  int32_t selEnd = 0;
  if (!aSelectionEnd.IsNull()) {
    selEnd = aSelectionEnd.Value();
  }

  if (mState.IsSelectionCached()) {
    mState.GetSelectionProperties().SetEnd(selEnd);
    return;
  }

  nsAutoString direction;
  nsresult rv = GetSelectionDirection(direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  int32_t start, end;
  rv = GetSelectionRange(&start, &end);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
    return;
  }
  end = selEnd;
  if (start > end) {
    start = end;
  }
  rv = SetSelectionRange(start, end, direction);
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
NS_IMETHODIMP
HTMLTextAreaElement::SetSelectionRange(int32_t aSelectionStart,
                                       int32_t aSelectionEnd,
                                       const nsAString& aDirection)
{
  ErrorResult error;
  Optional<nsAString> dir;
  dir = &aDirection;
  SetSelectionRange(aSelectionStart, aSelectionEnd, dir, error);
  return error.ErrorCode();
}
Beispiel #4
0
void SjColumnMixer::SelectShifted(SjRow* rowClicked)
{
	// Function selects all rows from the "currently selected" row
	// up to the given row. All other rows are deselected.

	// The "currently selected" row is the first selected row or a stored anchor.

	wxASSERT( rowClicked );
	wxASSERT( rowClicked->IsSelectable()==2 );

	long rowClickedColIndex, rowClickedRowIndex;

	// If there is no selected row/no anchor, we cannot shift to the given row;
	// simply select the given row in this case.
	if( !GetSelectionAnchor(rowClickedColIndex/*dummy*/, rowClickedRowIndex/*dummy*/) )
	{
		rowClicked->Select(TRUE);
		return; // Done.
	}

	// find out "shift to" column and row index
	if( GetMaskedColIndexByRow(rowClicked, rowClickedColIndex, rowClickedRowIndex) )
	{
		// okay, now we have the first and the last selected row index
		// and the index of the row to shift to -- see what to do
		if(  rowClickedColIndex > m_selAnchorColIndex
		        || (rowClickedColIndex == m_selAnchorColIndex && rowClickedRowIndex > m_selAnchorRowIndex) )
		{
			// select from the first selected row up to the shifted row
			SetSelectionRange(m_selAnchorColIndex, m_selAnchorRowIndex, rowClickedColIndex, rowClickedRowIndex, TRUE);
		}
		else
		{
			// select from the shifted row up to the first selected row;
			SetSelectionRange(rowClickedColIndex, rowClickedRowIndex, m_selAnchorColIndex, m_selAnchorRowIndex, TRUE);
		}
	}
}
void
HTMLTextAreaElement::SetSelectionDirection(const nsAString& aDirection, ErrorResult& aError)
{
  if (mState.IsSelectionCached()) {
    nsITextControlFrame::SelectionDirection dir = nsITextControlFrame::eNone;
    if (aDirection.EqualsLiteral("forward")) {
      dir = nsITextControlFrame::eForward;
    } else if (aDirection.EqualsLiteral("backward")) {
      dir = nsITextControlFrame::eBackward;
    }
    mState.GetSelectionProperties().mDirection = dir;
    return;
  }

  int32_t start, end;
  nsresult rv = GetSelectionRange(&start, &end);
  if (NS_SUCCEEDED(rv)) {
    rv = SetSelectionRange(start, end, aDirection);
  }
  if (NS_FAILED(rv)) {
    aError.Throw(rv);
  }
}
void
HTMLTextAreaElement::SetRangeText(const nsAString& aReplacement,
                                  uint32_t aStart, uint32_t aEnd,
                                  const SelectionMode& aSelectMode,
                                  ErrorResult& aRv, int32_t aSelectionStart,
                                  int32_t aSelectionEnd)
{
  if (aStart > aEnd) {
    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return;
  }

  nsAutoString value;
  GetValueInternal(value, false);
  uint32_t inputValueLength = value.Length();

  if (aStart > inputValueLength) {
    aStart = inputValueLength;
  }

  if (aEnd > inputValueLength) {
    aEnd = inputValueLength;
  }

  if (aSelectionStart == -1 && aSelectionEnd == -1) {
    aRv = GetSelectionRange(&aSelectionStart, &aSelectionEnd);
    if (aRv.Failed()) {
      if (mState.IsSelectionCached()) {
        aSelectionStart = mState.GetSelectionProperties().mStart;
        aSelectionEnd = mState.GetSelectionProperties().mEnd;
        aRv = NS_OK;
      }
    }
  }

  if (aStart <= aEnd) {
    value.Replace(aStart, aEnd - aStart, aReplacement);
    SetValueInternal(value, false);
  }

  uint32_t newEnd = aStart + aReplacement.Length();
  int32_t delta =  aReplacement.Length() - (aEnd - aStart);

  switch (aSelectMode) {
    case mozilla::dom::SelectionMode::Select:
    {
      aSelectionStart = aStart;
      aSelectionEnd = newEnd;
    }
    break;
    case mozilla::dom::SelectionMode::Start:
    {
      aSelectionStart = aSelectionEnd = aStart;
    }
    break;
    case mozilla::dom::SelectionMode::End:
    {
      aSelectionStart = aSelectionEnd = newEnd;
    }
    break;
    case mozilla::dom::SelectionMode::Preserve:
    {
      if ((uint32_t)aSelectionStart > aEnd) {
        aSelectionStart += delta;
      } else if ((uint32_t)aSelectionStart > aStart) {
        aSelectionStart = aStart;
      }

      if ((uint32_t)aSelectionEnd > aEnd) {
        aSelectionEnd += delta;
      } else if ((uint32_t)aSelectionEnd > aStart) {
        aSelectionEnd = newEnd;
      }
    }
    break;
  }

  Optional<nsAString> direction;
  SetSelectionRange(aSelectionStart, aSelectionEnd, direction, aRv);
}
Beispiel #7
0
bool CScrollBufL1::FindText(CString szFindString, BOOL bFindMatchCase, BOOL bFindSearchDown, SSelection *sStartingLine)
{
    long nEnd, nIncrement;
    bool bRet = false;
    SSelection sFound;
    bool bValid;
    SFullLine *sFullLine;
    char *pText;
    CScrollBufL3 *pL3;

    Enter();
    pL3 = m_pL2->GetScreen(&sStartingLine->y);
    if (bFindSearchDown)
    {
        nEnd = pL3->GetNumLines() - 1;
        nIncrement = 1;
        if ((sStartingLine->y > (long)pL3->GetNumLines()) || (sStartingLine->y < 0))
        {
            sStartingLine->y = 0;
        }
    }
    else
    {
        nEnd = 0;
        nIncrement = -1;
        if ((sStartingLine->y > (long)pL3->GetNumLines()) || (sStartingLine->y < 0))
        {
            sStartingLine->y = pL3->GetNumLines() - 1;
        }
    }
    
    while (sStartingLine->y != nEnd)
    {
        sFullLine = GetLine(sStartingLine->y, &bValid);
        if (bValid && sFullLine)
        {
            if (bFindMatchCase)
            {
                pText = strstr(sFullLine->szLine + sStartingLine->x, szFindString);
            }
            else
            {
                pText = stristr(sFullLine->szLine + sStartingLine->x, szFindString.GetBuffer());
            }
            if (pText)
            {
                sStartingLine->x = (pText - sFullLine->szLine) + szFindString.GetLength();
                sFound = *sStartingLine;
                ResetSelectionRange(sFound, false);
                sFound.x -= szFindString.GetLength();
                SetSelectionRange(sFound);
                bRet = true;
                break;
            }
        }
        sStartingLine->x = 0;
        sStartingLine->y += nIncrement;
    }
    Exit();
    return bRet;
}
Beispiel #8
0
bool SjColumnMixer::SelectShifted(int keyPressed/*-1=up, +1=down*/, long& retScopeColIndex, long& retScopeRowIndex)
{
	long    firstSelColIndex, firstSelRowIndex,
	        lastSelColIndex, lastSelRowIndex;
	bool    prevNextOk;

	// get selection anchor and the first/last selected row

	if( !GetSelectionAnchor(firstSelColIndex/*dummy*/, firstSelRowIndex/*dummy*/)
	        || !GetSelectionRange(firstSelColIndex, firstSelRowIndex, &lastSelColIndex, &lastSelRowIndex) )
	{
		return FALSE; // no anchor, the caller should preform a "simple" selection
	}

	// calculate the new selection...

	if( firstSelColIndex == lastSelColIndex && firstSelRowIndex == lastSelRowIndex )
	{
		if( keyPressed == -1 )
		{
			// ...initial selection from anchor to top
			prevNextOk = PrevNextRow(firstSelColIndex, firstSelRowIndex, -1);
			retScopeColIndex = firstSelColIndex;
			retScopeRowIndex = firstSelRowIndex;
		}
		else
		{
			// ...initial selection from anchor to bottom
			prevNextOk = PrevNextRow(lastSelColIndex, lastSelRowIndex, +1);
			retScopeColIndex = lastSelColIndex;
			retScopeRowIndex = lastSelRowIndex;
		}
	}
	else if(  firstSelColIndex < m_selAnchorColIndex
	          || (firstSelColIndex == m_selAnchorColIndex && firstSelRowIndex < m_selAnchorRowIndex) )
	{
		// ...selected stuff above the anchor...
		prevNextOk = PrevNextRow(firstSelColIndex, firstSelRowIndex, keyPressed);
		retScopeColIndex = firstSelColIndex;
		retScopeRowIndex = firstSelRowIndex;
	}
	else
	{
		// ...select stuff below the anchor...
		prevNextOk = PrevNextRow(lastSelColIndex, lastSelRowIndex, keyPressed);
		retScopeColIndex = lastSelColIndex;
		retScopeRowIndex = lastSelRowIndex;
	}

	if( prevNextOk )
	{
		// set the new selection

		SetSelectionRange(firstSelColIndex, firstSelRowIndex, lastSelColIndex, lastSelRowIndex, TRUE);

		// make sure, the anchor is always selected

		SjCol* col = GetMaskedCol(m_selAnchorColIndex);
		if( col )
		{
			if( m_selAnchorRowIndex >= 0 && m_selAnchorRowIndex < col->m_rowCount )
			{
				col->m_rows[m_selAnchorRowIndex]->Select(TRUE);
			}
			delete col;
		}
	}

	return TRUE;
}