diff --git a/apps/calculation/edit_expression_controller.cpp b/apps/calculation/edit_expression_controller.cpp index bcb0540bc..f46b16622 100644 --- a/apps/calculation/edit_expression_controller.cpp +++ b/apps/calculation/edit_expression_controller.cpp @@ -69,7 +69,7 @@ bool EditExpressionController::textFieldDidReceiveEvent(::TextField * textField, if (inputViewDidReceiveEvent(event, shouldDuplicateLastCalculation)) { return true; } - return app()->textFieldDidReceiveEvent(textField, event); + return textFieldDelegateApp()->textFieldDidReceiveEvent(textField, event); } bool EditExpressionController::textFieldDidFinishEditing(::TextField * textField, const char * text, Ion::Events::Event event) { @@ -120,10 +120,11 @@ bool EditExpressionController::inputViewDidReceiveEvent(Ion::Events::Event event if (shouldDuplicateLastCalculation && m_cacheBuffer[0] != 0) { /* The input text store in m_cacheBuffer might have beed correct the first * time but then be too long when replacing ans in another context */ - if (!app()->isAcceptableText(m_cacheBuffer)) { + Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp(); + if (!myApp->isAcceptableText(m_cacheBuffer)) { return true; } - m_calculationStore->push(m_cacheBuffer, app()->localContext()); + m_calculationStore->push(m_cacheBuffer, myApp->localContext()); m_historyController->reload(); ((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); return true; @@ -147,7 +148,7 @@ bool EditExpressionController::inputViewDidFinishEditing(const char * text, Layo } else { layoutR.serializeParsedExpression(m_cacheBuffer, k_cacheBufferSize); } - m_calculationStore->push(m_cacheBuffer, app()->localContext()); + m_calculationStore->push(m_cacheBuffer, textFieldDelegateApp()->localContext()); m_historyController->reload(); ((ContentView *)view())->mainView()->scrollToCell(0, m_historyController->numberOfRows()-1); ((ContentView *)view())->expressionField()->setEditing(true, true); diff --git a/apps/graph/graph/calculation_graph_controller.cpp b/apps/graph/graph/calculation_graph_controller.cpp index bb9513eec..dafde5ae7 100644 --- a/apps/graph/graph/calculation_graph_controller.cpp +++ b/apps/graph/graph/calculation_graph_controller.cpp @@ -48,7 +48,7 @@ Expression::Coordinate2D CalculationGraphController::computeNewPointOfInteresetF double step = m_graphRange->xGridUnit()/10.0; step = direction < 0 ? -step : step; double max = direction > 0 ? m_graphRange->xMax() : m_graphRange->xMin(); - return computeNewPointOfInterest(start, step, max, app()->localContext()); + return computeNewPointOfInterest(start, step, max, textFieldDelegateApp()->localContext()); } CartesianFunctionStore * CalculationGraphController::functionStore() const { diff --git a/apps/graph/graph/graph_controller.cpp b/apps/graph/graph/graph_controller.cpp index 30171637f..7240e0ba7 100644 --- a/apps/graph/graph/graph_controller.cpp +++ b/apps/graph/graph/graph_controller.cpp @@ -43,9 +43,10 @@ void GraphController::setDisplayDerivativeInBanner(bool displayDerivative) { float GraphController::interestingXHalfRange() const { float characteristicRange = 0.0f; + Poincare::Context * context = textFieldDelegateApp()->localContext(); for (int i = 0; i < functionStore()->numberOfActiveFunctions(); i++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); - float fRange = f->expressionReduced(app()->localContext()).characteristicXRange(*(app()->localContext()), Poincare::Preferences::sharedPreferences()->angleUnit()); + float fRange = f->expressionReduced(context).characteristicXRange(*context, Poincare::Preferences::sharedPreferences()->angleUnit()); if (!std::isnan(fRange)) { characteristicRange = maxFloat(fRange, characteristicRange); } diff --git a/apps/graph/graph/tangent_graph_controller.cpp b/apps/graph/graph/tangent_graph_controller.cpp index 4c7808c8b..bd066ea33 100644 --- a/apps/graph/graph/tangent_graph_controller.cpp +++ b/apps/graph/graph/tangent_graph_controller.cpp @@ -33,18 +33,19 @@ void TangentGraphController::viewWillAppear() { void TangentGraphController::didBecomeFirstResponder() { if (curveView()->isMainViewSelected()) { m_bannerView->abscissaValue()->setParentResponder(this); - m_bannerView->abscissaValue()->setDelegates(app(), this); + m_bannerView->abscissaValue()->setDelegates(textFieldDelegateApp(), this); app()->setFirstResponder(m_bannerView->abscissaValue()); } } bool TangentGraphController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { + Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp(); double floatBody; - if (app()->hasUndefinedValue(text, floatBody)) { + if (myApp->hasUndefinedValue(text, floatBody)) { return false; } ExpiringPointer function = app()->functionStore()->modelForRecord(m_record); - double y = function->evaluateAtAbscissa(floatBody, app()->localContext()); + double y = function->evaluateAtAbscissa(floatBody, myApp->localContext()); m_cursor->moveTo(floatBody, y); interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); reloadBannerView(); @@ -65,16 +66,18 @@ void TangentGraphController::reloadBannerView() { GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_record); constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits); char buffer[bufferSize]; + Poincare::Context * context = textFieldDelegateApp()->localContext(); + const char * legend = "a="; int legendLength = strlcpy(buffer, legend, bufferSize); ExpiringPointer function = app()->functionStore()->modelForRecord(m_record); - double y = function->approximateDerivative(m_cursor->x(), app()->localContext()); + double y = function->approximateDerivative(m_cursor->x(), context); PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView->aView()->setText(buffer); legend = "b="; legendLength = strlcpy(buffer, legend, bufferSize); - y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), app()->localContext()); + y = -y*m_cursor->x()+function->evaluateAtAbscissa(m_cursor->x(), context); PoincareHelpers::ConvertFloatToText(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits); m_bannerView->bView()->setText(buffer); m_bannerView->reload(); diff --git a/apps/graph/values/values_controller.cpp b/apps/graph/values/values_controller.cpp index 46e0e5123..6c2d00b09 100644 --- a/apps/graph/values/values_controller.cpp +++ b/apps/graph/values/values_controller.cpp @@ -147,10 +147,11 @@ double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int colum /* isDerivativeColumn uses expiring pointers, so "function" must be created * after the isDerivativeColumn call, else it will expire. */ Shared::ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); + Poincare::Context * context = textFieldDelegateApp()->localContext(); if (isDerivative) { - return function->approximateDerivative(abscissa, app()->localContext()); + return function->approximateDerivative(abscissa, context); } - return function->evaluateAtAbscissa(abscissa, app()->localContext()); + return function->evaluateAtAbscissa(abscissa, context); } void ValuesController::updateNumberOfColumns() { diff --git a/apps/probability/calculation_controller.cpp b/apps/probability/calculation_controller.cpp index 91e939d2a..e63aeeaed 100644 --- a/apps/probability/calculation_controller.cpp +++ b/apps/probability/calculation_controller.cpp @@ -211,7 +211,7 @@ bool CalculationController::textFieldShouldFinishEditing(TextField * textField, bool CalculationController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { double floatBody; - if (app()->hasUndefinedValue(text, floatBody)) { + if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) { return false; } if (m_calculation->type() != Calculation::Type::FiniteIntegral && selectedColumn() == 2) { diff --git a/apps/sequence/graph/graph_controller.cpp b/apps/sequence/graph/graph_controller.cpp index 68c0a1097..0aafbb3f8 100644 --- a/apps/sequence/graph/graph_controller.cpp +++ b/apps/sequence/graph/graph_controller.cpp @@ -61,12 +61,13 @@ float GraphController::interestingXHalfRange() const { } bool GraphController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { + Shared::TextFieldDelegateApp * myApp = textFieldDelegateApp(); double floatBody; - if (app()->hasUndefinedValue(text, floatBody)) { + if (myApp->hasUndefinedValue(text, floatBody)) { return false; } floatBody = std::fmax(0, std::round(floatBody)); - double y = yValue(selectedCurveIndex(), floatBody, app()->localContext()); + double y = yValue(selectedCurveIndex(), floatBody, myApp->localContext()); m_cursor->moveTo(floatBody, y); interactiveCurveViewRange()->panToMakePointVisible(m_cursor->x(), m_cursor->y(), cursorTopMarginRatio(), k_cursorRightMarginRatio, cursorBottomMarginRatio(), k_cursorLeftMarginRatio); reloadBannerView(); @@ -96,7 +97,7 @@ bool GraphController::moveCursorHorizontally(int direction) { return false; } Sequence * s = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(indexFunctionSelectedByCursor())); - double y = s->evaluateAtAbscissa(x, app()->localContext()); + double y = s->evaluateAtAbscissa(x, textFieldDelegateApp()->localContext()); m_cursor->moveTo(x, y); return true; } diff --git a/apps/sequence/list/list_parameter_controller.cpp b/apps/sequence/list/list_parameter_controller.cpp index d17d866f0..992ddb76e 100644 --- a/apps/sequence/list/list_parameter_controller.cpp +++ b/apps/sequence/list/list_parameter_controller.cpp @@ -72,7 +72,7 @@ bool ListParameterController::textFieldDidFinishEditing(TextField * textField, c /* -1 to take into account a double recursive sequence, which has * SecondIndex = FirstIndex + 1 */ double floatBody; - if (app()->hasUndefinedValue(text, floatBody)) { + if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) { return false; } int index = std::round(floatBody); diff --git a/apps/settings/sub_menu/display_mode_controller.cpp b/apps/settings/sub_menu/display_mode_controller.cpp index 8c22ca22a..29b94c25a 100644 --- a/apps/settings/sub_menu/display_mode_controller.cpp +++ b/apps/settings/sub_menu/display_mode_controller.cpp @@ -78,7 +78,7 @@ bool DisplayModeController::textFieldShouldFinishEditing(TextField * textField, bool DisplayModeController::textFieldDidFinishEditing(TextField * textField, const char * text, Ion::Events::Event event) { double floatBody; - if (app()->hasUndefinedValue(text, floatBody)) { + if (textFieldDelegateApp()->hasUndefinedValue(text, floatBody)) { return false; } if (floatBody < 1) { diff --git a/apps/shared/function_graph_controller.cpp b/apps/shared/function_graph_controller.cpp index 5c1b876bd..a6312dd66 100644 --- a/apps/shared/function_graph_controller.cpp +++ b/apps/shared/function_graph_controller.cpp @@ -42,8 +42,7 @@ void FunctionGraphController::viewWillAppear() { functionGraphView()->setAreaHighlight(NAN,NAN); if (functionGraphView()->context() == nullptr) { - FunctionApp * myApp = static_cast(app()); - functionGraphView()->setContext(myApp->localContext()); + functionGraphView()->setContext(textFieldDelegateApp()->localContext()); } Preferences::AngleUnit newAngleUnitVersion = Preferences::sharedPreferences()->angleUnit(); if (*m_angleUnitVersion != newAngleUnitVersion) { @@ -74,7 +73,7 @@ void FunctionGraphController::reloadBannerView() { } InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange(InteractiveCurveViewRange * interactiveCurveViewRange) { - FunctionApp * myApp = static_cast(app()); + Poincare::Context * context = textFieldDelegateApp()->localContext(); float min = FLT_MAX; float max = -FLT_MAX; float xMin = interactiveCurveViewRange->xMin(); @@ -87,13 +86,12 @@ InteractiveCurveViewRangeDelegate::Range FunctionGraphController::computeYRange( } for (int i=0; inumberOfActiveFunctions(); i++) { ExpiringPointer f = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(i)); - float y = 0.0f; float res = curveView()->resolution(); /* Scan x-range from the middle to the extrema in order to get balanced * y-range for even functions (y = 1/x). */ for (int j = -res/2; j <= res/2; j++) { float x = (xMin+xMax)/2.0+(xMax-xMin)*j/res; - y = f->evaluateAtAbscissa(x, myApp->localContext()); + float y = f->evaluateAtAbscissa(x, context); if (!std::isnan(y) && !std::isinf(y)) { min = min < y ? min : y; max = max > y ? max : y; @@ -116,12 +114,12 @@ FunctionStore * FunctionGraphController::functionStore() const { void FunctionGraphController::initCursorParameters() { double x = defaultCursorAbscissa(); - FunctionApp * myApp = static_cast(app()); + Poincare::Context * context = textFieldDelegateApp()->localContext(); int functionIndex = 0; double y = 0; do { ExpiringPointer firstFunction = functionStore()->modelForRecord(functionStore()->activeRecordAtIndex(functionIndex++)); - y = firstFunction->evaluateAtAbscissa(x, myApp->localContext()); + y = firstFunction->evaluateAtAbscissa(x, context); } while ((std::isnan(y) || std::isinf(y)) && functionIndex < functionStore()->numberOfActiveFunctions()); m_cursor->moveTo(x, y); functionIndex = (std::isnan(y) || std::isinf(y)) ? 0 : functionIndex - 1; @@ -133,8 +131,7 @@ void FunctionGraphController::initCursorParameters() { bool FunctionGraphController::moveCursorVertically(int direction) { int currentActiveFunctionIndex = indexFunctionSelectedByCursor(); - Poincare::Context * context = static_cast(app())->localContext(); - + Poincare::Context * context = textFieldDelegateApp()->localContext(); int nextActiveFunctionIndex = InteractiveCurveViewController::closestCurveIndexVertically(direction > 0, currentActiveFunctionIndex, context); if (nextActiveFunctionIndex < 0) { return false; diff --git a/apps/shared/values_controller.cpp b/apps/shared/values_controller.cpp index be80085bc..d2a1f7691 100644 --- a/apps/shared/values_controller.cpp +++ b/apps/shared/values_controller.cpp @@ -327,8 +327,7 @@ int ValuesController::maxNumberOfElements() const { double ValuesController::evaluationOfAbscissaAtColumn(double abscissa, int columnIndex) { ExpiringPointer function = functionStore()->modelForRecord(recordAtColumn(columnIndex)); - TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app(); - return function->evaluateAtAbscissa(abscissa, myApp->localContext()); + return function->evaluateAtAbscissa(abscissa, textFieldDelegateApp()->localContext()); } void ValuesController::updateNumberOfColumns() { diff --git a/apps/solver/interval_controller.cpp b/apps/solver/interval_controller.cpp index 19b1c5aed..8be37e5a8 100644 --- a/apps/solver/interval_controller.cpp +++ b/apps/solver/interval_controller.cpp @@ -103,7 +103,7 @@ bool IntervalController::textFieldDidFinishEditing(TextField * textField, const void IntervalController::buttonAction() { StackViewController * stack = stackController(); - m_equationStore->approximateSolve(app()->localContext()); + m_equationStore->approximateSolve(textFieldDelegateApp()->localContext()); stack->push(app()->solutionsControllerStack(), KDColorWhite, Palette::SubTab, Palette::SubTab); } diff --git a/apps/solver/list_controller.cpp b/apps/solver/list_controller.cpp index c0ef1956d..3125c9188 100644 --- a/apps/solver/list_controller.cpp +++ b/apps/solver/list_controller.cpp @@ -175,7 +175,7 @@ void ListController::resolveEquations() { app()->displayWarning(I18n::Message::EnterEquation); return; } - EquationStore::Error e = m_equationStore->exactSolve(app()->localContext()); + EquationStore::Error e = m_equationStore->exactSolve(textFieldDelegateApp()->localContext()); switch (e) { case EquationStore::Error::EquationUndefined: app()->displayWarning(I18n::Message::UndefinedEquation);