-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathListBox.cpp
More file actions
63 lines (54 loc) · 1.02 KB
/
Copy pathListBox.cpp
File metadata and controls
63 lines (54 loc) · 1.02 KB
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
#include "ListBox.h"
#include "ListBoxElement.h"
using namespace std;
ListBox::ListBox()
{
itemToSelect = 1;
}
void ListBox::setItemsToSelect(int items)
{
this->itemToSelect = items;
}
int ListBox::getItemsToSelect()
{
return this->itemToSelect;
}
void ListBox::add(ListBoxElement* el)
{
if(el == NULL) return;
__hook(&ListBoxElement::selectionChanged, el, &ListBox::select);
this->elements.push_back(el);
}
void ListBox::remove(ListBoxElement* el)
{
for(int i=0; i<elements.size(); i++)
{
if(elements[i] == el)
elements.erase(elements.begin() + i);
}
}
vector<ListBoxElement*> ListBox::getSelected()
{
vector<ListBoxElement*> selected;
for(int i=0; i<elements.size(); i++)
{
if(elements[i]->isSelected())
selected.push_back(elements[i]);
}
return selected;
}
void ListBox::select(ListBoxElement* e, bool value)
{
vector<ListBoxElement*>s = getSelected();
if(value)
{
if(s.size() == this->itemToSelect)
{
(*s.begin())->setSelection(false);
s.erase(s.begin());
}
}
}
ListBox::~ListBox(void)
{
}