wa_subclass.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #include "main.h"
  2. #include "../Winamp/wa_ipc.h"
  3. #include "replicant/nu/AutoLock.h"
  4. #include <algorithm>
  5. using namespace Nullsoft::Utility;
  6. static WNDPROC waProc = 0;
  7. extern HMENU wa_play_menu;
  8. static HMENU last_playlistsmenu = NULL;
  9. WORD waMenuID = 0;
  10. extern int IPC_LIBRARY_PLAYLISTS_REFRESH, IPC_CLOUD_ENABLED;
  11. LRESULT WINAPI WinampProcedure(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  12. {
  13. if (msg == WM_COMMAND || msg == WM_SYSCOMMAND)
  14. {
  15. if (LOWORD(wParam) == WINAMP_MANAGEPLAYLISTS)
  16. {
  17. mediaLibrary.ShowMediaLibrary();
  18. mediaLibrary.SelectTreeItem(playlistsTreeId);
  19. return 1;
  20. }
  21. else if (msg == WM_COMMAND && wParam > 45000 && wParam < 55000)
  22. {
  23. INT_PTR treeId = wParam - 45000;
  24. if (FindTreeItem(treeId))
  25. {
  26. mediaLibrary.SwitchToPluginView(treeId);
  27. }
  28. }
  29. else if (msg == WM_COMMAND && wParam > 55000 && wParam < 65000)
  30. {
  31. if (PlayPlaylist(wParam - 55000))
  32. return 0;
  33. }
  34. }
  35. else if (msg == WM_INITMENUPOPUP)
  36. {
  37. HMENU hmenuPopup = (HMENU) wParam;
  38. if (hmenuPopup == wa_play_menu)
  39. {
  40. if (last_playlistsmenu)
  41. {
  42. RemoveMenu(wa_play_menu, waMenuID, MF_BYCOMMAND);
  43. DestroyMenu(last_playlistsmenu);
  44. last_playlistsmenu = NULL;
  45. }
  46. mlGetTreeStruct mgts = { 3001, 55000, -1};
  47. last_playlistsmenu = (HMENU)SendMessage(plugin.hwndLibraryParent, WM_ML_IPC, (WPARAM) &mgts, ML_IPC_GETTREE);
  48. if (last_playlistsmenu)
  49. {
  50. MENUITEMINFOW menuItem = {sizeof(MENUITEMINFOW), MIIM_SUBMENU | MIIM_ID | MIIM_TYPE, MFT_STRING,
  51. MFS_ENABLED, waMenuID, last_playlistsmenu, NULL, NULL, NULL,
  52. WASABI_API_LNGSTRINGW(IDS_PLAYLIST_FROM_ML), 0};
  53. // if there's no playlists then let the user know this
  54. if(!AGAVE_API_PLAYLISTS->GetCount())
  55. {
  56. wchar_t buf[64] = {0};
  57. DestroyMenu(last_playlistsmenu);
  58. menuItem.hSubMenu = last_playlistsmenu = CreateMenu();
  59. InsertMenuW(menuItem.hSubMenu, 0, MF_BYPOSITION | MF_STRING | MF_GRAYED, 0, WASABI_API_LNGSTRINGW_BUF(IDS_NO_PLAYLIST_IN_LIBRARY,buf,64));
  60. }
  61. InsertMenuItemW(wa_play_menu, GetMenuItemCount(wa_play_menu), TRUE, &menuItem);
  62. }
  63. }
  64. }
  65. else if (msg == WM_WA_IPC && lParam == IPC_LIBRARY_PLAYLISTS_REFRESH)
  66. {
  67. // refresh the status of the tree items e.g. when made
  68. // being made into a cloud playlist or remove from it
  69. UpdatePlaylists();
  70. }
  71. else if (msg == WM_WA_IPC && lParam == IPC_CLOUD_ENABLED)
  72. {
  73. cloud_avail = 1;
  74. if (IsWindow(currentView)) PostMessage(currentView, WM_APP + 102, 0, 0);
  75. }
  76. if (waProc)
  77. return CallWindowProcW(waProc, hwnd, msg, wParam, lParam);
  78. else
  79. return DefWindowProc(hwnd, msg, wParam, lParam);
  80. }
  81. void Hook(HWND winamp)
  82. {
  83. if (IsWindow(winamp))
  84. waProc = (WNDPROC)SetWindowLongPtrW(winamp, GWLP_WNDPROC, (LONG_PTR)WinampProcedure);
  85. }