1
0

local_menu.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #include "./local_menu.h"
  2. #include "../../General/gen_ml/ml.h"
  3. #include "../../General/gen_ml/menu.h"
  4. #include "./resource1.h"
  5. #include "../nu/menushortcuts.h"
  6. #include "api__ml_pmp.h"
  7. #include "main.h"
  8. extern winampMediaLibraryPlugin plugin;
  9. extern HWND hwndMediaView;
  10. #define RATING_MARKER MAKELONG(MAKEWORD('R','A'),MAKEWORD('T','E'))
  11. #define RATING_MINSPACECX 16
  12. #ifndef ARRAYSIZE
  13. #define ARRAYSIZE(x) (sizeof(x)/sizeof((x)))
  14. #endif
  15. static HMENU Menu_FindRatingByChild(HMENU hMenu, MENUINFO *pmi, MENUITEMINFO *pmii, UINT childId)
  16. {
  17. INT count = GetMenuItemCount(hMenu);
  18. for(INT i = 0; i < count; i++)
  19. {
  20. if (GetMenuItemInfo(hMenu, i, TRUE, pmii))
  21. {
  22. if (childId == pmii->wID) return hMenu;
  23. if (NULL != pmii->hSubMenu)
  24. {
  25. HMENU hRating = Menu_FindRatingByChild(pmii->hSubMenu, pmi, pmii, childId);
  26. if (NULL != hRating)
  27. return hRating;
  28. }
  29. }
  30. }
  31. return NULL;
  32. }
  33. static HMENU Menu_FindRatingByMarker(HMENU hMenu, MENUINFO *pmi, MENUITEMINFO *pmii)
  34. {
  35. if (GetMenuInfo(hMenu, pmi) && RATING_MARKER == pmi->dwMenuData)
  36. return hMenu;
  37. INT count = GetMenuItemCount(hMenu);
  38. for(INT i = 0; i < count; i++)
  39. {
  40. if (GetMenuItemInfo(hMenu, i, TRUE, pmii) && NULL != pmii->hSubMenu)
  41. {
  42. HMENU hRating = Menu_FindRatingByMarker(pmii->hSubMenu, pmi, pmii);
  43. if (NULL != hRating)
  44. return hRating;
  45. }
  46. }
  47. return NULL;
  48. }
  49. HMENU Menu_FindRatingMenu(HMENU hMenu, BOOL fUseMarker)
  50. {
  51. if (NULL == hMenu)
  52. return NULL;
  53. MENUITEMINFO mii = {0};
  54. mii.cbSize = sizeof(MENUITEMINFO);
  55. mii.fMask = MIIM_SUBMENU;
  56. if (FALSE == fUseMarker)
  57. mii.fMask |= MIIM_ID;
  58. MENUINFO mi = {0};
  59. mi.cbSize = sizeof(MENUINFO);
  60. mi.fMask = MIM_MENUDATA;
  61. return (FALSE == fUseMarker) ?
  62. Menu_FindRatingByChild(hMenu, &mi, &mii, ID_RATE_5) :
  63. Menu_FindRatingByMarker(hMenu, &mi, &mii);
  64. }
  65. BOOL Menu_SetRatingValue(HMENU ratingMenu, INT ratingValue)
  66. {
  67. if (NULL == ratingMenu) return FALSE;
  68. INT ratingList[] = { ID_RATE_0, ID_RATE_1, ID_RATE_2,
  69. ID_RATE_3, ID_RATE_4, ID_RATE_5};
  70. /// set rating marker
  71. MENUINFO mi = {0};
  72. mi.cbSize = sizeof(MENUINFO);
  73. mi.fMask = MIM_MENUDATA;
  74. mi.dwMenuData = RATING_MARKER;
  75. if (!SetMenuInfo(ratingMenu, &mi))
  76. return FALSE;
  77. MENUITEMINFO mii = {0};
  78. mii.cbSize = sizeof(MENUITEMINFO);
  79. UINT type, state;
  80. for (INT i = 0; i < ARRAYSIZE(ratingList); i++)
  81. {
  82. mii.fMask = MIIM_STATE | MIIM_FTYPE;
  83. if (GetMenuItemInfo(ratingMenu, ratingList[i], FALSE, &mii))
  84. {
  85. if (ratingValue == i)
  86. {
  87. type = mii.fType | MFT_RADIOCHECK;
  88. state = mii.fState | MFS_CHECKED;
  89. }
  90. else
  91. {
  92. type = mii.fType & ~MFT_RADIOCHECK;
  93. state = mii.fState & ~MFS_CHECKED;
  94. }
  95. mii.fMask = 0;
  96. if (type != mii.fType)
  97. {
  98. mii.fType = type;
  99. mii.fMask |= MIIM_FTYPE;
  100. }
  101. if (state != mii.fState)
  102. {
  103. mii.fState = state;
  104. mii.fMask |= MIIM_STATE;
  105. }
  106. if (0 != mii.fMask)
  107. SetMenuItemInfo(ratingMenu, ratingList[i], FALSE, &mii);
  108. }
  109. }
  110. return TRUE;
  111. }
  112. void SyncMenuWithAccelerators(HWND hwndDlg, HMENU menu)
  113. {
  114. HACCEL szAccel[24] = {0};
  115. INT c = WASABI_API_APP->app_getAccelerators(hwndDlg, szAccel, sizeof(szAccel)/sizeof(szAccel[0]), FALSE);
  116. AppendMenuShortcuts(menu, szAccel, c, MSF_REPLACE);
  117. }
  118. void SwapPlayEnqueueInMenu(HMENU listMenu)
  119. {
  120. int playPos=-1, enqueuePos=-1;
  121. MENUITEMINFOW playItem={sizeof(MENUITEMINFOW), 0,}, enqueueItem={sizeof(MENUITEMINFOW), 0,};
  122. int numItems = GetMenuItemCount(listMenu);
  123. for (int i=0;i<numItems;i++)
  124. {
  125. UINT id = GetMenuItemID(listMenu, i);
  126. if (id == ID_TRACKSLIST_PLAYSELECTION)
  127. {
  128. playItem.fMask = MIIM_ID;
  129. playPos = i;
  130. GetMenuItemInfoW(listMenu, i, TRUE, &playItem);
  131. }
  132. else if (id == ID_TRACKSLIST_ENQUEUESELECTION)
  133. {
  134. enqueueItem.fMask = MIIM_ID;
  135. enqueuePos= i;
  136. GetMenuItemInfoW(listMenu, i, TRUE, &enqueueItem);
  137. }
  138. }
  139. playItem.wID = ID_TRACKSLIST_ENQUEUESELECTION;
  140. enqueueItem.wID = ID_TRACKSLIST_PLAYSELECTION;
  141. SetMenuItemInfoW(listMenu, playPos, TRUE, &playItem);
  142. SetMenuItemInfoW(listMenu, enqueuePos, TRUE, &enqueueItem);
  143. }
  144. INT Menu_TrackSkinnedPopup(HMENU hMenu, UINT fuFlags, INT x, INT y, HWND hwnd, LPTPMPARAMS lptpm)
  145. {
  146. if (NULL == hMenu)
  147. return NULL;
  148. bool swapPlayEnqueue=false;
  149. if (gen_mlconfig->ReadInt(L"enqueuedef", 0) == 1)
  150. {
  151. SwapPlayEnqueueInMenu(hMenu);
  152. swapPlayEnqueue = true;
  153. }
  154. SyncMenuWithAccelerators(hwndMediaView, hMenu);
  155. if (swapPlayEnqueue)
  156. SwapPlayEnqueueInMenu(hMenu);
  157. return Menu_TrackPopupParam(plugin.hwndLibraryParent, hMenu, fuFlags, x, y,
  158. hwnd, lptpm, (ULONG_PTR)Menu_FindRatingMenu(hMenu, TRUE));
  159. }