// Copyright (c) 1997-2001 Microsoft Corporation, All Rights Reserved
//***************************************************************************
//
//  (c) 1996, 1997 by Microsoft Corporation
//
//  mv.cpp
//
// This file contains the implementation of the CMultiView and CMultiViewContext
// classes. This class extends the CMultiViewBase class that is automatically
// generated by the component gallery.
//
//  a-larryf    21-Feb-1997   Created.
//
//***************************************************************************

#include "precomp.h"
//#include <hmmsvc.h>
#include "mvbase.h"
#include "hmmvctl.h"
#include "mv.h"
#include "hmomutil.h"
#include "resource.h"
#include "PolyView.h"
#include "globals.h"


//========================================================
// EVENT HANDLING
//========================================================

BEGIN_EVENTSINK_MAP(CMultiView, CMultiViewBase)
    //{{AFX_EVENTSINK_MAP(CMultiView)
	ON_EVENT_REFLECT(CMultiView, 1 /* NotifyViewModified */, OnNotifyViewModified, VTS_NONE)
	ON_EVENT_REFLECT(CMultiView, 2 /* NotifySelectionChanged */, OnNotifySelectionChanged, VTS_NONE)
	ON_EVENT_REFLECT(CMultiView, 3 /* NotifySaveRequired */, OnNotifySaveRequired, VTS_NONE)
	ON_EVENT_REFLECT(CMultiView, 4 /* NotifyViewObjectSelected */, OnNotifyViewObjectSelected, VTS_BSTR)
	ON_EVENT_REFLECT(CMultiView, 5 /* GetIWbemServices */, OnGetIWbemServices, VTS_BSTR VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT)
	ON_EVENT_REFLECT(CMultiView, 6 /* NotifyContextChanged */, OnNotifyContextChanged, VTS_I4)
	ON_EVENT_REFLECT(CMultiView, 7 /* RequestUIActive */, OnRequestUIActive, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()




//*********************************************************************
// CMultiView::CMultiView
//
// Constructor for the multiview control,
//
// Parameters:
//		[in] CWBEMViewContainerCtrl* phmmv
//			Pointer to the view container.
//
// Returns:
//		Nothing.
//
//*********************************************************************
CMultiView::CMultiView(CWBEMViewContainerCtrl* phmmv)
{
	m_phmmv = phmmv;
}

SCODE CMultiView::GetCurrentObjectPath(CString& sPath)
{

	long lPos =  StartObjectEnumeration(OBJECT_CURRENT);
	if (lPos >= 0) {
		sPath = GetObjectPath(lPos);
		return S_OK;
	}
	return E_FAIL;
}


void CMultiView::OnNotifyViewModified()
{
}

void CMultiView::OnNotifySelectionChanged()
{
	m_phmmv->UpdateToolbar();

}

void CMultiView::OnNotifySaveRequired()
{
	m_phmmv->NotifyDataChange();
}


void CMultiView::OnNotifyViewObjectSelected(LPCTSTR szObjectPath)
{
	//if path is empty, display an error message and stay in multiview
	if (_tcslen(szObjectPath) == 0) {
		CString msg;
		msg.LoadString(IDS_NO_PATH);
		HmmvMessageBox(m_phmmv, msg, MB_OK);
		return;
	}
	m_phmmv->JumpToObjectPathFromMultiview(szObjectPath, FALSE, FALSE);
	m_phmmv->PushView();

}



void CMultiView::OnNotifyContextChanged(long bPushContext)
{
	m_phmmv->UpdateViewContext();
	if (bPushContext) {
		m_phmmv->PushView();
	}
}


void CMultiView::OnGetIWbemServices
(LPCTSTR lpctstrNamespace, VARIANT FAR* pvarUpdatePointer, VARIANT FAR* pvarServices, VARIANT FAR* pvarSC, VARIANT FAR* pvarUserCancel)
{
	m_phmmv->PassThroughGetIHmmServices
		(lpctstrNamespace, pvarUpdatePointer, pvarServices, pvarSC, pvarUserCancel);

}




void CMultiView::OnRequestUIActive()
{
	// TODO: Add your control notification handler code here
	m_phmmv->RequestUIActive();
}