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 : :
30 : : #include "Outliner.hxx"
31 : : #include <vcl/wrkwin.hxx>
32 : : #include <svl/srchitem.hxx>
33 : : #include <editeng/colritem.hxx>
34 : : #include <editeng/eeitem.hxx>
35 : : #include <editeng/editstat.hxx>
36 : : #include <vcl/outdev.hxx>
37 : : #include <svx/dlgutil.hxx>
38 : : #include <svx/xtable.hxx>
39 : : #include <vcl/msgbox.hxx>
40 : : #include <sfx2/dispatch.hxx>
41 : : #include <sfx2/printer.hxx>
42 : : #include <svx/svxerr.hxx>
43 : : #include <svx/svdotext.hxx>
44 : : #include <editeng/unolingu.hxx>
45 : : #include <svx/svditer.hxx>
46 : : #include <comphelper/extract.hxx>
47 : : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
48 : : #include <com/sun/star/beans/XPropertySet.hpp>
49 : : #include <comphelper/processfactory.hxx>
50 : : #include <editeng/forbiddencharacterstable.hxx>
51 : : #include <svx/srchdlg.hxx>
52 : : #include <unotools/linguprops.hxx>
53 : : #include <unotools/lingucfg.hxx>
54 : : #include <editeng/editeng.hxx>
55 : : #include <vcl/metric.hxx>
56 : : #include <sfx2/viewfrm.hxx>
57 : : #include <svtools/langtab.hxx>
58 : : #include <tools/diagnose_ex.h>
59 : :
60 : : #include "strings.hrc"
61 : : #include "sdstring.hrc"
62 : : #include "eetext.hxx"
63 : : #include "sdpage.hxx"
64 : : #include "app.hxx"
65 : : #include "Window.hxx"
66 : : #include "sdresid.hxx"
67 : : #include "DrawViewShell.hxx"
68 : : #include "OutlineViewShell.hxx"
69 : : #include "drawdoc.hxx"
70 : : #include "DrawDocShell.hxx"
71 : : #include "FrameView.hxx"
72 : : #include "optsitem.hxx"
73 : : #include "drawview.hxx"
74 : : #include "ViewShellBase.hxx"
75 : : #include "SpellDialogChildWindow.hxx"
76 : : #include "ToolBarManager.hxx"
77 : : #include "framework/FrameworkHelper.hxx"
78 : : #include <svx/svxids.hrc>
79 : : #include <editeng/editerr.hxx>
80 : :
81 : : using ::rtl::OUString;
82 : : using namespace ::com::sun::star;
83 : : using namespace ::com::sun::star::uno;
84 : : using namespace ::com::sun::star::lang;
85 : : using namespace ::com::sun::star::linguistic2;
86 : :
87 : : class SfxStyleSheetPool;
88 : :
89 : : namespace sd {
90 : :
91 : : class Outliner::Implementation
92 : : {
93 : : public:
94 : : /** The original edit mode directly after switching to a different view
95 : : mode. Used for restoring the edit mode when leaving that view mode
96 : : again.
97 : : */
98 : : EditMode meOriginalEditMode;
99 : :
100 : : Implementation (void);
101 : : ~Implementation (void);
102 : :
103 : : /** Return the OutlinerView that was provided by the last call to
104 : : ProvideOutlinerView() (or NULL when there was no such call.)
105 : : */
106 : : OutlinerView* GetOutlinerView (void);
107 : :
108 : : /** Provide in the member mpOutlineView an instance of OutlinerView that
109 : : is either taken from the ViewShell, when it is an OutlineViewShell,
110 : : or is created. When an OutlinerView already exists it is initialied.
111 : : */
112 : : void ProvideOutlinerView (
113 : : Outliner& rOutliner,
114 : : const ::boost::shared_ptr<ViewShell>& rpViewShell,
115 : : ::Window* pWindow);
116 : :
117 : : /** This method is called when the OutlinerView is no longer used.
118 : : */
119 : : void ReleaseOutlinerView (void);
120 : :
121 : : private:
122 : : /** Flag that specifies whether we own the outline view pointed to by
123 : : <member>mpOutlineView</member> and thus have to
124 : : delete it in <member>EndSpelling()</member>.
125 : : */
126 : : bool mbOwnOutlineView;
127 : :
128 : : /** The outline view used for searching and spelling. If searching or
129 : : spell checking an outline view this data member points to that view.
130 : : For all other views an instance is created. The
131 : : <member>mbOwnOutlineView</member> distinguishes between both cases.
132 : : */
133 : : OutlinerView* mpOutlineView;
134 : : };
135 : :
136 : :
137 : :
138 : :
139 : : /*************************************************************************
140 : : |*
141 : : |* Ctor
142 : : |*
143 : : \************************************************************************/
144 : :
145 : 154 : Outliner::Outliner( SdDrawDocument* pDoc, sal_uInt16 nMode )
146 : 154 : : SdrOutliner( &pDoc->GetItemPool(), nMode ),
147 : : mpImpl(new Implementation()),
148 : : meMode(SEARCH),
149 : : mpView(NULL),
150 : : mpWeakViewShell(),
151 : : mpWindow(NULL),
152 : : mpDrawDocument(pDoc),
153 : : mnConversionLanguage(LANGUAGE_NONE),
154 : : mnIgnoreCurrentPageChangesLevel(0),
155 : : mbStringFound(sal_False),
156 : : mbMatchMayExist(false),
157 : : mnPageCount(0),
158 : : mnObjectCount(0),
159 : : mbEndOfSearch(sal_False),
160 : : mbFoundObject(sal_False),
161 : : mbError(sal_False),
162 : : mbDirectionIsForward(true),
163 : : mbRestrictSearchToSelection(false),
164 : : maMarkListCopy(),
165 : : mbProcessCurrentViewOnly(false),
166 : : mpObj(NULL),
167 : : mpFirstObj(NULL),
168 : : mpTextObj(NULL),
169 : : mnText(0),
170 : : mpParaObj(NULL),
171 : : meStartViewMode(PK_STANDARD),
172 : : meStartEditMode(EM_PAGE),
173 : : mnStartPageIndex((sal_uInt16)-1),
174 : : mpStartEditedObject(NULL),
175 : : maStartSelection(),
176 : : mpSearchItem(NULL),
177 : : maObjectIterator(),
178 : : maCurrentPosition(),
179 : : maSearchStartPosition(),
180 : : maLastValidPosition(),
181 : : mbSelectionHasChanged(false),
182 : : mbExpectingSelectionChangeEvent(false),
183 : : mbWholeDocumentProcessed(false),
184 [ + - ][ + - ]: 154 : mbPrepareSpellingPending(true)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
185 : : {
186 [ + - ][ + - ]: 154 : SetStyleSheetPool((SfxStyleSheetPool*) mpDrawDocument->GetStyleSheetPool());
187 [ + - ]: 154 : SetEditTextObjectPool( &pDoc->GetItemPool() );
188 [ + - ][ + - ]: 154 : SetCalcFieldValueHdl(LINK(SD_MOD(), SdModule, CalcFieldValueHdl));
189 [ + - ][ + - ]: 154 : SetForbiddenCharsTable( pDoc->GetForbiddenCharsTable() );
[ + - ]
190 : :
191 [ + - ]: 154 : sal_uLong nCntrl = GetControlWord();
192 : 154 : nCntrl |= EE_CNTRL_ALLOWBIGOBJS;
193 : 154 : nCntrl |= EE_CNTRL_URLSFXEXECUTE;
194 : 154 : nCntrl |= EE_CNTRL_MARKFIELDS;
195 : 154 : nCntrl |= EE_CNTRL_AUTOCORRECT;
196 : :
197 : 154 : sal_Bool bOnlineSpell = false;
198 : :
199 : 154 : DrawDocShell* pDocSh = mpDrawDocument->GetDocSh();
200 : :
201 [ + - ]: 154 : if (pDocSh)
202 : : {
203 : 154 : bOnlineSpell = mpDrawDocument->GetOnlineSpell();
204 : : }
205 : : else
206 : : {
207 : 0 : bOnlineSpell = false;
208 : :
209 : : try
210 : : {
211 [ # # ]: 0 : const SvtLinguConfig aLinguConfig;
212 : 0 : Any aAny;
213 : :
214 [ # # ]: 0 : aAny = aLinguConfig.GetProperty( UPN_IS_SPELL_AUTO );
215 [ # # ]: 0 : aAny >>= bOnlineSpell;
216 : : }
217 [ # # ]: 0 : catch( ... )
218 : : {
219 : : OSL_FAIL( "Ill. type in linguistic property" );
220 : : }
221 : : }
222 : :
223 [ + - ]: 154 : if (bOnlineSpell)
224 : 154 : nCntrl |= EE_CNTRL_ONLINESPELLING;
225 : : else
226 : 0 : nCntrl &= ~EE_CNTRL_ONLINESPELLING;
227 : :
228 [ + - ]: 154 : SetControlWord(nCntrl);
229 : :
230 [ + - ]: 154 : Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
231 [ + - ]: 154 : if ( xSpellChecker.is() )
232 [ + - ]: 154 : SetSpeller( xSpellChecker );
233 : :
234 [ + - ]: 154 : Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
235 [ + - ]: 154 : if( xHyphenator.is() )
236 [ + - ]: 154 : SetHyphenator( xHyphenator );
237 : :
238 [ + - ][ + - ]: 154 : SetDefaultLanguage( Application::GetSettings().GetLanguage() );
[ + - ]
239 : 154 : }
240 : :
241 : :
242 : :
243 : :
244 : : /// Nothing spectecular in the destructor.
245 [ + - ][ + - ]: 151 : Outliner::~Outliner (void)
[ + - ][ + - ]
[ + - ][ + - ]
246 : : {
247 : 151 : mpImpl.reset();
248 [ - + ]: 302 : }
249 : :
250 : :
251 : :
252 : :
253 : : /** Prepare find&replace or spellchecking. This distinguishes between three
254 : : cases:
255 : : <ol>
256 : : <li>The current shell is a <type>DrawViewShell</type>: Create a
257 : : <type>OutlinerView</type> object and search all objects of (i) the
258 : : current mark list, (ii) of the current view, or (iii) of all the view
259 : : combinations:
260 : : <ol>
261 : : <li>Draw view, slide view</li>
262 : : <li>Draw view, background view</li>
263 : : <li>Notes view, slide view</li>
264 : : <li>Notes view, background view</li>
265 : : <li>Handout view, slide view</li>
266 : : <li>Handout view, background view</li>
267 : : </ol>
268 : :
269 : : <li>When the current shell is a <type>SdOutlineViewShell</type> then
270 : : directly operate on it. No switching into other views takes place.</li>
271 : : </ol>
272 : : */
273 : 0 : void Outliner::PrepareSpelling (void)
274 : : {
275 : 0 : mbPrepareSpellingPending = false;
276 : :
277 [ # # ][ # # ]: 0 : ViewShellBase* pBase = PTR_CAST(ViewShellBase,SfxViewShell::Current());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
278 [ # # ]: 0 : if (pBase != NULL)
279 [ # # ][ # # ]: 0 : SetViewShell (pBase->GetMainViewShell());
[ # # ]
280 [ # # ][ # # ]: 0 : SetRefDevice( SD_MOD()->GetRefDevice( *mpDrawDocument->GetDocSh() ) );
[ # # ]
281 : :
282 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
283 [ # # ]: 0 : if (pViewShell)
284 : : {
285 : 0 : mbStringFound = sal_False;
286 : :
287 : 0 : mbWholeDocumentProcessed = false;
288 : : // Supposed that we are not located at the very beginning/end of
289 : : // the document then there may be a match in the document
290 : : // prior/after the current position.
291 : 0 : mbMatchMayExist = sal_True;
292 : :
293 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::Iterator();
[ # # ]
294 [ # # ][ # # ]: 0 : maSearchStartPosition = ::sd::outliner::Iterator();
[ # # ]
295 [ # # ]: 0 : RememberStartPosition();
296 : :
297 [ # # ]: 0 : mpImpl->ProvideOutlinerView(*this, pViewShell, mpWindow);
298 : :
299 [ # # ]: 0 : HandleChangedSelection ();
300 : : }
301 [ # # ][ # # ]: 0 : ClearModifyFlag();
302 : 0 : }
303 : :
304 : :
305 : :
306 : :
307 : :
308 : 0 : void Outliner::StartSpelling (void)
309 : : {
310 : 0 : meMode = SPELL;
311 : 0 : mbDirectionIsForward = true;
312 : 0 : mpSearchItem = NULL;
313 : 0 : }
314 : :
315 : : /** Proxy for method from base class to avoid compiler warning */
316 : 0 : void Outliner::StartSpelling(EditView& rView, unsigned char c)
317 : : {
318 : 0 : SdrOutliner::StartSpelling( rView, c );
319 : 0 : }
320 : :
321 : : /** Free all resources acquired during the search/spell check. After a
322 : : spell check the start position is restored here.
323 : : */
324 : 0 : void Outliner::EndSpelling (void)
325 : : {
326 : : // Keep old view shell alive until we release the outliner view.
327 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
328 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pOldViewShell (pViewShell);
329 : :
330 [ # # ][ # # ]: 0 : ViewShellBase* pBase = PTR_CAST(ViewShellBase,SfxViewShell::Current());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
331 [ # # ]: 0 : if (pBase != NULL)
332 [ # # ][ # # ]: 0 : pViewShell = pBase->GetMainViewShell();
[ # # ]
333 : : else
334 [ # # ]: 0 : pViewShell.reset();
335 [ # # ]: 0 : mpWeakViewShell = pViewShell;
336 : :
337 : : // When in <member>PrepareSpelling()</member> a new outline view has
338 : : // been created then delete it here.
339 [ # # ][ # # ]: 0 : sal_Bool bViewIsDrawViewShell(pViewShell && pViewShell->ISA(DrawViewShell));
[ # # ][ # # ]
340 [ # # ]: 0 : if (bViewIsDrawViewShell)
341 : : {
342 [ # # ][ # # ]: 0 : SetStatusEventHdl(Link());
343 : 0 : mpView = pViewShell->GetView();
344 [ # # ]: 0 : mpView->UnmarkAllObj (mpView->GetSdrPageView());
345 [ # # ]: 0 : mpView->SdrEndTextEdit();
346 : : // Make FuSelection the current function.
347 : 0 : pViewShell->GetDispatcher()->Execute(
348 : : SID_OBJECT_SELECT,
349 [ # # ][ # # ]: 0 : SFX_CALLMODE_SYNCHRON | SFX_CALLMODE_RECORD);
350 : :
351 : : // Remove and, if previously created by us, delete the outline
352 : : // view.
353 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
354 [ # # ]: 0 : if (pOutlinerView != NULL)
355 : : {
356 [ # # ]: 0 : RemoveView(pOutlinerView);
357 [ # # ]: 0 : mpImpl->ReleaseOutlinerView();
358 : : }
359 : :
360 [ # # ]: 0 : SetUpdateMode(sal_True);
361 : : }
362 : :
363 : : // Before clearing the modify flag use it as a hint that
364 : : // changes were done at SpellCheck
365 [ # # ][ # # ]: 0 : if(IsModified())
366 : : {
367 [ # # ][ # # ]: 0 : if(mpView && mpView->ISA(OutlineView))
[ # # ][ # # ]
[ # # ]
368 [ # # ]: 0 : static_cast<OutlineView*>(mpView)->PrepareClose(sal_False);
369 [ # # ][ # # ]: 0 : if(mpDrawDocument && !mpDrawDocument->IsChanged())
[ # # ]
370 [ # # ]: 0 : mpDrawDocument->SetChanged(sal_True);
371 : : }
372 : :
373 : : // Now clear the modify flag to have a specified state of
374 : : // Outliner
375 [ # # ]: 0 : ClearModifyFlag();
376 : :
377 : : // When spell checking then restore the start position.
378 [ # # ][ # # ]: 0 : if (meMode==SPELL || meMode==TEXT_CONVERSION)
379 [ # # ]: 0 : RestoreStartPosition ();
380 : :
381 [ # # ]: 0 : mpWeakViewShell.reset();
382 : 0 : mpView = NULL;
383 : 0 : mpWindow = NULL;
384 [ # # ][ # # ]: 0 : mnStartPageIndex = (sal_uInt16) -1;
385 : 0 : }
386 : :
387 : :
388 : :
389 : :
390 : 0 : sal_Bool Outliner::SpellNextDocument (void)
391 : : {
392 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
393 [ # # ][ # # ]: 0 : if (pViewShell->ISA(OutlineViewShell))
[ # # ]
394 : : {
395 : : // When doing a spell check in the outline view then there is
396 : : // only one document.
397 : 0 : mbEndOfSearch = true;
398 [ # # ]: 0 : EndOfSearch ();
399 : : }
400 : : else
401 : : {
402 [ # # ][ # # ]: 0 : if (mpView->ISA(OutlineView))
[ # # ]
403 [ # # ]: 0 : ((OutlineView*)mpView)->PrepareClose(sal_False);
404 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_True );
405 : :
406 [ # # ]: 0 : Initialize (true);
407 : :
408 [ # # ]: 0 : mpWindow = pViewShell->GetActiveWindow();
409 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
410 [ # # ]: 0 : if (pOutlinerView != NULL)
411 [ # # ]: 0 : pOutlinerView->SetWindow(mpWindow);
412 [ # # ]: 0 : ProvideNextTextObject ();
413 : :
414 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
415 [ # # ]: 0 : ClearModifyFlag();
416 : : }
417 : :
418 [ # # ][ # # ]: 0 : return mbEndOfSearch ? sal_False : sal_True;
419 : :
420 : : }
421 : :
422 : :
423 : : /*************************************************************************
424 : : |*
425 : : |* Spelling: naechstes TextObjekt pruefen
426 : : |*
427 : : \************************************************************************/
428 : :
429 : 0 : ::svx::SpellPortions Outliner::GetNextSpellSentence (void)
430 : : {
431 : 0 : ::svx::SpellPortions aResult;
432 : :
433 [ # # ]: 0 : DetectChange();
434 : : // Iterate over sentences and text shapes until a sentence with a
435 : : // spelling error has been found. If no such sentence can be
436 : : // found the loop is left through a break.
437 : : // It is the responsibility of the sd outliner object to correctly
438 : : // iterate over all text shapes, i.e. switch between views, wrap
439 : : // arround at the end of the document, stop when all text shapes
440 : : // have been examined exactly once.
441 : 0 : bool bFoundNextSentence = false;
442 [ # # ]: 0 : while ( ! bFoundNextSentence)
443 : : {
444 [ # # ]: 0 : OutlinerView* pOutlinerView = GetView(0);
445 [ # # ]: 0 : if (pOutlinerView != NULL)
446 : : {
447 [ # # ]: 0 : ESelection aCurrentSelection (pOutlinerView->GetSelection());
448 [ # # # # ]: 0 : if ( ! mbMatchMayExist
[ # # ]
449 : 0 : && maStartSelection.IsLess(aCurrentSelection))
450 [ # # ]: 0 : EndOfSearch();
451 : :
452 : : // Advance to the next sentence.
453 : : bFoundNextSentence = SpellSentence (
454 : 0 : pOutlinerView->GetEditView(),
455 [ # # ]: 0 : aResult, false);
456 : : }
457 : :
458 : : // When no sentence with spelling errors has been found in the
459 : : // currently selected text shape or there is no selected text
460 : : // shape then advance to the next text shape.
461 [ # # ]: 0 : if ( ! bFoundNextSentence)
462 [ # # ][ # # ]: 0 : if ( ! SpellNextDocument())
463 : : // All text objects have been processed so exit the
464 : : // loop and return an empty portions list.
465 : 0 : break;
466 : : }
467 : :
468 : 0 : return aResult;
469 : : }
470 : :
471 : :
472 : :
473 : :
474 : : /** Go to next match.
475 : : */
476 : 0 : bool Outliner::StartSearchAndReplace (const SvxSearchItem* pSearchItem)
477 : : {
478 : 0 : sal_Bool bEndOfSearch = sal_True;
479 : :
480 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_True );
481 [ # # ]: 0 : if (mbPrepareSpellingPending)
482 [ # # ]: 0 : PrepareSpelling();
483 [ # # ][ # # ]: 0 : ViewShellBase* pBase = PTR_CAST(ViewShellBase,SfxViewShell::Current());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
484 : : // Determine whether we have to abort the search. This is necessary
485 : : // when the main view shell does not support searching.
486 : 0 : bool bAbort = false;
487 [ # # ]: 0 : if (pBase != NULL)
488 : : {
489 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pShell (pBase->GetMainViewShell());
490 [ # # ]: 0 : SetViewShell(pShell);
491 [ # # ]: 0 : if (pShell.get() == NULL)
492 : 0 : bAbort = true;
493 : : else
494 [ # # ][ # # ]: 0 : switch (pShell->GetShellType())
495 : : {
496 : : case ViewShell::ST_DRAW:
497 : : case ViewShell::ST_IMPRESS:
498 : : case ViewShell::ST_NOTES:
499 : : case ViewShell::ST_HANDOUT:
500 : : case ViewShell::ST_OUTLINE:
501 : 0 : bAbort = false;
502 : 0 : break;
503 : : default:
504 : 0 : bAbort = true;
505 : 0 : break;
506 [ # # ]: 0 : }
507 : : }
508 : :
509 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
510 [ # # ]: 0 : if ( ! pViewShell)
511 : : {
512 : : OSL_ASSERT(pViewShell);
513 : 0 : return true;
514 : : }
515 : :
516 [ # # ]: 0 : if ( ! bAbort)
517 : : {
518 : 0 : meMode = SEARCH;
519 : 0 : mpSearchItem = pSearchItem;
520 : :
521 : 0 : mbFoundObject = sal_False;
522 : :
523 [ # # ]: 0 : Initialize ( ! mpSearchItem->GetBackward());
524 : :
525 : 0 : sal_uInt16 nCommand = mpSearchItem->GetCommand();
526 [ # # ]: 0 : if (nCommand == SVX_SEARCHCMD_REPLACE_ALL)
527 [ # # ]: 0 : bEndOfSearch = SearchAndReplaceAll ();
528 : : else
529 : : {
530 [ # # ]: 0 : RememberStartPosition ();
531 [ # # ]: 0 : bEndOfSearch = SearchAndReplaceOnce ();
532 : : // restore start position if nothing was found
533 [ # # ]: 0 : if(!mbStringFound)
534 [ # # ]: 0 : RestoreStartPosition ();
535 : 0 : mnStartPageIndex = (sal_uInt16)-1;
536 : : }
537 : : }
538 : : else
539 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
540 : :
541 [ # # ]: 0 : return bEndOfSearch;
542 : : }
543 : :
544 : :
545 : :
546 : :
547 : 0 : void Outliner::Initialize (bool bDirectionIsForward)
548 : : {
549 [ # # ][ # # ]: 0 : const bool bIsAtEnd (maObjectIterator == ::sd::outliner::OutlinerContainer(this).end());
[ # # ]
550 : 0 : const bool bOldDirectionIsForward = mbDirectionIsForward;
551 : 0 : mbDirectionIsForward = bDirectionIsForward;
552 : :
553 [ # # ][ # # ]: 0 : if (maObjectIterator == ::sd::outliner::Iterator())
554 : : {
555 : : // Initialize a new search.
556 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
557 [ # # ][ # # ]: 0 : maCurrentPosition = *maObjectIterator;
558 : :
559 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
560 [ # # ]: 0 : if ( ! pViewShell)
561 : : {
562 : : OSL_ASSERT(pViewShell);
563 : 0 : return;
564 : : }
565 : :
566 : : // In case we are searching in an outline view then first remove the
567 : : // current selection and place cursor at its start or end.
568 [ # # ][ # # ]: 0 : if (pViewShell->ISA(OutlineViewShell))
[ # # ]
569 : : {
570 [ # # ]: 0 : ESelection aSelection = mpImpl->GetOutlinerView()->GetSelection ();
571 [ # # ]: 0 : if (mbDirectionIsForward)
572 : : {
573 : 0 : aSelection.nEndPara = aSelection.nStartPara;
574 : 0 : aSelection.nEndPos = aSelection.nStartPos;
575 : : }
576 : : else
577 : : {
578 : 0 : aSelection.nStartPara = aSelection.nEndPara;
579 : 0 : aSelection.nStartPos = aSelection.nEndPos;
580 : : }
581 [ # # ]: 0 : mpImpl->GetOutlinerView()->SetSelection (aSelection);
582 : : }
583 : :
584 : : // When not beginning the search at the beginning of the search area
585 : : // then there may be matches before the current position.
586 [ # # ][ # # ]: 0 : mbMatchMayExist = (maObjectIterator!=::sd::outliner::OutlinerContainer(this).begin());
[ # # ][ # # ]
[ # # ][ # # ]
587 : : }
588 [ # # ]: 0 : else if (bOldDirectionIsForward != mbDirectionIsForward)
589 : : {
590 : : // Requested iteration direction has changed. Turn arround the iterator.
591 : 0 : maObjectIterator.Reverse();
592 [ # # ]: 0 : if (bIsAtEnd)
593 : : {
594 : : // The iterator has pointed to end(), which after the search
595 : : // direction is reversed, becomes begin().
596 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).begin();
[ # # ]
597 : : }
598 : : else
599 : : {
600 : : // The iterator has pointed to the object one ahead/before the current
601 : : // one. Now move it to the one before/ahead the current one.
602 : 0 : ++maObjectIterator;
603 : 0 : ++maObjectIterator;
604 : : }
605 : :
606 : 0 : mbMatchMayExist = true;
607 : : }
608 : :
609 : : // Initialize the last valid position with where the search starts so
610 : : // that it always points to a valid position.
611 [ # # ][ # # ]: 0 : maLastValidPosition = *::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
612 : : }
613 : :
614 : :
615 : :
616 : :
617 : 0 : bool Outliner::SearchAndReplaceAll (void)
618 : : {
619 : : // Save the current position to be restored after having replaced all
620 : : // matches.
621 [ # # ]: 0 : RememberStartPosition ();
622 : :
623 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
624 [ # # ]: 0 : if ( ! pViewShell)
625 : : {
626 : : OSL_ASSERT(pViewShell);
627 : 0 : return true;
628 : : }
629 : :
630 [ # # ][ # # ]: 0 : if (pViewShell->ISA(OutlineViewShell))
[ # # ]
631 : : {
632 : : // Put the cursor to the beginning/end of the outliner.
633 [ # # ][ # # ]: 0 : mpImpl->GetOutlinerView()->SetSelection (GetSearchStartPosition ());
634 : :
635 : : // The outliner does all the work for us when we are in this mode.
636 [ # # ]: 0 : SearchAndReplaceOnce();
637 : : }
638 [ # # ][ # # ]: 0 : else if (pViewShell->ISA(DrawViewShell))
[ # # ]
639 : : {
640 : : // Go to beginning/end of document.
641 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).begin();
[ # # ][ # # ]
642 : : // Switch to the current object only if it is a valid text object.
643 [ # # ][ # # ]: 0 : ::sd::outliner::IteratorPosition aNewPosition (*maObjectIterator);
644 [ # # ][ # # ]: 0 : if (IsValidTextObject (aNewPosition))
645 : : {
646 [ # # ]: 0 : maCurrentPosition = aNewPosition;
647 [ # # ]: 0 : SetObject (maCurrentPosition);
648 : : }
649 : :
650 : : // Search/replace until the end of the document is reached.
651 : : bool bFoundMatch;
652 [ # # ]: 0 : do
653 : : {
654 [ # # ]: 0 : bFoundMatch = ! SearchAndReplaceOnce();
655 : : }
656 [ # # ]: 0 : while (bFoundMatch);
657 : : }
658 : :
659 [ # # ]: 0 : RestoreStartPosition ();
660 : 0 : mnStartPageIndex = (sal_uInt16)-1;
661 : :
662 [ # # ]: 0 : return true;
663 : : }
664 : :
665 : :
666 : :
667 : :
668 : 0 : bool Outliner::SearchAndReplaceOnce (void)
669 : : {
670 [ # # ]: 0 : DetectChange ();
671 : :
672 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
673 : : DBG_ASSERT(pOutlinerView!=NULL && GetEditEngine().HasView( &pOutlinerView->GetEditView() ),
674 : : "SearchAndReplace without valid view!" );
675 : :
676 [ # # ][ # # ]: 0 : if( NULL == pOutlinerView || !GetEditEngine().HasView( &pOutlinerView->GetEditView() ) )
[ # # ][ # # ]
677 : 0 : return true;
678 : :
679 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
680 [ # # ]: 0 : if (pViewShell != NULL)
681 : : {
682 : 0 : mpView = pViewShell->GetView();
683 [ # # ]: 0 : mpWindow = pViewShell->GetActiveWindow();
684 [ # # ]: 0 : pOutlinerView->SetWindow(mpWindow);
685 : :
686 [ # # ][ # # ]: 0 : if (pViewShell->ISA(DrawViewShell) )
[ # # ]
687 : : {
688 : : // When replacing we first check if there is a selection
689 : : // indicating a match. If there is then replace it. The
690 : : // following call to StartSearchAndReplace will then search for
691 : : // the next match.
692 [ # # # # ]: 0 : if (meMode == SEARCH
[ # # ]
693 : 0 : && mpSearchItem->GetCommand() == SVX_SEARCHCMD_REPLACE)
694 [ # # ][ # # ]: 0 : if (pOutlinerView->GetSelection().HasRange())
695 [ # # ]: 0 : pOutlinerView->StartSearchAndReplace(*mpSearchItem);
696 : :
697 : : // Search for the next match.
698 : 0 : sal_uLong nMatchCount = 0;
699 [ # # ]: 0 : if (mpSearchItem->GetCommand() != SVX_SEARCHCMD_REPLACE_ALL)
700 [ # # ]: 0 : nMatchCount = pOutlinerView->StartSearchAndReplace(*mpSearchItem);
701 : :
702 : : // Go to the next text object when there have been no matches in
703 : : // the current object or the whole object has already been
704 : : // processed.
705 [ # # ][ # # ]: 0 : if (nMatchCount==0 || mpSearchItem->GetCommand()==SVX_SEARCHCMD_REPLACE_ALL)
[ # # ]
706 : : {
707 [ # # ]: 0 : ProvideNextTextObject ();
708 : :
709 [ # # ]: 0 : if ( ! mbEndOfSearch)
710 : : {
711 : : // Remember the current position as the last one with a
712 : : // text object.
713 [ # # ]: 0 : maLastValidPosition = maCurrentPosition;
714 : :
715 : : // Now that the mbEndOfSearch flag guards this block the
716 : : // following assertion and return should not be
717 : : // necessary anymore.
718 : : DBG_ASSERT(GetEditEngine().HasView(&pOutlinerView->GetEditView() ),
719 : : "SearchAndReplace without valid view!" );
720 [ # # ][ # # ]: 0 : if ( ! GetEditEngine().HasView( &pOutlinerView->GetEditView() ) )
721 : : {
722 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
723 : 0 : return true;
724 : : }
725 : :
726 [ # # ]: 0 : if (meMode == SEARCH)
727 [ # # ]: 0 : nMatchCount = pOutlinerView->StartSearchAndReplace(*mpSearchItem);
728 : : }
729 : : }
730 : : }
731 [ # # ][ # # ]: 0 : else if (pViewShell->ISA(OutlineViewShell))
[ # # ]
732 : : {
733 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor (sal_False);
734 : : // The following loop is executed more then once only when a
735 : : // wrap arround search is done.
736 : 0 : while (true)
737 : : {
738 [ # # ]: 0 : int nResult = pOutlinerView->StartSearchAndReplace(*mpSearchItem);
739 [ # # ]: 0 : if (nResult == 0)
740 : : {
741 [ # # ][ # # ]: 0 : if (HandleFailedSearch ())
742 : : {
743 [ # # ][ # # ]: 0 : pOutlinerView->SetSelection (GetSearchStartPosition ());
744 : 0 : continue;
745 : : }
746 : : }
747 : : else
748 : 0 : mbStringFound = true;
749 : 0 : break;
750 : : }
751 : : }
752 : : }
753 : :
754 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
755 : :
756 [ # # ]: 0 : return mbEndOfSearch;
757 : : }
758 : :
759 : :
760 : :
761 : :
762 : : /** Try to detect whether the document or the view (shell) has changed since
763 : : the last time <member>StartSearchAndReplace()</member> has been called.
764 : : */
765 : 0 : void Outliner::DetectChange (void)
766 : : {
767 [ # # ]: 0 : ::sd::outliner::IteratorPosition aPosition (maCurrentPosition);
768 : :
769 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
770 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
771 [ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell));
772 : :
773 : : // Detect whether the view has been switched from the outside.
774 [ # # # # : 0 : if (pDrawViewShell.get() != NULL
# # ][ # # ]
775 : 0 : && (aPosition.meEditMode != pDrawViewShell->GetEditMode()
776 : 0 : || aPosition.mePageKind != pDrawViewShell->GetPageKind()))
777 : : {
778 : : // Either the edit mode or the page kind has changed.
779 [ # # ][ # # ]: 0 : SetStatusEventHdl(Link());
780 : :
781 : 0 : SdrPageView* pPageView = mpView->GetSdrPageView();
782 [ # # ]: 0 : if (pPageView != NULL)
783 [ # # ]: 0 : mpView->UnmarkAllObj (pPageView);
784 [ # # ]: 0 : mpView->SdrEndTextEdit();
785 [ # # ]: 0 : SetUpdateMode(sal_False);
786 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
787 [ # # ]: 0 : if (pOutlinerView != NULL)
788 [ # # ][ # # ]: 0 : pOutlinerView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
789 [ # # ]: 0 : if (meMode == SPELL)
790 [ # # ]: 0 : SetPaperSize( Size(1, 1) );
791 [ # # ][ # # ]: 0 : SetText( String(), GetParagraph( 0 ) );
[ # # ][ # # ]
792 : :
793 [ # # ]: 0 : RememberStartPosition ();
794 : :
795 [ # # ]: 0 : mnPageCount = mpDrawDocument->GetSdPageCount(pDrawViewShell->GetPageKind());
796 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
797 : : }
798 : :
799 : : // Detect change of the set of selected objects. If their number has
800 : : // changed start again with the first selected object.
801 [ # # ][ # # ]: 0 : else if (DetectSelectionChange())
802 : : {
803 [ # # ]: 0 : HandleChangedSelection ();
804 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
805 : : }
806 : :
807 : : // Detect change of page count. Restart search at first/last page in
808 : : // that case.
809 [ # # ][ # # ]: 0 : else if (aPosition.meEditMode == EM_PAGE
[ # # ]
810 [ # # ]: 0 : && mpDrawDocument->GetSdPageCount(aPosition.mePageKind) != mnPageCount)
811 : : {
812 : : // The number of pages has changed.
813 [ # # ]: 0 : mnPageCount = mpDrawDocument->GetSdPageCount(aPosition.mePageKind);
814 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
815 : : }
816 [ # # ][ # # ]: 0 : else if (aPosition.meEditMode == EM_MASTERPAGE
[ # # ]
817 [ # # ]: 0 : && mpDrawDocument->GetSdPageCount(aPosition.mePageKind) != mnPageCount)
818 : : {
819 : : // The number of master pages has changed.
820 [ # # ]: 0 : mnPageCount = mpDrawDocument->GetSdPageCount(aPosition.mePageKind);
821 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).current();
[ # # ][ # # ]
822 [ # # ][ # # ]: 0 : }
[ # # ]
823 : 0 : }
824 : :
825 : :
826 : :
827 : :
828 : 0 : bool Outliner::DetectSelectionChange (void)
829 : : {
830 : 0 : bool bSelectionHasChanged = false;
831 : 0 : sal_uLong nMarkCount = mpView->GetMarkedObjectList().GetMarkCount();
832 : :
833 : : // If mpObj is NULL then we have not yet found our first match.
834 : : // Detecting a change makes no sense.
835 [ # # ]: 0 : if (mpObj != NULL)
836 [ # # # ]: 0 : switch (nMarkCount)
837 : : {
838 : : case 0:
839 : : // The selection has changed when previously there have been
840 : : // selected objects.
841 : 0 : bSelectionHasChanged = mbRestrictSearchToSelection;
842 : 0 : break;
843 : : case 1:
844 : : // Check if the only selected object is not the one that we
845 : : // had selected.
846 [ # # ]: 0 : if (mpView != NULL)
847 : : {
848 : 0 : SdrMark* pMark = mpView->GetMarkedObjectList().GetMark(0);
849 [ # # ]: 0 : if (pMark != NULL)
850 : 0 : bSelectionHasChanged = (mpObj != pMark->GetMarkedSdrObj ());
851 : : }
852 : 0 : break;
853 : : default:
854 : : // We had selected exactly one object.
855 : 0 : bSelectionHasChanged = true;
856 : 0 : break;
857 : : }
858 : :
859 : 0 : return bSelectionHasChanged;
860 : : }
861 : :
862 : :
863 : :
864 : :
865 : 0 : void Outliner::RememberStartPosition (void)
866 : : {
867 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
868 [ # # ]: 0 : if ( ! pViewShell)
869 : : {
870 : : OSL_ASSERT(pViewShell);
871 : : return;
872 : : }
873 : :
874 [ # # ]: 0 : if ( mnStartPageIndex != (sal_uInt16) -1 )
875 : : return;
876 : :
877 [ # # ][ # # ]: 0 : if (pViewShell->ISA(DrawViewShell))
[ # # ]
878 : : {
879 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
880 [ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell));
881 [ # # ]: 0 : if (pDrawViewShell.get() != NULL)
882 : : {
883 : 0 : meStartViewMode = pDrawViewShell->GetPageKind();
884 : 0 : meStartEditMode = pDrawViewShell->GetEditMode();
885 : 0 : mnStartPageIndex = pDrawViewShell->GetCurPageId() - 1;
886 : : }
887 : :
888 [ # # ]: 0 : if (mpView != NULL)
889 : : {
890 [ # # ]: 0 : mpStartEditedObject = mpView->GetTextEditObject();
891 [ # # ]: 0 : if (mpStartEditedObject != NULL)
892 : : {
893 : : // Try to retrieve current caret position only when there is an
894 : : // edited object.
895 : : ::Outliner* pOutliner =
896 : 0 : static_cast<DrawView*>(mpView)->GetTextEditOutliner();
897 [ # # ][ # # ]: 0 : if (pOutliner!=NULL && pOutliner->GetViewCount()>0)
[ # # ][ # # ]
898 : : {
899 [ # # ]: 0 : OutlinerView* pOutlinerView = pOutliner->GetView(0);
900 [ # # ]: 0 : maStartSelection = pOutlinerView->GetSelection();
901 : : }
902 : : }
903 [ # # ]: 0 : }
904 : : }
905 [ # # ][ # # ]: 0 : else if (pViewShell->ISA(OutlineViewShell))
[ # # ]
906 : : {
907 : : // Remember the current cursor position.
908 [ # # ]: 0 : OutlinerView* pView = GetView(0);
909 [ # # ]: 0 : if (pView != NULL)
910 [ # # ]: 0 : pView->GetSelection();
911 : : }
912 : : else
913 : : {
914 : 0 : mnStartPageIndex = (sal_uInt16)-1;
915 [ # # ][ # # ]: 0 : }
916 : : }
917 : :
918 : :
919 : :
920 : :
921 : 0 : void Outliner::RestoreStartPosition (void)
922 : : {
923 : 0 : bool bRestore = true;
924 : : // Take a negative start page index as inidicator that restoring the
925 : : // start position is not requested.
926 [ # # ]: 0 : if (mnStartPageIndex == (sal_uInt16)-1 )
927 : 0 : bRestore = false;
928 : : // Dont't restore when the view shell is not valid.
929 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
930 [ # # ]: 0 : if (pViewShell == NULL)
931 : 0 : bRestore = false;
932 : :
933 [ # # ]: 0 : if (bRestore)
934 : : {
935 [ # # ][ # # ]: 0 : if (pViewShell->ISA(DrawViewShell))
[ # # ]
936 : : {
937 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
938 [ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell));
939 [ # # ]: 0 : SetViewMode (meStartViewMode);
940 [ # # ]: 0 : if (pDrawViewShell.get() != NULL)
941 [ # # ]: 0 : SetPage (meStartEditMode, mnStartPageIndex);
942 : :
943 : :
944 [ # # ]: 0 : if (mpStartEditedObject != NULL)
945 : : {
946 : : // Turn on the text toolbar as it is done in FuText so that
947 : : // undo manager setting/restoring in
948 : : // sd::View::{Beg,End}TextEdit() works on the same view shell.
949 [ # # ]: 0 : pViewShell->GetViewShellBase().GetToolBarManager()->SetToolBarShell(
950 : : ToolBarManager::TBG_FUNCTION,
951 [ # # ][ # # ]: 0 : RID_DRAW_TEXT_TOOLBOX);
[ # # ]
952 : :
953 [ # # ]: 0 : mpView->SdrBeginTextEdit(mpStartEditedObject);
954 : : ::Outliner* pOutliner =
955 : 0 : static_cast<DrawView*>(mpView)->GetTextEditOutliner();
956 [ # # ][ # # ]: 0 : if (pOutliner!=NULL && pOutliner->GetViewCount()>0)
[ # # ][ # # ]
957 : : {
958 [ # # ]: 0 : OutlinerView* pOutlinerView = pOutliner->GetView(0);
959 [ # # ]: 0 : pOutlinerView->SetSelection(maStartSelection);
960 : : }
961 [ # # ]: 0 : }
962 : : }
963 [ # # ][ # # ]: 0 : else if (pViewShell->ISA(OutlineViewShell))
[ # # ]
964 : : {
965 : : // Set cursor to its old position.
966 [ # # ]: 0 : OutlinerView* pView = GetView(0);
967 [ # # ]: 0 : if (pView != NULL)
968 [ # # ]: 0 : pView->SetSelection (maStartSelection);
969 : : }
970 [ # # ]: 0 : }
971 : 0 : }
972 : :
973 : :
974 : :
975 : :
976 : : /** The main purpose of this method is to iterate over all shape objects of
977 : : the search area (current selection, current view, or whole document)
978 : : until a text object has been found that contains at least one match or
979 : : until no such object can be found anymore. These two conditions are
980 : : expressed by setting one of the flags <member>mbFoundObject</member> or
981 : : <member>mbEndOfSearch</member> to <TRUE/>.
982 : : */
983 : 0 : void Outliner::ProvideNextTextObject (void)
984 : : {
985 : 0 : mbEndOfSearch = false;
986 : 0 : mbFoundObject = false;
987 : :
988 : 0 : mpView->UnmarkAllObj (mpView->GetSdrPageView());
989 : : try
990 : : {
991 [ # # ]: 0 : mpView->SdrEndTextEdit();
992 : : }
993 : 0 : catch (const ::com::sun::star::uno::Exception&)
994 : : {
995 : : DBG_UNHANDLED_EXCEPTION();
996 : : }
997 : 0 : SetUpdateMode(sal_False);
998 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
999 [ # # ]: 0 : if (pOutlinerView != NULL)
1000 [ # # ][ # # ]: 0 : pOutlinerView->SetOutputArea( Rectangle( Point(), Size(1, 1) ) );
1001 [ # # ]: 0 : if (meMode == SPELL)
1002 [ # # ]: 0 : SetPaperSize( Size(1, 1) );
1003 [ # # ]: 0 : SetText( String(), GetParagraph( 0 ) );
1004 : :
1005 : 0 : mpTextObj = NULL;
1006 : :
1007 : : // Iterate until a valid text object has been found or the search ends.
1008 [ # # ]: 0 : do
1009 : : {
1010 : 0 : mpObj = NULL;
1011 : 0 : mpParaObj = NULL;
1012 : :
1013 [ # # ][ # # ]: 0 : if (maObjectIterator != ::sd::outliner::OutlinerContainer(this).end())
[ # # ][ # # ]
1014 : : {
1015 : 0 : maCurrentPosition = *maObjectIterator;
1016 : : // Switch to the current object only if it is a valid text object.
1017 [ # # ]: 0 : if (IsValidTextObject (maCurrentPosition))
1018 : : {
1019 : 0 : mpObj = SetObject (maCurrentPosition);
1020 : : }
1021 : 0 : ++maObjectIterator;
1022 : :
1023 [ # # ]: 0 : if (mpObj != NULL)
1024 : : {
1025 [ # # ]: 0 : PutTextIntoOutliner ();
1026 : :
1027 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1028 [ # # ]: 0 : if (pViewShell != NULL)
1029 [ # # # # ]: 0 : switch (meMode)
1030 : : {
1031 : : case SEARCH:
1032 [ # # ]: 0 : PrepareSearchAndReplace ();
1033 : 0 : break;
1034 : : case SPELL:
1035 [ # # ]: 0 : PrepareSpellCheck ();
1036 : 0 : break;
1037 : : case TEXT_CONVERSION:
1038 [ # # ]: 0 : PrepareConversion();
1039 : 0 : break;
1040 [ # # ]: 0 : }
1041 : : }
1042 : : }
1043 : : else
1044 : : {
1045 : 0 : mbEndOfSearch = true;
1046 : 0 : EndOfSearch ();
1047 : : }
1048 : : }
1049 [ # # ][ # # ]: 0 : while ( ! (mbFoundObject || mbEndOfSearch));
1050 [ # # ]: 0 : }
1051 : :
1052 : :
1053 : :
1054 : :
1055 : 0 : void Outliner::EndOfSearch (void)
1056 : : {
1057 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1058 [ # # ]: 0 : if ( ! pViewShell)
1059 : : {
1060 : : OSL_ASSERT(pViewShell);
1061 : 0 : return;
1062 : : }
1063 : :
1064 : : // Before we display a dialog we first jump to where the last valid text
1065 : : // object was found. All page and view mode switching since then was
1066 : : // temporary and should not be visible to the user.
1067 [ # # ][ # # ]: 0 : if ( ! pViewShell->ISA(OutlineViewShell))
[ # # ]
1068 [ # # ]: 0 : SetObject (maLastValidPosition);
1069 : :
1070 [ # # ]: 0 : if (mbRestrictSearchToSelection)
1071 [ # # ]: 0 : ShowEndOfSearchDialog ();
1072 : : else
1073 : : {
1074 : : // When no match has been found so far then terminate the search.
1075 [ # # ]: 0 : if ( ! mbMatchMayExist)
1076 : : {
1077 [ # # ]: 0 : ShowEndOfSearchDialog ();
1078 : 0 : mbEndOfSearch = sal_True;
1079 : : }
1080 : : // Ask the user whether to wrap arround and continue the search or
1081 : : // to terminate.
1082 [ # # ][ # # ]: 0 : else if (meMode==TEXT_CONVERSION || ShowWrapArroundDialog ())
[ # # ][ # # ]
1083 : : {
1084 : 0 : mbMatchMayExist = false;
1085 : : // Everything back to beginning (or end?) of the document.
1086 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::OutlinerContainer(this).begin();
[ # # ][ # # ]
1087 [ # # ][ # # ]: 0 : if (pViewShell->ISA(OutlineViewShell))
[ # # ]
1088 : : {
1089 : : // Set cursor to first character of the document.
1090 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1091 [ # # ]: 0 : if (pOutlinerView != NULL)
1092 [ # # ][ # # ]: 0 : pOutlinerView->SetSelection (GetSearchStartPosition ());
1093 : : }
1094 : :
1095 : 0 : mbEndOfSearch = false;
1096 : : }
1097 : : else
1098 : : {
1099 : : // No wrap arround.
1100 : 0 : mbEndOfSearch = true;
1101 : : }
1102 [ # # ][ # # ]: 0 : }
1103 : : }
1104 : :
1105 : 0 : void Outliner::ShowEndOfSearchDialog (void)
1106 : : {
1107 [ # # ]: 0 : String aString;
1108 [ # # ]: 0 : if (meMode == SEARCH)
1109 : : {
1110 [ # # ]: 0 : if (mbStringFound)
1111 [ # # ][ # # ]: 0 : aString = String( SdResId(STR_END_SEARCHING) );
[ # # ][ # # ]
1112 : : else
1113 [ # # ][ # # ]: 0 : aString = String( SdResId(STR_STRING_NOTFOUND) );
[ # # ][ # # ]
1114 : : }
1115 : : else
1116 : : {
1117 [ # # ]: 0 : if (mpView->AreObjectsMarked())
1118 [ # # ][ # # ]: 0 : aString = String(SdResId(STR_END_SPELLING_OBJ));
[ # # ][ # # ]
1119 : : else
1120 [ # # ][ # # ]: 0 : aString = String(SdResId(STR_END_SPELLING));
[ # # ][ # # ]
1121 : : }
1122 : :
1123 : : // Show the message in an info box that is modal with respect to the
1124 : : // whole application.
1125 [ # # ]: 0 : InfoBox aInfoBox (NULL, aString);
1126 [ # # ]: 0 : ShowModalMessageBox (aInfoBox);
1127 : :
1128 [ # # ][ # # ]: 0 : mbWholeDocumentProcessed = true;
1129 : 0 : }
1130 : :
1131 : :
1132 : :
1133 : :
1134 : 0 : bool Outliner::ShowWrapArroundDialog (void)
1135 : : {
1136 : 0 : bool bDoWrapArround = false;
1137 : :
1138 : : // Determine whether to show the dialog.
1139 : 0 : bool bShowDialog = false;
1140 [ # # ]: 0 : if (mpSearchItem != NULL)
1141 : : {
1142 : : // When searching display the dialog only for single find&replace.
1143 : 0 : sal_uInt16 nCommand = mpSearchItem->GetCommand();
1144 : : bShowDialog = (nCommand==SVX_SEARCHCMD_REPLACE)
1145 [ # # ][ # # ]: 0 : || (nCommand==SVX_SEARCHCMD_FIND);
1146 : : }
1147 : : else
1148 : : // Spell checking needs the dialog, too.
1149 : 0 : bShowDialog = (meMode == SPELL);
1150 : :
1151 [ # # ]: 0 : if (bShowDialog)
1152 : : {
1153 : : // The question text depends on the search direction.
1154 : : sal_Bool bImpress = mpDrawDocument!=NULL
1155 [ # # ][ # # ]: 0 : && mpDrawDocument->GetDocumentType() == DOCUMENT_TYPE_IMPRESS;
1156 : : sal_uInt16 nStringId;
1157 [ # # ]: 0 : if (mbDirectionIsForward)
1158 : : nStringId = bImpress
1159 : : ? STR_SAR_WRAP_FORWARD
1160 [ # # ]: 0 : : STR_SAR_WRAP_FORWARD_DRAW;
1161 : : else
1162 : : nStringId = bImpress
1163 : : ? STR_SAR_WRAP_BACKWARD
1164 [ # # ]: 0 : : STR_SAR_WRAP_BACKWARD_DRAW;
1165 : :
1166 : : // Pop up question box that asks the user whether to wrap arround.
1167 : : // The dialog is made modal with respect to the whole application.
1168 : : QueryBox aQuestionBox (
1169 : : NULL,
1170 : : WB_YES_NO | WB_DEF_YES,
1171 [ # # ][ # # ]: 0 : String(SdResId(nStringId)));
[ # # ][ # # ]
1172 [ # # ][ # # ]: 0 : aQuestionBox.SetImage (QueryBox::GetStandardImage());
[ # # ]
1173 [ # # ]: 0 : sal_uInt16 nBoxResult = ShowModalMessageBox(aQuestionBox);
1174 [ # # ]: 0 : bDoWrapArround = (nBoxResult == BUTTONID_YES);
1175 : : }
1176 : :
1177 : 0 : return bDoWrapArround;
1178 : : }
1179 : :
1180 : :
1181 : :
1182 : :
1183 : 0 : bool Outliner::IsValidTextObject (const ::sd::outliner::IteratorPosition& rPosition)
1184 : : {
1185 [ # # ]: 0 : SdrTextObj* pObject = dynamic_cast< SdrTextObj* >( rPosition.mxObject.get() );
1186 [ # # ][ # # ]: 0 : return (pObject != NULL) && pObject->HasText() && ! pObject->IsEmptyPresObj();
[ # # ]
1187 : : }
1188 : :
1189 : :
1190 : :
1191 : :
1192 : 0 : void Outliner::PutTextIntoOutliner()
1193 : : {
1194 [ # # ]: 0 : mpTextObj = dynamic_cast<SdrTextObj*>( mpObj );
1195 [ # # ][ # # ]: 0 : if ( mpTextObj && mpTextObj->HasText() && !mpTextObj->IsEmptyPresObj() )
[ # # ][ # # ]
1196 : : {
1197 : 0 : SdrText* pText = mpTextObj->getText( mnText );
1198 [ # # ]: 0 : mpParaObj = pText ? pText->GetOutlinerParaObject() : NULL;
1199 : :
1200 [ # # ]: 0 : if (mpParaObj != NULL)
1201 : : {
1202 : 0 : SetText(*mpParaObj);
1203 : :
1204 : 0 : ClearModifyFlag();
1205 : : }
1206 : : }
1207 : : else
1208 : : {
1209 : 0 : mpTextObj = NULL;
1210 : : }
1211 : 0 : }
1212 : :
1213 : :
1214 : :
1215 : :
1216 : 0 : void Outliner::PrepareSpellCheck (void)
1217 : : {
1218 : 0 : EESpellState eState = HasSpellErrors();
1219 : : DBG_ASSERT(eState != EE_SPELL_NOSPELLER, "No SpellChecker");
1220 : :
1221 [ # # ]: 0 : if (eState == EE_SPELL_NOLANGUAGE)
1222 : : {
1223 : 0 : mbError = sal_True;
1224 : 0 : mbEndOfSearch = sal_True;
1225 : : ErrorBox aErrorBox (NULL,
1226 : : WB_OK,
1227 [ # # ][ # # ]: 0 : String(SdResId(STR_NOLANGUAGE)));
[ # # ][ # # ]
1228 [ # # ][ # # ]: 0 : ShowModalMessageBox (aErrorBox);
1229 : : }
1230 [ # # ]: 0 : else if (eState != EE_SPELL_OK)
1231 : : {
1232 : : // When spell checking we have to test whether we have processed the
1233 : : // whole document and have reached the start page again.
1234 [ # # ]: 0 : if (meMode == SPELL)
1235 : : {
1236 [ # # ][ # # ]: 0 : if (maSearchStartPosition == ::sd::outliner::Iterator())
1237 : : // Remember the position of the first text object so that we
1238 : : // know when we have processed the whole document.
1239 : 0 : maSearchStartPosition = maObjectIterator;
1240 [ # # ]: 0 : else if (maSearchStartPosition == maObjectIterator)
1241 : : {
1242 : 0 : mbEndOfSearch = true;
1243 : : }
1244 : : }
1245 : :
1246 : 0 : EnterEditMode( sal_False );
1247 : : }
1248 : 0 : }
1249 : :
1250 : :
1251 : :
1252 : :
1253 : 0 : void Outliner::PrepareSearchAndReplace (void)
1254 : : {
1255 [ # # ]: 0 : if (HasText( *mpSearchItem ))
1256 : : {
1257 : 0 : mbStringFound = true;
1258 : 0 : mbMatchMayExist = true;
1259 : :
1260 : 0 : EnterEditMode ();
1261 : :
1262 : 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
1263 : : // Start seach at the right end of the current object's text
1264 : : // depending on the search direction.
1265 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1266 [ # # ]: 0 : if (pOutlinerView != NULL)
1267 [ # # ]: 0 : pOutlinerView->SetSelection (GetSearchStartPosition ());
1268 : : }
1269 : 0 : }
1270 : :
1271 : :
1272 : :
1273 : :
1274 : 0 : void Outliner::SetViewMode (PageKind ePageKind)
1275 : : {
1276 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1277 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
1278 [ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell));
1279 [ # # ][ # # ]: 0 : if (pDrawViewShell.get()!=NULL && ePageKind != pDrawViewShell->GetPageKind())
[ # # ]
1280 : : {
1281 : : // Restore old edit mode.
1282 [ # # ]: 0 : pDrawViewShell->ChangeEditMode(mpImpl->meOriginalEditMode, sal_False);
1283 : :
1284 [ # # ][ # # ]: 0 : SetStatusEventHdl(Link());
1285 : 0 : ::rtl::OUString sViewURL;
1286 [ # # # ]: 0 : switch (ePageKind)
1287 : : {
1288 : : case PK_STANDARD:
1289 : : default:
1290 : 0 : sViewURL = framework::FrameworkHelper::msImpressViewURL;
1291 : 0 : break;
1292 : : case PK_NOTES:
1293 : 0 : sViewURL = framework::FrameworkHelper::msNotesViewURL;
1294 : 0 : break;
1295 : : case PK_HANDOUT:
1296 : 0 : sViewURL = framework::FrameworkHelper::msHandoutViewURL;
1297 : 0 : break;
1298 : : }
1299 : : // The text object iterator is destroyed when the shells are
1300 : : // switched but we need it so save it and restore it afterwards.
1301 [ # # ]: 0 : ::sd::outliner::Iterator aIterator (maObjectIterator);
1302 : 0 : bool bMatchMayExist = mbMatchMayExist;
1303 : :
1304 [ # # ]: 0 : ViewShellBase& rBase = pViewShell->GetViewShellBase();
1305 [ # # ][ # # ]: 0 : SetViewShell(::boost::shared_ptr<ViewShell>());
[ # # ]
1306 : : framework::FrameworkHelper::Instance(rBase)->RequestView(
1307 : : sViewURL,
1308 [ # # ][ # # ]: 0 : framework::FrameworkHelper::msCenterPaneURL);
[ # # ]
1309 : :
1310 : : // Force (well, request) a synchronous update of the configuration.
1311 : : // In a better world we would handle the asynchronous view update
1312 : : // instead. But that would involve major restucturing of the
1313 : : // Outliner code.
1314 [ # # ][ # # ]: 0 : framework::FrameworkHelper::Instance(rBase)->RequestSynchronousUpdate();
[ # # ]
1315 [ # # ][ # # ]: 0 : SetViewShell(rBase.GetMainViewShell());
[ # # ]
1316 : :
1317 : : // Switching to another view shell has intermediatly called
1318 : : // EndSpelling(). A PrepareSpelling() is pending, so call that now.
1319 [ # # ]: 0 : PrepareSpelling();
1320 : :
1321 : : // Update the number of pages so that
1322 : : // <member>DetectChange()</member> has the correct value to compare
1323 : : // to.
1324 [ # # ]: 0 : mnPageCount = mpDrawDocument->GetSdPageCount(ePageKind);
1325 : :
1326 [ # # ]: 0 : maObjectIterator = aIterator;
1327 : 0 : mbMatchMayExist = bMatchMayExist;
1328 : :
1329 : : // Save edit mode so that it can be restored when switching the view
1330 : : // shell again.
1331 [ # # ][ # # ]: 0 : pDrawViewShell = ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell);
[ # # ]
1332 : : OSL_ASSERT(pDrawViewShell.get()!=NULL);
1333 [ # # ]: 0 : if (pDrawViewShell.get() != NULL)
1334 [ # # ]: 0 : mpImpl->meOriginalEditMode = pDrawViewShell->GetEditMode();
1335 [ # # ][ # # ]: 0 : }
1336 : 0 : }
1337 : :
1338 : :
1339 : :
1340 : :
1341 : 0 : void Outliner::SetPage (EditMode eEditMode, sal_uInt16 nPageIndex)
1342 : : {
1343 [ # # ]: 0 : if ( ! mbRestrictSearchToSelection)
1344 : : {
1345 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1346 : : ::boost::shared_ptr<DrawViewShell> pDrawViewShell(
1347 [ # # ]: 0 : ::boost::dynamic_pointer_cast<DrawViewShell>(pViewShell));
1348 : : OSL_ASSERT(pDrawViewShell.get()!=NULL);
1349 [ # # ]: 0 : if (pDrawViewShell.get() != NULL)
1350 : : {
1351 [ # # ]: 0 : pDrawViewShell->ChangeEditMode(eEditMode, sal_False);
1352 [ # # ]: 0 : pDrawViewShell->SwitchPage(nPageIndex);
1353 [ # # ][ # # ]: 0 : }
1354 : : }
1355 : 0 : }
1356 : :
1357 : :
1358 : :
1359 : :
1360 : 0 : void Outliner::EnterEditMode (sal_Bool bGrabFocus)
1361 : : {
1362 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1363 [ # # ]: 0 : if (pOutlinerView != NULL)
1364 : : {
1365 [ # # ][ # # ]: 0 : pOutlinerView->SetOutputArea( Rectangle( Point(), Size(1, 1)));
1366 [ # # ][ # # ]: 0 : SetPaperSize( mpTextObj->GetLogicRect().GetSize() );
[ # # ]
1367 : 0 : SdrPageView* pPV = mpView->GetSdrPageView();
1368 : :
1369 : : // Make FuText the current function.
1370 [ # # ]: 0 : SfxUInt16Item aItem (SID_TEXTEDIT, 1);
1371 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1372 : 0 : pViewShell->GetDispatcher()->
1373 : : Execute(SID_TEXTEDIT, SFX_CALLMODE_SYNCHRON |
1374 [ # # ][ # # ]: 0 : SFX_CALLMODE_RECORD, &aItem, 0L);
1375 : :
1376 : : // To be consistent with the usual behaviour in the Office the text
1377 : : // object that is put into edit mode would have also to be selected.
1378 : : // Starting the text edit mode is not enough so we do it here by
1379 : : // hand.
1380 : 0 : mbExpectingSelectionChangeEvent = true;
1381 [ # # ]: 0 : mpView->UnmarkAllObj (pPV);
1382 [ # # ]: 0 : mpView->MarkObj (mpTextObj, pPV);
1383 : :
1384 [ # # ]: 0 : if( mpTextObj )
1385 [ # # ]: 0 : mpTextObj->setActiveText( mnText );
1386 : :
1387 : : // Turn on the edit mode for the text object.
1388 [ # # ]: 0 : mpView->SdrBeginTextEdit(mpTextObj, pPV, mpWindow, sal_True, this, pOutlinerView, sal_True, sal_True, bGrabFocus);
1389 : :
1390 [ # # ]: 0 : SetUpdateMode(sal_True);
1391 [ # # ][ # # ]: 0 : mbFoundObject = sal_True;
1392 : : }
1393 : 0 : }
1394 : :
1395 : :
1396 : :
1397 : :
1398 : : /*************************************************************************
1399 : : |*
1400 : : |* SpellChecker: Error-LinkHdl
1401 : : |*
1402 : : \************************************************************************/
1403 : :
1404 : 0 : IMPL_LINK_INLINE_START( Outliner, SpellError, void *, nLang )
1405 : : {
1406 : 0 : mbError = true;
1407 [ # # ]: 0 : String aError( SvtLanguageTable::GetLanguageString( (LanguageType)(sal_uLong)nLang ) );
1408 : : ErrorHandler::HandleError(* new StringErrorInfo(
1409 [ # # ][ # # ]: 0 : ERRCODE_SVX_LINGU_LANGUAGENOTEXISTS, aError) );
[ # # ][ # # ]
1410 [ # # ]: 0 : return 0;
1411 : : }
1412 : 0 : IMPL_LINK_INLINE_END( Outliner, SpellError, void *, nLang )
1413 : :
1414 : :
1415 : :
1416 : :
1417 : 0 : ESelection Outliner::GetSearchStartPosition (void)
1418 : : {
1419 : 0 : ESelection aPosition;
1420 [ # # ]: 0 : if (mbDirectionIsForward)
1421 : : {
1422 : : // The default constructor uses the beginning of the text as default.
1423 : 0 : aPosition = ESelection ();
1424 : : }
1425 : : else
1426 : : {
1427 : : // Retrieve the position after the last character in the last
1428 : : // paragraph.
1429 : 0 : sal_uInt16 nParagraphCount = static_cast<sal_uInt16>(GetParagraphCount());
1430 [ # # ]: 0 : if (nParagraphCount == 0)
1431 : 0 : aPosition = ESelection();
1432 : : else
1433 : : {
1434 : 0 : xub_StrLen nLastParagraphLength = GetEditEngine().GetTextLen (
1435 : 0 : nParagraphCount-1);
1436 : 0 : aPosition = ESelection (nParagraphCount-1, nLastParagraphLength);
1437 : : }
1438 : : }
1439 : :
1440 : 0 : return aPosition;
1441 : : }
1442 : :
1443 : :
1444 : :
1445 : :
1446 : 0 : bool Outliner::HasNoPreviousMatch (void)
1447 : : {
1448 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1449 : :
1450 : : DBG_ASSERT (pOutlinerView!=NULL, "outline view in Outliner::HasNoPreviousMatch is NULL");
1451 : :
1452 : : // Detect whether the cursor stands at the beginning
1453 : : // resp. at the end of the text.
1454 [ # # ]: 0 : return pOutlinerView->GetSelection().IsEqual(GetSearchStartPosition ()) == sal_True;
1455 : : }
1456 : :
1457 : :
1458 : :
1459 : :
1460 : 0 : bool Outliner::HandleFailedSearch (void)
1461 : : {
1462 : 0 : bool bContinueSearch = false;
1463 : :
1464 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1465 [ # # ][ # # ]: 0 : if (pOutlinerView != NULL && mpSearchItem != NULL)
1466 : : {
1467 : : // Detect whether there is/may be a prior match. If there is then
1468 : : // ask the user whether to wrap arround. Otherwise tell the user
1469 : : // that there is no match.
1470 [ # # ]: 0 : if (HasNoPreviousMatch ())
1471 : : {
1472 : : // No match found in the whole presentation. Tell the user.
1473 : : InfoBox aInfoBox (NULL,
1474 [ # # ][ # # ]: 0 : String(SdResId(STR_SAR_NOT_FOUND)));
[ # # ][ # # ]
1475 [ # # ][ # # ]: 0 : ShowModalMessageBox (aInfoBox);
1476 : : }
1477 : :
1478 : : else
1479 : : {
1480 : : // No further matches found. Ask the user whether to wrap
1481 : : // arround and start again.
1482 : 0 : bContinueSearch = ShowWrapArroundDialog ();
1483 : : }
1484 : : }
1485 : :
1486 : 0 : return bContinueSearch;
1487 : : }
1488 : :
1489 : :
1490 : 0 : SdrObject* Outliner::SetObject (
1491 : : const ::sd::outliner::IteratorPosition& rPosition)
1492 : : {
1493 : 0 : SetViewMode (rPosition.mePageKind);
1494 : 0 : SetPage (rPosition.meEditMode, (sal_uInt16)rPosition.mnPageIndex);
1495 : 0 : mnText = rPosition.mnText;
1496 : 0 : return rPosition.mxObject.get();
1497 : : }
1498 : :
1499 : :
1500 : :
1501 : :
1502 : 0 : void Outliner::SetViewShell (const ::boost::shared_ptr<ViewShell>& rpViewShell)
1503 : : {
1504 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1505 [ # # ]: 0 : if (pViewShell != rpViewShell)
1506 : : {
1507 : : // Set the new view shell.
1508 [ # # ]: 0 : mpWeakViewShell = rpViewShell;
1509 : : // When the outline view is not owned by us then we have to clear
1510 : : // that pointer so that the current one for the new view shell will
1511 : : // be used (in ProvideOutlinerView).
1512 [ # # ]: 0 : if (rpViewShell)
1513 : : {
1514 : 0 : mpView = rpViewShell->GetView();
1515 : :
1516 [ # # ]: 0 : mpWindow = rpViewShell->GetActiveWindow();
1517 : :
1518 [ # # ]: 0 : mpImpl->ProvideOutlinerView(*this, rpViewShell, mpWindow);
1519 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1520 [ # # ]: 0 : if (pOutlinerView != NULL)
1521 [ # # ]: 0 : pOutlinerView->SetWindow(mpWindow);
1522 : : }
1523 : : else
1524 : : {
1525 : 0 : mpView = NULL;
1526 : 0 : mpWindow = NULL;
1527 : : }
1528 [ # # ]: 0 : }
1529 : 0 : }
1530 : :
1531 : :
1532 : :
1533 : :
1534 : 0 : void Outliner::HandleChangedSelection (void)
1535 : : {
1536 : 0 : maMarkListCopy.clear();
1537 : 0 : mbRestrictSearchToSelection = (mpView->AreObjectsMarked()==sal_True);
1538 [ # # ]: 0 : if (mbRestrictSearchToSelection)
1539 : : {
1540 : : // Make a copy of the current mark list.
1541 : 0 : const SdrMarkList& rMarkList = mpView->GetMarkedObjectList();
1542 : 0 : sal_uLong nCount = rMarkList.GetMarkCount();
1543 [ # # ]: 0 : if (nCount > 0)
1544 : : {
1545 : 0 : maMarkListCopy.clear();
1546 : 0 : maMarkListCopy.reserve (nCount);
1547 [ # # ]: 0 : for (sal_uLong i=0; i<nCount; i++)
1548 [ # # ]: 0 : maMarkListCopy.push_back (rMarkList.GetMark(i)->GetMarkedSdrObj ());
1549 : : }
1550 : : else
1551 : : // No marked object. Is this case possible?
1552 : 0 : mbRestrictSearchToSelection = false;
1553 : : }
1554 : 0 : }
1555 : :
1556 : :
1557 : :
1558 : :
1559 : :
1560 : 0 : void Outliner::StartConversion( sal_Int16 nSourceLanguage, sal_Int16 nTargetLanguage,
1561 : : const Font *pTargetFont, sal_Int32 nOptions, sal_Bool bIsInteractive )
1562 : : {
1563 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1564 [ # # ][ # # ]: 0 : sal_Bool bMultiDoc = pViewShell->ISA(DrawViewShell);
1565 : :
1566 : 0 : meMode = TEXT_CONVERSION;
1567 : 0 : mbDirectionIsForward = true;
1568 : 0 : mpSearchItem = NULL;
1569 : 0 : mnConversionLanguage = nSourceLanguage;
1570 : :
1571 [ # # ]: 0 : BeginConversion();
1572 : :
1573 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1574 [ # # ]: 0 : if (pOutlinerView != NULL)
1575 : : {
1576 : : pOutlinerView->StartTextConversion(
1577 : : nSourceLanguage,
1578 : : nTargetLanguage,
1579 : : pTargetFont,
1580 : : nOptions,
1581 : : bIsInteractive,
1582 [ # # ]: 0 : bMultiDoc);
1583 : : }
1584 : :
1585 [ # # ][ # # ]: 0 : EndConversion();
1586 : 0 : }
1587 : :
1588 : :
1589 : :
1590 : :
1591 : : /** Prepare to do a text conversion on the current text object. This
1592 : : includes putting it into edit mode.
1593 : : */
1594 : 0 : void Outliner::PrepareConversion (void)
1595 : : {
1596 : 0 : SetUpdateMode(sal_True);
1597 [ # # ]: 0 : if( HasConvertibleTextPortion( mnConversionLanguage ) )
1598 : : {
1599 : 0 : SetUpdateMode(sal_False);
1600 : 0 : mbStringFound = sal_True;
1601 : 0 : mbMatchMayExist = sal_True;
1602 : :
1603 : 0 : EnterEditMode ();
1604 : :
1605 : 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
1606 : : // Start seach at the right end of the current object's text
1607 : : // depending on the search direction.
1608 : : }
1609 : : else
1610 : : {
1611 : 0 : SetUpdateMode(sal_False);
1612 : : }
1613 : 0 : }
1614 : :
1615 : :
1616 : :
1617 : :
1618 : 0 : void Outliner::BeginConversion (void)
1619 : : {
1620 [ # # ][ # # ]: 0 : SetRefDevice( SD_MOD()->GetRefDevice( *mpDrawDocument->GetDocSh() ) );
[ # # ]
1621 : :
1622 [ # # ][ # # ]: 0 : ViewShellBase* pBase = PTR_CAST(ViewShellBase, SfxViewShell::Current());
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
1623 [ # # ]: 0 : if (pBase != NULL)
1624 [ # # ][ # # ]: 0 : SetViewShell (pBase->GetMainViewShell());
[ # # ]
1625 : :
1626 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1627 [ # # ]: 0 : if (pViewShell)
1628 : : {
1629 : 0 : mbStringFound = sal_False;
1630 : :
1631 : : // Supposed that we are not located at the very beginning/end of the
1632 : : // document then there may be a match in the document prior/after
1633 : : // the current position.
1634 : 0 : mbMatchMayExist = sal_True;
1635 : :
1636 [ # # ][ # # ]: 0 : maObjectIterator = ::sd::outliner::Iterator();
[ # # ]
1637 [ # # ][ # # ]: 0 : maSearchStartPosition = ::sd::outliner::Iterator();
[ # # ]
1638 [ # # ]: 0 : RememberStartPosition();
1639 : :
1640 [ # # ]: 0 : mpImpl->ProvideOutlinerView(*this, pViewShell, mpWindow);
1641 : :
1642 [ # # ]: 0 : HandleChangedSelection ();
1643 : : }
1644 [ # # ][ # # ]: 0 : ClearModifyFlag();
1645 : 0 : }
1646 : :
1647 : :
1648 : :
1649 : :
1650 : 0 : void Outliner::EndConversion()
1651 : : {
1652 : 0 : EndSpelling();
1653 : 0 : }
1654 : :
1655 : :
1656 : :
1657 : :
1658 : 0 : sal_Bool Outliner::ConvertNextDocument()
1659 : : {
1660 [ # # ]: 0 : ::boost::shared_ptr<ViewShell> pViewShell (mpWeakViewShell.lock());
1661 [ # # ][ # # ]: 0 : if (pViewShell && pViewShell->ISA(OutlineViewShell) )
[ # # ][ # # ]
[ # # ]
1662 : 0 : return false;
1663 : :
1664 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_True );
1665 : :
1666 [ # # ]: 0 : Initialize ( true );
1667 : :
1668 : 0 : OutlinerView* pOutlinerView = mpImpl->GetOutlinerView();
1669 [ # # ]: 0 : if (pOutlinerView != NULL)
1670 : : {
1671 [ # # ]: 0 : mpWindow = pViewShell->GetActiveWindow();
1672 [ # # ]: 0 : pOutlinerView->SetWindow(mpWindow);
1673 : : }
1674 [ # # ]: 0 : ProvideNextTextObject ();
1675 : :
1676 [ # # ]: 0 : mpDrawDocument->GetDocSh()->SetWaitCursor( sal_False );
1677 [ # # ]: 0 : ClearModifyFlag();
1678 : :
1679 : : // for text conversion we automaticly wrap around one
1680 : : // time and stop at the start shape
1681 [ # # ]: 0 : if( mpFirstObj )
1682 : : {
1683 [ # # ][ # # ]: 0 : if( (mnText == 0) && (mpFirstObj == mpObj) )
1684 : 0 : return false;
1685 : : }
1686 : : else
1687 : : {
1688 : 0 : mpFirstObj = mpObj;
1689 : : }
1690 : :
1691 [ # # ]: 0 : return !mbEndOfSearch;
1692 : : }
1693 : :
1694 : :
1695 : :
1696 : :
1697 : 0 : sal_uInt16 Outliner::ShowModalMessageBox (Dialog& rMessageBox)
1698 : : {
1699 : : // We assume that the parent of the given messge box is NULL, i.e. it is
1700 : : // modal with respect to the top application window. However, this
1701 : : // does not affect the search dialog. Therefore we have to lock it here
1702 : : // while the message box is being shown. We also have to take into
1703 : : // account that we are called during a spell check and the search dialog
1704 : : // is not available.
1705 : 0 : ::Window* pSearchDialog = NULL;
1706 : 0 : SfxChildWindow* pChildWindow = NULL;
1707 [ # # # # ]: 0 : switch (meMode)
1708 : : {
1709 : : case SEARCH:
1710 : : pChildWindow = SfxViewFrame::Current()->GetChildWindow(
1711 : 0 : SvxSearchDialogWrapper::GetChildWindowId());
1712 : 0 : break;
1713 : :
1714 : : case SPELL:
1715 : : pChildWindow = SfxViewFrame::Current()->GetChildWindow(
1716 : 0 : SpellDialogChildWindow::GetChildWindowId());
1717 : 0 : break;
1718 : :
1719 : : case TEXT_CONVERSION:
1720 : : // There should no messages boxes be displayed while doing the
1721 : : // hangul hanja conversion.
1722 : 0 : break;
1723 : : }
1724 : :
1725 [ # # ]: 0 : if (pChildWindow != NULL)
1726 : 0 : pSearchDialog = pChildWindow->GetWindow();
1727 [ # # ]: 0 : if (pSearchDialog != NULL)
1728 : 0 : pSearchDialog->EnableInput(sal_False,sal_True);
1729 : :
1730 : 0 : sal_uInt16 nResult = rMessageBox.Execute();
1731 : :
1732 : : // Unlock the search dialog.
1733 [ # # ]: 0 : if (pSearchDialog != NULL)
1734 : 0 : pSearchDialog->EnableInput(sal_True,sal_True);
1735 : :
1736 : 0 : return nResult;
1737 : : }
1738 : :
1739 : :
1740 : :
1741 : :
1742 : : //===== Outliner::Implementation ==============================================
1743 : :
1744 : 154 : Outliner::Implementation::Implementation (void)
1745 : : : meOriginalEditMode(EM_PAGE),
1746 : : mbOwnOutlineView(false),
1747 : 154 : mpOutlineView(NULL)
1748 : : {
1749 : 154 : }
1750 : :
1751 : :
1752 : :
1753 : :
1754 : 151 : Outliner::Implementation::~Implementation (void)
1755 : : {
1756 [ - + ][ # # ]: 151 : if (mbOwnOutlineView && mpOutlineView!=NULL)
1757 : : {
1758 : 0 : mpOutlineView->SetWindow(NULL);
1759 [ # # ]: 0 : delete mpOutlineView;
1760 : 0 : mpOutlineView = NULL;
1761 : : }
1762 : 151 : }
1763 : :
1764 : :
1765 : :
1766 : :
1767 : 0 : OutlinerView* Outliner::Implementation::GetOutlinerView ()
1768 : : {
1769 : 0 : return mpOutlineView;
1770 : : }
1771 : :
1772 : :
1773 : :
1774 : :
1775 : : /** We try to create a new OutlinerView only when there is none available,
1776 : : either from an OutlinerViewShell or a previous call to
1777 : : ProvideOutlinerView(). This is necessary to support the spell checker
1778 : : which can not cope with exchanging the OutlinerView.
1779 : : */
1780 : 0 : void Outliner::Implementation::ProvideOutlinerView (
1781 : : Outliner& rOutliner,
1782 : : const ::boost::shared_ptr<ViewShell>& rpViewShell,
1783 : : ::Window* pWindow)
1784 : : {
1785 [ # # ]: 0 : if (rpViewShell.get() != NULL)
1786 : : {
1787 [ # # # ]: 0 : switch (rpViewShell->GetShellType())
1788 : : {
1789 : : case ViewShell::ST_DRAW:
1790 : : case ViewShell::ST_IMPRESS:
1791 : : case ViewShell::ST_NOTES:
1792 : : case ViewShell::ST_HANDOUT:
1793 : : {
1794 : : // Create a new outline view to do the search on.
1795 : 0 : bool bInsert = false;
1796 [ # # ][ # # ]: 0 : if (mpOutlineView!=NULL && !mbOwnOutlineView)
1797 : 0 : mpOutlineView = NULL;
1798 [ # # ]: 0 : if (mpOutlineView == NULL)
1799 : : {
1800 [ # # ]: 0 : mpOutlineView = new OutlinerView(&rOutliner, pWindow);
1801 : 0 : mbOwnOutlineView = true;
1802 : 0 : bInsert = true;
1803 : : }
1804 : : else
1805 : 0 : mpOutlineView->SetWindow(pWindow);
1806 : 0 : sal_uLong nStat = mpOutlineView->GetControlWord();
1807 : 0 : nStat &= ~EV_CNTRL_AUTOSCROLL;
1808 : 0 : mpOutlineView->SetControlWord(nStat);
1809 [ # # ]: 0 : if (bInsert)
1810 : 0 : rOutliner.InsertView( mpOutlineView );
1811 : 0 : rOutliner.SetUpdateMode(sal_False);
1812 [ # # ][ # # ]: 0 : mpOutlineView->SetOutputArea (Rectangle (Point(), Size(1, 1)));
1813 [ # # ]: 0 : rOutliner.SetPaperSize( Size(1, 1) );
1814 [ # # ]: 0 : rOutliner.SetText( String(), rOutliner.GetParagraph( 0 ) );
1815 : :
1816 : : meOriginalEditMode =
1817 : 0 : ::boost::static_pointer_cast<DrawViewShell>(rpViewShell)->GetEditMode();
1818 : : }
1819 : 0 : break;
1820 : :
1821 : : case ViewShell::ST_OUTLINE:
1822 : : {
1823 [ # # ][ # # ]: 0 : if (mpOutlineView!=NULL && mbOwnOutlineView)
1824 [ # # ]: 0 : delete mpOutlineView;
1825 : 0 : mpOutlineView = rOutliner.GetView(0);
1826 : 0 : mbOwnOutlineView = false;
1827 : : }
1828 : 0 : break;
1829 : :
1830 : : default:
1831 : : case ViewShell::ST_NONE:
1832 : : case ViewShell::ST_PRESENTATION:
1833 : : // Ignored
1834 : 0 : break;
1835 : : }
1836 : : }
1837 : 0 : }
1838 : :
1839 : :
1840 : :
1841 : :
1842 : 0 : void Outliner::Implementation::ReleaseOutlinerView (void)
1843 : : {
1844 [ # # ]: 0 : if (mbOwnOutlineView)
1845 : : {
1846 : 0 : OutlinerView* pView = mpOutlineView;
1847 : 0 : mpOutlineView = NULL;
1848 : 0 : mbOwnOutlineView = false;
1849 [ # # ]: 0 : if (pView != NULL)
1850 : : {
1851 : 0 : pView->SetWindow(NULL);
1852 [ # # ]: 0 : delete pView;
1853 : : }
1854 : : }
1855 : : else
1856 : : {
1857 : 0 : mpOutlineView = NULL;
1858 : : }
1859 : 0 : }
1860 : :
1861 : : } // end of namespace sd
1862 : :
1863 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|