Skip to content

Commit

Permalink
CHexDlgTemplMgr is now MFC free.
Browse files Browse the repository at this point in the history
wnd::CWndBtn, wnd::CWndTree, wnd::CMenu classes added.
  • Loading branch information
jovibor committed Dec 22, 2024
1 parent a230274 commit 59bc632
Show file tree
Hide file tree
Showing 9 changed files with 726 additions and 601 deletions.
2 changes: 1 addition & 1 deletion HexCtrl/HexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ namespace HEXCTRL {
COLORREF clrBkSel { GetSysColor(COLOR_HIGHLIGHT) }; //Background color of the selected Hex/Text.
COLORREF clrBkBkm { RGB(240, 240, 0) }; //Bookmarks background color.
COLORREF clrBkDataInterp { RGB(147, 58, 22) }; //Data Interpreter Bk color.
COLORREF clrBkInfoBar { GetSysColor(COLOR_BTNFACE) }; //Background color of the bottom Info bar.
COLORREF clrBkInfoBar { GetSysColor(COLOR_3DFACE) }; //Background color of the bottom Info bar.
COLORREF clrBkCaret { RGB(0, 0, 255) }; //Caret background color.
COLORREF clrBkCaretSel { RGB(0, 0, 200) }; //Caret background color in selection.
};
Expand Down
29 changes: 10 additions & 19 deletions HexCtrl/src/CHexCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ auto CHexDlgAbout::OnCtlClrStatic(const MSG& stMsg)->INT_PTR
if (hWndFrom == m_WndLink) {
const auto hDC = reinterpret_cast<HDC>(stMsg.wParam);
::SetTextColor(hDC, RGB(0, 50, 250));
::SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
::SetBkColor(hDC, ::GetSysColor(COLOR_3DFACE));
::SelectObject(hDC, m_fLinkUnderline ? m_hFontUnderline : m_hFontDef);
return reinterpret_cast<INT_PTR>(::GetStockObject(HOLLOW_BRUSH));
return reinterpret_cast<INT_PTR>(::GetSysColorBrush(COLOR_3DFACE));
}

return FALSE; //Default handler.
Expand Down Expand Up @@ -1010,10 +1010,10 @@ auto CHexCtrl::GetWndHandle(EHexWnd eWnd, bool fCreate)const->HWND
}
return m_pDlgGoTo->GetHWND();
case EHexWnd::DLG_TEMPLMGR:
if (!IsWindow(m_pDlgTemplMgr->m_hWnd) && fCreate) {
m_pDlgTemplMgr->Create(IDD_HEXCTRL_TEMPLMGR, CWnd::FromHandle(m_hWnd));
if (!IsWindow(m_pDlgTemplMgr->GetHWND()) && fCreate) {
m_pDlgTemplMgr->CreateDlg();
}
return m_pDlgTemplMgr->m_hWnd;
return m_pDlgTemplMgr->GetHWND();
default:
return { };
}
Expand Down Expand Up @@ -6868,11 +6868,9 @@ void CHexCtrl::OnContextMenu(CWnd* /*pWnd*/, CPoint point)

void CHexCtrl::OnDestroy()
{
//All these cleanups below are important in case when HexCtrl window is destroyed
//but IHexCtrl object itself is still alive.
//When the main window is destroyed, the IHexCtrl object is still alive unless the
//IHexCtrl::Destroy() method is called.
//All the child dialogs' DestroyWindow will be called automatically.
//All these cleanups below are important when HexCtrl window is destroyed but IHexCtrl object
//itself is still alive. The IHexCtrl object is alive until the IHexCtrl::Destroy() method is called.
//Child windows of IHexCtrl (dialogs, tooltips, etc...) will be destroyed automatically by Windows.

ClearData();
m_vecHBITMAP.clear();
Expand All @@ -6886,15 +6884,8 @@ void CHexCtrl::OnDestroy()
m_fntInfoBar.DeleteObject();
m_penLines.DeleteObject();
m_penDataTempl.DeleteObject();
m_pScrollV->DestroyWindow();
m_pScrollH->DestroyWindow();
m_pDlgBkmMgr->DestroyWindow();
m_pDlgCodepage->DestroyWindow();
m_pDlgDataInterp->DestroyWindow();
m_pDlgModify->DestroyWindow();
m_pDlgGoTo->DestroyWindow();
m_pDlgSearch->DestroyWindow();
m_pDlgTemplMgr->DestroyWindow();
m_pScrollV->DestroyWindow(); //Not child of the IHexCtrl.
m_pScrollH->DestroyWindow(); //Not child of the IHexCtrl.
m_fCreated = false;

ParentNotify(HEXCTRL_MSG_DESTROY);
Expand Down
6 changes: 3 additions & 3 deletions HexCtrl/src/CHexScroll.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ void CHexScroll::DrawScrollBar()const
return;
}

static const auto clrBkNC { GetSysColor(COLOR_3DFACE) }; //Bk color of the non client area.
static const auto clrBkNC { ::GetSysColor(COLOR_3DFACE) }; //Bk color of the non client area.
static constexpr auto clrBkScroll = RGB(241, 241, 241); //Scroll Bk color.

const auto wndParent = GetParent();
Expand Down Expand Up @@ -819,7 +819,7 @@ auto CHexScroll::GetScrollWorkAreaSizeWH()const->UINT

auto CHexScroll::GetThumbRect(bool fClientCoord)const->wnd::CRect
{
wnd::CRect rc { };
wnd::CRect rc;
const auto uiThumbSize = GetThumbSizeWH();
if (!uiThumbSize) {
return rc;
Expand Down Expand Up @@ -953,7 +953,7 @@ auto CHexScroll::GetLastChannelRect(bool fClientCoord)const->wnd::CRect
auto CHexScroll::GetParentRect(bool fClient)const->wnd::CRect
{
const auto wndParent = GetParent();
return fClient ? wndParent.GetClientRect() : wndParent.GetWndRect();
return fClient ? wndParent.GetClientRect() : wndParent.GetWindowRect();
}

int CHexScroll::GetTopDelta()const
Expand Down
110 changes: 52 additions & 58 deletions HexCtrl/src/Dialogs/CHexDlgCodepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,79 +125,46 @@ void CHexDlgCodepage::OnCancel()
ShowWindow(SW_HIDE);
}

auto CHexDlgCodepage::OnDestroy()->INT_PTR
auto CHexDlgCodepage::OnClose()->INT_PTR
{
m_vecCodePage.clear();
m_u64Flags = { };
m_pHexCtrl = nullptr;
m_Wnd.Detach();

ShowWindow(SW_HIDE);
return TRUE;
}

auto CHexDlgCodepage::OnDrawItem(const MSG& stMsg)->INT_PTR
auto CHexDlgCodepage::OnCommand(const MSG& stMsg)->INT_PTR
{
if (auto pDIS = reinterpret_cast<LPDRAWITEMSTRUCT>(stMsg.lParam);
pDIS->CtlID == static_cast<UINT>(IDC_HEXCTRL_CODEPAGE_LIST)) {
m_pList->DrawItem(pDIS);
const auto uCtrlID = LOWORD(stMsg.wParam);
switch (uCtrlID) {
case IDOK:
case IDCANCEL:
OnCancel(); break;
default:
return FALSE;
}

return TRUE;
}

auto CHexDlgCodepage::OnMeasureItem(const MSG& stMsg)->INT_PTR
auto CHexDlgCodepage::OnDestroy()->INT_PTR
{
if (auto pMIS = reinterpret_cast<LPMEASUREITEMSTRUCT>(stMsg.lParam);
pMIS->CtlID == static_cast<UINT>(IDC_HEXCTRL_CODEPAGE_LIST)) {
m_pList->MeasureItem(pMIS);
}
m_vecCodePage.clear();
m_u64Flags = { };
m_pHexCtrl = nullptr;
m_DynLayout.RemoveAll();
m_Wnd.Detach();

return TRUE;
}

auto CHexDlgCodepage::OnNotify(const MSG& stMsg)->INT_PTR
auto CHexDlgCodepage::OnDrawItem(const MSG& stMsg)->INT_PTR
{
auto pNMHDR = reinterpret_cast<NMHDR*>(stMsg.lParam);
if (pNMHDR->idFrom == IDC_HEXCTRL_CODEPAGE_LIST) {
switch (pNMHDR->code) {
case LVN_COLUMNCLICK:
SortList(); break;
case LVN_GETDISPINFOW:
OnListGetDispInfo(pNMHDR); break;
case LVN_ITEMCHANGED:
OnListItemChanged(pNMHDR); break;
case LISTEX::LISTEX_MSG_GETCOLOR:
OnListGetColor(pNMHDR); break;
case LISTEX::LISTEX_MSG_LINKCLICK:
OnListLinkClick(pNMHDR); break;
default:
break;
}
const auto pDIS = reinterpret_cast<LPDRAWITEMSTRUCT>(stMsg.lParam);
if (pDIS->CtlID == static_cast<UINT>(IDC_HEXCTRL_CODEPAGE_LIST)) {
m_pList->DrawItem(pDIS);
}

return TRUE;
}

auto CHexDlgCodepage::OnClose()->INT_PTR
{
ShowWindow(SW_HIDE);
return TRUE;
}

auto CHexDlgCodepage::OnCommand(const MSG& stMsg)->INT_PTR
{
const auto uCtrlID = LOWORD(stMsg.wParam);
switch (uCtrlID) {
case IDOK:
case IDCANCEL:
OnCancel();
break;
default:
return FALSE;
}
return TRUE;
}

auto CHexDlgCodepage::OnInitDialog(const MSG& stMsg)->INT_PTR
{
m_Wnd.Attach(stMsg.hwnd);
Expand All @@ -217,12 +184,39 @@ auto CHexDlgCodepage::OnInitDialog(const MSG& stMsg)->INT_PTR

m_DynLayout.SetHost(m_Wnd);
m_DynLayout.AddItem(IDC_HEXCTRL_CODEPAGE_LIST, wnd::CDynLayout::MoveNone(), wnd::CDynLayout::SizeHorzAndVert(100, 100));
m_DynLayout.EnableTrack(true);
m_DynLayout.Enable(true);

return TRUE;
}

auto CHexDlgCodepage::OnMeasureItem(const MSG& stMsg)->INT_PTR
{
const auto pMIS = reinterpret_cast<LPMEASUREITEMSTRUCT>(stMsg.lParam);
if (pMIS->CtlID == static_cast<UINT>(IDC_HEXCTRL_CODEPAGE_LIST)) {
m_pList->MeasureItem(pMIS);
}

return TRUE;
}

auto CHexDlgCodepage::OnNotify(const MSG& stMsg)->INT_PTR
{
const auto pNMHDR = reinterpret_cast<NMHDR*>(stMsg.lParam);
if (pNMHDR->idFrom == IDC_HEXCTRL_CODEPAGE_LIST) {
switch (pNMHDR->code) {
case LVN_COLUMNCLICK: SortList(); break;
case LVN_GETDISPINFOW: OnNotifyListGetDispInfo(pNMHDR); break;
case LVN_ITEMCHANGED: OnNotifyListItemChanged(pNMHDR); break;
case LISTEX::LISTEX_MSG_GETCOLOR: OnNotifyListGetColor(pNMHDR); break;
case LISTEX::LISTEX_MSG_LINKCLICK: OnNotifyListLinkClick(pNMHDR); break;
default: break;
}
}

return TRUE;
}

void CHexDlgCodepage::OnListGetDispInfo(NMHDR* pNMHDR)
void CHexDlgCodepage::OnNotifyListGetDispInfo(NMHDR* pNMHDR)
{
const auto pDispInfo = reinterpret_cast<NMLVDISPINFOW*>(pNMHDR);
const auto pItem = &pDispInfo->item;
Expand All @@ -245,15 +239,15 @@ void CHexDlgCodepage::OnListGetDispInfo(NMHDR* pNMHDR)
}
}

void CHexDlgCodepage::OnListItemChanged(NMHDR* pNMHDR)
void CHexDlgCodepage::OnNotifyListItemChanged(NMHDR* pNMHDR)
{
if (const auto* const pNMI = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
pNMI->iItem != -1 && pNMI->iSubItem != -1 && (pNMI->uNewState & LVIS_SELECTED)) {
m_pHexCtrl->SetCodepage(m_vecCodePage[static_cast<std::size_t>(pNMI->iItem)].iCPID);
}
}

void CHexDlgCodepage::OnListGetColor(NMHDR* pNMHDR)
void CHexDlgCodepage::OnNotifyListGetColor(NMHDR* pNMHDR)
{
if (const auto pLCI = reinterpret_cast<LISTEX::PLISTEXCOLORINFO>(pNMHDR);
m_vecCodePage[static_cast<std::size_t>(pLCI->iItem)].uMaxChars > 1) {
Expand All @@ -262,7 +256,7 @@ void CHexDlgCodepage::OnListGetColor(NMHDR* pNMHDR)
}
}

void CHexDlgCodepage::OnListLinkClick(NMHDR* pNMHDR)
void CHexDlgCodepage::OnNotifyListLinkClick(NMHDR* pNMHDR)
{
const auto* const pLLI = reinterpret_cast<LISTEX::PLISTEXLINKINFO>(pNMHDR);
ShellExecuteW(nullptr, L"open", pLLI->pwszText, nullptr, nullptr, SW_SHOWNORMAL);
Expand Down
10 changes: 5 additions & 5 deletions HexCtrl/src/Dialogs/CHexDlgCodepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace HEXCTRL::INTERNAL {
auto OnCommand(const MSG& stMsg) -> INT_PTR;
auto OnDestroy() -> INT_PTR;
auto OnDrawItem(const MSG& stMsg) -> INT_PTR;
auto OnInitDialog(const MSG& stMsg) -> INT_PTR;
auto OnMeasureItem(const MSG& stMsg) -> INT_PTR;
auto OnNotify(const MSG& stMsg) -> INT_PTR;
auto OnInitDialog(const MSG& stMsg) -> INT_PTR;
void OnListGetDispInfo(NMHDR *pNMHDR);
void OnListItemChanged(NMHDR *pNMHDR);
void OnListGetColor(NMHDR *pNMHDR);
void OnListLinkClick(NMHDR *pNMHDR);
void OnNotifyListGetDispInfo(NMHDR* pNMHDR);
void OnNotifyListItemChanged(NMHDR* pNMHDR);
void OnNotifyListGetColor(NMHDR* pNMHDR);
void OnNotifyListLinkClick(NMHDR* pNMHDR);
auto OnSize(const MSG& stMsg) -> INT_PTR;
void SortList();
static BOOL CALLBACK EnumCodePagesProc(LPWSTR pwszCP);
Expand Down
4 changes: 2 additions & 2 deletions HexCtrl/src/Dialogs/CHexDlgProgress.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ auto CHexDlgProgress::OnCtlClrStatic(const MSG& stMsg)->INT_PTR
if (hWndFrom == m_WndCount) {
const auto hDC = reinterpret_cast<HDC>(stMsg.wParam);
::SetTextColor(hDC, RGB(0, 200, 0));
::SetBkColor(hDC, GetSysColor(COLOR_BTNFACE));
return reinterpret_cast<INT_PTR>(::GetStockObject(HOLLOW_BRUSH));
::SetBkColor(hDC, ::GetSysColor(COLOR_3DFACE));
return reinterpret_cast<INT_PTR>(::GetSysColorBrush(COLOR_3DFACE));
}

return FALSE; //Default handler.
Expand Down
Loading

0 comments on commit 59bc632

Please sign in to comment.