1 /*****************************************************************************
4 ** Name: backgroundmgr.cpp
5 ** Purpose: Background manager class
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: February 2001
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2001 Kevin Rosenberg
12 ** $Id: backgroundmgr.cpp,v 1.2 2001/02/22 18:22:40 kevin Exp $
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
28 #include "wx/wxprec.h"
38 #include "threadrecon.h"
39 #include "backgroundmgr.h"
42 #if defined(HAVE_CONFIG_H)
47 IMPLEMENT_DYNAMIC_CLASS(BackgroundManager, wxMiniFrame)
48 BEGIN_EVENT_TABLE(BackgroundManager, wxMiniFrame)
49 EVT_CLOSE(BackgroundManager::OnCloseWindow)
52 BackgroundManager::BackgroundManager ()
53 : wxMiniFrame (theApp->getMainFrame(), -1, _T("Background Tasks"), wxPoint(0,0), wxSize(200, 100)) //, wxTHICK_FRAME)
56 m_pCanvas = new BackgroundManagerCanvas (this);
57 theApp->setIconForFrame (this);
64 BackgroundManager::OnCloseWindow (wxCloseEvent& event)
66 if (theApp->getMainFrame()->getShuttingDown())
67 wxMiniFrame::OnCloseWindow (event);
74 BackgroundManager::addTask (BackgroundTask* pTask, int iNumUnits, const char* const pszTaskName)
76 wxCriticalSectionLocker locker (m_criticalSection);
77 int iNumTasks = m_vecpBackgroundTasks.size();
80 wxPoint pos (4, 5 + iNumTasks * iTaskHeight);
82 wxGauge* pGauge = new wxGauge (m_pCanvas, -1, iNumUnits, pos, size);
83 m_vecpBackgroundTasks.push_back (pTask);
84 m_vecpGauges.push_back (pGauge);
85 m_vecpNames.push_back (new std::string (pszTaskName));
94 BackgroundManager::taskDone (BackgroundTask* pTask)
96 wxCriticalSection doneSection;
99 StringContainer::iterator iName = m_vecpNames.begin();
100 GaugeContainer::iterator iGauge = m_vecpGauges.begin();
101 for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) {
102 if (*iTask == pTask) {
105 m_vecpBackgroundTasks.erase (iTask);
106 m_vecpGauges.erase (iGauge);
107 m_vecpNames.erase (iName);
116 if (m_iNumTasks <= 0)
118 m_pCanvas->Refresh();
123 BackgroundManager::isCancelling (BackgroundTask* pTask)
130 IMPLEMENT_DYNAMIC_CLASS(BackgroundManagerCanvas, wxPanel)
131 BEGIN_EVENT_TABLE(BackgroundManagerCanvas, wxPanel)
132 EVT_PAINT(BackgroundManagerCanvas::OnPaint)
135 BackgroundManagerCanvas::BackgroundManagerCanvas (BackgroundManager* pMgr)
136 : m_pBackgroundManager(pMgr), wxPanel (pMgr)
142 BackgroundManagerCanvas::OnPaint (wxPaintEvent& event)
145 // dc.DrawLine (0, 0, 30, 30);
146 // dc.DrawLine (30,0, 0, 30);