1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_SD_INC_OUTLINER_HXX
21 #define INCLUDED_SD_INC_OUTLINER_HXX
23 #include <svx/svdobj.hxx>
24 #include <svx/svdoutl.hxx>
26 #include "OutlinerIterator.hxx"
27 #include <editeng/SpellPortions.hxx>
29 #include <boost/shared_ptr.hpp>
30 #include <boost/weak_ptr.hpp>
31 #include <boost/noncopyable.hpp>
44 /// Describes a single search hit: a set of rectangles on a given page.
45 struct SearchSelection
47 /// 0-based index of the page that has the selection.
50 * List of selection rectangles in twips -- multiple rectangles only in
51 * case the selection spans over more layout lines.
53 OString m_aRectangles
;
55 SearchSelection(int nPage
, const OString
& rRectangles
);
58 /** The main purpose of this class is searching and replacing as well as
59 spelling of impress documents. The main part of both tasks lies in
60 iterating over the pages and view modes of a document and apply the
61 respective function to all objects containing text on those pages.
63 <p>Relevant objects: There are two sets of objects to search/spell
64 check. One is the set of all selected objects. The other consists of
65 all objects on all pages in draw-, notes-, and handout view as well as
66 slide- and background view (draw pages and master pages).</p>
68 <p>Iteration: Search/replace and spelling functions operate on shapes
69 containing text. To cover all relevant objects an order has to be
70 defined on the objects. For the set of all selected objects this order
71 is simply the order in which they can be retrieved from the selection
73 When there is no selection the order is nested. The three modes of the
74 draw view are on the outer level: draw mode, notes mode, handout mode.
75 The inner level switches between draw pages and master pages. This
76 leads to the following order:
78 <li>draw pages of draw mode</li>
79 <li>master pages of draw mode</li>
80 <li>draw pages of notes mode</li>
81 <li>master pages of notes mode</li>
82 <li>draw pages of handout mode</li>
83 <li>master pages of handout mode</li>
85 Iteration starts at the top of the current page. When reaching the end
86 of the document, i.e. the last master page of the handout mode, it jumps
87 to the first draw page of draw mode. In backward searches this order is
88 reversed. When doing a <em>replace all</em> then the whole document is
89 searched for matches starting at the first page of the draw/slide view
90 (or last page of handout/background view even though search
93 <p>The start position is restored after finishing spell checking or
94 replacing all matches in a document.</p>
96 <p>Some related pieces of information:
97 The search dialog (<type>SvxSearchDialog</type>) can be controlled in
99 <ul><li>A set of option flags returned by the slot call
100 SID_SEARCH_OPTIONS handled by the
101 <member>SdDrawDocument::GetState()</member> method.</li>
102 <li>The contents of the search item of type
103 <type>SvxSearchItem</type>.</li>
104 <li>The <member>HasSelection()</member> view shell method that returns
105 whether or not a selection exists. However, it is called from the
106 search dialog with an argument so that only text selections are
107 queried. This is only sufficient for searching the outline view.
111 : public SdrOutliner
,
112 public ::boost::noncopyable
115 friend class ::sd::outliner::OutlinerContainer
;
117 /** Create a new sd outliner object.
119 The draw document from which to take the content.
121 The valid values <const>OUTLINERMODE_DONTKNOW</const>,
122 <const>OUTLINERMODE_TEXTOBJECT</const>,
123 <const>OUTLINERMODE_TITLEOBJECT</const>,
124 <const>OUTLINERMODE_OUTLINEOBJECT</const>, and
125 <const>OUTLINERMODE_OUTLINEVIEW</const> are defined in
126 editeng/outliner.hxx.
128 Outliner( SdDrawDocument
* pDoc
, sal_uInt16 nMode
);
131 /** Despite the name this method is called prior to spell checking *and*
132 searching and replacing. The position of current view
133 mode/page/object/caret position is remembered and, depending on the
134 search mode, may be restored after finishing searching/spell
137 void PrepareSpelling();
139 /** Initialize a spell check but do not start it yet. This method
140 is a better candidate for the name PrepareSpelling.
142 void StartSpelling();
144 /** Proxy for method from base class to avoid compiler warning */
145 void StartSpelling(EditView
&, unsigned char);
147 /** Initiate a find and/or replace on the next relevant text object.
149 Returns </sal_True> when the search/replace is finished (as
150 indicated by user input to the search dialog). A </sal_False> value
151 indicates that another call to this method is required.
153 bool StartSearchAndReplace (const SvxSearchItem
* pSearchItem
);
155 /** Iterate over the sentences in all text shapes and stop at the
156 next sentence with spelling errors. While doing so the view
157 mode may be changed and text shapes are set into edit mode.
159 svx::SpellPortions
GetNextSpellSentence();
161 /** Release all resources that have been created during the find&replace
166 /** callback for textconversion */
167 bool ConvertNextDocument() SAL_OVERRIDE
;
169 /** Starts the text conversion (hangul/hanja or Chinese simplified/traditional)
170 for the current viewshell */
171 void StartConversion( sal_Int16 nSourceLanguage
, sal_Int16 nTargetLanguage
,
172 const vcl::Font
*pTargetFont
, sal_Int32 nOptions
, bool bIsInteractive
);
174 /** This is called internally when text conversion is started.
175 The position of current view mode/page/object/caret position
176 is remembered and will be restored after conversion.
178 void BeginConversion();
180 /** Release all resources that have been created during the conversion */
181 void EndConversion();
183 DECL_LINK( SpellError
, void * );
185 enum ChangeHint
{ CH_VIEW_SHELL_INVALID
, CH_VIEW_SHELL_VALID
};
187 int GetIgnoreCurrentPageChangesLevel() const { return mnIgnoreCurrentPageChangesLevel
; };
188 void IncreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel
++; };
189 void DecreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel
--; };
192 class Implementation
;
193 ::std::unique_ptr
<Implementation
> mpImpl
;
195 /// Specifies whether to search and replace, to spell check or to do a
197 enum mode
{SEARCH
, SPELL
, TEXT_CONVERSION
} meMode
;
199 /// The view which displays the searched objects.
201 /** The view shell containing the view. It is held as weak
202 pointer to avoid keeping it alive when the view is changed
205 ::boost::weak_ptr
<ViewShell
> mpWeakViewShell
;
206 /// This window contains the view.
207 VclPtr
< ::sd::Window
> mpWindow
;
208 /// The document on whose objects and pages this class operates.
209 SdDrawDocument
* mpDrawDocument
;
211 /** this is the language that is used for current text conversion.
212 Only valid if meMode is TEXT_CONVERSION.
214 sal_Int16 mnConversionLanguage
;
216 /** While the value of this flag is greater than 0 changes of the current page
217 do not lead to selecting the corresponding text in the outliner.
219 int mnIgnoreCurrentPageChangesLevel
;
221 /// Specifies whether the search string has been found so far.
224 /** This flag indicates whether there may exist a match of the search
225 string before/after the current position in the document. It can be
226 set to </sal_False> only when starting from the beginning/end of the
227 document. When reaching the end/beginning with it still be set to
228 </sal_False> then there exists no match and the search can be terminated.
230 bool mbMatchMayExist
;
232 /// The number of pages in the current view.
233 sal_uInt16 mnPageCount
;
235 /// Number of objects on the current page / in the current selection.
236 sal_Int32 mnObjectCount
;
238 /** A <TRUE/> value indicates that the end of the find&replace or spell
239 check has been reached.
243 /** Set to <TRUE/> when an object has been prepared successfully for
244 searching/spell checking. This flag directs the internal iteration
245 which stops when set to </sal_True>.
249 /** When set to <TRUE/> this flag indicates that an error has occurred
250 that should terminate the iteration over the objects to search/spell
255 /** This flag indicates whether to search forward or backwards.
257 bool mbDirectionIsForward
;
259 /** This flag indicates that only the selected objects are to be
262 bool mbRestrictSearchToSelection
;
264 /** When the search is restricted to the current selection then
265 this list contains pointers to all the objects of the
266 selection. This copy is necessary because during the search
267 process the mark list is modified.
269 ::std::vector
<SdrObjectWeakRef
> maMarkListCopy
;
271 /** This flag indicates that only the current view is to be used for
272 searching and spelling. Automatically switching to other view does
273 not take place when this flag is set.
275 bool mbProcessCurrentViewOnly
;
277 /** Current object that may be a text object. The object pointer to
278 corresponds to <member>mnObjIndex</member>. While iterating over the
279 objects on a page <member>mpObj</member> will point to every object
280 while <member>mpTextObj</member> will be set only to valid text
285 /** this stores the first object that is used for text conversion.
286 Conversion automatically wraps around the document and stops when it
287 finds this object again.
289 SdrObject
* mpFirstObj
;
291 /// Candidate for being searched/spell checked.
292 SdrTextObj
* mpTextObj
;
294 /// Current text to be searched/spelled inside the current text object
297 /// Paragraph object of <member>mpTextObj</member>.
298 OutlinerParaObject
* mpParaObj
;
300 /// The view mode that was active when starting to search/spell check.
301 PageKind meStartViewMode
;
303 /// The master page mode that was active when starting to search/spell check.
304 EditMode meStartEditMode
;
306 /// The current page index on starting to search/spell check.
307 sal_uInt16 mnStartPageIndex
;
309 /// The object in edit mode when searching /spell checking was started
311 SdrObject
* mpStartEditedObject
;
313 /// The position of the caret when searching /spell checking was started.
314 ESelection maStartSelection
;
316 /** The search item contains various attributes that define the type of
317 search. It is set every time the
318 <member>SearchAndReplaceAll</member> method is called.
320 const SvxSearchItem
* mpSearchItem
;
322 /// The actual object iterator.
323 ::sd::outliner::Iterator maObjectIterator
;
324 /// The current position of the object iterator.
325 ::sd::outliner::IteratorPosition maCurrentPosition
;
326 /// The position when the search started. Corresponds largely to the
327 /// m?Start* members.
328 ::sd::outliner::Iterator maSearchStartPosition
;
329 /** The last valid position describes where the last text object has been
330 found. This position is restored when some dialogs are shown. The
331 position is initially set to the where the search begins.
333 ::sd::outliner::IteratorPosition maLastValidPosition
;
335 /** This flag remembers a selection change between a call to the
336 selection change listener callback and the next
337 <member>DetectChange()</member> method call.
339 bool mbSelectionHasChanged
;
341 /** This flag indicates whether a selection change event is expected due
342 to a programatical change of the selection.
344 bool mbExpectingSelectionChangeEvent
;
346 /** This flag is set to true when the whole document has been
347 processed once 'officially', i.e. a message box has been shown
348 that tells the user so.
350 bool mbWholeDocumentProcessed
;
352 /** When this flag is true then a PrepareSpelling() is executed when
353 StartSearchAndReplace() is called the next time.
355 bool mbPrepareSpellingPending
;
357 /** Initialize the object iterator. Call this method after being
358 invoked from the search or spellcheck dialog. It creates a new
359 iterator pointing at the current object when this has not been done
360 before. It reverses the direction of iteration if the given flag
361 differs from the current direction.
362 @param bDirectionIsForward
363 This flag specifies in which direction to iterator over the
364 objects. If it differs from the current direction the iterator
367 void Initialize (bool bDirectionIsForward
);
369 /** Do search and replace for whole document.
371 bool SearchAndReplaceAll();
373 /** Do search and replace for next match.
375 When tiled rendering and not 0, then don't emit LOK events, instead
376 assume the caller will do so.
378 The return value specifies whether the search ended (</sal_True>) or
379 another call to this method is required (</sal_False>).
381 bool SearchAndReplaceOnce(std::vector
<SearchSelection
>* pSelections
= 0);
383 /** Detect changes of the document or view and react accordingly. Such
384 changes may occur because different calls to
385 <member>SearchAndReplace()</member> there usually is user
386 interaction. This is at least the press of the search or replace
387 button but may include any other action some of which affect the
392 /** Detect whether the selection has changed.
394 Return <TRUE/> when the selection has been changed since the
395 last call to this method.
397 bool DetectSelectionChange();
399 /** Remember the current edited object/caret position/page/view mode
400 when starting to search/spell check so that it can be restored on
403 void RememberStartPosition();
405 /** Restore the position stored in the last call of
406 <member>RememberStartPositiony</member>.
408 void RestoreStartPosition();
410 /** Provide next object to search or spell check as text object in edit
411 mode on the current page. This skips all objects that do not
412 match or are no text object.
414 void ProvideNextTextObject();
416 /** Handle the situation that the iterator has reached the last object.
417 This may result in setting the <member>mbEndOfSearch</member> flag
418 back to </sal_False>. This method may show either the end-of-search
419 dialog or the wrap-around dialog.
423 /** Show a dialog that tells the user that the search has ended either
424 because there are no more matches after finding at least one or that
425 no match has been found at all.
427 void ShowEndOfSearchDialog();
429 /** Show a dialog that asks the user whether to wrap around to the
430 beginning/end of the document and continue with the search/spell
433 bool ShowWrapArroundDialog();
435 /** Check whether the object pointed to by the iterator is a valid text
438 The object for which to test whether it is a valid text object.
440 static bool IsValidTextObject (const ::sd::outliner::IteratorPosition
& rPosition
);
442 /** Put text of current text object into outliner so that the text can
443 be searched/spell checked.
445 void PutTextIntoOutliner();
447 /** Prepare to do spell checking on the current text object. This
448 includes putting it into edit mode. Under certain conditions this
449 method sets <member>mbEndOfSearch</member> to <TRUE/>.
451 void PrepareSpellCheck();
453 /** Prepare to search and replace on the current text object. This
454 includes putting it into edit mode.
456 void PrepareSearchAndReplace();
458 /** Prepare to do a text conversion on the current text
459 object. This includes putting it into edit mode.
461 void PrepareConversion();
463 /** Switch to a new view mode. Try to restore the original edit mode
466 Specifies the new view mode.
468 void SetViewMode (PageKind ePageKind
);
470 /** Switch to the page or master page specified by the
471 <member>mnPage</member> index. Master page mode is specified by
472 <member>meEditMode</member>.
478 void SetPage (EditMode eEditMode
, sal_uInt16 nPageIndex
);
480 /** Switch on edit mode for the currently selected text object.
482 void EnterEditMode (bool bGrabFocus
=true);
484 /** Return the position at which a new search is started with respect to
485 the search direction as specified by the argument.
487 The position mentioned above in form of a selection with start
490 ESelection
GetSearchStartPosition();
492 /** Detect whether there exists a previous match. Note that only the
493 absence of such a match can be detected reliably. An existing match
494 is assumed when the search started not at the beginning/end of the
495 presentation. This does not have to be true. The user can have set
496 the cursor at the middle of the text without a prior search.
498 Returns </True> when there is no previous match and </False>
499 when there may be one.
501 bool HasNoPreviousMatch();
503 /** Handle a failed search (with or without replace) for the outline
504 mode. Show message boxes when the search failed completely,
505 i.e. there is no match in the whole presentation, or when no further
508 The returned value indicates whether another (wrapped around)
509 search shall take place. If that is so, then it is the caller's
510 responsibility to set the cursor position accordingly.
512 bool HandleFailedSearch();
514 /** Take a position as returned by an object iterator and switch to the
515 view and page on which the object specified by this position is
518 This position points to a <type>SdrObject</type> object and
519 contains the view and page where it is located.
521 Return a pointer to the <type>SdrObject</type>.
523 SdrObject
* SetObject (const ::sd::outliner::IteratorPosition
& rPosition
);
525 /** Use this method when the view shell in which to search has changed.
526 It handles i.e. registering at the associated view as selection
529 void SetViewShell (const ::boost::shared_ptr
<ViewShell
>& rpViewShell
);
531 /** Activate or deactivate the search in the current selection. Call
532 this method whenever the selection has changed. This method creates
533 a copy of the current selection and reassigns the object iterator to
534 the current() iterator.
536 void HandleChangedSelection();
538 /** Initiate the spell check of the next relevant text object.
539 When the outline view is active then this method is called
540 after a wrap around to continue at the beginning of the document.
542 Returns <TRUE/> to indicate that another call to this method is
543 required. When all text objects have been processed then
544 <FALSE/> is returned.
546 virtual bool SpellNextDocument() SAL_OVERRIDE
;
548 /** Show the given message box and make it modal. It is assumed that
549 the parent of the given dialog is NULL, i.e. the application
550 window. This function makes sure that the otherwise non-modal
551 search dialog, if visible, is locked, too.
553 sal_uInt16
ShowModalMessageBox (Dialog
& rMessageBox
);
556 } // end of namespace sd
560 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */