-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileEditDialog.cpp
More file actions
495 lines (394 loc) · 11.5 KB
/
FileEditDialog.cpp
File metadata and controls
495 lines (394 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
// FileEditDialog.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "FileEditDialog.h"
#include "TimerShaft.h"
#include "MainFrm.h"
#include "PreView.h"
#include "MediaPlayerDialog.h"
#include "TaskListDialog.h"
#include "FilePreView.h"
#include "EditStatueFile.h"
#include "SAStatusLog.h"
#include <memory>
// CFileEditDialog dialog
extern CMainFrame* g_pMainFrame;
extern CTimeRecord g_timeRecord;
extern CSAStatusLog g_statusLog;
IMPLEMENT_DYNAMIC(CFileEditDialog, CDialog)
CFileEditDialog::CFileEditDialog(CWnd* pParent /*=NULL*/)
: CDialog(CFileEditDialog::IDD, pParent)
{
m_Duration = 0;
m_bDrawTimershaft =false;
m_nTimerShaftCount = 0;
m_nImageContainerCount = 0;
m_page = 0;
m_nScrollPos = 0;
m_hReadTimeRecrod = INVALID_HANDLE_VALUE;
m_hReadNotifyEvent = INVALID_HANDLE_VALUE;
m_hReadEvent = INVALID_HANDLE_VALUE;
}
CFileEditDialog::~CFileEditDialog()
{
TIMERSHARTLIST::iterator it = m_TimerShaftList.begin();
for (; it != m_TimerShaftList.end(); ++it)
{
if (*it)
{
delete *it;
*it = NULL;
}
}
m_TimerShaftList.clear();
m_editTaskList.clear();
if (m_hReadEvent)
{
CloseHandle(m_hReadEvent);
m_hReadEvent = INVALID_HANDLE_VALUE;
}
if (m_hReadTimeRecrod)
{
CloseHandle(m_hReadTimeRecrod);
m_hReadTimeRecrod = INVALID_HANDLE_VALUE;
}
}
void CFileEditDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CFileEditDialog, CDialog)
ON_WM_LBUTTONUP()
ON_MESSAGE(WM_DRAWTIMERSHAFT, OnDrawTimershaft)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_WM_SIZE()
ON_WM_VSCROLL()
ON_WM_CLOSE()
END_MESSAGE_MAP()
// CFileEditDialog message handlers
BOOL CFileEditDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
// CRect rc;
// GetClientRect(&rc);
//
// const SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
//
// SCROLLINFO si;
// si.cbSize = sizeof(SCROLLINFO);
// si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE;
// si.nPos = si.nMin = 1;
//
// si.nMax = sz.cy*m_page;
// si.nPage = sz.cy;
// SetScrollInfo(SB_VERT, &si, FALSE); //此函数将产生一个垂直滚动条
m_taskNameList.clear();
m_hReadTimeRecrod = (HANDLE)_beginthreadex(NULL, 0, ReadTimeRecordThd, this, 0, NULL);
m_hReadNotifyEvent = ::CreateEvent(nullptr, FALSE, FALSE, nullptr);
m_hReadEvent = ::CreateEvent(NULL, TRUE, FALSE, NULL);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CFileEditDialog::OnLButtonUp(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonUp(nFlags, point);
}
LRESULT CFileEditDialog::OnDrawTimershaft(WPARAM wParam, LPARAM lParam)
{
SetEvent(m_hReadNotifyEvent);
int nTaskId = (int)wParam;
BOOL bAdd = (BOOL)lParam;
DrawTimershaft(nTaskId, bAdd);
return 0;
}
void CFileEditDialog::DrawTimershaft(int nTaskId, BOOL bAdd)
{
if (bAdd)
{
CreateNewTimerShaft(nTaskId, m_strMp4Name, m_nTimerShaftCount);
}
else
{
m_Lock.Lock();
TIMERSHAFTMAP::iterator it = m_TimerShaftMap.begin();
for (; it != m_TimerShaftMap.end(); ++it)
{
const CString& strMp4 = it->first;
if (m_strMp4Name == strMp4)
{
CTimerShaft* pShaft = it->second;
if (pShaft && pShaft->GetSafeHwnd())
{
CRect rtRemove;
DelTimershaftMember(pShaft, rtRemove);
::PostMessage(pShaft->GetSafeHwnd(), WM_REMOVEEDITTASK, NULL, NULL);
SAFE_DELETE(pShaft);
m_TimerShaftMap.erase(it);
}
m_Lock.Unlock();
::InterlockedDecrement(&m_nTimerShaftCount);
CTaskListDialog* pTaskListDlg = g_pMainFrame->m_pFileView->GetTaskListDlg();
if (pTaskListDlg->GetDelItem() == pTaskListDlg->GetPlayItem())
{
//重绘播放界面
CMediaPlayerDialog* pPlayDlg = g_pMainFrame->m_pPreView->GetMediaPlayDlg();
if (pPlayDlg && pPlayDlg->GetSafeHwnd())
{
::PostMessage(pPlayDlg->GetSafeHwnd(), WM_RESETPLAYSTATUS, WPARAM(false), NULL);
}
}
break;
}
}
//update file
// g_timeRecord.Delete(m_nSelTaskId);
}
}
void CFileEditDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
}
void CFileEditDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CDialog::OnLButtonDown(nFlags, point);
}
bool CFileEditDialog::CreateNewTimerShaft(int nTaskId, const CString& strMp4Name, int nRef)
{
m_editTaskList.clear();
const unsigned nHeight = 100;
const unsigned nSpace = 15;
CRect rt;
GetClientRect(&rt);
rt.top += 8;
rt.left += 8;
rt.right -= 8;
rt.bottom = rt.top + nHeight;
m_strMp4Name = strMp4Name;
CTimerShaft* pShaft = new CTimerShaft(nTaskId, *this, m_Duration,
m_strMp4Name.GetBuffer(), nRef, m_taskNameList);
if (!pShaft)
{
return false;
}
m_Lock.Lock();
m_TimerShaftMap[strMp4Name] = pShaft;
m_Lock.Unlock();
rt.top += m_nTimerShaftCount*nHeight;
rt.bottom = rt.top + nHeight;
pShaft->Create(_T(""), WS_CHILD | WS_VISIBLE | SS_NOTIFY | WS_BORDER, rt,
this, TIMERSHAFT_BASE + m_nTimerShaftCount);
pShaft->SetRect(rt);
SYSTEMTIME time;
GetLocalTime(&time);
g_statusLog.StatusOut("CFileEditDialog::CreateNewTimerShaft %d:%d:%d:%d",
time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
WaitForSingleObject(m_hReadEvent, INFINITE);
GetLocalTime(&time);
g_statusLog.StatusOut("CFileEditDialog::CreateNewTimerShaft %d:%d:%d:%d",
time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
m_Lock.Lock();
EDIT_TASK_LIST::const_iterator it = m_editTaskList.begin();
for (; it != m_editTaskList.end(); ++it)
{
if ((*it)->m_nID == m_nSelTaskId)
{
pShaft->SetCuttimes((*it)->m_pCutTime, (*it)->m_nCutTimeCount);
break;
}
}
m_TimerShaftList.push_back(pShaft);
m_Lock.Unlock();
::InterlockedIncrement(&m_nTimerShaftCount);
InvalidateRect(&rt);
return true;
}
void CFileEditDialog::DelTimershaftMember(CTimerShaft* pShaft, CRect& rtRemove)
{
if (!pShaft)
{
return;
}
CRect rtPrev, rtCur;
int i = 0, j = 0;
m_Lock.Lock();
TIMERSHARTLIST::iterator it = m_TimerShaftList.begin();
for (int i = 0; i < m_TimerShaftList.size(), it != m_TimerShaftList.end(); ++i, ++it)
{
if (pShaft == m_TimerShaftList[i])
{
rtPrev = m_TimerShaftList[i]->GetRect();
for (j = i + 1; j < m_TimerShaftList.size(); ++j)
{
rtCur = m_TimerShaftList[j]->GetRect();
m_TimerShaftList[j]->SetRect(rtPrev);
m_TimerShaftList[j]->MoveWindow(&rtPrev);
rtPrev = rtCur;
}
break;
}
}
m_TimerShaftList.erase(it);
m_Lock.Unlock();
}
void CFileEditDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CFileEditDialog::ScrollClient(int nBar, int nPos)
{
static int s_prevx = 1;
static int s_prevy = 1;
int cx = 0;
int cy = 0;
int& delta = cy;
int& prev = s_prevy;
delta = prev - nPos;
prev = nPos;
if(cx || cy)
{
ScrollWindow(cx, cy, NULL, NULL);
}
}
int CFileEditDialog::GetScrollPos(int nBar, UINT nSBCode)
{
SCROLLINFO si;
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
GetScrollInfo(nBar, &si);
const int minPos = si.nMin;
const int maxPos = si.nMax - (si.nPage - 1);
int result = -1;
switch(nSBCode)
{
case SB_LINEUP /*SB_LINELEFT*/:
result = max(si.nPos - 1, minPos);
break;
case SB_LINEDOWN /*SB_LINERIGHT*/:
result = min(si.nPos + 1, maxPos);
break;
case SB_PAGEUP /*SB_PAGELEFT*/:
result = max(si.nPos - (int)si.nPage, minPos);
break;
case SB_PAGEDOWN /*SB_PAGERIGHT*/:
result = min(si.nPos + (int)si.nPage, maxPos);
break;
case SB_THUMBPOSITION:
// do nothing
break;
case SB_THUMBTRACK:
result = si.nTrackPos;
break;
case SB_TOP /*SB_LEFT*/:
result = minPos;
break;
case SB_BOTTOM /*SB_RIGHT*/:
result = maxPos;
break;
case SB_ENDSCROLL:
// do nothing
break;
}
return result;
}
void CFileEditDialog::VScrool(int nBar, UINT nSBCode)
{
const int scrollPos = GetScrollPos(nBar,nSBCode);
if(scrollPos == -1)
return;
SetScrollPos(nBar, scrollPos, TRUE);
ScrollClient(nBar, scrollPos);
}
void CFileEditDialog::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
VScrool(SB_VERT,nSBCode);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
void CFileEditDialog::Release()
{
EDIT_TASK_LIST::iterator it1 = m_editTaskList.begin();
for (; it1 != m_editTaskList.end(); ++it1)
{
delete [] (*it1)->m_pCutTime;
(*it1)->m_pCutTime = NULL;
}
TIMERSHAFTMAP::iterator it2 = m_TimerShaftMap.begin();
// for (; it2 != m_TimerShaftMap.end(); ++it2)
// {
// delete it2->second;
// it2->second = nullptr;
// }
m_TimerShaftMap.clear();
m_editTaskList.clear();
m_taskNameList.clear();
if (m_hReadEvent)
{
::CloseHandle(m_hReadEvent);
m_hReadEvent = INVALID_HANDLE_VALUE;
}
if (m_hReadNotifyEvent)
{
::CloseHandle(m_hReadNotifyEvent);
m_hReadNotifyEvent = INVALID_HANDLE_VALUE;
}
if (m_hReadTimeRecrod)
{
::CloseHandle(m_hReadTimeRecrod);
m_hReadTimeRecrod = INVALID_HANDLE_VALUE;
}
}
void CFileEditDialog::RemoveTimeShaft(const CString& strTaskName)
{
if (strTaskName.IsEmpty())
{
return;
}
m_Lock.Lock();
TIMERSHAFTMAP::iterator it = m_TimerShaftMap.find(strTaskName);
if (it != m_TimerShaftMap.end())
{
const CTimerShaft* pShaft = it->second;
::PostMessage(pShaft->GetSafeHwnd(), WM_REMOVEEDITTASK, NULL, NULL);
TIMERSHARTLIST::iterator _it = m_TimerShaftList.begin();
for (; _it != m_TimerShaftList.end(); ++_it)
{
if ((*_it) == pShaft)
{
m_TimerShaftList.erase(_it);
break;
}
}
m_TimerShaftMap.erase(it);
}
m_Lock.Unlock();
}
unsigned int __stdcall CFileEditDialog::ReadTimeRecordThd(void* pParam)
{
CFileEditDialog* pThis = (CFileEditDialog*)pParam;
SYSTEMTIME time;
GetLocalTime(&time);
g_statusLog.StatusOut("CFileEditDialog::ReadTimeRecordThd %d:%d:%d:%d",
time.wHour, time.wMinute, time.wSecond, time.wMilliseconds);
while (!theApp.IsTerminate())
{
WaitForSingleObject(pThis->m_hReadNotifyEvent, INFINITE);
g_timeRecord.Read(pThis->m_editTaskList);
SetEvent(pThis->m_hReadEvent);
}
return 0;
}
void CFileEditDialog::OnClose()
{
// TODO: Add your message handler code here and/or call default
g_statusLog.StatusOut("CFileEditDialog::OnClose()");
Release();
CDialog::OnClose();
}