Skip to content

Commit

Permalink
simplified HoverText Option
Browse files Browse the repository at this point in the history
  • Loading branch information
daddel80 committed Dec 8, 2024
1 parent 6ee8c00 commit a91b668
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 40 deletions.
46 changes: 7 additions & 39 deletions src/MultiReplacePanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ void MultiReplace::initializeListView() {
columnSortOrder[ColumnID::FIND_TEXT] = SortDirection::Unsorted;
columnSortOrder[ColumnID::REPLACE_TEXT] = SortDirection::Unsorted;
columnSortOrder[ColumnID::COMMENTS] = SortDirection::Unsorted;

}

void MultiReplace::initializeDragAndDrop() {
Expand Down Expand Up @@ -2289,12 +2290,12 @@ LRESULT CALLBACK MultiReplace::ListViewSubclassProc(HWND hwnd, UINT msg, WPARAM
LVHITTESTINFO hitTestInfo = {};
hitTestInfo.pt = pt;

int hitResult = ListView_HitTest(hwnd, &hitTestInfo);
int hitResult = ListView_HitTest(hwnd, &hitTestInfo);
if (hitResult != -1) {

int currentRow = hitTestInfo.iItem;
int currentSubItem = hitTestInfo.iSubItem;

// Update only if the row, sub-item, or mouse position has significantly changed
if (currentRow != pThis->lastTooltipRow || currentSubItem != pThis->lastTooltipSubItem ||
abs(pt.x - pThis->lastMouseX) > 5 || abs(pt.y - pThis->lastMouseY) > 5) {

Expand All @@ -2303,21 +2304,12 @@ LRESULT CALLBACK MultiReplace::ListViewSubclassProc(HWND hwnd, UINT msg, WPARAM
pThis->lastMouseX = pt.x;
pThis->lastMouseY = pt.y;

RECT rect = {};
if (ListView_GetSubItemRect(hwnd, currentRow, currentSubItem, LVIR_LABEL, &rect)) {
const ReplaceItemData& itemData = pThis->replaceListData[currentRow];
const std::wstring& text = (currentSubItem == pThis->getColumnIndexFromID(ColumnID::FIND_TEXT)) ? itemData.findText :
(currentSubItem == pThis->getColumnIndexFromID(ColumnID::REPLACE_TEXT)) ? itemData.replaceText :
itemData.comments;

if (pThis->isTextTruncated(text, rect)) {
// Tooltip logic (e.g., create and display a custom tooltip)
}
}

// Temporarily disable LVS_EX_INFOTIP to force tooltip update
DWORD extendedStyle = ListView_GetExtendedListViewStyle(hwnd);
ListView_SetExtendedListViewStyle(hwnd, extendedStyle & ~LVS_EX_INFOTIP);
SetTimer(hwnd, 1, 10, NULL); // 10ms delay

// Set a timer to re-enable LVS_EX_INFOTIP after 10ms
SetTimer(hwnd, 1, 10, NULL);
}
}
break;
Expand All @@ -2343,30 +2335,6 @@ LRESULT CALLBACK MultiReplace::ListViewSubclassProc(HWND hwnd, UINT msg, WPARAM
return CallWindowProc(pThis->originalListViewProc, hwnd, msg, wParam, lParam);
}

bool MultiReplace::isTextTruncated(const std::wstring& text, RECT rect) {
int columnWidth = rect.right - rect.left;
HDC hdc = GetDC(_replaceListView);
if (!hdc) return false;

HFONT hFont = (HFONT)SendMessage(_replaceListView, WM_GETFONT, 0, 0);
HFONT hOldFont = nullptr;
if (hFont) {
hOldFont = (HFONT)SelectObject(hdc, hFont);
}

SIZE size = {};
if (!GetTextExtentPoint32W(hdc, text.c_str(), static_cast<int>(text.length()), &size)) {
size.cx = 0; // Default to 0 if text measurement fails
}

if (hOldFont) {
SelectObject(hdc, hOldFont);
}
ReleaseDC(_replaceListView, hdc);

return size.cx > columnWidth - 4;
}

void MultiReplace::createContextMenu(HWND hwnd, POINT ptScreen, MenuState state) {
HMENU hMenu = CreatePopupMenu();
if (hMenu) {
Expand Down
1 change: 0 additions & 1 deletion src/MultiReplacePanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,6 @@ class MultiReplace : public StaticDialog
ColumnID getColumnIDFromIndex(int columnIndex) const;
int getColumnIndexFromID(ColumnID columnID) const;
void updateListViewItem(size_t index);
bool isTextTruncated(const std::wstring& text, RECT rect);

//Contextmenu Display Columns
void showColumnVisibilityMenu(HWND hWnd, POINT pt);
Expand Down

0 comments on commit a91b668

Please sign in to comment.