HexEditCtl.h

00001 /*
00002  * Softerra Hex Editor (c) Softerra, LLC 2005
00003  *
00004  * FILENAME:    HexEditCtl.h
00005  * SUBSYSTEM:   Core
00006  * DESCRIPTION: Declaration of the CHexEditCtrl ActiveX Control class.
00007  *              See HexEditCtl.cpp for implementation.
00008  */
00009 
00010 #if !defined(SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_)
00011 #define SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_
00012 
00013 #if _MSC_VER > 1000
00014 #pragma once
00015 #endif // _MSC_VER > 1000
00016 
00018 class CHexEditCtrl : public COleControl
00019 {
00020       DECLARE_DYNCREATE(CHexEditCtrl)
00021 
00023 public:
00024         CHexEditCtrl();
00025 
00026 // Overrides
00027         // ClassWizard generated virtual function overrides
00028         //{{AFX_VIRTUAL(CHexEditCtrl)
00029         public:
00030         virtual void OnDraw(CDC* pdc, const CRect& rcBounds, const CRect& rcInvalid);
00031         virtual void DoPropExchange(CPropExchange* pPX);
00032         virtual void OnResetState();
00033         protected:
00034         virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
00035         //}}AFX_VIRTUAL
00036 
00037 // Implementation
00038 protected:
00039 // Properties
00040 
00042         COleSafeArray m_data;
00043 
00045         short m_digitsInAddress;
00046 
00052         short m_digitsInData;
00053 
00055         short m_columns;
00056 
00058         short m_fontHeight;
00059 
00061         DWORD m_dwStartAddr;
00062 
00064         bool m_bDataModified;
00065 
00066 // Other data
00067 
00069         bool m_bRealShowAscii;
00070 
00072         int m_nHorzScroll;
00073 
00075         bool m_bMouseDown;
00076 
00078         bool m_bMouseMove;
00079 
00081         int m_posMouseDown;
00082 
00084         CSize m_charCountWindow;
00085 
00087         CSize m_charCountView;
00088 
00090         CSize m_cellSize;
00091 
00092         /* !!! IMPORTANT
00093                 m_selStart, m_selEnd and other number addresses are counts of numbers (NOT NESESSARY BYTES!),
00094                 depending on m_digitsInData.*/
00095 
00097         long m_selStart;
00098 
00100         long m_selEnd;
00101 
00103         long m_editPos;
00104 
00106         long m_viewPos;
00107 
00109         int m_nEditDigit;
00110 
00112         int m_addrMargin;
00113 
00115         int m_asciiMargin;
00116 
00121         int m_editMode;
00122 
00124         CRect m_rcClient;
00125 
00127         bool m_bTimer;
00128 
00130         CPoint m_prevMousePoint;
00131 
00133         static CString m_strWindowClass;
00134 
00136         static CCriticalSection _critSect;
00137 
00139         void TextOutWithCheck(CDC* pdc, const CRect& rcInvalid, int x, int y, CString& strText );
00140 
00146         bool EnterNumber();
00147 
00149         void ClearSelection();
00150 
00152         void DeleteSelection();
00153 
00157         void RecalcSelection(CPoint point);
00158 
00160         bool IsSelectionEmpty();
00161 
00165         bool UpdateScrollBars();
00166 
00168         void InvalidateEditRect(long nEditPos);
00169 
00171         void DeleteData ( DWORD dwPos, DWORD dwCount = 1 );
00172 
00174         void InsertData ( DWORD dwPos, DWORD dwCount = 1 );
00175 
00177         bool NormalizeEditPos();
00178 
00182         void ChangeEditPos ( CPoint pt );
00183 
00189         void ChangeEditPos ( long dx, long dy, bool bRepaint = false);
00190 
00192         void PlaceCaret();
00193 
00195         void RecalcLayout();
00196 
00198         ~CHexEditCtrl();
00199 
00200         DECLARE_OLECREATE_EX(CHexEditCtrl)      // Class factory and guid
00201         DECLARE_OLETYPELIB(CHexEditCtrl)                // GetTypeInfo
00202         DECLARE_PROPPAGEIDS(CHexEditCtrl)               // Property page IDs
00203         DECLARE_OLECTLTYPE(CHexEditCtrl)                // Type name and misc status
00204 
00205 // Message maps
00206         //{{AFX_MSG(CHexEditCtrl)
00207         afx_msg void OnKillFocus(CWnd* pNewWnd);
00208         afx_msg void OnSetFocus(CWnd* pOldWnd);
00209         afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
00210         afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
00211         afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
00212         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
00213         afx_msg UINT OnGetDlgCode();
00214         afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
00215         afx_msg void OnMouseMove(UINT nFlags, CPoint point);
00216         afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
00217         afx_msg void OnEditCopy();
00218         afx_msg void OnEditCut();
00219         afx_msg void OnEditPaste();
00220         afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
00221         afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
00222         afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
00223         afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
00224         afx_msg void OnTimer(UINT nIDEvent);
00225         afx_msg void OnSize(UINT nType, int cx, int cy);
00226         //}}AFX_MSG
00227         afx_msg void OnEditSelectAll();
00228         afx_msg void OnUpdateEditSelectAll(CCmdUI* pCmdUI);
00229         DECLARE_MESSAGE_MAP()
00230         afx_msg void OnContextMenu(CWnd*, CPoint point);        // right click handler
00231 
00232 // Dispatch maps
00233         //{{AFX_DISPATCH(CHexEditCtrl)
00234         BOOL m_showAddress;
00235         afx_msg void OnShowAddressChanged();
00236         BOOL m_showAscii;
00237         afx_msg void OnShowAsciiChanged();
00238         BOOL m_allowChangeSize;
00239         afx_msg void OnAllowChangeSizeChanged();
00240         BOOL m_dataModified;
00241         afx_msg void OnDataModifiedChanged();
00242         afx_msg short GetDigitsInAddress();
00243         afx_msg void SetDigitsInAddress(short nNewValue);
00244         afx_msg short GetDigitsInData();
00245         afx_msg void SetDigitsInData(short nNewValue);
00246         afx_msg short GetColumns();
00247         afx_msg void SetColumns(short nNewValue);
00248         afx_msg short GetFontHeight();
00249         afx_msg void SetFontHeight(short nNewValue);
00250         afx_msg SCODE SetData(VARIANT FAR* pData, long dwStartAddr);
00251         //}}AFX_DISPATCH
00252         DECLARE_DISPATCH_MAP()
00253 
00254         afx_msg void AboutBox();
00255 
00256 // Event maps
00257         //{{AFX_EVENT(CHexEditCtrl)
00258         //}}AFX_EVENT
00259         DECLARE_EVENT_MAP()
00260 
00261 // Dispatch and event IDs
00262 public:
00263         enum {
00264         //{{AFX_DISP_ID(CHexEditCtrl)
00265         dispidShowAddress = 1L,
00266         dispidShowAscii = 2L,
00267         dispidDigitsInAddress = 5L,
00268         dispidDigitsInData = 6L,
00269         dispidColumns = 7L,
00270         dispidFontHeight = 8L,
00271         dispidAllowChangeSize = 3L,
00272         dispidDataModified = 4L,
00273         dispidSetData = 9L,
00274         //}}AFX_DISP_ID
00275         };
00276 };
00277 
00278 //{{AFX_INSERT_LOCATION}}
00279 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
00280 
00281 #endif // !defined(SOFTERRA_HEXEDITOR_HEXEDITCTL_H_INCLUDED_)