** This is part of the CTSim program
** Copyright (C) 1983-2001 Kevin Rosenberg
**
-** $Id: backgroundmgr.cpp,v 1.14 2001/03/09 18:50:46 kevin Exp $
+** $Id$
**
** 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
#ifdef HAVE_WXTHREADS
+int BackgroundManager::s_iNextButtonID = 0;
IMPLEMENT_DYNAMIC_CLASS(BackgroundManager, wxMiniFrame)
BEGIN_EVENT_TABLE(BackgroundManager, wxMiniFrame)
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)
+EVT_COMMAND_RANGE(0, 30000, wxEVT_COMMAND_BUTTON_CLICKED, BackgroundManager::OnCancelButton)
END_EVENT_TABLE()
m_sizeBorder.Set (4, 4);
m_sizeCellSpacing.Set (3, 3);
m_sizeButton.Set (70, 20);
- m_sizeButton.Set (0, 0);
m_sizeCell.Set (m_sizeGauge.x + m_sizeLabel.x + m_sizeCellSpacing.x + m_sizeButton.x, 25);
+ theApp->getMainFrame()->SetFocus();
Show(false);
}
BackgroundManager::OnUnitTick (wxCommandEvent& event)
{
int iUnits = event.GetInt();
-
+
BackgroundSupervisor* pSupervisor = reinterpret_cast<BackgroundSupervisor*>(event.GetClientData());
if (pSupervisor == NULL) {
sys_error (ERR_SEVERE, "Received NULL task [BackgroundManager::OnUnitTick]");
BackgroundManagerTask* pTask = lookupTask (pSupervisor);
if (pTask == NULL) {
- sys_error (ERR_SEVERE, "Error looking up task [BackgroundManager::OnUnitTick]");
- return;
+ sys_error (ERR_SEVERE, "Error looking up task [BackgroundManager::OnUnitTick]");
+ return;
}
pTask->gauge()->SetValue (iUnits);
}
BackgroundManager::OnAddTask (wxCommandEvent& event)
{
int iNumUnits = event.GetInt();
- const char* const pszTaskName = event.GetString().c_str();
+ const char* const pszTaskName = event.GetString().mb_str(wxConvUTF8);
BackgroundSupervisor* pSupervisor = reinterpret_cast<BackgroundSupervisor*>(event.GetClientData());
if (pSupervisor == NULL) {
sys_error (ERR_SEVERE, "Received NULL supervisor [BackgroundManager::OnAddTask]");
wxCriticalSectionLocker locker (m_criticalSection);
int iNumTasks = m_vecpTasks.size();
- std::vector<bool> vecPositionUsed (iNumTasks); //vector of used table positions
+ std::vector<bool> vecPositionUsed (iNumTasks); //vector of used table positions
for (int iP = 0; iP < iNumTasks; iP++)
vecPositionUsed[iP] = false;
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);
+ 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);
+ BackgroundManagerTask* pTask = new BackgroundManagerTask (pSupervisor, pszTaskName,
+ iFirstUnusedPos, pGauge, pLabel, pButton, s_iNextButtonID);
m_vecpTasks.push_back (pTask);
m_iNumTasks++;
+ s_iNextButtonID++;
resizeWindow();
if (m_iNumTasks == 1) {
- SetFocus();
- Show(true);
- theApp->getMainFrame()->SetFocus(); // necessary to keep wxWindows from crashing
+ m_pCanvas->SetFocus();
+ Show(true);
}
}
bool bFound = false;
for (TaskContainer::iterator iTask = m_vecpTasks.begin(); iTask != m_vecpTasks.end(); iTask++) {
if ((*iTask)->supervisor() == pSupervisor) {
- delete (*iTask)->gauge();
- delete (*iTask)->label();
- delete (*iTask)->button();
+ delete (*iTask)->gauge();
+ delete (*iTask)->label();
+ delete (*iTask)->button();
delete *iTask;
m_vecpTasks.erase (iTask);
m_iNumTasks--;
- bFound = true;
+ bFound = true;
break;
}
}
- if (! bFound)
- sys_error (ERR_SEVERE, "Unable to find supervisor [BackgroundManager::OnRemoveTask]");
-
+ if (! bFound) {
+ sys_error (ERR_SEVERE, "Unable to find supervisor [BackgroundManager::OnRemoveTask]");
+ return;
+ }
+ pSupervisor->ackRemoveBackgroundManager();
resizeWindow();
- if (m_iNumTasks <= 0)
+ if (m_iNumTasks <= 0) {
+ m_pCanvas->SetFocus();
Show(false);
+ }
}
void
BackgroundManager::OnCancelButton (wxCommandEvent& event)
{
+ BackgroundManagerTask* pTask = lookupTask (event.GetId());
+ if (! pTask) {
+ sys_error (ERR_SEVERE, "Unable to lookup task for button");
+ return;
+ }
+
+ pTask->supervisor()->onCancel();
}
BackgroundManagerTask*
return pTask;
}
+BackgroundManagerTask*
+BackgroundManager::lookupTask (int iButtonID)
+{
+ BackgroundManagerTask* pTask = NULL;
+
+ wxCriticalSectionLocker locker (m_criticalSection);
+ for (TaskContainer::iterator iTask = m_vecpTasks.begin(); iTask != m_vecpTasks.end(); iTask++) {
+ if ((*iTask)->buttonID() == iButtonID) {
+ pTask = *iTask;
+ break;
+ }
+ }
+
+ return pTask;
+}
+
void
BackgroundManager::resizeWindow()
{