OSDN Git Service

Adapt to heksedit hosting interface version 1; Require heksedit.dll to be regsvr32ed.
authorJochen Tucht <jtuc@users.sourceforge.net>
Sun, 12 Apr 2009 09:30:35 +0000 (09:30 +0000)
committerJochen Tucht <jtuc@users.sourceforge.net>
Sun, 12 Apr 2009 09:30:35 +0000 (09:30 +0000)
Src/HexMergeFrm.cpp
Src/HexMergeFrm.h
Src/HexMergeView.cpp
Src/HexMergeView.h
Src/heksedit.h [new file with mode: 0644]

index d0a10be..d30eb87 100644 (file)
 static char THIS_FILE[] = __FILE__;
 #endif
 
-/**
- * @brief RO status panel width
- */
-static UINT RO_PANEL_WIDTH = 40;
-
 /////////////////////////////////////////////////////////////////////////////
 // CHexMergeFrame
 
@@ -78,19 +73,6 @@ enum
        PANE_RIGHT_EOL,
 };
 
-/**
- * @brief Bottom statusbar panels and indicators
- */
-static UINT indicatorsBottom[] =
-{
-       ID_SEPARATOR,
-       ID_SEPARATOR,
-       ID_SEPARATOR,
-       ID_SEPARATOR,
-       ID_SEPARATOR,
-       ID_SEPARATOR,
-};
-
 /////////////////////////////////////////////////////////////////////////////
 // CHexMergeFrame construction/destruction
 
@@ -145,13 +127,15 @@ static void Customize(IHexEditorWindow *pif)
 /**
  * @brief Create a status bar to be associated with a heksedit control
  */
-void CHexMergeFrame::CreateHexWndStatusBar(CStatusBar &wndStatusBar)
+void CHexMergeFrame::CreateHexWndStatusBar(CStatusBar &wndStatusBar, CWnd *pwndPane)
 {
-       wndStatusBar.Create(this, WS_CHILD|WS_VISIBLE);
+       wndStatusBar.Create(pwndPane, WS_CHILD|WS_VISIBLE);
        wndStatusBar.SetIndicators(0, 3);
        wndStatusBar.SetPaneInfo(0, 0, SBPS_STRETCH, 0);
-       wndStatusBar.SetPaneInfo(1, 0, 0, 72);
-       wndStatusBar.SetPaneInfo(2, 0, 0, 72);
+       wndStatusBar.SetPaneInfo(1, 0, 0, 80);
+       wndStatusBar.SetPaneInfo(2, 0, 0, 80);
+       wndStatusBar.SetParent(this);
+       wndStatusBar.SetWindowPos(&wndBottom, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
 }
 
 /**
@@ -194,35 +178,31 @@ BOOL CHexMergeFrame::OnCreateClient( LPCREATESTRUCT /*lpcs*/,
        m_wndFilePathBar.SetActive(0, FALSE);
        m_wndFilePathBar.SetActive(1, FALSE);
 
+       CHexMergeView *pLeft = static_cast<CHexMergeView *>(m_wndSplitter.GetPane(0, 0));
+       CHexMergeView *pRight = static_cast<CHexMergeView *>(m_wndSplitter.GetPane(0, 1));
+
        m_wndLeftStatusBar.m_cxRightBorder = 4;
-       ModifyStyle(WS_THICKFRAME, 0); // Prevent SBARS_SIZEGRIP
-       CreateHexWndStatusBar(m_wndLeftStatusBar);
-       ModifyStyle(0, WS_THICKFRAME);
-       CreateHexWndStatusBar(m_wndRightStatusBar);
+       CreateHexWndStatusBar(m_wndLeftStatusBar, pLeft);
+       pRight->ModifyStyle(0, WS_THICKFRAME); // Create an SBARS_SIZEGRIP
+       CreateHexWndStatusBar(m_wndRightStatusBar, pRight);
+       pRight->ModifyStyle(WS_THICKFRAME, 0);
        CSize size = m_wndLeftStatusBar.CalcFixedLayout(TRUE, TRUE);
        m_rectBorder.bottom = size.cy;
 
        m_hIdentical = AfxGetApp()->LoadIcon(IDI_EQUALBINARY);
        m_hDifferent = AfxGetApp()->LoadIcon(IDI_BINARYDIFF);
 
-       // stash left & right pointers into the mergedoc
-       CHexMergeView *pLeft = static_cast<CHexMergeView *>(m_wndSplitter.GetPane(0,0));
-       CHexMergeView *pRight = static_cast<CHexMergeView *>(m_wndSplitter.GetPane(0,1));
+       // get the IHexEditorWindow interfaces
+       IHexEditorWindow *pifLeft = pLeft->GetInterface();
+       IHexEditorWindow *pifRight = pRight->GetInterface();
 
-       IHexEditorWindow *pifLeft = reinterpret_cast<IHexEditorWindow *>(
-               ::GetWindowLongPtr(pLeft->m_hWnd, GWLP_USERDATA));
-       IHexEditorWindow *pifRight = reinterpret_cast<IHexEditorWindow *>(
-               ::GetWindowLongPtr(pRight->m_hWnd, GWLP_USERDATA));
+       // tell the heksedit controls about each other
+       pifLeft->set_sibling(pifRight);
+       pifRight->set_sibling(pifLeft);
 
-       if (pifLeft && pifRight)
-       {
-               pifLeft->set_sibling(pifRight);
-               pifRight->set_sibling(pifLeft);
-               pifLeft->set_status_bar(m_wndLeftStatusBar.m_hWnd);
-               pifRight->set_status_bar(m_wndRightStatusBar.m_hWnd);
-               Customize(pifLeft);
-               Customize(pifRight);
-       }
+       // adjust a few settings and colors
+       Customize(pifLeft);
+       Customize(pifRight);
 
        // tell merge doc about these views
        m_pMergeDoc = dynamic_cast<CHexMergeDoc *>(pContext->m_pCurrentDoc);
index ceff7f6..ce076cd 100644 (file)
@@ -28,7 +28,9 @@
 
 #include "SplitterWndEx.h"
 #include "EditorFilepathBar.h"
-#include "../externals/heksedit/heksedit.h"
+
+#define HEKSEDIT_INTERFACE_VERSION 1
+#include "heksedit.h"
 
 class CHexMergeDoc;
 
@@ -75,7 +77,7 @@ public:
 private:
        void SavePosition();
        virtual ~CHexMergeFrame();
-       void CreateHexWndStatusBar(CStatusBar &);
+       void CreateHexWndStatusBar(CStatusBar &, CWnd *);
 // Generated message map functions
 private:
        int m_nLastSplitPos;
index 5da33b6..72768ff 100644 (file)
@@ -34,7 +34,6 @@
 #include "HexMergeView.h"
 #include "OptionsDef.h"
 #include "Environment.h"
-#include "../externals/heksedit/version.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -122,14 +121,14 @@ void CHexMergeView::OnDraw(CDC *)
  */
 BOOL CHexMergeView::PreCreateWindow(CREATESTRUCT& cs)
 {
-       static const TCHAR pe[] = PE_HEKSEDIT;
-       static const TCHAR wc[] = WC_HEKSEDIT;
-       if ((cs.hInstance = ::GetModuleHandle(pe)) == 0 &&
-               (cs.hInstance = ::LoadLibrary(pe)) == 0)
+       static void *pv = NULL;
+       if (pv == NULL)
        {
-               return FALSE;
+               static const CLSID clsid = { 0xBCA3CA6B, 0xCC6B, 0x4F79,
+                       { 0xA2, 0xC2, 0xDD, 0xBE, 0x86, 0x4B, 0x1C, 0x90 } };
+               CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL, IID_IUnknown, &pv);
        }
-       cs.lpszClass = wc;
+       cs.lpszClass = _T("heksedit");
        cs.style |= WS_HSCROLL | WS_VSCROLL;
        return TRUE;
 }
@@ -142,7 +141,7 @@ int CHexMergeView::OnCreate(LPCREATESTRUCT lpCreateStruct)
        if (CView::OnCreate(lpCreateStruct) == -1)
                return -1;
        m_pif = reinterpret_cast<IHexEditorWindow *>(::GetWindowLongPtr(m_hWnd, GWLP_USERDATA));
-       if (m_pif == 0)
+       if (m_pif == 0 || m_pif->get_interface_version() < HEKSEDIT_INTERFACE_VERSION)
                return -1;
        return 0;
 }
index b61796c..95946c8 100644 (file)
@@ -47,6 +47,7 @@ protected: // create from serialization only
 public:
        HRESULT LoadFile(LPCTSTR);
        HRESULT SaveFile(LPCTSTR);
+       IHexEditorWindow *GetInterface() const { return m_pif; }
        IHexEditorWindow::Status *GetStatus();
        BYTE *GetBuffer(int);
        int GetLength();
diff --git a/Src/heksedit.h b/Src/heksedit.h
new file mode 100644 (file)
index 0000000..e81f139
--- /dev/null
@@ -0,0 +1,115 @@
+/////////////////////////////////////////////////////////////////////////////\r
+//    License (GPLv2+):\r
+//    This program is free software; you can redistribute it and/or modify\r
+//    it under the terms of the GNU General Public License as published by\r
+//    the Free Software Foundation; either version 2 of the License, or\r
+//    (at your option) any later version.\r
+//\r
+//    This program is distributed in the hope that it will be useful, but\r
+//    WITHOUT ANY WARRANTY; without even the implied warranty of\r
+//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
+//    General Public License for more details.\r
+//\r
+//    You should have received a copy of the GNU General Public License\r
+//    along with this program; if not, write to the Free Software\r
+//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
+/////////////////////////////////////////////////////////////////////////////\r
+/** \r
+ * @file  heksedit.h\r
+ *\r
+ * @brief Interface definition for the hekseditor window.\r
+ *\r
+ */\r
+// ID line follows -- this is updated by SVN\r
+// $Id: heksedit.h 492 2009-04-11 15:17:02Z jtuc $\r
+\r
+#ifndef _HEKSEDIT_H_\r
+#define _HEKSEDIT_H_\r
+\r
+#ifndef HEKSEDIT_INTERFACE_VERSION\r
+#define HEKSEDIT_INTERFACE_VERSION 1\r
+#endif\r
+\r
+/**\r
+ * @brief Interface for the Hexeditor window.\r
+ * @note This file is published to hosting applications. Do not add global declarations.\r
+ */\r
+class IHexEditorWindow\r
+{\r
+public:\r
+       /**\r
+        * @brief Byte endians.\r
+        */\r
+       enum BYTE_ENDIAN\r
+       {\r
+               ENDIAN_LITTLE, /**< Little endian used e.g. in Intel processors. */\r
+               ENDIAN_BIG /**< Big endian used e.g. in Motorola processors. */\r
+       };\r
+\r
+       struct Colors\r
+       {\r
+               COLORREF iTextColorValue, iBkColorValue, iSepColorValue;\r
+               COLORREF iSelBkColorValue, iSelTextColorValue;\r
+               COLORREF iBmkColor;\r
+               COLORREF iDiffBkColorValue, iDiffTextColorValue, iSelDiffBkColorValue, iSelDiffTextColorValue;\r
+       };\r
+\r
+       struct Settings\r
+       {\r
+               int iBytesPerLine;\r
+               int iAutomaticBPL;\r
+               BYTE_ENDIAN iBinaryMode;\r
+               int bReadOnly;\r
+               int bSaveIni;\r
+               int iFontSize;\r
+               int iCharacterSet;\r
+               int iMinOffsetLen;\r
+               int iMaxOffsetLen;\r
+               int bAutoOffsetLen;\r
+               int bCenterCaret;\r
+               int iFontZoom;\r
+       };\r
+\r
+       struct Status\r
+       {\r
+               int iFileChanged;\r
+               int iEnteringMode;\r
+               int iCurByte;\r
+               int iCurNibble;\r
+               int iVscrollMax;\r
+               int iVscrollPos;\r
+               int iHscrollMax;\r
+               int iHscrollPos;\r
+               int bSelected;\r
+               int iStartOfSelection;\r
+               int iEndOfSelection;\r
+       };\r
+\r
+       virtual unsigned STDMETHODCALLTYPE get_interface_version() = 0;\r
+       virtual unsigned char *STDMETHODCALLTYPE get_buffer(int) = 0;\r
+       virtual int STDMETHODCALLTYPE get_length() = 0;\r
+       virtual void STDMETHODCALLTYPE set_sibling(IHexEditorWindow *) = 0;\r
+       virtual Colors *STDMETHODCALLTYPE get_colors() = 0;\r
+       virtual Settings *STDMETHODCALLTYPE get_settings() = 0;\r
+       virtual Status *STDMETHODCALLTYPE get_status() = 0;\r
+       virtual void STDMETHODCALLTYPE resize_window() = 0;\r
+       virtual void STDMETHODCALLTYPE repaint(int from, int to) = 0;\r
+       virtual void STDMETHODCALLTYPE adjust_hscrollbar() = 0;\r
+       virtual void STDMETHODCALLTYPE adjust_vscrollbar() = 0;\r
+       virtual int STDMETHODCALLTYPE translate_accelerator(MSG *) = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_find() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_findprev() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_findnext() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_replace() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_edit_cut() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_edit_copy() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_edit_paste() = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_edit_clear() = 0;\r
+       virtual BOOL STDMETHODCALLTYPE select_next_diff(BOOL bFromStart) = 0;\r
+       virtual BOOL STDMETHODCALLTYPE select_prev_diff(BOOL bFromEnd) = 0;\r
+       virtual BOOL STDMETHODCALLTYPE load_lang(LANGID langid, LPCWSTR langdir = NULL) = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_zoom(int) = 0;\r
+       virtual void STDMETHODCALLTYPE CMD_select_all() = 0;\r
+};\r
+\r
+#endif // _HEKSEDIT_H_\r