From: <sv...@op...> - 2024-12-10 17:34:27
|
Author: sagamusix Date: Tue Dec 10 18:34:12 2024 New Revision: 22506 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22506 Log: [Fix] Moving the OpenMPT window to a screen with different size didn't adjust the frame size of MDI children. [Ref] Small general improvements to CChildFrame code. Modified: trunk/OpenMPT/mptrack/Childfrm.cpp trunk/OpenMPT/mptrack/Childfrm.h trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Moddoc.cpp Modified: trunk/OpenMPT/mptrack/Childfrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Childfrm.cpp Tue Dec 10 18:23:59 2024 (r22505) +++ trunk/OpenMPT/mptrack/Childfrm.cpp Tue Dec 10 18:34:12 2024 (r22506) @@ -61,10 +61,6 @@ CChildFrame::CChildFrame() { - m_bInitialActivation=true; //rewbs.fix3185 - m_szCurrentViewClassName[0] = 0; - m_hWndCtrl = m_hWndView = nullptr; - m_bMaxWhenClosed = false; glMdiOpenCount++; } @@ -73,7 +69,7 @@ { if ((--glMdiOpenCount) == 0) { - TrackerSettings::Instance().gbMdiMaximize = m_bMaxWhenClosed; + TrackerSettings::Instance().gbMdiMaximize = m_maxWhenClosed; } } @@ -96,6 +92,8 @@ pModView->SetMDIParentFrame(m_hWnd); } + m_dpi = HighDPISupport::GetDpiForWindow(m_hWnd); + const BOOL bStatus = ChangeViewClass(RUNTIME_CLASS(CViewGlobals), pContext); // If it all worked, we now have a splitter window which contain two different views @@ -122,6 +120,18 @@ m_wndSplitter.RecalcLayout(); } } + const int newDPI = HighDPISupport::GetDpiForWindow(m_hWnd); + if(m_dpi) + { + // MDI child windows are not resized automatically on DPI change. + CRect windowRect; + GetClientRect(windowRect); + windowRect.right = Util::muldiv(windowRect.right, newDPI, m_dpi); + windowRect.bottom = Util::muldiv(windowRect.bottom, newDPI, m_dpi); + HighDPISupport::AdjustWindowRectEx(windowRect, GetStyle(), FALSE, GetExStyle(), newDPI); + SetWindowPos(nullptr, 0, 0, windowRect.Width(), windowRect.Height(), SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE); + } + m_dpi = newDPI; return result; } @@ -190,11 +200,11 @@ if (pView) pModDoc = (CModDoc *)pView->GetDocument(); if ((m_hWndCtrl) && (pModDoc)) { - if (m_bInitialActivation && m_ViewPatterns.nPattern == 0) + if (m_initialActivation && m_ViewPatterns.nPattern == 0) { if(!pModDoc->GetSoundFile().Order().empty()) m_ViewPatterns.nPattern = pModDoc->GetSoundFile().Order()[0]; - m_bInitialActivation = false; + m_initialActivation = false; } } } @@ -234,10 +244,10 @@ { CMainFrame *pMainFrm = CMainFrame::GetMainFrame(); CWnd *pWnd; - if (!strcmp(pViewClass->m_lpszClassName, m_szCurrentViewClassName)) return TRUE; - if (m_szCurrentViewClassName[0]) + if (pViewClass->m_lpszClassName == m_currentViewClassName) return TRUE; + if(!m_currentViewClassName.empty()) { - m_szCurrentViewClassName[0] = 0; + m_currentViewClassName.clear(); m_wndSplitter.DeleteView(1, 0); } if ((m_hWndView) && (pMainFrm)) @@ -251,7 +261,7 @@ if (!m_wndSplitter.CreateView(1, 0, pViewClass, CSize(0, 0), pContext)) return FALSE; // Get 2nd window handle if ((pWnd = m_wndSplitter.GetPane(1, 0)) != NULL) m_hWndView = pWnd->m_hWnd; - strcpy(m_szCurrentViewClassName, pViewClass->m_lpszClassName); + m_currentViewClassName = pViewClass->m_lpszClassName; m_wndSplitter.RecalcLayout(); if ((m_hWndView) && (m_hWndCtrl)) { @@ -273,12 +283,13 @@ return; } -void CChildFrame::SavePosition(BOOL bForce) +void CChildFrame::SavePosition(bool force) { if (m_hWnd) { - m_bMaxWhenClosed = IsZoomed() != FALSE; - if (bForce) TrackerSettings::Instance().gbMdiMaximize = m_bMaxWhenClosed; + m_maxWhenClosed = IsZoomed() != FALSE; + if (force) + TrackerSettings::Instance().gbMdiMaximize = m_maxWhenClosed; if (!IsIconic()) { CWnd *pWnd = m_wndSplitter.GetPane(0, 0); @@ -290,15 +301,15 @@ return; int l = HighDPISupport::ScalePixelsInv(rect.Height(), m_hWnd); //rewbs.varWindowSize - not the nicest piece of code, but we need to distinguish between the views: - if (strcmp(CViewGlobals::classCViewGlobals.m_lpszClassName, m_szCurrentViewClassName) == 0) + if(CViewGlobals::classCViewGlobals.m_lpszClassName == m_currentViewClassName) TrackerSettings::Instance().glGeneralWindowHeight = l; - else if (strcmp(CViewPattern::classCViewPattern.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewPattern::classCViewPattern.m_lpszClassName == m_currentViewClassName) TrackerSettings::Instance().glPatternWindowHeight = l; - else if (strcmp(CViewSample::classCViewSample.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewSample::classCViewSample.m_lpszClassName == m_currentViewClassName) TrackerSettings::Instance().glSampleWindowHeight = l; - else if (strcmp(CViewInstrument::classCViewInstrument.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewInstrument::classCViewInstrument.m_lpszClassName == m_currentViewClassName) TrackerSettings::Instance().glInstrumentWindowHeight = l; - else if (strcmp(CViewComments::classCViewComments.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewComments::classCViewComments.m_lpszClassName == m_currentViewClassName) TrackerSettings::Instance().glCommentsWindowHeight = l; } } @@ -390,24 +401,24 @@ } -const char *CChildFrame::GetCurrentViewClassName() const +bool CChildFrame::IsPatternView() const { - return m_szCurrentViewClassName; + return CViewPattern::classCViewPattern.m_lpszClassName == m_currentViewClassName; } void CChildFrame::SaveAllViewStates() { void *ptr = nullptr; - if(strcmp(CViewPattern::classCViewPattern.m_lpszClassName, m_szCurrentViewClassName) == 0) + if(CViewPattern::classCViewPattern.m_lpszClassName == m_currentViewClassName) ptr = &m_ViewPatterns; - else if(strcmp(CViewSample::classCViewSample.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewSample::classCViewSample.m_lpszClassName == m_currentViewClassName) ptr = &m_ViewSamples; - else if(strcmp(CViewInstrument::classCViewInstrument.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewInstrument::classCViewInstrument.m_lpszClassName == m_currentViewClassName) ptr = &m_ViewInstruments; - else if(strcmp(CViewGlobals::classCViewGlobals.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewGlobals::classCViewGlobals.m_lpszClassName == m_currentViewClassName) ptr = &m_ViewGeneral; - else if(strcmp(CViewComments::classCViewComments.m_lpszClassName, m_szCurrentViewClassName) == 0) + else if(CViewComments::classCViewComments.m_lpszClassName == m_currentViewClassName) ptr = &m_ViewComments; ::SendMessage(m_hWndView, WM_MOD_VIEWMSG, VIEWMSG_SAVESTATE, reinterpret_cast<LPARAM>(ptr)); } @@ -440,63 +451,64 @@ void CChildFrame::DeserializeView(FileReader &file) { uint32 version, page; - if(file.ReadVarInt(version) && version < 2 && - file.ReadVarInt(page) && page >= 0 && static_cast<CModControlView::Page>(page) < CModControlView::Page::NumPages) - { - UINT pageDlg = 0; + if(!file.ReadVarInt(version) || version > 1) + return; + if(!file.ReadVarInt(page) || page >= static_cast<uint32>(CModControlView::Page::NumPages)) + return; + + UINT pageDlg = 0; + switch(static_cast<CModControlView::Page>(page)) + { + case CModControlView::Page::Globals: + pageDlg = IDD_CONTROL_GLOBALS; + break; + case CModControlView::Page::Patterns: + pageDlg = IDD_CONTROL_PATTERNS; + if(version == 0) + m_ViewPatterns.Deserialize(file); + break; + case CModControlView::Page::Samples: + pageDlg = IDD_CONTROL_SAMPLES; + if(version == 0) + m_ViewSamples.Deserialize(file); + break; + case CModControlView::Page::Instruments: + pageDlg = IDD_CONTROL_INSTRUMENTS; + if(version == 0) + m_ViewInstruments.Deserialize(file); + break; + case CModControlView::Page::Comments: + pageDlg = IDD_CONTROL_COMMENTS; + break; + case CModControlView::Page::Unknown: + case CModControlView::Page::NumPages: + break; + } + + // Version 1 extensions: Deserialize all views, not just current view + while(file.CanRead(3)) + { + uint32 size = 0; + file.ReadVarInt(page); + file.ReadVarInt(size); + FileReader chunk = file.ReadChunk(size); + if(page >= static_cast<uint32>(CModControlView::Page::NumPages) || !chunk.IsValid()) + continue; + switch(static_cast<CModControlView::Page>(page)) { - case CModControlView::Page::Globals: - pageDlg = IDD_CONTROL_GLOBALS; - break; - case CModControlView::Page::Patterns: - pageDlg = IDD_CONTROL_PATTERNS; - if(version == 0) - m_ViewPatterns.Deserialize(file); - break; - case CModControlView::Page::Samples: - pageDlg = IDD_CONTROL_SAMPLES; - if(version == 0) - m_ViewSamples.Deserialize(file); - break; - case CModControlView::Page::Instruments: - pageDlg = IDD_CONTROL_INSTRUMENTS; - if(version == 0) - m_ViewInstruments.Deserialize(file); - break; - case CModControlView::Page::Comments: - pageDlg = IDD_CONTROL_COMMENTS; - break; + case CModControlView::Page::Globals: m_ViewGeneral.Deserialize(chunk); break; + case CModControlView::Page::Patterns: m_ViewPatterns.Deserialize(chunk); break; + case CModControlView::Page::Samples: m_ViewSamples.Deserialize(chunk); break; + case CModControlView::Page::Instruments: m_ViewInstruments.Deserialize(chunk); break; + case CModControlView::Page::Comments: m_ViewComments.Deserialize(chunk); break; case CModControlView::Page::Unknown: case CModControlView::Page::NumPages: break; } - - // Version 1 extensions - while(file.CanRead(3)) - { - uint32 size = 0; - file.ReadVarInt(page); - file.ReadVarInt(size); - FileReader chunk = file.ReadChunk(size); - if(page >= 0 && static_cast<CModControlView::Page>(page) < CModControlView::Page::NumPages && chunk.IsValid()) - { - switch(static_cast<CModControlView::Page>(page)) - { - case CModControlView::Page::Globals: m_ViewGeneral.Deserialize(chunk); break; - case CModControlView::Page::Patterns: m_ViewPatterns.Deserialize(chunk); break; - case CModControlView::Page::Samples: m_ViewSamples.Deserialize(chunk); break; - case CModControlView::Page::Instruments: m_ViewInstruments.Deserialize(chunk); break; - case CModControlView::Page::Comments: m_ViewComments.Deserialize(chunk); break; - case CModControlView::Page::Unknown: - case CModControlView::Page::NumPages: - break; - } - } - } - - GetModControlView()->PostMessage(WM_MOD_ACTIVATEVIEW, pageDlg, LPARAM(-1)); } + + GetModControlView()->PostMessage(WM_MOD_ACTIVATEVIEW, pageDlg, LPARAM(-1)); } Modified: trunk/OpenMPT/mptrack/Childfrm.h ============================================================================== --- trunk/OpenMPT/mptrack/Childfrm.h Tue Dec 10 18:23:59 2024 (r22505) +++ trunk/OpenMPT/mptrack/Childfrm.h Tue Dec 10 18:34:12 2024 (r22506) @@ -99,23 +99,23 @@ // Attributes protected: CSplitterWnd m_wndSplitter; - HWND m_hWndCtrl, m_hWndView; + HWND m_hWndCtrl = nullptr, m_hWndView = nullptr; GeneralViewState m_ViewGeneral; PatternViewState m_ViewPatterns; SampleViewState m_ViewSamples; InstrumentViewState m_ViewInstruments; CommentsViewState m_ViewComments; - CHAR m_szCurrentViewClassName[256]; - bool m_bMaxWhenClosed; - bool m_bInitialActivation; + std::string m_currentViewClassName; + int m_dpi = 0; + bool m_maxWhenClosed = false; + bool m_initialActivation = true; // Operations public: - CModControlView *GetModControlView() const { return (CModControlView *)m_wndSplitter.GetPane(0, 0); } - BOOL ChangeViewClass(CRuntimeClass* pNewViewClass, CCreateContext* pContext=NULL); + CModControlView *GetModControlView() const { return reinterpret_cast<CModControlView *>(m_wndSplitter.GetPane(0, 0)); } + BOOL ChangeViewClass(CRuntimeClass *pNewViewClass, CCreateContext *pContext = nullptr); void ForceRefresh(); - void SavePosition(BOOL bExit=FALSE); - const char *GetCurrentViewClassName() const; + void SavePosition(bool exit = false); LRESULT SendCtrlMessage(UINT uMsg, LPARAM lParam = 0) const; LRESULT SendViewMessage(UINT uMsg, LPARAM lParam = 0) const; LRESULT ActivateView(UINT nId, LPARAM lParam); @@ -127,6 +127,8 @@ InstrumentViewState &GetInstrumentViewState() { return m_ViewInstruments; } CommentsViewState &GetCommentViewState() { return m_ViewComments; } + bool IsPatternView() const; + void SetSplitterHeight(int x); int GetSplitterHeight(); Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Tue Dec 10 18:23:59 2024 (r22505) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Tue Dec 10 18:34:12 2024 (r22506) @@ -459,7 +459,7 @@ BeginWaitCursor(); if (IsPlaying()) PauseMod(); - if (pMDIActive) pMDIActive->SavePosition(TRUE); + if (pMDIActive) pMDIActive->SavePosition(true); if(gpSoundDevice) { Modified: trunk/OpenMPT/mptrack/Moddoc.cpp ============================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp Tue Dec 10 18:23:59 2024 (r22505) +++ trunk/OpenMPT/mptrack/Moddoc.cpp Tue Dec 10 18:34:12 2024 (r22506) @@ -2120,7 +2120,7 @@ if (pMainFrm) { CChildFrame *pChildFrm = GetChildFrame(); - if (strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) + if(pChildFrm->IsPatternView()) { //User has sent play song command: set loop pattern checkbox to false. pChildFrm->SendViewMessage(VIEWMSG_PATTERNLOOP, 0); @@ -2221,7 +2221,7 @@ if (pMainFrm) { CChildFrame *pChildFrm = GetChildFrame(); - if (strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) + if(pChildFrm->IsPatternView()) { //User has sent play song command: set loop pattern checkbox to false. pChildFrm->SendViewMessage(VIEWMSG_PATTERNLOOP, 0); @@ -2459,7 +2459,7 @@ { CChildFrame *pChildFrm = GetChildFrame(); - if(strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) // dirty HACK + if(pChildFrm->IsPatternView()) { PatternViewState patternViewState; pChildFrm->SendViewMessage(VIEWMSG_SAVESTATE, (LPARAM)(&patternViewState)); @@ -2516,7 +2516,7 @@ if ((pMainFrm) && (pChildFrm)) { - if (strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) + if(pChildFrm->IsPatternView()) { //User has sent play pattern command: set loop pattern checkbox to true. pChildFrm->SendViewMessage(VIEWMSG_PATTERNLOOP, loop ? 1 : 0); @@ -2572,7 +2572,7 @@ if ((pMainFrm) && (pChildFrm)) { - if (strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) + if(pChildFrm->IsPatternView()) { //User has sent play pattern command: set loop pattern checkbox to true. pChildFrm->SendViewMessage(VIEWMSG_PATTERNLOOP, 1); @@ -2623,7 +2623,7 @@ if ((pMainFrm) && (pChildFrm)) { - if (strcmp("CViewPattern", pChildFrm->GetCurrentViewClassName()) == 0) + if(pChildFrm->IsPatternView()) { //User has sent play song command: set loop pattern checkbox to false. pChildFrm->SendViewMessage(VIEWMSG_PATTERNLOOP, 0); |