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.3 2001/02/23 02:06:02 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(210, 50)) //, wxTHICK_FRAME)
56 m_pCanvas = new BackgroundManagerCanvas (this);
57 theApp->setIconForFrame (this);
59 m_sizeGauge.Set (50, 15);
60 m_sizeLabel.Set (140, 15);
61 m_sizeCell.Set (200, 25);
62 m_sizeBorder.Set (4, 4);
69 BackgroundManager::OnCloseWindow (wxCloseEvent& event)
71 if (theApp->getMainFrame()->getShuttingDown())
72 wxMiniFrame::OnCloseWindow (event);
79 BackgroundManager::addTask (BackgroundTask* pTask, int iNumUnits, const char* const pszTaskName)
81 wxCriticalSectionLocker locker (m_criticalSection);
82 int iNumTasks = m_vecpBackgroundTasks.size();
83 std::vector<bool> vecPositionUsed (iNumTasks);
85 for (i = 0; i < iNumTasks; i++)
86 vecPositionUsed[i] = false;
88 for (i = 0; i < iNumTasks; i++) {
89 int iPosUsed = m_vecpPositions[i];
90 if (iPosUsed < iNumTasks)
91 vecPositionUsed[iPosUsed] = true;
94 int iFirstUnusedPos = iNumTasks; // default is just past current number of tasks
95 for (i = 0; i < iNumTasks; i++)
96 if (! vecPositionUsed[i]) {
101 wxPoint posGauge (m_sizeBorder.x, m_sizeBorder.y + iFirstUnusedPos * m_sizeCell.y);
102 wxPoint posLabel (m_sizeBorder.x + m_sizeGauge.x, m_sizeBorder.y + iFirstUnusedPos * m_sizeCell.y);
103 wxGauge* pGauge = new wxGauge (m_pCanvas, -1, iNumUnits, posGauge, m_sizeGauge);
104 wxStaticText* pLabel = new wxStaticText (m_pCanvas, -1, pszTaskName, posLabel, m_sizeLabel);
106 m_vecpBackgroundTasks.push_back (pTask);
107 m_vecpGauges.push_back (pGauge);
108 m_vecpNames.push_back (new std::string (pszTaskName));
109 m_vecpPositions.push_back (iFirstUnusedPos);
110 m_vecpLabels.push_back (pLabel);
120 BackgroundManager::taskDone (BackgroundTask* pTask)
122 wxCriticalSectionLocker locker (m_criticalSection);
124 StringContainer::iterator iName = m_vecpNames.begin();
125 GaugeContainer::iterator iGauge = m_vecpGauges.begin();
126 PositionContainer::iterator iPosition = m_vecpPositions.begin();
127 LabelContainer::iterator iLabel = m_vecpLabels.begin();
128 for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) {
129 if (*iTask == pTask) {
133 m_vecpBackgroundTasks.erase (iTask);
134 m_vecpGauges.erase (iGauge);
135 m_vecpNames.erase (iName);
136 m_vecpPositions.erase (iPosition);
137 m_vecpLabels.erase (iLabel);
148 if (m_iNumTasks <= 0)
154 BackgroundManager::resizeWindow()
156 int iHighestPosition = -1;
158 for (int i = 0; i < m_vecpPositions.size(); i++)
159 if (iHighestPosition < m_vecpPositions[i])
160 iHighestPosition = m_vecpPositions[i];
162 wxSize sizeWindow (m_sizeCell.x, m_sizeCell.y * (iHighestPosition + 1));
163 SetClientSize (sizeWindow);
164 m_pCanvas->Refresh();
169 BackgroundManager::isCancelling (BackgroundTask* pTask)
176 IMPLEMENT_DYNAMIC_CLASS(BackgroundManagerCanvas, wxPanel)
177 BEGIN_EVENT_TABLE(BackgroundManagerCanvas, wxPanel)
178 EVT_PAINT(BackgroundManagerCanvas::OnPaint)
181 BackgroundManagerCanvas::BackgroundManagerCanvas (BackgroundManager* pMgr)
182 : m_pBackgroundManager(pMgr), wxPanel (pMgr)
188 BackgroundManagerCanvas::OnPaint (wxPaintEvent& event)
191 // dc.DrawLine (0, 0, 30, 30);
192 // dc.DrawLine (30,0, 0, 30);