/** * @file XTPMarkupCanvas.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/XTPCasting.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Markup/XTPMarkupTools.h" #include "Markup/XTPMarkupObject.h" #include "Markup/XTPMarkupInputElement.h" #include "Markup/XTPMarkupUIElement.h" #include "Markup/XTPMarkupFrameworkElement.h" #include "Markup/Controls/XTPMarkupUIElementCollection.h" #include "Markup/Controls/XTPMarkupPanel.h" #include "Markup/Controls/XTPMarkupCanvas.h" #include "Markup/XTPMarkupIIDs.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif ////////////////////////////////////////////////////////////////////// // CXTPMarkupCanvas CXTPMarkupDependencyProperty* CXTPMarkupCanvas::m_pTopProperty = NULL; CXTPMarkupDependencyProperty* CXTPMarkupCanvas::m_pRightProperty = NULL; CXTPMarkupDependencyProperty* CXTPMarkupCanvas::m_pLeftProperty = NULL; CXTPMarkupDependencyProperty* CXTPMarkupCanvas::m_pBottomProperty = NULL; IMPLEMENT_MARKUPCLASS(L"Canvas", CXTPMarkupCanvas, CXTPMarkupPanel) void CXTPMarkupCanvas::RegisterMarkupClass() { m_pTopProperty = CXTPMarkupDependencyProperty::RegisterAttached( L"Top", MARKUP_TYPE(CXTPMarkupInt), MARKUP_TYPE(CXTPMarkupCanvas), new CXTPMarkupPropertyMetadata(NULL, CXTPMarkupPropertyMetadata::flagVertDpiSensible | CXTPMarkupPropertyMetadata::flagAffectsArrange | CXTPMarkupPropertyMetadata::flagAffectsMeasure | CXTPMarkupPropertyMetadata::flagAffectsParentArrange | CXTPMarkupPropertyMetadata::flagAffectsParentMeasure)); m_pRightProperty = CXTPMarkupDependencyProperty::RegisterAttached( L"Right", MARKUP_TYPE(CXTPMarkupInt), MARKUP_TYPE(CXTPMarkupCanvas), new CXTPMarkupPropertyMetadata(NULL, CXTPMarkupPropertyMetadata::flagHorzDpiSensible | CXTPMarkupPropertyMetadata::flagAffectsArrange | CXTPMarkupPropertyMetadata::flagAffectsMeasure | CXTPMarkupPropertyMetadata::flagAffectsParentArrange | CXTPMarkupPropertyMetadata::flagAffectsParentMeasure)); m_pLeftProperty = CXTPMarkupDependencyProperty::RegisterAttached( L"Left", MARKUP_TYPE(CXTPMarkupInt), MARKUP_TYPE(CXTPMarkupCanvas), new CXTPMarkupPropertyMetadata(NULL, CXTPMarkupPropertyMetadata::flagHorzDpiSensible | CXTPMarkupPropertyMetadata::flagAffectsArrange | CXTPMarkupPropertyMetadata::flagAffectsMeasure | CXTPMarkupPropertyMetadata::flagAffectsParentArrange | CXTPMarkupPropertyMetadata::flagAffectsParentMeasure)); m_pBottomProperty = CXTPMarkupDependencyProperty::RegisterAttached( L"Bottom", MARKUP_TYPE(CXTPMarkupInt), MARKUP_TYPE(CXTPMarkupCanvas), new CXTPMarkupPropertyMetadata(NULL, CXTPMarkupPropertyMetadata::flagVertDpiSensible | CXTPMarkupPropertyMetadata::flagAffectsArrange | CXTPMarkupPropertyMetadata::flagAffectsMeasure | CXTPMarkupPropertyMetadata::flagAffectsParentArrange | CXTPMarkupPropertyMetadata::flagAffectsParentMeasure)); } CXTPMarkupCanvas::CXTPMarkupCanvas() { } CXTPMarkupCanvas::~CXTPMarkupCanvas() { } void CXTPMarkupCanvas::SetLeft(CXTPMarkupUIElement* pElement, int nLeft) { pElement->SetValue(m_pLeftProperty, new CXTPMarkupInt(nLeft)); } void CXTPMarkupCanvas::SetTop(CXTPMarkupUIElement* pElement, int nTop) { pElement->SetValue(m_pTopProperty, new CXTPMarkupInt(nTop)); } void CXTPMarkupCanvas::SetRight(CXTPMarkupUIElement* pElement, int nRight) { pElement->SetValue(m_pRightProperty, new CXTPMarkupInt(nRight)); } void CXTPMarkupCanvas::SetBottom(CXTPMarkupUIElement* pElement, int nBottom) { pElement->SetValue(m_pBottomProperty, new CXTPMarkupInt(nBottom)); } int CXTPMarkupCanvas::GetLeft(CXTPMarkupUIElement* pElement) { int nValue = 0; return (TryGetLeft(pElement, nValue) ? nValue : 0); } int CXTPMarkupCanvas::GetTop(CXTPMarkupUIElement* pElement) { int nValue = 0; return (TryGetTop(pElement, nValue) ? nValue : 0); } int CXTPMarkupCanvas::GetRight(CXTPMarkupUIElement* pElement) { int nValue = 0; return (TryGetRight(pElement, nValue) ? nValue : 0); } int CXTPMarkupCanvas::GetBottom(CXTPMarkupUIElement* pElement) { int nValue = 0; return (TryGetBottom(pElement, nValue) ? nValue : 0); } BOOL CXTPMarkupCanvas::TryGetLeft(CXTPMarkupUIElement* pElement, int& nValue) { CXTPMarkupInt* pValue = MARKUP_DYNAMICCAST(CXTPMarkupInt, pElement->GetValue(m_pLeftProperty)); if (NULL == pValue) return FALSE; nValue = *pValue; return TRUE; } BOOL CXTPMarkupCanvas::TryGetTop(CXTPMarkupUIElement* pElement, int& nValue) { CXTPMarkupInt* pValue = MARKUP_DYNAMICCAST(CXTPMarkupInt, pElement->GetValue(m_pTopProperty)); if (NULL == pValue) return FALSE; nValue = *pValue; return TRUE; } BOOL CXTPMarkupCanvas::TryGetRight(CXTPMarkupUIElement* pElement, int& nValue) { CXTPMarkupInt* pValue = MARKUP_DYNAMICCAST(CXTPMarkupInt, pElement->GetValue(m_pRightProperty)); if (NULL == pValue) return FALSE; nValue = *pValue; return TRUE; } BOOL CXTPMarkupCanvas::TryGetBottom(CXTPMarkupUIElement* pElement, int& nValue) { CXTPMarkupInt* pValue = MARKUP_DYNAMICCAST(CXTPMarkupInt, pElement->GetValue(m_pBottomProperty)); if (NULL == pValue) return FALSE; nValue = *pValue; return TRUE; } CSize CXTPMarkupCanvas::MeasureOverride(CXTPMarkupDrawingContext* pDC, CSize /*availableSize*/) { int cx = 0, cy = 0; int nCount = m_pChildren->GetCount(); for (int i = 0; i < nCount; i++) { CXTPMarkupUIElement* pElement = m_pChildren->GetItem(i); if (pElement == NULL) continue; pElement->Measure(pDC, CSize(INT_MAX, INT_MAX)); CSize sz = pElement->GetDesiredSize(); cx = max(cx, sz.cx); cy = max(cy, sz.cy); } return CSize(cx, cy); } CSize CXTPMarkupCanvas::ArrangeOverride(CSize arrangeSize) { int nCount = m_pChildren->GetCount(); for (int i = 0; i < nCount; i++) { CXTPMarkupUIElement* pElement = m_pChildren->GetItem(i); if (pElement == NULL) continue; int nLeft = 0; if (!TryGetLeft(pElement, nLeft) && TryGetRight(pElement, nLeft)) nLeft = arrangeSize.cx - pElement->GetDesiredSize().cx - nLeft; int nTop = 0; if (!TryGetTop(pElement, nTop) && TryGetBottom(pElement, nTop)) nTop = arrangeSize.cy - pElement->GetDesiredSize().cy - nTop; pElement->Arrange(CRect(CPoint(nLeft, nTop), pElement->GetDesiredSize())); } return arrangeSize; } #include "Common/Base/Diagnostic/XTPBeginAfxMap.h" BEGIN_DISPATCH_MAP(CXTPMarkupCanvas, CXTPMarkupPanel) DISP_FUNCTION_ID(CXTPMarkupCanvas, "SetLeft", 600, OleSetLeft, VT_EMPTY, VTS_DISPATCH VTS_I4) DISP_FUNCTION_ID(CXTPMarkupCanvas, "SetTop", 601, OleSetTop, VT_EMPTY, VTS_DISPATCH VTS_I4) DISP_FUNCTION_ID(CXTPMarkupCanvas, "SetRight", 602, OleSetRight, VT_EMPTY, VTS_DISPATCH VTS_I4) DISP_FUNCTION_ID(CXTPMarkupCanvas, "SetBottom", 603, OleSetBottom, VT_EMPTY, VTS_DISPATCH VTS_I4) DISP_FUNCTION_ID(CXTPMarkupCanvas, "GetLeft", 604, OleGetLeft, VT_I4, VTS_DISPATCH) DISP_FUNCTION_ID(CXTPMarkupCanvas, "GetTop", 605, OleGetTop, VT_I4, VTS_DISPATCH) DISP_FUNCTION_ID(CXTPMarkupCanvas, "GetRight", 606, OleGetRight, VT_I4, VTS_DISPATCH) DISP_FUNCTION_ID(CXTPMarkupCanvas, "GetBottom", 607, OleGetBottom, VT_I4, VTS_DISPATCH) END_DISPATCH_MAP() #include "Common/Base/Diagnostic/XTPEndAfxMap.h" #ifdef _XTP_ACTIVEX BEGIN_INTERFACE_MAP(CXTPMarkupCanvas, CXTPMarkupPanel) INTERFACE_PART(CXTPMarkupCanvas, XTPDIID_MarkupCanvas, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPMarkupCanvas, XTPDIID_MarkupCanvas) #endif void CXTPMarkupCanvas::OleSetLeft(LPDISPATCH pDisp, int nValue) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); SetLeft(static_cast(pObject), nValue); } void CXTPMarkupCanvas::OleSetTop(LPDISPATCH pDisp, int nValue) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); SetTop(static_cast(pObject), nValue); } void CXTPMarkupCanvas::OleSetRight(LPDISPATCH pDisp, int nValue) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); SetRight(static_cast(pObject), nValue); } void CXTPMarkupCanvas::OleSetBottom(LPDISPATCH pDisp, int nValue) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); SetBottom(static_cast(pObject), nValue); } int CXTPMarkupCanvas::OleGetLeft(LPDISPATCH pDisp) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); return GetLeft(static_cast(pObject)); } int CXTPMarkupCanvas::OleGetRight(LPDISPATCH pDisp) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); return GetRight(static_cast(pObject)); } int CXTPMarkupCanvas::OleGetTop(LPDISPATCH pDisp) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); return GetTop(static_cast(pObject)); } int CXTPMarkupCanvas::OleGetBottom(LPDISPATCH pDisp) { CXTPMarkupObject* pObject = FromDispatchAs(MARKUP_TYPE(CXTPMarkupUIElement), pDisp, FALSE); if (NULL == pObject) AfxThrowOleException(E_INVALIDARG); return GetBottom(static_cast(pObject)); }