/** * @file XTPTaskDialogAPI.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/XTPTypeId.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Common/XTPGdiObjects.h" #include "Common/XTPDrawHelpers.h" #include "Common/XTPMarkupRender.h" #include "Controls/Dialog/XTPTaskDialogAPI.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif namespace XTPTaskDialogAPI { _XTP_EXT_CLASS int AFXAPI XTPLoadStringInst(HINSTANCE hInstance, UINT nID, CString* pString) { #ifdef _UNICODE const int nChar = 1; // one TCHAR unused is good enough #else const int nChar = 2; // two BYTES unused for case of DBC last char #endif const int nMax = 256; TCHAR szBuffer[nMax]; int nLen = ::LoadString(hInstance, nID, szBuffer, (nMax - 1)); if ((nMax - 1) - nLen > nChar) { *pString = nLen > 0 ? szBuffer : _T(""); return nLen; } int nSize = nMax; do { nSize += nMax; nLen = ::LoadString(hInstance, nID, pString->GetBuffer(nSize - 1), nSize); } while (nSize - nLen <= nChar); pString->ReleaseBuffer(); return nLen; } _XTP_EXT_CLASS CPoint AFXAPI XTPDlu2Pix(int dluX, int dluY) { CPoint baseXY(::GetDialogBaseUnits()); CPoint pixXY(0, 0); pixXY.x = ::MulDiv(dluX, baseXY.x, 4); pixXY.y = ::MulDiv(dluY, baseXY.y, 8); return pixXY; } _XTP_EXT_CLASS CPoint AFXAPI XTPPix2Dlu(int pixX, int pixY) { CPoint baseXY(::GetDialogBaseUnits()); CPoint dluXY; dluXY.x = ::MulDiv(pixX, 4, baseXY.x); dluXY.y = ::MulDiv(pixY, 8, baseXY.y); return dluXY; } _XTP_EXT_CLASS BOOL AFXAPI XTPCalcTextSize(const CString& strText, CSize& sizeText, CFont& font, BOOL* pbWordWrap /*=NULL*/) { if (strText.IsEmpty() || font.m_hObject == NULL) { sizeText = CSize(0, 0); return FALSE; } CWindowDC dc(NULL); CXTPFontDC fontDC(&dc, &font); CRect rectText = XTPSize2Rect(sizeText); if (dc.DrawText(strText, &rectText, DT_CALCRECT | DT_LEFT | DT_NOPREFIX | DT_TOP | DT_WORDBREAK) != 0) { sizeText = rectText.Size(); if (pbWordWrap) *pbWordWrap = (sizeText.cy > dc.GetTextExtent(strText).cy); return TRUE; } sizeText = CSize(0, 0); return FALSE; } _XTP_EXT_CLASS BOOL AFXAPI XTPCalcIdealTextSize(const CString& strText, CSize& sizeText, CFont& font, int dluMax /*=xtpDluMax*/, int dluGrow /*=xtpDluAdd*/) { if (strText.IsEmpty() || font.m_hObject == NULL) return FALSE; CWindowDC dc(NULL); CXTPFontDC fontDC(&dc, &font); CSize sizeExtent = dc.GetTextExtent(strText); int nMaxPix = XTPDlu2Pix(dluMax, 0).x; if (sizeExtent.cx > nMaxPix) { sizeText.cx += MulDiv(sizeExtent.cx, XTPDlu2Pix(dluGrow, 0).x, nMaxPix); return XTPCalcTextSize(strText, sizeText, font); } else if (sizeExtent.cx > sizeText.cx) { CSize sizeMin = sizeText; XTPCalcTextSize(strText, sizeText, font); if (sizeText.cx > sizeMin.cx) { return TRUE; } } sizeText = sizeExtent; return FALSE; } _XTP_EXT_CLASS BOOL AFXAPI XTPCalcIdealTextSize(CXTPMarkupContext* pMarkupContext, CXTPMarkupUIElement* pUIElement, CSize& sizeText, CFont& font, int dluMax /*=xtpDluMax*/, int dluGrow /*=xtpDluAdd*/) { XTPMarkupSetDefaultFont(pMarkupContext, (HFONT)font.GetSafeHandle(), (COLORREF)-1); CSize sizeExtent = XTPMarkupMeasureElement(pUIElement, INT_MAX, INT_MAX); CSize sizeMax = sizeExtent; int nMaxPix = XTPDlu2Pix(dluMax, 0).x; if (sizeExtent.cx > nMaxPix) { sizeText.cx += MulDiv(sizeExtent.cx, XTPDlu2Pix(dluGrow, 0).x, nMaxPix); } sizeExtent = XTPMarkupMeasureElement(pUIElement, sizeText.cx, INT_MAX); if (sizeExtent.cx == sizeText.cx && sizeExtent.cy == sizeMax.cy && sizeExtent.cx < sizeMax.cx) sizeExtent = sizeMax; sizeText = sizeExtent; return TRUE; } _XTP_EXT_CLASS CString AFXAPI XTPExtractSubString(CString strFullString, int iSubString) { if (strFullString.Find(_T('\n')) != -1) { CString strSubString; AfxExtractSubString(strSubString, strFullString, iSubString, _T('\n')); return strSubString; } return ((iSubString == 0) ? strFullString : CString()); } _XTP_EXT_CLASS CRect AFXAPI XTPSize2Rect(CSize size) { return CRect(CPoint(0, 0), size); } } // namespace XTPTaskDialogAPI