OSDN Git Service

theApp is unnecessary because these methods are a static methods
[winmerge-jp/winmerge-jp.git] / Src / HexMergeView.cpp
index 7571e02..f5a3114 100644 (file)
@@ -2,21 +2,7 @@
 //    WinMerge:  an interactive diff/merge utility
 //    Copyright (C) 1997-2000  Thingamahoochie Software
 //    Author: Dean Grimm
-//
-//    This program is free software; you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation; either version 2 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program; if not, write to the Free Software
-//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
+//    SPDX-License-Identifier: GPL-2.0-or-later
 /////////////////////////////////////////////////////////////////////////////
 /** 
  * @file  HexMergeView.cpp
@@ -38,6 +24,9 @@
 #define new DEBUG_NEW
 #endif
 
+/** @brief Location for hex compare specific help to open. */
+static TCHAR HexMergeViewHelpLocation[] = _T("::/htmlhelp/Compare_bin.html");
+
 /**
  * @brief Turn bool api result into success/error code
  */
@@ -46,8 +35,8 @@ static HRESULT NTAPI SE(BOOL f)
        if (f)
                return S_OK;
        HRESULT hr = (HRESULT)::GetLastError();
-       ASSERT(hr);
-       if (hr == 0)
+       ASSERT(hr != NULL);
+       if (hr == NULL)
                hr = E_UNEXPECTED;
        return hr;
 }
@@ -74,7 +63,9 @@ BEGIN_MESSAGE_MAP(CHexMergeView, CView)
        ON_WM_CREATE()
        ON_WM_HSCROLL()
        ON_WM_VSCROLL()
+       ON_WM_MOUSEWHEEL()
        ON_WM_NCCALCSIZE()
+       ON_COMMAND(ID_HELP, OnHelp)
        ON_COMMAND(ID_EDIT_FIND, OnEditFind)
        ON_COMMAND(ID_EDIT_REPLACE, OnEditReplace)
        ON_COMMAND(ID_EDIT_REPEAT, OnEditRepeat)
@@ -103,7 +94,7 @@ END_MESSAGE_MAP()
  * @brief Constructor.
  */
 CHexMergeView::CHexMergeView()
-: m_pif(0)
+: m_pif(nullptr)
 , m_nThisPane(0)
 {
 }
@@ -113,7 +104,7 @@ CHexMergeView::CHexMergeView()
  */
 void CHexMergeView::OnDraw(CDC *)
 {
-       ASSERT(FALSE);
+       ASSERT(false);
 }
 
 /**
@@ -121,8 +112,8 @@ void CHexMergeView::OnDraw(CDC *)
  */
 bool CHexMergeView::IsLoadable()
 {
-       static void *pv = NULL;
-       if (pv == NULL)
+       static void *pv = nullptr;
+       if (pv == nullptr)
        {
                pv = LoadLibrary(_T("Frhed\\hekseditU.dll"));
        }
@@ -149,7 +140,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 || m_pif->get_interface_version() < HEKSEDIT_INTERFACE_VERSION)
+       if (m_pif == nullptr || m_pif->get_interface_version() < HEKSEDIT_INTERFACE_VERSION)
                return -1;
        return 0;
 }
@@ -174,7 +165,7 @@ void CHexMergeView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
                SetScrollInfo(SB_HORZ, &si);
        }
        CView::OnHScroll(nSBCode, nPos, pScrollBar);
-       if (pScrollBar)
+       if (pScrollBar != nullptr)
        {
                GetScrollInfo(SB_HORZ, &si, SIF_ALL | SIF_DISABLENOSCROLL);
                if (nSBCode != SB_THUMBTRACK)
@@ -215,6 +206,16 @@ void CHexMergeView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
        }
 }
 
+BOOL CHexMergeView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
+{
+       if ((GetAsyncKeyState(VK_CONTROL) &0x8000) != 0) // if (nFlags & MK_CONTROL)
+       {
+               PostMessage(WM_COMMAND, zDelta < 0 ? ID_VIEW_ZOOMOUT : ID_VIEW_ZOOMIN);
+               return 1;
+       }
+       return 0;
+}
+
 /**
  * @brief Synchronize file path bar activation states
  */
@@ -246,18 +247,19 @@ int CHexMergeView::GetLength()
  * @param [in] path File to check
  * @return `true` if file is changed.
  */
-bool CHexMergeView::IsFileChangedOnDisk(LPCTSTR path)
+IMergeDoc::FileChange CHexMergeView::IsFileChangedOnDisk(LPCTSTR path)
 {
        DiffFileInfo dfi;
-       dfi.Update(path);
+       if (!dfi.Update(path))
+               return IMergeDoc::FileChange::Removed;
        int tolerance = 0;
        if (GetOptionsMgr()->GetBool(OPT_IGNORE_SMALL_FILETIME))
                tolerance = SmallTimeDiff; // From MainFrm.h
        int64_t timeDiff = dfi.mtime - m_fileInfo.mtime;
        if (timeDiff < 0) timeDiff = -timeDiff;
        if ((timeDiff > tolerance * Poco::Timestamp::resolution()) || (dfi.size != m_fileInfo.size))
-               return true;
-       return false;
+               return IMergeDoc::FileChange::Changed;
+       return IMergeDoc::FileChange::NoChange;
 }
 
 /**
@@ -298,7 +300,7 @@ HRESULT CHexMergeView::LoadFile(LPCTSTR path)
 HRESULT CHexMergeView::SaveFile(LPCTSTR path)
 {
        // Warn user in case file has been changed by someone else
-       if (IsFileChangedOnDisk(path))
+       if (IsFileChangedOnDisk(path) == IMergeDoc::FileChange::Changed)
        {
                String msg = strutils::format_string1(_("Another application has updated file\n%1\nsince WinMerge loaded it.\n\nOverwrite changed file?"), path);
                if (AfxMessageBox(msg.c_str(), MB_ICONWARNING | MB_YESNO) == IDNO)
@@ -307,11 +309,11 @@ HRESULT CHexMergeView::SaveFile(LPCTSTR path)
        // Ask user what to do about FILE_ATTRIBUTE_READONLY
        String strPath = path;
        bool bApplyToAll = false;
-       if (theApp.HandleReadonlySave(strPath, false, bApplyToAll) == IDCANCEL)
+       if (CMergeApp::HandleReadonlySave(strPath, false, bApplyToAll) == IDCANCEL)
                return S_OK;
        path = strPath.c_str();
        // Take a chance to create a backup
-       if (!theApp.CreateBackup(false, path))
+       if (!CMergeApp::CreateBackup(false, path))
                return S_OK;
        // Write data to an intermediate file
        String tempPath = env::GetTemporaryPath();
@@ -344,7 +346,7 @@ HRESULT CHexMergeView::SaveFile(LPCTSTR path)
        if (hr != S_OK)
        {
                LogErrorString(strutils::format(_T("DeleteFile(%s) failed: %s"),
-                       sIntermediateFilename.c_str(), GetSysError(hr).c_str()));
+                       sIntermediateFilename, GetSysError(hr)));
        }
        return S_OK;
 }
@@ -354,7 +356,7 @@ HRESULT CHexMergeView::SaveFile(LPCTSTR path)
  */
 bool CHexMergeView::GetModified()
 {
-       return m_pif->get_status()->bFileChanged;
+       return m_pif->get_status()->iFileChanged != 0;
 }
 
 /**
@@ -507,7 +509,7 @@ BOOL CHexMergeView::PreTranslateMessage(MSG* pMsg)
        if (pMsg->message == WM_KEYDOWN)
        {
                // Close window in response to VK_ESCAPE if user has allowed it from options
-               if (pMsg->wParam == VK_ESCAPE && GetOptionsMgr()->GetBool(OPT_CLOSE_WITH_ESC))
+               if (pMsg->wParam == VK_ESCAPE && GetOptionsMgr()->GetInt(OPT_CLOSE_WITH_ESC) != 0)
                {
                        GetParentFrame()->PostMessage(WM_CLOSE, 0, 0);
                        return TRUE;
@@ -548,6 +550,12 @@ void CHexMergeView::OnPrevdiff()
        m_pif->select_prev_diff(FALSE);
 }
 
+/** @brief Open help from mainframe when user presses F1*/
+void CHexMergeView::OnHelp()
+{
+       theApp.ShowHelp(HexMergeViewHelpLocation);
+}
+
 void CHexMergeView::ZoomText(int amount)
 {
        m_pif->CMD_zoom(amount);