[apps] AppsContainer does not own the apps but a pointer to the apps

Change-Id: I9b6787be2cd143b52fd8dd60f3528fed2f74e4bb
This commit is contained in:
Émilie Feral
2017-05-03 14:21:36 +02:00
parent 5a78411dc6
commit 62c93e49a6
24 changed files with 99 additions and 42 deletions

View File

@@ -6,34 +6,33 @@ extern "C" {
#include <assert.h>
}
using namespace Poincare;
using namespace Shared;
AppsContainer::AppsContainer() :
Container(),
m_window(AppsWindow()),
m_emptyBatteryWindow(EmptyBatteryWindow()),
m_homeApp(this),
m_graphApp(this, &m_globalContext),
m_probabilityApp(this),
m_calculationApp(this, &m_globalContext),
m_hardwareTestApp(this),
m_regressionApp(this),
m_sequenceApp(this, &m_globalContext),
m_settingsApp(this),
m_statisticsApp(this),
m_globalContext(GlobalContext()),
m_globalContext(Poincare::GlobalContext()),
m_variableBoxController(&m_globalContext),
m_examPopUpController(ExamPopUpController()),
m_ledTimer(LedTimer()),
m_batteryTimer(BatteryTimer(this)),
m_USBTimer(USBTimer(this)),
m_suspendTimer(SuspendTimer(this)),
m_backlightDimmingTimer(BacklightDimmingTimer())
m_backlightDimmingTimer(BacklightDimmingTimer()),
m_homeApp(new Home::App(this)),
m_graphApp(new Graph::App(this, &m_globalContext)),
m_probabilityApp(new Probability::App(this)),
m_calculationApp(new Calculation::App(this, &m_globalContext)),
m_hardwareTestApp(new HardwareTest::App(this)),
m_regressionApp(new Regression::App(this)),
m_sequenceApp(new Sequence::App(this, &m_globalContext)),
m_settingsApp(new Settings::App(this)),
m_statisticsApp(new Statistics::App(this))
{
refreshPreferences();
m_emptyBatteryWindow.setFrame(KDRect(0, 0, Ion::Display::Width, Ion::Display::Height));
Expression::setCircuitBreaker(AppsContainer::poincareCircuitBreaker);
Poincare::Expression::setCircuitBreaker(AppsContainer::poincareCircuitBreaker);
}
bool AppsContainer::poincareCircuitBreaker(const Poincare::Expression * e) {
@@ -46,15 +45,15 @@ int AppsContainer::numberOfApps() {
}
App * AppsContainer::appAtIndex(int index) {
static App * apps[] = {
&m_homeApp,
&m_calculationApp,
&m_graphApp,
&m_sequenceApp,
&m_settingsApp,
&m_statisticsApp,
&m_probabilityApp,
&m_regressionApp,
App * apps[] = {
m_homeApp,
m_calculationApp,
m_graphApp,
m_sequenceApp,
m_settingsApp,
m_statisticsApp,
m_probabilityApp,
m_regressionApp,
};
assert(sizeof(apps)/sizeof(apps[0]) == k_numberOfApps);
assert(index >= 0 && index < k_numberOfApps);
@@ -62,14 +61,38 @@ App * AppsContainer::appAtIndex(int index) {
}
App * AppsContainer::hardwareTestApp() {
return &m_hardwareTestApp;
return m_hardwareTestApp;
}
void AppsContainer::reset() {
Clipboard::sharedClipboard()->reset();
if (m_calculationApp != nullptr) {
delete m_calculationApp;
}
m_calculationApp = new Calculation::App(this, &m_globalContext);
if (m_graphApp != nullptr) {
delete m_graphApp;
}
m_graphApp = new Graph::App(this, &m_globalContext);
if (m_sequenceApp != nullptr) {
delete m_sequenceApp;
}
m_sequenceApp = new Sequence::App(this, &m_globalContext);
if (m_statisticsApp != nullptr) {
delete m_statisticsApp;
}
m_statisticsApp = new Statistics::App(this);
if (m_probabilityApp != nullptr) {
delete m_probabilityApp;
}
m_probabilityApp = new Probability::App(this);
if (m_regressionApp != nullptr) {
delete m_regressionApp;
}
m_regressionApp = new Regression::App(this);
}
Context * AppsContainer::globalContext() {
Poincare::Context * AppsContainer::globalContext() {
return &m_globalContext;
}
@@ -99,11 +122,11 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
bool alphaLockWantsRedraw = m_window.updateAlphaLock();
// Home and Power buttons are not sent to apps. We handle them straight away.
if (event == Ion::Events::Home && activeApp() != &m_hardwareTestApp) {
if (event == Ion::Events::Home && activeApp() != m_hardwareTestApp) {
switchTo(appAtIndex(0));
return true;
}
if (event == Ion::Events::OnOff && activeApp() != &m_hardwareTestApp) {
if (event == Ion::Events::OnOff && activeApp() != m_hardwareTestApp) {
suspend();
return true;
}

View File

@@ -51,15 +51,6 @@ private:
static constexpr int k_numberOfApps = 8;
AppsWindow m_window;
EmptyBatteryWindow m_emptyBatteryWindow;
Home::App m_homeApp;
Graph::App m_graphApp;
Probability::App m_probabilityApp;
Calculation::App m_calculationApp;
HardwareTest::App m_hardwareTestApp;
Regression::App m_regressionApp;
Sequence::App m_sequenceApp;
Settings::App m_settingsApp;
Statistics::App m_statisticsApp;
#if USE_PIC_VIEW_APP
PicViewApp m_picViewApp;
#endif
@@ -72,6 +63,15 @@ private:
USBTimer m_USBTimer;
SuspendTimer m_suspendTimer;
BacklightDimmingTimer m_backlightDimmingTimer;
Home::App * m_homeApp;
Graph::App * m_graphApp;
Probability::App * m_probabilityApp;
Calculation::App * m_calculationApp;
HardwareTest::App * m_hardwareTestApp;
Regression::App * m_regressionApp;
Sequence::App * m_sequenceApp;
Settings::App * m_settingsApp;
Statistics::App * m_statisticsApp;
};
#endif

View File

@@ -7,6 +7,7 @@ namespace Calculation {
HistoryController::HistoryController(Responder * parentResponder, CalculationStore * calculationStore) :
DynamicViewController(parentResponder),
m_calculationHistory{},
m_calculationStore(calculationStore)
{
}

View File

@@ -9,6 +9,8 @@ namespace Graph {
ListController::ListController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header, ButtonRowController * footer) :
Shared::ListController(parentResponder, functionStore, header, footer, I18n::Message::AddFunction),
m_functionTitleCells{},
m_expressionCells{},
m_parameterController(ListParameterController(this, functionStore, I18n::Message::FunctionColor, I18n::Message::DeleteFunction))
{
}

View File

@@ -9,6 +9,8 @@ namespace Graph {
ValuesController::ValuesController(Responder * parentResponder, CartesianFunctionStore * functionStore, ButtonRowController * header) :
Shared::ValuesController(parentResponder, header, I18n::Message::XColumn, &m_intervalParameterController),
m_functionTitleCells{},
m_floatCells{},
m_functionStore(functionStore),
m_functionParameterController(FunctionParameterController(this)),
m_intervalParameterController(IntervalParameterController(this, &m_interval)),

View File

@@ -12,7 +12,6 @@ App::App(AppsContainer * container) :
::App(container, &m_controller, I18n::Message::Apps, I18n::Message::AppsCapital, nullptr, I18n::Message::Warning),
m_controller(Controller(&m_modalViewController, container))
{
assert(container->appAtIndex(0) == this);
}
}

View File

@@ -69,6 +69,8 @@ void ParametersController::ContentView::layoutSubviews() {
ParametersController::ParametersController(Responder * parentResponder) :
FloatParameterController(parentResponder),
m_selectableTableView(nullptr),
m_menuListCell{},
m_law(nullptr),
m_calculationController(CalculationController(nullptr))
{

View File

@@ -14,6 +14,11 @@ namespace Regression {
CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) :
TabTableController(parentResponder, this, Metric::CommonTopMargin, Metric::CommonRightMargin, Metric::CommonBottomMargin, Metric::CommonLeftMargin, true),
ButtonRowDelegate(header, nullptr),
m_titleCells{},
m_r2TitleCell(nullptr),
m_columnTitleCell(nullptr),
m_doubleCalculationCells{},
m_calculationCells{},
m_store(store)
{
m_r2Layout = new BaselineRelativeLayout(new StringLayout("r", 1, KDText::FontSize::Small), new StringLayout("2", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Superscript);

View File

@@ -12,7 +12,8 @@ using namespace Shared;
namespace Regression {
StoreController::StoreController(Responder * parentResponder, Store * store, ButtonRowController * header) :
Shared::StoreController(parentResponder, store, header)
Shared::StoreController(parentResponder, store, header),
m_titleCells{}
{
m_titleLayout[0] = new BaselineRelativeLayout(new StringLayout("X", 1, KDText::FontSize::Small), new StringLayout("i", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);
m_titleLayout[1] = new BaselineRelativeLayout(new StringLayout("Y", 1, KDText::FontSize::Small), new StringLayout("i", 1, KDText::FontSize::Small), BaselineRelativeLayout::Type::Subscript);

View File

@@ -10,6 +10,8 @@ namespace Sequence {
ListController::ListController(Responder * parentResponder, SequenceStore * sequenceStore, ButtonRowController * header, ButtonRowController * footer) :
Shared::ListController(parentResponder, sequenceStore, header, footer, I18n::Message::AddSequence),
m_sequenceStore(sequenceStore),
m_sequenceTitleCells{},
m_expressionCells{},
m_parameterController(ListParameterController(this, sequenceStore)),
m_typeParameterController(this, sequenceStore, this, TableCell::Layout::Vertical),
m_typeStackController(StackViewController(nullptr, &m_typeParameterController, true, KDColorWhite, Palette::PurpleDark, Palette::PurpleDark)),

View File

@@ -7,6 +7,8 @@ namespace Sequence {
ValuesController::ValuesController(Responder * parentResponder, SequenceStore * sequenceStore, ButtonRowController * header) :
Shared::ValuesController(parentResponder, header, I18n::Message::NColumn, &m_intervalParameterController),
m_sequenceTitleCells{},
m_floatCells{},
m_sequenceStore(sequenceStore),
#if COPY_COLUMN
m_sequenceParameterController(Shared::ValuesFunctionParameterController('n')),

View File

@@ -6,7 +6,7 @@ namespace Settings {
App::App(Container * container) :
::App(container, &m_stackViewController, I18n::Message::SettingsApp, I18n::Message::SettingsAppCapital, ImageStore::SettingsIcon, I18n::Message::Warning),
m_mainController(MainController(nullptr)),
m_mainController(MainController(&m_stackViewController)),
m_stackViewController(StackViewController(&m_modalViewController, &m_mainController))
{
}

View File

@@ -9,7 +9,8 @@ using namespace Poincare;
namespace Shared {
FloatParameterController::FloatParameterController(Responder * parentResponder) :
DynamicViewController(parentResponder)
DynamicViewController(parentResponder),
m_okButton(nullptr)
{
}

View File

@@ -7,6 +7,7 @@ namespace Shared {
GoToParameterController::GoToParameterController(Responder * parentResponder, InteractiveCurveViewRange * graphRange, CurveViewCursor * cursor, I18n::Message symbol) :
FloatParameterController(parentResponder),
m_cursor(cursor),
m_abscisseCell(nullptr),
m_graphRange(graphRange),
m_abscissaSymbol(symbol)
{

View File

@@ -5,7 +5,8 @@ namespace Shared {
IntervalParameterController::IntervalParameterController(Responder * parentResponder, Interval * interval) :
FloatParameterController(parentResponder),
m_interval(interval)
m_interval(interval),
m_intervalCells{}
{
}

View File

@@ -7,7 +7,9 @@ ListController::ListController(Responder * parentResponder, FunctionStore * func
DynamicViewController(parentResponder),
ButtonRowDelegate(header, footer),
m_functionStore(functionStore),
m_emptyCell(nullptr),
m_addNewMessage(text),
m_addNewFunction(nullptr),
m_plotButton(this, I18n::Message::Plot, Invocation([](void * context, void * sender) {
ListController * list = (ListController *)context;
TabViewController * tabController = list->tabController();

View File

@@ -9,7 +9,9 @@ namespace Shared {
RangeParameterController::RangeParameterController(Responder * parentResponder, InteractiveCurveViewRange * interactiveRange) :
FloatParameterController(parentResponder),
m_interactiveRange(interactiveRange)
m_interactiveRange(interactiveRange),
m_rangeCells{},
m_yAutoCell(nullptr)
{
}

View File

@@ -10,6 +10,7 @@ namespace Shared {
StoreController::StoreController(Responder * parentResponder, FloatPairStore * store, ButtonRowController * header) :
EditableCellTableViewController(parentResponder, Metric::CommonTopMargin, Metric::CommonRightMargin, Metric::CommonBottomMargin, Metric::CommonLeftMargin),
ButtonRowDelegate(header, nullptr),
m_editableCells{},
m_store(store),
m_storeParameterController(this, store)
{

View File

@@ -11,6 +11,8 @@ namespace Shared {
ValuesController::ValuesController(Responder * parentResponder, ButtonRowController * header, I18n::Message parameterTitle, IntervalParameterController * intervalParameterController) :
EditableCellTableViewController(parentResponder, k_topMargin, k_rightMargin, k_bottomMargin, k_leftMargin),
ButtonRowDelegate(header, nullptr),
m_abscissaTitleCell(nullptr),
m_abscissaCells{},
m_abscissaParameterController(ValuesParameterController(this, intervalParameterController, parameterTitle)),
m_setIntervalButton(Button(this, I18n::Message::IntervalSet, Invocation([](void * context, void * sender) {
ValuesController * valuesController = (ValuesController *) context;

View File

@@ -13,6 +13,8 @@ namespace Statistics {
CalculationController::CalculationController(Responder * parentResponder, ButtonRowController * header, Store * store) :
TabTableController(parentResponder, this, Metric::CommonTopMargin, Metric::CommonRightMargin, Metric::CommonBottomMargin, Metric::CommonLeftMargin, true),
ButtonRowDelegate(header, nullptr),
m_titleCells{},
m_calculationCells{},
m_store(store)
{
}

View File

@@ -8,6 +8,7 @@ namespace Statistics {
HistogramParameterController::HistogramParameterController(Responder * parentResponder, Store * store) :
FloatParameterController(parentResponder),
m_cells{},
m_store(store)
{
}

View File

@@ -9,7 +9,8 @@ using namespace Shared;
namespace Statistics {
StoreController::StoreController(Responder * parentResponder, Store * store, ButtonRowController * header) :
Shared::StoreController(parentResponder, store, header)
Shared::StoreController(parentResponder, store, header),
m_titleCells{}
{
}

View File

@@ -23,6 +23,7 @@ class App : public Responder {
public:
constexpr static uint8_t Magic = 0xA8;
App(Container * container, ViewController * rootViewController, I18n::Message name = (I18n::Message)0, I18n::Message upperName = (I18n::Message)0, const Image * icon = nullptr, I18n::Message warningMessage = (I18n::Message)0);
virtual ~App();
void setFirstResponder(Responder * responder);
Responder * firstResponder();
bool processEvent(Ion::Events::Event event);

View File

@@ -17,6 +17,9 @@ App::App(Container * container, ViewController * rootViewController, I18n::Messa
{
}
App::~App() {
}
bool App::processEvent(Ion::Events::Event event) {
Responder * responder = m_firstResponder;
bool didHandleEvent = false;