/** * @file XTPMarkupButtonBase.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/XTPWinThemeWrapper.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/XTPMarkupControl.h" #include "Markup/Controls/XTPMarkupContentControl.h" #include "Markup/Controls/XTPMarkupButtonBase.h" #include "Markup/XTPMarkupRoutedEvent.h" #include "Markup/XTPMarkupRoutedEventArgs.h" #include "Markup/XTPMarkupMouseEventArgs.h" #include "Markup/XTPMarkupMouseButtonEventArgs.h" #include "Markup/XTPMarkupDelegate.h" #include "Markup/XTPMarkupIIDs.h" #include "Common/Base/Diagnostic/XTPDisableNoisyWarnings.h" #ifdef _DEBUG # define new DEBUG_NEW # undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ////////////////////////////////////////////////////////////////////////// // CXTPMarkupButtonBase CXTPMarkupRoutedEvent* CXTPMarkupButtonBase::m_pClickEvent = NULL; CXTPMarkupDependencyProperty* CXTPMarkupButtonBase::m_pIsPressedProperty = NULL; IMPLEMENT_MARKUPCLASS(NULL, CXTPMarkupButtonBase, CXTPMarkupContentControl) void CXTPMarkupButtonBase::RegisterMarkupClass() { m_pClickEvent = CXTPMarkupRoutedEvent::RegisterRoutedEvent(L"Click", CXTPMarkupRoutedEvent::routingBubble, MARKUP_TYPE(CXTPMarkupButtonBase)); m_pIsPressedProperty = CXTPMarkupDependencyProperty::Register( L"IsPressed", MARKUP_TYPE(CXTPMarkupBool), MARKUP_TYPE(CXTPMarkupButtonBase), new CXTPMarkupPropertyMetadata(CXTPMarkupBool::CreateFalseValue(), CXTPMarkupPropertyMetadata::flagAffectsArrange)); } CXTPMarkupButtonBase::CXTPMarkupButtonBase() : m_bPushed(FALSE) , m_bMouseOver(FALSE) , m_pClick(NULL) { m_themeButton = new CXTPWinThemeWrapper(); SetValue(m_pFocusableProperty, CXTPMarkupBool::CreateTrueValue()); } CXTPMarkupButtonBase::~CXTPMarkupButtonBase() { SAFE_DELETE(m_themeButton); MARKUP_RELEASE(m_pClick); } void CXTPMarkupButtonBase::OnMouseLeave(CXTPMarkupMouseEventArgs* e) { m_bMouseOver = FALSE; if (m_bPushed) { SetValue(m_pIsPressedProperty, NULL); } else { CXTPMarkupContentControl::OnMouseLeave(e); InvalidateVisual(); } } void CXTPMarkupButtonBase::OnMouseEnter(CXTPMarkupMouseEventArgs* e) { m_bMouseOver = TRUE; if (m_bPushed) { SetValue(m_pIsPressedProperty, CXTPMarkupBool::CreateTrueValue()); } else { CXTPMarkupContentControl::OnMouseEnter(e); InvalidateVisual(); } } void CXTPMarkupButtonBase::OnLostMouseCapture(CXTPMarkupMouseEventArgs* /*e*/) { SetPressed(FALSE); } void CXTPMarkupButtonBase::SetPressed(BOOL bPressed) { if (!bPressed && m_bPushed) { m_bPushed = FALSE; SetValue(m_pIsPressedProperty, NULL); if (!m_bMouseOver && IsMouseOver()) { SetValue(m_pIsMouseOverProperty, NULL); InvalidateVisual(); } } else if (bPressed && !m_bPushed) { m_bPushed = TRUE; SetValue(m_pIsPressedProperty, CXTPMarkupBool::CreateTrueValue()); } } void CXTPMarkupButtonBase::OnMouseLeftButtonUp(CXTPMarkupMouseButtonEventArgs* e) { if (m_bPushed) { ReleaseMouseCapture(); SetPressed(FALSE); if (m_bMouseOver) { OnClick(); } e->SetHandled(); } } void CXTPMarkupButtonBase::OnMouseLeftButtonDown(CXTPMarkupMouseButtonEventArgs* e) { e->SetHandled(); if (!IsEnabled()) return; Focus(); SetPressed(TRUE); CaptureMouse(); } void CXTPMarkupButtonBase::OnClick() { CXTPMarkupRoutedEventArgs* e = new CXTPMarkupRoutedEventArgs(m_pClickEvent, this); RaiseEvent(e); e->Release(); } BOOL CXTPMarkupButtonBase::IsPressed() const { CXTPMarkupBool* pValue = MARKUP_DYNAMICCAST(CXTPMarkupBool, GetValue(m_pIsPressedProperty)); return (NULL != pValue ? (BOOL)*pValue : FALSE); } void CXTPMarkupButtonBase::UseParentBackground(HDC destHdc, HDC srcHdc, CRect srcRect) const { ::BitBlt(destHdc, 0, 0, srcRect.Width(), srcRect.Height(), srcHdc, srcRect.left, srcRect.top, SRCCOPY); } #include "Common/Base/Diagnostic/XTPBeginAfxMap.h" BEGIN_DISPATCH_MAP(CXTPMarkupButtonBase, CXTPMarkupContentControl) DISP_PROPERTY_EX_ID(CXTPMarkupButtonBase, "IsPressed", 700, OleGetIsPressed, OleSetIsPressed, VT_BOOL) DISP_PROPERTY_EX_ID(CXTPMarkupButtonBase, "ClickEvent", 701, OleGetClickEvent, SetNotSupported, VT_DISPATCH) DISP_PROPERTY_EX_ID(CXTPMarkupButtonBase, "Click", 1701, OleGetClick, OleSetClick, VT_DISPATCH) END_DISPATCH_MAP() #include "Common/Base/Diagnostic/XTPEndAfxMap.h" #ifdef _XTP_ACTIVEX BEGIN_INTERFACE_MAP(CXTPMarkupButtonBase, CXTPMarkupFrameworkElement) INTERFACE_PART(CXTPMarkupButtonBase, XTPDIID_MarkupButtonBase, Dispatch) END_INTERFACE_MAP() IMPLEMENT_OLETYPELIB_EX(CXTPMarkupButtonBase, XTPDIID_MarkupButtonBase) #endif BOOL CXTPMarkupButtonBase::OleGetIsPressed() { return IsPressed(); } void CXTPMarkupButtonBase::OleSetIsPressed(BOOL /*bNewValue*/) { } LPDISPATCH CXTPMarkupButtonBase::OleGetClickEvent() { return XTPGetDispatch(m_pClickEvent); } LPDISPATCH CXTPMarkupButtonBase::OleGetClick() { return GetDispDelegate(m_pClick); } void CXTPMarkupButtonBase::OleSetClick(LPDISPATCH pDisp) { SetDispDelegate(m_pClick, m_pClickEvent, pDisp); }