1
0

menu.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #include "main.h"
  2. #include "./menu.h"
  3. #include "./ratingMenu.h"
  4. #include "./ifc_skinhelper.h"
  5. #include "./ifc_skinnedmenu.h"
  6. #include "./ifc_menucustomizer.h"
  7. #include "./resource.h"
  8. #include "../nu/menuHelpers.h"
  9. #define SUBMENU_RATING 0
  10. #define SUBMENU_TOOLBAR 1
  11. #define SUBMENU_ADDRESSBAR 2
  12. static HRESULT Menu_GetSkinnedMenu(ifc_skinnedmenu **skinnedMenu)
  13. {
  14. if (NULL == skinnedMenu) return E_POINTER;
  15. ifc_skinhelper *skinHelper = NULL;
  16. HRESULT hr = Plugin_GetSkinHelper(&skinHelper);
  17. if (SUCCEEDED(hr) && skinHelper != NULL)
  18. {
  19. hr = skinHelper->QueryInterface(IFC_SkinnedMenu, (void**)skinnedMenu);
  20. skinHelper->Release();
  21. }
  22. return hr;
  23. }
  24. static HMENU Menu_CreateRatingMenu(HMENU baseMenu, INT ratingValue)
  25. {
  26. HMENU menu = GetSubMenu(baseMenu, SUBMENU_RATING);
  27. if (NULL == menu) return NULL;
  28. menu = MenuHelper_DuplcateMenu(menu);
  29. if (NULL == menu) return NULL;
  30. if (FALSE == RatingMenu_InitializeMenu(menu, ratingValue))
  31. {
  32. DestroyMenu(menu);
  33. menu = NULL;
  34. }
  35. return menu;
  36. }
  37. static HMENU Menu_GetToolbarContext(HMENU baseMenu, UINT flags)
  38. {
  39. HMENU hMenu = GetSubMenu(baseMenu, SUBMENU_TOOLBAR);
  40. return hMenu;
  41. }
  42. static HMENU Menu_GetAddressbarContext(HMENU baseMenu, UINT flags)
  43. {
  44. HMENU hMenu = GetSubMenu(baseMenu, SUBMENU_ADDRESSBAR);
  45. return hMenu;
  46. }
  47. void Menu_ConvertRatingMenuStar(HMENU menu, UINT menu_id)
  48. {
  49. MENUITEMINFOW mi = {sizeof(mi), MIIM_DATA | MIIM_TYPE, MFT_STRING};
  50. wchar_t rateBuf[32] = {0}, *rateStr = rateBuf;
  51. mi.dwTypeData = rateBuf;
  52. mi.cch = 32;
  53. if(GetMenuItemInfoW(menu, menu_id, FALSE, &mi))
  54. {
  55. while(rateStr && *rateStr)
  56. {
  57. if(*rateStr == L'*') *rateStr = L'\u2605';
  58. rateStr=CharNextW(rateStr);
  59. }
  60. SetMenuItemInfoW(menu, menu_id, FALSE, &mi);
  61. }
  62. }
  63. HMENU Menu_GetMenu(INT menuKind, UINT flags)
  64. {
  65. HMENU baseMenu = Plugin_LoadMenu(MAKEINTRESOURCE(IDR_CONTEXTMENU));
  66. if (NULL == baseMenu)
  67. return NULL;
  68. HMENU rate_hmenu = GetSubMenu(baseMenu,0);
  69. Menu_ConvertRatingMenuStar(rate_hmenu, ID_RATING_VALUE_5);
  70. Menu_ConvertRatingMenuStar(rate_hmenu, ID_RATING_VALUE_4);
  71. Menu_ConvertRatingMenuStar(rate_hmenu, ID_RATING_VALUE_3);
  72. Menu_ConvertRatingMenuStar(rate_hmenu, ID_RATING_VALUE_2);
  73. Menu_ConvertRatingMenuStar(rate_hmenu, ID_RATING_VALUE_1);
  74. switch(menuKind)
  75. {
  76. case MENU_RATING:
  77. return Menu_CreateRatingMenu(baseMenu, RATINGFROMMCF(flags));
  78. case MENU_TOOLBAR:
  79. return Menu_GetToolbarContext(baseMenu, flags);
  80. case MENU_ADDRESSBAR:
  81. return Menu_GetAddressbarContext(baseMenu, flags);
  82. }
  83. return NULL;
  84. }
  85. void Menu_ReleaseMenu(HMENU hMenu, INT menuKind)
  86. {
  87. if (NULL == hMenu)
  88. return;
  89. switch(menuKind)
  90. {
  91. case MENU_RATING:
  92. DestroyMenu(hMenu);
  93. break;
  94. case MENU_TOOLBAR:
  95. break;
  96. case MENU_ADDRESSBAR:
  97. break;
  98. }
  99. }
  100. BOOL Menu_TrackPopup(HMENU hMenu, UINT fuFlags, INT x, INT y, HWND hwnd, LPTPMPARAMS lptpm)
  101. {
  102. BOOL result = FALSE;
  103. ifc_skinnedmenu *skinnedMenu = NULL;
  104. if (SUCCEEDED(Menu_GetSkinnedMenu(&skinnedMenu)) && skinnedMenu != NULL)
  105. {
  106. ifc_menucustomizer *customizer = NULL;
  107. if (FAILED(RatingMenu_GetCustomizer(hMenu, &customizer)))
  108. customizer = NULL;
  109. result = skinnedMenu->TrackPopup(hMenu, fuFlags, x, y, hwnd, lptpm, customizer);
  110. if (NULL != customizer)
  111. customizer->Release();
  112. skinnedMenu->Release();
  113. }
  114. return result;
  115. }
  116. HANDLE Menu_InitializeHook(HWND hwnd, ifc_menucustomizer *customizer)
  117. {
  118. ifc_skinnedmenu *skinnedMenu = NULL;
  119. HANDLE hook = NULL;
  120. if (SUCCEEDED(Menu_GetSkinnedMenu(&skinnedMenu)) && skinnedMenu != NULL)
  121. {
  122. hook = skinnedMenu->InitPopupHook(hwnd, customizer);
  123. skinnedMenu->Release();
  124. }
  125. return hook;
  126. }
  127. HRESULT Menu_RemoveHook(HANDLE menuHook)
  128. {
  129. ifc_skinnedmenu *skinnedMenu = NULL;
  130. HRESULT hr = Menu_GetSkinnedMenu(&skinnedMenu);
  131. if (SUCCEEDED(hr) && skinnedMenu != NULL)
  132. {
  133. hr = skinnedMenu->RemovePopupHook(menuHook);
  134. skinnedMenu->Release();
  135. }
  136. return hr;
  137. }