Skip to content

Commit

Permalink
[Changes] DialogSampleWnd now hides on tabs switching.
Browse files Browse the repository at this point in the history
CViewRightTL::OnNotify decoupling. Latest HexCtrl, latest IListEx. Code cleanups.
  • Loading branch information
jovibor committed Jun 3, 2020
1 parent 079eabb commit 25a97c5
Show file tree
Hide file tree
Showing 30 changed files with 1,770 additions and 1,175 deletions.
22 changes: 22 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Checks: '*,
-cppcoreguidelines-*,-google-*,-fuchsia-*,-hicpp-*,-cert-*,-clang-*,
-modernize-use-trailing-return-type,
-modernize-avoid-c-arrays,
-llvm-header-guard,
-llvm-namespace-comment,
-llvm-qualified-auto,
-readability-braces-around-statements,
-readability-implicit-bool-conversion,
-readability-magic-numbers,
-readability-redundant-access-specifiers,
-readability-isolate-declaration,
-readability-qualified-auto,
-readability-convert-member-functions-to-static,
-readability-misleading-indentation,
-misc-non-private-member-variables-in-classes,
-misc-use-after-move,
-bugprone-narrowing-conversions,
-bugprone-use-after-move'


HeaderFilterRegex: '.*'
33 changes: 31 additions & 2 deletions Pepper/ChildFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
****************************************************************************************************/
#include "stdafx.h"
#include "ChildFrm.h"
#include "MainFrm.h"
#include "ViewLeft.h"
#include "ViewRightTL.h"
#include "ViewRightBL.h"
#include "ViewRightTR.h"
#include "ViewRightBR.h"
#include "ViewRightTL.h"
#include "ViewRightTR.h"
#include <cmath>

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
ON_WM_SIZE()
ON_WM_ERASEBKGND()
ON_WM_CLOSE()
END_MESSAGE_MAP()

BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
Expand Down Expand Up @@ -54,14 +56,41 @@ BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pConte

m_fSplitterCreated = true;

auto pMainFrm = (CMainFrame*)AfxGetMainWnd();
pMainFrm->GetChildFramesCount()++;

return TRUE;
}

void CChildFrame::OnClose()
{
auto pMainFrm = (CMainFrame*)AfxGetMainWnd();
--pMainFrm->GetChildFramesCount();
pMainFrm->SetCurrFramePtrNull();
m_vecWndStatus.clear();

CMDIChildWndEx::OnClose();
}

BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
{
return CMDIChildWndEx::OnEraseBkgnd(pDC);
}

auto CChildFrame::GetWndStatData() -> std::vector<SWINDOWSTATUS>&
{
return m_vecWndStatus;
}

void CChildFrame::SetWindowStatus(CWnd* pWnd, bool fVisible)
{
if (auto iter = std::find_if(m_vecWndStatus.begin(), m_vecWndStatus.end(),
[pWnd](const SWINDOWSTATUS& ref) {return ref.pWnd == pWnd; }); iter != m_vecWndStatus.end())
{
iter->fVisible = fVisible;
}
}

void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
if (m_fSplitterCreated && nType != SIZE_MINIMIZED && cx > 0 && cy > 0)
Expand Down
53 changes: 25 additions & 28 deletions Pepper/FileLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
{
if (!pHexCtrl)
{
if (!m_stHex->IsCreated())
m_stHex->Create(m_hcs);
pHexCtrl = m_stHex.get();
if (!m_pHex->IsCreated())
m_pHex->Create(m_hcs);
pHexCtrl = m_pHex.get();
}

EHexDataMode enMode;
PBYTE pData;
std::byte* pData;
if (m_fMapViewOfFileWhole) {
enMode = EHexDataMode::DATA_MEMORY;
pData = (PBYTE)m_lpBase;
pData = (std::byte*)m_lpBase;
}
else {
enMode = EHexDataMode::DATA_MSG;
Expand Down Expand Up @@ -124,7 +124,7 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
pHexCtrl->SetData(m_hds);

//If floating HexCtrl in use - bring it to front.
if (pHexCtrl == m_stHex.get())
if (pHexCtrl == m_pHex.get())
::SetForegroundWindow(pHexCtrl->GetWindowHandle());

return S_OK;
Expand All @@ -137,9 +137,9 @@ HRESULT CFileLoader::ShowFilePiece(ULONGLONG ullOffset, ULONGLONG ullSize, IHexC

if (!pHexCtrl)
{
if (!m_stHex->IsCreated())
m_stHex->Create(m_hcs);
pHexCtrl = m_stHex.get();
if (!m_pHex->IsCreated())
m_pHex->Create(m_hcs);
pHexCtrl = m_pHex.get();
}

if (ullOffset >= (ULONGLONG)m_stFileSize.QuadPart) //Overflow check.
Expand All @@ -151,10 +151,10 @@ HRESULT CFileLoader::ShowFilePiece(ULONGLONG ullOffset, ULONGLONG ullSize, IHexC
ullSize = (ULONGLONG)m_stFileSize.QuadPart - ullOffset;

EHexDataMode enMode;
PBYTE pData;
std::byte* pData;
if (m_fMapViewOfFileWhole) {
enMode = EHexDataMode::DATA_MEMORY;
pData = (PBYTE)((DWORD_PTR)m_lpBase + ullOffset);
pData = (std::byte*)((DWORD_PTR)m_lpBase + ullOffset);
}
else {
enMode = EHexDataMode::DATA_MSG;
Expand Down Expand Up @@ -207,8 +207,8 @@ HRESULT CFileLoader::MapFileOffset(QUERYDATA & rData, ULONGLONG ullOffset, DWORD
if ((LONGLONG)(ullStartOffsetMapped + dwSizeToMap) > m_stFileSize.QuadPart)
dwSizeToMap = (DWORD_PTR)(m_stFileSize.QuadPart - (LONGLONG)ullStartOffsetMapped);

DWORD dwOffsetHigh = (ullStartOffsetMapped >> 32) & 0xFFFFFFFFul;
DWORD dwOffsetLow = ullStartOffsetMapped & 0xFFFFFFFFul;
DWORD dwOffsetHigh = (ullStartOffsetMapped >> 32) & 0xFFFFFFFFUL;
DWORD dwOffsetLow = ullStartOffsetMapped & 0xFFFFFFFFUL;
LPVOID lpData { };
if ((lpData = MapViewOfFile(m_hMapObject, FILE_MAP_READ, dwOffsetHigh, dwOffsetLow, dwSizeToMap)) == nullptr)
return E_FILE_MAPVIEWOFFILE_SECTION_FAILED;
Expand Down Expand Up @@ -269,14 +269,14 @@ HRESULT CFileLoader::UnloadFile()
return S_OK;
}

bool CFileLoader::IsLoaded()
bool CFileLoader::IsLoaded()const
{
return m_fLoaded;
}

BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
{
PHEXNOTIFYSTRUCT pHexNtfy = (PHEXNOTIFYSTRUCT)lParam;
auto pHexNtfy = (PHEXNOTIFYSTRUCT)lParam;

switch (pHexNtfy->hdr.code)
{
Expand All @@ -293,41 +293,38 @@ BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
}
break;
case HEXCTRL_MSG_GETDATA:
m_byte = GetByte(pHexNtfy->hdr.hwndFrom, pHexNtfy->stSpan.ullOffset);
pHexNtfy->pData = &m_byte;
pHexNtfy->pData = GetData(pHexNtfy->hdr.hwndFrom, pHexNtfy->stSpan.ullOffset);
break;
case HEXCTRL_MSG_DATACHANGE:
case HEXCTRL_MSG_SETDATA:
m_fModified = true;
break;
}

return CWnd::OnNotify(wParam, lParam, pResult);
}

unsigned char CFileLoader::GetByte(HWND hWnd, ULONGLONG ullOffset)
std::byte* CFileLoader::GetData(HWND hWnd, ULONGLONG ullOffset)
{
auto const& iter = std::find_if(m_vecQuery.begin(), m_vecQuery.end(),
[hWnd](const QUERYDATA & rData) {return rData.hWnd == hWnd; });
if (iter == m_vecQuery.end())
return 0;
return nullptr;

unsigned char chByte;
std::byte* pData { };
ullOffset += iter->ullOffsetDelta;

if (m_fMapViewOfFileWhole && ullOffset < (ULONGLONG)m_stFileSize.QuadPart)
chByte = ((PBYTE)m_lpBase)[ullOffset];
pData = ((std::byte*)m_lpBase) + ullOffset;
else
{
if (ullOffset >= iter->ullStartOffsetMapped && ullOffset < iter->ullEndOffsetMapped)
chByte = ((PBYTE)iter->lpData)[ullOffset - iter->ullStartOffsetMapped];
pData = ((std::byte*)iter->lpData) + (ullOffset - iter->ullStartOffsetMapped);
else
{
if (MapFileOffset(*iter, ullOffset) == S_OK)
chByte = ((PBYTE)iter->lpData)[ullOffset - iter->ullStartOffsetMapped];
else
chByte = 0;
pData = ((std::byte*)iter->lpData) + (ullOffset - iter->ullStartOffsetMapped);
}
}

return chByte;
return pData;
}
108 changes: 63 additions & 45 deletions Pepper/ListEx/ListEx.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/****************************************************************************************
* Copyright © 2018-2020 Jovibor https://github.com/jovibor/ *
* Copyright © 2018-2020 Jovibor https://github.com/jovibor/ *
* This is very extended and featured version of CMFCListCtrl class. *
* Official git repository: https://github.com/jovibor/ListEx/ *
* This class is available under the "MIT License". *
Expand All @@ -8,54 +8,70 @@
#pragma once
#include <afxcontrolbars.h>
#include <memory>
#include <string>

namespace LISTEX
{
/********************************************************************************************
* EnListExSortMode - Sorting mode. *
* EListExSortMode - Sorting mode. *
********************************************************************************************/
enum class EnListExSortMode : short
enum class EListExSortMode : WORD
{
SORT_LEX, SORT_NUMERIC
};

/********************************************
* LISTEXCELLCOLOR - colors for the cell. *
********************************************/
struct LISTEXCELLCOLOR
{
COLORREF clrBk { };
COLORREF clrText { };
};
using PLISTEXCELLCOLOR = LISTEXCELLCOLOR*;

/********************************************************************************************
* LISTEXCOLORSTRUCT - All ListEx colors. *
* LISTEXCOLORS - All ListEx colors. *
********************************************************************************************/
struct LISTEXCOLORSTRUCT
struct LISTEXCOLORS
{
COLORREF clrListText { GetSysColor(COLOR_WINDOWTEXT) }; //List text color.
COLORREF clrListBkRow1 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the odd rows.
COLORREF clrListBkRow2 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the even rows.
COLORREF clrListGrid { RGB(220, 220, 220) }; //List grid color.
COLORREF clrListTextSelected { GetSysColor(COLOR_HIGHLIGHTTEXT) }; //Selected item text color.
COLORREF clrListBkSelected { GetSysColor(COLOR_HIGHLIGHT) }; //Selected item bk color.
COLORREF clrTooltipText { GetSysColor(COLOR_INFOTEXT) }; //Tooltip window text color.
COLORREF clrTooltipBk { GetSysColor(COLOR_INFOBK) }; //Tooltip window bk color.
COLORREF clrListTextCellTt { GetSysColor(COLOR_WINDOWTEXT) }; //Text color of a cell that has tooltip.
COLORREF clrListBkCellTt { RGB(170, 170, 230) }; //Bk color of a cell that has tooltip.
COLORREF clrHdrText { GetSysColor(COLOR_WINDOWTEXT) }; //List header text color.
COLORREF clrHdrBk { GetSysColor(COLOR_WINDOW) }; //List header bk color.
COLORREF clrHdrHglInactive { GetSysColor(COLOR_GRADIENTINACTIVECAPTION) };//Header highlight inactive.
COLORREF clrHdrHglActive { GetSysColor(COLOR_GRADIENTACTIVECAPTION) }; //Header highlight active.
COLORREF clrBkNWA { GetSysColor(COLOR_WINDOW) }; //Bk of non working area.
COLORREF clrListText { GetSysColor(COLOR_WINDOWTEXT) }; //List text color.
COLORREF clrListTextLink { RGB(0, 0, 200) }; //List hyperlink text color.
COLORREF clrListTextSel { GetSysColor(COLOR_HIGHLIGHTTEXT) }; //Selected item text color.
COLORREF clrListTextLinkSel { RGB(250, 250, 250) }; //List hyperlink text color in selected cell.
COLORREF clrListTextCellTt { GetSysColor(COLOR_WINDOWTEXT) }; //Text color of a cell that has tooltip.
COLORREF clrListBkRow1 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the odd rows.
COLORREF clrListBkRow2 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the even rows.
COLORREF clrListBkSel { GetSysColor(COLOR_HIGHLIGHT) }; //Selected item bk color.
COLORREF clrListBkCellTt { RGB(170, 170, 230) }; //Bk color of a cell that has tooltip.
COLORREF clrListGrid { RGB(220, 220, 220) }; //List grid color.
COLORREF clrTooltipText { GetSysColor(COLOR_INFOTEXT) }; //Tooltip window text color.
COLORREF clrTooltipBk { GetSysColor(COLOR_INFOBK) }; //Tooltip window bk color.
COLORREF clrHdrText { GetSysColor(COLOR_WINDOWTEXT) }; //List header text color.
COLORREF clrHdrBk { GetSysColor(COLOR_WINDOW) }; //List header bk color.
COLORREF clrHdrHglInact { GetSysColor(COLOR_GRADIENTINACTIVECAPTION) };//Header highlight inactive.
COLORREF clrHdrHglAct { GetSysColor(COLOR_GRADIENTACTIVECAPTION) }; //Header highlight active.
COLORREF clrNWABk { GetSysColor(COLOR_WINDOW) }; //Bk of Non Working Area.
};

/********************************************************************************************
* LISTEXCREATESTRUCT - Main initialization helper struct for CListEx::Create method. *
********************************************************************************************/
struct LISTEXCREATESTRUCT {
LISTEXCOLORSTRUCT stColor { }; //All control's colors.
CRect rect; //Initial rect.
CWnd* pwndParent { }; //Parent window.
const LOGFONTW* pListLogFont { }; //List font.
const LOGFONTW* pHdrLogFont { }; //Header font.
DWORD dwStyle { }; //Control's styles. Zero for default.
UINT uID { }; //Control Id.
DWORD dwListGridWidth { 1 }; //Width of the list grid.
DWORD dwHdrHeight { 20 }; //Header height.
bool fSortable { false }; //Is list sortable, by clicking on the header column?
bool fDialogCtrl { false }; //If it's a list within dialog.
struct LISTEXCREATESTRUCT
{
LISTEXCOLORS stColor { }; //All control's colors.
CRect rect; //Initial rect.
CWnd* pParent { }; //Parent window.
LOGFONTW* pListLogFont { }; //List font.
LOGFONTW* pHdrLogFont { }; //Header font.
UINT uID { }; //List control ID.
DWORD dwStyle { }; //Control's styles. Zero for default.
DWORD dwListGridWidth { 1 }; //Width of the list grid.
DWORD dwHdrHeight { 20 }; //Header height.
bool fDialogCtrl { false }; //If it's a list within dialog.
bool fSortable { false }; //Is list sortable, by clicking on the header column?
bool fLinkUnderline { true }; //Links are displayed underlined or not.
bool fLinkTooltip { true }; //Show links' toolips.
};

/********************************************
Expand All @@ -64,35 +80,35 @@ namespace LISTEX
class IListEx : public CMFCListCtrl
{
public:
IListEx() = default;
virtual ~IListEx() = default;
virtual bool Create(const LISTEXCREATESTRUCT& lcs) = 0;
virtual void CreateDialogCtrl(UINT uCtrlID, CWnd* pwndDlg) = 0;
virtual BOOL DeleteAllItems() = 0;
virtual BOOL DeleteColumn(int nCol) = 0;
virtual BOOL DeleteItem(int nItem) = 0;
virtual void Destroy() = 0;
virtual ULONGLONG GetCellData(int iItem, int iSubitem)const = 0;
virtual EnListExSortMode GetColumnSortMode(int iColumn)const = 0;
virtual UINT GetFontSize()const = 0;
virtual int GetSortColumn()const = 0;
virtual bool GetSortAscending()const = 0;
virtual bool IsCreated()const = 0;
[[nodiscard]] virtual ULONGLONG GetCellData(int iItem, int iSubitem)const = 0;
[[nodiscard]] virtual LISTEXCOLORS GetColors()const = 0;
[[nodiscard]] virtual EListExSortMode GetColumnSortMode(int iColumn)const = 0;
[[nodiscard]] virtual UINT GetFontSize()const = 0;
[[nodiscard]] virtual int GetSortColumn()const = 0;
[[nodiscard]] virtual bool GetSortAscending()const = 0;
[[nodiscard]] virtual bool IsCreated()const = 0;
virtual void SetCellColor(int iItem, int iSubitem, COLORREF clrBk, COLORREF clrText = -1) = 0;
virtual void SetCellData(int iItem, int iSubitem, ULONGLONG ullData) = 0;
virtual void SetCellMenu(int iItem, int iSubitem, CMenu* pMenu) = 0;
virtual void SetCellTooltip(int iItem, int iSubitem, const wchar_t* pwszTooltip, const wchar_t* pwszCaption = nullptr) = 0;
virtual void SetColor(const LISTEXCOLORSTRUCT& lcs) = 0;
virtual void SetCellTooltip(int iItem, int iSubitem, std::wstring_view wstrTooltip, std::wstring_view wstrCaption = L"") = 0;
virtual void SetColors(const LISTEXCOLORS& lcs) = 0;
virtual void SetColumnColor(int iColumn, COLORREF clrBk, COLORREF clrText = -1) = 0;
virtual void SetColumnSortMode(int iColumn, EnListExSortMode enSortMode) = 0;
virtual void SetColumnSortMode(int iColumn, EListExSortMode enSortMode) = 0;
virtual void SetFont(const LOGFONTW* pLogFontNew) = 0;
virtual void SetFontSize(UINT uiSize) = 0;
virtual void SetHdrHeight(DWORD dwHeight) = 0;
virtual void SetHdrFont(const LOGFONTW* pLogFontNew) = 0;
virtual void SetHdrColumnColor(int iColumn, COLORREF clrBk, COLORREF clrText = -1) = 0;
virtual void SetListMenu(CMenu* pMenu) = 0;
virtual void SetRowColor(DWORD dwRow, COLORREF clrBk, COLORREF clrText = -1) = 0;
virtual void SetSortable(bool fSortable, PFNLVCOMPARE pfnCompare = nullptr, EnListExSortMode enSortMode = EnListExSortMode::SORT_LEX) = 0;
virtual void SetSortable(bool fSortable, PFNLVCOMPARE pfnCompare = nullptr,
EListExSortMode enSortMode = EListExSortMode::SORT_LEX) = 0;
};

/********************************************************************************************
Expand Down Expand Up @@ -120,5 +136,7 @@ namespace LISTEX
* WM_NOTIFY codes (NMHDR.code values) *
****************************************************************************/

constexpr auto LISTEX_MSG_MENUSELECTED = 0x1000u;
constexpr auto LISTEX_MSG_MENUSELECTED = 0x1000U; //User defined menu item selected.
constexpr auto LISTEX_MSG_CELLCOLOR = 0x1001U; //Get cell color.
constexpr auto LISTEX_MSG_LINKCLICK = 0x1002U; //Hyperlink has been clicked.
}
Loading

0 comments on commit 25a97c5

Please sign in to comment.