1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include "crsrsh.hxx"
29cdf0e10cSrcweir #include "ndtxt.hxx"
30cdf0e10cSrcweir #include <docary.hxx>
31cdf0e10cSrcweir #include <boost/bind.hpp>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "IMark.hxx"
34cdf0e10cSrcweir #include "callnk.hxx"
35cdf0e10cSrcweir #include "swcrsr.hxx"
36cdf0e10cSrcweir #include <IDocumentMarkAccess.hxx>
37cdf0e10cSrcweir #include <IDocumentSettingAccess.hxx>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace std;
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace
42cdf0e10cSrcweir {
43cdf0e10cSrcweir struct CrsrStateHelper
44cdf0e10cSrcweir {
CrsrStateHelper__anon85df58550111::CrsrStateHelper45cdf0e10cSrcweir CrsrStateHelper(SwCrsrShell& rShell)
46cdf0e10cSrcweir : m_aLink(rShell)
47cdf0e10cSrcweir , m_pCrsr(rShell.GetSwCrsr())
48cdf0e10cSrcweir , m_aSaveState(*m_pCrsr)
49cdf0e10cSrcweir { }
50cdf0e10cSrcweir
SetCrsrToMark__anon85df58550111::CrsrStateHelper51cdf0e10cSrcweir void SetCrsrToMark(::sw::mark::IMark const * const pMark)
52cdf0e10cSrcweir {
53cdf0e10cSrcweir *(m_pCrsr->GetPoint()) = pMark->GetMarkStart();
54cdf0e10cSrcweir if(pMark->IsExpanded())
55cdf0e10cSrcweir {
56cdf0e10cSrcweir m_pCrsr->SetMark();
57cdf0e10cSrcweir *(m_pCrsr->GetMark()) = pMark->GetMarkEnd();
58cdf0e10cSrcweir }
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
61cdf0e10cSrcweir // returns true if the Cursor had been rolled back
RollbackIfIllegal__anon85df58550111::CrsrStateHelper62cdf0e10cSrcweir bool RollbackIfIllegal()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir if(m_pCrsr->IsSelOvr(nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION
65cdf0e10cSrcweir | nsSwCursorSelOverFlags::SELOVER_TOGGLE))
66cdf0e10cSrcweir {
67cdf0e10cSrcweir m_pCrsr->DeleteMark();
68cdf0e10cSrcweir m_pCrsr->RestoreSavePos();
69cdf0e10cSrcweir return true;
70cdf0e10cSrcweir }
71cdf0e10cSrcweir return false;
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir SwCallLink m_aLink;
75cdf0e10cSrcweir SwCursor* m_pCrsr;
76cdf0e10cSrcweir SwCrsrSaveState m_aSaveState;
77cdf0e10cSrcweir };
78cdf0e10cSrcweir
79cdf0e10cSrcweir
lcl_ReverseMarkOrderingByEnd(const IDocumentMarkAccess::pMark_t & rpFirst,const IDocumentMarkAccess::pMark_t & rpSecond)80cdf0e10cSrcweir static bool lcl_ReverseMarkOrderingByEnd(const IDocumentMarkAccess::pMark_t& rpFirst,
81cdf0e10cSrcweir const IDocumentMarkAccess::pMark_t& rpSecond)
82cdf0e10cSrcweir {
83cdf0e10cSrcweir return rpFirst->GetMarkEnd() > rpSecond->GetMarkEnd();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir
lcl_IsInvisibleBookmark(IDocumentMarkAccess::pMark_t pMark)86cdf0e10cSrcweir static bool lcl_IsInvisibleBookmark(IDocumentMarkAccess::pMark_t pMark)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir return IDocumentMarkAccess::GetType(*pMark) != IDocumentMarkAccess::BOOKMARK;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir
92cdf0e10cSrcweir // at CurCrsr.SPoint
SetBookmark(const KeyCode & rCode,const::rtl::OUString & rName,const::rtl::OUString & rShortName,IDocumentMarkAccess::MarkType eMark)93cdf0e10cSrcweir ::sw::mark::IMark* SwCrsrShell::SetBookmark(
94cdf0e10cSrcweir const KeyCode& rCode,
95cdf0e10cSrcweir const ::rtl::OUString& rName,
96cdf0e10cSrcweir const ::rtl::OUString& rShortName,
97cdf0e10cSrcweir IDocumentMarkAccess::MarkType eMark)
98cdf0e10cSrcweir {
99cdf0e10cSrcweir StartAction();
100cdf0e10cSrcweir ::sw::mark::IMark* pMark = getIDocumentMarkAccess()->makeMark(
101cdf0e10cSrcweir *GetCrsr(),
102cdf0e10cSrcweir rName,
103cdf0e10cSrcweir eMark);
104cdf0e10cSrcweir ::sw::mark::IBookmark* pBookmark = dynamic_cast< ::sw::mark::IBookmark* >(pMark);
105cdf0e10cSrcweir if(pBookmark)
106cdf0e10cSrcweir {
107cdf0e10cSrcweir pBookmark->SetKeyCode(rCode);
108cdf0e10cSrcweir pBookmark->SetShortName(rShortName);
109cdf0e10cSrcweir }
110cdf0e10cSrcweir EndAction();
111cdf0e10cSrcweir return pMark;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir // setzt CurCrsr.SPoint
114cdf0e10cSrcweir
GotoMark(const::sw::mark::IMark * const pMark,bool bAtStart)115cdf0e10cSrcweir bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark, bool bAtStart)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir // watch Crsr-Moves
118cdf0e10cSrcweir CrsrStateHelper aCrsrSt(*this);
119cdf0e10cSrcweir if ( bAtStart )
120cdf0e10cSrcweir *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkStart();
121cdf0e10cSrcweir else
122cdf0e10cSrcweir *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkEnd();
123cdf0e10cSrcweir if(aCrsrSt.RollbackIfIllegal()) return false;
124cdf0e10cSrcweir
125cdf0e10cSrcweir UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
126cdf0e10cSrcweir return true;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir
GotoMark(const::sw::mark::IMark * const pMark)129cdf0e10cSrcweir bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark)
130cdf0e10cSrcweir {
131cdf0e10cSrcweir // watch Crsr-Moves
132cdf0e10cSrcweir CrsrStateHelper aCrsrSt(*this);
133cdf0e10cSrcweir aCrsrSt.SetCrsrToMark(pMark);
134cdf0e10cSrcweir
135cdf0e10cSrcweir if(aCrsrSt.RollbackIfIllegal()) return false;
136cdf0e10cSrcweir
137cdf0e10cSrcweir UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
138cdf0e10cSrcweir return true;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
GoNextBookmark()141cdf0e10cSrcweir bool SwCrsrShell::GoNextBookmark()
142cdf0e10cSrcweir {
143cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
144cdf0e10cSrcweir IDocumentMarkAccess::container_t vCandidates;
145cdf0e10cSrcweir remove_copy_if(
146cdf0e10cSrcweir upper_bound(
147cdf0e10cSrcweir pMarkAccess->getBookmarksBegin(),
148cdf0e10cSrcweir pMarkAccess->getBookmarksEnd(),
149cdf0e10cSrcweir *GetCrsr()->GetPoint(),
150cdf0e10cSrcweir bind(&::sw::mark::IMark::StartsAfter, _2, _1)), // finds the first that is starting after
151cdf0e10cSrcweir pMarkAccess->getBookmarksEnd(),
152cdf0e10cSrcweir back_inserter(vCandidates),
153cdf0e10cSrcweir &lcl_IsInvisibleBookmark);
154cdf0e10cSrcweir
155cdf0e10cSrcweir // watch Crsr-Moves
156cdf0e10cSrcweir CrsrStateHelper aCrsrSt(*this);
157cdf0e10cSrcweir IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
158cdf0e10cSrcweir for(; ppMark!=vCandidates.end(); ++ppMark)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir aCrsrSt.SetCrsrToMark(ppMark->get());
161cdf0e10cSrcweir if(!aCrsrSt.RollbackIfIllegal())
162cdf0e10cSrcweir break; // found legal move
163cdf0e10cSrcweir }
164cdf0e10cSrcweir if(ppMark==vCandidates.end())
165cdf0e10cSrcweir {
166cdf0e10cSrcweir SttEndDoc(false);
167cdf0e10cSrcweir return false;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir
170cdf0e10cSrcweir UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
171cdf0e10cSrcweir return true;
172cdf0e10cSrcweir }
173cdf0e10cSrcweir
GoPrevBookmark()174cdf0e10cSrcweir bool SwCrsrShell::GoPrevBookmark()
175cdf0e10cSrcweir {
176cdf0e10cSrcweir IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
177cdf0e10cSrcweir // candidates from which to choose the mark before
178cdf0e10cSrcweir // no need to consider marks starting after rPos
179cdf0e10cSrcweir IDocumentMarkAccess::container_t vCandidates;
180cdf0e10cSrcweir remove_copy_if(
181cdf0e10cSrcweir pMarkAccess->getBookmarksBegin(),
182cdf0e10cSrcweir upper_bound(
183cdf0e10cSrcweir pMarkAccess->getBookmarksBegin(),
184cdf0e10cSrcweir pMarkAccess->getBookmarksEnd(),
185cdf0e10cSrcweir *GetCrsr()->GetPoint(),
186cdf0e10cSrcweir bind(&::sw::mark::IMark::StartsAfter, _2, _1)),
187cdf0e10cSrcweir back_inserter(vCandidates),
188cdf0e10cSrcweir &lcl_IsInvisibleBookmark);
189cdf0e10cSrcweir sort(
190cdf0e10cSrcweir vCandidates.begin(),
191cdf0e10cSrcweir vCandidates.end(),
192cdf0e10cSrcweir &lcl_ReverseMarkOrderingByEnd);
193cdf0e10cSrcweir
194cdf0e10cSrcweir // watch Crsr-Moves
195cdf0e10cSrcweir CrsrStateHelper aCrsrSt(*this);
196cdf0e10cSrcweir IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
197cdf0e10cSrcweir for(; ppMark!=vCandidates.end(); ++ppMark)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir // ignoring those not ending before the Crsr
200cdf0e10cSrcweir // (we were only able to eliminate those starting
201cdf0e10cSrcweir // behind the Crsr by the upper_bound(..)
202cdf0e10cSrcweir // above)
203cdf0e10cSrcweir if(!(**ppMark).EndsBefore(*GetCrsr()->GetPoint()))
204cdf0e10cSrcweir continue;
205cdf0e10cSrcweir aCrsrSt.SetCrsrToMark(ppMark->get());
206cdf0e10cSrcweir if(!aCrsrSt.RollbackIfIllegal())
207cdf0e10cSrcweir break; // found legal move
208cdf0e10cSrcweir }
209cdf0e10cSrcweir if(ppMark==vCandidates.end())
210cdf0e10cSrcweir {
211cdf0e10cSrcweir SttEndDoc(true);
212cdf0e10cSrcweir return false;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir
215cdf0e10cSrcweir UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
216cdf0e10cSrcweir return true;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
IsFormProtected()219cdf0e10cSrcweir bool SwCrsrShell::IsFormProtected()
220cdf0e10cSrcweir {
221cdf0e10cSrcweir return getIDocumentSettingAccess()->get(IDocumentSettingAccess::PROTECT_FORM);
222cdf0e10cSrcweir }
223cdf0e10cSrcweir
GetCurrentFieldmark()224cdf0e10cSrcweir ::sw::mark::IFieldmark* SwCrsrShell::GetCurrentFieldmark()
225cdf0e10cSrcweir {
226cdf0e10cSrcweir // TODO: Refactor
227cdf0e10cSrcweir SwPosition pos(*GetCrsr()->GetPoint());
228cdf0e10cSrcweir return getIDocumentMarkAccess()->getFieldmarkFor(pos);
229cdf0e10cSrcweir }
230cdf0e10cSrcweir
GetFieldmarkAfter()231cdf0e10cSrcweir ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkAfter()
232cdf0e10cSrcweir {
233cdf0e10cSrcweir SwPosition pos(*GetCrsr()->GetPoint());
234cdf0e10cSrcweir return getIDocumentMarkAccess()->getFieldmarkAfter(pos);
235cdf0e10cSrcweir }
236cdf0e10cSrcweir
GetFieldmarkBefore()237cdf0e10cSrcweir ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkBefore()
238cdf0e10cSrcweir {
239cdf0e10cSrcweir SwPosition pos(*GetCrsr()->GetPoint());
240cdf0e10cSrcweir return getIDocumentMarkAccess()->getFieldmarkBefore(pos);
241cdf0e10cSrcweir }
242cdf0e10cSrcweir
GotoFieldmark(::sw::mark::IFieldmark const * const pMark)243cdf0e10cSrcweir bool SwCrsrShell::GotoFieldmark(::sw::mark::IFieldmark const * const pMark)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir if(pMark==NULL) return false;
246cdf0e10cSrcweir
247cdf0e10cSrcweir // watch Crsr-Moves
248cdf0e10cSrcweir CrsrStateHelper aCrsrSt(*this);
249cdf0e10cSrcweir aCrsrSt.SetCrsrToMark(pMark);
250cdf0e10cSrcweir //aCrsrSt.m_pCrsr->GetPoint()->nContent--;
251cdf0e10cSrcweir //aCrsrSt.m_pCrsr->GetMark()->nContent++;
252cdf0e10cSrcweir if(aCrsrSt.RollbackIfIllegal()) return false;
253cdf0e10cSrcweir
254cdf0e10cSrcweir UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
255cdf0e10cSrcweir return true;
256cdf0e10cSrcweir }
257