/** * @file XTPUtil.cpp * * @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 * */ #include "stdafx.h" #include "Common/XTPVC80Helpers.h" // Visual Studio 2005 helper functions #include "Controls/Util/XTPUtil.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif //=========================================================================== // CXTPIconHandle class //=========================================================================== CXTPIconHandle::CXTPIconHandle() : m_hIcon(NULL) { } CXTPIconHandle::CXTPIconHandle(HICON hIcon) : m_hIcon(hIcon) { } CXTPIconHandle::~CXTPIconHandle() { if (m_hIcon != NULL) { ::DestroyIcon(m_hIcon); } } CXTPIconHandle& CXTPIconHandle::operator=(HICON hIcon) { if (m_hIcon != NULL) { ::DestroyIcon(m_hIcon); } m_hIcon = hIcon; return *this; } CSize AFX_CDECL CXTPIconHandle::GetExtent(HICON hIcon) { CSize extent(0); if (hIcon) { ICONINFO iconinfo; if (::GetIconInfo(hIcon, &iconinfo)) { BITMAP bmpinfo; ZeroMemory(&bmpinfo, sizeof(BITMAP)); if (::GetObject(iconinfo.hbmMask, sizeof(bmpinfo), &bmpinfo)) { extent.cx = (int)bmpinfo.bmWidth; extent.cy = (int)bmpinfo.bmHeight; if (!iconinfo.hbmColor) { // b/w icons have double size for XOR and AND masks extent.cy /= 2; } } // cleanup GDI if (iconinfo.hbmMask) { ::DeleteObject(iconinfo.hbmMask); } if (iconinfo.hbmColor) { ::DeleteObject(iconinfo.hbmColor); } } } return extent; } CSize CXTPIconHandle::GetExtent() const { return GetExtent(m_hIcon); } HICON AFX_CDECL CXTPIconHandle::ScaleToFit(HICON hIcon, CSize desiredExtent) { if (desiredExtent == CSize(0)) { // invalid arg return NULL; } CSize realExtent = GetExtent(hIcon); if (realExtent == CSize(0)) { // icon destroyed or not created yet return NULL; } // ensure icon retains aspect after scaling int delta = desiredExtent.cx * realExtent.cy - desiredExtent.cy * realExtent.cx; if (delta < 0) { desiredExtent.cy = MulDiv(realExtent.cy, desiredExtent.cx, realExtent.cx); } else if (delta > 0) { desiredExtent.cx = MulDiv(realExtent.cx, desiredExtent.cy, realExtent.cy); } // scale the icon CImageList images; VERIFY(images.Create(desiredExtent.cx, desiredExtent.cy, ILC_COLOR32 | ILC_MASK, 1, 1)); images.Add(hIcon); return images.ExtractIcon(0); } HICON CXTPIconHandle::ScaleToFit(CSize desiredExtent) const { return ScaleToFit(m_hIcon, desiredExtent); } //=========================================================================== // CXTPSplitPath class //=========================================================================== CXTPSplitPath::CXTPSplitPath(LPCTSTR lpszPathBuffer /*= NULL*/) { m_szDrive[0] = 0; m_szDir[0] = 0; m_szFName[0] = 0; m_szExt[0] = 0; if (lpszPathBuffer != NULL) { SplitPath(lpszPathBuffer); } } CXTPSplitPath::~CXTPSplitPath() { } void CXTPSplitPath::SplitPath(LPCTSTR lpszPathBuffer) { SPLITPATH_S(lpszPathBuffer, m_szDrive, m_szDir, m_szFName, m_szExt); } CString CXTPSplitPath::GetDrive() const { return CString(m_szDrive); } CString CXTPSplitPath::GetDir() const { return CString(m_szDir); } CString CXTPSplitPath::GetFName() const { return CString(m_szFName); } CString CXTPSplitPath::GetExt() const { return CString(m_szExt); } CString CXTPSplitPath::GetFullPath() const { return GetDrive() + GetDir(); } CString CXTPSplitPath::GetFullName() const { return GetFName() + GetExt(); }