forked from BOINC/boinc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBOINCBitmapComboBox.cpp
119 lines (96 loc) · 3.51 KB
/
BOINCBitmapComboBox.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
// This file is part of BOINC.
// http://boinc.berkeley.edu
// Copyright (C) 2008 University of California
//
// BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// BOINC is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
#include "stdwx.h"
#include "BOINCBitmapComboBox.h"
// On Windows, wxBitmapComboBox loses an item's clientData when
// another item is inserted in front of it. This subclass works
// around that bug by keeping the clientData separately.
IMPLEMENT_DYNAMIC_CLASS(CBOINCBitmapComboBox, wxBitmapComboBox)
CBOINCBitmapComboBox::CBOINCBitmapComboBox() {}
CBOINCBitmapComboBox::CBOINCBitmapComboBox(wxWindow *parent, wxWindowID id,
const wxString& value,
const wxPoint& pos,
const wxSize& size,
int n, const wxString choices[],
long style,
const wxValidator& validator,
const wxString& name
) :
wxBitmapComboBox(parent, id, value, pos, size, n,
choices, style, validator, name
)
{
int i;
for (i=0; i<n; ++i) {
m_pClientData.push_back(NULL);
}
}
CBOINCBitmapComboBox::~CBOINCBitmapComboBox() {
Clear();
}
void * CBOINCBitmapComboBox::GetClientData(unsigned int n) const {
if (n < GetCount()) {
return m_pClientData[n];
}
else {
return NULL;
}
}
void CBOINCBitmapComboBox::SetClientData(unsigned int n, void *data) {
if (n < GetCount()) {
m_pClientData[n] = data;
}
}
int CBOINCBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap) {
m_pClientData.push_back(NULL);
int n = wxBitmapComboBox::Append(item, bitmap);
return n;
}
int CBOINCBitmapComboBox::Append(const wxString& item, const wxBitmap& bitmap, void *clientData) {
m_pClientData.push_back(clientData);
int n = wxBitmapComboBox::Append(item, bitmap, (void*)NULL);
return n;
}
int CBOINCBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos) {
std::vector<void*>::iterator insertionPoint = m_pClientData.begin();
m_pClientData.insert(insertionPoint + pos, NULL);
int n = wxBitmapComboBox::Insert(item, bitmap, pos);
return n;
}
int CBOINCBitmapComboBox::Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos, void *clientData) {
std::vector<void*>::iterator insertionPoint = m_pClientData.begin();
m_pClientData.insert(insertionPoint + pos, clientData);
int n = wxBitmapComboBox::Insert(item, bitmap, pos, (void*)NULL);
return n;
}
void CBOINCBitmapComboBox::Delete(unsigned int n) {
if (n < GetCount()) {
std::vector<void*>::iterator deletionPoint = m_pClientData.begin();
m_pClientData.erase(deletionPoint + n);
}
wxBitmapComboBox::Delete(n);
// Refresh();
}
void CBOINCBitmapComboBox::Clear() {
int count = GetCount();
for(int j = count-1; j >=0; --j) {
wxASSERT(!m_pClientData[j]);
m_pClientData[j] = NULL;
}
m_pClientData.clear();
wxBitmapComboBox::Clear();
}