home *** CD-ROM | disk | FTP | other *** search
/ ActiveX Programming Unleashed CD / AXU.iso / source / chap18 / doserver / bindtarg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-02  |  4.0 KB  |  153 lines

  1. // bindtarg.cpp : implementation of the DocObject OLE
  2. //         server document class IOleCommandTarget interface
  3. //
  4. // This is a part of the Microsoft Foundation Classes C++ library.
  5. // Copyright (C) 1992-1995 Microsoft Corporation
  6. // All rights reserved.
  7. //
  8. // This source code is only intended as a supplement to the
  9. // Microsoft Foundation Classes Reference and related
  10. // electronic documentation provided with the library.
  11. // See these sources for detailed information regarding the
  12. // Microsoft Foundation Classes product.
  13.  
  14. //BINDER
  15. // The COleCmdTarget class implements a command-handler for the binder.
  16. // The interface may be queried by the binder to see what commands and
  17. // menu items are available.  This file also defines a COleCmdUI class
  18. // which lets the binder understand what menu items and tool bars must
  19. // be disabled or marked selected based on the state of hte document.
  20. //BINDER_END
  21.  
  22. #include "stdafx.h"
  23. #include "binddoc.h"
  24.  
  25. #ifdef _DEBUG
  26. #undef THIS_FILE
  27. static char BASED_CODE THIS_FILE[] = __FILE__;
  28. #endif
  29.  
  30. /////////////////////////////////////////////////////////////////////////////
  31. // COleCmdUI   (private class)
  32.  
  33. class COleCmdUI : public CCmdUI 
  34. {
  35. public:
  36.    COleCmdUI(OLECMD* rgCmds, ULONG cCmds);
  37.    virtual void Enable(BOOL bOn);
  38.    virtual void SetCheck(int nCheck);
  39.    virtual void SetText(LPCTSTR lpszText);
  40.  
  41. protected:
  42.    OLECMD* m_rgCmds;
  43. };
  44.  
  45. COleCmdUI::COleCmdUI(OLECMD* rgCmds, ULONG cCmds)
  46. {
  47.    m_rgCmds    = rgCmds;
  48.    m_nIndexMax = cCmds;
  49. }
  50.  
  51. void COleCmdUI::Enable(BOOL bOn)
  52. {
  53.    if (m_rgCmds != NULL)
  54.    {
  55.       ASSERT(m_nIndex < m_nIndexMax);
  56.       
  57.       if (bOn)
  58.          m_rgCmds[m_nIndex].cmdf |= OLECMDF_ENABLED;
  59.       else
  60.          m_rgCmds[m_nIndex].cmdf &= ~OLECMDF_ENABLED;
  61.       m_bEnableChanged = TRUE;
  62.    }
  63. }
  64.  
  65. void COleCmdUI::SetCheck(int nCheck)
  66. {
  67.    if (m_rgCmds != NULL)
  68.    {
  69.       ASSERT(m_nIndex < m_nIndexMax);
  70.       
  71.       m_rgCmds[m_nIndex].cmdf &= ~(OLECMDF_LATCHED|OLECMDF_NINCHED);
  72.       if (nCheck == 1)
  73.          m_rgCmds[m_nIndex].cmdf |= OLECMDF_LATCHED;
  74.       else if (nCheck == 2)
  75.          m_rgCmds[m_nIndex].cmdf |= OLECMDF_NINCHED;
  76.    }
  77. }
  78.  
  79. void COleCmdUI::SetText(LPCSTR lpszText)
  80. {
  81.    // ignore it...
  82. }
  83.  
  84. STDMETHODIMP_(ULONG) CDocObjectServerDoc::XOleCommandTarget::AddRef()
  85. {
  86.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleCommandTarget)
  87.     return pThis->ExternalAddRef();
  88. }
  89.  
  90. STDMETHODIMP_(ULONG) CDocObjectServerDoc::XOleCommandTarget::Release()
  91. {
  92.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleCommandTarget)
  93.     return pThis->ExternalRelease();
  94. }
  95.  
  96. STDMETHODIMP CDocObjectServerDoc::XOleCommandTarget::QueryInterface(
  97.     REFIID iid, LPVOID* ppvObj)
  98. {
  99.     METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleCommandTarget)
  100.     return pThis->ExternalQueryInterface(&iid, ppvObj);
  101. }
  102.  
  103. STDMETHODIMP CDocObjectServerDoc::XOleCommandTarget::QueryStatus(
  104.    const GUID* pguidCmdGroup, ULONG cCmds, OLECMD rgCmds[], 
  105.    OLECMDTEXT* pcmdtext)
  106. {
  107.    METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleCommandTarget)
  108.    ASSERT_VALID(pThis);
  109.  
  110.    HRESULT hr = NOERROR;
  111.  
  112.    // this implementation only supports the standard Office95 commands
  113.  
  114.    if (pguidCmdGroup != NULL)
  115.       hr = OLECMDERR_E_UNKNOWNGROUP;
  116.    else if (rgCmds == NULL)
  117.       hr = E_INVALIDARG;
  118.  
  119.    // TODO: determine the state of requested commands 
  120.    hr = E_FAIL;
  121.    
  122.    // TODO: get command name or status bar text for first supported command
  123.    if (pcmdtext)
  124.    {   
  125.       hr = E_FAIL;
  126.    }
  127.  
  128.    return hr;
  129. }
  130.  
  131. STDMETHODIMP CDocObjectServerDoc::XOleCommandTarget::Exec(
  132.    const GUID* pguidCmdGroup, DWORD nCmdID, DWORD nCmdExecOpt, 
  133.    VARIANTARG* pvarargIn, VARIANTARG* pvarargOut)
  134. {
  135.    METHOD_PROLOGUE_EX(CDocObjectServerDoc, OleCommandTarget)
  136.    ASSERT_VALID(pThis);
  137.  
  138.    HRESULT hr = NOERROR;
  139.  
  140.    // this implementation only supports standard Office95 commands
  141.    if (pguidCmdGroup != NULL)
  142.        hr = OLECMDERR_E_UNKNOWNGROUP;
  143.    else
  144.    {
  145.    // TODO: figure out what is supposed to be done based on nCmdExecOpt
  146.    //       and do it
  147.        hr = E_FAIL;
  148.    }
  149.  
  150.    return hr;
  151. }
  152.  
  153.