www.pudn.com > HexEditOcx.rar > HexEditCtl.h


/* 
 * Softerra Hex Editor (c) Softerra, LLC 2005 
 * 
 * FILENAME:	HexEditCtl.h 
 * SUBSYSTEM:	Core 
 * DESCRIPTION:	Declaration of the CHexEditCtrl ActiveX Control class. 
 *		See HexEditCtl.cpp for implementation. 
 */ 
 
#if !defined(SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_) 
#define SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_ 
 
#if _MSC_VER > 1000 
#pragma once 
#endif // _MSC_VER > 1000 
 
/*! CHexEditCtrl ActiveX Control class.*/ 
class CHexEditCtrl : public COleControl, 
	public CLangEventListener 
{ 
	DECLARE_DYNCREATE(CHexEditCtrl) 
 
/*! Constructor */ 
public: 
	CHexEditCtrl(); 
 
// Overrides 
	// ClassWizard generated virtual function overrides 
	//{{AFX_VIRTUAL(CHexEditCtrl) 
	public: 
	virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid); 
	virtual void DoPropExchange(CPropExchange* pPX); 
	virtual void OnResetState(); 
	protected: 
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs); 
	//}}AFX_VIRTUAL 
 
// Implementation 
protected: 
// Properties 
 
	/*! Data displayed.*/ 
	COleSafeArray m_data; 
 
	/*! Data edit result.*/ 
	VARIANT* m_pDestData; 
 
	/*! Number of hex digits shown in address field (4 or 8).*/ 
	short m_digitsInAddress; 
 
	/*! Number of hex digits in one number 
	 - 2 - BYTE view 
  	 - 4 - WORD view 
	 - 8 - DWORD view 
	 */ 
	short m_digitsInData; 
 
	/*! Number of columns.*/ 
	short m_columns; 
 
	/*! Font height.*/ 
	short m_fontHeight; 
 
	/*! Starting address to display.*/ 
	DWORD m_dwStartAddr; 
 
	/*! True if data are modified.*/ 
	bool m_bDataModified; 
 
// Other data 
 
	/*! This value equals the following expression: (m_showAscii && m_digitsInData == 2).*/ 
	bool m_bRealShowAscii; 
 
	/*! Current horizontal scroll shift in chars.*/ 
	int m_nHorzScroll; 
 
	/*! True after WM_LBUTTONDOWN, false after WM_LBUTTONUP.*/ 
	bool m_bMouseDown; 
 
	/*! True after WM_MOUSEMOVE, false after WM_LBUTTONUP.*/ 
	bool m_bMouseMove; 
 
	/*! Address of number under mouse cursor in WM_LBUTTONDOWN.*/ 
	int m_posMouseDown; 
 
	/*! Window size in chars.*/ 
	CSize m_charCountWindow; 
 
	/*! Total view size in chars.*/ 
	CSize m_charCountView; 
 
	/*! Char size in device points.*/ 
	CSize m_cellSize; 
 
	/* !!! IMPORTANT 
		m_selStart, m_selEnd and other addresses of numbers are counts of numbers (NOT NESESSARY BYTES!), 
		depending on m_digitsInData.*/ 
 
	/*! Selection start (in numbers).*/ 
	long m_selStart; 
 
	/*! Selection end (in numbers).*/ 
	long m_selEnd; 
 
	/*! Address of number being edited.*/ 
	long m_editPos; 
 
	/*! Address of the first visible number.*/ 
	long m_viewPos; 
 
	/*! Digit being edited (0 - leftmost).*/ 
	int m_nEditDigit; 
 
	/*! Right margin of address field in chars.*/ 
	int m_addrMargin; 
 
	/*! Left margin of ASCII field in chars.*/ 
	int m_asciiMargin; 
 
	/*! This value is a combination of following flags: 
	- EDIT_BYTES - edit hex data mode (if not set - edit ASCII data) 
	- EDIT_INSERT - insert mode (if not set - overwrite mode) 
	*/ 
	int m_editMode; 
 
	/*! Control client rect.*/ 
	CRect m_rcClient; 
 
	/*! True if timer is active.*/ 
	bool m_bTimer; 
 
	/*! Coordinates of last point in OnMouseMove.*/ 
	CPoint m_prevMousePoint; 
 
	/*! Name of the window class.*/ 
	static CString m_strWindowClass; 
 
   	/*! Lock for m_strWindowClass.*/ 
   	static CCriticalSection _critSect; 
 
	/*! This function calls pdc->TextOut ( x, y, strText ) function if text overlaps with rcInvalid.*/ 
	void TextOutWithCheck(CDC* pdc, const CRect& rcInvalid, int x, int y, CString& strText ); 
 
	/*! This function calls pdc->TextOut ( x, y, eChar ) function if char overlaps with rcInvalid.*/ 
	void CharOutWithCheck(CDC* pdc, const CRect &rcInvalid, int x, int y, WCHAR wChar); 
 
	/*! This function called before entering a new number or ascii byte. 
	 * It does InsertBytes, scrolling, repainting if nesessary. 
	 * @return false, if it's impossible to insert number because of 
	 * m_allowChangeSize == false, otherwise - true. 
	 */ 
	bool EnterNumber(); 
 
	/*! Clear selection.*/ 
	void ClearSelection(); 
 
	/*! Delete currently selected data.*/ 
	void DeleteSelection(); 
 
	/*! Update selection margins when mouse is moving. 
	 * @param point mouse coordinates. 
	 */ 
	void RecalcSelection(CPoint point); 
 
	/*! Returns true, if nothing is selected, and false otherwise.*/ 
	bool IsSelectionEmpty(); 
 
	/*! Recalculate scroll ranges and positions of scrollbars, 
	 * show or hide scroll bars if nesessary. 
	 */ 
	bool UpdateScrollBars(); 
 
	/*! Invalidate rect occupied by number with address nEditPos.*/ 
	void InvalidateEditRect(long nEditPos); 
 
	/*! Delete dwCount numbers (not bytes!) from m_data, starting from dwPos.*/ 
	void DeleteData ( DWORD dwPos, DWORD dwCount = 1 ); 
 
	/*! Insert dwCount numbers (not bytes!) in m_data, starting from dwPos.*/ 
	void InsertData ( DWORD dwPos, DWORD dwCount = 1 ); 
 
	/*! Update caret position and scroll bars when m_editPos is changed.*/ 
	bool NormalizeEditPos(); 
 
	/*! Set new edit position after mouse click. 
	 * @param pt - mouse coordinates. 
	 */ 
	void ChangeEditPos ( CPoint pt ); 
 
	/*! Get prefered code page depends on current keyboard loyout.*/ 
	UINT GetPreferedCodePage(); 
 
 
	/*! Set new edit position after moving caret. 
	 * @param dx - horizontal shift of cursor (in numbers), positive - left, negative - right direction 
	 * @param dx - vertical shift of cursor (in numbers), positive - down, negative - upward direction 
	 * @param bRepaint = true - repaint the control always,	false - only if scrolling is nesessary 
	 */ 
	void ChangeEditPos ( long dx, long dy, bool bRepaint = false); 
 
	/*! Calculate coordinates and show caret.*/ 
	void PlaceCaret(); 
 
	/*! Compute m_editPos, m_viewPos, margins etc. after changing properties of the control.*/ 
	void RecalcLayout(); 
 
	/*! Destructor*/ 
	~CHexEditCtrl(); 
 
	DECLARE_OLECREATE_EX(CHexEditCtrl)	// Class factory and guid 
	DECLARE_OLETYPELIB(CHexEditCtrl)		// GetTypeInfo 
	DECLARE_PROPPAGEIDS(CHexEditCtrl)		// Property page IDs 
	DECLARE_OLECTLTYPE(CHexEditCtrl)		// Type name and misc status 
 
// Message maps 
	//{{AFX_MSG(CHexEditCtrl) 
	afx_msg void OnKillFocus(CWnd* pNewWnd); 
	afx_msg void OnSetFocus(CWnd* pOldWnd); 
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags); 
	afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); 
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point); 
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point); 
	afx_msg UINT OnGetDlgCode(); 
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point); 
	afx_msg void OnMouseMove(UINT nFlags, CPoint point); 
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); 
	afx_msg void OnEditCopy(); 
	afx_msg void OnEditCut(); 
	afx_msg void OnEditPaste(); 
	afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI); 
	afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI); 
	afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI); 
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar); 
	afx_msg void OnTimer(UINT nIDEvent); 
	afx_msg void OnSize(UINT nType, int cx, int cy); 
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); 
	afx_msg void OnDestroy(); 
	//}}AFX_MSG 
	afx_msg void OnEditSelectAll(); 
	afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI); 
	DECLARE_MESSAGE_MAP() 
	afx_msg void OnContextMenu(CWnd*, CPoint point);	// right click handler 
	virtual void OnLangEvent(int nCode, WPARAM wParam, LPARAM lParam); 
 
// Dispatch maps 
	//{{AFX_DISPATCH(CHexEditCtrl) 
	BOOL m_showAddress; 
	afx_msg void OnShowAddressChanged(); 
	BOOL m_showAscii; 
	afx_msg void OnShowAsciiChanged(); 
	BOOL m_allowChangeSize; 
	afx_msg void OnAllowChangeSizeChanged(); 
	BOOL m_dataModified; 
	afx_msg void OnDataModifiedChanged(); 
	afx_msg short GetDigitsInAddress(); 
	afx_msg void SetDigitsInAddress(short nNewValue); 
	afx_msg short GetDigitsInData(); 
	afx_msg void SetDigitsInData(short nNewValue); 
	afx_msg short GetColumns(); 
	afx_msg void SetColumns(short nNewValue); 
	afx_msg short GetFontHeight(); 
	afx_msg void SetFontHeight(short nNewValue); 
	afx_msg SCODE SetData(VARIANT FAR* pData, long dwStartAddr); 
	afx_msg SCODE GetData(VARIANT FAR* pData); 
	//}}AFX_DISPATCH 
	DECLARE_DISPATCH_MAP() 
 
	afx_msg void AboutBox(); 
 
// Event maps 
	//{{AFX_EVENT(CHexEditCtrl) 
	//}}AFX_EVENT 
	DECLARE_EVENT_MAP() 
 
// Dispatch and event IDs 
public: 
	enum { 
	//{{AFX_DISP_ID(CHexEditCtrl) 
	dispidShowAddress = 1L, 
	dispidShowAscii = 2L, 
	dispidDigitsInAddress = 5L, 
	dispidDigitsInData = 6L, 
	dispidColumns = 7L, 
	dispidFontHeight = 8L, 
	dispidAllowChangeSize = 3L, 
	dispidDataModified = 4L, 
	dispidSetData = 9L, 
	dispidGetData = 10L, 
	//}}AFX_DISP_ID 
	}; 
 
	enum { 
		vtCharArray = VT_ARRAY | VT_I1, 
		vtByteArray = VT_ARRAY | VT_UI1 
	}; 
 
	inline bool PermissibleType(VARTYPE vt); 
}; 
 
//{{AFX_INSERT_LOCATION}} 
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. 
 
#endif // !defined(SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_)