Skip to content

Commit

Permalink
CMD_NAV_DATABEG changed from "home" to "ctrl+home". CMD_NAV_DATAEND c…
Browse files Browse the repository at this point in the history
…hanged from "end" to "ctrl+end".

CMD_NAV_LINEBEG is now [ "home", "ctrl+left" ]. CMD_NAV_LINEEND is now [ "end", "ctrl+right" ].
Fixed bug with not loaded menu shortcuts.
Code cleaning.
  • Loading branch information
jovibor committed Jan 3, 2025
1 parent 8ef91a1 commit ea4a29b
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 324 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Checks: '*,
-misc-use-internal-linkage,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays,
-modernize-use-nodiscard,
-modernize-use-ranges,
-performance-no-int-to-ptr,
-portability-simd-intrinsics,
Expand Down
325 changes: 200 additions & 125 deletions HexCtrl/dep/ListEx/ListEx.ixx

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions HexCtrl/res/HexCtrl.rc
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ BEGIN
CONTROL "Hex numbers",IDC_HEXCTRL_BKMMGR_CHK_HEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,306,55,8
END

IDD_HEXCTRL_DATAINTERP DIALOGEX 0, 0, 275, 320
IDD_HEXCTRL_DATAINTERP DIALOGEX 0, 0, 255, 280
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Data Interpreter"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
CONTROL "Hex numbers",IDC_HEXCTRL_DATAINTERP_CHK_HEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,306,55,8
CONTROL "Big-endian",IDC_HEXCTRL_DATAINTERP_CHK_BE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,306,47,8
CONTROL "",IDC_HEXCTRL_DATAINTERP_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_TABSTOP,0,0,275,300
CONTROL "Hex numbers",IDC_HEXCTRL_DATAINTERP_CHK_HEX,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,264,55,8
CONTROL "Big-endian",IDC_HEXCTRL_DATAINTERP_CHK_BE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,70,264,47,8
CONTROL "",IDC_HEXCTRL_DATAINTERP_LIST,"SysListView32",LVS_REPORT | LVS_SHOWSELALWAYS | LVS_ALIGNLEFT | LVS_OWNERDATA | WS_TABSTOP,0,0,255,255
END

IDD_HEXCTRL_PROGRESS DIALOGEX 0, 0, 203, 74
Expand Down
8 changes: 4 additions & 4 deletions HexCtrl/res/IDJ_HEXCTRL_KEYBIND.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
"CMD_NAV_GOTO_DLG": [ "ctrl+alt+g" ],
"CMD_NAV_REPFWD": [ "ctrl+shift+right" ],
"CMD_NAV_REPBKW": [ "ctrl+shift+left" ],
"CMD_NAV_DATABEG": [ "home" ],
"CMD_NAV_DATAEND": [ "end" ],
"CMD_NAV_DATABEG": [ "ctrl+home" ],
"CMD_NAV_DATAEND": [ "ctrl+end" ],
"CMD_NAV_PAGEBEG": [ "ctrl+pageup" ],
"CMD_NAV_PAGEEND": [ "ctrl+pagedown" ],
"CMD_NAV_LINEBEG": [ "ctrl+left" ],
"CMD_NAV_LINEEND": [ "ctrl+right" ],
"CMD_NAV_LINEBEG": [ "home", "ctrl+left" ],
"CMD_NAV_LINEEND": [ "end", "ctrl+right" ],
"CMD_GROUPDATA_BYTE": [ "" ],
"CMD_GROUPDATA_WORD": [ "" ],
"CMD_GROUPDATA_DWORD": [ "" ],
Expand Down
90 changes: 48 additions & 42 deletions HexCtrl/src/CHexCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,27 +353,27 @@ bool CHexCtrl::Create(const HEXCREATE& hcs)
//"Search" menu icon.
mii.hbmpItem = static_cast<HBITMAP>(::LoadImageW(m_hInstRes, MAKEINTRESOURCEW(IDB_HEXCTRL_SEARCH), IMAGE_BITMAP,
iSizeIcon, iSizeIcon, LR_CREATEDIBSECTION));
menuTop.SetMenuItemInfoW(0, &mii); //"Search" parent menu icon.
menuTop.SetMenuItemInfoW(0, &mii, false); //"Search" parent menu icon.
m_MenuMain.SetMenuItemInfoW(IDM_HEXCTRL_SEARCH_DLGSEARCH, &mii);
m_vecHBITMAP.emplace_back(mii.hbmpItem);

//"Group Data" menu icon.
mii.hbmpItem = static_cast<HBITMAP>(::LoadImageW(m_hInstRes, MAKEINTRESOURCEW(IDB_HEXCTRL_GROUP), IMAGE_BITMAP,
iSizeIcon, iSizeIcon, LR_CREATEDIBSECTION));
menuTop.SetMenuItemInfoW(2, &mii); //"Group Data" parent menu icon.
menuTop.SetMenuItemInfoW(2, &mii, false); //"Group Data" parent menu icon.
m_vecHBITMAP.emplace_back(mii.hbmpItem);

//"Bookmarks->Add" menu icon.
mii.hbmpItem = static_cast<HBITMAP>(::LoadImageW(m_hInstRes, MAKEINTRESOURCEW(IDB_HEXCTRL_BKMS), IMAGE_BITMAP,
iSizeIcon, iSizeIcon, LR_CREATEDIBSECTION));
menuTop.SetMenuItemInfoW(4, &mii); //"Bookmarks" parent menu icon.
menuTop.SetMenuItemInfoW(4, &mii, false); //"Bookmarks" parent menu icon.
m_MenuMain.SetMenuItemInfoW(IDM_HEXCTRL_BKM_ADD, &mii);
m_vecHBITMAP.emplace_back(mii.hbmpItem);

//"Clipboard->Copy as Hex" menu icon.
mii.hbmpItem = static_cast<HBITMAP>(::LoadImageW(m_hInstRes, MAKEINTRESOURCEW(IDB_HEXCTRL_CLPBRD_COPYHEX), IMAGE_BITMAP,
iSizeIcon, iSizeIcon, LR_CREATEDIBSECTION));
menuTop.SetMenuItemInfoW(5, &mii); //"Clipboard" parent menu icon.
menuTop.SetMenuItemInfoW(5, &mii, false); //"Clipboard" parent menu icon.
m_MenuMain.SetMenuItemInfoW(IDM_HEXCTRL_CLPBRD_COPYHEX, &mii);
m_vecHBITMAP.emplace_back(mii.hbmpItem);

Expand All @@ -386,7 +386,7 @@ bool CHexCtrl::Create(const HEXCREATE& hcs)
//"Modify" parent menu icon.
mii.hbmpItem = static_cast<HBITMAP>(::LoadImageW(m_hInstRes, MAKEINTRESOURCEW(IDB_HEXCTRL_MODIFY), IMAGE_BITMAP,
iSizeIcon, iSizeIcon, LR_CREATEDIBSECTION));
menuTop.SetMenuItemInfoW(6, &mii);
menuTop.SetMenuItemInfoW(6, &mii, false);
m_vecHBITMAP.emplace_back(mii.hbmpItem);

//"Modify->Fill with Zeros" menu icon.
Expand Down Expand Up @@ -1788,21 +1788,31 @@ bool CHexCtrl::SetConfig(std::wstring_view wsvPath)

rapidjson::Document docJSON;
if (wsvPath.empty()) { //Default IDR_HEXCTRL_JSON_KEYBIND.json, from resources.
if (const auto hRes = ::FindResourceW(m_hInstRes, MAKEINTRESOURCEW(IDJ_HEXCTRL_KEYBIND), L"JSON"); hRes != nullptr) {
if (const auto hData = ::LoadResource(m_hInstRes, hRes); hData != nullptr) {
const auto nSize = static_cast<std::size_t>(::SizeofResource(m_hInstRes, hRes));
const auto* const pData = static_cast<char*>(::LockResource(hData));
if (docJSON.Parse(pData, nSize); docJSON.IsNull()) { //Parse all default keybindings.
ut::DBG_REPORT(L"docJSON.IsNull()");
return false;
}
}
const auto hRes = ::FindResourceW(m_hInstRes, MAKEINTRESOURCEW(IDJ_HEXCTRL_KEYBIND), L"JSON");
if (hRes == nullptr) {
ut::DBG_REPORT(L"FindResourceW failed.");
return false;
}

const auto hResData = ::LoadResource(m_hInstRes, hRes);
if (hResData == nullptr) {
ut::DBG_REPORT(L"LoadResource failed.");
return false;
}

const auto nSize = static_cast<std::size_t>(::SizeofResource(m_hInstRes, hRes));
const auto pData = static_cast<char*>(::LockResource(hResData));
docJSON.Parse(pData, nSize);
if (docJSON.IsNull()) { //Parse all default keybindings.
ut::DBG_REPORT(L"docJSON.IsNull().");
return false;
}

}
else if (std::ifstream ifs(std::wstring { wsvPath }); ifs.is_open()) {
rapidjson::IStreamWrapper isw { ifs };
if (docJSON.ParseStream(isw); docJSON.IsNull()) {
ut::DBG_REPORT(L"docJSON.IsNull()");
ut::DBG_REPORT(L"docJSON.IsNull().");
return false;
}
}
Expand All @@ -1811,7 +1821,7 @@ bool CHexCtrl::SetConfig(std::wstring_view wsvPath)
if (sv.empty())
return { };

KEYBIND stRet { };
KEYBIND stKB;
const auto nSize = sv.size();
std::size_t nPosStart { 0 }; //Next position to start search for '+' sign.
const auto nSubWords = std::count(sv.begin(), sv.end(), '+') + 1; //How many sub-words (divided by '+')?
Expand All @@ -1822,26 +1832,26 @@ bool CHexCtrl::SetConfig(std::wstring_view wsvPath)
nPosStart = nPosNext + 1;

if (strSubWord.size() == 1) {
stRet.uKey = static_cast<UCHAR>(std::toupper(strSubWord[0])); //Binding keys are in uppercase.
stKB.uKey = static_cast<UCHAR>(std::toupper(strSubWord[0])); //Binding keys are in uppercase.
}
else if (const auto itKey = umapKeys.find(strSubWord); itKey != umapKeys.end()) {
switch (const auto uChar = itKey->second.first; uChar) {
case VK_CONTROL:
stRet.fCtrl = true;
stKB.fCtrl = true;
break;
case VK_SHIFT:
stRet.fShift = true;
stKB.fShift = true;
break;
case VK_MENU:
stRet.fAlt = true;
stKB.fAlt = true;
break;
default:
stRet.uKey = uChar;
stKB.uKey = uChar;
}
}
}

return stRet;
return stKB;
};

for (auto itMembers = docJSON.MemberBegin(); itMembers != docJSON.MemberEnd(); ++itMembers) { //JSON data iterating.
Expand Down Expand Up @@ -1870,11 +1880,11 @@ bool CHexCtrl::SetConfig(std::wstring_view wsvPath)
for (const auto& refKB : m_vecKeyBind) {
//Check for previous same menu ID. To assign only one, first, keybinding for menu name.
//With `"ctrl+f", "ctrl+h"` in JSON, only the "Ctrl+F" will be assigned as the menu name.
const auto iterEnd = m_vecKeyBind.begin() + i++;
if (const auto iterTmp = std::find_if(m_vecKeyBind.begin(), iterEnd, [&](const KEYBIND& ref) {
const auto itEnd = m_vecKeyBind.begin() + i++;
if (const auto iterTmp = std::find_if(m_vecKeyBind.begin(), itEnd, [&](const KEYBIND& ref) {
return ref.wMenuID == refKB.wMenuID; });
iterTmp == iterEnd && refKB.wMenuID != 0 && refKB.uKey != 0) {
std::wstring wstr = m_MenuMain.GetMenuStr(refKB.wMenuID);
iterTmp == itEnd && refKB.wMenuID != 0 && refKB.uKey != 0) {
auto wstr = m_MenuMain.GetMenuWstr(refKB.wMenuID);
if (const auto nPos = wstr.find('\t'); nPos != std::wstring::npos) {
wstr.erase(nPos);
}
Expand All @@ -1900,7 +1910,7 @@ bool CHexCtrl::SetConfig(std::wstring_view wsvPath)
}

//Modify menu with a new name (with shortcut appended) and old bitmap.
MENUITEMINFOW mii { .cbSize = sizeof(MENUITEMINFOW), .fMask = MIIM_BITMAP | MIIM_STRING };
MENUITEMINFOW mii { .cbSize { sizeof(MENUITEMINFOW) }, .fMask { MIIM_BITMAP | MIIM_STRING } };
m_MenuMain.GetMenuItemInfoW(refKB.wMenuID, &mii);
mii.dwTypeData = wstr.data();
m_MenuMain.SetMenuItemInfoW(refKB.wMenuID, &mii);
Expand Down Expand Up @@ -7447,25 +7457,21 @@ auto CHexCtrl::OnTimer(const MSG& msg)->LRESULT
{
static constexpr auto dbSecToShow { 5000.0 }; //How many ms to show tooltips.
const auto nIDEvent = static_cast<UINT_PTR>(msg.wParam);
if (nIDEvent != m_uIDTTTMain)
return wnd::DefWndProc(msg);

auto rcClient = m_Wnd.GetClientRect();
m_Wnd.ClientToScreen(rcClient);
wnd::CPoint ptCursor;
GetCursorPos(ptCursor);
wnd::CPoint ptCur;
::GetCursorPos(ptCur);

switch (nIDEvent) {
case m_uIDTTTMain:
if (!rcClient.PtInRect(ptCursor)) { //Check if cursor has left client rect,
TTMainShow(false);
}
else if (const auto msElapsed = std::chrono::duration<double, std::milli>
(std::chrono::high_resolution_clock::now() - m_tmTT).count();
msElapsed >= dbSecToShow) { //or more than dbSecToShow ms have passed since toolip was shown.
TTMainShow(false, true);
}
break;
default:
break;
if (!rcClient.PtInRect(ptCur)) { //Check if cursor has left client rect,
TTMainShow(false);
}
else if (const auto msElapsed = std::chrono::duration<double, std::milli>
(std::chrono::high_resolution_clock::now() - m_tmTT).count();
msElapsed >= dbSecToShow) { //or more than dbSecToShow ms have passed since toolip was shown.
TTMainShow(false, true);
}

return 0;
Expand Down
114 changes: 57 additions & 57 deletions HexCtrl/src/Dialogs/CHexDlgBkmMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,63 @@ auto CHexDlgBkmMgr::OnNotify(const MSG& msg)->INT_PTR
return TRUE;
}

void CHexDlgBkmMgr::OnNotifyListDblClick(NMHDR* pNMHDR)
{
const auto* const pNMI = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (pNMI->iSubItem != 4 && pNMI->iSubItem != 5) {
return;
}

const auto pBkm = GetByIndex(static_cast<std::size_t>(pNMI->iItem));
if (pBkm == nullptr) {
return;
}

COLORREF* pClr { };
switch (pNMI->iSubItem) {
case 4: //Bk color.
pClr = &pBkm->stClr.clrBk;
break;
case 5: //Text color.
pClr = &pBkm->stClr.clrText;
break;
default:
return;
}

COLORREF arrClr[16] { };
CHOOSECOLORW stChclr { .lStructSize { sizeof(CHOOSECOLORW) }, .rgbResult { *pClr },
.lpCustColors { arrClr }, .Flags { CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT } };
if (ChooseColorW(&stChclr) == FALSE) {
return;
}

*pClr = stChclr.rgbResult;
m_pHexCtrl->Redraw();
}

void CHexDlgBkmMgr::OnNotifyListGetColor(NMHDR* pNMHDR)
{
const auto pLCI = reinterpret_cast<LISTEX::PLISTEXCOLORINFO>(pNMHDR);

switch (pLCI->iSubItem) {
case 4: //Bk color.
if (const auto* const pBkm = GetByIndex(static_cast<std::size_t>(pLCI->iItem)); pBkm != nullptr) {
pLCI->stClr.clrBk = pBkm->stClr.clrBk;
return;
}
break;
case 5: //Text color.
if (const auto* const pBkm = GetByIndex(static_cast<std::size_t>(pLCI->iItem)); pBkm != nullptr) {
pLCI->stClr.clrBk = pBkm->stClr.clrText;
return;
}
break;
default:
break;
}
}

void CHexDlgBkmMgr::OnNotifyListGetDispInfo(NMHDR* pNMHDR)
{
const auto pDispInfo = reinterpret_cast<NMLVDISPINFOW*>(pNMHDR);
Expand Down Expand Up @@ -590,41 +647,6 @@ void CHexDlgBkmMgr::OnNotifyListItemChanged(NMHDR* pNMHDR)
}
}

void CHexDlgBkmMgr::OnNotifyListDblClick(NMHDR* pNMHDR)
{
const auto* const pNMI = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
if (pNMI->iSubItem != 4 && pNMI->iSubItem != 5) {
return;
}

const auto pBkm = GetByIndex(static_cast<std::size_t>(pNMI->iItem));
if (pBkm == nullptr) {
return;
}

COLORREF* pClr { };
switch (pNMI->iSubItem) {
case 4: //Bk color.
pClr = &pBkm->stClr.clrBk;
break;
case 5: //Text color.
pClr = &pBkm->stClr.clrText;
break;
default:
return;
}

COLORREF arrClr[16] { };
CHOOSECOLORW stChclr { .lStructSize { sizeof(CHOOSECOLORW) }, .rgbResult { *pClr },
.lpCustColors { arrClr }, .Flags { CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT } };
if (ChooseColorW(&stChclr) == FALSE) {
return;
}

*pClr = stChclr.rgbResult;
m_pHexCtrl->Redraw();
}

void CHexDlgBkmMgr::OnNotifyListRClick(NMHDR* pNMHDR)
{
bool fEnabled { false };
Expand All @@ -642,28 +664,6 @@ void CHexDlgBkmMgr::OnNotifyListRClick(NMHDR* pNMHDR)
m_menuList.TrackPopupMenu(pt.x, pt.y, m_Wnd);
}

void CHexDlgBkmMgr::OnNotifyListGetColor(NMHDR* pNMHDR)
{
const auto pLCI = reinterpret_cast<LISTEX::PLISTEXCOLORINFO>(pNMHDR);

switch (pLCI->iSubItem) {
case 4: //Bk color.
if (const auto* const pBkm = GetByIndex(static_cast<std::size_t>(pLCI->iItem)); pBkm != nullptr) {
pLCI->stClr.clrBk = pBkm->stClr.clrBk;
return;
}
break;
case 5: //Text color.
if (const auto* const pBkm = GetByIndex(static_cast<std::size_t>(pLCI->iItem)); pBkm != nullptr) {
pLCI->stClr.clrBk = pBkm->stClr.clrText;
return;
}
break;
default:
break;
}
}

void CHexDlgBkmMgr::OnNotifyListSetData(NMHDR* pNMHDR)
{
const auto pLDI = reinterpret_cast<LISTEX::PLISTEXDATAINFO>(pNMHDR);
Expand Down
4 changes: 2 additions & 2 deletions HexCtrl/src/Dialogs/CHexDlgBkmMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ namespace HEXCTRL::INTERNAL {
auto OnInitDialog(const MSG& msg) -> INT_PTR;
auto OnMeasureItem(const MSG& msg) -> INT_PTR;
auto OnNotify(const MSG& msg) -> INT_PTR;
void OnNotifyListDblClick(NMHDR* pNMHDR);
void OnNotifyListGetColor(NMHDR* pNMHDR);
void OnNotifyListGetDispInfo(NMHDR* pNMHDR);
void OnNotifyListItemChanged(NMHDR* pNMHDR);
void OnNotifyListDblClick(NMHDR* pNMHDR);
void OnNotifyListRClick(NMHDR* pNMHDR);
void OnNotifyListGetColor(NMHDR* pNMHDR);
void OnNotifyListSetData(NMHDR* pNMHDR);
auto OnSize(const MSG& msg) -> INT_PTR;
void RemoveBookmark(std::uint64_t ullID);
Expand Down
Loading

0 comments on commit ea4a29b

Please sign in to comment.