Logo Search packages:      
Sourcecode: kdeutils version File versions

void KHexEdit::insert ( const QByteArray &  D  )  [virtual, slot]

inserts

Definition at line 766 of file khexedit.cpp.

References KHE::KBufferRanges::addChangedRange(), KHE::KBufferCursor::atAppendPos(), bufferChanged(), BufferCursor, BufferLayout, BufferRanges, DataBuffer, KHE::KBufferCursor::gotoCIndex(), KHE::KBufferCursor::gotoEnd(), KHE::KBufferCursor::gotoIndex(), KHE::KBufferCursor::gotoNextByte(), KHE::KBufferRanges::hasSelection(), InEditMode, inputFailed(), KHE::KDataBuffer::insert(), KHE::KBufferCursor::isBehind(), KHE::KBufferLayout::length(), OverWrite, pauseCursor(), KHE::KBufferCursor::realIndex(), KHE::KBufferRanges::removeSelection(), repaintChanged(), KHE::KDataBuffer::replace(), KHE::KRange< T >::restrictEndTo(), KHE::KBufferRanges::selection(), selectionChanged(), KHE::KDataBuffer::size(), KHE::KRange< T >::start(), unpauseCursor(), updateLength(), and KHE::KSection::width().

Referenced by KBytesEditWidget::insert().

{
  if( InEditMode )
  {
    emit inputFailed();
    return;
  }

  pauseCursor();

  if( OverWrite )
  {
    if( BufferRanges->hasSelection() )
    {
      // replacing the selection:
      // we restrict the replacement to the minimum length of selection and input
      KSection Selection = BufferRanges->selection();
      Selection.restrictEndTo( Selection.start()+D.size()-1 );
      int W = DataBuffer->replace( Selection, D.data(), Selection.width() );
      BufferCursor->gotoCIndex( Selection.start()+W );
      BufferRanges->addChangedRange( Selection );
      BufferRanges->removeSelection();
    }
    else
    {
      // replacing the normal data, at least until the end
      KSection Section( BufferCursor->realIndex(), D.size(), false );
      Section.restrictEndTo( BufferLayout->length()-1 );
      if( Section.isValid() && !BufferCursor->isBehind() )
      {
        int W = DataBuffer->replace( Section, D.data(), Section.width() );
        BufferCursor->gotoNextByte( W );
        BufferRanges->addChangedRange( Section );
      }
      else
      {
        unpauseCursor();

        emit inputFailed();
        return;
      }
    }
  }
  else
  {
    if( BufferRanges->hasSelection() )
    {
      // replacing the selection
      KSection Selection = BufferRanges->selection();
      int OldLastIndex = BufferLayout->length() - 1;
      int W = DataBuffer->replace( Selection, D.data(), D.size() );
      updateLength();
      BufferCursor->gotoIndex( Selection.start() + W );
      if( W > 0 )
      {
        if( Selection.width() == (int)D.size() )
          BufferRanges->addChangedRange( Selection );
        else
        {
          int NewLastIndex = DataBuffer->size() - 1;
          BufferRanges->addChangedRange( Selection.start(), NewLastIndex>OldLastIndex?NewLastIndex:OldLastIndex );
        }
      }
      BufferRanges->removeSelection();
    }
    else
    {
      bool Appending = BufferCursor->atAppendPos();
      int OldIndex = BufferCursor->realIndex();
      int W = DataBuffer->insert( OldIndex, D.data(), D.size() );
      updateLength();
      if( W > 0 )
      {
        if( Appending )
          BufferCursor->gotoEnd();
        else
          BufferCursor->gotoNextByte( W );
        BufferRanges->addChangedRange( KSection(OldIndex,DataBuffer->size()-1) );
      }
      else
      {
        unpauseCursor();

        emit inputFailed();
        return;
      }
    }
  }
  repaintChanged();

  unpauseCursor();

  emit bufferChanged();
  emit selectionChanged();
}


Generated by  Doxygen 1.6.0   Back to index