Applied initial patches for wx2.8 compatibility
[ctsim.git] / src / backgroundmgr.cpp
index 6d4a50cafd2ff13479b45be2c7432ee1bab600a9..5ba1b786d08e99104791d1caad4f922c716820a5 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2001 Kevin Rosenberg
 **
-**  $Id: backgroundmgr.cpp,v 1.15 2001/03/09 21:31:51 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
@@ -67,6 +67,7 @@ BackgroundManager::BackgroundManager ()
 
   m_sizeCell.Set (m_sizeGauge.x + m_sizeLabel.x + m_sizeCellSpacing.x + m_sizeButton.x, 25);
 
+  theApp->getMainFrame()->SetFocus();
   Show(false);
 }
 
@@ -88,7 +89,7 @@ void
 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]");
@@ -97,8 +98,8 @@ BackgroundManager::OnUnitTick (wxCommandEvent& event)
 
   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);
 }
@@ -107,7 +108,7 @@ void
 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]");
@@ -117,7 +118,7 @@ BackgroundManager::OnAddTask (wxCommandEvent& event)
   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;
 
@@ -133,15 +134,15 @@ BackgroundManager::OnAddTask (wxCommandEvent& event)
       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);
+  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, 
+  BackgroundManagerTask* pTask = new BackgroundManagerTask (pSupervisor, pszTaskName,
     iFirstUnusedPos, pGauge, pLabel, pButton, s_iNextButtonID);
 
   m_vecpTasks.push_back (pTask);
@@ -150,9 +151,8 @@ BackgroundManager::OnAddTask (wxCommandEvent& event)
 
   resizeWindow();
   if (m_iNumTasks == 1) {
-       SetFocus();
-    Show(true);  
-    theApp->getMainFrame()->SetFocus();  // necessary to keep wxWindows from crashing
+    m_pCanvas->SetFocus();
+    Show(true);
   }
 }
 
@@ -170,24 +170,26 @@ BackgroundManager::OnRemoveTask (wxCommandEvent& event)
   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]");
+          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