EVENTS.CPP

// This is a part of the Microsoft Management Console. 
// Copyright 1995 - 1997 Microsoft Corporation
// All rights reserved.
//
// This source code is only intended as a supplement to the
// Microsoft Management Console and related
// electronic documentation provided with the interfaces.

#include "stdafx.h"
#include "Service.h"
#include "CSnapin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

// Primary Data
RESULT_DATA StaticRootData[NUM_NAMES] =
{
{RESULT_ITEM, USER, L"Bill", L"990", L"CEO"},
{RESULT_ITEM, USER, L"Jill", L"991", L"Director"},
{RESULT_ITEM, USER, L"Hill", L"992", L"President"},
{RESULT_ITEM, USER, L"Will", L"993", L"Chairman"},
};

RESULT_DATA UserData[NUM_NAMES] =
{
{RESULT_ITEM, USER, L"Joe", L"100", L"Employee"},
{RESULT_ITEM, USER, L"Harry", L"101", L"Manager"},
{RESULT_ITEM, USER, L"Jane", L"102", L"Vice President"},
{RESULT_ITEM, USER, L"Sue", L"103", L"Developer"},
};

RESULT_DATA CompanyData[NUM_COMPANY] =
{
{RESULT_ITEM, COMPANY, L"Taxes", L"43", L"IRS Documents"},
{RESULT_ITEM, COMPANY, L"Medical", L"345", L"HMO"},
{RESULT_ITEM, COMPANY, L"Dental", L"121", L"Plus Plan"},
{RESULT_ITEM, COMPANY, L"Insurance", L"2332", L"Dollars are Us"},
{RESULT_ITEM, COMPANY, L"401K", L"1000", L"Up to you"},
{RESULT_ITEM, COMPANY, L"Legal", L"78", L"Yes"}
};

// Extension data
RESULT_DATA UserDataExt[NUM_NAMES] =
{
{RESULT_ITEM, EXT_USER, L"Charles", L"200", L"Employee"},
{RESULT_ITEM, EXT_USER, L"Jill", L"201", L"Manager"},
{RESULT_ITEM, EXT_USER, L"John", L"202", L"Vice President"},
{RESULT_ITEM, EXT_USER, L"Tami", L"203", L"Developer"},
};

RESULT_DATA CompanyDataExt[NUM_COMPANY] =
{
{RESULT_ITEM, EXT_COMPANY, L"Payroll", L"99", L"Corporate Payroll"},
{RESULT_ITEM, EXT_COMPANY, L"Health", L"568", L"HMO"},
{RESULT_ITEM, EXT_COMPANY, L"Health Club", L"834", L"Plus Plan"},
{RESULT_ITEM, EXT_COMPANY, L"Insurance", L"1101", L"Dollars are Us"},
{RESULT_ITEM, EXT_COMPANY, L"401K", L"1543", L"Up to you"},
{RESULT_ITEM, EXT_COMPANY, L"Legal", L"27", L"Yes"}
};

// We use a single structure for all virtual items, so
// the name field points to this buffer that is changed
// on the fly.
WCHAR VirtualItemName[MAX_ITEM_NAME];

RESULT_DATA VirtualData[1] =
{
{RESULT_ITEM, VIRTUAL, VirtualItemName, L"100", L"Virtual"}
};


/////////////////////////////////////////////////////////////////////////////
// Event handlers for IFrame::Notify

HRESULT CSnapin::OnFolder(long cookie, long arg, long param)
{
ASSERT(FALSE);

return S_OK;
}

HRESULT CSnapin::OnAddImages(long cookie, long arg, long param)
{
if (arg == 0)
return E_INVALIDARG;

// if cookie is from a different snapin
// if (IsMyCookie(cookie) == FALSE)
if (0)
{
// add the images for the scope tree only
::CBitmap bmp16x16;
::CBitmap bmp32x32;
LPIMAGELIST lpImageList = reinterpret_cast<LPIMAGELIST>(arg);

// Load the bitmaps from the dll
bmp16x16.LoadBitmap(IDB_16x16);
bmp32x32.LoadBitmap(IDB_32x32);

// Set the images
lpImageList->ImageListSetStrip(
reinterpret_cast<long*>(static_cast<HBITMAP>(bmp16x16)),
reinterpret_cast<long*>(static_cast<HBITMAP>(bmp32x32)),
0, RGB(255, 0, 255));

lpImageList->Release();
}
else
{
InitializeBitmaps(cookie);
}
return S_OK;
}

HRESULT CSnapin::OnShow(long cookie, long arg, long param)
{
// Note - arg is TRUE when it is time to enumerate
if (arg == TRUE)
{
// if list view on display
if (m_CustomViewID == VIEW_DEFAULT_LV)
{
// Show the headers for this nodetype
InitializeHeaders(cookie);
Enumerate(cookie, param);
}
// BUBBUG - Demonstration to should how you can attach
// and a toolbar when a particular nodes gets focus.
// warning this needs to be here as the toolbars are
// currently hidden when the previous node looses focus.
// This should be update to show the user how to hide
// and show toolbars. (Detach and Attach).

//m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar1);
//m_pControlbar->Attach(TOOLBAR, (LPUNKNOWN) m_pToolbar2);
}
else
{

// BUGBUG - Demonstration this to show how to hide toolbars that
// could be particular to a single node.
// currently this is used to hide the toolbars the console
// does not do any toolbar clean up.

//m_pControlbar->Detach(m_pToolbar1);
//m_pControlbar->Detach(m_pToolbar2);
// Free data associated with the result pane items, because
// your node is no longer being displayed.
// Note: The console will remove the items from the result pane
}

return S_OK;
}

HRESULT CSnapin::OnActivate(long cookie, long arg, long param)
{
return S_OK;
}

HRESULT CSnapin::OnResultItemClk(DATA_OBJECT_TYPES type, long cookie)
{
RESULT_DATA* pResult;

if (m_bVirtualView == TRUE)
{
pResult = GetVirtualResultItem(cookie);
}
else if (cookie != 0)
{
DWORD* pdw = reinterpret_cast<DWORD*>(cookie);
if (*pdw == RESULT_ITEM)
{
pResult = reinterpret_cast<RESULT_DATA*>(cookie);
}
}

return S_OK;
}

HRESULT CSnapin::OnMinimize(long cookie, long arg, long param)
{
return S_OK;
}

HRESULT CSnapin::OnPropertyChange(LPDATAOBJECT lpDataObject)
{

return S_OK;
}

HRESULT CSnapin::OnUpdateView(LPDATAOBJECT lpDataObject)
{
return S_OK;
}

void CSnapin::Enumerate(long cookie, HSCOPEITEM pParent)
{
EnumerateResultPane(cookie);
}

void CSnapin::EnumerateResultPane(long cookie)
{
ASSERT(m_pResult != NULL); // make sure we QI'ed for the interface
ASSERT(m_pComponentData != NULL);

// Our static folders must be displayed in the result pane
// by use because the console doesn't do it.
CFolder* pFolder = dynamic_cast<CComponentDataImpl*>(m_pComponentData)->FindObject(cookie);

// The dynamic folder must be in our list
ASSERT(pFolder != NULL);

FOLDER_TYPES type = pFolder->GetType();

switch(type)
{
case STATIC:
AddResultItems(&StaticRootData[0], NUM_NAMES, 4);
break;

case COMPANY:
AddCompany();
break;

case USER:
AddUser();
break;

case EXT_USER:
AddExtUser();
break;

case EXT_COMPANY:
AddExtCompany();
break;

case VIRTUAL:
case EXT_VIRTUAL:
AddVirtual();
break;

default:
break;
}
}

void CSnapin::AddResultItems(RESULT_DATA* pData, int nCount, int imageIndex)
{
ASSERT(m_pResult);

RESULTDATAITEM resultItem;
memset(&resultItem, 0, sizeof(RESULTDATAITEM));

for (int i=0; i < nCount; i++)
{
resultItem.mask = RDI_STR | RDI_IMAGE | RDI_PARAM;
resultItem.str = MMC_CALLBACK;
resultItem.nImage = imageIndex;
resultItem.lParam = reinterpret_cast<LPARAM>(pData + i);
m_pResult->InsertItem(&resultItem);
}

m_pResult->Sort(0,0,-1);

}

void CSnapin::AddUser()
{
AddResultItems(&UserData[0], NUM_NAMES, 4);
}

void CSnapin::AddCompany()
{
AddResultItems(&CompanyData[0], NUM_COMPANY, 3);
}

void CSnapin::AddExtUser()
{
AddResultItems(&UserDataExt[0], NUM_NAMES, 4);
}

void CSnapin::AddExtCompany()
{
AddResultItems(&CompanyDataExt[0], NUM_COMPANY, 3);
}

void CSnapin::AddVirtual()
{
// for virtual data, just set the item count
m_pResult->SetItemCount(NUM_VIRTUAL_ITEMS, MMCLV_UPDATE_NOINVALIDATEALL);
}


RESULT_DATA* CSnapin::GetVirtualResultItem(int iIndex)
{
// reverse order for descending sort
if (m_dwVirtualSortOptions & RSI_DESCENDING)
iIndex = (NUM_VIRTUAL_ITEMS - 1) - iIndex;

// Create a name from the index
swprintf(VirtualItemName, L"%d", iIndex);

// return pointer to the virtual result item
return &VirtualData[0];

}