32c32a6e0f6ce7f6f9da7ac4a76fab1f83e07ab8
[ctsim.git] / src / backgroundmgr.cpp
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          backgroundmgr.cpp
5 **   Purpose:       Background manager class
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  February 2001
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2001 Kevin Rosenberg
11 **
12 **  $Id: backgroundmgr.cpp,v 1.2 2001/02/22 18:22:40 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #include "wx/wxprec.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/wx.h"
32 #endif
33
34 #include "ct.h"
35 #include "ctsim.h"
36 #include "docs.h"
37 #include "views.h"
38 #include "threadrecon.h"
39 #include "backgroundmgr.h"
40
41
42 #if defined(HAVE_CONFIG_H)
43 #include "config.h"
44 #endif
45
46
47 IMPLEMENT_DYNAMIC_CLASS(BackgroundManager, wxMiniFrame)
48 BEGIN_EVENT_TABLE(BackgroundManager, wxMiniFrame)
49 EVT_CLOSE(BackgroundManager::OnCloseWindow)
50 END_EVENT_TABLE()
51
52 BackgroundManager::BackgroundManager ()
53   : wxMiniFrame (theApp->getMainFrame(), -1, _T("Background Tasks"), wxPoint(0,0), wxSize(200, 100)) //, wxTHICK_FRAME)
54 {
55   m_iNumTasks = 0;
56   m_pCanvas = new BackgroundManagerCanvas (this);
57   theApp->setIconForFrame (this);
58
59    Show(false);
60 }
61
62
63 void
64 BackgroundManager::OnCloseWindow (wxCloseEvent& event)
65 {
66   if (theApp->getMainFrame()->getShuttingDown())
67     wxMiniFrame::OnCloseWindow (event);
68   else
69     event.Veto();
70 }
71
72
73 wxGauge* 
74 BackgroundManager::addTask (BackgroundTask* pTask, int iNumUnits, const char* const pszTaskName)
75 {
76   wxCriticalSectionLocker locker (m_criticalSection);
77   int iNumTasks = m_vecpBackgroundTasks.size();
78   int iTaskHeight = 20;
79   wxSize size (50, 10);
80   wxPoint pos (4, 5 + iNumTasks * iTaskHeight);
81
82   wxGauge* pGauge = new wxGauge (m_pCanvas, -1, iNumUnits, pos, size);
83   m_vecpBackgroundTasks.push_back (pTask);
84   m_vecpGauges.push_back (pGauge);
85   m_vecpNames.push_back (new std::string (pszTaskName));
86   m_iNumTasks++;
87
88   Show(true);
89   return (pGauge);
90 }
91
92
93 void 
94 BackgroundManager::taskDone (BackgroundTask* pTask)
95 {
96   wxCriticalSection doneSection;
97   doneSection.Enter();
98
99   StringContainer::iterator iName = m_vecpNames.begin();
100   GaugeContainer::iterator iGauge = m_vecpGauges.begin();
101   for (TaskContainer::iterator iTask = m_vecpBackgroundTasks.begin(); iTask != m_vecpBackgroundTasks.end(); iTask++) {
102     if (*iTask == pTask) {
103       delete *iName;
104       delete *iGauge;
105       m_vecpBackgroundTasks.erase (iTask);
106       m_vecpGauges.erase (iGauge);
107       m_vecpNames.erase (iName);
108       m_iNumTasks--;
109       break;
110     }
111     iTask++;
112     iGauge++;
113   }
114
115   doneSection.Leave();
116   if (m_iNumTasks <= 0)
117     Show(false);
118   m_pCanvas->Refresh();
119   // delete pTask;
120 }
121
122 bool
123 BackgroundManager::isCancelling (BackgroundTask* pTask)
124 {
125   return false;
126 }
127
128
129
130 IMPLEMENT_DYNAMIC_CLASS(BackgroundManagerCanvas, wxPanel)
131 BEGIN_EVENT_TABLE(BackgroundManagerCanvas, wxPanel)
132 EVT_PAINT(BackgroundManagerCanvas::OnPaint)
133 END_EVENT_TABLE()
134
135 BackgroundManagerCanvas::BackgroundManagerCanvas (BackgroundManager* pMgr)
136 : m_pBackgroundManager(pMgr), wxPanel (pMgr)
137 {
138 }
139
140
141 void
142 BackgroundManagerCanvas::OnPaint (wxPaintEvent& event)
143 {
144   wxPaintDC dc (this);
145 //  dc.DrawLine (0, 0, 30, 30);
146 //  dc.DrawLine (30,0, 0, 30);
147 }