예제 #1
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : bSplitter - 
//-----------------------------------------------------------------------------
void CChildFrame::SetSplitterMode(BOOL bSplitter)
{
	if(bSplitter == bUsingSplitter)
		return;	// already at this mode

	if(!bSplitter)
	{
		// delete the splitterwnd.. first, get the view that it is currently
		//  using.
		CView * pActiveView = GetActiveView();
		CDocument* pDoc = pActiveView->GetDocument();

	    BOOL bAutoDelete=pDoc->m_bAutoDelete;
		pDoc->m_bAutoDelete=FALSE;

		pActiveView->SetRedraw(FALSE);
		m_wndSplitter->SetRedraw(FALSE);
		pActiveView->SetParent(this);

		m_wndSplitter->DestroyWindow();
		delete m_wndSplitter;
		m_wndSplitter = NULL;

		pDoc->m_bAutoDelete = bAutoDelete;

		// redraw active view
		CRect r;
		GetClientRect(r);
		pActiveView->SetRedraw(TRUE);
		pActiveView->MoveWindow(0, 0, r.right, r.bottom, TRUE);
	}
	else
	{
		CView * pActiveView = GetActiveView();
		Assert(pActiveView);
		CMapDoc* pDoc = (CMapDoc*) pActiveView->GetDocument();

	    BOOL bAutoDelete=pDoc->m_bAutoDelete;
		pDoc->m_bAutoDelete=FALSE;
		pActiveView->DestroyWindow();
		pDoc->m_bAutoDelete = bAutoDelete;

		// creating new four views.
		m_wndSplitter = new CMySplitterWnd;
		if(!m_wndSplitter->CreateStatic(this, 2, 2))
		{
			TRACE0("Failed to create split bar ");
			return;    // failed to create
		}

		CRect r;
		GetClientRect(r);
		CSize sizeView(r.Width()/2 - 3, r.Height()/2 - 3);

		CCreateContext context;
		context.m_pNewViewClass = NULL;
		context.m_pCurrentDoc = pDoc;
		context.m_pNewDocTemplate = NULL;
		context.m_pLastView = NULL;
		context.m_pCurrentFrame = this;

		context.m_pNewViewClass = RUNTIME_CLASS(CMapView2D);
		m_wndSplitter->CreateView(0, 1, RUNTIME_CLASS(CMapView2D),
			sizeView, &context);
		m_wndSplitter->CreateView(1, 0, RUNTIME_CLASS(CMapView2D),
			sizeView, &context);
		m_wndSplitter->CreateView(1, 1, RUNTIME_CLASS(CMapView2D),
			sizeView, &context);

		context.m_pNewViewClass = RUNTIME_CLASS(CMapView3D);

		m_wndSplitter->CreateView(0, 0, context.m_pNewViewClass,
			sizeView, &context);
	}

	bUsingSplitter = bSplitter;
}
예제 #2
0
void CChildFrame::AddView(UINT docNum, UINT viewNum, UINT type,
    CSplitterControl *splitter,
    CView *pCurView)
{
    CRect rect;
    CView *pAddView = NULL;
    pCurView->GetWindowRect(rect);
    ScreenToClient(rect);


    //create the new Split	
    CSplitterControl *pNewSplit = new CSplitterControl;
    CRect rc;
    if (type == 1)   //Ver
    {
        rc.left = rect.left + rect.Width() / 2;
        rc.top = rect.top / 2;
        rc.right = rect.left + 5;
        rc.bottom = rect.top + rect.Height();

        pNewSplit->m_rect0.left = rect.left;
        pNewSplit->m_rect0.right = rect.left + rect.Width() / 2;
        pNewSplit->m_rect0.top = rect.top;
        pNewSplit->m_rect0.bottom = rect.bottom;

        pNewSplit->m_rect1.left = rect.left + rect.Width() / 2;
        pNewSplit->m_rect1.right = rect.left + rect.Width();
        pNewSplit->m_rect1.top = rect.top;
        pNewSplit->m_rect1.bottom = rect.bottom;
    }
    else if (type == 2)  //h
    {
        rc.left = rect.left;
        rc.top = rect.top + rect.Height() / 2;
        rc.right = rc.left + rect.Width();
        rc.bottom = rc.top + 5;

        pNewSplit->m_rect0.left = rect.left;
        pNewSplit->m_rect0.right = rect.right;
        pNewSplit->m_rect0.top = rect.top;
        pNewSplit->m_rect0.bottom = rect.top + rect.Height() / 2;

        pNewSplit->m_rect1.left = rect.left;
        pNewSplit->m_rect1.right = rect.right;
        pNewSplit->m_rect1.top = rect.top + rect.Height() / 2;
        pNewSplit->m_rect1.bottom = rect.top + rect.Height();
    }

    pNewSplit->Create(WS_CHILD | WS_VISIBLE, rc, this, IDC_STA_SPLIT);
    pNewSplit->SetRange(300, 300, -1);

    //judge the type of view on his parent,(Left<top> or Right<bottom>)
    if (*pCurView == *(splitter->m_pLView))
    {
        splitter->m_pSplit0 = pNewSplit;
    }
    else
    {
        splitter->m_pSplit1 = pNewSplit;
    }


    CWnd* pFrameWnd = this;
    //decide the type of Doc
    switch (docNum) {
    case 0:
        m_pContext.m_pCurrentDoc = new CMyDoc2;
        break;
    case 1:
        m_pContext.m_pCurrentDoc = new CMyDocument;
        break;
    }
    //decide the type of view
    switch (viewNum) {
    case 0:
    {
        m_pContext.m_pNewViewClass = RUNTIME_CLASS(CMyView);
        CMyView  *pView = (CMyView  *)((CFrameWnd*)pFrameWnd)->CreateView(&m_pContext);
        pAddView = pView;
    }
    break;
    case 1:
    {
        m_pContext.m_pNewViewClass = RUNTIME_CLASS(CDisView);
        CDisView *pView = (CDisView *)((CFrameWnd*)pFrameWnd)->CreateView(&m_pContext);
        pAddView = pView;
    }
    break;
    }
    //adjust views point
    static_cast<CDisplayView *>(pAddView)->m_Split = pNewSplit;
    static_cast<CDisplayView *>(pCurView)->m_Split = pNewSplit;
    pNewSplit->m_pLView = pCurView;
    pNewSplit->m_pRView = pAddView;
    //adjust the new view's pos
    CRect recttemp;

    if (type == 1)        //Ver
    {
        recttemp.left = rect.left + rect.Width() / 2;
        recttemp.top = rect.top;
        recttemp.right = recttemp.left + rect.Width() / 2;
        recttemp.bottom = recttemp.top + rect.Height();

        rect.right = rect.left + rect.Width() / 2;
    }
    else if (type == 2)  //H
    {
        recttemp.top = rect.top + rect.Height() / 2;
        recttemp.left = rect.left;
        recttemp.right = recttemp.left + rect.Width();
        recttemp.bottom = recttemp.top + rect.Height() / 2;

        rect.bottom = rect.top + rect.Height() / 2;
    }
    pCurView->MoveWindow(rect);
    pAddView->MoveWindow(recttemp);
}