InfoDialog.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #include "MKVInfo.h"
  2. #include "api__in_mkv.h"
  3. #include "../nu/ListView.h"
  4. #include "../nu/AutoWide.h"
  5. #include "resource.h"
  6. #include "main.h"
  7. #include <strsafe.h>
  8. enum
  9. {
  10. COLUMN_TRACK_TYPE = 0,
  11. COLUMN_CODEC_NAME = 1,
  12. COLUMN_CODEC_ID = 2,
  13. COLUMN_DESCRIPTION = 3,
  14. COLUMN_STREAM_NAME = 4,
  15. COLUMN_LANGUAGE = 5,
  16. };
  17. #if 0
  18. static INT_PTR CALLBACK InfoDialog_Metadata(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  19. {
  20. switch (uMsg)
  21. {
  22. case WM_INITDIALOG:
  23. {
  24. nsavi::Metadata *metadata = (nsavi::Metadata *)lParam;
  25. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,lParam);
  26. W_ListView list_view(hwndDlg, IDC_TRACKLIST);
  27. list_view.AddCol(L"Field", 100);
  28. list_view.AddCol(L"FOURCC", 75);
  29. list_view.AddCol(L"Value", 250);
  30. nsavi::Info *info;
  31. if (metadata->GetInfo(&info) == nsavi::READ_OK)
  32. {
  33. int n=0;
  34. for (nsavi::Info::const_iterator itr = info->begin();itr!=info->end();itr++)
  35. {
  36. const wchar_t *field_name = FindKnownName(known_fields, sizeof(known_fields)/sizeof(known_fields[0]), itr->first);
  37. wchar_t fourcc[5] = {0};
  38. MakeStringFromFOURCC(fourcc, itr->first);
  39. if (field_name)
  40. n= list_view.AppendItem(field_name, 0);
  41. else
  42. n= list_view.AppendItem(fourcc, 0);
  43. list_view.SetItemText(n, 1, fourcc);
  44. list_view.SetItemText(n, 2, AutoWide(itr->second, CP_UTF8));
  45. }
  46. }
  47. }
  48. return 1;
  49. }
  50. return 0;
  51. }
  52. #endif
  53. static INT_PTR CALLBACK InfoDialog_Tracks(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  54. {
  55. switch (uMsg)
  56. {
  57. case WM_INITDIALOG:
  58. {
  59. MKVInfo *metadata = (MKVInfo *)lParam;
  60. SetWindowLongPtr(hwndDlg,GWLP_USERDATA,lParam);
  61. W_ListView list_view(hwndDlg, IDC_TRACKLIST);
  62. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_TRACK_TYPE), 100);
  63. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_CODEC_NAME), 100);
  64. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_CODEC_ID), 75);
  65. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_DESCRIPTION), 100);
  66. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_STREAM_NAME), 100);
  67. list_view.AddCol(WASABI_API_LNGSTRINGW(IDS_COLUMN_LANGUAGE), 50);
  68. const nsmkv::Tracks *tracks = metadata->GetTracks();
  69. if (tracks)
  70. {
  71. const nsmkv::TrackEntry *track_entry;
  72. size_t i=0;
  73. while (track_entry = tracks->EnumTrack(i++))
  74. {
  75. int n;
  76. switch(track_entry->track_type)
  77. {
  78. case mkv_track_type_audio:
  79. {
  80. n = list_view.AppendItem(WASABI_API_LNGSTRINGW(IDS_TYPE_AUDIO), 0);
  81. }
  82. break;
  83. case mkv_track_type_video:
  84. {
  85. n = list_view.AppendItem(WASABI_API_LNGSTRINGW(IDS_TYPE_VIDEO), 0);
  86. }
  87. break;
  88. case mkv_track_type_subtitle:
  89. {
  90. n = list_view.AppendItem(WASABI_API_LNGSTRINGW(IDS_TYPE_SUBTITLE), 0);
  91. }
  92. break;
  93. default:
  94. {
  95. wchar_t track_type[64] = {0};
  96. StringCchPrintf(track_type, 64, L"%X", track_entry->track_type);
  97. n = list_view.AppendItem(track_type, 0);
  98. }
  99. break;
  100. }
  101. if (track_entry->codec_id)
  102. list_view.SetItemText(n, COLUMN_CODEC_ID, AutoWide(track_entry->codec_id, CP_UTF8));
  103. if (track_entry->codec_name)
  104. {
  105. list_view.SetItemText(n, COLUMN_CODEC_NAME, AutoWide(track_entry->codec_name, CP_UTF8));
  106. }
  107. else
  108. {
  109. // TODO: enumerate through a list of known codecs
  110. if (track_entry->codec_id)
  111. list_view.SetItemText(n, COLUMN_CODEC_NAME, AutoWide(track_entry->codec_id, CP_UTF8));
  112. }
  113. if (track_entry->name)
  114. {
  115. list_view.SetItemText(n, COLUMN_STREAM_NAME, AutoWide(track_entry->name, CP_UTF8));
  116. }
  117. if (track_entry->language && stricmp(track_entry->language, "und"))
  118. {
  119. list_view.SetItemText(n, COLUMN_LANGUAGE, AutoWide(track_entry->language, CP_UTF8));
  120. }
  121. }
  122. }
  123. }
  124. return 1;
  125. case WM_SIZE:
  126. {
  127. RECT r;
  128. GetClientRect(hwndDlg, &r);
  129. SetWindowPos(GetDlgItem(hwndDlg, IDC_TRACKLIST), HWND_TOP, r.left, r.top, r.right, r.bottom, SWP_NOACTIVATE);
  130. }
  131. break;
  132. }
  133. return 0;
  134. }
  135. struct InfoDialogContext
  136. {
  137. MKVInfo *metadata;
  138. HWND active_tab;
  139. };
  140. static VOID WINAPI OnSelChanged(HWND hwndDlg, HWND hwndTab, InfoDialogContext *context)
  141. {
  142. if (context->active_tab)
  143. {
  144. DestroyWindow(context->active_tab);
  145. }
  146. int selection = TabCtrl_GetCurSel(hwndTab);
  147. switch(selection)
  148. {
  149. case 0:
  150. context->active_tab = WASABI_API_CREATEDIALOGPARAMW(IDD_TRACKS, hwndDlg, InfoDialog_Tracks, (LPARAM)context->metadata);
  151. break;
  152. case 1:
  153. // context->active_tab = WASABI_API_CREATEDIALOGPARAMW(IDD_TRACKS, hwndDlg, InfoDialog_Metadata, (LPARAM)context->metadata);
  154. break;
  155. }
  156. RECT r;
  157. GetWindowRect(hwndTab,&r);
  158. TabCtrl_AdjustRect(hwndTab,FALSE,&r);
  159. MapWindowPoints(NULL,hwndDlg,(LPPOINT)&r,2);
  160. SetWindowPos(context->active_tab,HWND_TOP,r.left,r.top,r.right-r.left,r.bottom-r.top,SWP_NOACTIVATE);
  161. ShowWindow(context->active_tab, SW_SHOWNA);
  162. if (GetFocus() != hwndTab)
  163. {
  164. SetFocus(context->active_tab);
  165. }
  166. }
  167. INT_PTR CALLBACK InfoDialog(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  168. {
  169. switch (uMsg)
  170. {
  171. case WM_INITDIALOG:
  172. {
  173. HWND hwndTab = GetDlgItem(hwndDlg,IDC_TAB1);
  174. InfoDialogContext *context = (InfoDialogContext *)calloc(1, sizeof(InfoDialogContext));
  175. context->metadata = (MKVInfo *)lParam;
  176. context->active_tab = 0;
  177. SetWindowLongPtr(hwndDlg,GWLP_USERDATA, (LPARAM)context);
  178. TCITEMW tie;
  179. tie.mask = TCIF_TEXT;
  180. tie.pszText = WASABI_API_LNGSTRINGW(IDS_TAB_TRACKS);
  181. SendMessageW(hwndTab, TCM_INSERTITEMW, 0, (LPARAM)&tie);
  182. OnSelChanged(hwndDlg, hwndTab, context);
  183. }
  184. return 1;
  185. case WM_DESTROY:
  186. {
  187. InfoDialogContext *context = (InfoDialogContext *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  188. free(context);
  189. }
  190. break;
  191. case WM_NOTIFY:
  192. {
  193. LPNMHDR lpn = (LPNMHDR) lParam;
  194. if (lpn && lpn->code==TCN_SELCHANGE)
  195. {
  196. InfoDialogContext *context = (InfoDialogContext *)GetWindowLongPtr(hwndDlg,GWLP_USERDATA);
  197. OnSelChanged(hwndDlg,GetDlgItem(hwndDlg,IDC_TAB1),context);
  198. }
  199. }
  200. break;
  201. case WM_COMMAND:
  202. switch (LOWORD(wParam))
  203. {
  204. case IDOK:
  205. {
  206. EndDialog(hwndDlg,0);
  207. }
  208. break;
  209. case IDCANCEL:
  210. {
  211. EndDialog(hwndDlg,1);
  212. }
  213. break;
  214. }
  215. break;
  216. }
  217. return 0;
  218. }