X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fbackgroundmgr.cpp;h=ee789deb155b0128914c7f259a24c42b9c8cda9e;hp=c835b7b744565925b2c369e0daa4319273368fa1;hb=6480e936da257519dd36840862ac995ca8c374da;hpb=1ef49f39828474ed05fe69aff68d400e3b7d4044 diff --git a/src/backgroundmgr.cpp b/src/backgroundmgr.cpp index c835b7b..ee789de 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.4 2001/02/23 18:56:56 kevin Exp $ +** $Id: backgroundmgr.cpp,v 1.5 2001/02/23 21:58:31 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 @@ -46,7 +46,11 @@ IMPLEMENT_DYNAMIC_CLASS(BackgroundManager, wxMiniFrame) BEGIN_EVENT_TABLE(BackgroundManager, wxMiniFrame) +EVT_MENU(BackgroundSupervisor::MSG_BACKGROUND_SUPERVISOR_ADD, BackgroundManager::OnAddTask) +EVT_MENU(BackgroundSupervisor::MSG_BACKGROUND_SUPERVISOR_REMOVE, BackgroundManager::OnRemoveTask) +EVT_MENU(BackgroundSupervisor::MSG_BACKGROUND_SUPERVISOR_UNIT_TICK, BackgroundManager::OnUnitTick) EVT_CLOSE(BackgroundManager::OnCloseWindow) +EVT_COMMAND_RANGE(0, 1000, wxEVT_COMMAND_BUTTON_CLICKED, BackgroundManager::OnCancelButton) END_EVENT_TABLE() BackgroundManager::BackgroundManager () @@ -56,11 +60,14 @@ BackgroundManager::BackgroundManager () m_pCanvas = new BackgroundManagerCanvas (this); theApp->setIconForFrame (this); - m_sizeGauge.Set (50, 15); - m_sizeLabel.Set (140, 15); - m_sizeCell.Set (200, 25); + m_sizeGauge.Set (70, 20); + m_sizeLabel.Set (140, 20); m_sizeBorder.Set (4, 4); + m_sizeCellSpacing.Set (3, 3); + m_sizeButton.Set (70, 20); + m_sizeCell.Set (m_sizeGauge.x + m_sizeLabel.x + m_sizeCellSpacing.x + m_sizeButton.x, 25); + Show(false); } @@ -74,10 +81,30 @@ BackgroundManager::OnCloseWindow (wxCloseEvent& event) event.Veto(); } +void +BackgroundManager::OnUnitTick (wxCommandEvent& event) +{ + int iUnits = event.GetInt(); + BackgroundSupervisor* pTask = reinterpret_cast(event.GetClientData()); + if (pTask == NULL) { + sys_error (ERR_SEVERE, "Received NULL task [BackgroundManager::OnAddTask]"); + return; + } + if (wxGauge* pGauge = lookupGauge (pTask)) + pGauge->SetValue (iUnits); +} -wxGauge* -BackgroundManager::addTask (BackgroundSupervisor* pTask, int iNumUnits, const char* const pszTaskName) +void +BackgroundManager::OnAddTask (wxCommandEvent& event) { + int iNumUnits = event.GetInt(); + const char* const pszTaskName = event.GetString().c_str(); + BackgroundSupervisor* pTask = reinterpret_cast(event.GetClientData()); + if (pTask == NULL) { + sys_error (ERR_SEVERE, "Received NULL task [BackgroundManager::OnAddTask]"); + return; + } + wxCriticalSectionLocker locker (m_criticalSection); int iNumTasks = m_vecpBackgroundTasks.size(); std::vector vecPositionUsed (iNumTasks); @@ -100,41 +127,51 @@ BackgroundManager::addTask (BackgroundSupervisor* pTask, int iNumUnits, const ch 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); + wxPoint posButton (m_sizeBorder.x + m_sizeGauge.x + m_sizeLabel.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); + wxButton* pCancelButton = new wxButton (m_pCanvas, iFirstUnusedPos, _T("Cancel"), posButton, m_sizeButton, wxBU_LEFT); 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_vecpCancelButtons.push_back (pCancelButton); m_iNumTasks++; resizeWindow(); Show(true); - return (pGauge); } - -void -BackgroundManager::taskDone (BackgroundSupervisor* pTask) +void +BackgroundManager::OnRemoveTask (wxCommandEvent& event) { + BackgroundSupervisor* pTask = reinterpret_cast(event.GetClientData()); + if (pTask == NULL) { + sys_error (ERR_SEVERE, "Received NULL task [BackgroundManager::OnAddTask]"); + return; + } + 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(); + ButtonContainer::iterator iCancelButton = m_vecpCancelButtons.begin(); for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) { if (*iTask == pTask) { delete *iName; delete *iGauge; delete *iLabel; + delete *iCancelButton; m_vecpBackgroundTasks.erase (iTask); m_vecpGauges.erase (iGauge); m_vecpNames.erase (iName); m_vecpPositions.erase (iPosition); m_vecpLabels.erase (iLabel); + m_vecpCancelButtons.erase (iCancelButton); m_iNumTasks--; break; } @@ -142,12 +179,33 @@ BackgroundManager::taskDone (BackgroundSupervisor* pTask) iGauge++; iPosition++; iLabel++; + iCancelButton++; } resizeWindow(); if (m_iNumTasks <= 0) Show(false); - // delete pTask; +} + +void +BackgroundManager::OnCancelButton (wxCommandEvent& event) +{ +} + +wxGauge* +BackgroundManager::lookupGauge (BackgroundSupervisor* pTask) +{ + wxGauge* pGauge = NULL; + int i = 0; + for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) { + if (*iTask == pTask) { + pGauge = m_vecpGauges[i]; + break; + } + i++; + } + + return pGauge; } void @@ -165,13 +223,6 @@ BackgroundManager::resizeWindow() } -bool -BackgroundManager::isCancelling (BackgroundSupervisor* pTask) -{ - return false; -} - - IMPLEMENT_DYNAMIC_CLASS(BackgroundManagerCanvas, wxPanel) BEGIN_EVENT_TABLE(BackgroundManagerCanvas, wxPanel)