Add support for history listing

This commit is contained in:
Jérôme Laban 2019-05-22 15:22:37 -04:00
commit e5cdaeaf0d
12 changed files with 423 additions and 236 deletions

View file

@ -83,13 +83,13 @@ public:
{
DBGPRINT("Native:SetExpressionDisplay()\n");
auto item = std::make_shared<HISTORYITEM>();
auto item = std::make_shared<HISTORYITEM>();
item->historyItemVector.expression = L"";
item->historyItemVector.result = L"";
item->historyItemVector.spCommands = commands;
item->historyItemVector.spTokens = tokens;
auto pItem = MarshalHistoryItem(item);
auto pItem = MarshalHistoryItem(item);
_params.SetExpressionDisplay(_params.CalculatorState, pItem);
}
@ -187,6 +187,21 @@ IExpressionCommand* AsIExpressionCommand(void* pExpressionCommand)
return static_cast<IExpressionCommand*>(pExpressionCommand);
}
COpndCommand* AsCOpndCommand(void* pExpressionCommand)
{
return static_cast<COpndCommand*>(pExpressionCommand);
}
CUnaryCommand* AsCUnaryCommand(void* pExpressionCommand)
{
return static_cast<CUnaryCommand*>(pExpressionCommand);
}
CBinaryCommand* AsCBinaryCommand(void* pExpressionCommand)
{
return static_cast<CBinaryCommand*>(pExpressionCommand);
}
const wchar_t* ToWChar(std::wstring& str)
{
auto out = new wchar_t[str.size() + 1]{};
@ -270,7 +285,6 @@ void* MarshalHistoryItems(std::vector<std::shared_ptr<CalculationManager::HISTOR
return result;
}
void* CalculatorManager_Create(CalculatorManager_CreateParams* pParams)
{
auto calcDisplay = new CalcDisplay(*pParams);
@ -423,10 +437,71 @@ void* CalculatorManager_GetHistoryItem(void* manager, int index)
{
auto historyItem = AsManager(manager)->GetHistoryItem(index);
return MarshalHistoryItem(historyItem);
return MarshalHistoryItem(historyItem);
}
void Free(void* ptr)
{
free(ptr);
}
int IExpressionCommand_GetCommandType(void* pExpressionCommand)
{
return (int)AsIExpressionCommand(pExpressionCommand)->GetCommandType();
}
void* COpndCommand_GetCommands(void* pExpressionCommand)
{
auto res = AsCOpndCommand(pExpressionCommand)->GetCommands();
auto pRes = (COpndCommand_GetCommandsResult*)malloc(sizeof(COpndCommand_GetCommandsResult));
unsigned int commandCount;
res->GetSize(&commandCount);
pRes->CommandCount = commandCount;
auto pCommands = (int32_t*)malloc(commandCount * sizeof(int32_t));
pRes->pCommands = pCommands;
for (unsigned int i = 0; i < commandCount; i++)
{
int value;
res->GetAt(i, &value);
pCommands[i] = (int32_t)value;
}
return pRes;
}
void* CUnaryCommand_GetCommands(void* pExpressionCommand)
{
auto res = AsCUnaryCommand(pExpressionCommand)->GetCommands();
auto pRes = (CUnaryCommand_GetCommandsResult*)malloc(sizeof(CUnaryCommand_GetCommandsResult));
unsigned int commandCount;
res->GetSize(&commandCount);
pRes->CommandCount = commandCount;
auto pCommands = (int32_t*)malloc(commandCount * sizeof(int32_t));
pRes->pCommands = pCommands;
for (unsigned int i = 0; i < commandCount; i++)
{
int value;
res->GetAt(i, &value);
pCommands[i] = (int32_t)value;
}
return pRes;
}
bool COpndCommand_IsNegative(void* pExpressionCommand)
{
return (int)AsCOpndCommand(pExpressionCommand)->IsNegative();
}
int CBinaryCommand_GetCommand(void* pExpressionCommand)
{
return (int)AsCBinaryCommand(pExpressionCommand)->GetCommand();
}

View file

@ -22,22 +22,23 @@ typedef void (*MemoryItemChangedFunc)(void* state, unsigned int indexOfMemory);
typedef const wchar_t* (*GetCEngineStringFunc)(void* state, const wchar_t* id);
struct CalculatorManager_CreateParams {
void* CalculatorState;
struct CalculatorManager_CreateParams
{
void* CalculatorState;
SetPrimaryDisplayFunc SetPrimaryDisplay;
SetIsInErrorFunc SetIsInError;
SetExpressionDisplayFunc SetExpressionDisplay;
SetParenthesisNumberFunc SetParenthesisNumber;
OnNoRightParenAddedFunc OnNoRightParenAdded;
MaxDigitsReachedFunc MaxDigitsReached;
BinaryOperatorReceivedFunc BinaryOperatorReceived;
OnHistoryItemAddedFunc OnHistoryItemAdded;
SetMemorizedNumbersFunc SetMemorizedNumbers;
MemoryItemChangedFunc MemoryItemChanged;
SetPrimaryDisplayFunc SetPrimaryDisplay;
SetIsInErrorFunc SetIsInError;
SetExpressionDisplayFunc SetExpressionDisplay;
SetParenthesisNumberFunc SetParenthesisNumber;
OnNoRightParenAddedFunc OnNoRightParenAdded;
MaxDigitsReachedFunc MaxDigitsReached;
BinaryOperatorReceivedFunc BinaryOperatorReceived;
OnHistoryItemAddedFunc OnHistoryItemAdded;
SetMemorizedNumbersFunc SetMemorizedNumbers;
MemoryItemChangedFunc MemoryItemChanged;
void* ResourceState;
GetCEngineStringFunc GetCEngineString;
void* ResourceState;
GetCEngineStringFunc GetCEngineString;
};
#if defined(__EMSCRIPTEN__) || defined(__APPLE__)
@ -49,9 +50,9 @@ struct CalculatorManager_CreateParams {
GetHistoryItemResult* MarshalHistoryItem(std::shared_ptr<CalculationManager::HISTORYITEM>& historyItem);
void* MarshalHistoryItems(std::vector<std::shared_ptr<CalculationManager::HISTORYITEM>>& historyItems);
extern "C" {
struct GetHistoryItemsResult
extern "C"
{
struct GetHistoryItemsResult
{
int32_t ItemsCount;
void* HistoryItems;
@ -70,6 +71,18 @@ extern "C" {
void** Commands;
};
struct COpndCommand_GetCommandsResult
{
int32_t CommandCount;
int32_t* pCommands;
};
struct CUnaryCommand_GetCommandsResult
{
int32_t CommandCount;
int32_t* pCommands;
};
DLL_EXPORT void* CalculatorManager_Create(CalculatorManager_CreateParams* params);
DLL_EXPORT void CalculatorManager_SendCommand(void* manager, int command);
DLL_EXPORT void CalculatorManager_SetRadix(void* manager, RADIX_TYPE iRadixType);
@ -98,6 +111,14 @@ extern "C" {
DLL_EXPORT void* CalculatorManager_GetHistoryItems(void* manager);
DLL_EXPORT void* CalculatorManager_GetHistoryItem(void* manager, int index);
DLL_EXPORT int IExpressionCommand_GetCommandType(void* pExpressionCommand);
}
DLL_EXPORT void Free(void* ptr);
DLL_EXPORT int IExpressionCommand_GetCommandType(void* pExpressionCommand);
DLL_EXPORT void* COpndCommand_GetCommands(void* pExpressionCommand);
DLL_EXPORT bool COpndCommand_IsNegative(void* pExpressionCommand);
DLL_EXPORT void* CUnaryCommand_GetCommands(void* pExpressionCommand);
DLL_EXPORT int CBinaryCommand_GetCommand(void* pExpressionCommand);
}

View file

@ -9,12 +9,17 @@ namespace CalculatorApp
{
List<TType> m_vector;
public CalculatorList()
{
m_vector = new List<TType>();
}
public CalculatorList()
{
m_vector = new List<TType>();
}
public CalculatorList(CalculatorList<TType> source)
public CalculatorList(IEnumerable<TType> source)
{
m_vector = new List<TType>(source);
}
public CalculatorList(CalculatorList<TType> source)
{
m_vector = new List<TType>(source.m_vector);
}

View file

@ -99,15 +99,32 @@ namespace CalculationManager
[DllImport(DllPath)]
public static extern IntPtr CalculatorManager_GetHistoryItem(IntPtr nativeManager, int uIdx);
[DllImport(DllPath)]
public static extern int CBinaryCommand_GetCommand(IntPtr m_pExpressionCommand);
[DllImport(DllPath)]
public static extern void Free(IntPtr ptr);
[DllImport(DllPath)]
public static extern CommandType IExpressionCommand_GetCommandType(IntPtr pExpressionCommand);
[DllImport(DllPath)]
public static extern bool COpndCommand_IsNegative(IntPtr pExpressionCommand);
[DllImport(DllPath)]
public static extern IntPtr COpndCommand_GetCommands(IntPtr pExpressionCommand);
[DllImport(DllPath)]
public static extern IntPtr CUnaryCommand_GetCommands(IntPtr pExpressionCommand);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate IntPtr GetCEngineStringFunc(IntPtr state, IntPtr id);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void BinaryOperatorReceivedFunc(IntPtr state);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetPrimaryDisplayCallbackFunc(IntPtr state, IntPtr pDisplayStringValue, bool isError);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void SetIsInErrorCallbackFunc(IntPtr state, bool isError);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -353,8 +370,8 @@ namespace CalculationManager
[StructLayout(LayoutKind.Sequential)]
public struct GetHistoryItemResult
{
public string expression;
public string result;
public IntPtr expression;
public IntPtr result;
public int TokenCount;
public IntPtr TokenStrings;
@ -364,6 +381,19 @@ namespace CalculationManager
public IntPtr Commands;
}
[StructLayout(LayoutKind.Sequential)]
public struct COpndCommand_GetCommandsResult
{
public int CommandCount;
public IntPtr Commands;
}
[StructLayout(LayoutKind.Sequential)]
public struct CUnaryCommand_GetCommandsResult
{
public int CommandCount;
public IntPtr Commands;
}
public partial class CalculatorManager : ICalcDisplay
{
@ -371,6 +401,5 @@ namespace CalculationManager
private GCHandle _displayCallbackHandle;
private GCHandle _resourceProviderHandle;
private readonly IntPtr _nativeManager;
}
}

View file

@ -251,8 +251,8 @@ namespace CalculationManager
internal static HISTORYITEM UnmarshalHistoryItemResult(GetHistoryItemResult historyResultItem)
{
var historyItem = new HISTORYITEM();
historyItem.historyItemVector.expression = historyResultItem.expression;
historyItem.historyItemVector.result = historyResultItem.result;
historyItem.historyItemVector.expression = NativeDispatch.PtrToString(historyResultItem.expression);
historyItem.historyItemVector.result = NativeDispatch.PtrToString(historyResultItem.result);
historyItem.historyItemVector.spTokens = new CalculatorList<(string, int)>();
for (var i = 0; i < historyResultItem.TokenCount; i++)
@ -274,7 +274,7 @@ namespace CalculationManager
switch (commandType)
{
case CommandType.BinaryCommand:
return new CUnaryCommand(pExpressionCommand);
return new CBinaryCommand(pExpressionCommand);
case CommandType.OperandCommand:
return new COpndCommand(pExpressionCommand);

View file

@ -3,6 +3,7 @@
using CalculatorApp;
using System;
using System.Runtime.InteropServices;
namespace CalculationManager
{
@ -73,13 +74,27 @@ namespace CalculationManager
public class CUnaryCommand : IUnaryCommand
{
private IntPtr pExpressionCommand;
private IntPtr m_pExpressionCommand;
public CUnaryCommand(IntPtr pExpressionCommand) => this.pExpressionCommand = pExpressionCommand;
public CUnaryCommand(IntPtr pExpressionCommand) => this.m_pExpressionCommand = pExpressionCommand;
public CUnaryCommand(int command) => throw new NotImplementedException();
public CUnaryCommand(int command1, int command2) => throw new NotImplementedException();
public CalculatorList<int> GetCommands() => throw new NotImplementedException();
public CalculatorList<int> GetCommands()
{
var pResult = NativeDispatch.CUnaryCommand_GetCommands(m_pExpressionCommand);
var result = Marshal.PtrToStructure<CUnaryCommand_GetCommandsResult>(pResult);
int[] commandsArray = new int[result.CommandCount];
Marshal.Copy(result.Commands, commandsArray, 0, commandsArray.Length);
NativeDispatch.Free(result.Commands);
NativeDispatch.Free(pResult);
return new CalculatorList<int>(commandsArray);
}
public CalculationManager.CommandType GetCommandType() => CommandType.UnaryCommand;
public void SetCommand(int command) => throw new NotImplementedException();
public void SetCommands(int command1, int command2) => throw new NotImplementedException();
@ -88,32 +103,45 @@ namespace CalculationManager
public class CBinaryCommand : IBinaryCommand
{
private IntPtr pExpressionCommand;
private IntPtr m_pExpressionCommand;
public CBinaryCommand(IntPtr pExpressionCommand) => this.pExpressionCommand = pExpressionCommand;
public CBinaryCommand(IntPtr pExpressionCommand) => this.m_pExpressionCommand = pExpressionCommand;
public CBinaryCommand(int command) => throw new NotImplementedException();
public void SetCommand(int command) => throw new NotImplementedException();
public int GetCommand() => throw new NotImplementedException();
public int GetCommand() => NativeDispatch.CBinaryCommand_GetCommand(m_pExpressionCommand);
public CalculationManager.CommandType GetCommandType() => CommandType.BinaryCommand;
public void Accept(ISerializeCommandVisitor commandVisitor) => throw new NotImplementedException();
}
public class COpndCommand : IOpndCommand
{
private IntPtr pExpressionCommand;
private IntPtr m_pExpressionCommand;
public COpndCommand(CalculatorList<int> commands, bool fNegative, bool fDecimal, bool fSciFmt) => throw new NotImplementedException();
public COpndCommand(IntPtr pExpressionCommand) => this.pExpressionCommand = pExpressionCommand;
public COpndCommand(IntPtr pExpressionCommand) => this.m_pExpressionCommand = pExpressionCommand;
// public void Initialize(CalcEngine.Rational rat) => throw new NotImplementedException();
public CalculatorList<int> GetCommands() => throw new NotImplementedException();
public void SetCommands(CalculatorList<int> commands) => throw new NotImplementedException();
public CalculatorList<int> GetCommands()
{
var pResult = NativeDispatch.COpndCommand_GetCommands(m_pExpressionCommand);
var result = Marshal.PtrToStructure<COpndCommand_GetCommandsResult>(pResult);
int[] commandsArray = new int[result.CommandCount];
Marshal.Copy(result.Commands, commandsArray, 0, commandsArray.Length);
NativeDispatch.Free(result.Commands);
NativeDispatch.Free(pResult);
return new CalculatorList<int>(commandsArray);
}
public void SetCommands(CalculatorList<int> commands) => throw new NotImplementedException();
public void AppendCommand(int command) => throw new NotImplementedException();
public void ToggleSign() => throw new NotImplementedException();
public void RemoveFromEnd() => throw new NotImplementedException();
public bool IsNegative() => throw new NotImplementedException();
public bool IsNegative() => NativeDispatch.COpndCommand_IsNegative(m_pExpressionCommand);
public bool IsSciFmt() => throw new NotImplementedException();
public bool IsDecimalPresent() => throw new NotImplementedException();
public string GetToken(char decimalSymbol) => throw new NotImplementedException();

View file

@ -167,7 +167,7 @@ namespace CalculatorApp.Common
}
}
public FlowDirection GetFlowDirection()
public FlowDirection GetFlowDirection()
{
return m_flowDirection;
}

View file

@ -153,12 +153,12 @@ namespace CalculatorApp
calculatorDisplay.SetHistoryCallback(new WeakReference(this));
}
void ShowItem(HistoryItemViewModel e)
public void ShowItem(HistoryItemViewModel e)
{
HistoryItemClicked(e);
}
void DeleteItem(HistoryItemViewModel e)
public void DeleteItem(HistoryItemViewModel e)
{
int itemIndex= Items.IndexOf(e);
if (itemIndex != -1)

View file

@ -4,217 +4,199 @@
xmlns:automation="using:CalculatorApp.Common.Automation"
xmlns:controls="using:CalculatorApp.Controls"
xmlns:converters="using:CalculatorApp.Converters"
xmlns:local="using:CalculatorApp.Views"
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"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
AutomationProperties.AutomationId="HistoryList"
FlowDirection="LeftToRight"
mc:Ignorable="">
mc:Ignorable="d">
<!--UNO TODO
x:Name="HistoryList"
Loaded="HistoryList_Loaded"
Unloaded="HistoryList_Unloaded"
-->
<!-- UNO TODO x:Name="HistoryList"-->
<!--<UserControl.Resources>
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Default">
<Style x:Key="BodyTextBlockMediumStyle"
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="Foreground"
Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}"/>
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="Light">
<Style x:Key="BodyTextBlockMediumStyle"
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="Foreground"
Value="{ThemeResource SystemControlForegroundBaseMediumBrush}" />
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock">
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseMediumBrush}"/>
</Style>
</ResourceDictionary>
<ResourceDictionary x:Key="HighContrast">
<Style x:Key="BodyTextBlockMediumStyle"
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock" />
BasedOn="{StaticResource BodyTextBlockStyle}"
TargetType="TextBlock"/>
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
<converters:ItemSizeToVisibilityNegationConverter x:Key="ItemSizeToVisibilityNegationConverter" />
<converters:ItemSizeToVisibilityConverter x:Key="ItemSizeToVisibilityConverter" />
--><!--
UNO TODO
<automation:NarratorNotifier x:Name="NarratorNotifier"
Announcement="{x:Bind Model.HistoryAnnouncement, Mode=OneWay}" />
--><!--
--><!--
UNO TODO
<muxc:SymbolIconSource x:Key="DeleteSymbol"
Symbol="Delete" />
<muxc:SwipeItems x:Key="HistorySwipeItems"
Mode="Execute">
<muxc:SwipeItem x:Uid="DeleteHistorySwipeItem"
IconSource="{StaticResource DeleteSymbol}"
Invoked="OnDeleteSwipeInvoked" />
</muxc:SwipeItems>
--><!--
<converters:ItemSizeToVisibilityNegationConverter x:Key="ItemSizeToVisibilityNegationConverter"/>
<converters:ItemSizeToVisibilityConverter x:Key="ItemSizeToVisibilityConverter"/>
<MenuFlyout x:Key="HistoryContextMenu">
<MenuFlyoutItem x:Uid="DeleteHistoryMenuItem"
Click="OnDeleteMenuItemClicked"
Icon="Delete" />
Click="OnDeleteMenuItemClicked"
Icon="Delete"/>
</MenuFlyout>
<DataTemplate x:Key="HistoryItemTemplate"
x:DataType="model:HistoryItemViewModel">
--><!-- UNO TODO
<!--
UNO TODO
<automation:NarratorNotifier x:Name="NarratorNotifier" Announcement="{x:Bind Model.HistoryAnnouncement, Mode=OneWay}"/>
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
<muxc:SymbolIconSource x:Key="DeleteSymbol" Symbol="Delete"/>
<muxc:SwipeItems x:Key="HistorySwipeItems" Mode="Execute">
<muxc:SwipeItem x:Uid="DeleteHistorySwipeItem"
IconSource="{StaticResource DeleteSymbol}"
Invoked="OnDeleteSwipeInvoked"/>
</muxc:SwipeItems>
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
<StackPanel Margin="0,6,4,6"
Background="Transparent"
ContextFlyout="{StaticResource HistoryContextMenu}">
<TextBlock x:Name="exprTextBlock"
Margin="0,0,0,4"
Style="{ThemeResource BodyTextBlockMediumStyle}"
AutomationProperties.Name="{x:Bind AccExpression}"
Text="{x:Bind Expression}"
TextAlignment="Right"
TextWrapping="Wrap" />
<TextBlock x:Name="resultTextBlock"
Style="{ThemeResource TitleTextBlockStyle}"
FontWeight="SemiBold"
AutomationProperties.Name="{x:Bind AccResult}"
Text="{x:Bind Result}"
TextAlignment="Right"
TextWrapping="Wrap" />
Background="Transparent"
ContextFlyout="{StaticResource HistoryContextMenu}">
<TextBlock x:Name="ExprTextBlock"
Margin="0,0,0,4"
HorizontalAlignment="Right"
Style="{ThemeResource BodyTextBlockMediumStyle}"
AutomationProperties.Name="{x:Bind AccExpression}"
IsTextSelectionEnabled="True"
Text="{x:Bind Expression}"
TextAlignment="Right"
TextWrapping="Wrap"/>
<TextBlock x:Name="ResultTextBlock"
HorizontalAlignment="Right"
Style="{ThemeResource TitleTextBlockStyle}"
FontWeight="SemiBold"
AutomationProperties.Name="{x:Bind AccResult}"
IsTextSelectionEnabled="True"
Text="{x:Bind Result}"
TextAlignment="Right"
TextWrapping="Wrap"/>
</StackPanel>
</muxc:SwipeControl>--><!--
<TextBlock Text="TODO HistoryItemTemplate not supported"/>
</muxc:SwipeControl>
</DataTemplate>
-->
<Style x:Key="HistoryItemContainerStyle"
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
TargetType="ListViewItem">
<Setter Property="Margin" Value="0,0,0,20"/>
</Style>
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
<StackPanel Margin="0,6,4,6"
Background="Transparent"
ContextFlyout="{StaticResource HistoryContextMenu}">
<TextBlock x:Name="ExprTextBlock"
Margin="0,0,0,4"
HorizontalAlignment="Right"
Style="{ThemeResource BodyTextBlockMediumStyle}"
AutomationProperties.Name="{x:Bind AccExpression}"
IsTextSelectionEnabled="True"
Text="{x:Bind Expression}"
TextAlignment="Right"
TextWrapping="Wrap"/>
<TextBlock x:Name="ResultTextBlock"
HorizontalAlignment="Right"
Style="{ThemeResource TitleTextBlockStyle}"
FontWeight="SemiBold"
AutomationProperties.Name="{x:Bind AccResult}"
IsTextSelectionEnabled="True"
Text="{x:Bind Result}"
TextAlignment="Right"
TextWrapping="Wrap"/>
</StackPanel>
</DataTemplate>
<Style x:Key="HistoryItemContainerStyle"
BasedOn="{StaticResource HistoryMemoryItemContainerStyle}"
TargetType="ListViewItem">
<Setter Property="Margin"
Value="0,0,0,20" />
</Style>
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="LayoutGrid">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="{Binding RowHeight, ElementName=HistoryList, Mode=OneWay}" />
<RowDefinition Height="*"/>
<RowDefinition Height="{Binding RowHeight, ElementName=HistoryList, Mode=OneWay}"/>
</Grid.RowDefinitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="DockedLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="560" />
<AdaptiveTrigger MinWindowWidth="560"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="HistoryListRootGrid.(Grid.Row)"
Value="1" />
<Setter Target="HistoryListRootGrid.(Grid.RowSpan)"
Value="2" />
<Setter Target="HistoryListView.Padding"
Value="0" />
<Setter Target="BackgroundShade.Opacity"
Value="0" />
<Setter Target="CustomTitleBar.Height"
Value="0" />
<Setter Target="HistoryListRootGrid.(Grid.Row)" Value="0"/>
<Setter Target="HistoryListRootGrid.(Grid.RowSpan)" Value="2"/>
<Setter Target="HistoryListView.Padding" Value="0"/>
<Setter Target="BackgroundShade.Visibility" Value="Collapsed"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="DefaultLayout">
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="0" />
<AdaptiveTrigger MinWindowWidth="0"/>
</VisualState.StateTriggers>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Border x:Name="BackgroundShade"
Grid.Row="2"
Margin="0,-1,0,0"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{ThemeResource SystemControlChromeMediumLowAcrylicElementMediumBrush}"
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="{ThemeResource HighContrastThicknessTop}" />
<Grid x:Name="HistoryListRootGrid"
Grid.Row="2">
Grid.Row="1"
Margin="0,-1,0,0"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{ThemeResource SystemControlChromeMediumLowAcrylicElementMediumBrush}"
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="{ThemeResource HighContrastThicknessTop}"/>
<Grid x:Name="HistoryListRootGrid" Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock x:Name="HistoryEmpty"
x:Uid="HistoryEmpty"
Margin="12,14,24,0"
Style="{ThemeResource BaseTextBlockStyle}"
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
TextWrapping="Wrap"
Visibility="{Binding ItemSize, Converter={StaticResource ItemSizeToVisibilityConverter}}" />
x:Uid="HistoryEmpty"
Margin="12,14,24,0"
Style="{ThemeResource BaseTextBlockStyle}"
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
TextWrapping="Wrap"
Visibility="{Binding ItemSize, Converter={StaticResource ItemSizeToVisibilityConverter}}"/>
<ListView x:Name="HistoryListView"
MinHeight="60"
Padding="0,12,0,0"
HorizontalAlignment="Stretch"
AutomationProperties.AutomationId="HistoryListView"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemContainerStyle="{StaticResource HistoryItemContainerStyle}"
ItemTemplate="{StaticResource HistoryItemTemplate}"
ItemsSource="{x:Bind Model.Items, Mode=OneWay}"
SelectionMode="None"
TabIndex="0"
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}">
MinHeight="60"
Padding="0,12,0,0"
HorizontalAlignment="Stretch"
AutomationProperties.AutomationId="HistoryListView"
IsItemClickEnabled="True"
ItemClick="ListView_ItemClick"
ItemContainerStyle="{StaticResource HistoryItemContainerStyle}"
ItemTemplate="{StaticResource HistoryItemTemplate}"
ItemsSource="{x:Bind Model.Items, Mode=OneWay}"
SelectionMode="None"
TabIndex="0"
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}">
<ListView.ItemContainerTransitions>
<TransitionCollection>
<AddDeleteThemeTransition />
<ContentThemeTransition />
<ReorderThemeTransition />
<AddDeleteThemeTransition/>
<ContentThemeTransition/>
<ReorderThemeTransition/>
</TransitionCollection>
</ListView.ItemContainerTransitions>
</ListView>
<Button x:Name="ClearHistory"
x:Uid="ClearHistory"
Grid.Row="1"
Style="{StaticResource ClearAllHistoryMemoryButtonStyle}"
AutomationProperties.AutomationId="ClearHistory"
Command="{x:Bind Model.ClearCommand, Mode=OneWay}"
Content="&#xE74D;"
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}" />
x:Uid="ClearHistory"
Grid.Row="1"
Style="{StaticResource ClearAllHistoryMemoryButtonStyle}"
AutomationProperties.AutomationId="ClearHistory"
Command="{x:Bind Model.ClearCommand, Mode=OneWay}"
Content="&#xE74D;"
Visibility="{x:Bind Model.ItemSize, Mode=OneWay, Converter={StaticResource ItemSizeToVisibilityNegationConverter}}"/>
</Grid>
<Border x:Name="CustomTitleBar"
Height="32"
HorizontalAlignment="Stretch"
Background="{ThemeResource TitleBarBackgroundTransparentBrush}" />
</Grid>-->
</Grid>
</UserControl>

View file

@ -1,27 +1,73 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using CalculatorApp.Common;
using CalculatorApp.ViewModel;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236
namespace CalculatorApp
{
public sealed partial class HistoryList : UserControl
public partial class HistoryList
{
public HistoryViewModel Model => (CalculatorApp.ViewModel.HistoryViewModel)(this.DataContext);
public GridLength RowHeight
{
get { return (GridLength)GetValue(RowHeightProperty); }
set { SetValue(RowHeightProperty, value); }
}
// Using a DependencyProperty as the backing store for RowHeight. This enables animation, styling, binding, etc...
public static readonly DependencyProperty RowHeightProperty =
DependencyProperty.Register("RowHeight", typeof(GridLength), typeof(HistoryList), new PropertyMetadata(GridLength.Auto));
Windows.Foundation.Rect m_visibleBounds;
Windows.Foundation.Rect m_coreBounds;
public HistoryList()
{
this.InitializeComponent();
InitializeComponent();
HistoryEmpty.FlowDirection = LocalizationService.GetInstance().GetFlowDirection();
}
}
void ListView_ItemClick(object sender, ItemClickEventArgs e)
{
HistoryViewModel historyVM = (HistoryViewModel)(this.DataContext);
HistoryItemViewModel clickedItem = (HistoryItemViewModel)(e.ClickedItem);
// When the user clears the history list in the overlay view and presses enter, the clickedItem is null
if (clickedItem != null)
{
historyVM.ShowItem(clickedItem);
}
}
void OnDeleteMenuItemClicked(object sender, RoutedEventArgs e)
{
var clickedItem = (HistoryItemViewModel)((FrameworkElement)sender).DataContext;
Model.DeleteItem(clickedItem);
}
#if false // UNO TODO
void OnDeleteSwipeInvoked(MUXC.SwipeItem sender, MUXC.SwipeItemInvokedEventArgs e)
{
var swipedItem = safe_cast<HistoryItemViewModel>(e.SwipeControl.DataContext);
Model.DeleteItem(swipedItem);
}
#endif
void ScrollToBottom()
{
var historyItems = this.HistoryListView.Items;
if (historyItems.Count > 0)
{
this.HistoryListView.ScrollIntoView(historyItems[historyItems.Count - 1]);
}
}
};
}

View file

@ -127,27 +127,24 @@
Grid.Row="0"
Visibility="Collapsed"/>
<!--
x:Uid="NavView"
IsBackButtonVisible="Collapsed"
PaneClosed="OnNavPaneClosed"
PaneOpened="OnNavPaneOpened"
PaneOpening="OnNavPaneOpening"
-->
<!--UNO TODO
CompactModeThresholdWidth="Infinity"
ExpandedModeThresholdWidth="Infinity"
-->
<NavigationView x:Name="NavView"
Grid.Row="2"
DataContext="{x:Bind Model}"
IsSettingsVisible="False"
Loaded="OnNavLoaded"
MenuItemsSource="{x:Bind UIElementsForCategories, Mode=OneWay}"
OpenPaneLength="{StaticResource SplitViewOpenPaneLength}"
SelectionChanged="OnNavSelectionChanged"
TabIndex="1"
UseSystemFocusVisuals="True">
CompactModeThresholdWidth="10000"
ExpandedModeThresholdWidth="10000"
IsBackButtonVisible="Collapsed"
PaneClosed="OnNavPaneClosed"
PaneOpened="OnNavPaneOpened"
PaneOpening="OnNavPaneOpening"
Grid.Row="2"
DataContext="{x:Bind Model}"
IsSettingsVisible="False"
Loaded="OnNavLoaded"
MenuItemsSource="{x:Bind UIElementsForCategories, Mode=OneWay}"
OpenPaneLength="{StaticResource SplitViewOpenPaneLength}"
SelectionChanged="OnNavSelectionChanged"
TabIndex="1"
UseSystemFocusVisuals="True">
<NavigationView.PaneFooter>

View file

@ -77,7 +77,11 @@ namespace CalculatorApp
{
initialized = true;
NavView.DataContext = m_model;
if (NavView != null)
{
// UNO TODO OnNavigatedTo/Loaded Sequence is different
NavView.DataContext = m_model;
}
if (m_model.CalculatorViewModel != null)
{