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: HexEditViewBase.h 5445 2009-02-07 00:35:09Z byo $
20
* $HeadURL: svn+ssh://jenslody@svn.berlios.de/svnroot/repos/codeblocks/trunk/src/plugins/contrib/HexEditor/HexEditViewBase.h $
23
#ifndef HEXEDITVIEWBASE_H
24
#define HEXEDITVIEWBASE_H
26
#include "FileContentBase.h"
27
#include "HexEditLineBuffer.h"
32
/** \brief Base class for the view in editor area
34
* This is base interface used to represent views inside of the editor
35
* (like the hex view or character preview, I don't know anything about
36
* other usages at the momment of writing this peace of code ;) )
38
* Offtopic: There's strange story about how this class was created
39
* I tried to make some nice solution for the problem with lack
40
* of editor's flexibility. I tied at least four solutions and
41
* I was dropping the m one after another since more problems
42
* were found while coding. Finally I was so angry about that
43
* that I said "God help me" ... and the solution was just
44
* few hours later, jumped into my mind just with all those
45
* details needed to make it work. Yeah, for me it's a proof
46
* that God really exists and that He cares about the
47
* Open-Source community :)
53
typedef FileContentBase::OffsetT OffsetT;
56
HexEditViewBase( HexEditPanel* panel );
59
virtual ~HexEditViewBase();
61
/** \brief Activate this view
62
* \return previous active state
64
bool SetActive( bool makeMeActive = true );
66
/** \brief Get the active state */
67
bool GetActive() { return m_IsActive; }
69
/** \brief Calculate size of block at current offset's position */
70
void CalculateBlockSize(
71
OffsetT screenStartOffset,
72
OffsetT currentOffset,
76
/** \brief Jump to given offset and calculate range for current data block
77
* \param screenStartOffset offset of first data byte shown on the screen
78
* \param currentOffset offset of current position
79
* \param blockStart here current block start is put and new value will be stored if wider range is required
80
* \param blockEnd here current block end is put and new value will be storeed if wider range is required
81
* \param positionFlags flags of current position (like which bit of the byte is currently edited), this
82
* argument will be -1 if called can not deduce it's value
85
OffsetT screenStartOffset,
86
OffsetT currentOffset,
91
/** \brief Get scrren start offset */
92
OffsetT GetScreenStartOffset() { return m_ScreenStartOffset; }
94
/** \brief Get current position offset */
95
OffsetT GetCurrentOffset() { return m_CurrentOffset; }
97
/** \brief Get flags for current offset */
98
int GetCurrentPositionFlags() { return OnGetCurrentPositionFlags(); }
100
/** \brief Get block start offset */
101
OffsetT GetBlockStartOffset() { return m_BlockStartOffset; }
103
/** \brief Get block end offset */
104
OffsetT GetBlockEndOffset() { return m_BlockEndOffset; }
106
/** \brief Drop a character into this view
107
* \note If the view is not active, character will not be processed
109
void PutChar( wxChar ch );
111
/** \brief Move cursor left */
114
/** \brief Move cursor right */
117
/** \brief Move cursor up */
120
/** \brief Move cursor down */
123
/** \brief Put given line into line buffer */
124
void PutLine( OffsetT lineStartOffset, HexEditLineBuffer& buffer, char* content, int bytes );
126
/** \brief Get block sizez */
127
void GetBlockSizes( int& blockLength, int& blockBytes, int& spacing );
129
/** \brief Detect offset from position in line */
130
int GetOffsetFromColumn( int column, int& positionFlags );
134
/** \brief Called when switching the active state */
135
virtual void OnActivate( bool becomesActive ) = 0;
137
/** \brief Detect block start and end at given offset */
138
virtual void OnCalculateBlockSize( OffsetT& blockStart, OffsetT& blockEnd );
140
/** \brief Called when changing current cursor offset */
141
virtual void OnOffsetChange( int positionFlags );
143
/** \brief Called when fetching current position flags */
144
virtual int OnGetCurrentPositionFlags();
146
/** \brief Called when character is sent to this view */
147
virtual void OnProcessChar( wxChar ) = 0;
149
/** \brief Called when moving left */
150
virtual void OnMoveLeft() = 0;
152
/** \brief Called when moving right */
153
virtual void OnMoveRight() = 0;
155
/** \brief Called when moving up */
156
virtual void OnMoveUp() = 0;
158
/** \brief Called when moving down */
159
virtual void OnMoveDown() = 0;
161
/** \brief Called when there's need to fill line buffer for this content */
162
virtual void OnPutLine( OffsetT startOffset, HexEditLineBuffer& buff, char* content, int bytes ) = 0;
164
/** \brief Fetching informations about current data block sizes
165
* \param blockLength length of block in characters
166
* \param blockBytes number of bytes in one block
167
* \param spacing number of characters splitting two blocks next to each other
169
virtual void OnGetBlockSizes( int& blockLength, int& blockBytes, int& spacing ) = 0;
171
/** \brief Calculate offset from the beginning of the line at given position */
172
virtual int OnGetOffsetFromColumn( int column, int& positionFlags ) = 0;
175
/** \brief Fetch assigned file content */
176
FileContentBase* GetContent();
178
/** \brief Get length of one line */
179
unsigned int GetLineBytes();
181
/** \brief Notify about offset change
182
* \param currentOffset new current offset
184
void OffsetChange( OffsetT currentOffset );
186
/** \brief Notify about content change */
187
void ContentChange();
192
bool m_IsActive; ///< \brief Set to true if this view is active (has keyboard focus)
193
OffsetT m_ScreenStartOffset; ///< \brief Offset of first data byte shown on the screen
194
OffsetT m_CurrentOffset; ///< \brief Offset of current byte
195
OffsetT m_BlockStartOffset; ///< \brief Start offset of current data block
196
OffsetT m_BlockEndOffset; ///< \brief End offset of current data block
197
HexEditPanel* m_Panel; ///< \brief Owning panel