diff options
author | Underground78 <underground78@users.sourceforge.net> | 2014-10-27 13:42:17 +0300 |
---|---|---|
committer | Underground78 <underground78@users.sourceforge.net> | 2014-10-31 01:05:26 +0300 |
commit | ecad25dfa94e135df8211089f7dc6a55b8809802 (patch) | |
tree | 64828336a71e280440560a9f496eea1e0a2f93ba | |
parent | 3a8c22636f2e55611d172bb07f33ec16a0902423 (diff) |
PPageFileMediaInfo: Various cosmetics.
Reduce the visibility of the member functions and variables and simplify the code.
-rw-r--r-- | src/mpc-hc/PPageFileInfoSheet.cpp | 23 | ||||
-rw-r--r-- | src/mpc-hc/PPageFileMediaInfo.cpp | 99 | ||||
-rw-r--r-- | src/mpc-hc/PPageFileMediaInfo.h | 25 |
3 files changed, 74 insertions, 73 deletions
diff --git a/src/mpc-hc/PPageFileInfoSheet.cpp b/src/mpc-hc/PPageFileInfoSheet.cpp index 3e77bdccf..673673040 100644 --- a/src/mpc-hc/PPageFileInfoSheet.cpp +++ b/src/mpc-hc/PPageFileInfoSheet.cpp @@ -92,26 +92,5 @@ BOOL CPPageFileInfoSheet::OnInitDialog() void CPPageFileInfoSheet::OnSaveAs()
{
- CString fn = m_mi.m_fn;
-
- fn.TrimRight('/');
- int i = max(fn.ReverseFind('\\'), fn.ReverseFind('/'));
- if (i >= 0 && i < fn.GetLength() - 1) {
- fn = fn.Mid(i + 1);
- }
- fn.Append(_T(".MediaInfo.txt"));
-
- CFileDialog filedlg(FALSE, _T("*.txt"), fn,
- OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR,
- _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"), this, 0);
-
- if (filedlg.DoModal() == IDOK) { // user has chosen a file, so
- TCHAR bom = (TCHAR)0xFEFF;
- CFile mFile;
- if (mFile.Open(filedlg.GetPathName(), CFile::modeCreate | CFile::modeWrite)) {
- mFile.Write(&bom, sizeof(TCHAR));
- mFile.Write(LPCTSTR(m_mi.m_futureMIText.get()), m_mi.m_futureMIText.get().GetLength()*sizeof(TCHAR));
- mFile.Close();
- }
- }
+ m_mi.OnSaveAs();
}
diff --git a/src/mpc-hc/PPageFileMediaInfo.cpp b/src/mpc-hc/PPageFileMediaInfo.cpp index de2b98ab5..02c26adf9 100644 --- a/src/mpc-hc/PPageFileMediaInfo.cpp +++ b/src/mpc-hc/PPageFileMediaInfo.cpp @@ -44,7 +44,6 @@ CPPageFileMediaInfo::CPPageFileMediaInfo(CString path, IFileSourceFilter* pFSF) : CPropertyPage(CPPageFileMediaInfo::IDD, CPPageFileMediaInfo::IDD)
, m_fn(path)
, m_path(path)
- , m_pCFont(nullptr)
{
CComQIPtr<IAsyncReader> pAR;
if (pFSF) {
@@ -126,8 +125,6 @@ CPPageFileMediaInfo::CPPageFileMediaInfo(CString path, IFileSourceFilter* pFSF) CPPageFileMediaInfo::~CPPageFileMediaInfo()
{
- delete m_pCFont;
- m_pCFont = nullptr;
}
void CPPageFileMediaInfo::DoDataExchange(CDataExchange* pDX)
@@ -136,6 +133,16 @@ void CPPageFileMediaInfo::DoDataExchange(CDataExchange* pDX) DDX_Control(pDX, IDC_MIEDIT, m_mediainfo);
}
+BOOL CPPageFileMediaInfo::PreTranslateMessage(MSG* pMsg)
+{
+ if (pMsg->message == WM_KEYDOWN && pMsg->hwnd == m_mediainfo) {
+ if (OnKeyDownInEdit(pMsg)) {
+ return TRUE;
+ }
+ }
+
+ return __super::PreTranslateMessage(pMsg);
+}
BEGIN_MESSAGE_MAP(CPPageFileMediaInfo, CPropertyPage)
ON_WM_SHOWWINDOW()
@@ -144,58 +151,34 @@ BEGIN_MESSAGE_MAP(CPPageFileMediaInfo, CPropertyPage) END_MESSAGE_MAP()
// CPPageFileMediaInfo message handlers
-static WNDPROC OldControlProc;
-
-static LRESULT CALLBACK ControlProc(HWND control, UINT message, WPARAM wParam, LPARAM lParam)
-{
- if (message == WM_KEYDOWN) {
- if ((LOWORD(wParam) == 'A' || LOWORD(wParam) == 'a')
- && (GetKeyState(VK_CONTROL) < 0)) {
- CEdit* pEdit = (CEdit*)CWnd::FromHandle(control);
- pEdit->SetSel(0, pEdit->GetWindowTextLength(), TRUE);
- return 0;
- }
- }
-
- return CallWindowProc(OldControlProc, control, message, wParam, lParam); // call edit control's own windowproc
-}
BOOL CPPageFileMediaInfo::OnInitDialog()
{
__super::OnInitDialog();
- if (!m_pCFont) {
- m_pCFont = DEBUG_NEW CFont;
- }
- if (!m_pCFont) {
- return TRUE;
- }
-
LOGFONT lf;
ZeroMemory(&lf, sizeof(lf));
lf.lfPitchAndFamily = DEFAULT_PITCH | FF_MODERN;
- // The empty string will fallback to the first font that matches the other specified attributes.
+ // The empty string will fall back to the first font that matches the other specified attributes.
LPCTSTR fonts[] = { _T("Lucida Console"), _T("Courier New"), _T("") };
// Use a negative value to match the character height instead of the cell height.
int fonts_size[] = { -10, -11, -11 };
- UINT i = 0;
- BOOL success;
+ size_t i = 0;
+ bool bSuccess;
do {
_tcscpy_s(lf.lfFaceName, fonts[i]);
lf.lfHeight = fonts_size[i];
- success = IsFontInstalled(fonts[i]) && m_pCFont->CreateFontIndirect(&lf);
+ bSuccess = IsFontInstalled(fonts[i]) && m_font.CreateFontIndirect(&lf);
i++;
- } while (!success && i < _countof(fonts));
- m_mediainfo.SetFont(m_pCFont);
+ } while (!bSuccess && i < _countof(fonts));
+ m_mediainfo.SetFont(&m_font);
+
m_mediainfo.SetWindowText(ResStr(IDS_MEDIAINFO_ANALYSIS_IN_PROGRESS));
m_threadSetText = std::thread([this]() {
m_futureMIText.wait(); // Wait for the info to be ready
PostMessage(WM_REFRESH_TEXT); // then notify the window to set the text
});
- // subclass the edit control
- OldControlProc = (WNDPROC)SetWindowLongPtr(m_mediainfo.m_hWnd, GWLP_WNDPROC, (LONG_PTR)ControlProc);
-
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
@@ -203,11 +186,8 @@ BOOL CPPageFileMediaInfo::OnInitDialog() void CPPageFileMediaInfo::OnShowWindow(BOOL bShow, UINT nStatus)
{
__super::OnShowWindow(bShow, nStatus);
- if (bShow) {
- GetParent()->GetDlgItem(IDC_BUTTON_MI)->ShowWindow(SW_SHOW);
- } else {
- GetParent()->GetDlgItem(IDC_BUTTON_MI)->ShowWindow(SW_HIDE);
- }
+
+ GetParent()->GetDlgItem(IDC_BUTTON_MI)->ShowWindow(bShow ? SW_SHOW : SW_HIDE);
}
void CPPageFileMediaInfo::OnDestroy()
@@ -222,10 +202,41 @@ void CPPageFileMediaInfo::OnRefreshText() m_mediainfo.SetWindowText(m_futureMIText.get());
}
-#if !USE_STATIC_MEDIAINFO
-bool CPPageFileMediaInfo::HasMediaInfo()
+bool CPPageFileMediaInfo::OnKeyDownInEdit(MSG* pMsg)
{
- MediaInfo MI;
- return MI.IsReady();
+ bool bHandled = false;
+
+ if ((LOWORD(pMsg->wParam) == _T('A') || LOWORD(pMsg->wParam) == _T('a'))
+ && (GetKeyState(VK_CONTROL) < 0)) {
+ m_mediainfo.SetSel(0, -1, TRUE);
+ bHandled = true;
+ }
+
+ return bHandled;
+}
+
+void CPPageFileMediaInfo::OnSaveAs()
+{
+ CString fn = m_fn;
+
+ fn.TrimRight(_T('/'));
+ int i = std::max(fn.ReverseFind(_T('\\')), fn.ReverseFind(_T('/')));
+ if (i >= 0 && i < fn.GetLength() - 1) {
+ fn = fn.Mid(i + 1);
+ }
+ fn.Append(_T(".MediaInfo.txt"));
+
+ CFileDialog fileDlg(FALSE, _T("*.txt"), fn,
+ OFN_EXPLORER | OFN_ENABLESIZING | OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR,
+ _T("Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"), this, 0);
+
+ if (fileDlg.DoModal() == IDOK) { // user has chosen a file
+ CFile file;
+ if (file.Open(fileDlg.GetPathName(), CFile::modeCreate | CFile::modeWrite)) {
+ TCHAR bom = (TCHAR)0xFEFF;
+ file.Write(&bom, sizeof(TCHAR));
+ file.Write(LPCTSTR(m_futureMIText.get()), m_futureMIText.get().GetLength() * sizeof(TCHAR));
+ file.Close();
+ }
+ }
}
-#endif
diff --git a/src/mpc-hc/PPageFileMediaInfo.h b/src/mpc-hc/PPageFileMediaInfo.h index 781da1579..e1a795804 100644 --- a/src/mpc-hc/PPageFileMediaInfo.h +++ b/src/mpc-hc/PPageFileMediaInfo.h @@ -21,6 +21,7 @@ #pragma once
#include <future>
+#include "mpc-hc_config.h"
// CPPageFileMediaInfo dialog
@@ -28,6 +29,14 @@ class CPPageFileMediaInfo : public CPropertyPage {
DECLARE_DYNAMIC(CPPageFileMediaInfo)
+private:
+ CEdit m_mediainfo;
+ CFont m_font;
+
+ CString m_fn, m_path;
+ std::shared_future<CString> m_futureMIText;
+ std::thread m_threadSetText;
+
public:
CPPageFileMediaInfo(CString path, IFileSourceFilter* pFSF);
virtual ~CPPageFileMediaInfo();
@@ -35,22 +44,22 @@ public: // Dialog Data
enum { IDD = IDD_FILEMEDIAINFO };
- CEdit m_mediainfo;
- CString m_fn, m_path;
- CFont* m_pCFont;
- std::shared_future<CString> m_futureMIText;
- std::thread m_threadSetText;
-
#if !USE_STATIC_MEDIAINFO
- static bool HasMediaInfo();
+ static bool HasMediaInfo() {
+ MediaInfo MI;
+ return MI.IsReady();
+ };
#endif
+ void OnSaveAs();
+
protected:
enum {
WM_REFRESH_TEXT = WM_APP + 1
};
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
+ virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual BOOL OnInitDialog();
DECLARE_MESSAGE_MAP()
@@ -58,4 +67,6 @@ protected: afx_msg void OnShowWindow(BOOL bShow, UINT nStatus);
afx_msg void OnDestroy();
afx_msg void OnRefreshText();
+
+ bool OnKeyDownInEdit(MSG* pMsg);
};
|