Skip to content

Commit

Permalink
* MessageList layout fixes
Browse files Browse the repository at this point in the history
* Fix UB in ProfilePopout
  • Loading branch information
iProgramMC committed May 28, 2024
1 parent ecc5833 commit 2bc9647
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
32 changes: 14 additions & 18 deletions src/windows/MessageList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2490,7 +2490,7 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c
RECT embedRect = item.m_messageRect;
auto& embedVec = item.m_embedData;
size_t sz = embedVec.size();
if (isChainBegin && sz)
if (sz)
embedRect.bottom += ScaleByDPI(5);

embedRect.right = msgRect.right - ScaleByDPI(10);
Expand Down Expand Up @@ -2531,17 +2531,17 @@ void MessageList::DrawMessage(HDC hdc, MessageItem& item, RECT& msgRect, RECT& c

// draw available attachments, if any:
RECT attachRect = embedRect;
if (isChainBegin || sz != 0)
auto& attachVec = item.m_msg.m_attachments;
auto& attachItemVec = item.m_attachmentData;
sz = attachVec.size();
if (sz != 0)
attachRect.bottom += ScaleByDPI(5) + ATTACHMENT_GAP;

attachRect.right = msgRect.right - ScaleByDPI(10);
attachRect.top = attachRect.bottom;

if (bIsCompact) attachRect.left = rc.left;

auto& attachVec = item.m_msg.m_attachments;
auto& attachItemVec = item.m_attachmentData;
sz = attachVec.size();
for (size_t i = 0; i < sz; i++)
{
auto& attach = attachVec[i];
Expand Down Expand Up @@ -3683,19 +3683,15 @@ void MessageList::AdjustHeightInfo(const MessageItem& msg, int& height, int& tex
attachheight += inc;
}

if (isChainCont) {
if (embedheight != 0)
height -= ScaleByDPI(5);
else if (attachheight != 0)
height -= ATTACHMENT_GAP;
}
else {
// add some separators
if (attachheight != 0)
height += ScaleByDPI(5);
if (embedheight != 0)
height += ScaleByDPI(5);
}
if (embedheight != 0)
embedheight -= ScaleByDPI(5);
if (attachheight != 0)
attachheight -= ATTACHMENT_GAP;

if (attachheight != 0)
height += ScaleByDPI(5);
if (embedheight != 0)
height += ScaleByDPI(5);

if (!IsActionMessage(msg.m_msg.m_type) && !IsCompact() && !isChainCont && height < minHeight)
height = minHeight;
Expand Down
12 changes: 8 additions & 4 deletions src/windows/ProfilePopout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,8 @@ bool ProfileViewerLayout(HWND hWnd, SIZE& fullSize)
free(pronouns);
free(dscJoinedAt);
free(gldJoinedAt);

return FALSE;
}

static SIZE g_ProfilePopoutSize;
Expand Down Expand Up @@ -490,10 +492,12 @@ BOOL CALLBACK ProfileViewerProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lPar
case WM_INITDIALOG:
case WM_UPDATEPROFILEPOPOUT: {
g_ProfilePopoutSize = {};
ProfileViewerLayout(hWnd, g_ProfilePopoutSize);
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, g_ProfilePopoutSize.cx, g_ProfilePopoutSize.cy, SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOZORDER | SWP_NOMOVE);
InvalidateRect(hWnd, NULL, TRUE);
break;
BOOL res = ProfileViewerLayout(hWnd, g_ProfilePopoutSize);
if (!res) {
SetWindowPos(hWnd, HWND_NOTOPMOST, 0, 0, g_ProfilePopoutSize.cx, g_ProfilePopoutSize.cy, SWP_NOACTIVATE | SWP_NOREPOSITION | SWP_NOZORDER | SWP_NOMOVE);
InvalidateRect(hWnd, NULL, TRUE);
}
return res;
}

case WM_DESTROY:
Expand Down

0 comments on commit 2bc9647

Please sign in to comment.