Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "crsrsh.hxx"
30 : : #include "ndtxt.hxx"
31 : : #include <docary.hxx>
32 : : #include <boost/bind.hpp>
33 : :
34 : : #include "IMark.hxx"
35 : : #include "callnk.hxx"
36 : : #include "swcrsr.hxx"
37 : : #include <IDocumentMarkAccess.hxx>
38 : : #include <IDocumentSettingAccess.hxx>
39 : :
40 : : using namespace std;
41 : :
42 : : namespace
43 : : {
44 [ # # ]: 0 : struct CrsrStateHelper
45 : : {
46 : 0 : CrsrStateHelper(SwCrsrShell& rShell)
47 : : : m_aLink(rShell)
48 [ # # ]: 0 : , m_pCrsr(rShell.GetSwCrsr())
49 [ # # ]: 0 : , m_aSaveState(*m_pCrsr)
50 : 0 : { }
51 : :
52 : 0 : void SetCrsrToMark(::sw::mark::IMark const * const pMark)
53 : : {
54 : 0 : *(m_pCrsr->GetPoint()) = pMark->GetMarkStart();
55 [ # # ]: 0 : if(pMark->IsExpanded())
56 : : {
57 : 0 : m_pCrsr->SetMark();
58 : 0 : *(m_pCrsr->GetMark()) = pMark->GetMarkEnd();
59 : : }
60 : 0 : }
61 : :
62 : : /// returns true if the Cursor had been rolled back
63 : 0 : bool RollbackIfIllegal()
64 : : {
65 [ # # ]: 0 : if(m_pCrsr->IsSelOvr(nsSwCursorSelOverFlags::SELOVER_CHECKNODESSECTION
66 : 0 : | nsSwCursorSelOverFlags::SELOVER_TOGGLE))
67 : : {
68 : 0 : m_pCrsr->DeleteMark();
69 : 0 : m_pCrsr->RestoreSavePos();
70 : 0 : return true;
71 : : }
72 : 0 : return false;
73 : : }
74 : :
75 : : SwCallLink m_aLink;
76 : : SwCursor* m_pCrsr;
77 : : SwCrsrSaveState m_aSaveState;
78 : : };
79 : :
80 : :
81 : 0 : static bool lcl_ReverseMarkOrderingByEnd(const IDocumentMarkAccess::pMark_t& rpFirst,
82 : : const IDocumentMarkAccess::pMark_t& rpSecond)
83 : : {
84 : 0 : return rpFirst->GetMarkEnd() > rpSecond->GetMarkEnd();
85 : : }
86 : :
87 : 0 : static bool lcl_IsInvisibleBookmark(IDocumentMarkAccess::pMark_t pMark)
88 : : {
89 : 0 : return IDocumentMarkAccess::GetType(*pMark) != IDocumentMarkAccess::BOOKMARK;
90 : : }
91 : : }
92 : :
93 : : // at CurCrsr.SPoint
94 : 0 : ::sw::mark::IMark* SwCrsrShell::SetBookmark(
95 : : const KeyCode& rCode,
96 : : const ::rtl::OUString& rName,
97 : : const ::rtl::OUString& rShortName,
98 : : IDocumentMarkAccess::MarkType eMark)
99 : : {
100 : 0 : StartAction();
101 : 0 : ::sw::mark::IMark* pMark = getIDocumentMarkAccess()->makeMark(
102 : 0 : *GetCrsr(),
103 : : rName,
104 : 0 : eMark);
105 [ # # ]: 0 : ::sw::mark::IBookmark* pBookmark = dynamic_cast< ::sw::mark::IBookmark* >(pMark);
106 [ # # ]: 0 : if(pBookmark)
107 : : {
108 : 0 : pBookmark->SetKeyCode(rCode);
109 : 0 : pBookmark->SetShortName(rShortName);
110 : : }
111 : 0 : EndAction();
112 : 0 : return pMark;
113 : : }
114 : : // set CurCrsr.SPoint
115 : :
116 : 0 : bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark, bool bAtStart)
117 : : {
118 : : // watch Crsr-Moves
119 [ # # ]: 0 : CrsrStateHelper aCrsrSt(*this);
120 [ # # ]: 0 : if ( bAtStart )
121 [ # # ][ # # ]: 0 : *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkStart();
122 : : else
123 [ # # ][ # # ]: 0 : *(aCrsrSt.m_pCrsr)->GetPoint() = pMark->GetMarkEnd();
124 [ # # ][ # # ]: 0 : if(aCrsrSt.RollbackIfIllegal()) return false;
125 : :
126 [ # # ]: 0 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
127 [ # # ]: 0 : return true;
128 : : }
129 : :
130 : 0 : bool SwCrsrShell::GotoMark(const ::sw::mark::IMark* const pMark)
131 : : {
132 : : // watch Crsr-Moves
133 [ # # ]: 0 : CrsrStateHelper aCrsrSt(*this);
134 [ # # ]: 0 : aCrsrSt.SetCrsrToMark(pMark);
135 : :
136 [ # # ][ # # ]: 0 : if(aCrsrSt.RollbackIfIllegal()) return false;
137 : :
138 [ # # ]: 0 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
139 [ # # ]: 0 : return true;
140 : : }
141 : :
142 : 0 : bool SwCrsrShell::GoNextBookmark()
143 : : {
144 [ # # ]: 0 : IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
145 [ # # ]: 0 : IDocumentMarkAccess::container_t vCandidates;
146 : : remove_copy_if(
147 : : upper_bound(
148 : 0 : pMarkAccess->getBookmarksBegin(),
149 : 0 : pMarkAccess->getBookmarksEnd(),
150 [ # # ]: 0 : *GetCrsr()->GetPoint(),
151 : : bind(&::sw::mark::IMark::StartsAfter, _2, _1)), // finds the first that is starting after
152 : 0 : pMarkAccess->getBookmarksEnd(),
153 : : back_inserter(vCandidates),
154 [ # # ][ # # ]: 0 : &lcl_IsInvisibleBookmark);
[ # # # # ]
[ # # ][ # # ]
[ # # ]
155 : :
156 : : // watch Crsr-Moves
157 [ # # ]: 0 : CrsrStateHelper aCrsrSt(*this);
158 [ # # ]: 0 : IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
159 [ # # ][ # # ]: 0 : for(; ppMark!=vCandidates.end(); ++ppMark)
160 : : {
161 [ # # ]: 0 : aCrsrSt.SetCrsrToMark(ppMark->get());
162 [ # # ][ # # ]: 0 : if(!aCrsrSt.RollbackIfIllegal())
163 : 0 : break; // found legal move
164 : : }
165 [ # # ][ # # ]: 0 : if(ppMark==vCandidates.end())
166 : : {
167 [ # # ]: 0 : SttEndDoc(false);
168 : 0 : return false;
169 : : }
170 : :
171 [ # # ]: 0 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
172 [ # # ]: 0 : return true;
173 : : }
174 : :
175 : 0 : bool SwCrsrShell::GoPrevBookmark()
176 : : {
177 [ # # ]: 0 : IDocumentMarkAccess* const pMarkAccess = getIDocumentMarkAccess();
178 : : // candidates from which to choose the mark before
179 : : // no need to consider marks starting after rPos
180 [ # # ]: 0 : IDocumentMarkAccess::container_t vCandidates;
181 : : remove_copy_if(
182 : 0 : pMarkAccess->getBookmarksBegin(),
183 : : upper_bound(
184 : 0 : pMarkAccess->getBookmarksBegin(),
185 : 0 : pMarkAccess->getBookmarksEnd(),
186 [ # # ]: 0 : *GetCrsr()->GetPoint(),
187 : : bind(&::sw::mark::IMark::StartsAfter, _2, _1)),
188 : : back_inserter(vCandidates),
189 [ # # ]: 0 : &lcl_IsInvisibleBookmark);
[ # # # # ]
[ # # ][ # # ]
[ # # ][ # # ]
190 : : sort(
191 : : vCandidates.begin(),
192 : : vCandidates.end(),
193 [ # # ]: 0 : &lcl_ReverseMarkOrderingByEnd);
194 : :
195 : : // watch Crsr-Moves
196 [ # # ]: 0 : CrsrStateHelper aCrsrSt(*this);
197 [ # # ]: 0 : IDocumentMarkAccess::const_iterator_t ppMark = vCandidates.begin();
198 [ # # ][ # # ]: 0 : for(; ppMark!=vCandidates.end(); ++ppMark)
199 : : {
200 : : // ignoring those not ending before the Crsr
201 : : // (we were only able to eliminate those starting
202 : : // behind the Crsr by the upper_bound(..)
203 : : // above)
204 [ # # ][ # # ]: 0 : if(!(**ppMark).EndsBefore(*GetCrsr()->GetPoint()))
[ # # ]
205 : 0 : continue;
206 [ # # ]: 0 : aCrsrSt.SetCrsrToMark(ppMark->get());
207 [ # # ][ # # ]: 0 : if(!aCrsrSt.RollbackIfIllegal())
208 : 0 : break; // found legal move
209 : : }
210 [ # # ][ # # ]: 0 : if(ppMark==vCandidates.end())
211 : : {
212 [ # # ]: 0 : SttEndDoc(true);
213 : 0 : return false;
214 : : }
215 : :
216 [ # # ]: 0 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
217 [ # # ]: 0 : return true;
218 : : }
219 : :
220 : 1318 : bool SwCrsrShell::IsFormProtected()
221 : : {
222 : 1318 : return getIDocumentSettingAccess()->get(IDocumentSettingAccess::PROTECT_FORM);
223 : : }
224 : :
225 : 0 : ::sw::mark::IFieldmark* SwCrsrShell::GetCurrentFieldmark()
226 : : {
227 : : // TODO: Refactor
228 [ # # ][ # # ]: 0 : SwPosition pos(*GetCrsr()->GetPoint());
229 [ # # ][ # # ]: 0 : return getIDocumentMarkAccess()->getFieldmarkFor(pos);
[ # # ]
230 : : }
231 : :
232 : 0 : ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkAfter()
233 : : {
234 [ # # ][ # # ]: 0 : SwPosition pos(*GetCrsr()->GetPoint());
235 [ # # ][ # # ]: 0 : return getIDocumentMarkAccess()->getFieldmarkAfter(pos);
[ # # ]
236 : : }
237 : :
238 : 0 : ::sw::mark::IFieldmark* SwCrsrShell::GetFieldmarkBefore()
239 : : {
240 [ # # ][ # # ]: 0 : SwPosition pos(*GetCrsr()->GetPoint());
241 [ # # ][ # # ]: 0 : return getIDocumentMarkAccess()->getFieldmarkBefore(pos);
[ # # ]
242 : : }
243 : :
244 : 0 : bool SwCrsrShell::GotoFieldmark(::sw::mark::IFieldmark const * const pMark)
245 : : {
246 [ # # ]: 0 : if(pMark==NULL) return false;
247 : :
248 : : // watch Crsr-Moves
249 [ # # ]: 0 : CrsrStateHelper aCrsrSt(*this);
250 [ # # ][ # # ]: 0 : aCrsrSt.SetCrsrToMark(pMark);
251 [ # # ]: 0 : aCrsrSt.m_pCrsr->GetPoint()->nContent++;
252 [ # # ]: 0 : aCrsrSt.m_pCrsr->GetMark()->nContent--;
253 [ # # ][ # # ]: 0 : if(aCrsrSt.RollbackIfIllegal()) return false;
254 : :
255 [ # # ]: 0 : UpdateCrsr(SwCrsrShell::SCROLLWIN|SwCrsrShell::CHKRANGE|SwCrsrShell::READONLY);
256 [ # # ]: 0 : return true;
257 [ + - ][ + - ]: 219 : }
258 : :
259 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|