Skip to content

Commit 30f3421

Browse files
committed
[Changes] Latest HexCtrl with fixes for cases when ullDataSize in SetData is zero.
Sections with SizeOfRawData == 0 now show empty.
1 parent 00f5891 commit 30f3421

File tree

3 files changed

+51
-33
lines changed

3 files changed

+51
-33
lines changed

Pepper/FileLoader.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ HRESULT CFileLoader::LoadFile(LPCWSTR lpszFileName, CPepperDoc* pDoc)
7171
return S_OK;
7272
}
7373

74-
HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize, IHexCtrl* pHexCtrl)
74+
HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelSize, IHexCtrl* pHexCtrl)
7575
{
7676
if (!pHexCtrl)
7777
{
@@ -95,8 +95,6 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
9595
m_hds.pData = pData;
9696
m_hds.ullDataSize = static_cast<ULONGLONG>(m_stFileSize.QuadPart);
9797
m_hds.enDataMode = enMode;
98-
m_hds.stSelSpan.ullOffset = ullOffset;
99-
m_hds.stSelSpan.ullSize = ullSelectionSize;
10098

10199
auto const& iter = std::find_if(m_vecQuery.begin(), m_vecQuery.end(),
102100
[pHexCtrl](const QUERYDATA & r) {return r.hWnd == pHexCtrl->GetWindowHandle(EHexWnd::WND_MAIN); });
@@ -111,9 +109,7 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
111109
//to ShowOffset or to ShowFilePiece. If the latter we reset it to show full file.
112110
if (fExist)
113111
{
114-
if (!iter->fShowPiece)
115-
pHexCtrl->GoToOffset(ullOffset, true, ullSelectionSize);
116-
else
112+
if (iter->fShowPiece)
117113
{
118114
iter->ullOffsetDelta = 0;
119115
iter->fShowPiece = false;
@@ -123,6 +119,14 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
123119
else
124120
pHexCtrl->SetData(m_hds);
125121

122+
if (ullSelSize > 0)
123+
{
124+
std::vector<HEXSPANSTRUCT> vecSel { { ullOffset, ullSelSize } };
125+
pHexCtrl->SetSelection(vecSel);
126+
if (!pHexCtrl->IsOffsetVisible(ullOffset))
127+
pHexCtrl->GoToOffset(ullOffset);
128+
}
129+
126130
//If floating HexCtrl in use - bring it to front.
127131
if (pHexCtrl == m_pHex.get())
128132
::SetForegroundWindow(pHexCtrl->GetWindowHandle(EHexWnd::WND_MAIN));
@@ -177,7 +181,6 @@ HRESULT CFileLoader::ShowFilePiece(ULONGLONG ullOffset, ULONGLONG ullSize, IHexC
177181
m_hds.pData = pData;
178182
m_hds.ullDataSize = ullSize;
179183
m_hds.enDataMode = enMode;
180-
m_hds.stSelSpan.ullSize = 0;
181184
pHexCtrl->SetData(m_hds);
182185

183186
return S_OK;

Pepper/include/FileLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class CFileLoader : public CWnd
2727
[[nodiscard]] bool IsWritable()const { return m_fWritable; }
2828
//Shows arbitrary offset in already loaded file (LoadFile)
2929
//If pHexCtrl == nullptr inner CHexCtrl object is used.
30-
HRESULT ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize, IHexCtrl* pHexCtrl = nullptr);
30+
HRESULT ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelSize, IHexCtrl* pHexCtrl = nullptr);
3131
//Shows only a piece of the whole loaded file.
3232
//If pHexCtrl == nullptr inner CHexCtrl object is used.
3333
HRESULT ShowFilePiece(ULONGLONG ullOffset, ULONGLONG ullSize, IHexCtrl* pHexCtrl = nullptr);

Pepper/include/HexCtrl.h

Lines changed: 40 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,21 @@ namespace HEXCTRL
4444
********************************************************************************************/
4545
enum class EHexCmd : WORD
4646
{
47-
CMD_SEARCH = 0x01, CMD_SEARCH_NEXT, CMD_SEARCH_PREV,
47+
CMD_DLG_SEARCH = 0x01, CMD_SEARCH_NEXT, CMD_SEARCH_PREV,
48+
CMD_NAV_DLG_GOTO, CMD_NAV_REPFWD, CMD_NAV_REPBKW, CMD_NAV_DATABEG, CMD_NAV_DATAEND,
49+
CMD_NAV_PAGEBEG, CMD_NAV_PAGEEND, CMD_NAV_LINEBEG, CMD_NAV_LINEEND,
4850
CMD_SHOWDATA_BYTE, CMD_SHOWDATA_WORD, CMD_SHOWDATA_DWORD, CMD_SHOWDATA_QWORD,
49-
CMD_BKM_ADD, CMD_BKM_REMOVE, CMD_BKM_NEXT, CMD_BKM_PREV, CMD_BKM_CLEARALL, CMD_BKM_MANAGER,
50-
CMD_CLIPBOARD_COPY_HEX, CMD_CLIPBOARD_COPY_HEXLE, CMD_CLIPBOARD_COPY_HEXFMT, CMD_CLIPBOARD_COPY_TEXT,
51-
CMD_CLIPBOARD_COPY_BASE64, CMD_CLIPBOARD_COPY_CARR, CMD_CLIPBOARD_COPY_GREPHEX, CMD_CLIPBOARD_COPY_PRNTSCRN,
52-
CMD_CLIPBOARD_PASTE_HEX, CMD_CLIPBOARD_PASTE_TEXT,
53-
CMD_MODIFY_OPERS, CMD_MODIFY_FILLZEROS, CMD_MODIFY_FILLDATA, CMD_MODIFY_UNDO, CMD_MODIFY_REDO,
51+
CMD_BKM_ADD, CMD_BKM_REMOVE, CMD_BKM_NEXT, CMD_BKM_PREV, CMD_BKM_CLEARALL, CMD_BKM_DLG_MANAGER,
52+
CMD_CLPBRD_COPYHEX, CMD_CLPBRD_COPYHEXLE, CMD_CLPBRD_COPYHEXFMT, CMD_CLPBRD_COPYTEXT,
53+
CMD_CLPBRD_COPYBASE64, CMD_CLPBRD_COPYCARR, CMD_CLPBRD_COPYGREPHEX, CMD_CLPBRD_COPYPRNTSCRN,
54+
CMD_CLPBRD_PASTEHEX, CMD_CLPBRD_PASTETEXT,
55+
CMD_MODIFY_DLG_OPERS, CMD_MODIFY_FILLZEROS, CMD_MODIFY_DLG_FILLDATA, CMD_MODIFY_UNDO, CMD_MODIFY_REDO,
5456
CMD_SEL_MARKSTART, CMD_SEL_MARKEND, CMD_SEL_ALL, CMD_SEL_ADDLEFT, CMD_SEL_ADDRIGHT, CMD_SEL_ADDUP, CMD_SEL_ADDDOWN,
55-
CMD_DATAINTERPRET, CMD_ENCODING,
56-
CMD_APPEARANCE_FONTINC, CMD_APPEARANCE_FONTDEC, CMD_APPEARANCE_CAPACINC, CMD_APPEARANCE_CAPACDEC,
57-
CMD_PRINT, CMD_ABOUT,
57+
CMD_DLG_DATAINTERP, CMD_DLG_ENCODING,
58+
CMD_APPEAR_FONTINC, CMD_APPEAR_FONTDEC, CMD_APPEAR_CAPACINC, CMD_APPEAR_CAPACDEC,
59+
CMD_DLG_PRINT, CMD_DLG_ABOUT,
5860
CMD_CARET_LEFT, CMD_CARET_RIGHT, CMD_CARET_UP, CMD_CARET_DOWN,
59-
CMD_SCROLL_PAGEUP, CMD_SCROLL_PAGEDOWN, CMD_SCROLL_TOP, CMD_SCROLL_BOTTOM
61+
CMD_SCROLL_PAGEUP, CMD_SCROLL_PAGEDOWN
6062
};
6163

6264
/********************************************************************************************
@@ -91,7 +93,8 @@ namespace HEXCTRL
9193
********************************************************************************************/
9294
enum class EHexWnd : WORD
9395
{
94-
WND_MAIN, DLG_BKMMANAGER, DLG_DATAINTERPRET, DLG_FILLDATA, DLG_OPERS, DLG_SEARCH, DLG_ENCODING
96+
WND_MAIN, DLG_BKMMANAGER, DLG_DATAINTERP, DLG_FILLDATA,
97+
DLG_OPERS, DLG_SEARCH, DLG_ENCODING, DLG_GOTO
9598
};
9699

97100
/********************************************************************************************
@@ -213,7 +216,6 @@ namespace HEXCTRL
213216
{
214217
EHexDataMode enDataMode { EHexDataMode::DATA_MEMORY }; //Working data mode.
215218
ULONGLONG ullDataSize { }; //Size of the data to display, in bytes.
216-
HEXSPANSTRUCT stSelSpan { }; //Select .ullOffset initial position. Works only if .ullSize > 0.
217219
HWND hwndMsg { }; //Window for DATA_MSG mode. Parent is used by default.
218220
IHexVirtData* pHexVirtData { }; //Pointer for DATA_VIRTUAL mode.
219221
IHexVirtColors* pHexVirtColors { }; //Pointer for Custom Colors class.
@@ -245,6 +247,15 @@ namespace HEXCTRL
245247
bool fIsAscii { false }; //Is cursor at ASCII part or at Hex.
246248
};
247249

250+
/********************************************************************************************
251+
* HEXVISSTRUCT - Offset visibility struct, used in IsOffsetVisible method. *
252+
********************************************************************************************/
253+
struct HEXVISSTRUCT
254+
{
255+
std::int8_t i8Vert { }; //Vertical offset.
256+
std::int8_t i8Horz { }; //Horizontal offset.
257+
operator bool() { return i8Vert == 0 && i8Horz == 0; }; //For test simplicity: if(IsOffsetVisible()).
258+
};
248259

249260
/********************************************************************************************
250261
* IHexCtrl - pure abstract base class. *
@@ -264,38 +275,42 @@ namespace HEXCTRL
264275
virtual bool Create(const HEXCREATESTRUCT& hcs) = 0; //Main initialization method.
265276
virtual bool CreateDialogCtrl(UINT uCtrlID, HWND hParent) = 0; //Сreates custom dialog control.
266277
virtual void Destroy() = 0; //Deleter.
267-
virtual void ExecuteCmd(EHexCmd enCmd) = 0; //Execute a command within the control.
278+
virtual void ExecuteCmd(EHexCmd enCmd) = 0; //Execute a command within the control.
268279
[[nodiscard]] virtual DWORD GetCapacity()const = 0; //Current capacity.
269280
[[nodiscard]] virtual ULONGLONG GetCaretPos()const = 0; //Cursor position.
270281
[[nodiscard]] virtual auto GetColors()const->HEXCOLORSSTRUCT = 0; //Current colors.
282+
[[nodiscard]] virtual auto GetDataSize()const->ULONGLONG = 0; //Get currently set data size.
271283
[[nodiscard]] virtual int GetEncoding()const = 0; //Get current code page ID.
272284
[[nodiscard]] virtual long GetFontSize()const = 0; //Current font size.
273285
[[nodiscard]] virtual HMENU GetMenuHandle()const = 0; //Context menu handle.
274-
[[nodiscard]] virtual DWORD GetSectorSize()const = 0; //Current sector size.
286+
[[nodiscard]] virtual auto GetPagesCount()const->ULONGLONG = 0; //Get count of pages.
287+
[[nodiscard]] virtual auto GetPagePos()const->ULONGLONG = 0; //Get current page a cursor stays at.
288+
[[nodiscard]] virtual DWORD GetPageSize()const = 0; //Current page size.
275289
[[nodiscard]] virtual auto GetSelection()const->std::vector<HEXSPANSTRUCT> = 0; //Gets current selection.
276290
[[nodiscard]] virtual auto GetShowMode()const->EHexShowMode = 0; //Retrieves current show mode.
277291
[[nodiscard]] virtual HWND GetWindowHandle(EHexWnd enWnd)const = 0; //Retrieves control's window/dialog handle.
278-
virtual void GoToOffset(ULONGLONG ullOffset, bool fSelect = false, ULONGLONG ullSize = 1) = 0; //Scrolls to given offset.
292+
virtual void GoToOffset(ULONGLONG ullOffset, int iRelPos = 0) = 0; //Go (scroll) to a given offset.
279293
[[nodiscard]] virtual auto HitTest(POINT pt, bool fScreen = true)const->std::optional<HEXHITTESTSTRUCT> = 0; //HitTest given point.
280294
[[nodiscard]] virtual bool IsCmdAvail(EHexCmd enCmd)const = 0; //Is given Cmd currently available (can be executed)?
281295
[[nodiscard]] virtual bool IsCreated()const = 0; //Shows whether control is created or not.
282296
[[nodiscard]] virtual bool IsDataSet()const = 0; //Shows whether a data was set to the control or not.
283297
[[nodiscard]] virtual bool IsMutable()const = 0; //Is edit mode enabled or not.
284298
[[nodiscard]] virtual bool IsOffsetAsHex()const = 0; //Is "Offset" currently represented (shown) as Hex or as Decimal.
285-
[[nodiscard]] virtual bool IsOffsetVisible(ULONGLONG ullOffset)const = 0; //Ensures that given offset is visible.
299+
[[nodiscard]] virtual HEXVISSTRUCT IsOffsetVisible(ULONGLONG ullOffset)const = 0; //Ensures that the given offset is visible.
286300
virtual void Redraw() = 0; //Redraw the control's window.
287-
virtual void SetCapacity(DWORD dwCapacity) = 0; //Sets the control's current capacity.
288-
virtual void SetColors(const HEXCOLORSSTRUCT& clr) = 0;//Sets all the control's colors.
301+
virtual void SetCapacity(DWORD dwCapacity) = 0; //Set the control's current capacity.
302+
virtual void SetCaretPos(ULONGLONG ullOffset, bool fHighLow = true, bool fRedraw = true) = 0; //Set the caret position.
303+
virtual void SetColors(const HEXCOLORSSTRUCT& clr) = 0;//Set all the control's colors.
289304
virtual bool SetConfig(std::wstring_view wstrPath) = 0;//Set configuration file, or "" for defaults.
290305
virtual void SetData(const HEXDATASTRUCT& hds) = 0; //Main method for setting data to display (and edit).
291-
virtual void SetEncoding(int iCodePage) = 0; //Code page for text area.
292-
virtual void SetFont(const LOGFONTW* pLogFont) = 0; //Sets the control's new font. This font has to be monospaced.
293-
virtual void SetFontSize(UINT uiSize) = 0; //Sets the control's font size.
306+
virtual void SetEncoding(int iCodePage) = 0; //Code-page for text area.
307+
virtual void SetFont(const LOGFONTW* pLogFont) = 0; //Set the control's new font. This font has to be monospaced.
308+
virtual void SetFontSize(UINT uiSize) = 0; //Set the control's font size.
294309
virtual void SetMutable(bool fEnable) = 0; //Enable or disable mutable/edit mode.
295-
virtual void SetSectorSize(DWORD dwSize, std::wstring_view wstrName = L"Sector") = 0; //Sets sector/page size and name to draw the lines in-between.
296-
virtual void SetSelection(const std::vector<HEXSPANSTRUCT>& vecSel) = 0; //Sets current selection.
297-
virtual void SetShowMode(EHexShowMode enMode) = 0; //Sets current data show mode.
298-
virtual void SetWheelRatio(double dbRatio) = 0; //Sets the ratio for how much to scroll with mouse-wheel.
310+
virtual void SetPageSize(DWORD dwSize, std::wstring_view wstrName = L"Page") = 0; //Set page size and name to draw the lines in-between.
311+
virtual void SetSelection(const std::vector<HEXSPANSTRUCT>& vecSel, bool fRedraw = true) = 0; //Set current selection.
312+
virtual void SetShowMode(EHexShowMode enMode) = 0; //Set current data show mode.
313+
virtual void SetWheelRatio(double dbRatio) = 0; //Set the ratio for how much to scroll with mouse-wheel.
299314
};
300315

301316
/********************************************************************************************

0 commit comments

Comments
 (0)