Format MathML equations before submission to the GraphControl (#926)

* Format richedit input

* fix spelling error
This commit is contained in:
Pepe Rivera
2020-01-10 15:17:36 -08:00
committed by Stephanie Anderl
parent c8a67eb574
commit 397c180d52
12 changed files with 60 additions and 3 deletions

View File

@@ -54,6 +54,7 @@ void EquationTextBox::OnApplyTemplate()
m_richEditBox->SelectionFlyout = nullptr;
m_richEditBox->EquationSubmitted +=
ref new EventHandler<MathRichEditBoxSubmission ^>(this, &EquationTextBox::OnEquationSubmitted);
m_richEditBox->FormatRequest += ref new EventHandler<MathRichEditBoxFormatRequest ^>(this, &EquationTextBox::OnEquationFormatRequested);
}
if (m_equationButton != nullptr)
@@ -381,3 +382,8 @@ void EquationTextBox::OnEquationSubmitted(Platform::Object ^ sender, MathRichEdi
EquationSubmitted(this, args);
}
void EquationTextBox::OnEquationFormatRequested(Object ^ sender, MathRichEditBoxFormatRequest ^ args)
{
EquationFormatRequested(this, args);
}

View File

@@ -30,6 +30,7 @@ namespace CalculatorApp
event Windows::UI::Xaml::RoutedEventHandler ^ RemoveButtonClicked;
event Windows::UI::Xaml::RoutedEventHandler ^ KeyGraphFeaturesButtonClicked;
event Windows::Foundation::EventHandler<MathRichEditBoxSubmission ^> ^ EquationSubmitted;
event Windows::Foundation::EventHandler<MathRichEditBoxFormatRequest ^> ^ EquationFormatRequested;
event Windows::UI::Xaml::RoutedEventHandler ^ EquationButtonClicked;
Platform::String ^ GetEquationText();
@@ -79,6 +80,7 @@ namespace CalculatorApp
bool m_isPointerOver;
bool m_isColorChooserFlyoutOpen;
void OnEquationSubmitted(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxSubmission ^ args);
void OnEquationFormatRequested(Platform::Object ^ sender, CalculatorApp::Controls::MathRichEditBoxFormatRequest ^ args);
};
}
}

View File

@@ -190,6 +190,15 @@ void MathRichEditBox::SubmitEquation(EquationSubmissionSource source)
auto newVal = GetMathTextProperty();
if (MathText != newVal)
{
// Request the final formatting of the text
auto formatRequest = ref new MathRichEditBoxFormatRequest(newVal);
FormatRequest(this, formatRequest);
if (!formatRequest->FormattedText->IsEmpty())
{
newVal = formatRequest->FormattedText;
}
SetValue(MathTextProperty, newVal);
EquationSubmitted(this, ref new MathRichEditBoxSubmission(true, source));
}

View File

@@ -30,6 +30,20 @@ namespace CalculatorApp
}
};
public
ref class MathRichEditBoxFormatRequest sealed
{
public:
PROPERTY_R(Platform::String^, OriginalText);
PROPERTY_RW(Platform::String ^, FormattedText);
public:
MathRichEditBoxFormatRequest(Platform::String^ originalText)
{
m_OriginalText = originalText;
}
};
public
ref class MathRichEditBox sealed : Windows::UI::Xaml::Controls::RichEditBox
{
@@ -39,6 +53,7 @@ namespace CalculatorApp
DEPENDENCY_PROPERTY_OWNER(MathRichEditBox);
DEPENDENCY_PROPERTY_WITH_DEFAULT_AND_CALLBACK(Platform::String ^, MathText, L"");
event Windows::Foundation::EventHandler<MathRichEditBoxFormatRequest ^> ^ FormatRequest;
event Windows::Foundation::EventHandler<MathRichEditBoxSubmission^> ^ EquationSubmitted;
void OnMathTextPropertyChanged(Platform::String ^ oldValue, Platform::String ^ newValue);
void InsertText(Platform::String ^ text, int cursorOffSet, int selectionLength);