2006-07-20 22:15:29 +00:00
// Berkeley Open Infrastructure for Network Computing
// http://boinc.berkeley.edu
// Copyright (C) 2005 University of California
//
// 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.
//
// 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.
//
// To view the GNU Lesser General Public License visit
// http://www.gnu.org/copyleft/lesser.html
// or write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# if defined(__GNUG__) && !defined(__APPLE__)
# pragma implementation "sg_ProjectsComponent.h"
# endif
# include "stdwx.h"
# include "BOINCGUIApp.h"
2006-08-07 15:33:03 +00:00
# include "sg_BoincSimpleGUI.h"
2006-07-20 22:15:29 +00:00
# include "sg_SkinClass.h"
2006-08-07 15:33:03 +00:00
# include "sg_ImageLoader.h"
# include "sg_StaticLine.h"
2006-07-20 22:15:29 +00:00
# include "sg_StatImageLoader.h"
2006-08-07 15:33:03 +00:00
# include "sg_DlgMessages.h"
# include "sg_DlgPreferences.h"
# include "sg_ProjectsComponent.h"
2006-07-24 22:10:28 +00:00
2006-07-20 22:15:29 +00:00
# include "app_ipc.h"
IMPLEMENT_DYNAMIC_CLASS ( CProjectsComponent , wxPanel )
BEGIN_EVENT_TABLE ( CProjectsComponent , wxPanel )
2006-08-07 17:44:46 +00:00
EVT_PAINT ( CProjectsComponent : : OnPaint )
2006-07-20 22:15:29 +00:00
EVT_BUTTON ( - 1 , CProjectsComponent : : OnBtnClick )
2006-08-07 15:33:03 +00:00
EVT_ERASE_BACKGROUND ( CProjectsComponent : : OnEraseBackground )
2006-07-20 22:15:29 +00:00
END_EVENT_TABLE ( )
CProjectsComponent : : CProjectsComponent ( ) { }
2006-08-07 17:44:46 +00:00
2006-07-20 22:15:29 +00:00
CProjectsComponent : : CProjectsComponent ( CSimpleFrame * parent , wxPoint coord ) :
2006-08-07 15:33:03 +00:00
wxPanel ( parent , - 1 , coord , wxSize ( 343 , 113 ) , wxNO_BORDER )
2006-07-20 22:15:29 +00:00
{
wxASSERT ( parent ) ;
m_maxNumOfIcons = 6 ; // max number of icons in component
2006-07-21 18:05:43 +00:00
m_rightIndex = 0 ;
m_leftIndex = 0 ;
2006-08-17 17:36:51 +00:00
m_projCnt = 0 ;
2006-07-20 22:15:29 +00:00
LoadSkinImages ( ) ;
CreateComponent ( ) ;
}
CProjectsComponent : : ~ CProjectsComponent ( ) { }
void CProjectsComponent : : LoadSkinImages ( ) {
//app skin class
appSkin = SkinClass : : Instance ( ) ;
wxString dirPref = appSkin - > GetSkinsFolder ( ) + _T ( " / " ) + appSkin - > GetSkinName ( ) + _T ( " / " ) ;
2006-08-07 15:33:03 +00:00
//
//component bg
2006-08-10 19:32:47 +00:00
fileImgBuf [ 0 ] . LoadFile ( dirPref + appSkin - > GetProjCompBg ( ) , wxBITMAP_TYPE_PNG ) ;
2006-07-20 22:15:29 +00:00
// default stat icon
g_statIcnDefault = new wxImage ( dirPref + appSkin - > GetDefaultStatIcn ( ) , wxBITMAP_TYPE_PNG ) ;
// arrows
g_arwLeft = new wxImage ( dirPref + appSkin - > GetBtnLeftArr ( ) , wxBITMAP_TYPE_PNG ) ;
2006-08-07 15:33:03 +00:00
g_arwRight = new wxImage ( dirPref + appSkin - > GetBtnRightArr ( ) , wxBITMAP_TYPE_PNG ) ;
2006-07-20 22:15:29 +00:00
g_arwLeftClick = new wxImage ( dirPref + appSkin - > GetBtnLeftArrClick ( ) , wxBITMAP_TYPE_PNG ) ;
g_arwRightClick = new wxImage ( dirPref + appSkin - > GetBtnRightArrClick ( ) , wxBITMAP_TYPE_PNG ) ;
2006-08-07 15:33:03 +00:00
// add proj
g_addProj = new wxImage ( dirPref + appSkin - > GetBtnAddProj ( ) , wxBITMAP_TYPE_PNG ) ;
g_addProjClick = new wxImage ( dirPref + appSkin - > GetBtnAddProjClick ( ) , wxBITMAP_TYPE_PNG ) ;
// messages
g_messages = new wxImage ( dirPref + appSkin - > GetBtnMessages ( ) , wxBITMAP_TYPE_PNG ) ;
g_messagesClick = new wxImage ( dirPref + appSkin - > GetBtnMessages ( ) , wxBITMAP_TYPE_PNG ) ;
// pause
g_pause = new wxImage ( dirPref + appSkin - > GetBtnPause ( ) , wxBITMAP_TYPE_PNG ) ;
g_pauseClick = new wxImage ( dirPref + appSkin - > GetBtnPause ( ) , wxBITMAP_TYPE_PNG ) ;
// resume
g_resume = new wxImage ( dirPref + appSkin - > GetBtnResume ( ) , wxBITMAP_TYPE_PNG ) ;
g_resumeClick = new wxImage ( dirPref + appSkin - > GetBtnResume ( ) , wxBITMAP_TYPE_PNG ) ;
// resume
g_pref = new wxImage ( dirPref + appSkin - > GetBtnPrefer ( ) , wxBITMAP_TYPE_PNG ) ;
g_prefClick = new wxImage ( dirPref + appSkin - > GetBtnPrefer ( ) , wxBITMAP_TYPE_PNG ) ;
// resume
g_advView = new wxImage ( dirPref + appSkin - > GetBtnAdvView ( ) , wxBITMAP_TYPE_PNG ) ;
g_advViewClick = new wxImage ( dirPref + appSkin - > GetBtnAdvView ( ) , wxBITMAP_TYPE_PNG ) ;
//spacer
2006-08-11 20:40:52 +00:00
g_spacer = new wxImage ( dirPref + appSkin - > GetSpacerImage ( ) , wxBITMAP_TYPE_PNG ) ;
2006-08-07 15:33:03 +00:00
btmpComponentBg = & fileImgBuf [ 0 ] ;
2006-07-20 22:15:29 +00:00
btmpArwL = wxBitmap ( g_arwLeft ) ;
btmpArwR = wxBitmap ( g_arwRight ) ;
btmpArwLC = wxBitmap ( g_arwLeftClick ) ;
btmpArwRC = wxBitmap ( g_arwRightClick ) ;
2006-08-07 15:33:03 +00:00
btmpAddProj = wxBitmap ( g_addProj ) ;
btmpAddProjC = wxBitmap ( g_addProjClick ) ;
btmpMessages = wxBitmap ( g_messages ) ;
btmpMessagesC = wxBitmap ( g_messagesClick ) ;
btmpPause = wxBitmap ( g_pause ) ;
btmpPauseC = wxBitmap ( g_pauseClick ) ;
btmpResume = wxBitmap ( g_resume ) ;
btmpResumeC = wxBitmap ( g_resumeClick ) ;
btmpPref = wxBitmap ( g_pref ) ;
btmpPrefC = wxBitmap ( g_prefClick ) ;
btmpAdvView = wxBitmap ( g_advView ) ;
btmpAdvViewC = wxBitmap ( g_advViewClick ) ;
2006-07-20 22:15:29 +00:00
}
void CProjectsComponent : : CreateComponent ( )
{
//Set Background color
SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
2006-08-07 15:33:03 +00:00
//Static content in my Projects section
// add project button
wxToolTip * ttAddProject = new wxToolTip ( wxT ( " Add Project " ) ) ;
2006-08-07 17:44:46 +00:00
btnAddProj = new wxBitmapButton ( this , - 1 , btmpAddProj , wxPoint ( 235 , 7 ) , wxSize ( 81 , 18 ) , wxNO_BORDER ) ;
2006-08-07 15:33:03 +00:00
btnAddProj - > SetBitmapSelected ( btmpAddProjC ) ;
btnAddProj - > SetToolTip ( ttAddProject ) ;
/// Line
2006-08-10 19:32:47 +00:00
lnMyProjTop = new CStaticLine ( this , wxPoint ( 29 , 29 ) , wxSize ( 292 , 1 ) ) ;
lnMyProjTop - > SetLineColor ( appSkin - > GetStaticLineCol ( ) ) ;
2006-07-20 22:15:29 +00:00
/////////////// ICONS /////////////////////
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
2006-07-31 13:59:21 +00:00
m_projCnt = pDoc - > GetProjectCount ( ) ;
2006-07-21 18:05:43 +00:00
projectIconName = " stat_icon " ;
defaultIcnPath [ 256 ] ;
2006-07-20 22:15:29 +00:00
// url of project directory
2006-07-21 18:05:43 +00:00
urlDirectory [ 256 ] ;
2006-07-20 22:15:29 +00:00
for ( int j = 0 ; j < m_projCnt ; j + + ) {
PROJECT * project = pDoc - > state . projects [ j ] ;
//user credit text
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
if ( j < m_maxNumOfIcons ) {
// Project button
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
2006-07-31 13:59:21 +00:00
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-07 15:33:03 +00:00
i_statW - > Move ( wxPoint ( 55 + 40 * j , 37 ) ) ;
2006-07-21 18:05:43 +00:00
2006-07-20 22:15:29 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
//load stat icon
2006-07-21 18:05:43 +00:00
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
2006-07-20 22:15:29 +00:00
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . push_back ( i_statW ) ;
2006-07-21 18:05:43 +00:00
//increment left index
2006-07-31 13:59:21 +00:00
m_rightIndex + + ;
2006-07-20 22:15:29 +00:00
}
}
//// Arrow Btns
2006-08-10 19:32:47 +00:00
btnArwLeft = new wxBitmapButton ( this , - 1 , btmpArwL , wxPoint ( 29 , 47 ) , wxSize ( 20 , 20 ) , wxNO_BORDER ) ;
2006-07-20 22:15:29 +00:00
btnArwLeft - > SetBitmapSelected ( btmpArwLC ) ;
btnArwLeft - > Show ( false ) ; //on creation this one is always false
2006-08-10 19:32:47 +00:00
btnArwRight = new wxBitmapButton ( this , - 1 , btmpArwR , wxPoint ( 301 , 47 ) , wxSize ( 20 , 20 ) , wxNO_BORDER ) ;
2006-07-20 22:15:29 +00:00
btnArwRight - > SetBitmapSelected ( btmpArwRC ) ;
if ( m_projCnt > m_maxNumOfIcons ) { //right shows up only if there is more than max num of icons
btnArwRight - > Show ( true ) ;
} else {
btnArwRight - > Show ( false ) ;
}
2006-08-07 15:33:03 +00:00
//
//// Messages Play Pause Btns
wxToolTip * ttMessages = new wxToolTip ( wxT ( " Messages " ) ) ;
btnMessages = new wxBitmapButton ( this , - 1 , btmpMessages , wxPoint ( 11 , 86 ) , wxSize ( 70 , 20 ) , wxNO_BORDER ) ;
btnMessages - > SetBitmapSelected ( btmpMessagesC ) ;
btnMessages - > SetToolTip ( ttMessages ) ;
//spacer
wxWindow * w_sp1 = new wxWindow ( this , - 1 , wxPoint ( 83 , 91 ) , wxSize ( 2 , 11 ) ) ;
i_spacer = new ImageLoader ( w_sp1 ) ;
i_spacer - > LoadImage ( g_spacer ) ;
// pause btn
wxToolTip * ttPause = new wxToolTip ( wxT ( " Pause all processing " ) ) ;
btnPause = new wxBitmapButton ( this , - 1 , btmpPause , wxPoint ( 85 , 86 ) , wxSize ( 59 , 20 ) , wxNO_BORDER ) ;
btnPause - > SetBitmapSelected ( btmpPauseC ) ;
btnPause - > SetToolTip ( ttPause ) ;
// resume btn
wxToolTip * ttResume = new wxToolTip ( wxT ( " Resume all Processing " ) ) ;
btnResume = new wxBitmapButton ( this , - 1 , btmpResume , wxPoint ( 85 , 86 ) , wxSize ( 59 , 20 ) , wxNO_BORDER ) ;
btnResume - > SetBitmapSelected ( btmpResumeC ) ;
btnResume - > SetToolTip ( ttResume ) ;
btnResume - > Show ( false ) ;
//spacer
wxWindow * w_sp2 = new wxWindow ( this , - 1 , wxPoint ( 144 , 91 ) , wxSize ( 2 , 11 ) ) ;
i_spacer = new ImageLoader ( w_sp2 ) ;
i_spacer - > LoadImage ( g_spacer ) ;
// Pref Btn
wxToolTip * ttPreferences = new wxToolTip ( wxT ( " Preferences " ) ) ;
btnPreferences = new wxBitmapButton ( this , - 1 , btmpPref , wxPoint ( 149 , 86 ) , wxSize ( 81 , 20 ) , wxNO_BORDER ) ;
btnPreferences - > SetBitmapSelected ( btmpPrefC ) ;
btnPreferences - > SetToolTip ( ttPreferences ) ;
//spacer
wxWindow * w_sp3 = new wxWindow ( this , - 1 , wxPoint ( 230 , 91 ) , wxSize ( 2 , 11 ) ) ;
i_spacer = new ImageLoader ( w_sp3 ) ;
i_spacer - > LoadImage ( g_spacer ) ;
// Advanced View
wxToolTip * ttAdvView = new wxToolTip ( wxT ( " Advanced View " ) ) ;
btnAdvancedView = new wxBitmapButton ( this , - 1 , btmpAdvView , wxPoint ( 233 , 86 ) , wxSize ( 101 , 20 ) , wxNO_BORDER ) ;
btnAdvancedView - > SetBitmapSelected ( btmpAdvViewC ) ;
btnAdvancedView - > SetToolTip ( ttAdvView ) ;
/// Line
2006-08-10 19:32:47 +00:00
lnMyProjBtm = new CStaticLine ( this , wxPoint ( 29 , 83 ) , wxSize ( 292 , 1 ) ) ;
lnMyProjBtm - > SetLineColor ( appSkin - > GetStaticLineCol ( ) ) ;
2006-07-24 22:10:28 +00:00
}
2006-08-07 17:44:46 +00:00
void CProjectsComponent : : OnPaint ( wxPaintEvent & WXUNUSED ( event ) )
{
wxPaintDC dc ( this ) ;
//My Projects
dc . SetFont ( wxFont ( 10 , 74 , 90 , 92 , 0 , wxT ( " Arial " ) ) ) ;
dc . DrawText ( wxT ( " My Projects: " ) , wxPoint ( 32 , 9 ) ) ;
}
2006-07-24 22:10:28 +00:00
void CProjectsComponent : : RemoveProject ( std : : string prjUrl )
{
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
2006-07-31 13:59:21 +00:00
//update project count
m_projCnt = pDoc - > GetProjectCount ( ) ;
2006-07-24 22:10:28 +00:00
int indexOfIcon = - 1 ;
for ( int m = 0 ; m < ( int ) m_statProjects . size ( ) ; m + + ) {
StatImageLoader * i_statWShifting = m_statProjects . at ( m ) ;
if ( i_statWShifting - > m_prjUrl = = prjUrl ) {
delete m_statProjects . at ( m ) ;
m_statProjects . erase ( m_statProjects . begin ( ) + m ) ;
indexOfIcon = m ;
break ;
}
}
2006-07-31 13:59:21 +00:00
// if last icon is removed but there is still hidden icons on left shifting to right
if ( ( m_leftIndex > 0 ) & & ( m_rightIndex - 1 = = m_projCnt ) ) {
//shift icons right
for ( int m = 0 ; m < indexOfIcon ; m + + ) {
StatImageLoader * i_statWShifting = m_statProjects . at ( m ) ;
2006-08-10 19:32:47 +00:00
i_statWShifting - > Move ( wxPoint ( 55 + 40 * ( m + 1 ) , 37 ) ) ;
2006-07-31 13:59:21 +00:00
}
// create the icon on left
if ( m_leftIndex - 1 > = 0 ) {
PROJECT * project = pDoc - > state . projects . at ( m_leftIndex - 1 ) ;
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-10 19:32:47 +00:00
i_statW - > Move ( wxPoint ( 55 , 37 ) ) ;
2006-07-31 13:59:21 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . insert ( m_statProjects . begin ( ) , i_statW ) ;
//decrement left index
m_leftIndex - - ;
//decrement right index since project was removed at last slot
m_rightIndex - - ;
}
} else {
//shift icons to the left. Nothing will be shifted if last icon is removed
for ( int k = indexOfIcon ; k < ( int ) m_statProjects . size ( ) ; k + + ) {
StatImageLoader * i_statWShifting = m_statProjects . at ( k ) ;
2006-08-11 20:40:52 +00:00
i_statWShifting - > Move ( wxPoint ( 55 + 40 * k , 37 ) ) ;
2006-07-31 13:59:21 +00:00
}
// create the icon on right
if ( m_rightIndex < = m_projCnt ) {
PROJECT * project = pDoc - > state . projects . at ( m_rightIndex - 1 ) ;
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-10 19:32:47 +00:00
i_statW - > Move ( wxPoint ( 55 + 40 * ( m_maxNumOfIcons - 1 ) , 37 ) ) ;
2006-07-31 13:59:21 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . push_back ( i_statW ) ;
} else { //if nothing can be shifted in place of last icon
//decrement right index
m_rightIndex - - ;
}
}
////////////hide or show arrows///////////
if ( m_leftIndex = = 0 ) {
btnArwLeft - > Show ( false ) ;
} else {
btnArwLeft - > Show ( true ) ;
2006-07-24 22:10:28 +00:00
}
2006-07-31 13:59:21 +00:00
//
if ( m_rightIndex < m_projCnt ) {
btnArwRight - > Show ( true ) ;
} else {
btnArwRight - > Show ( false ) ;
}
///////////////////////////////////////////
}
void CProjectsComponent : : UpdateInterface ( )
{
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
int oldProjCnt = m_projCnt ;
m_projCnt = pDoc - > GetProjectCount ( ) ;
if ( m_projCnt = = oldProjCnt ) {
return ;
}
if ( m_projCnt < = m_maxNumOfIcons ) {
PROJECT * project = pDoc - > state . projects . at ( m_projCnt - 1 ) ;
2006-07-24 22:10:28 +00:00
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
2006-07-31 13:59:21 +00:00
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-11 20:40:52 +00:00
i_statW - > Move ( wxPoint ( 55 + 40 * ( m_projCnt - 1 ) , 37 ) ) ;
2006-07-24 22:10:28 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . push_back ( i_statW ) ;
//increment left index
m_rightIndex + + ;
}
2006-07-31 13:59:21 +00:00
//show arrow if we are at the over max number of projects
if ( m_projCnt > m_maxNumOfIcons ) {
btnArwRight - > Show ( true ) ;
2006-07-24 22:10:28 +00:00
}
2006-07-20 22:15:29 +00:00
}
2006-07-24 22:10:28 +00:00
void CProjectsComponent : : ReskinInterface ( )
{
//Load new skin images
LoadSkinImages ( ) ;
//Set Background color only
SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
//right button
btnArwRight - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnArwRight - > SetBitmapLabel ( btmpArwR ) ;
btnArwRight - > SetBitmapSelected ( btmpArwRC ) ;
//left button
btnArwLeft - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnArwLeft - > SetBitmapLabel ( btmpArwL ) ;
btnArwLeft - > SetBitmapSelected ( btmpArwLC ) ;
2006-08-10 19:32:47 +00:00
// add project btn
btnAddProj - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnAddProj - > SetBitmapLabel ( btmpAddProj ) ;
btnAddProj - > SetBitmapSelected ( btmpAddProjC ) ;
// messages btn
btnMessages - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnMessages - > SetBitmapLabel ( btmpMessages ) ;
btnMessages - > SetBitmapSelected ( btmpMessagesC ) ;
// pause btn
btnPause - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnPause - > SetBitmapLabel ( btmpPause ) ;
btnPause - > SetBitmapSelected ( btmpPauseC ) ;
// resume btn
btnResume - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnResume - > SetBitmapLabel ( btmpResume ) ;
btnResume - > SetBitmapSelected ( btmpResumeC ) ;
// preferences btn
btnPreferences - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnPreferences - > SetBitmapLabel ( btmpPref ) ;
btnPreferences - > SetBitmapSelected ( btmpPrefC ) ;
// advance view btn
btnAdvancedView - > SetBackgroundColour ( appSkin - > GetAppBgCol ( ) ) ;
btnAdvancedView - > SetBitmapLabel ( btmpAdvView ) ;
btnAdvancedView - > SetBitmapSelected ( btmpAdvViewC ) ;
//set line colors
lnMyProjTop - > SetLineColor ( appSkin - > GetStaticLineCol ( ) ) ;
lnMyProjBtm - > SetLineColor ( appSkin - > GetStaticLineCol ( ) ) ;
2006-07-24 22:10:28 +00:00
}
2006-07-20 22:15:29 +00:00
void CProjectsComponent : : OnBtnClick ( wxCommandEvent & event ) { //init function
wxObject * m_wxBtnObj = event . GetEventObject ( ) ;
2006-08-07 15:33:03 +00:00
CSimpleFrame * pFrame = wxDynamicCast ( GetParent ( ) , CSimpleFrame ) ;
wxASSERT ( pFrame ) ;
2006-07-20 22:15:29 +00:00
if ( m_wxBtnObj = = btnArwLeft ) {
2006-07-21 18:05:43 +00:00
//delete proj icon at position max number - 1(5)
delete m_statProjects . at ( m_maxNumOfIcons - 1 ) ;
//remove last element from vector
m_statProjects . pop_back ( ) ;
//shift icons right
for ( int m = 0 ; m < ( int ) m_statProjects . size ( ) ; m + + ) {
StatImageLoader * i_statWShifting = m_statProjects . at ( m ) ;
2006-08-10 19:32:47 +00:00
i_statWShifting - > Move ( wxPoint ( 55 + 40 * ( m + 1 ) , 37 ) ) ;
2006-07-21 18:05:43 +00:00
}
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
2006-07-31 13:59:21 +00:00
if ( m_leftIndex - 1 > = 0 ) {
PROJECT * project = pDoc - > state . projects . at ( m_leftIndex - 1 ) ;
2006-07-21 18:05:43 +00:00
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
2006-07-31 13:59:21 +00:00
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-10 19:32:47 +00:00
i_statW - > Move ( wxPoint ( 55 , 37 ) ) ;
2006-07-21 18:05:43 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . insert ( m_statProjects . begin ( ) , i_statW ) ;
2006-07-31 13:59:21 +00:00
//decrement left index
2006-07-21 18:05:43 +00:00
m_leftIndex - - ;
2006-07-31 13:59:21 +00:00
//decrement right index
2006-07-21 18:05:43 +00:00
m_rightIndex - - ;
//now show left button
btnArwRight - > Show ( true ) ;
}
//hide right arrow if we got to the end of the list
2006-07-31 13:59:21 +00:00
if ( m_leftIndex < = 0 ) {
2006-07-21 18:05:43 +00:00
btnArwLeft - > Show ( false ) ;
}
2006-08-10 19:32:47 +00:00
Refresh ( ) ;
2006-07-21 18:05:43 +00:00
2006-07-20 22:15:29 +00:00
} else if ( m_wxBtnObj = = btnArwRight ) {
2006-07-21 18:05:43 +00:00
//delete proj icon at position 1(0)
delete m_statProjects . at ( 0 ) ;
//shift the vector
m_statProjects . assign ( m_statProjects . begin ( ) + 1 , m_statProjects . end ( ) ) ;
//shift icons left
for ( int m = 0 ; m < ( int ) m_statProjects . size ( ) ; m + + ) {
2006-07-20 22:15:29 +00:00
StatImageLoader * i_statWShifting = m_statProjects . at ( m ) ;
2006-07-21 18:05:43 +00:00
wxPoint currPoint = i_statWShifting - > GetPosition ( ) ;
2006-08-10 19:32:47 +00:00
i_statWShifting - > Move ( wxPoint ( 55 + 40 * m , 37 ) ) ;
2006-07-20 22:15:29 +00:00
}
2006-07-21 18:05:43 +00:00
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
//update project count
m_projCnt = ( int ) pDoc - > state . projects . size ( ) ;
2006-07-31 13:59:21 +00:00
if ( m_rightIndex + 1 < = m_projCnt ) {
PROJECT * project = pDoc - > state . projects . at ( m_rightIndex ) ;
2006-07-21 18:05:43 +00:00
userCredit . Printf ( wxT ( " %0.2f " ) , project - > user_total_credit ) ;
toolTipTxt = wxString ( project - > project_name . c_str ( ) , wxConvUTF8 ) + wxT ( " . User " ) + wxString ( project - > user_name . c_str ( ) , wxConvUTF8 ) + wxT ( " has " ) + userCredit + wxT ( " points. " ) ;
wxToolTip * statToolTip = new wxToolTip ( toolTipTxt ) ;
2006-07-31 13:59:21 +00:00
StatImageLoader * i_statW = new StatImageLoader ( this , project - > master_url ) ;
2006-08-10 19:32:47 +00:00
i_statW - > Move ( wxPoint ( 55 + 40 * ( m_maxNumOfIcons - 1 ) , 37 ) ) ;
2006-07-21 18:05:43 +00:00
// resolve the proj image
url_to_project_dir ( ( char * ) project - > master_url . c_str ( ) , urlDirectory ) ;
dirProjectGraphic = ( std : : string ) urlDirectory + " / " + projectIconName ;
if ( boinc_resolve_filename ( dirProjectGraphic . c_str ( ) , defaultIcnPath , sizeof ( defaultIcnPath ) ) = = 0 ) {
g_statIcn = new wxImage ( defaultIcnPath , wxBITMAP_TYPE_PNG ) ;
i_statW - > LoadImage ( g_statIcn ) ;
} else {
i_statW - > LoadImage ( g_statIcnDefault ) ;
}
2006-07-20 22:15:29 +00:00
2006-07-21 18:05:43 +00:00
i_statW - > SetToolTip ( statToolTip ) ;
// push icon in the vector
m_statProjects . push_back ( i_statW ) ;
//increment left index
m_leftIndex + + ;
//increment right index
m_rightIndex + + ;
//now show left button
btnArwLeft - > Show ( true ) ;
}
//hide right arrow if we got to the end of the list
2006-07-31 13:59:21 +00:00
if ( m_rightIndex > = m_projCnt ) {
2006-07-21 18:05:43 +00:00
btnArwRight - > Show ( false ) ;
}
2006-08-10 19:32:47 +00:00
Refresh ( ) ;
2006-08-07 15:33:03 +00:00
} else if ( m_wxBtnObj = = btnAddProj ) {
pFrame - > OnProjectsAttachToProject ( ) ;
btnAddProj - > Refresh ( ) ;
} else if ( m_wxBtnObj = = btnMessages ) {
CDlgMessages * pDlg = new CDlgMessages ( NULL , appSkin - > GetSkinsFolder ( ) + _T ( " / " ) + appSkin - > GetSkinName ( ) + _T ( " / " ) ) ;
wxASSERT ( pDlg ) ;
pDlg - > ShowModal ( ) ;
pDlg - > Destroy ( ) ;
} else if ( m_wxBtnObj = = btnPause ) {
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
pDoc - > GetActivityRunMode ( clientRunMode ) ;
pDoc - > SetActivityRunMode ( RUN_MODE_NEVER ) ;
btnPause - > Show ( false ) ;
btnResume - > Show ( true ) ;
} else if ( m_wxBtnObj = = btnResume ) {
CMainDocument * pDoc = wxGetApp ( ) . GetDocument ( ) ;
pDoc - > SetActivityRunMode ( clientRunMode ) ;
btnResume - > Show ( false ) ;
btnPause - > Show ( true ) ;
} else if ( m_wxBtnObj = = btnPreferences ) {
CDlgPreferences * pDlg = new CDlgPreferences ( NULL , appSkin - > GetSkinsFolder ( ) + _T ( " / " ) + appSkin - > GetSkinName ( ) + _T ( " / " ) ) ;
wxASSERT ( pDlg ) ;
if ( pDlg - > ShowModal ( ) = = wxID_OK ) {
if ( pDlg - > GetSkinName ( ) ! = pFrame - > skinName ) {
2006-08-11 20:40:52 +00:00
wxString oldSkinName = appSkin - > GetSkinName ( ) ;
// set new skin name
2006-08-07 15:33:03 +00:00
appSkin - > SetSkinName ( pDlg - > GetSkinName ( ) ) ;
pFrame - > skinName = pDlg - > GetSkinName ( ) ;
pFrame - > skinPath = appSkin - > GetSkinsFolder ( ) + _T ( " / " ) + appSkin - > GetSkinName ( ) + _T ( " / " ) + _T ( " skin.xml " ) ;
2006-08-11 20:40:52 +00:00
//Check if skin can be loaded
if ( pFrame - > CheckSkin ( ) ) {
pFrame - > ReskinAppGUI ( ) ;
} else {
wxMessageBox ( " Incompatible skin. Skin will not be changed. " ) ;
appSkin - > SetSkinName ( oldSkinName ) ;
pFrame - > skinName = oldSkinName ;
pFrame - > skinPath = appSkin - > GetSkinsFolder ( ) + _T ( " / " ) + appSkin - > GetSkinName ( ) + _T ( " / " ) + _T ( " skin.xml " ) ;
}
2006-08-07 15:33:03 +00:00
}
}
pDlg - > Destroy ( ) ;
} else if ( m_wxBtnObj = = btnAdvancedView ) {
wxGetApp ( ) . SetActiveGUI ( BOINC_ADVANCEDGUI , true ) ;
}
}
void CProjectsComponent : : OnEraseBackground ( wxEraseEvent & event ) {
wxObject * m_wxWin = event . GetEventObject ( ) ;
if ( m_wxWin = = this ) { event . Skip ( true ) ; DrawBackImg ( event , this , * btmpComponentBg , 0 ) ; return ; }
event . Skip ( true ) ;
}
void CProjectsComponent : : DrawBackImg ( wxEraseEvent & event , wxWindow * win , wxBitmap & bitMap , int opz ) {
event . Skip ( false ) ;
wxDC * dc ;
dc = event . GetDC ( ) ;
dc - > SetBackground ( wxBrush ( win - > GetBackgroundColour ( ) , wxSOLID ) ) ;
dc - > Clear ( ) ;
switch ( opz ) {
case 0 : {
dc - > DrawBitmap ( bitMap , 0 , 0 ) ;
break ; }
case 1 : {
wxRect rec = win - > GetClientRect ( ) ;
rec . SetLeft ( ( rec . GetWidth ( ) - bitMap . GetWidth ( ) ) / 2 ) ;
rec . SetTop ( ( rec . GetHeight ( ) - bitMap . GetHeight ( ) ) / 2 ) ;
dc - > DrawBitmap ( bitMap , rec . GetLeft ( ) , rec . GetTop ( ) , 0 ) ;
break ; }
case 2 : {
wxRect rec = win - > GetClientRect ( ) ;
for ( int y = 0 ; y < rec . GetHeight ( ) ; y + = bitMap . GetHeight ( ) ) {
for ( int x = 0 ; x < rec . GetWidth ( ) ; x + = bitMap . GetWidth ( ) ) {
dc - > DrawBitmap ( bitMap , x , y , 0 ) ;
}
}
break ; }
2006-07-20 22:15:29 +00:00
}
}