~efargaspro/+junk/codeblocks-16.01-release

« back to all changes in this revision

Viewing changes to src/plugins/contrib/HexEditor/CharacterView.cpp

  • Committer: damienlmoore at gmail
  • Date: 2016-02-02 02:43:22 UTC
  • Revision ID: damienlmoore@gmail.com-20160202024322-yql5qmtbwdyamdwd
Code::BlocksĀ 16.01

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* This file is part of HexEditor plugin for Code::Blocks Studio
 
3
* Copyright (C) 2008-2009 Bartlomiej Swiecki
 
4
*
 
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.
 
9
*
 
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.
 
14
*
 
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/>.
 
17
*
 
18
* $Revision: 8208 $
 
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 $
 
21
*/
 
22
 
 
23
#include "CharacterView.h"
 
24
 
 
25
#include <algorithm>
 
26
 
 
27
CharacterView::CharacterView( HexEditPanel* panel ): HexEditViewBase( panel )
 
28
{
 
29
}
 
30
 
 
31
void CharacterView::OnActivate( bool )
 
32
{
 
33
    // We don't have to do anything
 
34
}
 
35
 
 
36
void CharacterView::OnOffsetChange(
 
37
    OffsetT  /*screenStartOffset*/,
 
38
    OffsetT  /*currentOffset*/,
 
39
    OffsetT /*blockStart*/,
 
40
    OffsetT /*blockEnd*/ )
 
41
{
 
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;
 
45
}
 
46
 
 
47
void CharacterView::OnProcessChar(wxChar ch)
 
48
{
 
49
    // We skip all non-printable characters
 
50
    if ( !wxIsprint( ch ) || ch >= 0x100 ) return;
 
51
 
 
52
    // Check if we didnt went out of the file
 
53
    if ( GetCurrentOffset() >= GetContent()->GetSize() ) return;
 
54
 
 
55
    // Calculate offset after the change
 
56
    OffsetT nextPosition = std::min( GetContent()->GetSize(), GetCurrentOffset() + 1 );
 
57
 
 
58
    // Change affected byte
 
59
    GetContent()->WriteByte(
 
60
        FileContentBase::ExtraUndoData( this, GetCurrentOffset(), 0, nextPosition, 0 ),
 
61
        GetCurrentOffset(),
 
62
        (unsigned char) ch );
 
63
 
 
64
    OnMoveRight();
 
65
}
 
66
 
 
67
void CharacterView::OnMoveLeft()
 
68
{
 
69
    if ( GetCurrentOffset() == 0 ) return;
 
70
    OffsetChange( GetCurrentOffset() - 1 );
 
71
}
 
72
 
 
73
void CharacterView::OnMoveRight()
 
74
{
 
75
    if ( GetCurrentOffset() >= GetContent()->GetSize()-1 ) return;
 
76
    OffsetChange( GetCurrentOffset() + 1 );
 
77
}
 
78
 
 
79
void CharacterView::OnMoveUp()
 
80
{
 
81
    if ( GetCurrentOffset() < GetLineBytes() ) return;
 
82
    OffsetChange( GetCurrentOffset() - GetLineBytes() );
 
83
}
 
84
 
 
85
void CharacterView::OnMoveDown()
 
86
{
 
87
    if ( GetCurrentOffset() >= GetContent()->GetSize() - GetLineBytes() ) return;
 
88
    OffsetChange( GetCurrentOffset() + GetLineBytes() );
 
89
}
 
90
 
 
91
void CharacterView::OnPutLine( OffsetT startOffset, HexEditLineBuffer& buff, char* content, int bytes )
 
92
{
 
93
    for ( int i=0; i<bytes; ++i )
 
94
    {
 
95
        buff.PutChar(
 
96
            Strip( *content++ ),
 
97
            ( startOffset+i != GetCurrentOffset() ) ? stNormal :
 
98
            GetActive() ? stCurCar : stCurNon
 
99
        );
 
100
    }
 
101
 
 
102
    int lineBytes = (int)GetLineBytes();
 
103
 
 
104
    for ( int i=bytes; i<lineBytes; ++i )
 
105
    {
 
106
        buff.PutChar( ' ' );
 
107
    }
 
108
}
 
109
 
 
110
void CharacterView::OnGetBlockSizes( int& blockLength, int& blockBytes, int& spacing )
 
111
{
 
112
    blockLength = 1;    // One char per byte
 
113
    blockBytes  = 1;    // One byte in block
 
114
    spacing     = 0;    // No spacing between blocks
 
115
}
 
116
 
 
117
int CharacterView::OnGetOffsetFromColumn( int column, int& positionFlags )
 
118
{
 
119
    positionFlags = 0;
 
120
    return column;
 
121
}
 
122
 
 
123
inline char CharacterView::Strip( char ch )
 
124
{
 
125
    if ( !isprint( ch ) ) return ' ';
 
126
    if ( ch >= 0x7F ) return ' ';
 
127
    return ch;
 
128
}