// 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
#ifdef _DEBUG
#define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
#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
*/
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;
}
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)
* @brief Constructor.
*/
CHexMergeView::CHexMergeView()
-: m_pif(0)
+: m_pif(nullptr)
, m_nThisPane(0)
{
}
*/
void CHexMergeView::OnDraw(CDC *)
{
- ASSERT(FALSE);
+ ASSERT(false);
}
/**
- * @brief Load heksedit.dll and setup window class name
+ * @brief returns true if heksedit.dll is loadable
*/
-BOOL CHexMergeView::PreCreateWindow(CREATESTRUCT& cs)
+bool CHexMergeView::IsLoadable()
{
- static void *pv = NULL;
- if (pv == NULL)
+ static void *pv = nullptr;
+ if (pv == nullptr)
{
- static const CLSID clsid = { 0xBCA3CA6B, 0xCC6B, 0x4F79,
- { 0xA2, 0xC2, 0xDD, 0xBE, 0x86, 0x4B, 0x1C, 0x90 } };
- if (FAILED(::CoGetClassObject(clsid, CLSCTX_INPROC_SERVER, NULL, IID_IUnknown, &pv)))
- {
- pv = LoadLibrary(_T("Frhed\\hekseditU.dll"));
- if (!pv)
- LangMessageBox(IDS_FRHED_NOTINSTALLED, MB_OK);
- }
+ pv = LoadLibrary(_T("Frhed\\hekseditU.dll"));
}
+ return pv != nullptr;
+}
+
+/**
+ * @brief Load heksedit.dll and setup window class name
+ */
+BOOL CHexMergeView::PreCreateWindow(CREATESTRUCT& cs)
+{
+ if (!IsLoadable())
+ LangMessageBox(IDS_FRHED_NOTINSTALLED, MB_OK);
cs.lpszClass = _T("heksedit");
cs.style |= WS_HSCROLL | WS_VSCROLL;
return TRUE;
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;
}
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)
}
}
+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
*/
/**
* @brief Checks if file has changed since last update
* @param [in] path File to check
- * @return TRUE if file is changed.
+ * @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;
}
/**
FILE_SHARE_READ | FILE_SHARE_WRITE,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
HRESULT hr = SE(h != INVALID_HANDLE_VALUE);
- if (hr != S_OK)
+ if (h == INVALID_HANDLE_VALUE)
return hr;
DWORD length = GetFileSize(h, 0);
hr = SE(length != INVALID_FILE_SIZE);
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 = string_format_string1(_("Another application has updated file\n%1\nsince WinMerge loaded it.\n\nOverwrite changed file?"), path);
+ 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)
return S_OK;
}
// Ask user what to do about FILE_ATTRIBUTE_READONLY
String strPath = path;
- BOOL bApplyToAll = FALSE;
- if (theApp.HandleReadonlySave(strPath, FALSE, bApplyToAll) == IDCANCEL)
+ bool bApplyToAll = false;
+ 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_GetTempPath();
- String sIntermediateFilename = env_GetTempFileName(tempPath, _T("MRG_"), 0);
+ String tempPath = env::GetTemporaryPath();
+ String sIntermediateFilename = env::GetTemporaryFileName(tempPath, _T("MRG_"), 0);
if (sIntermediateFilename.empty())
return E_FAIL; //Nothing to do if even tempfile name fails
HANDLE h = CreateFile(sIntermediateFilename.c_str(), GENERIC_WRITE, FILE_SHARE_READ,
0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
HRESULT hr = SE(h != INVALID_HANDLE_VALUE);
- if (hr != S_OK)
+ if (h == INVALID_HANDLE_VALUE)
return hr;
DWORD length = GetLength();
void *buffer = GetBuffer(length);
if (buffer == 0)
+ {
+ CloseHandle(h);
return E_POINTER;
+ }
DWORD cb = 0;
hr = SE(WriteFile(h, buffer, length, &cb, 0) && cb == length);
CloseHandle(h);
hr = SE(DeleteFile(sIntermediateFilename.c_str()));
if (hr != S_OK)
{
- LogErrorString(string_format(_T("DeleteFile(%s) failed: %s"),
- sIntermediateFilename.c_str(), GetSysError(hr).c_str()));
+ LogErrorString(strutils::format(_T("DeleteFile(%s) failed: %s"),
+ sIntermediateFilename, GetSysError(hr)));
}
return S_OK;
}
/**
* @brief Get modified flag
*/
-BOOL CHexMergeView::GetModified()
+bool CHexMergeView::GetModified()
{
- return m_pif->get_modified();
+ return m_pif->get_status()->iFileChanged != 0;
}
/**
/**
* @brief Get readonly flag
*/
-BOOL CHexMergeView::GetReadOnly()
+bool CHexMergeView::GetReadOnly()
{
return m_pif->get_settings()->bReadOnly;
}
/**
* @brief Set readonly flag
*/
-void CHexMergeView::SetReadOnly(BOOL bReadOnly)
+void CHexMergeView::SetReadOnly(bool bReadOnly)
{
m_pif->get_settings()->bReadOnly = bReadOnly;
}
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;
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);