Numworks Epsilon  1.4.1
Graphing Calculator Operating System
list_controller.cpp
Go to the documentation of this file.
1 #include "list_controller.h"
2 #include <assert.h>
3 
4 namespace Shared {
5 
6 ListController::ListController(Responder * parentResponder, FunctionStore * functionStore, ButtonRowController * header, ButtonRowController * footer, I18n::Message text) :
7  DynamicViewController(parentResponder),
8  ButtonRowDelegate(header, footer),
9  m_functionStore(functionStore),
10  m_emptyCell(nullptr),
11  m_addNewMessage(text),
12  m_addNewFunction(nullptr),
13  m_plotButton(this, I18n::Message::Plot, Invocation([](void * context, void * sender) {
14  ListController * list = (ListController *)context;
15  TabViewController * tabController = list->tabController();
16  tabController->setActiveTab(1);
18  m_valuesButton(this, I18n::Message::DisplayValues, Invocation([](void * context, void * sender) {
19  ListController * list = (ListController *)context;
20  TabViewController * tabController = list->tabController();
21  tabController->setActiveTab(2);
23 {
24 }
25 
27  return 2;
28 };
29 
31  switch (i) {
32  case 0:
33  return k_functionNameWidth;
34  case 1:
35  return selectableTableView()->bounds().width()-k_functionNameWidth;
36  default:
37  assert(false);
38  return 0;
39  }
40 }
41 
43  switch (i) {
44  case 0:
45  return 0;
46  case 1:
47  return k_functionNameWidth;
48  case 2:
49  return selectableTableView()->bounds().width();
50  default:
51  assert(false);
52  return 0;
53  }
54 }
55 
57  int result = 0;
58  for (int k = 0; k < j; k++) {
59  result += rowHeight(k);
60  }
61  return result;
62 }
63 
65  if (offsetX <= k_functionNameWidth) {
66  return 0;
67  } else {
68  if (offsetX <= selectableTableView()->bounds().width())
69  return 1;
70  else {
71  return 2;
72  }
73  }
74 }
75 
77  int result = 0;
78  int j = 0;
79  while (result < offsetY && j < numberOfRows()) {
80  result += rowHeight(j++);
81  }
82  return (result < offsetY || offsetY == 0) ? j : j - 1;
83 }
84 
85 int ListController::typeAtLocation(int i, int j) {
87  && j == numberOfRows() - 1) {
88  return i + 2;
89  }
90  return i;
91 }
92 
94  assert(index >= 0);
95  assert(index < maxNumberOfRows());
96  switch (type) {
97  case 0:
98  return titleCells(index);
99  case 1:
100  return expressionCells(index);
101  case 2:
102  return m_emptyCell;
103  case 3:
104  return m_addNewFunction;
105  default:
106  assert(false);
107  return nullptr;
108  }
109 }
110 
112  if (type > 1) {
113  return 1;
114  }
115  return maxNumberOfRows();
116 }
117 
120  if (i == 0) {
121  willDisplayTitleCellAtIndex(cell, j);
122  } else {
123  willDisplayExpressionCellAtIndex(cell, j);
124  }
125  }
126  EvenOddCell * myCell = (EvenOddCell *)cell;
127  myCell->setEven(j%2 == 0);
128  myCell->setHighlighted(i == selectedColumn() && j == selectedRow());
129  myCell->reloadCell();
130 }
131 
133  if (position == ButtonRowController::Position::Bottom) {
134  return 2;
135  }
136  return 0;
137 }
138 
140  if (position == ButtonRowController::Position::Top) {
141  return nullptr;
142  }
143  const Button * buttons[2] = {&m_plotButton, &m_valuesButton};
144  return (Button *)buttons[index];
145 }
146 
148  if (selectedRow() == -1) {
149  selectCellAtLocation(1, 0);
150  } else {
152  }
153  if (selectedRow() >= numberOfRows()) {
155  }
156  footer()->setSelectedButton(-1);
158 }
159 
161  if (event == Ion::Events::Up) {
162  if (selectedRow() == -1) {
163  footer()->setSelectedButton(-1);
166  return true;
167  }
169  assert(selectedRow() == -1);
170  app()->setFirstResponder(tabController());
171  return true;
172  }
173  if (event == Ion::Events::Down) {
174  if (selectedRow() == -1) {
175  return false;
176  }
179  return true;
180  }
181  if (event == Ion::Events::OK || event == Ion::Events::EXE) {
182  switch (selectedColumn()) {
183  case 0:
184  {
186  selectedRow() == numberOfRows() - 1) {
187  return true;
188  }
190  return true;
191  }
192  case 1:
193  {
195  selectedRow() == numberOfRows() - 1) {
196  addEmptyFunction();
197  return true;
198  }
199  Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(selectedRow()));
200  editExpression(function, event);
201  return true;
202  }
203  default:
204  {
205  return false;
206  }
207  }
208  }
209  if (event == Ion::Events::Backspace && selectedRow() >= 0 &&
211  Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(selectedRow()));
212  if (selectedColumn() == 1 && !function->isEmpty()) {
213  reinitExpression(function);
214  } else {
215  if (removeFunctionRow(function)) {
217  if (selectedRow() >= numberOfRows()) {
219  }
221  }
222  }
223  return true;
224  }
225  if ((event.hasText() || event == Ion::Events::XNT || event == Ion::Events::Paste || event == Ion::Events::Toolbox || event == Ion::Events::Var)
226  && selectedColumn() == 1
227  && (selectedRow() != numberOfRows() - 1
229  Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(selectedRow()));
230  editExpression(function, event);
231  return true;
232  }
233  if (event == Ion::Events::Copy && selectedColumn() == 1 &&
235  Clipboard::sharedClipboard()->store(textForRow(selectedRow()));
236  return true;
237  }
238  return false;
239 }
240 
241 void ListController::didEnterResponderChain(Responder * previousFirstResponder) {
243 }
244 
246  if (nextFirstResponder == tabController()) {
248  footer()->setSelectedButton(-1);
249  }
250 }
251 
252 void ListController::tableViewDidChangeSelection(SelectableTableView * t, int previousSelectedCellX, int previousSelectedCellY) {
255  }
256 }
257 
260 }
261 
264  parameterController()->setFunction(function);
265  stack->push(parameterController());
266 }
267 
269  function->setContent("");
271 }
272 
274  return (SelectableTableView *)view();
275 }
276 
277 TabViewController * ListController::tabController() const{
279 }
280 
281 int ListController::functionIndexForRow(int j) {
282  return j;
283 }
284 
285 const char * ListController::textForRow(int j) {
286  Shared::Function * function = m_functionStore->functionAtIndex(functionIndexForRow(j));
287  return function->text();
288 }
289 
290 void ListController::addEmptyFunction() {
293 }
294 
296  m_emptyCell = new EvenOddCell();
297  m_addNewFunction = new NewFunctionCell(m_addNewMessage);
298  SelectableTableView * selectableTableView = new SelectableTableView(this, this, this, this);
302  return selectableTableView;
303 }
304 
306  delete m_emptyCell;
307  m_emptyCell = nullptr;
308  delete m_addNewFunction;
309  m_addNewFunction = nullptr;
310  delete view;
311 }
312 
313 }
int numberOfButtons(ButtonRowController::Position position) const override
constexpr Event Var
Definition: events.h:74
Definition: i18n.h:6
void didBecomeFirstResponder() override
void setShowsIndicators(bool s)
Definition: scroll_view.h:28
StackViewController * stackController() const
#define assert(e)
Definition: assert.h:9
void setActiveTab(int8_t index)
virtual void setEven(bool even)
const char * text() const
Definition: function.cpp:64
constexpr Event EXE
Definition: events.h:114
static constexpr KDColor PurpleBright
Definition: palette.h:10
int16_t KDCoordinate
Definition: coordinate.h:6
void push(ViewController *vc, KDColor textColor=Palette::SubTab, KDColor backgroundColor=KDColorWhite, KDColor separatorColor=Palette::GreyBright)
Responder * parentResponder() const
Definition: responder.cpp:12
void tableViewDidChangeSelection(SelectableTableView *t, int previousSelectedCellX, int previousSelectedCellY) override
void setVerticalCellOverlap(KDCoordinate o)
Definition: table_view.h:14
void configureFunction(Function *function)
constexpr Event Up
Definition: events.h:62
constexpr Event Down
Definition: events.h:63
bool selectCellAtLocation(int i, int j, bool setFirstResponder=true)
KDCoordinate columnWidth(int i) override
int indexFromCumulatedHeight(KDCoordinate offsetY) override
int reusableCellCount(int type) override
FunctionStore * m_functionStore
virtual Function * functionAtIndex(int i)=0
constexpr Event Paste
Definition: events.h:124
void store(const char *storedText)
Definition: clipboard.cpp:9
void reloadData(bool setFirstResponder=true)
virtual int maxNumberOfFunctions()=0
bool hasText() const
Definition: events.cpp:122
View * loadView() override
ButtonRowController * footer()
int numberOfColumns() override
void willExitResponderChain(Responder *nextFirstResponder) override
KDCoordinate cumulatedHeightFromIndex(int j) override
HighlightCell * reusableCell(int index, int type) override
Button * buttonAtIndex(int index, ButtonRowController::Position position) const override
void willDisplayCellAtLocation(HighlightCell *cell, int i, int j) override
list
Definition: grammar.h:158
constexpr Event XNT
Definition: events.h:73
int indexFromCumulatedWidth(KDCoordinate offsetX) override
ListController(Responder *parentResponder, FunctionStore *functionStore, ButtonRowController *header, ButtonRowController *footer, I18n::Message text)
void unloadView(View *view) override
bool setSelectedButton(int selectedButton)
void setMargins(KDCoordinate top, KDCoordinate right, KDCoordinate bottom, KDCoordinate left)
Definition: scroll_view.h:22
constexpr Event Copy
Definition: events.h:123
virtual int numberOfRows()=0
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
SelectableTableView * selectableTableView()
int typeAtLocation(int i, int j) override
KDCoordinate width() const
Definition: rect.h:39
static Clipboard * sharedClipboard()
Definition: clipboard.cpp:5
virtual void reinitExpression(Function *function)
constexpr Event Toolbox
Definition: events.h:75
App * app()
Definition: responder.cpp:77
constexpr Event OK
Definition: events.h:65
virtual void setHighlighted(bool highlight)
Definition: button.h:10
virtual void reloadCell()
bool handleEvent(Ion::Events::Event event) override
virtual KDCoordinate rowHeight(int j)=0
void didEnterResponderChain(Responder *previousFirstResponder) override
KDRect bounds() const
Definition: view.cpp:157
KDCoordinate cumulatedWidthFromIndex(int i) override
virtual Function * addEmptyFunction()=0
virtual void setFunction(Function *function)
constexpr Event Backspace
Definition: events.h:76