2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// 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.
|
2004-09-21 01:30:29 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// 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
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "BOINCTaskCtrl.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
|
|
|
#include "BOINCBaseView.h"
|
|
|
|
#include "BOINCTaskCtrl.h"
|
|
|
|
|
2012-01-25 11:51:31 +00:00
|
|
|
#define TASKPANEWIDTH 200
|
|
|
|
#define TASKBUTTONWIDTH (TASKPANEWIDTH - 55)
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2005-07-22 20:19:58 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(CBOINCTaskCtrl, wxScrolledWindow)
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CBOINCTaskCtrl::CBOINCTaskCtrl() {}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
2005-04-20 22:22:41 +00:00
|
|
|
CBOINCTaskCtrl::CBOINCTaskCtrl(CBOINCBaseView* pView, wxWindowID iTaskWindowID, wxInt32 iTaskWindowFlags) :
|
2012-01-25 11:53:41 +00:00
|
|
|
wxScrolledWindow(pView, iTaskWindowID, wxDefaultPosition, wxSize(TASKPANEWIDTH, -1), iTaskWindowFlags)
|
2004-09-21 01:30:29 +00:00
|
|
|
{
|
2005-04-20 22:22:41 +00:00
|
|
|
m_pParent = pView;
|
2005-07-22 20:19:58 +00:00
|
|
|
m_pSizer = NULL;
|
2005-07-21 09:43:40 +00:00
|
|
|
|
2012-01-25 11:53:41 +00:00
|
|
|
SetVirtualSize( TASKPANEWIDTH, 1000 );
|
2005-07-24 08:35:57 +00:00
|
|
|
EnableScrolling(false, true);
|
|
|
|
SetScrollRate( 0, 10 );
|
2009-11-25 12:43:22 +00:00
|
|
|
|
|
|
|
#ifdef __WXMAC__
|
|
|
|
//Accessibility
|
|
|
|
HIObjectSetAccessibilityIgnored((HIObjectRef)GetHandle(), true);
|
|
|
|
#endif
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
CBOINCTaskCtrl::~CBOINCTaskCtrl() {}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
|
|
|
|
2005-04-27 06:32:40 +00:00
|
|
|
wxInt32 CBOINCTaskCtrl::DeleteTaskGroupAndTasks( CTaskItemGroup* pGroup ) {
|
|
|
|
unsigned int i;
|
|
|
|
CTaskItem* pItem = NULL;
|
|
|
|
|
|
|
|
for (i=0; i < pGroup->m_Tasks.size(); i++) {
|
|
|
|
pItem = pGroup->m_Tasks[i];
|
|
|
|
DeleteTask(pGroup, pItem);
|
|
|
|
}
|
|
|
|
if (pGroup->m_pStaticBoxSizer) {
|
2005-07-22 20:19:58 +00:00
|
|
|
m_pSizer->Detach(pGroup->m_pStaticBoxSizer);
|
2005-04-27 06:32:40 +00:00
|
|
|
pGroup->m_pStaticBoxSizer->Detach(pGroup->m_pStaticBox);
|
|
|
|
|
|
|
|
delete pGroup->m_pStaticBox;
|
|
|
|
delete pGroup->m_pStaticBoxSizer;
|
|
|
|
|
|
|
|
pGroup->m_pStaticBox = NULL;
|
|
|
|
pGroup->m_pStaticBoxSizer = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::DisableTaskGroupTasks( CTaskItemGroup* pGroup ) {
|
|
|
|
unsigned int i;
|
|
|
|
CTaskItem* pItem = NULL;
|
|
|
|
|
|
|
|
if (pGroup) {
|
|
|
|
for (i=0; i < pGroup->m_Tasks.size(); i++) {
|
|
|
|
pItem = pGroup->m_Tasks[i];
|
|
|
|
DisableTask(pItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::EnableTaskGroupTasks( CTaskItemGroup* pGroup ) {
|
|
|
|
unsigned int i;
|
|
|
|
CTaskItem* pItem = NULL;
|
|
|
|
|
|
|
|
if (pGroup) {
|
|
|
|
for (i=0; i < pGroup->m_Tasks.size(); i++) {
|
|
|
|
pItem = pGroup->m_Tasks[i];
|
|
|
|
EnableTask(pItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::DeleteTask( CTaskItemGroup* pGroup, CTaskItem* pItem ) {
|
|
|
|
if (pItem->m_pButton) {
|
|
|
|
pGroup->m_pStaticBoxSizer->Detach(pItem->m_pButton);
|
|
|
|
delete pItem->m_pButton;
|
|
|
|
pItem->m_pButton = NULL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::DisableTask( CTaskItem* pItem ) {
|
|
|
|
if (pItem->m_pButton) {
|
|
|
|
pItem->m_pButton->Disable();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::EnableTask( CTaskItem* pItem ) {
|
|
|
|
if (pItem->m_pButton) {
|
|
|
|
pItem->m_pButton->Enable();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxInt32 CBOINCTaskCtrl::UpdateTask( CTaskItem* pItem, wxString strName, wxString strDescription ) {
|
|
|
|
if (pItem->m_pButton) {
|
2012-01-25 11:51:31 +00:00
|
|
|
if (!pItem->m_strName.Cmp(strName) &&
|
|
|
|
!pItem->m_strDescription.Cmp(strDescription)) {
|
|
|
|
return 0;
|
|
|
|
}
|
2005-04-27 06:32:40 +00:00
|
|
|
pItem->m_strName = strName;
|
2012-01-25 11:51:31 +00:00
|
|
|
pItem->m_strNameEllipsed = pItem->m_strName;
|
|
|
|
EllipseStringIfNeeded(pItem->m_strNameEllipsed, pItem->m_pButton);
|
2005-04-27 06:32:40 +00:00
|
|
|
pItem->m_strDescription = strDescription;
|
2012-01-25 11:51:31 +00:00
|
|
|
pItem->m_pButton->SetLabel( pItem->m_strNameEllipsed );
|
2005-07-21 09:43:40 +00:00
|
|
|
pItem->m_pButton->SetHelpText( strDescription );
|
2005-04-27 06:32:40 +00:00
|
|
|
#if wxUSE_TOOLTIPS
|
2012-01-25 11:51:31 +00:00
|
|
|
pItem->m_pButton->SetToolTip(pItem->m_strName + wxT(": ") + pItem->m_strDescription);
|
2005-04-27 06:32:40 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-04-06 20:40:19 +00:00
|
|
|
|
2005-04-21 23:14:10 +00:00
|
|
|
wxInt32 CBOINCTaskCtrl::UpdateControls() {
|
2005-04-20 22:22:41 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int j;
|
2005-04-21 23:14:10 +00:00
|
|
|
bool bCreateMainSizer = false;
|
2005-04-20 22:22:41 +00:00
|
|
|
CTaskItemGroup* pGroup = NULL;
|
|
|
|
CTaskItem* pItem = NULL;
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2005-04-27 06:32:40 +00:00
|
|
|
|
|
|
|
bCreateMainSizer = !GetSizer();
|
|
|
|
if (bCreateMainSizer) {
|
|
|
|
SetAutoLayout(TRUE);
|
2005-07-22 20:19:58 +00:00
|
|
|
m_pSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
m_pSizer->Add(5, 5, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
|
2005-04-21 23:14:10 +00:00
|
|
|
}
|
2004-09-21 01:30:29 +00:00
|
|
|
|
2005-04-27 06:32:40 +00:00
|
|
|
|
2005-04-21 23:14:10 +00:00
|
|
|
// Create static boxes and sizers if they don't exist
|
2005-04-20 22:22:41 +00:00
|
|
|
for (i=0; i < m_pParent->m_TaskGroups.size(); i++) {
|
|
|
|
pGroup = m_pParent->m_TaskGroups[i];
|
2005-04-27 06:32:40 +00:00
|
|
|
if (!pGroup->m_pStaticBoxSizer) {
|
2005-04-21 23:14:10 +00:00
|
|
|
pGroup->m_pStaticBox = new wxStaticBox(this, wxID_ANY, pGroup->m_strName);
|
|
|
|
pGroup->m_pStaticBoxSizer = new wxStaticBoxSizer(pGroup->m_pStaticBox, wxVERTICAL);
|
2005-07-22 20:19:58 +00:00
|
|
|
m_pSizer->Add(pGroup->m_pStaticBoxSizer, 0, wxEXPAND|wxALL, 5);
|
2009-11-25 12:43:22 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
pGroup->SetupMacAccessibilitySupport();
|
|
|
|
#endif
|
2005-04-21 23:14:10 +00:00
|
|
|
}
|
|
|
|
}
|
2004-12-23 03:36:51 +00:00
|
|
|
|
2005-04-21 23:14:10 +00:00
|
|
|
// Create buttons if they don't exist
|
|
|
|
for (i=0; i < m_pParent->m_TaskGroups.size(); i++) {
|
|
|
|
pGroup = m_pParent->m_TaskGroups[i];
|
2005-04-20 22:22:41 +00:00
|
|
|
for (j=0; j < pGroup->m_Tasks.size(); j++) {
|
|
|
|
pItem = pGroup->m_Tasks[j];
|
2005-04-21 23:14:10 +00:00
|
|
|
if (!pItem->m_pButton) {
|
|
|
|
pItem->m_pButton = new wxButton;
|
2012-01-25 11:51:31 +00:00
|
|
|
pItem->m_strNameEllipsed = pItem->m_strName;
|
|
|
|
pItem->m_pButton->Create(this, pItem->m_iEventID, wxEmptyString, wxDefaultPosition, wxSize(TASKBUTTONWIDTH, -1), 0);
|
|
|
|
EllipseStringIfNeeded(pItem->m_strNameEllipsed, pItem->m_pButton);
|
|
|
|
pItem->m_pButton->SetLabel(pItem->m_strNameEllipsed);
|
2005-07-21 09:43:40 +00:00
|
|
|
pItem->m_pButton->SetHelpText(pItem->m_strDescription);
|
2005-04-25 17:57:27 +00:00
|
|
|
#if wxUSE_TOOLTIPS
|
2012-01-25 11:51:31 +00:00
|
|
|
pItem->m_pButton->SetToolTip(pItem->m_strName + wxT(": ") + pItem->m_strDescription);
|
2005-04-25 17:57:27 +00:00
|
|
|
#endif
|
2005-04-21 23:14:10 +00:00
|
|
|
pGroup->m_pStaticBoxSizer->Add(pItem->m_pButton, 0, wxEXPAND|wxALL, 5);
|
|
|
|
}
|
2005-03-30 21:11:49 +00:00
|
|
|
}
|
2004-12-23 01:06:41 +00:00
|
|
|
}
|
2004-09-22 21:53:07 +00:00
|
|
|
|
2005-04-21 23:14:10 +00:00
|
|
|
if (bCreateMainSizer) {
|
2005-07-22 20:19:58 +00:00
|
|
|
SetSizer(m_pSizer);
|
2005-04-21 23:14:10 +00:00
|
|
|
}
|
2005-04-21 19:10:10 +00:00
|
|
|
|
2005-07-22 20:19:58 +00:00
|
|
|
// Force update layout and scrollbars, since nothing we do here
|
|
|
|
// necessarily generates a size event which would do it for us.
|
|
|
|
FitInside();
|
2009-11-25 12:43:22 +00:00
|
|
|
|
2005-04-20 22:22:41 +00:00
|
|
|
return 0;
|
2004-09-21 01:30:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCTaskCtrl::OnSaveState(wxConfigBase* pConfig) {
|
2005-04-06 20:40:19 +00:00
|
|
|
wxString strBaseConfigLocation = wxEmptyString;
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pConfig);
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Retrieve the base location to store configuration information
|
|
|
|
// Should be in the following form: "/Projects/"
|
|
|
|
strBaseConfigLocation = pConfig->GetPath() + wxT("/");
|
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + wxT("TaskCtrl/"));
|
|
|
|
|
2005-04-20 22:22:41 +00:00
|
|
|
//WriteCustomization(pConfig);
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation);
|
|
|
|
|
2004-09-21 01:30:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-07 07:04:50 +00:00
|
|
|
bool CBOINCTaskCtrl::OnRestoreState(wxConfigBase* pConfig) {
|
2005-04-06 20:40:19 +00:00
|
|
|
wxString strBaseConfigLocation = wxEmptyString;
|
|
|
|
|
2005-04-27 06:55:28 +00:00
|
|
|
wxASSERT(pConfig);
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
// Retrieve the base location to store configuration information
|
|
|
|
// Should be in the following form: "/Projects/"
|
|
|
|
strBaseConfigLocation = pConfig->GetPath() + wxT("/");
|
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation + wxT("TaskCtrl/"));
|
|
|
|
|
2005-04-20 22:22:41 +00:00
|
|
|
//ReadCustomization(pConfig);
|
2005-04-06 20:40:19 +00:00
|
|
|
|
|
|
|
pConfig->SetPath(strBaseConfigLocation);
|
|
|
|
|
2004-09-21 01:30:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-01-25 11:51:31 +00:00
|
|
|
|
|
|
|
void CBOINCTaskCtrl::EllipseStringIfNeeded(wxString& s, wxWindow *win) {
|
|
|
|
int w, h;
|
|
|
|
wxSize sz = win->GetSize();
|
|
|
|
int maxWidth = sz.GetWidth() - 10;
|
|
|
|
|
|
|
|
win->GetTextExtent(s, &w, &h);
|
|
|
|
|
|
|
|
// Adapted from ellipis code in wxRendererGeneric::DrawHeaderButtonContents()
|
|
|
|
if (w > maxWidth) {
|
|
|
|
int ellipsisWidth;
|
|
|
|
win->GetTextExtent( wxT("..."), &ellipsisWidth, NULL);
|
|
|
|
if (ellipsisWidth > maxWidth) {
|
|
|
|
s.Clear();
|
|
|
|
w = 0;
|
|
|
|
} else {
|
|
|
|
do {
|
|
|
|
s.Truncate( s.length() - 1 );
|
|
|
|
win->GetTextExtent( s, &w, &h);
|
|
|
|
} while (((w + ellipsisWidth) > maxWidth) && s.length() );
|
|
|
|
s.append( wxT("...") );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|