|
//------------------------------------------------------------------------------
// $Workfile: PropMap.cpp $
// $Header: /SbjDev/SbjCore/PropMap.cpp 2 11/12/08 2:22p Steve $
//
// Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
// Steve Johnson
//
// $Revision: 2 $
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "PropMap.h"
#include "PropFactories.h"
#include "ModelController.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
namespace SbjCore
{
namespace Mvc
{
namespace PropGrid
{
struct PropMapImpl
{
CMFCPropertyGridCtrl* pTheGrid;
typedef std::map<CString, PropFactory*> PropFactoryMap;
PropFactoryMap thePropFactoryMap;
typedef std::map<CString, CMFCPropertyGridProperty*> PropertyMap;
PropertyMap thePropMap;
HANDLE hItem;
PropMapImpl() :
pTheGrid(NULL),
hItem(NULL)
{
}
virtual ~PropMapImpl()
{
thePropFactoryMap.clear();
thePropMap.clear();
}
void OnLoadPropGrid(HANDLE h)
{
pTheGrid->RemoveAll();
hItem = h;
SbjCore::Mvc::Model::Controller* pTheModelCtrlr = SbjCore::Mvc::Model::GetCurController();
SbjCore::Mvc::Model::ItemAttrNames attrNames;
pTheModelCtrlr->GetItemAttrNames(hItem, attrNames);
int nIndex = 0;
for (SbjCore::Mvc::Model::ItemAttrNamesIter iter = attrNames.begin(); iter != attrNames.end(); iter++)
{
CMFCPropertyGridProperty* pProp = NULL;
CString sAttrName(*iter);
COleVariant val = pTheModelCtrlr->GetItemAttrValue(hItem, sAttrName);
PropFactory* pPropFactory = thePropFactoryMap[sAttrName];
if (pPropFactory != NULL)
{
pProp = pPropFactory->CreateProp(sAttrName, nIndex, val);
}
else
{
PropFactory theProp;
pProp = theProp.CreateProp(sAttrName, nIndex, val);
}
if (pProp != NULL)
{
thePropMap[sAttrName] = pProp;
pTheGrid->AddProperty(pProp); // note: pGrid takes ownership and deletes
}
nIndex++;
}
}
void OnUpdate(HANDLE h)
{
hItem = h;
SbjCore::Mvc::Model::Controller* pTheModelCtrlr = SbjCore::Mvc::Model::GetCurController();
SbjCore::Mvc::Model::ItemAttrNames attrNames;
pTheModelCtrlr->GetItemAttrNames(hItem, attrNames);
for (SbjCore::Mvc::Model::ItemAttrNamesIter iter = attrNames.begin(); iter != attrNames.end(); iter++)
{
CString sAttrName(*iter);
CMFCPropertyGridProperty* pProp = thePropMap[sAttrName];
if (pProp != NULL)
{
pProp->SetValue(pTheModelCtrlr->GetItemAttrValue(hItem, sAttrName));
COleVariant v = pProp->GetValue();
pProp->SetOriginalValue(v);
}
}
}
};
/////////////////////////////////////////////////////////
PropMap::PropMap() :
m_pImpl(new PropMapImpl)
{
}
PropMap::~PropMap()
{
try
{
delete m_pImpl;
}
catch(...)
{
ASSERT(FALSE);
}
}
void PropMap::AddProp( LPCTSTR lpszAttrName, PropFactory* pProp )
{
m_pImpl->thePropFactoryMap[lpszAttrName] = pProp;
}
PropFactory* PropMap::GetProp( LPCTSTR lpszAttrName ) const
{
return m_pImpl->thePropFactoryMap[lpszAttrName];
}
void PropMap::LoadPropGrid(HANDLE hItem)
{
OnLoadPropGrid(hItem);
}
void PropMap::Update(HANDLE hItem)
{
OnUpdate(hItem);
}
void PropMap::OnLoadPropGrid(HANDLE hItem)
{
m_pImpl->OnLoadPropGrid(hItem);
}
void PropMap::OnUpdate(HANDLE hItem)
{
m_pImpl->OnUpdate(hItem);
}
void PropMap::SetPropGridCtrl( CMFCPropertyGridCtrl* pGrid )
{
m_pImpl->pTheGrid = pGrid;
}
CMFCPropertyGridCtrl* PropMap::GetPropGridCtrl() const
{
return m_pImpl->pTheGrid;
}
HANDLE PropMap::GetModelItemHandle() const
{
return m_pImpl->hItem;
}
}
}
}
//*** Modification History ***
// $Log: /SbjDev/SbjCore/PropMap.cpp $
//
// 2 11/12/08 2:22p Steve
// Finished Generalization of Model v2.0.1
//
// 1 10/29/08 3:36p Steve
//
// 4 10/14/08 1:12p Steve
// Implemented Deletes
|
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.
Real name is Steve Johnson. Programming since 1979. Started on a Heathkit Micro with a DEC LSI-11 and UCSD Pascal. Moved to PCs & DOS as soon as Turbo Pascal became available. Did some Assembly, ISR, TSR etc. All this while working for a Manufacturing Co. for 8 years. Had my own solo Co. doing barcode labeling software for 4 years (terrible business man, all I wanted to do was code). Since then working for various software companies. Moved to Windows around the time of 3.1 with Borland C then C++. Then on to VC++ and MFC, and just about anything I could get my hands on or had to learn for my job, and been at it ever since. Of course recently I've been playing with .NET, ASP, C#, WPF etc.