From: <sv...@op...> - 2024-11-29 13:52:28
|
Author: sagamusix Date: Fri Nov 29 14:52:20 2024 New Revision: 22345 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=22345 Log: [Ref] Forward-declare CAutoSaver in Mainfrm.h. [Ref] Turn CInputHandler instance into an mpt::heap_value instead of doing manual memory management. Modified: trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mainfrm.h trunk/OpenMPT/src/mpt/base/alloc.hpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp ============================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp Fri Nov 29 14:49:16 2024 (r22344) +++ trunk/OpenMPT/mptrack/MainFrm.cpp Fri Nov 29 14:52:20 2024 (r22345) @@ -181,8 +181,6 @@ MODPLUGDIB *CMainFrame::bmpNotes = nullptr; COLORREF CMainFrame::gcolrefVuMeter[NUM_VUMETER_PENS * 2]; -CInputHandler *CMainFrame::m_InputHandler = nullptr; - static constexpr UINT StatusBarIndicators[] = { ID_SEPARATOR, // status line indicator @@ -198,15 +196,13 @@ CMainFrame::CMainFrame() : SoundDevice::CallbackBufferHandler<DithersOpenMPT>(theApp.PRNG()) , m_SoundDeviceFillBufferCriticalSection(CriticalSection::InitialState::Unlocked) + , m_InputHandler{this} { m_szUserText[0] = 0; m_szInfoText[0] = 0; m_szXInfoText[0]= 0; MemsetZero(gcolrefVuMeter); - - m_InputHandler = new CInputHandler(this); - } @@ -277,7 +273,6 @@ CMainFrame::~CMainFrame() { - delete m_InputHandler; CChannelManagerDlg::DestroySharedInstance(); } @@ -329,7 +324,7 @@ #pragma warning(push) #pragma warning(disable:6387) // '_Param_(2)' could be '0': this does not adhere to the specification for the function 'HtmlHelpW' #endif - ::HtmlHelp(m_hWnd, nullptr, HH_INITIALIZE, reinterpret_cast<DWORD_PTR>(&helpCookie)); + ::HtmlHelp(m_hWnd, nullptr, HH_INITIALIZE, reinterpret_cast<DWORD_PTR>(&m_helpCookie)); #if MPT_COMPILER_MSVC #pragma warning(pop) #endif @@ -404,7 +399,7 @@ #pragma warning(push) #pragma warning(disable:6387) // '_Param_(2)' could be '0': this does not adhere to the specification for the function 'HtmlHelpW' #endif - ::HtmlHelp(m_hWnd, nullptr, HH_UNINITIALIZE, reinterpret_cast<DWORD_PTR>(&helpCookie)); + ::HtmlHelp(m_hWnd, nullptr, HH_UNINITIALIZE, reinterpret_cast<DWORD_PTR>(&m_helpCookie)); #if MPT_COMPILER_MSVC #pragma warning(pop) #endif @@ -477,7 +472,7 @@ AddControlBar(&m_wndStatusBar); // Restore statusbar to mainframe. TrackerSettings::Instance().SaveSettings(); - if(m_InputHandler && m_InputHandler->m_activeCommandSet) + if(m_InputHandler->m_activeCommandSet) { m_InputHandler->m_activeCommandSet->SaveFile(TrackerSettings::Instance().m_szKbdFile); } @@ -1451,7 +1446,7 @@ void CMainFrame::GenerateStopNotification() { Notification mn(Notification::Stop); - SendMessage(WM_MOD_UPDATEPOSITION, 0, (LPARAM)&mn); + SendMessage(WM_MOD_UPDATEPOSITION, 0, reinterpret_cast<LPARAM>(&mn)); } @@ -2220,9 +2215,9 @@ } } - if(m_AutoSaver.IsEnabled()) + if(m_AutoSaver->IsEnabled()) { - bool success = m_AutoSaver.DoSave(); + bool success = m_AutoSaver->DoSave(); if(!success) // autosave failure; bring up options. { CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_PATHS; @@ -2585,7 +2580,7 @@ } -void CMainFrame::AddToolBarMenuEntries(CMenu &menu) +void CMainFrame::AddToolBarMenuEntries(CMenu &menu) const { menu.AppendMenu(MF_STRING, ID_VIEW_TOOLBAR, m_InputHandler->GetMenuText(ID_VIEW_TOOLBAR)); menu.AppendMenu(MF_STRING, IDD_TREEVIEW, m_InputHandler->GetMenuText(IDD_TREEVIEW)); @@ -2800,6 +2795,14 @@ } +CInputHandler *CMainFrame::GetInputHandler() +{ + if(CMainFrame *mainFrm = GetMainFrame()) + return GetMainFrame()->m_InputHandler.get(); + return nullptr; +} + + // We have switched focus to a new module - might need to update effect keys to reflect module type bool CMainFrame::UpdateEffectKeys(const CModDoc *modDoc) { @@ -3202,7 +3205,7 @@ "Make sure that there's a proper range for menu commands in resources."); HMENU hMenu = CreateFileMenu(nMaxItemsInExampleModulesMenu, m_ExampleModulePaths, P_("ExampleSongs\\"), ID_EXAMPLE_MODULES); CMenu* const pMainMenu = GetMenu(); - if (hMenu && pMainMenu && m_InputHandler) + if (hMenu && pMainMenu) VERIFY(pMainMenu->ModifyMenu(ID_EXAMPLE_MODULES, MF_BYCOMMAND | MF_POPUP, (UINT_PTR)hMenu, m_InputHandler->GetMenuText(ID_EXAMPLE_MODULES))); else ASSERT(false); @@ -3233,7 +3236,7 @@ "Make sure that there's a proper range for menu commands in resources."); HMENU hMenu = CreateFileMenu(nMaxItemsInTemplateModulesMenu, m_TemplateModulePaths, P_("TemplateModules\\"), ID_FILE_OPENTEMPLATE); auto [fileMenu, position] = FindMenuItemByCommand(*GetMenu(), ID_FILE_OPEN); - if(hMenu && fileMenu && m_InputHandler) + if(hMenu && fileMenu) { VERIFY(fileMenu->RemoveMenu(position + 1, MF_BYPOSITION)); VERIFY(fileMenu->InsertMenu(position + 1, MF_BYPOSITION | MF_POPUP, (UINT_PTR)hMenu, m_InputHandler->GetMenuText(ID_FILE_OPENTEMPLATE))); Modified: trunk/OpenMPT/mptrack/Mainfrm.h ============================================================================== --- trunk/OpenMPT/mptrack/Mainfrm.h Fri Nov 29 14:49:16 2024 (r22344) +++ trunk/OpenMPT/mptrack/Mainfrm.h Fri Nov 29 14:52:20 2024 (r22345) @@ -11,7 +11,6 @@ #pragma once #include "openmpt/all/BuildSettings.hpp" -#include "AutoSaver.h" #include "CImageListEx.h" #include "Mainbar.h" #include "Notification.h" @@ -29,6 +28,7 @@ OPENMPT_NAMESPACE_BEGIN +class CAutoSaver; class CDLSBank; class CInputHandler; class CModDoc; @@ -197,25 +197,26 @@ std::unique_ptr<UpdateCheckResult> m_updateCheckResult; bool m_cancelUpdateCheck = false; #endif // MPT_ENABLE_UPDATE - DWORD helpCookie = 0; + DWORD m_helpCookie = 0; bool m_bOptionsLocked = false; // Notification Buffer mpt::mutex m_NotificationBufferMutex; // to avoid deadlocks, this mutex should only be taken as a innermost lock, i.e. do not block on anything while holding this mutex - Util::fixed_size_queue<Notification,MAX_UPDATE_HISTORY> m_NotifyBuffer; + Util::fixed_size_queue<Notification, MAX_UPDATE_HISTORY> m_NotifyBuffer; // Instrument preview in tree view CSoundFile m_WaveFile; TCHAR m_szUserText[512], m_szInfoText[512], m_szXInfoText[512]; - CAutoSaver m_AutoSaver; + mpt::heap_value<CAutoSaver> m_AutoSaver; + mpt::heap_value<CInputHandler> m_InputHandler; public: bool m_bModTreeHasFocus = false; public: - CMainFrame(/*CString regKeyExtension*/); + CMainFrame(); void Initialize(); @@ -264,7 +265,6 @@ static HICON GetModIcon() { return m_hIcon; } static HFONT GetGUIFont() { return m_hGUIFont; } static LRESULT CALLBACK FocusChangeProc(int code, WPARAM wParam, LPARAM lParam); - static CInputHandler *m_InputHandler; // Misc functions public: @@ -282,7 +282,7 @@ void OnDocumentClosed(CModDoc *pModDoc); void UpdateTree(CModDoc *pModDoc, UpdateHint hint, CObject *pHint = nullptr); void RefreshDlsBanks(); - static CInputHandler* GetInputHandler() { return m_InputHandler; } + static CInputHandler *GetInputHandler(); void SetElapsedTime(double t) { m_dwTimeSec = mpt::saturate_cast<samplecount_t>(t * 10.0); } #if defined(MPT_ENABLE_UPDATE) @@ -305,7 +305,7 @@ // [out] paths: Receives the full paths of the files added to the menu. // [in] folderName: Name of the folder // [in] idRangeBegin: First ID for the menu item. - static HMENU CreateFileMenu(const size_t maxCount, std::vector<mpt::PathString>& paths, const mpt::PathString &folderName, const uint16 idRangeBegin); + static HMENU CreateFileMenu(const size_t maxCount, std::vector<mpt::PathString> &paths, const mpt::PathString &folderName, const uint16 idRangeBegin); // Player functions public: @@ -316,7 +316,7 @@ void StopPlayback(); bool RestartPlayback(); bool PausePlayback(); - static bool IsValidSoundFile(CSoundFile &sndFile) { return sndFile.GetType() ? true : false; } + static bool IsValidSoundFile(CSoundFile &sndFile) { return sndFile.GetType() != MOD_TYPE_NONE; } static bool IsValidSoundFile(CSoundFile *pSndFile) { return pSndFile && pSndFile->GetType(); } void SetPlaybackSoundFile(CSoundFile *pSndFile); void UnsetPlaybackSoundFile(); @@ -367,7 +367,7 @@ protected: // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CMainFrame) - BOOL PreCreateWindow(CREATESTRUCT& cs) override; + BOOL PreCreateWindow(CREATESTRUCT &cs) override; BOOL PreTranslateMessage(MSG *pMsg) override; BOOL DestroyWindow() override; void OnUpdateFrameTitle(BOOL bAddToTitle) override; @@ -377,7 +377,7 @@ void OpenMenuItemFile(const UINT nId, const bool isTemplateFile); void ShowToolbarMenu(CPoint screenPt); - static void AddToolBarMenuEntries(CMenu &menu); + void AddToolBarMenuEntries(CMenu &menu) const; void RecreateImageLists(); void SetupStatusBarSizes(); Modified: trunk/OpenMPT/src/mpt/base/alloc.hpp ============================================================================== --- trunk/OpenMPT/src/mpt/base/alloc.hpp Fri Nov 29 14:49:16 2024 (r22344) +++ trunk/OpenMPT/src/mpt/base/alloc.hpp Fri Nov 29 14:52:20 2024 (r22345) @@ -174,6 +174,12 @@ T * operator->() { return m_value.get(); } + const T * get() const { + return m_value.get(); + } + T * get() { + return m_value.get(); + } }; |