1efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5efeef26fSAndrew Rist * distributed with this work for additional information 6efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10efeef26fSAndrew Rist * 11efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12efeef26fSAndrew Rist * 13efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14efeef26fSAndrew Rist * software distributed under the License is distributed on an 15efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17efeef26fSAndrew Rist * specific language governing permissions and limitations 18efeef26fSAndrew Rist * under the License. 19efeef26fSAndrew Rist * 20efeef26fSAndrew Rist *************************************************************/ 21efeef26fSAndrew Rist 22efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include <bookmrk.hxx> 29cdf0e10cSrcweir #include <IDocumentMarkAccess.hxx> 30cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx> 31cdf0e10cSrcweir #include <doc.hxx> 32cdf0e10cSrcweir #include <errhdl.hxx> 33cdf0e10cSrcweir #include <ndtxt.hxx> 34cdf0e10cSrcweir #include <pam.hxx> 35cdf0e10cSrcweir #include <swserv.hxx> 36cdf0e10cSrcweir #include <sfx2/linkmgr.hxx> 37cdf0e10cSrcweir #include <swtypes.hxx> 38cdf0e10cSrcweir #include <UndoBookmark.hxx> 39cdf0e10cSrcweir #include <unobookmark.hxx> 40cdf0e10cSrcweir #include <rtl/random.h> 41cdf0e10cSrcweir #include <xmloff/odffields.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir 44cdf0e10cSrcweir SV_IMPL_REF( SwServerObject ) 45cdf0e10cSrcweir 46cdf0e10cSrcweir using namespace ::sw::mark; 47cdf0e10cSrcweir using namespace ::com::sun::star; 48cdf0e10cSrcweir using namespace ::com::sun::star::uno; 49cdf0e10cSrcweir 50cdf0e10cSrcweir namespace 51cdf0e10cSrcweir { lcl_FixPosition(SwPosition & rPos)52cdf0e10cSrcweir static void lcl_FixPosition(SwPosition& rPos) 53cdf0e10cSrcweir { 54cdf0e10cSrcweir // make sure the position has 1) the proper node, and 2) a proper index 55cdf0e10cSrcweir SwTxtNode* pTxtNode = rPos.nNode.GetNode().GetTxtNode(); 56cdf0e10cSrcweir if(pTxtNode == NULL && rPos.nContent.GetIndex() > 0) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir OSL_TRACE( 59cdf0e10cSrcweir "bookmrk.cxx::lcl_FixPosition" 60cdf0e10cSrcweir " - illegal position: %d without proper TxtNode", rPos.nContent.GetIndex()); 61cdf0e10cSrcweir rPos.nContent.Assign(NULL, 0); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir else if(pTxtNode != NULL && rPos.nContent.GetIndex() > pTxtNode->Len()) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir OSL_TRACE( 66cdf0e10cSrcweir "bookmrk.cxx::lcl_FixPosition" 67cdf0e10cSrcweir " - illegal position: %d is beyond %d", rPos.nContent.GetIndex(), pTxtNode->Len()); 68cdf0e10cSrcweir rPos.nContent.Assign(pTxtNode, pTxtNode->Len()); 69cdf0e10cSrcweir } 70cdf0e10cSrcweir }; 71cdf0e10cSrcweir lcl_AssureFieldMarksSet(Fieldmark * const pField,SwDoc * const io_pDoc,const sal_Unicode aStartMark,const sal_Unicode aEndMark)72cdf0e10cSrcweir static void lcl_AssureFieldMarksSet(Fieldmark* const pField, 73cdf0e10cSrcweir SwDoc* const io_pDoc, 74cdf0e10cSrcweir const sal_Unicode aStartMark, 75cdf0e10cSrcweir const sal_Unicode aEndMark) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); 78*5b9fe260SOliver-Rainer Wittmann 79*5b9fe260SOliver-Rainer Wittmann SwPosition rStart = pField->GetMarkStart(); 80*5b9fe260SOliver-Rainer Wittmann SwTxtNode const*const pStartTxtNode = rStart.nNode.GetNode().GetTxtNode(); 81*5b9fe260SOliver-Rainer Wittmann const sal_Unicode ch_start=pStartTxtNode->GetTxt().GetChar(rStart.nContent.GetIndex()); 82cdf0e10cSrcweir if(ch_start != aStartMark) 83cdf0e10cSrcweir { 84*5b9fe260SOliver-Rainer Wittmann SwPaM aStartPaM(rStart); 85cdf0e10cSrcweir io_pDoc->InsertString(aStartPaM, aStartMark); 861cd05511SOliver-Rainer Wittmann rStart.nContent--; 87*5b9fe260SOliver-Rainer Wittmann pField->SetMarkStartPos( rStart ); 88cdf0e10cSrcweir } 89*5b9fe260SOliver-Rainer Wittmann 90*5b9fe260SOliver-Rainer Wittmann const SwPosition& rEnd = pField->GetMarkEnd(); 91*5b9fe260SOliver-Rainer Wittmann SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); 92*5b9fe260SOliver-Rainer Wittmann const sal_Unicode ch_end=pEndTxtNode->GetTxt().GetChar(rEnd.nContent.GetIndex()-1); 93cdf0e10cSrcweir if ( aEndMark && ( ch_end != aEndMark ) && ( rStart != rEnd ) ) 94cdf0e10cSrcweir { 95*5b9fe260SOliver-Rainer Wittmann SwPaM aEndPaM(rEnd); 96cdf0e10cSrcweir io_pDoc->InsertString(aEndPaM, aEndMark); 97cdf0e10cSrcweir } 98*5b9fe260SOliver-Rainer Wittmann 99*5b9fe260SOliver-Rainer Wittmann 100cdf0e10cSrcweir io_pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_UI_REPLACE, NULL); 101cdf0e10cSrcweir }; 1023b32dd21SOliver-Rainer Wittmann lcl_RemoveFieldMarks(Fieldmark * const pField,SwDoc * const io_pDoc,const sal_Unicode aStartMark,const sal_Unicode aEndMark)1033b32dd21SOliver-Rainer Wittmann static void lcl_RemoveFieldMarks(Fieldmark* const pField, 1043b32dd21SOliver-Rainer Wittmann SwDoc* const io_pDoc, 1053b32dd21SOliver-Rainer Wittmann const sal_Unicode aStartMark, 1063b32dd21SOliver-Rainer Wittmann const sal_Unicode aEndMark) 1073b32dd21SOliver-Rainer Wittmann { 108*5b9fe260SOliver-Rainer Wittmann io_pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_UI_REPLACE, NULL); 109*5b9fe260SOliver-Rainer Wittmann 110*5b9fe260SOliver-Rainer Wittmann const SwPosition& rStart = pField->GetMarkStart(); 1113b32dd21SOliver-Rainer Wittmann SwTxtNode const*const pStartTxtNode = rStart.nNode.GetNode().GetTxtNode(); 1123b32dd21SOliver-Rainer Wittmann const sal_Unicode ch_start=pStartTxtNode->GetTxt().GetChar(rStart.nContent.GetIndex()); 1133b32dd21SOliver-Rainer Wittmann if( ch_start == aStartMark ) 1143b32dd21SOliver-Rainer Wittmann { 1153b32dd21SOliver-Rainer Wittmann SwPaM aStart(rStart, rStart); 1163b32dd21SOliver-Rainer Wittmann aStart.End()->nContent++; 1173b32dd21SOliver-Rainer Wittmann io_pDoc->DeleteRange(aStart); 1183b32dd21SOliver-Rainer Wittmann } 119*5b9fe260SOliver-Rainer Wittmann 120*5b9fe260SOliver-Rainer Wittmann const SwPosition& rEnd = pField->GetMarkEnd(); 121*5b9fe260SOliver-Rainer Wittmann SwTxtNode const*const pEndTxtNode = rEnd.nNode.GetNode().GetTxtNode(); 122*5b9fe260SOliver-Rainer Wittmann const xub_StrLen nEndPos = ( rEnd == rStart || rEnd.nContent.GetIndex() == 0 ) 123*5b9fe260SOliver-Rainer Wittmann ? rEnd.nContent.GetIndex() 124*5b9fe260SOliver-Rainer Wittmann : rEnd.nContent.GetIndex() - 1; 125*5b9fe260SOliver-Rainer Wittmann const sal_Unicode ch_end=pEndTxtNode->GetTxt().GetChar( nEndPos ); 1263b32dd21SOliver-Rainer Wittmann if ( ch_end == aEndMark ) 1273b32dd21SOliver-Rainer Wittmann { 1283b32dd21SOliver-Rainer Wittmann SwPaM aEnd(rEnd, rEnd); 1293b32dd21SOliver-Rainer Wittmann aEnd.Start()->nContent--; 1303b32dd21SOliver-Rainer Wittmann io_pDoc->DeleteRange(aEnd); 1313b32dd21SOliver-Rainer Wittmann } 132*5b9fe260SOliver-Rainer Wittmann 1333b32dd21SOliver-Rainer Wittmann io_pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_UI_REPLACE, NULL); 1343b32dd21SOliver-Rainer Wittmann }; 135cdf0e10cSrcweir } 136cdf0e10cSrcweir 137cdf0e10cSrcweir namespace sw { namespace mark 138cdf0e10cSrcweir { MarkBase(const SwPaM & aPaM,const::rtl::OUString & rName)139cdf0e10cSrcweir MarkBase::MarkBase(const SwPaM& aPaM, 140cdf0e10cSrcweir const ::rtl::OUString& rName) 141cdf0e10cSrcweir : SwModify(0) 142cdf0e10cSrcweir , m_pPos1(new SwPosition(*(aPaM.GetPoint()))) 143cdf0e10cSrcweir , m_aName(rName) 144cdf0e10cSrcweir { 145cdf0e10cSrcweir lcl_FixPosition(*m_pPos1); 146cdf0e10cSrcweir if (aPaM.HasMark() && (*aPaM.GetMark() != *aPaM.GetPoint())) 147cdf0e10cSrcweir { 148cdf0e10cSrcweir MarkBase::SetOtherMarkPos(*(aPaM.GetMark())); 149cdf0e10cSrcweir lcl_FixPosition(*m_pPos2); 150cdf0e10cSrcweir } 151cdf0e10cSrcweir } 152cdf0e10cSrcweir IsCoveringPosition(const SwPosition & rPos) const153cdf0e10cSrcweir bool MarkBase::IsCoveringPosition(const SwPosition& rPos) const 154cdf0e10cSrcweir { 155cdf0e10cSrcweir return GetMarkStart() <= rPos && rPos <= GetMarkEnd(); 156cdf0e10cSrcweir } 157cdf0e10cSrcweir SetMarkPos(const SwPosition & rNewPos)158cdf0e10cSrcweir void MarkBase::SetMarkPos(const SwPosition& rNewPos) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir ::boost::scoped_ptr<SwPosition>(new SwPosition(rNewPos)).swap(m_pPos1); 161cdf0e10cSrcweir //lcl_FixPosition(*m_pPos1); 162cdf0e10cSrcweir } 163cdf0e10cSrcweir SetOtherMarkPos(const SwPosition & rNewPos)164cdf0e10cSrcweir void MarkBase::SetOtherMarkPos(const SwPosition& rNewPos) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir ::boost::scoped_ptr<SwPosition>(new SwPosition(rNewPos)).swap(m_pPos2); 167cdf0e10cSrcweir //lcl_FixPosition(*m_pPos2); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir ToString() const170cdf0e10cSrcweir rtl::OUString MarkBase::ToString( ) const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir rtl::OUStringBuffer buf; 173cdf0e10cSrcweir buf.appendAscii( "Mark: ( Name, [ Node1, Index1 ] ): ( " ); 174cdf0e10cSrcweir buf.append( m_aName ).appendAscii( ", [ " ); 175cdf0e10cSrcweir buf.append( sal_Int32( GetMarkPos().nNode.GetIndex( ) ) ).appendAscii( ", " ); 176cdf0e10cSrcweir buf.append( sal_Int32( GetMarkPos().nContent.GetIndex( ) ) ).appendAscii( " ] )" ); 177cdf0e10cSrcweir 178cdf0e10cSrcweir return buf.makeStringAndClear( ); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir ~MarkBase()181cdf0e10cSrcweir MarkBase::~MarkBase() 182cdf0e10cSrcweir { } 183cdf0e10cSrcweir GenerateNewName(const::rtl::OUString & rPrefix)184cdf0e10cSrcweir ::rtl::OUString MarkBase::GenerateNewName(const ::rtl::OUString& rPrefix) 185cdf0e10cSrcweir { 186cdf0e10cSrcweir static rtlRandomPool aPool = rtl_random_createPool(); 187cdf0e10cSrcweir static ::rtl::OUString sUniquePostfix; 188cdf0e10cSrcweir static sal_Int32 nCount = SAL_MAX_INT32; 189cdf0e10cSrcweir ::rtl::OUStringBuffer aResult(rPrefix); 190cdf0e10cSrcweir if(nCount == SAL_MAX_INT32) 191cdf0e10cSrcweir { 192cdf0e10cSrcweir sal_Int32 nRandom; 193cdf0e10cSrcweir rtl_random_getBytes(aPool, &nRandom, sizeof(nRandom)); 194cdf0e10cSrcweir sUniquePostfix = ::rtl::OUStringBuffer(13).appendAscii("_").append(static_cast<sal_Int32>(abs(nRandom))).makeStringAndClear(); 195cdf0e10cSrcweir nCount = 0; 196cdf0e10cSrcweir } 197cdf0e10cSrcweir // putting the counter in front of the random parts will speed up string comparisons 198cdf0e10cSrcweir return aResult.append(nCount++).append(sUniquePostfix).makeStringAndClear(); 199cdf0e10cSrcweir } 200cdf0e10cSrcweir 201cdf0e10cSrcweir Modify(const SfxPoolItem * pOld,const SfxPoolItem * pNew)202cdf0e10cSrcweir void MarkBase::Modify( const SfxPoolItem *pOld, const SfxPoolItem *pNew ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir NotifyClients(pOld, pNew); 205cdf0e10cSrcweir if (pOld && (RES_REMOVE_UNO_OBJECT == pOld->Which())) 206cdf0e10cSrcweir { // invalidate cached uno object 207cdf0e10cSrcweir SetXBookmark(uno::Reference<text::XTextContent>(0)); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir } 210cdf0e10cSrcweir 211cdf0e10cSrcweir NavigatorReminder(const SwPaM & rPaM)212cdf0e10cSrcweir NavigatorReminder::NavigatorReminder(const SwPaM& rPaM) 213cdf0e10cSrcweir : MarkBase(rPaM, our_sNamePrefix) 214cdf0e10cSrcweir { } 215cdf0e10cSrcweir 216cdf0e10cSrcweir const ::rtl::OUString NavigatorReminder::our_sNamePrefix = ::rtl::OUString::createFromAscii("__NavigatorReminder__"); 217cdf0e10cSrcweir UnoMark(const SwPaM & aPaM)218cdf0e10cSrcweir UnoMark::UnoMark(const SwPaM& aPaM) 219cdf0e10cSrcweir : MarkBase(aPaM, MarkBase::GenerateNewName(our_sNamePrefix)) 220cdf0e10cSrcweir { } 221cdf0e10cSrcweir 222cdf0e10cSrcweir const ::rtl::OUString UnoMark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__UnoMark__"); 223cdf0e10cSrcweir DdeBookmark(const SwPaM & aPaM)224cdf0e10cSrcweir DdeBookmark::DdeBookmark(const SwPaM& aPaM) 225cdf0e10cSrcweir : MarkBase(aPaM, MarkBase::GenerateNewName(our_sNamePrefix)) 226cdf0e10cSrcweir , m_aRefObj(NULL) 227b0b7a757SOliver-Rainer Wittmann , mbInDestruction( false ) 228cdf0e10cSrcweir { } 229cdf0e10cSrcweir SetRefObject(SwServerObject * pObj)230cdf0e10cSrcweir void DdeBookmark::SetRefObject(SwServerObject* pObj) 231cdf0e10cSrcweir { 232cdf0e10cSrcweir m_aRefObj = pObj; 233cdf0e10cSrcweir } 234cdf0e10cSrcweir 235cdf0e10cSrcweir const ::rtl::OUString DdeBookmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__DdeLink__"); 236cdf0e10cSrcweir DeregisterFromDoc(SwDoc * const pDoc)237cdf0e10cSrcweir void DdeBookmark::DeregisterFromDoc(SwDoc* const pDoc) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir if(m_aRefObj.Is()) 240cdf0e10cSrcweir pDoc->GetLinkManager().RemoveServer(m_aRefObj); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir ~DdeBookmark()243cdf0e10cSrcweir DdeBookmark::~DdeBookmark() 244cdf0e10cSrcweir { 245b0b7a757SOliver-Rainer Wittmann mbInDestruction = true; 246cdf0e10cSrcweir if( m_aRefObj.Is() ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir if(m_aRefObj->HasDataLinks()) 249cdf0e10cSrcweir { 250cdf0e10cSrcweir ::sfx2::SvLinkSource* p = &m_aRefObj; 251cdf0e10cSrcweir p->SendDataChanged(); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir m_aRefObj->SetNoServer(); 254cdf0e10cSrcweir } 255cdf0e10cSrcweir } 256cdf0e10cSrcweir Bookmark(const SwPaM & aPaM,const KeyCode & rCode,const::rtl::OUString & rName,const::rtl::OUString & rShortName)257cdf0e10cSrcweir Bookmark::Bookmark(const SwPaM& aPaM, 258cdf0e10cSrcweir const KeyCode& rCode, 259cdf0e10cSrcweir const ::rtl::OUString& rName, 260cdf0e10cSrcweir const ::rtl::OUString& rShortName) 261cdf0e10cSrcweir : DdeBookmark(aPaM) 262cdf0e10cSrcweir , ::sfx2::Metadatable() 263cdf0e10cSrcweir , m_aCode(rCode) 264cdf0e10cSrcweir , m_sShortName(rShortName) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir m_aName = rName; 267cdf0e10cSrcweir } 268cdf0e10cSrcweir InitDoc(SwDoc * const io_pDoc)269cdf0e10cSrcweir void Bookmark::InitDoc(SwDoc* const io_pDoc) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir if (io_pDoc->GetIDocumentUndoRedo().DoesUndo()) 272cdf0e10cSrcweir { 273cdf0e10cSrcweir io_pDoc->GetIDocumentUndoRedo().AppendUndo( 274cdf0e10cSrcweir new SwUndoInsBookmark(*this)); 275cdf0e10cSrcweir } 276cdf0e10cSrcweir io_pDoc->SetModified(); 277cdf0e10cSrcweir } 278cdf0e10cSrcweir 279cdf0e10cSrcweir // ::sfx2::Metadatable GetRegistry()280cdf0e10cSrcweir ::sfx2::IXmlIdRegistry& Bookmark::GetRegistry() 281cdf0e10cSrcweir { 282cdf0e10cSrcweir SwDoc *const pDoc( GetMarkPos().GetDoc() ); 283cdf0e10cSrcweir OSL_ENSURE(pDoc, "Bookmark::MakeUnoObject: no doc?"); 284cdf0e10cSrcweir return pDoc->GetXmlIdRegistry(); 285cdf0e10cSrcweir } 286cdf0e10cSrcweir IsInClipboard() const287cdf0e10cSrcweir bool Bookmark::IsInClipboard() const 288cdf0e10cSrcweir { 289cdf0e10cSrcweir SwDoc *const pDoc( GetMarkPos().GetDoc() ); 290cdf0e10cSrcweir OSL_ENSURE(pDoc, "Bookmark::IsInClipboard: no doc?"); 291cdf0e10cSrcweir return pDoc->IsClipBoard(); 292cdf0e10cSrcweir } 293cdf0e10cSrcweir IsInUndo() const294cdf0e10cSrcweir bool Bookmark::IsInUndo() const 295cdf0e10cSrcweir { 296cdf0e10cSrcweir return false; 297cdf0e10cSrcweir } 298cdf0e10cSrcweir IsInContent() const299cdf0e10cSrcweir bool Bookmark::IsInContent() const 300cdf0e10cSrcweir { 301cdf0e10cSrcweir SwDoc *const pDoc( GetMarkPos().GetDoc() ); 302cdf0e10cSrcweir OSL_ENSURE(pDoc, "Bookmark::IsInContent: no doc?"); 303cdf0e10cSrcweir return !pDoc->IsInHeaderFooter( SwNodeIndex(GetMarkPos().nNode) ); 304cdf0e10cSrcweir } 305cdf0e10cSrcweir MakeUnoObject()306cdf0e10cSrcweir uno::Reference< rdf::XMetadatable > Bookmark::MakeUnoObject() 307cdf0e10cSrcweir { 308cdf0e10cSrcweir // create new SwXBookmark 309cdf0e10cSrcweir SwDoc *const pDoc( GetMarkPos().GetDoc() ); 310cdf0e10cSrcweir OSL_ENSURE(pDoc, "Bookmark::MakeUnoObject: no doc?"); 311cdf0e10cSrcweir const uno::Reference< rdf::XMetadatable> xMeta( 312cdf0e10cSrcweir SwXBookmark::CreateXBookmark(*pDoc, *this), uno::UNO_QUERY); 313cdf0e10cSrcweir return xMeta; 314cdf0e10cSrcweir } 315cdf0e10cSrcweir 316cdf0e10cSrcweir Fieldmark(const SwPaM & rPaM)317cdf0e10cSrcweir Fieldmark::Fieldmark(const SwPaM& rPaM) 318cdf0e10cSrcweir : MarkBase(rPaM, MarkBase::GenerateNewName(our_sNamePrefix)) 319cdf0e10cSrcweir { 320cdf0e10cSrcweir if(!IsExpanded()) 321cdf0e10cSrcweir SetOtherMarkPos(GetMarkPos()); 322cdf0e10cSrcweir } 323cdf0e10cSrcweir SetMarkStartPos(const SwPosition & rNewStartPos)324*5b9fe260SOliver-Rainer Wittmann void Fieldmark::SetMarkStartPos( const SwPosition& rNewStartPos ) 325*5b9fe260SOliver-Rainer Wittmann { 326*5b9fe260SOliver-Rainer Wittmann if ( GetMarkPos( ) <= GetOtherMarkPos( ) ) 327*5b9fe260SOliver-Rainer Wittmann return SetMarkPos( rNewStartPos ); 328*5b9fe260SOliver-Rainer Wittmann else 329*5b9fe260SOliver-Rainer Wittmann return SetOtherMarkPos( rNewStartPos ); 330*5b9fe260SOliver-Rainer Wittmann } 331*5b9fe260SOliver-Rainer Wittmann SetMarkEndPos(const SwPosition & rNewEndPos)332*5b9fe260SOliver-Rainer Wittmann void Fieldmark::SetMarkEndPos( const SwPosition& rNewEndPos ) 333*5b9fe260SOliver-Rainer Wittmann { 334*5b9fe260SOliver-Rainer Wittmann if ( GetMarkPos( ) <= GetOtherMarkPos( ) ) 335*5b9fe260SOliver-Rainer Wittmann return SetOtherMarkPos( rNewEndPos ); 336*5b9fe260SOliver-Rainer Wittmann else 337*5b9fe260SOliver-Rainer Wittmann return SetMarkPos( rNewEndPos ); 338*5b9fe260SOliver-Rainer Wittmann } 339*5b9fe260SOliver-Rainer Wittmann ToString() const340cdf0e10cSrcweir rtl::OUString Fieldmark::ToString( ) const 341cdf0e10cSrcweir { 342cdf0e10cSrcweir rtl::OUStringBuffer buf; 343cdf0e10cSrcweir buf.appendAscii( "Fieldmark: ( Name, Type, [ Nd1, Id1 ], [ Nd2, Id2 ] ): ( " ); 344cdf0e10cSrcweir buf.append( m_aName ).appendAscii( ", " ); 345cdf0e10cSrcweir buf.append( m_aFieldname ).appendAscii( ", [ " ); 346cdf0e10cSrcweir buf.append( sal_Int32( GetMarkPos().nNode.GetIndex( ) ) ).appendAscii( ", " ); 347cdf0e10cSrcweir buf.append( sal_Int32( GetMarkPos( ).nContent.GetIndex( ) ) ).appendAscii( " ], [" ); 348cdf0e10cSrcweir buf.append( sal_Int32( GetOtherMarkPos().nNode.GetIndex( ) ) ).appendAscii( ", " ); 349cdf0e10cSrcweir buf.append( sal_Int32( GetOtherMarkPos( ).nContent.GetIndex( ) ) ).appendAscii( " ] ) " ); 350cdf0e10cSrcweir 351cdf0e10cSrcweir return buf.makeStringAndClear( ); 352cdf0e10cSrcweir } 353cdf0e10cSrcweir Invalidate()354cdf0e10cSrcweir void Fieldmark::Invalidate( ) 355cdf0e10cSrcweir { 356cdf0e10cSrcweir // @TODO: Does exist a better solution to trigger a format of the 357cdf0e10cSrcweir // fieldmark portion? If yes, please use it. 358cdf0e10cSrcweir SwPaM aPaM( this->GetMarkPos(), this->GetOtherMarkPos() ); 359cdf0e10cSrcweir aPaM.InvalidatePaM(); 360cdf0e10cSrcweir } 361cdf0e10cSrcweir 362cdf0e10cSrcweir const ::rtl::OUString Fieldmark::our_sNamePrefix = ::rtl::OUString::createFromAscii("__Fieldmark__"); 363cdf0e10cSrcweir TextFieldmark(const SwPaM & rPaM)364cdf0e10cSrcweir TextFieldmark::TextFieldmark(const SwPaM& rPaM) 365cdf0e10cSrcweir : Fieldmark(rPaM) 366cdf0e10cSrcweir { } 367cdf0e10cSrcweir InitDoc(SwDoc * const io_pDoc)368cdf0e10cSrcweir void TextFieldmark::InitDoc(SwDoc* const io_pDoc) 369cdf0e10cSrcweir { 370cdf0e10cSrcweir lcl_AssureFieldMarksSet(this, io_pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND); 371cdf0e10cSrcweir } 372cdf0e10cSrcweir ReleaseDoc(SwDoc * const pDoc)3733b32dd21SOliver-Rainer Wittmann void TextFieldmark::ReleaseDoc(SwDoc* const pDoc) 3743b32dd21SOliver-Rainer Wittmann { 3753b32dd21SOliver-Rainer Wittmann lcl_RemoveFieldMarks(this, pDoc, CH_TXT_ATR_FIELDSTART, CH_TXT_ATR_FIELDEND); 3763b32dd21SOliver-Rainer Wittmann } 3773b32dd21SOliver-Rainer Wittmann CheckboxFieldmark(const SwPaM & rPaM)378cdf0e10cSrcweir CheckboxFieldmark::CheckboxFieldmark(const SwPaM& rPaM) 379cdf0e10cSrcweir : Fieldmark(rPaM) 380cdf0e10cSrcweir { } 381cdf0e10cSrcweir InitDoc(SwDoc * const io_pDoc)382cdf0e10cSrcweir void CheckboxFieldmark::InitDoc(SwDoc* const io_pDoc) 383cdf0e10cSrcweir { 384cdf0e10cSrcweir lcl_AssureFieldMarksSet(this, io_pDoc, CH_TXT_ATR_FORMELEMENT, CH_TXT_ATR_FIELDEND); 385cdf0e10cSrcweir 386cdf0e10cSrcweir // For some reason the end mark is moved from 1 by the Insert: we don't 387cdf0e10cSrcweir // want this for checkboxes 388*5b9fe260SOliver-Rainer Wittmann SwPosition aNewEndPos = this->GetMarkEnd(); 389*5b9fe260SOliver-Rainer Wittmann aNewEndPos.nContent--; 390*5b9fe260SOliver-Rainer Wittmann SetMarkEndPos( aNewEndPos ); 391cdf0e10cSrcweir } SetChecked(bool checked)392cdf0e10cSrcweir void CheckboxFieldmark::SetChecked(bool checked) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir (*GetParameters())[::rtl::OUString::createFromAscii(ODF_FORMCHECKBOX_RESULT)] = makeAny(checked); 395cdf0e10cSrcweir } 396cdf0e10cSrcweir IsChecked() const397cdf0e10cSrcweir bool CheckboxFieldmark::IsChecked() const 398cdf0e10cSrcweir { 399cdf0e10cSrcweir bool bResult = false; 400cdf0e10cSrcweir parameter_map_t::const_iterator pResult = GetParameters()->find(::rtl::OUString::createFromAscii(ODF_FORMCHECKBOX_RESULT)); 401cdf0e10cSrcweir if(pResult != GetParameters()->end()) 402cdf0e10cSrcweir pResult->second >>= bResult; 403cdf0e10cSrcweir return bResult; 404cdf0e10cSrcweir } 405cdf0e10cSrcweir 406cdf0e10cSrcweir }} 407