From 4d9a3af61b5081c1e3b771389be47b3f0313cddd Mon Sep 17 00:00:00 2001 From: sdottaka Date: Thu, 7 May 2015 20:04:51 +0900 Subject: [PATCH] Remove CSubclass.{cpp, h} --HG-- branch : stable --- Src/Common/CMoveConstraint.cpp | 69 ++++--------- Src/Common/CMoveConstraint.h | 7 +- Src/Common/CSubclass.cpp | 225 ----------------------------------------- Src/Common/CSubclass.h | 51 ---------- Src/Merge.vcxproj | 3 - Src/Merge.vcxproj.filters | 6 -- 6 files changed, 19 insertions(+), 342 deletions(-) delete mode 100644 Src/Common/CSubclass.cpp delete mode 100644 Src/Common/CSubclass.h diff --git a/Src/Common/CMoveConstraint.cpp b/Src/Common/CMoveConstraint.cpp index eea532d12..70597f494 100644 --- a/Src/Common/CMoveConstraint.cpp +++ b/Src/Common/CMoveConstraint.cpp @@ -20,11 +20,6 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI #include // MFC template collection classes #include // needed for CFormView -#ifndef NOSUBCLASS -#include "CSubclass.h" -#endif // NOSUBCLASS - - #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE @@ -83,6 +78,7 @@ CMoveConstraint::Constraint::Init() CMoveConstraint::CMoveConstraint() { m_bSubclassed = false; + m_oldWndProc = NULL; m_sRegistryValueName = _T("UnnamedWindow"); m_sRegistrySubkey = _T("LastWindowPos"); ClearMostData(); @@ -92,7 +88,7 @@ CMoveConstraint::CMoveConstraint() bool CMoveConstraint::InitializeCurrentSize(HWND hwndDlg) { -ASSERT(!m_hwndDlg); + ASSERT(!m_hwndDlg); if (!IsWindow(hwndDlg)) return false; m_hwndDlg = hwndDlg; @@ -337,37 +333,19 @@ ConstrainItem(int nId, double fLeftX, double fExpandX, double fAboveY, double fE } /** - * Chain to further CSubclass processing if appropriate - */ -LRESULT -CMoveConstraint::CallOriginalProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ -#ifndef NOSUBCLASS - if (m_bSubclassed) - return CallOldProc(ConstraintWndProc, hwnd, msg, wParam, lParam); -#else - if (0) - ; -#endif // NOSUBCLASS - else - return (LRESULT)0; -} - -#ifndef NOSUBCLASS -/** * This is the window proc callback that works with the CSubclass module. */ LRESULT CALLBACK CMoveConstraint::ConstraintWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { - void * data = GetData(ConstraintWndProc, hwnd); + void * data = GetProp(hwnd, _T("CMoveConstraintData")); CMoveConstraint * constraint = reinterpret_cast(data); LRESULT lresult; if (constraint->WindowProc(hwnd, msg, wParam, lParam, &lresult)) return lresult; - return constraint->CallOriginalProc(hwnd, msg, wParam, lParam); + return CallWindowProc(constraint->m_oldWndProc, hwnd, msg, wParam, lParam); } bool CMoveConstraint::SubclassWnd() @@ -375,15 +353,23 @@ CMoveConstraint::SubclassWnd() void * data = reinterpret_cast(this); // this will return false if this window/wndproc combination has already // been established (subclassed) - m_bSubclassed = Subclass(ConstraintWndProc, m_hwndDlg, data); + m_bSubclassed = true; + m_oldWndProc = reinterpret_cast(GetWindowLongPtr(m_hwndDlg, GWLP_WNDPROC)); + SetWindowLongPtr(m_hwndDlg, GWLP_WNDPROC, (__int3264)(LONG_PTR)(CMoveConstraint::ConstraintWndProc)); + SetProp(m_hwndDlg, _T("CMoveConstraintData"), data); return m_bSubclassed; } bool CMoveConstraint::UnSubclassWnd() { - return UnSubclass(ConstraintWndProc, m_hwndDlg); + if (!m_bSubclassed) + return false; + SetWindowLongPtr(m_hwndDlg, GWLP_WNDPROC, (__int3264)(LONG_PTR)(m_oldWndProc)); + RemoveProp(m_hwndDlg, _T("CMoveConstraintData")); + m_oldWndProc = NULL; + m_bSubclassed = false; + return true; } -#endif /** * Check if we have any pending constraints not yet added to constraint list @@ -506,26 +492,6 @@ CMoveConstraint::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) lpMMI->ptMaxTrackSize.y = m_nMaxY; } -/** - * Client is asking for window proc handling for a property page. - */ -bool -CMoveConstraint::WindowProcPropertyPage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult) -{ - m_bPropertyPage = true; - return WindowProc(hWnd, message, wParam, lParam, plresult); -} - -/** - * Client is asking for window proc handling for a property sheet. - */ -bool -CMoveConstraint::WindowProcPropertySheet(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult) -{ - m_bPropertySheet = true; - return WindowProc(hWnd, message, wParam, lParam, plresult); -} - bool CMoveConstraint::PaintGrip() { @@ -547,7 +513,7 @@ CMoveConstraint::OnNcHitTest(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT * p return false; if (m_nMinY == m_nMaxY) { - LRESULT nRet = CallOriginalProc(m_hwndDlg, msg, wParam, lParam); + LRESULT nRet = CallWindowProc(m_oldWndProc, m_hwndDlg, msg, wParam, lParam); switch(nRet) { case HTBOTTOMLEFT: @@ -567,7 +533,7 @@ CMoveConstraint::OnNcHitTest(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT * p } if (m_nMinX == m_nMaxX) { - LRESULT nRet = CallOriginalProc(m_hwndDlg, msg, wParam, lParam); + LRESULT nRet = CallWindowProc(m_oldWndProc, m_hwndDlg, msg, wParam, lParam); switch(nRet) { case HTBOTTOMLEFT: @@ -611,6 +577,7 @@ CMoveConstraint::OnDestroy() { if (m_bPersistent) Persist(true, true); + UnSubclassWnd(); // the one variable that CANNOT safely be cleared now is m_bSubclassed // because the subclass is almost certainly not yet removed // (the subclass calls us to let us do destroy processing, before diff --git a/Src/Common/CMoveConstraint.h b/Src/Common/CMoveConstraint.h index 4946663ed..1c5193cab 100644 --- a/Src/Common/CMoveConstraint.h +++ b/Src/Common/CMoveConstraint.h @@ -159,10 +159,6 @@ public: // see usage section above bool WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult); - // obsolete now 2000/10/06 - // (use SetIsPropertyPage etc, and WindowProc above, or just Subclass) - bool WindowProcPropertyPage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult); - bool WindowProcPropertySheet(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult); // ToolTips void SetTip(int id, LPCTSTR szTip); @@ -183,8 +179,6 @@ protected: bool OnNcHitTest(UINT message, WPARAM wParam, LPARAM lParam, LRESULT * plresult); // handle WM_NOTIFY/TTN_NEEDTEXT combination bool OnTtnNeedText(TOOLTIPTEXT * pTTT, LRESULT * plresult); - // forwarder - LRESULT CallOriginalProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); bool PaintGrip(); void ClearMostData(); void DeleteAllConstraints(); @@ -231,6 +225,7 @@ private: int m_nMaxY; int m_nDelayed; // CWnds without HWND bool m_bSubclassed; + WNDPROC m_oldWndProc; // formview stuff CFormView * m_pFormView; // formview original scrollbars diff --git a/Src/Common/CSubclass.cpp b/Src/Common/CSubclass.cpp deleted file mode 100644 index dc15b0bf1..000000000 --- a/Src/Common/CSubclass.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/*! - \file CSubclass.cpp - \author Perry Rapp, Creator, 1998-2003 - \date Created: 1998 - \date Edited: 2006/09/20 Kimmo Varis: use Get/SetWindowLongPtr(). - - \brief Implementation of CSubclass - -*/ -/* The MIT License -Copyright (c) 2001 Perry Rapp -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - - -#include "StdAfx.h" -#include "CSubclass.h" - -#include - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -namespace prdlg { - -struct SubclassRec -{ - WNDPROC m_newproc; - WNDPROC m_oldproc; - void * m_data; - bool m_suppressing; // set during the failed message - Msg m_succeededMsg; - Msg m_failedMsg; -}; - -// all the subclasses for a given hwnd -// newest is head -typedef CList SubclassList; - -// map of hwnds to subclasses -typedef CTypedPtrMap SubclassMap; - -#ifdef _MT -#define THREAD _declspec(thread) -#else -#define THREAD -#endif -// map of hwnds to subclasses for current thread -static THREAD SubclassMap * f_Subclasses=0; - - - -bool Subclass(WNDPROC wndproc, HWND hwnd, void * data - , Msg * unsubclassSucceeded, Msg * unsubclassFailed) -{ - ASSERT(IsWindow(hwnd)); - // cross-thread window usage is not kosher ? - ASSERT(GetCurrentThreadId() == GetWindowThreadProcessId(hwnd, 0)); - if (!f_Subclasses) - f_Subclasses = new SubclassMap; - SubclassList *pList = 0; - if (f_Subclasses->Lookup(hwnd, pList)) - { // we've already subclassed this window - for (POSITION pos = pList->GetHeadPosition(); pos; pList->GetNext(pos)) - { - SubclassRec & srec = pList->GetAt(pos); - if (srec.m_newproc == wndproc) - return false; // cannot resubclass with same WNDPROC - } - } - else - { - pList = new SubclassList; - f_Subclasses->SetAt(hwnd, pList); - } - SubclassRec sdata; - sdata.m_data = data; - sdata.m_newproc = wndproc; - sdata.m_oldproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); - sdata.m_suppressing = false; - if (unsubclassSucceeded) - sdata.m_succeededMsg = *unsubclassSucceeded; - else - sdata.m_succeededMsg.msg = 0; - if (unsubclassFailed) - sdata.m_failedMsg = *unsubclassFailed; - else - sdata.m_failedMsg.msg = 0; - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)wndproc); - pList->AddHead(sdata); - return true; -} - -bool UnSubclass(WNDPROC id, HWND hwnd) -{ - ASSERT(IsWindow(hwnd)); - // cross-thread window usage is not kosher ? - ASSERT(GetCurrentThreadId() == GetWindowThreadProcessId(hwnd, 0)); - SubclassList *pList = 0; - if (!f_Subclasses || !f_Subclasses->Lookup(hwnd, pList)) - // We've not subclassed this hwnd! - return false; - if (!pList->GetCount()) - // internal error - return false; - POSITION pos = pList->GetHeadPosition(); - SubclassRec srec = pList->GetNext(pos); - if (srec.m_newproc == id) - { // we're the latest subclass - WNDPROC curproc = (WNDPROC) GetWindowLongPtr(hwnd, GWLP_WNDPROC); - if (id != curproc) - // We're not the current wndproc, so we can't safely unhook - return false; - ASSERT(srec.m_oldproc); // internal error - SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)srec.m_oldproc); - pList->RemoveHead(); - // fall thru to garbage collect list - } - else - { // we're not the latest, but try to unhook anyway (may be ok) - bool found=false; - SubclassRec sprevrec = srec; - for ( ; pos; pList->GetNext(pos), sprevrec=srec) - { - srec = pList->GetAt(pos); - if (srec.m_newproc == id) - { - found=true; - break; - } - } - if (!found) - // We've not subclassed with this wndproc (id) (or its been unsubclassed already) - return false; - if (sprevrec.m_oldproc != id) - // Foreign subclass has intervened - we can't unhook - return false; - sprevrec.m_oldproc = srec.m_oldproc; - pList->RemoveAt(pos); - // fall thru to garbage collect list - } - // garbage collect - if (!pList->GetCount()) - { - f_Subclasses->RemoveKey(hwnd); - delete pList; - if (!f_Subclasses->GetCount()) - { - delete f_Subclasses; - f_Subclasses = 0; - } - } - return true; -} - -static SubclassRec * FindSubclass(WNDPROC id, HWND hwnd) -{ - SubclassList *pList = 0; - if (!f_Subclasses || !f_Subclasses->Lookup(hwnd, pList)) - // We've not subclassed this hwnd! - return 0; - for (POSITION pos = pList->GetHeadPosition(); pos; pList->GetNext(pos)) - { - SubclassRec & srec = pList->GetAt(pos); - if (srec.m_newproc == id) - return &srec; - } - // We couldn't find our subclass of this hwnd - return 0; -} - -LRESULT CallOldProc(WNDPROC id, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - SubclassRec * psrec = FindSubclass(id, hwnd); - if (!psrec) return 0; - WNDPROC oldproc = psrec->m_oldproc; // psrec may get destroyed by the UnSubclass - if (msg == WM_DESTROY || msg == WM_NCDESTROY) - { - Msg smsg = psrec->m_succeededMsg; - bool succeeded = UnSubclass(id, hwnd); - // if UnSubclass succeeds, psrec will be deleted - if (succeeded) - psrec = 0; - if (!psrec && smsg.msg) - { - // succeeded, inform client - CallWindowProc(id, hwnd, smsg.msg, smsg.wparam, smsg.lparam); - } - if (psrec && (msg == WM_NCDESTROY) && psrec->m_failedMsg.msg) - { - // failed our last chance, inform client - Msg & fmsg = psrec->m_failedMsg; - psrec->m_suppressing = true; - CallWindowProc(id, hwnd, fmsg.msg, fmsg.wparam, fmsg.lparam); - psrec->m_suppressing = false; - } - } - // we don't forward the failed message - // (the succeeded message will never get here, as it was sent after unsubclassed) - if (psrec && psrec->m_suppressing) - { - const Msg & tmsg = psrec->m_failedMsg; - if (tmsg.msg == msg && tmsg.wparam == wParam && tmsg.lparam == lParam) - return 0; - } - - return CallWindowProc(oldproc, hwnd, msg, wParam, lParam); -} - -void * GetData(WNDPROC id, HWND hwnd) -{ - SubclassRec * psrec = FindSubclass(id, hwnd); - if (!psrec) return 0; - return psrec->m_data; -} - - - - -} // namespace diff --git a/Src/Common/CSubclass.h b/Src/Common/CSubclass.h deleted file mode 100644 index ab464e09c..000000000 --- a/Src/Common/CSubclass.h +++ /dev/null @@ -1,51 +0,0 @@ -/*! - \file CSubclass.h - \author Perry Rapp, Creator, 1998-2003 - \date Created: 1998 - \date Edited: 2001/12/12 PR - - \brief Subclass library - functions to subclass any window proc - - - Multiple subclasses of a given window proc are allowed, as long as each is a different - subclass window proc. A second subclass attempt with same window proc will fail -- - Subclass(..) will return false. - - Client may optionally specify unsubclass messages, if client wants to be notified - after the subclass has succeeded or failed. -*/ -/* The MIT License -Copyright (c) 2001 Perry Rapp -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ -#pragma once - -namespace prdlg { - -//! post-subclass message (CallOldProc does not forward these) -// note that if another subclass removes ours violently, these will not get sent -struct Msg -{ - UINT msg; // must be non-zero to be used - WPARAM wparam; - LPARAM lparam; -}; - - //! Client calls Subclass(..) to install new window proc -bool Subclass(WNDPROC wndproc, HWND hwnd, void * data - , Msg * unsubclassSucceeded = NULL, Msg * unsubclassFailed = NULL); - - //! Client calls UnSubclass(..) to remove existing window proc subclass - // this does NOT trigger post-subclass messages -bool UnSubclass(WNDPROC id, HWND hwnd); - - //! Client must call CallOldProc(..) at end of subclassing proc -LRESULT CallOldProc(WNDPROC id, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); - - //! Client calls GetData(..) to retrieve data pointer passed in its Subclass(..) call -void * GetData(WNDPROC id, HWND hwnd); - - -} // namespace diff --git a/Src/Merge.vcxproj b/Src/Merge.vcxproj index 1e3c74522..5eb0fae7e 100644 --- a/Src/Merge.vcxproj +++ b/Src/Merge.vcxproj @@ -634,8 +634,6 @@ NotUsing NotUsing - - @@ -1469,7 +1467,6 @@ - diff --git a/Src/Merge.vcxproj.filters b/Src/Merge.vcxproj.filters index 1672b12ee..94e0fe140 100644 --- a/Src/Merge.vcxproj.filters +++ b/Src/Merge.vcxproj.filters @@ -739,9 +739,6 @@ MFCGui\Common - - MFCGui\Common - MFCGui\Common @@ -1362,9 +1359,6 @@ MFCGui\Header Files - - MFCGui\Common - MFCGui\Common -- 2.11.0