/** * @file XTPFlowGraphTools.h * * @copyright * (c) 1998-2025 Codejock Software, All Rights Reserved. * * This source file is the property of Codejock Software and must not be * redistributed by any means without the explicit written permission of * Codejock Software. * * The use of this source code is governed by the terms and conditions specified * in the Toolkit Pro license agreement. Codejock Software grants you, as a * single software developer, the limited right to use this software on one * computer only. * * Contact Information: * support@codejock.com * http://www.codejock.com * */ /** @cond */ #if !defined(__XTPFLOWGRAPHTOOLS_H__) # define __XTPFLOWGRAPHTOOLS_H__ /** @endcond */ # if _MSC_VER > 1000 # pragma once # endif // _MSC_VER > 1000 # include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" /** @cond */ template class CXTPFlowGraphGDIHandles : public Traits { public: typedef typename Traits::FromType FromType; typedef typename Traits::ToType ToType; /** * @brief * Constructs a CXTPFlowGraphGDIHandles object. */ CXTPFlowGraphGDIHandles() { m_nCount = 0; } /** * @brief * Destroys a CXTPFlowGraphGDIHandles object, handles cleanup and * deallocation. */ ~CXTPFlowGraphGDIHandles() { for (int i = 0; i < m_nCount; i++) { CXTPFlowGraphGDIHandles::DestroyHandle(m_arr[i].hTo); } } ToType GetHandle(const FromType& hFrom) { int i; for (i = 0; i < m_nCount; i++) { if (Traits::CompareHandle(m_arr[i].hFrom, hFrom)) return m_arr[i].hTo; } if (m_nCount == MAX_HANDLE) { Traits::DestroyHandle(m_arr[m_nCount - 1].hTo); } else if (m_nCount) { m_arr[m_nCount] = m_arr[m_nCount - 1]; } for (i = m_nCount - 1; i >= 1; i--) { m_arr[i] = m_arr[i - 1]; } if (m_nCount != MAX_HANDLE) m_nCount++; m_arr[0].hFrom = hFrom; m_arr[0].hTo = Traits::CreateHandle(hFrom); return m_arr[0].hTo; } struct GDIREC { FromType hFrom; ToType hTo; }; enum { MAX_HANDLE = 6 }; int m_nCount; GDIREC m_arr[MAX_HANDLE]; }; struct CXTPFlowGraphFontTraits { typedef LOGFONT FromType; typedef HFONT ToType; void DestroyHandle(HFONT hFont) { DeleteObject(hFont); } HFONT CreateHandle(const LOGFONT& lf) { return CreateFontIndirect(&lf); } BOOL CompareHandle(const LOGFONT& lfLeft, const LOGFONT& lfRight) { if (lfLeft.lfHeight != lfRight.lfHeight) return FALSE; if (lfLeft.lfWeight != lfRight.lfWeight) return FALSE; if (lfLeft.lfItalic != lfRight.lfItalic) return FALSE; if (lfLeft.lfQuality != lfRight.lfQuality) return FALSE; if (_tcscmp(lfLeft.lfFaceName, lfRight.lfFaceName) != 0) return FALSE; return TRUE; } }; struct CXTPFlowGraphBrushTraits { typedef COLORREF FromType; typedef HBRUSH ToType; void DestroyHandle(HBRUSH hFont) { DeleteObject(hFont); } HBRUSH CreateHandle(COLORREF clr) { return CreateSolidBrush(clr); } BOOL CompareHandle(COLORREF clrLeft, COLORREF clrRight) { return clrLeft == clrRight; } }; /** @endcond */ /** @cond */ # include "Common/Base/Diagnostic/XTPEnableNoisyWarnings.h" #endif //#if !defined(__XTPFLOWGRAPHTOOLS_H__) /** @endcond */