+void
+BackgroundManager::OnAddTask (wxCommandEvent& event)
+{
+ int iNumUnits = event.GetInt();
+ const char* const pszTaskName = event.GetString().c_str();
+ BackgroundSupervisor* pSupervisor = reinterpret_cast<BackgroundSupervisor*>(event.GetClientData());
+ if (pSupervisor == NULL) {
+ sys_error (ERR_SEVERE, "Received NULL supervisor [BackgroundManager::OnAddTask]");
+ return;
+ }
+
+ wxCriticalSectionLocker locker (m_criticalSection);
+
+ int iNumTasks = m_vecpTasks.size();
+ std::vector<bool> vecPositionUsed (iNumTasks); //vector of used table positions
+ for (int iP = 0; iP < iNumTasks; iP++)
+ vecPositionUsed[iP] = false;
+
+ for (TaskContainer::iterator iT = m_vecpTasks.begin(); iT != m_vecpTasks.end(); iT++) {
+ int iPosUsed = (*iT)->position();
+ if (iPosUsed < iNumTasks)
+ vecPositionUsed[iPosUsed] = true;
+ }
+
+ int iFirstUnusedPos = iNumTasks; // default is just past current number of tasks
+ for (int 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);
+ 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* pButton = NULL; // new wxButton (m_pCanvas, reinterpret_cast<wxWindowID>(pSupervisor), _T("Cancel"), posButton, m_sizeButton, wxBU_LEFT);
+
+ BackgroundManagerTask* pTask = new BackgroundManagerTask (pSupervisor, pszTaskName, iFirstUnusedPos, pGauge, pLabel, pButton);
+
+ m_vecpTasks.push_back (pTask);