// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #include "pch.h" #include "OverflowTextBlock.h" #include "OverflowTextBlockAutomationPeer.h" using namespace CalculatorApp; using namespace CalculatorApp::Common; using namespace CalculatorApp::Controls; using namespace Platform; using namespace std; using namespace Windows::Foundation; using namespace Windows::Foundation::Collections; using namespace Windows::Devices::Input; using namespace Windows::UI::Xaml; using namespace Windows::UI::Xaml::Automation; using namespace Windows::UI::Xaml::Automation::Peers; using namespace Windows::UI::Xaml::Controls; using namespace Windows::UI::Xaml::Controls::Primitives; using namespace Windows::UI::Xaml::Data; using namespace Windows::UI::Xaml::Input; using namespace Windows::UI::Xaml::Media; using namespace Windows::UI::Xaml::Navigation; DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, IsActive); DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, TextStyle); DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, TokensUpdated); DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, ScrollButtonsWidth); DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, ScrollButtonsFontSize); DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, ScrollButtonsPlacement); static constexpr unsigned int SCROLL_BUTTONS_APPROXIMATION_RANGE = 4; static constexpr double SCROLL_RATIO = 0.7; void OverflowTextBlock::OnApplyTemplate() { UnregisterEventHandlers(); auto uiElement = GetTemplateChild("ExpressionContainer"); if (uiElement != nullptr) { m_expressionContainer = safe_cast(uiElement); m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr); m_containerViewChangedToken = m_expressionContainer->ViewChanged += ref new EventHandler(this, &OverflowTextBlock::OnViewChanged); } uiElement = GetTemplateChild("ExpressionContent"); if (uiElement != nullptr) { m_expressionContent = safe_cast(uiElement); } uiElement = GetTemplateChild("ScrollLeft"); if (uiElement != nullptr) { m_scrollLeft = safe_cast