mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 06:13:14 -07:00
- remove double scrollviewer
- optimize ExpressionTokens in StandardCalculatorViewModel to only update new tokens instead of the full list - refactor how we manage the visibility of left/right buttons - remove useless ExpressionItemContainerStyle - only modify accessbility view if necessary
This commit is contained in:
parent
7a48f66807
commit
319ac1ff12
11 changed files with 141 additions and 309 deletions
|
@ -129,6 +129,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() :
|
||||||
AreHistoryShortcutsEnabled = true;
|
AreHistoryShortcutsEnabled = true;
|
||||||
AreProgrammerRadixOperatorsEnabled = false;
|
AreProgrammerRadixOperatorsEnabled = false;
|
||||||
|
|
||||||
|
m_ExpressionTokens = ref new Vector<DisplayExpressionToken^>();
|
||||||
m_tokenPosition = -1;
|
m_tokenPosition = -1;
|
||||||
m_isLastOperationHistoryLoad = false;
|
m_isLastOperationHistoryLoad = false;
|
||||||
}
|
}
|
||||||
|
@ -321,61 +322,68 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr<CalculatorVector<
|
||||||
{
|
{
|
||||||
AreTokensUpdated = false;
|
AreTokensUpdated = false;
|
||||||
|
|
||||||
if (m_ExpressionTokens == nullptr)
|
|
||||||
{
|
|
||||||
m_ExpressionTokens = ref new Vector<DisplayExpressionToken^>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_ExpressionTokens->Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned int nTokens = 0;
|
unsigned int nTokens = 0;
|
||||||
tokens->GetSize(&nTokens);
|
tokens->GetSize(&nTokens);
|
||||||
|
|
||||||
|
if (nTokens == 0)
|
||||||
|
{
|
||||||
|
m_ExpressionTokens->Clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
pair <wstring, int> currentToken;
|
pair <wstring, int> currentToken;
|
||||||
const auto& localizer = LocalizationSettings::GetInstance();
|
const auto& localizer = LocalizationSettings::GetInstance();
|
||||||
|
|
||||||
|
const wstring separator = L" ";
|
||||||
for (unsigned int i = 0; i < nTokens; ++i)
|
for (unsigned int i = 0; i < nTokens; ++i)
|
||||||
{
|
{
|
||||||
if (SUCCEEDED(tokens->GetAt(i, ¤tToken)))
|
if (SUCCEEDED(tokens->GetAt(i, ¤tToken)))
|
||||||
{
|
{
|
||||||
Common::TokenType type;
|
Common::TokenType type;
|
||||||
const wstring separator = L" ";
|
|
||||||
bool isEditable = (currentToken.second == -1) ? false : true;
|
bool isEditable = (currentToken.second == -1) ? false : true;
|
||||||
localizer.LocalizeDisplayValue(&(currentToken.first));
|
localizer.LocalizeDisplayValue(&(currentToken.first));
|
||||||
|
|
||||||
if (!isEditable)
|
if (!isEditable)
|
||||||
{
|
{
|
||||||
if (currentToken.first == separator)
|
type = currentToken.first == separator ? TokenType::Separator : TokenType::Operator;
|
||||||
{
|
|
||||||
type = TokenType::Separator;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
type = TokenType::Operator;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
shared_ptr<IExpressionCommand> command;
|
shared_ptr<IExpressionCommand> command;
|
||||||
IFTPlatformException(m_commands->GetAt(static_cast<unsigned int>(currentToken.second), &command));
|
IFTPlatformException(m_commands->GetAt(static_cast<unsigned int>(currentToken.second), &command));
|
||||||
|
type = command->GetCommandType() == CommandType::OperandCommand ? TokenType::Operand : TokenType::Operator;
|
||||||
|
}
|
||||||
|
|
||||||
if (command->GetCommandType() == CommandType::OperandCommand)
|
auto currentTokenString = ref new String(currentToken.first.c_str());
|
||||||
|
auto expressionToken = ref new DisplayExpressionToken(currentTokenString, i, isEditable, type);
|
||||||
|
if (i < m_ExpressionTokens->Size)
|
||||||
{
|
{
|
||||||
type = TokenType::Operand;
|
auto existingItem = m_ExpressionTokens->GetAt(i);
|
||||||
|
if (type == existingItem->Type && expressionToken->Token->Equals(currentTokenString))
|
||||||
|
{
|
||||||
|
existingItem->TokenPosition = i;
|
||||||
|
existingItem->IsTokenEditable = isEditable;
|
||||||
|
existingItem->CommandIndex = expressionToken->CommandIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
type = TokenType::Operator;
|
m_ExpressionTokens->InsertAt(i, expressionToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
DisplayExpressionToken^ expressionToken = ref new DisplayExpressionToken(ref new String(currentToken.first.c_str()), i, isEditable, type);
|
else
|
||||||
|
{
|
||||||
m_ExpressionTokens->Append(expressionToken);
|
m_ExpressionTokens->Append(expressionToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (m_ExpressionTokens->Size != nTokens)
|
||||||
|
{
|
||||||
|
m_ExpressionTokens->RemoveAtEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String^ StandardCalculatorViewModel::GetCalculatorExpressionAutomationName()
|
String^ StandardCalculatorViewModel::GetCalculatorExpressionAutomationName()
|
||||||
{
|
{
|
||||||
String^ expression = L"";
|
String^ expression = L"";
|
||||||
|
|
|
@ -48,7 +48,7 @@ namespace CalculatorApp
|
||||||
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInError);
|
OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInError);
|
||||||
OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand);
|
OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand);
|
||||||
OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression);
|
OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression);
|
||||||
OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector<Common::DisplayExpressionToken^>^, ExpressionTokens);
|
OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector<Common::DisplayExpressionToken^>^, ExpressionTokens);
|
||||||
OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue);
|
OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue);
|
||||||
OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue);
|
OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue);
|
||||||
OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue);
|
OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue);
|
||||||
|
|
|
@ -246,7 +246,6 @@
|
||||||
<ClInclude Include="Converters\BitFlipAutomationNameConverter.h" />
|
<ClInclude Include="Converters\BitFlipAutomationNameConverter.h" />
|
||||||
<ClInclude Include="Converters\BooleanNegationConverter.h" />
|
<ClInclude Include="Converters\BooleanNegationConverter.h" />
|
||||||
<ClInclude Include="Converters\BooleanToVisibilityConverter.h" />
|
<ClInclude Include="Converters\BooleanToVisibilityConverter.h" />
|
||||||
<ClInclude Include="Converters\ExpressionItemContainerStyle.h" />
|
|
||||||
<ClInclude Include="Converters\ExpressionItemTemplateSelector.h" />
|
<ClInclude Include="Converters\ExpressionItemTemplateSelector.h" />
|
||||||
<ClInclude Include="Converters\ItemSizeToVisibilityConverter.h" />
|
<ClInclude Include="Converters\ItemSizeToVisibilityConverter.h" />
|
||||||
<ClInclude Include="Converters\RadixToStringConverter.h" />
|
<ClInclude Include="Converters\RadixToStringConverter.h" />
|
||||||
|
@ -380,7 +379,6 @@
|
||||||
<ClCompile Include="Converters\BitFlipAutomationNameConverter.cpp" />
|
<ClCompile Include="Converters\BitFlipAutomationNameConverter.cpp" />
|
||||||
<ClCompile Include="Converters\BooleanNegationConverter.cpp" />
|
<ClCompile Include="Converters\BooleanNegationConverter.cpp" />
|
||||||
<ClCompile Include="Converters\BooleanToVisibilityConverter.cpp" />
|
<ClCompile Include="Converters\BooleanToVisibilityConverter.cpp" />
|
||||||
<ClCompile Include="Converters\ExpressionItemContainerStyle.cpp" />
|
|
||||||
<ClCompile Include="Converters\ExpressionItemTemplateSelector.cpp" />
|
<ClCompile Include="Converters\ExpressionItemTemplateSelector.cpp" />
|
||||||
<ClCompile Include="Converters\ItemSizeToVisibilityConverter.cpp" />
|
<ClCompile Include="Converters\ItemSizeToVisibilityConverter.cpp" />
|
||||||
<ClCompile Include="Converters\RadixToStringConverter.cpp" />
|
<ClCompile Include="Converters\RadixToStringConverter.cpp" />
|
||||||
|
|
|
@ -243,9 +243,6 @@
|
||||||
<ClCompile Include="Converters\BooleanToVisibilityConverter.cpp">
|
<ClCompile Include="Converters\BooleanToVisibilityConverter.cpp">
|
||||||
<Filter>Converters</Filter>
|
<Filter>Converters</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="Converters\ExpressionItemContainerStyle.cpp">
|
|
||||||
<Filter>Converters</Filter>
|
|
||||||
</ClCompile>
|
|
||||||
<ClCompile Include="Converters\ExpressionItemTemplateSelector.cpp">
|
<ClCompile Include="Converters\ExpressionItemTemplateSelector.cpp">
|
||||||
<Filter>Converters</Filter>
|
<Filter>Converters</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
@ -342,9 +339,6 @@
|
||||||
<ClInclude Include="Converters\BooleanToVisibilityConverter.h">
|
<ClInclude Include="Converters\BooleanToVisibilityConverter.h">
|
||||||
<Filter>Converters</Filter>
|
<Filter>Converters</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="Converters\ExpressionItemContainerStyle.h">
|
|
||||||
<Filter>Converters</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="Converters\ExpressionItemTemplateSelector.h">
|
<ClInclude Include="Converters\ExpressionItemTemplateSelector.h">
|
||||||
<Filter>Converters</Filter>
|
<Filter>Converters</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
@ -34,7 +34,7 @@ void OverflowTextBlock::OnApplyTemplate()
|
||||||
|
|
||||||
m_expressionContainer = safe_cast<ScrollViewer^>(GetTemplateChild("expressionContainer"));
|
m_expressionContainer = safe_cast<ScrollViewer^>(GetTemplateChild("expressionContainer"));
|
||||||
m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr);
|
m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr);
|
||||||
|
m_expressionContainer->ViewChanged += ref new Windows::Foundation::EventHandler<Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs ^>(this, &CalculatorApp::Controls::OverflowTextBlock::OnViewChanged);
|
||||||
m_scrollLeft = safe_cast<Button^>(GetTemplateChild("scrollLeft"));
|
m_scrollLeft = safe_cast<Button^>(GetTemplateChild("scrollLeft"));
|
||||||
m_scrollRight = safe_cast<Button^>(GetTemplateChild("scrollRight"));
|
m_scrollRight = safe_cast<Button^>(GetTemplateChild("scrollRight"));
|
||||||
|
|
||||||
|
@ -44,12 +44,7 @@ void OverflowTextBlock::OnApplyTemplate()
|
||||||
m_scrollingLeft = false;
|
m_scrollingLeft = false;
|
||||||
m_scrollingRight = false;
|
m_scrollingRight = false;
|
||||||
|
|
||||||
auto borderContainer = safe_cast<Border^>(GetTemplateChild("expressionborder"));
|
m_itemsControl = safe_cast<ItemsControl^>(GetTemplateChild("TokenList"));
|
||||||
m_pointerEnteredEventToken = borderContainer->PointerEntered += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerEntered);
|
|
||||||
m_pointerExitedEventToken = borderContainer->PointerExited += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerExited);
|
|
||||||
|
|
||||||
m_listView = safe_cast<ListView^>(GetTemplateChild("TokenList"));
|
|
||||||
|
|
||||||
UpdateAllState();
|
UpdateAllState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,18 +55,19 @@ AutomationPeer^ OverflowTextBlock::OnCreateAutomationPeer()
|
||||||
|
|
||||||
void OverflowTextBlock::OnTokensUpdatedPropertyChanged(bool /*oldValue*/, bool newValue)
|
void OverflowTextBlock::OnTokensUpdatedPropertyChanged(bool /*oldValue*/, bool newValue)
|
||||||
{
|
{
|
||||||
if ((m_listView != nullptr) && (newValue))
|
if ((m_expressionContainer != nullptr) && (newValue))
|
||||||
{
|
{
|
||||||
unsigned int tokenCount = m_listView->Items->Size;
|
m_expressionContainer->UpdateLayout();
|
||||||
if (tokenCount > 0)
|
m_expressionContainer->ChangeView(m_expressionContainer->ScrollableWidth, nullptr, nullptr, true);
|
||||||
|
}
|
||||||
|
auto newIsAccessibilityViewControl = m_itemsControl != nullptr && m_itemsControl->Items->Size > 0;
|
||||||
|
if (m_isAccessibilityViewControl != newIsAccessibilityViewControl)
|
||||||
{
|
{
|
||||||
m_listView->UpdateLayout();
|
m_isAccessibilityViewControl = newIsAccessibilityViewControl;
|
||||||
m_listView->ScrollIntoView(m_listView->Items->GetAt(tokenCount - 1));
|
|
||||||
m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AutomationProperties::SetAccessibilityView(this,
|
AutomationProperties::SetAccessibilityView(this,
|
||||||
m_listView != nullptr && m_listView->Items->Size > 0 ? AccessibilityView::Control : AccessibilityView::Raw);
|
newIsAccessibilityViewControl ? AccessibilityView::Control : AccessibilityView::Raw);
|
||||||
|
}
|
||||||
|
UpdateScrollButtons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverflowTextBlock::UpdateAllState()
|
void OverflowTextBlock::UpdateAllState()
|
||||||
|
@ -128,26 +124,15 @@ void OverflowTextBlock::OnScrollClick(_In_ Object^ sender, _In_ RoutedEventArgs^
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OverflowTextBlock::OnPointerEntered(_In_ Object^, _In_ PointerRoutedEventArgs^ e)
|
|
||||||
{
|
|
||||||
if (e->Pointer->PointerDeviceType == PointerDeviceType::Mouse)
|
|
||||||
{
|
|
||||||
UpdateScrollButtons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OverflowTextBlock::OnPointerExited(_In_ Object^, _In_ PointerRoutedEventArgs^ e)
|
|
||||||
{
|
|
||||||
if (e->Pointer->PointerDeviceType == PointerDeviceType::Mouse)
|
|
||||||
{
|
|
||||||
UpdateScrollButtons();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void OverflowTextBlock::UpdateScrollButtons()
|
void OverflowTextBlock::UpdateScrollButtons()
|
||||||
{
|
{
|
||||||
|
if (m_itemsControl == nullptr && m_expressionContainer == nullptr)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// When the width is smaller than the container, don't show any
|
// When the width is smaller than the container, don't show any
|
||||||
if (m_listView->ActualWidth <= m_expressionContainer->ActualWidth)
|
if (m_itemsControl->ActualWidth <= m_expressionContainer->ActualWidth)
|
||||||
{
|
{
|
||||||
ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Collapsed);
|
ShowHideScrollButtons(::Visibility::Collapsed, ::Visibility::Collapsed);
|
||||||
}
|
}
|
||||||
|
@ -163,19 +148,25 @@ void OverflowTextBlock::UpdateScrollButtons()
|
||||||
if (m_scrollingLeft)
|
if (m_scrollingLeft)
|
||||||
{
|
{
|
||||||
m_scrollingLeft = false;
|
m_scrollingLeft = false;
|
||||||
|
if (m_scrollRight != nullptr)
|
||||||
|
{
|
||||||
m_scrollRight->Focus(::FocusState::Programmatic);
|
m_scrollRight->Focus(::FocusState::Programmatic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else // Width is larger than the container and right most part of the number is shown. Should be able to scroll left.
|
else // Width is larger than the container and right most part of the number is shown. Should be able to scroll left.
|
||||||
{
|
{
|
||||||
ShowHideScrollButtons(::Visibility::Visible, ::Visibility::Collapsed);
|
ShowHideScrollButtons(::Visibility::Visible, ::Visibility::Collapsed);
|
||||||
if (m_scrollingRight)
|
if (m_scrollingRight)
|
||||||
{
|
{
|
||||||
m_scrollingRight = false;
|
m_scrollingRight = false;
|
||||||
|
if (m_scrollLeft != nullptr)
|
||||||
|
{
|
||||||
m_scrollLeft->Focus(::FocusState::Programmatic);
|
m_scrollLeft->Focus(::FocusState::Programmatic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OverflowTextBlock::ShowHideScrollButtons(::Visibility vLeft, ::Visibility vRight)
|
void OverflowTextBlock::ShowHideScrollButtons(::Visibility vLeft, ::Visibility vRight)
|
||||||
{
|
{
|
||||||
|
@ -198,13 +189,10 @@ void OverflowTextBlock::UnregisterEventHandlers()
|
||||||
{
|
{
|
||||||
m_scrollRight->Click -= m_scrollRightClickEventToken;
|
m_scrollRight->Click -= m_scrollRightClickEventToken;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
auto borderContainer = safe_cast<Border^>(GetTemplateChild("expressionborder"));
|
|
||||||
|
|
||||||
// Adding an extra check, in case the returned template is null
|
void CalculatorApp::Controls::OverflowTextBlock::OnViewChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs ^args)
|
||||||
if (borderContainer != nullptr)
|
|
||||||
{
|
{
|
||||||
borderContainer->PointerEntered -= m_pointerEnteredEventToken;
|
UpdateScrollButtons();
|
||||||
borderContainer->PointerExited -= m_pointerExitedEventToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,15 +44,15 @@ namespace CalculatorApp
|
||||||
double scrollRatio = 0.7;
|
double scrollRatio = 0.7;
|
||||||
bool m_scrollingLeft;
|
bool m_scrollingLeft;
|
||||||
bool m_scrollingRight;
|
bool m_scrollingRight;
|
||||||
Windows::UI::Xaml::Controls::ListView^ m_listView;
|
bool m_isAccessibilityViewControl;
|
||||||
|
Windows::UI::Xaml::Controls::ItemsControl^ m_itemsControl;
|
||||||
Windows::UI::Xaml::Controls::ScrollViewer^ m_expressionContainer;
|
Windows::UI::Xaml::Controls::ScrollViewer^ m_expressionContainer;
|
||||||
Windows::UI::Xaml::Controls::Button^ m_scrollLeft;
|
Windows::UI::Xaml::Controls::Button^ m_scrollLeft;
|
||||||
Windows::UI::Xaml::Controls::Button^ m_scrollRight;
|
Windows::UI::Xaml::Controls::Button^ m_scrollRight;
|
||||||
|
|
||||||
Windows::Foundation::EventRegistrationToken m_scrollLeftClickEventToken;
|
Windows::Foundation::EventRegistrationToken m_scrollLeftClickEventToken;
|
||||||
Windows::Foundation::EventRegistrationToken m_scrollRightClickEventToken;
|
Windows::Foundation::EventRegistrationToken m_scrollRightClickEventToken;
|
||||||
Windows::Foundation::EventRegistrationToken m_pointerEnteredEventToken;
|
void OnViewChanged(Platform::Object ^sender, Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs ^args);
|
||||||
Windows::Foundation::EventRegistrationToken m_pointerExitedEventToken;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,44 +0,0 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
#include "pch.h"
|
|
||||||
#include "ExpressionItemContainerStyle.h"
|
|
||||||
#include "CalcViewModel/Common/DisplayExpressionToken.h"
|
|
||||||
|
|
||||||
using namespace CalculatorApp::Common;
|
|
||||||
|
|
||||||
namespace CalculatorApp
|
|
||||||
{
|
|
||||||
namespace Converters
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::Style^ ExpressionItemContainerStyle::SelectStyleCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container)
|
|
||||||
{
|
|
||||||
DisplayExpressionToken^ token = dynamic_cast<DisplayExpressionToken^>(item);
|
|
||||||
if (token != nullptr)
|
|
||||||
{
|
|
||||||
Common::TokenType type = token->Type;
|
|
||||||
|
|
||||||
switch (type)
|
|
||||||
{
|
|
||||||
case TokenType::Operator:
|
|
||||||
if (token->IsTokenEditable)
|
|
||||||
{
|
|
||||||
return m_editableOperatorStyle;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return m_nonEditableOperatorStyle;
|
|
||||||
}
|
|
||||||
case TokenType::Operand:
|
|
||||||
return m_operandStyle;
|
|
||||||
case TokenType::Separator:
|
|
||||||
return m_separatorStyle;
|
|
||||||
default:
|
|
||||||
throw ref new Platform::Exception(E_FAIL, L"Invalid token type");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return m_separatorStyle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,71 +0,0 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
// Licensed under the MIT License.
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace CalculatorApp
|
|
||||||
{
|
|
||||||
namespace Converters
|
|
||||||
{
|
|
||||||
[Windows::UI::Xaml::Data::Bindable]
|
|
||||||
public ref class ExpressionItemContainerStyle sealed : public Windows::UI::Xaml::Controls::StyleSelector
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual Windows::UI::Xaml::Style^ SelectStyleCore(Platform::Object^ item, Windows::UI::Xaml::DependencyObject^ container) override;
|
|
||||||
|
|
||||||
property Windows::UI::Xaml::Style^ EditableOperatorStyle
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::Style^ get()
|
|
||||||
{
|
|
||||||
return m_editableOperatorStyle;
|
|
||||||
}
|
|
||||||
void set(Windows::UI::Xaml::Style^ val)
|
|
||||||
{
|
|
||||||
m_editableOperatorStyle = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
property Windows::UI::Xaml::Style^ OperandStyle
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::Style^ get()
|
|
||||||
{
|
|
||||||
return m_operandStyle;
|
|
||||||
}
|
|
||||||
void set(Windows::UI::Xaml::Style^ val)
|
|
||||||
{
|
|
||||||
m_operandStyle = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
property Windows::UI::Xaml::Style^ SeparatorStyle
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::Style^ get()
|
|
||||||
{
|
|
||||||
return m_separatorStyle;
|
|
||||||
}
|
|
||||||
void set(Windows::UI::Xaml::Style^ val)
|
|
||||||
{
|
|
||||||
m_separatorStyle = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
property Windows::UI::Xaml::Style^ NonEditableOperatorStyle
|
|
||||||
{
|
|
||||||
Windows::UI::Xaml::Style^ get()
|
|
||||||
{
|
|
||||||
return m_nonEditableOperatorStyle;
|
|
||||||
}
|
|
||||||
void set(Windows::UI::Xaml::Style^ val)
|
|
||||||
{
|
|
||||||
m_nonEditableOperatorStyle = val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Windows::UI::Xaml::Style^ m_editableOperatorStyle;
|
|
||||||
Windows::UI::Xaml::Style^ m_nonEditableOperatorStyle;
|
|
||||||
Windows::UI::Xaml::Style^ m_operandStyle;
|
|
||||||
Windows::UI::Xaml::Style^ m_separatorStyle;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,7 +8,6 @@
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:local="using:CalculatorApp"
|
xmlns:local="using:CalculatorApp"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:model="using:CalculatorApp.ViewModel"
|
|
||||||
Loaded="OnLoaded"
|
Loaded="OnLoaded"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
|
@ -19,20 +18,20 @@
|
||||||
<TextBlock Margin="2,0,0,0"
|
<TextBlock Margin="2,0,0,0"
|
||||||
Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
|
Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
|
||||||
IsTextScaleFactorEnabled="False"
|
IsTextScaleFactorEnabled="False"
|
||||||
Text="{Binding Token, Mode=OneWay}"/>
|
Text="{x:Bind Token}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate x:Key="Operator" x:DataType="common:DisplayExpressionToken">
|
<DataTemplate x:Key="Operator" x:DataType="common:DisplayExpressionToken">
|
||||||
<TextBlock Margin="2,0,0,0"
|
<TextBlock Margin="2,0,0,0"
|
||||||
Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
|
Foreground="{ThemeResource SystemControlPageTextBaseMediumBrush}"
|
||||||
IsTextScaleFactorEnabled="False"
|
IsTextScaleFactorEnabled="False"
|
||||||
Text="{Binding Token, Mode=OneWay}"/>
|
Text="{x:Bind Token}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<DataTemplate x:Key="Separator" x:DataType="common:DisplayExpressionToken">
|
<DataTemplate x:Key="Separator" x:DataType="common:DisplayExpressionToken">
|
||||||
<TextBlock x:Name="MainText"
|
<TextBlock x:Name="MainText"
|
||||||
IsTextScaleFactorEnabled="False"
|
IsTextScaleFactorEnabled="False"
|
||||||
Text="{Binding Token, Mode=OneWay}"/>
|
Text="{x:Bind Token}"/>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
|
|
||||||
<!-- TextBox Styles -->
|
<!-- TextBox Styles -->
|
||||||
|
@ -141,7 +140,6 @@
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
<ControlTemplate TargetType="controls:OverflowTextBlock">
|
<ControlTemplate TargetType="controls:OverflowTextBlock">
|
||||||
<Border x:Name="expressionborder" Background="Transparent">
|
|
||||||
<Grid x:Name="tokenContainer" Background="{TemplateBinding Background}">
|
<Grid x:Name="tokenContainer" Background="{TemplateBinding Background}">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition Width="12"/>
|
<ColumnDefinition Width="12"/>
|
||||||
|
@ -153,33 +151,23 @@
|
||||||
Padding="0,0,0,0"
|
Padding="0,0,0,0"
|
||||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||||
Style="{StaticResource ResultsScrollerSnapped}"
|
Style="{StaticResource ResultsScrollerSnapped}"
|
||||||
AutomationProperties.AccessibilityView="Raw"
|
AutomationProperties.AccessibilityView="Raw">
|
||||||
LayoutUpdated="expressionContainer_LayoutUpdated">
|
<ItemsControl x:Name="TokenList"
|
||||||
<ListView x:Name="TokenList"
|
|
||||||
Padding="0"
|
Padding="0"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
HorizontalContentAlignment="Right"
|
HorizontalContentAlignment="Right"
|
||||||
VerticalContentAlignment="Stretch"
|
VerticalContentAlignment="Stretch"
|
||||||
IsTabStop="False"
|
IsTabStop="False"
|
||||||
ItemContainerStyleSelector="{StaticResource ExpressionItemContainerStyle}"
|
|
||||||
ItemTemplateSelector="{StaticResource ExpressionItemTemplateSelector}"
|
ItemTemplateSelector="{StaticResource ExpressionItemTemplateSelector}"
|
||||||
ItemsSource="{Binding ExpressionTokens}"
|
ItemsSource="{Binding ExpressionTokens}">
|
||||||
ScrollViewer.HorizontalScrollBarVisibility="Hidden"
|
<ItemsControl.ItemsPanel>
|
||||||
ScrollViewer.HorizontalScrollMode="Enabled"
|
|
||||||
ScrollViewer.VerticalScrollBarVisibility="Disabled"
|
|
||||||
ScrollViewer.VerticalScrollMode="Disabled"
|
|
||||||
SelectionMode="None">
|
|
||||||
<ListView.ItemsPanel>
|
|
||||||
<ItemsPanelTemplate>
|
<ItemsPanelTemplate>
|
||||||
<StackPanel HorizontalAlignment="Right"
|
<ItemsStackPanel HorizontalAlignment="Right"
|
||||||
VerticalAlignment="Stretch"
|
VerticalAlignment="Stretch"
|
||||||
Orientation="Horizontal"/>
|
Orientation="Horizontal"/>
|
||||||
</ItemsPanelTemplate>
|
</ItemsPanelTemplate>
|
||||||
</ListView.ItemsPanel>
|
</ItemsControl.ItemsPanel>
|
||||||
<ListView.ItemContainerTransitions>
|
</ItemsControl>
|
||||||
<TransitionCollection/>
|
|
||||||
</ListView.ItemContainerTransitions>
|
|
||||||
</ListView>
|
|
||||||
</ScrollViewer>
|
</ScrollViewer>
|
||||||
<Button x:Name="scrollLeft"
|
<Button x:Name="scrollLeft"
|
||||||
x:Uid="scrollLeft"
|
x:Uid="scrollLeft"
|
||||||
|
@ -200,7 +188,6 @@
|
||||||
Glyph=""/>
|
Glyph=""/>
|
||||||
</Button>
|
</Button>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
</Setter.Value>
|
</Setter.Value>
|
||||||
</Setter>
|
</Setter>
|
||||||
|
@ -239,21 +226,6 @@
|
||||||
</Setter>
|
</Setter>
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
<Style x:Key="NonEditableOperatorContainerStyle"
|
|
||||||
BasedOn="{StaticResource ExpressionBaseContainerStyle}"
|
|
||||||
TargetType="ListViewItem">
|
|
||||||
<Setter Property="IsHitTestVisible" Value="False"/>
|
|
||||||
<Setter Property="IsTabStop" Value="False"/>
|
|
||||||
<Setter Property="MinWidth" Value="4"/>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<Style x:Key="EditableOperatorContainerStyle"
|
|
||||||
BasedOn="{StaticResource ExpressionBaseContainerStyle}"
|
|
||||||
TargetType="ListViewItem">
|
|
||||||
<Setter Property="IsHitTestVisible" Value="True"/>
|
|
||||||
<Setter Property="MinWidth" Value="32"/>
|
|
||||||
</Style>
|
|
||||||
|
|
||||||
<!-- Calculation Result Styles -->
|
<!-- Calculation Result Styles -->
|
||||||
|
|
||||||
<Style x:Key="ResultsStyleL"
|
<Style x:Key="ResultsStyleL"
|
||||||
|
@ -443,12 +415,6 @@
|
||||||
OperatorTemplate="{StaticResource Operator}"
|
OperatorTemplate="{StaticResource Operator}"
|
||||||
SeparatorTemplate="{StaticResource Separator}"/>
|
SeparatorTemplate="{StaticResource Separator}"/>
|
||||||
|
|
||||||
<converters:ExpressionItemContainerStyle x:Key="ExpressionItemContainerStyle"
|
|
||||||
EditableOperatorStyle="{StaticResource NonEditableOperatorContainerStyle}"
|
|
||||||
NonEditableOperatorStyle="{StaticResource NonEditableOperatorContainerStyle}"
|
|
||||||
OperandStyle="{StaticResource NonEditableOperatorContainerStyle}"
|
|
||||||
SeparatorStyle="{StaticResource NonEditableOperatorContainerStyle}"/>
|
|
||||||
|
|
||||||
<!-- Miscellaneous Resources -->
|
<!-- Miscellaneous Resources -->
|
||||||
|
|
||||||
<automation:NarratorNotifier x:Name="NarratorNotifier" Announcement="{x:Bind Model.Announcement, Mode=OneWay}"/>
|
<automation:NarratorNotifier x:Name="NarratorNotifier" Announcement="{x:Bind Model.Announcement, Mode=OneWay}"/>
|
||||||
|
@ -649,7 +615,7 @@
|
||||||
AutomationProperties.AutomationId="CalculatorExpression"
|
AutomationProperties.AutomationId="CalculatorExpression"
|
||||||
AutomationProperties.Name="{x:Bind Model.CalculationExpressionAutomationName, Mode=OneWay}"
|
AutomationProperties.Name="{x:Bind Model.CalculationExpressionAutomationName, Mode=OneWay}"
|
||||||
IsTabStop="False"
|
IsTabStop="False"
|
||||||
TokensUpdated="{Binding AreTokensUpdated, Mode=OneWay}"/>
|
TokensUpdated="{x:Bind Model.AreTokensUpdated, Mode=OneWay}"/>
|
||||||
|
|
||||||
<!-- Programmer display panel controls -->
|
<!-- Programmer display panel controls -->
|
||||||
<local:CalculatorProgrammerOperators x:Name="ProgrammerOperators"
|
<local:CalculatorProgrammerOperators x:Name="ProgrammerOperators"
|
||||||
|
|
|
@ -685,11 +685,6 @@ void Calculator::OnHistoryFlyOutTapped(_In_ Object^ sender, _In_ TappedRoutedEve
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Calculator::expressionContainer_LayoutUpdated(_In_ Object^ sender, _In_ Object^ e)
|
|
||||||
{
|
|
||||||
expressionText->UpdateScrollButtons();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Calculator::IsValidRegularExpression(std::wstring str)
|
bool Calculator::IsValidRegularExpression(std::wstring str)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
|
@ -1,11 +1,10 @@
|
||||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
// Licensed under the MIT License.
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Views/Calculator.g.h"
|
#include "Views/Calculator.g.h"
|
||||||
#include "Converters/BooleanNegationConverter.h"
|
#include "Converters/BooleanNegationConverter.h"
|
||||||
#include "Converters/ExpressionItemContainerStyle.h"
|
|
||||||
#include "Converters/ExpressionItemTemplateSelector.h"
|
#include "Converters/ExpressionItemTemplateSelector.h"
|
||||||
#include "Converters/VisibilityNegationConverter.h"
|
#include "Converters/VisibilityNegationConverter.h"
|
||||||
#include "CalcViewModel/Common/Automation/NarratorNotifier.h"
|
#include "CalcViewModel/Common/Automation/NarratorNotifier.h"
|
||||||
|
@ -130,7 +129,6 @@ namespace CalculatorApp
|
||||||
void EnableMemoryControls(bool enable);
|
void EnableMemoryControls(bool enable);
|
||||||
void OnMemoryFlyOutTapped(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
void OnMemoryFlyOutTapped(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
||||||
void OnHistoryFlyOutTapped(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
void OnHistoryFlyOutTapped(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
||||||
void expressionContainer_LayoutUpdated(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
|
|
||||||
bool IsValidRegularExpression(std::wstring str);
|
bool IsValidRegularExpression(std::wstring str);
|
||||||
void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
void DockPanelTapped(_In_ Windows::UI::Xaml::Input::TappedRoutedEventArgs^ e);
|
||||||
void OnResultsLayoutChanged(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
|
void OnResultsLayoutChanged(_In_ Platform::Object^ sender, _In_ Platform::Object^ e);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue