Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

242 lines
7.8 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: C M D T A B L E . C P P
  7. //
  8. // Contents: Command-table code -- determines which menu options are
  9. // available by the selection count, among other criteria
  10. //
  11. // Notes:
  12. //
  13. // Author: jeffspr 28 Jan 1998
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "pch.h"
  17. #pragma hdrstop
  18. #include "upsres.h" // Folder resource IDs
  19. #include "cmdtable.h" // Header for this file
  20. // Enable this if we have checked items
  21. //
  22. // #define CHECKED_ITEMS_PRESENT 1
  23. //---[ Prototypes ]-----------------------------------------------------------
  24. VOID DoMenuItemExceptionLoop(
  25. LPCITEMIDLIST * apidlSelected,
  26. DWORD cPidl);
  27. VOID DoMenuItemCheckLoop(VOID);
  28. COMMANDTABLEENTRY g_cteFolderCommands[] =
  29. {
  30. // command id
  31. // | valid when 0 items selected
  32. // | |
  33. // | | valid when multiple items selected
  34. // | | | command is currently enabled
  35. // | | | | new state (temp)
  36. // | | | | |
  37. // | | | | |
  38. // | | | | |
  39. // | | | | |
  40. // v v v v v
  41. //
  42. { CMIDM_CREATE_SHORTCUT, false, false, true, true },
  43. { SFVIDM_FILE_LINK, false, false, true, true },
  44. { CMIDM_DELETE, false, false, false, true },
  45. { SFVIDM_FILE_DELETE, false, false, false, true },
  46. { CMIDM_RENAME, false, false, true, true },
  47. { SFVIDM_FILE_RENAME, false, false, true, true },
  48. { CMIDM_PROPERTIES, false, false, true, true },
  49. { SFVIDM_FILE_PROPERTIES, false, false, true, true },
  50. { CMIDM_ARRANGE_BY_NAME, true, true, true, true },
  51. { CMIDM_ARRANGE_BY_URL, true, true, true, true },
  52. { CMIDM_INVOKE, false, false, true, true }
  53. };
  54. const DWORD g_nFolderCommandCount = celems(g_cteFolderCommands);
  55. //+---------------------------------------------------------------------------
  56. //
  57. // Function: HrEnableOrDisableMenuItems
  58. //
  59. // Purpose: Enable, disable, and or check/uncheck menu items depending
  60. // on the current selection count, as well as exceptions for
  61. // the type and state of the connections themselves
  62. //
  63. // Arguments:
  64. // hwnd [in] Our window handle
  65. // apidlSelected [in] Currently selected objects
  66. // cPidl [in] Number selected
  67. // hmenu [in] Our command menu handle
  68. // idCmdFirst [in] First valid command
  69. //
  70. // Returns:
  71. //
  72. // Author: jeffspr 2 Feb 1998
  73. //
  74. // Notes:
  75. //
  76. HRESULT HrEnableOrDisableMenuItems(
  77. HWND hwnd,
  78. LPCITEMIDLIST * apidlSelected,
  79. DWORD cPidl,
  80. HMENU hmenu,
  81. UINT idCmdFirst)
  82. {
  83. HRESULT hr = S_OK;
  84. DWORD dwLoop = 0;
  85. // Loop through, and set the new state, based on the selection
  86. // count compared to the flags for 0-select and multi-select
  87. //
  88. for (dwLoop = 0; dwLoop < g_nFolderCommandCount; dwLoop++)
  89. {
  90. // If nothing is selected, then check the current state, and
  91. // if different, adjust
  92. //
  93. if (cPidl == 0)
  94. {
  95. g_cteFolderCommands[dwLoop].fNewState =
  96. g_cteFolderCommands[dwLoop].fValidOnZero;
  97. }
  98. else
  99. {
  100. // If singly-selected, then by default, we're always on.
  101. //
  102. if (cPidl == 1)
  103. {
  104. g_cteFolderCommands[dwLoop].fNewState =
  105. g_cteFolderCommands[dwLoop].fValidOnSingle;
  106. }
  107. else
  108. {
  109. // Multi-selected
  110. //
  111. g_cteFolderCommands[dwLoop].fNewState =
  112. g_cteFolderCommands[dwLoop].fValidOnMultiple;
  113. }
  114. }
  115. }
  116. for (dwLoop = 0; dwLoop < g_nFolderCommandCount; dwLoop++)
  117. {
  118. DWORD dwCommandId = 0;
  119. switch(g_cteFolderCommands[dwLoop].iCommandId)
  120. {
  121. case SFVIDM_FILE_DELETE:
  122. case SFVIDM_FILE_RENAME:
  123. case SFVIDM_FILE_LINK:
  124. case SFVIDM_FILE_PROPERTIES:
  125. dwCommandId = g_cteFolderCommands[dwLoop].iCommandId;
  126. break;
  127. default:
  128. dwCommandId = g_cteFolderCommands[dwLoop].iCommandId +
  129. idCmdFirst - CMIDM_FIRST;
  130. break;
  131. }
  132. // Enable or disable the menu item, as appopriate
  133. //
  134. EnableMenuItem(hmenu, dwCommandId,
  135. g_cteFolderCommands[dwLoop].fNewState ?
  136. MF_ENABLED | MF_BYCOMMAND : // enable
  137. MF_GRAYED | MF_BYCOMMAND); // disable
  138. }
  139. TraceHr(ttidShellFolder, FAL, hr, FALSE, "HrEnableOrDisableMenuItems");
  140. return hr;
  141. }
  142. //+---------------------------------------------------------------------------
  143. //
  144. // Function: DoMenuItemExceptionLoop
  145. //
  146. // Purpose: Check for various menu item exceptions.
  147. //
  148. // Arguments:
  149. // apidlSelected [in] Selected items
  150. // cPidl [in] Count of selected items
  151. //
  152. // Returns:
  153. //
  154. // Author: jeffspr 26 Feb 1998
  155. //
  156. // Notes:
  157. //
  158. VOID DoMenuItemExceptionLoop(
  159. LPCITEMIDLIST * apidlSelected,
  160. DWORD cPidl)
  161. {
  162. DWORD dwLoop = 0;
  163. DWORD dwObjectLoop = 0;
  164. bool fEnableDelete = false; // For now, this is ALWAYS disabled (jeffspr)
  165. bool fEnableRename = true;
  166. if (cPidl)
  167. {
  168. // Loop through each of the selected objects
  169. //
  170. for (dwObjectLoop = 0; dwObjectLoop < cPidl; dwObjectLoop++)
  171. {
  172. // Validate the pidls
  173. //
  174. PUPNPDEVICEFOLDPIDL pudfp = NULL;
  175. if (!(apidlSelected[dwObjectLoop]) ||
  176. ILIsEmpty(apidlSelected[dwObjectLoop]))
  177. {
  178. AssertSz(FALSE, "Bogus pidl array in DoMenuItemExceptionLoop (status)");
  179. }
  180. else
  181. {
  182. pudfp = ConvertToUPnPDevicePIDL(apidlSelected[dwObjectLoop]);
  183. }
  184. if (pudfp)
  185. {
  186. // Loop through the commands
  187. //
  188. for (dwLoop = 0; dwLoop < g_nFolderCommandCount; dwLoop++)
  189. {
  190. // Only allow items to be changed to ENABLED states when they're
  191. // previously DISABLED
  192. //
  193. if (g_cteFolderCommands[dwLoop].fNewState)
  194. {
  195. }
  196. }
  197. }
  198. }
  199. // Loop through the commands, and disable the commands, if appropriate
  200. //
  201. for (dwLoop = 0; dwLoop < g_nFolderCommandCount; dwLoop++)
  202. {
  203. switch(g_cteFolderCommands[dwLoop].iCommandId)
  204. {
  205. case CMIDM_DELETE:
  206. case SFVIDM_FILE_DELETE:
  207. g_cteFolderCommands[dwLoop].fNewState = fEnableDelete;
  208. break;
  209. case CMIDM_RENAME:
  210. case SFVIDM_FILE_RENAME:
  211. g_cteFolderCommands[dwLoop].fNewState = fEnableRename;
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. }
  218. }