File: combo-edit.cpp

package info (click to toggle)
higan 106-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 9,640 kB
  • sloc: cpp: 108,736; ansic: 809; makefile: 22; sh: 7
file content (107 lines) | stat: -rw-r--r-- 2,463 bytes parent folder | download
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
#if defined(Hiro_ComboEdit)

auto mComboEdit::allocate() -> pObject* {
  return new pComboEdit(*this);
}

auto mComboEdit::destruct() -> void {
  mWidget::destruct();
}

//

auto mComboEdit::append(sComboEditItem item) -> type& {
  state.items.append(item);
  item->setParent(this, itemCount() - 1);
  signal(append, item);
  return *this;
}

auto mComboEdit::backgroundColor() const -> Color {
  return state.backgroundColor;
}

auto mComboEdit::doActivate() const -> void {
  if(state.onActivate) return state.onActivate();
}

auto mComboEdit::doChange() const -> void {
  if(state.onChange) return state.onChange();
}

auto mComboEdit::foregroundColor() const -> Color {
  return state.foregroundColor;
}

auto mComboEdit::item(uint position) const -> ComboEditItem {
  if(position < itemCount()) return state.items[position];
  return {};
}

auto mComboEdit::itemCount() const -> uint {
  return state.items.size();
}

auto mComboEdit::items() const -> vector<ComboEditItem> {
  vector<ComboEditItem> items;
  for(auto& item : state.items) items.append(item);
  return items;
}

auto mComboEdit::onActivate(const function<void ()>& callback) -> type& {
  state.onActivate = callback;
  return *this;
}

auto mComboEdit::onChange(const function<void ()>& callback) -> type& {
  state.onChange = callback;
  return *this;
}

auto mComboEdit::remove(sComboEditItem item) -> type& {
  signal(remove, item);
  state.items.remove(item->offset());
  for(auto n : range(item->offset(), itemCount())) {
    state.items[n]->adjustOffset(-1);
  }
  item->setParent();
  return *this;
}

auto mComboEdit::reset() -> type& {
  signal(reset);
  for(auto& item : state.items) item->setParent();
  state.items.reset();
  return *this;
}

auto mComboEdit::setBackgroundColor(Color color) -> type& {
  state.backgroundColor = color;
  signal(setBackgroundColor, color);
  return *this;
}

auto mComboEdit::setForegroundColor(Color color) -> type& {
  state.foregroundColor = color;
  signal(setForegroundColor, color);
  return *this;
}

auto mComboEdit::setParent(mObject* parent, int offset) -> type& {
  for(auto& item : state.items) item->destruct();
  mObject::setParent(parent, offset);
  for(auto& item : state.items) item->setParent(this, item->offset());
  return *this;
}

auto mComboEdit::setText(const string& text) -> type& {
  state.text = text;
  signal(setText, text);
  return *this;
}

auto mComboEdit::text() const -> string {
  return state.text;
}

#endif