Numworks Epsilon  1.4.1
Graphing Calculator Operating System
app.cpp
Go to the documentation of this file.
1 #include <escher/app.h>
2 #include <escher/window.h>
3 extern "C" {
4 #include <assert.h>
5 }
6 
7 I18n::Message App::Descriptor::name() {
8  return (I18n::Message)0;
9 }
10 
11 I18n::Message App::Descriptor::upperName() {
12  return (I18n::Message)0;
13 }
14 
16  return nullptr;
17 }
18 
20  tidy();
21  delete app;
22 }
23 
25 }
26 
27 void App::Snapshot::tidy() {
28 }
29 
30 App::App(Container * container, Snapshot * snapshot, ViewController * rootViewController, I18n::Message warningMessage) :
31  Responder(nullptr),
32  m_magic(Magic),
33  m_modalViewController(this, rootViewController),
34  m_container(container),
35  m_firstResponder(nullptr),
36  m_snapshot(snapshot),
37  m_warningController(this, warningMessage)
38 {
39 }
40 
42  return m_snapshot;
43 }
44 
46  Responder * responder = m_firstResponder;
47  bool didHandleEvent = false;
48  while (responder) {
49  didHandleEvent = responder->handleEvent(event);
50  if (didHandleEvent) {
51  return true;
52  }
53  responder = responder->parentResponder();
54  }
55  return false;
56 }
57 
59  return m_firstResponder;
60 }
61 
62 void App::setFirstResponder(Responder * responder) {
63  Responder * previousResponder = m_firstResponder;
64  m_firstResponder = responder;
65  if (previousResponder) {
66  Responder * commonAncestor = previousResponder->commonAncestorWith(m_firstResponder);
67  Responder * leafResponder = previousResponder;
68  while (leafResponder != commonAncestor) {
69  leafResponder->willExitResponderChain(m_firstResponder);
70  leafResponder = leafResponder->parentResponder();
71  }
72  previousResponder->willResignFirstResponder();
73  }
74  if (m_firstResponder) {
75  Responder * commonAncestor = m_firstResponder->commonAncestorWith(previousResponder);
76  Responder * leafResponder = m_firstResponder;
77  while (leafResponder != commonAncestor) {
78  leafResponder->didEnterResponderChain(previousResponder);
79  leafResponder = leafResponder->parentResponder();
80  }
81  m_firstResponder->didBecomeFirstResponder();
82  }
83 }
84 
85 void App::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
86  KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin) {
89  }
90  m_modalViewController.displayModalViewController(vc, verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin);
91 }
92 
95 }
96 
97 void App::displayWarning(I18n::Message warningMessage) {
98  m_warningController.setLabel(warningMessage);
99  m_modalViewController.displayModalViewController(&m_warningController, 0.5f, 0.5f);
100 }
101 
102 const Container * App::container() const {
103  return m_container;
104 }
105 
106 void App::didBecomeActive(Window * window) {
107  View * view = m_modalViewController.view();
108  assert(m_modalViewController.app() == this);
110  window->setContentView(view);
112 }
113 
117  }
118  setFirstResponder(nullptr);
120 }
121 
123  return m_modalViewController.view();
124 }
125 
127  return 0;
128 }
129 
131  assert(false);
132  return nullptr;
133 }
virtual void didBecomeActive(Window *window)
Definition: app.cpp:106
virtual void willResignFirstResponder()
Definition: responder.cpp:32
Definition: timer.h:15
#define assert(e)
Definition: assert.h:9
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
Definition: app.cpp:85
Definition: window.h:6
Responder * commonAncestorWith(Responder *responder)
Definition: responder.cpp:41
virtual void didBecomeFirstResponder()
Definition: responder.cpp:29
int16_t KDCoordinate
Definition: coordinate.h:6
virtual void willBecomeInactive()
Definition: app.cpp:114
Responder * parentResponder() const
Definition: responder.cpp:12
uint8_t m_magic
Definition: app.h:56
Snapshot * snapshot()
Definition: app.cpp:41
Definition: image.h:6
virtual bool handleEvent(Ion::Events::Event event)
Definition: responder.cpp:20
App(Container *container, Snapshot *snapshot, ViewController *rootViewController, I18n::Message warningMessage=(I18n::Message) 0)
Definition: app.cpp:30
virtual bool processEvent(Ion::Events::Event event)
Definition: app.cpp:45
void setLabel(I18n::Message message)
ModalViewController m_modalViewController
Definition: app.h:65
void viewDidDisappear() override
static constexpr uint8_t Magic
Definition: app.h:46
virtual int numberOfTimers()
Definition: app.cpp:126
virtual void reset()
Definition: app.cpp:24
virtual void willExitResponderChain(Responder *nextFirstResponder)
Definition: responder.cpp:38
void displayWarning(I18n::Message warningMessage)
Definition: app.cpp:97
Responder * firstResponder()
Definition: app.cpp:58
void setContentView(View *contentView)
Definition: window.cpp:20
virtual Timer * timerAtIndex(int i)
Definition: app.cpp:130
Definition: app.h:23
virtual const Image * icon()
Definition: app.cpp:15
const Container * container() const
Definition: app.cpp:102
virtual I18n::Message upperName()
Definition: app.cpp:11
void displayModalViewController(ViewController *vc, float verticalAlignment, float horizontalAlignment, KDCoordinate topMargin=0, KDCoordinate leftMargin=0, KDCoordinate bottomMargin=0, KDCoordinate rightMargin=0)
void setFirstResponder(Responder *responder)
Definition: app.cpp:62
Definition: view.h:23
virtual void didEnterResponderChain(Responder *previousFirstResponder)
Definition: responder.cpp:35
View * modalView()
Definition: app.cpp:122
App * app()
Definition: responder.cpp:77
void dismissModalViewController()
Definition: app.cpp:93
virtual I18n::Message name()
Definition: app.cpp:7
void pack(App *app)
Definition: app.cpp:19