/** * @file XTPMarkupStackPanel.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/XTPMarkupStackPanel.h" #include "Markup/XTPMarkupBuilder.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 ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CXTPMarkupDependencyProperty* CXTPMarkupStackPanel::m_pOrientationProperty = NULL; IMPLEMENT_MARKUPCLASS(L"StackPanel", CXTPMarkupStackPanel, CXTPMarkupPanel) void CXTPMarkupStackPanel::RegisterMarkupClass() { m_pOrientationProperty = CXTPMarkupDependencyProperty::Register( L"Orientation", MARKUP_TYPE(CXTPMarkupEnum), MARKUP_TYPE(CXTPMarkupStackPanel), new CXTPMarkupPropertyMetadata(NULL, &CXTPMarkupBuilder::ConvertOrientation, CXTPMarkupPropertyMetadata::flagAffectsMeasure)); } CXTPMarkupStackPanel::CXTPMarkupStackPanel() { } CXTPMarkupStackPanel::~CXTPMarkupStackPanel() { } XTPMarkupOrientation CXTPMarkupStackPanel::GetOrientation() const { CXTPMarkupEnum* pOrientation = MARKUP_DYNAMICCAST(CXTPMarkupEnum, GetValue(m_pOrientationProperty)); return (NULL != pOrientation ? (XTPMarkupOrientation)(int)(*pOrientation) : xtpMarkupOrientationVertical); } void CXTPMarkupStackPanel::SetOrientation(XTPMarkupOrientation orientation) { SetValue(m_pOrientationProperty, CXTPMarkupEnum::CreateValue(orientation)); } CSize CXTPMarkupStackPanel::MeasureOverride(CXTPMarkupDrawingContext* pDC, CSize constraint) { CSize size(0, 0); CSize availableSize = constraint; bool bHorizontal = GetOrientation() == xtpMarkupOrientationHorizontal; if (bHorizontal) { availableSize.cx = INT_MAX; } else { availableSize.cy = INT_MAX; } 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, availableSize); CSize desiredSize = pElement->GetDesiredSize(); if (bHorizontal) { size.cx += desiredSize.cx; size.cy = max(size.cy, desiredSize.cy); } else { size.cx = max(size.cx, desiredSize.cx); size.cy += desiredSize.cy; } } return size; } CSize CXTPMarkupStackPanel::ArrangeOverride(CSize arrangeSize) { bool bHorizontal = GetOrientation() == xtpMarkupOrientationHorizontal; CRect finalRect(CPoint(0), arrangeSize); int width = 0; int nCount = m_pChildren->GetCount(); for (int i = 0; i < nCount; i++) { CXTPMarkupUIElement* pElement = m_pChildren->GetItem(i); if (pElement == NULL) continue; if (bHorizontal) { finalRect.left += width; width = pElement->GetDesiredSize().cx; finalRect.right = finalRect.left + width; finalRect.bottom = max(arrangeSize.cy, pElement->GetDesiredSize().cy); } else { finalRect.top += width; width = pElement->GetDesiredSize().cy; finalRect.bottom = finalRect.top + width; finalRect.right = max(arrangeSize.cx, pElement->GetDesiredSize().cx); } pElement->Arrange(finalRect); } return arrangeSize; } #include "Common/Base/Diagnostic/XTPBeginAfxMap.h" BEGIN_DISPATCH_MAP(CXTPMarkupStackPanel, CXTPMarkupPanel) DISP_PROPERTY_EX_ID(CXTPMarkupStackPanel, "Orientation", 600, OleGetOrientation, OleSetOrientation, VT_I4) END_DISPATCH_MAP() #include "Common/Base/Diagnostic/XTPEndAfxMap.h" #ifdef _XTP_ACTIVEX BEGIN_INTERFACE_MAP(CXTPMarkupStackPanel, CXTPMarkupPanel) INTERFACE_PART(CXTPMarkupStackPanel, XTPDIID_MarkupStackPanel, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPMarkupStackPanel, XTPDIID_MarkupStackPanel) #endif long CXTPMarkupStackPanel::OleGetOrientation() { return GetOrientation(); } void CXTPMarkupStackPanel::OleSetOrientation(long nValue) { SetOrientation((XTPMarkupOrientation)nValue); }