/** * @file XTPGaugeStateType.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/Base/Diagnostic/XTPDisableAdvancedWarnings.h" #include #include "Common/Base/Diagnostic/XTPEnableAdvancedWarnings.h" #include "Common/XTPTypeId.h" #include "Common/XTPCasting.h" #include "Common/XTPFramework.h" #include "Common/XTPSystemHelpers.h" #include "Common/XTPSynchro.h" #include "Common/XTPApplication.h" #include "Common/XTPSingleton.h" #include "Markup/XTPMarkupObject.h" #include "Markup/XTPMarkupContext.h" #include "Gauge/XTPGaugeBaseType.h" #include "Gauge/Types/XTPGaugeStateType.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # undef THIS_FILE static char THIS_FILE[] = __FILE__; # define new DEBUG_NEW #endif IMPLEMENT_DYNCREATE(CXTPGaugeStateType, CXTPGaugeBaseType); CXTPGaugeStateType::CXTPGaugeStateType() : m_pState(NULL) , m_nStateCount(UINT_MAX) , m_bInSetState(FALSE) { } CXTPGaugeStateType::~CXTPGaugeStateType() { SAFE_DELETE(m_pState); } LPCWSTR CXTPGaugeStateType::GetTypeName() const { return L"State"; } UINT CXTPGaugeStateType::GetState() const { COleVariant v; HRESULT hr = GetTrait(_T("state"), v); if (FAILED(hr)) AfxThrowOleException(hr); v.ChangeType(VT_UI4); if (NULL == m_pState) m_pState = new UINT(v.uintVal); else *m_pState = v.uintVal; return v.uintVal; } BOOL CXTPGaugeStateType::SetState(UINT nState) { if (nState == (NULL != m_pState ? *m_pState : GetState())) return FALSE; HRESULT hr = SetTrait(_T("state"), static_cast(nState)); if (FAILED(hr)) AfxThrowOleException(hr); try { m_bInSetState = TRUE; if (NULL == m_pState) m_pState = new UINT(nState); else *m_pState = nState; if (IsAutomaticUpdateEnabled()) Update(); m_bInSetState = FALSE; } catch (...) { m_bInSetState = FALSE; throw; } return TRUE; } UINT CXTPGaugeStateType::GetStateCount() const { if (UINT_MAX != m_nStateCount) return m_nStateCount; COleVariant v; HRESULT hr = GetTrait(_T("states.length"), v); if (FAILED(hr)) AfxThrowOleException(hr); v.ChangeType(VT_UI4); m_nStateCount = v.uintVal; return m_nStateCount; } void CXTPGaugeStateType::OnUpdate() { if (m_bInSetState) return; // Required to save m_pState GetState(); }