//*******************************************************************************
// COPYRIGHT NOTES
// ---------------
// This source code is a part of Tangram library.
// You may use, compile or redistribute it as part of your application
// for free. You cannot redistribute it as a part of a software development
// library without the agreement of the author. If the sources are
// distributed along with the application, you should leave the original
// copyright notes in the source code without any changes.
// This code can be used WITHOUT ANY WARRANTIES on your own risk.
//
// For the latest updates to this library, check site:
// http://www.tangramdev.com
//
// sunhui
//*******************************************************************************
// TangramObject.cpp: implementation of the CTangramObject class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "TabWnd.h"
#include "TangramDocCntrItem.h"
#include "TangramCntrItem.h"
#include "TangramDesignView.h"
#include "TangramObject.h"
#include "TangramServerObj.h"
//#include "DockingTangramBar.h"
#include "tangramDoc.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
extern CTangramServerObj* g_pTangramServer;
extern void SetResource();
#define IMPLTYPE_FDEFAULTSOURCE (IMPLTYPEFLAG_FSOURCE | IMPLTYPEFLAG_FDEFAULT)
#define IMPLTYPE_MASK (0x1 | 0x2 | 0x4 | 0x8)
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CTangramObject, CObject, 0)
CTangramObject::CTangramObject()
{
m_pMfcObj = NULL;
m_pWnd = NULL;
hComWnd = NULL;
m_pDisp = NULL;
m_pApcDisp = NULL;
bDefineRegist=false;
isRegist = false;
isDocking = false;
m_bHooked = false;
m_pConObj = NULL;
m_pDocCntrItem = NULL;
m_pObjCntrItem= NULL;
m_pParentObject = NULL;
m_strName = COleDateTime::GetCurrentTime().Format();
CString strID2 = "";
strID2.Format("%x",this);
m_strName += strID2;
m_ContainerType = UnknowType;
m_TangramObjType = Unknow;
m_Size.cx = 0;
m_Size.cy = 0;
m_SizeMin.cx = 0;
m_SizeMin.cy = 0;
m_nRowIndex = 0; // Splitter view: row index
m_nColIndex = 0; // Splitter view: column index
m_nRows = 0; // Splitters: number of rows
m_nCols = 0; // Splitters: number of columns
m_strTitle = _T("");
m_strExternalObjID = _T("");
InnerDoc = true;
m_ChildObjectMap.RemoveAll();
g_pTangramServer->m_pCurTangramObj = this;
}
CTangramObject::~CTangramObject()
{
int nObjCount = m_ChildObjectMap.GetSize();
if(nObjCount)
{
for(int i = 0; i < nObjCount; i++)
delete m_ChildObjectMap[i];
}
m_ChildObjectMap.RemoveAll();
m_ObArray.RemoveAll();
if(m_pConObj)
{
delete m_pConObj;
}
if(m_TangramObjType==ComWnd)
{
if(m_pDisp)
{
//m_pDisp->Release();
//delete m_pDisp;
}
}
if(m_ContainerType==Splitter||m_ContainerType==Board)
{
if(m_pWnd&&::IsWindow(m_pWnd->m_hWnd))
m_pWnd->DestroyWindow();
delete m_pWnd;
}
}
void CTangramObject::Serialize(CArchive& ar)
{
int nObjCount = m_ChildObjectMap.GetSize();
if(nObjCount>0)
for(int i = 0; i < nObjCount; i++)
m_ObArray.SetAtGrow(i,m_ChildObjectMap[i]);
if(m_pWnd&&::IsWindow(m_pWnd->m_hWnd))
{
CWnd* m_pParent = m_pWnd->GetParent();
if(m_pParent->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
{
CSplitterWnd* pSplitter = (CSplitterWnd*)m_pParent;
pSplitter->IsChildPane(m_pWnd,&m_nRowIndex,&m_nColIndex);
int nX,nMinX,nY,nMinY;
pSplitter->GetRowInfo(m_nRowIndex,nY,nMinY);
m_Size.cy = nY;
m_SizeMin.cy = nMinY;
pSplitter->GetColumnInfo(m_nColIndex,nX,nMinX);
m_Size.cx = nX;
m_SizeMin.cx = nMinX;
}
if(m_pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
{
m_nRows = ((CSplitterWnd*)m_pWnd)->GetRowCount();
m_nCols = ((CSplitterWnd*)m_pWnd)->GetColumnCount();
}
}
if (ar.IsStoring())
{
if(m_TangramObjType==MfcView||m_TangramObjType==MfcWnd)
{
CString strIndex="";
int nPos = -1;
nPos = m_strObjID.Find(_T("."));
if(nPos>=0)
strIndex = m_strObjID.Left(nPos);
strIndex.MakeLower();
if(m_strExternalCnn==_T(""))
m_strExternalCnn = g_pTangramServer->m_pCurDoc->m_CnnDictionary[LPCTSTR(strIndex)];
}
ar << m_strObjName;
ar << m_strName;
ar << m_ContainerType;
// ar << m_VbaObjType;
ar << m_nRowIndex;
ar << m_nColIndex;
ar << m_Size.cx;
ar << m_Size.cy; // Splitter: initial size
ar << m_SizeMin.cx;
ar << m_SizeMin.cy; // Splitter: initial size
ar << m_strTitle; // Title of this window
ar << m_nRows; // Splitters: number of rows
ar << m_nCols; // Splitters: number of columns
ar << uiImageId;
ar << m_TangramObjType;
// ar << m_CtrlID;
ar << m_strExternalCnn;
ar << m_strObjID;
ar << isDocking;
ar << m_strExternalObjID;
ar << InnerDoc;
}
else
{
ar >> m_strObjName;
if(m_strObjName!=_T(""))
{
CTangramDoc* m_pDoc = g_pTangramServer->m_pCurDoc;
m_pDoc->m_TangramObjectDictionary[m_strObjName] = this;
}
ar >> m_strName;
int nType;
ar >> nType;
m_ContainerType = (ContainerType)nType;
//ar >> nType;
//m_VbaObjType = (VbaObjType)nType;
ar >> m_nRowIndex;
ar >> m_nColIndex;
ar >> m_Size.cx;
//TRACE("���:%d\n",m_Size.cx);
ar >> m_Size.cy; // Splitter: initial size
//TRACE("�߶�:%d\n",m_Size.cy);
ar >> m_SizeMin.cx;
ar >> m_SizeMin.cy; // Splitter: initial size
ar >> m_strTitle; // Title of this window
ar >> m_nRows; // Splitters: number of rows
//TRACE("����:%d\n",m_nRows);
ar >> m_nCols; // Splitters: number of columns
//TRACE("����:%d\n",m_nCols);
//ar >> TopLevelID;
ar >> uiImageId;
ar >> nType;
m_TangramObjType = (TangramObjType)nType;
//ar >> m_CtrlID;
ar >> m_strExternalCnn;
//������������Ϣ���ӣ�
if(m_strExternalCnn!=_T(""))
g_pTangramServer->m_pCurDoc->m_pDocDisp->ConnectExternalLib(m_strExternalCnn);
ar >> m_strObjID;
CRuntimeClass *pMfcObjInfo = NULL;
CRuntimeClass *pMfcConnectObjInfo = NULL;
if(m_ContainerType==UnknowType&&(m_TangramObjType==MfcView||m_TangramObjType==MfcWnd))
{
if(g_pTangramServer->m_MfcObjInfoDictionary.Lookup(LPCTSTR(m_strObjID),(void *&)pMfcObjInfo)==TRUE)
{
m_pRuntimeClass = pMfcObjInfo;
if(g_pTangramServer->m_MfcConnectObjInfoDictionary.Lookup(LPCTSTR(m_strObjID),(void *&)pMfcConnectObjInfo)==TRUE)
{
m_pConObj = (CConnectObj*)pMfcConnectObjInfo->CreateObject();
m_pConObj->m_pContext = &g_pTangramServer->m_pCurDoc->m_Context;
m_pConObj->m_pObjExtManager = g_pTangramServer->m_pObjExtManager;
}
}
}
ar >> isDocking;
ar >> m_strExternalObjID;
ar >> InnerDoc;
}
if(m_pConObj&&m_ContainerType==UnknowType&&(m_TangramObjType==MfcView||m_TangramObjType==MfcWnd))
{
if(m_pConObj&&m_pConObj->m_DataObArray.GetSize()>0)
m_pConObj->m_DataObArray.Serialize(ar);
}
if(m_ContainerType==UnknowType&&(m_TangramObjType==MfcView||m_TangramObjType==MfcWnd))
{
if(m_TangramObjType==MfcView)
g_pTangramServer->m_pCurView = (CView*)m_pWnd;
m_DataObArray.Serialize(ar);
}
m_ObArray.Serialize(ar);
if(ar.IsStoring()==false)
{
nObjCount = m_ObArray.GetSize();
if(nObjCount)
for(int i = 0; i < nObjCount; i++)
{
CTangramObject* m_pTmpObj = (CTangramObject*)m_ObArray[i];
m_pTmpObj->m_pParentObject = this;
m_ChildObjectMap.SetAtGrow(i,m_pTmpObj);
}
}
}
void CTangramObject::Create()
{
g_pTangramServer->m_pCurTangramObj = this;
SetResource();
if(m_pDocCntrItem&&m_pDocCntrItem->m_pTangramWindow)
m_pDocCntrItem->m_pTangramWindow->IniContainer(true);
int dwStyle = AFX_WS_DEFAULT_VIEW;
CTangramDockingObjImpl* m_pDockingBarObj = NULL;
if(isDocking)
{
m_pDockingBarObj = (CTangramDockingObjImpl*)g_pTangramServer->m_pTangramDockingBarRuntimeClass->CreateObject();
m_pDockingBarObj->SetTangramObj(this);
}
CFrameWnd *pFrame = g_pTangramServer->m_pCurFrame;
if(g_pTangramServer->m_pCurDoc->m_bMainDoc)pFrame = pFrame->GetParentFrame();
CRect rc;
switch(m_ContainerType)
{
case Splitter:
{
CSplitterWnd* m_pSplitter = new CSplitterWnd();
m_pWnd = m_pSplitter;
if(isDocking)
{
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
m_pSplitter->CreateStatic(pDockFrame, m_nRows, m_nCols);
}
else if(!m_pParentObject)
g_pTangramServer->m_bMDI?m_pSplitter->CreateStatic(g_pTangramServer->m_pCurFrame, m_nRows, m_nCols):m_pSplitter->CreateStatic(g_pTangramServer->m_pSDIFrame, m_nRows, m_nCols);
else if(m_pParentObject->m_ContainerType==Splitter)
{
UINT nID = ((CSplitterWnd*)m_pParentObject->m_pWnd)->IdFromRowCol(m_nRowIndex,m_nColIndex);
m_pSplitter->CreateStatic(m_pParentObject->m_pWnd, m_nRows, m_nCols, WS_CHILD | WS_VISIBLE | WS_BORDER, nID);
((CSplitterWnd*)m_pParentObject->m_pWnd)->SetColumnInfo(m_nColIndex,m_Size.cx,m_SizeMin.cx);
((CSplitterWnd*)m_pParentObject->m_pWnd)->SetRowInfo(m_nRowIndex,m_Size.cy,m_SizeMin.cy);
}
else if(m_pParentObject->m_ContainerType==Board)
m_pSplitter->CreateStatic(m_pParentObject->m_pWnd, m_nRows, m_nCols, WS_CHILD | WS_VISIBLE | WS_BORDER, (UINT)this);
}
break;
case Board:
{
g_pTangramServer->m_pCurDoc->m_bAutoDelete = FALSE;
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pDocCntrItem->m_pWnd;;
m_pTabWnd -> m_pOleItem = m_pDocCntrItem;
m_pWnd = m_pTabWnd;
g_pTangramServer->m_bMDI?g_pTangramServer->m_pCurFrame->GetClientRect(&rc):g_pTangramServer->m_pSDIFrame->GetClientRect(&rc);
if(isDocking)
{
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
pDockFrame->ModifyStyleEx(WS_EX_CLIENTEDGE,0);
((CWnd*)m_pTabWnd)->Create(NULL, _T(""), WS_CHILD|WS_VISIBLE, rc, pDockFrame, AFX_IDW_PANE_FIRST,&(g_pTangramServer->m_pCurDoc->m_Context));
ASSERT(::IsWindow(m_pTabWnd->m_hWnd));
}
else if(!m_pParentObject)
{
if (!((CWnd*)m_pTabWnd)->Create(NULL, NULL, dwStyle, rc, pFrame, AFX_IDW_PANE_FIRST, &g_pTangramServer->m_pCurDoc->m_Context))//&g_pTangramServer->m_pCurDoc->m_Context
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
m_pTabWnd->ModifyStyle(WS_BORDER,0);
g_pTangramServer->m_bMDI?g_pTangramServer->m_pCurFrame->RecalcLayout():g_pTangramServer->m_pSDIFrame->RecalcLayout();
}
else
{
if(m_pParentObject->m_ContainerType==Splitter)
{
((CWnd*)m_pTabWnd)->Create(NULL, _T(""), WS_CHILD|WS_VISIBLE, rc, m_pParentObject->m_pWnd, AFX_IDW_PANE_FIRST, &g_pTangramServer->m_pCurDoc->m_Context);
::SetWindowLong(m_pTabWnd->m_hWnd,GWL_ID, ((CSplitterWnd*)m_pParentObject->m_pWnd)->IdFromRowCol(m_nRowIndex,m_nColIndex));
m_pTabWnd->ModifyStyle(WS_BORDER,0);
((CSplitterWnd*)m_pParentObject->m_pWnd)->SetColumnInfo(m_nColIndex,m_Size.cx,m_SizeMin.cx);
((CSplitterWnd*)m_pParentObject->m_pWnd)->SetRowInfo(m_nRowIndex,m_Size.cy,m_SizeMin.cy);
}
else if(m_pParentObject->m_ContainerType==Board)
{
if (!((CWnd*)m_pTabWnd)->Create(NULL, NULL, dwStyle, rc, m_pParentObject->m_pWnd, (UINT)this,&g_pTangramServer->m_pCurDoc->m_Context))//&g_pTangramServer->m_pCurDoc->m_Context
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
m_pTabWnd->ModifyStyle(WS_BORDER,0);
}
}
g_pTangramServer->m_pCurDoc->m_bAutoDelete = true;
}
break;
case UnknowType:
{
g_pTangramServer->m_pCurDoc->m_bAutoDelete = FALSE;
CView* m_pView=NULL;
switch(m_TangramObjType)
{
case Unknow:
case WebBrowser:
case WinCtrl:
if(isDocking)
{
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
g_pTangramServer->m_pCurDoc->m_Context.m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CView*)pDockFrame->CreateView(&g_pTangramServer->m_pCurDoc->m_Context);;
((CTangramDesignView*)m_pView)->m_pTangramObject = this;
m_pView->OnInitialUpdate();
}
else if(m_pParentObject==NULL)
{
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CView*)g_pTangramServer->m_pCurFrame->CreateView(pContext,AFX_IDW_PANE_FIRST);
((CTangramDesignView*)m_pView)->m_pTangramObject = this;
m_pView->OnInitialUpdate();
pFrame->RecalcLayout();
}
else if(m_pParentObject->m_ContainerType==Splitter)
{
((CSplitterWnd*)m_pParentObject->m_pWnd)->CreateView(m_nRowIndex, m_nColIndex, g_pTangramServer->m_pDesignViewRuntimeClass, m_Size,&(g_pTangramServer->m_pCurDoc->m_Context));
m_pView = (CView*)((CSplitterWnd*)m_pParentObject->m_pWnd)->GetPane(m_nRowIndex, m_nColIndex);
((CTangramDesignView*)m_pView)->m_pTangramObject = this;
((CTangramDesignView*)m_pView)->OnInitialUpdate();
}
else if(m_pParentObject&&m_pParentObject->m_ContainerType==Board)
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
CRect rect(0,0,100,100);
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CView*)pContext->m_pNewViewClass->CreateObject();
((CTangramDesignView*)m_pView)->m_pTangramObject = this;
if (!m_pView->Create(NULL, NULL, dwStyle, rect, m_pTabWnd, (UINT)this, pContext))
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
m_pView->ModifyStyle(WS_BORDER,0);
m_pTabWnd->AddTab(m_pView,m_strTitle,uiImageId);
m_pView->OnInitialUpdate();
m_pTabWnd->RecalcLayout();
}
m_pWnd = m_pView;
break;
case AxDoc:
case AxCtrl:
{
CTangramDesignView* m_pView = NULL;
if(isDocking)
{
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
g_pTangramServer->m_pCurDoc->m_Context.m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CTangramDesignView*)pDockFrame->CreateView(&g_pTangramServer->m_pCurDoc->m_Context);;
g_pTangramServer->m_pCurDoc -> m_TangramObjectArray[0] ->m_pWnd = m_pView;
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject==NULL)
{
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CTangramDesignView*)g_pTangramServer->m_pCurFrame->CreateView(pContext,AFX_IDW_PANE_FIRST);
}
else if(m_pParentObject->m_pWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
{
((CSplitterWnd*)m_pParentObject->m_pWnd)->CreateView(m_nRowIndex, m_nColIndex, g_pTangramServer->m_pDesignViewRuntimeClass, m_Size,&(g_pTangramServer->m_pCurDoc->m_Context));
m_pView = (CTangramDesignView*)((CSplitterWnd*)m_pParentObject->m_pWnd)->GetPane(m_nRowIndex, m_nColIndex);
}
else if(m_pParentObject&&m_pParentObject->m_ContainerType==Board) //ok!!
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
CRect rect(0,0,100,100);
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
m_pView = (CTangramDesignView*)pContext->m_pNewViewClass->CreateObject();
if (!m_pView->Create(NULL, NULL, dwStyle, rect, m_pTabWnd, (UINT)this, pContext))
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
}
m_pView->m_pTangramObject = this;
if(m_pObjCntrItem)
{
m_pView->m_pOleItem = m_pObjCntrItem;
m_pView->m_pOleItem->m_hParentWnd = m_pView->m_hWnd;
m_pView->m_pOleItem->GetCtrlWndHandle();
m_pView->m_pOleItem->m_pMfcView = m_pView;
m_pView->m_pOleItem->m_pView = m_pView;
}
//if(m_pView->m_pExternalDisp)
//{
//m_pView->m_pTangramObject->m_pDisp =m_pView->m_pExternalDisp;
//}
//m_pView->OnInitialUpdate();
m_pWnd = m_pView;
if(m_pParentObject&&m_pParentObject->m_ContainerType==Board)
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
m_pView->ModifyStyle(WS_BORDER,0);
m_pTabWnd->AddTab(m_pView,m_strTitle,uiImageId);
m_pTabWnd->RecalcLayout();
}
}
break;
case ComWnd:
{
CComPtr<IDispatch> pDisp;
pDisp.CoCreateInstance(m_strObjID.AllocSysString());
pDisp.p->AddRef();
m_pDisp = pDisp.p;
DISPID ObjectID;
DISPPARAMS dp = {NULL, NULL, 0, 0};
LPWSTR wszObject = OLESTR("GetWndHandle");
VARIANT vRet;
if (SUCCEEDED(pDisp->GetIDsOfNames(IID_NULL,&wszObject,1,LOCALE_NEUTRAL,&ObjectID)))
pDisp->Invoke(ObjectID,IID_NULL,LOCALE_NEUTRAL,DISPATCH_METHOD,&dp,&vRet,NULL,NULL);
hComWnd = (HWND)vRet.lVal;
}
if(isDocking)
{
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
g_pTangramServer->m_pCurDoc->m_Context.m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
CTangramDesignView* m_pViewWnd = (CTangramDesignView*)pDockFrame->CreateView(&g_pTangramServer->m_pCurDoc->m_Context);;
m_pWnd = m_pViewWnd;
m_pViewWnd->m_pTangramObject = this;
g_pTangramServer->m_pCurDoc -> m_TangramObjectArray[0] ->m_pWnd = m_pWnd;
if(hComWnd&&::IsWindow(hComWnd))
{
m_pViewWnd->hComWnd = hComWnd;
CWnd* pWnd = CWnd::FromHandle(hComWnd);
ASSERT(pWnd);
pWnd->ModifyStyle(WS_POPUP,WS_CHILD);
::SetParent(hComWnd,m_pWnd->m_hWnd);
pWnd->ShowWindow(SW_SHOW);
m_pWnd->GetWindowRect(&rc);
::MoveWindow(hComWnd,0,0,rc.Width(),rc.Height(),TRUE);
g_pTangramServer->ProcessDlgMsg(true,hComWnd);
}
m_pViewWnd->OnInitialUpdate();
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject==NULL)
{
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
CTangramDesignView* m_pViewWnd = (CTangramDesignView*)g_pTangramServer->m_pCurFrame->CreateView(pContext,AFX_IDW_PANE_FIRST);
m_pWnd = m_pViewWnd;
m_pViewWnd->m_pTangramObject = this;
g_pTangramServer->m_pCurDoc -> m_TangramObjectArray[0] ->m_pWnd = m_pWnd;
if(hComWnd&&::IsWindow(hComWnd))
{
m_pViewWnd->hComWnd = hComWnd;
CWnd* pWnd = CWnd::FromHandle(hComWnd);
ASSERT(pWnd);
pWnd->ModifyStyle(WS_POPUP,WS_CHILD);
::SetParent(hComWnd,m_pWnd->m_hWnd);
pWnd->ShowWindow(SW_SHOW);
m_pWnd->GetWindowRect(&rc);
::MoveWindow(hComWnd,0,0,rc.Width(),rc.Height(),TRUE);
g_pTangramServer->ProcessDlgMsg(true,hComWnd);
}
m_pViewWnd->OnInitialUpdate();
pFrame->RecalcLayout();
}
else if(m_pParentObject->m_ContainerType==Splitter)
{
((CSplitterWnd*)m_pParentObject->m_pWnd)->CreateView(m_nRowIndex, m_nColIndex, g_pTangramServer->m_pDesignViewRuntimeClass, m_Size,&(g_pTangramServer->m_pCurDoc->m_Context));
CTangramDesignView* pNewView = (CTangramDesignView*)((CSplitterWnd*)m_pParentObject->m_pWnd)->GetPane(m_nRowIndex, m_nColIndex);
pNewView->m_pTangramObject = this;
if(hComWnd&&::IsWindow(hComWnd))
{
pNewView->hComWnd = hComWnd;
CWnd* pWnd = CWnd::FromHandle(hComWnd);
ASSERT(pWnd);
pWnd->ModifyStyle(WS_POPUP,WS_CHILD);
::SetParent(hComWnd,pNewView->m_hWnd);
pWnd->ShowWindow(SW_SHOW);
m_pWnd->GetWindowRect(&rc);
::MoveWindow(hComWnd,0,0,rc.Width(),rc.Height(),TRUE);
g_pTangramServer->ProcessDlgMsg(true,hComWnd);
}
m_pWnd = pNewView;
}
else if(m_pParentObject&&m_pParentObject->m_ContainerType==Board) //ok!!
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
CRect rect(0,0,100,100);
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = g_pTangramServer->m_pDesignViewRuntimeClass;
CTangramDesignView* m_pView = (CTangramDesignView*)pContext->m_pNewViewClass->CreateObject();
m_pView->m_pTangramObject = this;
m_pView->m_pTangramObject->m_pWnd=m_pView;
if (!m_pView->Create(NULL, NULL, dwStyle, rect, m_pTabWnd, (UINT)this, pContext))//pContext
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
m_pView->ModifyStyle(WS_BORDER,0);
if(hComWnd&&::IsWindow(hComWnd))
{
m_pView->hComWnd = hComWnd;
CWnd* pWnd = CWnd::FromHandle(hComWnd);
ASSERT(pWnd);
pWnd->ModifyStyle(WS_POPUP,WS_CHILD);
::SetParent(hComWnd,m_pView->m_hWnd);
pWnd->ShowWindow(SW_SHOW);
m_pWnd->GetWindowRect(&rc);
::MoveWindow(hComWnd,0,0,rc.Width(),rc.Height(),TRUE);
g_pTangramServer->ProcessDlgMsg(true,hComWnd);
}
m_pView->OnInitialUpdate();
m_pTabWnd->AddTab(m_pView,m_strTitle,uiImageId);
m_pTabWnd->RecalcLayout();
}
break;
case MfcView:
{
g_pTangramServer->m_pCurTangramObj = this;
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = m_pRuntimeClass;
if(isDocking)
{
CFrameWnd* pDockFrame = m_pDockingBarObj->CreateDockingFrame(m_strTitle,pFrame);
m_pView = (CView*)pDockFrame->CreateView(pContext);
m_pView->OnInitialUpdate();
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject==NULL)
{
m_pView = (CView*)g_pTangramServer->m_pCurFrame->CreateView(pContext,AFX_IDW_PANE_FIRST);
m_pView->OnInitialUpdate();
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject->m_ContainerType==Splitter)
{
((CSplitterWnd*)m_pParentObject->m_pWnd)->CreateView(m_nRowIndex, m_nColIndex, m_pRuntimeClass, m_Size,&(g_pTangramServer->m_pCurDoc->m_Context));
m_pView = (CView*)((CSplitterWnd*)m_pParentObject->m_pWnd)->GetPane(m_nRowIndex, m_nColIndex);
m_pView->OnInitialUpdate();
}
else if(m_pParentObject&&m_pParentObject->m_ContainerType==Board)
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
CRect rect(0,0,100,100);
m_pView = (CView*)pContext->m_pNewViewClass->CreateObject();
if (!m_pView->Create(NULL, NULL, dwStyle, rect, m_pTabWnd, (UINT)this, pContext))
{
TRACE0("Warning: couldn't create client area for tab view\n");
return ;
}
m_pView->ModifyStyle(WS_BORDER,0);
m_pTabWnd->AddTab(m_pView,m_strTitle,uiImageId);
m_pView->OnInitialUpdate();
m_pTabWnd->RecalcLayout();
}
m_pWnd = m_pView;
}
break;
case MfcWnd:
{
g_pTangramServer->m_pCurTangramObj = this;
m_pWnd = (CWnd*)m_pRuntimeClass->CreateObject();
CCreateContext *pContext = &g_pTangramServer->m_pCurDoc->m_Context;
pContext->m_pNewViewClass = m_pRuntimeClass;
if(isDocking)
{
m_pDockingBarObj->m_pDockingWnd->SetBarStyle(m_pDockingBarObj->m_pDockingWnd->GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
m_pDockingBarObj->m_pDockingWnd->GetClientRect(&rc);
if(m_pConObj)
{
m_pConObj->m_pParentWnd=m_pDockingBarObj->m_pDockingWnd;
m_pConObj->m_pMfcObj = m_pDockingBarObj->m_pDockingWnd;
m_pConObj->Connect(true);
if(m_pConObj->m_pObjDisp)
m_pDisp = m_pConObj->m_pObjDisp;
}
m_pDockingBarObj->m_hWnd = m_pWnd->m_hWnd;
UINT pos=AFX_IDW_DOCKBAR_LEFT;
pFrame->DockControlBar(m_pDockingBarObj->m_pDockingWnd, pos);
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject==NULL)
{
if(m_pConObj)
{
m_pConObj->m_pMfcObj = m_pWnd;
m_pConObj->m_pParentWnd = g_pTangramServer->m_pCurFrame;
m_pConObj->Connect(true);
if(m_pConObj->m_pObjDisp)
m_pDisp = m_pConObj->m_pObjDisp;
}
g_pTangramServer->m_pCurDoc -> m_TangramObjectArray[0] ->m_pWnd = m_pWnd;
g_pTangramServer->m_pCurFrame->RecalcLayout();
}
else if(m_pParentObject->m_ContainerType==Splitter)
{
UINT nID = ((CSplitterWnd*)m_pParentObject->m_pWnd)->IdFromRowCol(m_nRowIndex, m_nColIndex);
if(m_pConObj)
{
m_pConObj->nChildID = nID;
m_pConObj->m_pMfcObj = m_pWnd;
m_pConObj->m_pParentWnd = m_pParentObject->m_pWnd;
m_pConObj->Connect(true);
if(m_pConObj->m_pObjDisp)
m_pDisp = m_pConObj->m_pObjDisp;
}
m_pWnd->ModifyStyle(WS_BORDER,0);
}
else if(m_pParentObject&&m_pParentObject->m_ContainerType==Board)
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pParentObject->m_pWnd;
CRect rect(0,0,100,100);
if(m_pConObj)
{
m_pConObj->m_pParentWnd = m_pParentObject->m_pWnd;
m_pConObj->m_pMfcObj = m_pWnd;
m_pConObj->Connect(true);
if(m_pConObj->m_pObjDisp)
m_pDisp = m_pConObj->m_pObjDisp;
}
m_pTabWnd->AddTab(m_pWnd,m_strTitle,uiImageId);
m_pTabWnd->RecalcLayout();
}
}
break;
case NonGUIObj:
{
HRESULT hr = NOERROR;
CComPtr<IDispatch> m_pDisp;
m_pDisp.CoCreateInstance(m_strObjID.AllocSysString());
}
break;
}
g_pTangramServer->m_pCurDoc->m_bAutoDelete = true;
}
break;
}
g_pTangramServer->m_pCurTangramObj = NULL;
int nObjCount = m_ChildObjectMap.GetSize();
if(nObjCount>0)
{
for(int i = 0; i < nObjCount; i++)
m_ChildObjectMap[i]->Create();
}
if((m_ContainerType==Splitter||m_ContainerType==Board)&&m_pParentObject&&m_pParentObject->m_ContainerType==Board)//m_pParentObject->m_pWnd->IsKindOf(RUNTIME_CLASS(CTangramContainerWnd))
{
CTangramContainerWnd* m_pTabWnd = ((CTangramContainerWnd*)m_pParentObject->m_pWnd);
int nTabIndex = m_pTabWnd->GetActiveTab();
if(nTabIndex==-1)nTabIndex=0;
m_pTabWnd->AddTab(m_pWnd,m_strTitle,uiImageId);
m_pTabWnd->RecalcLayout();
}
}
void CTangramObject::AttachDocCntrItem()
{
if(m_ContainerType==Board)
{
int nItemCount = g_pTangramServer->m_pCurDoc->m_BoardArray.GetSize();
if(nItemCount>0)
for(int nIndex = 0; nIndex < nItemCount; nIndex++)
if(m_strName==g_pTangramServer->m_pCurDoc->m_BoardArray[nIndex]->m_strName)
{
CDocCntrItem* m_pTmpItem = g_pTangramServer->m_pCurDoc->m_BoardArray[nIndex];
CComQIPtr<IDispatch, &IID_IDispatch> spControl(m_pTmpItem->m_lpObject);
ASSERT(spControl);
m_pDisp = spControl;
m_pTmpItem->m_pTangramObject=this;
g_pTangramServer->m_pCurDoc->m_BoardArray[nIndex]->m_pTangramObject = this;
m_pDocCntrItem = m_pTmpItem;
m_pTmpItem->m_pTangramWindow->SetTangramObj(this);
g_pTangramServer->m_pCurDoc->m_BoardArray.RemoveAt(nIndex);
int nObjCount = m_ChildObjectMap.GetSize();
if(nObjCount > 0)
for(int i = 0; i < nObjCount; i++)
if(m_ChildObjectMap[i]->m_ContainerType != Board)
{
//m_ChildObjectMap[i]->SetParentItem();
}
break;
}
}
else
{
POSITION nPos = g_pTangramServer->m_pCurDoc->GetStartPosition();
COleClientItem* pItem = NULL;
while ((pItem = g_pTangramServer->m_pCurDoc->GetNextClientItem(nPos)) != NULL)
{
if (pItem->IsKindOf(RUNTIME_CLASS(CTangramCntrItem)))
{
CTangramCntrItem* m_pTmpItem = (CTangramCntrItem*)pItem;
if(m_pTmpItem->m_strObjName == m_strName)
{
m_pObjCntrItem = m_pTmpItem;
m_pTmpItem->m_pTangramObject = this;
/*if(m_pTmpItem->bWinCtrl)
{
CLSID id;
CLSIDFromProgID(m_strObjID.AllocSysString(),&id);
if (!m_pTmpItem->CreateNewItem(id))
AfxThrowMemoryException();
//m_pTmpItem -> m_pDocument = g_pTangramServer->m_pCurDoc;
}*/
CComQIPtr<IDispatch, &IID_IDispatch> spControl(m_pTmpItem->m_lpObject);
m_pDisp = spControl;
break;
}
}
}
}
int nObjCount = m_ObArray.GetSize();
if(nObjCount>0)
{
for(int i = 0; i < nObjCount; i++)
m_ChildObjectMap[i]->AttachDocCntrItem();
}
}
void CTangramObject::DeleteChild()
{
int nObjCount = m_ChildObjectMap.GetSize();
if(nObjCount>0)
{
for(int i = 0; i < nObjCount; i++)
{
CTangramObject* pTangramObject = m_ChildObjectMap[i];
pTangramObject -> DeleteChild();
if(pTangramObject->m_ContainerType==Board)
{
CTangramContainerWnd* m_pTabWnd = (CTangramContainerWnd*)m_pWnd;
CDocCntrItem* pOleItem = (CDocCntrItem*)m_pTabWnd->m_pOleItem;
if(pOleItem)
{
pOleItem->Close();
pOleItem->Release();
g_pTangramServer->m_pCurDoc->RemoveItem(pOleItem);
pOleItem -> Delete();
}
}
if(pTangramObject->m_TangramObjType!=Unknow)
{
switch(pTangramObject->m_TangramObjType)
{
case AxDoc:
case AxCtrl:
{
CTangramCntrItem* m_pOleItem = pTangramObject->m_pObjCntrItem;
if(m_pOleItem)
{
if(m_pOleItem->IsInPlaceActive())
m_pOleItem->Deactivate();
if(g_pTangramServer->m_pActiveItem==m_pOleItem)
g_pTangramServer->m_pActiveItem = NULL;
m_pOleItem->Close();
m_pOleItem->Release();
g_pTangramServer->m_pCurDoc->RemoveItem(m_pOleItem);
m_pOleItem->Delete();
((CTangramDesignView*)pTangramObject->m_pWnd)->m_pOleItem = NULL;
}
}
break;
case MfcView:
break;
case WebBrowser:
break;
case MfcWnd:
case MfcWndContainer:
break;
}
}
/*/if(pTangramObject->m_pPrjItem)
{
//pTangramObject->m_pPrjItem->UnDefineVbaPrjItem();
//delete pTangramObject->m_pPrjItem;
//pTangramObject->m_pPrjItem=NULL;
}
if(pTangramObject->m_pCtrl)
{
//pTangramObject->m_pCtrl->UnDefineVbaCtrl();
//delete pTangramObject->m_pCtrl;
pTangramObject->m_pCtrl=NULL;
}*/
delete pTangramObject;
}
}
m_ChildObjectMap.RemoveAll();
}
//////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CTangramDockingObjImpl, CObject)
CTangramDockingObjImpl::CTangramDockingObjImpl(void)
{
m_pDockingFrame=NULL;
m_pDockingWnd = NULL;
m_pWnd=NULL;
}
CTangramDockingObjImpl::~CTangramDockingObjImpl(void)
{
if(m_pWnd)
{
delete m_pWnd;
m_pWnd = NULL;
}
//delete m_pDockingWnd;
}
CFrameWnd* CTangramDockingObjImpl::CreateDockingFrame(CString strTitle,CFrameWnd* pParentFrame)
{
/*m_pTangramObject->m_strTitle = strTitle;
if (!m_pDockingWnd->CreateEx(0,strTitle,pParentFrame, CSize(150,100), TRUE, AFX_IDW_CONTROLBAR_FIRST + 33 + g_pTangramServer->m_pCurDoc->m_DockingObjCount,WS_CHILD | WS_VISIBLE | CBRS_LEFT))
{
TRACE0("Failed to create DockingBar\n");
return NULL;
}
m_pDockingWnd->SetBarStyle(m_pDockingWnd->GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
CRect rc;
m_pDockingWnd->GetClientRect(&rc);
m_pDockingFrame = new CFrameWnd();
if (!m_pDockingFrame->Create(NULL, "", WS_CHILD|WS_VISIBLE, rc, m_pDockingWnd, NULL,NULL, NULL))//&g_pTangramServer->m_pCurDoc->m_Context
{
TRACE0("Warning: could not create view for frame.\n");
return NULL;
}
m_hWnd = m_pDockingFrame->m_hWnd;
m_pDockingWnd->EnableDocking(CBRS_ALIGN_ANY);
UINT pos=AFX_IDW_DOCKBAR_LEFT;
pParentFrame->EnableDocking(CBRS_ALIGN_ANY);
pParentFrame->DockControlBar(m_pDockingWnd, pos);
return m_pDockingFrame;*/
return NULL;
}
void CTangramDockingObjImpl::SetTangramObj(CTangramObject* pObj)
{
if(pObj==NULL)
m_pTangramObject = new CTangramObject();
else
m_pTangramObject = pObj;
m_pTangramObject->isDocking = true;
BOOL bInserted = false;
int nObjCount = g_pTangramServer->m_pCurDoc -> m_TangramObjectArray.GetSize();
if(nObjCount)
{
for(int i = 0; i < nObjCount; i++)
{
if(((CTangramObject*&)g_pTangramServer->m_pCurDoc -> m_TangramObjectArray[i]) == pObj)
{
bInserted = true;
break;
}
}
}
if(!bInserted)
g_pTangramServer->m_pCurDoc -> m_TangramObjectArray.SetAtGrow(g_pTangramServer->m_pCurDoc -> m_TangramObjectArray.GetSize(),m_pTangramObject);//�����¶������
g_pTangramServer->m_pCurDoc->m_DockingObjArray.SetAtGrow(g_pTangramServer->m_pCurDoc->m_DockingObjCount, this);
g_pTangramServer->m_pCurDoc->m_DockingObjCount++;
m_pWnd = NULL;
}
HRESULT CTangramObject::getAPCName(BSTR* pVal)
{
return S_OK;
}
HRESULT CTangramObject::putAPCName(BSTR newName)
{
return S_OK;
}