Numworks Epsilon  1.4.1
Graphing Calculator Operating System
editable_cell_table_view_controller.cpp
Go to the documentation of this file.
2 #include "../apps_container.h"
3 #include "../constant.h"
5 #include <assert.h>
6 #include <cmath>
7 
8 using namespace Poincare;
9 
10 namespace Shared {
11 
12 EditableCellTableViewController::EditableCellTableViewController(Responder * parentResponder) :
13  TabTableController(parentResponder, this)
14 {
15 }
16 
19  || (event == Ion::Events::Down && selectedRow() < numberOfRows()-1)
20  || (event == Ion::Events::Up && selectedRow() > 0)
21  || (event == Ion::Events::Right && textField->cursorLocation() == textField->draftTextLength() && selectedColumn() < numberOfColumns()-1)
22  || (event == Ion::Events::Left && textField->cursorLocation() == 0 && selectedColumn() > 0);
23 }
24 
26  AppsContainer * appsContainer = ((TextFieldDelegateApp *)app())->container();
27  Context * globalContext = appsContainer->globalContext();
28  double floatBody = Expression::approximateToScalar<double>(text, *globalContext);
29  if (std::isnan(floatBody) || std::isinf(floatBody)) {
30  app()->displayWarning(I18n::Message::UndefinedValue);
31  return false;
32  }
33  int nbOfRows = numberOfRows();
34  int nbOfColumns = numberOfColumns();
35  if (!setDataAtLocation(floatBody, selectedColumn(), selectedRow())) {
36  app()->displayWarning(I18n::Message::ForbiddenValue);
37  return false;
38  }
39  for (int j = 0; j < numberOfColumns(); j++) {
41  }
42  if (nbOfRows != numberOfRows() || nbOfColumns != numberOfColumns()) {
44  }
45  if (event == Ion::Events::EXE || event == Ion::Events::OK) {
47  } else {
49  }
50  return true;
51 }
52 
54  int numberOfModelElements = numberOfElements();
55  if (numberOfModelElements >= maxNumberOfElements()) {
56  return 1 + numberOfModelElements;
57  }
58  return 2 + numberOfModelElements;
59 }
60 
62  return k_cellHeight;
63 }
64 
66  EvenOddCell * myCell = (EvenOddCell *)cell;
67  /* We set the cell even or odd state only if the cell is not being edited.
68  * Otherwise, the cell background is white whichever it is an odd or even cell
69  * and we do not want to redraw the cell twice (in the even/odd color and
70  * then in white) to avoid screen blinking. */
71  // The cell is editable
72  if (cellAtLocationIsEditable(i, j)) {
73  EvenOddEditableTextCell * myEditableValueCell = (EvenOddEditableTextCell *)cell;
74  char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
75  // Special case 1: last row
76  if (j == numberOfRows() - 1) {
77  /* Display an empty line only if there is enough space for a new element in
78  * data */
79  if (numberOfElements() < maxNumberOfElements() && !myEditableValueCell->editableTextCell()->textField()->isEditing()) {
80  myCell->setEven(j%2 == 0);
81  buffer[0] = 0;
82  myEditableValueCell->editableTextCell()->textField()->setText(buffer);
83  return;
84  }
85  }
86  if (!myEditableValueCell->editableTextCell()->textField()->isEditing()) {
87  myCell->setEven(j%2 == 0);
88  PrintFloat::convertFloatToText<double>(dataAtLocation(i, j), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, floatDisplayMode);
89  myEditableValueCell->editableTextCell()->textField()->setText(buffer);
90  }
91  return;
92  } else {
93  myCell->setEven(j%2 == 0);
94  }
95 }
96 
98  if (selectedRow() >= 0) {
99  int selRow = selectedRow();
100  selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
101  int selColumn = selectedColumn();
102  selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
103  selectCellAtLocation(selColumn, selRow);
105  }
106 }
107 
110  if (selectedRow() == -1) {
111  selectCellAtLocation(0, 1);
112  } else {
113  int selRow = selectedRow();
114  selRow = selRow >= numberOfRows() ? numberOfRows()-1 : selRow;
115  int selColumn = selectedColumn();
116  selColumn = selColumn >= numberOfColumns() ? numberOfColumns() - 1 : selColumn;
117  selectCellAtLocation(selColumn, selRow);
118  }
119 }
120 
121 TextFieldDelegateApp * EditableCellTableViewController::textFieldDelegateApp() {
122  return (TextFieldDelegateApp *)app();
123 }
124 
125 }
bool isEditing() const
Definition: text_field.cpp:175
void willDisplayCellAtLocationWithDisplayMode(HighlightCell *cell, int i, int j, Poincare::PrintFloat::Mode mode)
virtual int numberOfColumns()=0
bool textFieldDidFinishEditing(TextField *textField, const char *text, Ion::Events::Event event) override
#define isinf(x)
Definition: math.h:44
void setText(const char *text)
Definition: text_field.cpp:184
virtual void setEven(bool even)
size_t cursorLocation() const
Definition: text_input.h:19
constexpr Event EXE
Definition: events.h:114
int16_t KDCoordinate
Definition: coordinate.h:6
constexpr Event Up
Definition: events.h:62
constexpr Event Down
Definition: events.h:63
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
TextField * textField()
void reloadData(bool setFirstResponder=true)
void displayWarning(I18n::Message warningMessage)
Definition: app.cpp:97
void reloadCellAtLocation(int i, int j)
Definition: table_view.cpp:49
Poincare::Context * globalContext()
static constexpr int LargeNumberOfSignificantDigits
Definition: constant.h:6
#define isnan(x)
Definition: math.h:43
constexpr Event Left
Definition: events.h:61
size_t draftTextLength() const
Definition: text_field.cpp:179
constexpr Event Right
Definition: events.h:64
virtual bool handleEvent(Ion::Events::Event event) override
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
bool textFieldShouldFinishEditing(TextField *textField, Ion::Events::Event event) override
SelectableTableView * selectableTableView()