Blame view

build1/epsilon-master/escher/src/editable_text_cell.cpp 2 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
  #include <escher/editable_text_cell.h>
  #include <escher/app.h>
  #include <escher/palette.h>
  #include <assert.h>
  
  EditableTextCell::EditableTextCell(Responder * parentResponder, TextFieldDelegate * delegate, char * draftTextBuffer,
     KDText::FontSize size, float horizontalAlignment, float verticalAlignment, KDColor textColor, KDColor backgroundColor, KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) :
    HighlightCell(),
    Responder(parentResponder),
    m_textField(this, m_textBody, draftTextBuffer, TextField::maxBufferSize(), delegate, true, size, horizontalAlignment, verticalAlignment, textColor, backgroundColor),
    m_topMargin(topMargin),
    m_rightMargin(rightMargin),
    m_bottomMargin(bottomMargin),
    m_leftMargin(leftMargin)
  {
    m_textBody[0] = 0;
  }
  
  void EditableTextCell::setMargins(KDCoordinate topMargin, KDCoordinate rightMargin, KDCoordinate bottomMargin, KDCoordinate leftMargin) {
    m_topMargin = topMargin;
    m_rightMargin = rightMargin;
    m_bottomMargin = bottomMargin;
    m_leftMargin = leftMargin;
  }
  
  TextField * EditableTextCell::textField() {
    return &m_textField;
  }
  
  void EditableTextCell::setHighlighted(bool highlight) {
    HighlightCell::setHighlighted(highlight);
    KDColor backgroundColor = highlight? Palette::Select : KDColorWhite;
    m_textField.setBackgroundColor(backgroundColor);
  }
  
  int EditableTextCell::numberOfSubviews() const {
    return 1;
  }
  
  View * EditableTextCell::subviewAtIndex(int index) {
    assert(index == 0);
    return &m_textField;
  }
  
  void EditableTextCell::layoutSubviews() {
    KDRect cellBounds = bounds();
    m_textField.setFrame(KDRect(cellBounds.x() + m_leftMargin,
          cellBounds.y() + m_topMargin,
          cellBounds.width() - m_leftMargin - m_rightMargin,
          cellBounds.height() - m_topMargin - m_bottomMargin));
  }
  
  void EditableTextCell::didBecomeFirstResponder() {
    app()->setFirstResponder(&m_textField);
  }
  
  KDSize EditableTextCell::minimalSizeForOptimalDisplay() const {
    return m_textField.minimalSizeForOptimalDisplay();
  }