/** * @file XTPHexEdit.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPHEXEDIT_H__) # define __XTPHEXEDIT_H__ /** @endcond */ # if _MSC_VER >= 1000 # pragma once # endif // _MSC_VER >= 1000j # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" # ifdef _XTP_ACTIVEX # define CXTPHexEditBase CXTPOleControl # else # define CXTPHexEditBase CEdit # endif /** * @brief * CXTPHexEdit is a CEdit derived class. It is used to create an edit control * which will allow editing in hex display format. */ class _XTP_EXT_CLASS CXTPHexEdit : public CXTPHexEditBase { /** @cond */ DECLARE_DYNAMIC(CXTPHexEdit) /** @endcond */ protected: /** * @brief * Enumeration used to determine current editing mode. * @details * EditMode type defines the constants used by the CXTPHexEdit * class to determine the current editing mode. * @see * CXTPHexEdit * * @see editNone, editAscii, editHigh, editLow */ enum EditMode { editNone, /**< No editing mode specified. */ editAscii, /**< ASCII editing mode. */ editHigh, /**< High editing mode. */ editLow /**< Low editing mode. */ }; public: /** * @brief * Constructs a CXTPHexEdit object. */ CXTPHexEdit(); /** * @brief * Destroys a CXTPHexEdit object, handles cleanup and deallocation. */ virtual ~CXTPHexEdit(); public: /** * @brief * This method creates the HexEdit control. * @param dwStyle Style for the HexEdit. * @param rect Specifies the size and position of the HexEdit control. * @param pParentWnd Specifies the parent window of the HexEdit control. * @param nID Specifies the HexEdit control ID. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID); /** * @brief * This method creates the HexEdit control. * @param dwStyle Style for the HexEdit. * @param rect Specifies the size and position of the HexEdit control. * @param pParentWnd Specifies the parent window of the HexEdit control. * @param nID Specifies the HexEdit control ID. * @param lpszClassName Class Name ("EDIT" by default). * @param lpszWindowName Window Name. * @param pContext Pointer to the CCreateContext. * @return * TRUE if successful, otherwise FALSE. */ virtual BOOL Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL); /** * @brief * Call this member function to return the current background color of * the hex edit control. The current background color depends on the * enabled, disabled, or read-only state of the control. * @return * An RGB value that represents the current background color of the control. */ COLORREF GetActualBackColor(); /** * @brief * Call this member function to return the current text color of the hex * edit control. The current text color depends on the enabled, disabled, * or read-only state of the control. * @return * An RGB value that represents the current text color of the control. */ COLORREF GetActualTextColor(); /** * @brief * Call this member function to return the current highlight background * color of the hex edit control. The current highlight background color * depends on the enabled, disabled, or read-only state of the control. * @return * An RGB value that represents the current highlight background color * of the control. */ COLORREF GetActualHighlightBackColor(); /** * @brief * Call this member function to return the current highlight text color * of the hex edit control. The current highlight text color depends * on the enabled, disabled, or read-only state of the control. * @return * An RGB value that represents the current highlight text color * of the control. */ COLORREF GetActualHighlightTextColor(); /** * @brief * Call this member function to set the background color for the hex edit * control. * @param crBack An RGB value that represents the background color for * the hex edit control. */ void SetBackColor(COLORREF crBack); /** * @brief * Call this member function to retrieve the current background color * of the hex edit control. * @return * An RGB value that represents the current background color of * the hex edit control. */ COLORREF GetBackColor(); /** * @brief * Call this member function to set the text color for the hex * edit control. * @param crText An RGB value that represents the text color for the * hex edit control. */ void SetTextColor(COLORREF crText); /** * @brief * Call this member function to retrieve the current text color of the * hex edit control. * @return * An RGB value that represents the current text color of * the hex edit control. */ COLORREF GetTextColor(); /** * @brief * Call this member function to set the disabled background color for * the hex edit control. * @param crDisabledBack An RGB value that represents the disabled background * color for the hex edit control. */ void SetDisabledBackColor(COLORREF crDisabledBack); /** * @brief * Call this member function to retrieve the current disabled background * color of the hex edit control. * @return * An RGB value that represents the current disabled background * color of the hex edit control. */ COLORREF GetDisabledBackColor(); /** * @brief * Call this member function to set the disabled text color for the hex * edit control. * @param crDisabledText An RGB value that represents the disabled text * color for the hex edit control. */ void SetDisabledTextColor(COLORREF crDisabledText); /** * @brief * Call this member function to retrieve the current disabled text color * of the hex edit control. * @return * An RGB value that represents the current disabled text color * of the hex edit control. */ COLORREF GetDisabledTextColor(); /** * @brief * Call this member function to set the highlighted text color for the * hex edit control. * @param crHighlightText An RGB value that represents the highlighted * text color for the hex edit control. */ void SetHighlightTextColor(COLORREF crHighlightText); /** * @brief * Call this member function to retrieve the current highlighted text * color of the hex edit control. * @return * An RGB value that represents the current highlighted text color * of the hex edit control. */ COLORREF GetHighlightTextColor(); /** * @brief * Call this member function to set the highlight background color for * the hex edit control. * @param crHighlight An RGB value that represents the highlight background * color for the hex edit control. */ void SetHighlightBackColor(COLORREF crHighlight); /** * @brief * Call this member function to retrieve the current highlight background * color of the hex edit control. * @return * An RGB value that represents the current highlight background * color of the hex edit control. */ COLORREF GetHighlightBackColor(); /** * @brief * Call this member function to set the disabled highlight text color for * the hex edit control. * @param crDisabledHighlightText An RGB value that represents the disabled * highlight text color for the hex edit control. */ void SetDisabledHighlightTextColor(COLORREF crDisabledHighlightText); /** * @brief * Call this member function to retrieve the current disabled highlight * text color of the hex edit control. * @return * An RGB value that represents the current disabled highlight text color * of the hex edit control. */ COLORREF GetDisabledHighlightTextColor(); /** * @brief * Call this member function to set the disabled highlight background * color for the hex edit control. * @param crDisabledHighlight An RGB value that represents the disabled * highlight background color for the hex edit * control. */ void SetDisabledHighlightBackColor(COLORREF crDisabledHighlight); /** * @brief * Call this member function to retrieve the current disabled highlight * background color of the hex edit control. * @return * An RGB value that represents the current disabled highlight background color * of the hex edit control. */ COLORREF GetDisabledHighlightBackColor(); /** * @brief * This member function sets the font for the hex edit control to the * default "Courier New" font. */ void RestoreDefaultFont(); /** * @brief * This member function sets the font used by the hex edit control. * @param pFont Pointer to a valid CFont object. */ void SetHexFont(CFont* pFont); /** * @brief * This member function sets the font used by the hex edit control. * @param pLogFont Pointer to a valid LOGFONT structure. */ void SetHexFont(LOGFONT* pLogFont); /** * @brief * This member function enables/disables a flashing screen caret. * @param bEnable true to enable caret, false to disable. */ void EnableCaret(bool bEnable); /** * @brief * This member function enables/disables a vertical and horizontal * scrollbar display. * @param bVertical true to display vertical scrollbar. * @param bHorizontal true to display horizontal scrollbar. */ void EnableScrollBars(bool bVertical, bool bHorizontal); /** * @brief * Call this member function to set the base address for the hex edit * control. * @param dwBase A DWORD value that represents the base address. * @return * A DWORD value. */ DWORD SetAddressBase(DWORD dwBase); /** * @brief * Call this method to extract the data in the hex edit control. * @param pData Pointer to the buffer that will be receiving the data. * @param nBufferLength Length of the target data buffer. * @return * The length of the data. */ int GetData(LPBYTE pData, int nBufferLength); /** * @brief * Call this member function to initialize the hex edit control with data * specified by 'pData'. * @param pData Pointer to a buffer that contains the initial data for the control. * @param nLength Length of the data buffer. * @param nMaxLength Optional maximum length that the buffer can grow, or -1 if you * want to allow the buffer to grow indefinitely. */ void SetData(LPBYTE pData, int nLength, int nMaxLength = 0); /** * @brief * Call this method to allow/disallow the deletion of characters * within the control. For instance, calling SetAllowDeletes(false) will * disable the delete, backspace, and other such keys. * @param bVal true to allow the deletion of characters within the control, * false to disallow. * @return * The previous value of the Allow Deletes setting. */ bool SetAllowDeletes(bool bVal = true); /** * @brief * This member function retrieves the current value of the Allow Deletes * setting. * @return * true if the Allow Deletes setting is enabled, or false if it is disabled. * @see * SetAllowDeletes */ bool GetAllowDeletes() const; /** * @brief * Call this member function to get the size of the current selection. * non-selected character past the end of the current selection. * @return * A CSize object. */ CSize GetSel(); /** * @brief * Call this member function to get the size of the current selection. * @param nSelStart Reference to an integer that will receive the position of the first * character in the current selection. * @param nSelEnd Reference to an integer that will receive the position of the first * non-selected character past the end of the current selection. */ void GetSel(int& nSelStart, int& nSelEnd); /** * @brief * Call this member function to set the current selection. * @param nSelStart Represents the position of the first character in the selection. * @param nSelEnd Represents the position of the last character in the selection. */ void SetSel(int nSelStart, int nSelEnd); /** * @brief * Call this member function to set the number of bytes per row. * @param nBytePerRow Represents the number of bytes to display. */ void SetBPR(int nBytePerRow); /** * @brief * Call this member function to set the display options for the hex edit * control. * @param bShowAddress TRUE to display the address value. * @param bShowHex TRUE to display the hex value. * @param bShowAscii TRUE to display the ASCII value. * @param bAddressIsWide TRUE if the display is 8 byte, FALSE for 4 byte display. */ void SetOptions(BOOL bShowAddress, BOOL bShowHex, BOOL bShowAscii, BOOL bAddressIsWide); /** * @brief * Call this member function to determine if the control is in a read-only state. * @return * TRUE if the control is in a read-only state, otherwise FALSE. */ BOOL IsReadOnly() const; /** * @brief * This method is called when the user changes text. */ virtual void OnChange(); protected: /** @cond */ DECLARE_MESSAGE_MAP() //{{AFX_VIRTUAL(CXTPHexEdit) virtual BOOL PreCreateWindow(CREATESTRUCT& cs); //}}AFX_VIRTUAL //{{AFX_MSG(CXTPHexEdit) afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnKillFocus(CWnd* pNewWnd); afx_msg void OnPaint(); afx_msg LRESULT OnPrintClient(WPARAM wParam, LPARAM /*lParam*/); afx_msg void OnDraw(CDC* pDC); afx_msg void OnSetFocus(CWnd* pOldWnd); afx_msg void OnSize(UINT nType, int cx, int cy); afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); afx_msg UINT OnGetDlgCode(); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnLButtonDown(UINT nFlags, CPoint point); afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); afx_msg void OnMouseMove(UINT nFlags, CPoint point); afx_msg void OnLButtonUp(UINT nFlags, CPoint point); afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); afx_msg void OnContextMenu(CWnd*, CPoint point); afx_msg void OnEditClear(); afx_msg void OnEditCopy(); afx_msg void OnEditCut(); afx_msg void OnEditPaste(); afx_msg void OnEditSelectAll(); afx_msg void OnEditUndo(); afx_msg void OnNcPaint(); afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt); //}}AFX_MSG /** @endcond */ private: void ScrollIntoView(int pData); void RepositionCaret(int pData); void Move(int x, int y); BOOL IsSelected(); void UpdateScrollbars(); void CreateEditCaret(); void CreateAddressCaret(); CPoint CalcPos(int x, int y); void SelInsert(int nSelStart, int nLength); void SelDelete(int nSelStart, int nSelEnd); void NormalizeSel(); void RecalcBPR(); void DoVScroll(UINT nSBCode, bool bMoveCaret); public: int m_nLength; /**< Length of data. */ int m_nTopIndex; /**< Offset of first visible byte on the screen. */ int m_nCurrentAddress; /**< Address under the cursor. */ int m_nSelStart; /**< Start address of the selection. */ int m_nSelEnd; /**< End address of the selection. */ int m_nBytePerRow; /**< Bytes per row. */ int m_nLinesPerPage; /**< Lines per page. */ int m_nLineHeight; /**< Height in pixels of a single line displayed in the control. */ int m_nNullWidth; /**< Width in pixels of a single character displayed in the control (uniform width). */ int m_nOffHex; /**< Internally used value - X position where hex part starts. */ int m_nOffAscii; /**< Internally used value - X position where ASCII part starts. */ int m_nOffAddress; /**< Internally used value - X position where address part starts. */ bool m_bAllowDeletes; /**< A boolean value indicating whether or not deletions are allowed. */ BOOL m_bDynamicBPR; /**< Calculate bytes-per-row dynamically. */ BOOL m_bShowAddress; /**< TRUE when showing the address part. */ BOOL m_bShowAscii; /**< TRUE when showing the ASCII part. */ BOOL m_bShowHex; /**< TRUE when showing the hex part. */ BOOL m_bAddressIsWide; /**< 4/8 byte address. */ BOOL m_bUpdate; /**< Value used internally to indicate that the font and size info need to be updated on the next paint cycle. */ UINT m_nMaxLength; /**< Maximum size of data. */ DWORD m_dwBaseAddress; /**< Base address for data. */ CPoint m_ptEditPos; /**< Current caret position. */ LPBYTE m_pData; /**< Pointer to data. */ EditMode m_eEditMode; /**< Current editing mode: address/hex/ASCII. */ protected: BOOL m_bShowCaret; /**< TRUE to display a flashing caret at the current caret position. */ CSize m_szCaret; /**< Current size of caret. */ CXTPFont m_xtpFontHex; /**< Represents the default font used by the hex edit control. */ XTP_SUBSTITUTE_GDI_MEMBER_WITH_CACHED(CFont, m_fontHex, m_xtpFontHex, GetHexFontHandle); COLORREF m_crBack; /**< RGB value that represents the background color of the hex edit control. */ COLORREF m_crText; /**< RGB value that represents the text color of the hex edit control. */ COLORREF m_crDisabledBack; /**< RGB value that represents the disabled background color for the hex edit control. */ COLORREF m_crDisabledText; /**< RGB value that represents the disabled text color of the hex edit control. */ COLORREF m_crHighlightText; /**< RGB value that represents the highlighted text color of the hex edit control. */ COLORREF m_crHighlightBack; /**< RGB value that represents the highlighted background color of the hex edit control. */ COLORREF m_crDisabledHighlightText; /**< RGB value that represents the disabled highlighted text color of the hex edit control. */ COLORREF m_crDisabledHighlightBack; /**< RGB value that represents the disabled highlighted background color of the hex edit control. */ }; ////////////////////////////////////////////////////////////////////// /** @cond */ AFX_INLINE UINT CXTPHexEdit::OnGetDlgCode() { return DLGC_WANTALLKEYS; } AFX_INLINE void CXTPHexEdit::SetOptions(BOOL bShowAddress, BOOL bShowHex, BOOL bShowAscii, BOOL bAddressIsWide) { m_bShowHex = bShowHex; m_bShowAscii = bShowAscii; m_bShowAddress = bShowAddress; m_bAddressIsWide = bAddressIsWide; m_bUpdate = TRUE; RepositionCaret(m_nCurrentAddress); } AFX_INLINE void CXTPHexEdit::SetBPR(int nBytePerRow) { if (nBytePerRow < 1) nBytePerRow = 1; if (nBytePerRow > 256) nBytePerRow = 256; if (nBytePerRow != m_nBytePerRow) { m_nBytePerRow = nBytePerRow; m_bUpdate = TRUE; RepositionCaret(m_nCurrentAddress); } } AFX_INLINE BOOL CXTPHexEdit::IsSelected() { return m_nSelStart != 0xffffffff; } AFX_INLINE CSize CXTPHexEdit::GetSel() { return CSize(m_nSelStart, m_nSelEnd); } AFX_INLINE void CXTPHexEdit::SetBackColor(COLORREF crBack) { m_crBack = crBack; } AFX_INLINE void CXTPHexEdit::SetTextColor(COLORREF crText) { m_crText = crText; } AFX_INLINE void CXTPHexEdit::SetDisabledBackColor(COLORREF crDisabledBack) { m_crDisabledBack = crDisabledBack; } AFX_INLINE void CXTPHexEdit::SetDisabledTextColor(COLORREF crDisabledText) { m_crDisabledText = crDisabledText; } AFX_INLINE void CXTPHexEdit::SetHighlightTextColor(COLORREF crHighlightText) { m_crHighlightText = crHighlightText; } AFX_INLINE void CXTPHexEdit::SetHighlightBackColor(COLORREF crHighlightBack) { m_crHighlightBack = crHighlightBack; } AFX_INLINE void CXTPHexEdit::SetDisabledHighlightTextColor(COLORREF crDisabledHighlightText) { m_crDisabledHighlightText = crDisabledHighlightText; } AFX_INLINE void CXTPHexEdit::SetDisabledHighlightBackColor(COLORREF crDisabledHighlightBack) { m_crDisabledHighlightBack = crDisabledHighlightBack; } AFX_INLINE COLORREF CXTPHexEdit::GetBackColor() { return m_crBack; } AFX_INLINE COLORREF CXTPHexEdit::GetTextColor() { return m_crText; } AFX_INLINE COLORREF CXTPHexEdit::GetDisabledBackColor() { return m_crDisabledBack; } AFX_INLINE COLORREF CXTPHexEdit::GetDisabledTextColor() { return m_crDisabledText; } AFX_INLINE COLORREF CXTPHexEdit::GetHighlightTextColor() { return m_crHighlightText; } AFX_INLINE COLORREF CXTPHexEdit::GetHighlightBackColor() { return m_crHighlightBack; } AFX_INLINE COLORREF CXTPHexEdit::GetDisabledHighlightTextColor() { return m_crDisabledHighlightText; } AFX_INLINE COLORREF CXTPHexEdit::GetDisabledHighlightBackColor() { return m_crDisabledHighlightBack; } AFX_INLINE void CXTPHexEdit::EnableCaret(bool bEnable) { m_bShowCaret = bEnable; } AFX_INLINE bool CXTPHexEdit::SetAllowDeletes(bool bVal) { const bool bOldVal = m_bAllowDeletes; m_bAllowDeletes = bVal; return bOldVal; } AFX_INLINE bool CXTPHexEdit::GetAllowDeletes() const { return m_bAllowDeletes; } /** @endcond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" /** @cond */ #endif // #if !defined(__XTPHEXEDIT_H__) /** @endcond */