diff --git a/src/CalcManager/CEngine/CalcInput.cpp b/src/CalcManager/CEngine/CalcInput.cpp index 45e553b9..1c47a8da 100644 --- a/src/CalcManager/CEngine/CalcInput.cpp +++ b/src/CalcManager/CEngine/CalcInput.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include #include "Header Files/CalcEngine.h" using namespace std; diff --git a/src/CalcManager/CEngine/CalcUtils.cpp b/src/CalcManager/CEngine/CalcUtils.cpp index 7980e4e0..15b11926 100644 --- a/src/CalcManager/CEngine/CalcUtils.cpp +++ b/src/CalcManager/CEngine/CalcUtils.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" #include "Header Files/CalcEngine.h" #include "Header Files/CalcUtils.h" diff --git a/src/CalcManager/CEngine/History.cpp b/src/CalcManager/CEngine/History.cpp index ca276a41..74edf3cc 100644 --- a/src/CalcManager/CEngine/History.cpp +++ b/src/CalcManager/CEngine/History.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" #include "Header Files/CalcEngine.h" #include "Command.h" #include "CalculatorVector.h" diff --git a/src/CalcManager/CEngine/Number.cpp b/src/CalcManager/CEngine/Number.cpp index 4bf83a33..fdf29e09 100644 --- a/src/CalcManager/CEngine/Number.cpp +++ b/src/CalcManager/CEngine/Number.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. -#include "pch.h" +#include #include "Header Files/Number.h" using namespace std; diff --git a/src/CalcManager/CEngine/Rational.cpp b/src/CalcManager/CEngine/Rational.cpp index c93c79a6..e116c237 100644 --- a/src/CalcManager/CEngine/Rational.cpp +++ b/src/CalcManager/CEngine/Rational.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. -#include "pch.h" +#include #include "Header Files/Rational.h" using namespace std; diff --git a/src/CalcManager/CEngine/RationalMath.cpp b/src/CalcManager/CEngine/RationalMath.cpp index f5de74fc..4b1a4b8a 100644 --- a/src/CalcManager/CEngine/RationalMath.cpp +++ b/src/CalcManager/CEngine/RationalMath.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" #include "Header Files/RationalMath.h" using namespace std; diff --git a/src/CalcManager/CEngine/calc.cpp b/src/CalcManager/CEngine/calc.cpp index 0e4979f2..65e6f0d0 100644 --- a/src/CalcManager/CEngine/calc.cpp +++ b/src/CalcManager/CEngine/calc.cpp @@ -1,9 +1,8 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include #include "Header Files/CalcEngine.h" - #include "CalculatorResource.h" using namespace std; diff --git a/src/CalcManager/CEngine/scicomm.cpp b/src/CalcManager/CEngine/scicomm.cpp index 4e0322d0..36130bb5 100644 --- a/src/CalcManager/CEngine/scicomm.cpp +++ b/src/CalcManager/CEngine/scicomm.cpp @@ -12,7 +12,8 @@ * * Author: \****************************************************************************/ -#include "pch.h" + +#include #include "Header Files/CalcEngine.h" #include "Header Files/CalcUtils.h" diff --git a/src/CalcManager/CEngine/scidisp.cpp b/src/CalcManager/CEngine/scidisp.cpp index 849fe863..1ef88799 100644 --- a/src/CalcManager/CEngine/scidisp.cpp +++ b/src/CalcManager/CEngine/scidisp.cpp @@ -12,7 +12,9 @@ * * Author: \****************************************************************************/ -#include "pch.h" + +#include +#include #include "Header Files/CalcEngine.h" using namespace std; diff --git a/src/CalcManager/CEngine/scifunc.cpp b/src/CalcManager/CEngine/scifunc.cpp index a1007c1c..c2341752 100644 --- a/src/CalcManager/CEngine/scifunc.cpp +++ b/src/CalcManager/CEngine/scifunc.cpp @@ -16,7 +16,6 @@ /*** ***/ /*** ***/ /**************************************************************************/ -#include "pch.h" #include "Header Files/CalcEngine.h" using namespace std; diff --git a/src/CalcManager/CEngine/scioper.cpp b/src/CalcManager/CEngine/scioper.cpp index 9ced7021..f8d04855 100644 --- a/src/CalcManager/CEngine/scioper.cpp +++ b/src/CalcManager/CEngine/scioper.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" #include "Header Files/CalcEngine.h" using namespace CalcEngine; diff --git a/src/CalcManager/CEngine/sciset.cpp b/src/CalcManager/CEngine/sciset.cpp index 5495748e..ca715be5 100644 --- a/src/CalcManager/CEngine/sciset.cpp +++ b/src/CalcManager/CEngine/sciset.cpp @@ -1,7 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" #include "Header Files/CalcEngine.h" using namespace CalcEngine; diff --git a/src/CalcManager/CalcManager.vcxproj b/src/CalcManager/CalcManager.vcxproj index 4a098141..4d03a5c9 100644 --- a/src/CalcManager/CalcManager.vcxproj +++ b/src/CalcManager/CalcManager.vcxproj @@ -157,6 +157,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -173,6 +174,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -189,6 +191,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -205,6 +208,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -222,6 +226,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -238,6 +243,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -254,6 +260,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -270,6 +277,7 @@ $(SolutionDir)..\src\;%(AdditionalIncludeDirectories) Level4 true + pch.h Console @@ -278,7 +286,6 @@ - diff --git a/src/CalcManager/CalculatorHistory.cpp b/src/CalcManager/CalculatorHistory.cpp index 31a1dae2..935ea8da 100644 --- a/src/CalcManager/CalculatorHistory.cpp +++ b/src/CalcManager/CalculatorHistory.cpp @@ -1,7 +1,7 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include #include "CalculatorHistory.h" using namespace std; diff --git a/src/CalcManager/CalculatorManager.cpp b/src/CalcManager/CalculatorManager.cpp index d5bbd029..e640bd94 100644 --- a/src/CalcManager/CalculatorManager.cpp +++ b/src/CalcManager/CalculatorManager.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include // for UCHAR_MAX #include "Header Files/CalcEngine.h" #include "CalculatorManager.h" #include "CalculatorResource.h" diff --git a/src/CalcManager/CalculatorVector.h b/src/CalcManager/CalculatorVector.h index a4de434d..e9f1b8dc 100644 --- a/src/CalcManager/CalculatorVector.h +++ b/src/CalcManager/CalculatorVector.h @@ -1,9 +1,14 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once +#include +#include +#include #include "Ratpack/CalcErr.h" +#include // for std::out_of_range +#include // for SAL template class CalculatorVector diff --git a/src/CalcManager/Command.h b/src/CalcManager/Command.h index e6eeb8ac..4d98d012 100644 --- a/src/CalcManager/Command.h +++ b/src/CalcManager/Command.h @@ -1,4 +1,4 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once diff --git a/src/CalcManager/ExpressionCommand.cpp b/src/CalcManager/ExpressionCommand.cpp index 0b68a374..9fc87708 100644 --- a/src/CalcManager/ExpressionCommand.cpp +++ b/src/CalcManager/ExpressionCommand.cpp @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include #include "Header Files/CCommand.h" #include "CalculatorVector.h" #include "ExpressionCommand.h" diff --git a/src/CalcManager/ExpressionCommandInterface.h b/src/CalcManager/ExpressionCommandInterface.h index ce89dd81..94bae836 100644 --- a/src/CalcManager/ExpressionCommandInterface.h +++ b/src/CalcManager/ExpressionCommandInterface.h @@ -1,7 +1,9 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. #pragma once + +#include // for std::shared_ptr #include "CalculatorVector.h" #include "Command.h" diff --git a/src/CalcManager/Header Files/CCommand.h b/src/CalcManager/Header Files/CCommand.h index 2fc08b3c..9530b5c5 100644 --- a/src/CalcManager/Header Files/CCommand.h +++ b/src/CalcManager/Header Files/CCommand.h @@ -13,6 +13,8 @@ * \****************************************************************************/ +#pragma once + // The following are the valid id's which can be passed to CCalcEngine::ProcessCommand #define IDM_HEX 313 diff --git a/src/CalcManager/Header Files/EngineStrings.h b/src/CalcManager/Header Files/EngineStrings.h index 37f11483..89d624bf 100644 --- a/src/CalcManager/Header Files/EngineStrings.h +++ b/src/CalcManager/Header Files/EngineStrings.h @@ -13,6 +13,11 @@ * Created: 13-Feb-2008 * \****************************************************************************/ + +#pragma once + +#include + inline constexpr auto IDS_ERRORS_FIRST = 99; // This is the list of error strings corresponding to SCERR_DIVIDEZERO.. diff --git a/src/CalcManager/Header Files/History.h b/src/CalcManager/Header Files/History.h index 4f82088f..7446616d 100644 --- a/src/CalcManager/Header Files/History.h +++ b/src/CalcManager/Header Files/History.h @@ -3,6 +3,7 @@ #pragma once +#include #include "ICalcDisplay.h" #include "IHistoryDisplay.h" #include "Rational.h" diff --git a/src/CalcManager/Header Files/Number.h b/src/CalcManager/Header Files/Number.h index c67aa108..769e3acf 100644 --- a/src/CalcManager/Header Files/Number.h +++ b/src/CalcManager/Header Files/Number.h @@ -3,6 +3,7 @@ #pragma once +#include #include "Ratpack/ratpak.h" namespace CalcEngine diff --git a/src/CalcManager/Ratpack/basex.cpp b/src/CalcManager/Ratpack/basex.cpp index 97a29dd4..2685af87 100644 --- a/src/CalcManager/Ratpack/basex.cpp +++ b/src/CalcManager/Ratpack/basex.cpp @@ -14,8 +14,8 @@ // internal base is a power of 2. // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" +#include // for memmove void _mulnumx( PNUMBER *pa, PNUMBER b ); diff --git a/src/CalcManager/Ratpack/conv.cpp b/src/CalcManager/Ratpack/conv.cpp index c25d4481..3a1aaa14 100644 --- a/src/CalcManager/Ratpack/conv.cpp +++ b/src/CalcManager/Ratpack/conv.cpp @@ -17,7 +17,10 @@ // //--------------------------------------------------------------------------- -#include "pch.h" +#include +#include +#include +#include // for memmove, memcpy #include "ratpak.h" using namespace std; diff --git a/src/CalcManager/Ratpack/exp.cpp b/src/CalcManager/Ratpack/exp.cpp index 95637404..e4939db4 100644 --- a/src/CalcManager/Ratpack/exp.cpp +++ b/src/CalcManager/Ratpack/exp.cpp @@ -14,7 +14,6 @@ // // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/Ratpack/fact.cpp b/src/CalcManager/Ratpack/fact.cpp index 276151ae..bdcbccb0 100644 --- a/src/CalcManager/Ratpack/fact.cpp +++ b/src/CalcManager/Ratpack/fact.cpp @@ -13,7 +13,6 @@ // Contains fact(orial) and supporting _gamma functions. // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/Ratpack/itrans.cpp b/src/CalcManager/Ratpack/itrans.cpp index 0d2a297e..1521308d 100644 --- a/src/CalcManager/Ratpack/itrans.cpp +++ b/src/CalcManager/Ratpack/itrans.cpp @@ -15,7 +15,6 @@ // Special Information // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/Ratpack/itransh.cpp b/src/CalcManager/Ratpack/itransh.cpp index d6734a1f..50941287 100644 --- a/src/CalcManager/Ratpack/itransh.cpp +++ b/src/CalcManager/Ratpack/itransh.cpp @@ -16,7 +16,6 @@ // // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/Ratpack/logic.cpp b/src/CalcManager/Ratpack/logic.cpp index 6444898e..7939ce26 100644 --- a/src/CalcManager/Ratpack/logic.cpp +++ b/src/CalcManager/Ratpack/logic.cpp @@ -13,7 +13,6 @@ // Contains routines for and, or, xor, not and other support // //--------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" using namespace std; diff --git a/src/CalcManager/Ratpack/num.cpp b/src/CalcManager/Ratpack/num.cpp index 2bfa6b89..7b45fea0 100644 --- a/src/CalcManager/Ratpack/num.cpp +++ b/src/CalcManager/Ratpack/num.cpp @@ -17,7 +17,8 @@ // // //----------------------------------------------------------------------------- -#include "pch.h" +#include +#include // for memmove #include "ratpak.h" using namespace std; diff --git a/src/CalcManager/Ratpack/rat.cpp b/src/CalcManager/Ratpack/rat.cpp index e101458a..e5a6d254 100644 --- a/src/CalcManager/Ratpack/rat.cpp +++ b/src/CalcManager/Ratpack/rat.cpp @@ -16,7 +16,6 @@ // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" using namespace std; diff --git a/src/CalcManager/Ratpack/ratpak.h b/src/CalcManager/Ratpack/ratpak.h index d9bc11ce..349569a6 100644 --- a/src/CalcManager/Ratpack/ratpak.h +++ b/src/CalcManager/Ratpack/ratpak.h @@ -17,7 +17,11 @@ // //----------------------------------------------------------------------------- +#include +#include #include "CalcErr.h" +#include // for memmove +#include // for SAL static constexpr uint32_t BASEXPWR = 31L;// Internal log2(BASEX) static constexpr uint32_t BASEX = 0x80000000; // Internal radix used in calculations, hope to raise diff --git a/src/CalcManager/Ratpack/support.cpp b/src/CalcManager/Ratpack/support.cpp index 22683b4c..1e6a9204 100644 --- a/src/CalcManager/Ratpack/support.cpp +++ b/src/CalcManager/Ratpack/support.cpp @@ -18,7 +18,9 @@ // //---------------------------------------------------------------------------- -#include "pch.h" +#include +#include // for memmove +#include // for wostream #include "ratpak.h" using namespace std; diff --git a/src/CalcManager/Ratpack/trans.cpp b/src/CalcManager/Ratpack/trans.cpp index 82897564..3706d44d 100644 --- a/src/CalcManager/Ratpack/trans.cpp +++ b/src/CalcManager/Ratpack/trans.cpp @@ -14,7 +14,6 @@ // //---------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/Ratpack/transh.cpp b/src/CalcManager/Ratpack/transh.cpp index 92a12583..85c27f8b 100644 --- a/src/CalcManager/Ratpack/transh.cpp +++ b/src/CalcManager/Ratpack/transh.cpp @@ -14,7 +14,6 @@ // // //----------------------------------------------------------------------------- -#include "pch.h" #include "ratpak.h" diff --git a/src/CalcManager/UnitConverter.cpp b/src/CalcManager/UnitConverter.cpp index c1e4cd16..7bfc4817 100644 --- a/src/CalcManager/UnitConverter.cpp +++ b/src/CalcManager/UnitConverter.cpp @@ -1,7 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +#include +#include +#include // for std::sort #include "Command.h" #include "UnitConverter.h" diff --git a/src/CalcManager/UnitConverter.h b/src/CalcManager/UnitConverter.h index 010216f0..4c77f8aa 100644 --- a/src/CalcManager/UnitConverter.h +++ b/src/CalcManager/UnitConverter.h @@ -3,6 +3,12 @@ #pragma once +#include +#include +#include +#include // for SAL +#include // for std::shared_ptr + namespace UnitConversionManager { enum class Command; diff --git a/src/CalcManager/pch.cpp b/src/CalcManager/pch.cpp index 1da170eb..8ca9987d 100644 --- a/src/CalcManager/pch.cpp +++ b/src/CalcManager/pch.cpp @@ -1,4 +1,6 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -#include "pch.h" +// Intentionally do not include the pch.h here. For projects that don't +// use precompiled headers, including the header here would force unnecessary compilation. +// The pch will be included through forced include. diff --git a/src/CalcManager/pch.h b/src/CalcManager/pch.h index c5f39b6d..e66e1a38 100644 --- a/src/CalcManager/pch.h +++ b/src/CalcManager/pch.h @@ -3,27 +3,20 @@ #pragma once -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif +// The CalcManager project should be able to be compiled with or without a precompiled header +// in - order to support other toolchains besides MSVC. When adding new system headers, make sure +// that the relevant source file includes all headers it needs, but then also add the system headers +// here so that MSVC users see the performance benefit. -// Windows headers define min/max macros. -// Disable it for project code. -#define NOMINMAX - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include #include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include diff --git a/src/CalcManager/targetver.h b/src/CalcManager/targetver.h deleted file mode 100644 index 221efabb..00000000 --- a/src/CalcManager/targetver.h +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -#pragma once - -// Including SDKDDKVer.h defines the highest available Windows platform. - -// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and -// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. - -#include diff --git a/src/CalcViewModel/StandardCalculatorViewModel.cpp b/src/CalcViewModel/StandardCalculatorViewModel.cpp index 944b8d1a..8b55299e 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.cpp +++ b/src/CalcViewModel/StandardCalculatorViewModel.cpp @@ -66,6 +66,7 @@ StandardCalculatorViewModel::StandardCalculatorViewModel() : m_BinaryDisplayValue(L"0"), m_OctalDisplayValue(L"0"), m_standardCalculatorManager(&m_calculatorDisplay, &m_resourceProvider), + m_ExpressionTokens(ref new Vector()), m_MemorizedNumbers(ref new Vector()), m_IsMemoryEmpty(true), m_IsFToEChecked(false), @@ -314,59 +315,67 @@ void StandardCalculatorViewModel::SetTokens(_Inout_ shared_ptr(); - } - else - { - m_ExpressionTokens->Clear(); - } - unsigned int nTokens = 0; tokens->GetSize(&nTokens); + + if (nTokens == 0) + { + m_ExpressionTokens->Clear(); + return; + } + pair currentToken; const auto& localizer = LocalizationSettings::GetInstance(); + const wstring separator = L" "; for (unsigned int i = 0; i < nTokens; ++i) { if (SUCCEEDED(tokens->GetAt(i, ¤tToken))) { Common::TokenType type; - const wstring separator = L" "; bool isEditable = (currentToken.second == -1) ? false : true; localizer.LocalizeDisplayValue(&(currentToken.first)); if (!isEditable) { - if (currentToken.first == separator) - { - type = TokenType::Separator; - } - else - { - type = TokenType::Operator; - } + type = currentToken.first == separator ? TokenType::Separator : TokenType::Operator; } - else { shared_ptr command; IFTPlatformException(m_commands->GetAt(static_cast(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()); + if (i < m_ExpressionTokens->Size) + { + auto existingItem = m_ExpressionTokens->GetAt(i); + if (type == existingItem->Type && existingItem->Token->Equals(currentTokenString)) { - type = TokenType::Operand; + existingItem->TokenPosition = i; + existingItem->IsTokenEditable = isEditable; + existingItem->CommandIndex = 0; } else { - type = TokenType::Operator; + auto expressionToken = ref new DisplayExpressionToken(currentTokenString, i, isEditable, type); + m_ExpressionTokens->InsertAt(i, expressionToken); } + + } + else + { + auto expressionToken = ref new DisplayExpressionToken(currentTokenString, i, isEditable, type); + m_ExpressionTokens->Append(expressionToken); } - DisplayExpressionToken^ expressionToken = ref new DisplayExpressionToken(ref new String(currentToken.first.c_str()), i, isEditable, type); - m_ExpressionTokens->Append(expressionToken); } } + + while (m_ExpressionTokens->Size != nTokens) + { + m_ExpressionTokens->RemoveAtEnd(); + } } String^ StandardCalculatorViewModel::GetCalculatorExpressionAutomationName() @@ -524,7 +533,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum) { if (commandIndex == 0) { - delete [] temp; + delete[] temp; return; } @@ -545,7 +554,7 @@ void StandardCalculatorViewModel::HandleUpdatedOperandData(Command cmdenum) length = m_selectedExpressionLastData->Length() + 1; if (length > 50) { - delete [] temp; + delete[] temp; return; } for (; i < length; ++i) diff --git a/src/CalcViewModel/StandardCalculatorViewModel.h b/src/CalcViewModel/StandardCalculatorViewModel.h index 42d025c4..f8140a75 100644 --- a/src/CalcViewModel/StandardCalculatorViewModel.h +++ b/src/CalcViewModel/StandardCalculatorViewModel.h @@ -48,7 +48,7 @@ namespace CalculatorApp OBSERVABLE_NAMED_PROPERTY_RW(bool, IsInError); OBSERVABLE_PROPERTY_RW(bool, IsOperatorCommand); OBSERVABLE_PROPERTY_RW(Platform::String^, DisplayStringExpression); - OBSERVABLE_PROPERTY_RW(Windows::Foundation::Collections::IVector^, ExpressionTokens); + OBSERVABLE_PROPERTY_R(Windows::Foundation::Collections::IObservableVector^, ExpressionTokens); OBSERVABLE_PROPERTY_RW(Platform::String^, DecimalDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, HexDisplayValue); OBSERVABLE_PROPERTY_RW(Platform::String^, OctalDisplayValue); diff --git a/src/Calculator/Calculator.vcxproj b/src/Calculator/Calculator.vcxproj index 64e4ad06..d4023eda 100644 --- a/src/Calculator/Calculator.vcxproj +++ b/src/Calculator/Calculator.vcxproj @@ -243,7 +243,6 @@ - @@ -375,7 +374,6 @@ - diff --git a/src/Calculator/Calculator.vcxproj.filters b/src/Calculator/Calculator.vcxproj.filters index a888b192..4b8b9ed8 100644 --- a/src/Calculator/Calculator.vcxproj.filters +++ b/src/Calculator/Calculator.vcxproj.filters @@ -243,9 +243,6 @@ Converters - - Converters - Converters @@ -333,9 +330,6 @@ Converters - - Converters - Converters diff --git a/src/Calculator/Controls/OverflowTextBlock.cpp b/src/Calculator/Controls/OverflowTextBlock.cpp index eff43e02..7d51fd78 100644 --- a/src/Calculator/Controls/OverflowTextBlock.cpp +++ b/src/Calculator/Controls/OverflowTextBlock.cpp @@ -30,25 +30,38 @@ DEPENDENCY_PROPERTY_INITIALIZATION(OverflowTextBlock, TokensUpdated); void OverflowTextBlock::OnApplyTemplate() { - assert(((m_scrollLeft == nullptr) && (m_scrollRight == nullptr)) || ((m_scrollLeft != nullptr) && (m_scrollRight != nullptr))); + UnregisterEventHandlers(); - m_expressionContainer = safe_cast(GetTemplateChild("ExpressionContainer")); - m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr); + 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); + } - m_scrollLeft = safe_cast(GetTemplateChild("ScrollLeft")); - m_scrollRight = safe_cast(GetTemplateChild("ScrollRight")); + uiElement = GetTemplateChild("ScrollLeft"); + if (uiElement != nullptr) + { + m_scrollLeft = safe_cast(uiElement); + m_scrollLeftClickEventToken = m_scrollLeft->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); + } - m_scrollLeftClickEventToken = m_scrollLeft->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); - m_scrollRightClickEventToken = m_scrollRight->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); + uiElement = GetTemplateChild("ScrollRight"); + if (uiElement != nullptr) + { + m_scrollRight = safe_cast(uiElement); + m_scrollRightClickEventToken = m_scrollRight->Click += ref new RoutedEventHandler(this, &OverflowTextBlock::OnScrollClick); + } m_scrollingLeft = false; m_scrollingRight = false; - auto borderContainer = safe_cast(GetTemplateChild("ExpressionBorder")); - m_pointerEnteredEventToken = borderContainer->PointerEntered += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerEntered); - m_pointerExitedEventToken = borderContainer->PointerExited += ref new PointerEventHandler(this, &OverflowTextBlock::OnPointerExited); - - m_listView = safe_cast(GetTemplateChild("TokenList")); + uiElement = GetTemplateChild("TokenList"); + if (uiElement != nullptr) + { + m_itemsControl = safe_cast(uiElement); + } UpdateAllState(); } @@ -60,18 +73,19 @@ AutomationPeer^ OverflowTextBlock::OnCreateAutomationPeer() void OverflowTextBlock::OnTokensUpdatedPropertyChanged(bool /*oldValue*/, bool newValue) { - if ((m_listView != nullptr) && (newValue)) + if (m_expressionContainer != nullptr && newValue) { - unsigned int tokenCount = m_listView->Items->Size; - if (tokenCount > 0) - { - m_listView->UpdateLayout(); - m_listView->ScrollIntoView(m_listView->Items->GetAt(tokenCount - 1)); - m_expressionContainer->ChangeView(m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth, nullptr, nullptr); - } + m_expressionContainer->UpdateLayout(); + m_expressionContainer->ChangeView(m_expressionContainer->ScrollableWidth, nullptr, nullptr, true); } - AutomationProperties::SetAccessibilityView(this, - m_listView != nullptr && m_listView->Items->Size > 0 ? AccessibilityView::Control : AccessibilityView::Raw); + auto newIsAccessibilityViewControl = m_itemsControl != nullptr && m_itemsControl->Items->Size > 0; + if (m_isAccessibilityViewControl != newIsAccessibilityViewControl) + { + m_isAccessibilityViewControl = newIsAccessibilityViewControl; + AutomationProperties::SetAccessibilityView(this, + newIsAccessibilityViewControl ? AccessibilityView::Control : AccessibilityView::Raw); + } + UpdateScrollButtons(); } void OverflowTextBlock::UpdateAllState() @@ -93,7 +107,7 @@ void OverflowTextBlock::UpdateVisualState() void OverflowTextBlock::ScrollLeft() { - if (m_expressionContainer->HorizontalOffset > 0) + if (m_expressionContainer != nullptr && m_expressionContainer->HorizontalOffset > 0) { m_scrollingLeft = true; double offset = m_expressionContainer->HorizontalOffset - (scrollRatio * m_expressionContainer->ViewportWidth); @@ -105,7 +119,7 @@ void OverflowTextBlock::ScrollLeft() void OverflowTextBlock::ScrollRight() { - if (m_expressionContainer->HorizontalOffset < m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth) + if (m_expressionContainer != nullptr && m_expressionContainer->HorizontalOffset < m_expressionContainer->ExtentWidth - m_expressionContainer->ViewportWidth) { m_scrollingRight = true; double offset = m_expressionContainer->HorizontalOffset + (scrollRatio * m_expressionContainer->ViewportWidth); @@ -128,26 +142,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() { + if (m_itemsControl == nullptr || m_expressionContainer == nullptr) + { + return; + } + // 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); } @@ -163,7 +166,10 @@ void OverflowTextBlock::UpdateScrollButtons() if (m_scrollingLeft) { m_scrollingLeft = false; - m_scrollRight->Focus(::FocusState::Programmatic); + if (m_scrollRight != nullptr) + { + 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. @@ -172,7 +178,10 @@ void OverflowTextBlock::UpdateScrollButtons() if (m_scrollingRight) { m_scrollingRight = false; - m_scrollLeft->Focus(::FocusState::Programmatic); + if (m_scrollLeft != nullptr) + { + m_scrollLeft->Focus(::FocusState::Programmatic); + } } } } @@ -199,12 +208,13 @@ void OverflowTextBlock::UnregisterEventHandlers() m_scrollRight->Click -= m_scrollRightClickEventToken; } - auto borderContainer = safe_cast(GetTemplateChild("ExpressionBorder")); - - // Adding an extra check, in case the returned template is null - if (borderContainer != nullptr) + if (m_expressionContainer != nullptr) { - borderContainer->PointerEntered -= m_pointerEnteredEventToken; - borderContainer->PointerExited -= m_pointerExitedEventToken; + m_expressionContainer->ViewChanged -= m_containerViewChangedToken; } } + +void OverflowTextBlock::OnViewChanged(_In_opt_ Object^ /*sender*/, _In_opt_ ScrollViewerViewChangedEventArgs^ /*args*/) +{ + UpdateScrollButtons(); +} diff --git a/src/Calculator/Controls/OverflowTextBlock.h b/src/Calculator/Controls/OverflowTextBlock.h index 13b2e828..d4102091 100644 --- a/src/Calculator/Controls/OverflowTextBlock.h +++ b/src/Calculator/Controls/OverflowTextBlock.h @@ -34,6 +34,7 @@ namespace CalculatorApp void OnPointerExited(_In_ Platform::Object^ sender, _In_ Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e); void ShowHideScrollButtons(Windows::UI::Xaml::Visibility vLeft, Windows::UI::Xaml::Visibility vRight); void OnTokensUpdatedPropertyChanged(bool oldValue, bool newValue); + void OnViewChanged(_In_opt_ Platform::Object ^sender, _In_opt_ Windows::UI::Xaml::Controls::ScrollViewerViewChangedEventArgs ^args); void UpdateVisualState(); void UpdateExpressionState(); @@ -44,15 +45,15 @@ namespace CalculatorApp double scrollRatio = 0.7; bool m_scrollingLeft; 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::Button^ m_scrollLeft; Windows::UI::Xaml::Controls::Button^ m_scrollRight; Windows::Foundation::EventRegistrationToken m_scrollLeftClickEventToken; Windows::Foundation::EventRegistrationToken m_scrollRightClickEventToken; - Windows::Foundation::EventRegistrationToken m_pointerEnteredEventToken; - Windows::Foundation::EventRegistrationToken m_pointerExitedEventToken; + Windows::Foundation::EventRegistrationToken m_containerViewChangedToken; }; } } diff --git a/src/Calculator/Converters/ExpressionItemContainerStyle.cpp b/src/Calculator/Converters/ExpressionItemContainerStyle.cpp deleted file mode 100644 index d99332c1..00000000 --- a/src/Calculator/Converters/ExpressionItemContainerStyle.cpp +++ /dev/null @@ -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(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; - } - } -} diff --git a/src/Calculator/Converters/ExpressionItemContainerStyle.h b/src/Calculator/Converters/ExpressionItemContainerStyle.h deleted file mode 100644 index e42ecc6a..00000000 --- a/src/Calculator/Converters/ExpressionItemContainerStyle.h +++ /dev/null @@ -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; - }; - } -} diff --git a/src/Calculator/Views/Calculator.xaml b/src/Calculator/Views/Calculator.xaml index 0b84b422..12546358 100644 --- a/src/Calculator/Views/Calculator.xaml +++ b/src/Calculator/Views/Calculator.xaml @@ -8,7 +8,6 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="using:CalculatorApp" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" - xmlns:model="using:CalculatorApp.ViewModel" Loaded="OnLoaded" mc:Ignorable="d"> @@ -19,20 +18,20 @@ + Text="{x:Bind Token, Mode=OneWay}"/> + Text="{x:Bind Token, Mode=OneWay}"/> + Text="{x:Bind Token, Mode=OneWay}"/> @@ -42,119 +41,59 @@ - - - - - - - - - + + + + + + + - - - - - - - - - - - - - - + ItemsSource="{Binding ExpressionTokens}"> + + + + + + + + + + - - - - - - - -