//------------------------------------------------------------------------------
// $Workfile: ShapesDoc.cpp $
// $Header: /SbjDev/Shapes/ShapesDoc.cpp 5 11/24/08 10:33a Steve $
//
// Copyright � 2008 SbjCat
// All rights reserved.
//
//
// *** Authors ***
// Steve Johnson
//
// $Revision: 5 $
//
//-----------------------------------------------------------------------------
#include "stdafx.h"
#include "Shapes.h"
#include "ShapesDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
namespace localNS
{
// Message Handlers /////////////////////////////////////////////////////////////////
class InsertShapeHandler : public SbjCore::Mvc::CmdMsgHandler
{
CString sShapeType;
public:
InsertShapeHandler(LPCTSTR lpszShapeType) :
sShapeType(lpszShapeType)
{
}
private:
virtual bool OnHandleCmd(UINT nID)
{
nID;
bool bRslt = false;
SbjCore::Mvc::Model::Controller* pModelCtrlr = dynamic_cast<SbjCore::Mvc::Model::Controller*>(GetController());
SbjCore::Mvc::Model::ItemHandles theItems;
int nCount = pModelCtrlr->GetItemChildren(SbjCore::Mvc::Model::Controller::GetItemRoot(), theItems);
if (1 == nCount)
{
HANDLE hDrawing = theItems[0];
HANDLE hItem = pModelCtrlr->CreateItem(sShapeType);
if (hItem != NULL)
{
CString sFmt;
sFmt.Format(_T("New %s"), sShapeType);
CString sLabel(pModelCtrlr->AssureUniqueItemAttrValue(hDrawing, _T("label"), (LPCTSTR)sFmt));
(void)pModelCtrlr->SetItemAttrValue( hItem, _T("label"), (LPCTSTR)sLabel);
DWORD dw = ::GetMessagePos();
CPoint pt(GET_X_LPARAM((LPARAM)dw), GET_Y_LPARAM((LPARAM)dw));
CWnd* pWnd = CWnd::FromHandle(GetFocus());
pWnd->ScreenToClient(&pt);
CRect r(pt.x, pt.y, pt.x + 350, pt.y + 200);
SbjCore::Mvc::Model::Rect::SetItemValue(pModelCtrlr, hItem, r);
(void)pModelCtrlr->SetItemAttrValue( hItem, _T("borderRGB"), RGB(0,0,0));
(void)pModelCtrlr->SetItemAttrValue( hItem, _T("borderWidth"), 5);
(void)pModelCtrlr->SetItemAttrValue( hItem, _T("fillRGB"), RGB(255,255,255));
bRslt = pModelCtrlr->InsertChild(hItem, hDrawing, NULL);
}
}
return bRslt;
}
virtual bool OnHandleCmdUI(CCmdUI* pCmdUI)
{
bool bRslt = true;
pCmdUI->Enable(true);
return bRslt;
};
};
}
struct ShapesDocImpl : public XmlMvc::XmlDoc::Controller
{
HANDLE hDrawing;
localNS::InsertShapeHandler theInsertRectangleHandler;
localNS::InsertShapeHandler theInsertEllipseHandler;
ShapesDocImpl() :
hDrawing(NULL),
theInsertRectangleHandler(_T("Rectangle")),
theInsertEllipseHandler(_T("Ellipse"))
{
SetDocElementName(_T("Shapes"));
AddHandler(ID_CMDS_NEWRECTANGLE, &theInsertRectangleHandler);
AddHandler(ID_CMDS_NEWELLIPSE, &theInsertEllipseHandler);
}
virtual ~ShapesDocImpl()
{
}
virtual BOOL OnNewDocument()
{
XmlMvc::XmlDoc::Controller::OnNewDocument();
HANDLE hItem = CreateItem(_T("Drawing"));
SetItemAttrValue(hItem, _T("name"), _T("New Drawing"));
BOOL bRslt = InsertChild(hItem, SbjCore::Mvc::Model::Controller::GetItemRoot(), NULL, false);
SbjCore::Mvc::Doc::Events::DocModified event(false);
return bRslt;
}
};
///////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(ShapesDoc, t_Base)
BEGIN_MESSAGE_MAP(ShapesDoc, t_Base)
END_MESSAGE_MAP()
ShapesDoc::ShapesDoc() :
m_pImpl(new ShapesDocImpl)
{
SetController(m_pImpl);
}
ShapesDoc::~ShapesDoc()
{
try
{
delete m_pImpl;
}
catch(...)
{
ASSERT(FALSE);
}
}
#ifdef _DEBUG
void ShapesDoc::AssertValid() const
{
t_Base::AssertValid();
}
void ShapesDoc::Dump(CDumpContext& dc) const
{
t_Base::Dump(dc);
}
#endif //_DEBUG
//*** Modification History ***
// $Log: /SbjDev/Shapes/ShapesDoc.cpp $
//
// 5 11/24/08 10:33a Steve
// Final changes before MVCChapt1 v2.0.1