[Libreoffice-commits] .: 2 commits - sw/source

Miklos Vajna vmiklos at kemper.freedesktop.org
Tue Jul 17 00:55:35 PDT 2012


 sw/source/core/doc/docedt.cxx   |   26 ++++++++++++++++++++++++++
 sw/source/ui/fldui/fldmgr.cxx   |   10 +++++++++-
 sw/source/ui/inc/fldmgr.hxx     |    3 ++-
 sw/source/ui/shells/textfld.cxx |    9 +++++++--
 4 files changed, 44 insertions(+), 4 deletions(-)

New commits:
commit acaa4d592a0d8cc219f7ec8a65b0c17757a856aa
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jul 16 18:42:30 2012 +0200

    fdo#38244 enable attaching comments to document text ranges in writer
    
    Change-Id: I1e1ec7e91d513bc34737c7659d1178a02e80c53e

diff --git a/sw/source/ui/fldui/fldmgr.cxx b/sw/source/ui/fldui/fldmgr.cxx
index e33c78e..e465e9f 100644
--- a/sw/source/ui/fldui/fldmgr.cxx
+++ b/sw/source/ui/fldui/fldmgr.cxx
@@ -59,6 +59,7 @@
 #include <svl/zforlist.hxx>
 #include <svl/zformat.hxx>
 #include <vcl/mnemonic.hxx>
+#include <xmloff/odffields.hxx>
 #include <view.hxx>
 #include <wrtsh.hxx>        // active window
 #include <doc.hxx>      // active window
@@ -849,7 +850,7 @@ sal_uInt16 SwFldMgr::GetCurTypeId() const
  --------------------------------------------------------------------*/
 
 
-sal_Bool SwFldMgr::InsertFld(  const SwInsertFld_Data& rData )
+sal_Bool SwFldMgr::InsertFld(  const SwInsertFld_Data& rData, SwPaM *pPam )
 {
     SwField* pFld   = 0;
     sal_Bool bExp = sal_False;
@@ -1378,6 +1379,13 @@ sal_Bool SwFldMgr::InsertFld(  const SwInsertFld_Data& rData )
     // insert
     pCurShell->StartAllAction();
 
+    if (pPam && *pPam->GetPoint() != *pPam->GetMark() && rData.nTypeId == TYP_POSTITFLD)
+    {
+        // If an annotation field is inserted, take care of the relevant fieldmark.
+        IDocumentMarkAccess* pMarksAccess = pCurShell->GetDoc()->getIDocumentMarkAccess();
+        pMarksAccess->makeFieldBookmark(*pPam, OUString(), ODF_COMMENTRANGE);
+    }
+
     pCurShell->Insert(*pFld);
 
     if(bExp && bEvalExp)
diff --git a/sw/source/ui/inc/fldmgr.hxx b/sw/source/ui/inc/fldmgr.hxx
index eabe9eb..af18d94 100644
--- a/sw/source/ui/inc/fldmgr.hxx
+++ b/sw/source/ui/inc/fldmgr.hxx
@@ -48,6 +48,7 @@ namespace com{namespace sun{namespace star{
 class SwWrtShell;
 class SwField;
 class SwFieldType;
+class SwPaM;
 class SbModule;
 class SvxMacroItem;
 class SvNumberFormatter;
@@ -141,7 +142,7 @@ public:
                         {   pWrtShell = pShell;     }
 
     // insert field using TypeID (TYP_ ...)
-    sal_Bool            InsertFld(  const SwInsertFld_Data& rData );
+    sal_Bool            InsertFld(  const SwInsertFld_Data& rData, SwPaM* pPam = 0 );
 
     // change the current field directly
     void            UpdateCurFld(sal_uLong nFormat,
diff --git a/sw/source/ui/shells/textfld.cxx b/sw/source/ui/shells/textfld.cxx
index 1292818..c07f57a 100644
--- a/sw/source/ui/shells/textfld.cxx
+++ b/sw/source/ui/shells/textfld.cxx
@@ -356,14 +356,19 @@ void SwTextShell::ExecField(SfxRequest &rReq)
                     if( !(sAuthor = aUserOpt.GetFullName()).Len())
                         if( !(sAuthor = aUserOpt.GetID()).Len() )
                             sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
+
+                    // Save the current selection, it will be required later for fieldmark insertion.
+                    SwPaM& rCurrPam = rSh.GetCurrentShellCursor();
+                    SwPaM aSaved(*rCurrPam.GetPoint(), *rCurrPam.GetMark());
                     if( rSh.HasSelection() )
                     {
-                        rSh.NormalizePam(true);
+                        rSh.NormalizePam(false);
                         rSh.KillPams();
                         rSh.ClearMark();
                     }
                     SwInsertFld_Data aData(TYP_POSTITFLD, 0, sAuthor, aEmptyStr, 0);
-                    aFldMgr.InsertFld(aData);
+                    aFldMgr.InsertFld(aData, &aSaved);
+
                     rSh.Push();
                     rSh.SwCrsrShell::Left(1, CRSR_SKIP_CHARS, sal_False);
                     pPostIt = (SwPostItField*)aFldMgr.GetCurFld();
commit 2f52f37f8363cb696bb3ead7249a87a826409908
Author: Miklos Vajna <vmiklos at suse.cz>
Date:   Mon Jul 16 16:09:52 2012 +0200

    SwDoc::DeleteRangeImplImpl: handle fieldmarks before postits
    
    These were not deleted earlier, leaving a gray field after comment
    deletion.
    
    Change-Id: I66d5e04f075a54eb0638a63b8cd7bd8c1920603e

diff --git a/sw/source/core/doc/docedt.cxx b/sw/source/core/doc/docedt.cxx
index fd75403..3655294 100644
--- a/sw/source/core/doc/docedt.cxx
+++ b/sw/source/core/doc/docedt.cxx
@@ -74,6 +74,8 @@
 #include <vcl/msgbox.hxx>
 #include "comcore.hrc"
 #include "editsh.hxx"
+#include <fldbas.hxx>
+#include <fmtfld.hxx>
 #include <unoflatpara.hxx>
 #include <SwGrammarMarkUp.hxx>
 
@@ -1639,6 +1641,30 @@ bool SwDoc::DeleteRangeImplImpl(SwPaM & rPam)
         }
     }
 
+    // Delete fieldmarks before postits.
+    if (pStt->nNode == pEnd->nNode && (pEnd->nContent.GetIndex() - pStt->nContent.GetIndex()) == 1)
+    {
+        SwTxtNode* pTxtNd = rPam.Start()->nNode.GetNode().GetTxtNode();
+        xub_StrLen nIndex = rPam.Start()->nContent.GetIndex();
+        // If there are at least two chars before the postit, we may have a fieldmark there.
+        if (pTxtNd->GetTxt().GetChar(nIndex) == CH_TXTATR_INWORD && nIndex > 1)
+        {
+            SwTxtAttr* pTxtAttr = pTxtNd->GetTxtAttrForCharAt(nIndex, RES_TXTATR_FIELD);
+            if (pTxtAttr && pTxtAttr->GetFld().GetFld()->Which() == RES_POSTITFLD && pTxtNd->GetTxt().GetChar(nIndex - 1) == CH_TXT_ATR_FIELDEND)
+            {
+                xub_StrLen nStart = pTxtNd->GetTxt().SearchBackward(CH_TXT_ATR_FIELDSTART, nIndex - 2);
+                if (nStart != STRING_NOTFOUND)
+                {
+                    SwIndex aStart(pStt->nContent);
+                    aStart = nStart;
+                    SwIndex aEnd(pEnd->nContent);
+                    aEnd = nIndex - 1;
+                    _DelBookmarks(pStt->nNode, pEnd->nNode, NULL, &aStart, &aEnd);
+                }
+            }
+        }
+    }
+
     {
         // Send DataChanged before deletion, so that we still know
         // which objects are in the range.


More information about the Libreoffice-commits mailing list