diff --git a/src/CalcManager/CCalcManager.cpp b/src/CalcManager/CCalcManager.cpp index 9f8393e2..1663554c 100644 --- a/src/CalcManager/CCalcManager.cpp +++ b/src/CalcManager/CCalcManager.cpp @@ -10,7 +10,8 @@ #include #include -#if !defined(__EMSCRIPTEN__) +#if DEBUG +#if defined(_WINDOWS_) #include #include @@ -25,23 +26,28 @@ VOID _DBGPRINT(LPCWSTR kwszFunction, INT iLineNumber, LPCWSTR kwszDebugFormatStr va_start(args, kwszDebugFormatString); - cbFormatString = _scwprintf(L"[%s:%d] ", kwszFunction, iLineNumber) * sizeof(WCHAR); - cbFormatString += _vscwprintf(kwszDebugFormatString, args) * sizeof(WCHAR) + 2; + cbFormatString = _scwDBGPRINT(L"[%s:%d] ", kwszFunction, iLineNumber) * sizeof(WCHAR); + cbFormatString += _vscwDBGPRINT(kwszDebugFormatString, args) * sizeof(WCHAR) + 2; /* Depending on the size of the format string, allocate space on the stack or the heap. */ wszDebugString = (PWCHAR)_malloca(cbFormatString); /* Populate the buffer with the contents of the format string. */ - StringCbPrintfW(wszDebugString, cbFormatString, L"[%s:%d] ", kwszFunction, iLineNumber); + StringCbDBGPRINTW(wszDebugString, cbFormatString, L"[%s:%d] ", kwszFunction, iLineNumber); StringCbLengthW(wszDebugString, cbFormatString, &st_Offset); - StringCbVPrintfW(&wszDebugString[st_Offset / sizeof(WCHAR)], cbFormatString - st_Offset, kwszDebugFormatString, args); + StringCbVDBGPRINTW(&wszDebugString[st_Offset / sizeof(WCHAR)], cbFormatString - st_Offset, kwszDebugFormatString, args); OutputDebugStringW(wszDebugString); _freea(wszDebugString); va_end(args); } +#elif defined(__EMSCRIPTEN__) +#define DBGPRINT(kwszDebugFormatString, ...) printf(kwszDebugFormatString, ##__VA_ARGS__); #endif +#else +#define DBGPRINT(kwszDebugFormatString, ...) +#endif // DEBUG using namespace CalculationManager; @@ -62,60 +68,69 @@ public: std::wstring_convert> convert; auto str = convert.to_bytes(pszText); - printf("Native:SetPrimaryDisplay(%ls, %d)\n", pszText.data(), isError); + DBGPRINT("Native:SetPrimaryDisplay(%ls, %d)\n", pszText.data(), isError); _params.SetPrimaryDisplay(_params.CalculatorState, str.data(), isError); } virtual void SetIsInError(bool isInError) override { - printf("Native:SetIsInError(%d)\n", isInError); + DBGPRINT("Native:SetIsInError(%d)\n", isInError); _params.SetIsInError(_params.CalculatorState, isInError); } virtual void SetExpressionDisplay( - std::shared_ptr>> const& /*tokens*/, - std::shared_ptr>> const& /*commands*/) override + std::shared_ptr>> const& tokens, + std::shared_ptr>> const& commands) override { - printf("Native:SetExpressionDisplay()\n"); + DBGPRINT("Native:SetExpressionDisplay()\n"); + auto item = std::make_shared(); + item->historyItemVector.expression = L""; + item->historyItemVector.result = L""; + item->historyItemVector.spCommands = commands; + item->historyItemVector.spTokens = tokens; + + auto pItem = MarshalHistoryItem(item); + + _params.SetExpressionDisplay(_params.CalculatorState, pItem); } virtual void SetParenthesisNumber(unsigned int count) override { - printf("Native:SetParenthesisNumber(%d)\n", count); + DBGPRINT("Native:SetParenthesisNumber(%d)\n", count); _params.SetParenthesisNumber(_params.CalculatorState, count); } virtual void OnNoRightParenAdded() override { - printf("Native:OnNoRightParenAdded()\n"); + DBGPRINT("Native:OnNoRightParenAdded()\n"); _params.OnNoRightParenAdded(_params.CalculatorState); } virtual void MaxDigitsReached() override { - printf("Native:MaxDigitsReached()\n"); + DBGPRINT("Native:MaxDigitsReached()\n"); _params.MaxDigitsReached(_params.CalculatorState); } virtual void BinaryOperatorReceived() override { - printf("Native:BinaryOperatorReceived()\n"); + DBGPRINT("Native:BinaryOperatorReceived()\n"); _params.BinaryOperatorReceived(_params.CalculatorState); } virtual void OnHistoryItemAdded(unsigned int addedItemIndex) override { - printf("Native:OnHistoryItemAdded(%d)\n", addedItemIndex); + DBGPRINT("Native:OnHistoryItemAdded(%d)\n", addedItemIndex); _params.OnHistoryItemAdded(_params.CalculatorState, addedItemIndex); } virtual void SetMemorizedNumbers(const std::vector& memorizedNumbers) override { - printf("Native:SetMemorizedNumbers(%d)\n", (int)memorizedNumbers.size()); + DBGPRINT("Native:SetMemorizedNumbers(%d)\n", (int)memorizedNumbers.size()); auto numbers = new const wchar_t* [memorizedNumbers.size()] {}; @@ -139,7 +154,7 @@ public: virtual void MemoryItemChanged(unsigned int indexOfMemory) override { - printf("Native:MemoryItemChanged(%d)\n", indexOfMemory); + DBGPRINT("Native:MemoryItemChanged(%d)\n", indexOfMemory); _params.MemoryItemChanged(_params.CalculatorState, indexOfMemory); } @@ -160,7 +175,7 @@ public: { auto pResult = _params.GetCEngineString(_params.ResourceState, id.data()); auto str = std::wstring(pResult); - printf("Native:GetCEngineString(id=%ls, str.data()=%ls)\n", id.data(), str.data()); + DBGPRINT("Native:GetCEngineString(id=%ls, str.data()=%ls)\n", id.data(), str.data()); return str; } }; @@ -182,6 +197,83 @@ const wchar_t* ToWChar(std::wstring& str) return out; } +GetHistoryItemResult* MarshalHistoryItem(std::shared_ptr& historyItem) +{ + auto itemResult = new GetHistoryItemResult{}; + + itemResult->expression = ToWChar(historyItem->historyItemVector.expression); + itemResult->result = ToWChar(historyItem->historyItemVector.result); + + unsigned int tokenCount; + historyItem->historyItemVector.spTokens->GetSize(&tokenCount); + itemResult->TokenCount = tokenCount; + + // + // Marshal Tokens + // + auto tokenStrings = new const wchar_t* [tokenCount] {}; + auto tokenValues = new int32_t[tokenCount]{}; + + // DBGPRINT(L"TokenCount: %d (int32_t: %d)\n", tokenCount, sizeof(int32_t)); + + for (uint32_t j = 0; j < tokenCount; j++) + { + std::pair pair; + + if (SUCCEEDED(historyItem->historyItemVector.spTokens->GetAt(j, &pair))) + { + tokenStrings[j] = ToWChar(pair.first); + tokenValues[j] = (int32_t)pair.second; + // DBGPRINT(L"\tPair: %ws;%d\n", pair.first.data(), tokenValues[j]); + } + } + + itemResult->TokenStrings = tokenStrings; + itemResult->TokenValues = tokenValues; + + // + // Marshal Commands + // + unsigned int commandCount; + historyItem->historyItemVector.spCommands->GetSize(&commandCount); + itemResult->CommandCount = commandCount; + + auto commands = new void* [commandCount] {}; + + for (uint32_t commandId = 0; commandId < commandCount; commandId++) + { + std::shared_ptr command; + if (SUCCEEDED(historyItem->historyItemVector.spCommands->GetAt(commandId, &command))) + { + commands[commandId] = command.get(); + } + } + + itemResult->Commands = commands; + + return itemResult; +} + +void* MarshalHistoryItems(std::vector>& historyItems) +{ + auto result = new GetHistoryItemsResult{}; + + result->ItemsCount = (int32_t)historyItems.size(); + + auto resultsArray = new GetHistoryItemResult*[result->ItemsCount]; + result->HistoryItems = (void*)resultsArray; + + for (size_t i = 0; i < historyItems.size(); i++) + { + auto historyItem = historyItems[i]; + + resultsArray[i] = MarshalHistoryItem(historyItem); + } + + return result; +} + + void* CalculatorManager_Create(CalculatorManager_CreateParams* pParams) { auto calcDisplay = new CalcDisplay(*pParams); @@ -316,82 +408,6 @@ void CalculatorManager_SetInHistoryItemLoadMode(void* manager, bool isHistoryIte AsManager(manager)->SetInHistoryItemLoadMode(isHistoryItemLoadMode); } -GetHistoryItemResult* MarshalHistoryItem(std::shared_ptr& historyItem) -{ - auto itemResult = new GetHistoryItemResult{}; - - itemResult->expression = ToWChar(historyItem->historyItemVector.expression); - itemResult->result = ToWChar(historyItem->historyItemVector.result); - - unsigned int tokenCount; - historyItem->historyItemVector.spTokens->GetSize(&tokenCount); - itemResult->TokenCount = tokenCount; - - // - // Marshal Tokens - // - auto tokenStrings = new const wchar_t* [tokenCount] {}; - auto tokenValues = new int32_t[tokenCount]{}; - - // DBGPRINT(L"TokenCount: %d (int32_t: %d)\n", tokenCount, sizeof(int32_t)); - - for (uint32_t j = 0; j < tokenCount; j++) - { - std::pair pair; - - if (SUCCEEDED(historyItem->historyItemVector.spTokens->GetAt(j, &pair))) - { - tokenStrings[j] = ToWChar(pair.first); - tokenValues[j] = (int32_t)pair.second; - // DBGPRINT(L"\tPair: %ws;%d\n", pair.first.data(), tokenValues[j]); - } - } - - itemResult->TokenStrings = tokenStrings; - itemResult->TokenValues = tokenValues; - - // - // Marshal Commands - // - unsigned int commandCount; - historyItem->historyItemVector.spCommands->GetSize(&commandCount); - itemResult->CommandCount = commandCount; - - auto commands = new void*[commandCount]{}; - - for (uint32_t commandId = 0; commandId < commandCount; commandId++) - { - std::shared_ptr command; - if (SUCCEEDED(historyItem->historyItemVector.spCommands->GetAt(commandId, &command))) - { - commands[commandId] = command.get(); - } - } - - itemResult->Commands = commands; - - return itemResult; -} - -void* MarshalHistoryItems(std::vector>& historyItems) -{ - auto result = new GetHistoryItemsResult{}; - - result->ItemsCount = (int32_t)historyItems.size(); - - auto resultsArray = new GetHistoryItemResult*[result->ItemsCount]; - result->HistoryItems = (void*)resultsArray; - - for (size_t i = 0; i < historyItems.size(); i++) - { - auto historyItem = historyItems[i]; - - resultsArray[i] = MarshalHistoryItem(historyItem); - } - - return result; -} - void* CalculatorManager_GetHistoryItems(void* manager) { auto historyItems = AsManager(manager)->GetHistoryItems(); diff --git a/src/CalcManager/CCalcManager.h b/src/CalcManager/CCalcManager.h index 76cf983d..4eb4e663 100644 --- a/src/CalcManager/CCalcManager.h +++ b/src/CalcManager/CCalcManager.h @@ -6,23 +6,12 @@ #include "headers/Rational.h" #include "headers/ICalcDisplay.h" - -struct TokenPair { - char* Item1; - int Item2; -}; - -struct ExpressionDisplayData { - int TokenCount; - TokenPair* Tokens; - - int CommandCount; - void* Commands; -}; +struct GetHistoryItemResult; +struct GetHistoryItemsResult; typedef void (*SetPrimaryDisplayFunc)(void* state, const char* text, bool isError); typedef void (*SetIsInErrorFunc)(void* state, bool isInError); -typedef void (*SetExpressionDisplayFunc)(void* state, ExpressionDisplayData* data); +typedef void (*SetExpressionDisplayFunc)(void* state, GetHistoryItemResult* data); typedef void (*SetParenthesisNumberFunc)(void* state, unsigned int count); typedef void (*OnNoRightParenAddedFunc)(void* state); typedef void (*MaxDigitsReachedFunc)(void* state); @@ -57,6 +46,9 @@ struct CalculatorManager_CreateParams { #define DLL_EXPORT __declspec(dllexport) #endif +GetHistoryItemResult* MarshalHistoryItem(std::shared_ptr& historyItem); +void* MarshalHistoryItems(std::vector>& historyItems); + extern "C" { struct GetHistoryItemsResult diff --git a/src/CalcManager/CalcManager.wasm b/src/CalcManager/CalcManager.wasm index 873bff55..7ba36e06 100644 Binary files a/src/CalcManager/CalcManager.wasm and b/src/CalcManager/CalcManager.wasm differ diff --git a/src/Calculator.Shared/App.xaml.cs b/src/Calculator.Shared/App.xaml.cs index dac57e65..bf38c091 100644 --- a/src/Calculator.Shared/App.xaml.cs +++ b/src/Calculator.Shared/App.xaml.cs @@ -106,8 +106,12 @@ namespace CalculatorApp public static string GetAppViewState() { String newViewState; - CoreWindow window = CoreWindow.GetForCurrentThread(); - if ((window.Bounds.Width >= 560) && (window.Bounds.Height >= 356)) +#if NETFX_CORE + CoreWindow window = CoreWindow.GetForCurrentThread(); +#else + var window = Windows.UI.Xaml.Window.Current; +#endif + if ((window.Bounds.Width >= 560) && (window.Bounds.Height >= 356)) { newViewState = ViewState.DockedView; } diff --git a/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs b/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs index d66d1a09..009198e3 100644 --- a/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs +++ b/src/Calculator.Shared/CalcManager/CalculatorManager.Interop.cs @@ -106,7 +106,7 @@ namespace CalculationManager public delegate void MemoryItemChangedCallbackFunc(IntPtr state, int indexOfMemory); public delegate void OnHistoryItemAddedCallbackFunc(IntPtr state, int addedItemIndex); public delegate void OnNoRightParenAddedCallbackFunc(IntPtr state); - public delegate void SetExpressionDisplayCallbackFunc(IntPtr state); + public delegate void SetExpressionDisplayCallbackFunc(IntPtr state, IntPtr data); public delegate void SetMemorizedNumbersCallbackFunc(IntPtr state, int count, IntPtr newMemorizedNumbers); public static GetCEngineStringFunc _getCEngineStringCallback = GetCEngineStringCallback; @@ -127,7 +127,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.MaxDigitsReached(); - Debug.WriteLine($"CalculatorManager.MaxDigitsReachedCallback"); + DebugTrace($"CalculatorManager.MaxDigitsReachedCallback"); } public static void MemoryItemChangedCallback(IntPtr state, int indexOfMemory) @@ -135,7 +135,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.MemoryItemChanged(indexOfMemory); - Debug.WriteLine($"CalculatorManager.MemoryItemChangedCallback({indexOfMemory})"); + DebugTrace($"CalculatorManager.MemoryItemChangedCallback({indexOfMemory})"); } public static void OnHistoryItemAddedCallback(IntPtr state, int addedItemIndex) @@ -143,7 +143,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.OnHistoryItemAdded(addedItemIndex); - Debug.WriteLine($"CalculatorManager.OnHistoryItemAddedCallback({addedItemIndex})"); + DebugTrace($"CalculatorManager.OnHistoryItemAddedCallback({addedItemIndex})"); } public static void OnNoRightParenAddedCallback(IntPtr state) @@ -151,15 +151,20 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.OnNoRightParenAdded(); - Debug.WriteLine($"CalculatorManager.OnNoRightParenAddedCallback"); + DebugTrace($"CalculatorManager.OnNoRightParenAddedCallback"); } - public static void SetExpressionDisplayCallback(IntPtr state) + public static void SetExpressionDisplayCallback(IntPtr state, IntPtr historyItem) { - var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; - // manager.SetExpressionDisplay(); + DebugTrace($"CalculatorManager.SetExpressionDisplayCallback({state}, {historyItem})"); + + var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; + + var nativeResult = Marshal.PtrToStructure(historyItem); + var itemResult = CalculatorManager.UnmarshalHistoryItemResult(nativeResult); + + manager.SetExpressionDisplay(itemResult.historyItemVector.spTokens, itemResult.historyItemVector.spCommands); - Debug.WriteLine($"CalculatorManager.SetExpressionDisplayCallback"); } public static void SetMemorizedNumbersCallback(IntPtr state, int count, IntPtr newMemorizedNumbers) @@ -175,7 +180,7 @@ namespace CalculationManager manager.SetMemorizedNumbers(numbers); - Debug.WriteLine($"CalculatorManager.SetMemorizedNumbersCallback({string.Join(";", numbers)})"); + DebugTrace($"CalculatorManager.SetMemorizedNumbersCallback({string.Join(";", numbers)})"); } public static void SetParenthesisNumberCallback(IntPtr state, int parenthesisCount) @@ -183,7 +188,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.SetParenthesisNumber(parenthesisCount); - Debug.WriteLine($"CalculatorManager.SetParenthesisNumberCallback({parenthesisCount})"); + DebugTrace($"CalculatorManager.SetParenthesisNumberCallback({parenthesisCount})"); } public static void BinaryOperatorReceivedCallback(IntPtr state) @@ -191,7 +196,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.BinaryOperatorReceived(); - Debug.WriteLine($"CalculatorManager.BinaryOperatorReceivedCallback"); + DebugTrace($"CalculatorManager.BinaryOperatorReceivedCallback"); } public static void SetPrimaryDisplayCallback(IntPtr state, [MarshalAs(UnmanagedType.LPWStr)] string displayStringValue, bool isError) @@ -199,7 +204,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.SetPrimaryDisplay(displayStringValue, isError); - Debug.WriteLine($"CalculatorManager.SetPrimaryDisplayCallback({displayStringValue}, {isError})"); + DebugTrace($"CalculatorManager.SetPrimaryDisplayCallback({displayStringValue}, {isError})"); } public static void SetIsInErrorCallback(IntPtr state, bool isError) @@ -207,7 +212,7 @@ namespace CalculationManager var manager = GCHandle.FromIntPtr((IntPtr)state).Target as CalculatorDisplay; manager.SetIsInError(isError); - Debug.WriteLine($"CalculatorManager.SetIsInErrorCallback({isError})"); + DebugTrace($"CalculatorManager.SetIsInErrorCallback({isError})"); } public static IntPtr GetCEngineStringCallback(IntPtr state, IntPtr pResourceId) @@ -223,7 +228,7 @@ namespace CalculationManager var pEngineString = Marshal.StringToHGlobalUni(resourceValue); #endif - Debug.WriteLine($"GetCEngineStringCallback({resourceId}, {resourceValue}"); + DebugTrace($"GetCEngineStringCallback({resourceId}, {resourceValue})"); return pEngineString; } @@ -236,6 +241,11 @@ namespace CalculationManager Marshal.WriteInt32(pRet2 + resourceValue.Length * 4, 0); return pRet2; } + + private static void DebugTrace(string message) + { + // Debug.WriteLine(message); + } } [StructLayout(LayoutKind.Sequential)] diff --git a/src/Calculator.Shared/CalcManager/CalculatorManager.cs b/src/Calculator.Shared/CalcManager/CalculatorManager.cs index f76b1ad2..a3937fae 100644 --- a/src/Calculator.Shared/CalcManager/CalculatorManager.cs +++ b/src/Calculator.Shared/CalcManager/CalculatorManager.cs @@ -248,7 +248,7 @@ namespace CalculationManager return output; } - private static HISTORYITEM UnmarshalHistoryItemResult(GetHistoryItemResult historyResultItem) + internal static HISTORYITEM UnmarshalHistoryItemResult(GetHistoryItemResult historyResultItem) { var historyItem = new HISTORYITEM(); historyItem.historyItemVector.expression = historyResultItem.expression; diff --git a/src/Calculator.Shared/CalcManager/ExpressionCommandInterface.cs b/src/Calculator.Shared/CalcManager/ExpressionCommandInterface.cs index fd052726..6a9eaae9 100644 --- a/src/Calculator.Shared/CalcManager/ExpressionCommandInterface.cs +++ b/src/Calculator.Shared/CalcManager/ExpressionCommandInterface.cs @@ -67,8 +67,8 @@ namespace CalculationManager public CParentheses(IntPtr pExpressionCommand) => this.pExpressionCommand = pExpressionCommand; public int GetCommand() => throw new NotImplementedException(); - public CalculationManager.CommandType GetCommandType() => throw new NotImplementedException(); - public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException(); + public CalculationManager.CommandType GetCommandType() => CommandType.Parentheses; + public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException(); } public class CUnaryCommand : IUnaryCommand @@ -80,8 +80,8 @@ namespace CalculationManager public CUnaryCommand(int command) => throw new NotImplementedException(); public CUnaryCommand(int command1, int command2) => throw new NotImplementedException(); public CalculatorList GetCommands() => throw new NotImplementedException(); - public CalculationManager.CommandType GetCommandType() => throw new NotImplementedException(); - public void SetCommand(int command) => throw new NotImplementedException(); + public CalculationManager.CommandType GetCommandType() => CommandType.UnaryCommand; + public void SetCommand(int command) => throw new NotImplementedException(); public void SetCommands(int command1, int command2) => throw new NotImplementedException(); public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException(); } @@ -95,7 +95,7 @@ namespace CalculationManager public CBinaryCommand(int command) => throw new NotImplementedException(); public void SetCommand(int command) => throw new NotImplementedException(); public int GetCommand() => throw new NotImplementedException(); - public CommandType GetCommandType() => throw new NotImplementedException(); + public CalculationManager.CommandType GetCommandType() => CommandType.BinaryCommand; public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException(); } @@ -117,7 +117,7 @@ namespace CalculationManager public bool IsSciFmt() => throw new NotImplementedException(); public bool IsDecimalPresent() => throw new NotImplementedException(); public string GetToken(char decimalSymbol) => throw new NotImplementedException(); - public CalculationManager.CommandType GetCommandType() => throw new NotImplementedException(); + public CalculationManager.CommandType GetCommandType() => CommandType.OperandCommand; public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException(); public string GetString(uint radix, int precision) => throw new NotImplementedException(); } diff --git a/src/Calculator.Shared/Converters/ExpressionItemTemplateSelector.cs b/src/Calculator.Shared/Converters/ExpressionItemTemplateSelector.cs index c1e56077..6e061742 100644 --- a/src/Calculator.Shared/Converters/ExpressionItemTemplateSelector.cs +++ b/src/Calculator.Shared/Converters/ExpressionItemTemplateSelector.cs @@ -11,7 +11,7 @@ namespace CalculatorApp [Windows.UI.Xaml.Data.Bindable] public sealed class ExpressionItemTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector { - Windows.UI.Xaml.DataTemplate SelectTemplateCore(object item, Windows.UI.Xaml.DependencyObject container) + protected override Windows.UI.Xaml.DataTemplate SelectTemplateCore(object item, Windows.UI.Xaml.DependencyObject container) { DisplayExpressionToken token = (DisplayExpressionToken)(item); if (token != null) diff --git a/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs b/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs index 92b64cc2..2e27efba 100644 --- a/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs +++ b/src/Calculator.Shared/ViewModels/StandardCalculatorViewModel.cs @@ -830,7 +830,7 @@ namespace CalculatorApp.ViewModel else { var expressionToken = new DisplayExpressionToken(currentTokenString, i, isEditable, type); - m_ExpressionTokens.Append(expressionToken); + m_ExpressionTokens.Add(expressionToken); } } } diff --git a/src/Calculator.Shared/Views/Calculator.xaml b/src/Calculator.Shared/Views/Calculator.xaml index 4e5f78a7..287c0b6b 100644 --- a/src/Calculator.Shared/Views/Calculator.xaml +++ b/src/Calculator.Shared/Views/Calculator.xaml @@ -907,7 +907,7 @@ - + @@ -969,7 +969,7 @@ IsOperatorCommand="{x:Bind Model.IsOperatorCommand, Mode=OneWay}" TabIndex="1" /> (s as AspectRatioTrigger)?.OnSourcePropertyChanged(e.OldValue as FrameworkElement, e.NewValue as FrameworkElement)) + ); - /* Either Height or Width. The property will determine which aspect is used as the numerator when calculating + /* Either Height or Width. The property will determine which aspect is used as the numerator when calculating the aspect ratio. */ - public Aspect NumeratorAspect - { - get { return (Aspect)GetValue(NumeratorAspectProperty); } - set { SetValue(NumeratorAspectProperty, value); } - } + public Aspect NumeratorAspect + { + get { return (Aspect)GetValue(NumeratorAspectProperty); } + set { SetValue(NumeratorAspectProperty, value); } + } - // Using a DependencyProperty as the backing store for NumeratorAspect. This enables animation, styling, binding, etc... - public static readonly DependencyProperty NumeratorAspectProperty = - DependencyProperty.Register("NumeratorAspect", typeof(Aspect), typeof(AspectRatioTrigger), new PropertyMetadata(Aspect.Height)); + // Using a DependencyProperty as the backing store for NumeratorAspect. This enables animation, styling, binding, etc... + public static readonly DependencyProperty NumeratorAspectProperty = + DependencyProperty.Register( + name: "NumeratorAspect", + propertyType: typeof(Aspect), + ownerType: typeof(AspectRatioTrigger), + typeMetadata: new PropertyMetadata(Aspect.Height) + ); - /* The threshold that will cause the trigger to fire when the aspect ratio exceeds this value. */ - public double Threshold - { - get { return (double)GetValue(ThresholdProperty); } - set { SetValue(ThresholdProperty, value); } - } + /* The threshold that will cause the trigger to fire when the aspect ratio exceeds this value. */ + public double Threshold + { + get { return (double)GetValue(ThresholdProperty); } + set { SetValue(ThresholdProperty, value); } + } - // Using a DependencyProperty as the backing store for Threshold. This enables animation, styling, binding, etc... - public static readonly DependencyProperty ThresholdProperty = - DependencyProperty.Register("Threshold", typeof(double), typeof(AspectRatioTrigger), new PropertyMetadata(0.0)); + // Using a DependencyProperty as the backing store for Threshold. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ThresholdProperty = + DependencyProperty.Register( + name: "Threshold", + propertyType: typeof(double), + ownerType: typeof(AspectRatioTrigger), + typeMetadata: new PropertyMetadata(0.0) + ); + + /* If true, the trigger will fire if the aspect ratio is greater than or equal to the threshold. */ + public bool ActiveIfEqual + { + get { return (bool)GetValue(ActiveIfEqualProperty); } + set { SetValue(ActiveIfEqualProperty, value); } + } + + // Using a DependencyProperty as the backing store for ActiveIfEqual. This enables animation, styling, binding, etc... + public static readonly DependencyProperty ActiveIfEqualProperty = + DependencyProperty.Register( + name: "ActiveIfEqual", + propertyType: typeof(bool), + ownerType: typeof(AspectRatioTrigger), + typeMetadata: new PropertyMetadata(false) + ); + AspectRatioTrigger() + { + SetActive(false); + } - /* If true, the trigger will fire if the aspect ratio is greater than or equal to the threshold. */ - public bool ActiveIfEqual - { - get { return (bool)GetValue(ActiveIfEqualProperty); } - set { SetValue(ActiveIfEqualProperty, value); } - } + void OnSourcePropertyChanged(FrameworkElement oldValue, FrameworkElement newValue) + { + UnregisterSizeChanged(oldValue); + RegisterSizeChanged(newValue); + } - // Using a DependencyProperty as the backing store for ActiveIfEqual. This enables animation, styling, binding, etc... - public static readonly DependencyProperty ActiveIfEqualProperty = - DependencyProperty.Register("ActiveIfEqual", typeof(bool), typeof(AspectRatioTrigger), new PropertyMetadata(false)); + void RegisterSizeChanged(FrameworkElement element) + { + if (element == null) + { + return; + } + if (element != Source) + { + UnregisterSizeChanged(Source); + } - AspectRatioTrigger() - { - SetActive(false); - } + element.SizeChanged += OnSizeChanged; + } - void OnSourcePropertyChanged(FrameworkElement oldValue, FrameworkElement newValue) - { - UnregisterSizeChanged(oldValue); - RegisterSizeChanged(newValue); - } + void UnregisterSizeChanged(FrameworkElement element) + { + if (element != null) + { + element.SizeChanged -= OnSizeChanged; + } + } - void RegisterSizeChanged(FrameworkElement element) - { - if (element == null) - { - return; - } + void OnSizeChanged(object sender, SizeChangedEventArgs e) + { + UpdateIsActive(e.NewSize); + } - if (element != Source) - { - UnregisterSizeChanged(Source); - } + void UpdateIsActive(Size sourceSize) + { + double numerator, denominator; + if (NumeratorAspect == Aspect.Height) + { + numerator = sourceSize.Height; + denominator = sourceSize.Width; + } + else + { + numerator = sourceSize.Width; + denominator = sourceSize.Height; + } - element.SizeChanged += OnSizeChanged; - } + bool isActive = false; + if (denominator > 0) + { + double ratio = numerator / denominator; + double threshold = Math.Abs(Threshold); - void UnregisterSizeChanged(FrameworkElement element) - { - if (element != null) - { - element.SizeChanged -= OnSizeChanged; - } - } + isActive = ((ratio > threshold) || (ActiveIfEqual && (ratio == threshold))); + } - void OnSizeChanged(object sender, SizeChangedEventArgs e) - { - UpdateIsActive(e.NewSize); - } + SetActive(isActive); + } - void UpdateIsActive(Size sourceSize) - { - double numerator, denominator; - if (NumeratorAspect == Aspect.Height) - { - numerator = sourceSize.Height; - denominator = sourceSize.Width; - } - else - { - numerator = sourceSize.Width; - denominator = sourceSize.Height; - } - - bool isActive = false; - if (denominator > 0) - { - double ratio = numerator / denominator; - double threshold = Math.Abs(Threshold); - - isActive = ((ratio > threshold) || (ActiveIfEqual && (ratio == threshold))); - } - - SetActive(isActive); - } - - } + } } diff --git a/src/Calculator.Wasm/WasmScripts/AppManifest.js b/src/Calculator.Wasm/WasmScripts/AppManifest.js index bb8fff30..87d7f7ca 100644 --- a/src/Calculator.Wasm/WasmScripts/AppManifest.js +++ b/src/Calculator.Wasm/WasmScripts/AppManifest.js @@ -2,6 +2,6 @@ splashScreenImage: "Assets/SplashScreen.scale-200.png", splashScreenColor: "#00f", - displayName: "WindowsCalculator" + displayName: "Calculator" } diff --git a/src/Calculator.Wasm/WasmScripts/CalcManager.js b/src/Calculator.Wasm/WasmScripts/CalcManager.js index e3c5ac1e..fe4fdf17 100644 --- a/src/Calculator.Wasm/WasmScripts/CalcManager.js +++ b/src/Calculator.Wasm/WasmScripts/CalcManager.js @@ -22,8 +22,8 @@ var fMaxDigitsReachedCallback = Module.addFunction((state) => _maxDigitsReachedCallback(state), 'vii'); var fMemoryItemChangedCallback = Module.addFunction((state, indexOfMemory) => _memoryItemChangedCallback(state, indexOfMemory), 'vii'); var fOnHistoryItemAddedCallback = Module.addFunction((state, addedItemIndex) => _onHistoryItemAddedCallback(state, addedItemIndex), 'vii'); - var fOnNoRightParenAddedCallback = Module.addFunction((state) => _onNoRightParenAddedCallback (state), 'vi'); - var fSetExpressionDisplayCallback = Module.addFunction((state) => _setExpressionDisplayCallback (state), 'vi'); + var fOnNoRightParenAddedCallback = Module.addFunction((state) => _onNoRightParenAddedCallback(state), 'vi'); + var fSetExpressionDisplayCallback = Module.addFunction((state, historyItem) => _setExpressionDisplayCallback(state, historyItem), 'vii'); var fSetMemorizedNumbersCallback = Module.addFunction((state, size, numbers) => _setMemorizedNumbersCallback(state, size, numbers), 'viii'); var ret = `${fGetCEngineStringCallback};`