Leaked source code of windows server 2003
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.

187 lines
4.3 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995 - 1995.
  5. //
  6. // File: menuutil.cxx
  7. //
  8. // Contents: Context menu utilities, stolen from the shell. This is
  9. // basically CDefFolderMenu_MergeMenu and its support.
  10. //
  11. // History: 20-Dec-95 BruceFo Created
  12. //
  13. //----------------------------------------------------------------------------
  14. #include "headers.hxx"
  15. #pragma hdrstop
  16. #include "menuutil.hxx"
  17. // Cannonical command names stolen from the shell
  18. TCHAR const c_szDelete[] = TEXT("delete");
  19. TCHAR const c_szCut[] = TEXT("cut");
  20. TCHAR const c_szCopy[] = TEXT("copy");
  21. TCHAR const c_szLink[] = TEXT("link");
  22. TCHAR const c_szProperties[] = TEXT("properties");
  23. TCHAR const c_szPaste[] = TEXT("paste");
  24. TCHAR const c_szPasteLink[] = TEXT("pastelink");
  25. TCHAR const c_szRename[] = TEXT("rename");
  26. HMENU
  27. LoadPopupMenu(
  28. HINSTANCE hinst,
  29. UINT id
  30. )
  31. {
  32. HMENU hmParent = LoadMenu(hinst, MAKEINTRESOURCE(id));
  33. if (NULL == hmParent)
  34. {
  35. return NULL;
  36. }
  37. HMENU hmPopup = GetSubMenu(hmParent, 0);
  38. RemoveMenu(hmParent, 0, MF_BYPOSITION);
  39. DestroyMenu(hmParent);
  40. return hmPopup;
  41. }
  42. HMENU
  43. MyGetMenuFromID(
  44. HMENU hmMain,
  45. UINT uID
  46. )
  47. {
  48. MENUITEMINFO mii;
  49. mii.cbSize = sizeof(mii);
  50. mii.fMask = MIIM_SUBMENU;
  51. mii.cch = 0; // just in case
  52. if (!GetMenuItemInfo(hmMain, uID, FALSE, &mii))
  53. {
  54. return NULL;
  55. }
  56. return mii.hSubMenu;
  57. }
  58. int
  59. MyMergePopupMenus(
  60. HMENU hmMain,
  61. HMENU hmMerge,
  62. int idCmdFirst,
  63. int idCmdLast)
  64. {
  65. int i;
  66. int idTemp;
  67. int idMax = idCmdFirst;
  68. for (i = GetMenuItemCount(hmMerge) - 1; i >= 0; --i)
  69. {
  70. MENUITEMINFO mii;
  71. mii.cbSize = sizeof(mii);
  72. mii.fMask = MIIM_ID | MIIM_SUBMENU;
  73. mii.cch = 0; // just in case
  74. if (!GetMenuItemInfo(hmMerge, i, TRUE, &mii))
  75. {
  76. continue;
  77. }
  78. idTemp = Shell_MergeMenus(
  79. MyGetMenuFromID(hmMain, mii.wID),
  80. mii.hSubMenu,
  81. 0,
  82. idCmdFirst,
  83. idCmdLast,
  84. MM_ADDSEPARATOR | MM_SUBMENUSHAVEIDS);
  85. if (idMax < idTemp)
  86. {
  87. idMax = idTemp;
  88. }
  89. }
  90. return idMax;
  91. }
  92. VOID
  93. MyMergeMenu(
  94. HINSTANCE hinst,
  95. UINT idMainMerge,
  96. UINT idPopupMerge,
  97. LPQCMINFO pqcm)
  98. {
  99. HMENU hmMerge;
  100. UINT idMax = pqcm->idCmdFirst;
  101. UINT idTemp;
  102. if (idMainMerge
  103. && (hmMerge = LoadPopupMenu(hinst, idMainMerge)) != NULL)
  104. {
  105. idMax = Shell_MergeMenus(
  106. pqcm->hmenu,
  107. hmMerge,
  108. pqcm->indexMenu,
  109. pqcm->idCmdFirst,
  110. pqcm->idCmdLast,
  111. MM_ADDSEPARATOR | MM_SUBMENUSHAVEIDS);
  112. DestroyMenu(hmMerge);
  113. }
  114. if (idPopupMerge
  115. && (hmMerge = LoadMenu(hinst, MAKEINTRESOURCE(idPopupMerge))) != NULL)
  116. {
  117. idTemp = MyMergePopupMenus(
  118. pqcm->hmenu,
  119. hmMerge,
  120. pqcm->idCmdFirst,
  121. pqcm->idCmdLast);
  122. if (idMax < idTemp)
  123. {
  124. idMax = idTemp;
  125. }
  126. DestroyMenu(hmMerge);
  127. }
  128. pqcm->idCmdFirst = idMax;
  129. }
  130. VOID
  131. MyInsertMenu(
  132. HINSTANCE hinst,
  133. UINT idInsert,
  134. LPQCMINFO pqcm)
  135. {
  136. HMENU hmInsert;
  137. UINT idMax = pqcm->idCmdFirst;
  138. if (idInsert
  139. && (hmInsert = LoadPopupMenu(hinst, idInsert)) != NULL)
  140. {
  141. for (int i = GetMenuItemCount(hmInsert) - 1; i >= 0; --i)
  142. {
  143. MENUITEMINFO mii;
  144. mii.cbSize = sizeof(mii);
  145. mii.fMask = MIIM_ID | MIIM_SUBMENU;
  146. mii.cch = 0; // just in case
  147. if (!GetMenuItemInfo(hmInsert, i, TRUE, &mii))
  148. {
  149. continue;
  150. }
  151. if (!InsertMenuItem(pqcm->hmenu, idMax, TRUE, &mii))
  152. {
  153. ++idMax;
  154. }
  155. }
  156. DestroyMenu(hmInsert);
  157. }
  158. pqcm->idCmdFirst = idMax;
  159. }