Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Types | Public Member Functions
IOleCommandTargetImpl< T > Class Template Reference

#include <IOleCommandTargetImpl.h>

Inheritance diagram for IOleCommandTargetImpl< T >:
Inheritance graph
[legend]
Collaboration diagram for IOleCommandTargetImpl< T >:
Collaboration graph
[legend]

List of all members.

Classes

struct  OleCommandInfo
struct  OleExecData

Public Types

typedef HRESULT(_stdcall * OleCommandProc )(T *pT, const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)

Public Member Functions

virtual HRESULT STDMETHODCALLTYPE QueryStatus (const GUID __RPC_FAR *pguidCmdGroup, ULONG cCmds, OLECMD __RPC_FAR prgCmds[], OLECMDTEXT __RPC_FAR *pCmdText)
virtual HRESULT STDMETHODCALLTYPE Exec (const GUID __RPC_FAR *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT __RPC_FAR *pvaIn, VARIANT __RPC_FAR *pvaOut)

Detailed Description

template<class T>
class IOleCommandTargetImpl< T >

Definition at line 87 of file IOleCommandTargetImpl.h.


Class Documentation

struct IOleCommandTargetImpl::OleCommandInfo

template<class T>
struct IOleCommandTargetImpl< T >::OleCommandInfo

Definition at line 101 of file IOleCommandTargetImpl.h.

Class Members
ULONG nCmdID
ULONG nWindowsCmdID
const GUID * pCmdGUID
OleCommandProc pfnCommandProc
wchar_t * szStatusText
wchar_t * szVerbText
struct IOleCommandTargetImpl::OleExecData

template<class T>
struct IOleCommandTargetImpl< T >::OleExecData

Definition at line 89 of file IOleCommandTargetImpl.h.

Class Members
DWORD nCmdexecopt
DWORD nCmdID
const GUID * pguidCmdGroup
VARIANT * pvaIn
VARIANT * pvaOut

Member Typedef Documentation

template<class T>
typedef HRESULT(_stdcall * IOleCommandTargetImpl< T >::OleCommandProc)(T *pT, const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut)

Definition at line 99 of file IOleCommandTargetImpl.h.


Member Function Documentation

template<class T>
virtual HRESULT STDMETHODCALLTYPE IOleCommandTargetImpl< T >::Exec ( const GUID __RPC_FAR *  pguidCmdGroup,
DWORD  nCmdID,
DWORD  nCmdexecopt,
VARIANT __RPC_FAR *  pvaIn,
VARIANT __RPC_FAR *  pvaOut 
) [inline, virtual]

Definition at line 203 of file IOleCommandTargetImpl.h.

    {
        T* pT = static_cast<T*>(this);
        BOOL bCmdGroupFound = FALSE;

        OleCommandInfo *pCommands = pT->GetCommandTable();
        ATLASSERT(pCommands);

        // Search the support command list
        for (int nSupported = 0; pCommands[nSupported].pCmdGUID != &GUID_NULL; nSupported++)
        {
            OleCommandInfo *pCI = &pCommands[nSupported];

            if (pguidCmdGroup && pCI->pCmdGUID && memcmp(pguidCmdGroup, pCI->pCmdGUID, sizeof(GUID)) == 0)
            {
                continue;
            }
            bCmdGroupFound = TRUE;

            if (pCI->nCmdID != nCmdID)
            {
                continue;
            }

            // Send ourselves a WM_COMMAND windows message with the associated
            // identifier and exec data
            OleExecData cData;
            cData.pguidCmdGroup = pguidCmdGroup;
            cData.nCmdID = nCmdID;
            cData.nCmdexecopt = nCmdexecopt;
            cData.pvaIn = pvaIn;
            cData.pvaOut = pvaOut;

            if (pCI->pfnCommandProc)
            {
                pCI->pfnCommandProc(pT, pCI->pCmdGUID, pCI->nCmdID, nCmdexecopt, pvaIn, pvaOut);
            }
            else if (pCI->nWindowsCmdID != 0 && nCmdexecopt != OLECMDEXECOPT_SHOWHELP)
            {
                HWND hwndTarget = pT->GetCommandTargetWindow();
                if (hwndTarget)
                {
                    ::SendMessage(hwndTarget, WM_COMMAND, LOWORD(pCI->nWindowsCmdID), (LPARAM) &cData);
                }
            }
            else
            {
                // Command supported but not implemented
                continue;
            }

            return S_OK;
        }

        // Was the command group found?
        if (!bCmdGroupFound)
        {
            OLECMDERR_E_UNKNOWNGROUP;
        }

        return OLECMDERR_E_NOTSUPPORTED;
    }
template<class T>
virtual HRESULT STDMETHODCALLTYPE IOleCommandTargetImpl< T >::QueryStatus ( const GUID __RPC_FAR *  pguidCmdGroup,
ULONG  cCmds,
OLECMD __RPC_FAR  prgCmds[],
OLECMDTEXT __RPC_FAR *  pCmdText 
) [inline, virtual]

Definition at line 112 of file IOleCommandTargetImpl.h.

    {
        T* pT = static_cast<T*>(this);
        
        if (prgCmds == NULL)
        {
            return E_INVALIDARG;
        }

        OleCommandInfo *pCommands = pT->GetCommandTable();
        ATLASSERT(pCommands);

        BOOL bCmdGroupFound = FALSE;
        BOOL bTextSet = FALSE;

        // Iterate through list of commands and flag them as supported/unsupported
        for (ULONG nCmd = 0; nCmd < cCmds; nCmd++)
        {
            // Unsupported by default
            prgCmds[nCmd].cmdf = 0;

            // Search the support command list
            for (int nSupported = 0; pCommands[nSupported].pCmdGUID != &GUID_NULL; nSupported++)
            {
                OleCommandInfo *pCI = &pCommands[nSupported];

                if (pguidCmdGroup && pCI->pCmdGUID && memcmp(pguidCmdGroup, pCI->pCmdGUID, sizeof(GUID)) == 0)
                {
                    continue;
                }
                bCmdGroupFound = TRUE;

                if (pCI->nCmdID != prgCmds[nCmd].cmdID)
                {
                    continue;
                }

                // Command is supported so flag it and possibly enable it
                prgCmds[nCmd].cmdf = OLECMDF_SUPPORTED;
                if (pCI->nWindowsCmdID != 0)
                {
                    prgCmds[nCmd].cmdf |= OLECMDF_ENABLED;
                }

                // Copy the status/verb text for the first supported command only
                if (!bTextSet && pCmdText)
                {
                    // See what text the caller wants
                    wchar_t *pszTextToCopy = NULL;
                    if (pCmdText->cmdtextf & OLECMDTEXTF_NAME)
                    {
                        pszTextToCopy = pCI->szVerbText;
                    }
                    else if (pCmdText->cmdtextf & OLECMDTEXTF_STATUS)
                    {
                        pszTextToCopy = pCI->szStatusText;
                    }
                    
                    // Copy the text
                    pCmdText->cwActual = 0;
                    memset(pCmdText->rgwz, 0, pCmdText->cwBuf * sizeof(wchar_t));
                    if (pszTextToCopy)
                    {
                        // Don't exceed the provided buffer size
                        size_t nTextLen = wcslen(pszTextToCopy);
                        if (nTextLen > pCmdText->cwBuf)
                        {
                            nTextLen = pCmdText->cwBuf;
                        }

                        wcsncpy(pCmdText->rgwz, pszTextToCopy, nTextLen);
                        pCmdText->cwActual = nTextLen;
                    }
                    
                    bTextSet = TRUE;
                }
                break;
            }
        }
        
        // Was the command group found?
        if (!bCmdGroupFound)
        {
            OLECMDERR_E_UNKNOWNGROUP;
        }

        return S_OK;
    }

The documentation for this class was generated from the following file: