summaryrefslogtreecommitdiffabout
path: root/ActivityView.cpp
Unidiff
Diffstat (limited to 'ActivityView.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--ActivityView.cpp297
1 files changed, 297 insertions, 0 deletions
diff --git a/ActivityView.cpp b/ActivityView.cpp
new file mode 100644
index 0000000..664b3d4
--- a/dev/null
+++ b/ActivityView.cpp
@@ -0,0 +1,297 @@
1// ActivityView.cpp : implementation file
2//
3
4#include "stdafx.h"
5#include "BigBrother.h"
6#include "ActivityView.h"
7
8#include "BigBrotherDoc.h"
9
10#ifdef _DEBUG
11#define new DEBUG_NEW
12#undef THIS_FILE
13static char THIS_FILE[] = __FILE__;
14#endif
15
16/////////////////////////////////////////////////////////////////////////////
17// CActivityView
18
19IMPLEMENT_DYNCREATE(CActivityView, CScrollView)
20
21CActivityView::CActivityView()
22{
23 m_Background = GetSysColor(COLOR_MENU);
24 //RGB(128,255,128);
25 m_BoxColor = RGB(192,255,255);
26 m_Red = RGB(255,0,0);
27 m_Green = RGB(0,192,0);
28 m_Yellow = RGB(255,255,0);
29 m_Dim = RGB(192,192,192);
30 m_Brothers = new CBrotherList;
31}
32
33CActivityView::~CActivityView()
34{
35 delete m_Brothers;
36}
37
38
39BEGIN_MESSAGE_MAP(CActivityView, CScrollView)
40 //{{AFX_MSG_MAP(CActivityView)
41 ON_WM_ERASEBKGND()
42 ON_WM_CREATE()
43 ON_WM_MOUSEMOVE()
44 ON_WM_LBUTTONDOWN()
45 ON_WM_LBUTTONUP()
46 ON_WM_SIZE()
47 //}}AFX_MSG_MAP
48END_MESSAGE_MAP()
49
50/////////////////////////////////////////////////////////////////////////////
51// CActivityView drawing
52
53void CActivityView::OnInitialUpdate()
54{
55 CScrollView::OnInitialUpdate();
56
57 OnUpdate(NULL,0,NULL);
58}
59
60void CActivityView::OnDraw(CDC* pDC)
61{
62CBigBrotherDoc* pDoc = (CBigBrotherDoc*)GetDocument();
63 if(!pDoc)
64 return;
65 ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CBigBrotherDoc)));
66 if(m_Brothers->IsEmpty())
67 return;
68BOOL bt = FALSE, et=FALSE;
69BOOL isAny = FALSE;
70CTime beginTime, endTime;
71POSITION p = m_Brothers->GetHeadPosition();
72 while(p){
73 CBrother *b = m_Brothers->GetNext(p);
74 ASSERT(b);
75 if(b->m_Log.IsEmpty())
76 continue;
77 isAny=TRUE;
78 if((!bt) || b->m_Log.GetHead()->m_Time<beginTime){
79 bt=TRUE;
80 beginTime=b->m_Log.GetHead()->m_Time;
81 }
82 if((!et) || b->m_Log.GetTail()->m_Time>endTime){
83 et=TRUE;
84 endTime=b->m_Log.GetTail()->m_Time;
85 }
86 }
87 if(!isAny){
88 m_bPainted=FALSE;
89 return;
90 }
91 m_bPainted=TRUE;
92CTimeSpan ts = endTime-beginTime;
93 if(ts<pDoc->m_MaxLogTime)
94 ts = pDoc->m_MaxLogTime;
95 m_BeginTime=beginTime;
96 m_TimeSpan=ts;
97 p = m_Brothers->GetHeadPosition();
98int host = 0;
99 while(p){
100 CBrother *b = m_Brothers->GetNext(p);
101 ASSERT(b);
102 CRect rc(10,20+host*105,10+500,20+host*105+100);
103 pDC->FillSolidRect(rc,m_BoxColor);
104 PaintHost(b,pDC,rc,&beginTime,&ts);
105 host++;
106 }
107}
108
109/////////////////////////////////////////////////////////////////////////////
110// CActivityView diagnostics
111
112#ifdef _DEBUG
113void CActivityView::AssertValid() const
114{
115 CScrollView::AssertValid();
116}
117
118void CActivityView::Dump(CDumpContext& dc) const
119{
120 CScrollView::Dump(dc);
121}
122#endif //_DEBUG
123
124/////////////////////////////////////////////////////////////////////////////
125// CActivityView message handlers
126
127void CActivityView::PaintHost(CBrother *b,CDC *pDC,CRect& rc,CTime *bTime,CTimeSpan *tSpan)
128{
129 ASSERT(b);
130 if(b->m_Log.IsEmpty())
131 return;
132CBigBrotherDoc* pDoc = (CBigBrotherDoc*)GetDocument();
133 ASSERT(pDoc);
134 ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CBigBrotherDoc)));
135 ULONGrttMax = b->m_TimeOut;
136CTime beginTime;
137CTimeSpan ts;
138 if(bTime && tSpan){
139 beginTime= *bTime;
140 ts = *tSpan;
141 }else{
142 beginTime = b->m_Log.GetHead()->m_Time;
143 CTime endTime = b->m_Log.GetTail()->m_Time;
144 ts = endTime-beginTime;
145 if(ts<pDoc->m_MaxLogTime)
146 ts = pDoc->m_MaxLogTime;
147 }
148 POSITIONp = b->m_Log.GetHeadPosition();
149 ASSERT(p);
150CLogEntry *le = b->m_Log.GetNext(p);
151 ASSERT(le);
152 intx = rc.left+(le->m_Time-beginTime).GetTotalSeconds()*rc.Width()/ts.GetTotalSeconds();
153 while(p){
154 le = b->m_Log.GetNext(p);
155 ASSERT(le);
156 int newx=rc.left+(le->m_Time-beginTime).GetTotalSeconds()*rc.Width()/ts.GetTotalSeconds();
157 if(!(le->flags&CLogEntry::flagsSeparator)){
158 UINTsize = le->m_bReached?min(rttMax,le->m_RTT):rttMax;
159 intdrawSize=(rttMax-size)*rc.Height()/rttMax;
160 COLORREF color=le->m_bReached?((size<(rttMax/3))?m_Green:((size<(rttMax*2/3))?m_Yellow:m_Red)):m_Dim;
161 pDC->FillSolidRect(x,rc.bottom-drawSize,newx-x,drawSize,color);
162 }
163 x=newx;
164 }
165}
166
167void CActivityView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
168{
169CBigBrotherDoc* pDoc = (CBigBrotherDoc*)GetDocument();
170 if(!pDoc)
171 return;
172 ASSERT(pDoc->IsKindOf(RUNTIME_CLASS(CBigBrotherDoc)));
173 if(pHint){
174 CBrother *b = (CBrother*)pHint;
175 if(m_Brothers->Find(b)){
176 CClientDC dc(this);
177 OnPrepareDC(&dc);
178 CRect rc = b->m_rc;
179 dc.LPtoDP(&rc);
180 InvalidateRect(rc,FALSE);
181 }
182 return;
183 }
184 m_Brothers->RemoveAll();
185CBrother *b = pDoc->GetCurrentBrother();
186 if(b)
187 pDoc->GetFamily(b,m_Brothers);
188 SetScaleToFitSize(CSize(10+500+10,20+m_Brothers->GetCount()*105+20));
189POSITION p = m_Brothers->GetHeadPosition();
190int host = 0;
191 while(p){
192 CBrother *b = m_Brothers->GetNext(p);
193 b->m_rc.SetRect(10,20+host*105,10+500,20+host*105+100);
194 host++;
195 }
196 CScrollView::OnUpdate(pSender,lHint,pHint);
197}
198
199BOOL CActivityView::OnEraseBkgnd(CDC* pDC)
200{
201CRect rc;
202 GetClientRect(rc);
203 pDC->FillSolidRect(rc,m_Background);
204 return TRUE;
205}
206
207int CActivityView::OnCreate(LPCREATESTRUCT lpCreateStruct)
208{
209 if (CScrollView::OnCreate(lpCreateStruct) == -1)
210 return -1;
211
212 m_ToolTip.Create(this);
213 m_ToolTip.Activate(TRUE);
214 m_ToolTip.AddTool(this,IDS_AVIEW_NOTIP);
215
216 return 0;
217}
218
219BOOL CActivityView::PreTranslateMessage(MSG* pMsg)
220{
221 m_ToolTip.RelayEvent(pMsg);
222 return CScrollView::PreTranslateMessage(pMsg);
223}
224
225void CActivityView::OnMouseMove(UINT nFlags, CPoint point)
226{
227 UpdateTip(nFlags,point);
228 CScrollView::OnMouseMove(nFlags, point);
229}
230
231void CActivityView::UpdateTip(UINT nFlags,CPoint point)
232{
233CClientDC dc(this);
234 OnPrepareDC(&dc);
235 dc.DPtoLP(&point);
236POSITION p = m_Brothers->GetHeadPosition();
237 while(p){
238 CBrother *b = m_Brothers->GetNext(p);
239 if(b->m_rc.PtInRect(point)){
240 CString tmp;
241 tmp.Format(IDS_AVIEW_SHORTTIP,(LPCTSTR)b->m_Desc,(LPCTSTR)b->m_Host);
242 if(m_bPainted && (nFlags&(MK_LBUTTON|MK_CONTROL|MK_SHIFT))){
243 CTime theTime = m_BeginTime + CTimeSpan((point.x-b->m_rc.left)*m_TimeSpan.GetTotalSeconds()/b->m_rc.Width());
244 if(nFlags&(MK_LBUTTON|MK_CONTROL)){
245 // Add Time
246 tmp += ", "+theTime.Format(IDS_AVIEW_TIP_TIMEFORMAT);
247 }
248 if(nFlags&MK_SHIFT){
249 // Add RTT report
250 CLogEntry *le = NULL;
251 POSITION p = b->m_Log.GetTailPosition();
252 while(p){
253 CLogEntry *l = b->m_Log.GetPrev(p);
254 if(theTime<l->m_Time)
255 le = l;
256 else
257 break;
258 }
259 CString ttmp;
260 if(le){
261 if(le->m_bReached)
262 ttmp.Format(IDS_AVIEW_TIP_RTTREPORT, le->m_RTT);
263 else
264 ttmp.LoadString(IDS_AVIEW_TIP_UNREACHABLE);
265 }else
266 ttmp.LoadString(IDS_AVIEW_TIP_UNPINGED);
267 tmp += ", "+ttmp;
268 }
269 }
270 m_ToolTip.Activate(TRUE);
271 m_ToolTip.UpdateTipText(tmp,this);
272 return;
273 }
274 }
275 m_ToolTip.Activate(FALSE);
276 m_ToolTip.UpdateTipText(IDS_AVIEW_NOTIP,this);
277}
278
279void CActivityView::OnLButtonDown(UINT nFlags, CPoint point)
280{
281 UpdateTip(nFlags,point);
282 CScrollView::OnLButtonDown(nFlags, point);
283}
284
285void CActivityView::OnLButtonUp(UINT nFlags, CPoint point)
286{
287 UpdateTip(nFlags,point);
288 CScrollView::OnLButtonUp(nFlags, point);
289}
290
291void CActivityView::OnSize(UINT nType, int cx, int cy)
292{
293 CScrollView::OnSize(nType, cx, cy);
294CDocument *pDoc = GetDocument();
295 ASSERT(pDoc);
296 pDoc->UpdateAllViews(NULL);
297}