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(); }
CView* CProtoHapticApp::SwitchView( CView* v ) { CView* pActiveView = ((CFrameWnd*) m_pMainWnd)->GetActiveView(); CView* pNewView= v; // Exchange view window IDs so RecalcLayout() works. #ifndef _WIN32 UINT temp = ::GetWindowWord(pActiveView->m_hWnd, GWW_ID); ::SetWindowWord(pActiveView->m_hWnd, GWW_ID, ::GetWindowWord(pNewView->m_hWnd, GWW_ID)); ::SetWindowWord(pNewView->m_hWnd, GWW_ID, temp); #else UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID); ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID)); ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp); #endif pActiveView->ShowWindow(SW_HIDE); pNewView->ShowWindow(SW_SHOW); ((CFrameWnd*) m_pMainWnd)->SetActiveView(pNewView); ((CFrameWnd*) m_pMainWnd)->RecalcLayout(); pNewView->Invalidate(); return pActiveView; }
void CMainFrame::OnOutlookBarShortcut(UINT id) { const int nIndex = id - ID_SHORTCUT_1; ASSERT( nIndex >=0 && nIndex < NUMVIEWS ); if ( nIndex < 0 || nIndex >= NUMVIEWS ) return; if (!m_pViews) return; CView* pNewView = m_pViews[nIndex]; if (!pNewView) return; CView* pActiveView =GetActiveView(); if ( !pActiveView ) // No currently active view return; if ( pNewView == pActiveView ) // Already there return; m_nCurView = nIndex; // Store the new current view's index // exchange view window ID's so RecalcLayout() works UINT temp = ::GetWindowLong(pActiveView->m_hWnd, GWL_ID); ::SetWindowLong(pActiveView->m_hWnd, GWL_ID, ::GetWindowLong(pNewView->m_hWnd, GWL_ID)); ::SetWindowLong(pNewView->m_hWnd, GWL_ID, temp); // Display and update the new current view - hide the old one pActiveView->ShowWindow(SW_HIDE); pNewView->ShowWindow(SW_SHOW); SetActiveView(pNewView); RecalcLayout(); pNewView->Invalidate(); CString strCaption; strCaption.Format (_T("View %d"), nIndex + 1); m_wndCaptionBar.SetText (strCaption); m_wndCaptionBar.RedrawWindow (); }
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(); }
void CMainFrame::OnViewChange(UINT nCmdID) // There is an ON_COMMAND_RANGE message map entry associated with // OnViewChange: // ON_COMMAND_RANGE(ID_VIEW_CHANGE1, ID_VIEW_CHANGE2, &OnViewChange) { CView* pViewAdd; CView* pViewRemove; CDocument* pDoc = GetActiveDocument(); // cvView1 and cvView2 are enum members defined in my CMainFrame class if((nCmdID == ID_VIEW_CHANGE1) && (m_currentView == cvView1)) return; if((nCmdID == ID_VIEW_CHANGE2) && (m_currentView == cvView2)) return; if (nCmdID == ID_VIEW_CHANGE2) { if (m_pView2 == NULL) { m_pView1 = GetActiveView(); m_pView2 = new CMyView2; //Note that if OnSize has been overridden in CMyView2 //and GetDocument() is used in this override it can //cause assertions and, if the assertions are ignored, //cause access violation. m_pView2->Create(NULL, NULL, AFX_WS_DEFAULT_VIEW, rectDefault, this, AFX_IDW_PANE_FIRST + 1, NULL); } pViewAdd = m_pView2; pViewRemove = m_pView1; m_currentView = cvView2; } else { pViewAdd = m_pView1; pViewRemove = m_pView2; m_currentView = cvView1; } // Set the child i.d. of the active view to AFX_IDW_PANE_FIRST, // so that CFrameWnd::RecalcLayout will allocate to this // "first pane" that portion of the frame window's client area // not allocated to control bars. Set the child i.d. of the // other view to anything other than AFX_IDW_PANE_FIRST; this // examples switches the child id's of the two views. int nSwitchChildID = pViewAdd->GetDlgCtrlID(); pViewAdd->SetDlgCtrlID(AFX_IDW_PANE_FIRST); pViewRemove->SetDlgCtrlID(nSwitchChildID); // Show the newly active view and hide the inactive view. pViewAdd->ShowWindow(SW_SHOW); pViewRemove->ShowWindow(SW_HIDE); // Connect the newly active view to the document, and // disconnect the inactive view. pDoc->AddView(pViewAdd); pDoc->RemoveView(pViewRemove); SetActiveView(pViewAdd); RecalcLayout(); }
/******************************************************************** * Funzione : SwitchToForm * Descrizione: Passa a visualizzare una diversa view nel pannello di destra della splitter window, e un nuovo menu e una nuova toolbar nella frame window * Parametri : nForm = intero che e' l'ID (identificatore) della nuova vista da visualizzare nel pannello di destra * Ritorno : * Note : *********************************************************************/ void CMainFrame::SwitchToForm(int nForm) { CMenu menu; //static bool bFirst = true; // ricava un puntatore alla vista (child window) attualmente presente nel pannello // di destra della splitter window CView* pOldActiveView = (CView*)m_wndSplitter.GetPane(0, 1); // ricava un puntatore alla child window avente identificatore nForm CView* pNewActiveView = (CView*)GetDlgItem(nForm); // se non esite una child window con identificatore nForm (il puntatore e' nullo), // la crea if (pNewActiveView == NULL) { CCreateContext context; context.m_pCurrentDoc = pOldActiveView->GetDocument(); // nascondo la view atualmente visualizzata e passa l'attivazione ad un altra pOldActiveView->ShowWindow(SW_HIDE); // disattivo l'autodistruzione del doc context.m_pCurrentDoc->m_bAutoDelete = FALSE; // cancello la vecchia view m_wndSplitter.DeleteView(0, 1); // riattivo l'autodistruzione del doc context.m_pCurrentDoc->m_bAutoDelete = TRUE; switch(m_iForm = nForm) { case IDD_FORM_AZIENDE: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CAziendeView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_AZIENDE); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_AZIENDE); break; case IDD_FORM_VERBALI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CVerbaliView), CSize(0,0), &context); #ifdef WINSIGMA2 menu.LoadMenu(IDR_MENU_VERBALI_WS2); #else menu.LoadMenu(IDR_MENU_VERBALI); #endif m_wndToolBar.LoadToolBar(IDR_TOOLBAR_VERBALI); #ifdef WINSIGMA2 m_wndToolBar.SetButtonInfo(0,ID_SEPARATOR,TBBS_SEPARATOR,0); m_wndToolBar.SetButtonInfo(2,ID_SEPARATOR,TBBS_SEPARATOR,0); #endif break; case IDD_FORM_FATTURE: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CFattureView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_FATTURE); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_FATTURE); break; case IDD_FORM_LISTINI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CListiniView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_LISTINI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_LISTINI); break; case IDD_FORM_OPERATORI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(COperatoriView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_OPERATORI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_OPERATORI); break; case IDD_FORM_PAGAMENTI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CTipiPagamentoView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_PAGAMENTI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_PAGAMENTI); break; case IDD_FORM_MATERIALI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CTipiMaterialeView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_MATERIALI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_MATERIALI); break; case IDD_FORM_MARCHI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CMarchiView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_MARCHI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_MARCHI); break; case IDD_FORM_ARCHIVIO_VERBALI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CArchivioVerbaliView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_ARCHIVIO_VERBALI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_ARCHIVIO_VERBALI); break; case IDD_FORM_ARCHIVIO_CERTIFICATI: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CArchivioCertificatiView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_ARCHIVIO_CERTIFICATI); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_ARCHIVIO_CERTIFICATI); break; case IDD_FORM_ARCHIVIO_FATTURE: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CArchivioFattureView), CSize(0,0), &context); menu.LoadMenu(IDR_MENU_ARCHIVIO_FATTURE); m_wndToolBar.LoadToolBar(IDR_TOOLBAR_ARCHIVIO_FATTURE); break; case IDD_FORM_STATISTICHE_PROVE: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CStatProveView), CSize(0,0), &context); menu.Detach(); break; case IDD_FORM_STATISTICHE_FATTURATO: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CStatFatturatoView), CSize(0,0), &context); menu.Detach(); break; case IDD_FORM_TOTALI_FATTURATO: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CTotFatturatoView), CSize(0,0), &context); menu.Detach(); break; case IDD_FORM_ESPORTAZIONE_CSV: m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CEsportazioneCSVView), CSize(0,0), &context); menu.Detach(); break; } // imposta il nuovo menu come menu corrente SetMenu(&menu); // discollega il windows menu handle dall'oggetto, cosicche' uscendo tra poco dalla /// funzione, il distruttore dell'oggetto CMenu non distruggera' il nuovo menu menu.Detach(); CView* pView = (CView*)m_wndSplitter.GetPane(0, 1); if (pView) { SetActiveView(pView); if ( !bFirst) pView->OnInitialUpdate(); bFirst = false; } } // imposto la larghezza dei due pannelli in base alla vista selezionata CRect r; GetClientRect(&r); int w1 = (r.Width() * SPLIT_RATIO) / 100; int w2 = (r.Width() * (100 - SPLIT_RATIO)) / 100; // m_wndSplitter.SetColumnInfo( 0, w1, 0); // m_wndSplitter.SetColumnInfo( 1, w2, 0); // adatto il frame m_wndSplitter.RecalcLayout(); }
///////////////////////////////////////////////////////////////////////////// // 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; }