Commits

Anonymous committed 8bd6c92 Merge

swbookmarkfixes01: merging minibranches

  • Participants
  • Parent commits f5c48e5, 010e598

Comments (0)

Files changed (3)

sw/inc/IDocumentMarkAccess.hxx

             const ::rtl::OUString& rProposedName,
             MarkType eMark) =0;
 
-        virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM, 
-            const rtl::OUString& rName, 
+        virtual sw::mark::IFieldmark* makeFieldBookmark( const SwPaM& rPaM,
+            const rtl::OUString& rName,
             const rtl::OUString& rType) = 0;
-        virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM, 
-            const rtl::OUString& rName, 
+        virtual sw::mark::IFieldmark* makeNoTextFieldBookmark( const SwPaM& rPaM,
+            const rtl::OUString& rName,
             const rtl::OUString& rType) = 0;
 
         /** Returns a mark in the document for a paragraph.
             an iterator pointing to the mark, or pointing to getMarksEnd() if nothing was found. 
         */
         virtual const_iterator_t findMark(const ::rtl::OUString& rMark) const =0;
+        virtual bool hasMark(const ::rtl::OUString& rMark) const =0;
 
 
         // interface IBookmarks (BOOKMARK, CROSSREF_NUMITEM_BOOKMARK, CROSSREF_HEADING_BOOKMARK)

sw/source/core/doc/MarkManager.hxx

 
 #include <IMark.hxx>
 #include <IDocumentMarkAccess.hxx>
+#include <hash_map>
 
 namespace sw { namespace mark
 {
             virtual const_iterator_t getMarksEnd() const;
             virtual sal_Int32 getMarksCount() const;
             virtual const_iterator_t findMark(const ::rtl::OUString& rName) const;
+            virtual bool hasMark(const ::rtl::OUString& rName) const;
 
             // bookmarks 
             virtual const_iterator_t getBookmarksBegin() const;
 
         private:
             // make names
+            typedef ::std::hash_map< const ::rtl::OUString, ::boost::shared_ptr<const ::sw::mark::IMark>, ::rtl::OUStringHash > namemap_t;
             ::rtl::OUString getUniqueMarkName(const ::rtl::OUString& rName) const;
             void sortMarks();
 
             container_t m_vMarks;
             container_t m_vBookmarks;
             container_t m_vFieldmarks;
+            namemap_t m_vMarksByName;
             SwDoc * const m_pDoc;
     };
 }}

sw/source/core/doc/docbm.cxx

 
         // register mark
         lcl_InsertMarkSorted(m_vMarks, pMark);
+        m_vMarksByName[pMarkBase->GetName()] = pMark;
         switch(eType)
         {
             case IDocumentMarkAccess::BOOKMARK:
         const rtl::OUString& rName,
         const rtl::OUString& rType )
     {
-        sw::mark::IMark* pMark = makeMark( rPaM, rName, 
+        sw::mark::IMark* pMark = makeMark( rPaM, rName,
                 IDocumentMarkAccess::TEXT_FIELDMARK );
         sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
         pFieldMark->SetFieldname( rType );
 
         return pFieldMark;
     }
-            
-    ::sw::mark::IFieldmark* MarkManager::makeNoTextFieldBookmark( const SwPaM& rPaM, 
-        const rtl::OUString& rName, 
+
+    ::sw::mark::IFieldmark* MarkManager::makeNoTextFieldBookmark( const SwPaM& rPaM,
+        const rtl::OUString& rName,
         const rtl::OUString& rType)
     {
-        sw::mark::IMark* pMark = makeMark( rPaM, rName, 
+        sw::mark::IMark* pMark = makeMark( rPaM, rName,
                 IDocumentMarkAccess::CHECKBOX_FIELDMARK );
         sw::mark::IFieldmark* pFieldMark = dynamic_cast<sw::mark::IFieldmark*>( pMark );
         pFieldMark->SetFieldname( rType );
             " - Mark is not in my doc.");
         if(io_pMark->GetName() == rNewName)
             return true;
-        if(findMark(rNewName) != getMarksEnd())
+        if(hasMark(rNewName))
             return false;
+        m_vMarksByName[rNewName] = m_vMarksByName[io_pMark->GetName()];
+        m_vMarksByName.erase(io_pMark->GetName());
         dynamic_cast< ::sw::mark::MarkBase* >(io_pMark)->SetName(rNewName);
         return true;
     }
         DdeBookmark* const pDdeBookmark = dynamic_cast<DdeBookmark*>(ppMark->get());
         if(pDdeBookmark)
             pDdeBookmark->DeregisterFromDoc(m_pDoc);
+        m_vMarksByName.erase((*ppMark)->GetName());
         m_vMarks.erase(m_vMarks.begin() + (ppMark - m_vMarks.begin())); // clumsy const-cast
     }
 
 
     void MarkManager::clearAllMarks()
     {
+        m_vMarksByName.clear();
         m_vFieldmarks.clear();
         m_vBookmarks.clear();
 #ifdef DEBUG
         return lcl_FindMarkByName(rName, m_vMarks.begin(), m_vMarks.end());
     }
 
+    bool MarkManager::hasMark(const ::rtl::OUString& rName) const
+    {
+        return m_vMarksByName.find(rName) != m_vMarksByName.end();
+    }
+
     IDocumentMarkAccess::const_iterator_t MarkManager::findBookmark(const ::rtl::OUString& rName) const
     {
         return lcl_FindMarkByName(rName, m_vBookmarks.begin(), m_vBookmarks.end());
         OSL_ENSURE(rName.getLength(),
             "<MarkManager::getUniqueMarkName(..)>"
             " - a name should be proposed");
-        if(findMark(rName) == getMarksEnd()) return rName;
+        if(!hasMark(rName))
+            return rName;
         ::rtl::OUStringBuffer sBuf;
         ::rtl::OUString sTmp;
         for(sal_Int32 nCnt = 1; nCnt < SAL_MAX_INT32; nCnt++)
         {
             sTmp = sBuf.append(rName).append(nCnt).makeStringAndClear();
-            if(findMark(sTmp) == getMarksEnd()) break;
+            if(!hasMark(rName))
+                break;
         }
         return sTmp;
     }