-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathCustomComboBoxes.cpp
More file actions
75 lines (65 loc) · 1.66 KB
/
CustomComboBoxes.cpp
File metadata and controls
75 lines (65 loc) · 1.66 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
64
65
66
67
68
69
70
71
72
73
74
75
#include "Common.h"
#include "CustomComboBoxes.h"
AGEComboBox::AGEComboBox(wxWindow *parent, wxArrayString *choices, int width, bool pass) :
wxComboCtrl(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, -1), wxCB_READONLY)
{
popup = new SharedComboPopup();
SetPopupControl(popup);
popup->SetFont(parent->GetFont());
popup->Imbue(choices);
if (pass)
{
// Stop accidental selection changes
Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent &event) {GetParent()->GetEventHandler()->ProcessEvent(event); });
}
}
void AGEComboBox::SetSelection(int n)
{
wxString str;
if (GetCount())
{
popup->SetSelection(n);
if (n >= 0)
{
str = popup->GetString(n);
}
}
// Refresh text portion in control
if (m_text)
m_text->ChangeValue(str);
else
m_valueString = str;
Refresh();
}
void AGEComboBox::Flash()
{
int sel = GetSelection();
popup->Flash();
SetSelection(sel >= 0 && sel < GetCount() ? sel : 0);
}
LinkedComboBox::LinkedComboBox(wxWindow *parent, AGETextCtrl *link, wxArrayString *choices,
bool connect, int width) :
AGEComboBox(parent, choices, width), LinkedControl(link)
{
if (connect)
{
Bind(wxEVT_COMBOBOX, &LinkedComboBox::OnChoose, this);
}
}
void LinkedComboBox::OnChoose(wxCommandEvent &)
{
TextControl->ChangeValue(lexical_cast<std::string>(GetSelection() - 1));
TextControl->SaveEdits();
}
void LinkedComboBox::SetChoice(int value)
{
if (GetCount() == 0) return;
if (value >= 0 && ++value < GetCount())
{
SetSelection(value);
}
else
{
SetSelection(0);
}
}