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/svdoutl.hxx>
25 #include "OutlinerIterator.hxx"
26 #include <editeng/SpellPortions.hxx>
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.
51 * List of selection rectangles in twips -- multiple rectangles only in
52 * case the selection spans over more layout lines.
54 OString m_aRectangles
;
56 SearchSelection(int nPage
, const OString
& rRectangles
)
58 , m_aRectangles(rRectangles
)
62 bool operator==(const SearchSelection
& rOther
) const
64 return m_nPage
== rOther
.m_nPage
&& m_aRectangles
== rOther
.m_aRectangles
;
68 } // end of namespace sd
70 /** The main purpose of this class is searching and replacing as well as
71 spelling of impress documents. The main part of both tasks lies in
72 iterating over the pages and view modes of a document and apply the
73 respective function to all objects containing text on those pages.
75 <p>Relevant objects: There are two sets of objects to search/spell
76 check. One is the set of all selected objects. The other consists of
77 all objects on all pages in draw-, notes-, and handout view as well as
78 slide- and background view (draw pages and master pages).</p>
80 <p>Iteration: Search/replace and spelling functions operate on shapes
81 containing text. To cover all relevant objects an order has to be
82 defined on the objects. For the set of all selected objects this order
83 is simply the order in which they can be retrieved from the selection
85 When there is no selection the order is nested. The three modes of the
86 draw view are on the outer level: draw mode, notes mode, handout mode.
87 The inner level switches between draw pages and master pages. This
88 leads to the following order:
90 <li>draw pages of draw mode</li>
91 <li>master pages of draw mode</li>
92 <li>draw pages of notes mode</li>
93 <li>master pages of notes mode</li>
94 <li>draw pages of handout mode</li>
95 <li>master pages of handout mode</li>
97 Iteration starts at the top of the current page. When reaching the end
98 of the document, i.e. the last master page of the handout mode, it jumps
99 to the first draw page of draw mode. In backward searches this order is
100 reversed. When doing a <em>replace all</em> then the whole document is
101 searched for matches starting at the first page of the draw/slide view
102 (or last page of handout/background view even though search
105 <p>The start position is restored after finishing spell checking or
106 replacing all matches in a document.</p>
108 <p>Some related pieces of information:
109 The search dialog (<type>SvxSearchDialog</type>) can be controlled in
111 <ul><li>A set of option flags returned by the slot call
112 SID_SEARCH_OPTIONS handled by the
113 <member>SdDrawDocument::GetState()</member> method.</li>
114 <li>The contents of the search item of type
115 <type>SvxSearchItem</type>.</li>
116 <li>The <member>HasSelection()</member> view shell method that returns
117 whether or not a selection exists. However, it is called from the
118 search dialog with an argument so that only text selections are
119 queried. This is only sufficient for searching the outline view.
122 class SdOutliner
: public SdrOutliner
125 friend class ::sd::outliner::OutlinerContainer
;
127 /** Create a new sd outliner object.
129 The draw document from which to take the content.
131 The valid values <const>OutlinerMode::DontKnow</const>,
132 <const>OutlinerMode::TextObject</const>,
133 <const>OutlinerMode::TitleObject</const>,
134 <const>OutlinerMode::OutlineObject</const>, and
135 <const>OutlinerMode::OutlineView</const> are defined in
136 editeng/outliner.hxx.
138 SdOutliner(SdDrawDocument
* pDoc
, OutlinerMode nMode
);
139 virtual ~SdOutliner() override
;
140 /// Forbid copy construction and copy assignment
141 SdOutliner(const Outliner
&) = delete;
142 SdOutliner
& operator=(const Outliner
&) = delete;
144 /** Despite the name this method is called prior to spell checking *and*
145 searching and replacing. The position of current view
146 mode/page/object/caret position is remembered and, depending on the
147 search mode, may be restored after finishing searching/spell
150 void PrepareSpelling();
152 /** Initialize a spell check but do not start it yet. This method
153 is a better candidate for the name PrepareSpelling.
155 void StartSpelling();
157 /** Initiate a find and/or replace on the next relevant text object.
159 Returns </sal_True> when the search/replace is finished (as
160 indicated by user input to the search dialog). A </sal_False> value
161 indicates that another call to this method is required.
163 bool StartSearchAndReplace(const SvxSearchItem
* pSearchItem
);
165 /** Iterate over the sentences in all text shapes and stop at the
166 next sentence with spelling errors. While doing so the view
167 mode may be changed and text shapes are set into edit mode.
169 svx::SpellPortions
GetNextSpellSentence();
171 /** Release all resources that have been created during the find&replace
176 /** callback for textconversion */
177 bool ConvertNextDocument() override
;
179 /** Starts the text conversion (hangul/hanja or Chinese simplified/traditional)
180 for the current viewshell */
181 void StartConversion(LanguageType nSourceLanguage
, LanguageType nTargetLanguage
,
182 const vcl::Font
* pTargetFont
, sal_Int32 nOptions
, bool bIsInteractive
);
184 /** This is called internally when text conversion is started.
185 The position of current view mode/page/object/caret position
186 is remembered and will be restored after conversion.
188 void BeginConversion();
190 /** Release all resources that have been created during the conversion */
191 void EndConversion();
193 int GetIgnoreCurrentPageChangesLevel() const { return mnIgnoreCurrentPageChangesLevel
; };
194 void IncreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel
++; };
195 void DecreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel
--; };
196 SdDrawDocument
* GetDoc() const { return mpDrawDocument
; }
199 class Implementation
;
200 ::std::unique_ptr
<Implementation
> mpImpl
;
202 /// Specifies whether to search and replace, to spell check or to do a
211 /// The view which displays the searched objects.
213 /** The view shell containing the view. It is held as weak
214 pointer to avoid keeping it alive when the view is changed
217 std::weak_ptr
<::sd::ViewShell
> mpWeakViewShell
;
218 /// This window contains the view.
219 VclPtr
<::sd::Window
> mpWindow
;
220 /// The document on whose objects and pages this class operates.
221 SdDrawDocument
* mpDrawDocument
;
223 /** this is the language that is used for current text conversion.
224 Only valid if meMode is TEXT_CONVERSION.
226 LanguageType mnConversionLanguage
;
228 /** While the value of this flag is greater than 0 changes of the current page
229 do not lead to selecting the corresponding text in the outliner.
231 int mnIgnoreCurrentPageChangesLevel
;
233 /// Specifies whether the search string has been found so far.
236 /** This flag indicates whether there may exist a match of the search
237 string before/after the current position in the document. It can be
238 set to </sal_False> only when starting from the beginning/end of the
239 document. When reaching the end/beginning with it still be set to
240 </sal_False> then there exists no match and the search can be terminated.
242 bool mbMatchMayExist
;
244 /// The number of pages in the current view.
245 sal_uInt16 mnPageCount
;
247 /** A <TRUE/> value indicates that the end of the find&replace or spell
248 check has been reached.
252 /** Set to <TRUE/> when an object has been prepared successfully for
253 searching/spell checking. This flag directs the internal iteration
254 which stops when set to </sal_True>.
258 /** This flag indicates whether to search forward or backwards.
260 bool mbDirectionIsForward
;
262 /** This flag indicates that only the selected objects are to be
265 bool mbRestrictSearchToSelection
;
267 /** When the search is restricted to the current selection then
268 this list contains pointers to all the objects of the
269 selection. This copy is necessary because during the search
270 process the mark list is modified.
272 ::std::vector
<tools::WeakReference
<SdrObject
>> maMarkListCopy
;
274 /** Current object that may be a text object. The object pointer to
275 corresponds to <member>mnObjIndex</member>. While iterating over the
276 objects on a page <member>mpObj</member> will point to every object
277 while <member>mpTextObj</member> will be set only to valid text
282 /** this stores the first object that is used for text conversion.
283 Conversion automatically wraps around the document and stops when it
284 finds this object again.
286 SdrObject
* mpFirstObj
;
288 /// Candidate for being searched/spell checked.
289 SdrTextObj
* mpSearchSpellTextObj
;
291 /// Current text to be searched/spelled inside the current text object
294 /// Paragraph object of <member>mpTextObj</member>.
295 OutlinerParaObject
* mpParaObj
;
297 /// The view mode that was active when starting to search/spell check.
298 PageKind meStartViewMode
;
300 /// The master page mode that was active when starting to search/spell check.
301 EditMode meStartEditMode
;
303 /// The current page index on starting to search/spell check.
304 sal_uInt16 mnStartPageIndex
;
306 /// The object in edit mode when searching /spell checking was started
308 SdrObject
* mpStartEditedObject
;
310 /// The position of the caret when searching /spell checking was started.
311 ESelection maStartSelection
;
313 /** The search item contains various attributes that define the type of
314 search. It is set every time the
315 <member>SearchAndReplaceAll</member> method is called.
317 const SvxSearchItem
* mpSearchItem
;
319 /// The actual object iterator.
320 ::sd::outliner::Iterator maObjectIterator
;
321 /// The current position of the object iterator.
322 ::sd::outliner::IteratorPosition maCurrentPosition
;
323 /// The position when the search started. Corresponds largely to the
324 /// m?Start* members.
325 ::sd::outliner::Iterator maSearchStartPosition
;
326 /** The last valid position describes where the last text object has been
327 found. This position is restored when some dialogs are shown. The
328 position is initially set to the where the search begins.
330 ::sd::outliner::IteratorPosition maLastValidPosition
;
332 /** When this flag is true then a PrepareSpelling() is executed when
333 StartSearchAndReplace() is called the next time.
335 bool mbPrepareSpellingPending
;
337 /** Initialize the object iterator. Call this method after being
338 invoked from the search or spellcheck dialog. It creates a new
339 iterator pointing at the current object when this has not been done
340 before. It reverses the direction of iteration if the given flag
341 differs from the current direction.
342 @param bDirectionIsForward
343 This flag specifies in which direction to iterator over the
344 objects. If it differs from the current direction the iterator
347 void Initialize(bool bDirectionIsForward
);
349 /** Do search and replace for whole document.
351 bool SearchAndReplaceAll();
353 /** Do search and replace for next match.
355 When tiled rendering and not 0, then don't emit LOK events, instead
356 assume the caller will do so.
358 The return value specifies whether the search ended (</sal_True>) or
359 another call to this method is required (</sal_False>).
361 bool SearchAndReplaceOnce(std::vector
<::sd::SearchSelection
>* pSelections
= nullptr);
363 void sendLOKSearchResultCallback(const std::shared_ptr
<sd::ViewShell
>& pViewShell
,
364 const OutlinerView
* pOutlinerView
,
365 std::vector
<sd::SearchSelection
>* pSelections
);
367 /** Detect changes of the document or view and react accordingly. Such
368 changes may occur because different calls to
369 <member>SearchAndReplace()</member> there usually is user
370 interaction. This is at least the press of the search or replace
371 button but may include any other action some of which affect the
376 /** Detect whether the selection has changed.
378 Return <TRUE/> when the selection has been changed since the
379 last call to this method.
381 bool DetectSelectionChange();
383 /** Remember the current edited object/caret position/page/view mode
384 when starting to search/spell check so that it can be restored on
387 void RememberStartPosition();
389 /** Restore the position stored in the last call of
390 <member>RememberStartPositiony</member>.
392 void RestoreStartPosition();
394 /** Provide next object to search or spell check as text object in edit
395 mode on the current page. This skips all objects that do not
396 match or are no text object.
398 void ProvideNextTextObject();
400 /** Handle the situation that the iterator has reached the last object.
401 This may result in setting the <member>mbEndOfSearch</member> flag
402 back to </sal_False>. This method may show either the end-of-search
403 dialog or the wrap-around dialog.
407 /** Show a dialog that tells the user that the search has ended either
408 because there are no more matches after finding at least one or that
409 no match has been found at all.
411 void ShowEndOfSearchDialog();
413 /** Show a dialog that asks the user whether to wrap around to the
414 beginning/end of the document and continue with the search/spell
417 bool ShowWrapAroundDialog();
419 /** Put text of current text object into outliner so that the text can
420 be searched/spell checked.
422 void PutTextIntoOutliner();
424 /** Prepare to do spell checking on the current text object. This
425 includes putting it into edit mode. Under certain conditions this
426 method sets <member>mbEndOfSearch</member> to <TRUE/>.
428 void PrepareSpellCheck();
430 /** Prepare to search and replace on the current text object. This
431 includes putting it into edit mode.
433 void PrepareSearchAndReplace();
435 /** Prepare to do a text conversion on the current text
436 object. This includes putting it into edit mode.
438 void PrepareConversion();
440 /** Switch to a new view mode. Try to restore the original edit mode
443 Specifies the new view mode.
445 void SetViewMode(PageKind ePageKind
);
447 /** Switch to the page or master page specified by the
448 <member>mnPage</member> index. Master page mode is specified by
449 <member>meEditMode</member>.
455 void SetPage(EditMode eEditMode
, sal_uInt16 nPageIndex
);
457 /** Switch on edit mode for the currently selected text object.
459 void EnterEditMode(bool bGrabFocus
);
461 /** Return the position at which a new search is started with respect to
462 the search direction as specified by the argument.
464 The position mentioned above in form of a selection with start
467 ESelection
GetSearchStartPosition() const;
469 /** Detect whether there exists a previous match. Note that only the
470 absence of such a match can be detected reliably. An existing match
471 is assumed when the search started not at the beginning/end of the
472 presentation. This does not have to be true. The user can have set
473 the cursor at the middle of the text without a prior search.
475 Returns </True> when there is no previous match and </False>
476 when there may be one.
478 bool HasNoPreviousMatch();
480 /** Handle a failed search (with or without replace) for the outline
481 mode. Show message boxes when the search failed completely,
482 i.e. there is no match in the whole presentation, or when no further
485 The returned value indicates whether another (wrapped around)
486 search shall take place. If that is so, then it is the caller's
487 responsibility to set the cursor position accordingly.
489 bool HandleFailedSearch();
491 /** Take a position as returned by an object iterator and switch to the
492 view and page on which the object specified by this position is
495 This position points to a <type>SdrObject</type> object and
496 contains the view and page where it is located.
498 Return a pointer to the <type>SdrObject</type>.
500 SdrObject
* SetObject(const ::sd::outliner::IteratorPosition
& rPosition
);
502 /** Use this method when the view shell in which to search has changed.
503 It handles i.e. registering at the associated view as selection
506 void SetViewShell(const std::shared_ptr
<::sd::ViewShell
>& rpViewShell
);
508 /** Activate or deactivate the search in the current selection. Call
509 this method whenever the selection has changed. This method creates
510 a copy of the current selection and reassigns the object iterator to
511 the current() iterator.
513 void HandleChangedSelection();
515 /** Initiate the spell check of the next relevant text object.
516 When the outline view is active then this method is called
517 after a wrap around to continue at the beginning of the document.
519 Returns <TRUE/> to indicate that another call to this method is
520 required. When all text objects have been processed then
521 <FALSE/> is returned.
523 virtual bool SpellNextDocument() override
;
525 /** Find the right parent to use for a message. This function makes sure
526 that the otherwise non-modal search or spell dialogs, if visible, are
529 weld::Window
* GetMessageBoxParent();
534 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */