Blame view

Giac_maj/epsilon-giac/apps/math_toolbox.h 2.66 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  #ifndef APPS_MATH_TOOLBOX_H
  #define APPS_MATH_TOOLBOX_H
  
  #define MATRICES_ARE_DEFINED 1
  #include <escher.h>
  #include "toolbox_node.h"
  
  /* m_nodeModel points at the node of the tree (describing the whole model)
   * where we are located. It enables to know which rows are leaves and which are
   * subtrees. */
  
  class MathToolbox : public Toolbox, public ListViewDataSource, public SelectableTableViewDataSource {
  public:
    MathToolbox();
    void didBecomeFirstResponder() override;
    bool handleEvent(Ion::Events::Event event) override;
  
    int numberOfRows() override;
    HighlightCell * reusableCell(int index, int type) override;
    int reusableCellCount(int type) override;
    void willDisplayCellForIndex(HighlightCell * cell, int index) override;
    KDCoordinate rowHeight(int j) override;
    KDCoordinate cumulatedHeightFromIndex(int j) override;
    int indexFromCumulatedHeight(KDCoordinate offsetY) override;
    int typeAtLocation(int i, int j) override;
  
    void viewWillAppear() override;
    void viewDidDisappear() override;
  protected:
    int stackDepth();
    TextField * sender() override;
    bool handleEventForRow(Ion::Events::Event event, int selectedRow);
    SelectableTableView m_selectableTableView;
    constexpr static int k_maxNumberOfDisplayedRows = 6; //240/40
  private:
    class Stack {
    public:
      class State {
      public:
        State(int selectedRow = -1, KDCoordinate verticalScroll = 0);
        bool isNull();
        int selectedRow();
        KDCoordinate verticalScroll();
      private:
        int m_selectedRow;
        KDCoordinate m_verticalScroll;
      };
      void push(int selectedRow, KDCoordinate verticalScroll);
      void pop();
      State * stateAtIndex(int index);
      int depth();
      void resetStack();
    private:
      constexpr static int k_maxModelTreeDepth = 2;
      State m_statesStack[k_maxModelTreeDepth];
    };
    class ListController : public ViewController {
    public:
      ListController(Responder * parentResponder, SelectableTableView * tableView);
      const char * title() override;
      View * view() override;
      void didBecomeFirstResponder() override;
      void setFirstSelectedRow(int firstSelectedRow);
    private:
      SelectableTableView * m_selectableTableView;
      int m_firstSelectedRow;
    };
    constexpr static KDCoordinate k_nodeRowHeight = 40;
    constexpr static KDCoordinate k_leafRowHeight = 40;
    const ToolboxNode * rootModel();
    bool selectLeaf(ToolboxNode * selectedNode);
    bool selectSubMenu(ToolboxNode * selectedNode);
    bool returnToPreviousMenu();
    Stack m_stack;
    MessageTableCellWithMessage m_leafCells[k_maxNumberOfDisplayedRows];
    MessageTableCellWithChevron m_nodeCells[k_maxNumberOfDisplayedRows];
    ListController m_listController;
    ToolboxNode * m_nodeModel;
  };
  
  #endif