2
* This file is part of HexEditor plugin for Code::Blocks Studio
3
* Copyright (C) 2008-2009 Bartlomiej Swiecki
5
* HexEditor plugin is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 3 of the License, or
8
* (at your option) any later version.
10
* HexEditor pluging is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with HexEditor. If not, see <http://www.gnu.org/licenses/>.
19
* $Id: CharacterView.cpp 8208 2012-08-07 22:08:06Z killerbot $
20
* $HeadURL: http://svn.code.sf.net/p/codeblocks/code/branches/release-16.xx/src/plugins/contrib/HexEditor/CharacterView.cpp $
23
#include "CharacterView.h"
27
CharacterView::CharacterView( HexEditPanel* panel ): HexEditViewBase( panel )
31
void CharacterView::OnActivate( bool )
33
// We don't have to do anything
36
void CharacterView::OnOffsetChange(
37
OffsetT /*screenStartOffset*/,
38
OffsetT /*currentOffset*/,
39
OffsetT /*blockStart*/,
40
OffsetT /*blockEnd*/ )
42
// commented out the fopllowing 2 lines to avoid warning, since value set the argument that can in by value --> useless
43
//blockStart = currentOffset;
44
//blockEnd = currentOffset + 1;
47
void CharacterView::OnProcessChar(wxChar ch)
49
// We skip all non-printable characters
50
if ( !wxIsprint( ch ) || ch >= 0x100 ) return;
52
// Check if we didnt went out of the file
53
if ( GetCurrentOffset() >= GetContent()->GetSize() ) return;
55
// Calculate offset after the change
56
OffsetT nextPosition = std::min( GetContent()->GetSize(), GetCurrentOffset() + 1 );
58
// Change affected byte
59
GetContent()->WriteByte(
60
FileContentBase::ExtraUndoData( this, GetCurrentOffset(), 0, nextPosition, 0 ),
67
void CharacterView::OnMoveLeft()
69
if ( GetCurrentOffset() == 0 ) return;
70
OffsetChange( GetCurrentOffset() - 1 );
73
void CharacterView::OnMoveRight()
75
if ( GetCurrentOffset() >= GetContent()->GetSize()-1 ) return;
76
OffsetChange( GetCurrentOffset() + 1 );
79
void CharacterView::OnMoveUp()
81
if ( GetCurrentOffset() < GetLineBytes() ) return;
82
OffsetChange( GetCurrentOffset() - GetLineBytes() );
85
void CharacterView::OnMoveDown()
87
if ( GetCurrentOffset() >= GetContent()->GetSize() - GetLineBytes() ) return;
88
OffsetChange( GetCurrentOffset() + GetLineBytes() );
91
void CharacterView::OnPutLine( OffsetT startOffset, HexEditLineBuffer& buff, char* content, int bytes )
93
for ( int i=0; i<bytes; ++i )
97
( startOffset+i != GetCurrentOffset() ) ? stNormal :
98
GetActive() ? stCurCar : stCurNon
102
int lineBytes = (int)GetLineBytes();
104
for ( int i=bytes; i<lineBytes; ++i )
110
void CharacterView::OnGetBlockSizes( int& blockLength, int& blockBytes, int& spacing )
112
blockLength = 1; // One char per byte
113
blockBytes = 1; // One byte in block
114
spacing = 0; // No spacing between blocks
117
int CharacterView::OnGetOffsetFromColumn( int column, int& positionFlags )
123
inline char CharacterView::Strip( char ch )
125
if ( !isprint( ch ) ) return ' ';
126
if ( ch >= 0x7F ) return ' ';