Commits

os  committed fffa316

ReferenceFieldmark added - reference to bookmark content

  • Participants
  • Parent commits 2e5208d

Comments (0)

Files changed (23)

File sw/inc/IDocumentMarkAccess.hxx

             TEXT_FIELDMARK,
             CHECKBOX_FIELDMARK,
             NAVIGATOR_REMINDER,
-            DATETIME_FIELD
+            DATETIME_FIELD,
+            REFERENCE_FIELD
         };
 
         typedef ::boost::shared_ptr< ::sw::mark::IMark> pMark_t;

File sw/inc/IFieldmarkData.hxx

 #define _IFIELDMARKDATA_HXX
 
 #include <sal/types.h>
-
 namespace com { namespace sun { namespace star { 
     namespace uno { class Any; } 
     namespace util { struct DateTime; } 
 } } }
+namespace rtl { class OUString; } 
 
 namespace sw { namespace mark
 {
     
     }; 
 
+    //field copies the text selected by a bookmark
+    //TODO: Should it also allow references to sections, tables?
+    class IReferenceFieldmarkData : virtual public IFieldmarkData 
+    {
+        public:
+            virtual const ::rtl::OUString& GetReferenceName() const = 0;
+            virtual void SetReferenceName( const ::rtl::OUString& rRefName ) = 0;
+    }; 
+
 }}
 #endif

File sw/inc/fieldmarkdata.hxx

             bool                            m_bIsDate;
             sal_Int32                       m_nOffsetMinutes;
     };
+    class ReferenceFieldmarkData : 
+            virtual public IReferenceFieldmarkData 
+    {
+        public:
+            ReferenceFieldmarkData(){}
+            ReferenceFieldmarkData( const ::rtl::OUString& rRefName ) :
+                m_sReferenceName( rRefName ){}
+            
+            virtual ~ReferenceFieldmarkData();
+            virtual const ::rtl::OUString& GetReferenceName() const;
+            virtual void SetReferenceName( const ::rtl::OUString& rRefName );
+        
+            virtual bool QueryValue( ::com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
+            virtual bool PutValue( const ::com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
+        private:
+            ::rtl::OUString m_sReferenceName;
+    }; 
+
 }
 }
 #endif

File sw/inc/unocoll.hxx

 #define SW_SERVICE_TYPE_FIELDMARK                       107
 #define SW_SERVICE_TYPE_FORMFIELDMARK                   108
 #define SW_SERVICE_TYPE_META                            109
-
-#define SW_SERVICE_LAST                 SW_SERVICE_TYPE_META
+#define SW_SERVICE_FIELDMARK_REFERENCE                  110
+#define SW_SERVICE_LAST                 SW_SERVICE_FIELDMARK_REFERENCE
 
 #define SW_SERVICE_INVALID			USHRT_MAX
 

File sw/inc/unomap.hxx

 #define PROPERTY_MAP_FLDTYP_DOCINFO_CUSTOM				97
 #define PROPERTY_MAP_METAFIELD                          98
 #define PROPERTY_MAP_FIELDMARK_DATETIME                 99
+#define PROPERTY_MAP_FIELDMARK_REFERENCE                100
 
-#define PROPERTY_MAP_END                                100
+#define PROPERTY_MAP_END                                101
 
 //S&E
 #define WID_WORDS				 0

File sw/source/core/doc/docbm.cxx

 #include <unocrsr.hxx>
 #include <viscrs.hxx>
 #include <stdio.h>
-#include <richfieldmark.hxx>
+#include <DateTimeFieldmark.hxx>
+#include <ReferenceFieldmark.hxx>
 
 using namespace ::std;
 using namespace ::boost;
         return NAVIGATOR_REMINDER;
     else if(*pMarkTypeInfo == typeid(DateTimeFieldmark))
         return DATETIME_FIELD;
+    else if(*pMarkTypeInfo == typeid(ReferenceFieldmark))
+        return REFERENCE_FIELD;
     else
     {
         OSL_ENSURE(false,
             case IDocumentMarkAccess::DATETIME_FIELD:
                 pMark = shared_ptr<IMark>(new DateTimeFieldmark(rPaM));
             break;
+            case IDocumentMarkAccess::REFERENCE_FIELD:
+                pMark = shared_ptr<IMark>(new ReferenceFieldmark(rPaM));
+            break;
         }
         OSL_ENSURE(pMark.get(),
             "MarkManager::makeMark(..)"
             // if(dynamic_cast<IFieldmark*>
                 lcl_InsertMarkSorted(m_vFieldmarks, pMark);
                 break;
+            case IDocumentMarkAccess::REFERENCE_FIELD:
             case IDocumentMarkAccess::DATETIME_FIELD:
                 lcl_InsertMarkSorted(m_vRichFieldmarks, pMark);
             break;
                 m_vFieldmarks.erase(ppFieldmark);
                 break;
             }
+            case IDocumentMarkAccess::REFERENCE_FIELD:
             case IDocumentMarkAccess::DATETIME_FIELD:
             {    
                 IDocumentMarkAccess::iterator_t ppFieldmark = lcl_FindMark(m_vRichFieldmarks, *ppMark);

File sw/source/core/fields/DateTimeFieldmark.cxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sw.hxx"
+
+#include <DateTimeFieldmark.hxx>
+#include <tools/datetime.hxx>
+#include <svl/zforlist.hxx>
+#include <svl/zformat.hxx>
+#include <doc.hxx>
+#include <swundo.hxx>
+#include <pam.hxx>
+#include <viewsh.hxx>
+#include <shellres.hxx>
+#include <ndtxt.hxx>
+#include <unocrsr.hxx>
+#include <crsskip.hxx>
+#include <com/sun/star/util/DateTime.hpp>
+
+using namespace ::sw::mark;
+using namespace ::com::sun::star;
+
+/*-- 16.11.2009 14:06:56---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+DateTimeFieldmark::DateTimeFieldmark(const SwPaM& rPaM) :
+        RichFieldmark( rPaM )
+{
+}
+/*-- 16.11.2009 14:06:56---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+DateTimeFieldmark::~DateTimeFieldmark()
+{
+}
+/*-- 16.11.2009 16:32:59---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+void DateTimeFieldmark::Update()
+{
+    SwUnoCrsr* pUnoCrsr = RichFieldmark::CreateContentCursor();
+    if( pUnoCrsr )
+    {
+        SwDoc* pDoc = pUnoCrsr->GetDoc();
+        pDoc->StartUndo( UNDO_REPLACE, NULL );
+    
+        pDoc->DeleteAndJoin( *pUnoCrsr );
+        if( !m_aData.IsFixed() )
+        {
+            DateTime aDateTime;
+            m_aData.SetDateTime(
+                util::DateTime(aDateTime.Get100Sec(), aDateTime.GetSec(), aDateTime.GetMin(), aDateTime.GetHour(), 
+                                                         aDateTime.GetDay(), aDateTime.GetMonth(), aDateTime.GetYear() ));
+        }
+
+        rtl::OUString sExpanded = ToString();
+        pDoc->InsertString( *pUnoCrsr, sExpanded );
+        // who has to put the end marker to the new end position?
+        SetOtherMarkPos(*pUnoCrsr->End());
+        delete pUnoCrsr;
+        // create new result from value
+        pDoc->EndUndo( UNDO_REPLACE, NULL );
+    }
+}
+/*-- 16.11.2009 14:06:57---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+const IFieldmarkData& DateTimeFieldmark::GetData() const
+{
+    return m_aData;
+}    
+/*-- 16.11.2009 14:06:57---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+IFieldmarkData* DateTimeFieldmark::CloneData() const
+{
+    return new DateTimeFieldmarkData( m_aData );
+}    
+/*-- 02.12.2009 13:07:58---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+bool DateTimeFieldmark::SetData(const IFieldmarkData& rNew)
+{
+    const DateTimeFieldmarkData* pNew = dynamic_cast<const DateTimeFieldmarkData*>( &rNew );
+    if( !pNew )
+        return false;               
+    m_aData = *pNew;
+    return true;
+}
+
+/*-- 16.11.2009 16:18:32---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+
+void lcl_DoubleToString(String &rValue, const double &rVal, USHORT nLng, SwDoc* pDoc ) 
+{
+    SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
+
+    // wegen Bug #60010
+    if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
+        nLng = LANGUAGE_SYSTEM;
+
+    pFormatter->ChangeIntl( nLng ); // Separator in der richtigen Sprache besorgen
+    rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
+                                    pFormatter->GetDecSep(), true );
+}
+::rtl::OUString DateTimeFieldmark::ToString() const
+{
+    if( m_aData.GetValue() >= DBL_MAX )        // show error string
+        return ViewShell::GetShellRes()->aCalc_Error;
+
+    ::rtl::OUString sExpand;
+    SwDoc* pDoc = GetMarkPos().GetDoc();
+    SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
+    Color* pCol = 0;
+
+    //todo: language support?
+    USHORT nFmtLng = LANGUAGE_SYSTEM; //::lcl_GetLanguageOfFormat( nLng, m_nNumberFormat, *pFormatter );
+
+    
+    sal_uInt32 nTempNumberFormat = m_aData.GetNumberFormat();
+    if( nTempNumberFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFmtLng )
+    {
+        short nType = NUMBERFORMAT_DEFINED;
+        xub_StrLen nDummy;
+
+        const SvNumberformat* pEntry = pFormatter->GetEntry( nTempNumberFormat );
+
+        if( pEntry /*&& nLng != pEntry->GetLanguage()*/ )
+        {
+            sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nTempNumberFormat,
+                                                    (LanguageType)nFmtLng);
+
+            if (nNewFormat == nTempNumberFormat)
+            {
+                // probably user defined format
+                String sFmt(pEntry->GetFormatstring());
+                pFormatter->PutandConvertEntry(sFmt, nDummy, nType, nTempNumberFormat,
+                                        pEntry->GetLanguage(), nFmtLng );
+            }
+            else
+                nTempNumberFormat = nNewFormat;
+        }
+        OSL_ENSURE(pEntry, "invalid number format");
+    }
+    //SvNumberformatter doesn't like rtl strings
+    String sTempExpand;
+
+    Date* pNullDate = pFormatter->GetNullDate();
+    const util::DateTime& rDT = m_aData.GetDateTime();
+    DateTime aDateTime(
+        Date( rDT.Day, rDT.Month, rDT.Year), 
+        Time( rDT.Hours, rDT.Minutes, rDT.Seconds, rDT.HundredthSeconds ));
+
+    double fVal = aDateTime - DateTime( *pNullDate );
+    sal_Int32 nOffsetMinutes = m_aData.GetOffsetMinutes();
+    if(nOffsetMinutes) 
+    {
+        fVal += (double)(nOffsetMinutes * 60L) / 86400.0;
+    }
+    
+    if( pFormatter->IsTextFormat( nTempNumberFormat ) )
+    {
+        String sValue;
+        lcl_DoubleToString(sValue, fVal, nFmtLng, pDoc);
+        pFormatter->GetOutputString(sValue, nTempNumberFormat, sTempExpand, &pCol );
+    }
+    else
+        pFormatter->GetOutputString( fVal, nTempNumberFormat, sTempExpand, &pCol);
+    sExpand = sTempExpand;
+    return sExpand;
+}
+

File sw/source/core/fields/ReferenceFieldmark.cxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_sw.hxx"
+
+#include <tools/datetime.hxx>
+#include <ReferenceFieldmark.hxx>
+#include <doc.hxx>
+#include <swundo.hxx>
+#include <pam.hxx>
+#include <viewsh.hxx>
+#include <shellres.hxx>
+#include <ndtxt.hxx>
+#include <unocrsr.hxx>
+#include <crsskip.hxx>
+
+using namespace ::sw::mark;
+
+/*-- 14.01.2010 09:54:35---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+ReferenceFieldmark::ReferenceFieldmark(const SwPaM& rPaM) :
+        RichFieldmark( rPaM )
+{
+}
+/*-- 14.01.2010 09:54:35---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+ReferenceFieldmark::~ReferenceFieldmark()
+{
+}
+/*-- 14.01.2010 09:54:36---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+void ReferenceFieldmark::Update()
+{
+    SwUnoCrsr* pUnoCrsr = RichFieldmark::CreateContentCursor();
+    if( pUnoCrsr )
+    {
+        SwDoc* pDoc = pUnoCrsr->GetDoc();
+        pDoc->StartUndo( UNDO_REPLACE, NULL );
+    
+        pDoc->DeleteAndJoin( *pUnoCrsr );
+    
+        IDocumentMarkAccess* pMarkAccess = pDoc->getIDocumentMarkAccess();
+        IDocumentMarkAccess::const_iterator_t ppMark = pMarkAccess->findMark(m_aData.GetReferenceName());
+        ::sw::mark::Bookmark* pBkmk = 0;
+        if( ppMark != pMarkAccess->getMarksEnd() &&
+            0 != (pBkmk = dynamic_cast< ::sw::mark::Bookmark* >(ppMark->get())))
+        {
+            SwPaM aCopyPaM( pBkmk->GetMarkPos(), pBkmk->GetOtherMarkPos());
+            //field position must not be inside of the bookmark
+            if( *pUnoCrsr->GetPoint() < *aCopyPaM.Start() || 
+                    *pUnoCrsr->GetPoint() > *aCopyPaM.End() )
+            {
+                pDoc->CopyRange( aCopyPaM, *pUnoCrsr->GetPoint(), false );
+            }
+        }
+        // who has to put the end marker to the new end position?
+        SetOtherMarkPos(*pUnoCrsr->End());
+        delete pUnoCrsr;
+        // create new result from value
+        pDoc->EndUndo( UNDO_REPLACE, NULL );
+    }
+}
+/*-- 14.01.2010 09:54:36---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+const IFieldmarkData& ReferenceFieldmark::GetData() const
+{
+    return m_aData;
+}
+/*-- 14.01.2010 09:54:36---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+IFieldmarkData* ReferenceFieldmark::CloneData() const
+{
+    return new ReferenceFieldmarkData( m_aData );
+}
+/*-- 14.01.2010 09:54:36---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+bool ReferenceFieldmark::SetData(const IFieldmarkData& rNew)
+{
+    const ReferenceFieldmarkData* pNew = dynamic_cast<const ReferenceFieldmarkData*>( &rNew );
+    if( !pNew )
+        return false;               
+    m_aData = *pNew;
+    return true;
+}

File sw/source/core/fields/fieldmarkdata.cxx

     return bRet;
 }
 
+/*-- 14.01.2010 09:17:14---------------------------------------------------
 
+  -----------------------------------------------------------------------*/
+ReferenceFieldmarkData::~ReferenceFieldmarkData()
+{
+}
+/*-- 14.01.2010 09:17:14---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+const ::rtl::OUString& ReferenceFieldmarkData::GetReferenceName() const
+{
+    return m_sReferenceName;
+}
+/*-- 14.01.2010 09:17:14---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+void ReferenceFieldmarkData::SetReferenceName( const ::rtl::OUString& rRefName )
+{
+    m_sReferenceName = rRefName;
+}
+/*-- 14.01.2010 09:19:47---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+bool ReferenceFieldmarkData::QueryValue( uno::Any& rVal, sal_uInt16 nWhich ) const
+{
+    bool bRet = false;
+    switch(nWhich)
+    {
+        case FIELD_PROP_PAR1:
+        {
+            rVal <<= m_sReferenceName;
+            bRet = true;
+        }
+        break;
+        default:
+            ;
+    }    
+    return bRet;
+}
+/*-- 14.01.2010 09:19:47---------------------------------------------------
+
+  -----------------------------------------------------------------------*/
+bool ReferenceFieldmarkData::PutValue( const uno::Any& rVal, sal_uInt16 nWhich )
+{
+    bool bRet = false;
+    switch(nWhich)
+    {
+        case FIELD_PROP_PAR1:
+        {
+            if( rVal >>= m_sReferenceName)
+            {
+                bRet = true;
+            }
+        }
+        break;
+        default:
+            ;
+    }    
+    return bRet;
+}
+
+

File sw/source/core/fields/makefile.mk

 		$(SLO)$/tblcalc.obj \
         $(SLO)$/usrfld.obj \
         $(SLO)$/richfieldmark.obj \
-        $(SLO)$/fieldmarkdata.obj
+        $(SLO)$/fieldmarkdata.obj \
+        $(SLO)$/DateTimeFieldmark.obj \
+        $(SLO)$/ReferenceFieldmark.obj 
 
 EXCEPTIONSFILES = \
         $(SLO)$/flddropdown.obj \

File sw/source/core/fields/richfieldmark.cxx

 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sw.hxx"
 
-#include <tools/datetime.hxx>
-#include <svl/zforlist.hxx>
-#include <svl/zformat.hxx>
 #include <richfieldmark.hxx>
 #include <doc.hxx>
-#include <swundo.hxx>
 #include <pam.hxx>
-#include <viewsh.hxx>
-#include <shellres.hxx>
 #include <ndtxt.hxx>
 #include <unocrsr.hxx>
 #include <crsskip.hxx>
-#include <com/sun/star/util/DateTime.hpp>
 
 using namespace ::sw::mark;
-using namespace ::com::sun::star;
 
 /*-- 16.11.2009 14:06:49---------------------------------------------------
 
     //AssureFieldMarksSet( pDoc );
     //create undo object!
 }
-
-/*-- 16.11.2009 14:06:56---------------------------------------------------
+/*-- 14.01.2010 10:00:55---------------------------------------------------
 
   -----------------------------------------------------------------------*/
-DateTimeFieldmark::DateTimeFieldmark(const SwPaM& rPaM) :
-        RichFieldmark( rPaM )
+SwUnoCrsr* RichFieldmark::CreateContentCursor()
 {
-}
-/*-- 16.11.2009 14:06:56---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-DateTimeFieldmark::~DateTimeFieldmark()
-{
-}
-/*-- 16.11.2009 16:32:59---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-void DateTimeFieldmark::Update()
-{
+    SwUnoCrsr* pUnoCrsr = 0;
     //todo: is it still valid
     //if( IsInContent() )
     {
         SwPaM aPam( GetOtherMarkPos(), GetMarkPos() );
         aPam.Normalize();
         SwDoc* pDoc = aPam.GetDoc();
-        pDoc->StartUndo( UNDO_REPLACE, NULL );
         // if !m_bIsFixed > update value
 #if OSL_DEBUG_LEVEL > 1        
         const sal_Unicode uStartMark = CH_TXT_ATR_FIELDSTART;
             , "start or end mark are missing");
 #endif
         //do not delete start and end marker
-        SwUnoCrsr* pUnoCrsr = pDoc->CreateUnoCrsr( *aPam.GetPoint() );
+        pUnoCrsr = pDoc->CreateUnoCrsr( *aPam.GetPoint() );
         pUnoCrsr->SetMark();
         (*pUnoCrsr->GetMark()) = *aPam.GetMark();
         //pUnoCrsr->Right( 1, CRSR_SKIP_CHARS, FALSE, FALSE );
         pUnoCrsr->Right( 1, CRSR_SKIP_CHARS, FALSE, FALSE );
         pUnoCrsr->Exchange();
-    
-        pDoc->DeleteAndJoin( *pUnoCrsr );
-        if( !m_aData.IsFixed() )
-        {
-            DateTime aDateTime;
-            m_aData.SetDateTime(
-                util::DateTime(aDateTime.Get100Sec(), aDateTime.GetSec(), aDateTime.GetMin(), aDateTime.GetHour(), 
-                                                         aDateTime.GetDay(), aDateTime.GetMonth(), aDateTime.GetYear() ));
-        }
-
-        rtl::OUString sExpanded = ToString();
-        pDoc->InsertString( *pUnoCrsr, sExpanded );
-        // who has to put the end marker to the new end position?
-        SetOtherMarkPos(*pUnoCrsr->End());
-        delete pUnoCrsr;
-        // create new result from value
-        pDoc->EndUndo( UNDO_REPLACE, NULL );
     }
+    return pUnoCrsr;
 }
-/*-- 16.11.2009 14:06:57---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-const IFieldmarkData& DateTimeFieldmark::GetData() const
-{
-    return m_aData;
-}    
-/*-- 16.11.2009 14:06:57---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-IFieldmarkData* DateTimeFieldmark::CloneData() const
-{
-    return new DateTimeFieldmarkData( m_aData );
-}    
-/*-- 02.12.2009 13:07:58---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-bool DateTimeFieldmark::SetData(const IFieldmarkData& rNew)
-{
-    const DateTimeFieldmarkData* pNew = dynamic_cast<const DateTimeFieldmarkData*>( &rNew );
-    if( !pNew )
-        return false;               
-    m_aData = *pNew;
-    return true;
-}
-
-/*-- 16.11.2009 16:18:32---------------------------------------------------
-
-  -----------------------------------------------------------------------*/
-
-void lcl_DoubleToString(String &rValue, const double &rVal, USHORT nLng, SwDoc* pDoc ) 
-{
-    SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
-
-    // wegen Bug #60010
-    if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
-        nLng = LANGUAGE_SYSTEM;
-
-    pFormatter->ChangeIntl( nLng ); // Separator in der richtigen Sprache besorgen
-    rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
-                                    pFormatter->GetDecSep(), true );
-}
-::rtl::OUString DateTimeFieldmark::ToString() const
-{
-    if( m_aData.GetValue() >= DBL_MAX )        // show error string
-        return ViewShell::GetShellRes()->aCalc_Error;
-
-    ::rtl::OUString sExpand;
-    SwDoc* pDoc = GetMarkPos().GetDoc();
-    SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
-    Color* pCol = 0;
-
-    //todo: language support?
-    USHORT nFmtLng = LANGUAGE_SYSTEM; //::lcl_GetLanguageOfFormat( nLng, m_nNumberFormat, *pFormatter );
-
-    
-    sal_uInt32 nTempNumberFormat = m_aData.GetNumberFormat();
-    if( nTempNumberFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFmtLng )
-    {
-        short nType = NUMBERFORMAT_DEFINED;
-        xub_StrLen nDummy;
-
-        const SvNumberformat* pEntry = pFormatter->GetEntry( nTempNumberFormat );
-
-        if( pEntry /*&& nLng != pEntry->GetLanguage()*/ )
-        {
-            sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn( nTempNumberFormat,
-                                                    (LanguageType)nFmtLng);
-
-            if (nNewFormat == nTempNumberFormat)
-            {
-                // probably user defined format
-                String sFmt(pEntry->GetFormatstring());
-                pFormatter->PutandConvertEntry(sFmt, nDummy, nType, nTempNumberFormat,
-                                        pEntry->GetLanguage(), nFmtLng );
-            }
-            else
-                nTempNumberFormat = nNewFormat;
-        }
-        OSL_ENSURE(pEntry, "invalid number format");
-    }
-    //SvNumberformatter doesn't like rtl strings
-    String sTempExpand;
-
-    Date* pNullDate = pFormatter->GetNullDate();
-    const util::DateTime& rDT = m_aData.GetDateTime();
-    DateTime aDateTime(
-        Date( rDT.Day, rDT.Month, rDT.Year), 
-        Time( rDT.Hours, rDT.Minutes, rDT.Seconds, rDT.HundredthSeconds ));
-
-    double fVal = aDateTime - DateTime( *pNullDate );
-    sal_Int32 nOffsetMinutes = m_aData.GetOffsetMinutes();
-    if(nOffsetMinutes) 
-    {
-        fVal += (double)(nOffsetMinutes * 60L) / 86400.0;
-    }
-    
-    if( pFormatter->IsTextFormat( nTempNumberFormat ) )
-    {
-        String sValue;
-        lcl_DoubleToString(sValue, fVal, nFmtLng, pDoc);
-        pFormatter->GetOutputString(sValue, nTempNumberFormat, sTempExpand, &pCol );
-    }
-    else
-        pFormatter->GetOutputString( fVal, nTempNumberFormat, sTempExpand, &pCol);
-    sExpand = sTempExpand;
-    return sExpand;
-}
-

File sw/source/core/inc/DateTimeFieldmark.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _DATE_TIME_FIELDMARK_HXX
+#define _DATE_TIME_FIELDMARK_HXX
+
+#include <richfieldmark.hxx>
+
+
+namespace sw { namespace mark
+{
+    class DateTimeFieldmark : public RichFieldmark
+    {
+        public:
+            DateTimeFieldmark(const SwPaM& rPaM);
+            virtual ~DateTimeFieldmark();
+        
+            //IRichFieldmark
+            virtual void Update();
+            
+            ::rtl::OUString ToString() const;
+                        
+            virtual const IFieldmarkData& GetData() const;
+            virtual IFieldmarkData* CloneData() const;
+        private:
+            virtual bool SetData(const IFieldmarkData& rNew);
+            DateTimeFieldmarkData   m_aData;
+    };
+
+    
+}}
+#endif

File sw/source/core/inc/ReferenceFieldmark.hxx

+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ * 
+ * Copyright 2008 by Sun Microsystems, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: $
+ * $Revision: $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org.  If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef _REFERENCE_FIELDMARK_HXX
+#define _REFERENCE_FIELDMARK_HXX
+
+#include <richfieldmark.hxx>
+
+
+namespace sw { namespace mark
+{
+    class ReferenceFieldmark : public RichFieldmark
+    {
+        public:
+            ReferenceFieldmark(const SwPaM& rPaM);
+            virtual ~ReferenceFieldmark();
+        
+            //IRichFieldmark
+            virtual void Update();
+            
+            //::rtl::OUString ToString() const;
+                        
+            virtual const IFieldmarkData& GetData() const;
+            virtual IFieldmarkData* CloneData() const;
+        
+        private:
+            virtual bool SetData(const IFieldmarkData& rNew);
+            ReferenceFieldmarkData   m_aData;
+    };
+
+    
+}}
+#endif

File sw/source/core/inc/richfieldmark.hxx

 #include <bookmrk.hxx>
 #include <fieldmarkdata.hxx>
 
-
+class SwUnoCrsr;
 namespace sw { namespace mark
 {
     class MarkManager;
         
             virtual const IFieldmarkData& GetData() const = 0;
             virtual IFieldmarkData* CloneData() const = 0;
+        protected:
+            SwUnoCrsr* RichFieldmark::CreateContentCursor();
         private:
             friend class MarkManager;
             virtual bool SetData(const IFieldmarkData& rNew) = 0;
             bool    m_bShowCommand;
     };
-
-    class DateTimeFieldmark : public RichFieldmark
-    {
-        public:
-            DateTimeFieldmark(const SwPaM& rPaM);
-            virtual ~DateTimeFieldmark();
-        
-            //IRichFieldmark
-            virtual void Update();
-            
-            // IValueFieldmark
-//            virtual double GetValue() const;
-//            virtual void SetValue( double fValue );
-    
-//            virtual sal_uInt32 GetNumberFormat() const;
-//            virtual void SetNumberFormat( sal_uInt32 nFormat );
-            
-//            virtual bool IsAutomaticLocale() const;
-//            virtual void SetAutomaticLocale( bool bIsAutomatic );
-
-            ::rtl::OUString ToString() const;
-                        
-            // IDateTimeFieldmark
-//            virtual bool IsFixed() const;
-//            virtual void SetIsFixed( bool bIsFixed );
-            virtual const IFieldmarkData& GetData() const;
-            virtual IFieldmarkData* CloneData() const;
-        private:
-            virtual bool SetData(const IFieldmarkData& rNew);
-            DateTimeFieldmarkData   m_aData;
-    };
-
-    
 }}
 #endif

File sw/source/core/unocore/unocoll.cxx

     { "com.sun.star.text.Fieldmark",                          SW_SERVICE_TYPE_FIELDMARK },
     { "com.sun.star.text.FormFieldmark",                      SW_SERVICE_TYPE_FORMFIELDMARK },
     { "com.sun.star.text.InContentMetadata",                  SW_SERVICE_TYPE_META },
+    { "com.sun.star.text.ReferenceFieldmark",                 SW_SERVICE_FIELDMARK_REFERENCE },
 
     // case-correct versions of the service names (see #i67811)
     { CSS_TEXT_TEXTFIELD_DATE_TIME,                   SW_SERVICE_FIELDTYPE_DATETIME },
         case SW_SERVICE_FIELDTYPE_COMBINED_CHARACTERS       :
         case SW_SERVICE_FIELDTYPE_DROPDOWN                  :
         case SW_SERVICE_FIELDTYPE_TABLE_FORMULA:
+        case SW_SERVICE_FIELDMARK_REFERENCE:
             xRet = (cppu::OWeakObject*)new SwXTextField(nObjectType);
             break;
         case SW_SERVICE_FIELDTYPE_ANNOTATION:

File sw/source/core/unocore/unofield.cxx

 	case SW_SERVICE_FIELDMASTER_DUMMY4:
 	case SW_SERVICE_FIELDMASTER_DUMMY5: nRet = PROPERTY_MAP_FLDMSTR_DUMMY0; break;
 	case SW_SERVICE_FIELDTYPE_HIDDEN_TEXT: nRet = PROPERTY_MAP_FLDTYP_HIDDEN_TEXT; break;
+    case SW_SERVICE_FIELDMARK_REFERENCE: nRet = PROPERTY_MAP_FIELDMARK_REFERENCE; break;
 	default:
 		DBG_ERROR( "wrong service id" );
 		nRet = USHRT_MAX;
                 m_pFieldmark->Update();
 			}
 			break;
+            case SW_SERVICE_FIELDMARK_REFERENCE:
+            {    
+                sw::mark::ReferenceFieldmarkData aReferenceData( m_pProps->sPar1 );
+                m_pFieldmark = 
+                    dynamic_cast< ::sw::mark::IRichFieldmark*>( pDoc->getIDocumentMarkAccess()->makeRichFieldmark(
+                        aPam, aReferenceData, IDocumentMarkAccess::REFERENCE_FIELD));
+                m_pFieldmark->Update();
+            }
+            break;
 			case SW_SERVICE_FIELDTYPE_FILE_NAME:
 			{
 				SwFieldType* pFldType = pDoc->GetSysFldType(RES_FILENAMEFLD);

File sw/source/core/unocore/unomap.cxx

                 aMapEntriesArr[nPropertyId] = aDateTimeFieldmarkPropMap;
             }
             break;
-
+            case PROPERTY_MAP_FIELDMARK_REFERENCE:
+            {    
+                static SfxItemPropertyMapEntry aReferenceFieldmarkPropMap[] =
+                {
+                    COMMON_TEXT_CONTENT_PROPERTIES
+                    {SW_PROP_NMID(UNO_NAME_SOURCE_NAME),        FIELD_PROP_PAR1,    CPPU_E2T(CPPUTYPE_OUSTRING),   PROPERTY_NONE, 0},
+                    COMMON_FLDTYP_PROPERTIES
+                    {0,0,0,0,0,0}
+                };
+                aMapEntriesArr[nPropertyId] = aReferenceFieldmarkPropMap;
+            }
+            break;
             default:
                 DBG_ERROR( "unexpected property map ID" );
 		}
             }
             break;
             case PROPERTY_MAP_FIELDMARK_DATETIME:
+            {
                 static SfxItemPropertySet aPROPERTY_MAP_FIELDMARK_DATETIME(pEntries);
                 aPropertySetArr[nPropertyId] = &aPROPERTY_MAP_FIELDMARK_DATETIME;
+            }
+            break;
+            case PROPERTY_MAP_FIELDMARK_REFERENCE:
+            {
+                static SfxItemPropertySet aPROPERTY_MAP_FIELDMARK_REFERENCE(pEntries);
+                aPropertySetArr[nPropertyId] = &aPROPERTY_MAP_FIELDMARK_REFERENCE;
+            }
             break;
         }
     }

File sw/source/core/unocore/unorichfieldmark.cxx

         case IDocumentMarkAccess::DATETIME_FIELD: 
             m_pFieldmarkData = new DateTimeFieldmarkData;
         break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            m_pFieldmarkData = new ReferenceFieldmarkData;
+        break;
         default: ;
     }
 }
         case IDocumentMarkAccess::DATETIME_FIELD: 
             nServiceId = SW_SERVICE_FIELDTYPE_DATETIME;
         break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            nServiceId = SW_SERVICE_FIELDMARK_REFERENCE;
+        break;
         default: ;
     }
     OUString sServiceName = SwXServiceProvider::GetProviderName(nServiceId);
         case IDocumentMarkAccess::DATETIME_FIELD: 
             nServiceId = SW_SERVICE_FIELDTYPE_DATETIME;
         break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            nServiceId = SW_SERVICE_FIELDMARK_REFERENCE;
+        break;
         default: ;
     }
     OUString sServiceName = SwXServiceProvider::GetProviderName(nServiceId);
 {
     vos::OGuard aGuard(Application::GetSolarMutex());
     uno::Reference< beans::XPropertySetInfo >  aRef;
+    sal_uInt16 nPropId = 0;
     switch( m_eMarkType )
     {
         case IDocumentMarkAccess::DATETIME_FIELD: 
-            aRef = aSwMapProvider.GetPropertySet( PROPERTY_MAP_FIELDMARK_DATETIME )->getPropertySetInfo();
+            nPropId = PROPERTY_MAP_FIELDMARK_DATETIME;
+        break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            nPropId = PROPERTY_MAP_FIELDMARK_REFERENCE;
         break;
         default: throw uno::RuntimeException();
     }
+    aRef = aSwMapProvider.GetPropertySet( nPropId )->getPropertySetInfo();
 
     return aRef;
 }
             lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
 {
     vos::OGuard aGuard(Application::GetSolarMutex());
-    const SfxItemPropertySet* pPropSet = 0;
+    sal_uInt16 nPropId = 0;
     switch( m_eMarkType )
     {
         case IDocumentMarkAccess::DATETIME_FIELD: 
-            pPropSet = aSwMapProvider.GetPropertySet( PROPERTY_MAP_FIELDMARK_DATETIME );
+            nPropId = PROPERTY_MAP_FIELDMARK_DATETIME;
+        break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            nPropId = PROPERTY_MAP_FIELDMARK_REFERENCE;
         break;
         default: throw uno::RuntimeException();
     }
+    const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet( nPropId );
     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName(rPropertyName);
     if( !pEntry )
     {
     throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
 {
     vos::OGuard aGuard(Application::GetSolarMutex());
-    const SfxItemPropertySet* pPropSet = 0;
+    sal_uInt16 nPropId = 0;
     switch( m_eMarkType )
     {
         case IDocumentMarkAccess::DATETIME_FIELD: 
-            pPropSet = aSwMapProvider.GetPropertySet( PROPERTY_MAP_FIELDMARK_DATETIME );
+            nPropId = PROPERTY_MAP_FIELDMARK_DATETIME;
+        break;
+        case IDocumentMarkAccess::REFERENCE_FIELD: 
+            nPropId = PROPERTY_MAP_FIELDMARK_REFERENCE;
         break;
         default: throw uno::RuntimeException();
     }
+    const SfxItemPropertySet* pPropSet = aSwMapProvider.GetPropertySet( nPropId );
     const SfxItemPropertySimpleEntry* pEntry = pPropSet->getPropertyMap()->getByName(rPropertyName);
     if( !pEntry )
     {

File sw/source/ui/fldui/fieldmarkdialog.cxx

 #include <numfmtlb.hxx>
 #include <IMark.hxx>
 #include <IFieldmarkData.hxx>
-
+#include <vcl/Fixed.hxx>
 using namespace sw::mark;
 
 struct ControlWrapper
     std::auto_ptr<IFieldmarkData>   pFieldmarkData;
     IValueFieldmarkData*            pValueData;
     IDateTimeFieldmarkData*         pDTData;
+    IReferenceFieldmarkData*        pRefData;
 
     SwFieldmarkDialog_Impl() : 
         pValueData( 0 ),
-        pDTData( 0 )
+        pDTData( 0 ),
+        pRefData( 0 )
         {}
     ~SwFieldmarkDialog_Impl();
 };    
         pCheckBox->Check( bFixed );
         pCheckBox->SetClickHdl( LINK(this, SwFieldmarkDialog, ActionHdl));
     }
+    m_pImpl->pRefData = dynamic_cast<IReferenceFieldmarkData*>( m_pImpl->pFieldmarkData.get() );
+    if( m_pImpl->pRefData )
+    {
+        FixedText* pFixedText = new FixedText( this, SW_RES( FT_REFERENCE_NAME ) );
+        Edit* pEdit = new Edit( this, SW_RES( ED_REFERENCE_NAME ) );
+        m_pImpl->aDialogControls.push_back( ControlWrapper( pFixedText, FT_REFERENCE_NAME ));
+        m_pImpl->aDialogControls.push_back( ControlWrapper( pEdit, ED_REFERENCE_NAME ));
+        sal_Int32 nTemp = nYPos;
+        lcl_MoveYPos( pFixedText, nYPos );
+        lcl_MoveYPos( pEdit, nTemp );
+        pEdit->SetText(m_pImpl->pRefData->GetReferenceName());
+        pEdit->SetModifyHdl( LINK(this, SwFieldmarkDialog, ActionHdl));
+    }    
     FreeResource();
 }
 /*-- 19.11.2009 11:24:04---------------------------------------------------
             m_pImpl->pDTData->SetIsFixed( pCheckBox->IsChecked() );
         
     }    
+    Edit* pEdit = dynamic_cast<Edit*>(pControl);
+    if( pEdit )
+    {
+        if( m_pImpl->pRefData )
+            m_pImpl->pRefData->SetReferenceName( pEdit->GetText() );
+    }    
     return true;
 }
 /*-- 03.12.2009 14:36:29---------------------------------------------------

File sw/source/ui/fldui/fieldmarkdialog.hrc

 #define FT_NUMBERFORMAT        5
 #define LB_NUMBERFORMAT        7
 #define CB_FIXED               8
-
+#define FT_REFERENCE_NAME      9 
+#define ED_REFERENCE_NAME      10
 
 #endif
 

File sw/source/ui/fldui/fieldmarkdialog.src

         DropDown = TRUE;
         Text [ en-US ] = "Number format" ;
     };
+    FixedText FT_REFERENCE_NAME
+    {
+        Pos = MAP_APPFONT ( 12 , 14 ) ;
+        Size = MAP_APPFONT ( 50 , 8 ) ;
+        Text [ en-US ] = "ReferenceName";
+    };
+    Edit ED_REFERENCE_NAME
+    {
+        Border = TRUE;
+        TabStop = TRUE;
+        Pos = MAP_APPFONT ( 60 , 12 ) ;
+        Size = MAP_APPFONT ( 50 , 14 ) ;
+        Text [ en-US ] = "ReferenceName";
+    };
     String ST_DATETIME
     {
         Text [ en-US ] = "Date and Time field";

File sw/source/ui/fldui/fldmgr.cxx

     if(!pCurShell)
         return FALSE;
     std::auto_ptr< ::sw::mark::IFieldmarkData > pFieldmarkData;
+    IDocumentMarkAccess::MarkType eMarkType = IDocumentMarkAccess::UNO_BOOKMARK;
     switch(rData.nTypeId)
 	{   // ACHTUNG dieses Feld wird ueber einen gesonderten Dialog eingefuegt
 		case TYP_POSTITFLD:
             pFieldmarkData.reset( new sw::mark::DateTimeFieldmarkData( 
                         true, nFormatId, &aDT, bFixed, rData.nTypeId == TYP_DATEFLD, 
                             rData.sPar2.ToInt32()));
+            eMarkType = IDocumentMarkAccess::DATETIME_FIELD;
             break;
 		}
 		case TYP_FILENAMEFLD:
         pCurShell->StartAllAction();
         ::sw::mark::IRichFieldmark* pFieldmark = 
                 dynamic_cast< ::sw::mark::IRichFieldmark*>( pCurShell->getIDocumentMarkAccess()->makeRichFieldmark(
-                    *pCurShell->GetCrsr(), *pFieldmarkData.get(), IDocumentMarkAccess::DATETIME_FIELD));
+                    *pCurShell->GetCrsr(), *pFieldmarkData.get(), eMarkType ));
         pFieldmark->Update();
         pCurShell->EndAllAction();
     }   

File sw/source/ui/shells/textfld.cxx

                     const sw::mark::IFieldmarkData& rData = pDlg->GetChangedData();
                     IDocumentMarkAccess* const pMarkAccess = rSh.getIDocumentMarkAccess();
                     pMarkAccess->updateRichFieldmark( *pCurFieldmark, rData );
+                    rSh.StartAction();
                     pCurFieldmark->Update();
+                    rSh.EndAction();
                 }    
                 delete pDlg;
             }