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 : : #ifndef SD_OUTLINER_HXX
30 : : #define SD_OUTLINER_HXX
31 : :
32 : : #include <svx/svdobj.hxx>
33 : : #include <svx/svdoutl.hxx>
34 : : #include "pres.hxx"
35 : : #include "OutlinerIterator.hxx"
36 : : #include <editeng/SpellPortions.hxx>
37 : : #include <memory>
38 : : #include <boost/shared_ptr.hpp>
39 : : #include <boost/weak_ptr.hpp>
40 : : #include <boost/noncopyable.hpp>
41 : :
42 : : class Dialog;
43 : : class SdrObject;
44 : : class SdrTextObj;
45 : : class SdDrawDocument;
46 : :
47 : : namespace sd {
48 : :
49 : : class View;
50 : : class ViewShell;
51 : : class Window;
52 : :
53 : : /** The main purpose of this class is searching and replacing as well as
54 : : spelling of impress documents. The main part of both tasks lies in
55 : : iterating over the pages and view modes of a document and apply the
56 : : respective function to all objects containing text on those pages.
57 : :
58 : : <p>Relevant objects: There are two sets of objects to search/spell
59 : : check. One is the set of all selected objects. The other consists of
60 : : all objects on all pages in draw-, notes-, and handout view as well as
61 : : slide- and background view (draw pages and master pages).</p>
62 : :
63 : : <p>Iteration: Search/replace and spelling functions operate on shapes
64 : : containing text. To cover all relevant objects an order has to be
65 : : defined on the objects. For the set of all selected objects this order
66 : : is simply the order in which they can be retrieved from the selection
67 : : object.<br>
68 : : When there is no selection the order is nested. The three modes of the
69 : : draw view are on the outer level: draw mode, notes mode, handout mode.
70 : : The inner level switches between draw pages and master pages. This
71 : : leads to the following order:
72 : : <ol>
73 : : <li>draw pages of draw mode</li>
74 : : <li>master pages of draw mode</li>
75 : : <li>draw pages of notes mode</li>
76 : : <li>master pages of notes mode</li>
77 : : <li>draw pages of handout mode</li>
78 : : <li>master pages of handout mode</li>
79 : : </ol>
80 : : Iteration starts at the top of the current page. When reaching the end
81 : : of the document, i.e. the last master page of the handout mode, it jumps
82 : : to the first draw page of draw mode. In backward searches this order is
83 : : reversed. When doing a <em>replace all</em> then the whole document is
84 : : searched for matches starting at the first page of the draw/slide view
85 : : (or last page of handout/background view even though search
86 : : direction).</p>
87 : :
88 : : <p>The start position is restored after finishing spell checking or
89 : : replacing all matches in a document.</p>
90 : :
91 : : <p>Some related pieces of information:
92 : : The search dialog (<type>SvxSearchDialog</type>) can be controlled in
93 : : more than one way:
94 : : <ul><li>A set of option flags returned by the slot call
95 : : SID_SEARCH_OPTIONS handled by the
96 : : <member>SdDrawDocument::GetState()</member> method.</li>
97 : : <li>The contents of the search item of type
98 : : <type>SvxSearchItem</type>.</li>
99 : : <li>The <member>HasSelection()</member> view shell method that returns
100 : : whether or not a selection exists. However, it is called from the
101 : : search dialog with an argument so that only text selections are
102 : : queried. This is only sufficient for searching the outline view.
103 : : </p>
104 : : */
105 : : class Outliner
106 : : : public SdrOutliner,
107 : : public ::boost::noncopyable
108 : : {
109 : : public:
110 : : friend class ::sd::outliner::OutlinerContainer;
111 : :
112 : : /** Create a new sd outliner object.
113 : : @param pDoc
114 : : The draw document from which to take the content.
115 : : @param nMode
116 : : The valid values <const>OUTLINERMODE_DONTKNOW</const>,
117 : : <const>OUTLINERMODE_TEXTOBJECT</const>,
118 : : <const>OUTLINERMODE_TITLEOBJECT</const>,
119 : : <const>OUTLINERMODE_OUTLINEOBJECT</const>, and
120 : : <const>OUTLINERMODE_OUTLINEVIEW</const> are defined in
121 : : editeng/outliner.hxx.
122 : : */
123 : : Outliner( SdDrawDocument* pDoc, sal_uInt16 nMode );
124 : : virtual ~Outliner();
125 : :
126 : : /** Despite the name this method is called prior to spell cheking *and*
127 : : searching and replacing. The position of current view
128 : : mode/page/object/caret position is remembered and, depending on the
129 : : search mode, may be restored after finishing searching/spell
130 : : checking.
131 : : */
132 : : void PrepareSpelling (void);
133 : :
134 : : /** Initialize a spell check but do not start it yet. This method
135 : : is a better candiate for the name PrepareSpelling.
136 : : */
137 : : void StartSpelling (void);
138 : :
139 : : /** Proxy for method from base class to avoid compiler warning */
140 : : void StartSpelling(EditView&, unsigned char);
141 : :
142 : : /** Initiate a find and/or replace on the next relevant text object.
143 : : @return
144 : : Returns </sal_True> when the search/replace is finished (as
145 : : indicated by user input to the search dialog). A </sal_False> value
146 : : indicates that another call to this method is required.
147 : : */
148 : : bool StartSearchAndReplace (const SvxSearchItem* pSearchItem);
149 : :
150 : : /** Iterate over the sentences in all text shapes and stop at the
151 : : next sentence with spelling errors. While doing so the view
152 : : mode may be changed and text shapes are set into edit mode.
153 : : */
154 : : ::svx::SpellPortions GetNextSpellSentence (void);
155 : :
156 : : /** Release all resources that have been created during the find&replace
157 : : or spell check.
158 : : */
159 : : void EndSpelling (void);
160 : :
161 : : /** callback for textconversion */
162 : : sal_Bool ConvertNextDocument (void);
163 : :
164 : : /** Starts the text conversion (hangul/hanja or Chinese simplified/traditional)
165 : : for the current viewshell */
166 : : void StartConversion( sal_Int16 nSourceLanguage, sal_Int16 nTargetLanguage,
167 : : const Font *pTargetFont, sal_Int32 nOptions, sal_Bool bIsInteractive );
168 : :
169 : : /** This is called internaly when text conversion is started.
170 : : The position of current view mode/page/object/caret position
171 : : is remembered and will be restored after conversion.
172 : : */
173 : : void BeginConversion (void);
174 : :
175 : : /** Release all resources that have been created during the conversion */
176 : : void EndConversion (void);
177 : :
178 : : DECL_LINK( SpellError, void * );
179 : :
180 : : enum ChangeHint { CH_VIEW_SHELL_INVALID, CH_VIEW_SHELL_VALID };
181 : :
182 : 0 : int GetIgnoreCurrentPageChangesLevel() const { return mnIgnoreCurrentPageChangesLevel; };
183 : 0 : void IncreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel++; };
184 : 0 : void DecreIgnoreCurrentPageChangesLevel() { mnIgnoreCurrentPageChangesLevel--; };
185 : :
186 : : private:
187 : : class Implementation;
188 : : ::std::auto_ptr<Implementation> mpImpl;
189 : :
190 : : /// Specifies whether to search and replace, to spell check or to do a
191 : : /// text conversion.
192 : : enum mode {SEARCH, SPELL, TEXT_CONVERSION} meMode;
193 : :
194 : : /// The view which displays the searched objects.
195 : : ::sd::View* mpView;
196 : : /** The view shell containing the view. It is held as weak
197 : : pointer to avoid keeping it alive when the view is changed
198 : : during searching.
199 : : */
200 : : ::boost::weak_ptr<ViewShell> mpWeakViewShell;
201 : : /// This window contains the view.
202 : : ::sd::Window* mpWindow;
203 : : /// The document on whose objects and pages this class operates.
204 : : SdDrawDocument* mpDrawDocument;
205 : :
206 : : /** this is the language that is used for current text conversion.
207 : : Only valid if meMode is TEXT_CONVERSION.
208 : : */
209 : : sal_Int16 mnConversionLanguage;
210 : :
211 : : /** While the value of this flag is greater than 0 changes of the current page
212 : : do not lead to selecting the corresponding text in the outliner.
213 : : */
214 : : int mnIgnoreCurrentPageChangesLevel;
215 : :
216 : : /// Specifies whether the search string has been found so far.
217 : : bool mbStringFound;
218 : :
219 : : /** This flag indicates whether there may exist a match of the search
220 : : string before/after the current position in the document. It can be
221 : : set to </sal_False> only when starting from the beginning/end of the
222 : : document. When reaching the end/beginning with it still be set to
223 : : </sal_False> then there exists no match and the search can be terminated.
224 : : */
225 : : bool mbMatchMayExist;
226 : :
227 : : /// The number of pages in the current view.
228 : : sal_uInt16 mnPageCount;
229 : :
230 : : /// Number of objects on the current page / in the current selection.
231 : : sal_Int32 mnObjectCount;
232 : :
233 : : /** A <TRUE/> value indicates that the end of the find&replace or spell
234 : : check has been reached.
235 : : */
236 : : bool mbEndOfSearch;
237 : :
238 : : /** Set to <TRUE/> when an object has been prepared successfully for
239 : : searching/spell checking. This flag directs the internal iteration
240 : : which stops when set to </sal_True>.
241 : : */
242 : : bool mbFoundObject;
243 : :
244 : : /** When set to <TRUE/> this flag indicates that an error has occurred
245 : : that should terminate the iteration over the objects to search/spell
246 : : check.
247 : : */
248 : : bool mbError;
249 : :
250 : : /** This flag indicates whether to search forward or backwards.
251 : : */
252 : : bool mbDirectionIsForward;
253 : :
254 : : /** This flag indicates that only the selected objects are to be
255 : : searched.
256 : : */
257 : : bool mbRestrictSearchToSelection;
258 : :
259 : : /** When the search is restricted to the current selection then
260 : : this list contains pointers to all the objects of the
261 : : selection. This copy is necessary because during the search
262 : : process the mark list is modified.
263 : : */
264 : : ::std::vector<SdrObjectWeakRef> maMarkListCopy;
265 : :
266 : : /** This flag inidcates that only the current view is to be used for
267 : : searching and spelling. Automatically switching to other view does
268 : : not take place when this flag is set.
269 : : */
270 : : bool mbProcessCurrentViewOnly;
271 : :
272 : : /** Current object that may be a text object. The object pointer to
273 : : corresponds to <member>mnObjIndex</member>. While iterating over the
274 : : objects on a page <member>mpObj</member> will point to every object
275 : : while <member>mpTextObj</member> will be set only to valid text
276 : : objects.
277 : : */
278 : : SdrObject* mpObj;
279 : :
280 : : /** this stores the first object that is used for text conversion.
281 : : Conversion automaticly wraps around the document and stops when it
282 : : finds this object again.
283 : : */
284 : : SdrObject* mpFirstObj;
285 : :
286 : : /// Candidate for being searched/spell checked.
287 : : SdrTextObj* mpTextObj;
288 : :
289 : : /// Current text to be searched/spelled inside the current text object
290 : : sal_Int32 mnText;
291 : :
292 : : /// Paragraph object of <member>mpTextObj</member>.
293 : : OutlinerParaObject* mpParaObj;
294 : :
295 : : /// The view mode that was active when starting to search/spell check.
296 : : PageKind meStartViewMode;
297 : :
298 : : /// The master page mode that was active when starting to search/spell check.
299 : : EditMode meStartEditMode;
300 : :
301 : : /// The current page index on starting to search/spell check.
302 : : sal_uInt16 mnStartPageIndex;
303 : :
304 : : /// The object in edit mode when searching /spell checking was started
305 : : /// (if any).
306 : : SdrObject* mpStartEditedObject;
307 : :
308 : : /// The position of the caret when searching /spell checking was started.
309 : : ESelection maStartSelection;
310 : :
311 : : /** The search item contains various attributes that define the type of
312 : : search. It is set every time the
313 : : <member>SearchAndReplaceAll</member> method is called.
314 : : */
315 : : const SvxSearchItem* mpSearchItem;
316 : :
317 : : /// The actual object iterator.
318 : : ::sd::outliner::Iterator maObjectIterator;
319 : : /// The current position of the object iterator.
320 : : ::sd::outliner::IteratorPosition maCurrentPosition;
321 : : /// The position when the search started. Corresponds largely to the
322 : : /// m?Start* members.
323 : : ::sd::outliner::Iterator maSearchStartPosition;
324 : : /** The last valid position desribes where the last text object has been
325 : : found. This position is restored when some dialogs are shown. The
326 : : position is initially set to the where the search begins.
327 : : */
328 : : ::sd::outliner::IteratorPosition maLastValidPosition;
329 : :
330 : : /** This flag remebers a selection change between a call to the
331 : : selection change listener callback and the next
332 : : <member>DetectChange()</member> method call.
333 : : */
334 : : bool mbSelectionHasChanged;
335 : :
336 : : /** This flag indicates whether a selection change event is expected due
337 : : to a programatical change of the selection.
338 : : */
339 : : bool mbExpectingSelectionChangeEvent;
340 : :
341 : : /** This flag is set to true when the whole document has been
342 : : processed once 'officially', i.e. a message box has been shown
343 : : that tells the user so.
344 : : */
345 : : bool mbWholeDocumentProcessed;
346 : :
347 : : /** When this flag is true then a PrepareSpelling() is executed when
348 : : StartSearchAndReplace() is called the next time.
349 : : */
350 : : bool mbPrepareSpellingPending;
351 : :
352 : : /** Initialize the object iterator. Call this method after being
353 : : invoked from the search or spellcheck dialog. It creates a new
354 : : iterator pointing at the current object when this has not been done
355 : : before. It reverses the direction of iteration if the given flag
356 : : differs from the current direction.
357 : : @param bDirectionIsForward
358 : : This flag specifies in which direction to iterator over the
359 : : objects. If it differs from the current direction the iterator
360 : : is reversed.
361 : : */
362 : : void Initialize (bool bDirectionIsForward);
363 : :
364 : : /** Do search and replace for whole document.
365 : : */
366 : : bool SearchAndReplaceAll (void);
367 : :
368 : : /** Do search and replace for next match.
369 : : @return
370 : : The return value specifies whether the search ended (</sal_True>) or
371 : : another call to this method is required (</sal_False>).
372 : : */
373 : : bool SearchAndReplaceOnce (void);
374 : :
375 : : /** Detect changes of the document or view and react accordingly. Such
376 : : changes may occur because different calls to
377 : : <member>SearchAndReplace()</member> there usually is user
378 : : interaction. This is at least the press of the search or replace
379 : : button but may include any other action some of which affect the
380 : : search.
381 : : */
382 : : void DetectChange (void);
383 : :
384 : : /** Detect whether the selection has changed.
385 : : @return
386 : : Return <TRUE/> when the selection has been changed since the
387 : : last call to this method.
388 : : */
389 : : bool DetectSelectionChange (void);
390 : :
391 : : /** Remember the current edited object/caret position/page/view mode
392 : : when starting to search/spell check so that it can be restored on
393 : : termination.
394 : : */
395 : : void RememberStartPosition (void);
396 : :
397 : : /** Restore the position stored in the last call of
398 : : <member>RememberStartPositiony</member>.
399 : : */
400 : : void RestoreStartPosition (void);
401 : :
402 : : /** Provide next object to search or spell check as text object in edit
403 : : mode on the current page. This skips all objects that do not
404 : : match or are no text object.
405 : : */
406 : : void ProvideNextTextObject (void);
407 : :
408 : : /** Handle the situation that the iterator has reached the last object.
409 : : This may result in setting the <member>mbEndOfSearch</member> flag
410 : : back to </sal_False>. This method may show either the end-of-search
411 : : dialog or the wrap-arround dialog.
412 : : */
413 : : void EndOfSearch (void);
414 : :
415 : : /** Show a dialog that tells the user that the search has ended either
416 : : because there are no more matches after finding at least one or that
417 : : no match has been found at all.
418 : : */
419 : : void ShowEndOfSearchDialog (void);
420 : :
421 : : /** Show a dialog that asks the user whether to wrap arround to the
422 : : beginning/end of the document and continue with the search/spell
423 : : check.
424 : : */
425 : : bool ShowWrapArroundDialog (void);
426 : :
427 : : /** Check whether the object pointed to by the iterator is a valid text
428 : : object.
429 : : @param aPosition
430 : : The object for which to test whether it is a valid text object.
431 : : */
432 : : bool IsValidTextObject (const ::sd::outliner::IteratorPosition& rPosition);
433 : :
434 : : /** Put text of current text object into outliner so that the text can
435 : : be searched/spell checked.
436 : : */
437 : : void PutTextIntoOutliner (void);
438 : :
439 : : /** Prepare to do spell checking on the current text object. This
440 : : includes putting it into edit mode. Under certain conditions this
441 : : method sets <member>mbEndOfSearch</member> to <TRUE/>.
442 : : */
443 : : void PrepareSpellCheck (void);
444 : :
445 : : /** Prepare to search and replace on the current text object. This
446 : : includes putting it into edit mode.
447 : : */
448 : : void PrepareSearchAndReplace (void);
449 : :
450 : : /** Prepare to do a text conversion on the current text
451 : : object. This includes putting it into edit mode.
452 : : */
453 : : void PrepareConversion (void);
454 : :
455 : : /** Switch to a new view mode. Try to restore the original edit mode
456 : : before doing so.
457 : : @param ePageKind
458 : : Specifies the new view mode.
459 : : */
460 : : void SetViewMode (PageKind ePageKind);
461 : :
462 : : /** Switch to the page or master page specified by the
463 : : <member>mnPage</member> index. Master page mode is specified by
464 : : <member>meEditMode</member>.
465 : : @param eEditMode
466 : : The new edit mode.
467 : : @param nPageIndex
468 : : The new page index.
469 : : */
470 : : void SetPage (EditMode eEditMode, sal_uInt16 nPageIndex);
471 : :
472 : : /** Switch on edit mode for the currently selected text object.
473 : : */
474 : : void EnterEditMode (sal_Bool bGrabFocus=sal_True);
475 : :
476 : : /** Return the position at which a new search is started with respect to
477 : : the search direction as specified by the argument.
478 : : @return
479 : : The position mentioned above in form of a selection with start
480 : : equals end.
481 : : */
482 : : ESelection GetSearchStartPosition (void);
483 : :
484 : : /** Detect whether there exists a previous match. Note that only the
485 : : absence of such a match can be detected reliably. An existing match
486 : : is assumed when the search started not at the beginning/end of the
487 : : presentation. This does not have to be true. The user can have set
488 : : the cursor at the middle of the text without a prior search.
489 : : @return
490 : : Returns </True> when there is no previous match and </False>
491 : : when there may be one.
492 : : */
493 : : bool HasNoPreviousMatch (void);
494 : :
495 : : /** Handle a failed search (with or without replace) for the outline
496 : : mode. Show message boxes when the search failed completely,
497 : : i.e. there is no match in the whole presentation, or when no further
498 : : match exists.
499 : : @return
500 : : The returned value indicates whether another (wrapped arround)
501 : : search shall take place. If that is so, then it is the caller's
502 : : responsibility to set the cursor position accordingly.
503 : : */
504 : : bool HandleFailedSearch (void);
505 : :
506 : : /** Take a position as returned by an object iterator and switch to the
507 : : view and page on which the object specified by this position is
508 : : located.
509 : : @param rPosition
510 : : This position points to a <type>SdrObject</type> object and
511 : : contains the view and page where it is located.
512 : : @return
513 : : Return a pointer to the <type>SdrObject</type>.
514 : : */
515 : : SdrObject* SetObject (const ::sd::outliner::IteratorPosition& rPosition);
516 : :
517 : : /** Use this method when the view shell in which to search has changed.
518 : : It handles i.e. registering at the associated view as selection
519 : : change listener.
520 : : */
521 : : void SetViewShell (const ::boost::shared_ptr<ViewShell>& rpViewShell);
522 : :
523 : : /** Activate or deactivate the search in the current selection. Call
524 : : this method whenever the selection has changed. This method creates
525 : : a copy of the current selection and reassings the object iterator to
526 : : the current() iterator.
527 : : */
528 : : void HandleChangedSelection (void);
529 : :
530 : : /** Initiate the spell check of the next relevant text object.
531 : : When the outline view is active then this method is called
532 : : after a wrap arround to continue at the beginning of the document.
533 : : @return
534 : : Returns <TRUE/> to indicate that another call to this method is
535 : : required. When all text objects have been processed then
536 : : <FALSE/> is returned.
537 : : */
538 : : virtual sal_Bool SpellNextDocument (void);
539 : :
540 : : /** Show the given message box and make it modal. It is assumed that
541 : : the parent of the given dialog is NULL, i.e. the application
542 : : window. This function makes sure that the otherwise non-modal
543 : : search dialog, if visible, is locked, too.
544 : : */
545 : : sal_uInt16 ShowModalMessageBox (Dialog& rMessageBox);
546 : : };
547 : :
548 : : } // end of namespace sd
549 : :
550 : : #endif
551 : :
552 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|