//*******************************************************************************
// 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
//*******************************************************************************
// DockingTangramBar.cpp : implementation file
//
#include "stdafx.h"
#include "DockingTangramBar.h"
#include "TangramServerObj.h"
#include "TangramDoc.h"
#include "TangramObject.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CDockingTangramBar
IMPLEMENT_DYNCREATE(CDockingTangramBar,CBCGSizingControlBar);
CDockingTangramBar::CDockingTangramBar(CTangramObject* pObj, BOOL DockingMain)
{
bDockingMain = false;
m_pDockingFrame = NULL;
}
CDockingTangramBar::~CDockingTangramBar()
{
/*if(m_pWnd)
{
delete m_pWnd;
m_pWnd = NULL;
}*/
}
BEGIN_MESSAGE_MAP(CDockingTangramBar, CBCGSizingControlBar)
//{{AFX_MSG_MAP(CDockingTangramBar)
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDockingTangramBar message handlers
void CDockingTangramBar::OnDestroy()
{
if(!bDockingMain)
if(m_pDockingFrame&&::IsWindow(m_pDockingFrame->m_hWnd))
m_pDockingFrame->DestroyWindow();
//else
//if(m_pWnd&&::IsWindow(m_pWnd->m_hWnd))
//m_pWnd->DestroyWindow();
CBCGSizingControlBar::OnDestroy();
}
void CDockingTangramBar::OnSize(UINT nType, int cx, int cy)
{
CBCGSizingControlBar::OnSize(nType, cx, cy);
/*if(m_pWnd&&::IsWindow(m_pWnd->m_hWnd))
{
::SetWindowPos(m_pWnd->m_hWnd,NULL, -1, -1, cx, cy,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}
if(::IsWindow(hWnd))
{
::SetWindowPos(hWnd,NULL, -1, -1, cx, cy,
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
} */
}
int CDockingTangramBar::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CBCGSizingControlBar::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
/*if(m_pWndClass&&m_pWnd)
{
CCreateContext* pContext = new CCreateContext;
m_pWnd->Create(NULL,_T(""),WS_VISIBLE|WS_CHILD,CRect(0,0,0,0),this,1,pContext);
delete pContext;
}*/
return 0;
}
CFrameWnd* CDockingTangramBar::CreateDockingFrame(CString strTitle,CFrameWnd* pParentFrame)
{
m_pTangramObject->m_strTitle = strTitle;
if (!Create(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;
}
SetBarStyle(GetBarStyle()|CBRS_TOOLTIPS|CBRS_FLYBY|CBRS_SIZE_DYNAMIC);
CRect rc;
GetClientRect(&rc);
m_pDockingFrame = new CFrameWnd();
if (!m_pDockingFrame->Create(NULL, "", WS_CHILD|WS_VISIBLE, rc, this, NULL,NULL, NULL))//&g_pTangramServer->m_pCurDoc->m_Context
{
TRACE0("Warning: could not create view for frame.\n");
return NULL;
}
hWnd = m_pDockingFrame->m_hWnd;
EnableDocking(CBRS_ALIGN_ANY);
UINT pos=AFX_IDW_DOCKBAR_LEFT;
pParentFrame->EnableDocking(CBRS_ALIGN_ANY);
pParentFrame->DockControlBar(this, pos);
return m_pDockingFrame;
}
void CDockingTangramBar::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;
}