Update share output (#782)
* fix share bugs * PR feedback * PR feedback and merge fix * Fix spacing and use explicit break * Fix extra space
This commit is contained in:
committed by
Stephanie Anderl
parent
afc1b2146c
commit
b55659f236
@@ -50,10 +50,10 @@
|
||||
<graphControl:Grapher Name="GraphingControl"
|
||||
EquationsSource="{x:Bind ViewModel.Equations, Mode=OneWay}"
|
||||
ForceProportionalAxes="True"
|
||||
LosingFocus="OnLoosingFocus"
|
||||
LostFocus="OnGraphLostFocus"
|
||||
LosingFocus="GraphingControl_LosingFocus"
|
||||
LostFocus="GraphingControl_LostFocus"
|
||||
UseSystemFocusVisuals="True"
|
||||
VariablesUpdated="GraphVariablesUpdated">
|
||||
VariablesUpdated="GraphingControl_VariablesUpdated">
|
||||
<graphControl:Grapher.Background>
|
||||
<SolidColorBrush Color="White"/>
|
||||
</graphControl:Grapher.Background>
|
||||
|
@@ -2,17 +2,21 @@
|
||||
// Licensed under the MIT License.
|
||||
|
||||
#include "pch.h"
|
||||
#include "CalcViewModel/Common/TraceLogger.h"
|
||||
#include "GraphingCalculator.xaml.h"
|
||||
#include "CalcViewModel/Common/TraceLogger.h"
|
||||
#include "CalcViewModel/Common/LocalizationSettings.h"
|
||||
#include "CalcViewModel/Common/KeyboardShortcutManager.h"
|
||||
#include "Controls/CalculationResult.h"
|
||||
#include "Calculator\Controls\EquationTextBox.h"
|
||||
#include "Calculator\Views\GraphingCalculator\EquationInputArea.xaml.h"
|
||||
#include "CalcManager/NumberFormattingUtils.h"
|
||||
#include "Calculator/Controls/EquationTextBox.h"
|
||||
#include "Calculator/Views/GraphingCalculator/EquationInputArea.xaml.h"
|
||||
#include "CalcViewModel/Common/Utils.h"
|
||||
|
||||
using namespace CalculatorApp;
|
||||
using namespace CalculatorApp::Common;
|
||||
using namespace CalculatorApp::Controls;
|
||||
using namespace CalculatorApp::ViewModel;
|
||||
using namespace CalcManager::NumberFormattingUtils;
|
||||
using namespace concurrency;
|
||||
using namespace GraphControl;
|
||||
using namespace Platform;
|
||||
@@ -21,6 +25,7 @@ using namespace std;
|
||||
using namespace std::chrono;
|
||||
using namespace Utils;
|
||||
using namespace Windows::ApplicationModel::DataTransfer;
|
||||
using namespace Windows::ApplicationModel::Resources;
|
||||
using namespace Windows::Foundation;
|
||||
using namespace Windows::Foundation::Collections;
|
||||
using namespace Windows::Storage::Streams;
|
||||
@@ -109,79 +114,94 @@ void CalculatorApp::GraphingCalculator::OnShareClick(Platform::Object ^ sender,
|
||||
// data to be shared. We will request the current graph image from the grapher as a stream that will pass to the share request.
|
||||
void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataRequestedEventArgs ^ args)
|
||||
{
|
||||
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
|
||||
auto resourceLoader = ResourceLoader::GetForCurrentView();
|
||||
|
||||
try
|
||||
{
|
||||
// Get our title from the localized resources
|
||||
auto EmptyEquationString = resourceLoader->GetString(L"EmptyEquationString");
|
||||
std::wstringstream rawHtml;
|
||||
std::wstringstream equationHtml;
|
||||
|
||||
std::wstring rawHtml = L"<p><img src='graph.png'></p>";
|
||||
rawHtml << L"<p><img src='graph.png' width='600' alt='" << resourceLoader->GetString(L"GraphImageAltText")->Data() << "'></p>";
|
||||
|
||||
auto equations = ViewModel->Equations;
|
||||
rawHtml += L"<p><table cellpadding=\"10\">";
|
||||
rawHtml += L"<col width=\"20\">";
|
||||
rawHtml += L"<row height=\"20\">";
|
||||
for (unsigned i = 0; i < equations->Size; i++)
|
||||
bool hasEquations = false;
|
||||
|
||||
if (equations->Size > 0)
|
||||
{
|
||||
auto expression = equations->GetAt(i)->Expression->Data();
|
||||
auto color = equations->GetAt(i)->LineColor->Color;
|
||||
equationHtml << L"<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size : 13pt;\">";
|
||||
equationHtml << resourceLoader->GetString(L"EquationsShareHeader")->Data();
|
||||
equationHtml << L"</span>";
|
||||
equationHtml << L"<table cellpadding=\"0\">";
|
||||
|
||||
if (equations->GetAt(i)->Expression->Length() == 0)
|
||||
for (auto equation : equations)
|
||||
{
|
||||
expression = EmptyEquationString->Data();
|
||||
auto expression = equation->Expression;
|
||||
if (expression->IsEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
auto color = equation->LineColor->Color;
|
||||
hasEquations = true;
|
||||
|
||||
expression = GraphingControl->ConvertToLinear(expression);
|
||||
|
||||
std::wstringstream equationColorHtml;
|
||||
equationColorHtml << L"color:rgb(" << color.R.ToString()->Data() << L"," << color.G.ToString()->Data() << L"," << color.B.ToString()->Data()
|
||||
<< L");";
|
||||
|
||||
equationHtml << L"<tr><td><span style=\"line-height: 0; font-size: 24pt;" << equationColorHtml.str()
|
||||
<< L"\">■</span></td><td><div style=\"margin: 4pt 0pt 0pt 0pt; \">";
|
||||
equationHtml << EscapeHtmlSpecialCharacters(expression)->Data();
|
||||
equationHtml << L"</div></td>";
|
||||
}
|
||||
|
||||
rawHtml += L"<tr>";
|
||||
|
||||
rawHtml += L"<td style=\"background-color:rgb(";
|
||||
rawHtml += color.R.ToString()->Data();
|
||||
rawHtml += L",";
|
||||
rawHtml += color.G.ToString()->Data();
|
||||
rawHtml += L",";
|
||||
rawHtml += color.B.ToString()->Data();
|
||||
rawHtml += L"); \">";
|
||||
rawHtml += L"</td>";
|
||||
rawHtml += L"<td>";
|
||||
rawHtml += expression;
|
||||
rawHtml += L"</td>";
|
||||
|
||||
rawHtml += L"</tr>";
|
||||
equationHtml << L"</table>";
|
||||
}
|
||||
|
||||
if (hasEquations)
|
||||
{
|
||||
rawHtml << equationHtml.str();
|
||||
}
|
||||
rawHtml += L"</table></p>";
|
||||
|
||||
auto variables = ViewModel->Variables;
|
||||
rawHtml += L"<p><table cellpadding=\"10\">";
|
||||
rawHtml += L"<col width=\"20\">";
|
||||
rawHtml += L"<row height=\"20\">";
|
||||
for (unsigned i = 0; i < variables->Size; i++)
|
||||
|
||||
if (variables->Size > 0)
|
||||
{
|
||||
auto name = variables->GetAt(i)->Name;
|
||||
auto value = variables->GetAt(i)->Value;
|
||||
auto localizedSeperator = LocalizationSettings::GetInstance().GetListSeparator() + L" ";
|
||||
|
||||
if (name->Length() >= 0)
|
||||
rawHtml << L"<span style=\"color: rgb(68, 114, 196); font-style: bold; font-size: 13pt;\">";
|
||||
rawHtml << resourceLoader->GetString(L"VariablesShareHeader")->Data();
|
||||
rawHtml << L"</span><br><span>";
|
||||
|
||||
for (unsigned i = 0; i < variables->Size; i++)
|
||||
{
|
||||
rawHtml += L"<tr>";
|
||||
auto name = variables->GetAt(i)->Name;
|
||||
auto value = variables->GetAt(i)->Value;
|
||||
|
||||
rawHtml += L"<td>";
|
||||
rawHtml += name->Data();
|
||||
rawHtml += L"</td>";
|
||||
rawHtml += L"<td>";
|
||||
rawHtml += std::to_wstring(value);
|
||||
rawHtml += L"</td>";
|
||||
rawHtml << name->Data();
|
||||
rawHtml << L"=";
|
||||
auto formattedValue = to_wstring(value);
|
||||
TrimTrailingZeros(formattedValue);
|
||||
rawHtml << formattedValue;
|
||||
|
||||
rawHtml += L"</tr>";
|
||||
if (variables->Size - 1 != i)
|
||||
{
|
||||
rawHtml << localizedSeperator;
|
||||
}
|
||||
}
|
||||
|
||||
rawHtml << L"</span>";
|
||||
}
|
||||
rawHtml += L"</table></p>";
|
||||
|
||||
rawHtml << L"<br><br>";
|
||||
|
||||
// Shortcut to the request data
|
||||
auto requestData = args->Request->Data;
|
||||
|
||||
DataPackage ^ dataPackage = ref new DataPackage();
|
||||
auto html = HtmlFormatHelper::CreateHtmlFormat(ref new String(rawHtml.c_str()));
|
||||
auto html = HtmlFormatHelper::CreateHtmlFormat(ref new String(rawHtml.str().c_str()));
|
||||
|
||||
auto titleString = resourceLoader->GetString(L"ShareActionTitle");
|
||||
requestData->Properties->Title = titleString;
|
||||
requestData->Properties->Title = resourceLoader->GetString(L"ShareActionTitle");
|
||||
|
||||
requestData->SetHtmlFormat(html);
|
||||
|
||||
@@ -191,26 +211,21 @@ void GraphingCalculator::OnDataRequested(DataTransferManager ^ sender, DataReque
|
||||
|
||||
// Set the thumbnail image (in case the share target can't handle HTML)
|
||||
requestData->Properties->Thumbnail = bitmapStream;
|
||||
|
||||
// And the bitmap (in case the share target can't handle HTML)
|
||||
requestData->SetBitmap(bitmapStream);
|
||||
}
|
||||
catch (Exception ^ ex)
|
||||
{
|
||||
TraceLogger::GetInstance().LogPlatformException(ViewMode::Graphing, __FUNCTIONW__, ex);
|
||||
|
||||
// Something went wrong, notify the user.
|
||||
auto errorTitleString = resourceLoader->GetString(L"ShareActionErrorMessage");
|
||||
auto errorOkString = resourceLoader->GetString(L"ShareActionErrorOk");
|
||||
auto errDialog = ref new Windows::UI::Xaml::Controls::ContentDialog();
|
||||
|
||||
errDialog->Content = errorTitleString;
|
||||
errDialog->CloseButtonText = errorOkString;
|
||||
auto errDialog = ref new ContentDialog();
|
||||
errDialog->Content = resourceLoader->GetString(L"ShareActionErrorMessage");
|
||||
errDialog->CloseButtonText = resourceLoader->GetString(L"ShareActionErrorOk");
|
||||
errDialog->ShowAsync();
|
||||
}
|
||||
}
|
||||
|
||||
void GraphingCalculator::GraphVariablesUpdated(Object ^, Object ^)
|
||||
void GraphingCalculator::GraphingControl_VariablesUpdated(Object ^, Object ^)
|
||||
{
|
||||
m_viewModel->UpdateVariables(GraphingControl->Variables);
|
||||
}
|
||||
@@ -287,14 +302,14 @@ void GraphingCalculator::OnZoomResetCommand(Object ^ /* parameter */)
|
||||
GraphingControl->ResetGrid();
|
||||
}
|
||||
|
||||
void GraphingCalculator::OnActiveTracingClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
void GraphingCalculator::OnActiveTracingClick(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
// The focus change to this button will have turned off the tracing if it was on
|
||||
ActiveTracingOn = !ActiveTracingOn;
|
||||
GraphingControl->ActiveTracing = ActiveTracingOn;
|
||||
}
|
||||
|
||||
void CalculatorApp::GraphingCalculator::OnGraphLostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
void GraphingCalculator::GraphingControl_LostFocus(Object ^ sender, RoutedEventArgs ^ e)
|
||||
{
|
||||
// If the graph is losing focus while we are in active tracing we need to turn it off so we don't try to eat keys in other controls.
|
||||
if (GraphingControl->ActiveTracing)
|
||||
@@ -304,9 +319,9 @@ void CalculatorApp::GraphingCalculator::OnGraphLostFocus(Platform::Object ^ send
|
||||
}
|
||||
}
|
||||
|
||||
void CalculatorApp::GraphingCalculator::OnLoosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args)
|
||||
void GraphingCalculator::GraphingControl_LosingFocus(UIElement ^ sender, LosingFocusEventArgs ^ args)
|
||||
{
|
||||
FrameworkElement ^ newFocusElement = (FrameworkElement ^) args->NewFocusedElement;
|
||||
auto newFocusElement = dynamic_cast<FrameworkElement ^>(args->NewFocusedElement);
|
||||
if (newFocusElement == nullptr || newFocusElement->Name == nullptr)
|
||||
{
|
||||
// Because clicking on the swap chain panel will try to move focus to a control that can't actually take focus
|
||||
|
@@ -33,7 +33,6 @@ namespace CalculatorApp
|
||||
private:
|
||||
void GraphingCalculator_DataContextChanged(Windows::UI::Xaml::FrameworkElement^ sender, Windows::UI::Xaml::DataContextChangedEventArgs^ args);
|
||||
|
||||
void GraphVariablesUpdated(Platform::Object^ sender, Object^ args);
|
||||
void OnVariableChanged(Platform::Object^ sender, CalculatorApp::ViewModel::VariableChangedEventArgs args);
|
||||
|
||||
void TextBoxLosingFocus(Windows::UI::Xaml::Controls::TextBox^ textbox, Windows::UI::Xaml::Input::LosingFocusEventArgs^ args);
|
||||
@@ -60,8 +59,9 @@ namespace CalculatorApp
|
||||
|
||||
void TextBoxGotFocus(Windows::UI::Xaml::Controls::TextBox^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
|
||||
void OnActiveTracingClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnGraphLostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnLoosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
|
||||
void GraphingControl_LostFocus(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void GraphingControl_LosingFocus(Windows::UI::Xaml::UIElement ^ sender, Windows::UI::Xaml::Input::LosingFocusEventArgs ^ args);
|
||||
void GraphingControl_VariablesUpdated(Platform::Object ^ sender, Object ^ args);
|
||||
void OnEquationKeyGraphFeaturesVisibilityChanged(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void OnKeyGraphFeaturesClosed(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
bool ActiveTracingOn;
|
||||
|
Reference in New Issue
Block a user