Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Customized Visual Studio .NET package: your fully integrated document window inside the IDE

, 20 Dec 2003
Create a fully integrated document window inside the Visual Studio IDE.
#include "StdAfx.h"
#include "DocView.h"
#include "DocData.h"
#include "Mediator.h"
#include "CommandIDs.h"


static const GUID IID_IVsWindowPane = {0xB0834D0F,0xACFF,0x4EA5,0x80,0x9B,0x97,0xCB,0xB5,0xD3,0xD2,0x6B};


CDocumentView::CDocumentView()
{
	m_uRefCnt = 0;
	m_pMdtr = NULL;
}

CDocumentView::~CDocumentView()
{
	if ( m_pMdtr )
	{
		m_pMdtr->SetView( NULL );
	}
	CDbg::Trace("  CDocumentView:: destructor\n" );
}

void CDocumentView::Attach( CMediator* pMdtr )
{
	if ( m_pMdtr != NULL )
	{
		m_pMdtr->SetView(NULL);
	}
	m_pMdtr = pMdtr;
	m_pMdtr->SetView( this );
}

STDMETHODIMP CDocumentView::QueryInterface( REFIID rid,void** ppvObject )
{
	if ( (rid == IID_IVsWindowPane) || (rid == IID_IUnknown))
	{
		*ppvObject = (IVsWindowPane*)this;
		AddRef();
		CDbg::Trace("       DocView::QI: IVsWindowPane\n" );
		return S_OK;
	}
	if ( rid == IID_IOleCommandTarget )
	{
		*ppvObject = (IOleCommandTarget*)this;
		AddRef();
		CDbg::Trace("       DocView::QI: IOleCmmandTarget\n" );
		return S_OK;
	}
	if ( rid == IID_IDispatch )
	{
		CDbg::Trace("       DocView::QI: IDispatch #####\n" );
		//*ppvObject = (IDispatch*)this;
		//return S_OK;
	}

	*ppvObject = NULL;
	return E_NOINTERFACE;
}

STDMETHODIMP_(ULONG) CDocumentView::AddRef()
{
	++m_uRefCnt;
	return m_uRefCnt;
}

STDMETHODIMP_(ULONG) CDocumentView::Release()
{
	m_uRefCnt --;
	if ( m_uRefCnt == 0 )
	{
		delete this;
		return 0;
	}
	return m_uRefCnt;
}

STDMETHODIMP CDocumentView::WP_Stub3( DWORD p1 )
{
	CDbg::Trace("       IVsWindowPane::Stub3() = S_OK\n" );
	return S_OK;
}

STDMETHODIMP CDocumentView::WP_CreatePaneWindow( HWND hwndParent, int iX, int iY,
												int iCX, int iCY, HWND* phwnd )
{
	CDbg::Trace("       IVsWindowPane::CreatePaneWindow()\n" );

	if ( m_pMdtr )
	{
		*phwnd = m_pMdtr->CreateWnd( hwndParent, iX, iY, iCX, iCY);
		if ( *phwnd )
		{
			return S_OK;
		}
	}
	CDbg::Trace("       IVsWindowPane::CreatePaneWindow() = E_FAIL\n" );
	return E_FAIL;
}

STDMETHODIMP CDocumentView::WP_Stub5( void* p1 )
{
	CDbg::Trace("       IVsWindowPane::Stub5( ) =E_NOTIMPL\n" );
	return E_NOTIMPL;
}

STDMETHODIMP CDocumentView::WP_Close()
{
	CDbg::Trace("       IVsWindowPane::Close() = S_OK\n" );
	if ( m_pMdtr )
	{
		m_pMdtr->CloseWindow();
	}
	return S_OK;
}

STDMETHODIMP CDocumentView::WP_Stub7( void* p1 )
{
	CDbg::Trace("       IVsWindowPane::Stub7( )=E_NOTIMPL\n" );
	return E_NOTIMPL;
}

STDMETHODIMP CDocumentView::WP_Stub8( void* p1 )
{
	CDbg::Trace("       IVsWindowPane::Stub8( )=E_NOTIMPL\n" );
	return E_NOTIMPL;
}

STDMETHODIMP CDocumentView::WP_Stub9( void* p1 )
{
	// called frequently
	return E_NOTIMPL;
}

// all IDs are obtained while tracing original package activity:
static GUID guidCommonActionsGrp = {0x5EFC7975,0x14BC,0x11CF,0x9B,0x2B,0x00,0xAA,0x00,0x57,0x38,0x19};


STDMETHODIMP CDocumentView::QueryStatus(
		const GUID *pguidCmdGrp,
		ULONG cCmds, // Number of commands in prgCmds array
		OLECMD *prgCmds, // Array of commands
		OLECMDTEXT *pCmdText // Pointer to name or status of command
		)
{
	if ( (*pguidCmdGrp == guidCommonActionsGrp) && cCmds > 0 ) //standard group
	{
		// view specific commands affecting window pane:
		// return values obtained from original "bined" package
		if ( prgCmds[0].cmdID == COMMAND_ID_ONEXIT ||
			prgCmds[0].cmdID == COMMAND_ID_NEWPANE ||
			prgCmds[0].cmdID == COMMAND_ID_NEWPANE1 )
		{
			return 0x80040100;
		}
		if ( m_pMdtr )
		{
			BOOL bCmdEnabled = FALSE;
			DWORD dwCmdState = m_pMdtr->QueryCommandsState();

			switch(prgCmds[0].cmdID)
			{
			case COMMAND_ID_CUT:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_CUT);
				break;
			case COMMAND_ID_COPY:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_COPY);
				break;
			case COMMAND_ID_DELETE:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_DELETE);
				break;
			case COMMAND_ID_PASTE:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_PASTE);
				break;
			case COMMAND_ID_REDO:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_REDO);
				break;
			case COMMAND_ID_SAVE:
				bCmdEnabled = TRUE; // always enabled//IsCmdEnabled(dwCmdState,CMD_FLAG_S);
				break;
			case COMMAND_ID_SAVEALL:
				bCmdEnabled = TRUE; // - " - IsCmdEnabled(dwCmdState,CMD_FLAG_CUT);
				break;
			case COMMAND_ID_SEL_ALL:
				bCmdEnabled = FALSE;//IsCmdEnabled(dwCmdState,CMD_FLAG_CUT);
				break;
			case COMMAND_ID_UNDO:
				bCmdEnabled = IsCmdEnabled(dwCmdState,CMD_FLAG_UNDO);
				break;
			default:
				return E_UNEXPECTED;
			}
			prgCmds[0].cmdf = bCmdEnabled ? OLECMDF_SUPPORTED|OLECMDF_ENABLED : 0;
			return S_OK;
		}
	}
	return OLECMDERR_E_UNKNOWNGROUP;
}

STDMETHODIMP CDocumentView::Exec(
		const GUID *pguidCmdGroup, // Pointer to command group
		DWORD nCmdID, // Identifier of command to execute
		DWORD nCmdExecOpt, // Options for executing the command
		VARIANTARG *pvaIn, // Pointer to input arguments
		VARIANTARG *pvaOut // Pointer to command output
		)
{
	if ( *pguidCmdGroup == guidCommonActionsGrp )
	{
		// window show/activate(?)
		if ( nCmdID == COMMAND_ID_WNDSHO || nCmdID == COMMAND_ID_WNDSHO1 )
		{
			return S_OK;
		}
		if ( nCmdID == COMMAND_ID_ONEXIT ||	nCmdID == COMMAND_ID_NEWPANE ||
			nCmdID == COMMAND_ID_NEWPANE1 )
		{
			return 0x80040100;
		}
		if ( m_pMdtr )
		{
			return m_pMdtr->ExecCommand( nCmdID );
		}
	}
	return OLECMDERR_E_DISABLED;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Michael Sheinin
Web Developer
United States United States
For the last 7 years I have developed software in real-time/embedded and MS-Windows environments for military and civil markets. I hold B.Sc. degree in computer engineering. Living in Ontario, Canada, I like hiking and traveling in general. Currently, I'm looking for employment opportunity inside the GTA.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150331.1 | Last Updated 21 Dec 2003
Article Copyright 2003 by Michael Sheinin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid