oleui2.cpp 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10. #include "stdafx.h"
  11. #ifdef AFX_OLE2_SEG
  12. #pragma code_seg(AFX_OLE2_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. /////////////////////////////////////////////////////////////////////////////
  20. // more User interface for COleClientItem
  21. /////////////////////////////////////////////////////////////////////////////
  22. // OLE Object Verb Menu helpers
  23. // simple wrapper for OleUIAddVerbMenu API
  24. void AFXAPI AfxOleSetEditMenu(COleClientItem* pItem, CMenu* pMenu,
  25. UINT iMenuItem, UINT nIDVerbMin, UINT nIDVerbMax, UINT nIDConvert)
  26. {
  27. ASSERT_VALID(pMenu);
  28. if (pItem != NULL)
  29. ASSERT_VALID(pItem);
  30. HMENU hmenuDummy;
  31. if (!::OleUIAddVerbMenu(pItem != NULL ? pItem->m_lpObject : NULL,
  32. NULL, pMenu->GetSafeHmenu(), iMenuItem,
  33. nIDVerbMin, nIDVerbMax, nIDConvert != 0, nIDConvert, &hmenuDummy))
  34. {
  35. // turn gray popup into gray disabled normal menu item
  36. TCHAR szBuffer[256];
  37. pMenu->GetMenuString(iMenuItem, szBuffer, sizeof szBuffer, MF_BYPOSITION);
  38. pMenu->DeleteMenu(iMenuItem, MF_BYPOSITION);
  39. pMenu->InsertMenu(
  40. iMenuItem, MF_BYPOSITION|MF_STRING|MF_GRAYED|MF_DISABLED,
  41. nIDVerbMin, szBuffer);
  42. }
  43. }
  44. /////////////////////////////////////////////////////////////////////////////
  45. // UI message handlers
  46. void COleDocument::OnUpdatePasteMenu(CCmdUI* pCmdUI)
  47. {
  48. pCmdUI->Enable(COleClientItem::CanPaste());
  49. }
  50. void COleDocument::OnUpdatePasteLinkMenu(CCmdUI* pCmdUI)
  51. {
  52. pCmdUI->Enable(COleClientItem::CanPasteLink());
  53. }
  54. void COleDocument::OnUpdateEditLinksMenu(CCmdUI* pCmdUI)
  55. {
  56. POSITION pos = GetStartPosition();
  57. COleClientItem* pItem;
  58. while ((pItem = GetNextClientItem(pos)) != NULL)
  59. {
  60. if (pItem->GetType() == OT_LINK)
  61. {
  62. // we found a link!
  63. pCmdUI->Enable(TRUE);
  64. return;
  65. }
  66. }
  67. pCmdUI->Enable(FALSE); // no links today
  68. }
  69. void COleDocument::OnEditLinks()
  70. {
  71. ASSERT_VALID(this);
  72. COleLinksDialog dlg(this, GetRoutingView_());
  73. dlg.DoModal();
  74. }
  75. void COleDocument::OnEditConvert()
  76. {
  77. ASSERT_VALID(this);
  78. // get selected item
  79. COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  80. if (pItem == NULL)
  81. return;
  82. // do conversion dialog & convert for that item
  83. COleConvertDialog dlg(pItem);
  84. if (dlg.DoModal() == IDOK)
  85. dlg.DoConvert(pItem);
  86. }
  87. void COleDocument::OnUpdateEditChangeIcon(CCmdUI* pCmdUI)
  88. {
  89. ASSERT_VALID(this);
  90. pCmdUI->Enable(GetPrimarySelectedItem(GetRoutingView_()) != NULL);
  91. }
  92. void COleDocument::OnEditChangeIcon()
  93. {
  94. ASSERT_VALID(this);
  95. // get selected item
  96. COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  97. if (pItem == NULL)
  98. return;
  99. // do conversion dialog & convert for that item
  100. COleChangeIconDialog dlg(pItem);
  101. if (dlg.DoModal() == IDOK)
  102. dlg.DoChangeIcon(pItem);
  103. }
  104. void COleDocument::OnUpdateObjectVerbMenu(CCmdUI* pCmdUI)
  105. {
  106. if (pCmdUI->m_pMenu == NULL || pCmdUI->m_pParentMenu == NULL)
  107. {
  108. // not a menu or is on sub-menu (don't recurse)
  109. pCmdUI->ContinueRouting();
  110. return;
  111. }
  112. // check for single selection
  113. COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  114. if (pItem == NULL || pItem->GetType() == OT_STATIC)
  115. {
  116. // no selection, or is 'static' item
  117. pCmdUI->Enable(FALSE);
  118. }
  119. // only include Convert... if there is a handler for ID_OLE_EDIT_CONVERT
  120. UINT nConvertID = ID_OLE_EDIT_CONVERT;
  121. AFX_CMDHANDLERINFO info;
  122. if (!OnCmdMsg(ID_OLE_EDIT_CONVERT, CN_COMMAND, NULL, &info))
  123. nConvertID = 0;
  124. // update the menu
  125. AfxOleSetEditMenu(GetPrimarySelectedItem(GetRoutingView_()),
  126. pCmdUI->m_pMenu, pCmdUI->m_nIndex,
  127. ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, nConvertID);
  128. }
  129. /////////////////////////////////////////////////////////////////////////////