BOOL CStaticDoc::ShowStaticView( CRuntimeClass * pViewClass, BOOL bMaximized ) { if( NULL == pViewClass ) return FALSE; CChildFrame * pChildFrame = NULL; POSITION pos = GetFirstViewPosition( ); CView * pView = NULL; while( pView = GetNextView(pos) ) { if( pView->IsKindOf( pViewClass ) ) { pChildFrame = DYNAMIC_DOWNCAST( CChildFrame, pView->GetParentFrame() ); ASSERT( pChildFrame ); if( pChildFrame ) break; } } if( NULL == pChildFrame ) { // create frame pChildFrame = CChildFrame::CreateNewFrame( this ); ASSERT( pChildFrame ); if( pChildFrame ) { // create view CCreateContext context; context.m_pCurrentDoc = this; context.m_pCurrentFrame = pChildFrame; context.m_pLastView = NULL; context.m_pNewDocTemplate = NULL; context.m_pNewViewClass = pViewClass; CView * pNewView = DYNAMIC_DOWNCAST(CView,pChildFrame->CreateView( &context, AFX_IDW_PANE_FIRST)); if( pNewView ) { pChildFrame->SetActiveView( pNewView ); pNewView->OnInitialUpdate( ); } // if no active child frame, maximize this frame CMainFrame * pMainFrame = AfxGetMainFrame(); if( pMainFrame ) { CFrameWnd * pActiveFrame = AfxGetMainFrame()->GetActiveFrame(); if( !pActiveFrame || !pActiveFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)) ) pChildFrame->MDIMaximize(); } } } if( pChildFrame ) { // activate it pChildFrame->MDIActivate(); if( bMaximized ) pChildFrame->MDIMaximize(); else pChildFrame->ShowWindow( SW_SHOW ); } return TRUE; }
///////////////////////////////////////////////////////////////////////////// // 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; }