Skip to content

Commit

Permalink
[New] Interface methods: GetCacheSize, GetData, GetDataMode, ModifyDa…
Browse files Browse the repository at this point in the history
…ta. HEXMODIFY struct.

[Changes] GetData<>, SetData<> templated methods generalized and moved from CHexCtrl.h to Helper.h.
It's now GetIHexTData, SetIHexTData.
All remaining internal circular dependencies are finally resolved and removed.
[Fixes] As a consequence of above changes the old-standing bug is fixed with an inability to Undo after
DataInterpreter changes applying.
  • Loading branch information
jovibor committed Dec 17, 2020
1 parent ed34b73 commit a137107
Show file tree
Hide file tree
Showing 14 changed files with 379 additions and 282 deletions.
4 changes: 4 additions & 0 deletions HexCtrl/HexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ namespace HEXCTRL
virtual bool CreateDialogCtrl(UINT uCtrlID, HWND hParent) = 0; //Сreates custom dialog control.
virtual void Destroy() = 0; //Deleter.
virtual void ExecuteCmd(EHexCmd enCmd) = 0; //Execute a command within the control.
[[nodiscard]] virtual auto GetCacheSize()const->DWORD = 0; //Returns Virtual/Message mode cache size.
[[nodiscard]] virtual DWORD GetCapacity()const = 0; //Current capacity.
[[nodiscard]] virtual ULONGLONG GetCaretPos()const = 0; //Cursor position.
[[nodiscard]] virtual auto GetColors()const->HEXCOLORSSTRUCT = 0; //Current colors.
[[nodiscard]] virtual auto GetData(HEXSPANSTRUCT hss)const->std::byte* = 0; //Get pointer to data offset, no matter what mode the control works in.
[[nodiscard]] virtual auto GetDataMode()const->EHexDataMode = 0; //Get current Data mode.
[[nodiscard]] virtual auto GetDataSize()const->ULONGLONG = 0; //Get currently set data size.
[[nodiscard]] virtual int GetEncoding()const = 0; //Get current code page ID.
[[nodiscard]] virtual long GetFontSize()const = 0; //Current font size.
Expand All @@ -75,6 +78,7 @@ namespace HEXCTRL
[[nodiscard]] virtual bool IsMutable()const = 0; //Is edit mode enabled or not.
[[nodiscard]] virtual bool IsOffsetAsHex()const = 0; //Is "Offset" currently represented (shown) as Hex or as Decimal.
[[nodiscard]] virtual HEXVISSTRUCT IsOffsetVisible(ULONGLONG ullOffset)const = 0; //Ensures that the given offset is visible.
virtual void ModifyData(const HEXMODIFY& hms) = 0; //Main routine to modify data in IsMutable()==true mode.
virtual void Redraw() = 0; //Redraw the control's window.
virtual void SetCapacity(DWORD dwCapacity) = 0; //Set the control's current capacity.
virtual void SetCaretPos(ULONGLONG ullOffset, bool fHighLow = true, bool fRedraw = true) = 0; //Set the caret position.
Expand Down
40 changes: 40 additions & 0 deletions HexCtrl/HexCtrlDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,44 @@ namespace HEXCTRL
std::int8_t i8Horz { }; //Horizontal offset.
operator bool()const { return i8Vert == 0 && i8Horz == 0; }; //For test simplicity: if(IsOffsetVisible()).
};

/********************************************************************************************
* EHexModifyMode - Enum of the data modification mode, used in HEXMODIFY. *
********************************************************************************************/
enum class EHexModifyMode : WORD
{
MODIFY_DEFAULT, MODIFY_REPEAT, MODIFY_OPERATION
};

/********************************************************************************************
* EHexOperMode - Enum of the data operation mode, used in HEXMODIFY when *
* HEXMODIFY::enModifyMode is set to MODIFY_OPERATION. *
********************************************************************************************/
enum class EHexOperMode : WORD
{
OPER_OR = 0x01, OPER_XOR, OPER_AND, OPER_NOT, OPER_SHL, OPER_SHR,
OPER_ADD, OPER_SUBTRACT, OPER_MULTIPLY, OPER_DIVIDE
};

/********************************************************************************************
* HEXMODIFY - used to represent data modification parameters. *
* When enModifyMode is set to EHexModifyMode::MODIFY_DEFAULT, bytes from pData just replace *
* corresponding data bytes as is. If enModifyMode is equal to EHexModifyMode::MODIFY_REPEAT *
* then block by block replacement takes place few times. *
* For example : if SUM(vecSpan.ullSize) = 9, ullDataSize = 3 and enModifyMode is set to *
* EHexModifyMode::MODIFY_REPEAT, bytes in memory at vecSpan.ullOffset position are *
* 123456789, and bytes pointed to by pData are 345, then, after modification, bytes at *
* vecSpan.ullOffset will be 345345345. If enModifyMode is equal to *
* EHexModifyMode::MODIFY_OPERATION then enOperMode comes into play, showing what kind of *
* operation must be performed on data. *
********************************************************************************************/
struct HEXMODIFY
{
EHexModifyMode enModifyMode { EHexModifyMode::MODIFY_DEFAULT }; //Modify mode.
EHexOperMode enOperMode { }; //Operation mode, used only if enModifyMode == MODIFY_OPERATION.
std::byte* pData { }; //Pointer to a data to be set.
ULONGLONG ullDataSize { }; //Size of the data pData is pointing to.
std::vector<HEXSPANSTRUCT> vecSpan { }; //Vector of data offsets and sizes.
bool fRedraw { true }; //Redraw HexCtrl's window after data changes?
};
};
Loading

0 comments on commit a137107

Please sign in to comment.