Blame view

build6/epsilon-master/escher/src/alternate_empty_view_controller.cpp 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
82
83
84
85
86
87
88
  #include <escher/alternate_empty_view_controller.h>
  #include <escher/app.h>
  #include <escher/palette.h>
  #include <assert.h>
  
  /* ContentView */
  
  AlternateEmptyViewController::ContentView::ContentView(ViewController * mainViewController, AlternateEmptyViewDelegate * delegate) :
    m_message(KDText::FontSize::Small, (I18n::Message)0, 0.5f, 0.5f, KDColorBlack, Palette::WallScreen),
    m_mainViewController(mainViewController),
    m_delegate(delegate)
  {
  }
  
  int AlternateEmptyViewController::ContentView::numberOfSubviews() const {
    return 1;
  }
  
  View * AlternateEmptyViewController::ContentView::subviewAtIndex(int index) {
    assert(index == 0);
    if (m_delegate->isEmpty()) {
      m_message.setMessage(m_delegate->emptyMessage());
      return &m_message;
    }
    return m_mainViewController->view();
  }
  
  void AlternateEmptyViewController::ContentView::layoutSubviews() {
    if (alternateEmptyViewDelegate()->isEmpty()) {
      m_message.setFrame(bounds());
    } else {
      m_mainViewController->view()->setFrame(bounds());
    }
  }
  
  ViewController * AlternateEmptyViewController::ContentView::mainViewController() const {
    return m_mainViewController;
  }
  
  AlternateEmptyViewDelegate * AlternateEmptyViewController::ContentView::alternateEmptyViewDelegate() const {
    return m_delegate;
  }
  
  /* AlternateEmptyViewController */
  
  AlternateEmptyViewController::AlternateEmptyViewController(Responder * parentResponder, ViewController * mainViewController, AlternateEmptyViewDelegate * delegate) :
    ViewController(parentResponder),
    m_contentView(mainViewController, delegate)
  {
  }
  
  View * AlternateEmptyViewController::view() {
    return &m_contentView;
  }
  
  const char * AlternateEmptyViewController::title() {
    return m_contentView.mainViewController()->title();
  }
  
  bool AlternateEmptyViewController::handleEvent(Ion::Events::Event event) {
    if (m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
      if (event != Ion::Events::Home && event != Ion::Events::OnOff) {
        m_contentView.alternateEmptyViewDelegate()->defaultController()->handleEvent(Ion::Events::Back);
        return true;
      }
      return false;
    }
    return false;
  }
  
  void AlternateEmptyViewController::didBecomeFirstResponder() {
    if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
      app()->setFirstResponder(m_contentView.mainViewController());
    }
  }
  
  void AlternateEmptyViewController::viewWillAppear() {
    m_contentView.layoutSubviews();
    if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
      m_contentView.mainViewController()->viewWillAppear();
    }
  }
  
  void AlternateEmptyViewController::viewDidDisappear() {
    if (!m_contentView.alternateEmptyViewDelegate()->isEmpty()) {
      m_contentView.mainViewController()->viewDidDisappear();
    }
  }