Skip to content

Commit 3119a8d

Browse files
committed
draw the tool tip text wrapped if the width would exceed the width of the BowPad window
closes #411
1 parent 238bf85 commit 3119a8d

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/CustomTooltip.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is part of BowPad.
22
//
3-
// Copyright (C) 2016-2018, 2020-2022 - Stefan Kueng
3+
// Copyright (C) 2016-2018, 2020-2022, 2025 - Stefan Kueng
44
//
55
// This program is free software: you can redistribute it and/or modify
66
// it under the terms of the GNU General Public License as published by
@@ -78,19 +78,21 @@ void CCustomToolTip::ShowTip(POINT screenPt, const std::wstring& text, COLORREF*
7878
auto dc = GetDC(*this);
7979
auto textBuf = std::make_unique<wchar_t[]>(m_infoText.size() + 4);
8080
wcscpy_s(textBuf.get(), m_infoText.size() + 4, m_infoText.c_str());
81+
RECT parentRc{};
82+
GetWindowRect(m_hWndFit, &parentRc);
8183
RECT rc{};
8284
rc.left = 0;
83-
rc.right = CDPIAware::Instance().Scale(*this, 800);
85+
rc.right = parentRc.right - parentRc.left - BORDER - BORDER;
8486
rc.top = 0;
85-
rc.bottom = CDPIAware::Instance().Scale(*this, 800);
87+
rc.bottom = parentRc.bottom - parentRc.top - BORDER - BORDER;
8688

8789
NONCLIENTMETRICS ncm{};
8890
ncm.cbSize = sizeof(NONCLIENTMETRICS);
8991
SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(NONCLIENTMETRICS), &ncm, 0U);
9092
m_hFont = CreateFontIndirect(&ncm.lfStatusFont);
9193

9294
auto oldFont = SelectObject(dc, m_hFont);
93-
DrawText(dc, textBuf.get(), static_cast<int>(m_infoText.size()), &rc, DT_LEFT | DT_TOP | DT_CALCRECT | DT_NOPREFIX | DT_EXPANDTABS | DT_NOCLIP);
95+
DrawText(dc, textBuf.get(), static_cast<int>(m_infoText.size()), &rc, DT_LEFT | DT_TOP | DT_CALCRECT | DT_NOPREFIX | DT_EXPANDTABS | DT_NOCLIP | DT_WORDBREAK);
9496
SelectObject(dc, oldFont);
9597

9698
if (m_bShowColorBox)
@@ -104,8 +106,6 @@ void CCustomToolTip::ShowTip(POINT screenPt, const std::wstring& text, COLORREF*
104106
wndPos.top = screenPt.y - rc.bottom - COLORBOX_SIZE + HOVERDISTANCE;
105107
wndPos.right = wndPos.left + rc.right + BORDER + BORDER;
106108
wndPos.bottom = wndPos.top + rc.bottom + BORDER + BORDER;
107-
RECT parentRc{};
108-
GetWindowRect(m_hWndFit, &parentRc);
109109
if (wndPos.left < parentRc.left)
110110
OffsetRect(&wndPos, parentRc.left - wndPos.left, 0);
111111
if (wndPos.top < parentRc.top)
@@ -162,7 +162,7 @@ void CCustomToolTip::OnPaint(HDC hdc, RECT* pRc)
162162
auto oldFont = SelectObject(hdc, m_hFont);
163163
auto textBuf = std::make_unique<wchar_t[]>(m_infoText.size() + 4);
164164
wcscpy_s(textBuf.get(), m_infoText.size() + 4, m_infoText.c_str());
165-
DrawText(hdc, textBuf.get(), -1, pRc, DT_LEFT | DT_TOP | DT_NOPREFIX | DT_EXPANDTABS | DT_NOCLIP);
165+
DrawText(hdc, textBuf.get(), -1, pRc, DT_LEFT | DT_TOP | DT_NOPREFIX | DT_EXPANDTABS | DT_NOCLIP | DT_WORDBREAK);
166166
if (m_bShowColorBox)
167167
{
168168
RECT clrTextRc = *pRc;

0 commit comments

Comments
 (0)