2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2006-08-10 19:32:47 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2006-08-10 19:32:47 +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.
|
2006-08-10 19:32:47 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2006-08-10 19:32:47 +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.
|
|
|
|
//
|
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/>.
|
2006-08-10 19:32:47 +00:00
|
|
|
|
|
|
|
#if defined(__GNUG__) && !defined(__APPLE__)
|
|
|
|
#pragma implementation "sg_ImageButton.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "stdwx.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "diagnostics.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "mfile.h"
|
|
|
|
#include "miofile.h"
|
|
|
|
#include "parse.h"
|
|
|
|
#include "error_numbers.h"
|
2006-10-23 06:48:48 +00:00
|
|
|
#include "common/wxFlatNotebook.h"
|
2006-10-20 15:00:14 +00:00
|
|
|
#include "BOINCGUIApp.h"
|
|
|
|
#include "SkinManager.h"
|
|
|
|
#include "MainDocument.h"
|
2006-10-23 06:48:48 +00:00
|
|
|
#include "sg_ImageButton.h"
|
|
|
|
#include "sg_ImageLoader.h"
|
2006-08-10 19:32:47 +00:00
|
|
|
#include "sg_ViewTabPage.h"
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(CImageButton, wxPanel)
|
|
|
|
EVT_PAINT(CImageButton::OnPaint)
|
|
|
|
EVT_LEFT_UP(CImageButton::OnLeftUp)
|
|
|
|
EVT_ERASE_BACKGROUND(CImageButton::OnEraseBackground)
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2006-11-08 17:38:27 +00:00
|
|
|
CImageButton::CImageButton(wxWindow* parent,wxBitmap bg, wxPoint coord,wxSize size,bool enableShowGraphics, int initStatus) : wxPanel(parent, wxID_ANY, coord, size, wxNO_BORDER)
|
2006-08-10 19:32:47 +00:00
|
|
|
{
|
|
|
|
btnBG = bg;
|
2006-11-08 17:38:27 +00:00
|
|
|
m_enableShowGraphics = enableShowGraphics;
|
2006-10-12 02:18:08 +00:00
|
|
|
status = initStatus;
|
2006-11-08 17:38:27 +00:00
|
|
|
SetToolTip();
|
|
|
|
}
|
|
|
|
|
|
|
|
CImageButton::~CImageButton() {
|
2006-08-10 19:32:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CImageButton::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
2006-10-12 02:18:08 +00:00
|
|
|
dc.SetTextForeground(wxColour(*wxWHITE));
|
2006-11-02 11:59:42 +00:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
dc.SetFont(wxFont(10,74,90,90,0,wxT("Arial")));
|
|
|
|
#else
|
2006-10-12 02:18:08 +00:00
|
|
|
dc.SetFont(wxFont(7,74,90,90,0,wxT("Arial")));
|
2006-11-02 11:59:42 +00:00
|
|
|
#endif
|
2006-10-12 02:18:08 +00:00
|
|
|
int x, y;
|
|
|
|
GetSize(&x,&y);
|
|
|
|
wxCoord width, height;
|
|
|
|
dc.GetTextExtent(GetStatusText(), &width, &height);
|
|
|
|
dc.DrawText(GetStatusText(), wxPoint(7, y-height-4));
|
|
|
|
// display show graphics text (if available)
|
2006-11-08 17:38:27 +00:00
|
|
|
if(m_enableShowGraphics) {
|
2007-07-11 16:26:44 +00:00
|
|
|
wxString text = wxString(_T("Graphics Available"));
|
2006-09-29 16:01:17 +00:00
|
|
|
dc.GetTextExtent(text, &width, &height);
|
|
|
|
dc.DrawText(text, wxPoint(x-width-7,y-height-4));
|
2006-08-10 19:32:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void CImageButton::SetImage(wxBitmap bg)
|
|
|
|
{
|
2006-09-15 16:47:04 +00:00
|
|
|
btnBG = bg;
|
2006-08-10 19:32:47 +00:00
|
|
|
}
|
2006-10-12 02:18:08 +00:00
|
|
|
void CImageButton::SetStatus(int newStatus) {
|
|
|
|
status = newStatus;
|
|
|
|
}
|
|
|
|
int CImageButton::GetStatus() {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString CImageButton::GetStatusText() {
|
|
|
|
if ( status == TAB_STATUS_RUNNING ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Running"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PREEMPTED ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused: Other work running"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED_USER_REQ ) {
|
2010-07-20 21:15:15 +00:00
|
|
|
return wxString(_("Paused: User initiated. Click 'Resume' to continue"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED_USER_ACTIVE ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused: User active"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED_POWER ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused: Computer on battery"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED_TIME_OF_DAY ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused: Time of Day"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED_BENCHMARKS ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused: Benchmarks running"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else if ( status == TAB_STATUS_PAUSED ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
return wxString(_("Paused"));
|
2008-10-23 04:10:12 +00:00
|
|
|
} else if ( status == TAB_STATUS_INITIAL_DELAY ) {
|
|
|
|
return wxString(_("Paused: Application start delayed"));
|
2006-10-12 02:18:08 +00:00
|
|
|
} else {
|
2006-12-20 00:05:12 +00:00
|
|
|
return wxEmptyString;
|
2006-10-12 02:18:08 +00:00
|
|
|
}
|
|
|
|
}
|
2006-08-10 19:32:47 +00:00
|
|
|
void CImageButton::OnEraseBackground(wxEraseEvent& event){
|
|
|
|
|
|
|
|
event.Skip(false);
|
|
|
|
wxDC *dc;
|
|
|
|
dc=event.GetDC();
|
|
|
|
dc->SetBackground(wxBrush(this->GetBackgroundColour(),wxSOLID));
|
|
|
|
dc->Clear();
|
|
|
|
if(btnBG.Ok())
|
|
|
|
{
|
|
|
|
dc->DrawBitmap(btnBG, 0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2006-10-12 02:18:08 +00:00
|
|
|
void CImageButton::OnLeftUp(wxMouseEvent& WXUNUSED(event))
|
2006-08-10 19:32:47 +00:00
|
|
|
{
|
|
|
|
CViewTabPage* pView = wxDynamicCast(GetParent(), CViewTabPage);
|
|
|
|
wxASSERT(pView);
|
|
|
|
pView->OnImageButton();
|
|
|
|
|
|
|
|
}
|
2006-09-08 21:48:06 +00:00
|
|
|
|
2006-11-08 17:38:27 +00:00
|
|
|
void CImageButton::SetToolTip() {
|
|
|
|
if ( m_enableShowGraphics ) {
|
2007-07-11 16:26:44 +00:00
|
|
|
wxPanel::SetToolTip(new wxToolTip(_("Click to show project graphics")));
|
2006-11-08 17:38:27 +00:00
|
|
|
} else {
|
|
|
|
wxPanel::SetToolTip(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CImageButton::SetEnableShowGraphics(bool show) {
|
|
|
|
if ( show != m_enableShowGraphics ) {
|
|
|
|
m_enableShowGraphics = show;
|
|
|
|
SetToolTip();
|
2006-09-08 21:48:06 +00:00
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
}
|