Blame view

Giac_maj/epsilon-giac/escher/src/app.cpp 3.46 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  #include <escher/app.h>
  #include <escher/window.h>
  extern "C" {
  #include <assert.h>
  }
  
  I18n::Message App::Descriptor::name() {
    return (I18n::Message)0;
  }
  
  I18n::Message App::Descriptor::upperName() {
    return (I18n::Message)0;
  }
  
  const Image * App::Descriptor::icon() {
    return nullptr;
  }
  
  void App::Snapshot::pack(App * app) {
    tidy();
    delete app;
  }
  
  void App::Snapshot::reset() {
  }
  
  void App::Snapshot::tidy() {
  }
  
  App::App(Container * container, Snapshot * snapshot, ViewController * rootViewController, I18n::Message warningMessage) :
    Responder(nullptr),
    m_magic(Magic),
    m_modalViewController(this, rootViewController),
    m_container(container),
    m_firstResponder(nullptr),
    m_snapshot(snapshot),
    m_warningController(this, warningMessage)
  {
  }
  
  App::Snapshot * App::snapshot() {
    return m_snapshot;
  }
  
  bool App::processEvent(Ion::Events::Event event) {
    Responder * responder = m_firstResponder;
    bool didHandleEvent = false;
    while (responder) {
      didHandleEvent = responder->handleEvent(event);
      if (didHandleEvent) {
        return true;
      }
      responder = responder->parentResponder();
    }
    return false;
  }
  
  Responder * App::firstResponder() {
    return m_firstResponder;
  }
  
  void App::setFirstResponder(Responder * responder) {
    Responder * previousResponder = m_firstResponder;
    m_firstResponder = responder;
    if (previousResponder) {
      Responder * commonAncestor = previousResponder->commonAncestorWith(m_firstResponder);
      Responder * leafResponder = previousResponder;
      while (leafResponder != commonAncestor) {
        leafResponder->willExitResponderChain(m_firstResponder);
        leafResponder = leafResponder->parentResponder();
      }
      previousResponder->willResignFirstResponder();
    }
    if (m_firstResponder) {
      Responder * commonAncestor = m_firstResponder->commonAncestorWith(previousResponder);
      Responder * leafResponder = m_firstResponder;
      while (leafResponder != commonAncestor) {
        leafResponder->didEnterResponderChain(previousResponder);
        leafResponder = leafResponder->parentResponder();
      }
      m_firstResponder->didBecomeFirstResponder();
    }
  }
  
  void App::displayModalViewController(ViewController * vc, float verticalAlignment, float horizontalAlignment,
      KDCoordinate topMargin, KDCoordinate leftMargin, KDCoordinate bottomMargin, KDCoordinate rightMargin) {
    if (m_modalViewController.isDisplayingModal()) {
      m_modalViewController.dismissModalViewController();
    }
    m_modalViewController.displayModalViewController(vc, verticalAlignment, horizontalAlignment, topMargin, leftMargin, bottomMargin, rightMargin);
  }
  
  void App::dismissModalViewController() {
    m_modalViewController.dismissModalViewController();
  }
  
  void App::displayWarning(I18n::Message warningMessage) {
    m_warningController.setLabel(warningMessage);
    m_modalViewController.displayModalViewController(&m_warningController, 0.5f, 0.5f);
  }
  
  const Container * App::container() const {
    return m_container;
  }
  
  void App::didBecomeActive(Window * window) {
    View * view = m_modalViewController.view();
    assert(m_modalViewController.app() == this);
    m_modalViewController.viewWillAppear();
    window->setContentView(view);
    setFirstResponder(&m_modalViewController);
  }
  
  void App::willBecomeInactive() {
    if (m_modalViewController.isDisplayingModal()) {
      dismissModalViewController();
    }
    setFirstResponder(nullptr);
    m_modalViewController.viewDidDisappear();
  }
  
  int App::numberOfTimers() {
    return 0;
  }
  
  Timer * App::timerAtIndex(int i) {
    assert(false);
    return nullptr;
  }