2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software 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.
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "BOINCListCtrl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "BOINCBaseView.h"
|
|
|
|
#include "BOINCListCtrl.h"
|
2004-09-24 02:01:53 +00:00
|
|
|
#include "Events.h"
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CBOINCListCtrl, wxListView)
|
|
|
|
|
|
|
|
|
2005-04-08 16:58:55 +00:00
|
|
|
CBOINCListCtrl::CBOINCListCtrl() {}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
2005-04-08 16:58:55 +00:00
|
|
|
CBOINCListCtrl::CBOINCListCtrl(
|
|
|
|
CBOINCBaseView* pView, wxWindowID iListWindowID, wxInt32 iListWindowFlags
|
|
|
|
) : wxListView(
|
|
|
|
pView, iListWindowID, wxDefaultPosition, wxSize(-1, -1), iListWindowFlags
|
|
|
|
) {
|
2004-09-21 01:30:29 +00:00
|
|
|
m_pParentView = pView;
|
2004-12-10 20:46:43 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
m_bIsSingleSelection = (iListWindowFlags & wxLC_SINGLE_SEL) ? true : false ;
|
2004-12-10 20:46:43 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
Connect(
|
2004-12-10 20:46:43 +00:00
|
|
|
iListWindowID,
|
|
|
|
wxEVT_COMMAND_LEFT_CLICK,
|
2004-12-10 21:29:22 +00:00
|
|
|
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &CBOINCListCtrl::OnClick
|
2005-04-08 16:58:55 +00:00
|
|
|
);
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
CBOINCListCtrl::~CBOINCListCtrl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCListCtrl::OnSaveState(wxConfigBase* pConfig) {
|
2004-10-26 01:59:44 +00:00
|
|
|
wxString strBaseConfigLocation = wxEmptyString;
|
2004-09-21 01:30:29 +00:00
|
|
|
wxListItem liColumnInfo;
|
|
|
|
wxInt32 iIndex = 0;
|
|
|
|
wxInt32 iColumnCount = 0;
|
|
|
|
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pConfig);
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Retrieve the base location to store configuration information
|
|
|
|
// Should be in the following form: "/Projects/"
|
2004-10-05 02:55:26 +00:00
|
|
|
strBaseConfigLocation = pConfig->GetPath() + wxT("/");
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
// Convert to a zero based index
|
|
|
|
iColumnCount = GetColumnCount() - 1;
|
|
|
|
|
|
|
|
// Which fields are we interested in?
|
2005-04-07 07:04:50 +00:00
|
|
|
liColumnInfo.SetMask(
|
|
|
|
wxLIST_MASK_TEXT |
|
|
|
|
wxLIST_MASK_WIDTH |
|
|
|
|
wxLIST_MASK_FORMAT
|
|
|
|
);
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
// Cycle through the columns recording anything interesting
|
2005-04-07 07:04:50 +00:00
|
|
|
for (iIndex = 0; iIndex <= iColumnCount; iIndex++) {
|
2004-09-21 01:30:29 +00:00
|
|
|
GetColumn(iIndex, liColumnInfo);
|
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + liColumnInfo.GetText());
|
|
|
|
|
2004-10-05 02:55:26 +00:00
|
|
|
pConfig->Write(wxT("Width"), liColumnInfo.GetWidth());
|
2007-02-21 04:56:46 +00:00
|
|
|
|
|
|
|
#if (defined(__WXMAC__) && wxCHECK_VERSION(2,8,0))
|
|
|
|
pConfig->Write(wxT("Width"), GetColumnWidth(iIndex)); // Work around bug in wxMac-2.8.0 wxListCtrl::SetColumn()
|
|
|
|
#endif
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCListCtrl::OnRestoreState(wxConfigBase* pConfig) {
|
2004-10-26 01:59:44 +00:00
|
|
|
wxString strBaseConfigLocation = wxEmptyString;
|
2004-09-21 01:30:29 +00:00
|
|
|
wxListItem liColumnInfo;
|
|
|
|
wxInt32 iIndex = 0;
|
|
|
|
wxInt32 iColumnCount = 0;
|
|
|
|
wxInt32 iTempValue = 0;
|
|
|
|
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pConfig);
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Retrieve the base location to store configuration information
|
|
|
|
// Should be in the following form: "/Projects/"
|
2004-10-05 02:55:26 +00:00
|
|
|
strBaseConfigLocation = pConfig->GetPath() + wxT("/");
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
// Convert to a zero based index
|
|
|
|
iColumnCount = GetColumnCount() - 1;
|
|
|
|
|
|
|
|
// Which fields are we interested in?
|
2005-04-08 16:58:55 +00:00
|
|
|
liColumnInfo.SetMask(
|
|
|
|
wxLIST_MASK_TEXT | wxLIST_MASK_WIDTH | wxLIST_MASK_FORMAT
|
|
|
|
);
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
// Cycle through the columns recording anything interesting
|
2005-04-07 07:04:50 +00:00
|
|
|
for (iIndex = 0; iIndex <= iColumnCount; iIndex++) {
|
2004-09-21 01:30:29 +00:00
|
|
|
GetColumn(iIndex, liColumnInfo);
|
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + liColumnInfo.GetText());
|
|
|
|
|
2006-03-27 21:11:09 +00:00
|
|
|
pConfig->Read(wxT("Width"), &iTempValue, -1);
|
|
|
|
if (-1 != iTempValue) {
|
|
|
|
liColumnInfo.SetWidth(iTempValue);
|
2007-02-21 04:56:46 +00:00
|
|
|
#if (defined(__WXMAC__) && wxCHECK_VERSION(2,8,0))
|
|
|
|
SetColumnWidth(iIndex,iTempValue); // Work around bug in wxMac-2.8.0 wxListCtrl::SetColumn()
|
|
|
|
#endif
|
2006-03-27 21:11:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pConfig->Read(wxT("Format"), &iTempValue, -1);
|
|
|
|
if (-1 != iTempValue) {
|
|
|
|
liColumnInfo.SetAlign((wxListColumnFormat)iTempValue);
|
|
|
|
}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
SetColumn(iIndex, liColumnInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
void CBOINCListCtrl::OnClick(wxCommandEvent& event) {
|
2006-01-30 23:05:52 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCListCtrl::OnClick - Function Begin"));
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pParentView);
|
2004-12-10 20:46:43 +00:00
|
|
|
wxASSERT(wxDynamicCast(m_pParentView, CBOINCBaseView));
|
|
|
|
|
2006-01-30 23:05:52 +00:00
|
|
|
wxListEvent leDeselectedEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED, m_windowId);
|
|
|
|
leDeselectedEvent.SetEventObject(this);
|
2004-12-10 20:46:43 +00:00
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
if (m_bIsSingleSelection) {
|
2005-04-08 16:58:55 +00:00
|
|
|
if (GetFocusedItem() != GetFirstSelected()) {
|
2006-01-30 23:05:52 +00:00
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCListCtrl::OnClick - GetFocusedItem() '%d' != GetFirstSelected() '%d'"), GetFocusedItem(), GetFirstSelected());
|
|
|
|
|
|
|
|
if (-1 == GetFirstSelected()) {
|
|
|
|
wxLogTrace(wxT("Function Status"), wxT("CBOINCListCtrl::OnClick - Force Selected State"));
|
|
|
|
|
|
|
|
long desiredstate = wxLIST_STATE_FOCUSED | wxLIST_STATE_SELECTED;
|
|
|
|
SetItemState(GetFocusedItem(), desiredstate, desiredstate);
|
|
|
|
} else {
|
|
|
|
m_pParentView->FireOnListDeselected(leDeselectedEvent);
|
|
|
|
}
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2005-04-07 07:04:50 +00:00
|
|
|
} else {
|
2005-04-08 16:58:55 +00:00
|
|
|
if (-1 == GetFirstSelected()) {
|
2006-01-30 23:05:52 +00:00
|
|
|
m_pParentView->FireOnListDeselected(leDeselectedEvent);
|
2005-04-08 16:58:55 +00:00
|
|
|
}
|
2004-12-10 20:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
event.Skip();
|
2006-01-30 23:05:52 +00:00
|
|
|
wxLogTrace(wxT("Function Start/End"), wxT("CBOINCListCtrl::OnClick - Function End"));
|
2004-12-10 20:46:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxString CBOINCListCtrl::OnGetItemText(long item, long column) const {
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pParentView);
|
2004-09-21 01:30:29 +00:00
|
|
|
wxASSERT(wxDynamicCast(m_pParentView, CBOINCBaseView));
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
return m_pParentView->FireOnListGetItemText(item, column);
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
int CBOINCListCtrl::OnGetItemImage(long item) const {
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pParentView);
|
2004-09-21 01:30:29 +00:00
|
|
|
wxASSERT(wxDynamicCast(m_pParentView, CBOINCBaseView));
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
return m_pParentView->FireOnListGetItemImage(item);
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
wxListItemAttr* CBOINCListCtrl::OnGetItemAttr(long item) const {
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(m_pParentView);
|
2004-09-21 01:30:29 +00:00
|
|
|
wxASSERT(wxDynamicCast(m_pParentView, CBOINCBaseView));
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
return m_pParentView->FireOnListGetItemAttr(item);
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 00:40:19 +00:00
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_5cf411daa0 = "$Id$";
|