dlg_WavSrcInfo.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* PROJECT: Nero Plugin Manager Example
  10. |*
  11. |* FILE: dlg_WavSrcInfos.cpp
  12. |*
  13. |* PURPOSE: Implementation of the source info dialog.
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "dlg_WavSrcInfo.h"
  17. #include "WavSrc.h"
  18. #ifdef _DEBUG
  19. #define new DEBUG_NEW
  20. #undef THIS_FILE
  21. static char THIS_FILE[] = __FILE__;
  22. #endif
  23. extern IAudioPluginMgr* g_pPluginMgr;
  24. // CWavSrcInfoDlg
  25. CWavSrcInfoDlg::CWavSrcInfoDlg(CWavSrc* pSource)
  26. : CDialog (CWavSrcInfoDlg::IDD, NULL),
  27. m_pSource (pSource),
  28. m_bModified (0),
  29. m_iCustBtnCount (0)
  30. {
  31. if(pSource)
  32. {
  33. m_pInfo = static_cast<IAggregatable*>(pSource);
  34. ASSERT(m_pInfo);
  35. }
  36. //{{AFX_DATA_INIT(CWavSrcInfoDlg)
  37. m_csPath = _T("");
  38. m_csFileSize = _T("");
  39. m_csDateTime = _T("");
  40. m_csArtist = _T("");
  41. m_csDataFormat = _T("");
  42. m_csTitle = _T("");
  43. //}}AFX_DATA_INIT
  44. }
  45. void CWavSrcInfoDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CDialog::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CWavSrcInfoDlg)
  49. DDX_Control(pDX, IDBTN_STUB, m_btnStub);
  50. DDX_Control(pDX, IDOK, m_btnOK);
  51. DDX_Control(pDX, IDEDIT_DATA_FORMAT, m_editDataFormat);
  52. DDX_Text(pDX, IDEDIT_PATH, m_csPath);
  53. DDX_Text(pDX, IDEDIT_FILE_SIZE, m_csFileSize);
  54. DDX_Text(pDX, IDEDIT_DATETIME, m_csDateTime);
  55. DDX_Text(pDX, IDEDIT_ARTIST, m_csArtist);
  56. DDX_Text(pDX, IDEDIT_DATA_FORMAT, m_csDataFormat);
  57. DDX_Text(pDX, IDEDIT_TITLE, m_csTitle);
  58. //}}AFX_DATA_MAP
  59. }
  60. BEGIN_MESSAGE_MAP(CWavSrcInfoDlg, CDialog)
  61. //{{AFX_MSG_MAP(CWavSrcInfoDlg)
  62. ON_CBN_SELENDOK(IDCOMBO_GENRE, OnSelendokGenre)
  63. ON_EN_CHANGE(IDEDIT_ARTIST, OnChangeField)
  64. ON_EN_CHANGE(IDEDIT_DATETIME, OnChangeField)
  65. ON_EN_CHANGE(IDEDIT_TITLE, OnChangeField)
  66. ON_WM_DESTROY()
  67. //}}AFX_MSG_MAP
  68. END_MESSAGE_MAP()
  69. //#define EXTERNAL_GENRE
  70. #include "GenreStrings.inc"
  71. BOOL CWavSrcInfoDlg::OnInitDialog()
  72. {
  73. CDialog::OnInitDialog();
  74. // Obtainig the language information from the plugin manager in order to
  75. // translate this window.
  76. CComQIPtr<ILanguage> pLang = g_pPluginMgr;
  77. ASSERT(pLang);
  78. if(pLang)
  79. {
  80. m_pTranslator = CreateTranslator(IDR_PLUGIN_NLSDATA, pLang->GetLanguage());
  81. m_pTranslator->TranslateWindow(m_hWnd);
  82. }
  83. if(!(m_pSource && m_pInfo))
  84. {
  85. ASSERT(FALSE);
  86. EndDialog(IDCANCEL);
  87. return TRUE;
  88. }
  89. // file path
  90. CComQIPtr<IURLHolder> pURLHolder = m_pSource;
  91. if(pURLHolder)
  92. {
  93. m_csPath = pURLHolder->GetURL();
  94. }
  95. // file size
  96. DWORD dwSize = GetFileSize(m_pSource->GetFileHandle(), NULL);
  97. m_csFileSize.Format("%u", dwSize);
  98. for(int i = m_csFileSize.GetLength() - 3; i > 0; i -= 3)
  99. {
  100. m_csFileSize.Insert(i, ".");
  101. }
  102. // date / time
  103. CFile file;
  104. file.GetFilePath();
  105. FILETIME ft;
  106. GetFileTime(m_pSource->GetFileHandle(), NULL, NULL, &ft);
  107. CTime time(ft);
  108. m_csDateTime = time.Format("%d.%m.%Y %H:%M");
  109. // additional info values
  110. const char* szValue = NULL;
  111. CComQIPtr<IInfoReader> pInfoReader = m_pInfo;
  112. if(pInfoReader)
  113. {
  114. szValue = pInfoReader->GetArtist();
  115. if(szValue)
  116. {
  117. m_csArtist = szValue;
  118. }
  119. szValue = pInfoReader->GetTitle();
  120. if(szValue)
  121. {
  122. m_csTitle = szValue;
  123. }
  124. }
  125. // data format
  126. // 80 is the rough position of the second column
  127. m_editDataFormat.SetTabStops(80);
  128. m_csDataFormat.Format("Format:\tPCM\r\n"
  129. "Samplerate:\t%d\r\nChannels:\t%d\r\n"
  130. "BitPerSample:\t%d",
  131. m_pSource->GetWavSrcFormat().wf.nSamplesPerSec,
  132. m_pSource->GetWavSrcFormat().wf.nChannels,
  133. m_pSource->GetWavSrcFormat().wBitsPerSample);
  134. // application buttons
  135. CComPtr<ISrcInfoCallback> pCB;
  136. if(m_pInfo->GetCallback(&pCB) && pCB)
  137. {
  138. CRect rOK,
  139. rSave,
  140. rThisClient;
  141. GetClientRect(&rThisClient);
  142. m_btnOK.GetWindowRect(&rOK);
  143. m_btnStub.GetWindowRect(&rSave);
  144. ScreenToClient(&rOK);
  145. ScreenToClient(&rSave);
  146. int iDiff = rSave.top - rOK.top;
  147. m_iCustBtnCount = pCB->GetCustomControlCount();
  148. int iLastButtonBottom = 0;
  149. for(int i = 0; i < m_iCustBtnCount; i++)
  150. {
  151. CComPtr<IControl> pControl;
  152. if(!pCB->GetControl(i, &pControl) ||
  153. strcmpi(pControl->GetClassName(), "BUTTON"))
  154. continue;
  155. int iHInc = iDiff * i;
  156. CRect rNew(rOK.left, rSave.top + iHInc,
  157. rOK.right, rSave.bottom + iHInc);
  158. iLastButtonBottom = rNew.bottom;
  159. CButton* pBtn = new CButton;
  160. pBtn->Create(pControl->GetTitle(),
  161. GetWindowLong(m_btnStub.m_hWnd, GWL_STYLE),
  162. rNew, this, IDBTN_CUSTOM_FIRST +
  163. pControl->GetID());
  164. pBtn->SetFont(m_btnOK.GetFont());
  165. pBtn->ShowWindow(SW_SHOW);
  166. m_ptrarUserButtons.Add(pBtn);
  167. }
  168. // Resizind the dialog in order our new buttons to fit in it.
  169. iLastButtonBottom += (iDiff - rOK.Height());
  170. if(iLastButtonBottom > rThisClient.Height())
  171. {
  172. CRect r(0, 0, rThisClient.Width(), iLastButtonBottom);
  173. AdjustWindowRect(&r, GetWindowLong(m_hWnd, GWL_STYLE), FALSE);
  174. SetWindowPos(NULL, 0, 0, r.Width(), r.Height(),
  175. SWP_NOZORDER|SWP_NOMOVE);
  176. }
  177. }
  178. // update and validate
  179. UpdateData(FALSE);
  180. UpdateModified();
  181. return TRUE;
  182. }
  183. void CWavSrcInfoDlg::SetModified(bool b)
  184. {
  185. bool bModifiedChanged = (b == m_bModified);
  186. m_bModified = b;
  187. UpdateModified();
  188. CComPtr<ISrcInfoCallback> pCB;
  189. if(m_pSource->GetCallback(&pCB) && pCB)
  190. {
  191. pCB->OnModified(b);
  192. }
  193. }
  194. void CWavSrcInfoDlg::UpdateModified()
  195. {
  196. // m_btnSaveToID3Tag.EnableWindow(m_bModified);
  197. }
  198. void CWavSrcInfoDlg::OnChangeField()
  199. {
  200. SetModified(true);
  201. }
  202. void CWavSrcInfoDlg::OnSelendokGenre()
  203. {
  204. SetModified(true);
  205. }
  206. BOOL CWavSrcInfoDlg::OnCommand(WPARAM wParam, LPARAM lParam)
  207. {
  208. int iID = LOWORD(wParam) - IDBTN_CUSTOM_FIRST;
  209. if(iID >= 0 && iID < m_iCustBtnCount)
  210. {
  211. CComPtr<ISrcInfoCallback> pCB;
  212. if(m_pSource->GetCallback(&pCB) && pCB)
  213. {
  214. pCB->OnCustomButton(iID);
  215. }
  216. else
  217. {
  218. // this must be not NULL, otherwise where from did
  219. // we get our custom buttons?
  220. ASSERT(pCB);
  221. }
  222. return TRUE;
  223. }
  224. return CDialog::OnCommand(wParam, lParam);
  225. }
  226. // Destroys the translator after the dialog has been closed
  227. void CWavSrcInfoDlg::OnDestroy()
  228. {
  229. CDialog::OnDestroy();
  230. for(int i = 0; i < m_ptrarUserButtons.GetSize(); i++)
  231. {
  232. delete ((CButton*)m_ptrarUserButtons[i]);
  233. }
  234. DestroyTranslator(m_pTranslator);
  235. }