Blame view

build4/epsilon-master/apps/code/console_edit_cell.cpp 1.56 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
  #include "console_edit_cell.h"
  #include "console_controller.h"
  #include <escher/app.h>
  #include <apps/i18n.h>
  #include <assert.h>
  
  namespace Code {
  
  ConsoleEditCell::ConsoleEditCell(Responder * parentResponder, TextFieldDelegate * delegate) :
    HighlightCell(),
    Responder(parentResponder),
    m_textBuffer{0},
    m_promptView(ConsoleController::k_fontSize, nullptr, 0, 0.5),
    m_textField(this, m_textBuffer, m_textBuffer, TextField::maxBufferSize(), delegate, false, ConsoleController::k_fontSize)
  {
  }
  
  int ConsoleEditCell::numberOfSubviews() const {
    return 2;
  }
  
  View * ConsoleEditCell::subviewAtIndex(int index) {
    assert(index == 0 || index ==1);
    if (index == 0) {
     return &m_promptView;
    } else {
     return &m_textField;
    }
  }
  
  void ConsoleEditCell::layoutSubviews() {
    KDSize promptSize = m_promptView.minimalSizeForOptimalDisplay();
    m_promptView.setFrame(KDRect(KDPointZero, promptSize.width(), bounds().height()));
    m_textField.setFrame(KDRect(KDPoint(promptSize.width(), KDCoordinate(0)), bounds().width() - promptSize.width(), bounds().height()));
  }
  
  void ConsoleEditCell::didBecomeFirstResponder() {
    app()->setFirstResponder(&m_textField);
  }
  
  void ConsoleEditCell::setEditing(bool isEditing,  bool reinitDraftBuffer) {
    m_textField.setEditing(isEditing, reinitDraftBuffer);
  }
  
  void ConsoleEditCell::setText(const char * text) {
    m_textField.setText(text);
  }
  
  void ConsoleEditCell::setPrompt(const char * prompt) {
    m_promptView.setText(prompt);
    layoutSubviews();
  }
  
  bool ConsoleEditCell::insertText(const char * text) {
    return m_textField.handleEventWithText(text);
  }
  
  }