local_menu.cpp 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #include "main.h"
  2. #include "./local_menu.h"
  3. #include "./wasabi.h"
  4. #include "./resource.h"
  5. #include "./navigation.h"
  6. #include "./import.h"
  7. #include "../../General/gen_ml/ml_ipc_0313.h"
  8. #include "../nu/menuHelpers.h"
  9. #include "./ombrowser/browserView.h"
  10. #include "./ombrowser/toolbar.h"
  11. #include "./serviceHelper.h"
  12. #include <ifc_omservice.h>
  13. #define SUBMENU_VIEW 0
  14. #define SUBMENU_SERVICEMNGR 1
  15. #define SUBMENU_NAVIGATION 2
  16. #define SUBMENU_PLUGIN 3
  17. static INT Menu_AddViewContext(HMENU destMenu, HMENU baseMenu, BOOL viewActive)
  18. {
  19. if (NULL == destMenu) return 0;
  20. HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_VIEW);
  21. if (NULL == sorceMenu) return 0;
  22. INT c = GetMenuItemCount(destMenu);
  23. c = MenuHelper_CopyMenu(destMenu, c, sorceMenu);
  24. if (FALSE != viewActive)
  25. {
  26. EnableMenuItem(destMenu, ID_VIEW_OPEN, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED);
  27. }
  28. else
  29. {
  30. EnableMenuItem(destMenu, ID_VIEW_OPEN, MF_BYCOMMAND | MF_ENABLED);
  31. SetMenuDefaultItem(destMenu, ID_VIEW_OPEN, FALSE);
  32. }
  33. return c;
  34. }
  35. typedef struct __NAVITEMPAIR
  36. {
  37. INT wId;
  38. LPCSTR toolItem;
  39. } NAVITEMPAIR;
  40. static INT Menu_AddNavigationContext(HMENU destMenu, HMENU baseMenu)
  41. {
  42. if (NULL == destMenu) return 0;
  43. HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_NAVIGATION);
  44. if (NULL == sorceMenu) return 0;
  45. INT c = GetMenuItemCount(destMenu);
  46. c = MenuHelper_CopyMenu(destMenu, c, sorceMenu);
  47. if (0 == c) return c;
  48. HWND hView = NULL;
  49. Navigation *navigation;
  50. if (SUCCEEDED(Plugin_GetNavigation(&navigation)))
  51. {
  52. hView = navigation->GetActiveView(NULL);
  53. navigation->Release();
  54. }
  55. HWND hToolbar = (NULL != hView) ? BrowserView_GetToolbar(hView) : NULL;
  56. if (NULL != hToolbar)
  57. {
  58. NAVITEMPAIR szItems[] =
  59. {
  60. {ID_NAVIGATION_BACK, TOOLITEM_BUTTON_BACK},
  61. {ID_NAVIGATION_FORWARD, TOOLITEM_BUTTON_FORWARD},
  62. {ID_NAVIGATION_HOME, TOOLITEM_BUTTON_HOME},
  63. {ID_NAVIGATION_STOP, TOOLITEM_BUTTON_STOP},
  64. {ID_NAVIGATION_REFRESH, TOOLITEM_BUTTON_REFRESH},
  65. };
  66. for (INT i = 0; i < ARRAYSIZE(szItems); i++)
  67. {
  68. INT index = Toolbar_FindItem(hToolbar, szItems[i].toolItem);
  69. if (-1 != index)
  70. {
  71. BOOL fDisabled = Toolbar_GetItemStyle(hToolbar, MAKEINTRESOURCE(index), TBIS_DISABLED);
  72. EnableMenuItem(destMenu, szItems[i].wId, MF_BYCOMMAND | (fDisabled) ? (MF_DISABLED | MF_GRAYED) : (MF_ENABLED));
  73. }
  74. }
  75. }
  76. return c;
  77. }
  78. static INT Menu_AddServiceContext(HMENU destMenu, HMENU baseMenu, ifc_omservice *service)
  79. {
  80. if (NULL == destMenu || NULL == service) return 0;
  81. HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_SERVICEMNGR);
  82. if (NULL == sorceMenu) return 0;
  83. INT origCount = GetMenuItemCount(destMenu);
  84. INT c = MenuHelper_CopyMenu(destMenu, origCount, sorceMenu);
  85. UINT serviceFlags;
  86. if (FAILED(service->GetFlags(&serviceFlags))) serviceFlags = 0;
  87. if (0 != ((WDSVCF_ROOT | WDSVCF_SPECIAL) & serviceFlags))
  88. {
  89. UINT szDisabled[] = {ID_SERVICE_EDIT, ID_SERVICE_DELETE, ID_SERVICE_RELOAD,
  90. ID_SERVICE_LOCATE, ID_SERVICE_EDITEXTERNAL };
  91. for (INT i = 0; i < ARRAYSIZE(szDisabled); i++)
  92. EnableMenuItem(destMenu, szDisabled[i], MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);
  93. }
  94. UINT uEnable;
  95. uEnable = (S_OK == ImportService_GetFileSupported()) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED);
  96. EnableMenuItem(destMenu, ID_SERVICE_IMPORT_FILE, MF_BYCOMMAND | uEnable);
  97. uEnable = (S_OK == ImportService_GetUrlSupported()) ? MF_ENABLED : (MF_DISABLED | MF_GRAYED);
  98. EnableMenuItem(destMenu, ID_SERVICE_IMPORT_URL, MF_BYCOMMAND | uEnable);
  99. return c;
  100. }
  101. static INT Menu_AddPluginContext(HMENU destMenu, HMENU baseMenu, ifc_omservice *service)
  102. {
  103. UINT serviceFlags;
  104. if (NULL == service || FAILED(service->GetFlags(&serviceFlags)))
  105. serviceFlags = 0;
  106. if (NULL == destMenu || NULL == service ||
  107. 0 == (WDSVCF_ROOT & serviceFlags))
  108. {
  109. return 0;
  110. }
  111. HMENU sorceMenu = GetSubMenu(baseMenu, SUBMENU_PLUGIN);
  112. if (NULL == sorceMenu) return 0;
  113. INT origCount = GetMenuItemCount(destMenu);
  114. INT c = MenuHelper_CopyMenu(destMenu, origCount, sorceMenu);
  115. return c;
  116. }
  117. static HMENU Menu_GetServiceContext(HMENU baseMenu, ifc_omservice *service)
  118. {
  119. HMENU hMenu = CreatePopupMenu();
  120. if(NULL == hMenu) return NULL;
  121. ifc_omservice *activeService = NULL;
  122. Navigation *navigation;
  123. if (SUCCEEDED(Plugin_GetNavigation(&navigation)))
  124. {
  125. navigation->GetActive(&activeService);
  126. navigation->Release();
  127. }
  128. BOOL fActive = (NULL != service && activeService == service);
  129. INT c, total;
  130. total = Menu_AddViewContext(hMenu, baseMenu, fActive);
  131. if (FALSE != fActive)
  132. {
  133. c = Menu_AddNavigationContext(hMenu, baseMenu);
  134. if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
  135. total++;
  136. total += c;
  137. }
  138. if (NULL != service)
  139. {
  140. c = Menu_AddServiceContext(hMenu, baseMenu, service);
  141. if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
  142. total++;
  143. total += c;
  144. c = Menu_AddPluginContext(hMenu, baseMenu, service);
  145. if (0 != c && total > 0 && 0 != MenuHelper_InsertSeparator(hMenu, total))
  146. total++;
  147. total += c;
  148. }
  149. if (NULL != activeService)
  150. activeService->Release();
  151. return hMenu;
  152. }
  153. HMENU Menu_GetMenu(UINT menuKind, ifc_omservice *service)
  154. {
  155. HMENU baseMenu = WASABI_API_LOADMENUW(IDR_CONTEXTMENU);
  156. if (NULL == baseMenu)
  157. return NULL;
  158. switch(menuKind)
  159. {
  160. case MENU_SERVICECONTEXT:
  161. return Menu_GetServiceContext(baseMenu, service);
  162. }
  163. return NULL;
  164. }
  165. BOOL Menu_ReleaseMenu(HMENU hMenu, UINT menuKind)
  166. {
  167. if (NULL == hMenu) return FALSE;
  168. switch(menuKind)
  169. {
  170. case MENU_SERVICECONTEXT:
  171. return DestroyMenu(hMenu);
  172. }
  173. return FALSE;
  174. }