|
From: Emilien K. <cur...@us...> - 2005-08-02 12:51:08
|
Update of /cvsroot/wxdevcenter/wxDevCenter/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23161/src Modified Files: Application.cpp DocManager.cpp DocType.cpp Document.cpp Element.cpp FileSystem.cpp MDIFrame.cpp MainFrame.cpp View.cpp WorkBar.cpp Log Message: Passage à la nouvelle architecture basée sur la classe Element. Index: MainFrame.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/MainFrame.cpp,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** MainFrame.cpp 14 May 2005 12:15:56 -0000 1.15 --- MainFrame.cpp 2 Aug 2005 12:50:54 -0000 1.16 *************** *** 217,227 **** { View *pView = GetViewFrame()->GetActiveView(); - Document *pDoc; - if(pView!=NULL) ! { ! pDoc = pView->GetDocument(); ! Application::GetApp().GetDocManager().CloseDocument(pDoc); ! } } --- 217,222 ---- { View *pView = GetViewFrame()->GetActiveView(); if(pView!=NULL) ! pView->GetDocument()->Destroy(false); } *************** *** 236,240 **** void MainFrame::OnMenuWindowClose(wxCommandEvent& WXUNUSED(event)) { ! Application::GetApp().GetDocManager().CloseView(GetViewFrame()->GetActiveView()); } --- 231,235 ---- void MainFrame::OnMenuWindowClose(wxCommandEvent& WXUNUSED(event)) { ! GetViewFrame()->GetActiveView()->Destroy(false); } *************** *** 264,275 **** { Document *pDoc = pActiveView->GetDocument(); ! int iTypeView = Application::GetApp().GetDocManager().ChooseViewType(Application::GetApp().GetDocManager().FindTemplate(pDoc->GetDocTemplate())); if(iTypeView!=-1) ! { ! View *pNewView = Application::GetApp().GetDocManager().CreateView(pDoc, iTypeView); ! pDoc->AttachView(pNewView); ! AddView(pNewView); ! pNewView->OnInitialUpdate(); ! } } } --- 259,265 ---- { Document *pDoc = pActiveView->GetDocument(); ! int iTypeView = Application::GetApp().GetDocManager().ChooseViewType(Application::GetApp().GetDocManager().FindDocTemplate(pDoc->GetDocTemplate())); if(iTypeView!=-1) ! Application::GetApp().GetDocManager().CreateView(pDoc, (unsigned int)iTypeView); } } Index: DocType.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/DocType.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** DocType.cpp 14 May 2005 12:15:56 -0000 1.4 --- DocType.cpp 2 Aug 2005 12:50:54 -0000 1.5 *************** *** 29,38 **** using namespace wxDevCenter; - /** - * Tableaux dynamiques de types de documents : - */ - - namespace wxDevCenter - { /** --- 29,32 ---- *************** *** 51,63 **** m_strExt.Add(tkz.GetNextToken()); - // Enregistrement des données de la vue. - RegisterViewTemplate(&m_ViewTemplate); - - // Enregistrement du mini-doc si précisé. - // if(pMiniDocClassInfo!=NULL) - // SetMiniDoc(pMiniDocClassInfo); - - // Déclaration du type de documents. - Application::GetApp().GetDocManager().RegisterDocTemplate(this); } --- 45,48 ---- *************** *** 67,80 **** - // Initialisation. bool DocType::Initialize() { ! return true; } ! // Nettoyage. ! void DocType::Free() { } } --- 52,83 ---- bool DocType::Initialize() { ! if(!DocTemplate::Initialize()) ! return false; ! ! // Enregistrement du mini-doc si précisé. ! // if(pMiniDocClassInfo!=NULL) ! // SetMiniDoc(pMiniDocClassInfo); ! ! // Enregistrement des données de la vue. ! RegisterViewTemplate(&m_ViewTemplate); ! ! return Application::GetApp().GetDocManager().RegisterDocTemplate(this)!=-1; } ! void DocType::Finalize() { + DocTemplate::Finalize(); + Application::GetApp().GetDocManager().UnregisterDocTemplate(this); + } + + bool DocType::Destroy(bool bForce) + { + return DocTemplate::Destroy(bForce); } + bool DocType::CanDestroy() + { + return DocTemplate::CanDestroy(); } Index: Element.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Element.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Element.cpp 14 May 2005 12:15:56 -0000 1.1 --- Element.cpp 2 Aug 2005 12:50:54 -0000 1.2 *************** *** 51,55 **** m_bIsInit = true; ! wxLogDebug("%p (%s) initialized", this, this->GetClassInfo()->GetClassName()); return true; --- 51,55 ---- m_bIsInit = true; ! wxLogDebug("0x%p (%s) initialized", this, this->GetClassInfo()->GetClassName()); return true; *************** *** 75,79 **** // Fonction virtuelle de test de destruction de l'élément de plugin. ! bool Element::CanDestroy()const { return true; --- 75,79 ---- // Fonction virtuelle de test de destruction de l'élément de plugin. ! bool Element::CanDestroy() { return true; Index: WorkBar.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/WorkBar.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** WorkBar.cpp 14 May 2005 12:15:56 -0000 1.6 --- WorkBar.cpp 2 Aug 2005 12:50:54 -0000 1.7 *************** *** 60,64 **** } ! bool WorkBarTemplate::CanDestroy()const { return ObjectTemplate<WorkBar>::CanDestroy(); --- 60,64 ---- } ! bool WorkBarTemplate::CanDestroy() { return ObjectTemplate<WorkBar>::CanDestroy(); *************** *** 90,94 **** } ! bool WorkBarType::CanDestroy()const { return false; --- 90,94 ---- } ! bool WorkBarType::CanDestroy() { return false; Index: MDIFrame.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/MDIFrame.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** MDIFrame.cpp 14 May 2005 12:15:56 -0000 1.6 --- MDIFrame.cpp 2 Aug 2005 12:50:54 -0000 1.7 *************** *** 186,191 **** while(GetPageCount()>0) { ! if(!Application::GetApp().GetDocManager().CloseView((View*)GetPage(0))) ! return false; } return true; --- 186,193 ---- while(GetPageCount()>0) { ! View* pView = wxDynamicCast(GetPage(0), View); ! if(pView) ! if(pView->Destroy(false)) ! return false; } return true; *************** *** 211,215 **** wxWindow* pPage = GetCurrentPage(); if(pPage) ! return pPage->ProcessEvent(event); else return false; --- 213,217 ---- wxWindow* pPage = GetCurrentPage(); if(pPage) ! return wxDynamicCast(pPage, wxWindow)->ProcessEvent(event); else return false; Index: FileSystem.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/FileSystem.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** FileSystem.cpp 14 May 2005 12:15:56 -0000 1.5 --- FileSystem.cpp 2 Aug 2005 12:50:54 -0000 1.6 *************** *** 234,238 **** FileSystemManager::FileSystemManager(): ! ElementManager<FileSystem>() { } --- 234,239 ---- FileSystemManager::FileSystemManager(): ! Element(), ! ObjectManager<FileSystem>() { } *************** *** 265,269 **** bool FileSystemManager::Register(FileSystem* pFileSystem, bool bMountWorkBar) { ! if(!ElementManager<FileSystem>::Register(pFileSystem)) return false; if(bMountWorkBar) --- 266,270 ---- bool FileSystemManager::Register(FileSystem* pFileSystem, bool bMountWorkBar) { ! if(!ObjectManager<FileSystem>::Register(pFileSystem)) return false; if(bMountWorkBar) *************** *** 276,280 **** { Application::GetApp().GetWorkBarManager().UnregisterWorkBar(CLASSINFO(FileSystemTreeWorkBar), pFileSystem); ! return ElementManager<FileSystem>::Unregister(pFileSystem); } --- 277,281 ---- { Application::GetApp().GetWorkBarManager().UnregisterWorkBar(CLASSINFO(FileSystemTreeWorkBar), pFileSystem); ! return ObjectManager<FileSystem>::Unregister(pFileSystem); } Index: Application.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Application.cpp,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Application.cpp 14 May 2005 12:15:56 -0000 1.23 --- Application.cpp 2 Aug 2005 12:50:54 -0000 1.24 *************** *** 219,222 **** --- 219,229 ---- Document *pDoc = m_DocManager.CreateDocument(nDocType); + if(pDoc==NULL) + return false; + if(!pDoc->Initialize()) + { + delete pDoc; + return false; + } if(!pDoc->OnNewDocument()) { *************** *** 226,230 **** View *pView = m_DocManager.CreateView(pDoc, nDocView); ! pDoc->AttachView(pView); m_pMainFrame->AddView(pView); pView->OnInitialUpdate(); --- 233,242 ---- View *pView = m_DocManager.CreateView(pDoc, nDocView); ! if(pView==NULL) ! { ! delete pDoc; ! return false; ! } ! m_pMainFrame->AddView(pView); pView->OnInitialUpdate(); *************** *** 293,297 **** // Création et attache de la vue pView = m_DocManager.CreateView(pDoc, nDocView); ! pDoc->AttachView(pView); m_pMainFrame->AddView(pView); pView->OnInitialUpdate(); --- 305,314 ---- // Création et attache de la vue pView = m_DocManager.CreateView(pDoc, nDocView); ! if(pView==NULL) ! { ! delete pDoc; ! return false; ! } ! m_pMainFrame->AddView(pView); pView->OnInitialUpdate(); Index: DocManager.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/DocManager.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** DocManager.cpp 14 May 2005 12:15:56 -0000 1.9 --- DocManager.cpp 2 Aug 2005 12:50:54 -0000 1.10 *************** *** 65,69 **** } ! bool DocTemplate::CanDestroy()const { return plugins::PluginItem::CanDestroy(); --- 65,69 ---- } ! bool DocTemplate::CanDestroy() { return plugins::PluginItem::CanDestroy(); *************** *** 98,102 **** DocManager::DocManager(void): ! MultiObjectTemplateManager<Document, DocTemplate>(), m_ViewManager(), m_pDefaultViewContainer(NULL) --- 98,103 ---- DocManager::DocManager(void): ! Element(), ! wxObject(), m_ViewManager(), m_pDefaultViewContainer(NULL) *************** *** 131,159 **** } ! // Crée un document. Document* DocManager::CreateDocument(unsigned int nIndex) { ! Document *pDoc = CreateObject(nIndex); pDoc->m_pDocumentManager = this; ! pDoc->m_pDocumentTemplate = &GetTemplate(nIndex); ! return pDoc; ! } ! // Ferme le document spécifié. ! bool DocManager::CloseDocument(Document *pDoc) ! { ! // On teste si le document peut etre fermé ! if(pDoc->CanCloseDocument()) ! { ! // On ferme toutes les vues attachées au document. ! // Le document sera détruit automatiquement par la fermeture de la dernière vue. ! for(int i = pDoc->m_ViewArray.GetCount()-1; i>=0; i--) ! CloseView(&pDoc->m_ViewArray.Item(i)); ! return true; ! } ! else ! return false; } // Ferme tous les documents ouverts. bool DocManager::CloseAllDocuments() --- 132,149 ---- } ! // Crée un document vièrge. Document* DocManager::CreateDocument(unsigned int nIndex) { ! Document *pDoc = m_TemplateManager.CreateObjectFromTemplate(nIndex); pDoc->m_pDocumentManager = this; ! pDoc->m_pDocumentTemplate = &GetDocTemplate(nIndex); ! if(pDoc->Initialize()) ! return pDoc; ! else ! return NULL; } + // Ferme tous les documents ouverts. bool DocManager::CloseAllDocuments() *************** *** 161,165 **** while(GetDocumentCount()>0) { ! if(!CloseDocument(GetDocument(0))) return false; } --- 151,155 ---- while(GetDocumentCount()>0) { ! if(!GetDocument(0)->Destroy(false)) return false; } *************** *** 175,187 **** } - // Detruit le document spécifié. - void DocManager::DeleteDocument(Document* pDocument) - { - // Pré-ferme le document. - pDocument->OnCloseDocument(); - // Détruit le document (finalise, désenregistre et détruit). - DestroyObject(pDocument); - } - /** --- 165,168 ---- *************** *** 278,291 **** } - // Ajoute un patron de document à la liste des patrons. - int DocManager::RegisterDocTemplate(DocTemplate* pTemplate) - { - if(!RegisterTemplate(pTemplate)) - return -1; - else - return FindTemplate(pTemplate); - } - - --- 259,262 ---- *************** *** 295,308 **** // Crée une vue ! View* DocManager::CreateView(Document *pDoc, unsigned int nViewIndex) { View *pView = NULL; ! DocTemplate *pTemplate = pDoc->m_pDocumentTemplate; ! pView = pTemplate->GetViewTemplate(nViewIndex).CreateObject(); if(pView==NULL) return NULL; ! if(!m_ViewManager.Register(pView)) { delete pView; --- 266,290 ---- // Crée une vue ! View* DocManager::CreateView(Document *pDoc, int iViewIndex) { View *pView = NULL; ! DocTemplate *pTemplate = pDoc->m_pDocumentTemplate; ! // Met le type de vue par défaut. ! /** @todo Changer le type de vue par défaut en demande à l'utilisateur.*/ ! if(iViewIndex==-1) ! iViewIndex = 0; ! ! // Allocation ! pView = pTemplate->GetViewTemplate(iViewIndex).CreateObject(); if(pView==NULL) return NULL; ! // Construction ! pView->m_pViewTemplate = &pTemplate->GetViewTemplate(iViewIndex); ! pView->m_pDocument = pDoc; ! ! // Initialisation ! if(!pView->Initialize()) { delete pView; *************** *** 310,320 **** } ! pView->m_pViewTemplate = &pTemplate->GetViewTemplate(nViewIndex); ! pView->m_pDocument = NULL; ! if(pDoc!=NULL) ! pDoc->AttachView(pView); pView->Create(m_pDefaultViewContainer, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); pView->Hide(); pView->OnCreate(); pView->Show(); return pView; --- 292,300 ---- } ! // Création et affichage pView->Create(m_pDefaultViewContainer, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); pView->Hide(); pView->OnCreate(); + pView->OnInitialUpdate(); pView->Show(); return pView; *************** *** 335,339 **** return NULL; ! if(!m_ViewManager.Register(pView)) { delete pView; --- 315,322 ---- return NULL; ! pView->m_pViewTemplate = pViewTemp; ! pView->m_pDocument = pDoc; ! ! if(!pView->Initialize()) { delete pView; *************** *** 341,351 **** } - pView->m_pViewTemplate = pViewTemp; - pView->m_pDocument = NULL; - if(pDoc!=NULL) - pDoc->AttachView(pView); pView->Create(m_pDefaultViewContainer, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); pView->Hide(); pView->OnCreate(); pView->Show(); return pView; --- 324,331 ---- } pView->Create(m_pDefaultViewContainer, -1, wxDefaultPosition, wxDefaultSize, wxNO_BORDER); pView->Hide(); pView->OnCreate(); + pView->OnInitialUpdate(); pView->Show(); return pView; *************** *** 368,377 **** DeleteView(pView); - //On ferme le document si il n'a plus de vue. - if(pDoc->m_ViewArray.GetCount()==0) - { - DeleteDocument(pDoc); - } - return true; } --- 348,351 ---- *************** *** 380,394 **** void DocManager::DeleteView(View *pView) { ! // Processus pre-fermeture de la vue. ! pView->OnClose(); ! ! // Détache la vue du document. ! pView->GetDocument()->DetachView(pView); ! ! // Destruction de la vue. ! pView->GetFrame()->RemoveView(pView); ! ! // Désenregistre la vue (désinscrit la vue, la finalize et la détruit). ! m_ViewManager.Unregister(pView); } --- 354,358 ---- void DocManager::DeleteView(View *pView) { ! pView->Destroy(true); } Index: Document.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/Document.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** Document.cpp 14 May 2005 12:15:56 -0000 1.11 --- Document.cpp 2 Aug 2005 12:50:54 -0000 1.12 *************** *** 55,58 **** --- 55,97 ---- ////////////////////////////////////////////////////////////////////// + // Fonctions d'interface d'élément. + + bool Document::Initialize() + { + if(!Element::Initialize()) + return false; + + if(!Application::GetApp().GetDocManager().RegisterDocument(this)) + return false; + + return true; + } + + void Document::Finalize() + { + OnCloseDocument(); + Application::GetApp().GetDocManager().UnregisterDocument(this); + Element::Finalize(); + } + + bool Document::Destroy(bool bForce) + { + if(!bForce) + if(!CanCloseDocument()) + return false; + + while(m_ViewArray.GetCount()>0) + m_ViewArray[0].Destroy(bForce); + + return Element::Destroy(bForce); + } + + bool Document::CanDestroy() + { + return Element::CanDestroy() && CanCloseDocument(); + } + + + ////////////////////////////////////////////////////////////////////// // Etat du document *************** *** 119,138 **** } - // Attache la vue en parametre au document - void Document::AttachView(View *pView) - { - if(pView->m_pDocument!=NULL) - pView->m_pDocument->DetachView(pView); - pView->m_pDocument = this; - m_ViewArray.Register(pView); - } - - // Détache la vue en parametre du document - void Document::DetachView(View *pView) - { - m_ViewArray.Unregister(pView); - pView->m_pDocument = NULL; - } - ////////////////////////////////////////////////////////////////////// // Processus de sérialisation du document --- 158,161 ---- *************** *** 222,226 **** return SaveModified(); break; ! case wxNO: // Ne pas enregistrer mais fermer return true; break; --- 245,250 ---- return SaveModified(); break; ! case wxNO: // Ne pas enregistrer mais fermer donc marquer le document comme sauvegardé ! m_bIsDocumentModified = false; return true; break; Index: View.cpp =================================================================== RCS file: /cvsroot/wxdevcenter/wxDevCenter/src/View.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** View.cpp 14 May 2005 12:15:56 -0000 1.6 --- View.cpp 2 Aug 2005 12:50:54 -0000 1.7 *************** *** 53,56 **** --- 53,108 ---- + ////////////////////////////////////////////////////////////////////// + // Fonctions virtuelles d'interface Elément + + bool View::Initialize() + { + Element::Initialize(); + + if(m_pDocument!=NULL) + if(!m_pDocument->RegisterView(this)) + return false; + if(!Application::GetApp().GetDocManager().RegisterView(this)) + { + if(m_pDocument!=NULL) + m_pDocument->UnregisterView(this); + return false; + } + if(!((ObjectManager<wxDevCenter::View>*)m_pViewTemplate)->Register(this)) + { + if(m_pDocument!=NULL) + m_pDocument->UnregisterView(this); + Application::GetApp().GetDocManager().UnregisterView(this); + return false; + } + return true; + } + + void View::Finalize() + { + m_pChildFrame->RemoveView(this); + if(m_pDocument!=NULL) + m_pDocument->UnregisterView(this); + ((ObjectManager<wxDevCenter::View>*)m_pViewTemplate)->Unregister(this); + Application::GetApp().GetDocManager().UnregisterView(this); + Element::Finalize(); + } + + bool View::Destroy(bool bForce) + { + // Processus pre-fermeture de la vue. + OnClose(); + return Element::Destroy(bForce); + } + + bool View::CanDestroy() + { + if(!m_pDocument->CanDestroy()) + return false; + return Element::CanDestroy(); + } + + + // Fixe le texte du status de la vue. void View::SetStatusText(wxString strText) |