From 93d0805b35757bbfd30ed4ae6756b9764c112c0d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 24 Nov 2012 17:37:12 +0000 Subject: [PATCH] Add wxDocManager::Get{Views,Documents,Templates}Vector(). Add accessors returning more convenient wxVectors to supplement the existing ones giving access to internally used wxLists. Closes #14814. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73004 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/docview.h | 15 +++++++++++++ interface/wx/docview.h | 42 +++++++++++++++++++++++++++++++++++++ samples/docview/docview.cpp | 7 +++++-- src/common/docview.cpp | 10 ++++----- 5 files changed, 67 insertions(+), 8 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 38b75000a3..f3b0434f2a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -687,6 +687,7 @@ All (GUI): - Added support for Korean Johab and Vietnamese encodings (jank9201). - Fix off by 1 bug with setting font size in points in wxHTML (gevorg). - Fix return value of wxGenericListCtrl::InsertColumn() (Sebastian Walderich). +- Add wxDocManager::Get{Views,Documents,Templates}Vector() (troelsk). GTK: diff --git a/include/wx/docview.h b/include/wx/docview.h index 9b8cfa7354..f4ecc68950 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -60,6 +60,12 @@ enum #define wxMAX_FILE_HISTORY 9 +#ifndef __VISUALC6__ +typedef wxVector wxDocVector; +typedef wxVector wxViewVector; +typedef wxVector wxDocTemplateVector; +#endif + class WXDLLIMPEXP_CORE wxDocument : public wxEvtHandler { public: @@ -140,8 +146,13 @@ public: virtual bool AddView(wxView *view); virtual bool RemoveView(wxView *view); + +#ifndef __VISUALC6__ + wxViewVector GetViewsVector() const { return m_documentViews.AsVector(); } +#endif wxList& GetViews() { return m_documentViews; } const wxList& GetViews() const { return m_documentViews; } + wxView *GetFirstView() const; virtual void UpdateAllViews(wxView *sender = NULL, wxObject *hint = NULL); @@ -455,6 +466,10 @@ public: virtual void ActivateView(wxView *view, bool activate = true); virtual wxView *GetCurrentView() const { return m_currentView; } +#ifndef __VISUALC6__ + wxDocVector GetDocumentsVector() const { return m_docs.AsVector(); } + wxDocTemplateVector GetTemplatesVector() const { return m_templates.AsVector(); } +#endif wxList& GetDocuments() { return m_docs; } wxList& GetTemplates() { return m_templates; } diff --git a/interface/wx/docview.h b/interface/wx/docview.h index 848c987dea..13d8b218fe 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -6,6 +6,27 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +/** + A vector of wxDocument pointers. + + @since 2.9.5 +*/ +typedef wxVector wxDocVector; + +/** + A vector of wxView pointers. + + @since 2.9.5 +*/ +typedef wxVector wxViewVector; + +/** + A vector of wxDocTemplate pointers. + + @since 2.9.5 +*/ +typedef wxVector wxDocTemplateVector; + /** @class wxDocTemplate @@ -534,6 +555,20 @@ public: */ virtual wxView* GetCurrentView() const; + /** + Returns a vector of wxDocument pointers. + + @since 2.9.5 + */ + wxDocVector GetDocumentsVector() const; + + /** + Returns a vector of wxDocTemplate pointers. + + @since 2.9.5 + */ + wxDocTemplateVector GetTemplatesVector() const; + /** Returns a reference to the list of documents. */ @@ -1299,6 +1334,13 @@ public: */ virtual wxString GetUserReadableName() const; + /** + Returns a vector of wxView pointers. + + @since 2.9.5 + */ + wxViewVector GetViewsVector() const; + //@{ /** Returns the list whose elements are the views on the document. diff --git a/samples/docview/docview.cpp b/samples/docview/docview.cpp index 6c11e54648..7c305d7e57 100644 --- a/samples/docview/docview.cpp +++ b/samples/docview/docview.cpp @@ -385,16 +385,19 @@ void MyApp::OnAbout(wxCommandEvent& WXUNUSED(event)) default: wxFAIL_MSG( "unknown mode "); } + const wxDocVector + docList = wxDocManager::GetDocumentManager()->GetDocumentsVector(); wxLogMessage ( "This is the wxWidgets Document/View Sample\n" "running in %s mode.\n" + "%d open documents.\n" "\n" "Authors: Julian Smart, Vadim Zeitlin\n" "\n" "Usage: docview [--{mdi,sdi,single}]", - modeName + modeName, + static_cast(docList.size()) ); } - diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 8ed6b129aa..849a3a2754 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -76,8 +76,6 @@ #include "wx/wfstream.h" #endif -typedef wxVector wxDocTemplates; - // ---------------------------------------------------------------------------- // wxWidgets macros // ---------------------------------------------------------------------------- @@ -1384,11 +1382,11 @@ namespace { // helper function: return only the visible templates -wxDocTemplates GetVisibleTemplates(const wxList& allTemplates) +wxDocTemplateVector GetVisibleTemplates(const wxList& allTemplates) { // select only the visible templates const size_t totalNumTemplates = allTemplates.GetCount(); - wxDocTemplates templates; + wxDocTemplateVector templates; if ( totalNumTemplates ) { templates.reserve(totalNumTemplates); @@ -1425,7 +1423,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) // this ought to be const but SelectDocumentType/Path() are not // const-correct and can't be changed as, being virtual, this risks // breaking user code overriding them - wxDocTemplates templates(GetVisibleTemplates(m_templates)); + wxDocTemplateVector templates(GetVisibleTemplates(m_templates)); const size_t numTemplates = templates.size(); if ( !numTemplates ) { @@ -1532,7 +1530,7 @@ wxDocument *wxDocManager::CreateDocument(const wxString& pathOrig, long flags) wxView *wxDocManager::CreateView(wxDocument *doc, long flags) { - wxDocTemplates templates(GetVisibleTemplates(m_templates)); + wxDocTemplateVector templates(GetVisibleTemplates(m_templates)); const size_t numTemplates = templates.size(); if ( numTemplates == 0 ) -- 2.45.2