X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fbackgroundmgr.cpp;h=c835b7b744565925b2c369e0daa4319273368fa1;hb=1ef49f39828474ed05fe69aff68d400e3b7d4044;hp=32c32a6e0f6ce7f6f9da7ac4a76fab1f83e07ab8;hpb=9776c9a12ba53419d34563a5ec57c90e3d6798f4;p=ctsim.git diff --git a/src/backgroundmgr.cpp b/src/backgroundmgr.cpp index 32c32a6..c835b7b 100644 --- a/src/backgroundmgr.cpp +++ b/src/backgroundmgr.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2001 Kevin Rosenberg ** -** $Id: backgroundmgr.cpp,v 1.2 2001/02/22 18:22:40 kevin Exp $ +** $Id: backgroundmgr.cpp,v 1.4 2001/02/23 18:56:56 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -50,13 +50,18 @@ EVT_CLOSE(BackgroundManager::OnCloseWindow) END_EVENT_TABLE() BackgroundManager::BackgroundManager () - : wxMiniFrame (theApp->getMainFrame(), -1, _T("Background Tasks"), wxPoint(0,0), wxSize(200, 100)) //, wxTHICK_FRAME) + : wxMiniFrame (theApp->getMainFrame(), -1, _T("Background Tasks"), wxPoint(0,0), wxSize(210, 50)) //, wxTHICK_FRAME) { m_iNumTasks = 0; m_pCanvas = new BackgroundManagerCanvas (this); theApp->setIconForFrame (this); - Show(false); + m_sizeGauge.Set (50, 15); + m_sizeLabel.Set (140, 15); + m_sizeCell.Set (200, 25); + m_sizeBorder.Set (4, 4); + + Show(false); } @@ -71,56 +76,97 @@ BackgroundManager::OnCloseWindow (wxCloseEvent& event) wxGauge* -BackgroundManager::addTask (BackgroundTask* pTask, int iNumUnits, const char* const pszTaskName) +BackgroundManager::addTask (BackgroundSupervisor* pTask, int iNumUnits, const char* const pszTaskName) { wxCriticalSectionLocker locker (m_criticalSection); int iNumTasks = m_vecpBackgroundTasks.size(); - int iTaskHeight = 20; - wxSize size (50, 10); - wxPoint pos (4, 5 + iNumTasks * iTaskHeight); + std::vector vecPositionUsed (iNumTasks); + int i; + for (i = 0; i < iNumTasks; i++) + vecPositionUsed[i] = false; + + for (i = 0; i < iNumTasks; i++) { + int iPosUsed = m_vecpPositions[i]; + if (iPosUsed < iNumTasks) + vecPositionUsed[iPosUsed] = true; + } + + int iFirstUnusedPos = iNumTasks; // default is just past current number of tasks + for (i = 0; i < iNumTasks; i++) + if (! vecPositionUsed[i]) { + iFirstUnusedPos = i; + break; + } + + wxPoint posGauge (m_sizeBorder.x, m_sizeBorder.y + iFirstUnusedPos * m_sizeCell.y); + wxPoint posLabel (m_sizeBorder.x + m_sizeGauge.x, m_sizeBorder.y + iFirstUnusedPos * m_sizeCell.y); + wxGauge* pGauge = new wxGauge (m_pCanvas, -1, iNumUnits, posGauge, m_sizeGauge); + wxStaticText* pLabel = new wxStaticText (m_pCanvas, -1, pszTaskName, posLabel, m_sizeLabel); - wxGauge* pGauge = new wxGauge (m_pCanvas, -1, iNumUnits, pos, size); m_vecpBackgroundTasks.push_back (pTask); m_vecpGauges.push_back (pGauge); m_vecpNames.push_back (new std::string (pszTaskName)); + m_vecpPositions.push_back (iFirstUnusedPos); + m_vecpLabels.push_back (pLabel); m_iNumTasks++; + resizeWindow(); Show(true); return (pGauge); } void -BackgroundManager::taskDone (BackgroundTask* pTask) +BackgroundManager::taskDone (BackgroundSupervisor* pTask) { - wxCriticalSection doneSection; - doneSection.Enter(); + wxCriticalSectionLocker locker (m_criticalSection); StringContainer::iterator iName = m_vecpNames.begin(); GaugeContainer::iterator iGauge = m_vecpGauges.begin(); + PositionContainer::iterator iPosition = m_vecpPositions.begin(); + LabelContainer::iterator iLabel = m_vecpLabels.begin(); for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) { if (*iTask == pTask) { delete *iName; delete *iGauge; + delete *iLabel; m_vecpBackgroundTasks.erase (iTask); m_vecpGauges.erase (iGauge); m_vecpNames.erase (iName); + m_vecpPositions.erase (iPosition); + m_vecpLabels.erase (iLabel); m_iNumTasks--; break; } - iTask++; + iName++; iGauge++; + iPosition++; + iLabel++; } - doneSection.Leave(); + resizeWindow(); if (m_iNumTasks <= 0) Show(false); + // delete pTask; +} + +void +BackgroundManager::resizeWindow() +{ + int iHighestPosition = -1; + + for (int i = 0; i < m_vecpPositions.size(); i++) + if (iHighestPosition < m_vecpPositions[i]) + iHighestPosition = m_vecpPositions[i]; + + wxSize sizeWindow (m_sizeCell.x, m_sizeCell.y * (iHighestPosition + 1)); + SetClientSize (sizeWindow); m_pCanvas->Refresh(); - // delete pTask; } + bool -BackgroundManager::isCancelling (BackgroundTask* pTask) +BackgroundManager::isCancelling (BackgroundSupervisor* pTask) { return false; }