From 98b653bc88b8dcf03bd977fcde8e699f94b82d0e Mon Sep 17 00:00:00 2001 From: Charlie Fenton Date: Tue, 25 Oct 2011 11:22:57 +0000 Subject: [PATCH] MGR: Sort Simple View task selection control alphabetically, working around clientData bug in wxBitmapComboBox::Insert() svn path=/trunk/boinc/; revision=24478 --- clientgui/BOINCBitmapComboBox.cpp | 119 ++++++++++++++++++++++++++++++ clientgui/BOINCBitmapComboBox.h | 66 +++++++++++++++++ 2 files changed, 185 insertions(+) create mode 100644 clientgui/BOINCBitmapComboBox.cpp create mode 100644 clientgui/BOINCBitmapComboBox.h diff --git a/clientgui/BOINCBitmapComboBox.cpp b/clientgui/BOINCBitmapComboBox.cpp new file mode 100644 index 0000000000..0c70efa582 --- /dev/null +++ b/clientgui/BOINCBitmapComboBox.cpp @@ -0,0 +1,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 . + +#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::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::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::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(); +} diff --git a/clientgui/BOINCBitmapComboBox.h b/clientgui/BOINCBitmapComboBox.h new file mode 100644 index 0000000000..fef3856930 --- /dev/null +++ b/clientgui/BOINCBitmapComboBox.h @@ -0,0 +1,66 @@ +// 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 . + +#ifndef __BOINCBITMAPCOMBOBOX__ +#define __BOINCBITMAPCOMBOBOX__ + +#include + +#define EVT_BOINCBITMAPCOMBOBOX EVT_COMBOBOX + +// TODO: Subclass CBOINCBitmapComboBox to be accessible on Windows. +// Either: +// Add WxBitmapComboBoxAccessible class (like CNoticeListCtrlAccessible +// for CNoticeListCtrl) +// or +// simulate bitmap combo box using accessible standard Windows controls +// (as done for CBOINCBitmapComboBox on Mac) +// TODO: Add wx/bmpcbox.h to stdwx.h + +class CBOINCBitmapComboBox : public wxBitmapComboBox +{ + DECLARE_DYNAMIC_CLASS( CBOINCBitmapComboBox ) + +public: + CBOINCBitmapComboBox(); + + virtual ~CBOINCBitmapComboBox(); + + CBOINCBitmapComboBox(wxWindow *parent, wxWindowID id, + const wxString& value = wxT(""), + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + int n = 0, const wxString choices[] = NULL, + long style = 0, + const wxValidator& validator = wxDefaultValidator, + const wxString& name = wxT("combo")); + + void * GetClientData(unsigned int n) const; + void SetClientData(unsigned int n, void *data); + int Append(const wxString& item); + int Append(const wxString& item, const wxBitmap& bitmap); + int Append(const wxString& item, const wxBitmap& bitmap, void *clientData); + int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos); + int Insert(const wxString& item, const wxBitmap& bitmap, unsigned int pos, void *clientData); + void Delete(unsigned int n); + void Clear(); + +private: + std::vector m_pClientData; +}; + +#endif //__BOINCBITMAPCOMBOBOX__