home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / oleui2.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  4KB  |  158 lines

  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.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_OLE2_SEG
  14. #pragma code_seg(AFX_OLE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. /////////////////////////////////////////////////////////////////////////////
  25. // more User interface for COleClientItem
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // OLE Object Verb Menu helpers
  29.  
  30. // simple wrapper for OleUIAddVerbMenu API
  31.  
  32. void AFXAPI AfxOleSetEditMenu(COleClientItem* pItem, CMenu* pMenu,
  33.     UINT iMenuItem, UINT nIDVerbMin, UINT nIDVerbMax, UINT nIDConvert)
  34. {
  35.     ASSERT_VALID(pMenu);
  36.     if (pItem != NULL)
  37.         ASSERT_VALID(pItem);
  38.  
  39.     HMENU hmenuDummy;
  40.     if (!::OleUIAddVerbMenu(pItem != NULL ? pItem->m_lpObject : NULL,
  41.         NULL, pMenu->GetSafeHmenu(), iMenuItem,
  42.         nIDVerbMin, nIDVerbMax, nIDConvert != 0, nIDConvert, &hmenuDummy))
  43.     {
  44.         // turn gray popup into gray disabled normal menu item
  45.         TCHAR szBuffer[256];
  46.         pMenu->GetMenuString(iMenuItem, szBuffer, sizeof szBuffer, MF_BYPOSITION);
  47.         pMenu->DeleteMenu(iMenuItem, MF_BYPOSITION);
  48.         pMenu->InsertMenu(
  49.             iMenuItem, MF_BYPOSITION|MF_STRING|MF_GRAYED|MF_DISABLED,
  50.             nIDVerbMin, szBuffer);
  51.     }
  52. }
  53.  
  54. /////////////////////////////////////////////////////////////////////////////
  55. // UI message handlers
  56.  
  57. void COleDocument::OnUpdatePasteMenu(CCmdUI* pCmdUI)
  58. {
  59.     pCmdUI->Enable(COleClientItem::CanPaste());
  60. }
  61.  
  62. void COleDocument::OnUpdatePasteLinkMenu(CCmdUI* pCmdUI)
  63. {
  64.     pCmdUI->Enable(COleClientItem::CanPasteLink());
  65. }
  66.  
  67. void COleDocument::OnUpdateEditLinksMenu(CCmdUI* pCmdUI)
  68. {
  69.     POSITION pos = GetStartPosition();
  70.     COleClientItem* pItem;
  71.     while ((pItem = GetNextClientItem(pos)) != NULL)
  72.     {
  73.         if (pItem->GetType() == OT_LINK)
  74.         {
  75.             // we found a link!
  76.             pCmdUI->Enable(TRUE);
  77.             return;
  78.         }
  79.     }
  80.     pCmdUI->Enable(FALSE);      // no links today
  81. }
  82.  
  83. void COleDocument::OnEditLinks()
  84. {
  85.     ASSERT_VALID(this);
  86.  
  87.     COleLinksDialog dlg(this, GetRoutingView_());
  88.     dlg.DoModal();
  89. }
  90.  
  91. void COleDocument::OnEditConvert()
  92. {
  93.     ASSERT_VALID(this);
  94.  
  95.     // get selected item
  96.     COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  97.     if (pItem == NULL)
  98.         return;
  99.  
  100.     // do conversion dialog & convert for that item
  101.     COleConvertDialog dlg(pItem);
  102.     if (dlg.DoModal() == IDOK)
  103.         dlg.DoConvert(pItem);
  104. }
  105.  
  106. void COleDocument::OnUpdateEditChangeIcon(CCmdUI* pCmdUI)
  107. {
  108.     ASSERT_VALID(this);
  109.  
  110.     pCmdUI->Enable(GetPrimarySelectedItem(GetRoutingView_()) != NULL);
  111. }
  112.  
  113. void COleDocument::OnEditChangeIcon()
  114. {
  115.     ASSERT_VALID(this);
  116.  
  117.     // get selected item
  118.     COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  119.     if (pItem == NULL)
  120.         return;
  121.  
  122.     // do conversion dialog & convert for that item
  123.     COleChangeIconDialog dlg(pItem);
  124.     if (dlg.DoModal() == IDOK)
  125.         dlg.DoChangeIcon(pItem);
  126. }
  127.  
  128. void COleDocument::OnUpdateObjectVerbMenu(CCmdUI* pCmdUI)
  129. {
  130.     if (pCmdUI->m_pMenu == NULL || pCmdUI->m_pParentMenu == NULL)
  131.     {
  132.         // not a menu or is on sub-menu (don't recurse)
  133.         pCmdUI->ContinueRouting();
  134.         return;
  135.     }
  136.  
  137.     // check for single selection
  138.     COleClientItem* pItem = GetPrimarySelectedItem(GetRoutingView_());
  139.     if (pItem == NULL || pItem->GetType() == OT_STATIC)
  140.     {
  141.         // no selection, or is 'static' item
  142.         pCmdUI->Enable(FALSE);
  143.     }
  144.  
  145.     // only include Convert... if there is a handler for ID_OLE_EDIT_CONVERT
  146.     UINT nConvertID = ID_OLE_EDIT_CONVERT;
  147.     AFX_CMDHANDLERINFO info;
  148.     if (!OnCmdMsg(ID_OLE_EDIT_CONVERT, CN_COMMAND, NULL, &info))
  149.         nConvertID = 0;
  150.  
  151.     // update the menu
  152.     AfxOleSetEditMenu(GetPrimarySelectedItem(GetRoutingView_()),
  153.         pCmdUI->m_pMenu, pCmdUI->m_nIndex,
  154.         ID_OLE_VERB_FIRST, ID_OLE_VERB_LAST, nConvertID);
  155. }
  156.  
  157. /////////////////////////////////////////////////////////////////////////////
  158.