Source Code (Use browser search to find items of interest.)
Class Index
khexedit'CHexBuffer (./kdeutils/khexedit/hexbuffer.h:1033)
class CHexBuffer : public QByteArray
{
public:
enum EColumn
{
VisibleColumn = 0x0,
OffsetColumn = 0x1,
PrimaryColumn = 0x2,
SecondaryColumn = 0x4,
EveryColumn = 0x7
};
enum EEditArea
{
edit_none = 0,
edit_primary,
edit_secondary
};
enum ECursorMode
{
cursor_curr = 0,
cursor_prev
};
enum EEditMode
{
EditInsert = 0,
EditReplace
};
enum EUndoState
{
UndoOk = 1,
RedoOk = 2
};
public:
CHexBuffer( void );
~CHexBuffer( void );
int setLayout( SDisplayLayout &layout );
void setColor( SDisplayColor &color );
void setInputMode( SDisplayInputMode &mode );
bool toggleEditor( void );
bool matchWidth( uint width );
void setNonPrintChar( char nonPrintChar );
void setShowCursor( bool showCursor );
void setDisableCursor( bool disableCursor );
void setCursorShapeModifier( bool alwaysBlock, bool thickInsert );
void setEditMode( EEditMode editMode );
void setEditMode( EEditMode editMode, bool alwaysBlock, bool thickInsert );
void setMaximumSize( uint size );
void setDocumentSize( uint size );
void setUndoLevel( uint level );
void setSoundState( bool inputSound, bool fatalSound );
void setFont( const SDisplayFontInfo &fontInfo );
int setEncoding( CConversion::EMode mode, CProgress &p );
bool setCursorPosition( int x, int y, bool init, bool cellLevel );
int readFile( QFile &file, const QString &url, CProgress &p );
int insertFile( QFile &file, CProgress &p );
int writeFile( QFile &file, CProgress &p );
int newFile( const QString &url );
void closeFile( void );
void registerDiskModifyTime( const QFile &file );
bool changedOnDisk( void );
void drawText( QPainter &paint, uint line, int sx, int x, int w );
void drawText( QPainter &paint, uint line, int x1, int x2, int y,
bool useBlackWhite );
void drawHeader( QPainter &paint, int sx, int width, int y, bool isFooter,
const SPageHeader &header,const SPagePosition &position );
int headerHeight( QPainter &paint );
int headerMargin( QPainter &paint );
bool inputAtCursor( QChar c );
int inputAtCursor( const QByteArray &buf, uint oldSize );
bool removeAtCursor( bool beforeCursor );
int locateRange( const SExportRange &range, uint &start, uint &stop );
int exportText( const SExportText &ex, CProgress &p );
int exportHtml( const SExportHtml &ex, CProgress &p );
int exportCArray( const SExportCArray &ex, CProgress &p );
int copySelectedText( QByteArray &array, int columnSegment=VisibleColumn);
int copyAllText( QByteArray &array );
int copyText( QByteArray &array, const SExportRange &range,
int columnSegment );
int copySelectedData( QByteArray &array );
uint numPage( CHexPrinter &printer );
int print( CHexPrinter &printer, CProgress &p );
uint printLine( char *dst, uint line );
uint printLine( char *dst, uint line, int columnSegment );
bool cutSelection( void );
bool undo( void );
bool redo( void );
int addBookmark( int position );
bool removeBookmark( int position );
int findFirst( SSearchControl &sc );
int findNext( SSearchControl &sc );
int findWrap( SSearchControl &sc );
int replaceAll( SSearchControl &sc, bool init );
int replaceMarked( SSearchControl &sc );
int filter( SFilterControl &fc );
int collectStrings( CStringCollectControl &sc );
int collectStatistic( SStatisticControl &sc, CProgress &p );
void doActionGroup( CHexActionGroup *group );
void doAction( CHexAction *action );
inline SCursorState &cursorState( void );
inline void valueOnCursor( QByteArray &buf, uint size );
inline SFileState &fileState( void );
inline const SDisplayLayout &layout( void );
inline const SDisplayInputMode &inputMode( void );
inline QList<SCursorOffset> &bookmarkList( void );
inline bool documentPresent( void );
inline bool modified( void );
inline uint undoState( void );
inline uint documentSize( void );
inline EEditMode editMode( void );
inline const SEncodeState &encoding( void );
inline bool losslessEncoding( CConversion::EMode mode );
inline QString &url( void );
bool hasFileName( void );
inline void setUrl( const QString &url );
inline const QDateTime &diskModifyTime( void );
inline uint calculateLine( uint offset );
inline int lineSize( void );
inline int lineHeight( void );
inline int fontAscent( void );
inline int lineWidth( void );
inline int unitWidth( void );
inline int numLines( void );
inline int totalHeight( void );
inline const QFont &font( void );
inline SCursor *textCursor( void );
inline const QColor &backgroundColor( void );
inline int startX( void );
inline int startY( void );
inline void setStartX( int val );
inline void setStartY( int val );
inline bool selectionSet( uint offset, bool init );
inline void selectionSyncronize( void );
inline void selectionStartChange( uint &offset1, uint &offset2 );
inline void selectionStopChange( uint &offset1, uint &offset2 );
inline bool cursorInsideSelection( void );
inline void markSet( uint offset, uint size );
inline bool markSet( uint offset, bool init );
inline bool markRemove( void );
inline void markSyncronize( void );
inline void markStartChange( uint &offset1, uint &offset2 );
inline void markStopChange( uint &offset1, uint &offset2 );
inline uint cursorOffset( void );
inline uint cursorBit( void );
inline uint cursorLine( void );
inline uint prevCursorLine( void );
inline SCursor &cursor( void );
inline void currCursor( EEditArea editArea, SCursorPosition &p );
inline void prevCursor( EEditArea editArea, SCursorPosition &p );
inline void cursorUp( uint lines );
inline void cursorDown( uint lines );
inline void cursorRight( bool cellLevel );
inline void cursorLeft( bool cellLevel );
inline void cursorStep( uint size, bool forward, bool modulo );
inline void cursorHome( bool toExtreme );
inline void cursorEnd( bool toExtreme );
inline void cursorGoto( uint offset, uint bit );
inline void cursorGoto( uint offset, uint bit, bool backward,
bool fromCursor );
inline bool cursorChanged( void );
inline void cursorResetEditArea( void );
inline bool cursorPrimaryEdit( void );
inline int cursorFixedPosition( int position, int height );
inline int cursorChangePosition( int position, int height );
void cursorReset( void );
private:
void computeLineWidth( void );
void computeNumLines( void );
void cursorCompute( void );
void drawSelection( QPainter &paint, QColor &color, uint start, uint stop,
int sx );
void drawCursor( QPainter &paint, uint line, int startx );
void recordStart( SCursor &cursor );
void recordReplace( SCursor &cursor, uint size, char *data, uint dataSize);
void recordEnd( SCursor &cursor );
void doReplace( CHexAction *hexAction, bool removeData );
int scanData( SSearchControl &sc, bool init );
int initScanData( SSearchControl &sc );
inline const QColor &foregroundColor( uint column );
inline int printDummyCell( char *buf, unsigned char data );
inline int printHexadecimalBigCell( char *buf, unsigned char data );
inline int printHexadecimalSmallCell( char *buf, unsigned char data );
inline int printDecimalCell( char *buf, unsigned char data );
inline int printOctalCell( char *buf, unsigned char data );
inline int printBinaryCell( char *buf, unsigned char data );
inline int printAsciiCell( char *buf, unsigned char data );
inline void printDummyOffset( char *buf, uint offset );
inline void printHexadecimalBigOffset( char *buf, uint offset );
inline void printHexadecimalSmallOffset( char *buf, uint offset );
inline void printDecimalOffset( char *buf, uint offset );
bool inputDummy( unsigned char *dest, int value, uint cell );
bool inputHexadecimal( unsigned char *dest, int value, uint cell );
bool inputDecimal( unsigned char *dest, int value, uint cell );
bool inputOctal( unsigned char *dest, int value, uint cell );
bool inputBinary( unsigned char *dest, int value, uint cell );
bool inputAscii( unsigned char *dest, int value, uint cell );
int moveBuffer( uint destOffset, uint srcOffset );
int resizeBuffer( uint offset );
void inputSound( void );
void fatalSound( void );
int printHtmlDataPage( const QString &tocName,
const QStringList &fileNames, uint index,
const SExportHtml &ex, uint line, uint numLine );
void printHtmlCaption( QTextStream &os, uint captionType, uint curPage,
uint numPage );
void printHtmlNavigator( QTextStream &os, const QString *next,
const QString *prev, const QString *toc );
void printHtmlTocPage( const QString &tocName,
const QString &linkName,
const QStringList &fileNames,
const QStringList &offsets, uint numPage );
int printHtmlHeader( QTextStream &os, bool isFront );
int printHtmlTable( QTextStream &os, uint line, uint numLine, bool bw );
int printHtmlLine( QTextStream &os, uint offset, bool isPrimary, bool bw );
signals:
void fileSize( uint size );
private:
QString mUrl;
QDateTime mDiskModifyTime;
SDisplayLayout mLayout;
SDisplayColor mColor;
SDisplayFontInfo mFontInfo;
CConversion mEncode;
bool mCharValid[256];
char *mColorIndex;
char *mPrintBuf;
bool mLoadingData;
int mStartX;
int mStartY;
int mFontHeight;
int mFontAscent;
int mLineWidth;
int mFixedWidth;
int mUnitWidth;
int mSplitWidth;
int mNumLines;
int mTextStart1;
int mTextStart2;
int mNumCell;
uint mDocumentSize;
uint mMaximumSize;
bool mFixedSizeMode;
bool mDocumentModified;
EEditMode mEditMode;
SDisplayInputMode mInputMode;
int mOffsetSize;
int mOffsetIndex;
int mPrimaryWidth;
int mSecondaryWidth;
int mActiveEditor;
SSelect mSelect;
SSelect mMark;
SCursor mCursor;
bool mShowCursor;
bool mDisableCursor;
bool mInputErrorSound;
bool mFatalErrorSound;
uint mUndoLimit;
uint mUndoIndex;
QList<CHexActionGroup> mUndoList;
QList<SCursorOffset> mBookmarkList;
PrintCellFunc printCell;
PrintOffsetFunc printOffset;
InputCellFunc inputCell;
};
inline SCursorState &CHexBuffer::cursorState( void )
{
static SCursorState state;
if( size() == 0 )
{
state.valid = false;
state.selectionOffset = 0;
state.selectionSize = 0;
state.offset = 0;
state.cell = 0;
state.undoState = 0;
memset( state.data, 0, sizeof(state.data) );
state.charValid = false;
}
else
{
state.valid = true;
state.selectionOffset = mSelect.start();
state.selectionSize = mSelect.size();
state.offset = cursorOffset();
state.cell = cursorBit();
state.undoState = undoState();
for( uint i = 0; i < sizeof( state.data ); i++ )
{
state.data[i] = (state.offset+i >= mDocumentSize) ? 0 :
(unsigned char)data()[state.offset+i];
}
state.charValid = mCharValid[ state.data[0] ];
}
return( state );
}
inline void CHexBuffer::valueOnCursor( QByteArray &buf, uint size )
{
int offset = cursorOffset();
if( offset + size >= mDocumentSize )
{
size = mDocumentSize - offset;
}
buf.resize(size);
for( uint i=0; i<buf.size(); i++)
{
buf[i] = (unsigned char)data()[offset+i];
}
}
inline const SDisplayLayout &CHexBuffer::layout( void )
{
return( mLayout );
}
inline const SDisplayInputMode &CHexBuffer::inputMode( void )
{
return( mInputMode );
}
inline QList<SCursorOffset> &CHexBuffer::bookmarkList( void )
{
return( mBookmarkList );
}
inline SFileState &CHexBuffer::fileState( void )
{
static SFileState state;
if( size() == 0 )
{
state.valid = false;
state.size = 0;
state.modified = false;
}
else
{
state.valid = true;
state.size = mDocumentSize;
state.modified = mDocumentModified;
}
return( state );
}
inline bool CHexBuffer::modified( void )
{
return( mDocumentModified );
}
inline uint CHexBuffer::undoState( void )
{
return( (mUndoIndex > 0 ? UndoOk : 0) |
(mUndoIndex < mUndoList.count() ? RedoOk : 0) );
}
inline uint CHexBuffer::documentSize( void )
{
return( mDocumentSize );
}
inline CHexBuffer::EEditMode CHexBuffer::editMode( void )
{
return( mEditMode );
}
inline const SEncodeState &CHexBuffer::encoding( void )
{
return( mEncode.state() );
}
inline bool CHexBuffer::losslessEncoding( CConversion::EMode mode )
{
return( mEncode.lossless(mode) );
}
inline QString &CHexBuffer::url( void )
{
return( mUrl );
}
inline bool CHexBuffer::documentPresent( void )
{
return( size() == 0 ? false : true );
}
inline void CHexBuffer::setUrl( const QString &url )
{
mUrl = url;
}
inline const QDateTime &CHexBuffer::diskModifyTime( void )
{
return( mDiskModifyTime );
}
inline uint CHexBuffer::calculateLine( uint offset )
{
return( mLayout.lineSize == 0 ? 0 : offset / mLayout.lineSize );
}
inline const QColor &CHexBuffer::foregroundColor( uint column )
{
if( column > mLayout.lineSize )
{
return( Qt::black );
}
else
{
return( mColor.primaryFg[ mColorIndex[ column ] ] );
}
}
inline bool CHexBuffer::selectionSet( uint offset, bool init )
{
if( offset >= size() ) { offset = size() > 0 ? size() - 1 : 0; }
if( init == true )
{
return( mSelect.init( offset ) );
}
else
{
return( mSelect.set( offset ) );
}
}
inline void CHexBuffer::selectionSyncronize( void )
{
mSelect.sync();
}
inline void CHexBuffer::selectionStartChange( uint &offset1, uint &offset2 )
{
mSelect.startChange( offset1, offset2 );
}
inline void CHexBuffer::selectionStopChange( uint &offset1, uint &offset2 )
{
mSelect.stopChange( offset1, offset2 );
}
inline bool CHexBuffer::cursorInsideSelection( void )
{
return( mSelect.inside( cursorOffset() ) );
}
inline void CHexBuffer::markSet( uint offset, uint size )
{
markSet( offset, true );
markSet( offset+size, false );
mMark.sync();
}
inline bool CHexBuffer::markSet( uint offset, bool init )
{
if( offset >= size() ) { offset = size() > 0 ? size() - 1 : 0; }
if( init == true )
{
return( mMark.init( offset ) );
}
else
{
return( mMark.set( offset ) );
}
}
inline bool CHexBuffer::markRemove( void )
{
return( mMark.init( mMark.start() ) );
}
inline void CHexBuffer::markSyncronize( void )
{
mMark.sync();
}
inline void CHexBuffer::markStartChange( uint &offset1, uint &offset2 )
{
mMark.startChange( offset1, offset2 );
}
inline void CHexBuffer::markStopChange( uint &offset1, uint &offset2 )
{
mMark.stopChange( offset1, offset2 );
}
inline uint CHexBuffer::cursorOffset( void )
{
return( mCursor.curr.offset );
}
inline uint CHexBuffer::cursorBit( void )
{
return( mCursor.bit() );
}
inline uint CHexBuffer::cursorLine( void )
{
return( mCursor.curr.y / lineHeight() );
}
inline uint CHexBuffer::prevCursorLine( void )
{
return( mCursor.prev.y / lineHeight() );
}
inline SCursor &CHexBuffer::cursor( void )
{
return( mCursor );
}
inline void CHexBuffer::currCursor( EEditArea editArea, SCursorPosition &p )
{
if( editArea == edit_primary )
{
if( mActiveEditor == edit_primary )
{
p.x = mCursor.curr.drawX1();
p.w = mCursor.curr.width1();
}
else
{
p.x = mCursor.curr.drawX2();
p.w = mUnitWidth;
}
}
else
{
if( mActiveEditor == edit_primary )
{
p.x = mCursor.curr.drawX2();
p.w = mUnitWidth;
}
else
{
p.x = mCursor.curr.drawX1();
p.w = mUnitWidth * mNumCell;
}
}
p.x -= mStartX;
p.y = mCursor.curr.y - mStartY;
p.h = lineHeight();
}
inline void CHexBuffer::prevCursor( EEditArea editArea, SCursorPosition &p )
{
if( editArea == edit_primary )
{
if( mActiveEditor == edit_primary )
{
p.x = mCursor.prev.drawX1();
p.w = mUnitWidth * mNumCell;
}
else
{
p.x = mCursor.prev.drawX2();
p.w = mUnitWidth;
}
}
else
{
if( mActiveEditor == edit_primary )
{
p.x = mCursor.prev.drawX2();
p.w = mUnitWidth;
}
else
{
p.x = mCursor.prev.drawX1();
p.w = mUnitWidth * mNumCell;
}
}
p.x -= mStartX;
p.y = mCursor.prev.y - mStartY;
p.h = lineHeight();
}
inline void CHexBuffer::cursorUp( uint lines )
{
mCursor.up( lines );
cursorCompute();
}
inline void CHexBuffer::cursorDown( uint lines )
{
mCursor.down( lines );
cursorCompute();
}
inline void CHexBuffer::cursorRight( bool cellLevel )
{
if( cellLevel == true && mActiveEditor == edit_primary )
{
mCursor.incCell();
}
else
{
mCursor.addOffset( 1 );
}
cursorCompute();
}
inline void CHexBuffer::cursorStep( uint size, bool forward, bool modulo )
{
if( forward == true )
{
if( modulo == true )
{
uint offset = mCursor.getOffset() + size;
mCursor.setOffset( offset - offset % size );
}
else
{
mCursor.addOffset( size );
}
}
else
{
if( modulo == true )
{
uint offset = mCursor.getOffset();
if( offset % size )
{
mCursor.decOffset( offset % size, false );
}
else
{
mCursor.setOffset( offset < size ? 0 : offset - size );
}
}
else
{
mCursor.decOffset( size, false );
}
}
cursorCompute();
}
inline void CHexBuffer::cursorLeft( bool cellLevel )
{
if( cellLevel == true && mActiveEditor == edit_primary )
{
mCursor.decCell();
}
else
{
mCursor.decOffset( 1, false );
}
cursorCompute();
}
inline void CHexBuffer::cursorHome( bool toExtreme )
{
mCursor.home( toExtreme );
cursorCompute();
}
inline void CHexBuffer::cursorEnd( bool toExtreme )
{
mCursor.end( toExtreme );
cursorCompute();
}
inline void CHexBuffer::cursorGoto( uint offset, uint bit, bool backward,
bool fromCursor )
{
uint maxOffset = mFixedSizeMode == true ? mMaximumSize-1 : documentSize();
mCursor.setOffset( offset, bit, backward, fromCursor, maxOffset );
cursorCompute();
}
inline void CHexBuffer::cursorGoto( uint offset, uint bit )
{
mCursor.setOffset( offset );
mCursor.setBit( bit );
cursorCompute();
}
inline bool CHexBuffer::cursorChanged( void )
{
return( mCursor.changed() );
}
inline void CHexBuffer::cursorResetEditArea( void )
{
mCursor.setArea( edit_none );
}
inline bool CHexBuffer::cursorPrimaryEdit( void )
{
return( mActiveEditor == edit_primary ? true : false );
}
inline int CHexBuffer::cursorFixedPosition( int position, int height )
{
position += mCursor.curr.y - mCursor.prev.y;
if( position < 0 )
{
return( 0 );
}
else if( position + height > totalHeight() )
{
return( height > totalHeight() ? 0 : totalHeight() - height );
}
else
{
if( mCursor.curr.y < position )
{
return( mCursor.curr.y );
}
else if( mCursor.curr.y > position + height )
{
return( mCursor.curr.y - height + lineHeight() );
}
else
{
return( position );
}
}
}
inline int CHexBuffer::cursorChangePosition( int position, int height )
{
if( mCursor.curr.y < position || mCursor.curr.y > position + height )
{
// When cursor is at top of window
position = mCursor.curr.y;
}
else if( mCursor.curr.y > position + height - lineHeight() )
{
// When cursor is at bottom of window
position = mCursor.curr.y - height + lineHeight();
}
return( position );
}
inline int CHexBuffer::printDummyCell( char *buf, unsigned char )
{
buf[0] = 0;
return( 0 );
}
inline int CHexBuffer::printHexadecimalBigCell( char *buf, unsigned char data )
{
static char hexBuffer[16]=
{
'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
};
buf[0] = hexBuffer[ (data>>4)&0x0F ];
buf[1] = hexBuffer[ data&0x0F ];
return( 0 );
}
inline int CHexBuffer::printHexadecimalSmallCell( char *buf,
unsigned char data )
{
static char hexBuffer[16]=
{
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
};
buf[0] = hexBuffer[ (data>>4)&0x0F ];
buf[1] = hexBuffer[ data&0x0F ];
return( 0 );
}
inline int CHexBuffer::printDecimalCell( char *buf, unsigned char data )
{
static char decBuffer[10]=
{
'0','1','2','3','4','5','6','7','8','9'
};
buf[0] = decBuffer[ data/100 ];
data -= (data/100) * 100;
buf[1] = decBuffer[ data/10 ];
data -= (data/10) * 10;
buf[2] = decBuffer[ data ];
return( 0 );
}
inline int CHexBuffer::printOctalCell( char *buf, unsigned char data )
{
static char hexBuffer[8]=
{
'0','1','2','3','4','5','6','7'
};
buf[0] = hexBuffer[ (data>>6)&0x07 ];
buf[1] = hexBuffer[ (data>>3)&0x07 ];
buf[2] = hexBuffer[ data&0x07 ];
return( 0 );
}
inline int CHexBuffer::printBinaryCell( char *buf, unsigned char data )
{
for( int i = 0; i < 8; i++ )
{
buf[7-i] = (data&(1<<i)) ? '1' : '0';
}
return( 0 );
}
inline int CHexBuffer::printAsciiCell( char *buf, unsigned char data )
{
if( mCharValid[data] == 0 )
{
buf[0] = mFontInfo.nonPrintChar;
return( 1 );
}
else
{
buf[0] = data;
return( 0 );
}
}
inline void CHexBuffer::printDummyOffset( char *buf, uint /*offset*/ )
{
buf[0] = 0;
}
inline void CHexBuffer::printHexadecimalBigOffset( char *buf, uint offset )
{
sprintf( buf, "%04X:%04X", offset>>16, offset&0x0000FFFF );
}
inline void CHexBuffer::printHexadecimalSmallOffset( char *buf, uint offset )
{
sprintf( buf, "%04x:%04x", offset>>16, offset&0x0000FFFF );
}
inline void CHexBuffer::printDecimalOffset( char *buf, uint offset )
{
sprintf( buf, "%010u", offset );
}
inline int CHexBuffer::lineSize( void )
{
return( mLayout.lineSize );
}
inline int CHexBuffer::lineHeight( void )
{
return( mFontHeight + mLayout.horzGridWidth );
}
inline int CHexBuffer::fontAscent( void )
{
return( mFontAscent );
}
inline int CHexBuffer::lineWidth( void )
{
return( mLineWidth );
}
inline int CHexBuffer::unitWidth( void )
{
return( mUnitWidth );
}
inline int CHexBuffer::numLines( void )
{
return( mNumLines );
}
inline int CHexBuffer::totalHeight( void )
{
return( mNumLines * (mFontHeight+mLayout.horzGridWidth) );
}
inline const QFont &CHexBuffer::font( void )
{
return( mFontInfo.font );
}
inline SCursor *CHexBuffer::textCursor( void )
{
return( &mCursor );
}
inline const QColor &CHexBuffer::backgroundColor( void )
{
return( documentPresent() == true ? mColor.textBg : mColor.inactiveBg );
}
inline int CHexBuffer::startX( void )
{
return( mStartX );
}
inline int CHexBuffer::startY( void )
{
return( mStartY );
}
inline void CHexBuffer::setStartX( int val )
{
mStartX = val;
}
inline void CHexBuffer::setStartY( int val )
{
mStartY = val;
}
khexedit'CHexBuffer::CHexBuffer() (./kdeutils/khexedit/hexbuffer.cc:483)
CHexBuffer::CHexBuffer( void )
:QByteArray()
{
mColorIndex = 0;
mPrintBuf = 0;
mLoadingData = false;
mEditMode = EditReplace;
mActiveEditor = edit_primary;
mDocumentModified = false;
setDocumentSize(0);
#ifdef DEBUG_FIXED_SIZE
setMaximumSize( DEBUG_FIXED_SIZE );
#else
setMaximumSize( ~0 );
#endif
#ifdef PRINTER_TEST
puts("<CHexBuffer> Printer test is activated");
#endif
setInputMode( mInputMode );
int errCode = setLayout( mLayout );
if( errCode != 0 )
{
return;
}
setColor( mColor );
setFont( mFontInfo.init() );
setShowCursor( true );
setDisableCursor( false );
setEditMode( EditReplace, false, false );
setSoundState( false, false );
mUndoLimit = 10;
mUndoIndex = 0;
mUndoList.setAutoDelete( TRUE );
mBookmarkList.setAutoDelete( TRUE );
}
khexedit'CHexBuffer::~CHexBuffer() (./kdeutils/khexedit/hexbuffer.cc:527)
CHexBuffer::~CHexBuffer( void )
{
//debug("CHexBuffer::~CHexBuffer");
delete [] mColorIndex;
delete [] mPrintBuf;
}
khexedit'CHexBuffer::hasFileName() (./kdeutils/khexedit/hexbuffer.cc:536)
bool CHexBuffer::hasFileName( void )
{
//
// FIXME: Files can be called "Untitled" so this must be corrected.
//
if( mUrl.isEmpty() || mUrl.contains( i18n( "Untitled" ), false ) )
{
return( false );
}
else
{
return( true );
}
}
khexedit'CHexBuffer::setLayout() (./kdeutils/khexedit/hexbuffer.cc:553)
int CHexBuffer::setLayout( SDisplayLayout &layout )
{
mLayout = layout;
mLayout.verify();
if( mLayout.primaryMode == SDisplayLayout::textOnly )
{
mActiveEditor = edit_primary;
setEditMode( mEditMode );
}
mCursor.setLineSize( mLayout.lineSize );
mCursor.addOffset( 0 ); // This will only reset the cell position
computeLineWidth();
cursorCompute();
delete [] mColorIndex; mColorIndex = 0;
delete [] mPrintBuf; mPrintBuf = 0;
mColorIndex = new char[ mLayout.lineSize ];
if( mColorIndex == 0 )
{
return( Err_NoMemory );
}
setColor( mColor );
//
// The 'mPrintBuf' is used to store formatted text. It is used for all
// print operations and must have the size of the 'mDpyState.lineSize' which
// is the number of bytes in one single display line.
//
mPrintBuf = new char[ mLayout.lineSize < 12 ? 12 : mLayout.lineSize ];
if( mPrintBuf == 0 )
{
delete [] mColorIndex; mColorIndex = 0;
return( Err_NoMemory );
}
return( Err_Success );
}
khexedit'CHexBuffer::setColor() (./kdeutils/khexedit/hexbuffer.cc:596)
void CHexBuffer::setColor( SDisplayColor &color )
{
mColor = color;
//
// Test...
//
//mColor.secondTextBg = Qt::yellow;
//mColor.offsetBg = Qt::lightGray;
//mColor.gridFg = Qt::darkCyan;
/*
mColor.secondTextBg = mColor.textBg;
mColor.offsetBg = mColor.textBg;
mColor.gridFg = mColor.textBg;
*/
if( mColorIndex != 0 )
{
uint columnSize = mLayout.columnSize == 0 ? 1 : mLayout.columnSize;
for( uint i = 0, entry = 0; i < mLayout.lineSize; i++ )
{
if( i > 0 && i % columnSize == 0 ) { entry = entry == 0 ? 1 : 0; }
mColorIndex[i] = entry;
}
}
}
khexedit'CHexBuffer::setInputMode() (./kdeutils/khexedit/hexbuffer.cc:624)
void CHexBuffer::setInputMode( SDisplayInputMode &mode )
{
mInputMode = mode;
if( mInputMode.allowResize == false && mEditMode != EditReplace )
{
setEditMode( EditReplace );
}
}
khexedit'CHexBuffer::toggleEditor() (./kdeutils/khexedit/hexbuffer.cc:634)
inline bool CHexBuffer::toggleEditor( void )
{
bool changed;
if( mLayout.secondaryMode == SDisplayLayout::hide )
{
changed = mActiveEditor == edit_secondary ? true : false;
mActiveEditor = edit_primary;
}
else
{
changed = true;
mActiveEditor = mActiveEditor == edit_primary ?
edit_secondary : edit_primary;
}
setEditMode( mEditMode ); // Sets the cursor shapes as well
if( changed == true )
{
mCursor.resetCell();
cursorCompute();
}
return( changed );
}
khexedit'CHexBuffer::matchWidth() (./kdeutils/khexedit/hexbuffer.cc:666)
bool CHexBuffer::matchWidth( uint width )
{
if( documentPresent() == false || (uint)mFixedWidth >= width )
{
return( false );
}
width -= mFixedWidth;
uint g = mLayout.columnSpacing == 0 ? 1 : mLayout.columnSize;
uint n = g * mNumCell;
uint u = mUnitWidth;
uint s = mLayout.secondaryMode == SDisplayLayout::hide ? 0 : g;
uint o = mLayout.columnSpacing == 0 ? 0 : mSplitWidth;
float x = (float)(width+o)/(float)(u*(n+s)+o);
uint lineSize = (uint)x * g;
if( mLayout.lockColumn == false )
{
//
// Examine if we can add one or more entries from the next column. This
// will make the rightmost column smaller than the rest but we will
// utilize as much of the available space (ie., width) as possible.
// (Note that the entry itself (which represents one byte of filedata)
// can not be splitted, eg., in binary mode the entry is eight byte
// wide and will not be splitted).
//
int w = (int)((float)((int)x)* (float)(u*(n+s)+o) - (float)o);
if( w > 0 && (uint)w < width )
{
width -= w;
if( width > o )
{
x = (float)(width-o) / (float)(u*(mNumCell+1));
lineSize += (uint)x;
}
}
}
if( lineSize == 0 || lineSize == mLayout.lineSize )
{
//
// We have to redraw all text if a change occurs so we avoid it if
// possible.
//
return( false );
}
mLayout.lineSize = lineSize;
setLayout( mLayout );
return( true );
}
khexedit'CHexBuffer::setNonPrintChar() (./kdeutils/khexedit/hexbuffer.cc:721)
void CHexBuffer::setNonPrintChar( char nonPrintChar )
{
mFontInfo.nonPrintChar = nonPrintChar;
}
khexedit'CHexBuffer::setShowCursor() (./kdeutils/khexedit/hexbuffer.cc:727)
void CHexBuffer::setShowCursor( bool showCursor )
{
mShowCursor = showCursor;
}
khexedit'CHexBuffer::setDisableCursor() (./kdeutils/khexedit/hexbuffer.cc:733)
void CHexBuffer::setDisableCursor( bool disableCursor )
{
mDisableCursor = disableCursor;
}
khexedit'CHexBuffer::setCursorShapeModifier() (./kdeutils/khexedit/hexbuffer.cc:739)
void CHexBuffer::setCursorShapeModifier( bool alwaysBlock, bool thickInsert )
{
mCursor.setShapeModifier( alwaysBlock, thickInsert );
setEditMode( mEditMode );
}
khexedit'CHexBuffer::setEditMode() (./kdeutils/khexedit/hexbuffer.cc:745)
void CHexBuffer::setEditMode( EEditMode editMode, bool alwaysBlock,
bool thickInsert )
{
mCursor.setShapeModifier( alwaysBlock, thickInsert );
setEditMode( editMode );
}
khexedit'CHexBuffer::setEditMode() (./kdeutils/khexedit/hexbuffer.cc:752)
void CHexBuffer::setEditMode( EEditMode editMode )
{
mEditMode = editMode;
if( mEditMode == EditInsert )
{
if( mActiveEditor == edit_primary )
{
mCursor.setShape( SCursorSpec::thin, SCursorSpec::frame, mUnitWidth,
mNumCell );
}
else
{
mCursor.setShape( SCursorSpec::frame, SCursorSpec::thin, mUnitWidth,
mNumCell );
}
}
else
{
if( mActiveEditor == edit_primary )
{
mCursor.setShape( SCursorSpec::solid, SCursorSpec::frame, mUnitWidth,
mNumCell );
}
else
{
mCursor.setShape( SCursorSpec::frame, SCursorSpec::solid, mUnitWidth,
mNumCell );
}
}
}
khexedit'CHexBuffer::setMaximumSize() (./kdeutils/khexedit/hexbuffer.cc:786)
void CHexBuffer::setMaximumSize( uint maximumSize )
{
if( maximumSize == 0 ) { maximumSize = ~0; }
mMaximumSize = maximumSize;
mFixedSizeMode = maximumSize == (uint)~0 ? false : true;
mCursor.setFixedSizeMode( mFixedSizeMode );
if( mLayout.offsetVisible == false )
{
mOffsetSize = 0;
mOffsetIndex = 0;
printOffset = &CHexBuffer::printDummyOffset;
}
else
{
if( mLayout.offsetMode == SDisplayLayout::decimal )
{
printOffset = &CHexBuffer::printDecimalOffset;
for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
{
maximumSize = maximumSize / 10;
}
mOffsetIndex = 10 - mOffsetSize;
}
else if( mLayout.offsetMode == SDisplayLayout::hexadecimal )
{
if( mLayout.offsetUpperCase == true )
{
printOffset = &CHexBuffer::printHexadecimalBigOffset;
}
else
{
printOffset = &CHexBuffer::printHexadecimalSmallOffset;
}
for( mOffsetSize=0; maximumSize > 0; mOffsetSize += 1 )
{
maximumSize = maximumSize / 16;
}
if( mOffsetSize > 4 ) { mOffsetSize += 1; } // Space for the ':' sign
mOffsetIndex = 9 - mOffsetSize;
}
}
}
khexedit'CHexBuffer::setDocumentSize() (./kdeutils/khexedit/hexbuffer.cc:832)
void CHexBuffer::setDocumentSize( uint size )
{
if( size > mMaximumSize ) { size = mMaximumSize; }
mDocumentSize = size;
mCursor.setDocumentSize( size );
}
khexedit'CHexBuffer::setUndoLevel() (./kdeutils/khexedit/hexbuffer.cc:840)
void CHexBuffer::setUndoLevel( uint level )
{
if( level < 10 ) { level = 10; }
if( level >= mUndoLimit )
{
mUndoLimit = level;
return;
}
else
{
//
// The maximum size decreases. If the list is larger than the the new
// limit, then reduce the list size starting with the oldest elements.
//
mUndoLimit = level;
while( mUndoList.count() >= mUndoLimit )
{
mUndoList.removeFirst();
mUndoIndex -= (mUndoIndex > 0 ? 1 : 0);
}
}
}
khexedit'CHexBuffer::setSoundState() (./kdeutils/khexedit/hexbuffer.cc:865)
void CHexBuffer::setSoundState( bool inputSound, bool fatalSound )
{
mInputErrorSound = inputSound;
mFatalErrorSound = fatalSound;
}
khexedit'CHexBuffer::writeFile() (./kdeutils/khexedit/hexbuffer.cc:872)
int CHexBuffer::writeFile( QFile &file, CProgress &p )
{
uint offset = 0;
uint remaining = documentSize();
do
{
uint blockSize = remaining > 100000 ? 100000 : remaining;
int writeSize = file.writeBlock( &data()[offset], blockSize );
if( writeSize == -1 )
{
p.finish();
return( Err_ReadFailed );
}
offset += blockSize;
remaining -= blockSize;
if( p.expired() == true )
{
int errCode = p.step( (float)offset/(float)documentSize() );
if( errCode == Err_Stop && remaining > 0 )
{
p.finish();
return( Err_Success );
}
}
}
while( remaining > 0 );
p.finish();
mDocumentModified = false;
registerDiskModifyTime( file );
return( Err_Success );
}
khexedit'CHexBuffer::readFile() (./kdeutils/khexedit/hexbuffer.cc:909)
int CHexBuffer::readFile( QFile &file, const QString &url, CProgress &p )
{
if( resize( file.size() + 100 ) == false )
{
p.finish();
return( Err_NoMemory );
}
if( file.size() > 0 )
{
mLoadingData = true;
uint offset = 0;
uint remaining = file.size();
while( remaining > 0 )
{
uint blockSize = remaining > 100000 ? 100000 : remaining;
int readSize = file.readBlock( &data()[offset], blockSize );
if( readSize == -1 )
{
p.finish();
mLoadingData = false;
return( Err_ReadFailed );
}
for( uint i=0; i<blockSize; i++)
{
data()[offset+i] = mEncode[ (unsigned char) data()[offset+i] ];
}
offset += blockSize;
remaining -= blockSize;
if( p.expired() == true )
{
int errCode = p.step( (float)offset/(float)file.size() );
if( errCode == Err_Stop && remaining > 0 )
{
p.finish();
return( Err_OperationAborted );
}
}
}
mLoadingData = false;
}
p.finish();
mDocumentModified = false;
setDocumentSize( file.size() );
registerDiskModifyTime( file );
setUrl( url );
computeNumLines();
mSelect.reset();
mMark.reset();
mUndoList.clear();
mUndoIndex = 0;
return( Err_Success );
}
khexedit'CHexBuffer::insertFile() (./kdeutils/khexedit/hexbuffer.cc:969)
int CHexBuffer::insertFile( QFile &file, CProgress &p )
{
if( file.size() == 0 )
{
p.finish();
return( Err_Success );
}
QByteArray array( file.size() );
if( array.isNull() == true )
{
p.finish();
return( Err_NoMemory );
}
uint offset = 0;
uint remaining = file.size();
while( remaining > 0 )
{
uint blockSize = remaining > 100000 ? 100000 : remaining;
int readSize = file.readBlock( &array[offset], blockSize );
if( readSize == -1 )
{
p.finish();
return( Err_ReadFailed );
}
for( uint i=0; i<blockSize; i++)
{
array[offset+i] = mEncode[ (unsigned char) array[offset+i] ];
}
offset += blockSize;
remaining -= blockSize;
if( p.expired() == true )
{
int errCode = p.step( (float)offset/(float)file.size() );
if( errCode == Err_Stop && remaining > 0 )
{
p.finish();
return( Err_OperationAborted );
}
}
}
p.finish();
int errCode = inputAtCursor( array, 0 );
return( errCode );
}
khexedit'CHexBuffer::newFile() (./kdeutils/khexedit/hexbuffer.cc:1021)
int CHexBuffer::newFile( const QString &url )
{
if( resize( 100 ) == 0 )
{
return( Err_NoMemory );
}
mDocumentModified = false;
setDocumentSize( 0 );
setUrl( url );
computeNumLines();
mSelect.reset();
return( Err_Success );
}
khexedit'CHexBuffer::closeFile() (./kdeutils/khexedit/hexbuffer.cc:1038)
void CHexBuffer::closeFile( void )
{
resize(0);
computeNumLines();
mUndoList.clear();
mUndoIndex = 0;
setDocumentSize(0);
mDocumentModified = false;
QString emptyUrl;
setUrl( emptyUrl );
mSelect.reset();
mMark.reset();
}
khexedit'CHexBuffer::registerDiskModifyTime() (./kdeutils/khexedit/hexbuffer.cc:1057)
void CHexBuffer::registerDiskModifyTime( const QFile &file )
{
QFileInfo fileInfo( file );
mDiskModifyTime = fileInfo.lastModified();
}
khexedit'CHexBuffer::setFont() (./kdeutils/khexedit/hexbuffer.cc:1065)
void CHexBuffer::setFont( const SDisplayFontInfo &fontInfo )
{
mFontInfo = fontInfo;
QFontMetrics fm( mFontInfo.font );
mFontHeight = fm.height();
mFontAscent = fm.ascent();
computeLineWidth();
for( int i=0; i < 256; i++ )
{
mCharValid[i] = QChar(i).isPrint();
}
/*
QFontInfo info( mFontInfo.font );
puts("CHexBuffer mCharValid broken");
KCharset charset( info.charSet() );
for( int i=0; i < 256; i++ )
{
mCharValid[i] = charset.printable(i);
}
*/
}
khexedit'CHexBuffer::setEncoding() (./kdeutils/khexedit/hexbuffer.cc:1091)
int CHexBuffer::setEncoding( CConversion::EMode mode, CProgress &p )
{
int errCode = mEncode.convert( *this, mode, p );
if( errCode == Err_Success )
{
//
// The cursor stores the byte it is "covering", so this information
// must be updated.
//
cursorCompute();
}
return( errCode );
}
khexedit'CHexBuffer::computeLineWidth() (./kdeutils/khexedit/hexbuffer.cc:1109)
void CHexBuffer::computeLineWidth( void )
{
QFontMetrics fm( mFontInfo.font );
mUnitWidth = fm.width( "M" );
if( mLayout.primaryMode == SDisplayLayout::textOnly )
{
mSplitWidth = 0;
}
else if( mLayout.columnCharSpace == true )
{
mSplitWidth = mUnitWidth;
}
else
{
mSplitWidth = mLayout.columnSpacing;
}
setMaximumSize( mMaximumSize );
if( mLayout.primaryMode == SDisplayLayout::hexadecimal )
{
mNumCell = 2;
mCursor.setCellWeight( 4 );
if( mLayout.primaryUpperCase == true )
{
printCell = &CHexBuffer::printHexadecimalBigCell;
inputCell = &CHexBuffer::inputHexadecimal;
}
else
{
printCell = &CHexBuffer::printHexadecimalSmallCell;
inputCell = &CHexBuffer::inputHexadecimal;
}
}
else if( mLayout.primaryMode == SDisplayLayout::decimal )
{
mNumCell = 3;
printCell = &CHexBuffer::printDecimalCell;
inputCell = &CHexBuffer::inputDecimal;
mCursor.setCellWeight( 3 );
}
else if( mLayout.primaryMode == SDisplayLayout::octal )
{
mNumCell = 3;
printCell = &CHexBuffer::printOctalCell;
inputCell = &CHexBuffer::inputOctal;
mCursor.setCellWeight( 3 );
}
else if( mLayout.primaryMode == SDisplayLayout::binary )
{
mNumCell = 8;
printCell = &CHexBuffer::printBinaryCell;
inputCell = &CHexBuffer::inputBinary;
mCursor.setCellWeight( 1 );
}
else if( mLayout.primaryMode == SDisplayLayout::textOnly )
{
mNumCell = 1;
printCell = &CHexBuffer::printAsciiCell;
inputCell = &CHexBuffer::inputAscii;
mCursor.setCellWeight( 8 );
}
else
{
mNumCell = 2;
mLayout.primaryMode = SDisplayLayout::hexadecimal;
mLayout.primaryUpperCase = false;
printCell = &CHexBuffer::printHexadecimalSmallCell;
inputCell = &CHexBuffer::inputHexadecimal;
mCursor.setCellWeight( 4 );
}
//
// 'mPrimaryWidth' is the number of pixels that are needed to display a
// line in the primary field.
//
mPrimaryWidth = mLayout.lineSize * mNumCell * mUnitWidth;
if( mLayout.columnSpacing != 0 )
{
int numSplit = mLayout.lineSize / mLayout.columnSize;
numSplit -= mLayout.lineSize % mLayout.columnSize == 0 ? 1 : 0;
mPrimaryWidth += numSplit * mSplitWidth;
}
//
// 'mSecondaryWidth' is the number of pixels that are needed to display a
// line in the secondary field (there are no spaces).
//
if( mLayout.secondaryMode == SDisplayLayout::hide )
{
mSecondaryWidth = 0;
}
else
{
mSecondaryWidth = mLayout.lineSize * mUnitWidth;
}
//
// 'mLineWidth' is the total number of pixels required to display
// offset data, separators, primary and secondary data on a line.
//
mLineWidth = mPrimaryWidth + mSecondaryWidth + mOffsetSize * mUnitWidth;
//
// The 'mFixedWidth' is the number of pixels of the width that stays the
// same regardless of how many characters that are displayed.
// This entity consists of the edge margins, the inner margins and the
// separators.
//
mFixedWidth = mOffsetSize * mUnitWidth;
//
// The edge margin is always present in both ends.
//
mLineWidth += mLayout.edgeMarginWidth * 2;
mFixedWidth += mLayout.edgeMarginWidth * 2;
//
// 'mTextStart1' is the number of pixels from the left edge where the
// primary field starts.
//
mTextStart1 = mLayout.edgeMarginWidth;
if( mLayout.offsetVisible == true )
{
int width;
if( mLayout.leftSeparatorWidth > 0 )
{
width = mLayout.separatorMarginWidth * 2 + mLayout.leftSeparatorWidth;
}
else
{
width = (mLayout.separatorMarginWidth * 3) / 2;
}
mLineWidth += width;
mFixedWidth += width;
mTextStart1 += width + mOffsetSize * mUnitWidth;
}
//
// 'mTextStart2' is the number of pixels from the left edge where the
// secondary fields start.
//
mTextStart2 = mTextStart1;
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
int width;
if( mLayout.rightSeparatorWidth > 0 )
{
width = mLayout.separatorMarginWidth * 2 + mLayout.rightSeparatorWidth;
}
else
{
width = (mLayout.separatorMarginWidth * 3) / 2;
}
mLineWidth += width;
mFixedWidth += width;
mTextStart2 += width + mPrimaryWidth;
}
setEditMode( mEditMode );
computeNumLines();
}
khexedit'CHexBuffer::computeNumLines() (./kdeutils/khexedit/hexbuffer.cc:1277)
void CHexBuffer::computeNumLines( void )
{
if( mLayout.lineSize == 0 )
{
mNumLines = 1;
}
else
{
uint s = mFixedSizeMode == true ? mMaximumSize : documentSize() + 1;
mNumLines = s / mLayout.lineSize + (s % mLayout.lineSize ? 1 : 0);
}
}
khexedit'CHexBuffer::drawSelection() (./kdeutils/khexedit/hexbuffer.cc:1292)
void CHexBuffer::drawSelection( QPainter &paint, QColor &color, uint start,
uint stop, int sx )
{
if( start >= stop ) { return; }
uint width = stop - start;
uint addStart, addWidth;
addStart = (start / mLayout.columnSize) * mSplitWidth;
if( width == 0 )
{
addWidth = 0;
}
else
{
uint g = mLayout.columnSize;
addWidth = (((start % g) + width - 1) / g) * mSplitWidth;
}
int offset = mTextStart1 - sx;
paint.fillRect( offset + start * mNumCell * mUnitWidth + addStart,
0, width * mNumCell * mUnitWidth + addWidth,
mFontHeight, color );
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
offset = mTextStart2 - sx;
paint.fillRect( offset + start * mUnitWidth,
0, width * mUnitWidth,
mFontHeight, color );
}
}
khexedit'CHexBuffer::drawText() (./kdeutils/khexedit/hexbuffer.cc:1328)
void CHexBuffer::drawText( QPainter &paint, uint line, int sx, int x1, int x2 )
{
uint fileOffset = line * mLayout.lineSize;
if( documentPresent() == false || mLoadingData == true )
{
paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.inactiveBg );
return;
}
bool outsideText;
if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
{
outsideText = true;
}
else
{
outsideText = false;
}
if( (line+1) % 2 || outsideText == true )
{
paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.textBg );
}
else
{
paint.fillRect( x1, 0, x2-x1, lineHeight(), mColor.secondTextBg );
}
if( mLayout.horzGridWidth > 0 && outsideText == false )
{
paint.setPen( mColor.gridFg );
paint.drawLine( x1, mFontHeight, x2, mFontHeight );
}
if( mSelect.inside( fileOffset, mLayout.lineSize ) == true )
{
uint start = mSelect.start( fileOffset );
uint stop = mSelect.stop( fileOffset, mLayout.lineSize );
drawSelection( paint, mColor.selectBg, start, stop, sx );
}
//
// A marked area will be displayed "above" a selcted area (given
// the mark background color is different)
//
if( mMark.inside( fileOffset, mLayout.lineSize ) == true )
{
uint start = mMark.start( fileOffset );
uint stop = mMark.stop( fileOffset, mLayout.lineSize );
drawSelection( paint, mColor.markBg, start, stop, sx );
}
uint dataSize;
unsigned char *fileData;
if( outsideText == true )
{
if( size() == 0 )
{
return;
}
dataSize = 0;
fileData = 0;
}
else
{
dataSize = documentSize() - fileOffset;
if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
fileData = (unsigned char*)&(data()[ fileOffset ]);
}
int offset = mLayout.edgeMarginWidth - sx;
if( mLayout.offsetVisible == true )
{
int s0 = mOffsetSize * mUnitWidth;
int s1 = s0 + mLayout.separatorMarginWidth + mLayout.edgeMarginWidth - sx;
if( x1 < s1 && x2 > 0 )
{
if( outsideText == true )
{
paint.fillRect( 0, 0, s1, lineHeight(), mColor.offsetBg );
}
else
{
//
// I want to display the grid here so I cant use lineHeight()
//
paint.fillRect( 0, 0, s1, mFontHeight, mColor.offsetBg );
}
}
if( x1 < offset + s0 && x2 >= offset && fileData != 0 )
{
paint.setPen( mColor.offsetFg );
THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
paint.drawText(offset,mFontAscent,&mPrintBuf[mOffsetIndex],mOffsetSize);
}
offset += s0;
if( mLayout.leftSeparatorWidth > 0 )
{
offset += mLayout.separatorMarginWidth;
int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
if( x1 < offset + s2 && x2 >= offset )
{
QPen pen( mColor.leftSeparatorFg, mLayout.leftSeparatorWidth );
paint.setPen( pen );
int center = offset + mLayout.leftSeparatorWidth/2;
paint.drawLine( center, 0, center, lineHeight() );
}
offset += s2;
}
else
{
offset += (mLayout.separatorMarginWidth * 3) / 2;
}
}
int localOffset = offset;
for( uint i = 0; i < dataSize; i++ )
{
int s = mNumCell * mUnitWidth +
((i+1) % mLayout.columnSize == 0) * mSplitWidth;
if( x1 < localOffset + s && x2 >= localOffset )
{
int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
if( mSelect.inside( fileOffset+i ) )
{
paint.setPen( mColor.selectFg );
}
else if( mMark.inside( fileOffset+i ) )
{
paint.setPen( mColor.markFg );
}
else
{
paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
}
paint.drawText( localOffset, mFontAscent, mPrintBuf, mNumCell );
}
localOffset += s;
if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
{
if( (i+1) % mLayout.columnSize == 0 )
{
paint.setPen( mColor.gridFg );
int x = localOffset - (mSplitWidth+1) / 2;
paint.drawLine( x, 0, x, mFontHeight );
}
}
}
offset += mPrimaryWidth;
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
if( mLayout.rightSeparatorWidth > 0 )
{
offset += mLayout.separatorMarginWidth;
int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
if( x1 < offset + s && x2 >= offset )
{
QPen pen( mColor.rightSeparatorFg, mLayout.rightSeparatorWidth );
paint.setPen( pen );
int center = offset + mLayout.rightSeparatorWidth/2;
paint.drawLine( center, 0, center, lineHeight() );
}
offset += s;
}
else
{
offset += (mLayout.separatorMarginWidth * 3) / 2;
}
int s = mUnitWidth;
for( uint i = 0; i < dataSize; i++ )
{
if( x1 < offset + s && x2 >= offset )
{
int flag = printAsciiCell( mPrintBuf, fileData[i] );
if( mSelect.inside( fileOffset+i ) )
{
paint.setPen( mColor.selectFg );
}
else if( mMark.inside( fileOffset+i ) )
{
paint.setPen( mColor.markFg );
}
else
{
paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
}
paint.drawText( offset, mFontAscent, mPrintBuf, 1 );
}
offset += s;
}
}
//
// If the cursors are located on the line we have drawn we redraw
// them unless they have been disabled.
//
if( mDisableCursor == true )
{
return;
}
if( mCursor.curr.inside( fileOffset, fileOffset + mLayout.lineSize ) )
{
drawCursor( paint, line, sx );
}
}
khexedit'CHexBuffer::drawText() (./kdeutils/khexedit/hexbuffer.cc:1547)
void CHexBuffer::drawText( QPainter &paint, uint line, int x1, int x2, int y,
bool useBlackWhite )
{
uint fileOffset = line * mLayout.lineSize;
bool outsideText;
if( size() == 0 || fileOffset > documentSize() || fileOffset >= mMaximumSize)
{
outsideText = true;
}
else
{
outsideText = false;
}
if( (line+1) % 2 || outsideText == true )
{
paint.fillRect( x1, y, x2, lineHeight(),
useBlackWhite == true ? Qt::white : mColor.textBg );
}
else
{
paint.fillRect( x1, y, x2, lineHeight(),
useBlackWhite == true ? Qt::white : mColor.secondTextBg );
}
if( mLayout.horzGridWidth > 0 && outsideText == false )
{
QPen pen( useBlackWhite == true ? Qt::black : mColor.gridFg,
mLayout.horzGridWidth );
paint.setPen( pen );
paint.drawLine( x1, y+mFontHeight, x2+x1, y+mFontHeight );
}
uint dataSize;
unsigned char *fileData;
if( outsideText == true )
{
if( size() == 0 )
{
return;
}
dataSize = 0;
fileData = 0;
}
else
{
dataSize = documentSize() - fileOffset;
if( dataSize > mLayout.lineSize ) { dataSize = mLayout.lineSize; }
fileData = (unsigned char*)&(data()[ fileOffset ]);
}
int offset = mLayout.edgeMarginWidth + x1;
if( mLayout.offsetVisible == true )
{
int s1 = mOffsetSize * mUnitWidth;
if( fileData != 0 )
{
paint.setPen( useBlackWhite == true ? Qt::black : mColor.offsetFg );
THIS_FPTR(printOffset)( mPrintBuf, fileOffset );
paint.drawText( offset, mFontAscent+y, &mPrintBuf[mOffsetIndex],
mOffsetSize );
}
offset += s1;
if( mLayout.leftSeparatorWidth > 0 )
{
offset += mLayout.separatorMarginWidth;
int s2 = mLayout.leftSeparatorWidth + mLayout.separatorMarginWidth;
QPen pen( useBlackWhite == true ? Qt::black : mColor.leftSeparatorFg,
mLayout.leftSeparatorWidth );
paint.setPen( pen );
int center = offset + mLayout.leftSeparatorWidth/2;
paint.drawLine( center, y, center, mFontHeight+y );
offset += s2;
}
else
{
offset += (mLayout.separatorMarginWidth * 3) / 2;
}
}
int localOffset = offset;
for( uint i = 0; i < dataSize; i++ )
{
int s = mNumCell * mUnitWidth +
((i+1) % mLayout.columnSize == 0) * mSplitWidth;
int flag = THIS_FPTR(printCell)( mPrintBuf, fileData[i] );
if( useBlackWhite == true )
{
paint.setPen( Qt::black );
}
else
{
paint.setPen( flag == 0 ? foregroundColor( i ) : mColor.nonPrintFg );
}
paint.drawText( localOffset, mFontAscent+y, mPrintBuf, mNumCell );
localOffset += s;
if( mLayout.vertGridWidth > 0 && i+1 < dataSize )
{
if( (i+1) % mLayout.columnSize == 0 )
{
QPen pen( useBlackWhite == true ? Qt::black : mColor.gridFg,
mLayout.vertGridWidth );
paint.setPen( pen );
int x = localOffset - (mSplitWidth+1) / 2;
paint.drawLine( x, y, x, y+mFontHeight );
}
}
}
offset += mPrimaryWidth;
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
if( mLayout.rightSeparatorWidth > 0 )
{
offset += mLayout.separatorMarginWidth;
int s = mLayout.separatorMarginWidth + mLayout.rightSeparatorWidth;
QPen pen( useBlackWhite == true ? Qt::black : mColor.rightSeparatorFg,
mLayout.rightSeparatorWidth );
paint.setPen( pen );
int center = offset + mLayout.rightSeparatorWidth/2;
paint.drawLine( center, y, center, mFontHeight+y );
offset += s;
}
else
{
offset += (mLayout.separatorMarginWidth * 3) / 2;
}
int s = mUnitWidth;
for( uint i = 0; i < dataSize; i++ )
{
int flag = printAsciiCell( mPrintBuf, fileData[i] );
if( useBlackWhite == true )
{
paint.setPen( Qt::black );
}
else
{
paint.setPen( flag == 0 ? mColor.secondaryFg : mColor.nonPrintFg );
}
paint.drawText( offset, mFontAscent+y, mPrintBuf, 1 );
offset += s;
}
}
}
khexedit'CHexBuffer::headerHeight() (./kdeutils/khexedit/hexbuffer.cc:1703)
int CHexBuffer::headerHeight( QPainter &paint )
{
QFont font( paint.font() );
paint.setFont( QString("helvetica") );
const QFontMetrics &fm = paint.fontMetrics();
int height = fm.height();
paint.setFont( font );
return( height );
}
khexedit'CHexBuffer::headerMargin() (./kdeutils/khexedit/hexbuffer.cc:1714)
int CHexBuffer::headerMargin( QPainter &paint )
{
QFont font( paint.font() );
paint.setFont( QString("helvetica") );
const QFontMetrics &fm = paint.fontMetrics();
int margin = fm.height() / 2;
paint.setFont( font );
return( margin );
}
khexedit'CHexBuffer::drawHeader() (./kdeutils/khexedit/hexbuffer.cc:1726)
void CHexBuffer::drawHeader( QPainter &paint, int sx, int width, int y,
bool isFooter, const SPageHeader &header,
const SPagePosition &position )
{
QFont font( paint.font() );
paint.setFont( QFont( QString("helvetica"), 12, QFont::Normal, false) );
const QFontMetrics &fm = paint.fontMetrics();
paint.fillRect( sx, y, width, fm.height(), Qt::white );
paint.setPen( Qt::black );
if( header.line == SPageHeader::SingleLine )
{
if( isFooter == false )
{
paint.drawLine( sx, y+fm.height(), sx+width, y+fm.height() );
}
else
{
paint.drawLine( sx, y, sx+width, y );
}
}
else if( header.line == SPageHeader::Rectangle )
{
paint.drawRect( sx, y, width, fm.height() );
}
int pos[3] =
{
QPainter::AlignLeft, QPainter::AlignHCenter, QPainter::AlignRight
};
QString msg;
for( int i=0; i<3; i++ )
{
if( header.pos[i] == SPageHeader::DateTime )
{
msg = QString( ctime( &position.now ) );
}
else if( header.pos[i] == SPageHeader::PageNumber )
{
msg = i18n("Page %1 of %2").arg(position.curPage).arg(position.maxPage);
}
else if( header.pos[i] == SPageHeader::FileName )
{
msg = mUrl;
}
else
{
continue;
}
if( 0 && pos[i] == QPainter::AlignRight )
{
//const QFontMetrics &f = QFontMetrics( QFont(QString("helvetica")) );
QRect r = paint.boundingRect(sx, y, width, fm.height(), pos[i], msg );
printf("R: %d, %d, %d, %d\n", r.x(), r.y(), r.width(), r.height() );
int x = sx + width - /*r.width();*/ fm.width(msg);
paint.drawText( x, y+fm.height(), msg );
printf("paint at %d\n", x );
}
else
{
paint.drawText( sx, y, width, fm.height(), pos[i], msg );
}
}
//
// restore original font.
//
paint.setFont( font );
}
khexedit'CHexBuffer::drawCursor() (./kdeutils/khexedit/hexbuffer.cc:1803)
void CHexBuffer::drawCursor( QPainter &paint, uint line, int startx )
{
if( documentPresent() == false || mLoadingData == true )
{
return;
}
SCursorSpec &c = mCursor.curr;
//
// Draw the cursor in primary edit area.
//
QColor bg, fg;
bool useFg;
if( mMark.inside( c.offset ) == true )
{
bg = mColor.markBg;
fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
useFg = true;
}
else if( mSelect.inside( c.offset ) == true )
{
bg = mColor.selectBg;
fg = mColor.selectFg;
useFg = true;
}
else
{
bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
fg = foregroundColor( c.offset % mLayout.lineSize );
useFg = false; // Can be true later.
}
QColor cbg = mColor.cursorBg;
QColor cfg = mColor.cursorFg;
paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, bg );
if( mActiveEditor == edit_primary )
{
if( mShowCursor == true ) // Cursor blink on
{
if( c.mPrimaryShape == SCursorSpec::thin )
{
paint.setPen( cbg );
int center = c.x1 - startx - 1;
if( c.thickState == true )
{
paint.drawLine( center, 0, center, mFontHeight - 1 );
paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
}
else
{
paint.drawLine( center, 0, center, mFontHeight - 1 );
paint.drawLine( center-2, 0, center+2, 0 );
paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
}
}
else
{
paint.fillRect( c.x1 - startx, 0, mUnitWidth, mFontHeight, cbg );
useFg = true;
fg = cfg;
}
}
}
else
{
paint.setPen( cbg );
paint.drawRect( c.x1 - startx, 0, mUnitWidth*mNumCell, mFontHeight );
}
if( c.offset < documentSize() )
{
int flag = THIS_FPTR(printCell)( mPrintBuf, (unsigned char)c.data );
paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
paint.drawText( c.x1 - startx, mFontAscent, &mPrintBuf[c.cell], 1 );
}
//
// Draw the cursor in secodary edit area.
//
if( mLayout.secondaryMode == SDisplayLayout::hide )
{
return;
}
if( mMark.inside( c.offset ) == true )
{
bg = mColor.markBg;
fg = mSelect.inside( c.offset ) ? mColor.selectFg : mColor.markFg;
useFg = true;
}
else if( mSelect.inside( c.offset ) == true )
{
bg = mColor.selectBg;
fg = mColor.selectFg;
useFg = true;
}
else
{
bg = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
fg = mColor.secondaryFg;
useFg = false; // Can be true later.
}
paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, bg );
if( mActiveEditor == edit_secondary )
{
if( mShowCursor == true ) // Cursor blink on
{
if( c.mSecondaryShape == SCursorSpec::thin )
{
paint.setPen( cbg );
int center = c.x2 - startx - 1;
if( c.thickState == true )
{
paint.drawLine( center, 0, center, mFontHeight - 1 );
paint.drawLine( center+1, 0, center+1, mFontHeight - 1 );
}
else
{
paint.drawLine( center, 0, center, mFontHeight - 1 );
paint.drawLine( center-2, 0, center+2, 0 );
paint.drawLine( center-2, mFontHeight-1, center+2, mFontHeight-1 );
}
}
else
{
paint.fillRect( c.x2 - startx, 0, mUnitWidth, mFontHeight, cbg );
useFg = true;
fg = cfg;
}
}
}
else
{
paint.setPen( cbg );
paint.drawRect( c.x2 - startx, 0, mUnitWidth, mFontHeight );
}
if( c.offset < documentSize() )
{
int flag = printAsciiCell( mPrintBuf, (unsigned char)c.data );
paint.setPen( flag == 0 || useFg == true ? fg : mColor.nonPrintFg );
paint.drawText( c.x2 - startx, mFontAscent, mPrintBuf, 1 );
}
}
khexedit'CHexBuffer::cursorReset() (./kdeutils/khexedit/hexbuffer.cc:1960)
void CHexBuffer::cursorReset( void )
{
mCursor.reset();
cursorCompute();
}
khexedit'CHexBuffer::cursorCompute() (./kdeutils/khexedit/hexbuffer.cc:1966)
void CHexBuffer::cursorCompute( void )
{
mCursor.prev = mCursor.curr;
if( mCursor.next.offset >= documentSize() )
{
if( documentSize() == 0 )
{
mCursor.curr.offset = 0;
mCursor.curr.data = 0;
mCursor.curr.cell = 0;
mCursor.curr.maxCell = mNumCell;
int x = mCursor.curr.offset % mLayout.lineSize;
mCursor.curr.x1 = mTextStart1;
mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
mCursor.curr.y = (mCursor.curr.offset/mLayout.lineSize) *
(mFontHeight+mLayout.horzGridWidth);
return;
}
if( mFixedSizeMode == true )
{
uint max = mMaximumSize - 1;
uint off = mCursor.curr.offset % mLayout.lineSize;
uint end = max % mLayout.lineSize;
if( off > end )
{
uint diff = off - end;
if( max + diff > mLayout.lineSize )
{
mCursor.next.offset = max + diff - mLayout.lineSize;
}
else
{
mCursor.next.offset = 0;
}
}
else
{
uint diff = end - off;
mCursor.next.offset = diff > max ? max : max - diff;
}
}
else
{
mCursor.next.offset = documentSize();
}
}
mCursor.curr.offset = mCursor.next.offset;
mCursor.curr.data = data()[ mCursor.curr.offset ];
mCursor.curr.cell = mCursor.next.cell;
mCursor.curr.maxCell = mNumCell;
int x = mCursor.curr.offset % mLayout.lineSize;
mCursor.curr.x1 = mTextStart1;
mCursor.curr.x1 += (x * mNumCell + mCursor.curr.cell) * mUnitWidth;
mCursor.curr.x1 += (x / mLayout.columnSize) * mSplitWidth;
mCursor.curr.x2 = mTextStart2 + x * mUnitWidth;
mCursor.curr.y = (mCursor.curr.offset/mLayout.lineSize) *
(mFontHeight + mLayout.horzGridWidth);
}
khexedit'CHexBuffer::setCursorPosition() (./kdeutils/khexedit/hexbuffer.cc:2034)
bool CHexBuffer::setCursorPosition( int x, int y, bool init, bool cellLevel )
{
if( documentPresent() == false )
{
return( false );
}
uint line = y < 0 ? 0 : y / lineHeight();
uint entry = 0;
int bit = 7;
if( init == false )
{
if( mCursor.area() == edit_primary )
{
int start = mTextStart1;
if( x < start - (int)mLayout.separatorMarginWidth )
{
return( false );
}
else
{
int stop = mTextStart1 + mPrimaryWidth + mLayout.separatorMarginWidth;
int width = mNumCell * mUnitWidth;
int space = mSplitWidth;
for( int position = start, i=0; position < stop; i++ )
{
if( x <= position + width )
{
if( cellLevel == true )
{
while( bit > 0 )
{
if( x <= position + mUnitWidth )
{
break;
}
bit -= mCursor.cellWeight();
position += mUnitWidth;
}
}
break;
}
position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
entry += 1;
}
}
}
else
{
int start = mTextStart2;
if( x < start - (int)mLayout.separatorMarginWidth ||
mLayout.secondaryMode == SDisplayLayout::hide )
{
return( false );
}
int stop = mTextStart2 + mLayout.lineSize * mUnitWidth;
int width = mUnitWidth * 1;
int space = 0;
for( int position = start; position < stop; )
{
if( x <= position + width )
{
break;
}
position += width + space;
entry += 1;
}
}
}
else
{
int start = mTextStart1;
int stop = start + mPrimaryWidth + mLayout.separatorMarginWidth;
if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
{
int width = mUnitWidth * mNumCell;
int space = mSplitWidth;
for( int position = start, i=0; position < stop; i++ )
{
if( x <= position + width )
{
if( cellLevel == true )
{
while( bit > 0 )
{
if( x <= position + mUnitWidth )
{
break;
}
bit -= mCursor.cellWeight();
position += mUnitWidth;
}
}
break;
}
position += width + (((i+1) % mLayout.columnSize) ? 0 : space);
entry += 1;
}
mActiveEditor = edit_primary;
}
else if( mLayout.secondaryMode != SDisplayLayout::hide )
{
start = mTextStart2;
stop = mTextStart2 + mLayout.lineSize * mUnitWidth +
mLayout.edgeMarginWidth;
if( x >= start - (int)mLayout.separatorMarginWidth && x <= stop )
{
int width = mUnitWidth * 1;
int space = 0;
for( int position = start; position < stop; )
{
if( x <= position + width )
{
break;
}
position += width + space;
entry += 1;
}
mActiveEditor = edit_secondary;
}
}
else
{
return( false );
}
}
uint offset = line * mLayout.lineSize + entry;
if( offset > documentSize() )
{
offset = documentSize();
}
mCursor.setOffset( offset );
mCursor.setBit( bit < 0 ? 0 : bit );
cursorCompute();
if( mActiveEditor != mCursor.area() )
{
mCursor.setArea( mActiveEditor );
setEditMode( mEditMode );
}
return( true );
}
khexedit'CHexBuffer::inputAtCursor() (./kdeutils/khexedit/hexbuffer.cc:2190)
bool CHexBuffer::inputAtCursor( QChar c )
{
if( documentPresent() == false || mInputMode.noInput() == true )
{
if( mInputMode.noInput() == true ) { inputSound(); }
return( false );
}
if( c.isPrint() == false )
{
inputSound();
return( false );
}
unsigned char dest;
bool insert;
if( mEditMode == EditReplace || mCursor.curr.cell > 0 )
{
if( mCursor.curr.offset >= documentSize() )
{
dest = 0;
insert = true;
}
else
{
dest = (unsigned char)data()[ mCursor.curr.offset ];
insert = false;
}
}
else
{
dest = 0;
insert = true;
}
if( insert == true && mInputMode.allowResize == false )
{
inputSound();
return( false );
}
if( mActiveEditor == edit_primary )
{
if( THIS_FPTR(inputCell)( &dest, c.latin1(), mCursor.curr.cell ) == false )
{
inputSound();
return( false );
}
}
else if( mActiveEditor == edit_secondary )
{
if( inputAscii( &dest, c.latin1(), mCursor.curr.cell ) == false )
{
inputSound();
return( false );
}
}
else
{
return( false );
}
recordStart( mCursor );
recordReplace( mCursor, insert == true ? 0 : 1, (char*)&dest, 1 );
cursorRight( cursorPrimaryEdit() );
recordEnd( mCursor );
computeNumLines();
return( true );
}
khexedit'CHexBuffer::inputAtCursor() (./kdeutils/khexedit/hexbuffer.cc:2263)
int CHexBuffer::inputAtCursor( const QByteArray &buf, uint oldSize )
{
if( documentPresent() == false )
{
return( Err_NoActiveDocument );
}
if( buf.isNull() == true )
{
return( Err_EmptyArgument );
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
if( mInputMode.allowResize == false )
{
inputSound();
return( Err_NoResize );
}
recordStart( mCursor );
recordReplace( mCursor, oldSize, (char*)&buf[0], buf.size() );
cursorStep( buf.size(), true, false );
recordEnd( mCursor );
computeNumLines();
return( Err_Success );
}
khexedit'CHexBuffer::removeAtCursor() (./kdeutils/khexedit/hexbuffer.cc:2296)
bool CHexBuffer::removeAtCursor( bool beforeCursor )
{
if( documentPresent() == false )
{
return( false );
}
if( mInputMode.noInput() == true || mInputMode.allowResize == false )
{
inputSound();
return( false );
}
if( mSelect.valid() == true )
{
cutSelection();
return( true );
}
if( beforeCursor == true )
{
if( mCursor.curr.offset == 0 )
{
return( false );
}
recordStart( mCursor );
cursorLeft( false );
recordReplace( mCursor, 1, 0, 0 );
recordEnd( mCursor );
computeNumLines();
return( true );
}
else
{
if( mCursor.curr.offset + 1 > documentSize() )
{
return( false );
}
recordStart( mCursor );
recordReplace( mCursor, 1, 0, 0 );
recordEnd( mCursor );
computeNumLines();
return( true );
}
}
khexedit'CHexBuffer::locateRange() (./kdeutils/khexedit/hexbuffer.cc:2350)
int CHexBuffer::locateRange(const SExportRange &range, uint &start, uint &stop)
{
if( range.mode == SExportRange::All )
{
start = 0;
stop = documentSize();
}
else if( range.mode == SExportRange::Selection )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
start = mSelect.curr.start;
stop = mSelect.curr.stop;
}
else if( range.mode == SExportRange::Range )
{
start = range.start;
stop = range.stop;
}
else
{
return( Err_IllegalMode );
}
if( start >= stop )
{
return( Err_IllegalRange );
}
return( Err_Success );
}
khexedit'CHexBuffer::exportText() (./kdeutils/khexedit/hexbuffer.cc:2385)
int CHexBuffer::exportText( const SExportText &ex, CProgress &p )
{
uint start, stop;
int errCode = locateRange( ex.range, start, stop );
if( errCode != Err_Success )
{
p.finish();
return( errCode );
}
QFile file( ex.destFile );
if( file.open( IO_WriteOnly ) == false )
{
p.finish();
return( Err_OpenWriteFailed );
}
uint startLine = calculateLine( start );
if( startLine >= (uint)numLines() )
{
startLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint stopLine = calculateLine( stop );
if( stopLine >= (uint)numLines() )
{
stopLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint totalSize = stopLine - startLine + 1;
uint remaining = stopLine - startLine + 1;
uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
uint linePerStep = 20;
QByteArray array( bytePerLine * linePerStep + 1 ); // Line is 0 terminated
if( array.isEmpty() == true )
{
p.finish();
return( Err_NoMemory );
}
while( remaining > 0 )
{
uint blockSize = remaining > linePerStep ? linePerStep : remaining;
uint printSize = 0;
for( uint i = 0; i < blockSize; i++, startLine++ )
{
printSize += printLine( &array[printSize], startLine );
}
int writeSize = file.writeBlock( &array[0], printSize );
if( writeSize == -1 )
{
p.finish();
return( Err_WriteFailed );
}
remaining -= blockSize;
if( p.expired() == true )
{
int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
if( errCode == Err_Stop && remaining > 0 )
{
p.finish();
return( Err_OperationAborted );
}
}
}
p.finish();
return( Err_Success );
}
khexedit'CHexBuffer::exportHtml() (./kdeutils/khexedit/hexbuffer.cc:2461)
int CHexBuffer::exportHtml( const SExportHtml &ex, CProgress &p )
{
uint start, stop;
int errCode = locateRange( ex.range, start, stop );
if( errCode != Err_Success )
{
p.finish();
return( errCode );
}
uint startLine = calculateLine( start );
if( startLine >= (uint)numLines() )
{
startLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint stopLine = calculateLine( stop );
if( stopLine >= (uint)numLines() )
{
stopLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint totalSize = stopLine - startLine + 1;
uint remaining = stopLine - startLine + 1;
if( ex.linePerPage == 0 )
{
p.finish();
return( Err_IllegalArgument );
}
uint linePerPage = ex.linePerPage;
uint numFiles = remaining/linePerPage + (remaining%linePerPage ? 1 : 0);
uint fileCount = 0;
QStringList fileNames, offsets;
QString name, offset;
for( uint i=0; i < numFiles; i++ )
{
name.sprintf( "%08d.html", i+1 );
fileNames.append( QString("%1/%2%3").arg(ex.package).arg(ex.prefix).
arg(name));
}
name.sprintf( "%08d.html", 0 );
QString tocName =QString("%1/%2%3").arg(ex.package).arg(ex.prefix).arg(name);
QString linkName;
if( ex.symLink == true )
{
linkName = QString("%1/%2").arg(ex.package).arg("index.html");
}
while( remaining > 0 )
{
THIS_FPTR(printOffset)( mPrintBuf, startLine*mLayout.lineSize );
mPrintBuf[mOffsetSize]=0;
offset.sprintf("[%s]", mPrintBuf );
uint pageSize = remaining > linePerPage ? linePerPage : remaining;
printHtmlDataPage( tocName, fileNames, fileCount, ex, startLine, pageSize);
remaining -= pageSize;
startLine += pageSize;
fileCount += 1;
THIS_FPTR(printOffset)( mPrintBuf, (startLine-1)*mLayout.lineSize );
mPrintBuf[mOffsetSize]=0;
offset += QString(" %1 [%2]").arg(i18n("to")).arg(mPrintBuf);
offsets.append(offset);
if( p.expired() == true )
{
int errCode = p.step( (float)(totalSize-remaining)/(float)totalSize );
if( errCode == Err_Stop && remaining > 0 )
{
printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
p.finish();
return( Err_OperationAborted );
}
}
}
printHtmlTocPage( tocName, linkName, fileNames, offsets, fileCount );
p.finish();
return( Err_Success );
}
khexedit'CHexBuffer::exportCArray() (./kdeutils/khexedit/hexbuffer.cc:2550)
int CHexBuffer::exportCArray( const SExportCArray &ex, CProgress &p )
{
uint start, stop;
int errCode = locateRange( ex.range, start, stop );
if( errCode != Err_Success )
{
p.finish();
return( errCode );
}
QFile file( ex.destFile );
if( file.open( IO_WriteOnly ) == false )
{
p.finish();
return( Err_OpenWriteFailed );
}
uint startLine = calculateLine( start );
if( startLine >= (uint)numLines() )
{
startLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint stopLine = calculateLine( stop );
if( stopLine >= (uint)numLines() )
{
stopLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint elementSize = ex.elementSize();
uint elementOnThisLine = 0;
QTextStream dest( &file );
dest << ex.variableName(stop-start).latin1() << "={" << endl;
for( unsigned int i=start; i<stop; i+=elementSize )
{
dest << ex.printFormatted( (const char*)&data()[i], stop-i );
if( i + elementSize < stop )
{
dest << ",";
}
if( ++elementOnThisLine >= ex.elementPerLine )
{
dest << endl;
elementOnThisLine = 0;
}
if( p.expired() == true )
{
int errCode = p.step( (float)(i-start)/(float)(stop-start) );
if( errCode == Err_Stop && (i+elementSize) < stop)
{
p.finish();
return( Err_OperationAborted );
}
}
}
dest << "};" << endl;
p.finish();
return( Err_Success );
}
khexedit'CHexBuffer::copySelectedText() (./kdeutils/khexedit/hexbuffer.cc:2621)
int CHexBuffer::copySelectedText( QByteArray &array, int columnSegment )
{
SExportRange range;
range.mode = SExportRange::Selection;
return( copyText( array, range, columnSegment ) );
}
khexedit'CHexBuffer::copyAllText() (./kdeutils/khexedit/hexbuffer.cc:2629)
int CHexBuffer::copyAllText( QByteArray &array )
{
SExportRange range;
range.mode = SExportRange::All;
return( copyText( array, range, VisibleColumn ) );
}
khexedit'CHexBuffer::copyText() (./kdeutils/khexedit/hexbuffer.cc:2637)
int CHexBuffer::copyText( QByteArray &array, const SExportRange &range,
int columnSegment )
{
uint start, stop;
int errCode = locateRange( range, start, stop );
if( errCode != Err_Success )
{
return( errCode );
}
uint startLine = calculateLine( start );
uint stopLine = calculateLine( stop );
if( startLine >= (uint)numLines() )
{
startLine = numLines() == 0 ? 0 : numLines() - 1;
}
if( stopLine >= (uint)numLines() )
{
stopLine = numLines() == 0 ? 0 : numLines() - 1;
}
uint bytePerLine = mOffsetSize + 1 + (mNumCell + 2)*mLayout.lineSize + 1;
uint size = (stopLine - startLine + 1)*bytePerLine;
if( array.resize( size+1 ) == false )
{
return( Err_NoMemory );
}
if( columnSegment == VisibleColumn )
{
columnSegment = PrimaryColumn; // Always visible
if( mLayout.offsetVisible == true )
{
columnSegment |= OffsetColumn;
}
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
columnSegment |= SecondaryColumn;
}
}
uint offset = 0;
for( uint i = startLine; i <= stopLine; i++ )
{
offset += printLine( &array[offset], i, columnSegment );
}
array[size] = 0;
return( Err_Success );
}
khexedit'CHexBuffer::copySelectedData() (./kdeutils/khexedit/hexbuffer.cc:2689)
int CHexBuffer::copySelectedData( QByteArray &array )
{
uint start = mSelect.start();
uint stop = mSelect.stop();
if( mSelect.valid() == false || start >= stop )
{
return( Err_IllegalRange );
}
uint size = stop - start;
if( array.resize( size ) == false )
{
return( Err_NoMemory );
}
//unsigned char *src = (unsigned char*)data();
//char *dst = (char*)array.data();
memcpy( &array[0], &data()[start], size );
return( Err_Success );
}
khexedit'CHexBuffer::numPage() (./kdeutils/khexedit/hexbuffer.cc:2713)
uint CHexBuffer::numPage( CHexPrinter &printer )
{
if( printer.asText() == true )
{
//
// Assume 80 lines per page
//
if( printer.all() == true )
{
return( numLines() / 80 );
}
else if( printer.selection() == true )
{
if( mSelect.valid() == false )
{
return( 0 );
}
uint line = calculateLine( mSelect.curr.start );
uint remaining = calculateLine( mSelect.curr.stop ) - line + 1;
return( remaining / 80 );
}
else if( printer.range() == true )
{
uint line = calculateLine( printer.startRange() );
uint remaining = calculateLine( printer.stopRange() ) - line + 1;
return( remaining / 80 );
}
else
{
return( 0 );
}
}
QPainter paint( &printer );
paint.setFont( font() );
SPageMargin margin = printer.pageMargin();
SPageSize size = printer.pageUsableSize();
int headHeight, footHeight, headMargin, footMargin, freeHeight;
headHeight = footHeight = headMargin = footMargin = 0;
if( printer.pageHeader().enable == true )
{
headHeight = headerHeight( paint );
headMargin = headerMargin( paint );
}
if( printer.pageFooter().enable == true )
{
footHeight = headerHeight( paint );
footMargin = headerMargin( paint );
}
freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
float scale = 1.0;
if( (uint)mLineWidth > size.width && printer.scaleToFit() == true )
{
scale = (float)size.width / (float)mLineWidth;
}
uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
uint remaining, line;
if( printer.all() == true )
{
line = 0;
remaining = numLines();
}
else if( printer.selection() == true )
{
if( mSelect.valid() == false )
{
return( 0 );
}
line = calculateLine( mSelect.curr.start );
remaining = calculateLine( mSelect.curr.stop ) - line + 1;
}
else if( printer.range() == true )
{
line = calculateLine( printer.startRange() );
remaining = calculateLine( printer.stopRange() ) - line + 1;
}
else
{
return( 0 );
}
return( remaining / linePerPage + (remaining % linePerPage ? 1 : 0) );
}
khexedit'CHexBuffer::print() (./kdeutils/khexedit/hexbuffer.cc:2805)
int CHexBuffer::print( CHexPrinter &printer, CProgress &p )
{
printer.setDocName( mUrl );
QPainter paint( &printer );
paint.setFont( font() );
SPageMargin margin = printer.pageMargin();
SPageSize size = printer.pageUsableSize();
paint.setClipRect( margin.left, margin.top, size.width, size.height );
//printf("%d,%d,%d,%d\n", margin.left, margin.top, size.width, size.height );
int headHeight, footHeight, headMargin, footMargin, freeHeight;
headHeight = footHeight = headMargin = footMargin = 0;
if( printer.pageHeader().enable == true )
{
headHeight = headerHeight( paint );
headMargin = headerMargin( paint );
}
if( printer.pageFooter().enable == true )
{
footHeight = headerHeight( paint );
footMargin = headerMargin( paint );
}
freeHeight = size.height - headHeight - footHeight - headMargin - footMargin;
float scale = 1.0;
if( (uint)mLineWidth > size.width && printer.scaleToFit() == true )
{
scale = (float)size.width / (float)mLineWidth;
paint.scale( scale, scale );
}
uint linePerPage = (uint) ((float)freeHeight/((float)lineHeight()*scale));
uint sx = (uint) ((float)margin.left/scale);
uint sy = (uint) ((float)(margin.top+headHeight+headMargin)/scale);
uint remaining = numLines();
uint line = 0;
if( printer.all() == true )
{
line = 0;
remaining = numLines();
}
else if( printer.selection() == true )
{
if( mSelect.valid() == false )
{
p.finish();
return( Err_NoSelection );
}
line = calculateLine( mSelect.curr.start );
remaining = calculateLine( mSelect.curr.stop ) - line + 1;
}
else if( printer.range() == true )
{
line = calculateLine( printer.startRange() );
remaining = calculateLine( printer.stopRange() ) - line + 1;
}
else
{
p.finish();
return( Err_IllegalMode );
}
#ifdef PRINTER_TEST
remaining = remaining > linePerPage * 10 ? linePerPage * 10 : remaining;
#endif
SPagePosition pageData( time(0), remaining, linePerPage );
while( remaining > 0 )
{
uint lineInPage = remaining > linePerPage ? linePerPage : remaining;
uint y = sy;
//
// Draw header and footer. Reset scaling during that operation.
//
paint.scale( 1.0/scale, 1.0/scale );
if( printer.pageHeader().enable == true )
{
drawHeader( paint, margin.left, size.width, margin.top, false,
printer.pageHeader(), pageData );
}
if( printer.pageFooter().enable == true )
{
drawHeader( paint, margin.left, size.width,
margin.top+size.height-footHeight, true,
printer.pageFooter(), pageData );
}
paint.scale( scale, scale );
//
// Draw actual data
//
for( uint i=0; i < lineInPage; i++, line++ )
{
drawText( paint, line, sx, mLineWidth, y, printer.printBlackWhite() );
y += lineHeight();// - mLayout.horzGridWidth; // FIXME not really nice :)
if( p.expired() == true )
{
int errCode = p.step( pageData.current(), pageData.max() );
if( errCode == Err_Stop )
{
p.finish();
return( Err_Success ); // Success here, even if we cancel
}
}
}
if( p.expired() == true )
{
int errCode = p.step( pageData.current(), pageData.max() );
if( errCode == Err_Stop )
{
p.finish();
return( Err_Success );// Success here, even if we cancel
}
}
remaining -= lineInPage;
if( remaining > 0 )
{
printer.newPage();
}
pageData.step();
}
p.finish();
return( Err_Success );
}
khexedit'CHexBuffer::printLine() (./kdeutils/khexedit/hexbuffer.cc:2947)
uint CHexBuffer::printLine( char *dst, uint line )
{
uint offset = line * mLayout.lineSize;
unsigned char *src;
char *start = dst;
uint dataSize;
if( offset >= documentSize() )
{
src = 0;
dataSize = 0;
}
else
{
src = (unsigned char*)&data()[ offset ];
dataSize = documentSize() - offset;
}
if( mLayout.offsetVisible == true )
{
THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
sprintf( dst, " " ); dst += 1;
}
for( uint i=0; i < mLayout.lineSize; i++ )
{
if( i<dataSize )
{
THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
}
else
{
memset( dst, ' ', mNumCell ); dst += mNumCell;
}
if( mSplitWidth != 0 )
{
sprintf( dst, " " ); dst += 1;
}
}
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
for( uint i=0; i < mLayout.lineSize; i++ )
{
if( i < dataSize )
{
printAsciiCell( dst, src[i] ); dst += 1;
}
else
{
memset( dst, ' ', 1 ); dst += 1;
}
}
}
sprintf( dst, "\n" ); dst += 1;
return( (uint)(dst-start) );
}
khexedit'CHexBuffer::printLine() (./kdeutils/khexedit/hexbuffer.cc:3004)
uint CHexBuffer::printLine( char *dst, uint line, int columnSegment )
{
uint offset = line * mLayout.lineSize;
unsigned char *src;
char *start = dst;
uint dataSize;
if( offset >= documentSize() )
{
src = 0;
dataSize = 0;
}
else
{
src = (unsigned char*)&data()[ offset ];
dataSize = documentSize() - offset;
}
if( columnSegment & OffsetColumn )
{
THIS_FPTR(printOffset)( dst, offset ); dst += mOffsetSize;
sprintf( dst, " " ); dst += 1;
}
if( columnSegment & PrimaryColumn )
{
for( uint i=0; i < mLayout.lineSize; i++ )
{
if( i<dataSize )
{
THIS_FPTR(printCell)( dst, src[i] ); dst += mNumCell;
}
else
{
memset( dst, ' ', mNumCell ); dst += mNumCell;
}
if( mSplitWidth != 0 )
{
sprintf( dst, " " ); dst += 1;
}
}
}
if( columnSegment & SecondaryColumn )
{
for( uint i=0; i < mLayout.lineSize; i++ )
{
if( i < dataSize )
{
printAsciiCell( dst, src[i] ); dst += 1;
}
else
{
memset( dst, ' ', 1 ); dst += 1;
}
}
}
sprintf( dst, "\n" ); dst += 1;
return( (uint)(dst-start) );
}
khexedit'CHexBuffer::cutSelection() (./kdeutils/khexedit/hexbuffer.cc:3076)
bool CHexBuffer::cutSelection( void )
{
if( documentPresent() == false || mSelect.size() == 0 )
{
return( false );
}
if( mInputMode.noInput() == true || mInputMode.allowResize == false )
{
inputSound();
return( false );
}
recordStart( mCursor );
cursorGoto( mSelect.start(), 0 );
recordReplace( mCursor, mSelect.size(), 0, 0 );
recordEnd( mCursor );
mSelect.reset();
computeNumLines();
return( true );
}
khexedit'CHexBuffer::undo() (./kdeutils/khexedit/hexbuffer.cc:3102)
bool CHexBuffer::undo( void )
{
if( documentPresent() == false || mUndoIndex == 0 ||
mInputMode.noInput() == true )
{
if( mInputMode.noInput() == true ) { inputSound(); }
return( false );
}
CHexActionGroup *group = mUndoList.at( mUndoIndex-1 );
if( group == 0 )
{
return( false );
}
mUndoIndex -= 1;
doActionGroup( group );
cursorGoto( group->mStartOffset, group->mStartBit );
return( true );
}
khexedit'CHexBuffer::redo() (./kdeutils/khexedit/hexbuffer.cc:3126)
bool CHexBuffer::redo( void )
{
if( documentPresent() == false || mUndoIndex >= mUndoList.count() ||
mInputMode.noInput() == true )
{
if( mInputMode.noInput() == true ) { inputSound(); }
return( false );
}
CHexActionGroup *group = mUndoList.at( mUndoIndex );
if( group == 0 )
{
return( false );
}
mUndoIndex += 1;
doActionGroup( group );
cursorGoto( group->mStopOffset, group->mStopBit );
return( true );
}
khexedit'CHexBuffer::addBookmark() (./kdeutils/khexedit/hexbuffer.cc:3150)
int CHexBuffer::addBookmark( int position )
{
if( documentPresent() == false )
{
return( Err_NoData );
}
if( mBookmarkList.count() >= 9 && position == -1 )
{
return( Err_ListFull );
}
SCursorOffset *co = new SCursorOffset;
if( co == 0 )
{
fatalSound();
return( Err_NoMemory );
}
co->offset = mCursor.curr.offset;
co->bit = mCursor.bit();
if( position == -1 || position > (int)mBookmarkList.count() )
{
mBookmarkList.append( co );
}
else
{
mBookmarkList.remove( (uint)position );
mBookmarkList.insert( (uint)position, co );
}
return( Err_Success );
}
khexedit'CHexBuffer::removeBookmark() (./kdeutils/khexedit/hexbuffer.cc:3186)
bool CHexBuffer::removeBookmark( int position )
{
if( position < 0 )
{
if( mBookmarkList.count() == 0 )
{
return( false );
}
mBookmarkList.clear();
}
else
{
if( (uint)position >= mBookmarkList.count() )
{
return( false );
}
mBookmarkList.remove( position );
}
return( true );
}
khexedit'CHexBuffer::findFirst() (./kdeutils/khexedit/hexbuffer.cc:3211)
int CHexBuffer::findFirst( SSearchControl &sc )
{
mMark.reset();
int errCode = scanData( sc, true );
return( errCode );
}
khexedit'CHexBuffer::findNext() (./kdeutils/khexedit/hexbuffer.cc:3218)
int CHexBuffer::findNext( SSearchControl &sc )
{
sc.fromCursor = true;
int errCode = scanData( sc, false );
return( errCode );
}
khexedit'CHexBuffer::findWrap() (./kdeutils/khexedit/hexbuffer.cc:3225)
int CHexBuffer::findWrap( SSearchControl &sc )
{
if( sc.wrapValid == false )
{
return( Err_NoMatch );
}
sc.wrapValid = false;
sc.fromCursor = false;
sc.wrapActive = true;
int errCode = scanData( sc, false );
sc.fromCursor = true;
return( errCode );
}
khexedit'CHexBuffer::replaceAll() (./kdeutils/khexedit/hexbuffer.cc:3243)
int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
{
if( init == true )
{
initScanData( sc );
}
if( sc.key.isEmpty() == true )
{
return( Err_EmptyArgument );
}
if( documentSize() == 0 )
{
return( Err_EmptyDocument );
}
uint head, tail;
if( sc.inSelection == true )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
head = mSelect.start();
tail = mSelect.stop();
}
else
{
head = 0;
tail = documentSize();
}
uint start, stop;
if( sc.fromCursor == false )
{
if( sc.wrapActive == true )
{
start = sc.forward == true ? head : sc.wrapMark;
stop = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
}
else
{
start = head;
stop = tail;
}
}
else if( sc.forward == true )
{
start = cursorOffset() < head ? head : cursorOffset();
stop = sc.wrapActive == true ? sc.wrapMark+sc.key.size() : tail;
}
else
{
start = sc.wrapActive == true ? sc.wrapMark : head;
stop = cursorOffset() > tail ? tail : cursorOffset();
}
if( sc.forward == true && start + sc.key.size() > stop )
{
//
// When searching backwards "stop" is the last offset from where
// we do a memcmp() upward in memory. An overflow for that
// situation is taken care of below.
//
return( Err_NoMatch );
}
if( stop + sc.key.size() > tail )
{
uint diff = stop + sc.key.size() - tail;
stop = stop > diff ? stop - diff : 0;
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
recordStart( mCursor );
uint numReplaced = 0;
if( sc.forward == true )
{
for( uint i = start; i <= stop ; )
{
if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
{
i++;
}
else
{
cursorGoto( i, 7 );
recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
numReplaced += 1;
if( sc.inSelection == true )
{
if( sc.key.size() > sc.val.size() )
{
mSelect.shrink( sc.key.size() - sc.val.size() );
}
else
{
mSelect.expand( sc.val.size() - sc.key.size() );
}
}
if( sc.key.size() > sc.val.size() )
{
uint diff = sc.key.size() - sc.val.size();
stop -= QMIN( stop, diff );
}
else if( sc.key.size() < sc.val.size() )
{
stop += sc.val.size() - sc.key.size();
}
i += sc.val.size();
cursorStep( sc.val.size(), true, false );
}
}
}
else
{
for( uint i = stop; i >= start; )
{
if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) != 0 )
{
if( i == 0 ) { break; }
i--;
}
else
{
cursorGoto( i, 7 );
recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
numReplaced += 1;
if( sc.inSelection == true )
{
if( sc.key.size() > sc.val.size() )
{
mSelect.shrink( sc.key.size() - sc.val.size() );
}
else
{
mSelect.expand( sc.val.size() - sc.key.size() );
}
}
i -= QMIN( i, sc.key.size() );
if( i == 0 ) { break; }
}
}
}
recordEnd( mCursor );
computeNumLines();
if( numReplaced == 0 )
{
return( Err_NoMatch );
}
sc.numReplace += numReplaced;
sc.match = true;
mMark.reset();
return( Err_Success );
}
khexedit'CHexBuffer::replaceMarked() (./kdeutils/khexedit/hexbuffer.cc:3417)
int CHexBuffer::replaceMarked( SSearchControl &sc )
{
if( documentSize() == 0 )
{
return( Err_EmptyDocument );
}
if( mMark.valid() == false )
{
return( Err_NoMark );
}
bool inSelection;
if( mSelect.valid() == true )
{
if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
{
inSelection = true;
}
else
{
inSelection = false;
}
}
else
{
inSelection = false;
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
recordStart( mCursor );
cursorGoto( mMark.start(), 7 );
recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
sc.numReplace += 1;
if( inSelection == true )
{
if( mMark.size() > sc.val.size() )
{
mSelect.shrink( mMark.size() - sc.val.size() );
}
else
{
sc.wrapMark += sc.val.size() - mMark.size();
mSelect.expand( sc.val.size() - mMark.size() );
}
}
if( sc.wrapActive == false )
{
if( sc.forward == false )
{
sc.wrapMark += mMark.size() > sc.val.size() ?
mMark.size() - sc.val.size() : sc.val.size() - mMark.size();
}
}
recordEnd( mCursor );
computeNumLines();
if( sc.forward == true )
{
//
// We must step over the area we have just altered. This is
// vital if the search key contains a pattern that exists in
// the replace data buffer.
//
cursorStep( sc.val.size(), true, false );
}
mMark.reset();
return( Err_Success );
}
#if 0
int CHexBuffer::replaceAll( SSearchControl &sc, bool init )
{
if( init == true )
{
initScanData( sc );
}
if( sc.key.isEmpty() == true )
{
return( Err_EmptyArgument );
}
if( documentSize() == 0 )
{
return( Err_EmptyDocument );
}
uint head, tail;
if( sc.inSelection == true )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
head = mSelect.start();
tail = mSelect.stop();
}
else
{
head = 0;
tail = documentSize();
}
uint start, stop;
if( sc.fromCursor == false )
{
if( sc.wrapActive == true )
{
start = sc.forward == true ? head : sc.wrapMark;
stop = sc.forward == true ? sc.wrapMark : tail;
}
else
{
start = head;
stop = tail;
}
}
else if( sc.forward == true )
{
start = cursorOffset() < head ? head : cursorOffset();
stop = sc.wrapActive == true ? sc.wrapMark : tail;
}
else
{
start = sc.wrapActive == true ? sc.wrapMark : head;
stop = cursorOffset() > tail ? tail : cursorOffset();
}
if( start + sc.key.size() > stop )
{
return( Err_NoMatch );
}
if( stop + sc.key.size() > tail )
{
uint diff = stop + sc.key.size() - tail;
stop = stop > diff ? stop - diff : 0;
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
recordStart( mCursor );
uint numReplaced = 0;
if( sc.forward == true )
{
for( uint i = start; i <= stop; i++ )
{
if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
{
cursorGoto( i, 7 );
recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
numReplaced += 1;
if( sc.inSelection == true )
{
if( sc.key.size() > sc.val.size() )
{
mSelect.shrink( sc.key.size() - sc.val.size() );
}
else
{
mSelect.expand( sc.val.size() - sc.key.size() );
}
}
if( sc.key.size() > sc.key.size() )
{
uint diff = sc.key.size() - sc.val.size();
i += diff - 1;
}
else if( sc.key.size() < sc.val.size() )
{
uint diff = sc.val.size() - sc.key.size();
stop += diff;
}
else
{
i += sc.val.size() - 1;
}
cursorStep( sc.val.size(), true, false );
}
}
}
else
{
for( uint i = stop; i >= start; i-- )
{
if( memcmp( &data()[i], sc.key.data(), sc.key.size() ) == 0 )
{
cursorGoto( i, 7 );
recordReplace( mCursor, sc.key.size(), sc.val.data(), sc.val.size() );
numReplaced += 1;
if( sc.inSelection == true )
{
if( sc.key.size() > sc.val.size() )
{
mSelect.shrink( sc.key.size() - sc.val.size() );
}
else
{
mSelect.expand( sc.val.size() - sc.key.size() );
}
}
}
if( i == 0 ) { break; }
}
}
recordEnd( mCursor );
computeNumLines();
if( numReplaced == 0 )
{
return( Err_NoMatch );
}
sc.numReplace += numReplaced;
sc.match = true;
mMark.reset();
return( Err_Success );
}
int CHexBuffer::replaceMarked( SSearchControl &sc )
{
if( documentSize() == 0 )
{
return( Err_EmptyDocument );
}
if( mMark.valid() == false )
{
return( Err_NoMark );
}
bool inSelection;
if( mSelect.valid() == false )
{
if( mMark.start() >= mSelect.start() && mMark.stop() <= mSelect.stop() )
{
inSelection = true;
}
else
{
inSelection = false;
}
}
else
{
inSelection = false;
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
recordStart( mCursor );
cursorGoto( mMark.start(), 7 );
recordReplace( mCursor, mMark.size(), sc.val.data(), sc.val.size() );
sc.numReplace += 1;
if( inSelection == true )
{
if( mMark.size() > sc.val.size() )
{
mSelect.shrink( mMark.size() - sc.val.size() );
}
else
{
mSelect.expand( sc.val.size() - mMark.size() );
}
}
recordEnd( mCursor );
computeNumLines();
mMark.reset();
return( Err_Success );
}
khexedit'CHexBuffer::initScanData() (./kdeutils/khexedit/hexbuffer.cc:3725)
int CHexBuffer::initScanData( SSearchControl &sc )
{
sc.wrapValid = false;
sc.wrapActive = false;
sc.wrapMark = 0;
sc.match = false;
sc.numReplace = 0;
uint head, tail;
if( sc.inSelection == true )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
head = mSelect.start();
tail = mSelect.stop();
}
else
{
head = 0;
tail = documentSize();
}
if( sc.fromCursor == false )
{
sc.wrapValid = false;
sc.wrapActive = false;
sc.wrapMark = 0;
}
else if( sc.forward == true )
{
if( cursorOffset() > tail )
{
sc.wrapValid = true;
sc.wrapActive = false;
sc.wrapMark = tail;
}
else if( cursorOffset() <= head )
{
sc.wrapValid = false;
sc.wrapActive = false;
sc.wrapMark = 0;
}
else
{
sc.wrapValid = true;
sc.wrapActive = false;
sc.wrapMark = cursorOffset();
}
}
else
{
if( cursorOffset() >= tail )
{
sc.wrapValid = false;
sc.wrapActive = false;
sc.wrapMark = 0;
}
else if( cursorOffset() < head )
{
sc.wrapValid = true;
sc.wrapActive = false;
sc.wrapMark = head;
}
else
{
sc.wrapValid = true;
sc.wrapActive = false;
sc.wrapMark = cursorOffset();
}
}
return( Err_Success );
}
khexedit'CHexBuffer::scanData() (./kdeutils/khexedit/hexbuffer.cc:3804)
int CHexBuffer::scanData( SSearchControl &sc, bool init )
{
if( init == true )
{
int errCode = initScanData( sc );
if( errCode != Err_Success )
{
return( errCode );
}
}
if( sc.key.isEmpty() == true )
{
return( Err_EmptyArgument );
}
if( documentSize() == 0 )
{
return( Err_EmptyDocument );
}
uint head, tail;
if( sc.inSelection == true )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
head = mSelect.start();
tail = mSelect.stop();
}
else
{
head = 0;
tail = documentSize();
}
uint start, stop;
if( sc.fromCursor == false )
{
if( sc.wrapActive == true )
{
start = sc.forward == true ? head : sc.wrapMark;
stop = sc.forward == true ? sc.wrapMark+sc.key.size() : tail;
}
else
{
start = head;
stop = tail;
}
}
else if( sc.forward == true )
{
start = cursorOffset() < head ? head : cursorOffset();
stop = sc.wrapActive == true ? sc.wrapMark : tail;
}
else
{
start = sc.wrapActive == true ? sc.wrapMark : head;
stop = cursorOffset() > tail ? tail : cursorOffset();
}
if( sc.forward == true && start + sc.key.size() > stop )
{
//
// When searching backwards "stop" is the last offset from where
// we do a memcmp() upward in memory. An overflow for that
// situation is taken care of below.
//
return( stop + sc.key.size() < tail ? Err_WrapBuffer : Err_NoData );
}
if( stop + sc.key.size() > tail )
{
uint diff = stop + sc.key.size() - tail;
stop = stop > diff ? stop - diff : 0;
}
if( sc.forward == true )
{
for( uint i = start; i <= stop; i++ )
{
int result;
if( sc.ignoreCase == true )
{
result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
}
else
{
result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
}
if( result == 0 )
{
if( i != cursorOffset() || mMark.size() != sc.key.size() )
{
sc.match = true;
cursorGoto( i, 7 );
markSet( i, sc.key.size() );
return( Err_Success );
}
}
}
return( start > head ? Err_WrapBuffer : Err_NoData );
}
else
{
for( uint i = stop; i >= start; i-- )
{
int result;
if( sc.ignoreCase == true )
{
result = strncasecmp( &data()[i], sc.key.data(), sc.key.size() );
}
else
{
result = memcmp( &data()[i], sc.key.data(), sc.key.size() );
}
if( result == 0 )
{
if( i != cursorOffset() || mMark.size() != sc.key.size() )
{
sc.match = true;
cursorGoto( i, 7 );
markSet( i, sc.key.size() );
return( Err_Success );
}
}
if( i == 0 ) { break; }
}
return( stop + sc.key.size() <= tail ? Err_WrapBuffer : Err_NoData );
}
}
khexedit'CHexBuffer::filter() (./kdeutils/khexedit/hexbuffer.cc:3943)
int CHexBuffer::filter( SFilterControl &fc )
{
uint head, tail;
if( fc.inSelection == true )
{
if( mSelect.valid() == false )
{
return( Err_NoSelection );
}
head = mSelect.start();
tail = mSelect.stop();
}
else
{
head = 0;
tail = documentSize();
}
uint start, stop;
if( fc.fromCursor == false )
{
start = head;
stop = tail;
}
else if( fc.forward == true )
{
start = cursorOffset() < head ? head : cursorOffset();
stop = tail;
}
else
{
start = head;
stop = cursorOffset() > tail ? tail : cursorOffset();
}
if( mInputMode.noInput() == true )
{
inputSound();
return( Err_WriteProtect );
}
if( start >= stop ) { return( Err_IllegalRange ); }
QByteArray buf( stop - start );
if( buf.isEmpty() == true ) { return( Err_NoMemory ); }
int errCode = fc.execute((uchar*)&buf[0],(uchar*)&data()[start],buf.size());
if( errCode == Err_Success )
{
recordStart( mCursor );
cursorGoto( start, 7 );
recordReplace( mCursor, buf.size(), buf.data(), buf.size() );
recordEnd( mCursor );
}
return( errCode );
}
khexedit'CHexBuffer::collectStrings() (./kdeutils/khexedit/hexbuffer.cc:4003)
int CHexBuffer::collectStrings( CStringCollectControl &sc )
{
uint startOffset = 0;
uint start, i;
bool on = false;
if( sc.minLength < 1 ) { sc.minLength = 1; }
start = startOffset;
for( i = startOffset; i<documentSize(); i++ )
{
unsigned char item = data()[i];
if( isprint( item ) == 0 || item >= 128 )
{
if( on == true && i-start >= sc.minLength )
{
QByteArray a( i-start );
for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
sc.add( start, a );
}
on = false;
}
else
{
if( on == false ) { start = i; }
on = true;
}
}
if( on == true && i-start >= sc.minLength )
{
QByteArray a( i-start );
for( uint j=0; j<(i-start); a[j]=data()[start+j], j++ );
sc.add( start, a );
}
return( Err_Success );
}
khexedit'CHexBuffer::collectStatistic() (./kdeutils/khexedit/hexbuffer.cc:4043)
int CHexBuffer::collectStatistic( SStatisticControl &sc, CProgress &p )
{
sc.documentSize = documentSize();
sc.documentName = mUrl;
for( uint i = 0; i<documentSize(); i++ )
{
sc.occurence[ (unsigned char)data()[i] ] += 1;
//
// The expired() function introduces too much overhead in this case
// so it is only executed every 100'th character
//
if( i % 100 == 0 && p.expired() == true )
{
int errCode = p.step( (float)i/(float)documentSize() );
if( errCode == Err_Stop && i+1 < documentSize() )
{
p.finish();
return( Err_OperationAborted );
}
}
}
p.finish();
return( Err_NoErr );
}
khexedit'CHexBuffer::doActionGroup() (./kdeutils/khexedit/hexbuffer.cc:4071)
void CHexBuffer::doActionGroup( CHexActionGroup *group )
{
if( group == 0 )
{
return;
}
CHexAction *action = group->mHexAction;
group->mHexAction = 0;
while( action != 0 )
{
doAction( action );
CHexAction *next = action->mNext;
group->insertAction( action );
action = next;
}
computeNumLines();
}
khexedit'CHexBuffer::doAction() (./kdeutils/khexedit/hexbuffer.cc:4093)
void CHexBuffer::doAction( CHexAction *action )
{
if( action->mAction == CHexAction::replace )
{
doReplace( action, true );
}
}
khexedit'CHexBuffer::recordStart() (./kdeutils/khexedit/hexbuffer.cc:4105)
void CHexBuffer::recordStart( SCursor &cursor )
{
//
// Step 1: Remove any undo element that is more recent than the
// current undo index
//
while( mUndoList.count() > mUndoIndex )
{
mUndoList.removeLast();
}
//
// Step 2: Make sure the undo list is no larger than the undo limit.
// We remove the oldest elements in the list.
//
while( mUndoList.count() >= mUndoLimit )
{
mUndoList.removeFirst();
mUndoIndex -= 1;
}
CHexActionGroup *group = new CHexActionGroup( cursor.curr.offset,
cursor.bit() );
if( group == 0 )
{
return;
}
mUndoList.append( group );
mUndoIndex += 1;
}
khexedit'CHexBuffer::recordReplace() (./kdeutils/khexedit/hexbuffer.cc:4138)
void CHexBuffer::recordReplace( SCursor &cursor, uint size, char *data1,
uint data1Size )
{
CHexAction *hexAction = new CHexAction( CHexAction::replace,
cursor.curr.offset );
if( hexAction == 0 )
{
return;
}
hexAction->mSize = size;
hexAction->mData = data1;
hexAction->mDataSize = data1Size;
doReplace( hexAction, false );
mUndoList.getLast()->insertAction( hexAction );
if( mCursor.curr.offset < documentSize() )
{
mCursor.curr.data = data()[ mCursor.curr.offset ];
}
}
khexedit'CHexBuffer::recordEnd() (./kdeutils/khexedit/hexbuffer.cc:4162)
void CHexBuffer::recordEnd( SCursor &cursor )
{
mUndoList.getLast()->mStopOffset = cursor.curr.offset;
mUndoList.getLast()->mStopBit = cursor.bit();
}
//
// This method is the only place where the doucument data can be changed.
//
khexedit'CHexBuffer::doReplace() (./kdeutils/khexedit/hexbuffer.cc:4172)
void CHexBuffer::doReplace( CHexAction *hexAction, bool removeData )
{
uint offset = hexAction->mOffset;
uint oldSize = hexAction->mSize;
char *newData = hexAction->mData;
uint newSize = hexAction->mDataSize;
hexAction->setData( newSize, &data()[offset], oldSize );
//
// Input new data. Resize buffer first if necessary. We always mark the
// data as changed (dirty) when the buffer is resized, otherwise only
// when the new data differ from the current. Nice feature :-)
//
int errCode;
if( newSize > oldSize )
{
errCode = moveBuffer( offset + newSize - oldSize, offset );
mDocumentModified = true;
}
else if( newSize < oldSize )
{
errCode = moveBuffer( offset, offset + oldSize - newSize );
mDocumentModified = true;
}
else
{
errCode = Err_Success;
if( memcmp( &data()[offset], newData, newSize ) != 0 )
{
mDocumentModified = true;
}
}
if( errCode == Err_Success )
{
memcpy( &data()[offset], newData, newSize );
}
//
// Data is removed regardless of success or not. Otherwise we will
// have a mmeory leak. The single reason why the operation above could
// fail is because there was that no more memory that could be
// allocated.
//
if( removeData == true )
{
delete [] newData;
}
}
khexedit'CHexBuffer::inputDummy() (./kdeutils/khexedit/hexbuffer.cc:4225)
bool CHexBuffer::inputDummy( unsigned char *dest, int value, uint cell )
{
(void)dest;
(void)value;
(void)cell;
return( false );
}
khexedit'CHexBuffer::inputHexadecimal() (./kdeutils/khexedit/hexbuffer.cc:4234)
bool CHexBuffer::inputHexadecimal( unsigned char *dest, int value, uint cell )
{
if( value >= '0' && value <= '9' )
{
value = value - '0';
}
else if( value >= 'A' && value <= 'F' )
{
value = value - 'A' + 10;
}
else if( value >= 'a' && value <= 'f' )
{
value = value - 'a' + 10;
}
else
{
return( false );
}
if( cell > 1 )
{
return( false );
}
uint shift = 1 - cell;
*dest = (*dest & ~(0xF<<(shift*4)) ) | (value<<(shift*4));
return( true );
}
khexedit'CHexBuffer::inputDecimal() (./kdeutils/khexedit/hexbuffer.cc:4264)
bool CHexBuffer::inputDecimal( unsigned char *dest, int value, uint cell )
{
//
// 2000-01-22 Espen Sand
// I do the insertion a bit different here since decimal is special
// with respect to bitwidths.
//
if( value < '0' || value > '9' || cell > 2 )
{
return( false );
}
char buf[4];
printDecimalCell( buf, *dest );
buf[cell]=value;
buf[3]=0;
int tmp = atoi(buf);
if( tmp > 255 )
{
return( false );
}
*dest = tmp;
return( true );
}
khexedit'CHexBuffer::inputOctal() (./kdeutils/khexedit/hexbuffer.cc:4292)
bool CHexBuffer::inputOctal( unsigned char *dest, int value, uint cell )
{
if( value >= '0' && value <= '7' )
{
value = value - '0';
if( cell == 0 && value > 3 )
{
return( false );
}
}
else
{
return( false );
}
if( cell > 3 )
{
return( false );
}
uint shift = 2 - cell;
*dest = (*dest & ~(0x7<<(shift*3)) ) | (value<<(shift*3));
return( true );
}
khexedit'CHexBuffer::inputBinary() (./kdeutils/khexedit/hexbuffer.cc:4318)
bool CHexBuffer::inputBinary( unsigned char *dest, int value, uint cell )
{
if( value >= '0' && value <= '1' )
{
value = value - '0';
}
else
{
return( false );
}
if( cell > 7 )
{
return( false );
}
uint shift = 7 - cell;
*dest = (*dest & ~(1<<shift)) | (value<<shift);
return( true );
}
khexedit'CHexBuffer::inputAscii() (./kdeutils/khexedit/hexbuffer.cc:4341)
bool CHexBuffer::inputAscii( unsigned char *dest, int value, uint )
{
*dest = value;
return( true );
}
khexedit'CHexBuffer::moveBuffer() (./kdeutils/khexedit/hexbuffer.cc:4349)
int CHexBuffer::moveBuffer( uint destOffset, uint srcOffset )
{
if( srcOffset > documentSize() || destOffset == srcOffset )
{
return( Err_Success );
}
if( destOffset < srcOffset )
{
char *dest = &data()[ destOffset ];
char *src = &data()[ srcOffset ];
memmove( dest, src, documentSize() - srcOffset );
setDocumentSize( documentSize() - (srcOffset - destOffset) );
return( Err_Success );
}
else
{
uint s = documentSize() - srcOffset;
if( destOffset + s >= size() )
{
int errCode = resizeBuffer( destOffset + s );
if( errCode != Err_Success )
{
fatalSound();
return( errCode );
}
}
else
{
setDocumentSize( documentSize() + (destOffset - srcOffset) );
}
char *dest = &data()[ destOffset ];
char *src = &data()[ srcOffset ];
memmove( dest, src, s );
memset( src, 0, destOffset - srcOffset );
return( Err_Success );
}
}
khexedit'CHexBuffer::resizeBuffer() (./kdeutils/khexedit/hexbuffer.cc:4394)
int CHexBuffer::resizeBuffer( uint newSize )
{
if( newSize < documentSize() )
{
return( Err_Success );
}
if( newSize >= size() )
{
QByteArray tmp;
tmp.duplicate( data(), size() );
if( tmp.isNull() == true )
{
return( Err_NoMemory );
}
if( fill( '\0', newSize + 100 ) == false )
{
return( Err_NoMemory );
}
memcpy( data(), &tmp[0], tmp.size() );
}
setDocumentSize( newSize );
return( Err_Success );
}
khexedit'CHexBuffer::inputSound() (./kdeutils/khexedit/hexbuffer.cc:4423)
void CHexBuffer::inputSound( void )
{
if( mInputErrorSound == true )
{
QApplication::beep();
}
}
khexedit'CHexBuffer::fatalSound() (./kdeutils/khexedit/hexbuffer.cc:4432)
void CHexBuffer::fatalSound( void )
{
if( mFatalErrorSound == true )
{
QApplication::beep();
}
}
khexedit'CHexBuffer::printHtmlDataPage() (./kdeutils/khexedit/hexbuffer.cc:4441)
int CHexBuffer::printHtmlDataPage( const QString &tocName,
const QStringList &fileNames, uint index,
const SExportHtml &ex,
uint line, uint numLine )
{
if( fileNames.count() == 0 )
{
return( Err_NullArgument );
}
if( index >= fileNames.count() )
{
index = fileNames.count()-1;
}
QFile file( fileNames[index] );
if( file.open( IO_WriteOnly ) == false )
{
return( Err_OperationAborted );
}
QTextStream os( &file );
const QString *next = index+1 >= fileNames.count() ? 0 : &fileNames[index+1];
const QString *prev = index == 0 ? 0 : &fileNames[index-1];
const QString *toc = tocName.length() == 0 ? 0 : &tocName;
printHtmlHeader( os, true );
if( ex.navigator == true )
{
printHtmlNavigator( os, next, prev, toc );
}
printHtmlCaption( os, ex.topCaption, index+1, fileNames.count() );
printHtmlTable( os, line, numLine, ex.blackWhite );
printHtmlCaption( os, ex.bottomCaption, index+1, fileNames.count() );
if( ex.navigator == true )
{
printHtmlNavigator( os, next, prev, toc );
}
printHtmlHeader( os, false );
return( Err_Success );
}
khexedit'CHexBuffer::printHtmlTocPage() (./kdeutils/khexedit/hexbuffer.cc:4487)
void CHexBuffer::printHtmlTocPage( const QString &tocName,
const QString &linkName,
const QStringList &fileNames,
const QStringList &offsets,
uint numPage )
{
if( numPage == 0 || fileNames.count() == 0 )
{
return;
}
if( numPage >= fileNames.count() )
{
numPage = fileNames.count() - 1;
}
QFile file( tocName );
if( file.open( IO_WriteOnly ) == false )
{
return;
}
QTextStream os( &file );
printHtmlHeader( os, true );
os << "<P ALIGN=\"CENTER\">" << endl;
os << "<B><FONT COLOR=BLACK>" << endl;
os << mUrl << endl;
os << "</FONT></B></CAPTION>" << endl;
os << "</P>" << endl;
os << "<P ALIGN=\"CENTER\"><TT>" << endl;
for( uint i=0; i<=numPage; i++ )
{
QString n( fileNames[i].right( fileNames[i].length() -
fileNames[i].findRev('/') - 1) );
os << "<A HREF=\"" << n << "\">" << i18n("Page") << i+1;
os << "</A>";
os << " " << offsets[i];
os << "<br>" << endl;
}
os << "</P>" << endl;
printHtmlHeader( os, false );
if( linkName.isEmpty() == false )
{
//
// Make a symlink. We ignore any error here. I don't consider
// it to be fatal.
//
QString n( tocName.right( tocName.length() - tocName.findRev('/') - 1) );
symlink( n.latin1(), linkName.latin1() );
}
}
khexedit'CHexBuffer::printHtmlCaption() (./kdeutils/khexedit/hexbuffer.cc:4545)
void CHexBuffer::printHtmlCaption( QTextStream &os, uint captionType,
uint curPage, uint numPage )
{
QString caption;
switch( captionType )
{
case 0:
return;
break;
case 1:
caption = mUrl;
break;
case 2:
caption = mUrl.right( mUrl.length() - mUrl.findRev('/') - 1);
break;
case 3:
caption = i18n("Page %1 of %2").arg(curPage).arg(numPage);
break;
}
os << "<P ALIGN=\"CENTER\">" << endl;
os << "<B><FONT COLOR=BLACK>" << endl;
os << caption << endl;
os << "</FONT></B></CAPTION>" << endl;
os << "</P>" << endl;
}
khexedit'CHexBuffer::printHtmlNavigator() (./kdeutils/khexedit/hexbuffer.cc:4577)
void CHexBuffer::printHtmlNavigator( QTextStream &os, const QString *next,
const QString *prev, const QString *toc )
{
os << "<TABLE BORDER=\"0\" CELLSPACING=\"0\" WIDTH=\"100%\">" << endl;
os << "<TR>" << endl;
os << "<TD>" << endl;
if( next == 0 )
{
os << i18n("Next") << " ";
}
else
{
QString n( next->right( next->length() - next->findRev('/') - 1) );
os << "<A HREF=\"" << n << "\">" << i18n("Next") << "</A>" << " ";
}
if( prev == 0 )
{
os << i18n("Previous") << " ";
}
else
{
QString p( prev->right( prev->length() - prev->findRev('/') - 1) );
os << "<A HREF=\"" << p << "\">" << i18n("Previous") << "</A>" << " ";
}
if( toc == 0 )
{
os << i18n("Contents") << " ";
}
else
{
QString t( toc->right( toc->length() - toc->findRev('/') - 1) );
os << "<A HREF=\"" << t << "\">" << i18n("Contents");
os << "</A>" << " ";
}
os << "</TD>" << endl;
os << "<TD ALIGN=\"RIGHT\">" << endl;
os << "<A HREF=\"" << "http://home.sol.no/~espensa/khexedit" << "\">";
os << i18n("Generated by khexedit");
os << "</A>" << " ";
os << "</TD>" << endl;
os << "</TR>" << endl << "</TABLE>" << endl;
}
khexedit'CHexBuffer::printHtmlHeader() (./kdeutils/khexedit/hexbuffer.cc:4626)
int CHexBuffer::printHtmlHeader( QTextStream &os, bool isFront )
{
if( isFront == true )
{
os << "<HTML>" << endl << "<HEAD>" << endl;
os << "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; ";
os << "charset=iso-8859-1\">" << endl;
os << "<META NAME=\"hexdata\" CONTENT=\"khexedit dump\">" << endl;
os << "</HEAD>" << endl << "<BODY>" << endl;
}
else
{
os << "</BODY>" << endl << "</HTML>" << endl;
}
return( Err_Success );
}
khexedit'CHexBuffer::printHtmlTable() (./kdeutils/khexedit/hexbuffer.cc:4645)
int CHexBuffer::printHtmlTable( QTextStream &os, uint line, uint numLine,
bool bw )
{
uint i;
QColor color;
int numCol = 1;
if( mLayout.offsetVisible == true ) { numCol += 1; }
if( mLayout.secondaryMode != SDisplayLayout::hide ) { numCol += 1; }
os << "<TABLE BORDER=1 COLS=" << numCol << " WIDTH=\"100%\" ";
os << "CELLSPACING=0 CELLPADDING=2>" << endl;
if( mLayout.offsetVisible == true )
{
color = bw == true ? Qt::white : mColor.offsetBg;
os << "<TD BGCOLOR=" << color.name().latin1() << ">" << endl;
os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
os << "CELLSPACING=0 CELLPADDING=2>" << endl;
color = bw == true ? Qt::black : mColor.offsetFg;
for( i=0; i<numLine; i++ )
{
os << "<TR><TD><TT><b><FONT COLOR=" << color.name().latin1() << ">";
THIS_FPTR(printOffset)( mPrintBuf, (line+i)*mLayout.lineSize );
mPrintBuf[mOffsetSize]=0;
os << mPrintBuf << "</TD></TR>" << endl;
}
os << "</TABLE>" << endl << "</TD>" << endl;
}
color = bw == true ? Qt::white : mColor.textBg;
os << "<TD BGCOLOR=" << color.name().latin1() << ">" << endl;
os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
os << "CELLSPACING=0 CELLPADDING=2>" << endl;
for( i=0; i<numLine; i++ )
{
printHtmlLine( os, line+i, true, bw );
}
os << "</TABLE>" << endl << "</TD>" << endl;
if( mLayout.secondaryMode != SDisplayLayout::hide )
{
color = bw == true ? Qt::white : mColor.textBg;
os << "<TD BGCOLOR=" << color.name().latin1() << ">" << endl;
os << "<TABLE BORDER=0 COLS=1 WIDTH=\"100%\" ";
os << "CELLSPACING=0 CELLPADDING=2>" << endl;
for( i=0; i<numLine; i++ )
{
printHtmlLine( os, line+i, false, bw );
}
os << "</TABLE>" << endl << "</TD>" << endl;
}
os << "</TR>" << endl << "</TABLE>" << endl;
return( Err_Success );
}
khexedit'CHexBuffer::printHtmlLine() (./kdeutils/khexedit/hexbuffer.cc:4704)
int CHexBuffer::printHtmlLine( QTextStream &os, uint line, bool isPrimary,
bool bw )
{
uint offset = line * mLayout.lineSize;
QColor prevColor;
QColor color;
if( bw == true )
{
color = Qt::white;
}
else
{
color = (line+1) % 2 ? mColor.textBg : mColor.secondTextBg;
}
os << "<TR><TD NOWRAP BGCOLOR=" << color.name().latin1() << "><TT><B>"
<< endl;
if( offset >= documentSize() )
{
os << "<BR></TD></TR>" << endl;
return( Err_Success );
}
for( uint i=0; i < mLayout.lineSize; i++ )
{
if( isPrimary == true )
{
if( offset+i >= documentSize() )
{
memset(mPrintBuf, ' ', mNumCell );
mPrintBuf[mNumCell] = 0;
if( i == 0 )
{
color = bw == true ? Qt::black : foregroundColor(i);
}
else
{
color = prevColor;
}
}
else
{
unsigned char val = (unsigned char)data()[offset+i];
if( THIS_FPTR(printCell)( mPrintBuf, val ) == 0 )
{
color = bw == true ? Qt::black : foregroundColor(i);
}
else
{
color = bw == true ? Qt::black : mColor.nonPrintFg;
}
}
mPrintBuf[mNumCell] = 0;
if( i == 0 )
{
os << "<FONT COLOR=" << color.name().latin1() << ">";
}
else if( color != prevColor )
{
os << "</FONT><FONT COLOR=" << color.name().latin1() << ">";
}
prevColor = color;
if( mPrintBuf[0] == '<' )
{
os << "<";
}
else
{
os << mPrintBuf;
if( (i+1) % mLayout.columnSize == 0 && (i+1) != mLayout.lineSize )
{
os << " ";
}
}
}
else
{
if( offset+i >= documentSize() )
{
memset(mPrintBuf, ' ', 1 );
if( i == 0 )
{
color = bw == true ? Qt::black : mColor.secondaryFg;
}
else
{
color = prevColor;
}
}
else
{
unsigned char val = (unsigned char)data()[offset+i];
if( printAsciiCell( mPrintBuf, val ) == 0 )
{
color = bw == true ? Qt::black : mColor.secondaryFg;
}
else
{
color = bw == true ? Qt::black : mColor.nonPrintFg;
}
mPrintBuf[1] = 0;
if( i == 0 )
{
os << "<FONT COLOR=" << color.name().latin1() << ">";
}
else if( color != prevColor )
{
os << "</FONT><FONT COLOR=" << color.name().latin1() << ">";
}
prevColor = color;
mPrintBuf[1] = 0;
os << (mPrintBuf[0] == '<' ? "<" : mPrintBuf);
}
}
}
os << "</TD></TR>" << endl;
return( Err_Success );
}
khexedit'CHexBuffer::setStartY() (./kdeutils/khexedit/hexbuffer.h:2028)
inline void CHexBuffer::setStartY( int val )
{
mStartY = val;
}