-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilePrevDialog.cpp
More file actions
617 lines (492 loc) · 13.9 KB
/
FilePrevDialog.cpp
File metadata and controls
617 lines (492 loc) · 13.9 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
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
// FilePrevDialog.cpp : implementation file
//
#include "stdafx.h"
#include "MediaPlayer.h"
#include "FilePrevDialog.h"
#include "PreView.h"
#include "MainFrm.h"
#include "VLCPlayer.h"
#include "ProgressCtrlView.h"
#include "FileEditDialog.h"
#include "MediaPlayerDialog.h"
#include "SAStatusLog.h"
extern CmediaPlayerApp theApp;
extern CSAStatusLog g_statusLog;
// CFilePrevDialog dialog
IMPLEMENT_DYNAMIC(CFilePrevDialog, CDialog)
CFilePrevDialog::CFilePrevDialog(CWnd* pParent /*=NULL*/)
: CDialog(CFilePrevDialog::IDD, pParent),
m_strMp4Name(_T(""))
{
for (unsigned i = 0; i < MAX_EDIT_FILE_NUM; ++i)
{
m_UseFlagAry.push_back(0);
}
m_bSelect = false;
m_nCurSelMenu = -1;
m_nSelMp4 = -1;
m_nLastSelMp4 = -1;
m_bMp4Added = false;
m_pPopupMenu.reset(new CMenu);
}
CFilePrevDialog::~CFilePrevDialog()
{
m_filePathAry.clear();
m_fileNameAry.clear();
m_stFileInfoAryL.clear();
m_stFileInfoAryS.clear();
m_pPopupMenu->DestroyMenu();
}
void CFilePrevDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CFilePrevDialog, CDialog)
ON_WM_PAINT()
ON_WM_LBUTTONDOWN()
ON_MESSAGE(WM_SETFILEICON, OnSetFileIcon)
ON_WM_RBUTTONDOWN()
ON_COMMAND_RANGE(ID_ADD_MP4, ID_PREVIEW_MP4, OnMP4Operation)
ON_UPDATE_COMMAND_UI_RANGE(ID_ADD_MP4, ID_PREVIEW_MP4, OnMP4OperationUpdataUI)
ON_WM_CTLCOLOR()
ON_WM_SIZE()
ON_MESSAGE(WM_ADDMP4, OnAddMp4)
ON_MESSAGE(WM_SHOWMP4NAME, OnShowMp4Name)
END_MESSAGE_MAP()
// CFilePrevDialog message handlers
void CFilePrevDialog::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
// Do not call CDialog::OnPaint() for painting messages
if (m_nSelMp4 != -1)
{
dc.SetTextColor(RGB(0, 0, 255));
}
}
void CFilePrevDialog::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
g_statusLog.StatusOut("CFilePrevDialog::OnLButtonDown");
int nSelMp4 = -1;
if (!m_bMp4Added || (false == IsMp4Selected(point, nSelMp4)))
{
return;
}
m_nSelMp4 = nSelMp4;
CRect rt;
GetClientRect(&rt);
if (PtInRect(&rt, point))
{
InvalidateRect(&rt);
}
else
{
return;
}
CFileEditDialog* pEditDlg = NULL;
CMediaPlayerDialog* pPlayDlg = NULL;
CPreView* pView = (CPreView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd2().GetPane(0, 0));
if (pView)
{
pPlayDlg = pView->GetMediaPlayDlg();
if (pPlayDlg)
{
pPlayDlg->SetMp4Path(m_filePathAry[m_nSelMp4]);
::PostMessage(pPlayDlg->GetSafeHwnd(), WM_RESETPLAYSTATUS, NULL, NULL);
}
}
m_strMp4Name = m_filePathAry[m_nSelMp4];
if (1 == m_UseFlagAry[m_nSelMp4])
{
return;
}
else
{
m_UseFlagAry[m_nSelMp4] = 1;
}
if (m_nLastSelMp4 != m_nSelMp4)
{
CVLCPlayer::Instance()->OpenMedia(m_strMp4Name);
int64_t time = CVLCPlayer::Instance()->GetDuration(); //us
g_statusLog.StatusOut("media time len: %lf", time);
CProgressCtrlView* pView = (CProgressCtrlView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd().GetPane(0, 1));
if (pView)
{
pEditDlg = pView->GetEditDlg();
if (!pEditDlg)
{
return;
}
}
pEditDlg->SetDuration(time);
::PostMessage(pEditDlg->GetSafeHwnd(), WM_DRAWTIMERSHAFT, (WPARAM)(&m_strMp4Name), (LPARAM)TRUE);
}
if (pEditDlg)
{
pEditDlg->SetCurMp4Name(m_strMp4Name);
}
m_bSelect = true;
m_nLastSelMp4 = m_nSelMp4;
CVLCPlayer::Instance()->Stop();
CDialog::OnLButtonDown(nFlags, point);
}
BOOL CFilePrevDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CRect rt;
GetClientRect(&rt);
const unsigned nHeight = 30;
const unsigned nSpace = 10;
CRect rtText = rt;
rt.left += 5;
rt.top += 5;
rt.right = rt.left + 400;
rt.bottom = rt.top + nHeight;
rtText.top += rt.top;
rtText.left = rt.left;
rtText.right = rt.right;
rtText.bottom = rtText.top + nHeight;
//create MAX_EDIT_FILE_NUM CStatic, set icon and name
for (unsigned i = 0; i < MAX_EDIT_FILE_NUM; ++i)
{
m_FileNameCtrl[i].Create(_T(""), WS_CHILD | WS_VISIBLE | SS_LEFT |
SS_CENTERIMAGE, rtText, this, NAME_STATIC_BASE + i);
m_Mp4NameRect.push_back(rtText);
rtText.top = rtText.bottom + nSpace;
rtText.bottom = rtText.top + nHeight;
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
LRESULT CFilePrevDialog::OnSetFileIcon(WPARAM wParam, LPARAM lParam)
{
for (unsigned i = 0; i < m_fileNameAry.size(); ++i)
{
m_FileNameCtrl[i].SetWindowText(m_fileNameAry[i]);
}
return 0;
}
LRESULT CFilePrevDialog::OnShowMp4Name(WPARAM wParam, LPARAM lParam)
{
m_FileNameCtrl[static_cast<int>(wParam)].SetWindowText(m_fileNameAry[static_cast<int>(wParam)]);
return 0;
}
void CFilePrevDialog::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
//create popup menu
this->SetFocus();
if (FALSE == m_pPopupMenu->CreatePopupMenu())
{
TRACE(_T("create popupmenu failed\r\n"));
return;
}
CString str;
str.LoadString(ID_ADD_MP4);
BOOL bRet = m_pPopupMenu->AppendMenu(MF_STRING, ID_ADD_MP4, str);
str.LoadString(ID_REMOVE_MP4);
bRet = m_pPopupMenu->AppendMenu(MF_STRING, ID_REMOVE_MP4, str);
str.LoadString(ID_CLEARALL_MP4);
bRet = m_pPopupMenu->AppendMenu(MF_STRING, ID_CLEARALL_MP4, str);
str.LoadString(ID_PREVIEW_MP4);
bRet = m_pPopupMenu->AppendMenu(MF_STRING, ID_PREVIEW_MP4, str);
CPoint pt;
GetCursorPos(&pt);
m_pPopupMenu->TrackPopupMenu(TPM_RIGHTBUTTON, pt.x, pt.y, this);
m_pPopupMenu->DestroyMenu();
CDialog::OnRButtonDown(nFlags, point);
}
void CFilePrevDialog::OnMP4Operation(UINT nID)
{
// m_nCurSelMenu = nID - ID_ADD_MP4;
switch (nID)
{
case ID_ADD_MP4:
{
// AddMp4();
break;
}
case ID_REMOVE_MP4:
{
RemoveMp4();
break;
}
case ID_CLEARALL_MP4:
{
ClearAllMp4();
break;
}
default:
{
Mp4PrevView();
break;
}
}
}
void CFilePrevDialog::OnMP4OperationUpdataUI(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(m_nCurSelMenu == pCmdUI->m_nID - ID_ADD_MP4);
}
bool CFilePrevDialog::AddMp4()
{
static TCHAR BASED_CODE szFilter[] = _T("mp4 (*.mp4)|*.mp4|")_T("All Files (*.*)|*.*||");
CFileDialog dlg(TRUE, NULL, NULL,
OFN_ALLOWMULTISELECT | OFN_ENABLESIZING | OFN_HIDEREADONLY,
szFilter, this);
dlg.m_ofn.nMaxFile = 20 * MAX_PATH; //open 20 files
TCHAR* pszFile = new TCHAR[dlg.m_ofn.nMaxFile];
if (pszFile)
{
dlg.m_ofn.lpstrFile = pszFile;
ZeroMemory(dlg.m_ofn.lpstrFile, dlg.m_ofn.nMaxFile * sizeof(TCHAR));
}
CString strPath, strFileName;
SHFILEINFO stFileInfo = { 0 };
if (IDOK == dlg.DoModal())
{
//get first file positon
POSITION ps;
ps = dlg.GetStartPosition();
HICON hIconLarge = NULL, hIconSmall = NULL;
while (ps != NULL)
{
strPath = dlg.GetNextPathName(ps);
int nPos = strPath.ReverseFind(_T('\\'));
TCHAR* pPath = strPath.GetBuffer() + nPos + sizeof(TCHAR);
//get file name
while (true)
{
if (*pPath == _T('\0'))
{
break;
}
strFileName += *(pPath++);
}
strFileName += _T('\0');
//check whether add the same file
bool bSameFile = false;
if (m_filePathAry.size() != 0)
{
std::vector<CString>::iterator it = m_filePathAry.begin();
for (; it != m_filePathAry.end(); ++it)
{
if (*it == strPath)
{
bSameFile = true;
continue;
}
}
}
if (!bSameFile)
{
m_filePathAry.push_back(strPath);
m_fileNameAry.push_back(strFileName);
//get large icon and small icon
DWORD_PTR nRet = ::SHGetFileInfo(strPath, 0, &stFileInfo, sizeof(stFileInfo),
SHGFI_LARGEICON | SHGFI_OPENICON);
m_stFileInfoAryL.push_back(stFileInfo);
nRet = ::SHGetFileInfo(strPath, 0, &stFileInfo, sizeof(stFileInfo),
SHGFI_SMALLICON | SHGFI_OPENICON);
m_stFileInfoAryS.push_back(stFileInfo);
strPath.Empty();
strFileName.Empty();
}
}
PostMessage(WM_SETFILEICON);
m_bMp4Added = true;
delete [] pszFile;
pszFile = NULL;
return true;
}
delete [] pszFile;
pszFile = NULL;
return false;
}
bool CFilePrevDialog::RemoveMp4(const CPoint& pt)
{
bool bSelected = false;
int i = 0, j = 0;
std::vector<CRect>::const_iterator it1 = m_Mp4NameRect.begin();
// std::vector<CRect>::const_iterator it2 = m_IconRect.begin();
for (; it1 != m_Mp4NameRect.end(); ++it1)
{
if (PtInRect(&*it1, pt))
{
bSelected = true;
break;
}
i++;
}
if (bSelected)
{
std::vector<CString>::iterator it3 = m_fileNameAry.begin();
std::vector<CString>::iterator it4 = m_filePathAry.begin();
std::vector<SHFILEINFO>::iterator it5 = m_stFileInfoAryL.begin();
std::vector<SHFILEINFO>::iterator it6 = m_stFileInfoAryS.begin();
for (; it3 != m_fileNameAry.end(); ++it3, ++it4, ++it5, ++it6)
{
if (i == j++)
{
SendMessage(WM_UPDATAUI, WPARAM(i), LPARAM(FALSE));
CFileEditDialog* pEditDlg = ((CProgressCtrlView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd().GetPane(0, 1)))->GetEditDlg();
if (pEditDlg)
{
::SendMessage(pEditDlg->GetSafeHwnd(), WM_DRAWTIMERSHAFT, WPARAM(&m_filePathAry[i]), (LPARAM)FALSE);
}
m_fileNameAry.erase(it3);
m_filePathAry.erase(it4);
m_stFileInfoAryL.erase(it5);
m_stFileInfoAryS.erase(it6);
return true;
}
}
}
return false;
}
bool CFilePrevDialog::ClearAllMp4()
{
CVLCPlayer::Instance()->Stop();
SendMessage(WM_UPDATAUI, WPARAM(m_filePathAry.size()), LPARAM(TRUE));
for (unsigned i = 0; i < m_UseFlagAry.size(); ++i)
{
m_UseFlagAry[i] = 0;
}
m_bSelect = false;
m_nSelMp4 = -1;
m_nLastSelMp4 = -1;
m_bMp4Added = false;
m_strMp4Name.Empty();
m_fileNameAry.clear();
m_filePathAry.clear();
m_stFileInfoAryL.clear();
m_stFileInfoAryS.clear();
CFileEditDialog* pEditDlg = ((CProgressCtrlView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd().GetPane(0, 1)))->GetEditDlg();
if (pEditDlg)
{
pEditDlg->ResetTimerShaft();
}
return true;
}
bool CFilePrevDialog::Mp4PrevView(const CPoint& pt)
{
g_statusLog.StatusOut("CFilePrevDialog::Mp4PrevView");
unsigned int i = 0;
bool bSel = false;
std::vector<CRect>::const_iterator it = m_Mp4NameRect.begin();
for (i = 0; i < m_filePathAry.size(); ++i)
{
if (PtInRect(&*it++, pt))
{
bSel = true;
break;
}
}
if (false == bSel)
{
return false;
}
m_nSelMp4 = i;
m_strMp4Name = m_filePathAry[i];
CFileEditDialog* pEditDlg = NULL;
CProgressCtrlView* pView = (CProgressCtrlView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd().GetPane(0, 1));
if (pView)
{
pEditDlg = pView->GetEditDlg();
if (!pEditDlg)
{
return false;
}
}
if (pEditDlg)
{
pEditDlg->SetCurMp4Name(m_strMp4Name);
}
CRect rt;
GetClientRect(&rt);
InvalidateRect(&rt);
CDC* pDC = GetDC();
if (pDC)
{
pDC->SetTextColor(RGB(0, 0, 255));
}
//Ð޸IJ¥·Å״̬
CMediaPlayerDialog* pPlayDlg = ((CPreView*)(((CMainFrame*)theApp.GetMainWnd())->GetSplitterWnd2().GetPane(0, 0)))->GetMediaPlayDlg();
if (pPlayDlg)
{
::SendMessage(pPlayDlg->GetSafeHwnd(), WM_RESETPLAYSTATUS, WPARAM(true), NULL);
}
const CString& strFileName = m_filePathAry[i];
CVLCPlayer::Instance()->OpenMedia(strFileName);
CVLCPlayer::Instance()->Play();
return true;
}
bool CFilePrevDialog::IsMp4Selected(const CPoint& pt, int& nIndex)
{
for (unsigned i = 0; i < m_filePathAry.size(); ++i)
{
if (PtInRect(&m_Mp4NameRect[i], pt)/* || PtInRect(&m_IconRect[i], pt)*/)
{
nIndex = i;
return true;
}
}
return false;
}
HBRUSH CFilePrevDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
if (pWnd->GetDlgCtrlID() == NAME_STATIC_BASE + m_nSelMp4)
{
pDC->SetTextColor(RGB(0, 0, 255));
}
else
{
pDC->SetTextColor(RGB(0, 0, 0));
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CFilePrevDialog::OnSize(UINT nType, int cx, int cy)
{
CDialog::OnSize(nType, cx, cy);
// TODO: Add your message handler code here
}
void CFilePrevDialog::AdjustFlagAry(int nIndex)
{
m_UseFlagAry[nIndex] = 0;
}
LRESULT CFilePrevDialog::OnAddMp4(WPARAM wParam, LPARAM lParam)
{
bool bSameMp4 = false;
for (int i = 0; i < m_fileNameAry.size(); i++)
{
if (m_strMp4Name == m_fileNameAry[i])
{
bSameMp4 = true;
break;
}
}
if (m_fileNameAry.empty())
{
m_filePathAry.push_back(m_strDir + _T("\\") + m_strMp4Name);
m_fileNameAry.push_back(m_strMp4Name);
PostMessage(WM_SHOWMP4NAME, (WPARAM)0, NULL);
m_bMp4Added = true;
return 0;
}
if (!bSameMp4)
{
m_filePathAry.push_back(m_strDir + _T("\\") + m_strMp4Name);
m_fileNameAry.push_back(m_strMp4Name);
PostMessage(WM_SHOWMP4NAME, (WPARAM)(m_fileNameAry.size()-1), NULL);
m_bMp4Added = true;
}
return 0;
}
void CFilePrevDialog::UpdateUI()
{
PostMessage(WM_CTLCOLOR);
}