Skip to content

Commit 25a97c5

Browse files
committed
[Changes] DialogSampleWnd now hides on tabs switching.
CViewRightTL::OnNotify decoupling. Latest HexCtrl, latest IListEx. Code cleanups.
1 parent 079eabb commit 25a97c5

30 files changed

+1770
-1175
lines changed

.clang-tidy

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
Checks: '*,
2+
-cppcoreguidelines-*,-google-*,-fuchsia-*,-hicpp-*,-cert-*,-clang-*,
3+
-modernize-use-trailing-return-type,
4+
-modernize-avoid-c-arrays,
5+
-llvm-header-guard,
6+
-llvm-namespace-comment,
7+
-llvm-qualified-auto,
8+
-readability-braces-around-statements,
9+
-readability-implicit-bool-conversion,
10+
-readability-magic-numbers,
11+
-readability-redundant-access-specifiers,
12+
-readability-isolate-declaration,
13+
-readability-qualified-auto,
14+
-readability-convert-member-functions-to-static,
15+
-readability-misleading-indentation,
16+
-misc-non-private-member-variables-in-classes,
17+
-misc-use-after-move,
18+
-bugprone-narrowing-conversions,
19+
-bugprone-use-after-move'
20+
21+
22+
HeaderFilterRegex: '.*'

Pepper/ChildFrm.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,20 @@
88
****************************************************************************************************/
99
#include "stdafx.h"
1010
#include "ChildFrm.h"
11+
#include "MainFrm.h"
1112
#include "ViewLeft.h"
12-
#include "ViewRightTL.h"
1313
#include "ViewRightBL.h"
14-
#include "ViewRightTR.h"
1514
#include "ViewRightBR.h"
15+
#include "ViewRightTL.h"
16+
#include "ViewRightTR.h"
1617
#include <cmath>
1718

1819
IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWndEx)
1920

2021
BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWndEx)
2122
ON_WM_SIZE()
2223
ON_WM_ERASEBKGND()
24+
ON_WM_CLOSE()
2325
END_MESSAGE_MAP()
2426

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

5557
m_fSplitterCreated = true;
5658

59+
auto pMainFrm = (CMainFrame*)AfxGetMainWnd();
60+
pMainFrm->GetChildFramesCount()++;
61+
5762
return TRUE;
5863
}
5964

65+
void CChildFrame::OnClose()
66+
{
67+
auto pMainFrm = (CMainFrame*)AfxGetMainWnd();
68+
--pMainFrm->GetChildFramesCount();
69+
pMainFrm->SetCurrFramePtrNull();
70+
m_vecWndStatus.clear();
71+
72+
CMDIChildWndEx::OnClose();
73+
}
74+
6075
BOOL CChildFrame::OnEraseBkgnd(CDC* pDC)
6176
{
6277
return CMDIChildWndEx::OnEraseBkgnd(pDC);
6378
}
6479

80+
auto CChildFrame::GetWndStatData() -> std::vector<SWINDOWSTATUS>&
81+
{
82+
return m_vecWndStatus;
83+
}
84+
85+
void CChildFrame::SetWindowStatus(CWnd* pWnd, bool fVisible)
86+
{
87+
if (auto iter = std::find_if(m_vecWndStatus.begin(), m_vecWndStatus.end(),
88+
[pWnd](const SWINDOWSTATUS& ref) {return ref.pWnd == pWnd; }); iter != m_vecWndStatus.end())
89+
{
90+
iter->fVisible = fVisible;
91+
}
92+
}
93+
6594
void CChildFrame::OnSize(UINT nType, int cx, int cy)
6695
{
6796
if (m_fSplitterCreated && nType != SIZE_MINIMIZED && cx > 0 && cy > 0)

Pepper/FileLoader.cpp

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
7575
{
7676
if (!pHexCtrl)
7777
{
78-
if (!m_stHex->IsCreated())
79-
m_stHex->Create(m_hcs);
80-
pHexCtrl = m_stHex.get();
78+
if (!m_pHex->IsCreated())
79+
m_pHex->Create(m_hcs);
80+
pHexCtrl = m_pHex.get();
8181
}
8282

8383
EHexDataMode enMode;
84-
PBYTE pData;
84+
std::byte* pData;
8585
if (m_fMapViewOfFileWhole) {
8686
enMode = EHexDataMode::DATA_MEMORY;
87-
pData = (PBYTE)m_lpBase;
87+
pData = (std::byte*)m_lpBase;
8888
}
8989
else {
9090
enMode = EHexDataMode::DATA_MSG;
@@ -124,7 +124,7 @@ HRESULT CFileLoader::ShowOffset(ULONGLONG ullOffset, ULONGLONG ullSelectionSize,
124124
pHexCtrl->SetData(m_hds);
125125

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

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

138138
if (!pHexCtrl)
139139
{
140-
if (!m_stHex->IsCreated())
141-
m_stHex->Create(m_hcs);
142-
pHexCtrl = m_stHex.get();
140+
if (!m_pHex->IsCreated())
141+
m_pHex->Create(m_hcs);
142+
pHexCtrl = m_pHex.get();
143143
}
144144

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

153153
EHexDataMode enMode;
154-
PBYTE pData;
154+
std::byte* pData;
155155
if (m_fMapViewOfFileWhole) {
156156
enMode = EHexDataMode::DATA_MEMORY;
157-
pData = (PBYTE)((DWORD_PTR)m_lpBase + ullOffset);
157+
pData = (std::byte*)((DWORD_PTR)m_lpBase + ullOffset);
158158
}
159159
else {
160160
enMode = EHexDataMode::DATA_MSG;
@@ -207,8 +207,8 @@ HRESULT CFileLoader::MapFileOffset(QUERYDATA & rData, ULONGLONG ullOffset, DWORD
207207
if ((LONGLONG)(ullStartOffsetMapped + dwSizeToMap) > m_stFileSize.QuadPart)
208208
dwSizeToMap = (DWORD_PTR)(m_stFileSize.QuadPart - (LONGLONG)ullStartOffsetMapped);
209209

210-
DWORD dwOffsetHigh = (ullStartOffsetMapped >> 32) & 0xFFFFFFFFul;
211-
DWORD dwOffsetLow = ullStartOffsetMapped & 0xFFFFFFFFul;
210+
DWORD dwOffsetHigh = (ullStartOffsetMapped >> 32) & 0xFFFFFFFFUL;
211+
DWORD dwOffsetLow = ullStartOffsetMapped & 0xFFFFFFFFUL;
212212
LPVOID lpData { };
213213
if ((lpData = MapViewOfFile(m_hMapObject, FILE_MAP_READ, dwOffsetHigh, dwOffsetLow, dwSizeToMap)) == nullptr)
214214
return E_FILE_MAPVIEWOFFILE_SECTION_FAILED;
@@ -269,14 +269,14 @@ HRESULT CFileLoader::UnloadFile()
269269
return S_OK;
270270
}
271271

272-
bool CFileLoader::IsLoaded()
272+
bool CFileLoader::IsLoaded()const
273273
{
274274
return m_fLoaded;
275275
}
276276

277-
BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
277+
BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult)
278278
{
279-
PHEXNOTIFYSTRUCT pHexNtfy = (PHEXNOTIFYSTRUCT)lParam;
279+
auto pHexNtfy = (PHEXNOTIFYSTRUCT)lParam;
280280

281281
switch (pHexNtfy->hdr.code)
282282
{
@@ -293,41 +293,38 @@ BOOL CFileLoader::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
293293
}
294294
break;
295295
case HEXCTRL_MSG_GETDATA:
296-
m_byte = GetByte(pHexNtfy->hdr.hwndFrom, pHexNtfy->stSpan.ullOffset);
297-
pHexNtfy->pData = &m_byte;
296+
pHexNtfy->pData = GetData(pHexNtfy->hdr.hwndFrom, pHexNtfy->stSpan.ullOffset);
298297
break;
299-
case HEXCTRL_MSG_DATACHANGE:
298+
case HEXCTRL_MSG_SETDATA:
300299
m_fModified = true;
301300
break;
302301
}
303302

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

307-
unsigned char CFileLoader::GetByte(HWND hWnd, ULONGLONG ullOffset)
306+
std::byte* CFileLoader::GetData(HWND hWnd, ULONGLONG ullOffset)
308307
{
309308
auto const& iter = std::find_if(m_vecQuery.begin(), m_vecQuery.end(),
310309
[hWnd](const QUERYDATA & rData) {return rData.hWnd == hWnd; });
311310
if (iter == m_vecQuery.end())
312-
return 0;
311+
return nullptr;
313312

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

317316
if (m_fMapViewOfFileWhole && ullOffset < (ULONGLONG)m_stFileSize.QuadPart)
318-
chByte = ((PBYTE)m_lpBase)[ullOffset];
317+
pData = ((std::byte*)m_lpBase) + ullOffset;
319318
else
320319
{
321320
if (ullOffset >= iter->ullStartOffsetMapped && ullOffset < iter->ullEndOffsetMapped)
322-
chByte = ((PBYTE)iter->lpData)[ullOffset - iter->ullStartOffsetMapped];
321+
pData = ((std::byte*)iter->lpData) + (ullOffset - iter->ullStartOffsetMapped);
323322
else
324323
{
325324
if (MapFileOffset(*iter, ullOffset) == S_OK)
326-
chByte = ((PBYTE)iter->lpData)[ullOffset - iter->ullStartOffsetMapped];
327-
else
328-
chByte = 0;
325+
pData = ((std::byte*)iter->lpData) + (ullOffset - iter->ullStartOffsetMapped);
329326
}
330327
}
331328

332-
return chByte;
329+
return pData;
333330
}

Pepper/ListEx/ListEx.h

Lines changed: 63 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************************
2-
* Copyright © 2018-2020 Jovibor https://github.com/jovibor/ *
2+
* Copyright © 2018-2020 Jovibor https://github.com/jovibor/ *
33
* This is very extended and featured version of CMFCListCtrl class. *
44
* Official git repository: https://github.com/jovibor/ListEx/ *
55
* This class is available under the "MIT License". *
@@ -8,54 +8,70 @@
88
#pragma once
99
#include <afxcontrolbars.h>
1010
#include <memory>
11+
#include <string>
1112

1213
namespace LISTEX
1314
{
1415
/********************************************************************************************
15-
* EnListExSortMode - Sorting mode. *
16+
* EListExSortMode - Sorting mode. *
1617
********************************************************************************************/
17-
enum class EnListExSortMode : short
18+
enum class EListExSortMode : WORD
1819
{
1920
SORT_LEX, SORT_NUMERIC
2021
};
2122

23+
/********************************************
24+
* LISTEXCELLCOLOR - colors for the cell. *
25+
********************************************/
26+
struct LISTEXCELLCOLOR
27+
{
28+
COLORREF clrBk { };
29+
COLORREF clrText { };
30+
};
31+
using PLISTEXCELLCOLOR = LISTEXCELLCOLOR*;
32+
2233
/********************************************************************************************
23-
* LISTEXCOLORSTRUCT - All ListEx colors. *
34+
* LISTEXCOLORS - All ListEx colors. *
2435
********************************************************************************************/
25-
struct LISTEXCOLORSTRUCT
36+
struct LISTEXCOLORS
2637
{
27-
COLORREF clrListText { GetSysColor(COLOR_WINDOWTEXT) }; //List text color.
28-
COLORREF clrListBkRow1 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the odd rows.
29-
COLORREF clrListBkRow2 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the even rows.
30-
COLORREF clrListGrid { RGB(220, 220, 220) }; //List grid color.
31-
COLORREF clrListTextSelected { GetSysColor(COLOR_HIGHLIGHTTEXT) }; //Selected item text color.
32-
COLORREF clrListBkSelected { GetSysColor(COLOR_HIGHLIGHT) }; //Selected item bk color.
33-
COLORREF clrTooltipText { GetSysColor(COLOR_INFOTEXT) }; //Tooltip window text color.
34-
COLORREF clrTooltipBk { GetSysColor(COLOR_INFOBK) }; //Tooltip window bk color.
35-
COLORREF clrListTextCellTt { GetSysColor(COLOR_WINDOWTEXT) }; //Text color of a cell that has tooltip.
36-
COLORREF clrListBkCellTt { RGB(170, 170, 230) }; //Bk color of a cell that has tooltip.
37-
COLORREF clrHdrText { GetSysColor(COLOR_WINDOWTEXT) }; //List header text color.
38-
COLORREF clrHdrBk { GetSysColor(COLOR_WINDOW) }; //List header bk color.
39-
COLORREF clrHdrHglInactive { GetSysColor(COLOR_GRADIENTINACTIVECAPTION) };//Header highlight inactive.
40-
COLORREF clrHdrHglActive { GetSysColor(COLOR_GRADIENTACTIVECAPTION) }; //Header highlight active.
41-
COLORREF clrBkNWA { GetSysColor(COLOR_WINDOW) }; //Bk of non working area.
38+
COLORREF clrListText { GetSysColor(COLOR_WINDOWTEXT) }; //List text color.
39+
COLORREF clrListTextLink { RGB(0, 0, 200) }; //List hyperlink text color.
40+
COLORREF clrListTextSel { GetSysColor(COLOR_HIGHLIGHTTEXT) }; //Selected item text color.
41+
COLORREF clrListTextLinkSel { RGB(250, 250, 250) }; //List hyperlink text color in selected cell.
42+
COLORREF clrListTextCellTt { GetSysColor(COLOR_WINDOWTEXT) }; //Text color of a cell that has tooltip.
43+
COLORREF clrListBkRow1 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the odd rows.
44+
COLORREF clrListBkRow2 { GetSysColor(COLOR_WINDOW) }; //List Bk color of the even rows.
45+
COLORREF clrListBkSel { GetSysColor(COLOR_HIGHLIGHT) }; //Selected item bk color.
46+
COLORREF clrListBkCellTt { RGB(170, 170, 230) }; //Bk color of a cell that has tooltip.
47+
COLORREF clrListGrid { RGB(220, 220, 220) }; //List grid color.
48+
COLORREF clrTooltipText { GetSysColor(COLOR_INFOTEXT) }; //Tooltip window text color.
49+
COLORREF clrTooltipBk { GetSysColor(COLOR_INFOBK) }; //Tooltip window bk color.
50+
COLORREF clrHdrText { GetSysColor(COLOR_WINDOWTEXT) }; //List header text color.
51+
COLORREF clrHdrBk { GetSysColor(COLOR_WINDOW) }; //List header bk color.
52+
COLORREF clrHdrHglInact { GetSysColor(COLOR_GRADIENTINACTIVECAPTION) };//Header highlight inactive.
53+
COLORREF clrHdrHglAct { GetSysColor(COLOR_GRADIENTACTIVECAPTION) }; //Header highlight active.
54+
COLORREF clrNWABk { GetSysColor(COLOR_WINDOW) }; //Bk of Non Working Area.
4255
};
4356

4457
/********************************************************************************************
4558
* LISTEXCREATESTRUCT - Main initialization helper struct for CListEx::Create method. *
4659
********************************************************************************************/
47-
struct LISTEXCREATESTRUCT {
48-
LISTEXCOLORSTRUCT stColor { }; //All control's colors.
49-
CRect rect; //Initial rect.
50-
CWnd* pwndParent { }; //Parent window.
51-
const LOGFONTW* pListLogFont { }; //List font.
52-
const LOGFONTW* pHdrLogFont { }; //Header font.
53-
DWORD dwStyle { }; //Control's styles. Zero for default.
54-
UINT uID { }; //Control Id.
55-
DWORD dwListGridWidth { 1 }; //Width of the list grid.
56-
DWORD dwHdrHeight { 20 }; //Header height.
57-
bool fSortable { false }; //Is list sortable, by clicking on the header column?
58-
bool fDialogCtrl { false }; //If it's a list within dialog.
60+
struct LISTEXCREATESTRUCT
61+
{
62+
LISTEXCOLORS stColor { }; //All control's colors.
63+
CRect rect; //Initial rect.
64+
CWnd* pParent { }; //Parent window.
65+
LOGFONTW* pListLogFont { }; //List font.
66+
LOGFONTW* pHdrLogFont { }; //Header font.
67+
UINT uID { }; //List control ID.
68+
DWORD dwStyle { }; //Control's styles. Zero for default.
69+
DWORD dwListGridWidth { 1 }; //Width of the list grid.
70+
DWORD dwHdrHeight { 20 }; //Header height.
71+
bool fDialogCtrl { false }; //If it's a list within dialog.
72+
bool fSortable { false }; //Is list sortable, by clicking on the header column?
73+
bool fLinkUnderline { true }; //Links are displayed underlined or not.
74+
bool fLinkTooltip { true }; //Show links' toolips.
5975
};
6076

6177
/********************************************
@@ -64,35 +80,35 @@ namespace LISTEX
6480
class IListEx : public CMFCListCtrl
6581
{
6682
public:
67-
IListEx() = default;
68-
virtual ~IListEx() = default;
6983
virtual bool Create(const LISTEXCREATESTRUCT& lcs) = 0;
7084
virtual void CreateDialogCtrl(UINT uCtrlID, CWnd* pwndDlg) = 0;
7185
virtual BOOL DeleteAllItems() = 0;
7286
virtual BOOL DeleteColumn(int nCol) = 0;
7387
virtual BOOL DeleteItem(int nItem) = 0;
7488
virtual void Destroy() = 0;
75-
virtual ULONGLONG GetCellData(int iItem, int iSubitem)const = 0;
76-
virtual EnListExSortMode GetColumnSortMode(int iColumn)const = 0;
77-
virtual UINT GetFontSize()const = 0;
78-
virtual int GetSortColumn()const = 0;
79-
virtual bool GetSortAscending()const = 0;
80-
virtual bool IsCreated()const = 0;
89+
[[nodiscard]] virtual ULONGLONG GetCellData(int iItem, int iSubitem)const = 0;
90+
[[nodiscard]] virtual LISTEXCOLORS GetColors()const = 0;
91+
[[nodiscard]] virtual EListExSortMode GetColumnSortMode(int iColumn)const = 0;
92+
[[nodiscard]] virtual UINT GetFontSize()const = 0;
93+
[[nodiscard]] virtual int GetSortColumn()const = 0;
94+
[[nodiscard]] virtual bool GetSortAscending()const = 0;
95+
[[nodiscard]] virtual bool IsCreated()const = 0;
8196
virtual void SetCellColor(int iItem, int iSubitem, COLORREF clrBk, COLORREF clrText = -1) = 0;
8297
virtual void SetCellData(int iItem, int iSubitem, ULONGLONG ullData) = 0;
8398
virtual void SetCellMenu(int iItem, int iSubitem, CMenu* pMenu) = 0;
84-
virtual void SetCellTooltip(int iItem, int iSubitem, const wchar_t* pwszTooltip, const wchar_t* pwszCaption = nullptr) = 0;
85-
virtual void SetColor(const LISTEXCOLORSTRUCT& lcs) = 0;
99+
virtual void SetCellTooltip(int iItem, int iSubitem, std::wstring_view wstrTooltip, std::wstring_view wstrCaption = L"") = 0;
100+
virtual void SetColors(const LISTEXCOLORS& lcs) = 0;
86101
virtual void SetColumnColor(int iColumn, COLORREF clrBk, COLORREF clrText = -1) = 0;
87-
virtual void SetColumnSortMode(int iColumn, EnListExSortMode enSortMode) = 0;
102+
virtual void SetColumnSortMode(int iColumn, EListExSortMode enSortMode) = 0;
88103
virtual void SetFont(const LOGFONTW* pLogFontNew) = 0;
89104
virtual void SetFontSize(UINT uiSize) = 0;
90105
virtual void SetHdrHeight(DWORD dwHeight) = 0;
91106
virtual void SetHdrFont(const LOGFONTW* pLogFontNew) = 0;
92107
virtual void SetHdrColumnColor(int iColumn, COLORREF clrBk, COLORREF clrText = -1) = 0;
93108
virtual void SetListMenu(CMenu* pMenu) = 0;
94109
virtual void SetRowColor(DWORD dwRow, COLORREF clrBk, COLORREF clrText = -1) = 0;
95-
virtual void SetSortable(bool fSortable, PFNLVCOMPARE pfnCompare = nullptr, EnListExSortMode enSortMode = EnListExSortMode::SORT_LEX) = 0;
110+
virtual void SetSortable(bool fSortable, PFNLVCOMPARE pfnCompare = nullptr,
111+
EListExSortMode enSortMode = EListExSortMode::SORT_LEX) = 0;
96112
};
97113

98114
/********************************************************************************************
@@ -120,5 +136,7 @@ namespace LISTEX
120136
* WM_NOTIFY codes (NMHDR.code values) *
121137
****************************************************************************/
122138

123-
constexpr auto LISTEX_MSG_MENUSELECTED = 0x1000u;
139+
constexpr auto LISTEX_MSG_MENUSELECTED = 0x1000U; //User defined menu item selected.
140+
constexpr auto LISTEX_MSG_CELLCOLOR = 0x1001U; //Get cell color.
141+
constexpr auto LISTEX_MSG_LINKCLICK = 0x1002U; //Hyperlink has been clicked.
124142
}

0 commit comments

Comments
 (0)