/** * @file XTPChartAxisConstantLines.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/Math/XTPMathUtils.h" #include "Common/XTPCasting.h" #include "Common/XTPFramework.h" #include "Common/PropExchange/XTPPropExchangeSection.h" #include "Common/XTPPropExchange.h" #include "Common/PropExchange/XTPPropExchangeEnumerator.h" #include "Common/PropExchange/XTPPropExchangeEnumeratorPtr.h" #include "Common/Base/Types/XTPPoint2.h" #include "Common/Base/Types/XTPPoint3.h" #include "Common/Base/Types/XTPSize.h" #include "Common/Base/Types/XTPRect.h" #include "Chart/Types/XTPChartTypes.h" #include "Chart/XTPChartDefines.h" #include "Chart/XTPChartElement.h" #include "Chart/XTPChartLegendItem.h" #include "Chart/Diagram/Axis/XTPChartAxisConstantLines.h" #include "Chart/Diagram/Axis/XTPChartAxis.h" #include "Chart/Appearance/XTPChartAppearance.h" #include "Chart/Appearance/XTPChartLineStyle.h" #include "Chart/XTPChartIIDs.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif IMPLEMENT_DYNCREATE(CXTPChartAxisConstantLine, CXTPChartTextElement) ////////////////////////////////////////////////////////////////////////// // CXTPChartAxisConstantLine CXTPChartAxisConstantLine::CXTPChartAxisConstantLine() { m_bLegendVisible = TRUE; m_bVisible = TRUE; m_nAlignment = xtpChartAlignNear; m_bAntialiasing = FALSE; m_pFont = CXTPChartFont::GetTahoma8(); m_bShowTextBelow = FALSE; m_bShowBehind = FALSE; m_pLineStyle = new CXTPChartLineStyle(this); m_dAxisValue = 0; #ifdef _XTP_ACTIVEX EnableAutomation(); EnableTypeLib(); #endif } CXTPChartAxisConstantLine::~CXTPChartAxisConstantLine() { SAFE_RELEASE(m_pFont); SAFE_RELEASE(m_pLineStyle); } void CXTPChartAxisConstantLine::SetText(const CXTPChartString& lpszConstantLine) { m_strText = lpszConstantLine; OnChartChanged(); } void CXTPChartAxisConstantLine::SetFont(CXTPChartFont* pFont) { SAFE_RELEASE(m_pFont); m_pFont = pFont; OnChartChanged(); } void CXTPChartAxisConstantLine::SetTextColor(const CXTPChartColor& clrTextColor) { m_clrTextColor = clrTextColor; OnChartChanged(); } void CXTPChartAxisConstantLine::SetAlignment(XTPChartStringAlignment nAlignment) { m_nAlignment = nAlignment; OnChartChanged(); } CXTPChartString CXTPChartAxisConstantLine::GetLegendName() const { if (!m_strLegendName.IsEmpty()) return m_strLegendName; return m_strText; } CXTPChartColor CXTPChartAxisConstantLine::GetTextColor() const { return m_clrTextColor; } CXTPChartColor CXTPChartAxisConstantLine::GetActualTextColor() const { if (!m_clrTextColor.IsEmpty()) return m_clrTextColor; return GetAppearance()->GetDiagram2DAppearance()->GetAxisAppearance()->ConstantLineTextColor; } CXTPChartColor CXTPChartAxisConstantLine::GetActualColor() const { if (!m_clrColor.IsEmpty()) return m_clrColor; return GetAppearance()->GetDiagram2DAppearance()->GetAxisAppearance()->ConstantLineColor; } CXTPChartDeviceCommand* CXTPChartAxisConstantLine::CreateLegendDeviceCommand( CXTPChartDeviceContext* pDC, CRect rcBounds) { UNREFERENCED_PARAMETER(pDC); rcBounds.DeflateRect(1, 1); int nCenter = rcBounds.CenterPoint().y; return m_pLineStyle->CreateDeviceCommand(CXTPChartPointF((float)rcBounds.left, (float)nCenter), CXTPChartPointF((float)rcBounds.right, (float)nCenter), GetActualColor()); } void CXTPChartAxisConstantLine::DoPropExchange(CXTPPropExchange* pPX) { PX_Bool(pPX, _T("Visible"), m_bVisible, TRUE); PX_Bool(pPX, _T("LegendVisible"), m_bLegendVisible, TRUE); PX_String(pPX, _T("Text"), m_strText, _T("")); PX_String(pPX, _T("LegendName"), m_strLegendName, _T("")); PX_String(pPX, _T("AxisValue"), m_strAxisValue, _T("")); PX_Double(pPX, _T("AxisValueInternal"), m_dAxisValue, 0); PX_Color(pPX, _T("Color"), m_clrColor); PX_Color(pPX, _T("TextColor"), m_clrTextColor); PX_Enum(pPX, _T("Alignment"), m_nAlignment, xtpChartAlignNear); PX_Bool(pPX, _T("Antialiasing"), m_bAntialiasing, FALSE); PX_Font(pPX, _T("Font"), m_pFont); PX_Bool(pPX, _T("ShowTextBelow"), m_bShowTextBelow, FALSE); PX_Bool(pPX, _T("ShowBehind"), m_bShowBehind, FALSE); CXTPPropExchangeSection secLineStyle(pPX->GetSection(_T("LineStyle"))); m_pLineStyle->DoPropExchange(&secLineStyle); } ////////////////////////////////////////////////////////////////////////// // CXTPChartAxisConstantLines CXTPChartAxisConstantLines::CXTPChartAxisConstantLines(CXTPChartAxis* pAxis) { m_pOwner = pAxis; #ifdef _XTP_ACTIVEX EnableAutomation(); EnableTypeLib(); #endif } CXTPChartAxisConstantLines::~CXTPChartAxisConstantLines() { } CXTPChartAxisConstantLine* CXTPChartAxisConstantLines::Add(CXTPChartAxisConstantLine* pConstantLine) { InsertAt(GetCount(), pConstantLine); return pConstantLine; } void CXTPChartAxisConstantLines::DoPropExchange(CXTPPropExchange* pPX) { if (pPX->IsLoading()) { RemoveAll(); CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("ConstantLine"))); POSITION pos = pEnumerator->GetPosition(0); while (pos) { CXTPPropExchangeSection pxItem(pEnumerator->GetNext(pos)); CXTPChartAxisConstantLine* pElement = new CXTPChartAxisConstantLine(); Add(pElement); pElement->DoPropExchange(&pxItem); } } else { CXTPPropExchangeEnumeratorPtr pEnumerator(pPX->GetEnumerator(_T("ConstantLine"))); POSITION pos = pEnumerator->GetPosition(XTPToDWORDChecked(m_arrElements.GetSize())); for (int i = 0; i < GetCount(); i++) { CXTPPropExchangeSection pxItem(pEnumerator->GetNext(pos)); m_arrElements[i]->DoPropExchange(&pxItem); } } } #ifdef _XTP_ACTIVEX BEGIN_DISPATCH_MAP(CXTPChartAxisConstantLine, CXTPChartElement) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "Text", DISPID_VALUE, OleGetText, OleSetText, VT_BSTR) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "AxisValue", 1, OleGetAxisValue, OleSetAxisValue, VT_VARIANT) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "LegendVisible", 2, OleGetLegendVisible, OleSetLegendVisible, VT_BOOL) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "Visible", 3, OleGetVisible, OleSetVisible, VT_BOOL) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "ShowTextBelow", 4, OleGetShowTextBelow, OleSetShowTextBelow, VT_BOOL) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "Alignment", 5, OleGetAlignment, OleSetAlignment, VT_I4) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "LineStyle", 6, OleGetLineStyle, SetNotSupported, VT_DISPATCH) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "Font", DISPID_FONT, OleGetFont, SetNotSupported, VT_DISPATCH) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "Color", 7, OleGetColor, OleSetColor, VT_COLOR) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "TextColor", 8, OleGetTextColor, OleSetTextColor, VT_COLOR) DISP_PROPERTY_EX_ID(CXTPChartAxisConstantLine, "ShowBehind", 9, IsShowBehind, SetShowBehind, VT_BOOL) DISP_PROPERTY_ID(CXTPChartAxisConstantLine, "LegendText", 10, m_strLegendName, VT_BSTR) END_DISPATCH_MAP() BOOL CXTPChartAxisConstantLine::OleGetLegendVisible() { return m_bLegendVisible; } void CXTPChartAxisConstantLine::OleSetLegendVisible(BOOL bValue) { SetLegendVisible(bValue); } BOOL CXTPChartAxisConstantLine::OleGetVisible() { return m_bVisible; } void CXTPChartAxisConstantLine::OleSetVisible(BOOL bValue) { SetVisible(bValue); } BOOL CXTPChartAxisConstantLine::OleGetShowTextBelow() { return m_bShowTextBelow; } void CXTPChartAxisConstantLine::OleSetShowTextBelow(BOOL bValue) { ShowTextBelow(bValue); } BOOL CXTPChartAxisConstantLine::OleGetAlignment() { return m_nAlignment; } void CXTPChartAxisConstantLine::OleSetAlignment(int nValue) { SetAlignment((XTPChartStringAlignment)nValue); } LPDISPATCH CXTPChartAxisConstantLine::OleGetLineStyle() { return XTPGetDispatch(m_pLineStyle); } BSTR CXTPChartAxisConstantLine::OleGetText() { return m_strText.AllocSysString(); } void CXTPChartAxisConstantLine::OleSetText(LPCTSTR lpszText) { SetText(lpszText); } VARIANT CXTPChartAxisConstantLine::OleGetAxisValue() { VARIANT vt; if (!m_strAxisValue.IsEmpty()) { vt.vt = VT_BSTR; vt.bstrVal = m_strAxisValue.AllocSysString(); } else { vt.vt = VT_R8; vt.dblVal = m_dAxisValue; } return vt; } void CXTPChartAxisConstantLine::OleSetAxisValue(const VARIANT& var) { if (IsStringVariant(&var)) SetAxisValue(VariantToString(&var)); else SetAxisValue(VariantToDoubleEx(&var)); } LPDISPATCH CXTPChartAxisConstantLine::OleGetFont() { return XTPGetDispatch(m_pFont); } OLE_COLOR CXTPChartAxisConstantLine::OleGetColor() { return m_clrColor.ToOleColor(); } OLE_COLOR CXTPChartAxisConstantLine::OleGetTextColor() { return m_clrTextColor.ToOleColor(); } void CXTPChartAxisConstantLine::OleSetColor(OLE_COLOR clr) { SetColor(CXTPChartColor::FromOleColor(clr)); } void CXTPChartAxisConstantLine::OleSetTextColor(OLE_COLOR clr) { SetTextColor(CXTPChartColor::FromOleColor(clr)); } BEGIN_INTERFACE_MAP(CXTPChartAxisConstantLine, CXTPChartElement) INTERFACE_PART(CXTPChartAxisConstantLine, XTPDIID_ChartAxisConstantLine, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPChartAxisConstantLine, XTPDIID_ChartAxisConstantLine) ////////////////////////////////////////////////////////////////////////// // BEGIN_DISPATCH_MAP(CXTPChartAxisConstantLines, CXTPChartElement) DISP_FUNCTION_ID(CXTPChartAxisConstantLines, "Count", 1, OleGetItemCount, VT_I4, VTS_NONE) DISP_FUNCTION_ID(CXTPChartAxisConstantLines, "Item", DISPID_VALUE, OleGetItem, VT_DISPATCH, VTS_I4) DISP_FUNCTION_ID(CXTPChartAxisConstantLines, "_NewEnum", DISPID_NEWENUM, OleNewEnum, VT_UNKNOWN, VTS_NONE) DISP_FUNCTION_ID(CXTPChartAxisConstantLines, "Add", 2, OleAdd, VT_DISPATCH, VTS_WBSTR) DISP_FUNCTION_ID(CXTPChartAxisConstantLines, "DeleteAll", 5, RemoveAll, VT_EMPTY, VTS_NONE) END_DISPATCH_MAP() BEGIN_INTERFACE_MAP(CXTPChartAxisConstantLines, CXTPChartElement) INTERFACE_PART(CXTPChartAxisConstantLines, XTPDIID_ChartAxisConstantLines, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPChartAxisConstantLines, XTPDIID_ChartAxisConstantLines) long CXTPChartAxisConstantLines::OleGetItemCount() { return (long)GetCount(); } # pragma warning(push) # pragma warning(disable : 4702) LPDISPATCH CXTPChartAxisConstantLines::OleGetItem(long nIndex) { if (nIndex >= 0 && nIndex < GetCount()) { CXTPChartAxisConstantLine* pItem = GetAt(nIndex); return pItem->GetIDispatch(TRUE); } AfxThrowOleException(E_INVALIDARG); return 0; } # pragma warning(pop) LPDISPATCH CXTPChartAxisConstantLines::OleAdd(LPCOLESTR lpszConstantLine) { CXTPChartAxisConstantLine* pConstantLine = Add(new CXTPChartAxisConstantLine()); pConstantLine->SetText(lpszConstantLine); return XTPGetDispatch(pConstantLine); } IMPLEMENT_ENUM_VARIANT(CXTPChartAxisConstantLines) #endif