Ejemplo n.º 1
0
void CMainFrame::SwitchToView(eView nView)
{
	CView* pOldActiveView = GetActiveView();
	CView* pNewActiveView = (CView*) GetDlgItem(nView);
	if (pNewActiveView == NULL) {
		switch (nView) {
		case STRING:
			pNewActiveView = (CView*) new CStringView;
			break;
		case HEX:
			pNewActiveView = (CView*) new CHexView;
			break;
		}
		CCreateContext context;
		context.m_pCurrentDoc = pOldActiveView->GetDocument();
		pNewActiveView->Create(NULL, NULL, WS_BORDER,
			CFrameWnd::rectDefault, this, nView, &context);
		pNewActiveView->OnInitialUpdate();
	}
	SetActiveView(pNewActiveView);
	pNewActiveView->ShowWindow(SW_SHOW);
	pOldActiveView->ShowWindow(SW_HIDE);
	pOldActiveView->SetDlgCtrlID(
		pOldActiveView->GetRuntimeClass() == 
		RUNTIME_CLASS(CStringView) ? STRING : HEX);
	pNewActiveView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
	RecalcLayout();
}
Ejemplo n.º 2
0
void CMainFrame::SwitchView(ViewType nType)
{
	CView* pOldView = GetActiveView();
	CView* pNewView = (CView*)GetDlgItem(nType);

	if(pNewView == NULL)
	{
		switch(nType)
		{
		case FORMVIEW:
			pNewView = (CView*)new CMultiLookView;
			break;
		case FONTVIEW:
			pNewView = (CView*)new CFontView;
			break;
		case PAINTVIEW:
			pNewView = (CView*)new CPaintView;
			break;
		}

		CCreateContext context;
		context.m_pCurrentDoc = pOldView->GetDocument();
		pNewView->Create(NULL, NULL, WS_BORDER, 
			CFrameWnd::rectDefault, this, nType, &context);
		pNewView->OnInitialUpdate();
	}

	SetActiveView(pNewView);
	pNewView->ShowWindow(SW_SHOW);
	pOldView->ShowWindow(SW_HIDE);
	if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CMultiLookView))
		pOldView->SetDlgCtrlID(FORMVIEW);
	if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CFontView))
		pOldView->SetDlgCtrlID(FONTVIEW);
	if(pOldView->GetRuntimeClass() == RUNTIME_CLASS(CPaintView))
		pOldView->SetDlgCtrlID(PAINTVIEW);

	pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
	RecalcLayout();
	
}
BOOL COXChildFrameState::ComputeProperties(CFrameWnd* pFrameWnd)
	{
	ASSERT_VALID(this);

	// Get the position of the frame window
	::ZeroMemory(&m_framePlacement, sizeof(WINDOWPLACEMENT));
	m_framePlacement.length = sizeof(WINDOWPLACEMENT);
	if (pFrameWnd != NULL)
	{
		VERIFY(pFrameWnd->GetWindowPlacement(&m_framePlacement));
		if(!pFrameWnd->IsWindowVisible())
		{
			m_framePlacement.showCmd=SW_HIDE;
		}
	}

	// Get the document and view of this frame
	CDocument* pDoc = NULL;
	CView* pView = NULL;
	if (!GetDocView(pFrameWnd, pDoc, pView))
		{
		TRACE0("COXChildFrameState::ComputeProperties : Failed to get the doc-view for this frame, failing\n");
		return FALSE;
		}

	// Get the file path of the document
	if (pDoc != NULL)
		m_sDocPath = pDoc->GetPathName();

	// Store the name of the classes of doc, frame and view
	if (pDoc != NULL)
		m_sDocClassName = pDoc->GetRuntimeClass()->m_lpszClassName;
	if (pFrameWnd != NULL)
		m_sFrameClassName = pFrameWnd->GetRuntimeClass()->m_lpszClassName;
	if (pView != NULL)
		m_sViewClassName = pView->GetRuntimeClass()->m_lpszClassName;

	EmptySplitterPanes(m_pSplitterPanes);
	if (m_bSaveSplitterPanes)
		ComputeSplitterPanes(pFrameWnd);

	ASSERT_VALID(this);
	return TRUE;
	}
Ejemplo n.º 4
0
/////////////////////////////////////////////////////////////////////////////
// switch to the new selected view tab
/////////////////////////////////////////////////////////////////////////////
BOOL CBonfireDoc::SwitchToView(CString strTab)
{
	if (strTab == "")
		return FALSE;

	CChildFrame*	pChild		= (CChildFrame*)g_pMainFrame->MDIGetActive();
	if (!pChild || pChild->GetActiveDocument() != this)
	{
		POSITION pos = GetFirstViewPosition();
		pChild	= (CChildFrame*)GetNextView(pos)->GetParentFrame();
	}

	if (!pChild)
		return FALSE;

	CView*			pViewAdd	= NULL;
	CBonfireView*	pGlobalView	= NULL;
	CBonfireView*	pBNewView	= NULL;
	
	// get the view to "hide"
	CView*			pViewDel	= pChild->GetActiveView();
	
	// if we're already displaying this kind of view, no need to go further.
	for (int i = 0; i < theApp.m_arAllViews.GetSize(); i++)
	{
		if ( ((CBonfireView*)theApp.m_arAllViews[i])->m_strCaption.Compare(strTab) == 0 )
		{
			pGlobalView = (CBonfireView*)theApp.m_arAllViews[i];
			break;
		}
	}

	if ( pViewDel && pViewDel->IsKindOf(pGlobalView->m_pClass) )
		return TRUE;

	// check if a view of this type already exists
 	if ( !m_pViews->Lookup(pGlobalView->m_strCaption, (void*&)pBNewView) )
	{
		// doesn't exist so create a new view
		pViewAdd = (CView*)pGlobalView->m_pClass->CreateObject();
		if (pViewAdd == NULL)
		{
			TRACE1("Warning: Dynamic create of view type %Fs failed\n", pGlobalView->m_pClass->m_lpszClassName);
			return FALSE;
		}

		// draw new view
		CCreateContext context;
		context.m_pNewViewClass		= pGlobalView->m_pClass;
		context.m_pCurrentDoc		= NULL;
		context.m_pNewDocTemplate	= this->GetDocTemplate();
		context.m_pLastView			= NULL;
		context.m_pCurrentFrame		= pChild;

		// draw new view
		if (!pViewAdd->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, CRect(0, 0, 0, 0),
			pChild, AFX_IDW_PANE_FIRST, &context))
		{
			TRACE0("Warning: couldn't create view for frame\n");
			delete pViewAdd;
			return FALSE;
		}

		// add the view to the map
		pBNewView			= new CBonfireView(pGlobalView);
		pBNewView->m_pView	= pViewAdd;
		pBNewView->m_pClass	= pViewAdd->GetRuntimeClass();

		// add this view to the document's map
		AddViewToMap(pBNewView);

		// WM_INITIALUPDATE is defined in afxpriv.h
		pViewAdd->SendMessage(WM_INITIALUPDATE,0,0);

		// connect the view to the document
		AddView(pViewAdd);
	}
	else
	{
		pViewAdd = pBNewView->m_pView;
	}

	// save file on switching views
	if (theApp.m_opOptions.general.dwSaveOnSwitch && !m_xTextBuffer.GetReadOnly() && pViewDel)
		DoFileSave();
	
	CSplitterWnd*	pSplitter	= NULL;
	POSITION pos				= GetFirstViewPosition();
	BOOL firstOne				= true;
	while (pos)
	{
		CView* pv	= GetNextView(pos);
		if (pv == pViewAdd)	
		{
			pv->SetDlgCtrlID(AFX_IDW_PANE_FIRST);

			// show the view
			if (pBNewView->m_bAllowsSplitter)
			{
				pSplitter	= (CSplitterWnd*)pViewAdd->GetParent();
				
				// show the splitter (show the children view(s) as well)
				pSplitter->ShowWindow(SW_SHOW);
			}
			else
				// show the view
				pViewAdd->ShowWindow(SW_SHOW);
		}
		else 
		{
			// check if the view is inside a splitter
			if (pv->GetParent()->GetRuntimeClass() == (CRuntimeClass*)RUNTIME_CLASS(CSplitterWnd))
			{
				pSplitter	= (CSplitterWnd*)pv->GetParent();
				
				// hide the splitter (hide all views with the splitter)
				pSplitter->ShowWindow(SW_HIDE);
			}
			else
			{
				// hide the view
				pv->ShowWindow(SW_HIDE);
				pv->SetDlgCtrlID(AFX_IDW_PANE_FIRST + 255);
			}
		}

		TRACE("%s (%d) ", pv->GetRuntimeClass()->m_lpszClassName, (unsigned)(pv->GetDlgCtrlID() - AFX_IDW_PANE_FIRST));
		if (pv == pViewDel)		TRACE("= D ");
		if (pv == pViewAdd)		TRACE("= A ");
		if (pv->GetRuntimeClass() == pGlobalView->m_pClass)
		{
			if (firstOne)
				firstOne = false;
			else
				TRACE("removing ");
		}
	}
	TRACE("\n");

	// get rid of extra views created by the splitter
	if (pSplitter)
	{
		for (int cols = 1; cols < pSplitter->GetColumnCount(); cols++)
			pSplitter->DeleteColumn(cols);
		for (int rows = 1; rows < pSplitter->GetRowCount(); rows++)
			pSplitter->DeleteRow(rows);

		pSplitter->RecalcLayout();
	}

	pViewAdd->UpdateWindow();
	pChild->SetActiveView(pViewAdd);
	pChild->RecalcLayout();

	if (pBNewView->m_bModifiedSinceRefresh)
	{
		pBNewView->m_bModifiedSinceRefresh = FALSE;
		if (pGlobalView->m_pClass == RUNTIME_CLASS(CXMLTreeView))
		{
			((CXMLTreeView*)pViewAdd)->RefreshView();
		}
		else if (pGlobalView->m_pClass == RUNTIME_CLASS(CBrowserView))
		{
			((CBrowserView*)pViewAdd)->RefreshView();
		}
		else
		{
			pBNewView->m_bModifiedSinceRefresh = TRUE;
		}
	}

	return TRUE;
}