Example #1
0
void KNavigator::moveCursor( KMoveAction Action, bool Select )
{
  HexEdit->pauseCursor( true );

  TDEBufferCursor *BufferCursor = HexEdit->BufferCursor;
  TDEBufferRanges *BufferRanges = HexEdit->BufferRanges;

  if( Select )
  {
    if( !BufferRanges->selectionStarted() )
      BufferRanges->setSelectionStart( BufferCursor->realIndex() );
  }
  else
    BufferRanges->removeSelection();

  HexEdit->resetInputContext();
  switch( Action )
  {
    case MoveBackward:     BufferCursor->gotoPreviousByte(); break;
    case MoveWordBackward: {
      KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
      int NewIndex = WBS.indexOfPreviousWordStart( BufferCursor->realIndex() );
      BufferCursor->gotoIndex( NewIndex );
    }
    break;
    case MoveForward:      BufferCursor->gotoNextByte();     break;
    case MoveWordForward:  {
      KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
      int NewIndex = WBS.indexOfNextWordStart( BufferCursor->realIndex() );
      BufferCursor->gotoCIndex( NewIndex );
    }
    break;
    case MoveUp:           BufferCursor->gotoUp();             break;
    case MovePgUp:         BufferCursor->gotoPageUp();         break;
    case MoveDown:         BufferCursor->gotoDown();           break;
    case MovePgDown:       BufferCursor->gotoPageDown();       break;
    case MoveLineStart:    BufferCursor->gotoLineStart();      break;
    case MoveHome:         BufferCursor->gotoStart();          break;
    case MoveLineEnd:      BufferCursor->gotoLineEnd();        break;
    case MoveEnd:          BufferCursor->gotoEnd();            break;
  }

  if( Select )
    BufferRanges->setSelectionEnd( BufferCursor->realIndex() );

  HexEdit->repaintChanged();
  HexEdit->ensureCursorVisible();

  HexEdit->unpauseCursor();

  if( BufferRanges->isModified() )
  {
    if( !HexEdit->isOverwriteMode() ) emit HexEdit->cutAvailable( BufferRanges->hasSelection() );
    emit HexEdit->copyAvailable( BufferRanges->hasSelection() );
    KSection Selection = BufferRanges->selection();
    emit HexEdit->selectionChanged( Selection.start(), Selection.end() );
  }
}
Example #2
0
void KColumnsView::drawContents( TQPainter *P, int cx, int cy, int cw, int ch )
{
  //kdDebug(1501) << "drawContents(" << cx<<","<<cw<<"#"<<cy<<","<<ch<<")\n";
  KPixelXs AffectedXs( cx, cw, true );
  // content to be shown?
  if( AffectedXs.startsBefore(TotalWidth) )
  {
    KPixelYs AffectedYs( cy, ch, true );

    // collect affected columns
    TQPtrList<KColumn> RedrawColumns;
    for( KColumn *C=Columns.first(); C; C=Columns.next() )
      if( C->isVisible() && C->overlaps(AffectedXs) )
        RedrawColumns.append( C );

    // any lines to be drawn?
    if( NoOfLines > 0 )
    {
      // calculate affected lines
      KSection AffectedLines = visibleLines( AffectedYs );
      AffectedLines.restrictEndTo( NoOfLines - 1 );

      if( AffectedLines.isValid() )
      {
        TQPainter Paint;
        Paint.begin( const_cast<TQPixmap*>(&LineBuffer), this );

        // starting painting with the first line
        KColumn *C = RedrawColumns.first();
        Paint.translate( C->x(), 0 );

        for( ; C; C=RedrawColumns.next() )
        {
          C->paintFirstLine( &Paint, AffectedXs, AffectedLines.start() );
          Paint.translate( C->width(), 0 );
        }

        // Go through the other lines
        KPixelY y = AffectedLines.start() * LineHeight;
        int l = AffectedLines.start();
        while( true )
        {
          Paint.end();
          P->drawPixmap( cx, y, LineBuffer, cx, 0, cw, LineHeight ); // bitBlt directly impossible: lack of real coord

          // copy to screen
//        bitBlt( viewport(), cx - contentsX(), y - contentsY(),
//                &LineBuffer, cx, 0, cw, LineHeight );

          ++l;
          y += LineHeight;

          if( l > AffectedLines.end() )
            break;

          // to avoid flickers we first paint to the linebuffer
          Paint.begin( TQT_TQPAINTDEVICE(&LineBuffer), this );

          KColumn *C = RedrawColumns.first();
          Paint.translate( C->x(), 0 );

          for( ; C; C=RedrawColumns.next() )
          {
            C->paintNextLine( &Paint );
            Paint.translate( C->width(), 0 );
          }

          if( HorizontalGrid && cx < TotalWidth )
            Paint.drawLine( cx, LineHeight-1, TotalWidth-1, LineHeight-1 );  // TODO: use a additional TotalHeight?
        }
      }
    }

    // draw empty columns?
    AffectedYs.setStart( totalHeight() );
    if( AffectedYs.isValid() )
    {
      for( KColumn *C = RedrawColumns.first(); C; C=RedrawColumns.next() )
        C->paintEmptyColumn( P, AffectedXs, AffectedYs );
    }
  }

  // Paint empty rects
  AffectedXs.setStart( TotalWidth );
  if( AffectedXs.isValid() )
    paintEmptyArea( P, AffectedXs.start(), cy, AffectedXs.width(), ch );
}
Example #3
0
void KBufferRanges::addChangedRange( KSection S )
{
    addChangedRange( KCoordRange(Layout->coordOfIndex(S.start()),Layout->coordOfIndex(S.end())) );
}
Example #4
0
void KBufferRanges::setSelectionEnd( int EndIndex )
{
    KSection OldSelection = Selection;
    Selection.setEnd( EndIndex );

    // TODO: think about rather building a diff of the sections
    if( !OldSelection.isValid() )
    {
        addChangedRange( Selection );
        return;
    }
    if( !Selection.isValid() )
    {
        addChangedRange( OldSelection );
        return;
    }

    if( OldSelection == Selection )
        return;
    int CS_;
    int CE_;
    // changes at the end?
    if( Selection.start() == OldSelection.start() )
    {
        CS_ = OldSelection.end()+1;
        CE_ = Selection.end();
        if( CE_ < CS_ )
        {
            CS_ = Selection.end()+1;
            CE_ = OldSelection.end();
        }
    }
    // changes at the start?
    else if( Selection.end() == OldSelection.end() )
    {
        CS_ = OldSelection.start();
        CE_ = Selection.start()-1;
        if( CE_ < CS_ )
        {
            CS_ = Selection.start();
            CE_ = OldSelection.start()-1;
        }
    }
    // change over the anchor
    else
    {
        CS_ = OldSelection.start();
        CE_ = Selection.end();
        if( CE_ < CS_ )
        {
            CS_ = Selection.start();
            CE_ = OldSelection.end();
        }
    }
    KSection C( CS_, CE_ );

    bool Changed = C.isValid();
    if( Changed )
        addChangedRange( C );
    return;
}
Example #5
0
void KEditor::doEditAction( KEditAction Action )
{
  KSection ChangedRange;

  HexEdit->pauseCursor( true );

  switch( Action )
  {
    case CharDelete:
      if( !HexEdit->OverWrite )
      {
        int Index = BufferCursor->realIndex();
        if( Index < HexEdit->BufferLayout->length() )
        {
          ChangedRange = HexEdit->removeData( KSection(Index,1,false) );
          if( Index == HexEdit->BufferLayout->length() )
            BufferCursor->gotoEnd();
        }
      }
      break;

      case WordDelete: // kills data until the start of the next word
        if( !HexEdit->OverWrite )
        {
          int Index = BufferCursor->realIndex();
          if( Index < HexEdit->BufferLayout->length() )
          {
            KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
            int End = WBS.indexOfBeforeNextWordStart( Index );
            ChangedRange = HexEdit->removeData( KSection(Index,End) );
            if( Index == HexEdit->BufferLayout->length() )
              BufferCursor->gotoEnd();
          }
        }
        break;

    case CharBackspace:
      if( HexEdit->OverWrite )
        BufferCursor->gotoPreviousByte();
      else
      {
        int DeleteIndex = BufferCursor->realIndex() - 1;
        if( DeleteIndex >= 0 )
        {
          ChangedRange = HexEdit->removeData( KSection(DeleteIndex,1,false) );
          if( DeleteIndex == HexEdit->BufferLayout->length() )
            BufferCursor->gotoEnd();
          else
            BufferCursor->gotoPreviousByte();
        }
      }
      break;
    case WordBackspace:
    {
      int LeftIndex = BufferCursor->realIndex() - 1;
      if( LeftIndex >= 0 )
      {
        KWordBufferService WBS( HexEdit->DataBuffer, HexEdit->Codec );
        int WordStart = WBS.indexOfPreviousWordStart( LeftIndex );
        if( !HexEdit->OverWrite )
          ChangedRange = HexEdit->removeData( KSection(WordStart,LeftIndex) );
        if( WordStart == HexEdit->BufferLayout->length() )
          BufferCursor->gotoEnd();
        else
          BufferCursor->gotoIndex(WordStart);
      }
    }
  }

  HexEdit->repaintChanged();
  HexEdit->ensureCursorVisible();

  HexEdit->unpauseCursor();

  emit HexEdit->cursorPositionChanged( BufferCursor->index() );
  if( ChangedRange.isValid() ) emit HexEdit->bufferChanged( ChangedRange.start(), ChangedRange.end() );
}