From 720d774bfc0aa7941d1493a63291352f223aa61e Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 1 May 2024 14:07:01 +0300 Subject: CSplitter: fix to avoid problems caused by WM_SIZE optimization --- include/m_gui.h | 1 + plugins/TabSRMM/src/generic_msghandlers.cpp | 14 ++++++------- plugins/TabSRMM/src/infopanel.cpp | 2 +- plugins/TabSRMM/src/msgdialog.cpp | 26 +++++++++++------------ plugins/TabSRMM/src/msgdlgother.cpp | 18 ++++++++-------- src/mir_core/src/Windows/CDlgBase.cpp | 32 ++++++++++++++++++----------- src/mir_core/src/Windows/CSplitter.cpp | 4 ++-- 7 files changed, 53 insertions(+), 44 deletions(-) diff --git a/include/m_gui.h b/include/m_gui.h index 999db8899b..9f08d3d4f2 100644 --- a/include/m_gui.h +++ b/include/m_gui.h @@ -495,6 +495,7 @@ protected: bool m_bFixedSize; bool m_bSucceeded = false; // was IDOK pressed or not bool m_bExiting = false; // window received WM_CLOSE and gonna die soon + bool m_bScheduledResize = false; enum { CLOSE_ON_OK = 0x1, CLOSE_ON_CANCEL = 0x2 }; uint8_t m_autoClose; // automatically close dialog on IDOK/CANCEL commands. default: CLOSE_ON_OK|CLOSE_ON_CANCEL diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 4f965e728b..b2b14ad76b 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -253,7 +253,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara LoadSplitter(); AdjustBottomAvatarDisplay(); DM_RecalcPictureSize(); - OnResize(); + Resize(); break; case ID_MODE_PRIVATE: @@ -262,7 +262,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara LoadSplitter(); AdjustBottomAvatarDisplay(); DM_RecalcPictureSize(); - OnResize(); + Resize(); break; case ID_GLOBAL_BBCODE: @@ -365,7 +365,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara RedrawWindow(m_hwnd, nullptr, nullptr, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_ALLCHILDREN); } m_pContainer->QueryClientArea(rc); - OnResize(); + Resize(); DM_ScrollToBottom(1, 1); Utils::showDlgControl(m_hwnd, IDC_MULTISPLITTER, (m_sendMode & SMODE_MULTIPLE) ? SW_SHOW : SW_HIDE); Utils::showDlgControl(m_hwnd, IDC_CLIST, (m_sendMode & SMODE_MULTIPLE) ? SW_SHOW : SW_HIDE); @@ -390,7 +390,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara if (!m_bIsAutosizingInput) { m_iSplitterSaved = m_iSplitterY; m_iSplitterY = rc.bottom / 2; - OnResize(); + Resize(); } ptrW wszText(db_get_wsa(m_hContact, "UserInfo", "MyNotes")); @@ -404,7 +404,7 @@ LRESULT CMsgDialog::DM_MsgWindowCmdHandler(UINT cmd, WPARAM wParam, LPARAM lPara if (!m_bIsAutosizingInput) { m_iSplitterY = m_iSplitterSaved; - OnResize(); + Resize(); DM_ScrollToBottom(0, 1); } } @@ -617,7 +617,7 @@ void CMsgDialog::DM_RecalcPictureSize() BITMAP bminfo; GetObject(hbm, sizeof(bminfo), &bminfo); if (CalcDynamicAvatarSize(&bminfo)) - OnResize(); + Resize(); } else m_pic.cy = m_pic.cx = 60; } @@ -988,7 +988,7 @@ int CMsgDialog::DM_SplitterGlobalEvent(WPARAM wParam, LPARAM lParam) LoadSplitter(); AdjustBottomAvatarDisplay(); DM_RecalcPictureSize(); - OnResize(); + Resize(); DM_ScrollToBottom(1, 1); if (this != srcDat) UpdateToolbarBG(); diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index af11e3e1bc..4d2ed59efb 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -1204,7 +1204,7 @@ INT_PTR CALLBACK CInfoPanel::ConfigDlgProc(HWND hwnd, UINT msg, WPARAM wParam, L } if (m_height != lOldHeight) { - m_dat->OnResize(); + m_dat->Resize(); m_dat->m_pContainer->SetAeroMargins(); ::RedrawWindow(m_dat->GetHwnd(), nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); ::RedrawWindow(GetParent(m_dat->GetHwnd()), nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); diff --git a/plugins/TabSRMM/src/msgdialog.cpp b/plugins/TabSRMM/src/msgdialog.cpp index acc0cfc38c..7870fced95 100644 --- a/plugins/TabSRMM/src/msgdialog.cpp +++ b/plugins/TabSRMM/src/msgdialog.cpp @@ -147,7 +147,7 @@ void CMsgDialog::SetDialogToType() EnableSendButton(GetWindowTextLength(m_message.GetHwnd()) != 0); UpdateTitle(); - OnResize(); + Resize(); Utils::enableDlgControl(m_hwnd, IDC_CONTACTPIC, false); @@ -235,7 +235,7 @@ LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM ReleaseCapture(); dat->DM_ScrollToBottom(0, 1); if (!dat->isChat() && hwnd == GetDlgItem(hwndParent, IDC_PANELSPLITTER)) { - dat->OnResize(); + dat->Resize(); RedrawWindow(hwndParent, nullptr, nullptr, RDW_ALLCHILDREN | RDW_INVALIDATE | RDW_UPDATENOW); } else if (hwnd == GetDlgItem(hwndParent, IDC_SPLITTERY)) { @@ -298,7 +298,7 @@ LRESULT CALLBACK SplitterSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM dat->m_dynaSplitter = dat->m_savedDynaSplit; dat->DM_RecalcPictureSize(); dat->UpdateToolbarBG(); - dat->OnResize(); + dat->Resize(); dat->DM_ScrollToBottom(0, 1); break; } @@ -903,7 +903,7 @@ void CMsgDialog::onClick_Add(CCtrlButton*) ShowMultipleControls(m_hwnd, addControls, _countof(addControls), SW_HIDE); if (!m_bScrollingDisabled) Utils::showDlgControl(m_hwnd, IDC_LOGFROZENTEXT, SW_HIDE); - OnResize(); + Resize(); } } @@ -950,7 +950,7 @@ void CMsgDialog::onClick_CancelAdd(CCtrlButton*) ShowMultipleControls(m_hwnd, addControls, _countof(addControls), SW_HIDE); if (!m_bScrollingDisabled) Utils::showDlgControl(m_hwnd, IDC_LOGFROZENTEXT, SW_HIDE); - OnResize(); + Resize(); } void CMsgDialog::onClick_Filter(CCtrlButton *pButton) @@ -976,7 +976,7 @@ void CMsgDialog::onClick_ShowNickList(CCtrlButton *pButton) m_bNicklistEnabled = !m_bNicklistEnabled; - OnResize(); + Resize(); if (CSkin::m_skinEnabled) InvalidateRect(m_hwnd, nullptr, TRUE); m_pLog->ScrollToBottom(); @@ -1546,7 +1546,7 @@ int CMsgDialog::OnFilter(MSGFILTER *pFilter) HWND hwndEdit = m_message.GetHwnd(); SetWindowPos(hwndEdit, nullptr, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOSIZE | SWP_NOMOVE); - OnResize(); + Resize(); RedrawWindow(hwndEdit, nullptr, nullptr, RDW_INVALIDATE | RDW_FRAME | RDW_UPDATENOW | RDW_ERASE); DM_ScrollToBottom(0, 0); Utils::showDlgControl(m_hwnd, IDC_MULTISPLITTER, (m_sendMode & SMODE_MULTIPLE) ? SW_SHOW : SW_HIDE); @@ -1646,7 +1646,7 @@ int CMsgDialog::OnFilter(MSGFILTER *pFilter) SetDlgItemText(m_hwnd, IDC_LOGFROZENTEXT, TranslateT("Contact not on list. You may add it...")); else SetDlgItemText(m_hwnd, IDC_LOGFROZENTEXT, TranslateT("Auto scrolling is disabled (press F12 to enable it)")); - OnResize(); + Resize(); DM_ScrollToBottom(1, 1); return _dlgReturn(m_hwnd, 1); } @@ -2315,7 +2315,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) GetSendFormat(); SetDialogToType(); DM_RecalcPictureSize(); - OnResize(); + Resize(); DM_ScrollToBottom(0, 1); } return 0; @@ -2364,7 +2364,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) case DM_UPDATEPICLAYOUT: if (wParam == 0 || wParam == m_hContact) { LoadContactAvatar(); - OnResize(); + Resize(); } return 0; @@ -2429,7 +2429,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) MoveWindow(m_hwnd, rcClient.left, rcClient.top, (rcClient.right - rcClient.left), (rcClient.bottom - rcClient.top), TRUE); if (m_bWasBackgroundCreate) { m_bWasBackgroundCreate = false; - OnResize(); + Resize(); PostMessage(m_hwnd, DM_UPDATEPICLAYOUT, 0, 0); SetFocus(m_message.GetHwnd()); @@ -2437,7 +2437,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) m_pContainer->m_pSideBar->moveButtons(); } else { - OnResize(); + Resize(); if (lParam == 0) DM_ScrollToBottom(0, 1); } @@ -2730,7 +2730,7 @@ INT_PTR CMsgDialog::DlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam) m_pPanel.setHeight((LONG)lParam); } } - OnResize(); + Resize(); } return 0; diff --git a/plugins/TabSRMM/src/msgdlgother.cpp b/plugins/TabSRMM/src/msgdlgother.cpp index a296b2f32b..61ecf25175 100644 --- a/plugins/TabSRMM/src/msgdlgother.cpp +++ b/plugins/TabSRMM/src/msgdlgother.cpp @@ -1355,7 +1355,7 @@ void CMsgDialog::LoadContactAvatar() if (!m_pPanel.isActive() || m_pContainer->cfg.avatarMode == 3) { m_iRealAvatarHeight = 0; - OnResize(); + Resize(); } else if (m_pPanel.isActive()) GetAvatarVisibility(); @@ -1385,7 +1385,7 @@ void CMsgDialog::LoadOwnAvatar() BITMAP bm; GetObject(m_hOwnPic, sizeof(bm), &bm); if (CalcDynamicAvatarSize(&bm)) - OnResize(); + Resize(); } } @@ -1703,7 +1703,7 @@ int CMsgDialog::MsgWindowMenuHandler(int selection, int menuId) } ShowPicture(false); - OnResize(); + Resize(); DM_ScrollToBottom(0, 1); return 1; @@ -2059,7 +2059,7 @@ void CMsgDialog::ShowPicture(bool showNewPic) if (!m_hwndPanelPic) { InvalidateRect(m_hwnd, nullptr, TRUE); UpdateWindow(m_hwnd); - OnResize(); + Resize(); } return; } @@ -2077,7 +2077,7 @@ void CMsgDialog::ShowPicture(bool showNewPic) if (!showNewPic) SetDialogToType(); else - OnResize(); + Resize(); } ///////////////////////////////////////////////////////////////////////////////////////// @@ -2167,7 +2167,7 @@ void CMsgDialog::ShowPopupMenu(const CCtrlBase &pCtrl, POINT pt) PluginConfig.m_visualMessageSizeIndicator = !PluginConfig.m_visualMessageSizeIndicator; db_set_b(0, SRMSGMOD_T, "msgsizebar", (uint8_t)PluginConfig.m_visualMessageSizeIndicator); Srmm_Broadcast(DM_CONFIGURETOOLBAR, 0, 0); - OnResize(); + Resize(); if (m_pContainer->m_hwndStatus) RedrawWindow(m_pContainer->m_hwndStatus, nullptr, nullptr, RDW_INVALIDATE | RDW_UPDATENOW); break; @@ -2201,7 +2201,7 @@ void CMsgDialog::SplitterMoved(int coord, HWND hwnd) if (m_iMultiSplit > ((rc.right - rc.left) - 80)) m_iMultiSplit = oldSplitterX; } - OnResize(); + Resize(); break; case IDC_SPLITTERX: @@ -2216,7 +2216,7 @@ void CMsgDialog::SplitterMoved(int coord, HWND hwnd) iSplitterX = rc.right - rc.left - 35; m_pContainer->cfg.iSplitterX = iSplitterX; } - OnResize(); + Resize(); break; case IDC_SPLITTERY: @@ -2253,7 +2253,7 @@ void CMsgDialog::SplitterMoved(int coord, HWND hwnd) } } UpdateToolbarBG(); - OnResize(); + Resize(); break; case IDC_PANELSPLITTER: diff --git a/src/mir_core/src/Windows/CDlgBase.cpp b/src/mir_core/src/Windows/CDlgBase.cpp index d4a22ca021..b0f184acf3 100644 --- a/src/mir_core/src/Windows/CDlgBase.cpp +++ b/src/mir_core/src/Windows/CDlgBase.cpp @@ -144,7 +144,8 @@ void CDlgBase::NotifyChange(void) void CDlgBase::Resize() { - SendMessage(m_hwnd, WM_SIZE, 0, 0); + m_bScheduledResize = true; + PostMessageW(m_hwnd, WM_SIZE, 0, 0); } void CDlgBase::SetCaption(const wchar_t *ptszCaption) @@ -401,18 +402,25 @@ INT_PTR CDlgBase::DlgProc(UINT msg, WPARAM wParam, LPARAM lParam) break; case WM_SIZE: - RECT rc; - if (lParam == 0) - GetClientRect(m_hwnd, &rc); - else { - rc.left = rc.top = 0; - rc.right = GET_X_LPARAM(lParam); - rc.left = GET_Y_LPARAM(lParam); - } - - if (memcmp(&m_rcPrev, &rc, sizeof(RECT))) { + if (m_bScheduledResize) { + m_bScheduledResize = false; OnResize(); - m_rcPrev = rc; + GetClientRect(m_hwnd, &m_rcPrev); + } + else { + RECT rc; + if (lParam == 0) + GetClientRect(m_hwnd, &rc); + else { + rc.left = rc.top = 0; + rc.right = GET_X_LPARAM(lParam); + rc.left = GET_Y_LPARAM(lParam); + } + + if (memcmp(&m_rcPrev, &rc, sizeof(RECT))) { + OnResize(); + m_rcPrev = rc; + } } return TRUE; diff --git a/src/mir_core/src/Windows/CSplitter.cpp b/src/mir_core/src/Windows/CSplitter.cpp index d224e602ad..fc8ee7e561 100644 --- a/src/mir_core/src/Windows/CSplitter.cpp +++ b/src/mir_core/src/Windows/CSplitter.cpp @@ -69,13 +69,13 @@ LRESULT CSplitter::CustomWndProc(UINT msg, WPARAM wParam, LPARAM lParam) } OnChange(this); - PostMessage(m_parentWnd->GetHwnd(), WM_SIZE, 0, 0); + m_parentWnd->Resize(); } return 0; case WM_LBUTTONUP: ReleaseCapture(); - PostMessage(m_parentWnd->GetHwnd(), WM_SIZE, 0, 0); + m_parentWnd->Resize(); return 0; } -- cgit v1.2.3