- int iNumTasks = m_vecpBackgroundTasks.size();
- int iTaskHeight = 20;
- wxSize size (50, 10);
- wxPoint pos (4, 5 + iNumTasks * iTaskHeight);
-
- 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));
+
+ 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, wxConvUTF8.cMB2WX(pszTaskName), posLabel, m_sizeLabel);
+ wxButton* pButton = new wxButton (m_pCanvas, s_iNextButtonID, _T("Cancel"), posButton, m_sizeButton, wxBU_LEFT);
+
+ BackgroundManagerTask* pTask = new BackgroundManagerTask (pSupervisor, pszTaskName,
+ iFirstUnusedPos, pGauge, pLabel, pButton, s_iNextButtonID);
+
+ m_vecpTasks.push_back (pTask);