Skip to content

Commit

Permalink
[Fixes] List column names centering in CViewRightBL.
Browse files Browse the repository at this point in the history
Latest HexCtrl.
  • Loading branch information
jovibor committed Mar 6, 2021
1 parent 3069914 commit 46af190
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 61 deletions.
2 changes: 1 addition & 1 deletion Pepper/ListEx/ListEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ namespace LISTEX
********************************************/
struct LISTEXHDRICON
{
POINT pt { }; //Point of the top-left corner.
POINT pt { }; //Coords of the icon's top-left corner in the header item's rect.
int iIndex { }; //Icon index in the header's image list.
bool fClickable { true }; //Is icon sending LISTEX_MSG_HDRICONCLICK message when clicked.
};
Expand Down
45 changes: 36 additions & 9 deletions Pepper/ListEx/src/CListEx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,35 @@ bool CListEx::Create(const LISTEXCREATESTRUCT& lcs)
if (!m_stWndTtCell.CreateEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, TTS_BALLOON | TTS_NOANIMATE | TTS_NOFADE | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr))
return false;

SetWindowTheme(m_stWndTtCell, nullptr, L""); //To prevent Windows from changing theme of Balloon window.

m_stTInfoCell.cbSize = TTTOOLINFOW_V1_SIZE;
m_stTInfoCell.uFlags = TTF_TRACK;
m_stTInfoCell.uId = 0x1;
m_stTInfoCell.uId = 0x01;
m_stWndTtCell.SendMessageW(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&m_stTInfoCell));
m_stWndTtCell.SendMessageW(TTM_SETMAXTIPWIDTH, 0, static_cast<LPARAM>(400)); //to allow use of newline \n.
m_stWndTtCell.SendMessageW(TTM_SETTIPTEXTCOLOR, static_cast<WPARAM>(m_stColors.clrTooltipText), 0);
m_stWndTtCell.SendMessageW(TTM_SETTIPBKCOLOR, static_cast<WPARAM>(m_stColors.clrTooltipBk), 0);

if (!m_stWndTtLink.CreateEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, TTS_NOANIMATE | TTS_NOFADE | TTS_NOPREFIX | TTS_ALWAYSTIP,
if (!m_stWndTtLink.CreateEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, nullptr, nullptr))
return false;

m_stTInfoLink.cbSize = TTTOOLINFOW_V1_SIZE;
m_stTInfoLink.uFlags = TTF_TRACK;
m_stTInfoLink.uId = 0x2;
m_stTInfoLink.uId = 0x02;
m_stWndTtLink.SendMessageW(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&m_stTInfoLink));
m_stWndTtLink.SendMessageW(TTM_SETMAXTIPWIDTH, 0, static_cast<LPARAM>(400)); //to allow use of newline \n.

if (m_fHighLatency) //Tooltip for HighLatency mode.
{
if (!m_stWndTtRow.CreateEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, nullptr, TTS_NOANIMATE | TTS_NOFADE | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, m_hWnd, nullptr))
return false;
m_stToolInfoRow.cbSize = TTTOOLINFOW_V1_SIZE;
m_stToolInfoRow.uFlags = TTF_TRACK;
m_stToolInfoRow.uId = 0x03;
m_stWndTtRow.SendMessageW(TTM_ADDTOOL, 0, reinterpret_cast<LPARAM>(&m_stToolInfoRow));
}

m_dwGridWidth = lcs.dwListGridWidth;

LOGFONTW lf;
Expand Down Expand Up @@ -957,6 +965,22 @@ void CListEx::TtCellHide()
KillTimer(ID_TIMER_TT_CELL_CHECK);
}

void CListEx::TtRowShow(bool fShow, UINT uRow)
{
if (fShow)
{
CPoint ptScreen;
GetCursorPos(&ptScreen);

static wchar_t warrOffset[32] { L"Row: " };
swprintf_s(&warrOffset[5], 24, L"%u", uRow);
m_stToolInfoRow.lpszText = warrOffset;
m_stWndTtRow.SendMessageW(TTM_TRACKPOSITION, 0, static_cast<LPARAM>(MAKELONG(ptScreen.x - 5, ptScreen.y - 20)));
m_stWndTtRow.SendMessageW(TTM_UPDATETIPTEXT, 0, reinterpret_cast<LPARAM>(&m_stToolInfoRow));
}
m_stWndTtRow.SendMessageW(TTM_TRACKACTIVATE, static_cast<WPARAM>(fShow), reinterpret_cast<LPARAM>(&m_stToolInfoRow));
}

void CListEx::MeasureItem(LPMEASUREITEMSTRUCT lpMIS)
{
//Set row height according to current font's height.
Expand Down Expand Up @@ -1298,7 +1322,7 @@ void CListEx::OnPaint()
DefWindowProcW(WM_PAINT, reinterpret_cast<WPARAM>(rDC.m_hDC), static_cast<LPARAM>(0));
}

void CListEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
void CListEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (m_fVirtual && m_fHighLatency)
{
Expand All @@ -1317,6 +1341,7 @@ void CListEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
Scroll(size);
flag = false;
}
TtRowShow(false, 0);
CMFCListCtrl::OnVScroll(nSBCode, nPos, pScrollBar);
}
else
Expand All @@ -1327,6 +1352,7 @@ void CListEx::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar * pScrollBar)
si.fMask = SIF_ALL;
GetScrollInfo(SB_VERT, &si);
uItem = si.nTrackPos; //si.nTrackPos is in fact a row number.
TtRowShow(true, uItem);
}
}
else
Expand Down Expand Up @@ -1374,8 +1400,8 @@ BOOL CListEx::OnNotify(WPARAM wParam, LPARAM lParam, LRESULT * pResult)
void CListEx::OnLvnColumnClick(NMHDR* /*pNMHDR*/, LRESULT* /*pResult*/)
{
/*******************************************************************************
* Just an empty handler.
* Without it all works fine, but assert triggers in Debug mode, when clicking
* Just an empty handler.
* Without it all works fine, but assert triggers in Debug mode, when clicking
* on header, if list is in Virtual mode (LVS_OWNERDATA).
* ASSERT((GetStyle() & LVS_OWNERDATA)==0)
*******************************************************************************/
Expand All @@ -1401,6 +1427,7 @@ void CListEx::OnDestroy()

m_stWndTtCell.DestroyWindow();
m_stWndTtLink.DestroyWindow();
m_stWndTtRow.DestroyWindow();
m_fontList.DeleteObject();
m_fontListUnderline.DeleteObject();
m_penGrid.DeleteObject();
Expand Down
9 changes: 6 additions & 3 deletions Pepper/ListEx/src/CListEx.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace LISTEX::INTERNAL
[[nodiscard]] int GetSortColumn()const override;
[[nodiscard]] bool GetSortAscending()const override;
void HideColumn(int iIndex, bool fHide)override;
int InsertColumn(int nCol, const LVCOLUMN* pColumn);
int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1);
int InsertColumn(int nCol, const LVCOLUMN* pColumn)override;
int InsertColumn(int nCol, LPCTSTR lpszColumnHeading, int nFormat = LVCFMT_LEFT, int nWidth = -1, int nSubItem = -1)override;
[[nodiscard]] bool IsCreated()const override;
[[nodiscard]] bool IsColumnSortable(int iColumn)override;
void ResetSort()override; //Reset all the sort by any column to its default state.
Expand Down Expand Up @@ -66,6 +66,7 @@ namespace LISTEX::INTERNAL
auto ParseItemText(int iItem, int iSubitem)->std::vector<SITEMDATA>;
void TtLinkHide();
void TtCellHide();
void TtRowShow(bool fShow, UINT uRow); //Tooltips for HighLatency mode.
void DrawItem(LPDRAWITEMSTRUCT pDIS)override;
afx_msg void OnPaint();
afx_msg BOOL OnEraseBkgnd(CDC* pDC);
Expand Down Expand Up @@ -95,6 +96,8 @@ namespace LISTEX::INTERNAL
TTTOOLINFOW m_stTInfoCell { }; //Cells' tool-tip info struct.
CWnd m_stWndTtLink; //Link tool-tip window.
TTTOOLINFOW m_stTInfoLink { }; //Link's tool-tip info struct.
CWnd m_stWndTtRow { }; //Tooltip window for row in m_fHighLatency mode.
TTTOOLINFOW m_stToolInfoRow { };//Tooltips struct.
std::wstring m_wstrTtText { }; //Link's tool-tip current text.
HCURSOR m_cursorHand { }; //Hand cursor handle.
HCURSOR m_cursorDefault { }; //Standard (default) cursor handle.
Expand All @@ -105,6 +108,7 @@ namespace LISTEX::INTERNAL
long m_lSizeFont { }; //Font size.
PFNLVCOMPARE m_pfnCompare { nullptr }; //Pointer to user provided compare func.
EListExSortMode m_enDefSortMode { EListExSortMode::SORT_LEX }; //Default sorting mode.
CRect m_rcLinkCurr { }; //Current link's rect;
std::unordered_map<int, std::unordered_map<int, LISTEXTOOLTIP>> m_umapCellTt { }; //Cell's tooltips.
std::unordered_map<int, std::unordered_map<int, ULONGLONG>> m_umapCellData { }; //Cell's custom data.
std::unordered_map<int, std::unordered_map<int, LISTEXCOLOR>> m_umapCellColor { }; //Cell's colors.
Expand All @@ -122,7 +126,6 @@ namespace LISTEX::INTERNAL
bool m_fTtCellShown { false }; //Is cell's tool-tip shown atm.
bool m_fTtLinkShown { false }; //Is link's tool-tip shown atm.
bool m_fLDownAtLink { false }; //Left mouse down on link.
CRect m_rcLinkCurr { }; //Current link's rect;
};

/*******************Setting a manifest for ComCtl32.dll version 6.***********************/
Expand Down
2 changes: 1 addition & 1 deletion Pepper/Pepper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ BOOL CAboutDlg::OnInitDialog()
std::wstring wstrlibpeVer = L"libpe - PE/PE+ binaries library v";
wstrlibpeVer += libpeInfo()->pwszVersion;
GetDlgItem(IDC_LINK_LIBPE)->SetWindowTextW(wstrlibpeVer.data());
wstrlibpeVer = L"HexCtrl - Hex Control for MFC/Win32 v";
wstrlibpeVer = L"HexCtrl - ";
wstrlibpeVer += GetHexCtrlInfo()->pwszVersion;
GetDlgItem(IDC_LINK_HEXCTRL)->SetWindowTextW(wstrlibpeVer.data());

Expand Down
18 changes: 9 additions & 9 deletions Pepper/ViewRightBL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,10 @@ int CViewRightBL::CreateListImportEntry(DWORD dwEntry)
LVCOLUMNW stCol { LVCF_FMT, LVCFMT_CENTER };
m_listImportEntry->SetColumn(0, &stCol);
m_listImportEntry->SetHdrColumnColor(0, g_clrOffset);
m_listImportEntry->InsertColumn(1, L"Function Name", 0, 175);
m_listImportEntry->InsertColumn(2, L"Ordinal / Hint", 0, 100);
m_listImportEntry->InsertColumn(3, L"AddressOfData", 0, 150);
m_listImportEntry->InsertColumn(4, L"Thunk RVA", 0, 150);
m_listImportEntry->InsertColumn(1, L"Function Name", LVCFMT_CENTER, 175);
m_listImportEntry->InsertColumn(2, L"Ordinal / Hint", LVCFMT_CENTER, 100);
m_listImportEntry->InsertColumn(3, L"AddressOfData", LVCFMT_CENTER, 150);
m_listImportEntry->InsertColumn(4, L"Thunk RVA", LVCFMT_CENTER, 150);
}
else
m_listImportEntry->DeleteAllItems();
Expand Down Expand Up @@ -585,12 +585,12 @@ int CViewRightBL::CreateListDelayImportEntry(DWORD dwEntry)
LVCOLUMNW stCol { LVCF_FMT, LVCFMT_CENTER };
m_listDelayImportEntry->SetColumn(0, &stCol);
m_listDelayImportEntry->SetHdrColumnColor(0, g_clrOffset);
m_listDelayImportEntry->InsertColumn(1, L"Function Name", 0, 300);
m_listDelayImportEntry->InsertColumn(2, L"Ordinal / Hint", 0, 100);
m_listDelayImportEntry->InsertColumn(1, L"Function Name", LVCFMT_CENTER, 300);
m_listDelayImportEntry->InsertColumn(2, L"Ordinal / Hint", LVCFMT_CENTER, 100);
m_listDelayImportEntry->InsertColumn(3, L"ImportNameTable AddresOfData", 0, 220);
m_listDelayImportEntry->InsertColumn(4, L"IAT AddresOfData", 0, 200);
m_listDelayImportEntry->InsertColumn(5, L"BoundIAT AddresOfData", 0, 230);
m_listDelayImportEntry->InsertColumn(6, L"UnloadInfoTable AddresOfData", 0, 240);
m_listDelayImportEntry->InsertColumn(4, L"IAT AddresOfData", LVCFMT_CENTER, 200);
m_listDelayImportEntry->InsertColumn(5, L"BoundIAT AddresOfData", LVCFMT_CENTER, 230);
m_listDelayImportEntry->InsertColumn(6, L"UnloadInfoTable AddresOfData", LVCFMT_CENTER, 240);
}
else
m_listDelayImportEntry->DeleteAllItems();
Expand Down
7 changes: 4 additions & 3 deletions Pepper/include/HexCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,15 @@ namespace HEXCTRL
[[nodiscard]] virtual auto GetDataSize()const->ULONGLONG = 0; //Get currently set data size.
[[nodiscard]] virtual int GetEncoding()const = 0; //Get current code page ID.
[[nodiscard]] virtual long GetFontSize()const = 0; //Current font size.
[[nodiscard]] virtual auto GetGroupMode()const->EHexGroupMode = 0; //Retrieves current data grouping mode.
[[nodiscard]] virtual auto GetGroupMode()const->EHexDataSize = 0; //Retrieves current data grouping mode.
[[nodiscard]] virtual HMENU GetMenuHandle()const = 0; //Context menu handle.
[[nodiscard]] virtual auto GetPagesCount()const->ULONGLONG = 0; //Get count of pages.
[[nodiscard]] virtual auto GetPagePos()const->ULONGLONG = 0; //Get current page a cursor stays at.
[[nodiscard]] virtual DWORD GetPageSize()const = 0; //Current page size.
[[nodiscard]] virtual auto GetSelection()const->std::vector<HEXSPANSTRUCT> = 0; //Gets current selection.
[[nodiscard]] virtual auto GetSelection()const->std::vector<HEXSPANSTRUCT> = 0; //Get current selection.
[[nodiscard]] virtual HWND GetWindowHandle(EHexWnd enWnd)const = 0; //Retrieves control's window/dialog handle.
virtual void GoToOffset(ULONGLONG ullOffset, int iRelPos = 0) = 0; //Go (scroll) to a given offset.
[[nodiscard]] virtual bool HasSelection()const = 0; //Does currently have any selection or not.
[[nodiscard]] virtual auto HitTest(POINT pt, bool fScreen = true)const->std::optional<HEXHITTESTSTRUCT> = 0; //HitTest given point.
[[nodiscard]] virtual bool IsCmdAvail(EHexCmd enCmd)const = 0; //Is given Cmd currently available (can be executed)?
[[nodiscard]] virtual bool IsCreated()const = 0; //Shows whether control is created or not.
Expand All @@ -88,7 +89,7 @@ namespace HEXCTRL
virtual void SetEncoding(int iCodePage) = 0; //Code-page for text area.
virtual void SetFont(const LOGFONTW* pLogFont) = 0; //Set the control's new font. This font has to be monospaced.
virtual void SetFontSize(UINT uiSize) = 0; //Set the control's font size.
virtual void SetGroupMode(EHexGroupMode enMode) = 0; //Set current "Group Data By" mode.
virtual void SetGroupMode(EHexDataSize enMode) = 0; //Set current "Group Data By" mode.
virtual void SetMutable(bool fEnable) = 0; //Enable or disable mutable/editable mode.
virtual void SetOffsetMode(bool fHex) = 0; //Set offset being shown as Hex or as Decimal.
virtual void SetPageSize(DWORD dwSize, std::wstring_view wstrName = L"Page") = 0; //Set page size and name to draw the lines in-between.
Expand Down
Loading

0 comments on commit 46af190

Please sign in to comment.